diff --git a/xCAT-genesis-base/oe/meta-xcat-genesis/recipes-connectivity/xcat-genesis-network/files/genesis-bootnic b/xCAT-genesis-base/oe/meta-xcat-genesis/recipes-connectivity/xcat-genesis-network/files/genesis-bootnic new file mode 100755 index 0000000000..4aeaeb8be9 --- /dev/null +++ b/xCAT-genesis-base/oe/meta-xcat-genesis/recipes-connectivity/xcat-genesis-network/files/genesis-bootnic @@ -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" <"$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") +}