summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2017-10-18 17:32:23 +0200
committerJonathan Bauer2017-10-18 17:32:23 +0200
commit6842b8ca294a2535919cb6ffdadb2e9b30a68894 (patch)
tree09c4fb8867ecce9d5b5f00930ac38e5026a90323
parentremove dep on busybox (diff)
downloadsystemd-init-6842b8ca294a2535919cb6ffdadb2e9b30a68894.tar.gz
systemd-init-6842b8ca294a2535919cb6ffdadb2e9b30a68894.tar.xz
systemd-init-6842b8ca294a2535919cb6ffdadb2e9b30a68894.zip
[systemd-networkd-ext] support for bridged
* various fixes/improvements for bridged mode * will copy over the config to stage4 before switch_root and switch to DHCP on the PXE interface * will keep the parsed info in /run/openslx/pxe-network.conf for later use (instead of parsing it multiple times...) * bridged is still defined by BRIDGED in parse-kcl hook which should change * still has workarounds for hostname/dns/search as this is not yet fully working using systemd-networkd/resolved
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh50
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh1
-rw-r--r--builder/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh60
3 files changed, 82 insertions, 29 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 a0e876a4..6c9db9b4 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,25 +3,43 @@
# 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.
-mkdir -p "$NEWROOT/etc/systemd/network/"
-new_network_conf="$NEWROOT/etc/systemd/network/10-pxe-interface.network"
-echo '[Match]' > $new_network_conf
-grep "MACAddress=" /etc/systemd/network/*boot*.network >> $new_network_conf
-echo '' >> $new_network_conf
-echo '[Network]' >> $new_network_conf
-echo 'DHCP=ipv4' >> $new_network_conf
-grep "Domains=" /etc/systemd/network/*boot*.network >> $new_network_conf
-echo '' >> $new_network_conf
-echo '[DHCP]' >> $new_network_conf
-echo 'UseDNS=true' >> $new_network_conf
-echo 'UseDomains=true' >> $new_network_conf
-echo 'UseHostname=true' >> $new_network_conf
-echo 'CriticalConnection=true' >> $new_network_conf
+
+. "/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"
+
+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
+
+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
+
+# Copy bridge config too, if bridged
+[ -n "${SLX_BRIDGE}" ] && cp ${BRIDGE_CONF} ${NEWROOT_NETWORKD_DIR}
# Similarly, UseHostname seems to have no effect, so work around for now...
-cat /proc/sys/kernel/hostname > $NEWROOT/etc/hostname
+[ -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 9510c8d3..ad8d77a1 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
@@ -10,7 +10,6 @@ mkdir -p "${new_sysinit_wants}"
for unit in \
systemd-networkd.socket \
systemd-networkd.service \
- systemd-networkd-wait-online.service \
systemd-resolved.service
do
service_path="$(systemctl show -p FragmentPath $unit | cut -c 14-)"
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 44427e23..67bc50f5 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
@@ -10,7 +10,7 @@ command -v getarg >/dev/null || . /lib/dracut-lib.sh
# TODO could be configurable from the KCL
declare -rg BOOTIF_NAME="boot0"
declare -rg BRIDGE_NAME="br0"
-#declare -rg BRIDGED="bridged"
+declare -rg BRIDGED="bridged"
# Get all the ip-related arguments from the KCL
parse_kernel_command_line() {
@@ -32,6 +32,7 @@ parse_kernel_command_line() {
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
+
# Taken from parse-ip-opts.sh: Convert the netmask to CIDR notation
declare -g CIDR
if [[ "x$NETMASK" =~ ^x[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
@@ -52,12 +53,34 @@ parse_kernel_command_line() {
# KCL "domain"
declare -rg DOMAIN="$(getarg domain=)"
}
+
+# Dumps the parsed IP configuration to /run/openslx/pxe-network.conf
+# Creates a list of "KEY=value" type variables to source later on
+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=
+ 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
print_static_ip_conf() {
@@ -72,23 +95,31 @@ print_static_ip_conf() {
create_udev_bootif_name_rule() {
[ -z "${BOOTIF}" ] && echo "No BOOTIF set, was it present in the kernel command line?" && return 1
# priority 70 < 80-net-name-slot.rules.
- echo 'SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="'${BOOTIF}'", NAME="'${BOOTIF_NAME}'"' > /etc/udev/rules.d/70-pxe-boot-interface.rules
+ echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'${BOOTIF}'", NAME="'${BOOTIF_NAME}'"' > /etc/udev/rules.d/70-pxe-boot-interface.rules
}
## Generate network and link file(s) for networkd
# Checks if an IP configuration was forwarded by
generate_networkd_config() {
mkdir -p "/etc/systemd/network"
- local BOOTIF_NETWORK_CONF="/etc/systemd/network/01-boot-lan.network"
- print_match_mac "${BOOTIF}" > "${BOOTIF_NETWORK_CONF}"
+ 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}" >> "${BOOTIF_NETWORK_CONF}"
+ echo "Bridge=${BRIDGE_NAME}"
elif [ -n "${CLIENT_IP}" -a -n "${GATEWAY_IP}" ]; then
- print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}" >> "${BOOTIF_NETWORK_CONF}"
+ print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
else
- echo "DHCP=ipv4" >> "${BRIDGE_IF_CONF}"
- fi
+ echo "DHCP=ipv4"
+ fi >> "${BOOTIF_NETWORK_CONF}"
# we're done unless running in bridged mode
[ -n "${BRIDGED}" ] || return 0
@@ -97,17 +128,18 @@ generate_networkd_config() {
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}" >> "${BRIDGE_NETWORK_CONF}"
+ print_static_ip_conf "${CLIENT_IP}/${CIDR:-24}" "${GATEWAY_IP}"
else
# bad/no IP info, fallback to DHCP
- echo "DHCP=ipv4" >> "${BRIDGE_NETWORK_CONF}"
- fi
+ echo "DHCP=ipv4"
+ fi >> "${BRIDGE_NETWORK_CONF}"
return 0
}
# from parse-ip-opts.sh
@@ -131,6 +163,9 @@ mask2cidr() {
# Get IP config from KCL
parse_kernel_command_line
+# Save IP config for later use
+save_ip_config
+
# Create the udev rule to rename the boot interface to the declared BOOTIF_NAME
create_udev_bootif_name_rule
@@ -143,4 +178,5 @@ generate_networkd_config
NETIF=
[ -n "${BOOTIF_NAME}" ] && NETIF="${BOOTIF_NAME}"
[ -n "${BRIDGED}" ] && [ -n "${BRIDGE_NAME}" ] && NETIF="${BRIDGE_NAME}"
-/sbin/initqueue --finished /lib/systemd/systemd-networkd-wait-online -i "${NETIF}"
+
+/sbin/initqueue --finished /lib/systemd/systemd-networkd-wait-online --timeout=10 -i "${NETIF}"