dracut/modules.d/40network/ifup

102 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
die() {
echo $netif: "$@" 1>&2
exit 1
}
do_static() {
[ -n "$ip" ] || die "static: need IP address"
[ -n "$mask" ] || {
net=${ip%%.*}
mask=255.0.0.0
[ $net -ge 128 ] && mask=255.255.0.0
[ $net -ge 192 ] && mask=255.255.255.0
}
ip addr add $ip/$mask dev $netif || die "static: setting IP $ip/$mask"
[ -n "$gw" ] && {
ip route add default via $gw dev $netif ||
die "static: setting default route via $gw"
}
ip link set $netif up
[ -e /tmp/hostname.set ] || {
[ -n "$hostname" ] && mknod /tmp/hostname.set p 2>/dev/null &&
hostname $hostname
}
[ -n "$srv" ] &&
echo "new_dhcp_server_identifier=$srv" > /tmp/dhclient.$netif.dhcpopts
>/tmp/net.$netif.up
echo online > /sys/class/net/$netif/uevent
}
do_dhcp() {
# /sbin/dhclient-script will mark the netif up and generate the online
# event for nfsroot
# XXX add -V vendor class and option parsing per kernel
dhclient -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif
}
PATH=$PATH:/sbin:/usr/sbin
. /lib/dracut-lib
if getarg rdnetdebug ; then
exec >/tmp/ifup.$1.$$.out
exec 2>>/tmp/ifup.$1.$$.out
set -x
fi
# Huh? No $1?
[ -z "$1" ] && exit 1
# $netif reads easier than $1
netif=$1
# 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
[ -z "$netroot" ] && exit 0
# 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
# XXX need error handling like dhclient-script
# No ip lines default to dhcp
ip=$(getarg ip)
[ -z "$ip" ] && do_dhcp;
# Specific configuration, spin through the kernel command line
# looking for ip= lines
[ "$CMDLINE" ] || read CMDLINE </proc/cmdline;
for p in $CMDLINE; do
[ -n "${p%ip=*}" ] && continue
ip_to_var ${p#ip=}
# If this option isn't directed at our interface, skip it
[ "$dev" = "$netif" ] || continue
# Store config for later use
for i in ip srv gw mask hostname; do
eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
done > /tmp/net.$netif.override
case $autoconf in
static) do_static ;;
dhcp|on|any) do_dhcp ;;
bootp|rarp|both) die "autoconfig type $autoconf is not supported" ;;
''|none|off) ;;
esac
break
done
fi
exit 0