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

fix(xcat-core): configdhcpv6duid writes a DUID that the reservation does not hold

mypostscript assigned DHCP6DUID and did not export it, so configdhcpv6duid, which runs as a
child process, never saw mac.duid and wrote the firmware DUID-UUID. The script also rejected
ll, which makedhcp accepts and selects by default on ppc64le. It read the SMBIOS UUID before
the attribute, so a missing or nil UUID ended the script although a literal DUID needs none.
And it wrote no systemd-networkd configuration for a DUID that is not a DUID-UUID.

mypostscript now exports DHCP6DUID. The script reads the attribute first, builds the DUID-LL
from the first mac.mac address for ll and for an unset value on ppc64le, reads the UUID only
for firmware and canonical, and gives systemd-networkd the type of every DUID through
DUIDType and the rest through DUIDRawData.

postscript_dhcpv6_duid.bats fails without this change.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-11-06 17:32:00 -03:00
parent 9c778b9155
commit a5cd542a5d
3 changed files with 100 additions and 77 deletions
@@ -49,6 +49,7 @@ 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 DHCP6DUID
export MASTER
SERVICEGROUP=#TABLE:noderes:$NODE:servicenode#
export SERVICEGROUP
+1 -1
View File
@@ -283,5 +283,5 @@ DUIDRawData=00:01:52:54:00:aa:bb:cc" ]
[ "$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"
grep -q 'is not firmware, canonical, ll, or a DUID' "$XCAT_TEST_LOG"
}
+98 -76
View File
@@ -2,12 +2,13 @@
#
# Write the DHCPv6 client identifier that the xCAT reservation of this node holds.
#
# makedhcp builds a DUID-UUID (RFC 6355) from vpd.uuid, and a DHCPv6 host reservation carries
# either a duid or a hw-address, never both. A client that sends any other identifier matches no
# reservation and takes a pool address with no boot URL. No network manager derives a DUID from
# the SMBIOS UUID in the byte order the firmware sends: NetworkManager has no such option at all,
# and systemd-networkd's DUIDType=uuid uses the decoded product UUID, which is the other order.
# So the value is written as a literal, for whichever renderer the node has.
# makedhcp builds the DUID that mac.duid selects, by default a DUID-UUID (RFC 6355) from
# vpd.uuid. A DHCPv6 host reservation carries either a duid or a hw-address, never both. A
# client that sends any other identifier matches no reservation and takes a pool address with
# no boot URL. No network manager derives a DUID from the SMBIOS UUID in the byte order the
# firmware sends: NetworkManager has no such option at all, and systemd-networkd's
# DUIDType=uuid uses the decoded product UUID, which is the other order. So the value is
# written as a literal, for whichever renderer the node has.
#
# This covers a node whose installed OS speaks DHCPv6, which is a diskful or cloned node on a
# family with no static handoff. A diskless or statelite node needs nothing: the kernel command
@@ -30,76 +31,101 @@ log() {
logger -t xcat-dhcpv6-duid -- "$*" 2>/dev/null || echo "xcat-dhcpv6-duid: $*"
}
if [ ! -r "$uuid_file" ]; then
log "no SMBIOS UUID at $uuid_file, leaving the DHCPv6 client identifier alone"
exit 0
fi
uuid=$(tr -d -c '[:xdigit:]' <"$uuid_file" | tr 'A-F' 'a-f')
if [ "${#uuid}" -ne 32 ]; then
log "no usable SMBIOS UUID at $uuid_file, leaving the DHCPv6 client identifier alone"
exit 0
fi
# makedhcp refuses the nil UUID, because nodeimport writes it to every PowerKVM node, and
# reserves the hardware address instead. A DUID built from it would match no reservation.
case $uuid in
00000000000000000000000000000000)
log "SMBIOS UUID is the nil UUID, leaving the DHCPv6 client identifier alone"
exit 0
;;
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. 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= ;;
# it as DHCP6DUID. A node whose reservation holds a canonical-order, a link-layer or a literal
# DUID would match nothing if this script always derived the firmware order. With no value,
# makedhcp reserves the DUID-LL on ppc64le, because SLOF reports no UUID.
duid_setting=$(printf '%s' "${DHCP6DUID:-}" | tr -d '[:space:]' | tr 'A-Z' 'a-z')
if [ -z "$duid_setting" ]; then
case ${ARCH:-} in
ppc*) duid_setting=ll ;;
*) duid_setting=firmware ;;
esac
fi
literal=
case $duid_setting in
firmware|canonical) ;;
ll)
# makedhcp builds the DUID-LL from the first address of mac.mac, the netboot NIC.
mac=${MACMAC:-}
mac=${mac%%|*}
mac=${mac%%!*}
mac=$(printf '%s' "$mac" | tr 'A-F-' 'a-f:')
if ! printf '%s' "$mac" | grep -qE '^[0-9a-f]{2}(:[0-9a-f]{2}){5,8}$'; then
log "the duid attribute is ll and there is no usable address in mac.mac; leaving the DHCPv6 client identifier alone"
exit 0
fi
literal=00:03:00:01:$mac
;;
*)
# A literal DUID is reserved verbatim, so it is written verbatim.
if ! printf '%s' "$duid_setting" | grep -qE '^[0-9a-f]{2}(:[0-9a-f]{2}){2,129}$'; then
log "the duid attribute is '$duid_setting', which is not firmware, canonical, ll, or a DUID of colon-separated hexadecimal octets; leaving the DHCPv6 client identifier alone"
exit 0
fi
literal=$duid_setting
;;
esac
# Only the two UUID orders read the SMBIOS UUID. makedhcp reserves a literal or a DUID-LL
# without one.
if [ -n "$literal" ]; then
duid=$literal
else
if [ ! -r "$uuid_file" ]; then
log "no SMBIOS UUID at $uuid_file, leaving the DHCPv6 client identifier alone"
exit 0
fi
uuid=$(tr -d -c '[:xdigit:]' <"$uuid_file" | tr 'A-F' 'a-f')
if [ "${#uuid}" -ne 32 ]; then
log "no usable SMBIOS UUID at $uuid_file, leaving the DHCPv6 client identifier alone"
exit 0
fi
# makedhcp refuses the nil UUID, because nodeimport writes it to every PowerKVM node, and
# reserves the hardware address instead. A DUID built from it would match no reservation.
case $uuid in
00000000000000000000000000000000)
log "SMBIOS UUID is the nil UUID, leaving the DHCPv6 client identifier alone"
exit 0
;;
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. 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
duid=00:04:$octets
fi
# systemd-networkd composes the DUID from DUIDType and DUIDRawData: the first two octets are
# the type, and the raw data is everything after them.
case ${duid:0:5} in
00:01) networkd_type=link-layer-time ;;
00:02) networkd_type=vendor ;;
00:03) networkd_type=link-layer ;;
00:04) networkd_type=uuid ;;
*) networkd_type=$((16#${duid:0:2}${duid:3:2})) ;;
esac
networkd_raw=${duid:6}
written=0
# NetworkManager takes the whole DUID, including the 00:04 type. conf.d is read in name order
# NetworkManager takes the whole DUID, including its 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 &&
@@ -111,13 +137,9 @@ if [ -d "$nm_dir" ] || [ -d "${nm_dir%/*}" ]; then
fi
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 [ -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 [ -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=$networkd_octets" >"$networkd_dir/15-xcat-dhcpv6-duid.conf"; then
printf '%s\n' '[DHCPv6]' "DUIDType=$networkd_type" "DUIDRawData=$networkd_raw" >"$networkd_dir/15-xcat-dhcpv6-duid.conf"; then
log "systemd-networkd DHCPv6 client identifier is $duid"
written=$((written + 1))
else