2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-26 20:32:17 +00:00

fix(postscripts): an installed node ignores the DUID its reservation holds

configdhcpv6duid always derived the DHCPv6 client identifier from the SMBIOS
UUID in firmware byte order. makedhcp does that only when mac.duid is unset or
holds 'firmware': 'canonical' reserves the order product_uuid prints, and a
literal DUID is reserved as it stands. A node with either setting wrote an
identifier that matched no reservation, so it took a pool address and had no
boot file URL.

mypostscript.tmpl now exports the attribute as DHCP6DUID, and the postscript
reads it. 'canonical' keeps the order product_uuid printed. A literal is
written as it stands for NetworkManager, which takes a whole DUID.
systemd-networkd composes one from a named type, and only the UUID type can be
expressed that way, so a literal of another type is written for
NetworkManager alone and the reason is logged. A value that is neither keyword
nor DUID writes nothing, which is what makedhcp refuses as well.

The derived values are byte-identical to kea_duid_from_uuid for both orders.
postscript_dhcpv6_duid.bats goes from 9 checks to 16; ignoring the attribute
fails the five that name a setting and leaves the firmware default passing.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-30 13:17:39 -03:00
parent 8c704104ab
commit 102dc80920
3 changed files with 123 additions and 9 deletions
@@ -46,6 +46,9 @@ PRIMARYNIC=#TABLE:noderes:$NODE:primarynic#
export PRIMARYNIC
MASTER=#TABLE:noderes:$NODE:xcatmaster#
# The DHCPv6 client identifier that the reservation of this node holds, so
# configdhcpv6duid writes the one makedhcp reserved rather than deriving another.
DHCP6DUID=#TABLE:mac:$NODE:duid#
export MASTER
SERVICEGROUP=#TABLE:noderes:$NODE:servicenode#
export SERVICEGROUP
@@ -106,3 +106,75 @@ DUIDRawData=$RAW" ]
[ "$status" -eq 1 ]
grep -F 'the DHCPv6 client identifier is unset' "$XCAT_TEST_LOG"
}
# ---- mac.duid decides the identifier, the same way makedhcp decides it -------------------
# The script always derived the firmware order. A node whose reservation holds a
# canonical-order or a literal DUID matched nothing, took a pool address and had no boot URL.
# mypostscript exports the attribute as DHCP6DUID.
CANONICAL=00:04:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
@test "an unset attribute keeps the firmware order" {
unset DHCP6DUID
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nm_file)" = "[connection]
ipv6.dhcp-duid=$DUID" ]
}
@test "firmware asks for the order the firmware sends" {
export DHCP6DUID=firmware
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nm_file)" = "[connection]
ipv6.dhcp-duid=$DUID" ]
}
@test "canonical keeps the order product_uuid prints" {
export DHCP6DUID=canonical
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nm_file)" = "[connection]
ipv6.dhcp-duid=$CANONICAL" ]
}
@test "canonical gives systemd-networkd the same sixteen bytes" {
export DHCP6DUID=canonical
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nd_file)" = "[DHCPv6]
DUIDType=uuid
DUIDRawData=00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff" ]
}
@test "a literal UUID DUID is written as it stands" {
export DHCP6DUID=00:04:de:ad:be:ef:00:01:02:03:04:05:06:07:08:09
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nm_file)" = "[connection]
ipv6.dhcp-duid=00:04:de:ad:be:ef:00:01:02:03:04:05:06:07:08:09" ]
[ "$(nd_file)" = "[DHCPv6]
DUIDType=uuid
DUIDRawData=de:ad:be:ef:00:01:02:03:04:05:06:07:08:09" ]
}
@test "a literal DUID of another type goes to NetworkManager alone" {
export DHCP6DUID=00:01:00:01:aa:bb:cc:dd:ee:ff:00:11
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ "$(nm_file)" = "[connection]
ipv6.dhcp-duid=00:01:00:01:aa:bb:cc:dd:ee:ff:00:11" ]
# systemd-networkd composes a DUID from a named type, and only the UUID type can be
# expressed that way, so writing one of another type there would send the wrong value.
[ ! -e "$XCAT_NETWORKD_CONF_DIR/15-xcat-dhcpv6-duid.conf" ]
grep -q 'not a UUID DUID' "$XCAT_TEST_LOG"
}
@test "an attribute that is neither keyword nor DUID writes nothing" {
export DHCP6DUID=garbage-value
run_duid 00112233-4455-6677-8899-aabbccddeeff
[ "$status" -eq 0 ]
[ ! -e "$XCAT_NM_CONF_DIR/15-xcat-dhcpv6-duid.conf" ]
[ ! -e "$XCAT_NETWORKD_CONF_DIR/15-xcat-dhcpv6-duid.conf" ]
grep -q 'is not firmware, canonical, or a DUID' "$XCAT_TEST_LOG"
}
+48 -9
View File
@@ -50,24 +50,61 @@ case $uuid in
;;
esac
# mac.duid decides the identifier, the same way makedhcp decides it, and mypostscript exports
# it as DHCP6DUID. A node whose reservation holds a canonical-order or a literal DUID would
# match nothing if this script always derived the firmware order.
duid_setting=${DHCP6DUID:-firmware}
case $duid_setting in
''|firmware|canonical) ;;
*)
# A literal DUID is reserved verbatim, so it is written verbatim.
if ! printf '%s' "$duid_setting" | grep -qiE '^[0-9a-f]{2}(:[0-9a-f]{2}){2,129}$'; then
log "the duid attribute is '$duid_setting', which is not firmware, canonical, or a DUID of colon-separated hexadecimal octets; leaving the DHCPv6 client identifier alone"
exit 0
fi
literal=$(printf '%s' "$duid_setting" | tr 'A-F' 'a-f')
;;
esac
# SMBIOS 2.6 and later store the first three UUID fields little-endian, and EDK2 copies those
# bytes into its DUID. product_uuid prints the fields in canonical order, so the first three go
# back into firmware order here. makedhcp, doxcat and genesis-duid do the same swap.
octets=${uuid:6:2}:${uuid:4:2}:${uuid:2:2}:${uuid:0:2}
octets=$octets:${uuid:10:2}:${uuid:8:2}
octets=$octets:${uuid:14:2}:${uuid:12:2}
# back into firmware order here. makedhcp, doxcat and genesis-duid do the same swap. The
# canonical setting keeps the order product_uuid printed.
if [ "$duid_setting" = canonical ]; then
octets=${uuid:0:2}:${uuid:2:2}:${uuid:4:2}:${uuid:6:2}
octets=$octets:${uuid:8:2}:${uuid:10:2}
octets=$octets:${uuid:12:2}:${uuid:14:2}
else
octets=${uuid:6:2}:${uuid:4:2}:${uuid:2:2}:${uuid:0:2}
octets=$octets:${uuid:10:2}:${uuid:8:2}
octets=$octets:${uuid:14:2}:${uuid:12:2}
fi
for offset in 16 18 20 22 24 26 28 30; do
octets=$octets:${uuid:$offset:2}
done
# A literal replaces the derived value. NetworkManager takes a whole DUID, so it takes the
# literal as it stands. systemd-networkd composes one from a named type plus raw data, and only
# the UUID type (00:04) can be expressed that way, so a literal of any other type is written
# for NetworkManager alone.
duid=00:04:$octets
networkd_octets=$octets
if [ -n "${literal:-}" ]; then
duid=$literal
case $literal in
00:04:*) networkd_octets=${literal#00:04:} ;;
*) networkd_octets= ;;
esac
fi
written=0
# NetworkManager takes the whole DUID, including the 00:04 type. conf.d is read in name order
# and a later file wins, so this name sorts after the packaged defaults.
if [ -d "$nm_dir" ] || [ -d "${nm_dir%/*}" ]; then
if mkdir -p "$nm_dir" 2>/dev/null &&
printf '%s\n' '[connection]' "ipv6.dhcp-duid=00:04:$octets" >"$nm_dir/15-xcat-dhcpv6-duid.conf"; then
log "NetworkManager DHCPv6 client identifier is 00:04:$octets"
printf '%s\n' '[connection]' "ipv6.dhcp-duid=$duid" >"$nm_dir/15-xcat-dhcpv6-duid.conf"; then
log "NetworkManager DHCPv6 client identifier is $duid"
written=$((written + 1))
else
log "unable to write $nm_dir/15-xcat-dhcpv6-duid.conf"
@@ -76,10 +113,12 @@ fi
# systemd-networkd composes the DUID from DUIDType and DUIDRawData, so the type is named rather
# than written: DUIDRawData carries the sixteen UUID bytes alone.
if [ -d "$networkd_dir" ] || [ -d /run/systemd/network ] || [ -d "${networkd_dir%/*}" ]; then
if [ -z "$networkd_octets" ]; then
log "the reserved DUID $duid is not a UUID DUID, which systemd-networkd cannot express; only NetworkManager is configured"
elif [ -d "$networkd_dir" ] || [ -d /run/systemd/network ] || [ -d "${networkd_dir%/*}" ]; then
if mkdir -p "$networkd_dir" 2>/dev/null &&
printf '%s\n' '[DHCPv6]' 'DUIDType=uuid' "DUIDRawData=$octets" >"$networkd_dir/15-xcat-dhcpv6-duid.conf"; then
log "systemd-networkd DHCPv6 client identifier is 00:04:$octets"
printf '%s\n' '[DHCPv6]' 'DUIDType=uuid' "DUIDRawData=$networkd_octets" >"$networkd_dir/15-xcat-dhcpv6-duid.conf"; then
log "systemd-networkd DHCPv6 client identifier is $duid"
written=$((written + 1))
else
log "unable to write $networkd_dir/15-xcat-dhcpv6-duid.conf"