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 for ethname in $ethnames ; do
35 if [ "$netif" = "$ethname" ]; then
36 if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
37 : # We need to really setup bond (recursive call)
45 if [ -e /tmp/vlan.info ]; then
47 if [ "$netif" = "$phydevice" ]; then
48 if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
49 : # We need to really setup bond (recursive call)
56 # disable manual ifup while netroot is set for simplifying our logic
57 # in netroot case we prefer netroot to bringup $netif automaticlly
58 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
59 [ -z "$netroot" ] && [ -z "$manualup" ] && exit 0
60 [ -n "$manualup" ] && >/tmp/net.$netif.manualup
64 # dhclient-script will mark the netif up and generate the online
66 # XXX add -V vendor class and option parsing per kernel
67 echo "Starting dhcp for interface $netif"
68 dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
75 while [ ! -d /proc/sys/net/ipv6 ]; do
77 [ $i -gt 10 ] && break
84 echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
85 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
86 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
90 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
95 # Handle static ip configuration
97 strstr $ip '*:*:*' && load_ipv6
100 wait_for_if_up $netif
101 [ -n "$macaddr" ] && ip link set address $macaddr
102 [ -n "$mtu" ] && ip link set mtu $mtu
103 if strstr $ip '*:*:*'; then
104 # note no ip addr flush for ipv6
105 ip addr add $ip/$mask dev $netif
107 ip addr flush dev $netif
108 ip addr add $ip/$mask brd + dev $netif
111 [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
112 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
117 # loopback is always handled the same way
118 if [ "$netif" = "lo" ] ; then
120 ip addr add 127.0.0.1/8 dev lo
124 # start bond if needed
125 if [ -e /tmp/bond.info ]; then
128 if [ "$netif" = "$bondname" ] && [ ! -e /tmp/net.$bondname.up ] ; then # We are master bond device
130 ip link set $netif down
132 # Stolen from ifup-eth
133 # add the bits to setup driver parameters here
134 for arg in $bondoptions ; do
137 # %{value:0:1} is replaced with non-bash specific construct
138 if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
141 for arp_ip in $value; do
142 echo +$arp_ip > /sys/class/net/${netif}/bonding/$key
146 echo $value > /sys/class/net/${netif}/bonding/$key
150 ip link set $netif up
152 for slave in $bondslaves ; do
153 ip link set $slave down
154 echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
155 ip link set $slave up
156 wait_for_if_up $slave
159 # add the bits to setup the needed post enslavement parameters
160 for arg in $BONDING_OPTS ; do
163 if [ "${key}" = "primary" ]; then
164 echo $value > /sys/class/net/${netif}/bonding/$key
171 # XXX need error handling like dhclient-script
173 if [ -e /tmp/bridge.info ]; then
175 # start bridge if necessary
176 if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
177 brctl addbr $bridgename
178 brctl setfd $bridgename 0
179 for ethname in $ethnames ; do
180 if [ "$ethname" = "$bondname" ] ; then
181 DO_BOND_SETUP=yes ifup $bondname -m
183 ip link set $ethname up
185 wait_for_if_up $ethname
186 brctl addif $bridgename $ethname
202 if [ "$netif" = "$vlanname" ] && [ ! -e /tmp/net.$vlanname.up ]; then
204 if [ "$phydevice" = "$bondname" ] ; then
205 DO_BOND_SETUP=yes ifup $phydevice -m
207 ip link set "$phydevice" up
209 wait_for_if_up "$phydevice"
210 ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid $vlanname; echo $?)"
214 namesrv=$(getargs nameserver)
215 if [ -n "$namesrv" ] ; then
216 for s in $namesrv; do
219 fi >> /tmp/net.$netif.resolv.conf
221 # No ip lines default to dhcp
224 if [ -z "$ip" ]; then
225 if [ "$netroot" = "dhcp6" ]; then
232 # Specific configuration, spin through the kernel command line
233 # looking for ip= lines
234 for p in $(getargs ip=); do
237 [ "$autoconf" = "ibft" ] && continue
239 # If this option isn't directed at our interface, skip it
240 [ -n "$dev" ] && [ "$dev" != "$netif" ] && continue
242 # Store config for later use
243 for i in ip srv gw mask hostname macaddr; do
244 eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
245 done > /tmp/net.$netif.override
262 if [ $? -eq 0 ]; then
264 source_hook initqueue/online $netif
265 if [ -z "$manualup" ]; then