You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
6.7 KiB
246 lines
6.7 KiB
![]()
16 years ago
|
#!/bin/sh
|
||
![]()
15 years ago
|
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||
|
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||
![]()
16 years ago
|
#
|
||
|
# We don't need to check for ip= errors here, that is handled by the
|
||
|
# cmdline parser script
|
||
|
#
|
||
![]()
13 years ago
|
# without $2 means this is for real netroot case
|
||
|
# or it is for manually bring up network ie. for kdump scp vmcore
|
||
![]()
14 years ago
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin
|
||
![]()
16 years ago
|
|
||
![]()
14 years ago
|
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||
![]()
13 years ago
|
export PS4="ifup.$1.$$ + "
|
||
|
exec >>/run/initramfs/loginit.pipe 2>>/run/initramfs/loginit.pipe
|
||
|
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||
|
|
||
|
# Huh? No $1?
|
||
|
[ -z "$1" ] && exit 1
|
||
|
|
||
|
# $netif reads easier than $1
|
||
|
netif=$1
|
||
|
|
||
|
# enslave this interface to bond?
|
||
|
if [ -e /tmp/bond.info ]; then
|
||
|
. /tmp/bond.info
|
||
|
for slave in $bondslaves ; do
|
||
|
if [ "$netif" = "$slave" ] ; then
|
||
|
netif=$bondname
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
# bridge this interface?
|
||
|
if [ -e /tmp/bridge.info ]; then
|
||
|
. /tmp/bridge.info
|
||
|
if [ "$netif" = "$ethname" ]; then
|
||
|
if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
|
||
|
: # We need to really setup bond (recursive call)
|
||
|
else
|
||
|
netif="$bridgename"
|
||
|
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
|
||
|
[ -f "/tmp/root.info" ] || exit 0
|
||
|
. /tmp/root.info
|
||
|
|
||
|
# disable manual ifup while netroot is set for simplifying our logic
|
||
|
# in netroot case we prefer netroot to bringup $netif automaticlly
|
||
|
[ -n "$2" ] && [ -z "$netroot" ] && manualup="$2"
|
||
|
[ -z "$netroot" ] && [ -z "$manualup" ] && exit 0
|
||
|
[ -n "$manualup" ] && >/tmp/net.$netif.manualup
|
||
![]()
16 years ago
|
|
||
![]()
16 years ago
|
# Run dhclient
|
||
![]()
16 years ago
|
do_dhcp() {
|
||
![]()
14 years ago
|
# dhclient-script will mark the netif up and generate the online
|
||
![]()
16 years ago
|
# event for nfsroot
|
||
|
# XXX add -V vendor class and option parsing per kernel
|
||
![]()
15 years ago
|
echo "Starting dhcp for interface $netif"
|
||
|
dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
|
||
![]()
15 years ago
|
|| echo "dhcp failed"
|
||
![]()
15 years ago
|
}
|
||
|
|
||
|
load_ipv6() {
|
||
|
modprobe ipv6
|
||
|
i=0
|
||
|
while [ ! -d /proc/sys/net/ipv6 ]; do
|
||
![]()
15 years ago
|
i=$(($i+1))
|
||
|
[ $i -gt 10 ] && break
|
||
|
sleep 0.1
|
||
![]()
15 years ago
|
done
|
||
|
}
|
||
|
|
||
|
do_ipv6auto() {
|
||
|
load_ipv6
|
||
|
{
|
||
![]()
14 years ago
|
echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
|
||
![]()
15 years ago
|
echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
|
||
|
echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
|
||
![]()
14 years ago
|
echo ip link set $netif up
|
||
![]()
15 years ago
|
echo wait_for_if_up $netif
|
||
![]()
15 years ago
|
} > /tmp/net.$netif.up
|
||
|
|
||
|
[ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
|
||
|
|
||
|
namesrv=$(getargs nameserver)
|
||
|
if [ -n "$namesrv" ] ; then
|
||
![]()
15 years ago
|
for s in $namesrv; do
|
||
![]()
14 years ago
|
echo nameserver $s
|
||
![]()
15 years ago
|
done
|
||
![]()
15 years ago
|
fi >> /tmp/net.$netif.resolv.conf
|
||
|
|
||
|
|
||
|
echo online > /sys/class/net/$netif/uevent
|
||
![]()
13 years ago
|
if [ -n "$manualup" ]; then
|
||
|
/sbin/netroot $netif -m
|
||
|
else
|
||
|
initqueue --onetime --name netroot-$netif netroot $netif
|
||
|
fi
|
||
![]()
16 years ago
|
}
|
||
|
|
||
|
# Handle static ip configuration
|
||
|
do_static() {
|
||
![]()
15 years ago
|
strstr $ip '*:*:*' && load_ipv6
|
||
|
|
||
![]()
16 years ago
|
{
|
||
![]()
14 years ago
|
echo ip link set $netif up
|
||
![]()
15 years ago
|
echo wait_for_if_up $netif
|
||
|
# do not flush addr for ipv6
|
||
|
strstr $ip '*:*:*' || \
|
||
|
echo ip addr flush dev $netif
|
||
![]()
13 years ago
|
echo ip addr add $ip/$mask brd + dev $netif
|
||
![]()
16 years ago
|
} > /tmp/net.$netif.up
|
||
|
|
||
|
[ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
|
||
![]()
16 years ago
|
[ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
|
||
![]()
16 years ago
|
|
||
![]()
15 years ago
|
namesrv=$(getargs nameserver)
|
||
|
if [ -n "$namesrv" ] ; then
|
||
![]()
15 years ago
|
for s in $namesrv; do
|
||
![]()
14 years ago
|
echo nameserver $s
|
||
![]()
15 years ago
|
done
|
||
![]()
15 years ago
|
fi >> /tmp/net.$netif.resolv.conf
|
||
|
|
||
![]()
16 years ago
|
echo online > /sys/class/net/$netif/uevent
|
||
![]()
13 years ago
|
if [ -n "$manualup" ]; then
|
||
|
/sbin/netroot $netif -m
|
||
|
else
|
||
|
initqueue --onetime --name netroot-$netif netroot $netif
|
||
![]()
16 years ago
|
fi
|
||
![]()
13 years ago
|
}
|
||
![]()
16 years ago
|
|
||
|
# 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
|
||
|
|
||
![]()
15 years ago
|
# start bond if needed
|
||
|
if [ -e /tmp/bond.info ]; then
|
||
|
. /tmp/bond.info
|
||
|
|
||
|
if [ "$netif" = "$bondname" ] && [ ! -e /tmp/net.$bondname.up ] ; then # We are master bond device
|
||
|
modprobe bonding
|
||
|
ip link set $netif down
|
||
|
|
||
|
# Stolen from ifup-eth
|
||
|
# add the bits to setup driver parameters here
|
||
|
for arg in $bondoptions ; do
|
||
|
key=${arg%%=*};
|
||
|
value=${arg##*=};
|
||
|
# %{value:0:1} is replaced with non-bash specific construct
|
||
|
if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
|
||
|
OLDIFS=$IFS;
|
||
|
IFS=',';
|
||
|
for arp_ip in $value; do
|
||
|
echo +$arp_ip > /sys/class/net/${netif}/bonding/$key
|
||
|
done
|
||
|
IFS=$OLDIFS;
|
||
|
else
|
||
|
echo $value > /sys/class/net/${netif}/bonding/$key
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
ip link set $netif up
|
||
|
|
||
|
for slave in $bondslaves ; do
|
||
|
ip link set $slave down
|
||
|
ifenslave $bondname $slave
|
||
|
ip link set $slave up
|
||
|
wait_for_if_up $slave
|
||
|
done
|
||
|
|
||
|
# add the bits to setup the needed post enslavement parameters
|
||
|
for arg in $BONDING_OPTS ; do
|
||
|
key=${arg%%=*};
|
||
|
value=${arg##*=};
|
||
|
if [ "${key}" = "primary" ]; then
|
||
|
echo $value > /sys/class/net/${netif}/bonding/$key
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
|
||
![]()
16 years ago
|
# XXX need error handling like dhclient-script
|
||
![]()
16 years ago
|
|
||
![]()
16 years ago
|
# start bridge if necessary
|
||
|
if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
|
||
![]()
15 years ago
|
if [ "$ethname" = "$bondname" ] ; then
|
||
![]()
14 years ago
|
DO_BOND_SETUP=yes ifup $bondname
|
||
![]()
15 years ago
|
else
|
||
|
ip link set $ethname up
|
||
|
fi
|
||
![]()
16 years ago
|
wait_for_if_up $ethname
|
||
![]()
16 years ago
|
# Create bridge and add eth to bridge
|
||
|
brctl addbr $bridgename
|
||
|
brctl setfd $bridgename 0
|
||
|
brctl addif $bridgename $ethname
|
||
|
fi
|
||
|
|
||
![]()
16 years ago
|
# No ip lines default to dhcp
|
||
![]()
16 years ago
|
ip=$(getarg ip)
|
||
![]()
15 years ago
|
|
||
|
if [ -z "$ip" ]; then
|
||
|
if [ "$netroot" = "dhcp6" ]; then
|
||
![]()
15 years ago
|
do_dhcp -6
|
||
![]()
15 years ago
|
else
|
||
![]()
15 years ago
|
do_dhcp -4
|
||
![]()
15 years ago
|
fi
|
||
|
fi
|
||
![]()
16 years ago
|
|
||
|
# Specific configuration, spin through the kernel command line
|
||
|
# looking for ip= lines
|
||
![]()
16 years ago
|
for p in $(getargs ip=); do
|
||
|
ip_to_var $p
|
||
![]()
14 years ago
|
# skip ibft
|
||
|
[ "$autoconf" = "ibft" ] && continue
|
||
|
|
||
![]()
16 years ago
|
# If this option isn't directed at our interface, skip it
|
||
![]()
16 years ago
|
[ -n "$dev" ] && [ "$dev" != "$netif" ] && continue
|
||
![]()
16 years ago
|
|
||
|
# Store config for later use
|
||
|
for i in ip srv gw mask hostname; do
|
||
![]()
15 years ago
|
eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
|
||
![]()
16 years ago
|
done > /tmp/net.$netif.override
|
||
|
|
||
|
case $autoconf in
|
||
![]()
15 years ago
|
dhcp|on|any)
|
||
|
do_dhcp -4 ;;
|
||
|
dhcp6)
|
||
|
do_dhcp -6 ;;
|
||
|
auto6)
|
||
|
do_ipv6auto ;;
|
||
![]()
14 years ago
|
*)
|
||
![]()
15 years ago
|
do_static ;;
|
||
![]()
16 years ago
|
esac
|
||
|
break
|
||
|
done
|
||
![]()
16 years ago
|
exit 0
|