mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-12-04 08:07:04 +00:00
fix(xcat-core): bmcsetup compares BMC addresses as text
An OpenBMC node can report "failed" after its IPv6 address is set correctly, and "bmcready" when the BMC has a different address. bmc_has_address in bmcsetup searches the whole lan6 print output for the configured text. One IPv6 address has many spellings, so "2001:0db8:0001::0020" does not match "2001:db8:1::20". A substring match also accepts "2001:db8:1::20" for "2001:db8:1::2". The IPv4 check has the same substring defect. bmc_has_address now reads each "Address:" entry of lan6 print and compares it with the configured address after ipv6_expand writes both as eight zero-padded lowercase groups without the prefix length. ipv6_expand uses only bash. The IPv4 check compares the complete "IP Address" field. The new tests in genesis_bmcsetup_users.bats fail without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -151,18 +151,57 @@ function configure_ipv6_bmc() {
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Function: ipv6_expand
|
||||
#
|
||||
# Print the IPv6 address $1 as eight 4-digit lowercase groups, without a /prefix.
|
||||
# Fail when $1 is not an IPv6 address. Genesis carries no IPv6 parser, so
|
||||
# this is bash only.
|
||||
#
|
||||
function ipv6_expand() {
|
||||
local addr=${1%%/*} head tail group out= i
|
||||
local -a groups=() tailgroups=()
|
||||
addr=${addr,,}
|
||||
[[ $addr =~ ^[0-9a-f:]+$ ]] || return 1
|
||||
if [[ $addr == *::* ]]; then
|
||||
head=${addr%%::*}
|
||||
tail=${addr#*::}
|
||||
[[ $tail == *::* ]] && return 1
|
||||
IFS=: read -r -a groups <<< "$head"
|
||||
IFS=: read -r -a tailgroups <<< "$tail"
|
||||
for ((i = ${#groups[@]} + ${#tailgroups[@]}; i < 8; i++)); do
|
||||
groups+=(0)
|
||||
done
|
||||
groups+=("${tailgroups[@]}")
|
||||
else
|
||||
IFS=: read -r -a groups <<< "$addr"
|
||||
fi
|
||||
[ ${#groups[@]} -eq 8 ] || return 1
|
||||
for group in "${groups[@]}"; do
|
||||
[[ $group =~ ^[0-9a-f]{1,4}$ ]] || return 1
|
||||
out+=$(printf '%04x' $((16#$group))):
|
||||
done
|
||||
printf '%s\n' "${out%:}"
|
||||
}
|
||||
|
||||
#
|
||||
# Function: bmc_has_address
|
||||
#
|
||||
# Succeed when the BMC reports the address $1. lan print shows only the IPv4
|
||||
# parameters, so an IPv6 address is read with lan6 print on $LANCHAN.
|
||||
# parameters, so an IPv6 address is read with lan6 print on $LANCHAN. One IPv6
|
||||
# address has many spellings, so both sides are expanded before the compare.
|
||||
#
|
||||
function bmc_has_address() {
|
||||
local want key value
|
||||
if [[ "$1" == *:* ]]; then
|
||||
ipmitool lan6 print "$LANCHAN" | grep -qiF -- "$1"
|
||||
else
|
||||
ipmitool lan print 1 | grep $1 >/dev/null
|
||||
want=$(ipv6_expand "$1") || return 1
|
||||
while read -r key value; do
|
||||
[ "$key" = "Address:" ] || continue
|
||||
[ "$(ipv6_expand "$value")" = "$want" ] && return 0
|
||||
done < <(ipmitool lan6 print "$LANCHAN")
|
||||
return 1
|
||||
fi
|
||||
[ "$(lan_field 0 1 '^IP Address' Source)" = "$1" ]
|
||||
}
|
||||
|
||||
if ! ipmitool -V 2>/dev/null| grep "version"; then
|
||||
|
||||
Reference in New Issue
Block a user