chiark / gitweb /
networkd/sd-dhcp-server: only start dhcp server when necessary
authorTom Gundersen <teg@jklm.no>
Sun, 29 Jun 2014 11:11:44 +0000 (13:11 +0200)
committerTom Gundersen <teg@jklm.no>
Sun, 29 Jun 2014 13:18:21 +0000 (15:18 +0200)
src/libsystemd-network/sd-dhcp-server.c
src/network/networkd-link.c
src/systemd/sd-dhcp-server.h

index c932377..5c32fdf 100644 (file)
@@ -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);
index 9296a59..5527489 100644 (file)
@@ -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;
 
index cd0ff72..01595d3 100644 (file)
@@ -23,6 +23,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <stdbool.h>
 #include <netinet/in.h>
 
 #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);