From 8570b0b66c1a5cb69e821e6f5e48e542189148f6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 23 Jul 2018 13:30:53 +0200 Subject: [dhcpc-busybox] Don't deconfig the primary interface Deconfig-then-bound leaves us with a moment of no network connectivity which could potentially result in a system lockup. Ignore deconfig, but instead remove all but the assigned address in renew/bound. --- .../data/opt/openslx/scripts/udhcpc-openslx | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx') diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index d0fb2410..cfebcb73 100755 --- a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -19,6 +19,9 @@ . /opt/openslx/config +primary="br0" +[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE" + RESOLV_CONF="/opt/openslx/resolv.conf" THIS_RESOLV="/run/network/${interface}.resolv" @@ -71,7 +74,7 @@ case "$1" in check_env "$1" mkdir -p "/run/dhcpc" # Set address on interface - ip addr add "$ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//)" dev "$interface" + ip addr add "$ip/$(ipcalc -s -p "$ip" "$subnet" | sed s/.*=//)" dev "$interface" # Set default route, if given if [ -n "$router" ]; then ip route add default via "$router" @@ -135,7 +138,7 @@ case "$1" in # Things that should only happen for the main interface that was used for booting - if [ "$interface" == "br0" ]; then + if [ "$interface" = "$primary" ]; then # Update IP sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config # Write DOMAIN and SEARCH to /opt/openslx/config if empty @@ -156,7 +159,7 @@ case "$1" in # Only if network is not ready yet if [ ! -e "/run/network/network-ready" ]; then # Update hostname - if [ -z "$dns_fqdn" -a -n "$domain" -a -n "$hostname" ]; then + if [ -z "$dns_fqdn" ] && [ -n "$domain" ] && [ -n "$hostname" ]; then # fallback to what the dhcp told us dns_fqdn="${hostname}.${domain}" fi @@ -183,7 +186,18 @@ case "$1" in # Mark network target as reached systemctl start network.target & fi # end "network not ready yet" - fi # end "br0 only" + # 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 "/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" # Hostname in /etc/hosts touch "/etc/hosts" @@ -228,13 +242,13 @@ case "$1" in deconfig) check_env "$1" - if [ $(grep -c "nfs=" /proc/cmdline) == 0 ]; then + if [ "$interface" = "$primary" ]; then + echo "Ignoring deconfig for primary interface" + else echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" clientip=${ip%%:*} - ip addr del "$clientip/$(ipcalc -s -p $clientip $subnet|sed s/.*=//)" dev "$interface" + ip addr del "$clientip/$(ipcalc -s -p "$clientip" "$subnet" | sed s/.*=//)" dev "$interface" sed -i "/^$(escape_search "$ip")(\s|$)/d" /etc/hosts - else - echo "NFS is active, not removing old ip adress. warning: lease may expire after a while." fi if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then -- cgit v1.2.3-55-g7522