Blame 0031-network-fix-ifup-and-netroot-calling.patch

Harald Hoyer 2f4f1d
From c6c704fda61d791303ea71f49e914b260ff90dca Mon Sep 17 00:00:00 2001
Harald Hoyer 2f4f1d
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 2f4f1d
Date: Mon, 23 Apr 2012 11:31:59 +0200
Harald Hoyer 2f4f1d
Subject: [PATCH] network: fix ifup and netroot calling
Harald Hoyer 2f4f1d
Harald Hoyer 2f4f1d
---
Harald Hoyer 2f4f1d
 modules.d/40network/dhclient-script.sh |   32 ++++++++--------
Harald Hoyer 2f4f1d
 modules.d/40network/ifup.sh            |   65 ++++++++++++++------------------
Harald Hoyer 2f4f1d
 modules.d/40network/net-genrules.sh    |    6 ---
Harald Hoyer 2f4f1d
 modules.d/40network/net-lib.sh         |    4 --
Harald Hoyer 2f4f1d
 modules.d/40network/netroot.sh         |   27 ++-----------
Harald Hoyer 0c26bf
 5 Dateien geändert, 48 Zeilen hinzugefügt(+), 86 Zeilen entfernt(-)
Harald Hoyer 2f4f1d
Harald Hoyer 2f4f1d
diff --git a/modules.d/40network/dhclient-script.sh b/modules.d/40network/dhclient-script.sh
Harald Hoyer 2f4f1d
index 52e4900..dd893c1 100755
Harald Hoyer 2f4f1d
--- a/modules.d/40network/dhclient-script.sh
Harald Hoyer 2f4f1d
+++ b/modules.d/40network/dhclient-script.sh
Harald Hoyer 2f4f1d
@@ -22,15 +22,15 @@ setup_interface() {
Harald Hoyer 2f4f1d
     # disallow MTUs from 576 and below by default, so that broken
Harald Hoyer 2f4f1d
     # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
Harald Hoyer 2f4f1d
     if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then
Harald Hoyer 2f4f1d
-        echo "if ! ip link set $netif mtu $mtu ; then"
Harald Hoyer 2f4f1d
-        echo "ip link set $netif down"
Harald Hoyer 2f4f1d
-        echo "ip link set $netif mtu $mtu"
Harald Hoyer 2f4f1d
-        echo "ip link set $netif up"
Harald Hoyer 2f4f1d
-        echo wait_for_if_up $netif
Harald Hoyer 2f4f1d
-        echo "fi"
Harald Hoyer 2f4f1d
-    fi > /tmp/net.$netif.up
Harald Hoyer 2f4f1d
+        if ! ip link set $netif mtu $mtu ; then
Harald Hoyer 2f4f1d
+            ip link set $netif down
Harald Hoyer 2f4f1d
+            ip link set $netif mtu $mtu
Harald Hoyer 2f4f1d
+            ip link set $netif up
Harald Hoyer 2f4f1d
+            wait_for_if_up $netif
Harald Hoyer 2f4f1d
+        fi
Harald Hoyer 2f4f1d
+    fi
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-    echo ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif >> /tmp/net.$netif.up
Harald Hoyer 2f4f1d
+    ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
     [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
@@ -75,14 +75,16 @@ case $reason in
Harald Hoyer 2f4f1d
             [ "${line#new_}" = "$line" ] && continue
Harald Hoyer 2f4f1d
             echo "$line"
Harald Hoyer 2f4f1d
         done >/tmp/dhclient.$netif.dhcpopts
Harald Hoyer 2f4f1d
-        echo online > /sys/class/net/$netif/uevent
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-        if [ -e /tmp/net.$netif.manualup ]; then
Harald Hoyer 2f4f1d
-            /sbin/netroot $netif -m
Harald Hoyer 2f4f1d
-            rm -f /tmp/net.$netif.manualup
Harald Hoyer 2f4f1d
-        else
Harald Hoyer 2f4f1d
-            initqueue --onetime --name netroot-$netif netroot $netif
Harald Hoyer 2f4f1d
-        fi
Harald Hoyer 2f4f1d
+        {
Harald Hoyer 2f4f1d
+            echo '. /lib/net-lib.sh'
Harald Hoyer 2f4f1d
+            echo "setup_net $netif"
Harald Hoyer 2f4f1d
+            echo "source_hook initqueue/online $netif"
Harald Hoyer 2f4f1d
+            [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
Harald Hoyer 2f4f1d
+            echo "rm -f $hookdir/initqueue/setup_net_$netif.sh"
Harald Hoyer 2f4f1d
+        } > $hookdir/initqueue/setup_net_$netif.sh
Harald Hoyer 2f4f1d
+
Harald Hoyer 2f4f1d
+        >/tmp/net.$netif.up
Harald Hoyer 2f4f1d
         ;;
Harald Hoyer 2f4f1d
     *) echo "dhcp: $reason";;
Harald Hoyer 2f4f1d
 esac
Harald Hoyer 2f4f1d
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
Harald Hoyer 2f4f1d
index 2111b41..71b869d 100755
Harald Hoyer 2f4f1d
--- a/modules.d/40network/ifup.sh
Harald Hoyer 2f4f1d
+++ b/modules.d/40network/ifup.sh
Harald Hoyer 2f4f1d
@@ -40,10 +40,6 @@ if [ -e /tmp/bridge.info ]; then
Harald Hoyer 2f4f1d
     fi
Harald Hoyer 2f4f1d
 fi
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-# bail immediately if the interface is already up
Harald Hoyer 2f4f1d
-# or we don't need the network
Harald Hoyer 2f4f1d
-[ -f "/tmp/net.$netif.up" ] && exit 0
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
 # disable manual ifup while netroot is set for simplifying our logic
Harald Hoyer 2f4f1d
 # in netroot case we prefer netroot to bringup $netif automaticlly
Harald Hoyer 2f4f1d
 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
Harald Hoyer 2f4f1d
@@ -72,13 +68,11 @@ load_ipv6() {
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 do_ipv6auto() {
Harald Hoyer 2f4f1d
     load_ipv6
Harald Hoyer 2f4f1d
-    {
Harald Hoyer 2f4f1d
-        echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
Harald Hoyer 2f4f1d
-        echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
Harald Hoyer 2f4f1d
-        echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
Harald Hoyer 2f4f1d
-        echo ip link set $netif up
Harald Hoyer 2f4f1d
-        echo wait_for_if_up $netif
Harald Hoyer 2f4f1d
-    } > /tmp/net.$netif.up
Harald Hoyer 2f4f1d
+    echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
Harald Hoyer 2f4f1d
+    echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
Harald Hoyer 2f4f1d
+    echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
Harald Hoyer 2f4f1d
+    ip link set $netif up
Harald Hoyer 2f4f1d
+    wait_for_if_up $netif
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
     [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
@@ -88,30 +82,20 @@ do_ipv6auto() {
Harald Hoyer 2f4f1d
             echo nameserver $s
Harald Hoyer 2f4f1d
         done
Harald Hoyer 2f4f1d
     fi >> /tmp/net.$netif.resolv.conf
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
-    echo online > /sys/class/net/$netif/uevent
Harald Hoyer 2f4f1d
-    if [ -n "$manualup" ]; then
Harald Hoyer 2f4f1d
-        /sbin/netroot $netif -m
Harald Hoyer 2f4f1d
-    else
Harald Hoyer 2f4f1d
-        initqueue --onetime --name netroot-$netif netroot $netif
Harald Hoyer 2f4f1d
-    fi
Harald Hoyer 2f4f1d
 }
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 # Handle static ip configuration
Harald Hoyer 2f4f1d
 do_static() {
Harald Hoyer 2f4f1d
     strstr $ip '*:*:*' && load_ipv6
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-    {
Harald Hoyer 2f4f1d
-        echo ip link set $netif up
Harald Hoyer 2f4f1d
-        echo wait_for_if_up $netif
Harald Hoyer 2f4f1d
-        [ -n "$macaddr" ] && echo ip link set address $macaddr
Harald Hoyer 2f4f1d
-        [ -n "$mtu" ] && echo ip link set mtu $mtu
Harald Hoyer 2f4f1d
-        # do not flush addr for ipv6
Harald Hoyer 2f4f1d
-        strstr $ip '*:*:*' || \
Harald Hoyer 2f4f1d
-            echo ip addr flush dev $netif
Harald Hoyer 2f4f1d
-        echo ip addr add $ip/$mask brd + dev $netif
Harald Hoyer 2f4f1d
-    } > /tmp/net.$netif.up
Harald Hoyer 2f4f1d
+    ip link set $netif up
Harald Hoyer 2f4f1d
+    wait_for_if_up $netif
Harald Hoyer 2f4f1d
+    [ -n "$macaddr" ] && ip link set address $macaddr
Harald Hoyer 2f4f1d
+    [ -n "$mtu" ] && ip link set mtu $mtu
Harald Hoyer 2f4f1d
+    # do not flush addr for ipv6
Harald Hoyer 2f4f1d
+    strstr $ip '*:*:*' || \
Harald Hoyer 2f4f1d
+        ip addr flush dev $netif
Harald Hoyer 2f4f1d
+    ip addr add $ip/$mask brd + dev $netif
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
     [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
Harald Hoyer 2f4f1d
     [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
Harald Hoyer 2f4f1d
@@ -122,20 +106,12 @@ do_static() {
Harald Hoyer 2f4f1d
             echo nameserver $s
Harald Hoyer 2f4f1d
         done
Harald Hoyer 2f4f1d
     fi >> /tmp/net.$netif.resolv.conf
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
-    echo online > /sys/class/net/$netif/uevent
Harald Hoyer 2f4f1d
-    if [ -n "$manualup" ]; then
Harald Hoyer 2f4f1d
-        /sbin/netroot $netif -m
Harald Hoyer 2f4f1d
-    else
Harald Hoyer 2f4f1d
-        initqueue --onetime --name netroot-$netif netroot $netif
Harald Hoyer 2f4f1d
-    fi
Harald Hoyer 2f4f1d
 }
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 # loopback is always handled the same way
Harald Hoyer 2f4f1d
 if [ "$netif" = "lo" ] ; then
Harald Hoyer 2f4f1d
     ip link set lo up
Harald Hoyer 2f4f1d
     ip addr add 127.0.0.1/8 dev lo
Harald Hoyer 2f4f1d
-    >/tmp/net.$netif.up
Harald Hoyer 2f4f1d
     exit 0
Harald Hoyer 2f4f1d
 fi
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
@@ -238,6 +214,21 @@ for p in $(getargs ip=); do
Harald Hoyer 2f4f1d
         *)
Harald Hoyer 2f4f1d
             do_static ;;
Harald Hoyer 2f4f1d
     esac
Harald Hoyer 2f4f1d
+
Harald Hoyer 2f4f1d
+    case $autoconf in
Harald Hoyer 2f4f1d
+        dhcp|on|any|dhcp6)
Harald Hoyer 2f4f1d
+            ;;
Harald Hoyer 2f4f1d
+        *)
Harald Hoyer 2f4f1d
+            if [ $? -eq 0 ]; then
Harald Hoyer 2f4f1d
+                setup_net $netif
Harald Hoyer 2f4f1d
+                source_hook initqueue/online $netif
Harald Hoyer 2f4f1d
+                if [ -z "$manualup" ]; then
Harald Hoyer 2f4f1d
+                    /sbin/netroot $netif
Harald Hoyer 2f4f1d
+                fi
Harald Hoyer 2f4f1d
+            fi
Harald Hoyer 2f4f1d
+            ;;
Harald Hoyer 2f4f1d
+    esac
Harald Hoyer 2f4f1d
+
Harald Hoyer 2f4f1d
     break
Harald Hoyer 2f4f1d
 done
Harald Hoyer 2f4f1d
 exit 0
Harald Hoyer 2f4f1d
diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh
Harald Hoyer 2f4f1d
index b3d5584..7176681 100755
Harald Hoyer 2f4f1d
--- a/modules.d/40network/net-genrules.sh
Harald Hoyer 2f4f1d
+++ b/modules.d/40network/net-genrules.sh
Harald Hoyer 2f4f1d
@@ -51,10 +51,4 @@ fix_bootif() {
Harald Hoyer 2f4f1d
         printf 'SUBSYSTEM=="net", RUN+="%s"\n' "/sbin/initqueue --onetime $ifup"
Harald Hoyer 2f4f1d
     fi
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-    # Run the "online" hook
Harald Hoyer 2f4f1d
-    printf 'SUBSYSTEM=="net", ACTION=="online", RUN+="/sbin/initqueue --onetime --env netif=$env{INTERFACE} source_hook initqueue/online"\n'
Harald Hoyer 2f4f1d
-    # And make sure we run setup_net at the start of the hook
Harald Hoyer 2f4f1d
-    echo '. /lib/net-lib.sh; setup_net $netif' > \
Harald Hoyer 2f4f1d
-            $hookdir/initqueue/online/05-setup_net.sh
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
 } > /etc/udev/rules.d/60-net.rules
Harald Hoyer 2f4f1d
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
Harald Hoyer 2f4f1d
index c0f73da..d6adda9 100644
Harald Hoyer 2f4f1d
--- a/modules.d/40network/net-lib.sh
Harald Hoyer 2f4f1d
+++ b/modules.d/40network/net-lib.sh
Harald Hoyer 2f4f1d
@@ -65,13 +65,9 @@ ifdown() {
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 setup_net() {
Harald Hoyer 2f4f1d
     local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
Harald Hoyer 2f4f1d
-    [ -e /tmp/net.$netif.up ] || return 1
Harald Hoyer 2f4f1d
     [ -e /tmp/net.$netif.did-setup ] && return
Harald Hoyer 2f4f1d
     [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
Harald Hoyer 2f4f1d
     [ -z "$IFACES" ] && IFACES="$netif"
Harald Hoyer 2f4f1d
-    for iface in $IFACES ; do
Harald Hoyer 2f4f1d
-        . /tmp/net.$iface.up
Harald Hoyer 2f4f1d
-    done
Harald Hoyer 2f4f1d
     # run the scripts written by ifup
Harald Hoyer 2f4f1d
     [ -e /tmp/net.$netif.gw ]            && . /tmp/net.$netif.gw
Harald Hoyer 2f4f1d
     [ -e /tmp/net.$netif.hostname ]      && . /tmp/net.$netif.hostname
Harald Hoyer 2f4f1d
diff --git a/modules.d/40network/netroot.sh b/modules.d/40network/netroot.sh
Harald Hoyer 2f4f1d
index 1bb62bb..fa7e632 100755
Harald Hoyer 2f4f1d
--- a/modules.d/40network/netroot.sh
Harald Hoyer 2f4f1d
+++ b/modules.d/40network/netroot.sh
Harald Hoyer 2f4f1d
@@ -13,24 +13,13 @@ command -v setup_net >/dev/null || . /lib/net-lib.sh
Harald Hoyer 2f4f1d
 # instead of real netroot; If It's called without $2, then there's
Harald Hoyer 2f4f1d
 # no sense in doing something if no (net)root info is available
Harald Hoyer 2f4f1d
 # or root is already there
Harald Hoyer 2f4f1d
-if [ -z "$2" ]; then
Harald Hoyer 2f4f1d
-    [ -d $NEWROOT/proc ] && exit 0
Harald Hoyer 2f4f1d
-    [ -z "$netroot" ] && exit 1
Harald Hoyer 2f4f1d
-fi
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
-# Let's see if we have to wait for other interfaces
Harald Hoyer 2f4f1d
-# Note: exit works just fine, since the last interface to be
Harald Hoyer 2f4f1d
-#       online'd should see all files
Harald Hoyer 2f4f1d
-all_ifaces_up || exit 1
Harald Hoyer 2f4f1d
+[ -d $NEWROOT/proc ] && exit 0
Harald Hoyer 2f4f1d
+[ -z "$netroot" ] && exit 1
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 # Set or override primary interface
Harald Hoyer 2f4f1d
 netif=$1
Harald Hoyer 2f4f1d
 [ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-if [ -e /tmp/net.$netif.manualup ]; then
Harald Hoyer 2f4f1d
-    rm -f /tmp/net.$netif.manualup
Harald Hoyer 2f4f1d
-fi
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
 # Figure out the handler for root=dhcp by recalling all netroot cmdline
Harald Hoyer 2f4f1d
 # handlers when this is not called from manually network bringing up.
Harald Hoyer 2f4f1d
 if [ -z "$2" ]; then
Harald Hoyer 2f4f1d
@@ -72,23 +61,13 @@ if [ -z "$2" ]; then
Harald Hoyer 2f4f1d
     fi
Harald Hoyer 2f4f1d
 fi
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
-# We're here, so we can assume that upping interfaces is now ok
Harald Hoyer 2f4f1d
-setup_net $netif
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
-# exit in case manually bring up network
Harald Hoyer 2f4f1d
-[ -n "$2" ] && exit 0
Harald Hoyer 2f4f1d
-
Harald Hoyer 2f4f1d
 # Source netroot hooks before we start the handler
Harald Hoyer 2f4f1d
-source_hook netroot
Harald Hoyer 2f4f1d
+source_hook netroot $netif
Harald Hoyer 2f4f1d
 
Harald Hoyer 2f4f1d
 # Run the handler; don't store the root, it may change from device to device
Harald Hoyer 2f4f1d
 # XXX other variables to export?
Harald Hoyer 2f4f1d
 if $handler $netif $netroot $NEWROOT; then
Harald Hoyer 2f4f1d
     # Network rootfs mount successful - save interface info for ifcfg etc.
Harald Hoyer 2f4f1d
     save_netinfo $netif
Harald Hoyer 2f4f1d
-else
Harald Hoyer 2f4f1d
-    warn "Mounting root via '$netif' failed"
Harald Hoyer 2f4f1d
-    # If we're trying with multiple interfaces, put that one down.
Harald Hoyer 2f4f1d
-    [ -z "$BOOTDEV" ] && ifdown $netif
Harald Hoyer 2f4f1d
 fi
Harald Hoyer 2f4f1d
 exit 0