Skip to content

Commit 9c2faf8

Browse files
authored
feat(dhcp): enable --debug option for dhcpcd (#6693)
The primary motivation for this extra detail is to capture the flow when multiple DISCOVER requests are required, similar to what we see in dhclient today so we can better understand how time is spent in dhcpcd. Without debug: ``` 2026-01-28 18:19:59,156 - azure.py[DEBUG]: dhcp client stderr for interface=eth0: dhcpcd-10.0.6 starting DUID 00:01:00:01:31:0d:0f:cd:60:45:bd:86:6f:e1 eth0: IAID bd:86:6f:e1 eth0: soliciting a DHCP lease eth0: offered 10.0.0.4 from 168.63.129.16 LVL101082702015SOC eth0: leased 10.0.0.4 for infinity eth0: adding route to 10.0.0.0/16 eth0: adding default route via 10.0.0.1 eth0: adding host route to 168.63.129.16 via 10.0.0.1 eth0: adding host route to 169.254.169.254 via 10.0.0.1 ``` With debug: ``` 2026-01-28 19:52:56,822 - performance.py[DEBUG]: Running ['dhcpcd', '--ipv4only', '--waitip', '--persistent', '--noarp', '--debug', '--script=/bin/true', 'eth0'] took 0.128 seconds 2026-01-28 19:52:56,822 - azure.py[DEBUG]: dhcp client stdout for interface=eth0: 2026-01-28 19:52:56,822 - azure.py[DEBUG]: dhcp client stderr for interface=eth0: dhcpcd-10.0.6 starting spawned manager process on PID 527 chrooting as dhcpcd to /usr/lib/dhcpcd sandbox: seccomp spawned privileged proxy on PID 528 spawned controller proxy on PID 529 eth0: executing: /bin/true PREINIT eth0: executing: /bin/true CARRIER DUID 00:01:00:01:31:0d:25:98:60:45:bd:86:6f:e1 eth0: IAID bd:86:6f:e1 eth0: delaying IPv4 for 0.0 seconds eth0: reading lease: /var/lib/dhcpcd/eth0.lease eth0: soliciting a DHCP lease eth0: spawned BPF BOOTP on PID 535 eth0: sending DISCOVER (xid 0x3793814b), next in 4.6 seconds eth0: offered 10.0.0.4 from 168.63.129.16 LVL101082702015SOC eth0: process BPF BOOTP already started on pid 535 eth0: sending REQUEST (xid 0x3793814b), next in 4.4 seconds eth0: acknowledged 10.0.0.4 from 168.63.129.16 LVL101082702015SOC eth0: leased 10.0.0.4 for infinity eth0: writing lease: /var/lib/dhcpcd/eth0.lease eth0: adding IP address 10.0.0.4/16 broadcast 10.0.255.255 eth0: using Classless Static Routes eth0: adding route to 10.0.0.0/16 eth0: adding default route via 10.0.0.1 eth0: adding host route to 168.63.129.16 via 10.0.0.1 eth0: adding host route to 169.254.169.254 via 10.0.0.1 eth0: executing: /bin/true BOUND forked to background ``` One interesting detail I noticed is that a persistent lease file may be used for reboots and DISCOVER is skipped: ``` 2026-01-28 19:49:57,987 - performance.py[DEBUG]: Running ['dhcpcd', '--ipv4only', '--waitip', '--persistent', '--noarp', '--debug', '--script=/bin/true', 'eth0'] took 0.386 seconds 2026-01-28 19:49:57,987 - azure.py[DEBUG]: dhcp client stdout for interface=eth0: 2026-01-28 19:49:57,987 - azure.py[DEBUG]: dhcp client stderr for interface=eth0: dhcpcd-10.0.6 starting chrooting as dhcpcd to /usr/lib/dhcpcd sandbox: seccomp spawned manager process on PID 527 spawned privileged proxy on PID 528 spawned controller proxy on PID 529 DUID 00:01:00:01:31:0d:0f:cd:60:45:bd:86:6f:e1 eth0: executing: /bin/true PREINIT eth0: executing: /bin/true CARRIER eth0: IAID bd:86:6f:e1 eth0: delaying IPv4 for 0.4 seconds eth0: reading lease: /var/lib/dhcpcd/eth0.lease eth0: rebinding lease of 10.0.0.4 eth0: spawned BPF ARP 10.0.0.4 on PID 545 eth0: sending REQUEST (xid 0x3740297a), next in 4.5 seconds eth0: spawned BPF BOOTP on PID 546 eth0: acknowledged 10.0.0.4 from 168.63.129.16 LVL101082702015SOC eth0: leased 10.0.0.4 for infinity eth0: writing lease: /var/lib/dhcpcd/eth0.lease eth0: adding IP address 10.0.0.4/16 broadcast 10.0.255.255 eth0: using Classless Static Routes eth0: adding route to 10.0.0.0/16 eth0: adding default route via 10.0.0.1 eth0: adding host route to 168.63.129.16 via 10.0.0.1 eth0: adding host route to 169.254.169.254 via 10.0.0.1 eth0: executing: /bin/true REBOOT forked to background ``` The --debug option has been around forever for dhcpcd so it should be safe. We can see it the oldest tagged version in git and Ubuntu 14.04's manpage: https://manpages.ubuntu.com/manpages//trusty/man8/dhcpcd-bin.8.html Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
1 parent feaf147 commit 9c2faf8

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

cloudinit/net/dhcp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ def dhcp_discovery(
661661
"--waitip", # wait for ipv4 to be configured
662662
"--persistent", # don't deconfigure when dhcpcd exits
663663
"--noarp", # don't be slow
664+
"--debug", # verbose logging for debugging
664665
"--script=/bin/true", # disable hooks
665666
*infiniband_argument,
666667
interface,

tests/unittests/net/test_dhcp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ def test_dhcpcd_discovery_ib(
13301330
"--waitip",
13311331
"--persistent",
13321332
"--noarp",
1333+
"--debug",
13331334
"--script=/bin/true",
13341335
"--clientid",
13351336
"ib0",
@@ -1376,6 +1377,7 @@ def test_dhcpcd_discovery_timeout(
13761377
"--waitip",
13771378
"--persistent",
13781379
"--noarp",
1380+
"--debug",
13791381
"--script=/bin/true",
13801382
"eth0",
13811383
],

0 commit comments

Comments
 (0)