blob: 1f9eaddfda0e49f0f5f5a3d751930d4aa6195540 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/bash
type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh
. /run/openslx/network.conf
_logfile="/run/openslx/network.log"
# for the boot interface?
if [ ! -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; then
exit 1
fi
wait_for_iface() {
local _iface="$1"
local _timeout="${2:-50}"
while [ "$_timeout" -ne 0 ]; do
[ "$(cat /sys/class/net/${_iface}/operstate)" = "up" ] && break
(( _timeout -- ))
usleep 100000
done
[ "$_timeout" -ne 0 ]
}
# For debugging...
{
set -x
ip link set dev "$SLX_PXE_NETIF" up
if ! wait_for_iface "$SLX_PXE_NETIF" 100; then
warn "'$SLX_PXE_NETIF' still not up after 10sec ..."
# TODO handle case where we waited for 10sec and it is still not up
fi
if [ -n "$SLX_BRIDGE" ]; then
for try in 1 2 3 fail; do
(
set -e
brctl addbr "$SLX_BRIDGE"
brctl stp "$SLX_BRIDGE" 0
brctl setfd "$SLX_BRIDGE" 0.000000000001
ip link set addr "$SLX_PXE_MAC" "$SLX_BRIDGE"
brctl addif "$SLX_BRIDGE" "$SLX_PXE_NETIF"
ip link set dev "$SLX_BRIDGE" up
wait_for_iface "$SLX_BRIDGE"
)
# success?
[ "$?" -eq 0 ] && break
# nope, handle
if [ "$try" = "fail" ]; then
emergency_shell "Failed to setup main network bridge, giving up!"
fi
warn "Failed to setup main network bridge on try $try. Retrying ..."
# delete bridge, inc try and sleep 100ms before trying again
[ -e "/sys/class/net/${SLX_BRIDGE}" ] && brctl delbr "$SLX_BRIDGE"
try=$(( try + 1 ))
usleep 100000
done
fi
# add the IP address on the bridge/boot if
ip addr add \
"${SLX_PXE_CLIENT_IP}/$(ipcalc -s -p "$SLX_PXE_CLIENT_IP" "$SLX_PXE_NETMASK" | sed "s/.*=//")" \
broadcast "$(ipcalc -s -b "$SLX_PXE_CLIENT_IP" "$SLX_PXE_NETMASK" | sed "s/.*=//")" \
dev "${SLX_BRIDGE:-${SLX_PXE_NETIF}}"
if [ "$USE_DHCP_UUID" = "yes" ] && [ -s "/run/system-uuid" ]; then
UUID="$(cat /run/system-uuid)"
fi
# udhcpc
for i in 1 1 1 fail; do
[ "$i" = "fail" ] && emergency_shell "DHCP failed 3 times... cannot continue."
udhcpc -t 4 -T 3 -f -n -q \
-i "${SLX_BRIDGE:-${SLX_PXE_NETIF}}" \
"${SLX_PXE_CLIENT_IP:+-r $SLX_PXE_CLIENT_IP}" \
"${UUID:+-x 0x3d:$UUID}" \
-O ntpsrv -O domain -O wpad -O search -O nisdomain \
-s "/usr/local/bin/udhcpc-trigger"
# success?
[ "$?" -eq 0 ] && break
# nope, keep trying...
warn "DHCP failed, retrying in 1sec..."
sleep $i
done
set +x
} &>> "${_logfile}.$$"
|