2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # We don't need to check for ip= errors here, that is handled by the
6 # cmdline parser script
8 # without $2 means this is for real netroot case
9 # or it is for manually bring up network ie. for kdump scp vmcore
10 PATH=/usr/sbin:/usr/bin:/sbin:/bin
12 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
13 type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
18 # $netif reads easier than $1
21 # enslave this interface to bond?
22 if [ -e /tmp/bond.info ]; then
24 for slave in $bondslaves ; do
25 if [ "$netif" = "$slave" ] ; then
31 # bridge this interface?
32 if [ -e /tmp/bridge.info ]; then
34 if [ "$netif" = "$ethname" ]; then
35 if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
36 : # We need to really setup bond (recursive call)
43 # bail immediately if the interface is already up
44 # or we don't need the network
45 [ -f "/tmp/net.$netif.up" ] && exit 0
47 # disable manual ifup while netroot is set for simplifying our logic
48 # in netroot case we prefer netroot to bringup $netif automaticlly
49 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
50 [ -z "$netroot" ] && [ -z "$manualup" ] && exit 0
51 [ -n "$manualup" ] && >/tmp/net.$netif.manualup
55 # dhclient-script will mark the netif up and generate the online
57 # XXX add -V vendor class and option parsing per kernel
58 echo "Starting dhcp for interface $netif"
59 dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
66 while [ ! -d /proc/sys/net/ipv6 ]; do
68 [ $i -gt 10 ] && break
76 echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
77 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
78 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
79 echo ip link set $netif up
80 echo wait_for_if_up $netif
81 } > /tmp/net.$netif.up
83 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
85 namesrv=$(getargs nameserver)
86 if [ -n "$namesrv" ] ; then
90 fi >> /tmp/net.$netif.resolv.conf
93 echo online > /sys/class/net/$netif/uevent
94 if [ -n "$manualup" ]; then
95 /sbin/netroot $netif -m
97 initqueue --onetime --name netroot-$netif netroot $netif
101 # Handle static ip configuration
103 strstr $ip '*:*:*' && load_ipv6
106 echo ip link set $netif up
107 echo wait_for_if_up $netif
108 [ -n "$macaddr" ] && echo ip link set address $macaddr
109 [ -n "$mtu" ] && echo ip link set mtu $mtu
110 # do not flush addr for ipv6
111 strstr $ip '*:*:*' || \
112 echo ip addr flush dev $netif
113 echo ip addr add $ip/$mask brd + dev $netif
114 } > /tmp/net.$netif.up
116 [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
117 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
119 namesrv=$(getargs nameserver)
120 if [ -n "$namesrv" ] ; then
121 for s in $namesrv; do
124 fi >> /tmp/net.$netif.resolv.conf
126 echo online > /sys/class/net/$netif/uevent
127 if [ -n "$manualup" ]; then
128 /sbin/netroot $netif -m
130 initqueue --onetime --name netroot-$netif netroot $netif
134 # loopback is always handled the same way
135 if [ "$netif" = "lo" ] ; then
137 ip addr add 127.0.0.1/8 dev lo
142 # start bond if needed
143 if [ -e /tmp/bond.info ]; then
146 if [ "$netif" = "$bondname" ] && [ ! -e /tmp/net.$bondname.up ] ; then # We are master bond device
148 ip link set $netif down
150 # Stolen from ifup-eth
151 # add the bits to setup driver parameters here
152 for arg in $bondoptions ; do
155 # %{value:0:1} is replaced with non-bash specific construct
156 if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
159 for arp_ip in $value; do
160 echo +$arp_ip > /sys/class/net/${netif}/bonding/$key
164 echo $value > /sys/class/net/${netif}/bonding/$key
168 ip link set $netif up
170 for slave in $bondslaves ; do
171 ip link set $slave down
172 ifenslave $bondname $slave
173 ip link set $slave up
174 wait_for_if_up $slave
177 # add the bits to setup the needed post enslavement parameters
178 for arg in $BONDING_OPTS ; do
181 if [ "${key}" = "primary" ]; then
182 echo $value > /sys/class/net/${netif}/bonding/$key
189 # XXX need error handling like dhclient-script
191 # start bridge if necessary
192 if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
193 if [ "$ethname" = "$bondname" ] ; then
194 DO_BOND_SETUP=yes ifup $bondname
196 ip link set $ethname up
198 wait_for_if_up $ethname
199 # Create bridge and add eth to bridge
200 brctl addbr $bridgename
201 brctl setfd $bridgename 0
202 brctl addif $bridgename $ethname
205 # No ip lines default to dhcp
208 if [ -z "$ip" ]; then
209 if [ "$netroot" = "dhcp6" ]; then
216 # Specific configuration, spin through the kernel command line
217 # looking for ip= lines
218 for p in $(getargs ip=); do
221 [ "$autoconf" = "ibft" ] && continue
223 # If this option isn't directed at our interface, skip it
224 [ -n "$dev" ] && [ "$dev" != "$netif" ] && continue
226 # Store config for later use
227 for i in ip srv gw mask hostname macaddr; do
228 eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
229 done > /tmp/net.$netif.override