summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage31/data/inc/setup_network
diff options
context:
space:
mode:
authorSimon Rettberg2020-07-08 16:12:32 +0200
committerSimon Rettberg2020-07-08 16:12:32 +0200
commitc1d6cad0e7653fcad04f27a7827a439827470092 (patch)
tree32578b2e35511271a913ac01bfb9a6b30166e0fd /core/rootfs/rootfs-stage31/data/inc/setup_network
parent[remote-access] Tweak screen splitting (diff)
downloadmltk-c1d6cad0e7653fcad04f27a7827a439827470092.tar.gz
mltk-c1d6cad0e7653fcad04f27a7827a439827470092.tar.xz
mltk-c1d6cad0e7653fcad04f27a7827a439827470092.zip
[init/kexec/] More advanced network setup via KCL, could skip DHCP
If enough information if provided via KCL, we can skip the initial DHCP request in stage 3.1. Currently we require IP address, subnet mask and DNS server to skip DHCP. If we extend the boot server to supply a fallback/default DNS server, we could even do without DNS which would work in almost all cases. kexec-reboot has been extended to make use of this feature, but can be extended even more to provide up to date values from the current system configuration. Currently, some of the values it provides to the new kernel will be cached values from stage 3.1. kexec-reboot also honors the ipxe menu id from the KCL if given, to properly download the matching menu entry, which will take updates to the entry into account (e.g. changed URLs to kernel/init).
Diffstat (limited to 'core/rootfs/rootfs-stage31/data/inc/setup_network')
-rw-r--r--core/rootfs/rootfs-stage31/data/inc/setup_network43
1 files changed, 21 insertions, 22 deletions
diff --git a/core/rootfs/rootfs-stage31/data/inc/setup_network b/core/rootfs/rootfs-stage31/data/inc/setup_network
index 6b97fb18..e407d173 100644
--- a/core/rootfs/rootfs-stage31/data/inc/setup_network
+++ b/core/rootfs/rootfs-stage31/data/inc/setup_network
@@ -47,28 +47,24 @@ for LINE in $IP_OUT; do
IFMAC="$( echo "${LINE#*==}" | tr 'A-Z' 'a-z' )" # udev requires mac addesses to be lowercase (a-f), see http://www.debianhelp.co.uk/udev.htm
echo "${IFACE} = ${IFMAC}"
+ if [ -z "$MAC" ]; then
+ echo "No main MAC address given, trying first interface found..."
+ MAC="$IFMAC"
+ fi
+
if [ "x$IFMAC" == "x$MAC" ]; then
+ ip link set dev "$IFACE" up
brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE"
brctl stp "$BRIDGE" 0
brctl setfd "$BRIDGE" 0.000000000001
ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE"
- ip link set dev "$IFACE" up
wait_for_iface "$IFACE" 8
brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE"
# save our variables for retry on fail
echo "IFACE=$IFACE" > /run/network.conf
- # analyze ip information from the kernel command line and put parts
- # of it into several variables
- if [ -n "$CLIENTIP" ] ; then
- # set static ip address
- ip link set dev "$BRIDGE" up
- ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE"
- [ -n "$GATEWAY" ] && ip route add default via "$GATEWAY" dev "$BRIDGE"
- else
- ip link set dev "$BRIDGE" up
- fi
+ ip link set dev "$BRIDGE" up
# Ignore this device later on when systemd handles network interfaces (see hacked 99-systemd.rules in systemd data dir)
echo "SUBSYSTEM==\"net\", ACTION==\"add\", KERNEL==\"eth*\", ATTR{address}==\"$IFMAC\", TAG+=\"openslxignore\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/01-ignore-boot-interface.rules"
else
@@ -90,14 +86,17 @@ done
wait_for_iface "$BRIDGE" 5
+# See if we got all required attributes via KCL, in that case skip DHCP
+# TODO: Supply DNS servers in config from boot server, so we can even work witout it
+if [ -n "$ip" ] && [ -n "$router" ] && [ -n "$dns" ]; then
+ echo "Skipping DHCP since we have new style KCL"
+ interface="${BRIDGE}" /inc/udhcpc-trigger bound && return 0
+fi
+
# udhcpc
PARAM=
-if [ -n "$CLIENTIP" ]; then
- PARAM="-r $CLIENTIP"
- echo -n "$CLIENTIP" > "/run/firstip"
-fi
-if [ -n "$GATEWAY" ]; then
- echo -n "$GATEWAY" > "/run/firstgw"
+if [ -n "$ip" ]; then
+ PARAM="-r ${ip%/*}"
fi
if [ "$USE_DHCP_UUID" = "yes" ]; then
@@ -109,15 +108,15 @@ if [ "$USE_DHCP_UUID" = "yes" ]; then
fi
# save our variables for retry on fail ff.
-echo "CLIENTIP=$CLIENTIP" >> /run/network.conf
-echo "GATEWAY=$GATEWAY" >> /run/network.conf
+echo "ip=$ip" >> /run/network.conf
+echo "router=$router" >> /run/network.conf
echo "BRIDGE=$BRIDGE" >> /run/network.conf
echo "UID=$UID" >> /run/network.conf
-udhcpc $PARAM -O hostname -O ntpsrv -O domain -O search -t 5 -T 3 -A 4 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE"
+udhcpc $PARAM -O hostname -O ntpsrv -O domain -O search -O dns -t 5 -T 3 -A 4 -s "/inc/udhcpc-trigger" -f -n -q -i "$BRIDGE"
URET=$?
# if these were empty before, udhcpc might have filled them in
-[ -z "$CLIENTIP" ] && CLIENTIP=$(cat /run/firstip)
-[ -z "$GATEWAY" ] && GATEWAY=$(cat /run/firstgw)
+[ -z "$ip" ] && ip=$(cat /run/firstip)
+[ -z "$router" ] && router=$(cat /run/firstgw)
# udhcpc return value will be return value of this script
return $URET