mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-22 18:32:13 +00:00
fix(xcat-core): a BMC cannot be given an IPv6 address
When ipmi.bmc is an IPv6 address, bmcconfig finds no network for it and Genesis leaves the BMC unconfigured. bmcsetup only writes IPv4 LAN parameters. bmc_net_params now accepts an IPv6 address, or a name that resolves only to one, and returns the prefix length, the gateway and the prefix of the networks row that contains it. bmcconfig sends the prefix as routerprefix. bmcsetup writes the address with "ipmitool lan6 set static_addr" and, when there is a gateway, a static router. A name with an IPv4 address keeps the IPv4 setup. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -77,3 +77,25 @@ Ubuntu, diskless ``ip=`` with the address, from ``dracut_static_ip6``
|
||||
Ubuntu, diskful ``ip6=dhcp``, and casper runs ``dhcpcd -6`` as a third client
|
||||
SLES, openSUSE ``ipv6only=1 hostip=<address>/<prefix>``, from ``static_ipv6_boot_args``
|
||||
================ =========================================================================
|
||||
|
||||
A BMC on an IPv6 address
|
||||
------------------------
|
||||
|
||||
Genesis gives a BMC a static IPv6 address when ``ipmi.bmc`` is an IPv6 address, or a name
|
||||
that resolves only to an IPv6 address. A name that also resolves to an IPv4 address keeps
|
||||
the IPv4 setup. All BMCs of one node use the same address family.
|
||||
|
||||
``bmcconfig`` takes the prefix length and the gateway from the ``networks`` row that
|
||||
contains the address. ``bmcsetup`` then runs, on the LAN channel of the BMC::
|
||||
|
||||
ipmitool lan6 set <channel> nolock enables both
|
||||
ipmitool lan6 set <channel> nolock static_addr 0 enable <address> <prefix length>
|
||||
ipmitool lan6 set <channel> nolock rtr_cfg both
|
||||
ipmitool lan6 set <channel> nolock static_rtr 1 <gateway> 00:00:00:00:00:00 <prefix> <prefix length>
|
||||
|
||||
The last two commands run only when the network has a gateway. xCAT does not know the MAC
|
||||
address of the router, so the static router has the MAC address ``00:00:00:00:00:00``.
|
||||
``enables both`` keeps the IPv4 configuration of the BMC.
|
||||
|
||||
The Genesis image must have ipmitool 1.8.19 or later, which adds the ``lan6`` command.
|
||||
Sequential discovery does not assign IPv6 BMC addresses from ``bmciprange``.
|
||||
|
||||
@@ -117,6 +117,40 @@ function snooze() {
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Function: set_lan6
|
||||
#
|
||||
# Write one IPv6 LAN parameter of device $1 on $LANCHAN. ipmitool 1.8.19 added lan6.
|
||||
#
|
||||
function set_lan6() {
|
||||
local dev=$1 tries=0
|
||||
shift
|
||||
while ! ipmitool -d "$dev" lan6 set "$LANCHAN" nolock "$@"; do
|
||||
snooze
|
||||
let tries=tries+1
|
||||
if [ $tries -gt $TIMEOUT ]; then
|
||||
logger -s -t $log_label -p local4.err "ipmitool lan6 set $LANCHAN $* failed"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# Function: configure_ipv6_bmc
|
||||
#
|
||||
# Give device $1 the static address $2/$3 and, when $4 is set, the router $4 for prefix $5.
|
||||
# xCAT does not know the MAC address of the router, so the static router has none.
|
||||
#
|
||||
function configure_ipv6_bmc() {
|
||||
local dev=$1 addr=$2 prefix=$3 gw=$4 net=$5
|
||||
set_lan6 "$dev" enables both
|
||||
set_lan6 "$dev" static_addr 0 enable "$addr" "$prefix"
|
||||
if [ -n "$gw" ] && [ -n "$net" ]; then
|
||||
set_lan6 "$dev" rtr_cfg both
|
||||
set_lan6 "$dev" static_rtr 1 "$gw" 00:00:00:00:00:00 "$net" "$prefix"
|
||||
fi
|
||||
}
|
||||
|
||||
if ! ipmitool -V 2>/dev/null| grep "version"; then
|
||||
echo "No ipmitool find, please install it first";
|
||||
exit 1;
|
||||
@@ -395,7 +429,16 @@ done
|
||||
logger -s -t $log_label -p local4.info "Detected LAN channel $LANCHAN"
|
||||
|
||||
let idev=NUMBMCS
|
||||
if [ $IPCFGMETHOD="static" ]; then
|
||||
if [[ "$BMCIP" == *:* ]]; then
|
||||
mapfile -t BMCIPS < <(config_field bmcip)
|
||||
mapfile -t BMCNMS < <(config_field netmask)
|
||||
mapfile -t BMCGWS < <(config_field gateway)
|
||||
mapfile -t BMCNETS < <(config_field routerprefix)
|
||||
for idev in "${!BMCIPS[@]}"; do
|
||||
configure_ipv6_bmc "$idev" "${BMCIPS[$idev]}" "${BMCNMS[$idev]}" \
|
||||
"${BMCGWS[$idev]}" "${BMCNETS[$idev]}"
|
||||
done
|
||||
elif [ $IPCFGMETHOD="static" ]; then
|
||||
while [ $idev -gt 0 ]; do
|
||||
let idev=idev-1
|
||||
TRIES=0
|
||||
|
||||
@@ -3,7 +3,7 @@ package xCAT::BMCUtils;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Socket qw(inet_aton inet_ntoa);
|
||||
use Socket qw(AF_INET6 inet_aton inet_ntoa inet_pton);
|
||||
|
||||
my %per_bmc_setting = map { $_ => 1 } qw(ip netmask gateway);
|
||||
|
||||
@@ -40,6 +40,44 @@ sub _ipv4_number {
|
||||
return ($1 << 24) + ($2 << 16) + ($3 << 8) + $4;
|
||||
}
|
||||
|
||||
sub _ipv6_packed {
|
||||
my ($address) = @_;
|
||||
return unless defined($address) && $address =~ /:/;
|
||||
return eval { inet_pton(AF_INET6, $address) };
|
||||
}
|
||||
|
||||
sub _ipv6_in_prefix {
|
||||
my ($address, $network, $prefix) = @_;
|
||||
my $addr = _ipv6_packed($address);
|
||||
my $netp = _ipv6_packed($network);
|
||||
return 0 unless $addr && $netp;
|
||||
my $bits = '1' x $prefix . '0' x (128 - $prefix);
|
||||
my $mask = pack('B128', $bits);
|
||||
return (($addr & $mask) eq ($netp & $mask)) ? 1 : 0;
|
||||
}
|
||||
|
||||
# networks.mask holds "/64" for an IPv6 network, or the length is on networks.net.
|
||||
sub _bmc_net6_params {
|
||||
my ($ip, $nets, $facing) = @_;
|
||||
foreach my $row (@{ $nets || [] }) {
|
||||
my ($net, $prefix, $gw) = @{$row}{qw(net mask gateway)};
|
||||
next unless defined($net) && $net =~ /:/;
|
||||
if ($net =~ s{/([0-9]+)$}{}) {
|
||||
$prefix = $1 unless defined($prefix) && length($prefix);
|
||||
}
|
||||
next unless defined($prefix);
|
||||
$prefix =~ s{^/}{};
|
||||
next unless $prefix =~ /^\d+$/ && $prefix <= 128;
|
||||
next unless _ipv6_in_prefix($ip, $net, $prefix);
|
||||
|
||||
if (defined($gw) && $gw eq '<xcatmaster>') {
|
||||
$gw = $facing->($ip, 6);
|
||||
}
|
||||
return ($ip, $prefix, $gw, $net);
|
||||
}
|
||||
return (undef, "xCAT BMC configuration error, no appropriate network for $ip found in networks, unable to determine the prefix length");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 bmc_net_params
|
||||
@@ -47,13 +85,18 @@ sub _ipv4_number {
|
||||
Descriptions:
|
||||
The address, netmask and gateway that bmcconfig sends to bmcsetup for one BMC.
|
||||
The networks row that contains the address gives the netmask and the gateway.
|
||||
For an IPv6 BMC the netmask is the prefix length, and a fourth value is the
|
||||
prefix of the network, which bmcsetup writes with the static router.
|
||||
A name that resolves to both families gives the IPv4 address.
|
||||
Arguments:
|
||||
$bmc the ipmi.bmc value of one BMC, an address or a host name
|
||||
$nets array ref of networks rows, hashes with net, mask and gateway
|
||||
%opt resolve4 => coderef, name to packed IPv4 address, default inet_aton
|
||||
resolve6 => coderef, name to IPv6 address, default no IPv6
|
||||
facing => coderef, (address, family) to the MN address on that network
|
||||
Returns:
|
||||
(address, netmask, gateway), or (undef, error message)
|
||||
(address, netmask, gateway), (address, prefix length, gateway, prefix) for
|
||||
IPv6, or (undef, error message)
|
||||
|
||||
=cut
|
||||
|
||||
@@ -64,7 +107,12 @@ sub bmc_net_params {
|
||||
my $facing = $opt{facing} || sub { return; };
|
||||
|
||||
my $packed = $resolve4->($bmc);
|
||||
return (undef, "Unable to resolve $bmc") unless $packed;
|
||||
unless ($packed) {
|
||||
my $ip6 = $bmc =~ /:/ ? $bmc : ($opt{resolve6} || sub { return; })->($bmc);
|
||||
return _bmc_net6_params($ip6, $nets, $facing)
|
||||
if defined($ip6) && _ipv6_packed($ip6);
|
||||
return (undef, "Unable to resolve $bmc");
|
||||
}
|
||||
my $ip = inet_ntoa($packed);
|
||||
my $ipnum = unpack('N', $packed);
|
||||
|
||||
|
||||
@@ -37,8 +37,14 @@ sub net_parms {
|
||||
my @nets = $nettab->getAllAttribs('net', 'mask', 'gateway');
|
||||
my @parms = xCAT::BMCUtils::bmc_net_params(
|
||||
$bmc, \@nets,
|
||||
resolve6 => sub {
|
||||
return xCAT::NetworkUtils->getipaddr($_[0], OnlyV6 => 1);
|
||||
},
|
||||
facing => sub {
|
||||
my @facing = xCAT::NetworkUtils->my_ip_facing($_[0]);
|
||||
my ($ip, $family) = @_;
|
||||
my @facing = $family == 6
|
||||
? xCAT::NetworkUtils->my_ip_facing_family($ip, 6)
|
||||
: xCAT::NetworkUtils->my_ip_facing($ip);
|
||||
return $facing[0] ? undef : $facing[1];
|
||||
});
|
||||
return @parms if defined $parms[0];
|
||||
@@ -132,7 +138,7 @@ sub process_request {
|
||||
}
|
||||
my $bmcport_counter = 0;
|
||||
foreach my $sbmc (split /,/, $bmc) {
|
||||
(my $ip, my $mask, my $gw) = net_parms($sbmc);
|
||||
my ($ip, $mask, $gw, $routerprefix) = net_parms($sbmc);
|
||||
unless ($ip and $mask and $username and $password) {
|
||||
my $passtate = defined($password) && length($password) ? "set" : "missing";
|
||||
xCAT::MsgUtils->message('S', "Unable to determine IP, Netmask, Username, or Password for $sbmc. Ensure that hostname resolution is working. [IP=$ip Netmask=$mask User=$username Pass=$passtate]",);
|
||||
@@ -144,6 +150,7 @@ sub process_request {
|
||||
return;
|
||||
}
|
||||
my $response = { bmcip => $ip, netmask => $mask, gateway => $gw, username => $username, password => $password };
|
||||
$response->{routerprefix} = $routerprefix if defined $routerprefix;
|
||||
if (defined $bmcport) {
|
||||
if ($bmcport =~ /,/) {
|
||||
my @sbmcport = (split /,/, $bmcport);
|
||||
|
||||
Reference in New Issue
Block a user