Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dhcpcd -U <interface> only works with dhcpcd daemon running #286

Open
holmanb opened this issue Jan 19, 2024 · 0 comments
Open

dhcpcd -U <interface> only works with dhcpcd daemon running #286

holmanb opened this issue Jan 19, 2024 · 0 comments

Comments

@holmanb
Copy link

holmanb commented Jan 19, 2024

works as expected:

# dhcpcd --dumplease -4 eth0
reason=REBOOT
interface=eth0
protocol=dhcp
ip_address=10.0.0.4
subnet_cidr=24
broadcast_address=10.0.0.255
network_number=10.0.0.0
server_name=IAD201121002027
subnet_mask=255.255.255.0
classless_static_routes=0.0.0.0/0 10.0.0.1 168.63.129.16/32 10.0.0.1 169.254.169.254/32 10.0.0.1
routers=10.0.0.1
domain_name_servers=168.63.129.16
domain_name=v1n0blf1qpvufijtbcm2fvnk3c.bx.internal.cloudapp.net
dhcp_lease_time=4294967295
dhcp_message_type=5
dhcp_server_identifier=168.63.129.16
dhcp_renewal_time=4294967295
dhcp_rebinding_time=4294967295

without the daemon, this surprisingly fails

root@SRU-worked-azure:/home/ubuntu/dhcpcd-10.0.6# pkill -9 dhcpcd
root@SRU-worked-azure:/home/ubuntu/dhcpcd-10.0.6# dhcpcd --dumplease -4 eth0
dhcpcd is not running

Inspecting the code, it appears that if no data is read from the input buffer, the manager daemon is always contacted. This means that parsing via stdin (which is broken) is the only way to run --dumplease without contacting the manager daemon.

holmanb added a commit to holmanb/dhcpcd that referenced this issue Jan 20, 2024
Previous code used the non-existance of data in the input buffer to
determine whether to attempt parsing from stdin. When data is not
immediately available in the input buffer, that logic caused the code
to attempt to contact the manager daemon, which also fails. This means
that `dhcpcd -U <interface>` will sometimes fail:

 # dhcpcd --dumplease --ipv4only < /var/lib/dhcpcd/<iface>.lease
 dhcpcd is not running

This behavior is a race condition possibly exacerbated by slow storage
media or virtualization. The following reproducer makes this behavior
testable on any platform:

 # (sleep 0.1; sudo cat /var/lib/dhcpcd/<iface>.lease) | dhcpcd --dumplease -4

Note: Running dhcpcd -U <iface> explicitly requires a running manager
daemon (see upstream issue NetworkConfiguration#286). Therefore, parsing via stdin is the
only way to read leases without running the manager daemon. This is an
important feature for users that get dhcp leases using --oneshot.

Fixes NetworkConfiguration#286
holmanb added a commit to holmanb/dhcpcd that referenced this issue Jan 20, 2024
Previous code used the non-existance of data in the input buffer to
determine whether to attempt parsing from stdin. This is racy, so
`dhcpcd -U < /path/to/lease` will sometimes fail:

  # dhcpcd --dumplease --ipv4only < /var/lib/dhcpcd/<iface>.lease
  dhcpcd is not running

 The fix uses the (non-)existance of an interface argument to indicate
 that dhcpcd should wait for data to arrive on stdin.

Fixes NetworkConfiguration#286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant