]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
dhclient: wait to start dhcp if carrier is down
authorAndy Roulin <aroulin@nvidia.com>
Tue, 1 Dec 2020 20:45:22 +0000 (20:45 +0000)
committerJulien Fortin <julien@cumulusnetworks.com>
Mon, 25 Jan 2021 18:20:28 +0000 (19:20 +0100)
This prevents DHCP requests failures taking time during
boot if the interface isn't up yet. If the interface is
down, dhclient will fail to send packets.

At boot-time, enslaving an interface to vrf flaps it. By
waiting for the interface to come back up before starting
dhclient reduces time to boot.

Reviewed-by: CCR-10987
Closes: CM-32460
Co-developed-by: Nilesh Shinde <nilesh@nvidia.com>
Signed-off-by: Andy Roulin <aroulin@nvidia.com>
ifupdown2/ifupdownaddons/dhclient.py

index cf03f9a1c53173420ef9819fb97e1f1751a911a9..ef849d6b21a11c6c76357ff516a8698d25a69caf 100644 (file)
@@ -66,6 +66,16 @@ class dhclient(utilsBase):
         self._run_dhclient_cmd(cmd, cmd_prefix)
 
     def start(self, ifacename, wait=True, cmd_prefix=None):
+        retries = 0
+        out = "0"
+
+        # wait if interface isn't up yet
+        while '1' not in out and retries < 5:
+            path = 'sys/class/net/%s/carrier' %ifacename
+            out = self.read_file_oneline(path)
+            retries += 1
+            time.sleep(1)
+
         if os.path.exists('/sbin/dhclient3'):
             cmd = ['/sbin/dhclient3', '-pf',
                    '/run/dhclient.%s.pid' %ifacename,