]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
35network-legacy: simplify fallback dhcp setup
authorThomas Blume <Thomas.Blume@suse.com>
Wed, 22 Jul 2020 07:34:42 +0000 (09:34 +0200)
committerDaniel Molkentin <daniel@molkentin.de>
Wed, 5 Aug 2020 10:32:24 +0000 (12:32 +0200)
suppress redundant calls to network setup

combine code for "no ip option directed at our interface" and
"No ip lines default to dhcp"
correct evaluation of return code for creating did-setup files
fix application of "load_ipv6" call to ipv6 setup only

Reference: bsc#1173402

modules.d/35network-legacy/ifup.sh

index c05ccc1bcd4f2dd8113ef1ae2c470819d34696eb..b1ae52ea5b260e607e943de0191940a95c5740f9 100755 (executable)
@@ -376,23 +376,6 @@ else
 fi
 
 
-# No ip lines default to dhcp
-ip=$(getarg ip)
-
-if [ -z "$NO_AUTO_DHCP" ] && [ -z "$ip" ]; then
-    if [ "$netroot" = "dhcp6" ]; then
-        do_dhcp -6
-    else
-        do_dhcp -4
-    fi
-
-    for s in $(getargs nameserver); do
-        [ -n "$s" ] || continue
-        echo nameserver $s >> /tmp/net.$netif.resolv.conf
-    done
-fi
-
-
 # Specific configuration, spin through the kernel command line
 # looking for ip= lines
 for p in $(getargs ip=); do
@@ -473,21 +456,39 @@ done
 
 # no ip option directed at our interface?
 if [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then
+    ret=1
     if [ -e /tmp/net.bootdev ]; then
         BOOTDEV=$(cat /tmp/net.bootdev)
         if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat /sys/class/net/${netif}/address)" ]; then
-            load_ipv6
             do_dhcp
+            ret=$?
         fi
     else
-        if getargs 'ip=dhcp6'; then
+        # No ip lines, no bootdev -> default to dhcp
+        ip=$(getarg ip)
+
+        if getargs 'ip=dhcp6' || [ -z "$ip" -a "$netroot" = "dhcp6" ]; then
             load_ipv6
             do_dhcp -6
+            ret=$?
         fi
-        if getargs 'ip=dhcp'; then
+        if getargs 'ip=dhcp' || [ -z "$ip" -a "$netroot" != "dhcp6" ]; then
             do_dhcp -4
+            ret=$?
         fi
     fi
+
+    for s in $(getargs nameserver); do
+        [ -n "$s" ] || continue
+        echo nameserver $s >> /tmp/net.$netif.resolv.conf
+    done
+
+    if [ "$ret" -eq 0 ] && [ -n "$(ls /tmp/leaseinfo.${netif}*)" ]; then
+         > /tmp/net.${netif}.did-setup
+         if [ -e /sys/class/net/${netif}/address ]; then
+             > /tmp/net.$(cat /sys/class/net/${netif}/address).did-setup
+         fi
+    fi
 fi
 
 exit 0