From 7c16313f11e3953f3fe4dbf544f2d36f58d14138 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sun, 29 Jun 2014 13:11:44 +0200 Subject: networkd/sd-dhcp-server: only start dhcp server when necessary --- src/libsystemd-network/sd-dhcp-server.c | 6 ++++++ src/network/networkd-link.c | 3 ++- src/systemd/sd-dhcp-server.h | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index c932377d88..5c32fdfffa 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -62,6 +62,12 @@ int sd_dhcp_server_set_address(sd_dhcp_server *server, struct in_addr *address) return 0; } +bool sd_dhcp_server_is_running(sd_dhcp_server *server) { + assert_return(server, -EINVAL); + + return !!server->receive_message; +} + sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server) { if (server) assert_se(REFCNT_INC(server->n_ref) >= 2); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 9296a594db..5527489364 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -307,7 +307,8 @@ static int link_enter_configured(Link *link) { assert(link->network); assert(link->state == LINK_STATE_SETTING_ROUTES); - if (link->network->dhcp_server) { + if (link->network->dhcp_server && + !sd_dhcp_server_is_running(link->dhcp_server)) { struct in_addr pool_start; Address *address; diff --git a/src/systemd/sd-dhcp-server.h b/src/systemd/sd-dhcp-server.h index cd0ff72af2..01595d39d1 100644 --- a/src/systemd/sd-dhcp-server.h +++ b/src/systemd/sd-dhcp-server.h @@ -23,6 +23,7 @@ along with systemd; If not, see . ***/ +#include #include #include "sd-event.h" @@ -38,6 +39,8 @@ int sd_dhcp_server_attach_event(sd_dhcp_server *client, sd_event *event, int pri int sd_dhcp_server_detach_event(sd_dhcp_server *client); sd_event *sd_dhcp_server_get_event(sd_dhcp_server *client); +bool sd_dhcp_server_is_running(sd_dhcp_server *server); + int sd_dhcp_server_start(sd_dhcp_server *server); int sd_dhcp_server_stop(sd_dhcp_server *server); -- cgit v1.2.3-54-g00ecf