Skip to content

Commit b12f818

Browse files
TheJJjohannbg
authored andcommitted
feat(nbd): support ipv6 link local nbds
1 parent 7c0bc0b commit b12f818

File tree

7 files changed

+66
-31
lines changed

7 files changed

+66
-31
lines changed

dracut.cmdline.7.asc

+5-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ USB Android phone::
575575
* enp0s29u1u2
576576
=====================
577577
578-
**ip=**__{dhcp|on|any|dhcp6|auto6|either6|single-dhcp}__::
578+
**ip=**__{dhcp|on|any|dhcp6|auto6|either6|link6|single-dhcp}__::
579579
dhcp|on|any::: get ip from dhcp server from all interfaces. If root=dhcp,
580580
loop sequentially through all interfaces (eth0, eth1, ...) and use the first
581581
with a valid DHCP root-path.
@@ -592,12 +592,15 @@ USB Android phone::
592592
593593
either6::: if auto6 fails, then dhcp6
594594
595-
**ip=**__<interface>__:__{dhcp|on|any|dhcp6|auto6}__[:[__<mtu>__][:__<macaddr>__]]::
595+
link6::: bring up interface for IPv6 link-local addressing
596+
597+
**ip=**__<interface>__:__{dhcp|on|any|dhcp6|auto6|link6}__[:[__<mtu>__][:__<macaddr>__]]::
596598
This parameter can be specified multiple times.
597599
+
598600
=====================
599601
dhcp|on|any|dhcp6::: get ip from dhcp server on a specific interface
600602
auto6::: do IPv6 autoconfiguration
603+
link6::: bring up interface for IPv6 link local address
601604
<macaddr>::: optionally **set** <macaddr> on the <interface>. This
602605
cannot be used in conjunction with the **ifname** argument for the
603606
same <interface>.

modules.d/35network-legacy/ifup.sh

+15
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ do_ipv6auto() {
123123
return $ret
124124
}
125125

126+
do_ipv6link() {
127+
local ret
128+
load_ipv6
129+
echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding
130+
echo 0 > /proc/sys/net/ipv6/conf/$netif/accept_ra
131+
echo 0 > /proc/sys/net/ipv6/conf/$netif/accept_redirects
132+
linkup $netif
133+
134+
[ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
135+
136+
return $ret
137+
}
138+
126139
# Handle static ip configuration
127140
do_static() {
128141
strglobin $ip '*:*:*' && load_ipv6
@@ -449,6 +462,8 @@ for p in $(getargs ip=); do
449462
do_ipv6auto ;;
450463
either6)
451464
do_ipv6auto || do_dhcp -6 ;;
465+
link6)
466+
do_ipv6link ;;
452467
*)
453468
do_static ;;
454469
esac

modules.d/35network-legacy/parse-ip-opts.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for p in $(getargs ip=); do
7575
[ -z "$mask" ] && \
7676
die "Sorry, automatic calculation of netmask is not yet supported"
7777
;;
78-
auto6);;
78+
auto6|link6);;
7979
either6);;
8080
dhcp|dhcp6|on|any|single-dhcp) \
8181
[ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \

modules.d/95nbd/nbd-generator.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ GENERATOR_DIR="$2"
1414
ROOTFLAGS="$(getarg rootflags)"
1515

1616
nroot=${root#nbd:}
17-
nbdserver=${nroot%%:*}; nroot=${nroot#*:}
17+
nbdserver=${nroot%%:*};
18+
if [ "${nbdserver%"${nbdserver#?}"}" = "[" ]; then
19+
nbdserver=${nroot#[}
20+
nbdserver=${nbdserver%%]:*}\]; nroot=${nroot#*]:}
21+
else
22+
nroot=${nroot#*:}
23+
fi
1824
nbdport=${nroot%%:*}; nroot=${nroot#*:}
1925
nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
2026
nbdflags=${nroot%%:*}

modules.d/95nbd/nbdroot.sh

+21-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ NEWROOT="$3"
2222
[ "${nroot%%:*}" = "nbd" ] || return
2323

2424
nroot=${nroot#nbd:}
25-
nbdserver=${nroot%%:*}; nroot=${nroot#*:}
25+
nbdserver=${nroot%%:*};
26+
if [ "${nbdserver%"${nbdserver#?}"}" = "[" ]; then
27+
nbdserver=${nroot#[}
28+
nbdserver=${nbdserver%%]:*}; nroot=${nroot#*]:}
29+
else
30+
nroot=${nroot#*:}
31+
fi
2632
nbdport=${nroot%%:*}; nroot=${nroot#*:}
2733
nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
2834
nbdflags=${nroot%%:*}
@@ -91,29 +97,37 @@ done
9197
# If we didn't get a root= on the command line, then we need to
9298
# add the udev rules for mounting the nbd0 device
9399
if [ "$root" = "block:/dev/root" -o "$root" = "dhcp" ]; then
94-
printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-nbd-root.rules
100+
printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' > /etc/udev/rules.d/99-nbd-root.rules
95101
udevadm control --reload
96-
type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh
97-
write_fs_tab /dev/root "$nbdfstype" "$fsopts"
98102
wait_for_dev -n /dev/root
99103

100104
if [ -z "$DRACUT_SYSTEMD" ]; then
105+
type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh
106+
107+
write_fs_tab /dev/root "$nbdfstype" "$fsopts"
108+
101109
printf '/bin/mount %s\n' \
102110
"$NEWROOT" \
103111
> $hookdir/mount/01-$$-nbd.sh
104112
fi
113+
# if we're on systemd, use the nbd-generator script
114+
# to create the /sysroot mount.
105115
fi
106116

117+
# supported since nbd 3.8 via 77e97612
107118
if strstr "$(nbd-client --help 2>&1)" "systemd-mark"; then
108-
preopts="--systemd-mark $preopts"
119+
preopts="-systemd-mark $preopts"
109120
fi
110121

111122
if [ "$nbdport" -gt 0 ] 2>/dev/null; then
112-
nbd-client "$nbdserver" $nbdport /dev/nbd0 $preopts $opts || exit 1
123+
nbdport="$nbdport"
113124
else
114-
nbd-client -name "$nbdport" "$nbdserver" /dev/nbd0 $preopts $opts || exit 1
125+
nbdport="-name $nbdport"
115126
fi
116127

128+
nbd-client -check /dev/nbd0 >/dev/null || \
129+
nbd-client "$nbdserver" $nbdport /dev/nbd0 $preopts $opts || exit 1
130+
117131
# NBD doesn't emit uevents when it gets connected, so kick it
118132
echo change > /sys/block/nbd0/uevent
119133
udevadm settle

modules.d/95nbd/parse-nbdroot.sh

+12-19
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
# root= takes precedence over netroot= if root=nbd[...]
1010
#
1111

12-
# Sadly there's no easy way to split ':' separated lines into variables
13-
netroot_to_var() {
14-
local v=${1}:
15-
set --
16-
while [ -n "$v" ]; do
17-
set -- "$@" "${v%%:*}"
18-
v=${v#*:}
19-
done
20-
21-
unset server port
22-
server=$2; port=$3;
23-
}
2412

2513
# This script is sourced, so root should be set. But let's be paranoid
2614
[ -z "$root" ] && root=$(getarg root=)
@@ -46,13 +34,18 @@ fi
4634
[ "${netroot%%:*}" = "nbd" ] || return
4735

4836

49-
#if [ -n "${DRACUT_SYSTEMD}" ] && [ "$root" = "dhcp" ]; then
50-
# echo "root=$netroot" > /etc/cmdline.d/root.conf
51-
# systemctl --no-block daemon-reload
52-
#fi
53-
5437
# Check required arguments
55-
netroot_to_var $netroot
38+
nroot=${netroot#nbd:}
39+
server=${nroot%%:*};
40+
if [ "${server%"${server#?}"}" = "[" ]; then
41+
server=${nroot#[}
42+
server=${server%%]:*}\]; nroot=${nroot#*]:}
43+
else
44+
nroot=${nroot#*:}
45+
fi
46+
port=${nroot%%:*}
47+
unset nroot
48+
5649
[ -z "$server" ] && die "Argument server for nbdroot is missing"
5750
[ -z "$port" ] && die "Argument port for nbdroot is missing"
5851

@@ -65,6 +58,6 @@ rootok=1
6558
# Shut up init error check
6659
if [ -z "$root" ]; then
6760
root=block:/dev/root
68-
wait_for_dev -n /dev/root
61+
# the device is created and waited for in ./nbdroot.sh
6962
fi
7063

modules.d/99fs-lib/fs-lib.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,11 @@ write_fs_tab() {
247247
fi
248248
fi
249249
250-
echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab
250+
if grep -q "$_root /sysroot" /etc/fstab; then
251+
echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab
252+
else
253+
return
254+
fi
251255
252256
if type systemctl >/dev/null 2>/dev/null; then
253257
systemctl daemon-reload

0 commit comments

Comments
 (0)