summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-24 23:03:49 +0200
committerTom Gundersen <teg@jklm.no>2014-06-13 16:53:13 +0200
commit8de4a226c71ef43e652274b33b5d19211a44ac7b (patch)
tree29e6c012c969e7608ed330834581fe305f164335 /src/libsystemd-network
parent816e2e7af96886e4a43194042ef61ba9fec2c77d (diff)
sd-dhcp-server: bind to raw socket for sending
We would like to use the UDP socket, but we cannot as we need to specify the MAC address manually.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp-server-internal.h1
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c11
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h
index 3d49cba917..6c2f2b4070 100644
--- a/src/libsystemd-network/dhcp-server-internal.h
+++ b/src/libsystemd-network/dhcp-server-internal.h
@@ -36,6 +36,7 @@ struct sd_dhcp_server {
int event_priority;
sd_event_source *receive_message;
int fd;
+ int fd_raw;
int index;
};
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index b1f2fa063f..ecdc15dff7 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -58,6 +58,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
return -ENOMEM;
server->n_ref = REFCNT_INIT;
+ server->fd_raw = -1;
server->fd = -1;
server->index = ifindex;
@@ -106,6 +107,7 @@ int sd_dhcp_server_stop(sd_dhcp_server *server) {
server->receive_message =
sd_event_source_unref(server->receive_message);
+ server->fd_raw = safe_close(server->fd_raw);
server->fd = safe_close(server->fd);
log_dhcp_server(server, "STOPPED");
@@ -277,8 +279,17 @@ int sd_dhcp_server_start(sd_dhcp_server *server) {
assert_return(server, -EINVAL);
assert_return(server->event, -EINVAL);
assert_return(!server->receive_message, -EBUSY);
+ assert_return(server->fd_raw == -1, -EBUSY);
assert_return(server->fd == -1, -EBUSY);
+ r = socket(AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ if (r < 0) {
+ r = -errno;
+ sd_dhcp_server_stop(server);
+ return r;
+ }
+ server->fd_raw = r;
+
r = dhcp_network_bind_udp_socket(INADDR_ANY, DHCP_PORT_SERVER);
if (r < 0) {
sd_dhcp_server_stop(server);