From: Jonas Jelten Date: Sat, 27 Feb 2021 11:45:15 +0000 (+0100) Subject: feat(nbd): support ipv6 link local nbds X-Git-Tag: 054~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b12f8188a4ffac312694ebd48a5c99ba885e6467;p=thirdparty%2Fdracut.git feat(nbd): support ipv6 link local nbds --- diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc index e1b67b1c6..35a17c249 100644 --- a/dracut.cmdline.7.asc +++ b/dracut.cmdline.7.asc @@ -575,7 +575,7 @@ USB Android phone:: * enp0s29u1u2 ===================== -**ip=**__{dhcp|on|any|dhcp6|auto6|either6|single-dhcp}__:: +**ip=**__{dhcp|on|any|dhcp6|auto6|either6|link6|single-dhcp}__:: dhcp|on|any::: get ip from dhcp server from all interfaces. If root=dhcp, loop sequentially through all interfaces (eth0, eth1, ...) and use the first with a valid DHCP root-path. @@ -592,12 +592,15 @@ USB Android phone:: either6::: if auto6 fails, then dhcp6 -**ip=**____:__{dhcp|on|any|dhcp6|auto6}__[:[____][:____]]:: + link6::: bring up interface for IPv6 link-local addressing + +**ip=**____:__{dhcp|on|any|dhcp6|auto6|link6}__[:[____][:____]]:: This parameter can be specified multiple times. + ===================== dhcp|on|any|dhcp6::: get ip from dhcp server on a specific interface auto6::: do IPv6 autoconfiguration +link6::: bring up interface for IPv6 link local address ::: optionally **set** on the . This cannot be used in conjunction with the **ifname** argument for the same . diff --git a/modules.d/35network-legacy/ifup.sh b/modules.d/35network-legacy/ifup.sh index 3509d7a95..aae979f6f 100755 --- a/modules.d/35network-legacy/ifup.sh +++ b/modules.d/35network-legacy/ifup.sh @@ -123,6 +123,19 @@ do_ipv6auto() { return $ret } +do_ipv6link() { + local ret + load_ipv6 + echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding + echo 0 > /proc/sys/net/ipv6/conf/$netif/accept_ra + echo 0 > /proc/sys/net/ipv6/conf/$netif/accept_redirects + linkup $netif + + [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname + + return $ret +} + # Handle static ip configuration do_static() { strglobin $ip '*:*:*' && load_ipv6 @@ -449,6 +462,8 @@ for p in $(getargs ip=); do do_ipv6auto ;; either6) do_ipv6auto || do_dhcp -6 ;; + link6) + do_ipv6link ;; *) do_static ;; esac diff --git a/modules.d/35network-legacy/parse-ip-opts.sh b/modules.d/35network-legacy/parse-ip-opts.sh index 5a9f71f54..a93fbd90c 100755 --- a/modules.d/35network-legacy/parse-ip-opts.sh +++ b/modules.d/35network-legacy/parse-ip-opts.sh @@ -75,7 +75,7 @@ for p in $(getargs ip=); do [ -z "$mask" ] && \ die "Sorry, automatic calculation of netmask is not yet supported" ;; - auto6);; + auto6|link6);; either6);; dhcp|dhcp6|on|any|single-dhcp) \ [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \ diff --git a/modules.d/95nbd/nbd-generator.sh b/modules.d/95nbd/nbd-generator.sh index dccdacf70..5dc7dea97 100755 --- a/modules.d/95nbd/nbd-generator.sh +++ b/modules.d/95nbd/nbd-generator.sh @@ -14,7 +14,13 @@ GENERATOR_DIR="$2" ROOTFLAGS="$(getarg rootflags)" nroot=${root#nbd:} -nbdserver=${nroot%%:*}; nroot=${nroot#*:} +nbdserver=${nroot%%:*}; +if [ "${nbdserver%"${nbdserver#?}"}" = "[" ]; then + nbdserver=${nroot#[} + nbdserver=${nbdserver%%]:*}\]; nroot=${nroot#*]:} +else + nroot=${nroot#*:} +fi nbdport=${nroot%%:*}; nroot=${nroot#*:} nbdfstype=${nroot%%:*}; nroot=${nroot#*:} nbdflags=${nroot%%:*} diff --git a/modules.d/95nbd/nbdroot.sh b/modules.d/95nbd/nbdroot.sh index 7057f2332..6d6d47768 100755 --- a/modules.d/95nbd/nbdroot.sh +++ b/modules.d/95nbd/nbdroot.sh @@ -22,7 +22,13 @@ NEWROOT="$3" [ "${nroot%%:*}" = "nbd" ] || return nroot=${nroot#nbd:} -nbdserver=${nroot%%:*}; nroot=${nroot#*:} +nbdserver=${nroot%%:*}; +if [ "${nbdserver%"${nbdserver#?}"}" = "[" ]; then + nbdserver=${nroot#[} + nbdserver=${nbdserver%%]:*}; nroot=${nroot#*]:} +else + nroot=${nroot#*:} +fi nbdport=${nroot%%:*}; nroot=${nroot#*:} nbdfstype=${nroot%%:*}; nroot=${nroot#*:} nbdflags=${nroot%%:*} @@ -91,29 +97,37 @@ done # If we didn't get a root= on the command line, then we need to # add the udev rules for mounting the nbd0 device if [ "$root" = "block:/dev/root" -o "$root" = "dhcp" ]; then - printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-nbd-root.rules + printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' > /etc/udev/rules.d/99-nbd-root.rules udevadm control --reload - type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh - write_fs_tab /dev/root "$nbdfstype" "$fsopts" wait_for_dev -n /dev/root if [ -z "$DRACUT_SYSTEMD" ]; then + type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh + + write_fs_tab /dev/root "$nbdfstype" "$fsopts" + printf '/bin/mount %s\n' \ "$NEWROOT" \ > $hookdir/mount/01-$$-nbd.sh fi + # if we're on systemd, use the nbd-generator script + # to create the /sysroot mount. fi +# supported since nbd 3.8 via 77e97612 if strstr "$(nbd-client --help 2>&1)" "systemd-mark"; then - preopts="--systemd-mark $preopts" + preopts="-systemd-mark $preopts" fi if [ "$nbdport" -gt 0 ] 2>/dev/null; then - nbd-client "$nbdserver" $nbdport /dev/nbd0 $preopts $opts || exit 1 + nbdport="$nbdport" else - nbd-client -name "$nbdport" "$nbdserver" /dev/nbd0 $preopts $opts || exit 1 + nbdport="-name $nbdport" fi +nbd-client -check /dev/nbd0 >/dev/null || \ + nbd-client "$nbdserver" $nbdport /dev/nbd0 $preopts $opts || exit 1 + # NBD doesn't emit uevents when it gets connected, so kick it echo change > /sys/block/nbd0/uevent udevadm settle diff --git a/modules.d/95nbd/parse-nbdroot.sh b/modules.d/95nbd/parse-nbdroot.sh index d9e4bc67f..a11a365fa 100755 --- a/modules.d/95nbd/parse-nbdroot.sh +++ b/modules.d/95nbd/parse-nbdroot.sh @@ -9,18 +9,6 @@ # root= takes precedence over netroot= if root=nbd[...] # -# Sadly there's no easy way to split ':' separated lines into variables -netroot_to_var() { - local v=${1}: - set -- - while [ -n "$v" ]; do - set -- "$@" "${v%%:*}" - v=${v#*:} - done - - unset server port - server=$2; port=$3; -} # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) @@ -46,13 +34,18 @@ fi [ "${netroot%%:*}" = "nbd" ] || return -#if [ -n "${DRACUT_SYSTEMD}" ] && [ "$root" = "dhcp" ]; then -# echo "root=$netroot" > /etc/cmdline.d/root.conf -# systemctl --no-block daemon-reload -#fi - # Check required arguments -netroot_to_var $netroot +nroot=${netroot#nbd:} +server=${nroot%%:*}; +if [ "${server%"${server#?}"}" = "[" ]; then + server=${nroot#[} + server=${server%%]:*}\]; nroot=${nroot#*]:} +else + nroot=${nroot#*:} +fi +port=${nroot%%:*} +unset nroot + [ -z "$server" ] && die "Argument server for nbdroot is missing" [ -z "$port" ] && die "Argument port for nbdroot is missing" @@ -65,6 +58,6 @@ rootok=1 # Shut up init error check if [ -z "$root" ]; then root=block:/dev/root - wait_for_dev -n /dev/root + # the device is created and waited for in ./nbdroot.sh fi diff --git a/modules.d/99fs-lib/fs-lib.sh b/modules.d/99fs-lib/fs-lib.sh index 11e795d9c..987696deb 100755 --- a/modules.d/99fs-lib/fs-lib.sh +++ b/modules.d/99fs-lib/fs-lib.sh @@ -247,7 +247,11 @@ write_fs_tab() { fi fi - echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab + if grep -q "$_root /sysroot" /etc/fstab; then + echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab + else + return + fi if type systemctl >/dev/null 2>/dev/null; then systemctl daemon-reload