2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

fix(netboot): an IPv6-only diskless node boots with no address

xcatroot writes the netplan of the booted system from the interface it found,
and it always wrote "dhcp4: true". An IPv6-only node has no DHCPv4 server, so it
reached its login prompt with no address: Ubuntu 24.04.5 reported
"[FAILED] Failed to start systemd-networkd-w... Wait for Network to be
Configured." and "[FAILED] Failed to start xcatpostinit.service", and the node
answered no ssh.

The address is already on the kernel command line, in the static form dracut
takes. xcat_static_ip6_fields reads it and the netplan carries the address, the
prefix and a default route through the gateway. A node whose command line holds
an IPv4 form keeps dhcp4, because the fields are read only from a bracketed
literal.

Captured by xCAT-test/bats/ipv6_xcatroot_netplan.bats. Reading the fields by
cutting on the first colon, which is what an IPv6 literal breaks, fails the
three parsing assertions and leaves the four refusals passing.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-29 16:01:34 -03:00
parent 77eaf4d53c
commit cd67199463
2 changed files with 148 additions and 0 deletions
@@ -1,4 +1,46 @@
#!/bin/sh
# xcat_static_ip6_fields <ip= parameter> -- print "<address> <prefix> <gateway>" for the
# static IPv6 form dracut takes, client:peer:gateway:prefix:hostname:interface:autoconf.
#
# An IPv6 literal carries colons, so the fields cannot be cut on a colon: dracut brackets
# the address and the gateway, and the brackets are what delimits them.
xcat_static_ip6_fields()
{
local spec addr rest gw prefix
spec="${1#ip=}"
case "$spec" in
\[*) ;;
*) return 1 ;;
esac
addr="${spec#\[}"
addr="${addr%%\]*}"
rest="${spec#*\]:}"
# peer, which xCAT never sets
rest="${rest#*:}"
case "$rest" in
\[*)
gw="${rest#\[}"
gw="${gw%%\]*}"
rest="${rest#*\]:}"
;;
*)
gw=""
rest="${rest#*:}"
;;
esac
prefix="${rest%%:*}"
[ -n "$addr" ] || return 1
case "$prefix" in
''|*[!0-9]*) return 1 ;;
esac
printf '%s %s %s\n' "$addr" "$prefix" "$gw"
}
NEWROOT=$3
RWDIR=.statelite
XCATMASTER=$XCAT
@@ -264,8 +306,45 @@ if [ -z $STATEMNT ]; then
fi
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
# The booted system takes the address the node was given on the kernel command line
# when that address is IPv6. dhcp4 leaves an IPv6-only node with no address at all, and
# systemd-networkd-wait-online then fails.
XCAT_IP6_FIELDS=""
for xcat_cmdline_word in $(cat /proc/cmdline); do
case "$xcat_cmdline_word" in
ip=\[*)
XCAT_IP6_FIELDS=$(xcat_static_ip6_fields "$xcat_cmdline_word") || XCAT_IP6_FIELDS=""
break
;;
esac
done
if [ -x $NEWROOT/usr/sbin/netplan ]; then
mkdir -p $NEWROOT/etc/netplan
if [ -n "$XCAT_IP6_FIELDS" ]; then
set -- $XCAT_IP6_FIELDS
XCAT_IP6_ADDR=$1
XCAT_IP6_PREFIX=$2
XCAT_IP6_GW=$3
cat > $NEWROOT/etc/netplan/90-xcat.yaml <<XCATNETPLAN6
network:
version: 2
ethernets:
$ETHX:
dhcp4: false
addresses: [$XCAT_IP6_ADDR/$XCAT_IP6_PREFIX]
match:
macaddress: "$MACX"
XCATNETPLAN6
if [ -n "$XCAT_IP6_GW" ]; then
cat >> $NEWROOT/etc/netplan/90-xcat.yaml <<XCATNETPLAN6GW
routes:
- to: default
via: $XCAT_IP6_GW
XCATNETPLAN6GW
fi
chmod 600 $NEWROOT/etc/netplan/90-xcat.yaml
else
cat > $NEWROOT/etc/netplan/90-xcat.yaml <<XCATNETPLAN
network:
version: 2
@@ -275,6 +354,7 @@ network:
match:
macaddress: "$MACX"
XCATNETPLAN
fi
elif [ -d $NEWROOT/etc/sysconfig/network-scripts ]; then
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bats
#
# The booted stateless system of an IPv6-only Ubuntu node.
#
# xcatroot wrote "dhcp4: true" into the netplan of every node, so an IPv6-only node came up
# with no address: systemd-networkd-wait-online failed, xcatpostinit failed, and the node
# answered no ssh. Measured on Ubuntu 24.04.5, which reached its login prompt with
# "[FAILED] Failed to start systemd-networkd-w... Wait for Network to be Configured."
#
# The address is on the kernel command line already, in the static form dracut takes.
load 'helpers/shell_source'
setup()
{
XCATROOT_SCRIPT="$(require_repo_file \
'xCAT-server/share/xcat/netboot/ubuntu/dracut/xcatroot')"
SNIPPET="${BATS_TEST_TMPDIR}/fields.sh"
extract_shell_function "$XCATROOT_SCRIPT" xcat_static_ip6_fields >"$SNIPPET"
}
fields()
{
(
# shellcheck disable=SC1090
. "$SNIPPET" >/dev/null 2>&1
xcat_static_ip6_fields "$1"
)
}
@test "the address, prefix and gateway are read from the static form" {
run fields 'ip=[2001:db8:147::10]::[2001:db8:147::1]:64:::none'
[ "$status" -eq 0 ]
[ "$output" = '2001:db8:147::10 64 2001:db8:147::1' ]
}
@test "a node with no gateway still yields its address and prefix" {
run fields 'ip=[2001:db8:147::10]:::64:::none'
[ "$status" -eq 0 ]
[ "$output" = '2001:db8:147::10 64 ' ]
}
@test "an interface name in the parameter does not disturb the fields" {
run fields 'ip=[2001:db8:147::10]::[2001:db8:147::1]:64::eth0:none'
[ "$output" = '2001:db8:147::10 64 2001:db8:147::1' ]
}
# The IPv4 forms must be refused, or an IPv4 node would be given an IPv6 netplan.
@test "the dracut dhcp form is refused" {
run fields 'ip=dhcp'
[ "$status" -ne 0 ]
}
@test "the interface dhcp form is refused" {
run fields 'ip=eth0:dhcp'
[ "$status" -ne 0 ]
}
@test "either6 is refused, because it carries no address" {
run fields 'ip=either6'
[ "$status" -ne 0 ]
}
# A prefix that is not a number would reach the netplan as an address suffix.
@test "a parameter with no prefix is refused" {
run fields 'ip=[2001:db8:147::10]::[2001:db8:147::1]::::none'
[ "$status" -ne 0 ]
}