]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: start ipv4ll when dhcp has trouble getting a lease
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 8 Oct 2020 18:14:51 +0000 (20:14 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 30 Nov 2020 03:37:36 +0000 (12:37 +0900)
Fixes #13316.

man/systemd.network.xml
src/network/networkd-dhcp4.c
src/network/networkd-link.c
test/test-network/conf/dhcp-client-vrf.network
test/test-network/systemd-networkd-tests.py

index 3b029dca63cc1ac62e023eae323d394e47a67242..27263c34ebb6fcba460e4904fb47cdad550c9efc 100644 (file)
             <para>Enables link-local address autoconfiguration. Accepts <option>yes</option>,
             <option>no</option>, <option>ipv4</option>, and <option>ipv6</option>. An IPv6 link-local address
             is configured when <option>yes</option> or <option>ipv6</option>. An IPv4 link-local address is
-            configured when <option>yes</option> or <option>ipv4</option>.</para>
+            configured when <option>yes</option> or <option>ipv4</option> and when DHCPv4 autoconfiguration
+            has been unsuccessful for some time. (IPv4 link-local address autoconfiguration will usually
+            happen in parallel with repeated attempts to acquire a DHCPv4 lease).</para>
 
             <para>Defaults to <option>no</option> when <varname>Bridge=yes</varname> is set, and
             <option>ipv6</option> otherwise.</para>
@@ -1662,7 +1664,8 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
             <para>Specifies how many times the DHCPv4 client configuration should be attempted. Takes a
             number or <literal>infinity</literal>. Defaults to <literal>infinity</literal>. Note that the
             time between retries is increased exponentially, up to approximately one per minute, so the
-            network will not be overloaded even if this number is high.</para>
+            network will not be overloaded even if this number is high. The default is suitable in most
+            circumstances.</para>
           </listitem>
         </varlistentry>
 
index 8a2292b1a60909efdb4a376d58ddb0b094eb6060..78af53c38188fdfbe40d25ea7fb9cd22775e86f0 100644 (file)
@@ -1135,6 +1135,21 @@ static int dhcp4_handler(sd_dhcp_client *client, int event, void *userdata) {
                                         return -ENOMSG;
                         }
                         break;
+
+                case SD_DHCP_CLIENT_EVENT_TRANSIENT_FAILURE:
+                        if (link_ipv4ll_enabled(link)) {
+                                assert(link->ipv4ll);
+
+                                if (!sd_ipv4ll_is_running(link->ipv4ll)) {
+                                        log_link_debug(link, "Problems acquiring DHCP lease, acquiring IPv4 link-local address");
+
+                                        r = sd_ipv4ll_start(link->ipv4ll);
+                                        if (r < 0)
+                                                return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
+                                }
+                        }
+                        break;
+
                 default:
                         if (event < 0)
                                 log_link_warning_errno(link, event, "DHCP error: Client failed: %m");
index baaf0b8812433154d1260bf7cd2721e757e68631..07547d032b552e8553d3ed389c4609c8657f68a2 100644 (file)
@@ -1229,7 +1229,14 @@ static int link_acquire_ipv4_conf(Link *link) {
         assert(link->manager);
         assert(link->manager->event);
 
-        if (link_ipv4ll_enabled(link)) {
+        if (link->dhcp_client) {
+                log_link_debug(link, "Acquiring DHCPv4 lease");
+
+                r = sd_dhcp_client_start(link->dhcp_client);
+                if (r < 0)
+                        return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m");
+
+        } else if (link_ipv4ll_enabled(link)) {
                 assert(link->ipv4ll);
 
                 log_link_debug(link, "Acquiring IPv4 link-local address");
@@ -1239,14 +1246,6 @@ static int link_acquire_ipv4_conf(Link *link) {
                         return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m");
         }
 
-        if (link->dhcp_client) {
-                log_link_debug(link, "Acquiring DHCPv4 lease");
-
-                r = sd_dhcp_client_start(link->dhcp_client);
-                if (r < 0)
-                        return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m");
-        }
-
         return 0;
 }
 
index bb1d2e09c5e148e8545659119a90781b89e7c630..a277d5ecbf15be8c412b11d91d6ae2106f49b895 100644 (file)
@@ -4,5 +4,4 @@ Name=veth99
 [Network]
 DHCP=yes
 IPv6AcceptRA=yes
-LinkLocalAddressing=yes
 VRF=vrf99
index 1262611d2874987c7bdaf66b59cc75b604407b06..2c2ffcb9d0a74ab935d9cc390a7d690b4f4934d9 100755 (executable)
@@ -3925,7 +3925,6 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print('## ip address show vrf vrf99')
         output = check_output('ip address show vrf vrf99')
         print(output)
-        self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
         self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
         self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)')
         self.assertRegex(output, 'inet6 .* scope link')
@@ -3933,7 +3932,6 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print('## ip address show dev veth99')
         output = check_output('ip address show dev veth99')
         print(output)
-        self.assertRegex(output, 'inet 169.254.[0-9]*.[0-9]*/16 brd 169.254.255.255 scope link veth99')
         self.assertRegex(output, 'inet 192.168.5.[0-9]*/24 brd 192.168.5.255 scope global dynamic veth99')
         self.assertRegex(output, 'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)')
         self.assertRegex(output, 'inet6 .* scope link')
@@ -3942,7 +3940,6 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         output = check_output('ip route show vrf vrf99')
         print(output)
         self.assertRegex(output, 'default via 192.168.5.1 dev veth99 proto dhcp src 192.168.5.')
-        self.assertRegex(output, '169.254.0.0/16 dev veth99 proto kernel scope link src 169.254')
         self.assertRegex(output, '192.168.5.0/24 dev veth99 proto kernel scope link src 192.168.5')
         self.assertRegex(output, '192.168.5.0/24 via 192.168.5.5 dev veth99 proto dhcp')
         self.assertRegex(output, '192.168.5.1 dev veth99 proto dhcp scope link src 192.168.5')