chiark / gitweb /
networkd: dhcp-server - start as soon as addresses have been set
authorTom Gundersen <teg@jklm.no>
Fri, 30 Jan 2015 18:54:01 +0000 (19:54 +0100)
committerTom Gundersen <teg@jklm.no>
Sat, 31 Jan 2015 14:26:08 +0000 (15:26 +0100)
We would otherwise wait for the interface to be completely configured, which
could take considerable time with IPv4LL. As a result nspawn was very slow
at obtaining IP addresses.

src/network/networkd-link.c

index 310eb6c..acdb486 100644 (file)
@@ -443,7 +443,7 @@ static Address* link_find_dhcp_server_address(Link *link) {
         assert(link);
         assert(link->network);
 
         assert(link);
         assert(link->network);
 
-        /* The the first statically configured address if there is any */
+        /* The first statically configured address if there is any */
         LIST_FOREACH(addresses, address, link->network->static_addresses) {
 
                 if (address->family != AF_INET)
         LIST_FOREACH(addresses, address, link->network->static_addresses) {
 
                 if (address->family != AF_INET)
@@ -467,63 +467,10 @@ static Address* link_find_dhcp_server_address(Link *link) {
 }
 
 static int link_enter_configured(Link *link) {
 }
 
 static int link_enter_configured(Link *link) {
-        int r;
-
         assert(link);
         assert(link->network);
         assert(link->state == LINK_STATE_SETTING_ROUTES);
 
         assert(link);
         assert(link->network);
         assert(link->state == LINK_STATE_SETTING_ROUTES);
 
-        if (link_dhcp4_server_enabled(link) &&
-            !sd_dhcp_server_is_running(link->dhcp_server)) {
-                struct in_addr pool_start;
-                Address *address;
-
-                address = link_find_dhcp_server_address(link);
-                if (!address) {
-                        log_link_warning(link,
-                                         "Failed to find suitable address for DHCPv4 server instance.");
-                        link_enter_failed(link);
-                        return 0;
-                }
-
-                log_link_debug(link, "offering DHCPv4 leases");
-
-                r = sd_dhcp_server_set_address(link->dhcp_server,
-                                               &address->in_addr.in,
-                                               address->prefixlen);
-                if (r < 0)
-                        return r;
-
-                /* offer 32 addresses starting from the address following the server address */
-                pool_start.s_addr = htobe32(be32toh(address->in_addr.in.s_addr) + 1);
-                r = sd_dhcp_server_set_lease_pool(link->dhcp_server,
-                                                  &pool_start, 32);
-                if (r < 0)
-                        return r;
-
-                /* TODO:
-                r = sd_dhcp_server_set_router(link->dhcp_server,
-                                              &main_address->in_addr.in);
-                if (r < 0)
-                        return r;
-
-                r = sd_dhcp_server_set_prefixlen(link->dhcp_server,
-                                                 main_address->prefixlen);
-                if (r < 0)
-                        return r;
-                */
-
-                r = sd_dhcp_server_start(link->dhcp_server);
-                if (r < 0) {
-                        log_link_warning(link, "could not start DHCPv4 server "
-                                         "instance: %s", strerror(-r));
-
-                        link_enter_failed(link);
-
-                        return 0;
-                }
-        }
-
         log_link_info(link, "link configured");
 
         link->state = LINK_STATE_CONFIGURED;
         log_link_info(link, "link configured");
 
         link->state = LINK_STATE_CONFIGURED;
@@ -683,6 +630,58 @@ static int link_enter_set_addresses(Link *link) {
                 link->link_messages ++;
         }
 
                 link->link_messages ++;
         }
 
+        /* now that we can figure out a default address for the dhcp server,
+           start it */
+        if (link_dhcp4_server_enabled(link)) {
+                struct in_addr pool_start;
+                Address *address;
+
+                address = link_find_dhcp_server_address(link);
+                if (!address) {
+                        log_link_warning(link,
+                                         "Failed to find suitable address for DHCPv4 server instance.");
+                        link_enter_failed(link);
+                        return 0;
+                }
+
+                r = sd_dhcp_server_set_address(link->dhcp_server,
+                                               &address->in_addr.in,
+                                               address->prefixlen);
+                if (r < 0)
+                        return r;
+
+                /* offer 32 addresses starting from the address following the server address */
+                pool_start.s_addr = htobe32(be32toh(address->in_addr.in.s_addr) + 1);
+                r = sd_dhcp_server_set_lease_pool(link->dhcp_server,
+                                                  &pool_start, 32);
+                if (r < 0)
+                        return r;
+
+                /* TODO:
+                r = sd_dhcp_server_set_router(link->dhcp_server,
+                                              &main_address->in_addr.in);
+                if (r < 0)
+                        return r;
+
+                r = sd_dhcp_server_set_prefixlen(link->dhcp_server,
+                                                 main_address->prefixlen);
+                if (r < 0)
+                        return r;
+                */
+
+                r = sd_dhcp_server_start(link->dhcp_server);
+                if (r < 0) {
+                        log_link_warning(link, "could not start DHCPv4 server "
+                                         "instance: %s", strerror(-r));
+
+                        link_enter_failed(link);
+
+                        return 0;
+                }
+
+                log_link_debug(link, "offering DHCPv4 leases");
+        }
+
         if (link->link_messages == 0) {
                 link_enter_set_routes(link);
         } else
         if (link->link_messages == 0) {
                 link_enter_set_routes(link);
         } else