diff options
author | Tom Gundersen <teg@jklm.no> | 2015-01-30 19:54:01 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-01-31 15:26:08 +0100 |
commit | d4cdbea5550ae9defa1c731ffe091837d329fec7 (patch) | |
tree | 1b5eb9ec5b3f60438fb7c0e5e9e42d4a061f416d /src/network | |
parent | 79b1f37d95f08fe7620b071eec51d2810ed077c9 (diff) |
networkd: dhcp-server - start as soon as addresses have been set
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.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-link.c | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 310eb6c734..acdb486381 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -443,7 +443,7 @@ static Address* link_find_dhcp_server_address(Link *link) { 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) @@ -467,63 +467,10 @@ static Address* link_find_dhcp_server_address(Link *link) { } static int link_enter_configured(Link *link) { - int r; - 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; @@ -683,6 +630,58 @@ static int link_enter_set_addresses(Link *link) { 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 |