diff options
author | Jonathan Bauer | 2019-08-08 14:55:56 +0200 |
---|---|---|
committer | Jonathan Bauer | 2019-08-08 14:55:56 +0200 |
commit | ce1558966a8481d04f1ff78c1b58a91740513e69 (patch) | |
tree | 58c2042c79d57eea8ecefb413c1da805203a033f /builder/modules.d/slx-network/scripts | |
parent | [slx-network] support for dhcp in stage4 (diff) | |
download | systemd-init-ce1558966a8481d04f1ff78c1b58a91740513e69.tar.gz systemd-init-ce1558966a8481d04f1ff78c1b58a91740513e69.tar.xz systemd-init-ce1558966a8481d04f1ff78c1b58a91740513e69.zip |
[slx-network] only care about main bootif
+ rdns
Diffstat (limited to 'builder/modules.d/slx-network/scripts')
4 files changed, 79 insertions, 94 deletions
diff --git a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 index 1f9eaddf..24bf0245 100755 --- a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 +++ b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 @@ -1,12 +1,16 @@ #!/bin/bash +# +# This script sets up the main network interface we booted from, +# as designated by SLX_PXE_NETIF (parsed from the PXE KCL in the +# cmdline dracut hook). +# It is run inside dracut's initqueue, on settles to detect the +# physical network interface as fast as possible. type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh . /run/openslx/network.conf -_logfile="/run/openslx/network.log" - -# for the boot interface? +# guard to not run until the phsyical interface is not ready yet if [ ! -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; then exit 1 fi @@ -33,7 +37,7 @@ if ! wait_for_iface "$SLX_PXE_NETIF" 100; then fi if [ -n "$SLX_BRIDGE" ]; then - for try in 1 2 3 fail; do + for try in {1..10} ""; do ( set -e brctl addbr "$SLX_BRIDGE" @@ -48,13 +52,12 @@ if [ -n "$SLX_BRIDGE" ]; then [ "$?" -eq 0 ] && break # nope, handle - if [ "$try" = "fail" ]; then + if [ -z "$try" ]; 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 @@ -85,4 +88,4 @@ for i in 1 1 1 fail; do done set +x -} &>> "${_logfile}.$$" +} &>> "/run/openslx/network.log.$$" diff --git a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 index 7ccb94e6..bd89fec6 100755 --- a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 +++ b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 @@ -1,13 +1,18 @@ #!/bin/bash -# For arrays +# +# This script sets up the main network interface we booted from, +# as designated by SLX_PXE_NETIF in /opt/openslx/config +# It will run on either the bridge (SLX_BRIDGE is set) or the +# physical interface directly. export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin -. /run/openslx/network.conf +. /opt/openslx/config -net_if="$1" -net_ip="$(ip addr show dev "${net_if}" | grep -m1 '^\s*inet ' | \ - awk -F " " '{print $2}' | awk -F "/" '{print $1}')" +if [ -z "$SLX_PXE_NETIF" ] || [ -z "$SLX_PXE_CLIENT_IP" ]; then + echo "Missing network information of the main boot interface." + exit 1 +fi # set default options declare -a udhcpc_opts @@ -19,16 +24,8 @@ udhcpc_opts+=("-O" "wpad") udhcpc_opts+=("-O" "search") udhcpc_opts+=("-O" "wins") -# need to renew? -if [ -n "$net_ip" ]; then - udhcpc_opts+=( "-r" "$net_ip" ) -fi - -primary="br0" -[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE" - -# send machine uuid during DHCP if acting on primary interface -if [ "$primary" = "$net_if" ] && [ "$SLX_NET_DHCP_UUID" = "yes" ]; then +# send machine uuid during DHCP if configured +if [ "$SLX_NET_DHCP_UUID" = "yes" ]; then uid=$(dmidecode -s system-uuid | \ sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/') if [ "${#uid}" = 34 ]; then @@ -39,7 +36,9 @@ fi mkdir -p /run/udhcpc || echo "Could not create '/run/udhcpc'." -udhcpc "${udhcpc_opts[@]}" -i "${net_if}" \ +udhcpc "${udhcpc_opts[@]}" \ + -i "${SLX_BRIDGE:-${SLX_PXE_NETIF}}" \ + -r "${SLX_PXE_CLIENT_IP}" \ -s /opt/openslx/scripts/udhcpc-trigger \ -p "/run/udhcpc/udhcpc.${net_if}.pid" ret=$? diff --git a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 index 8bed11c7..2621b76f 100755 --- a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 +++ b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 @@ -1,8 +1,11 @@ -#!/bin/ash +#!/bin/bash +# +# This script is triggered by udhcpc in stage3 and handle the +# DHCP information given as parameters -exec &> "/run/openslx/udhcpc-trigger.log.$$" +{ +# for debugging set -x - NETWORK_CONF="/run/openslx/network.conf" . "$NETWORK_CONF" @@ -112,3 +115,5 @@ if [ -n "$hostname" ]; then fi touch /.network +set +x +} &>> "/run/openslx/network.log.$$" diff --git a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 index 92aa9596..b51328ca 100755 --- a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 +++ b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 @@ -1,32 +1,19 @@ #!/bin/bash -# Needs bash for printf -v VARNAME -# ----------------------------------------------------------------------------- # -# Copyright (c) 2011..2018 bwLehrpool-Projektteam -# -# This program/file is free software distributed under the GPL version 2. -# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html -# -# If you have any feedback please consult https://bwlehrpool.de and -# send your feedback to bwlehrpool@hs-offenburg.de. -# -# General information about bwLehrpool can be found at https://bwlehrpool.de -# -# ----------------------------------------------------------------------------- -# -# Mini-Linux Toolkit -# -# ----------------------------------------------------------------------------- +# This script is triggered by udhcpc and handle the DHCP information +# given to this script as parameters. export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin . /opt/openslx/config -primary="br0" -[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE" +if [ -z "$SLX_PXE_NETIF" ] || [ -z "$SLX_PXE_CLIENT_IP" ]; then + echo "Missing PXE network interface information." + exit 1 +fi RESOLV_CONF="/opt/openslx/resolv.conf" -THIS_RESOLV="/run/network/${interface}.resolv" +THIS_RESOLV="/run/network/${SLX_PXE_NETIF}.resolv" rebuild_resolv_conf () { # Don't do anything if the active resolv.conf is not ours @@ -59,23 +46,17 @@ check_env() { echo "interface = '$interface'" >&2 exit 1 fi + # only run for the boot network interface + # TODO VLAN support + if [ "$interface" != "${SLX_BRIDGE:-${SLX_PXE_NETIF}}" ]; then + echo "Ignoring '$interface'..." + exit 1 + fi } -if [ ! -d /run ]; then - echo -n "Waiting for /run." >&2 - while [ ! -d /run ]; do - echo -n "." >&2 - usleep 500000 - done - echo "" >&2 -fi - -mkdir -p "/run/network" - case "$1" in bound|renew) check_env "$1" - mkdir -p "/run/dhcpc" # Set address on interface ip addr add "$ip/$(ipcalc -s -p "$ip" "$subnet" | sed s/.*=//)" dev "$interface" # Set default route, if given @@ -140,42 +121,39 @@ case "$1" in rebuild_resolv_conf fi - - # Things that should only happen for the main interface that was used for booting - if [ "$interface" = "$primary" ]; then - # Update IP, TODO: check if we really want/need to overwrite the PXE_IP, - # it might be better/clearer to change the SLX_DHCP_CLIENT_IP... - sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config - # Write DOMAIN and SEARCH to /opt/openslx/config if empty - if [ -z "$SLX_NET_DOMAIN" ] && [ -n "$domain" ]; then - sed -i "/^SLX_NET_DOMAIN=/d" /opt/openslx/config - echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config - fi - if [ -z "$SLX_NET_SEARCH" ] && [ -n "$search" ]; then - sed -i "/^SLX_NET_SEARCH=/d" /opt/openslx/config - echo "SLX_NET_SEARCH='$search'" >> /opt/openslx/config - fi - # Same for WINS servers - if [ -z "$SLX_NET_WINS" ] && [ -n "$wins" ]; then - sed -i "/^SLX_NET_WINS=/d" /opt/openslx/config - echo "SLX_NET_WINS='$wins'" >> /opt/openslx/config - fi - - # Update /etc/issue for proper spacing - [ -x "/opt/openslx/scripts/openslx-create_issue" ] && /opt/openslx/scripts/openslx-create_issue - - # Remove any stray addresses; we expect the primary interface to only have one - # address supplied via DHCP. We do this after adding the new one, obviously. - rem_list=$( ip -o addr show "$interface" | awk '{ for (i=1;i<NF;++i) if ($i == "inet") print $(i+1) }' | grep -v "^${ip}/" ) - if [ -n "$rem_list" ]; then - echo "PRIMARY: Removing $rem_list since we just got assigned $ip" - echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" - for addr in $rem_list; do - ip addr del "$addr" dev "$interface" - sed -i "/^$(escape_search "${addr%/*}")(\s|$)/d" /etc/hosts - done - fi - fi # end "primary only" + # TODO: check if we really want/need to overwrite the PXE_IP, + # it might be better/clearer to change the SLX_DHCP_CLIENT_IP... + sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config + # Write DOMAIN and SEARCH to /opt/openslx/config if empty + if [ -z "$SLX_NET_DOMAIN" ] && [ -n "$domain" ]; then + sed -i "/^SLX_NET_DOMAIN=/d" /opt/openslx/config + echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config + fi + if [ -z "$SLX_NET_SEARCH" ] && [ -n "$search" ]; then + sed -i "/^SLX_NET_SEARCH=/d" /opt/openslx/config + echo "SLX_NET_SEARCH='$search'" >> /opt/openslx/config + fi + # Same for WINS servers + if [ -z "$SLX_NET_WINS" ] && [ -n "$wins" ]; then + sed -i "/^SLX_NET_WINS=/d" /opt/openslx/config + echo "SLX_NET_WINS='$wins'" >> /opt/openslx/config + fi + + # TODO find a better way to trigger additional code, hook dir? + # Update /etc/issue for proper spacing + [ -x "/opt/openslx/scripts/openslx-create_issue" ] && /opt/openslx/scripts/openslx-create_issue + + # Remove any stray addresses; we expect the primary interface to only have one + # address supplied via DHCP. We do this after adding the new one, obviously. + rem_list=$( ip -o addr show "$interface" | awk '{ for (i=1;i<NF;++i) if ($i == "inet") print $(i+1) }' | grep -v "^${ip}/" ) + if [ -n "$rem_list" ]; then + echo "PRIMARY: Removing $rem_list since we just got assigned $ip" + echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" + for addr in $rem_list; do + ip addr del "$addr" dev "$interface" + sed -i "/^$(escape_search "${addr%/*}")(\s|$)/d" /etc/hosts + done + fi # Write to openslx-config echo "# Config written by openslx-dhcp-script (2)" >> /opt/openslx/config |