mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-20 17:32:15 +00:00
fix(xcat-core): sequential discovery over IPv6 finds no nic in the deploy network
Sequential discovery over IPv6 matched the pool node and then failed with "No nic found in deploy network for seqdisc1". NetworkManager installs a DHCPv6 lease as a /128, so Genesis reports the boot nic as 2001:db8:188::1004/128. hosttag_for_ipv6_nic masked both addresses with that prefix length, and a /128 never matches the address of the node. For a /128, hosttag_for_ipv6_nic now takes the network from the IPv6 rows of the networks table, which nodediscover reads once per request through the new ipv6_networks. discovery_hosttag_ipv6_nic.t fails without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -327,6 +327,37 @@ sub nic_network_key
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
=head3 ipv6_networks
|
||||
|
||||
The IPv6 networks of networks table rows, as [network, prefix length] pairs.
|
||||
|
||||
Arguments:
|
||||
the rows, each a hash with net and mask. An IPv6 net may carry its own /len, and an
|
||||
IPv6 mask is written /len.
|
||||
Returns:
|
||||
an arrayref of pairs
|
||||
|
||||
=cut
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
sub ipv6_networks
|
||||
{
|
||||
my $rows = shift;
|
||||
$rows = shift if defined($rows) && !ref($rows) && $rows eq __PACKAGE__;
|
||||
|
||||
my @networks;
|
||||
foreach my $row ( @{ $rows || [] } ) {
|
||||
my ( $net, $bits ) = split m{/}, ( $row->{net} || '' ), 2;
|
||||
next unless defined($net) && xCAT::NetworkUtils->isIpv6addr($net);
|
||||
($bits) = ( $row->{mask} || '' ) =~ m{\A/?(\d+)\z} unless defined($bits) && length($bits);
|
||||
next unless defined($bits) && $bits =~ /\A\d+\z/ && $bits <= 128;
|
||||
push @networks, [ $net, $bits ];
|
||||
}
|
||||
return \@networks;
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
=head3 hosttag_for_ipv6_nic
|
||||
|
||||
The hostname tag a discovered IPv6 NIC takes.
|
||||
@@ -337,7 +368,8 @@ sub nic_network_key
|
||||
|
||||
Arguments:
|
||||
the node, its address, the interface name, the address of the NIC, the prefix length,
|
||||
and the names already taken
|
||||
the names already taken, and the IPv6 networks of the networks table as
|
||||
[network, prefix length] pairs
|
||||
Returns:
|
||||
the node, an interface-qualified name, or undef when the NIC is on another network
|
||||
|
||||
@@ -348,7 +380,7 @@ sub hosttag_for_ipv6_nic
|
||||
{
|
||||
my $node = shift;
|
||||
$node = shift if defined($node) && !ref($node) && $node eq __PACKAGE__;
|
||||
my ( $nodeaddr, $ifname, $nicaddr, $netbits, $usednames ) = @_;
|
||||
my ( $nodeaddr, $ifname, $nicaddr, $netbits, $usednames, $networks ) = @_;
|
||||
|
||||
return undef unless defined($node) && length($node);
|
||||
return undef unless defined($nicaddr) && length($nicaddr);
|
||||
@@ -360,7 +392,24 @@ sub hosttag_for_ipv6_nic
|
||||
|
||||
my $nicnet = nic_network_key( $nicaddr, $netbits );
|
||||
my $nodenet = nic_network_key( $nodeaddr, $netbits );
|
||||
return undef unless defined($nicnet) && defined($nodenet) && $nicnet eq $nodenet;
|
||||
my $same = defined($nicnet) && defined($nodenet) && $nicnet eq $nodenet;
|
||||
|
||||
# NetworkManager installs a DHCPv6 lease as a /128. That prefix names one address and no
|
||||
# network, so take the network from the networks table instead.
|
||||
if ( !$same && defined($netbits) && $netbits eq '128' ) {
|
||||
foreach my $network ( @{ $networks || [] } ) {
|
||||
my ( $net, $bits ) = @$network;
|
||||
my $key = nic_network_key( $net, $bits );
|
||||
next unless defined($key);
|
||||
my $nic = nic_network_key( $nicaddr, $bits );
|
||||
my $node = nic_network_key( $nodeaddr, $bits );
|
||||
if ( defined($nic) && defined($node) && $nic eq $key && $node eq $key ) {
|
||||
$same = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undef unless $same;
|
||||
|
||||
return $node unless $usednames && $usednames->{$node};
|
||||
return "$node-$ifname" if defined($ifname) && length($ifname);
|
||||
|
||||
@@ -304,6 +304,7 @@ sub process_request {
|
||||
my %bydriverindex;
|
||||
my $forcenic = 0; #-1 is force skip, 0 is use default behavior, 1 is force to be declared even if hosttag is skipped to do so
|
||||
my $localnic = 0;
|
||||
my $ipv6_networks;
|
||||
foreach (@{ $request->{mac} }) {
|
||||
@ifinfo = split /\|/;
|
||||
|
||||
@@ -357,8 +358,14 @@ sub process_request {
|
||||
} else {
|
||||
# gethosttag reads an A record and my_if_netmap, which is netstat -rn and
|
||||
# prints IPv4 routes only, so an IPv6 nic is matched on the addresses.
|
||||
unless ($ipv6_networks) {
|
||||
my $nettab = xCAT::Table->new('networks');
|
||||
my @rows = $nettab ? $nettab->getAllAttribs( 'net', 'mask' ) : ();
|
||||
$ipv6_networks = xCAT::DiscoveryUtils::ipv6_networks( \@rows );
|
||||
}
|
||||
$hosttag = xCAT::DiscoveryUtils::hosttag_for_ipv6_nic(
|
||||
$node, $nodeaddr, $ifinfo[1], $ip, $netbits, \%usednames);
|
||||
$node, $nodeaddr, $ifinfo[1], $ip, $netbits, \%usednames,
|
||||
$ipv6_networks);
|
||||
push @hostnames_to_update, $hosttag
|
||||
if defined($hosttag) && $hosttag ne $node;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# $localnic and stops process_request returning "No nic found in deploy network".
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 9;
|
||||
use Test::More tests => 10;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
|
||||
@@ -55,3 +55,12 @@ is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic(
|
||||
is( xCAT::DiscoveryUtils::hosttag_for_ipv6_nic(
|
||||
'seqdisc1', '2001:db8:188::21', 'eth0', '2001:db8:188::1004', 128, \%fresh ),
|
||||
undef, 'with no networks to compare a /128 against, it is not the node' );
|
||||
|
||||
# The rows as makenetworks writes them: an IPv6 net carries its own /len and the mask is /len.
|
||||
is_deeply( xCAT::DiscoveryUtils::ipv6_networks( [
|
||||
{ net => '192.168.88.0', mask => '255.255.255.0' },
|
||||
{ net => '2001:db8:188::/64', mask => '/64' },
|
||||
{ net => '2001:db8:99::', mask => '/56' },
|
||||
] ),
|
||||
[ [ '2001:db8:188::', 64 ], [ '2001:db8:99::', 56 ] ],
|
||||
'the IPv6 rows of the networks table, with the IPv4 row left out' );
|
||||
|
||||
Reference in New Issue
Block a user