n-dhcp4/socket: use SO_REUSEADDR on UDP socket

Otherwise, other applications cannot bind to port 0.0.0.0:68 at the same time.
This is for example what dhclient wants to do. So even when running
dhclient on another, unrelated interface, it would fail to bind the UDP
socket and quit.

Note that also systemd-networkd's DHCPv4 client sets this socket option.
Presumably for the same reasons.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://github.com/nettools/n-dhcp4/pull/12
(cherry picked from commit 53b74bc614)
This commit is contained in:
Thomas Haller 2019-12-11 09:22:47 +01:00
parent d33bea21b7
commit cf7662bc52

View file

@ -195,6 +195,10 @@ int n_dhcp4_c_socket_udp_new(int *sockfdp,
if (sockfd < 0)
return -errno;
r = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (r < 0)
return -errno;
r = setsockopt(sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog));
if (r < 0)
return -errno;