diff options
| author | Jonathan Bauer | 2020-07-28 14:57:16 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2020-07-29 12:55:52 +0200 |
| commit | 092ec5bd8ea2f1913543e85287e143fe5b139103 (patch) | |
| tree | 641a5b42ea72edc39a057c0202f4d4405c732604 /modules.d/slx-network/scripts | |
| parent | [slx-splash] reactivate systemd messages if fbsplash fails (diff) | |
| download | systemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.tar.gz systemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.tar.xz systemd-init-092ec5bd8ea2f1913543e85287e143fe5b139103.zip | |
[slx-network] new style KCL
Diffstat (limited to 'modules.d/slx-network/scripts')
| -rwxr-xr-x | modules.d/slx-network/scripts/setup-bootif-network.stage3 | 26 | ||||
| -rwxr-xr-x | modules.d/slx-network/scripts/udhcpc-trigger.stage3 | 34 |
2 files changed, 42 insertions, 18 deletions
diff --git a/modules.d/slx-network/scripts/setup-bootif-network.stage3 b/modules.d/slx-network/scripts/setup-bootif-network.stage3 index 50718894..74d1c2b5 100755 --- a/modules.d/slx-network/scripts/setup-bootif-network.stage3 +++ b/modules.d/slx-network/scripts/setup-bootif-network.stage3 @@ -80,14 +80,26 @@ if [ -n "$SLX_BRIDGE" ]; then done fi -# finally add the IP address on the main NIC -if [ -n "$SLX_PXE_CLIENT_IP" ]; then - 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 "$MAIN_NETIF" +# Finally add the IP address on the main NIC. +# Note: we should never have ip & netmask without the other. +if [ -n "$SLX_PXE_CLIENT_IP" ] && [ -n "$SLX_PXE_NETMASK" ]; then + ip addr add "${SLX_PXE_CLIENT_IP}/${SLX_PXE_NETMASK}" dev "$MAIN_NETIF" + + # now if we got everything from the KCL and skip dhcp if so + if [ -n "$SLX_PXE_GATEWAY" ] && [ -n "$SLX_PXE_DNS" ]; then + info "Got network configuration from KCL, skipping DHCP." + if ! interface="$MAIN_NETIF" \ + ip="$SLX_PXE_CLIENT_IP" \ + router="$SLX_PXE_GATEWAY" \ + dns="$SLX_PXE_DNS" \ + /usr/local/bin/udhcpc-trigger bound; then + warn "Failed to launch DHCP trigger with KCL configuration - will DHCP." + fi + exit 0 + fi fi +## DHCP additional_opts=() # we need to send the same UID (without '-') as the PXE firmware did, so use the plain @@ -106,6 +118,7 @@ fi # DHCP options to request request_opts=("-O" "hostname") +request_opts+=("-O" "dns") request_opts+=("-O" "ntpsrv") request_opts+=("-O" "domain") request_opts+=("-O" "wpad") @@ -131,3 +144,4 @@ set +x } &>> "/run/openslx/initramfs-network.log.$$" + diff --git a/modules.d/slx-network/scripts/udhcpc-trigger.stage3 b/modules.d/slx-network/scripts/udhcpc-trigger.stage3 index d54939a8..27c0f22a 100755 --- a/modules.d/slx-network/scripts/udhcpc-trigger.stage3 +++ b/modules.d/slx-network/scripts/udhcpc-trigger.stage3 @@ -32,26 +32,25 @@ if [ -n "$SLX_PXE_CLIENT_IP" ]; then #...some address is already configured... if [ "x${SLX_PXE_CLIENT_IP}" != "x${ip}" ]; then #...it's a different one, reconfigure... - echo "..reconfiguring ${SLX_PXE_CLIENT_IP} to ${ip}.." + echo "..reconfiguring '${SLX_PXE_CLIENT_IP}' to '${ip}'." # remove default route and let it be added again below, as it might get lost when changing the primary address on the interface ip route del default 2>/dev/null ip addr del "$SLX_PXE_CLIENT_IP" dev "${interface}" 2>/dev/null ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}" + echo "SLX_DHCP_CLIENT_IP='$ip'" >> "$NETWORK_CONF" fi else #...no address configured yet, just add... echo "..adding ${ip}.." ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}" fi -echo "SLX_DHCP_CLIENT_IP='$ip'" >> "$NETWORK_CONF" # Same procedure for default gateway -if [ -n "${router}" ]; then - if [ -s "$SLX_PXE_GATEWAY" ]; then - if [ "x${SLX_PXE_GATEWAY}" != "x${router}" ]; then - echo "..reconfiguring default gw from ${SLX_PXE_GATEWAY} to ${router}.." - ip route replace default via "$router" - fi +if [ -n "$router" ]; then + if [ -n "$SLX_PXE_GATEWAY" ] && [ "$SLX_PXE_GATEWAY" != "$router" ]; then + echo "..reconfiguring default gw from '$SLX_PXE_GATEWAY' to '$router'." + ip route del default 2>/dev/null + ip route add default via "$router" else ip route add default via "$router" fi @@ -65,21 +64,30 @@ fi rm -f -- "/etc/resolv.conf" +reverse_lookup() { + [ -z "$dns" ] && return + [ -z "$1" ] && return + timeout -t 3 nslookup "$1" | grep -E "^Address +[0-9]+: +$1 " | head -n 1 | awk '{print $4}' +} + +echo "# From DHCP in stage 3.1" >> "$NETWORK_CONF" + # DNS/domain? if [ -n "$dns" ]; then echo "..got DNS.." - echo "# From DHCP in stage 3.1" >> "$NETWORK_CONF" echo "SLX_DNS='$dns'" >> "$NETWORK_CONF" fi for srv in $dns; do echo "nameserver $srv" >> "/etc/resolv.conf" done + if [ -z "$domain" ]; then # try to get domain via reverse lookup if empty echo "..trying to get domain via DNS, as DHCP didn't supply one.." - fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}') + fqdn="$(reverse_lookup "$ip")" domain="${fqdn#*.}" fi + # Add domain to list of search domains if not in there yet if [ -n "$domain" ] && [ -n "$search" ]; then FOUND=no @@ -90,11 +98,13 @@ if [ -n "$domain" ] && [ -n "$search" ]; then elif [ -n "$domain" ]; then search="$domain" fi + # Write out if [ -n "$domain" ]; then echo "domain $domain" >> "/etc/resolv.conf" echo "SLX_NET_DOMAIN='$domain'" >> "/run/openslx/network.conf" fi + if [ -n "$search" ]; then echo "search $search" >> "/etc/resolv.conf" echo "SLX_NET_SEARCH='$search'" >> "/run/openslx/network.conf" @@ -113,7 +123,7 @@ else if [ -z "$hostname" ]; then # as with domain, if there's no hostname, try to get via DNS echo "..trying to get hostname via DNS, as DHCP didn't supply one.." - [ -z "$fqdn" ] && fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}') + [ -z "$fqdn" ] && fqdn="$(reverse_lookup "$ip")" hostname="${fqdn%%.*}" elif [ -n "$domain" ]; then fqdn="${hostname}.${domain%% *}" # in case domain is a list @@ -132,7 +142,7 @@ if [ -n "$hostname" ]; then echo "$hostname" > "/etc/hostname" echo "127.0.0.1 localhost" > "/etc/hosts" echo "127.0.1.1 $fqdn $hostname" >> "/etc/hosts" - echo "SLX_HOSTNAME='$hostname'" >> "/run/openslx/network.conf" + echo "SLX_HOSTNAME='$hostname'" >> "$NETWORK_CONF" fi touch /.network |
