diff options
author | Tom Gundersen <teg@jklm.no> | 2014-07-25 14:43:16 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-07-28 10:44:51 +0200 |
commit | 076adf013a171e819f84684e2eb22e965e96ee59 (patch) | |
tree | b9bea55088432a3764613b9a5afdd17d6c17f16f /src | |
parent | 2d2349cc3ed43153344807892332c9fa626c8d8a (diff) |
dhcp-network: enable IP_FREEBIND for UDP sockets
This allows the sockets to be bound to a specific address before it is configured,
also enable SO_REUSEADDR to allow multiple DHCP clients to run at the same time.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-network/dhcp-network.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libsystemd-network/dhcp-network.c b/src/libsystemd-network/dhcp-network.c index 16411cc41a..29276c0559 100644 --- a/src/libsystemd-network/dhcp-network.c +++ b/src/libsystemd-network/dhcp-network.c @@ -126,7 +126,7 @@ int dhcp_network_bind_udp_socket(be32_t address, uint16_t port) { .in.sin_addr.s_addr = address, }; _cleanup_close_ int s = -1; - int r, tos = IPTOS_CLASS_CS6; + int r, on = 1, tos = IPTOS_CLASS_CS6; s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); if (s < 0) @@ -136,13 +136,11 @@ int dhcp_network_bind_udp_socket(be32_t address, uint16_t port) { if (r < 0) return -errno; - if (address == INADDR_ANY) { - int on = 1; - - r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - if (r < 0) - return -errno; + r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + if (r < 0) + return -errno; + if (address == INADDR_ANY) { r = setsockopt(s, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on)); if (r < 0) return -errno; @@ -150,6 +148,10 @@ int dhcp_network_bind_udp_socket(be32_t address, uint16_t port) { r = setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); if (r < 0) return -errno; + } else { + r = setsockopt(s, IPPROTO_IP, IP_FREEBIND, &on, sizeof(on)); + if (r < 0) + return -errno; } r = bind(s, &src.sa, sizeof(src.in)); |