]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(systemd-networkd): add support for proper netroot invocation
authorTimo Rothenpieler <timo@rothenpieler.org>
Fri, 21 Jun 2024 15:29:06 +0000 (17:29 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Sat, 22 Jun 2024 21:25:15 +0000 (17:25 -0400)
.github/workflows/integration.yml
modules.d/01systemd-networkd/99-default.network [new file with mode: 0644]
modules.d/01systemd-networkd/99-wait-online-dracut.conf [new file with mode: 0644]
modules.d/01systemd-networkd/module-setup.sh
modules.d/01systemd-networkd/networkd-config.sh [new file with mode: 0755]
modules.d/01systemd-networkd/networkd-run.sh [new file with mode: 0755]

index d1f211790c3c5c2e8144f7724d604514e3d13068..bde1cc5379a0046d0e237bbdc3d304d271cec8cf 100644 (file)
@@ -109,14 +109,22 @@ jobs:
             matrix:
                 container: [
                         "arch",
+                        "gentoo",
                 ]
                 network: [
                         "systemd-networkd",
                 ]
                 test: [
+                        "20",
+                        "30",
                         "35",
                         "40",
                 ]
+                exclude:
+                  - container: "arch"
+                    test: "20"
+                  - container: "gentoo"
+                    test: "40"
             fail-fast: false
         container:
             image: ghcr.io/dracut-ng/${{ matrix.container }}
diff --git a/modules.d/01systemd-networkd/99-default.network b/modules.d/01systemd-networkd/99-default.network
new file mode 100644 (file)
index 0000000..d4fe15c
--- /dev/null
@@ -0,0 +1,13 @@
+[Match]
+Kind=!*
+Type=!loopback
+
+[Network]
+DHCP=yes
+
+[DHCPv4]
+ClientIdentifier=mac
+RequestOptions=17
+
+[DHCPv6]
+RequestOptions=59 60
diff --git a/modules.d/01systemd-networkd/99-wait-online-dracut.conf b/modules.d/01systemd-networkd/99-wait-online-dracut.conf
new file mode 100644 (file)
index 0000000..da90596
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Before=dracut-initqueue.service
+ConditionPathExists=/run/networkd/initrd/neednet
+
+[Service]
+TimeoutStartSec=120
+
+[Install]
+WantedBy=initrd.target
index ccc9133d8e06c5abc5fde9500e114dca491f695b..bbd9e4a63c85d46cfb2c7a772f29d16ad9a383e5 100755 (executable)
@@ -57,7 +57,16 @@ install() {
         "$systemdsystemunitdir"/systemd-networkd-wait-online.service \
         "$systemdsystemunitdir"/systemd-networkd-wait-online@.service \
         "$systemdsystemunitdir"/systemd-network-generator.service \
-        ip
+        ip sed grep
+
+    inst_simple "$moddir"/99-wait-online-dracut.conf \
+        "$systemdsystemunitdir"/systemd-networkd-wait-online.service.d/99-dracut.conf
+
+    inst_simple "$moddir"/99-default.network \
+        "$systemdnetworkconfdir"/99-default.network
+
+    inst_hook cmdline 99 "$moddir"/networkd-config.sh
+    inst_hook initqueue/settled 99 "$moddir"/networkd-run.sh
 
     # Enable systemd type units
     for i in \
diff --git a/modules.d/01systemd-networkd/networkd-config.sh b/modules.d/01systemd-networkd/networkd-config.sh
new file mode 100755 (executable)
index 0000000..809fc0e
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+type getcmdline > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+# Just in case we're running before it
+systemctl start systemd-network-generator.service
+
+# Customizations for systemd-network-generator generated networks.
+# We need to request certain DHCP options, and there is no way to
+# tell the generator to add those.
+for f in /run/systemd/network/*.network; do
+    [ -f "$f" ] || continue
+
+    {
+        echo "[DHCPv4]"
+        echo "ClientIdentifier=mac"
+        echo "RequestOptions=17"
+        echo "[DHCPv6]"
+        echo "RequestOptions=59 60"
+    } >> "$f"
+done
+
+# Just in case networkd was already running
+systemctl try-reload-or-restart systemd-networkd.service
+
+if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
+    echo rd.neednet >> /etc/cmdline.d/networkd.conf
+fi
+
+if getargbool 0 rd.neednet; then
+    mkdir -p /run/networkd/initrd
+    : > /run/networkd/initrd/neednet
+fi
diff --git a/modules.d/01systemd-networkd/networkd-run.sh b/modules.d/01systemd-networkd/networkd-run.sh
new file mode 100755 (executable)
index 0000000..5445b46
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+type source_hook > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+for ifpath in /sys/class/net/*; do
+    ifname="$(basename "$ifpath")"
+
+    # shellcheck disable=SC2015
+    [ "$ifname" != "lo" ] && [ -e "$ifpath" ] && [ ! -e /tmp/networkd."$ifname".done ] || continue
+
+    if /usr/lib/systemd/systemd-networkd-wait-online --timeout=0.000001 --interface="$ifname" 2> /dev/null; then
+        leases_file="/run/systemd/netif/leases/$(cat "$ifpath"/ifindex)"
+        dhcpopts_file="/tmp/dhclient.${ifname}.dhcpopts"
+        if [ -r "$leases_file" ]; then
+            grep -E "^(NEXT_SERVER|ROOT_PATH)=" "$leases_file" \
+                | sed -e "s/NEXT_SERVER=/new_next_server='/" \
+                    -e "s/ROOT_PATH=/new_root_path='/" \
+                    -e "s/$/'/" > "$dhcpopts_file" || true
+        fi
+
+        source_hook initqueue/online "$ifname"
+        /sbin/netroot "$ifname"
+
+        : > /tmp/networkd."$ifname".done
+    fi
+done