From 8f5453c47af12d362ac0298a0ab7ab6ab5e47560 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 26 Mar 2022 23:08:39 +0100 Subject: [PATCH 1/4] feat(network-legacy): Init Wicked static hook Initialize basic hook to apply Wicked based static network configuration from an installed system in a dracut based initramfs using cmdline `ip=wicked-static`. Signed-off-by: Georg Pfuetzenreuter --- modules.d/35network-legacy/ifup.sh | 51 ++++++++++++++++++++- modules.d/35network-legacy/module-setup.sh | 1 + modules.d/35network-legacy/parse-ip-opts.sh | 3 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/modules.d/35network-legacy/ifup.sh b/modules.d/35network-legacy/ifup.sh index 33ffb5af10..19184560f4 100755 --- a/modules.d/35network-legacy/ifup.sh +++ b/modules.d/35network-legacy/ifup.sh @@ -295,6 +295,52 @@ do_ipv6link() { return "$ret" } +# Prepare static IP configuration based on wicked ifcfg +do_wicked_static() { + if [ -e /etc/sysconfig/network/ifcfg-${netif} ] ; then + # Pull in existing interface configuration + . /etc/sysconfig/network/ifcfg-${netif} + + if [ "$BOOTPROTO" = "static" ] ; then + autoconf=${BOOTPROTO} + if [ -n "$IPADDR" ] ; then + local cidr=${IPADDR#*/} + if [ "$cidr" != "$IPADDR" ] ; then + mask=${cidr} + ip=${IPADDR%/*} + elif [ -n "$PREFIXLEN" ] ; then + mask=${PREFIXLEN} + ip=${IPADDR} + fi + [ -n "$GATEWAY" ] && gw=${GATEWAY} + fi + if [ -z "$IPADDR" ] ; then + warn "Blank interface configuration for $netif!" + return 1 + fi + else + warn "Non-static interface configuration for $netif!" + return 1 + fi + fi + + if [ -e /etc/sysconfig/network/config ] ; then + # Pull in existing configuration for name resolution + . /etc/sysconfig/network/config + + if [ -n "$NETCONFIG_DNS_STATIC_SERVERS" ] ; then + for ns in "$NETCONFIG_DNS_STATIC_SERVERS" ; do + echo "nameserver $ns" >> /etc/resolv.conf + done + fi + if [ -n "$NETCONFIG_DNS_STATIC_SEARCHLIST" ] ; then + echo "search $NETCONFIG_DNS_STATIC_SEARCHLIST" >> /etc/resolv.conf + fi + fi + + do_static +} + # Handle static ip configuration do_static() { strglobin "$ip" '*:*:*' && load_ipv6 @@ -657,6 +703,9 @@ for p in $(getargs ip=); do link6) do_ipv6link ;; + wicked-static) + do_wicked_static + ;; *) do_static ;; @@ -732,4 +781,4 @@ if [ -z "$NO_AUTO_DHCP" ] && [ ! -e "/tmp/net.${netif}.up" ]; then fi fi -exit 0 \ No newline at end of file +exit 0 diff --git a/modules.d/35network-legacy/module-setup.sh b/modules.d/35network-legacy/module-setup.sh index 8b8e93ffa0..6e96f03ed9 100755 --- a/modules.d/35network-legacy/module-setup.sh +++ b/modules.d/35network-legacy/module-setup.sh @@ -58,6 +58,7 @@ install() { # SUSE specific files for f in \ + /etc/sysconfig/network/config \ /etc/sysconfig/network/ifcfg-* \ /etc/sysconfig/network/ifroute-* \ /etc/sysconfig/network/routes \ diff --git a/modules.d/35network-legacy/parse-ip-opts.sh b/modules.d/35network-legacy/parse-ip-opts.sh index 19af878965..d86a7831f8 100755 --- a/modules.d/35network-legacy/parse-ip-opts.sh +++ b/modules.d/35network-legacy/parse-ip-opts.sh @@ -84,6 +84,7 @@ for p in $(getargs ip=); do [ -n "$ip" ] \ && die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'" ;; + wicked-static) ;; *) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'" ;; esac done @@ -112,7 +113,7 @@ for p in $(getargs ip=); do [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue # dhcp? (It's simpler to check for a set ip. Checks above ensure that if # ip is there, we're static - [ -z "$ip" ] && continue + [ -z "$ip" -o "$autoopt" = "wicked-static" ] && continue # Not good! die "Server-ip or dhcp for netboot needed, but current arguments say otherwise" fi From 68492ca126516be483898f99a1f9dc0523e578db Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Mon, 28 Mar 2022 16:58:51 +0200 Subject: [PATCH 2/4] feat(network-legacy): Document wicked-static in manual Signed-off-by: Georg Pfuetzenreuter --- man/dracut.cmdline.7.asc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/man/dracut.cmdline.7.asc b/man/dracut.cmdline.7.asc index 23f8b8d844..d624b2a7a7 100644 --- a/man/dracut.cmdline.7.asc +++ b/man/dracut.cmdline.7.asc @@ -580,7 +580,7 @@ module. Other network modules might support a slightly different set of options; refer to the documentation of the specific network module in use. For NetworkManager, see *nm-initrd-generator*(8). -**ip=**__{dhcp|on|any|dhcp6|auto6|either6|link6|single-dhcp}__:: +**ip=**__{dhcp|on|any|dhcp6|auto6|either6|link6|single-dhcp|wicked-static}__:: dhcp|on|any::: get ip from dhcp server from all interfaces. If netroot=dhcp, loop sequentially through all interfaces (eth0, eth1, ...) and use the first with a valid DHCP root-path. @@ -599,6 +599,11 @@ NetworkManager, see *nm-initrd-generator*(8). link6::: bring up interface for IPv6 link-local addressing + wicked-static::: Apply static network configuration from the installed system. + Files from /etc/sysconfig/network/ are copied upon buildtime. Changes require + the initramfs to be rebuilt. + This is a SUSE specific feature. + **ip=**____:__{dhcp|on|any|dhcp6|auto6|link6}__[:[____][:____]]:: This parameter can be specified multiple times. + From d4b75a673bcf66ec6931d8d3a9eb395e537dec26 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Mon, 28 Mar 2022 18:55:49 +0200 Subject: [PATCH 3/4] feat(network-legacy): Add comment + support NETMASK Signed-off-by: Georg Pfuetzenreuter --- modules.d/35network-legacy/ifup.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules.d/35network-legacy/ifup.sh b/modules.d/35network-legacy/ifup.sh index 19184560f4..44d2e413c2 100755 --- a/modules.d/35network-legacy/ifup.sh +++ b/modules.d/35network-legacy/ifup.sh @@ -304,6 +304,7 @@ do_wicked_static() { if [ "$BOOTPROTO" = "static" ] ; then autoconf=${BOOTPROTO} if [ -n "$IPADDR" ] ; then + # respect netmask priority described in ifcfg(5) local cidr=${IPADDR#*/} if [ "$cidr" != "$IPADDR" ] ; then mask=${cidr} @@ -311,6 +312,9 @@ do_wicked_static() { elif [ -n "$PREFIXLEN" ] ; then mask=${PREFIXLEN} ip=${IPADDR} + elif [ -n "$NETMASK" ] ; then + mask=${NETMASK} + ip=${IPADDR} fi [ -n "$GATEWAY" ] && gw=${GATEWAY} fi From 8f7d488b74d211fded9b3fd3fca0933ff6160757 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Tue, 29 Mar 2022 01:52:47 +0200 Subject: [PATCH 4/4] feat(network-legacy): Unset variables first Signed-off-by: Georg Pfuetzenreuter --- modules.d/35network-legacy/ifup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules.d/35network-legacy/ifup.sh b/modules.d/35network-legacy/ifup.sh index 44d2e413c2..e4e6b54f30 100755 --- a/modules.d/35network-legacy/ifup.sh +++ b/modules.d/35network-legacy/ifup.sh @@ -297,6 +297,9 @@ do_ipv6link() { # Prepare static IP configuration based on wicked ifcfg do_wicked_static() { + unset BOOTPROTO IPADDR PREFIXLEN NETMASK GATEWAY NETCONFIG_DNS_STATIC_SERVERS NETCONFIG_DNS_STATIC_SEARCHLIST \ + autoconf ip mask + if [ -e /etc/sysconfig/network/ifcfg-${netif} ] ; then # Pull in existing interface configuration . /etc/sysconfig/network/ifcfg-${netif}