summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp-network.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-24 15:48:47 +0200
committerTom Gundersen <teg@jklm.no>2014-06-13 16:53:13 +0200
commitfef0e0f3b2ad24ed825f04fe1fe60742958f3567 (patch)
tree6fb8c17d586fca4882e672f6acaf8d643db3027e /src/libsystemd-network/dhcp-network.c
parent55745f2054a1bc132ee415ddd72441bac52b89b6 (diff)
dhcp-network: allow UDP socket to listen on any address
For this to work nicely we need to use REUSEADDR so that more than one socket can be open at the same time. Also, we request the ifindex to be appended to incoming messages, so we know whence it came.
Diffstat (limited to 'src/libsystemd-network/dhcp-network.c')
-rw-r--r--src/libsystemd-network/dhcp-network.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libsystemd-network/dhcp-network.c b/src/libsystemd-network/dhcp-network.c
index dd26ef3e00..6fac80e873 100644
--- a/src/libsystemd-network/dhcp-network.c
+++ b/src/libsystemd-network/dhcp-network.c
@@ -68,7 +68,7 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link,
.filter = filter
};
_cleanup_close_ int s = -1;
- int r, one = 1;
+ int r, on = 1;
assert(index > 0);
assert(link);
@@ -77,7 +77,7 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link,
if (s < 0)
return -errno;
- r = setsockopt (s, SOL_PACKET, PACKET_AUXDATA, &one, sizeof(one));
+ r = setsockopt (s, SOL_PACKET, PACKET_AUXDATA, &on, sizeof(on));
if (r < 0)
return -errno;
@@ -117,6 +117,17 @@ int dhcp_network_bind_udp_socket(be32_t address, uint16_t port) {
r = setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
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, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on));
+ if (r < 0)
+ return -errno;
+ }
r = bind(s, &src.sa, sizeof(src.in));
if (r < 0)