network: fix ifup and netroot calling

master
Harald Hoyer 2012-04-23 11:31:59 +02:00
parent eef7649e71
commit c6c704fda6
5 changed files with 48 additions and 86 deletions

View File

@ -22,15 +22,15 @@ setup_interface() {
# disallow MTUs from 576 and below by default, so that broken # disallow MTUs from 576 and below by default, so that broken
# MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then
echo "if ! ip link set $netif mtu $mtu ; then" if ! ip link set $netif mtu $mtu ; then
echo "ip link set $netif down" ip link set $netif down
echo "ip link set $netif mtu $mtu" ip link set $netif mtu $mtu
echo "ip link set $netif up" ip link set $netif up
echo wait_for_if_up $netif wait_for_if_up $netif
echo "fi" fi
fi > /tmp/net.$netif.up 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 [ -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 [ "${line#new_}" = "$line" ] && continue
echo "$line" echo "$line"
done >/tmp/dhclient.$netif.dhcpopts done >/tmp/dhclient.$netif.dhcpopts
echo online > /sys/class/net/$netif/uevent


if [ -e /tmp/net.$netif.manualup ]; then {
/sbin/netroot $netif -m echo '. /lib/net-lib.sh'
rm -f /tmp/net.$netif.manualup echo "setup_net $netif"
else echo "source_hook initqueue/online $netif"
initqueue --onetime --name netroot-$netif netroot $netif [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
fi echo "rm -f $hookdir/initqueue/setup_net_$netif.sh"
} > $hookdir/initqueue/setup_net_$netif.sh

>/tmp/net.$netif.up
;; ;;
*) echo "dhcp: $reason";; *) echo "dhcp: $reason";;
esac esac

View File

@ -40,10 +40,6 @@ if [ -e /tmp/bridge.info ]; then
fi fi
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 # disable manual ifup while netroot is set for simplifying our logic
# in netroot case we prefer netroot to bringup $netif automaticlly # in netroot case we prefer netroot to bringup $netif automaticlly
[ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2" [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
@ -72,13 +68,11 @@ load_ipv6() {


do_ipv6auto() { do_ipv6auto() {
load_ipv6 load_ipv6
{ echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
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_ra echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects ip link set $netif up
echo ip link set $netif up wait_for_if_up $netif
echo wait_for_if_up $netif
} > /tmp/net.$netif.up


[ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname


@ -88,30 +82,20 @@ do_ipv6auto() {
echo nameserver $s echo nameserver $s
done done
fi >> /tmp/net.$netif.resolv.conf 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 # Handle static ip configuration
do_static() { do_static() {
strstr $ip '*:*:*' && load_ipv6 strstr $ip '*:*:*' && load_ipv6


{ ip link set $netif up
echo ip link set $netif up wait_for_if_up $netif
echo wait_for_if_up $netif [ -n "$macaddr" ] && ip link set address $macaddr
[ -n "$macaddr" ] && echo ip link set address $macaddr [ -n "$mtu" ] && ip link set mtu $mtu
[ -n "$mtu" ] && echo ip link set mtu $mtu # do not flush addr for ipv6
# do not flush addr for ipv6 strstr $ip '*:*:*' || \
strstr $ip '*:*:*' || \ ip addr flush dev $netif
echo ip addr flush dev $netif ip addr add $ip/$mask brd + dev $netif
echo ip addr add $ip/$mask brd + dev $netif
} > /tmp/net.$netif.up


[ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw [ -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 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
@ -122,20 +106,12 @@ do_static() {
echo nameserver $s echo nameserver $s
done done
fi >> /tmp/net.$netif.resolv.conf 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 # loopback is always handled the same way
if [ "$netif" = "lo" ] ; then if [ "$netif" = "lo" ] ; then
ip link set lo up ip link set lo up
ip addr add 127.0.0.1/8 dev lo ip addr add 127.0.0.1/8 dev lo
>/tmp/net.$netif.up
exit 0 exit 0
fi fi


@ -238,6 +214,21 @@ for p in $(getargs ip=); do
*) *)
do_static ;; do_static ;;
esac 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 break
done done
exit 0 exit 0

View File

@ -51,10 +51,4 @@ fix_bootif() {
printf 'SUBSYSTEM=="net", RUN+="%s"\n' "/sbin/initqueue --onetime $ifup" printf 'SUBSYSTEM=="net", RUN+="%s"\n' "/sbin/initqueue --onetime $ifup"
fi 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 } > /etc/udev/rules.d/60-net.rules

View File

@ -65,13 +65,9 @@ ifdown() {


setup_net() { setup_net() {
local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES="" 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.$netif.did-setup ] && return
[ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
[ -z "$IFACES" ] && IFACES="$netif" [ -z "$IFACES" ] && IFACES="$netif"
for iface in $IFACES ; do
. /tmp/net.$iface.up
done
# run the scripts written by ifup # run the scripts written by ifup
[ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw
[ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname

View File

@ -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 # 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 # no sense in doing something if no (net)root info is available
# or root is already there # or root is already there
if [ -z "$2" ]; then [ -d $NEWROOT/proc ] && exit 0
[ -d $NEWROOT/proc ] && exit 0 [ -z "$netroot" ] && exit 1
[ -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


# Set or override primary interface # Set or override primary interface
netif=$1 netif=$1
[ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev [ -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 # Figure out the handler for root=dhcp by recalling all netroot cmdline
# handlers when this is not called from manually network bringing up. # handlers when this is not called from manually network bringing up.
if [ -z "$2" ]; then if [ -z "$2" ]; then
@ -72,23 +61,13 @@ if [ -z "$2" ]; then
fi fi
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 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 # Run the handler; don't store the root, it may change from device to device
# XXX other variables to export? # XXX other variables to export?
if $handler $netif $netroot $NEWROOT; then if $handler $netif $netroot $NEWROOT; then
# Network rootfs mount successful - save interface info for ifcfg etc. # Network rootfs mount successful - save interface info for ifcfg etc.
save_netinfo $netif 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 fi
exit 0 exit 0