]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/35network-legacy/ifup.sh
docs: install `which` in Arch container
[thirdparty/dracut.git] / modules.d / 35network-legacy / ifup.sh
CommitLineData
0ac9584d 1#!/bin/sh
db815843
PS
2#
3# We don't need to check for ip= errors here, that is handled by the
4# cmdline parser script
5#
957bc5c9
DY
6# without $2 means this is for real netroot case
7# or it is for manually bring up network ie. for kdump scp vmcore
fb59f4c9 8PATH=/usr/sbin:/usr/bin:/sbin:/bin
db815843 9
9a52c3fd
HH
10type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
11type ip_to_var > /dev/null 2>&1 || . /lib/net-lib.sh
957bc5c9
DY
12
13# Huh? No $1?
14[ -z "$1" ] && exit 1
15
16# $netif reads easier than $1
17netif=$1
18
24a78b26 19# loopback is always handled the same way
9a52c3fd 20if [ "$netif" = "lo" ]; then
24a78b26
HH
21 ip link set lo up
22 ip addr add 127.0.0.1/8 dev lo
23 exit 0
d61a423f 24fi
7e9919b9 25
4026cd3b
AK
26do_dhcp_parallel() {
27 # dhclient-script will mark the netif up and generate the online
28 # event for nfsroot
29 # XXX add -V vendor class and option parsing per kernel
30
8c0fcdd9 31 [ -e "/tmp/dhclient.$netif.pid" ] && return 0
4026cd3b 32
8c0fcdd9 33 if ! iface_has_carrier "$netif"; then
4026cd3b
AK
34 warn "No carrier detected on interface $netif"
35 return 1
36 fi
37
8c0fcdd9
HH
38 bootintf=$(readlink "$IFNETFILE")
39 if [ -n "$bootintf" ] && [ -e "/tmp/dhclient.${bootintf}.lease" ]; then
4026cd3b 40 info "DHCP already succeeded for $bootintf, exiting for $netif"
9a52c3fd 41 return 1
4026cd3b
AK
42 fi
43
44 if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then
45 mkdir -p /run/NetworkManager/conf.d
46 echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf
9a52c3fd 47 echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf
4026cd3b
AK
48 fi
49
50 chmod +x /sbin/dhcp-multi.sh
51 /sbin/dhcp-multi.sh "$netif" "$DO_VLAN" "$@" &
52 return 0
53}
54
db815843 55# Run dhclient
7e9919b9 56do_dhcp() {
fb59f4c9 57 # dhclient-script will mark the netif up and generate the online
7e9919b9
DD
58 # event for nfsroot
59 # XXX add -V vendor class and option parsing per kernel
c84618d7 60
8c0fcdd9
HH
61 local _COUNT
62 local _timeout
63 local _DHCPRETRY
64
65 _COUNT=0
66 _timeout=$(getarg rd.net.timeout.dhcp=)
67 _DHCPRETRY=$(getargnum 1 1 1000000000 rd.net.dhcp.retry=)
2448fbf1 68
8c0fcdd9 69 [ -e "/tmp/dhclient.${netif}.pid" ] && return 0
c84618d7 70
8c0fcdd9 71 if ! iface_has_carrier "$netif"; then
2448fbf1 72 warn "No carrier detected on interface $netif"
271cd19d
HH
73 return 1
74 fi
2448fbf1 75
0454dc24
LR
76 if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then
77 mkdir -p /run/NetworkManager/conf.d
78 echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf
9a52c3fd 79 echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf
0454dc24
LR
80 fi
81
8c0fcdd9 82 while [ "$_COUNT" -lt "$_DHCPRETRY" ]; do
2448fbf1
HH
83 info "Starting dhcp for interface $netif"
84 dhclient "$@" \
8c0fcdd9 85 ${_timeout:+--timeout "$_timeout"} \
9a52c3fd
HH
86 -q \
87 -1 \
88 -cf /etc/dhclient.conf \
8c0fcdd9
HH
89 -pf "/tmp/dhclient.${netif}.pid" \
90 -lf "/tmp/dhclient.${netif}.lease" \
91 "$netif" \
2448fbf1 92 && return 0
75d758e8 93 _COUNT=$((_COUNT + 1))
8c0fcdd9 94 [ "$_COUNT" -lt "$_DHCPRETRY" ] && sleep 1
2448fbf1
HH
95 done
96 warn "dhcp for interface $netif failed"
d0de58f2
JL
97 # nuke those files since we failed; we might retry dhcp again if it's e.g.
98 # `ip=dhcp,dhcp6` and we check for the PID file at the top
8c0fcdd9 99 rm -f "/tmp/dhclient.${netif}".{pid,lease}
2448fbf1 100 return 1
c98bcec8
HH
101}
102
103load_ipv6() {
28f3f537 104 [ -d /proc/sys/net/ipv6 ] && return
c98bcec8
HH
105 modprobe ipv6
106 i=0
107 while [ ! -d /proc/sys/net/ipv6 ]; do
75d758e8 108 i=$((i + 1))
cc02093d
HH
109 [ $i -gt 10 ] && break
110 sleep 0.1
c98bcec8
HH
111 done
112}
113
114do_ipv6auto() {
67354eeb 115 local ret
c98bcec8 116 load_ipv6
8c0fcdd9
HH
117 echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding
118 echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra
119 echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects
120 linkup "$netif"
121 wait_for_ipv6_auto "$netif"
67354eeb 122 ret=$?
c98bcec8 123
8c0fcdd9 124 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > "/tmp/net.${netif}.hostname"
8bf25df6 125
8c0fcdd9 126 return "$ret"
db815843
PS
127}
128
b12f8188
JJ
129do_ipv6link() {
130 local ret
131 load_ipv6
8c0fcdd9
HH
132 echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding
133 echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra
134 echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects
135 linkup "$netif"
b12f8188 136
8c0fcdd9 137 [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > "/tmp/net.${netif}.hostname"
b12f8188 138
8c0fcdd9 139 return "$ret"
b12f8188
JJ
140}
141
db815843
PS
142# Handle static ip configuration
143do_static() {
8c0fcdd9 144 strglobin "$ip" '*:*:*' && load_ipv6
c98bcec8 145
c574c3f5 146 if ! iface_has_carrier "$netif"; then
df95b100
HH
147 warn "No carrier detected on interface $netif"
148 return 1
149 elif ! linkup "$netif"; then
b519ae70 150 warn "Could not bring interface $netif up!"
5193198d
HH
151 return 1
152 fi
153
9a52c3fd 154 ip route get "$ip" 2> /dev/null | {
8c0fcdd9 155 read -r a rest
27a5aecf
HH
156 if [ "$a" = "local" ]; then
157 warn "Not assigning $ip to interface $netif, cause it is already assigned!"
158 return 1
159 fi
160 return 0
161 } || return 1
162
8c0fcdd9
HH
163 [ -n "$macaddr" ] && ip link set address "$macaddr" dev "$netif"
164 [ -n "$mtu" ] && ip link set mtu "$mtu" dev "$netif"
165 if strglobin "$ip" '*:*:*'; then
50b08e7b 166 # note no ip addr flush for ipv6
8c0fcdd9
HH
167 ip addr add "$ip/$mask" ${srv:+peer "$srv"} dev "$netif"
168 echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding
169 echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra
170 echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects
171 wait_for_ipv6_dad "$netif"
50b08e7b 172 else
5abd692f 173 if [ -z "$srv" ]; then
9a52c3fd 174 if command -v arping2 > /dev/null; then
8c0fcdd9 175 if arping2 -q -C 1 -c 2 -I "$netif" -0 "$ip"; then
5abd692f
HH
176 warn "Duplicate address detected for $ip for interface $netif."
177 return 1
178 fi
179 else
8c0fcdd9 180 if ! arping -f -q -D -c 2 -I "$netif" "$ip"; then
5abd692f
HH
181 warn "Duplicate address detected for $ip for interface $netif."
182 return 1
183 fi
9853791d 184 fi
9ab5ddf1 185 fi
8c0fcdd9
HH
186 ip addr flush dev "$netif"
187 ip addr add "$ip/$mask" ${srv:+peer "$srv"} brd + dev "$netif"
50b08e7b 188 fi
db815843 189
8c0fcdd9
HH
190 [ -n "$gw" ] && echo "ip route replace default via '$gw' dev '$netif'" > "/tmp/net.$netif.gw"
191 [ -n "$hostname" ] && echo "echo '$hostname' > /proc/sys/kernel/hostname" > "/tmp/net.$netif.hostname"
8bf25df6
WC
192
193 return 0
957bc5c9 194}
580bb541 195
24a78b26
HH
196get_vid() {
197 case "$1" in
9a52c3fd 198 vlan*)
8c0fcdd9 199 echo "${1#vlan}"
9a52c3fd
HH
200 ;;
201 *.*)
8c0fcdd9 202 echo "${1##*.}"
9a52c3fd 203 ;;
24a78b26
HH
204 esac
205}
206
207# check, if we need VLAN's for this interface
8c0fcdd9 208if [ -z "$DO_VLAN_PHY" ] && [ -e "/tmp/vlan.${netif}.phy" ]; then
e7838a83 209 unset DO_VLAN
24a78b26
HH
210 NO_AUTO_DHCP=yes DO_VLAN_PHY=yes ifup "$netif"
211 modprobe -b -q 8021q
212
8c0fcdd9 213 for i in /tmp/vlan.*."${netif}"; do
24a78b26 214 [ -e "$i" ] || continue
0cf826a1
HH
215 unset vlanname
216 unset phydevice
8c0fcdd9 217 # shellcheck disable=SC1090
0cf826a1 218 . "$i"
24a78b26
HH
219 if [ -n "$vlanname" ]; then
220 linkup "$phydevice"
8c0fcdd9 221 ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid "$vlanname")"
24a78b26
HH
222 ifup "$vlanname"
223 fi
224 done
580bb541
PS
225 exit 0
226fi
227
e7838a83 228# Check, if interface is VLAN interface
8c0fcdd9
HH
229if ! [ -e "/tmp/vlan.${netif}.phy" ]; then
230 for i in "/tmp/vlan.${netif}".*; do
e7838a83
HH
231 [ -e "$i" ] || continue
232 export DO_VLAN=yes
233 break
234 done
235fi
236
24a78b26
HH
237# bridge this interface?
238if [ -z "$NO_BRIDGE_MASTER" ]; then
239 for i in /tmp/bridge.*.info; do
240 [ -e "$i" ] || continue
241 unset bridgeslaves
242 unset bridgename
8c0fcdd9 243 # shellcheck disable=SC1090
24a78b26 244 . "$i"
9a52c3fd 245 for ethname in $bridgeslaves; do
24a78b26
HH
246 [ "$netif" != "$ethname" ] && continue
247
8c0fcdd9
HH
248 NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup "$ethname"
249 linkup "$ethname"
250 if [ ! -e "/tmp/bridge.$bridgename.up" ]; then
251 ip link add name "$bridgename" type bridge
252 echo 0 > "/sys/devices/virtual/net/$bridgename/bridge/forward_delay"
253 : > "/tmp/bridge.$bridgename.up"
96fb9c8d 254 fi
8c0fcdd9
HH
255 ip link set dev "$ethname" master "$bridgename"
256 ifup "$bridgename"
24a78b26 257 exit 0
96fb9c8d 258 done
24a78b26
HH
259 done
260fi
96fb9c8d 261
24a78b26
HH
262# enslave this interface to bond?
263if [ -z "$NO_BOND_MASTER" ]; then
264 for i in /tmp/bond.*.info; do
265 [ -e "$i" ] || continue
266 unset bondslaves
267 unset bondname
8c0fcdd9 268 # shellcheck disable=SC1090
24a78b26 269 . "$i"
8c0fcdd9
HH
270 for testslave in $bondslaves; do
271 [ "$netif" != "testslave" ] && continue
96fb9c8d 272
24a78b26 273 # already setup
8c0fcdd9 274 [ -e "/tmp/bond.$bondname.up" ] && exit 0
24a78b26
HH
275
276 # wait for all slaves to show up
9a52c3fd 277 for slave in $bondslaves; do
24a78b26 278 # try to create the slave (maybe vlan or bridge)
8c0fcdd9 279 NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup "$slave"
24a78b26 280
8c0fcdd9 281 if ! ip link show dev "$slave" > /dev/null 2>&1; then
24a78b26
HH
282 # wait for the last slave to show up
283 exit 0
284 fi
285 done
286
287 modprobe -q -b bonding
9a52c3fd 288 echo "+$bondname" > /sys/class/net/bonding_masters 2> /dev/null
8c0fcdd9 289 ip link set "$bondname" down
24a78b26
HH
290
291 # Stolen from ifup-eth
292 # add the bits to setup driver parameters here
9a52c3fd
HH
293 for arg in $bondoptions; do
294 key=${arg%%=*}
295 value=${arg##*=}
24a78b26
HH
296 # %{value:0:1} is replaced with non-bash specific construct
297 if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
9a52c3fd
HH
298 OLDIFS=$IFS
299 IFS=','
24a78b26 300 for arp_ip in $value; do
8c0fcdd9 301 echo "+$arp_ip" > "/sys/class/net/${bondname}/bonding/$key"
24a78b26 302 done
9a52c3fd 303 IFS=$OLDIFS
24a78b26 304 else
8c0fcdd9 305 echo "$value" > "/sys/class/net/${bondname}/bonding/$key"
24a78b26
HH
306 fi
307 done
308
8c0fcdd9 309 linkup "$bondname"
24a78b26 310
9a52c3fd 311 for slave in $bondslaves; do
8c0fcdd9
HH
312 cat "/sys/class/net/$slave/address" > "/tmp/net.${bondname}.${slave}.hwaddr"
313 ip link set "$slave" down
314 echo "+$slave" > "/sys/class/net/$bondname/bonding/slaves"
315 linkup "$slave"
24a78b26
HH
316 done
317
292548be 318 # Set mtu on bond master
8c0fcdd9 319 [ -n "$bondmtu" ] && ip link set mtu "$bondmtu" dev "$bondname"
292548be 320
24a78b26 321 # add the bits to setup the needed post enslavement parameters
9a52c3fd
HH
322 for arg in $bondoptions; do
323 key=${arg%%=*}
324 value=${arg##*=}
24a78b26 325 if [ "${key}" = "primary" ]; then
8c0fcdd9 326 echo "$value" > "/sys/class/net/${bondname}/bonding/$key"
24a78b26
HH
327 fi
328 done
329
8c0fcdd9 330 : > "/tmp/bond.$bondname.up"
24a78b26 331
8c0fcdd9 332 NO_BOND_MASTER=yes ifup "$bondname"
24a78b26 333 exit $?
96fb9c8d 334 done
24a78b26 335 done
96fb9c8d
VB
336fi
337
24a78b26
HH
338if [ -z "$NO_TEAM_MASTER" ]; then
339 for i in /tmp/team.*.info; do
340 [ -e "$i" ] || continue
341 unset teammaster
342 unset teamslaves
8c0fcdd9 343 # shellcheck disable=SC1090
24a78b26 344 . "$i"
8c0fcdd9
HH
345 for testslave in $teamslaves; do
346 [ "$netif" != "$testslave" ] && continue
96fb9c8d 347
8c0fcdd9 348 [ -e "/tmp/team.$teammaster.up" ] && exit 0
7e9919b9 349
24a78b26 350 # wait for all slaves to show up
9a52c3fd 351 for slave in $teamslaves; do
24a78b26 352 # try to create the slave (maybe vlan or bridge)
8c0fcdd9 353 NO_TEAM_MASTER=yes NO_AUTO_DHCP=yes ifup "$slave"
24a78b26 354
8c0fcdd9 355 if ! ip link show dev "$slave" > /dev/null 2>&1; then
24a78b26
HH
356 # wait for the last slave to show up
357 exit 0
358 fi
359 done
360
8c0fcdd9 361 if [ ! -e "/tmp/team.$teammaster.up" ]; then
24a78b26
HH
362 # We shall only bring up those _can_ come up
363 # in case of some slave is gone in active-backup mode
364 working_slaves=""
9a52c3fd 365 for slave in $teamslaves; do
8c0fcdd9 366 teamdctl "${teammaster}" port present "${slave}" 2> /dev/null \
041e49ee 367 && continue
8c0fcdd9
HH
368 ip link set dev "$slave" up 2> /dev/null
369 if wait_for_if_up "$slave"; then
bcabe0fe 370 working_slaves="$working_slaves$slave "
24a78b26
HH
371 fi
372 done
373 # Do not add slaves now
8c0fcdd9 374 teamd -d -U -n -N -t "$teammaster" -f "/etc/teamd/${teammaster}.conf"
24a78b26
HH
375 for slave in $working_slaves; do
376 # team requires the slaves to be down before joining team
8c0fcdd9 377 ip link set dev "$slave" down
041e49ee
HH
378 (
379 unset TEAM_PORT_CONFIG
8c0fcdd9 380 _hwaddr=$(cat "/sys/class/net/$slave/address")
041e49ee
HH
381 _subchannels=$(iface_get_subchannels "$slave")
382 if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
8c0fcdd9 383 # shellcheck disable=SC1090
041e49ee
HH
384 . "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf"
385 elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then
8c0fcdd9 386 # shellcheck disable=SC1090
041e49ee
HH
387 . "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf"
388 elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then
8c0fcdd9 389 # shellcheck disable=SC1090
041e49ee
HH
390 . "/etc/sysconfig/network-scripts/ifcfg-${slave}"
391 fi
392
393 if [ -n "${TEAM_PORT_CONFIG}" ]; then
8c0fcdd9 394 /usr/bin/teamdctl "${teammaster}" port config update "${slave}" "${TEAM_PORT_CONFIG}"
041e49ee
HH
395 fi
396 )
8c0fcdd9 397 teamdctl "$teammaster" port add "$slave"
24a78b26
HH
398 done
399
8c0fcdd9 400 ip link set dev "$teammaster" up
24a78b26 401
8c0fcdd9
HH
402 : > "/tmp/team.$teammaster.up"
403 NO_TEAM_MASTER=yes ifup "$teammaster"
24a78b26 404 exit $?
21928b97 405 fi
21928b97 406 done
24a78b26 407 done
beb097d9
WT
408fi
409
24a78b26 410# all synthetic interfaces done.. now check if the interface is available
8c0fcdd9 411if ! ip link show dev "$netif" > /dev/null 2>&1; then
24a78b26
HH
412 exit 1
413fi
8eb81d48 414
24a78b26
HH
415# disable manual ifup while netroot is set for simplifying our logic
416# in netroot case we prefer netroot to bringup $netif automaticlly
417[ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
418
419if [ -n "$manualup" ]; then
8c0fcdd9
HH
420 : > "/tmp/net.$netif.manualup"
421 rm -f "/tmp/net.${netif}.did-setup"
24a78b26 422else
8c0fcdd9 423 [ -e "/tmp/net.${netif}.did-setup" ] && exit 0
9a52c3fd 424 [ -z "$DO_VLAN" ] \
8c0fcdd9
HH
425 && [ -e "/sys/class/net/$netif/address" ] \
426 && [ -e "/tmp/net.$(cat "/sys/class/net/$netif/address").did-setup" ] && exit 0
8eb81d48
AW
427fi
428
580bb541
PS
429# Specific configuration, spin through the kernel command line
430# looking for ip= lines
3e6d2b31 431for p in $(getargs ip=); do
8c0fcdd9 432 ip_to_var "$p"
38ba0d7a
HH
433 # skip ibft
434 [ "$autoconf" = "ibft" ] && continue
990e945f 435
c5f8b69a 436 case "$dev" in
9a52c3fd 437 ??:??:??:??:??:??) # MAC address
8c0fcdd9 438 _dev=$(iface_for_mac "$dev")
c5f8b69a
HH
439 [ -n "$_dev" ] && dev="$_dev"
440 ;;
9a52c3fd 441 ??-??-??-??-??-??) # MAC address in BOOTIF form
8c0fcdd9 442 _dev=$(iface_for_mac "$(fix_bootif "$dev")")
c5f8b69a
HH
443 [ -n "$_dev" ] && dev="$_dev"
444 ;;
445 esac
446
580bb541 447 # If this option isn't directed at our interface, skip it
f6e3b59e
HH
448 if [ -n "$dev" ]; then
449 [ "$dev" != "$netif" ] && continue
450 else
451 iface_is_enslaved "$netif" && continue
452 fi
580bb541 453
73fb5e76
LN
454 # Store config for later use
455 for i in ip srv gw mask hostname macaddr mtu dns1 dns2; do
456 eval '[ "$'$i'" ] && echo '$i'="$'$i'"'
8c0fcdd9 457 done > "/tmp/net.$netif.override"
73fb5e76 458
93342718
HH
459 for autoopt in $(str_replace "$autoconf" "," " "); do
460 case $autoopt in
9a52c3fd
HH
461 dhcp | on | any)
462 do_dhcp -4
463 ;;
4026cd3b
AK
464 single-dhcp)
465 do_dhcp_parallel -4
9a52c3fd
HH
466 exit 0
467 ;;
93342718
HH
468 dhcp6)
469 load_ipv6
9a52c3fd
HH
470 do_dhcp -6
471 ;;
93342718 472 auto6)
9a52c3fd
HH
473 do_ipv6auto
474 ;;
67354eeb 475 either6)
9a52c3fd
HH
476 do_ipv6auto || do_dhcp -6
477 ;;
b12f8188 478 link6)
9a52c3fd
HH
479 do_ipv6link
480 ;;
93342718 481 *)
9a52c3fd
HH
482 do_static
483 ;;
93342718
HH
484 esac
485 done
744c6593 486 ret=$?
c6c704fd 487
cf376023
XP
488 # setup nameserver
489 for s in "$dns1" "$dns2" $(getargs nameserver); do
490 [ -n "$s" ] || continue
8c0fcdd9 491 echo "nameserver $s" >> "/tmp/net.$netif.resolv.conf"
cf376023
XP
492 done
493
df95b100 494 if [ $ret -eq 0 ]; then
8c0fcdd9 495 : > "/tmp/net.${netif}.up"
43a85a73 496
8c0fcdd9
HH
497 if [ -z "$DO_VLAN" ] && [ -e "/sys/class/net/${netif}/address" ]; then
498 : > "/tmp/net.$(cat "/sys/class/net/${netif}/address").up"
df95b100 499 fi
26fbe97b 500
4985aa8c
JL
501 # and finally, finish interface set up if there isn't already a script
502 # to do so (which is the case in the dhcp path)
8c0fcdd9
HH
503 if [ ! -e "$hookdir/initqueue/setup_net_$netif.sh" ]; then
504 setup_net "$netif"
505 source_hook initqueue/online "$netif"
4985aa8c 506 if [ -z "$manualup" ]; then
8c0fcdd9 507 /sbin/netroot "$netif"
4985aa8c
JL
508 fi
509 fi
8c6ab479 510
9a52c3fd 511 if command -v wicked > /dev/null && [ -z "$manualup" ]; then
8c0fcdd9 512 /sbin/netroot "$netif"
8c6ab479
TB
513 fi
514
df95b100
HH
515 exit $ret
516 fi
db815843 517done
debf483d
HH
518
519# no ip option directed at our interface?
8c0fcdd9 520if [ -z "$NO_AUTO_DHCP" ] && [ ! -e "/tmp/net.${netif}.up" ]; then
3f5bf54f 521 ret=1
6cfdb5aa
HH
522 if [ -e /tmp/net.bootdev ]; then
523 BOOTDEV=$(cat /tmp/net.bootdev)
8c0fcdd9 524 if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat "/sys/class/net/${netif}/address")" ]; then
6cfdb5aa 525 do_dhcp
3f5bf54f 526 ret=$?
6cfdb5aa
HH
527 fi
528 else
3f5bf54f
TB
529 # No ip lines, no bootdev -> default to dhcp
530 ip=$(getarg ip)
531
9a52c3fd 532 if getargs 'ip=dhcp6' > /dev/null || [ -z "$ip" -a "$netroot" = "dhcp6" ]; then
6cfdb5aa
HH
533 load_ipv6
534 do_dhcp -6
3f5bf54f 535 ret=$?
6cfdb5aa 536 fi
9a52c3fd 537 if getargs 'ip=dhcp' > /dev/null || [ -z "$ip" -a "$netroot" != "dhcp6" ]; then
6cfdb5aa 538 do_dhcp -4
3f5bf54f 539 ret=$?
6cfdb5aa 540 fi
2c7f7a33 541 fi
3f5bf54f
TB
542
543 for s in $(getargs nameserver); do
544 [ -n "$s" ] || continue
8c0fcdd9 545 echo "nameserver $s" >> "/tmp/net.$netif.resolv.conf"
3f5bf54f
TB
546 done
547
8c0fcdd9
HH
548 if [ "$ret" -eq 0 ] && [ -n "$(ls "/tmp/leaseinfo.${netif}"* 2> /dev/null)" ]; then
549 : > "/tmp/net.${netif}.did-setup"
550 if [ -e "/sys/class/net/${netif}/address" ]; then
551 : > "/tmp/net.$(cat "/sys/class/net/${netif}/address").did-setup"
9a52c3fd 552 fi
3f5bf54f 553 fi
debf483d
HH
554fi
555
7e9919b9 556exit 0