2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-27 12:52:16 +00:00

test(xcat-core): Genesis OpenEmbedded asks for DHCPv6 on every nic

A DHCPv6 reservation is keyed on the DUID, and a DUID names the machine, not the
nic. 10-xcat-genesis.conf puts the DHCPv6 settings in [connection], which
NetworkManager applies to every nic, so each nic of a node asks for the same
reserved address and Kea gives it to the first REQUEST.

Measured on xcat88-cn, which carries three nics on the provisioning bridge
virbr-p88. Kea logged four solicits under one DUID in one boot, and granted
2001:db8:188::20 to whichever IA asked first; the others took pool addresses.
The node then reported to xcatd from an address xcatd could not match to a node,
so el10-x86_64-genesis-oe-ipv6 passed or failed by chance.

genesis-bootnic reads BOOTIF and writes 16-xcat-genesis-bootnic.conf, which
leaves DHCPv6 on the boot nic and puts every other nic on link-local. It follows
genesis-duid, which already writes 15-xcat-genesis-duid.conf from the SMBIOS UUID
before NetworkManager starts.

The six cases pass with the file as committed, so the evidence is a mutation:
writing ipv6.method=auto for the secondary nics, which is the behaviour before
this change, reds only "the boot nic keeps DHCPv6 and every other nic does not
ask for an address".

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-11-08 17:08:54 -03:00
parent cab264cb93
commit a5d910f663
2 changed files with 128 additions and 0 deletions
@@ -0,0 +1,60 @@
#!/bin/bash
#
# Keep the DHCPv6 reservation on the nic the node booted from.
#
# A DHCPv6 reservation is keyed on the DUID, and a DUID names the machine, not the nic.
# 10-xcat-genesis.conf sets the DHCPv6 defaults in [connection], which applies to every nic, so
# each nic of a node asks for the same reserved address and Kea gives it to the first REQUEST.
# When that is not the boot nic, the node holds its reserved address on a nic xcatd does not
# reach it on, and the report xcatd receives comes from a pool address it cannot match to a node.
set -u
LC_ALL=C
export LC_ALL
cmdline_file=${XCAT_CMDLINE_FILE:-/proc/cmdline}
conf_dir=${XCAT_NM_CONF_DIR:-/etc/NetworkManager/conf.d}
# NetworkManager reads conf.d in name order and a later file wins, so this sorts after
# 15-xcat-genesis-duid.conf, which the DUID is written to.
conf_file=$conf_dir/16-xcat-genesis-bootnic.conf
log() {
logger -t xcat-genesis-bootnic -- "$*" || true
}
[ -r "$cmdline_file" ] || { log "no kernel command line at $cmdline_file"; exit 0; }
# BOOTIF is the hardware type and the address, hyphen separated: 01-aa-bb-cc-dd-ee-ff.
bootif=""
for word in $(cat "$cmdline_file"); do
case $word in
BOOTIF=*) bootif=${word#BOOTIF=} ;;
esac
done
if [ -z "$bootif" ]; then
log "no BOOTIF on the command line, leaving DHCPv6 on every nic"
exit 0
fi
mac=$(printf '%s' "${bootif#01-}" | tr 'A-F-' 'a-f:')
case $mac in
[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]) ;;
*) log "BOOTIF $bootif is not a hardware address, leaving DHCPv6 on every nic"; exit 0 ;;
esac
mkdir -p "$conf_dir" || exit 1
# link-local, not disabled: a secondary nic keeps IPv6 on the link and the node still reports
# it to xcatd for the nic data, it just does not ask for an address the reservation holds.
cat >"$conf_file" <<EOF
# Written by xcat-genesis-bootnic from BOOTIF=$bootif. A DHCPv6 reservation is keyed on the
# DUID, which names the machine, so only the boot nic may ask for one.
[connection-xcat-genesis-bootnic]
match-device=mac:$mac
ipv6.method=auto
[connection-xcat-genesis-secondary]
match-device=except:mac:$mac
ipv6.method=link-local
EOF
log "DHCPv6 restricted to the boot nic $mac"
@@ -0,0 +1,68 @@
#!/usr/bin/env bats
#
# A DHCPv6 reservation is keyed on the DUID, and a DUID names the machine, not the nic.
# 10-xcat-genesis.conf puts the DHCPv6 settings in [connection], which NetworkManager applies to
# every nic, so each nic of a node asks for the same reserved address and Kea gives it to the
# first REQUEST. Measured on xcat88-cn, which has three nics on the provisioning bridge: the
# firmware and Genesis sent four solicits under one DUID and only one of them held 2001:db8:188::20.
load 'helpers/shell_source'
setup()
{
SCRIPT="$(require_repo_file 'xCAT-genesis-base/oe/meta-xcat-genesis/recipes-connectivity/xcat-genesis-network/files/genesis-bootnic')"
CONFD="${BATS_TEST_TMPDIR}/conf.d"
CMDLINE="${BATS_TEST_TMPDIR}/cmdline"
CONF="${CONFD}/16-xcat-genesis-bootnic.conf"
mkdir -p "$CONFD"
BIN="${BATS_TEST_TMPDIR}/bin"; mkdir -p "$BIN"
printf '#!/bin/sh\nexit 0\n' >"$BIN/logger"; chmod 0755 "$BIN/logger"
}
run_bootnic()
{
printf '%s\n' "$1" >"$CMDLINE"
run env PATH="$BIN:$PATH" XCAT_CMDLINE_FILE="$CMDLINE" XCAT_NM_CONF_DIR="$CONFD" \
bash "$SCRIPT"
}
@test "the boot nic keeps DHCPv6 and every other nic does not ask for an address" {
run_bootnic 'quiet xcatd=[2001:db8:188::1]:3001 BOOTIF=01-42-7c-b6-21-e1-81'
[ "$status" -eq 0 ]
[ -r "$CONF" ]
grep -q '^match-device=mac:42:7c:b6:21:e1:81$' "$CONF"
grep -q '^match-device=except:mac:42:7c:b6:21:e1:81$' "$CONF"
grep -q '^ipv6.method=auto$' "$CONF"
grep -q '^ipv6.method=link-local$' "$CONF"
}
@test "an upper case BOOTIF is written as NetworkManager matches it" {
run_bootnic 'BOOTIF=01-AA-BB-CC-DD-EE-FF'
[ "$status" -eq 0 ]
grep -q '^match-device=mac:aa:bb:cc:dd:ee:ff$' "$CONF"
}
@test "the file sorts after the DUID file, or NetworkManager would not read it last" {
run_bootnic 'BOOTIF=01-42-7c-b6-21-e1-81'
[ "$(ls "$CONFD")" = '16-xcat-genesis-bootnic.conf' ]
[[ '16-xcat-genesis-bootnic.conf' > '15-xcat-genesis-duid.conf' ]]
}
@test "no BOOTIF leaves every nic as it was" {
run_bootnic 'quiet xcatd=[2001:db8:188::1]:3001'
[ "$status" -eq 0 ]
refute_grep -q . <(ls "$CONFD")
}
@test "a BOOTIF that is not a hardware address leaves every nic as it was" {
run_bootnic 'BOOTIF=01-not-a-mac'
[ "$status" -eq 0 ]
refute_grep -q . <(ls "$CONFD")
}
@test "an unreadable command line leaves every nic as it was" {
rm -f "$CMDLINE"
run env PATH="$BIN:$PATH" XCAT_CMDLINE_FILE="$CMDLINE" XCAT_NM_CONF_DIR="$CONFD" bash "$SCRIPT"
[ "$status" -eq 0 ]
refute_grep -q . <(ls "$CONFD")
}