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