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
23 # enslave this interface to bond?
24 for i in /tmp/bond.*.info; do
25 [ -e "$i" ] || continue
29 for slave in $bondslaves ; do
30 if [ "$netif" = "$slave" ] ; then
37 if [ -e /tmp/team.info ]; then
39 for slave in $teamslaves ; do
40 if [ "$netif" = "$slave" ] ; then
46 if [ -e /tmp/vlan.info ]; then
48 if [ "$netif" = "$phydevice" ]; then
49 if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
50 : # We need to really setup bond (recursive call)
51 elif [ "$netif" = "$teammaster" ] && [ -n "$DO_TEAM_SETUP" ] ; then
52 : # We need to really setup team (recursive call)
60 # bridge this interface?
61 if [ -e /tmp/bridge.info ]; then
63 for ethname in $ethnames ; do
64 if [ "$netif" = "$ethname" ]; then
65 if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
66 : # We need to really setup bond (recursive call)
67 elif [ "$netif" = "$teammaster" ] && [ -n "$DO_TEAM_SETUP" ] ; then
68 : # We need to really setup team (recursive call)
69 elif [ "$netif" = "$vlanname" ] && [ -n "$DO_VLAN_SETUP" ]; then
70 : # We need to really setup vlan (recursive call)
79 # disable manual ifup while netroot is set for simplifying our logic
80 # in netroot case we prefer netroot to bringup $netif automaticlly
81 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
82 [ -z "$netroot" ] && [ -z "$manualup" ] && exit 0
83 [ -n "$manualup" ] && >/tmp/net.$netif.manualup
87 # dhclient-script will mark the netif up and generate the online
89 # XXX add -V vendor class and option parsing per kernel
90 echo "Starting dhcp for interface $netif"
91 dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
98 while [ ! -d /proc/sys/net/ipv6 ]; do
100 [ $i -gt 10 ] && break
107 echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
108 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra
109 echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
111 wait_for_ipv6_auto $netif
113 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
118 # Handle static ip configuration
120 strstr $ip '*:*:*' && load_ipv6
123 [ -n "$macaddr" ] && ip link set address $macaddr dev $netif
124 [ -n "$mtu" ] && ip link set mtu $mtu dev $netif
125 if strstr $ip '*:*:*'; then
126 # note no ip addr flush for ipv6
127 ip addr add $ip/$mask ${srv+peer $srv} dev $netif
129 ip addr flush dev $netif
130 ip addr add $ip/$mask ${srv+peer $srv} brd + dev $netif
133 [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
134 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
136 > /tmp/setup_net_${netif}.ok
140 # loopback is always handled the same way
141 if [ "$netif" = "lo" ] ; then
143 ip addr add 127.0.0.1/8 dev lo
147 # start bond if needed
148 if [ -e /tmp/bond.${netif}.info ]; then
149 . /tmp/bond.${netif}.info
151 if [ "$netif" = "$bondname" ] && [ ! -e /tmp/net.$bondname.up ] ; then # We are master bond device
153 echo "+$netif" > /sys/class/net/bonding_masters
154 ip link set $netif down
156 # Stolen from ifup-eth
157 # add the bits to setup driver parameters here
158 for arg in $bondoptions ; do
161 # %{value:0:1} is replaced with non-bash specific construct
162 if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
165 for arp_ip in $value; do
166 echo +$arp_ip > /sys/class/net/${netif}/bonding/$key
170 echo $value > /sys/class/net/${netif}/bonding/$key
176 for slave in $bondslaves ; do
177 ip link set $slave down
178 echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
182 # add the bits to setup the needed post enslavement parameters
183 for arg in $BONDING_OPTS ; do
186 if [ "${key}" = "primary" ]; then
187 echo $value > /sys/class/net/${netif}/bonding/$key
193 if [ -e /tmp/team.info ]; then
195 if [ "$netif" = "$teammaster" ] && [ ! -e /tmp/net.$teammaster.up ] ; then
196 # We shall only bring up those _can_ come up
197 # in case of some slave is gone in active-backup mode
199 for slave in $teamslaves ; do
200 ip link set $slave up 2>/dev/null
201 if wait_for_if_up $slave; then
202 working_slaves+="$slave "
205 # Do not add slaves now
206 teamd -d -U -n -t $teammaster -f /etc/teamd/$teammaster.conf
207 for slave in $working_slaves; do
208 # team requires the slaves to be down before joining team
209 ip link set $slave down
210 teamdctl $teammaster port add $slave
212 ip link set $teammaster up
216 # XXX need error handling like dhclient-script
218 if [ -e /tmp/bridge.info ]; then
220 # start bridge if necessary
221 if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
222 brctl addbr $bridgename
223 brctl setfd $bridgename 0
224 for ethname in $ethnames ; do
225 if [ "$ethname" = "$bondname" ] ; then
226 DO_BOND_SETUP=yes ifup $bondname -m
227 elif [ "$ethname" = "$teammaster" ] ; then
228 DO_TEAM_SETUP=yes ifup $teammaster -m
229 elif [ "$ethname" = "$vlanname" ]; then
230 DO_VLAN_SETUP=yes ifup $vlanname -m
234 brctl addif $bridgename $ethname
250 if [ "$netif" = "$vlanname" ] && [ ! -e /tmp/net.$vlanname.up ]; then
252 if [ "$phydevice" = "$bondname" ] ; then
253 DO_BOND_SETUP=yes ifup $phydevice -m
254 elif [ "$phydevice" = "$teammaster" ] ; then
255 DO_TEAM_SETUP=yes ifup $phydevice -m
259 ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid $vlanname)"
260 ip link set "$vlanname" up
264 namesrv=$(getargs nameserver)
265 if [ -n "$namesrv" ] ; then
266 for s in $namesrv; do
269 fi >> /tmp/net.$netif.resolv.conf
271 # No ip lines default to dhcp
274 if [ -z "$ip" ]; then
275 if [ "$netroot" = "dhcp6" ]; then
283 # Specific configuration, spin through the kernel command line
284 # looking for ip= lines
285 for p in $(getargs ip=); do
288 [ "$autoconf" = "ibft" ] && continue
291 ??:??:??:??:??:??) # MAC address
292 _dev=$(iface_for_mac $dev)
293 [ -n "$_dev" ] && dev="$_dev"
295 ??-??-??-??-??-??) # MAC address in BOOTIF form
296 _dev=$(iface_for_mac $(fix_bootif $dev))
297 [ -n "$_dev" ] && dev="$_dev"
301 # If this option isn't directed at our interface, skip it
302 [ -n "$dev" ] && [ "$dev" != "$netif" ] && \
303 [ "$use_bridge" != 'true' ] && \
304 [ "$use_vlan" != 'true' ] && continue
306 # Store config for later use
307 for i in ip srv gw mask hostname macaddr; do
308 eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
309 done > /tmp/net.$netif.override
326 if [ $? -eq 0 ]; then
328 source_hook initqueue/online $netif
329 if [ -z "$manualup" ]; then