diff options
author | Jonathan Bauer | 2019-08-01 14:55:11 +0200 |
---|---|---|
committer | Jonathan Bauer | 2019-08-01 14:55:11 +0200 |
commit | e35bce0d1bdce2d53573c75f496545d601a1ac8c (patch) | |
tree | 3cbad21b2eaa29c92eeddf9955bdb1e9edf962d8 /builder/modules.d/slx-network | |
parent | [slx-network] setup network on udev settles (diff) | |
download | systemd-init-e35bce0d1bdce2d53573c75f496545d601a1ac8c.tar.gz systemd-init-e35bce0d1bdce2d53573c75f496545d601a1ac8c.tar.xz systemd-init-e35bce0d1bdce2d53573c75f496545d601a1ac8c.zip |
[slx-network] do not bridge additional nic
+ bug fixes
Diffstat (limited to 'builder/modules.d/slx-network')
-rw-r--r-- | builder/modules.d/slx-network/hooks/copy-network-config.sh (renamed from builder/modules.d/slx-network/copy-network-config.sh) | 0 | ||||
-rw-r--r-- | builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh (renamed from builder/modules.d/slx-network/parse-ipxe-network-kcl.sh) | 2 | ||||
-rwxr-xr-x | builder/modules.d/slx-network/module-setup.sh | 8 | ||||
-rwxr-xr-x | builder/modules.d/slx-network/scripts/setup-network | 88 | ||||
-rwxr-xr-x | builder/modules.d/slx-network/scripts/udhcpc-trigger (renamed from builder/modules.d/slx-network/udhcpc-trigger) | 5 | ||||
-rw-r--r-- | builder/modules.d/slx-network/setup-network.sh | 110 |
6 files changed, 95 insertions, 118 deletions
diff --git a/builder/modules.d/slx-network/copy-network-config.sh b/builder/modules.d/slx-network/hooks/copy-network-config.sh index eeab0c85..eeab0c85 100644 --- a/builder/modules.d/slx-network/copy-network-config.sh +++ b/builder/modules.d/slx-network/hooks/copy-network-config.sh diff --git a/builder/modules.d/slx-network/parse-ipxe-network-kcl.sh b/builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh index 12d25322..472437fd 100644 --- a/builder/modules.d/slx-network/parse-ipxe-network-kcl.sh +++ b/builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh @@ -99,5 +99,5 @@ NETIF= [ -n "${BRIDGED}" ] && [ -n "${BRIDGE_NAME}" ] && NETIF="${BRIDGE_NAME}" [ -n "${VLAN}" ] && NETIF="${BOOTIF_NAME}.${VLAN}" -/sbin/initqueue --settled /usr/bin/setup-network "$BOOTIF_NAME" +/sbin/initqueue --settled /usr/local/bin/setup-network /sbin/initqueue --finished [ -e "/.network" ] diff --git a/builder/modules.d/slx-network/module-setup.sh b/builder/modules.d/slx-network/module-setup.sh index 45b91877..e9278474 100755 --- a/builder/modules.d/slx-network/module-setup.sh +++ b/builder/modules.d/slx-network/module-setup.sh @@ -23,9 +23,9 @@ install() { _arch=$(uname -m) inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" - inst "$moddir/udhcpc-trigger" "/usr/local/bin/udhcpc-trigger" - inst_hook cmdline 10 "$moddir/parse-ipxe-network-kcl.sh" - inst_hook pre-mount 00 "$moddir/setup-network.sh" - inst_hook pre-pivot 50 "$moddir/copy-network-config.sh" + inst "$moddir/scripts/setup-network" "/usr/local/bin/setup-network" + inst "$moddir/scripts/udhcpc-trigger" "/usr/local/bin/udhcpc-trigger" + inst_hook cmdline 10 "$moddir/hooks/parse-ipxe-network-kcl.sh" + inst_hook pre-pivot 50 "$moddir/hooks/copy-network-config.sh" } diff --git a/builder/modules.d/slx-network/scripts/setup-network b/builder/modules.d/slx-network/scripts/setup-network new file mode 100755 index 00000000..1f9eaddf --- /dev/null +++ b/builder/modules.d/slx-network/scripts/setup-network @@ -0,0 +1,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}.$$" diff --git a/builder/modules.d/slx-network/udhcpc-trigger b/builder/modules.d/slx-network/scripts/udhcpc-trigger index 9a056a6c..778b55f9 100755 --- a/builder/modules.d/slx-network/udhcpc-trigger +++ b/builder/modules.d/slx-network/scripts/udhcpc-trigger @@ -1,14 +1,13 @@ #!/bin/ash -exec >> /run/openslx/udhcpc-trigger.log -exec 2>> /run/openslx/udhcpc-trigger.log +exec &> "/run/openslx/udhcpc-trigger.log.$$" set -x NETWORK_CONF="/run/openslx/network.conf" . "$NETWORK_CONF" if [ "x$1" != "xbound" -a "x$1" != "xrenew" ] \ - || [ "x$interface" != "${SLX_BRIDGE:-${SLX_PXE_NETIF}" ] \ + || [ "x$interface" != "x${SLX_BRIDGE:-${SLX_PXE_NETIF}}" ] \ || [ -z "$ip" ]; then exit 0 fi diff --git a/builder/modules.d/slx-network/setup-network.sh b/builder/modules.d/slx-network/setup-network.sh deleted file mode 100644 index 6964f503..00000000 --- a/builder/modules.d/slx-network/setup-network.sh +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/bash - -type emergency_shell || . /lib/dracut-lib.sh - -. /run/openslx/network.conf - -_logfile="/run/openslx/network.log" - -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 - -addtional_nic=1 -# loop over all physical interface -for nic in "/sys/class/net/"*; do - [ -e "$nic/device" ] || continue - nic_iface="${nic##*/}" - nic_mac="$(cat ${nic}/address)" - if [ "$nic_mac" = "$SLX_PXE_MAC" ]; then - # found the boot interface, configure it - ip link set dev "$nic_iface" up - if ! wait_for_iface "$nic_iface" 100; then - # TODO handle? - : - 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" "$nic_iface" - 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:-${nic_iface}}" - continue - fi - # additional network interfaces, create additional bridges - addtional_bridge="br-nic-${addtional_nic}" - ( - set -e - brctl addbr "$addtional_bridge" - brctl stp "$addtional_bridge" 0 - ip link set addr "$nic_mac" "$addtional_bridge" - ip link set dev "$nic_iface" up - brctl addif "$addtional_bridge" "$nic_iface" - ip link set dev "$addtional_bridge" up - ) - if [ "$?" -ne 0 ]; then - warn "Failed to setup additional bridge for '$nic_mac'." - else - additional_nic=$(( additional_nic + 1 )) - fi -done - -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 - 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, handle - [ "$i" = "fail" ] && emergency_shell "DHCP failed 3 times... cannot continue." - warn "DHCP failed, retrying in 1sec..." - sleep $i -done - -set +x -} &> "$_logfile" |