summaryrefslogtreecommitdiffstats
path: root/modules.d/01systemd-networkd
diff options
context:
space:
mode:
Diffstat (limited to 'modules.d/01systemd-networkd')
-rw-r--r--modules.d/01systemd-networkd/99-default.network13
-rw-r--r--modules.d/01systemd-networkd/99-wait-online-dracut.conf9
-rwxr-xr-xmodules.d/01systemd-networkd/module-setup.sh19
-rwxr-xr-xmodules.d/01systemd-networkd/networkd-config.sh36
-rwxr-xr-xmodules.d/01systemd-networkd/networkd-run.sh26
5 files changed, 98 insertions, 5 deletions
diff --git a/modules.d/01systemd-networkd/99-default.network b/modules.d/01systemd-networkd/99-default.network
new file mode 100644
index 0000000..d4fe15c
--- /dev/null
+++ b/modules.d/01systemd-networkd/99-default.network
@@ -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
index 0000000..da90596
--- /dev/null
+++ b/modules.d/01systemd-networkd/99-wait-online-dracut.conf
@@ -0,0 +1,9 @@
+[Unit]
+Before=dracut-initqueue.service
+ConditionPathExists=/run/networkd/initrd/neednet
+
+[Service]
+TimeoutStartSec=120
+
+[Install]
+WantedBy=initrd.target
diff --git a/modules.d/01systemd-networkd/module-setup.sh b/modules.d/01systemd-networkd/module-setup.sh
index 3658882..007590b 100755
--- a/modules.d/01systemd-networkd/module-setup.sh
+++ b/modules.d/01systemd-networkd/module-setup.sh
@@ -22,7 +22,7 @@ check() {
depends() {
# This module has external dependency on other module(s).
- echo kernel-network-modules systemd-sysusers
+ echo kernel-network-modules systemd-sysusers systemd
# Return 0 to include the dependent module(s) in the initramfs.
return 0
@@ -31,6 +31,8 @@ depends() {
# Install the required file(s) and directories for the module in the initramfs.
install() {
+ inst_sysusers systemd-network.conf
+
inst_multiple -o \
"$tmpfilesdir"/systemd-network.conf \
"$dbussystem"/org.freedesktop.network1.conf \
@@ -55,8 +57,16 @@ install() {
"$systemdsystemunitdir"/systemd-networkd-wait-online.service \
"$systemdsystemunitdir"/systemd-networkd-wait-online@.service \
"$systemdsystemunitdir"/systemd-network-generator.service \
- "$sysusers"/systemd-network.conf \
- 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-dracut-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 \
@@ -82,7 +92,6 @@ install() {
"$systemdsystemconfdir"/systemd-networkd-wait-online.service \
"$systemdsystemconfdir/systemd-networkd-wait-online.service.d/*.conf" \
"$systemdsystemconfdir"/systemd-networkd-wait-online@.service \
- "$systemdsystemconfdir/systemd-networkd-wait-online@.service.d/*.conf" \
- "$sysusersconfdir"/systemd-network.conf
+ "$systemdsystemconfdir/systemd-networkd-wait-online@.service.d/*.conf"
fi
}
diff --git a/modules.d/01systemd-networkd/networkd-config.sh b/modules.d/01systemd-networkd/networkd-config.sh
new file mode 100755
index 0000000..eb450c6
--- /dev/null
+++ b/modules.d/01systemd-networkd/networkd-config.sh
@@ -0,0 +1,36 @@
+#!/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"
+
+ # Remove the default network if at least one was generated
+ rm -f "$systemdnetworkconfdir"/99-dracut-default.network
+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
index 0000000..5445b46
--- /dev/null
+++ b/modules.d/01systemd-networkd/networkd-run.sh
@@ -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