summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/slx-network/hooks
diff options
context:
space:
mode:
authorJonathan Bauer2019-08-01 14:55:11 +0200
committerJonathan Bauer2019-08-01 14:55:11 +0200
commite35bce0d1bdce2d53573c75f496545d601a1ac8c (patch)
tree3cbad21b2eaa29c92eeddf9955bdb1e9edf962d8 /builder/modules.d/slx-network/hooks
parent[slx-network] setup network on udev settles (diff)
downloadsystemd-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/hooks')
-rw-r--r--builder/modules.d/slx-network/hooks/copy-network-config.sh9
-rw-r--r--builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh103
2 files changed, 112 insertions, 0 deletions
diff --git a/builder/modules.d/slx-network/hooks/copy-network-config.sh b/builder/modules.d/slx-network/hooks/copy-network-config.sh
new file mode 100644
index 00000000..eeab0c85
--- /dev/null
+++ b/builder/modules.d/slx-network/hooks/copy-network-config.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+if [ -n "$NEWROOT" ]; then
+ for file in /etc/{hostname,resolv.conf,hosts}; do
+ unlink "${NEWROOT}/${file}"
+ cp -f "$file" "${NEWROOT}/etc"
+ done
+fi
+true
diff --git a/builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh b/builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh
new file mode 100644
index 00000000..472437fd
--- /dev/null
+++ b/builder/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+#
+# TODO VLAN support
+
+command -v getarg >/dev/null || . /lib/dracut-lib.sh
+
+# static names for the boot interface and its bridge
+declare -rg BOOTIF_NAME="boot0"
+declare -rg BRIDGE_NAME="br0"
+declare -rg RUNTIME_CONF="/run/openslx/network.conf"
+mkdir -p "${RUNTIME_CONF%/*}"
+# Get all the ip-related arguments from the KCL
+parse_kernel_command_line() {
+ ## KCL "BOOTIF": MAC address of the interface that DHCP'ed during PXE
+ declare -g BOOTIF="$(getarg BOOTIF=)"
+ # Remove the hardware type prefix of BOOTIF if it has 20 chars to get
+ # the plain MAC address. The hardware type prefix has length 3, e.g. "01-".
+ if [ -n "${BOOTIF}" ] && [ ${#BOOTIF} -eq 20 ]; then
+ BOOTIF="${BOOTIF#???}"
+ BOOTIF="${BOOTIF//-/:}"
+ fi
+ readonly BOOTIF
+
+ ## KCL "ip": is expected in following format (syslinux IPAPPEND3):
+ declare -rg IPCONF="$(getarg ip=)"
+ # <CLIENT_IP>:<PXE_SERVER_IP>:<GATEWAY_IP>:<NETMASK>
+ declare -g CLIENT_IP=
+ declare -g SERVER_IP=
+ declare -g GATEWAY_IP=
+ declare -g NETMASK=
+ read -r CLIENT_IP SERVER_IP GATEWAY_IP NETMASK \
+ <<< $( awk -F: '{print $1" "$2" "$3" "$4}' <<< "${IPCONF}" )
+ readonly CLIENT_IP SERVER_IP GATEWAY_IP NETMASK
+
+ # Calculate routing prefix from netmask
+ declare -rg ROUTING_PREFIX="$(ipcalc -s -p "$CLIENT_IP" "$NETMASK")"
+
+ # KCL "hostname"
+ declare -rg HOSTNAME="$(getarg hostname=)"
+ [ -n "$HOSTNAME" ] && echo "$HOSTNAME" > /proc/sys/kernel/hostname
+
+ # KCL "dns"
+ declare -rg DNS="$(getarg dns=)"
+
+ # KCL "domain"
+ declare -rg DOMAIN="$(getarg domain=)"
+
+ # VLAN tag
+ declare -rg VLAN="$(getarg vlan=)"
+ if [ -n "$VLAN" ]; then
+ modprobe 8021q || warn "VLAN mode detected but failed to load 8021q!"
+ fi
+
+ # Bridged mode?
+ grep -wqE 'bridged' /proc/cmdline && declare -rg BRIDGED="y"
+}
+
+save_network_config() {
+ cat <<-EOF > "${RUNTIME_CONF}"
+ SLX_PXE_CLIENT_IP='${CLIENT_IP}'
+ SLX_PXE_SERVER_IP='${SERVER_IP}'
+ SLX_PXE_GATEWAY='${GATEWAY_IP}'
+ SLX_PXE_NETMASK='${NETMASK}'
+ SLX_PXE_MAC='${BOOTIF}'
+ SLX_PXE_NETIF='${BOOTIF_NAME}'
+ SLX_PXE_DNS='${DNS}'
+ SLX_PXE_HOSTNAME='${HOSTNAME}'
+ SLX_PXE_DOMAIN='${DOMAIN}'
+ SLX_BRIDGE='${BRIDGED:+${BRIDGE_NAME}}'
+ SLX_VLAN_ID='${VLAN}'
+ EOF
+}
+
+# Create udev rule to rename the PXE boot interface to BOOTIF_NAME
+create_udev_bootif_name_rule() {
+ if [ -z "${BOOTIF}" ]; then
+ echo "No BOOTIF set, was it present in the kernel command line?"
+ return 1
+ fi
+ # priority 70 < 80-net-name-slot.rules.
+ echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'${BOOTIF}'", NAME="'${BOOTIF_NAME}'"' > /etc/udev/rules.d/70-pxe-boot-interface.rules
+}
+
+## MAIN ##
+# Get IP config from KCL
+parse_kernel_command_line
+
+# Save network config for later use
+save_network_config &
+
+# Create the udev rule to rename the boot interface to the declared BOOTIF_NAME
+create_udev_bootif_name_rule &
+
+## Make dracut wait for network during the udev loop (initqueue) to make
+## sure we have network access in the pre-mount hook as it is needed
+## to get configurations and the root filesystem
+NETIF=
+[ -n "${BOOTIF_NAME}" ] && NETIF="${BOOTIF_NAME}"
+[ -n "${BRIDGED}" ] && [ -n "${BRIDGE_NAME}" ] && NETIF="${BRIDGE_NAME}"
+[ -n "${VLAN}" ] && NETIF="${BOOTIF_NAME}.${VLAN}"
+
+/sbin/initqueue --settled /usr/local/bin/setup-network
+/sbin/initqueue --finished [ -e "/.network" ]