summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2018-01-18 18:22:36 +0100
committerJonathan Bauer2018-01-18 18:22:36 +0100
commit59cc08efc97564865cb468d7f6fc4bcdcd83a89a (patch)
treea8fbe3b954ad18c07942139e983efe4c6fdb0ab6
parentadd support for slxsrv=@<ip> (diff)
downloadsystemd-init-59cc08efc97564865cb468d7f6fc4bcdcd83a89a.tar.gz
systemd-init-59cc08efc97564865cb468d7f6fc4bcdcd83a89a.tar.xz
systemd-init-59cc08efc97564865cb468d7f6fc4bcdcd83a89a.zip
add VLAN support
* dhcp configuration for stage4 is still suboptimal * reworked various scripts
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh77
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh29
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh168
-rwxr-xr-xbuilder/modules.d/systemd-networkd-ext/module-setup.sh3
4 files changed, 169 insertions, 108 deletions
diff --git a/builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh b/builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
index 6c9db9b4..59311fb0 100644
--- a/builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
+++ b/builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh
@@ -3,43 +3,56 @@
# This hook creates a networkd configuration for the NEWROOT
# * DHCP configuration for the boot interface
# * Set static hostname via /etc/hostname
-# This uses the configuration file generated by the parse-kcl-for-networkd.sh hook
-# Note: on systemd v219, UseDomains is bugged and does not seem to do anything
-# thus that option is complemented with the KCL's domain
-# to hopefully garantee one of these will take effect.
+# This uses the configuration file generated by the parse-kcl-for-networkd.sh
+# hook Note: on systemd v219, UseDomains is bugged and does not seem to do
+# anything thus that option is complemented with the KCL's domain to hopefully
+# garantee one of these will take effect.
. "/run/openslx/pxe-network.conf"
-# the bridge configuration files
-BRIDGE_CONF="/etc/systemd/network/10-bridge-lan.netdev"
-NEWROOT_NETWORKD_DIR="$NEWROOT/etc/systemd/network"
-NEWROOT_NETWORKD_CONF="$NEWROOT_NETWORKD_DIR/00-boot-lan.network"
-mkdir -p "$NEWROOT_NETWORKD_DIR"
+NETWORKD_DIR="/etc/systemd/network"
+mkdir -p "${NEWROOT}/${NETWORKD_DIR}" # dirname a-la bash
-echo '[Match]' > $NEWROOT_NETWORKD_CONF
-if [ -n "${SLX_BRIDGE}" ]; then
- echo "Name=${SLX_BRIDGE}" >> $NEWROOT_NETWORKD_CONF
-elif [ -n "${SLX_PXE_MAC}" ]; then
- echo "MACAddress=${SLX_PXE_MAC}" >> $NEWROOT_NETWORKD_CONF
-else
- emergency_shell "Could not determine boot interface! \
- If you see this, something very fishy is going on..."
-fi
+# First, copy over every configuration made so far
+cp "${NETWORKD_DIR}/"* "${NEWROOT}/${NETWORKD_DIR}"
+
+# Now determine which network configuration we are running
+# VLANs are already configured to DHCP, so nothing to do
+if [ -z "${SLX_VLAN_ID}" ]; then
+ # In both bridged and non-bridged mode, we need to adjust
+ # the configuration to DHCP for stage4
+ MATCH_LINE=
+ MAIN_NET_CONF=
+ if [ -n "${SLX_BRIDGE}" ]; then
+ MATCH_LINE="Name=${SLX_BRIDGE}"
+ MAIN_NETIF_CONF="${NETWORKD_DIR}/${SLX_BRIDGE}.network"
+ elif [ -n "${SLX_PXE_MAC}" ]; then
+ MATCH_LINE="MACAddress=${SLX_PXE_MAC}"
+ MAIN_NETIF_CONF="${NETWORKD_DIR}/${SLX_PXE_NETIF}.network"
+ else
+ emergency_shell "Could not determine network configuration mode!"
+ fi
+ # backup current network config for later reference before overwritting it
+ if [ -e "${MAIN_NETIF_CONF}" ]; then
+ mv "${NEWROOT}/${MAIN_NETIF_CONF}" "${NEWROOT}/${MAIN_NETIF_CONF}.stage3"
+ else
+ emergency_shell "Failed to find main networkd configuration: ${MAIN_NETIF_CONF}"
+ fi
+ # Now generate a DHCP configuration for the main interface
+ cat <<-EOF > "${NEWROOT}/${MAIN_NETIF_CONF}"
+ [Match]
+ ${MATCH_LINE}
-echo '' >> $NEWROOT_NETWORKD_CONF
-echo '[Network]' >> $NEWROOT_NETWORKD_CONF
-echo 'DHCP=ipv4' >> $NEWROOT_NETWORKD_CONF
-# This should happen by systemd-resolved...
-#[ -n "${SLX_NET_DOMAIN}" ] && echo "Domains=${SLX_NET_DOMAIN}" >> $NEWROOT_NETWORKD_CONF
-echo '' >> $NEWROOT_NETWORKD_CONF
-echo '[DHCP]' >> $NEWROOT_NETWORKD_CONF
-echo 'UseDNS=true' >> $NEWROOT_NETWORKD_CONF
-echo 'UseDomains=true' >> $NEWROOT_NETWORKD_CONF
-echo 'UseHostname=true' >> $NEWROOT_NETWORKD_CONF
-echo 'CriticalConnection=true' >> $NEWROOT_NETWORKD_CONF
+ [Network]
+ DHCP=ipv4
-# Copy bridge config too, if bridged
-[ -n "${SLX_BRIDGE}" ] && cp ${BRIDGE_CONF} ${NEWROOT_NETWORKD_DIR}
+ [DHCP]
+ UseDNS=true
+ UseDomains=true
+ UseHostname=true
+ CriticalConnection=true
+ EOF
+fi
-# Similarly, UseHostname seems to have no effect, so work around for now...
+# Workaround: UseHostname seems broken, so manually set the hostname for now...
[ -n "${SLX_HOSTNAME}" ] && echo "${SLX_HOSTNAME}" > $NEWROOT/etc/hostname
diff --git a/builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh b/builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh
index ad8d77a1..1b5badc7 100644
--- a/builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh
+++ b/builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh
@@ -1,27 +1,30 @@
-
#!/bin/bash
#
# This hook copies the core systemd-networkd related service
-# to the NEWROOT and activated them in sysinit.target
+# files to the NEWROOT and activate them in sysinit.target
# to prevent systemd from killing these while pivot_root
-new_sysinit_wants="${NEWROOT}/usr/lib/systemd/system/sysinit.target.wants/"
-mkdir -p "${new_sysinit_wants}"
+NEWROOT_SYSTEMD_DIR="${NEWROOT}/usr/lib/systemd/system"
+NEWROOT_SYSINIT_TARGET_DIR="${NEWROOT_SYSTEMD_DIR}/sysinit.target.wants"
+mkdir -p "${NEWROOT_SYSINIT_TARGET_DIR}"
-for unit in \
+for UNIT in \
systemd-networkd.socket \
systemd-networkd.service \
systemd-resolved.service
do
- service_path="$(systemctl show -p FragmentPath $unit | cut -c 14-)"
- cp "${service_path}" "${NEWROOT}/${service_path}"
- ln -sf "../${unit}" "${new_sysinit_wants}/${unit}"
+ UNIT_PATH="$(systemctl show -p FragmentPath $UNIT | cut -c 14-)"
+ mkdir -p "${NEWROOT}/${UNIT_PATH%/*}"
+ cp "${UNIT_PATH}" "${NEWROOT}/${UNIT_PATH}"
+ ln -sf "${UNIT_PATH}" "${NEWROOT_SYSINIT_TARGET_DIR}/${UNIT}"
done
# this drop-in is needed to prevent a pull-in loop sysinit.target <-> basic.target
-mkdir -p "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/"
-echo '[Unit]' > "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/00-no-default-deps.conf"
-echo 'DefaultDependencies=no' >> "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/00-no-default-deps.conf"
+mkdir -p "${NEWROOT_SYSTEMD_DIR}/systemd-resolved.service.d/"
+cat <<-EOF > "${NEWROOT_SYSTEMD_DIR}/systemd-resolved.service.d/00-no-default-deps.conf"
+ [Unit]
+ DefaultDependencies=no
+EOF
# finally make sure the NEWROOT resolv.conf links to the one managed by resolved.
-rm $NEWROOT/etc/resolv.conf
-ln -s /run/systemd/resolve/resolv.conf $NEWROOT/etc/resolv.conf
+rm "${NEWROOT}"/etc/resolv.conf
+ln -s /run/systemd/resolve/resolv.conf "${NEWROOT}"/etc/resolv.conf
diff --git a/builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh b/builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh
index 67bc50f5..4c2d647a 100644
--- a/builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh
+++ b/builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh
@@ -7,10 +7,8 @@
command -v getarg >/dev/null || . /lib/dracut-lib.sh
# static names for the boot interface and its bridge
-# TODO could be configurable from the KCL
declare -rg BOOTIF_NAME="boot0"
declare -rg BRIDGE_NAME="br0"
-declare -rg BRIDGED="bridged"
# Get all the ip-related arguments from the KCL
parse_kernel_command_line() {
@@ -52,6 +50,15 @@ parse_kernel_command_line() {
# KCL "domain"
declare -rg DOMAIN="$(getarg domain=)"
+
+ # VLAN tag
+ declare -rg VLAN="$(getarg vlan=)"
+ if [ -n $VLAN ]; then
+ modprobe 8021q || emergency_shell "VLAN mode detected - failed to load 8021q"
+ fi
+
+ # Bridged mode?
+ grep -qE '\s+bridged\s+' /proc/cmdline && declare -rg BRIDGED="y"
}
# Dumps the parsed IP configuration to /run/openslx/pxe-network.conf
@@ -60,29 +67,22 @@ save_ip_config() {
local IP_RUNTIME_CONFIG="/run/openslx/pxe-network.conf"
mkdir -p "${IP_RUNTIME_CONFIG%/*}" # dirname a la bash
cat <<-EOF > "${IP_RUNTIME_CONFIG}"
- SLX_BRIDGE=${BRIDGED:+${BRIDGE_NAME}}
- SLX_PXE_CLIENT_IP=${CLIENT_IP}
- SLX_PXE_SERVER_IP=${SERVER_IP}
- SLX_PXE_GATEWAY=${GATEWAY_IP}
- SLX_PXE_DNS=${DNS}
- SLX_PXE_MAC=${BOOTIF}
- SLX_DNS=${DNS}
- SLX_HOSTNAME=${HOSTNAME}
- SLX_NET_DOMAIN=${DOMAIN}
- #SLX_NET_SEARCH=
+ SLX_PXE_CLIENT_IP=${CLIENT_IP}
+ SLX_PXE_SERVER_IP=${SERVER_IP}
+ SLX_PXE_GATEWAY=${GATEWAY_IP}
+ SLX_PXE_DNS=${DNS}
+ SLX_PXE_MAC=${BOOTIF}
+ SLX_PXE_NETIF=${BOOTIF_NAME}
+ SLX_BRIDGE=${BRIDGED:+${BRIDGE_NAME}}
+ SLX_VLAN_ID=${VLAN}
+ SLX_DNS=${DNS}
+ SLX_HOSTNAME=${HOSTNAME}
+ SLX_NET_DOMAIN=${DOMAIN}
EOF
}
-# Helper to echo a mac address matching [Match] section
-print_match_mac() {
- [ $# -ne 1 ] && echo "No MAC given!" && return 1
- echo '[Match]'
- [ -n "${BRIDGED}" ] && echo "Name=${BOOTIF_NAME}" && return 0
- echo "MACAddress=${1}"
-}
-
-# Helper to echo the static configuration, including
-# DNS and Domain if given per KCL
+# Helper to echo the static configuration,
+# including DNS and Domain, if given per KCL
print_static_ip_conf() {
[ $# -ne 2 ] && echo "Need 2 args: <ip/cidr> <gateway>. Given: $@" && return 1
echo "Address=${1}"
@@ -102,44 +102,83 @@ create_udev_bootif_name_rule() {
# Checks if an IP configuration was forwarded by
generate_networkd_config() {
mkdir -p "/etc/systemd/network"
- local BOOTIF_NETWORK_CONF="/etc/systemd/network/00-boot-lan.network"
- echo '[Match]' > "${BOOTIF_NETWORK_CONF}"
- # In bridged, match on the interface name as
- # the MAC will also match the bridge
- if [ -n "${BRIDGED}" ]; then
- echo "Name=${BOOTIF_NAME}"
- else
- echo "MACAddress=${BOOTIF}"
- fi >> "${BOOTIF_NETWORK_CONF}"
-
- echo '[Network]' >> "${BOOTIF_NETWORK_CONF}"
- if [ -n "${BRIDGED}" ]; then
- echo "Bridge=${BRIDGE_NAME}"
- elif [ -n "${CLIENT_IP}" -a -n "${GATEWAY_IP}" ]; then
- print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
- else
- echo "DHCP=ipv4"
- fi >> "${BOOTIF_NETWORK_CONF}"
- # we're done unless running in bridged mode
- [ -n "${BRIDGED}" ] || return 0
-
+ local BOOTIF_NETWORK_CONF="/etc/systemd/network/${BOOTIF_NAME}.network"
+ (
+ echo '[Match]'
+ # Use BOOTIF_NAME in bridged since the bridge will have the same MAC
+ if [ -n "${BRIDGED}" ]; then
+ echo "Name=${BOOTIF_NAME}"
+ else
+ echo "MACAddress=${BOOTIF}"
+ fi
+ # Currently the boot interface is configured to either:
+ # * static ip as given by the initial DHCP during PXE
+ # * bridged
+ # * vlan-tagged (ethernet interface not configured)
+ # In particular, configuring both vlan tags and the physical
+ # interface is not supported (might be needed in some setups)
+ echo '[Network]'
+ if [ -n "${BRIDGED}" ]; then
+ echo "Bridge=${BRIDGE_NAME}"
+ elif [ -n "${CLIENT_IP}" -a -n "${GATEWAY_IP}" ]; then
+ print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
+ elif [ -n "${VLAN}" ]; then
+ echo "VLAN=$BOOTIF_NAME.$VLAN"
+ else
+ echo "DHCP=ipv4"
+ fi
+ ) > "${BOOTIF_NETWORK_CONF}"
+
+ if [ -n "$VLAN" ]; then
+ local VLAN_DEV_CONF="/etc/systemd/network/${BOOTIF_NAME}.${VLAN}.netdev"
+ cat <<- EOF > "${VLAN_DEV_CONF}"
+ [NetDev]
+ Name=${BOOTIF_NAME}.${VLAN}
+ Kind=vlan
+
+ [VLAN]
+ Id=${VLAN}
+ EOF
+
+ # Configure the vlan tagged interface for DHCPv4, TODO IPv6
+ local VLAN_NETWORK_CONF="/etc/systemd/network/${BOOTIF_NAME}.${VLAN}.network"
+ cat <<- EOF > "${VLAN_NETWORK_CONF}"
+ [Match]
+ Name=${BOOTIF_NAME}.${VLAN}
+
+ [Link]
+ MACAddress=${BOOTIF}
+
+ [Network]
+ DHCP=ipv4
+ LinkLocalAddressing=no
+ EOF
+ fi
+
# bridge setup
- local BRIDGE_DEV_CONF="/etc/systemd/network/10-bridge-lan.netdev"
- echo '[NetDev]' > "${BRIDGE_DEV_CONF}"
- echo "Name=${BRIDGE_NAME}" >> "${BRIDGE_DEV_CONF}"
- echo 'Kind=bridge' >> "${BRIDGE_DEV_CONF}"
- echo "MACAddress=${BOOTIF}" >> "${BRIDGE_DEV_CONF}"
-
- local BRIDGE_NETWORK_CONF="/etc/systemd/network/11-bridge-lan.network"
- echo '[Match]' > "${BRIDGE_NETWORK_CONF}"
- echo "Name=${BRIDGE_NAME}" >> "${BRIDGE_NETWORK_CONF}"
- echo '[Network]' >> "${BRIDGE_NETWORK_CONF}"
- if [ -n "${CLIENT_IP}" -a -n "${GATEWAY_IP}" ]; then
- print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
- else
- # bad/no IP info, fallback to DHCP
- echo "DHCP=ipv4"
- fi >> "${BRIDGE_NETWORK_CONF}"
+ if [ -n "$BRIDGED" ]; then
+ local BRIDGE_DEV_CONF="/etc/systemd/network/${BRIDGE_NAME}.netdev"
+ cat <<- EOF > "${BRIDGE_DEV_CONF}"
+ [NetDev]
+ Name=${BRIDGE_NAME}
+ Kind=bridge
+ MACAddress=${BOOTIF}
+ EOF
+
+ local BRIDGE_NETWORK_CONF="/etc/systemd/network/${BRIDGE_NAME}.network"
+ (
+ echo '[Match]'
+ echo "Name=${BRIDGE_NAME}"
+ echo ""
+ echo '[Network]'
+ if [ -n "${CLIENT_IP}" -a -n "${GATEWAY_IP}" ]; then
+ print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
+ else
+ # bad/no IP info, fallback to DHCP
+ echo "DHCP=ipv4"
+ fi
+ ) > "${BRIDGE_NETWORK_CONF}"
+ fi
return 0
}
# from parse-ip-opts.sh
@@ -167,10 +206,12 @@ parse_kernel_command_line
save_ip_config
# Create the udev rule to rename the boot interface to the declared BOOTIF_NAME
-create_udev_bootif_name_rule
+create_udev_bootif_name_rule || \
+ emergency_shell "Failed to create udev rule for boot interface renaming."
# Generate config files for networkd
-generate_networkd_config
+generate_networkd_config || \
+ emergency_shell "Failed to generate networkd configuration."
# 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
@@ -178,5 +219,8 @@ generate_networkd_config
NETIF=
[ -n "${BOOTIF_NAME}" ] && NETIF="${BOOTIF_NAME}"
[ -n "${BRIDGED}" ] && [ -n "${BRIDGE_NAME}" ] && NETIF="${BRIDGE_NAME}"
+[ -n "${VLAN}" ] && NETIF="${BOOTIF_NAME}.${VLAN}"
-/sbin/initqueue --finished /lib/systemd/systemd-networkd-wait-online --timeout=10 -i "${NETIF}"
+BB=$(command -v busybox)
+[ -n "${BB}" ] && BB+=" timeout -t 10"
+/sbin/initqueue --finished ${BB} /lib/systemd/systemd-networkd-wait-online -i ${NETIF}
diff --git a/builder/modules.d/systemd-networkd-ext/module-setup.sh b/builder/modules.d/systemd-networkd-ext/module-setup.sh
index fd7dc537..be50973d 100755
--- a/builder/modules.d/systemd-networkd-ext/module-setup.sh
+++ b/builder/modules.d/systemd-networkd-ext/module-setup.sh
@@ -64,7 +64,8 @@ install() {
inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_myhostname.so.*" \
- {"tls/$_arch/",tls/,"$_arch/",}"libnss_resolve.so.*"
+ {"tls/$_arch/",tls/,"$_arch/",}"libnss_resolve.so.*" \
+ {"tls/$_arch/",tls/,"$_arch/",}"libresolve.so.*"
# the hook script that will parse the "ip=" kernel command line
# parameter and generate the .link and .network files needed