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

feat(ipv6): add EL10 IPv6-only provisioning support

An IPv6-only provisioning network cannot deploy a node. The discovery and
credential callbacks open IPv4 sockets, the kickstart and boot templates
render an IPv4 address into every endpoint, and makehosts drops an IPv6
value because hosts.pm gates on isIpv4addr.

NetworkUtils gains the address helpers the rest of the change uses:
format_host_port, parse_host_port and format_uri_host bracket an IPv6
literal, getNodeNetworkCfg6 reads the static IPv6 configuration of a node,
my_ip_facing_family selects the management-node address of one family,
getIPv6ReverseZone builds a nibble-aligned reverse zone, and
node_is_ipv6_only and ipv6_server_for_node answer the two questions the
plugins used to answer for themselves. credentials.pm opens the callback
socket through IO::Socket::INET6 when the modules are present and keeps the
IPv4 path when they are not. Template.pm and anaconda.pm render an IPv6
kickstart network line and bracketed endpoints. The postscripts and the
stateless xcatroot format every endpoint through the bracketing helpers.

xCAT-server requires perl-IO-Socket-INET6 and perl-Socket6 on EL, and
libio-socket-inet6-perl and libsocket6-perl on Debian.

(cherry picked from commits c0a69bb5a and caa8ca790)
Ported onto upstream master ee6b4f532. The two commits are folded because the
second refactors the first. Master is kept where it has a newer form of the
same thing: the getipaddr cache guard, the Kea control_socket_path helper, the
netboot method list, install_device_params, the modern_installer test and the
isValidIp validator, which replaces the isValidIPAddress this branch added.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Vinícius Ferrão
2026-10-21 18:59:05 -03:00
committed by Daniel Hilst
parent 21a0ad8089
commit 3928c04507
55 changed files with 5926 additions and 489 deletions
+8
View File
@@ -78,6 +78,14 @@ There are 3 methods to configure aliases:
20.1.1.1 node1-hd
* For an IPv6 address, use ``!`` instead of ``:`` to separate the interface hostname and address: ::
chdef node1 otherinterfaces='node1-v6!2001:db8::101'
After executing ``makehosts -n``, the generated record is: ::
2001:db8::101 node1-v6
**Note**: If suffixes or aliases for the same IP are configured in both ``hosts`` table and ``nics`` table, will cause conflicts. ``makehosts`` will use values from ``nics`` table. The values from ``nics`` table will over-write that from ``hosts`` table to create ``/etc/hosts`` records.
Q: How to handle the same short hostname in different domains?
@@ -44,7 +44,7 @@ hosts Attributes:
\ **ip**\
The IP address of the node. This is only used in makehosts. The rest of xCAT uses system name resolution to resolve node names to IP addresses.
The IPv4 or IPv6 address literal of the node. makehosts and makedns use this value; the rest of xCAT uses system name resolution to resolve node names to IP addresses.
@@ -56,7 +56,7 @@ hosts Attributes:
\ **otherinterfaces**\
Other IP addresses to add for this node. Format: -<ext>:<ip>,<intfhostname>:<ip>,...
Other IP addresses to add for this node. Format: -<ext>:<IPv4>, <intfhostname>:<IPv4>, -<ext>!<IPv6>, or <intfhostname>!<IPv6>. A leading - derives the interface hostname from the node name; ! is required as the delimiter for IPv6 addresses.
@@ -79,4 +79,3 @@ SEE ALSO
\ **nodels(1)**\ , \ **chtab(8)**\ , \ **tabdump(8)**\ , \ **tabedit(8)**\
@@ -391,7 +391,7 @@ group Attributes:
\ **ip**\ (hosts.ip)
The IP address of the node. This is only used in makehosts. The rest of xCAT uses system name resolution to resolve node names to IP addresses.
The IPv4 or IPv6 address literal of the node. makehosts and makedns use this value; the rest of xCAT uses system name resolution to resolve node names to IP addresses.
@@ -705,7 +705,7 @@ group Attributes:
\ **otherinterfaces**\ (hosts.otherinterfaces)
Other IP addresses to add for this node. Format: -<ext>:<ip>,<intfhostname>:<ip>,...
Other IP addresses to add for this node. Format: -<ext>:<IPv4>, <intfhostname>:<IPv4>, -<ext>!<IPv6>, or <intfhostname>!<IPv6>. A leading - derives the interface hostname from the node name; ! is required as the delimiter for IPv6 addresses.
@@ -1392,4 +1392,3 @@ SEE ALSO
\ **mkdef(1)**\ , \ **chdef(1)**\ , \ **lsdef(1)**\ , \ **rmdef(1)**\
@@ -403,7 +403,7 @@ node Attributes:
\ **ip**\ (hosts.ip)
The IP address of the node. This is only used in makehosts. The rest of xCAT uses system name resolution to resolve node names to IP addresses.
The IPv4 or IPv6 address literal of the node. makehosts and makedns use this value; the rest of xCAT uses system name resolution to resolve node names to IP addresses.
@@ -711,7 +711,7 @@ node Attributes:
\ **otherinterfaces**\ (hosts.otherinterfaces)
Other IP addresses to add for this node. Format: -<ext>:<ip>,<intfhostname>:<ip>,...
Other IP addresses to add for this node. Format: -<ext>:<IPv4>, <intfhostname>:<IPv4>, -<ext>!<IPv6>, or <intfhostname>!<IPv6>. A leading - derives the interface hostname from the node name; ! is required as the delimiter for IPv6 addresses.
@@ -1428,4 +1428,3 @@ SEE ALSO
\ **mkdef(1)**\ , \ **chdef(1)**\ , \ **lsdef(1)**\ , \ **rmdef(1)**\
@@ -102,11 +102,27 @@ EXAMPLES
"compute","|node(\d+)|1.2.3.($1+0)|","|(.*)|($1).cluster.net|",,
Assuming the group "compute" contains node01, node02, etc., then in /etc/hosts they will be given
IP addresses of 1.2.3.1, 1.2.3.2, etc.
IP addresses of 1.2.3.1, 1.2.3.2, etc.
3. Add an IPv6 primary address and an IPv6 additional interface for node01. The
exclamation mark separates an interface hostname from an IPv6 address because
the address itself contains colons. This example assumes the site domain is
example.com.
.. code-block:: perl
chdef node01 ip=2001:db8::10 otherinterfaces='node01-storage!2001:db8:1::10'
makehosts node01
The resulting entries include:
.. code-block:: perl
2001:db8::10 node01 node01.example.com
2001:db8:1::10 node01-storage node01-storage.example.com
********
@@ -114,4 +130,3 @@ SEE ALSO
********
hosts(5)|hosts.5, makedns(8)|makedns.8
+174 -3
View File
@@ -12,8 +12,17 @@ use strict;
use Socket;
use xCAT::MsgUtils;
use xCAT::NetworkUtils;
use xCAT::Utils;
=head1 NAME
xCAT::DSHCore - distributed command execution and reachability helpers
=head1 FUNCTIONS
=head2 Process and ping helpers
#---------------------------------------------------------------------------
=head3
@@ -676,6 +685,169 @@ sub ping_hostnames
}
#---------------------------------------------------------------------------
=head3
partition_ping_targets
Resolves ping targets and separates them into the address family that
should be probed. IPv4 remains preferred for dual-stack targets so
existing behavior is preserved.
Arguments:
@targets - hostnames or address literals
Returns:
references to the IPv4, IPv6, and unresolved target arrays
=cut
#---------------------------------------------------------------------------
sub partition_ping_targets
{
my ($class, @targets) = @_;
my (@ipv4, @ipv6, @unresolved);
foreach my $target (@targets)
{
my $family = xCAT::NetworkUtils->node_address_family($target);
if (defined($family) && $family == 4)
{
push @ipv4, $target;
}
elsif (defined($family) && $family == 6)
{
push @ipv6, $target;
}
else
{
push @unresolved, $target;
}
}
return (\@ipv4, \@ipv6, \@unresolved);
}
#---------------------------------------------------------------------------
=head3
match_ping_target
Maps a name or numeric address reported by a ping backend to the
original target supplied by xCAT.
=cut
#---------------------------------------------------------------------------
sub match_ping_target
{
my ($class, $candidate, $targets) = @_;
return unless defined($candidate) && ref($targets) eq 'ARRAY';
$candidate =~ s/^\s+|\s+$//g;
foreach my $target (@{$targets})
{
return $target if lc($candidate) eq lc($target);
return $target if $candidate =~ /^\Q$target\E\./i;
}
foreach my $target (@{$targets})
{
foreach my $family (qw(OnlyV4 OnlyV6))
{
my $address = xCAT::NetworkUtils->getipaddr($target, $family => 1);
return $target
if defined($address) && lc($candidate) eq lc($address);
}
}
return;
}
#---------------------------------------------------------------------------
=head3
nmap_alive_targets
Parses old and current nmap ping-scan output and returns the original
xCAT targets that nmap reported as reachable.
=cut
#---------------------------------------------------------------------------
sub nmap_alive_targets
{
my ($class, $targets, $output) = @_;
return unless ref($targets) eq 'ARRAY' && ref($output) eq 'ARRAY';
my %alive;
my $current_target;
foreach my $line (@{$output})
{
if ($line =~ /^Host\s+(.+?)(?:\s+\(([^)]*)\))?\s+appears to be up\b/)
{
my $target = $class->match_ping_target($1, $targets);
if (!defined($target) && defined($2))
{
$target = $class->match_ping_target($2, $targets);
}
$alive{$target} = 1 if defined($target);
next;
}
if ($line =~ /^Nmap scan report for\s+(.+?)\s*$/)
{
my $reported = $1;
my $reported_address;
if ($reported =~ s/\s+\(([^()]*)\)\s*$//)
{
$reported_address = $1;
}
$current_target = $class->match_ping_target($reported, $targets);
if (!defined($current_target) && defined($reported_address))
{
$current_target =
$class->match_ping_target($reported_address, $targets);
}
next;
}
if ($line =~ /^Host is up\b/ && defined($current_target))
{
$alive{$current_target} = 1;
}
}
return grep { $alive{$_} } @{$targets};
}
#---------------------------------------------------------------------------
=head3
parse_pping_result_line
Parses the stable C<target: ping|noping> output contract. The greedy
target match intentionally accepts IPv6 address literals containing
colons.
=cut
#---------------------------------------------------------------------------
sub parse_pping_result_line
{
my ($class, $line) = @_;
return unless defined($line);
return ($1, $2) if $line =~ /^(.+):\s+(ping|noping)\s*$/;
return;
}
#---------------------------------------------------------------------------
=head3
@@ -735,9 +907,8 @@ sub pping_hostnames
my @no_response = ();
foreach my $line (@output)
{
my ($hostname, $result) = split ':', $line;
my ($token, $status) = split ' ', $result;
chomp($token);
my ($hostname, $token) = $class->parse_pping_result_line($line);
next unless defined($hostname);
if ($token ne 'ping') {
push @no_response, $hostname;
}
+15 -3
View File
@@ -756,22 +756,34 @@ sub get_server_nodes
foreach my $node (@nodelist)
{
my $serv;
my $node_family = xCAT::NetworkUtils->node_address_family($node);
if ($xcatmasters->{$node}->[0]->{xcatmaster})
{
# get ip of node xcatmaster attribute
my $xcatmaster = $xcatmasters->{$node}->[0]->{xcatmaster};
$serv = xCAT::NetworkUtils->getipaddr($xcatmaster);
$serv = defined($node_family) && $node_family == 6
? xCAT::NetworkUtils->getipaddr($xcatmaster, OnlyV6 => 1)
: defined($node_family) && $node_family == 4
? xCAT::NetworkUtils->getipaddr($xcatmaster, OnlyV4 => 1)
: xCAT::NetworkUtils->getipaddr($xcatmaster);
}
elsif (!$skipfacing)
{
# get ip facing node
my @servd = xCAT::NetworkUtils->my_ip_facing($node);
my @servd = defined($node_family) && $node_family == 6
? xCAT::NetworkUtils->my_ip_facing_family($node, 6)
: xCAT::NetworkUtils->my_ip_facing($node);
unless ($servd[0]) { $serv = $servd[1]; }
}
else{
next;
}
chomp $serv if $serv;
unless (defined($serv) && length($serv))
{
push(@{ $servernodes{''} }, $node);
next;
}
chomp $serv;
if (xCAT::NetworkUtils->isValidIp($serv)) {
push(@{ $servernodes{$serv} }, $node);
+702 -27
View File
@@ -23,9 +23,26 @@ use Sys::Hostname;
use strict;
use warnings "all";
my $socket6support = eval { require Socket6 };
my $core_socket_resolver = defined(&Socket::getaddrinfo)
&& defined(&Socket::getnameinfo)
&& defined(&Socket::inet_pton)
&& eval {
my @required_constants = (
Socket::AF_INET6(),
Socket::AI_NUMERICHOST(),
Socket::NI_NUMERICHOST(),
);
scalar(@required_constants) == 3;
};
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(getipaddr);
our @EXPORT_OK = qw(
format_host_port
format_uri_host
getipaddr
my_ip_facing_family
parse_host_port
);
my $utildata; #data to persist locally
@@ -169,7 +186,7 @@ sub gethostname()
$iporhost = @{$iporhost}[0];
if (!$iporhost)
{
return undef;
return;
}
}
@@ -287,6 +304,15 @@ sub getipaddr
#print "\n";
#print "============================\n";
# Keep family-specific lookups out of the legacy cache. Otherwise an
# OnlyV6 lookup can make a later OnlyV4 lookup return an IPv6 address (and
# vice versa).
my $cache_suffix = $extraarguments{OnlyV6} ? '_v6'
: $extraarguments{OnlyV4} ? '_v4'
: '';
my $host_cache_key = 'hostip' . $cache_suffix;
my $number_cache_key = 'Number' . $cache_suffix;
#cache, do not lookup DNS each time
#
# An unrestricted lookup asks for AF_UNSPEC and caches whatever came back, which
@@ -305,13 +331,23 @@ sub getipaddr
{
if($extraarguments{GetNumber} ) {
if($::hostiphash{$iporhost}{Number}){
if(defined($::hostiphash{$iporhost}{$number_cache_key})){
#print "YYYYYYYYYY GetNumber Cache Hit!!!YYYYYYYYY\n";
return $::hostiphash{$iporhost}{Number};
return $::hostiphash{$iporhost}{$number_cache_key};
}
} elsif($::hostiphash{$iporhost}{hostip}) {
} elsif(defined($::hostiphash{$iporhost}{$host_cache_key})) {
#print "YYYYYYYYYY dns Cache Hit!!!YYYYYYYYY\n";
return $::hostiphash{$iporhost}{hostip};
return $::hostiphash{$iporhost}{$host_cache_key};
} elsif($cache_suffix && defined($::hostiphash{$iporhost}{hostip})) {
my $cached_ip = $::hostiphash{$iporhost}{hostip};
if (($extraarguments{OnlyV4} && xCAT::NetworkUtils->isIpaddr($cached_ip))
|| ($extraarguments{OnlyV6}
&& $cached_ip =~ /:/
&& xCAT::NetworkUtils->isValidIp($cached_ip)))
{
$::hostiphash{$iporhost}{$host_cache_key} = $cached_ip;
return $cached_ip;
}
}
}
@@ -334,10 +370,10 @@ sub getipaddr
unless($reqfamily == AF_INET6){
if($isip){
if($name){
$::hostiphash{$iporhost}{hostip}=$name;
$::hostiphash{$iporhost}{$host_cache_key}=$name;
}
}elsif($ip){
$::hostiphash{$iporhost}{hostip}=$ip;
$::hostiphash{$iporhost}{$host_cache_key}=$ip;
}
}
while ($ip)
@@ -350,10 +386,23 @@ sub getipaddr
$bignumber->badd($_);
}
push(@returns, $bignumber);
$::hostiphash{$iporhost}{Number}=$returns[0];
$::hostiphash{$iporhost}{$number_cache_key}=$returns[0];
unless ($cache_suffix)
{
my $family_key = $family == AF_INET6 ? 'Number_v6' : 'Number_v4';
$::hostiphash{$iporhost}{$family_key} = $bignumber
unless defined($::hostiphash{$iporhost}{$family_key});
}
} else {
push @returns, (Socket6::getnameinfo($ip, Socket6::NI_NUMERICHOST()))[0];
$::hostiphash{$iporhost}{hostip}=$returns[0];
my $numeric_ip = (Socket6::getnameinfo($ip, Socket6::NI_NUMERICHOST()))[0];
push @returns, $numeric_ip;
$::hostiphash{$iporhost}{$host_cache_key}=$returns[0];
unless ($cache_suffix)
{
my $family_key = $family == AF_INET6 ? 'hostip_v6' : 'hostip_v4';
$::hostiphash{$iporhost}{$family_key} = $numeric_ip
unless defined($::hostiphash{$iporhost}{$family_key});
}
}
if (scalar @addrinfo and $extraarguments{GetAllAddresses}) {
($family, $socket, $protocol, $ip, $name) = splice(@addrinfo, 0, 5);
@@ -366,11 +415,82 @@ sub getipaddr
}
return @returns;
}
elsif ($core_socket_resolver)
{
my $reqfamily = Socket::AF_UNSPEC();
if ($extraarguments{OnlyV6}) {
$reqfamily = Socket::AF_INET6();
} elsif ($extraarguments{OnlyV4}) {
$reqfamily = Socket::AF_INET();
}
my %hints = (
family => $reqfamily,
socktype => Socket::SOCK_STREAM(),
protocol => 6,
);
$hints{flags} = Socket::AI_NUMERICHOST() if $isip;
my ($error, @addrinfo) = Socket::getaddrinfo($iporhost, 0, \%hints);
if ($error)
{
return () if $extraarguments{GetAllAddresses};
return;
}
my @returns;
foreach my $address (@addrinfo)
{
my ($name_error, $numeric_ip) = Socket::getnameinfo(
$address->{addr}, Socket::NI_NUMERICHOST()
);
next if $name_error || !defined($numeric_ip);
if ($extraarguments{GetNumber})
{
my $packed = Socket::inet_pton($address->{family}, $numeric_ip);
next unless defined($packed);
my $bignumber = Math::BigInt->new(0);
foreach (unpack("N*", $packed))
{
$bignumber->blsft(32);
$bignumber->badd($_);
}
push @returns, $bignumber;
$::hostiphash{$iporhost}{$number_cache_key} = $returns[0];
unless ($cache_suffix)
{
my $family_key = $address->{family} == Socket::AF_INET6()
? 'Number_v6' : 'Number_v4';
$::hostiphash{$iporhost}{$family_key} = $bignumber
unless defined($::hostiphash{$iporhost}{$family_key});
}
}
else
{
push @returns, $numeric_ip;
$::hostiphash{$iporhost}{$host_cache_key} = $returns[0];
unless ($cache_suffix)
{
my $family_key = $address->{family} == Socket::AF_INET6()
? 'hostip_v6' : 'hostip_v4';
$::hostiphash{$iporhost}{$family_key} = $numeric_ip
unless defined($::hostiphash{$iporhost}{$family_key});
}
}
last unless $extraarguments{GetAllAddresses};
}
unless ($extraarguments{GetAllAddresses}) {
return $returns[0];
}
return @returns;
}
else
{
#return inet_ntoa(inet_aton($iporhost))
#TODO, what if no scoket6 support, but passing in a IPv6 hostname?
if ($iporhost =~ /:/) { #ipv6
if ($extraarguments{OnlyV6} || $iporhost =~ /:/) { #ipv6
return undef;
#die "Attempt to process IPv6 address, but system does not have requisite IPv6 perl support";
@@ -385,12 +505,22 @@ sub getipaddr
my $myip=inet_ntoa($packed_ip);
unless($isip) {
$::hostiphash{$iporhost}{hostip}=$myip;
$::hostiphash{$iporhost}{$host_cache_key}=$myip;
unless ($cache_suffix)
{
$::hostiphash{$iporhost}{hostip_v4}=$myip
unless defined($::hostiphash{$iporhost}{hostip_v4});
}
}
if ($extraarguments{GetNumber}) { #only 32 bits, no for loop needed.
my $number=Math::BigInt->new(unpack("N*", $packed_ip));
$::hostiphash{$iporhost}{Number}=$number;
$::hostiphash{$iporhost}{$number_cache_key}=$number;
unless ($cache_suffix)
{
$::hostiphash{$iporhost}{Number_v4}=$number
unless defined($::hostiphash{$iporhost}{Number_v4});
}
return $number;
}
@@ -1303,6 +1433,337 @@ sub my_ip_facing
#-------------------------------------------------------------------------------
=head3 my_ip_facing_family
Returns local addresses in the same subnet as the specified peer,
restricted to the requested address family. Linux only.
Arguments:
peer hostname or address
address family (4 or 6)
Returns:
[0, ip1, ip2, ...] when matching local addresses are found
[1, error] when the peer cannot be resolved in the requested family
[2, error] when no local address shares the peer's subnet
Example:
my @ip = xCAT::NetworkUtils->my_ip_facing_family($peer, 6)
=cut
#-------------------------------------------------------------------------------
sub _local_ip_prefixes
{
my $family = shift;
return unless defined($family) && ($family == 4 || $family == 6);
return if $^O eq 'aix';
my $ipcmd = -x '/sbin/ip' ? '/sbin/ip'
: -x '/usr/sbin/ip' ? '/usr/sbin/ip'
: undef;
return unless $ipcmd;
my $address_type = $family == 6 ? 'inet6' : 'inet';
my @addresses;
if (open(my $ipout, '-|', $ipcmd, '-o', "-$family", 'addr', 'show', 'scope', 'global'))
{
while (my $line = <$ipout>)
{
if ($line =~ /\s\Q$address_type\E\s+([^\s\/]+)\/(\d+)/)
{
push @addresses, [ $1, $2 ];
}
}
close($ipout);
}
return @addresses;
}
sub _pack_ip_address
{
my ($address, $family) = @_;
return unless defined($address);
if ($family == 4)
{
return inet_aton($address);
}
my $packed;
if (defined(&Socket::inet_pton))
{
$packed = eval { Socket::inet_pton(Socket::AF_INET6(), $address) };
}
if (!defined($packed) && $socket6support)
{
$packed = eval { Socket6::inet_pton(Socket6::AF_INET6(), $address) };
}
return $packed;
}
#-------------------------------------------------------------------------------
=head3 getIPv6PrefixLength
Returns the numeric prefix length from an IPv6 network and optional mask.
Arguments:
IPv6 network, optionally with a CIDR suffix
Optional numeric prefix mask
Returns:
Prefix length from 0 through 128, or undef
=cut
#-------------------------------------------------------------------------------
sub getIPv6PrefixLength
{
my $network = shift;
if (defined($network) && $network eq __PACKAGE__)
{
$network = shift;
}
my $mask = shift;
return unless defined($network) && $network =~ /:/;
my $prefix;
if ($network =~ m{/([0-9]+)$})
{
$prefix = $1;
}
elsif (defined($mask) && $mask =~ m{^/?([0-9]+)$})
{
$prefix = $1;
}
return unless defined($prefix) && $prefix <= 128;
return $prefix;
}
#-------------------------------------------------------------------------------
=head3 getIPv6ReverseZone
Formats the nibble-aligned ip6.arpa zone for an IPv6 network.
Arguments:
IPv6 network, optionally with a CIDR suffix
Optional numeric prefix mask
Returns:
Reverse zone name, or undef for invalid or non-nibble-aligned input
=cut
#-------------------------------------------------------------------------------
sub getIPv6ReverseZone
{
my $network = shift;
if (defined($network) && $network eq __PACKAGE__)
{
$network = shift;
}
my $mask = shift;
my $prefix = xCAT::NetworkUtils->getIPv6PrefixLength($network, $mask);
return unless defined($prefix) && $prefix % 4 == 0;
my $address = $network;
$address =~ s{/.*$}{};
my $packed = _pack_ip_address($address, 6);
return unless defined($packed);
return 'ip6.arpa.' if $prefix == 0;
my $hex = substr(unpack('H*', $packed), 0, $prefix / 4);
return join('.', reverse(split(//, $hex))) . '.ip6.arpa.';
}
#-------------------------------------------------------------------------------
=head3 getIPv6ReverseName
Formats the complete 32-nibble ip6.arpa owner name for an IPv6 literal.
=cut
#-------------------------------------------------------------------------------
sub getIPv6ReverseName
{
my $address = shift;
if (defined($address) && $address eq __PACKAGE__)
{
$address = shift;
}
return xCAT::NetworkUtils->getIPv6ReverseZone($address, 128);
}
#-------------------------------------------------------------------------------
=head3 isSameIPAddress
Compares two IPv4 or IPv6 literals by their packed address value.
Arguments:
Two IPv4 or IPv6 address literals
Returns:
1 - equivalent addresses
0 - different or invalid addresses
=cut
#-------------------------------------------------------------------------------
sub isSameIPAddress
{
my $first = shift;
if (defined($first) && $first eq __PACKAGE__)
{
$first = shift;
}
my $second = shift;
return 0 unless xCAT::NetworkUtils->isValidIp($first)
&& xCAT::NetworkUtils->isValidIp($second);
my $family = $first =~ /:/ ? 6 : 4;
return 0 if ($second =~ /:/ ? 6 : 4) != $family;
my $first_packed = _pack_ip_address($first, $family);
my $second_packed = _pack_ip_address($second, $family);
return defined($first_packed)
&& defined($second_packed)
&& $first_packed eq $second_packed ? 1 : 0;
}
sub _addresses_share_prefix
{
my ($first, $second, $prefix, $family) = @_;
my $max_prefix = $family == 6 ? 128 : 32;
return 0 unless defined($prefix)
&& $prefix =~ /^\d+$/
&& $prefix >= 0
&& $prefix <= $max_prefix;
my $first_packed = _pack_ip_address($first, $family);
my $second_packed = _pack_ip_address($second, $family);
return 0 unless defined($first_packed) && defined($second_packed);
my $whole_bytes = int($prefix / 8);
return 0
if substr($first_packed, 0, $whole_bytes)
ne substr($second_packed, 0, $whole_bytes);
my $remaining_bits = $prefix % 8;
if ($remaining_bits)
{
my $mask = (0xff << (8 - $remaining_bits)) & 0xff;
return 0
if (ord(substr($first_packed, $whole_bytes, 1)) & $mask)
!= (ord(substr($second_packed, $whole_bytes, 1)) & $mask);
}
return 1;
}
#-------------------------------------------------------------------------------
=head3 node_address_family
Returns the preferred address family for a node. IPv4 remains preferred
for dual-stack nodes to preserve existing xCAT behavior.
=cut
#-------------------------------------------------------------------------------
sub node_address_family
{
my $node = shift;
if (defined($node) && $node eq __PACKAGE__)
{
$node = shift;
}
return 4 if xCAT::NetworkUtils->getipaddr($node, OnlyV4 => 1);
return 6 if xCAT::NetworkUtils->getipaddr($node, OnlyV6 => 1);
return;
}
sub node_is_ipv6_only
{
my $node = shift;
if (defined($node) && $node eq __PACKAGE__)
{
$node = shift;
}
my $family = xCAT::NetworkUtils->node_address_family($node);
return defined($family) && $family == 6 ? 1 : 0;
}
sub my_ip_facing_family
{
my $peer = shift;
if (defined($peer) && $peer eq __PACKAGE__)
{
$peer = shift;
}
my $family = shift;
unless (defined($family) && ($family == 4 || $family == 6))
{
return (1, 'Address family must be 4 or 6');
}
my $peerip = $family == 6
? xCAT::NetworkUtils->getipaddr($peer, OnlyV6 => 1)
: xCAT::NetworkUtils->getipaddr($peer, OnlyV4 => 1);
unless ($peerip)
{
return (1, "The $peer can not be resolved as IPv$family");
}
my @ips;
foreach my $local (_local_ip_prefixes($family))
{
my ($address, $prefix) = @{$local};
if (_addresses_share_prefix($peerip, $address, $prefix, $family))
{
push @ips, $address;
}
}
if (@ips)
{
return (0, @ips);
}
return (2, "The IPv$family address of node $peer is in an undefined subnet");
}
sub ipv6_server_for_node
{
my $node = shift;
if (defined($node) && $node eq __PACKAGE__)
{
$node = shift;
}
my $server = shift;
if (!defined($server) || $server eq '!myipfn!' || $server eq '<xcatmaster>')
{
my @facing = xCAT::NetworkUtils->my_ip_facing_family($node, 6);
return unless @facing && !$facing[0];
return $facing[1];
}
return $server
if $server =~ /:/ && xCAT::NetworkUtils->isValidIPAddress($server);
return xCAT::NetworkUtils->getipaddr($server, OnlyV6 => 1);
}
#-------------------------------------------------------------------------------
=head3 my_ip_facing_aix
Returns my ip address
AIX only
@@ -1518,18 +1979,8 @@ sub isInSameSubnet
{
return undef;
}
my $netipmodule = eval { require Net::IP; };
if ($netipmodule) {
my $eip1 = Net::IP::ip_expand_address($ip1, 6);
my $eip2 = Net::IP::ip_expand_address($ip2, 6);
my $bmask = Net::IP::ip_get_mask($mask, 6);
my $bip1 = Net::IP::ip_iptobin($eip1, 6);
my $bip2 = Net::IP::ip_iptobin($eip2, 6);
if (($bip1 & $bmask) == ($bip2 & $bmask)) {
return 1;
}
} # else, can not check without Net::IP module
return undef;
$mask =~ s{^/}{} if defined($mask);
return _addresses_share_prefix($ip1, $ip2, $mask, 6) ? 1 : undef;
}
}
@@ -2099,7 +2550,7 @@ sub toIP
=head3 isIpv4addr
returns 1 if parameter is has a valid IP address form.
returns 1 if parameter has a valid IPv4 address form.
Arguments:
dot qulaified IP address: e.g. 1.2.3.4
@@ -2253,6 +2704,174 @@ sub isValidIp
#-------------------------------------------------------------------------------
=head3 format_uri_host
Formats a host for use in a URI authority. IPv6 literals are enclosed in
square brackets; IPv4 literals and hostnames are returned unchanged.
Arguments:
IPv4 address, IPv6 address, or hostname
Returns:
Formatted host, or undef for malformed input
=cut
#-------------------------------------------------------------------------------
sub _endpoint_hostname_is_valid
{
my $host = shift;
return 0 unless defined($host) && length($host);
# The endpoint grammar intentionally accepts uppercase and underscore
# labels used by xCAT; the legacy hostname validators do not accept both.
my $name = $host;
$name =~ s/\.$//;
return 0 unless length($name) && length($name) <= 253;
if ($name =~ /^(?:\d+\.){3}\d+$/)
{
return xCAT::NetworkUtils->isIpaddr($name);
}
foreach my $label (split(/\./, $name, -1))
{
return 0 unless length($label) <= 63
&& $label =~ /^[A-Za-z0-9_](?:[A-Za-z0-9_-]{0,61}[A-Za-z0-9_])?$/;
}
return 1;
}
sub format_uri_host
{
my $host = shift;
if (defined($host) && $host eq __PACKAGE__)
{
$host = shift;
}
return unless defined($host) && length($host);
if ($host =~ /^\[([^\]]+)\]$/)
{
my $address = $1;
return unless xCAT::NetworkUtils->isValidIp($address) && $address =~ /:/;
return $host;
}
if ($host =~ /:/)
{
return unless xCAT::NetworkUtils->isValidIp($host);
return "[$host]";
}
return _endpoint_hostname_is_valid($host) ? $host : undef;
}
#-------------------------------------------------------------------------------
=head3 format_host_port
Formats a host and TCP/UDP port. IPv6 literals use the standard bracketed
form so the result can be used as either a URI authority or endpoint.
Arguments:
IPv4 address, IPv6 address, or hostname
Port number (1-65535)
Returns:
host:port, [IPv6-address]:port, or undef for malformed input
=cut
#-------------------------------------------------------------------------------
sub _endpoint_port_is_valid
{
my $port = shift;
return defined($port)
&& $port =~ /^\d+$/
&& $port > 0
&& $port <= 65535;
}
sub format_host_port
{
my $host = shift;
if (defined($host) && $host eq __PACKAGE__)
{
$host = shift;
}
my $port = shift;
return unless _endpoint_port_is_valid($port);
my $formatted_host = xCAT::NetworkUtils->format_uri_host($host);
return unless defined($formatted_host);
return "$formatted_host:$port";
}
#-------------------------------------------------------------------------------
=head3 parse_host_port
Parses a hostname or address with an optional port. An IPv6 address with
an explicit port must use [address]:port syntax; an unbracketed IPv6
literal is treated only as a host.
Arguments:
Host or endpoint
Optional default port (1-65535)
Returns:
(host, port), or an empty list for malformed input
=cut
#-------------------------------------------------------------------------------
sub parse_host_port
{
my $endpoint = shift;
if (defined($endpoint) && $endpoint eq __PACKAGE__)
{
$endpoint = shift;
}
my $default_port = shift;
return unless defined($endpoint) && length($endpoint);
return if defined($default_port) && !_endpoint_port_is_valid($default_port);
my ($host, $port);
if ($endpoint =~ /^\[([^\]]+)\](?::(\d+))?$/)
{
$host = $1;
$port = defined($2) ? $2 : $default_port;
return unless xCAT::NetworkUtils->isValidIp($host) && $host =~ /:/;
}
elsif (xCAT::NetworkUtils->isValidIp($endpoint) && $endpoint =~ /:/)
{
$host = $endpoint;
$port = $default_port;
}
elsif ($endpoint =~ /^([^:]+):(\d+)$/)
{
($host, $port) = ($1, $2);
}
elsif ($endpoint !~ /:/)
{
$host = $endpoint;
$port = $default_port;
}
else
{
return;
}
return unless defined(xCAT::NetworkUtils->format_uri_host($host));
return if defined($port) && !_endpoint_port_is_valid($port);
return ($host, $port);
}
#-------------------------------------------------------------------------------
@@ -2363,6 +2982,62 @@ sub getNodeNetworkCfg
#-------------------------------------------------------------------------------
=head3 getNodeNetworkCfg6
Description:
Get the configured IPv6 address, hostname, gateway, and prefix length
for a node.
Arguments:
node: the nodename
Returns:
An array containing (IPv6 address, hostname, gateway, prefix length).
The address is undefined when the node has no IPv6 address. Gateway
and prefix are undefined when no matching networks row exists.
=cut
#-------------------------------------------------------------------------------
sub getNodeNetworkCfg6
{
my $node = shift;
if (defined($node) && $node =~ /xCAT::NetworkUtils/)
{
$node = shift;
}
my $ip = xCAT::NetworkUtils->getipaddr($node, OnlyV6 => 1);
return (undef, $node, undef, undef) unless $ip;
my ($gateway, $prefix);
my $nettab = xCAT::Table->new("networks");
if ($nettab) {
my @nets = $nettab->getAllAttribs('net', 'mask', 'gateway');
foreach my $net (@nets) {
my $network = $net->{'net'};
my $candidate_prefix = $net->{'mask'};
next unless defined($network);
if ($network =~ s{/([0-9]+)$}{}) {
$candidate_prefix = $1 unless defined($candidate_prefix) && length($candidate_prefix);
}
next unless defined($candidate_prefix);
$candidate_prefix =~ s{^/}{};
next unless $candidate_prefix =~ /^\d+$/ && $candidate_prefix <= 128;
if (xCAT::NetworkUtils::_addresses_share_prefix($network, $ip, $candidate_prefix, 6)) {
$gateway = $net->{'gateway'};
$prefix = $candidate_prefix;
last;
}
}
$nettab->close();
}
return ($ip, $node, $gateway, $prefix);
}
#-------------------------------------------------------------------------------
=head3 getNodesNetworkCfg
Description:
Get network configuration (ip,netmask,gateway) for a group of nodes
+88 -65
View File
@@ -12,6 +12,8 @@ use strict;
use lib "$::XCATROOT/lib/perl";
use xCAT::Utils;
use xCAT::DSHCore;
use xCAT::NetworkUtils;
use xCAT::TableUtils;
use POSIX qw(:signal_h :errno_h :sys_wait_h);
use IO::Socket::SSL;
@@ -22,6 +24,7 @@ $XML::Simple::PREFERRED_PARSER = 'XML::Parser';
use IO::Handle;
use IO::Select;
use Getopt::Long;
use Text::ParseWords qw(shellwords);
my $USAGE = "Usage: pping [-i|--interface interfaces][-f|--use_fping] noderange
pping -h|--help
@@ -143,53 +146,83 @@ foreach my $interf (@interfaces) {
$noderef = \@nodes; # use the original node list
}
if ($usenmap) { nmap_pping($noderef); }
else { fping_pping($noderef); }
my ($ipv4_nodes, $ipv6_nodes, $unresolved_nodes) =
xCAT::DSHCore->partition_ping_targets(@{$noderef});
foreach my $node (@{$unresolved_nodes}) {
print "$node: noping\n";
}
if ($usenmap) {
nmap_pping($ipv4_nodes, 4);
nmap_pping($ipv6_nodes, 6);
} else {
fping_pping($ipv4_nodes, 4);
fping_pping($ipv6_nodes, 6);
}
}
sub fping_pping {
my $nodes = shift;
my $master = xCAT::TableUtils->get_site_Master();
my $masterip = xCAT::NetworkUtils->getipaddr($master);
if ($masterip =~ /:/) #IPv6, needs fping6 support
{
if (!-x '/usr/bin/fping6')
{
print "fping6 is not availabe for IPv6 ping.\n";
exit 1;
my ($nodes, $family) = @_;
return unless @{$nodes};
my $fping = -x '/usr/bin/fping' ? '/usr/bin/fping'
: -x '/usr/sbin/fping' ? '/usr/sbin/fping'
: undef;
my @command;
if ($family == 6) {
my $fping6 = -x '/usr/bin/fping6' ? '/usr/bin/fping6'
: -x '/usr/sbin/fping6' ? '/usr/sbin/fping6'
: undef;
if ($fping6) {
@command = ($fping6);
} elsif ($fping) {
@command = ($fping, '-6');
}
open(FPING, "fping6 " . join(' ', @$nodes) . " 2>&1 |") or die("Cannot open fping pipe: $!");
} elsif ($fping) {
@command = ($fping);
}
else
{
if (!-x '/usr/bin/fping' and !-x '/usr/sbin/fping')
{
print "fping is not available, please install missing package fping.\n";
exit 1;
}
open(FPING, "fping " . join(' ', @$nodes) . " 2>&1 |") or die("Cannot open fping pipe: $!");
unless (@command) {
warn "fping is not available for IPv$family ping.\n";
print "$_: noping\n" foreach @{$nodes};
return;
}
while (<FPING>) {
if ($_ =~ /is unreachable/) {
s/ is unreachable/: noping/;
} elsif ($_ =~ /is alive/) {
s/ is alive/: ping/;
} elsif ($_ =~ /address not found/) {
s/ address not found/: noping/;
}
print $_;
push @command, '-a', @{$nodes};
my @output;
my $pid = open(my $fping_output, '-|');
if (!defined($pid)) {
warn "Cannot open fping pipe: $!\n";
print "$_: noping\n" foreach @{$nodes};
return;
}
if ($pid == 0) {
open(STDERR, '>', '/dev/null');
exec { $command[0] } @command;
exit 127;
}
@output = <$fping_output>;
close($fping_output);
my %alive;
foreach my $line (@output) {
chomp($line);
my $target = xCAT::DSHCore->match_ping_target($line, $nodes);
$alive{$target} = 1 if defined($target);
}
foreach my $node (@{$nodes}) {
print "$node: " . ($alive{$node} ? 'ping' : 'noping') . "\n";
}
}
sub nmap_pping {
my $nodes = shift;
my %deadnodes;
my ($nodes, $family) = @_;
return unless @{$nodes};
my @nmap_options;
my $more_options;
my $tcmd;
foreach (@$nodes) {
$deadnodes{$_} = 1;
}
if ($userid != 0) {
$tcmd = "tabdump site|grep nmapoptions|awk -F, '{print $2}'|sed -e 's/\"//g'|awk -F, '{print $1}'";
$more_options = xCAT::Utils->runcmd($tcmd, -1);
@@ -199,38 +232,28 @@ sub nmap_pping {
@nmap_options = xCAT::TableUtils->get_site_attribute("nmapoptions");
$more_options = $nmap_options[0];
}
$more_options = '' unless defined($more_options);
# Added port 22 for unprivileged case (#4324)
open(NMAP, "nmap -PE --system-dns --send-ip -sP --unprivileged -PA80,443,22 $more_options " . join(' ', @$nodes) . " 2> /dev/null|") or die("Cannot open nmap pipe: $!");
my $node;
while (<NMAP>) {
if (/Host (.*) \(.*\) appears to be up/) {
$node = $1;
unless ($deadnodes{$node}) {
foreach (keys %deadnodes) {
if ($node =~ /^$_\./) {
$node = $_;
last;
}
}
}
delete $deadnodes{$node};
print "$node: ping\n" if ($node);
} elsif (/Nmap scan report for ([^ ]*) /) {
$node = $1;
} elsif (/Host is up./) {
unless ($deadnodes{$node}) {
foreach (keys %deadnodes) {
if ($node =~ /^$_\./) {
$node = $_;
last;
}
}
}
delete $deadnodes{$node};
print "$node: ping\n" if ($node);
}
my @command = ('nmap');
push @command, '-6' if $family == 6;
push @command, qw(-PE --system-dns --send-ip -sP --unprivileged -PA80,443,22);
push @command, shellwords($more_options) if length($more_options);
push @command, @{$nodes};
my $pid = open(my $nmap_output, '-|');
die("Cannot open nmap pipe: $!") unless defined($pid);
if ($pid == 0) {
open(STDERR, '>', '/dev/null');
exec { $command[0] } @command;
exit 127;
}
foreach (sort keys %deadnodes) {
print "$_: noping\n";
my @output = <$nmap_output>;
close($nmap_output);
my %alive = map { $_ => 1 }
xCAT::DSHCore->nmap_alive_targets($nodes, \@output);
foreach my $node (@{$nodes}) {
print "$node: " . ($alive{$node} ? 'ping' : 'noping') . "\n";
}
}
+18 -4
View File
@@ -63,10 +63,24 @@ If the xCAT hosts table contains:
"compute","|node(\d+)|1.2.3.($1+0)|","|(.*)|($1).cluster.net|",,
Assuming the group "compute" contains node01, node02, etc., then in /etc/hosts they will be given
IP addresses of 1.2.3.1, 1.2.3.2, etc.
=back
Assuming the group "compute" contains node01, node02, etc., then in /etc/hosts they will be given
IP addresses of 1.2.3.1, 1.2.3.2, etc.
=item 3.
Add an IPv6 primary address and an IPv6 additional interface for node01. The
exclamation mark separates an interface hostname from an IPv6 address because
the address itself contains colons. This example assumes the site domain is
example.com.
chdef node01 ip=2001:db8::10 otherinterfaces='node01-storage!2001:db8:1::10'
makehosts node01
The resulting entries include:
2001:db8::10 node01 node01.example.com
2001:db8:1::10 node01-storage node01-storage.example.com
=back
=head1 SEE ALSO
+1 -1
View File
@@ -8,7 +8,7 @@ Homepage: https://xcat.org/
Package: xcat-server
Architecture: all
Depends: ${perl:Depends}, grub-common, libcgi-pm-perl, grub2-xcat (>= 2.02-0.76.el7.1.snap201905160255), perl-xcat (>= 2.13-snap000000000000), xcat-client (>= 2.13-snap000000000000), libsys-syslog-perl, libio-socket-ssl-perl, libxml-simple-perl, make, ucf, libdbd-sqlite3-perl, libexpect-perl, libnet-dns-perl, libsoap-lite-perl, libxml-libxml-perl, libsnmp-perl, debootstrap, libdigest-sha-perl,libcrypt-rijndael-perl,libcrypt-cbc-perl,libjson-perl, libnet-https-nb-perl, libhttp-async-perl
Depends: ${perl:Depends}, grub-common, libcgi-pm-perl, grub2-xcat (>= 2.02-0.76.el7.1.snap201905160255), perl-xcat (>= 2.13-snap000000000000), xcat-client (>= 2.13-snap000000000000), libsys-syslog-perl, libio-socket-ssl-perl, libxml-simple-perl, make, ucf, libdbd-sqlite3-perl, libexpect-perl, libnet-dns-perl, libsoap-lite-perl, libxml-libxml-perl, libsnmp-perl, debootstrap, libdigest-sha-perl,libcrypt-rijndael-perl,libcrypt-cbc-perl,libjson-perl, libnet-https-nb-perl, libhttp-async-perl, libio-socket-inet6-perl, libsocket6-perl
Description: Server and configuration utilities of xCAT
xCAT-server provides the core server and configuration management components
of xCAT.
+24 -7
View File
@@ -14,6 +14,7 @@ use xCAT::MsgUtils;
use xCAT::NodeRange;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
use xCAT::Template;
use xCAT::SvrUtils;
use xCAT::Zone;
@@ -23,6 +24,26 @@ use File::Basename;
use Socket;
use strict;
sub _facing_addresses_for_node
{
my $node = shift;
my $family = xCAT::NetworkUtils->node_address_family($node);
return defined($family) && $family == 6
? xCAT::NetworkUtils->my_ip_facing_family($node, 6)
: xCAT::NetworkUtils->my_ip_facing($node);
}
sub _resolve_server_for_node
{
my ($node, $server) = @_;
my $family = xCAT::NetworkUtils->node_address_family($node);
return xCAT::NetworkUtils->getipaddr($server, OnlyV6 => 1)
if defined($family) && $family == 6;
return xCAT::NetworkUtils->getipaddr($server, OnlyV4 => 1)
if defined($family) && $family == 4;
return xCAT::NetworkUtils->getipaddr($server);
}
#-------------------------------------------------------------------------------
=head1 Postage
@@ -469,7 +490,7 @@ sub makescript {
unless ($master) {
#the ip address of the mn facing the compute node
my @ipfnd = xCAT::NetworkUtils->my_ip_facing($node);
my @ipfnd = _facing_addresses_for_node($node);
my $ipfndscalar = @ipfnd;
unless ($ipfnd[0]) {
$master = $ipfnd[1];
@@ -644,11 +665,7 @@ sub makescript {
}
my ($host, $ipaddr) = xCAT::NetworkUtils->gethostnameandip($master);
my $master_ip;
if ($ipaddr) {
$master_ip = "$ipaddr";
}
my $master_ip = _resolve_server_for_node($node, $master);
unless($master_ip){
my $rsp;
@@ -1651,7 +1668,7 @@ sub collect_all_attribs_for_tables_in_template
$::GLOBAL_TAB_HASH{noderes}{$node}{xcatmaster} eq ""))
{
my $value = undef;
my @ipfnd = xCAT::NetworkUtils->my_ip_facing($node);
my @ipfnd = _facing_addresses_for_node($node);
my $ipfndscalar = @ipfnd;
unless ($ipfnd[0]) {
$value = $ipfnd[1];
+27
View File
@@ -2244,6 +2244,33 @@ sub parseosver
#-------------------------------------------------------------------------------
=head3 is_el10_os
Returns 1 when the xCAT OS version names an Enterprise Linux 10 family
distribution, otherwise 0.
=cut
#-------------------------------------------------------------------------------
sub is_el10_os
{
my $osver = shift;
if (defined($osver) && $osver eq __PACKAGE__)
{
$osver = shift;
}
return 0 unless defined($osver);
my ($basename, $majorversion) = xCAT::SvrUtils::parseosver($osver);
return defined($basename)
&& defined($majorversion)
&& $majorversion eq '10'
&& $basename =~ /^(?:rh\w*|centos|alma|rocky|ol)$/i ? 1 : 0;
}
#-------------------------------------------------------------------------------
=head3 update_osdistro_table
This function is called after copycds. It will update the osdistro table with
given osver and arch
+91 -9
View File
@@ -16,6 +16,7 @@ use xCAT::Utils;
use xCAT::HTTPUtils ();
use xCAT::TableUtils;
use xCAT::NetworkUtils;
use xCAT::SvrUtils;
use xCAT::PasswordUtils;
use xCAT::MsgUtils;
use XML::Simple;
@@ -39,6 +40,9 @@ my $field;
my $idir;
my $node;
my $master;
my $master_uri_host;
my $node_ipv6_only;
my $template_os;
my $httpportsuffix;
my %loggedrealms;
my $lastmachinepassdata;
@@ -54,18 +58,70 @@ sub httpport_suffix {
return xCAT::HTTPUtils::httpport_suffix($httpport);
}
sub _is_el10
{
my $os = shift;
return defined($os) && $os =~ /^(?:rh\w*|centos|alma|rocky|ol)10(?:\D|$)/i;
}
sub _dynamic_kickstart_network
{
my ($suffix, $ipv6_only) = @_;
my $network = "dhcp --device=$suffix";
$network .= " --noipv4 --ipv6=dhcp" if $ipv6_only;
return $network;
}
sub _static_kickstart_network6
{
my ($candidate, $suffix) = @_;
my ($ipaddr, $hostname, $gateway, $prefix) =
xCAT::NetworkUtils->getNodeNetworkCfg6($candidate);
unless ($ipaddr && defined($prefix)) {
$tmplerr = "Cannot resolve the static IPv6 network configuration of $candidate";
return;
}
if (defined($gateway) && length($gateway)) {
$gateway = xCAT::NetworkUtils->ipv6_server_for_node($candidate, $gateway);
unless ($gateway) {
$tmplerr = "Cannot resolve the IPv6 gateway of $candidate";
return;
}
}
my $network = "static --device=$suffix --activate --noipv4 --ipv6=$ipaddr/$prefix";
$network .= " --ipv6gateway=$gateway" if defined($gateway) && length($gateway);
$network .= " --hostname=$hostname" if defined($hostname) && length($hostname);
my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$candidate]) };
my @nameserver_ips;
foreach my $nameserver (split(/,/, $nameservers{$candidate} || '')) {
next unless length($nameserver);
my $resolved = xCAT::NetworkUtils->ipv6_server_for_node($candidate, $nameserver);
push @nameserver_ips, $resolved if $resolved;
}
$network .= " --nameserver=" . join(',', @nameserver_ips) if @nameserver_ips;
return $network;
}
sub subvars {
my $self = shift;
my $inf = shift;
my $outf = shift;
$tmplerr = undef; #clear tmplerr since we are starting fresh
$node = shift;
$node_ipv6_only = xCAT::NetworkUtils->node_is_ipv6_only($node);
my $pkglistfile = shift;
my $media_dir = shift;
my $platform = shift;
my $partitionfileval = shift;
my $tmpl_hash = shift;
my %namedargs = @_; #further expansion of this function will be named arguments, should have happened sooner.
$template_os = $namedargs{os};
unless ($namedargs{reusemachinepass}) {
$lastmachinepassdata->{password} = "";
@@ -95,6 +151,7 @@ sub subvars {
## 2, the ip address of the mn/sn facing the compute node
## 3, the site.master
$master = undef;
$master_uri_host = undef;
#the "xcatmaster" attribute of the node
if ($tmpl_hash->{'xcatmaster'}) {
@@ -105,7 +162,9 @@ sub subvars {
#the ip address of the mn facing the compute node
my $ipfn;
my @ipfnd = xCAT::NetworkUtils->my_ip_facing($node);
my @ipfnd = $node_ipv6_only
? xCAT::NetworkUtils->my_ip_facing_family($node, 6)
: xCAT::NetworkUtils->my_ip_facing($node);
unless ($ipfnd[0]) { $ipfn = $ipfnd[1]; }
if ($ipfn) {
$master = $ipfn;
@@ -128,12 +187,17 @@ sub subvars {
}
$ENV{XCATMASTER} = $master;
my $ipaddr = xCAT::NetworkUtils->getipaddr($master);
my $ipaddr = $node_ipv6_only
? xCAT::NetworkUtils->ipv6_server_for_node($node, $master)
: xCAT::NetworkUtils->getipaddr($master);
unless ($ipaddr) {
$tmplerr = "Unable to resolve master \"$master\" to an IP address for $node";
return;
}
$ENV{MASTER_IP} = "$ipaddr";
$master_uri_host = $node_ipv6_only
? xCAT::NetworkUtils->format_uri_host($ipaddr)
: $master;
my @nodestatus = xCAT::TableUtils->get_site_attribute("nodestatus");
my $tmp = $nodestatus[0];
@@ -316,15 +380,17 @@ sub subvars {
my $c = 0;
my $space10 = " " x 10;
my $space12 = " " x 12;
my $nextserver_url_var = $node_ipv6_only ? '$nextserver_uri_host' : '$nextserver';
foreach my $pkgdir (@pkgdirs) {
if ($platform =~ /^(rh|SL|centos|alma|ol|fedora|rocky|openeuler)$/) {
if ($c == 0) {
# After some tests, if we put the repo in pre scripts in the kickstart like for rhels6.x
# the rhels5.9 will not be installed successfully. So put in kickstart directly.
$source_in_pre .= "echo 'url --url http://'\$nextserver'$httpportsuffix/$pkgdir' >> /tmp/repos";
$source_in_pre .= 'nextserver_uri_host="[$nextserver]"' . "\n" if $node_ipv6_only;
$source_in_pre .= "echo 'url --url http://'$nextserver_url_var'$httpportsuffix/$pkgdir' >> /tmp/repos";
$source .= "url --url http://#TABLE:noderes:\$NODE:nfsserver#$httpportsuffix/$pkgdir\n"; #For rhels5.9
} else {
$source_in_pre .= "\necho 'repo --name=pkg$c --baseurl=http://'\$nextserver'$httpportsuffix/$pkgdir' >> /tmp/repos";
$source_in_pre .= "\necho 'repo --name=pkg$c --baseurl=http://'$nextserver_url_var'$httpportsuffix/$pkgdir' >> /tmp/repos";
$source .= "repo --name=pkg$c --baseurl=http://#TABLE:noderes:\$NODE:nfsserver#$httpportsuffix/$pkgdir\n"; #for rhels5.9
}
my $distrepofile="$installroot/postscripts/repos/$pkgdir/local-repository.tmpl";
@@ -335,7 +401,7 @@ sub subvars {
open($repofd,"<","$distrepofile");
$repo_in_post = <$repofd>;
close($repofd);
$repo_in_post =~ s#baseurl=#baseurl=http://$master$httpportsuffix/#g;
$repo_in_post =~ s#baseurl=#baseurl=http://$master_uri_host$httpportsuffix/#g;
$writerepo .= "\ncat >/etc/yum.repos.d/local-repository-$c.repo << 'EOF'\n";
$writerepo .="$repo_in_post\n";
$writerepo .="EOF\n";
@@ -1073,8 +1139,18 @@ sub kickstartnetwork {
my $params = install_device_params($installnic, $primarynic, $ent->{mac}, $node);
my $macaddr = defined($params->{mac}) ? lc($params->{mac}) : '';
my $suffix = defined($params->{nicname}) ? $params->{nicname} : $macaddr;
my $ipv6_only = defined($node_ipv6_only)
? $node_ipv6_only
: xCAT::NetworkUtils->node_is_ipv6_only($node);
if ($::XCATSITEVALS{managedaddressmode} eq "autoula") {
if ($ipv6_only
&& xCAT::SvrUtils->is_el10_os($template_os)
&& $::XCATSITEVALS{managedaddressmode} ne "autoula")
{
my $static_network = _static_kickstart_network6($node, $suffix);
return unless defined($static_network);
$line .= $static_network;
} elsif ($::XCATSITEVALS{managedaddressmode} eq "autoula") {
unless ($hoststab) { $hoststab = xCAT::Table->new('hosts', -create => 1); }
$line .= "static --device=$suffix --noipv4 --ipv6=";
my $ulaaddr = autoulaaddress($macaddr);
@@ -1116,7 +1192,7 @@ sub kickstartnetwork {
#return "#KSNET static unsupported";
} else {
$line .= "dhcp --device=$suffix";
$line .= _dynamic_kickstart_network($suffix, $ipv6_only);
$line .= " --hostname=$node" if (defined($platform) && $platform eq 'openeuler');
}
return $line;
@@ -2187,7 +2263,8 @@ sub ubuntu_subiquity_pkgdir_uri
return $path if $path =~ m{^https?://};
$path = "/$path" if $path !~ m{^/};
return "http://$master$httpportsuffix$path";
my $url_host = $master_uri_host || $master;
return "http://$url_host$httpportsuffix$path";
}
sub tabdb
@@ -2256,7 +2333,12 @@ sub tabdb
unless ($blankok) {
if ($field eq "xcatmaster") {
my $ipfn;
my @ipfnd = xCAT::NetworkUtils->my_ip_facing($node);
my $ipv6_only = defined($node_ipv6_only)
? $node_ipv6_only
: xCAT::NetworkUtils->node_is_ipv6_only($node);
my @ipfnd = $ipv6_only
? xCAT::NetworkUtils->my_ip_facing_family($node, 6)
: xCAT::NetworkUtils->my_ip_facing($node);
unless ($ipfnd[0]) { $ipfn = $ipfnd[1]; }
if ($ipfn) {
return $ipfn;
+144 -37
View File
@@ -57,6 +57,65 @@ sub _oracle_linux_distname
return "ol$version";
}
sub _server_authority
{
my ($server, $port, $ipv6_only) = @_;
return xCAT::NetworkUtils->format_host_port($server, $port) if $ipv6_only;
return "$server:$port";
}
sub _syslog_server_arg
{
my $server = shift;
return $server if defined($server) && $server eq '!myipfn!';
return xCAT::NetworkUtils->format_uri_host($server);
}
sub _el10_install_url_args
{
my ($method, $authority, $httpprefix, $node) = @_;
return "inst.repo=$method://$authority$httpprefix inst.ks=$method://$authority/install/autoinst/$node";
}
# UEFI and the EL10 initrd can use different DHCPv6 DUIDs and IAIDs. Keep
# DHCPv6 for the firmware handoff, then give the kernel the node's known address.
sub _el10_static_ipv6_boot_args
{
my ( $node, $net_params ) = @_;
$net_params ||= {};
my ( $ip, $hostname, $gateway, $prefix ) = xCAT::NetworkUtils->getNodeNetworkCfg6($node);
return unless $ip && defined($prefix) && $prefix =~ /^\d+$/ && $prefix <= 128;
my $interface = $net_params->{nicname};
my @args;
unless ($interface) {
my $mac = $net_params->{mac};
return unless $mac;
$mac =~ tr/-/:/;
return unless $mac =~ /^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/;
$mac = lc($mac);
$interface = 'xcatboot0';
push @args, "ifname=$interface:$mac";
}
if (defined($gateway) && length($gateway)) {
$gateway = xCAT::NetworkUtils->ipv6_server_for_node($node, $gateway);
return unless $gateway;
} else {
$gateway = '';
}
my $client_field = xCAT::NetworkUtils->format_uri_host($ip);
my $gateway_field = $gateway ? xCAT::NetworkUtils->format_uri_host($gateway) : '';
return unless $client_field && (!$gateway || $gateway_field);
$hostname ||= $node;
push @args, 'rd.neednet=1';
push @args, "ip=${client_field}::${gateway_field}:$prefix:$hostname:$interface:none";
return join(' ', @args);
}
sub _centos_linux_distname
{
@@ -742,6 +801,8 @@ sub mknetboot
$ent = $reshash->{$node}->[0]; #$restab->getNodeAttribs($node, ['primarynic']);
my $sent = $hmhash->{$node}->[0];
my $el10_ipv6_only = xCAT::SvrUtils->is_el10_os($osver)
&& xCAT::NetworkUtils->node_is_ipv6_only($node);
# $hmtab->getNodeAttribs($node,
# ['serialport', 'serialspeed', 'serialflow']);
@@ -774,23 +835,43 @@ sub mknetboot
}
my $imgsrvip;
unless ($imgsrv eq '!myipfn!' or xCAT::NetworkUtils->isValidIp($imgsrv)) {
# if imgsrv is hostname, convert it to ip address
# the host name might not be resolved inside initrd
$imgsrvip = xCAT::NetworkUtils->getipaddr($imgsrv);
}
unless($imgsrvip){
$imgsrvip=$imgsrv;
my $xcatmasterip;
if ($el10_ipv6_only) {
$imgsrvip = xCAT::NetworkUtils->ipv6_server_for_node($node, $imgsrv);
unless ($imgsrvip) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to resolve the image server for $node as IPv6");
next;
}
$xcatmasterip = xCAT::NetworkUtils->ipv6_server_for_node($node, $xcatmaster);
unless ($xcatmasterip) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to resolve the xCAT master for $node as IPv6");
next;
}
} else {
unless ($imgsrv eq '!myipfn!' or xCAT::NetworkUtils->isValidIp($imgsrv)) {
# if imgsrv is hostname, convert it to ip address
# the host name might not be resolved inside initrd
$imgsrvip = xCAT::NetworkUtils->getipaddr($imgsrv);
}
unless($imgsrvip){
$imgsrvip=$imgsrv;
}
unless (xCAT::NetworkUtils->isValidIp($xcatmaster)) {
# if xcatmaster is hostname, convert it to ip address
# the host name might not be resolved inside initrd
$xcatmasterip = xCAT::NetworkUtils->getipaddr($xcatmaster);
}
unless($xcatmasterip){
$xcatmasterip=$xcatmaster
}
}
my $xcatmasterip;
unless (xCAT::NetworkUtils->isValidIp($xcatmaster)) {
# if xcatmaster is hostname, convert it to ip address
# the host name might not be resolved inside initrd
$xcatmasterip = xCAT::NetworkUtils->getipaddr($xcatmaster);
}
unless($xcatmasterip){
$xcatmasterip=$xcatmaster
my $imgsrv_authority = _server_authority($imgsrvip, $httpport, $el10_ipv6_only);
my $xcatmaster_endpoint = _server_authority($xcatmasterip, $xcatdport, $el10_ipv6_only);
unless ($imgsrv_authority && $xcatmaster_endpoint) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to format the IPv6 server endpoint for $node");
next;
}
# Start to build kcmdline
@@ -832,9 +913,9 @@ sub mknetboot
}
} else {
if (-r "$rootimgdir/rootimg-statelite.gz.metainfo") {
$kcmdline = "imgurl=$httpmethod://$imgsrvip:$httpport/$rootimgdir/rootimg-statelite.gz.metainfo STATEMNT=";
$kcmdline = "imgurl=$httpmethod://$imgsrv_authority/$rootimgdir/rootimg-statelite.gz.metainfo STATEMNT=";
} else {
$kcmdline = "imgurl=$httpmethod://$imgsrvip:$httpport/$rootimgdir/rootimg-statelite.gz STATEMNT=";
$kcmdline = "imgurl=$httpmethod://$imgsrv_authority/$rootimgdir/rootimg-statelite.gz STATEMNT=";
}
$kcmdline = $checksum_arg . $kcmdline;
}
@@ -863,7 +944,7 @@ sub mknetboot
}
$kcmdline .= $statemnt . " ";
$kcmdline .= "XCAT=$xcatmasterip:$xcatdport ";
$kcmdline .= "XCAT=$xcatmaster_endpoint ";
if ($rootfstype ne "ramdisk") {
@@ -890,13 +971,13 @@ sub mknetboot
}
else {
if (-r "$rootimgdir/$compressedrootimg.metainfo") {
$kcmdline = "imgurl=$httpmethod://$imgsrvip:$httpport/$rootimgdir/$compressedrootimg.metainfo ";
$kcmdline = "imgurl=$httpmethod://$imgsrv_authority/$rootimgdir/$compressedrootimg.metainfo ";
} else {
$kcmdline = "imgurl=$httpmethod://$imgsrvip:$httpport/$rootimgdir/$compressedrootimg ";
$kcmdline = "imgurl=$httpmethod://$imgsrv_authority/$rootimgdir/$compressedrootimg ";
}
$kcmdline .= $checksum_arg;
$kcmdline .= $uftp_args;
$kcmdline .= "XCAT=$xcatmasterip:$xcatdport ";
$kcmdline .= "XCAT=$xcatmaster_endpoint ";
$kcmdline .= "NODE=$node ";
# add flow control setting
@@ -914,7 +995,8 @@ sub mknetboot
#for use in postscript and postbootscript in xcatdsklspost in the rootimg
$kcmdline .= " LOGSERVER=$xcatmasterip ";
#for use in syslog dracut module in the initrd
$kcmdline .= " syslog.server=$xcatmasterip syslog.type=rsyslogd syslog.filter=*.* ";
my $syslog_server = _syslog_server_arg($xcatmasterip);
$kcmdline .= " syslog.server=$syslog_server syslog.type=rsyslogd syslog.filter=*.* ";
$kcmdline .= " xcatdebugmode=$::XCATSITEVALS{xcatdebugmode} ";
}
@@ -944,6 +1026,14 @@ sub mknetboot
} elsif (defined($net_params->{BOOTIF}) && ($net_params->{setmac} || $arch =~ /ppc/)) {
$kcmdline .= "$net_params->{BOOTIF} ";
}
if ($el10_ipv6_only && !$statelite) {
my $network_args = _el10_static_ipv6_boot_args($node, $net_params);
unless ($network_args) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to render static IPv6 boot networking for $node");
next;
}
$kcmdline .= "$network_args ";
}
my %client_nethash = xCAT::DBobjUtils->getNetwkInfo([$node]);
if ($client_nethash{$node}{mgtifname} =~ /hf/)
@@ -1403,7 +1493,7 @@ sub mkinstall
$platform,
$partfile,
\%tmpl_hash,
$os
os => $os
);
}
@@ -1514,12 +1604,25 @@ sub mkinstall
$instserver = $ent->{nfsserver};
}
if ($::XCATSITEVALS{managedaddressmode} =~ /static/) {
my $el10_ipv6_only = xCAT::SvrUtils->is_el10_os($os)
&& xCAT::NetworkUtils->node_is_ipv6_only($node);
if ($el10_ipv6_only) {
$instserver = xCAT::NetworkUtils->ipv6_server_for_node($node, $instserver);
unless ($instserver) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to resolve the install server for $node as IPv6");
next;
}
} elsif ($::XCATSITEVALS{managedaddressmode} =~ /static/) {
unless ($instserver eq '!myipfn!') {
my ($host, $ip) = xCAT::NetworkUtils->gethostnameandip($instserver);
$instserver = $ip;
}
}
my $instserver_authority = _server_authority($instserver, $httpport, $el10_ipv6_only);
unless ($instserver_authority) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to format the install server endpoint for $node");
next;
}
my $httpprefix = $pkgdir;
if ($installroot =~ /\/$/) {
$httpprefix =~ s/^$installroot/\/install\//;
@@ -1535,19 +1638,15 @@ sub mkinstall
my $modern_installer = $os =~ /^openeuler/
|| xCAT::Utils->version_cmp($kversion, "7.0") >= 0;
if ($pkvm) {
$kcmdline = "ksdevice=bootif kssendmac text selinux=0 rd.dm=0 rd.md=0 repo=$httpmethod://$instserver:$httpport$httpprefix/packages/ kvmp.inst.auto=$httpmethod://$instserver:$httpport/install/autoinst/$node root=live:$httpmethod://$instserver:$httpport$httpprefix/LiveOS/squashfs.img";
$kcmdline = "ksdevice=bootif kssendmac text selinux=0 rd.dm=0 rd.md=0 repo=$httpmethod://$instserver_authority$httpprefix/packages/ kvmp.inst.auto=$httpmethod://$instserver_authority/install/autoinst/$node root=live:$httpmethod://$instserver_authority$httpprefix/LiveOS/squashfs.img";
} else {
if (!$modern_installer) {
$kcmdline = "repo=$httpmethod://$instserver:$httpport$httpprefix ks=$httpmethod://"
. $instserver . ":" . $httpport
$kcmdline = "repo=$httpmethod://$instserver_authority$httpprefix ks=$httpmethod://"
. $instserver_authority
. "/install/autoinst/"
. $node;
} else {
$kcmdline = "inst.repo=$httpmethod://$instserver:$httpport$httpprefix inst.ks="
. "$httpmethod://"
. $instserver . ":" . $httpport
. "/install/autoinst/"
. $node;
$kcmdline = _el10_install_url_args($httpmethod, $instserver_authority, $httpprefix, $node);
}
}
if ($maxmem) {
@@ -1574,9 +1673,16 @@ sub mkinstall
$kcmdline .= " $net_params->{BOOTIF} ";
}
#if site.managedaddressmode=static, specify the network configuration as kernel options
#to avoid multicast dhcp
if ($::XCATSITEVALS{managedaddressmode} =~ /static/) {
# EL10 IPv6-only boots need the node address after the firmware
# handoff. Other platforms retain the site-managed legacy path.
if ($el10_ipv6_only) {
my $network_args = _el10_static_ipv6_boot_args($node, $net_params);
unless ($network_args) {
xCAT::MsgUtils->report_node_error($callback, $node, "Unable to render static IPv6 boot networking for $node");
next;
}
$kcmdline .= " $network_args ";
} elsif ($::XCATSITEVALS{managedaddressmode} =~ /static/) {
my ($ipaddr, $hostname, $gateway, $netmask) = xCAT::NetworkUtils->getNodeNetworkCfg($node);
unless ($ipaddr) {
xCAT::MsgUtils->report_node_error($callback, $node, "cannot resolve the ip address of $node");
@@ -1634,7 +1740,7 @@ sub mkinstall
}
if (($::XCATSITEVALS{xcatdebugmode} eq "1") or ($::XCATSITEVALS{xcatdebugmode} eq "2")) {
unless ($instserver eq '!myipfn!') {
unless ($instserver eq '!myipfn!' || $el10_ipv6_only) {
my ($host, $ip) = xCAT::NetworkUtils->gethostnameandip($instserver);
$instserver = $ip;
}
@@ -1651,7 +1757,8 @@ sub mkinstall
$kcmdline .= " inst.loglevel=debug";
#all the logs during installation will be forwarded to xcatmster
$kcmdline .= " inst.syslog=$instserver";
my $syslog_server = _syslog_server_arg($instserver);
$kcmdline .= " inst.syslog=$syslog_server";
} else {
if ($::XCATSITEVALS{xcatdebugmode} eq "2") {
$kcmdline .= " sshd=1";
+42 -4
View File
@@ -31,9 +31,11 @@ use Data::Dumper;
use xCAT::NodeRange;
use xCAT::Zone;
use File::Temp qw(tempfile);
use IO::Select;
use IO::Socket::INET;
use Time::HiRes qw(sleep);
use xCAT::NetworkUtils;
use xCAT::Utils;
use xCAT::NetworkUtils;
use xCAT::PasswordUtils;
@@ -45,6 +47,14 @@ use Getopt::Long;
use constant DELEGATED_SIGNING_TIMEOUT => 30;
# IO::Socket::INET6 and Socket6 are optional on an older management node. A
# node reached over IPv6 needs them; without them the callback stays on IPv4.
my $inet6support = eval {
require Socket6;
require IO::Socket::INET6;
1;
};
#-------------------------------------------------------
=head3 handled_commands
@@ -619,6 +629,34 @@ sub configured_sudoers {
return \%sudoers;
}
sub _open_callback_socket {
my $node = shift;
my $port = shift;
my %socket_args = (
PeerAddr => $node,
PeerPort => $port,
Proto => 'tcp',
);
my $sock;
if ($inet6support) {
$sock = IO::Socket::INET6->new(%socket_args);
}
return $sock if $sock;
# Preserve the original IPv4 path on systems without the IPv6 modules and
# as a fallback if the family-neutral socket attempt fails.
return IO::Socket::INET->new(%socket_args);
}
sub _callback_https_uri {
my $node = shift;
my $port = shift;
my $authority = xCAT::NetworkUtils->format_host_port($node, $port);
return unless defined($authority);
return "https://$authority/";
}
sub ok_with_node {
my $node = shift;
@@ -639,9 +677,7 @@ sub ok_with_node {
my $method = $parms->[0];
my $port = $parms->[1];
if ($method == 0) { #PLAIN
my $sock = new IO::Socket::INET(PeerAddr => $node,
Proto => "tcp",
PeerPort => $port);
my $sock = _open_callback_socket($node, $port);
my $rsp;
unless ($sock) { return 0 }
$select->add($sock);
@@ -657,11 +693,13 @@ sub ok_with_node {
} elsif ($method == 1) { #HTTPS
use LWP;
use HTTP::Request::Common;
my $uri = _callback_https_uri($node, $port);
return 0 unless defined($uri);
my $browser = LWP::UserAgent->new();
$browser->timeout(10);
$SIG{ALRM} = sub { }; #just need to interrupt the system call
alarm(10);
my $response = $browser->request(GET "https://$node:$port/");
my $response = $browser->request(GET $uri);
alarm(0);
if ($response->is_success and $response->{'_content'} =~ /Ciphers supported in s_server binary/) {
+96 -76
View File
@@ -136,6 +136,19 @@ sub handled_commands
return { "makedns" => "site:dnshandler" };
}
sub _local_addresses_for_network {
my $network = shift;
return unless defined($network) && length($network);
my $peer = $network;
$peer =~ s{/.*$}{};
my @facing = $peer =~ /:/
? xCAT::NetworkUtils->my_ip_facing_family($peer, 6)
: xCAT::NetworkUtils->my_ip_facing($peer);
return if !@facing || $facing[0];
return @facing[ 1 .. $#facing ];
}
sub getzonesfornet {
my $netent = shift;
my $net = $netent->{net};
@@ -145,29 +158,15 @@ sub getzonesfornet {
push @zones, $netent->{ddnsdomain};
}
if ($net =~ /:/) { #ipv6, for now do the simple stuff under the assumption we won't have a mask indivisible by 4
$net =~ s/\/(.*)//;
my $maskbits = $1;
my $maskbits = xCAT::NetworkUtils->getIPv6PrefixLength($net, $mask);
$net =~ s{/.*$}{};
return @zones unless defined($maskbits);
if ($maskbits % 4) {
die "Not supporting having a mask like $mask on an ipv6 network like $net";
die "Not supporting an IPv6 prefix length that is not divisible by 4 on network $net";
}
my $netnum = getipaddr($net, GetNumber => 1);
unless ($netnum) { return (); }
$netnum->brsft(128 - $maskbits);
my $prefix = $netnum->as_hex();
my $nibbs = $maskbits / 4;
$prefix =~ s/^0x//;
my $rev;
foreach (reverse(split //, $prefix)) {
$rev .= $_ . ".";
$nibbs--;
}
while ($nibbs) {
$rev .= "0.";
$nibbs--;
}
$rev .= "ip6.arpa.";
push @zones, $rev;
my $zone = xCAT::NetworkUtils->getIPv6ReverseZone($net, $maskbits);
return @zones unless defined($zone);
push @zones, $zone;
return @zones;
}
@@ -247,7 +246,7 @@ sub get_reverse_zones_for_entity {
foreach $tvar (@tvars) {
foreach my $net (keys %{ $ctx->{nets} }) {
if ($ctx->{nets}->{$net}->{netn} == ($tvar & $ctx->{nets}->{$net}->{mask})) {
if ($net =~ /\./) { #IPv4/IN-ADDR.ARPA case.
if ($net !~ /:/ && $net =~ /\./) { #IPv4/IN-ADDR.ARPA case.
my $maskstr = unpack("B32", pack("N", $ctx->{nets}->{$net}->{mask}));
my $maskcount = ($maskstr =~ tr/1//);
if ($maskcount >= 24)
@@ -272,25 +271,10 @@ sub get_reverse_zones_for_entity {
} elsif ($net =~ /:/) { #v6/ip6.arpa case
$net =~ /\/(.*)/;
my $maskbits = $1;
unless ($maskbits and (($maskbits % 4) == 0)) {
unless (defined($maskbits) && (($maskbits % 4) == 0)) {
die "Never expected this, $net should have had CIDR / notation... and the mask should be a factor of 4, if not, need work..."
}
my $netnum = Math::BigInt->new($ctx->{nets}->{$net}->{netn});
$netnum->brsft(128 - $maskbits);
my $prefix = $netnum->as_hex();
my $nibbs = $maskbits / 4;
$prefix =~ s/^0x//;
my $rev;
foreach (reverse(split //, $prefix)) {
$rev .= $_ . ".";
$nibbs--;
}
while ($nibbs) {
$rev .= "0.";
$nibbs--;
}
$rev .= "ip6.arpa.";
push @revs, $rev;
push @revs, xCAT::NetworkUtils->getIPv6ReverseZone($net);
}
}
}
@@ -466,6 +450,7 @@ sub process_request {
if ($net and $net->{nameservers})
{
my $valid = 0;
my @myips = _local_addresses_for_network($net->{net});
foreach (split /,/, $net->{nameservers})
{
chomp $_;
@@ -537,11 +522,11 @@ sub process_request {
next unless ($_); #skip empty lines
($addr, $names) = split /[ \t]+/, $_, 2;
if ($addr !~ /^\d+\.\d+\.\d+\.\d+$/ and $addr !~ /^[abcdef0123456789:]+$/) {
unless (isvalidip($addr)) {
xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, address seems malformed.", $callback);
next;
}
if ($addr =~ /(?:^|\.)0+(?=\d)/ and $addr !~ /^[abcdef0123456789:]+$/) {
if ($addr !~ /:/ and $addr =~ /(?:^|\.)0+(?=\d)/) {
xCAT::SvrUtils::sendmsg(":Ignoring line $_ in /etc/hosts, ip address octets can not contain leading zeroes.", $callback);
next;
}
@@ -650,7 +635,21 @@ sub process_request {
foreach (@networks) {
my $maskn;
if ($_->{mask}) { #better be IPv4, we only do CIDR for v6, use the v4/v6 agnostic just in case
my $network_key = $_->{net};
if ($_->{net} =~ /:/) {
my $maskbits = xCAT::NetworkUtils->getIPv6PrefixLength(
$_->{net}, $_->{mask}
);
unless (defined($maskbits)) {
umask($oldmask);
die "IPv6 network " . $_->{net} . " must include a valid prefix length or numeric mask";
}
$maskn = Math::BigInt->new(
"0b" . ("1" x $maskbits) . ("0" x (128 - $maskbits))
);
$network_key =~ s{/.*$}{};
$network_key .= "/$maskbits";
} elsif ($_->{mask}) {
$maskn = getipaddr($_->{mask}, GetNumber => 1); #pack("N",inet_aton($_->{mask}));
} elsif ($_->{net} =~ /\/(.*)/) { #CIDR
my $maskbits = $1;
@@ -665,11 +664,11 @@ sub process_request {
}
$maskn = Math::BigInt->new("0b" . ("1" x $maskbits) . ("0" x ($numbits - $maskbits)));
}
$ctx->{nets}->{ $_->{net} }->{mask} = $maskn;
$ctx->{nets}->{$network_key}->{mask} = $maskn;
my $net = $_->{net};
$net =~ s/\/.*//;
$ctx->{nets}->{ $_->{net} }->{netn} = getipaddr($net, GetNumber => 1);
$ctx->{nets}->{$network_key}->{netn} = getipaddr($net, GetNumber => 1);
my $currzone;
foreach $currzone (getzonesfornet($_)) {
$ctx->{zonestotouch}->{$currzone} = 1;
@@ -1113,11 +1112,11 @@ sub get_dbdir {
}
sub isvalidip {
#inet_pton/ntop good for ensuring an ip looks like an ip? or do string compare manually?
#for now, do string analysis, one problem with pton/ntop is that 010.1.1.1 would look diff from 10.1.1.1)
my $candidate = shift;
if ($candidate =~ /^(\d+)\.(\d+)\.(\d+).(\d+)\z/) {
return unless defined($candidate);
# Preserve the existing IPv4 validation semantics, including leading zeros.
if ($candidate =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)\z/) {
return (
$1 >= 0 and $1 <= 255 and
$2 >= 0 and $2 <= 255 and
@@ -1125,6 +1124,37 @@ sub isvalidip {
$4 >= 0 and $4 <= 255
);
}
return xCAT::NetworkUtils->isValidIp($candidate);
}
sub _preferred_ip_address {
my @addresses = @_;
foreach my $address (@addresses) {
return $address if isvalidip($address) && $address !~ /:/;
}
foreach my $address (@addresses) {
return $address if isvalidip($address) && $address =~ /:/;
}
return;
}
sub _dns_record_type {
my $address = shift;
return $address =~ /:/ ? 'AAAA' : 'A';
}
sub _dns_reverse_name {
my $address = shift;
return xCAT::NetworkUtils->getIPv6ReverseName($address)
if $address =~ /:/;
return join('.', reverse(split(/\./, $address))) . '.IN-ADDR.ARPA.'
if $address =~ /\./;
return;
}
sub update_zones {
@@ -1135,7 +1165,7 @@ sub update_zones {
my $node = $name;
# get the domain for the node - which is the local hostname
my ($host, $nip) = xCAT::NetworkUtils->gethostnameandip($node);
my $host = $node;
my @hosts;
push(@hosts, $host);
my $nd = xCAT::NetworkUtils->getNodeDomains(\@hosts);
@@ -1153,20 +1183,20 @@ sub update_zones {
unless ($name =~ /\.\z/) {
$name .= '.';
}
my $ip = $node;
my $ip;
if ($ctx->{hoststab} and $ctx->{hoststab}->{$node} and $ctx->{hoststab}->{$node}->[0]->{ip}) {
$ip = $ctx->{hoststab}->{$node}->[0]->{ip};
unless (isvalidip($ip)) {
xCAT::SvrUtils::sendmsg([ 1, "The hosts table entry for $node indicates $ip as an ip address, which is not a valid address" ], $callback);
next;
return;
}
} else {
unless ($ip = inet_aton($ip)) {
print "Unable to find an IP for $node in hosts table or via system lookup (i.e. /etc/hosts";
xCAT::SvrUtils::sendmsg([ 1, "Unable to find an IP for $node in hosts table or via system lookup (i.e. /etc/hosts" ], $callback);
next;
my @addresses = getipaddr($node, GetAllAddresses => 1);
$ip = _preferred_ip_address(@addresses);
unless ($ip) {
xCAT::SvrUtils::sendmsg([ 1, "Unable to find an IP for $node in hosts table or via system lookup (i.e. /etc/hosts)" ], $callback);
return;
}
$ip = inet_ntoa($ip);
}
my @neededzones = keys %{ $ctx->{zonestotouch} };
push @neededzones, keys %{ $ctx->{adzones} };
@@ -1195,8 +1225,9 @@ sub update_zones {
print $zonehdl '@ IN SOA ' . $name . " root.$name ( $serial 10800 3600 604800 86400 )\n";
print $zonehdl " IN NS $name\n";
if ($name =~ /$currzone/) { #Must guarantee an A record for the DNS server
print $zonehdl "$name IN A $ip\n";
if ($name =~ /$currzone/) { #Must guarantee an address record for the DNS server
my $record_type = _dns_record_type($ip);
print $zonehdl "$name IN $record_type $ip\n";
}
flock($zonehdl, LOCK_UN);
close($zonehdl);
@@ -1692,19 +1723,10 @@ sub add_or_delete_records {
foreach my $ip (@ips) {
$ctx->{currip} = $ip;
#time to update, A and PTR records, IPv6 still TODO
if ($ip =~ /\./) { #v4
$ip = join('.', reverse(split(/\./, $ip)));
$ip .= '.IN-ADDR.ARPA.';
} elsif ($ip =~ /:/) { #v6
$ip = getipaddr($ip, GetNumber => 1);
$ip = $ip->as_hex();
$ip =~ s/^0x//;
$ip = join('.', reverse(split(//, $ip)));
$ip .= '.ip6.arpa.';
} else {
die "ddns did not understand $ip result of lookup";
}
# Convert the address to the owner name used by its reverse zone.
my $address = $ip;
$ip = _dns_reverse_name($address);
die "ddns did not understand $address result of lookup" unless $ip;
#ok, now it is time to identify which zones should actually hold the forward (A) and reverse (PTR) records and a nameserver to handle the request
my $revzone = $ip;
@@ -1770,11 +1792,8 @@ sub find_nameserver_for_dns {
unless ($name =~ /\.\z/) { $name .= '.' }
my @rrcontent;
if ($ip =~ /:/) {
@rrcontent = ("$name IN AAAA $ip");
} else {
@rrcontent = ("$name IN A $ip");
}
my $record_type = _dns_record_type($ip);
@rrcontent = ("$name IN $record_type $ip");
foreach (keys %{ $ctx->{nodeips}->{$node} }) {
unless ($_ eq $ip) {
if ($_ =~ /:/) {
@@ -1793,6 +1812,7 @@ sub find_nameserver_for_dns {
if ($ctx->{deletemode}) {
push @rrcontent, "$name TXT";
push @rrcontent, "$name A";
push @rrcontent, "$name AAAA";
}
if ($zone =~ /IN-ADDR.ARPA/ or $zone =~ /ip6.arpa/) { #reverse style
@rrcontent = ("$rname IN PTR $name");
+72 -32
View File
@@ -3163,7 +3163,11 @@ sub kea_build_ddns_intent
# same way kea_subnet4_intent does for DHCP options. Skip the network's
# DDNS domains if we can't resolve a real IP rather than emit an invalid one.
if ($dns =~ /<xcatmaster>/) {
my @myipd = xCAT::NetworkUtils->my_ip_facing($entry->{net});
my $peer = $entry->{net};
$peer =~ s{/.*$}{};
my @myipd = $peer =~ /:/
? xCAT::NetworkUtils->my_ip_facing_family($peer, 6)
: xCAT::NetworkUtils->my_ip_facing($peer);
my $myip = $myipd[0] ? undef : $myipd[1];
$dns =~ s/<xcatmaster>/$myip/g if $myip;
}
@@ -3177,8 +3181,7 @@ sub kea_build_ddns_intent
}
}
my $zone_mask = $entry->{net} =~ /:/ ? undef : $entry->{mask};
foreach my $zone (getzonesfornet($entry->{net}, $zone_mask)) {
foreach my $zone (getzonesfornet($entry->{net}, $entry->{mask})) {
$zone .= '.' unless $zone =~ /\.$/;
if (!$reverse_seen{$zone}++) {
push @reverse, kea_ddns_domain($zone, $dns);
@@ -3730,7 +3733,7 @@ sub kea_build_node_reservations6
my $mactab = xCAT::Table->new('mac');
my $vpdtab = xCAT::Table->new('vpd', -create => 0);
$nrhash = $nrtab ? $nrtab->getNodesAttribs($nodes, [ 'tftpserver', 'xcatmaster', 'servicenode' ]) : undef;
$nrhash = $nrtab ? $nrtab->getNodesAttribs($nodes, [ 'tftpserver', 'netboot', 'xcatmaster', 'servicenode' ]) : undef;
$machash = $mactab ? $mactab->getNodesAttribs($nodes, ['mac']) : undef;
$vpdhash = $vpdtab ? $vpdtab->getNodesAttribs($nodes, ['uuid']) : undef;
@@ -4169,6 +4172,7 @@ sub kea_node_reservations6
{
my ( $backend, $config, $node ) = @_;
my $nrent = $nrhash && $nrhash->{$node} ? $nrhash->{$node}->[0] : undef;
my $macent = $machash && $machash->{$node} ? $machash->{$node}->[0] : undef;
my $vpdent = $vpdhash && $vpdhash->{$node} ? $vpdhash->{$node}->[0] : undef;
unless ($macent and $macent->{mac}) {
@@ -4217,6 +4221,16 @@ sub kea_node_reservations6
} else {
$reservation{'hw-address'} = $mac;
}
my $bootfile_url = kea_bootfile_url6_for_node($node, $hname, $nrent);
if ($bootfile_url) {
$reservation{'option-data'} = [
{
name => 'bootfile-url',
data => $bootfile_url,
'always-send' => JSON::true,
},
];
}
push @reservations, \%reservation;
}
@@ -4224,6 +4238,54 @@ sub kea_node_reservations6
return \@reservations;
}
sub kea_bootfile_url6_for_node
{
my ( $node, $peer, $nrent ) = @_;
my $netboot = $nrent ? $nrent->{netboot} : undef;
return unless $netboot
&& ($netboot eq 'grub2'
|| $netboot eq 'grub2-http'
|| $netboot eq 'grub2-tftp');
my $server = kea_boot_server6_for_node($node, $peer, $nrent);
return unless $server;
my $uri_host = xCAT::NetworkUtils->format_uri_host($server);
return unless $uri_host;
return "tftp://$uri_host/boot/grub2/grub2-$node";
}
sub kea_boot_server6_for_node
{
my ( $node, $peer, $nrent ) = @_;
my $configured_server;
if ($nrent && $nrent->{tftpserver} && $nrent->{tftpserver} ne '<xcatmaster>') {
$configured_server = $nrent->{tftpserver};
} elsif ($nrent && $nrent->{xcatmaster} && $nrent->{xcatmaster} ne '<xcatmaster>') {
$configured_server = $nrent->{xcatmaster};
}
if ($configured_server) {
my $server = getipaddr($configured_server, OnlyV6 => 1);
unless ($server) {
$callback->({ error => ["Unable to resolve an IPv6 boot server for $node from $configured_server"], errorcode => [1] });
return;
}
return $server;
}
my @facing = xCAT::NetworkUtils->my_ip_facing_family($peer, 6);
if (!@facing || $facing[0]) {
my $reason = @facing > 1 ? $facing[1] : 'no IPv6-facing address was found';
$callback->({ error => ["Unable to determine the IPv6 boot server for $node: $reason"], errorcode => [1] });
return;
}
return $facing[1];
}
sub kea_duid_from_uuid
{
my ($uuid) = @_;
@@ -4558,35 +4620,13 @@ sub getzonesfornet {
my $mask = shift;
my @zones = ();
if ($net =~ /:/) { #ipv6, for now do the simple stuff under the assumption we won't have a mask indivisible by 4
$net =~ s/\/(.*)//;
my $maskbits = $1;
if ($mask) {
die "Not supporting having a mask like $mask on an ipv6 network like $net";
my $maskbits = xCAT::NetworkUtils->getIPv6PrefixLength($net, $mask);
return () unless defined($maskbits);
if ($maskbits % 4) {
die "Not supporting an IPv6 prefix length that is not divisible by 4 on network $net";
}
my $netnum = getipaddr($net, GetNumber => 1);
unless ($netnum) { return (); }
$netnum->brsft(128 - $maskbits);
my $prefix = $netnum->as_hex();
my $nibbs = $maskbits / 4;
$prefix =~ s/^0x//;
my $rev;
foreach (reverse(split //, $prefix)) {
$rev .= $_ . ".";
$nibbs--;
}
if ($nibbs < 0) {
# a sub-nibble (not 4-bit-aligned) IPv6 mask leaves $nibbs negative;
# bail rather than spin forever in the loop below. $nibbs == 0 is the
# normal nibble-aligned case (e.g. a /64) and must still emit a zone.
return ();
}
while ($nibbs > 0) {
$rev .= "0.";
$nibbs--;
}
$rev .= "ip6.arpa.";
return ($rev);
my $zone = xCAT::NetworkUtils->getIPv6ReverseZone($net, $mask);
return defined($zone) ? ($zone) : ();
}
#return all in-addr reverse zones for a given mask and net
+65 -30
View File
@@ -62,6 +62,57 @@ sub _slow_get_tftpdir { #make up for paths where tftpdir is not passed in
}
}
sub grub2_server_for_node {
my ($node, $tftpserver) = @_;
my $family = xCAT::NetworkUtils->node_address_family($node);
# Preserve the legacy IPv4 path and its error reporting when the node does
# not resolve in either family.
$family = 4 unless defined($family);
if ($tftpserver eq '<xcatmaster>') {
my @facing = $family == 6
? xCAT::NetworkUtils->my_ip_facing_family($node, 6)
: xCAT::NetworkUtils->my_ip_facing($node);
return (0, $facing[1]) unless $facing[0];
return (1, $facing[1]);
}
my $cachekey = $family == 6 ? "6:$tftpserver" : $tftpserver;
return (0, $tftpserverip{$cachekey}) if defined($tftpserverip{$cachekey});
my $serverip = $family == 6
? xCAT::NetworkUtils->getipaddr($tftpserver, OnlyV6 => 1)
: xCAT::NetworkUtils->getipaddr($tftpserver);
return (1, "xCAT unable to resolve $tftpserver") unless $serverip;
$tftpserverip{$cachekey} = $serverip;
return (0, $serverip);
}
sub grub2_root_spec {
my ($protocol, $serverip, $httpport) = @_;
my $authority;
if ($protocol eq 'http' && $httpport ne '80') {
$authority = xCAT::NetworkUtils->format_host_port($serverip, $httpport);
} else {
$authority = xCAT::NetworkUtils->format_uri_host($serverip);
}
return unless $authority;
return "$protocol,$authority";
}
sub grub2_ipv4_config_name {
my $ip = shift;
return unless xCAT::NetworkUtils->isIpaddr($ip);
my @octets = split(/\./, $ip);
return unless @octets == 4;
return "grub.cfg-" . sprintf("%02X%02X%02X%02X", @octets);
}
sub getstate {
my $node = shift;
my $tftpdir = shift;
@@ -216,26 +267,8 @@ sub setstate {
$tftpserver = "<xcatmaster>";
}
my $serverip;
if($tftpserver eq "<xcatmaster>"){
my @nxtsrvd = xCAT::NetworkUtils->my_ip_facing($node);
unless ($nxtsrvd[0]) {
$serverip = $nxtsrvd[1];
} else {
return (1, $nxtsrvd[1]);
}
} else {
if (defined($tftpserverip{$tftpserver})) {
$serverip = $tftpserverip{$tftpserver};
} else {
$serverip = xCAT::NetworkUtils->getipaddr($tftpserver);
unless ($serverip) {
return (1, "xCAT unable to resolve $tftpserver");
}
$tftpserverip{$tftpserver} = $serverip;
}
}
my ($server_rc, $serverip) = grub2_server_for_node($node, $tftpserver);
return ($server_rc, $serverip) if $server_rc;
unless($serverip){
close($pcfg);
@@ -264,11 +297,12 @@ sub setstate {
print $pcfg "menuentry \"xCAT OS Deployment\" {\n";
print $pcfg " insmod http\n";
print $pcfg " insmod tftp\n";
if ($grub2protocol eq "http" && $httpport ne "80") {
print $pcfg " set root=http,$serverip:$httpport\n";
} else {
print $pcfg " set root=$grub2protocol,$serverip\n";
my $root_spec = grub2_root_spec($grub2protocol, $serverip, $httpport);
unless ($root_spec) {
close($pcfg);
return (1, "Unable to format the grub2 server for $node");
}
print $pcfg " set root=$root_spec\n";
print $pcfg " echo Loading Install kernel ...\n";
my $protocolrootdir = "";
@@ -327,14 +361,15 @@ sub setstate {
symlink("grub2." . $nodearch, "grub2-$node");
}
my $ip = xCAT::NetworkUtils->getipaddr($node);
unless ($ip) {
my $ip = xCAT::NetworkUtils->getipaddr($node, OnlyV4 => 1);
my $ipv6 = $ip ? undef : xCAT::NetworkUtils->getipaddr($node, OnlyV6 => 1);
unless ($ip || $ipv6) {
return (1, "xCAT unable to resolve IP in grub2 plugin");
}
#my $mactab = xCAT::Table->new('mac');
my %ipaddrs;
my $macstring;
$ipaddrs{$ip} = 1;
$ipaddrs{$ip} = 1 if $ip;
my $ment = $machash{$node}->[0];
if ($ment and $ment->{mac}) {
@@ -342,7 +377,7 @@ sub setstate {
my @macs = split(/\|/, $ment->{mac});
foreach (@macs) {
if (/!(.*)/) {
my $ipaddr = xCAT::NetworkUtils->getipaddr($1);
my $ipaddr = xCAT::NetworkUtils->getipaddr($1, OnlyV4 => 1);
if ($ipaddr) {
$ipaddrs{$ipaddr} = 1;
}
@@ -353,8 +388,8 @@ sub setstate {
# Do not use symbolic link, p5 does not support symbolic link in /tftpboot
# my $hassymlink = eval { symlink("",""); 1 };
foreach $ip (keys %ipaddrs) {
my @ipa = split(/\./, $ip);
my $pname = "grub.cfg-" . sprintf("%02X%02X%02X%02X", @ipa);
my $pname = grub2_ipv4_config_name($ip);
next unless $pname;
# remove the old boot configuration file and copy (link) a new one, but only if not offline directive
unlink("$bootloader_root/" . $pname);
+24 -4
View File
@@ -21,6 +21,26 @@ my $ADDNAMES;
my $MACTOLINKLOCAL;
sub _host_entry_matches
{
my ($line, $node, $ip) = @_;
return 0 unless defined($line) && defined($node);
$line =~ s/^\s+//;
my ($line_ip, $primary_name) = split(/\s+/, $line, 3);
return 0 unless defined($line_ip) && length($line_ip);
return 1 if defined($ip)
&& xCAT::NetworkUtils->isSameIPAddress($line_ip, $ip);
my $legacy_ipv4 = $line_ip =~ /^\d+\.\d+\.\d+\.\d+\z/;
return 0 unless $legacy_ipv4
|| xCAT::NetworkUtils->isValidIp($line_ip);
return 0 unless defined($primary_name);
return 1 if $primary_name eq $node;
return $primary_name =~ /^\Q$node\E\./ ? 1 : 0;
}
############# TODO - add return code checking !!!!!
@@ -297,7 +317,7 @@ sub addotherinterfaces
} else {
($itf, $ip) = split(/:/, $_);
}
if ($ip && xCAT::NetworkUtils->isIpv4addr($ip))
if ($ip && xCAT::NetworkUtils->isValidIp($ip))
{
if ($itf =~ /^-/)
{
@@ -330,7 +350,7 @@ sub delotherinterfaces
} else {
($itf, $ip) = split(/:/, $_);
}
if ($ip && xCAT::NetworkUtils->isIpv4addr($ip))
if ($ip && xCAT::NetworkUtils->isValidIp($ip))
{
if ($itf =~ /^-/)
{
@@ -393,7 +413,7 @@ sub add_hosts_content {
}
else
{
if (xCAT::NetworkUtils->isIpv4addr($ip))
if (xCAT::NetworkUtils->isValidIp($ip))
{
addnode $callback, $nodename, $ip, $ref->{hostnames}, $domain;
}
@@ -632,7 +652,7 @@ sub process_request
$domain = $::XCATSITEVALS{domain};
}
if (xCAT::NetworkUtils->isIpv4addr($_->{ip}))
if (xCAT::NetworkUtils->isValidIp($_->{ip}))
{
addnode $callback, $_->{node}, $_->{ip}, $_->{hostnames}, $domain;
}
+21 -4
View File
@@ -1603,6 +1603,15 @@ sub updatenoderunps
next;
}
my $nodestring = join(',', @{ $servernodes{$snkey} });
my $httpendpoint = xCAT::NetworkUtils->format_host_port($snkey, $httpport);
unless (defined($httpendpoint)) {
my $rsp = {
errorcode => [1],
error => ["Unable to format the xCAT HTTP endpoint for $nodestring. Will skip these nodes."],
};
$callback->($rsp);
next;
}
my $args;
my $mode;
@@ -1630,10 +1639,10 @@ sub updatenoderunps
if ($::SETSERVER) { # update the xcatinfo file on the node and run setuppostbootscripts
$runpscmd =
"$installdir/postscripts/xcatdsklspost $mode -M $snkey:$httpport '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c";
"$installdir/postscripts/xcatdsklspost $mode -M '$httpendpoint' '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c";
} else {
$runpscmd =
"$installdir/postscripts/xcatdsklspost $mode -m $snkey:$httpport '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c"
"$installdir/postscripts/xcatdsklspost $mode -m '$httpendpoint' '$postscripts' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c"
}
# add flowcontrol flag
@@ -2125,10 +2134,19 @@ sub updatenodesoftware
foreach my $snkey (keys %servernodes)
{
my $nodestring = join(',', @{ $servernodes{$snkey} });
my $httpendpoint = xCAT::NetworkUtils->format_host_port($snkey, $httpport);
unless (defined($httpendpoint)) {
my $rsp = {
errorcode => [1],
error => ["Unable to format the xCAT HTTP endpoint for $nodestring. Will skip these nodes."],
};
$callback->($rsp);
next;
}
my $cmd;
my $args1;
$cmd =
"$installdir/postscripts/xcatdsklspost 2 -m $snkey:$httpport 'ospkgs,otherpkgs,syscloneimgupdate' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c";
"$installdir/postscripts/xcatdsklspost 2 -m '$httpendpoint' 'ospkgs,otherpkgs,syscloneimgupdate' --tftp $tftpdir --installdir $installdir --nfsv4 $nfsv4 -c";
# add flowcontrol flag
if ($flowcontrol == 1) {
@@ -3573,4 +3591,3 @@ sub updatenodeappstat
return 0;
}
@@ -13,6 +13,20 @@ export HTTPPORT="#TABLEBLANKOKAY:site:key=httpport:value#"
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib#
format_uri_host()
{
case "$1" in
\[*\]) printf '%s' "$1" ;;
*:*) printf '[%s]' "$1" ;;
*) printf '%s' "$1" ;;
esac
}
format_host_port()
{
printf '%s:%s' "$(format_uri_host "$1")" "$2"
}
umask 0022
case "$XCATDEBUGMODE" in
@@ -36,6 +50,7 @@ fi
if [ -z "$HTTPPORT" ]; then
HTTPPORT="80"
fi
MASTER_HTTP_HOST="$(format_uri_host "$MASTER_IP")"
NODESTATUS="$(echo "$NODESTATUS"| tr -d \'\" | tr A-Z a-z)"
@@ -63,7 +78,7 @@ sleep "$RAND"
if ! type openssl >/dev/null 2>&1
then
msgutil_r "$MASTER_IP" "error" "/usr/bin/openssl does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed"
/tmp/updateflag "$MASTER_IP" "$XCATIPORT" "installstatus failed"
sleep infinity
fi
@@ -107,7 +122,7 @@ msgutil_r "$MASTER_IP" "info" "trying to download postscripts from $MASTER_IP...
if ! type curl >/dev/null 2>&1
then
msgutil_r "$MASTER_IP" "error" "Command curl not found, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed"
/tmp/updateflag "$MASTER_IP" "$XCATIPORT" "installstatus failed"
sleep infinity
fi
@@ -139,11 +154,11 @@ function download_recursive()
return 0
}
download_recursive "http://$MASTER_IP:${HTTPPORT}$INSTALLDIR/postscripts/" "/xcatpost" 2>/tmp/download.log
download_recursive "http://${MASTER_HTTP_HOST}:${HTTPPORT}$INSTALLDIR/postscripts/" "/xcatpost" 2>/tmp/download.log
if [ "$?" -ne "0" ]
then
msgutil_r "$MASTER_IP" "error" "failed to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/, check /tmp/download.log on the node, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed"
msgutil_r "$MASTER_IP" "error" "failed to download postscripts from http://${MASTER_HTTP_HOST}:${HTTPPORT}$INSTALLDIR/postscripts/, check /tmp/download.log on the node, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER_IP" "$XCATIPORT" "installstatus failed"
sleep infinity
fi
@@ -158,7 +173,7 @@ export NODE="#TABLE:nodelist:THISNODE:node#"
msgutil_r "$MASTER_IP" "info" "trying to get mypostscript from $MASTER_IP..." "/var/log/xcat/xcat.log" "$log_label"
curl --fail --retry 20 --max-time 60 "http://$MASTER_IP:${HTTPPORT}$TFTPDIR/mypostscripts/mypostscript.$NODE" -o "/xcatpost/mypostscript.$NODE" 2> /tmp/download.log
curl --fail --retry 20 --max-time 60 "http://${MASTER_HTTP_HOST}:${HTTPPORT}$TFTPDIR/mypostscripts/mypostscript.$NODE" -o "/xcatpost/mypostscript.$NODE" 2> /tmp/download.log
if [ "$?" = "0" ]
then
case "$XCATDEBUGMODE" in
@@ -173,7 +188,7 @@ fi
# Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images
USEOPENSSLFORXCAT=1
export USEOPENSSLFORXCAT
XCATSERVER=$MASTER_IP:3001
XCATSERVER="$(format_host_port "$MASTER_IP" 3001)"
export XCATSERVER
# If mypostscript doesn't exist, we will get it through getpostscript.awk
@@ -189,7 +204,7 @@ if [ ! -x /xcatpost/mypostscript ]; then
# Stop if no getpostscript.awk to help the next bit
if [ ! -x /xcatpost/getpostscript.awk ]; then
msgutil_r "$MASTER_IP" "error" "/xcatpost/getpostscript.awk does not exist, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed"
/tmp/updateflag "$MASTER_IP" "$XCATIPORT" "installstatus failed"
sleep infinity
fi
/xcatpost/getpostscript.awk | egrep '<data>' | sed -e 's/<[^>]*>//g' | egrep -v '^ *$' | sed -e 's/^ *//' | sed -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&amp;/\&/g' -e 's/&quot;/"/g' -e "s/&apos;/'/g" >/xcatpost/mypostscript
@@ -301,7 +316,7 @@ esac
chmod 0755 /xcatpost/mypostscript
if [ ! -x /xcatpost/mypostscript ]; then
msgutil_r "$MASTER_IP" "error" "failed to generate mypostscript file, halt ..." "/var/log/xcat/xcat.log" "$log_label"
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus failed"
/tmp/updateflag "$MASTER_IP" "$XCATIPORT" "installstatus failed"
sleep infinity
else
case "$XCATDEBUGMODE" in
@@ -434,7 +449,7 @@ esac
msgutil_r "$MASTER_IP" "info" "finished firstboot preparation, sending request to $MASTER:3002 for changing status..." "/var/log/xcat/xcat.log" "$log_label"
# The following command should always be run to prevent infinite installation loops
updateflag.awk "$MASTER" 3002
updateflag.awk "$MASTER_IP" 3002
cd /
@@ -32,8 +32,7 @@ cat >/tmp/baz.py <<'EOF'
import socket
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#))
sock = socket.create_connection(('#ENV:MASTER_IP#',#TABLE:site:key=xcatiport:value#))
print(sys.argv[1])
response = sock.recv(100)
@@ -52,8 +51,39 @@ import os
import linecache
import re
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#))
def create_listen_socket(port, master):
last_error = None
master_addresses = socket.getaddrinfo(master, None, socket.AF_UNSPEC,
socket.SOCK_STREAM)
seen_families = set()
for master_family, socktype, proto, canonname, master_sockaddr in master_addresses:
if master_family in seen_families:
continue
seen_families.add(master_family)
allowed_peers = {
address[4][0]
for address in master_addresses
if address[0] == master_family
}
listen_addresses = socket.getaddrinfo(
None, port, master_family, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
for family, socktype, proto, canonname, sockaddr in listen_addresses:
listen_sock = socket.socket(family, socktype, proto)
listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if family == socket.AF_INET6 and hasattr(socket, 'IPV6_V6ONLY'):
listen_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
try:
listen_sock.bind(sockaddr)
listen_sock.listen(5)
return listen_sock, allowed_peers
except OSError as error:
last_error = error
listen_sock.close()
if last_error:
raise last_error
raise OSError('no usable address for install monitor')
sock = socket.create_connection(('#ENV:MASTER_IP#',#TABLE:site:key=xcatiport:value#))
response = sock.recv(100)
if(response == b"ready\n"):
@@ -62,22 +92,20 @@ if(response == b"ready\n"):
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port = 3054
sock.bind(('', port))
sock.listen(5)
sock, allowed_peers = create_listen_socket(port, '#ENV:MASTER_IP#')
try:
while 1:
newSocket, address = sock.accept()
if address[0] not in allowed_peers:
newSocket.close()
continue
while 1:
received = newSocket.recv(200)
if not received:
break
command = re.split(b'\s+',received)
command = re.split(b'\s+',received.strip())
if(command[0] == b"stat"):
ilog = ""
line = ""
@@ -120,11 +148,17 @@ try:
#UNCOMMENTOENABLEDEBUGPORT# newSocket.send(output)
#UNCOMMENTOENABLEDEBUGPORT# break
if(command[0] == b"screendump"):
newcommand = "cat /dev/vcs"
for i in command[1:]:
newcommand = newcommand + i
output = os.popen(newcommand).read()
newSocket.send(output.encode())
screen = command[1] if len(command) == 2 else b""
if len(command) > 2 or (screen and not screen.isdigit()):
newSocket.send(b"invalid virtual console\n")
break
console_path = "/dev/vcs" + screen.decode("ascii")
try:
with open(console_path, "rb") as console:
output = console.read()
except OSError as error:
output = (str(error) + "\n").encode()
newSocket.sendall(output)
break
newSocket.close()
@@ -315,9 +349,24 @@ msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/v
# The following code is to generate the repository for the installation
cat /proc/cmdline
NEXTSERVER="$(grep -m 1 http /proc/cmdline)"
NEXTSERVER="${NEXTSERVER#*http://}"
NEXTSERVER="${NEXTSERVER%%:*}"
extract_url_host()
{
local authority="${1#*://}"
authority="${authority%%/*}"
case "$authority" in
\[*\]*)
authority="${authority#\[}"
printf '%s\n' "${authority%%\]*}"
;;
*)
printf '%s\n' "${authority%%:*}"
;;
esac
}
NEXTSERVER_URL="$(grep -oE 'https?://(\[[^]]+\]|[^[:space:]/:]+)(:[0-9]+)?' /proc/cmdline | head -n 1)"
NEXTSERVER="$(extract_url_host "$NEXTSERVER_URL")"
export nextserver="$NEXTSERVER"
#INSTALL_SOURCES_IN_PRE#
@@ -6,8 +6,17 @@
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
format_syslog_server() {
case "$1" in
\[*\]) printf '%s\n' "$1" ;;
*:*) printf '[%s]\n' "$1" ;;
*) printf '%s\n' "$1" ;;
esac
}
rsyslog_config() {
local server=$1
local server
server=$(format_syslog_server "$1")
shift
local syslog_template=$1
shift
+164 -35
View File
@@ -1,4 +1,115 @@
#!/bin/bash
xcat_endpoint_host() {
local endpoint="$1"
local host
local remainder
case "$endpoint" in
\[*\]:*)
host=${endpoint#\[}
host=${host%%\]*}
;;
\[*\])
host=${endpoint#\[}
host=${host%\]}
;;
*:*)
remainder=${endpoint#*:}
if [[ "$remainder" == *:* ]]; then
# An unbracketed IPv6 literal has no unambiguous port suffix.
host=$endpoint
else
host=${endpoint%%:*}
fi
;;
*)
host=$endpoint
;;
esac
[ -n "$host" ] || return 1
printf '%s\n' "$host"
}
xcat_is_ipv6_boot() {
local iparg="$1"
local netif="$2"
case "$iparg" in
dhcp6|*:dhcp6|*:dhcp6:*)
return 0
;;
esac
[ -n "$netif" ] || return 1
ip -6 -o addr show dev "$netif" scope global 2>/dev/null | grep -q . || return 1
! ip -4 -o addr show dev "$netif" scope global 2>/dev/null | grep -q .
}
persist_ipv6_nm_connection() {
local newroot="$1"
local netif="$2"
local mac="$3"
shift 3
local destination="$newroot/etc/NetworkManager/system-connections"
local source
local profile
local copied=0
local address_cidr
local gateway
local sources=("$@")
if [ ${#sources[@]} -eq 0 ]; then
sources=(
/run/NetworkManager/system-connections
/etc/NetworkManager/system-connections
)
fi
mkdir -p "$destination"
for source in "${sources[@]}"; do
[ -d "$source" ] || continue
for profile in "$source"/*.nmconnection; do
[ -f "$profile" ] || continue
cp -p "$profile" "$destination/"
chmod 600 "$destination/${profile##*/}"
copied=1
done
done
if [ "$copied" -eq 0 ]; then
address_cidr=$(ip -6 -o addr show dev "$netif" scope global 2>/dev/null |
awk '$3 == "inet6" { print $4; exit }')
[ -n "$address_cidr" ] || return 1
gateway=$(ip -6 route show default dev "$netif" 2>/dev/null |
awk '$1 == "default" && $2 == "via" { print $3; exit }')
profile="$destination/xcat-$netif.nmconnection"
cat > "$profile" <<EOF
[connection]
id=xcat-$netif
type=ethernet
interface-name=$netif
autoconnect=true
[ethernet]
mac-address=$mac
[ipv4]
method=disabled
[ipv6]
method=manual
address1=$address_cidr
gateway=$gateway
addr-gen-mode=default
EOF
chmod 600 "$profile"
fi
}
log_label="xcat.deployment"
NEWROOT=$3
@@ -14,20 +125,20 @@ rflags="$(getarg rootflags=)"
getarg nonodestatus
NODESTATUS=$?
MASTER=`echo $XCATMASTER |awk -F: '{print $1}'`
MASTER="$(xcat_endpoint_host "$XCATMASTER")"
XCATIPORT="$(getarg XCATIPORT=)"
if [ $? -ne 0 ]; then
XCATIPORT="3002"
fi
[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST="" || SYSLOGHOST="-n $MASTER"
logger $SYSLOGHOST -t $log_label -p local4.info "=============deployment starting===================="
logger $SYSLOGHOST -t $log_label -p local4.info "Executing xcatroot to prepare for netbooting (dracut_33)..."
[ "$xcatdebugmode" = "1" -o "$xcatdebugmode" = "2" ] && SYSLOGHOST=() || SYSLOGHOST=(-n "$MASTER")
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "=============deployment starting===================="
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Executing xcatroot to prepare for netbooting (dracut_33)..."
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "MASTER=$MASTER XCATIPORT=$XCATIPORT NODESTATUS=$NODESTATUS"
if [ "$NODESTATUS" != "0" ]; then
logger $SYSLOGHOST -t $log_label -p local4.info "Sending request to $MASTER:$XCATIPORT for changing status to netbooting..."
/tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Sending request to $MASTER:$XCATIPORT for changing status to netbooting..."
/tmp/updateflag "$MASTER" "$XCATIPORT" "installstatus netbooting"
fi
@@ -63,7 +174,7 @@ rootimg_download() {
xcat_uftp_rootimg "$1" "$2" /tmp/rootimg.sha256.before "$rootimg_uftp_port" "$(getarg xcat.uftpfp=)"; then
return 0
fi
logger $SYSLOGHOST -t $log_label -p local4.warning "Cannot receive $1 over UFTP, downloading it over HTTP..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.warning "Cannot receive $1 over UFTP, downloading it over HTTP..."
fi
curl --fail "$1" -o "$2"
}
@@ -74,25 +185,25 @@ rootimg_uftp="$(getarg xcat.uftp=)"
imgurl="$(getarg imgurl=)";
if [ ! -z "$imgurl" ]; then
if [ xhttp = x${imgurl%%:*} ] || [ xhttps = x${imgurl%%:*} ]; then
logger $SYSLOGHOST -t $log_label -p local4.info "Downloading rootfs image from $imgurl..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Downloading rootfs image from $imgurl..."
NFS=0
FILENAME=${imgurl##*/}
[ "$rootimgchecksum" = yes ] || logger $SYSLOGHOST -t $log_label -p local4.info "nodeset did not ask for a check of $FILENAME, so it is not checked."
[ "$rootimgchecksum" = yes ] || logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "nodeset did not ask for a check of $FILENAME, so it is not checked."
# A file that an earlier attempt left is checked like a new download.
if [ -r "$FILENAME" ] && [ "$rootimgchecksum" = yes ] && ! rootimg_matches_checksum "$imgurl" "$FILENAME" >/dev/null; then
rm -f $FILENAME
fi
while [ ! -r "$FILENAME" ]; do
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..."
echo Getting $imgurl...
echo "Getting $imgurl..."
[ "$rootimgchecksum" != yes ] || rootimg_fetch_checksum "$imgurl" /tmp/rootimg.sha256.before || rm -f /tmp/rootimg.sha256.before
if ! rootimg_download "$imgurl" "$FILENAME"; then
logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..."
rm -f $FILENAME
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..."
rm -f "$FILENAME"
echo Failed to get the image, waiting for next retrying...
sleep 27
elif [ "$rootimgchecksum" = yes ] && ! rootimg_check=$(rootimg_matches_checksum "$imgurl" "$FILENAME"); then
logger $SYSLOGHOST -t $log_label -p local4.error "$rootimg_check, retrying..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.error "$rootimg_check, retrying..."
rm -f $FILENAME
echo "$rootimg_check, waiting for next retrying..."
sleep 27
@@ -135,7 +246,7 @@ if [ -r /rootimg.sfs ]; then
mount --move /rw $NEWROOT/rw
fi
elif [ -r /rootimg.cpio.gz ] || [ -r /rootimg.cpio.xz ]; then
logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.cpio.[gz/xz]..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.cpio.[gz/xz]..."
echo Setting up RAM-root tmpfs.
rootopts="mode=755"
if [ -n "$rflags" ]; then
@@ -169,7 +280,7 @@ elif [ -r /rootimg.cpio.gz ] || [ -r /rootimg.cpio.xz ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Done extracting the root filesystem..."
echo "Done extracting the root filesystem..."
elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
logger $SYSLOGHOST -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.tar.[gz/xz]..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Setting up RAM-root tmpfs on downloaded rootimg.tar.[gz/xz]..."
echo Setting up RAM-root tmpfs.
if [ -z $rootlimit ];then
mount -t tmpfs -o mode=755 rootfs $NEWROOT
@@ -199,7 +310,7 @@ elif [ -r /rootimg.tar.gz ] || [ -r /rootimg.tar.xz ]; then
echo "$msg"
elif [ -r /rootimg-statelite.gz ]; then
msg="Setting up RAM-root tmpfs for statelite mode."
logger $SYSLOGHOST -t $log_label -p local4.info "$msg"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "$msg"
echo "$msg"
if [ -z $rootlimit];then
@@ -232,7 +343,7 @@ elif [ -r /rootimg-statelite.gz ]; then
echo ""
echo "The /$RWDIR directory doesn't exist in the rootimg... "
echo ""
logger $SYSLOGHOST -t $log_label -p local4.err "The /$RWDIR directory doesn't exist in the rootimg..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.err "The /$RWDIR directory doesn't exist in the rootimg..."
/bin/sh
fi
@@ -240,7 +351,7 @@ elif [ -r /rootimg-statelite.gz ]; then
echo ""
echo "$NEWROOT/etc/init.d/statelite doesn't exist... "
echo ""
logger $SYSLOGHOST -t $log_label -p local4.err "$NEWROOT/etc/init.d/statelite doesn't exist... "
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.err "$NEWROOT/etc/init.d/statelite doesn't exist... "
/bin/sh
fi
@@ -279,7 +390,7 @@ elif [ -r /rootimg-statelite.gz ]; then
1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ?
2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER."
echo "$msg"
logger $SYSLOGHOST -t $log_label -p local4.err "$msg"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.err "$msg"
/bin/sh
exit
fi
@@ -298,7 +409,7 @@ elif [ -r /rootimg-statelite.gz ]; then
msg="Your are dead, rpower $ME boot to play again.
Cannot umount $NEWROOT/$RWDIR/persistent."
echo "$msg"
logger $SYSLOGHOST -t $log_label -p local4.err "$msg"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.err "$msg"
/bin/sh
exit
fi
@@ -315,7 +426,7 @@ elif [ -r /rootimg-statelite.gz ]; then
msg="Your are dead, rpower $ME boot to play again.
Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME."
echo "$msg"
logger $SYSLOGHOST -t $log_label -p local4.err "$msg"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.err "$msg"
/bin/sh
exit
fi
@@ -325,9 +436,9 @@ elif [ -r /rootimg-statelite.gz ]; then
done
fi
logger $SYSLOGHOST -t $log_label -p local4.info "Enabling localdisk ..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Enabling localdisk ..."
$NEWROOT/etc/init.d/localdisk
logger $SYSLOGHOST -t $log_label -p local4.info "Preparing mount points ..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Preparing mount points ..."
$NEWROOT/etc/init.d/statelite
fastboot=yes
export fastboot
@@ -340,7 +451,7 @@ elif [ -r /rootimg-statelite.gz ]; then
else
msg="Failed to download image, panic in 5..."
logger $SYSLOGHOST -t $log_label -p local4.error "$msg"
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.error "$msg"
echo -n "$msg"
for i in 4 3 2 1 0; do
/bin/sleep 1
@@ -387,7 +498,7 @@ function getdevfrommac() {
}
if [ -z $STATEMNT ]; then
if [ -z "$STATEMNT" ]; then
for lf in /tmp/dhclient.*.lease; do
netif=${lf#*.}
netif=${netif%.*}
@@ -412,16 +523,34 @@ if [ -z $STATEMNT ]; then
fi
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
if [ -n "$MACX" ] && [ -n "$ETHX" ]; then
BOOT_IP="$(getarg ip=)"
IPV6_BOOT=0
if xcat_is_ipv6_boot "$BOOT_IP" "$ETHX"; then
IPV6_BOOT=1
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Persisting the NetworkManager connection for IPv6 interface $ETHX"
if ! persist_ipv6_nm_connection "$NEWROOT" "$ETHX" "$MACX"; then
logger -t $log_label -p local4.error "Unable to persist the static IPv6 configuration for $ETHX"
exit 1
fi
fi
if [ "$IPV6_BOOT" -eq 1 ]; then
# EL10 uses NetworkManager keyfiles. Do not leave a competing
# legacy ifcfg profile that would start a new DHCPv6 identity.
rm -f "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
else
if [ ! -e "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX" ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
mkdir -p "$NEWROOT/etc/sysconfig/network-scripts"
touch "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
fi
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes"
echo "DEVICE=$ETHX" > "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
echo "BOOTPROTO=dhcp" >> "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
echo "HWADDR=$MACX" >> "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
echo "ONBOOT=yes" >> "$NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
fi
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes"
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
fi
fi
@@ -433,7 +562,7 @@ if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; the
echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux"
fi
logger $SYSLOGHOST -t $log_label -p local4.info "Exiting xcatroot..."
logger "${SYSLOGHOST[@]}" -t $log_label -p local4.info "Exiting xcatroot..."
# inject new exit_if_exists
echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh
# force udevsettle to break
+6
View File
@@ -88,8 +88,14 @@ Requires: chkconfig
# openssl is present on all EL; require it uniformly (not just el10) so a single
# flat xcat-core build is correct everywhere. Excluded on SLES, where the package
# name differs and it was never required before.
#
# IO::Socket::INET6 and Socket6 carry the AF_INET6 constants the dual-stack
# listener and the discovery callbacks need. They are not in core perl, so a
# management node without them falls back to IPv4 and an IPv6-only node cannot
# reach xcatd.
%if !0%{?suse_version}
Requires: openssl
Requires: perl-IO-Socket-INET6 perl-Socket6
%endif
%if %fsm
@@ -211,6 +211,13 @@ SKIP: {
duid => '00:04:52:54:00:12:34:56',
'ip-addresses' => ['2001:db8:1::50'],
hostname => 'nodev6',
'option-data' => [
{
name => 'bootfile-url',
data => 'tftp://[2001:db8:1::1]/boot/grub2/grub2-nodev6',
'always-send' => JSON::true,
},
],
},
],
},
+178
View File
@@ -0,0 +1,178 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use File::Spec;
use FindBin;
use Test::More;
my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..');
$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server');
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
my $anaconda = File::Spec->catfile(
$repo_root,
'xCAT-server/lib/xcat/plugins/anaconda.pm'
);
do $anaconda or die $@ || "Unable to load $anaconda: $!";
open(my $anaconda_fh, '<', $anaconda) or die "Unable to read $anaconda: $!";
my $anaconda_source = do { local $/; <$anaconda_fh> };
close($anaconda_fh);
my %addresses = (
nodev4 => { 4 => '192.0.2.50' },
nodev6 => { 6 => '2001:db8:1::50' },
nodedual => { 4 => '192.0.2.60', 6 => '2001:db8:1::60' },
'boot6.example.test' => { 6 => '2001:db8::10' },
);
my @facing_calls;
my %network_cfg = (
nodev6 => [ '2001:db8:1::50', 'nodev6', '2001:db8:1::fe', 64 ],
nodev6mastergw => [ '2001:db8:2::50', 'nodev6mastergw', '<xcatmaster>', 64 ],
nodev6nogw => [ '2001:db8:3::50', 'nodev6nogw', '', 64 ],
);
no warnings 'redefine';
local *xCAT::NetworkUtils::getipaddr = sub {
my $host = shift;
$host = shift if defined($host) && $host eq 'xCAT::NetworkUtils';
my %opts = @_;
my $entry = $addresses{$host} || {};
return $entry->{6} if $opts{OnlyV6};
return $entry->{4} if $opts{OnlyV4};
return $entry->{4} || $entry->{6};
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my $node = shift;
$node = shift if defined($node) && $node eq 'xCAT::NetworkUtils';
my $family = shift;
push @facing_calls, [$node, $family];
return (0, '2001:db8::1');
};
local *xCAT::NetworkUtils::getNodeNetworkCfg6 = sub {
my $node = shift;
$node = shift if defined($node) && $node eq 'xCAT::NetworkUtils';
return @{ $network_cfg{$node} || [] };
};
ok(xCAT::SvrUtils->is_el10_os('rhels10.0'), 'RHEL 10 is recognized as EL10');
ok(xCAT::SvrUtils->is_el10_os('rocky10'), 'Rocky 10 is recognized as EL10');
ok(!xCAT::SvrUtils->is_el10_os('rhels9.6'), 'EL9 is outside the EL10 IPv6 rendering path');
ok(xCAT::NetworkUtils->node_is_ipv6_only('nodev6'), 'AAAA-only node is detected as IPv6-only');
ok(!xCAT::NetworkUtils->node_is_ipv6_only('nodev4'), 'IPv4-only node stays on the IPv4 path');
ok(!xCAT::NetworkUtils->node_is_ipv6_only('nodedual'), 'dual-stack node retains IPv4 preference');
is(
xCAT::NetworkUtils->ipv6_server_for_node('nodev6', 'boot6.example.test'),
'2001:db8::10',
'explicit image server resolves in the node IPv6 family'
);
is(
xCAT::NetworkUtils->ipv6_server_for_node('nodev6', '!myipfn!'),
'2001:db8::1',
'dynamic xCAT master resolves to the IPv6-facing local address'
);
is_deeply($facing_calls[-1], ['nodev6', 6], 'dynamic master uses the shared family helper');
is(
xCAT_plugin::anaconda::_server_authority('192.0.2.1', 8080, 0),
'192.0.2.1:8080',
'IPv4 authority remains byte-for-byte unchanged'
);
is(
xCAT_plugin::anaconda::_server_authority('2001:db8::1', 8080, 1),
'[2001:db8::1]:8080',
'IPv6 URL authority is bracketed before its port'
);
is(
xCAT_plugin::anaconda::_syslog_server_arg('192.0.2.1'),
'192.0.2.1',
'IPv4 syslog kernel arguments remain unchanged'
);
is(
xCAT_plugin::anaconda::_syslog_server_arg('2001:db8::1'),
'[2001:db8::1]',
'IPv6 syslog kernel arguments use a bracketed server literal'
);
is(
xCAT_plugin::anaconda::_syslog_server_arg('!myipfn!'),
'!myipfn!',
'deferred xCAT master token remains available for late bootloader replacement'
);
is(
xCAT_plugin::anaconda::_syslog_server_arg('mgmt.example.test'),
'mgmt.example.test',
'hostname syslog kernel arguments remain unchanged'
);
is(
xCAT_plugin::anaconda::_syslog_server_arg('[2001:db8::1]'),
'[2001:db8::1]',
'already-bracketed IPv6 syslog kernel arguments remain unchanged'
);
ok(
!defined(xCAT_plugin::anaconda::_syslog_server_arg('bad host')),
'malformed syslog server arguments remain rejected'
);
like(
$anaconda_source,
qr/syslog\.server=\$syslog_server syslog\.type=rsyslogd/,
'stateless debug boot uses the family-safe syslog argument'
);
like(
$anaconda_source,
qr/inst\.syslog=\$syslog_server/,
'stateful EL10 debug install uses the family-safe syslog argument'
);
is(
xCAT_plugin::anaconda::_el10_install_url_args(
'http', '192.0.2.1:8080', '/install/rhels10/x86_64', 'nodev4'
),
'inst.repo=http://192.0.2.1:8080/install/rhels10/x86_64 inst.ks=http://192.0.2.1:8080/install/autoinst/nodev4',
'EL10 IPv4 install URL arguments remain unchanged'
);
is(
xCAT_plugin::anaconda::_el10_install_url_args(
'http', '[2001:db8::1]:8080', '/install/rhels10/x86_64', 'nodev6'
),
'inst.repo=http://[2001:db8::1]:8080/install/rhels10/x86_64 inst.ks=http://[2001:db8::1]:8080/install/autoinst/nodev6',
'EL10 IPv6 install URL arguments use bracketed authorities'
);
is(
xCAT_plugin::anaconda::_el10_static_ipv6_boot_args(
'nodev6', { nicname => 'eno1', mac => '02:00:00:00:00:61' }
),
'rd.neednet=1 ip=[2001:db8:1::50]::[2001:db8:1::fe]:64:nodev6:eno1:none',
'named install interface receives the configured static IPv6 boot address'
);
is(
xCAT_plugin::anaconda::_el10_static_ipv6_boot_args(
'nodev6nogw', { mac => '02-00-00-00-00-63' }
),
'ifname=xcatboot0:02:00:00:00:00:63 rd.neednet=1 ip=[2001:db8:3::50]:::64:nodev6nogw:xcatboot0:none',
'unspecified install interface is deterministically named and bound to its MAC'
);
is(
xCAT_plugin::anaconda::_el10_static_ipv6_boot_args(
'nodev6mastergw', { nicname => 'ens3' }
),
'rd.neednet=1 ip=[2001:db8:2::50]::[2001:db8::1]:64:nodev6mastergw:ens3:none',
'xcatmaster gateway resolves to the IPv6-facing address and is bracketed'
);
is_deeply(
$facing_calls[-1],
['nodev6mastergw', 6],
'static IPv6 xcatmaster gateway lookup is constrained to IPv6'
);
ok(
!defined(xCAT_plugin::anaconda::_el10_static_ipv6_boot_args('nodev6nogw', {})),
'static IPv6 boot rendering refuses an unbound interface when no NIC name or MAC exists'
);
done_testing();
+237
View File
@@ -0,0 +1,237 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $source = "$FindBin::Bin/../../xCAT/postscripts/configeth";
open( my $source_fh, '<', $source ) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($function) = $content =~ /^(function \Q$name\E\(\)\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($function);
return $function;
}
is( system( 'bash', '-n', $source ), 0, 'configeth has valid bash syntax' );
my ( $harness_fh, $harness ) = tempfile();
print {$harness_fh} shell_function('discover_install_nic_ipv6'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_connection'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_nm'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_keyfile'), "\n";
print {$harness_fh} <<'SHELL';
set -eu
NMCLI_LOG=$1
KEYFILE=$2
fail() {
echo "$*" >&2
exit 1
}
ip() {
case "$*" in
'-6 -o addr show dev eth0 scope global')
printf '%s\n' \
'2: eth0 inet6 2001:db8:1::88/56 scope global dynamic noprefixroute' \
'2: eth0 inet6 2001:db8:1::99/64 scope global temporary dynamic' \
'2: eth0 inet6 2001:db8:1::21/64 scope global dynamic noprefixroute'
;;
'-6 route show default dev eth0')
printf '%s\n' 'default via fe80::1 dev eth0 proto ra metric 100'
;;
'-o link show dev eth0')
printf '%s\n' '2: eth0: <BROADCAST,MULTICAST,UP> mtu 9000 state UP'
;;
'-6 -o addr show dev eth1 scope global')
printf '%s\n' '3: eth1 inet6 2001:db8:2::21/64 scope global dynamic noprefixroute'
;;
'-6 route show default dev eth1')
return 0
;;
'-o link show dev eth1')
printf '%s\n' '3: eth1: <BROADCAST,MULTICAST,UP> mtu 1500 state UP'
;;
*)
return 1
;;
esac
}
nmcli() {
case "$*" in
'--escape no -g IP6.DNS device show eth0')
printf '%s\n' '2001:db8::53' '2001:db8::54'
;;
'--escape no -g IP6.SEARCHES device show eth0')
printf '%s\n' 'cluster.example' 'lab.example'
;;
'--escape no -g IP6.GATEWAY device show eth0')
printf '%s\n' 'fe80::2'
;;
'--escape no -g IP6.GATEWAY device show eth1')
printf '%s\n' 'fe80::2'
;;
'--escape no -g IP6.DNS device show eth1'|'--escape no -g IP6.SEARCHES device show eth1')
printf '%s\n' '--'
;;
'--offline con add type ethernet con-name xcat-eth0 ifname eth0 ipv4.method disabled ipv6.method manual ipv6.addresses 2001:db8:1::21/64 connection.autoconnect yes connection.autoconnect-priority 9 ipv6.gateway fe80::1 ipv6.dns 2001:db8::53,2001:db8::54 ipv6.dns-search cluster.example,lab.example 802-3-ethernet.mtu 9000')
printf '%s\n' \
'[connection]' \
'id=xcat-eth0' \
'uuid=01234567-89ab-cdef-0123-456789abcdef' \
'type=ethernet' \
'autoconnect-priority=9' \
'interface-name=eth0' \
'' \
'[ethernet]' \
'mtu=9000' \
'' \
'[ipv4]' \
'method=disabled' \
'' \
'[ipv6]' \
'addr-gen-mode=default' \
'address1=2001:db8:1::21/64' \
'dns=2001:db8::53;2001:db8::54;' \
'dns-search=cluster.example;lab.example;' \
'gateway=fe80::1' \
'method=manual' \
'' \
'[proxy]'
;;
*)
printf '%s\n' "$*" >> "$NMCLI_LOG"
;;
esac
}
discover_install_nic_ipv6 eth0 2001:db8:1::21 || fail 'IPv6 discovery failed'
[ "$str_inst_ipv6" = '2001:db8:1::21' ] || fail "unexpected address: $str_inst_ipv6"
[ "$str_inst_ipv6_prefix" = '64' ] || fail "unexpected prefix: $str_inst_ipv6_prefix"
[ "$str_inst_ipv6_gateway" = 'fe80::1' ] || fail "unexpected gateway: $str_inst_ipv6_gateway"
[ "$str_inst_ipv6_dns" = '2001:db8::53,2001:db8::54' ] || fail "unexpected DNS: $str_inst_ipv6_dns"
[ "$str_inst_ipv6_dns_search" = 'cluster.example,lab.example' ] || fail "unexpected DNS search: $str_inst_ipv6_dns_search"
[ "$str_inst_mtu" = '9000' ] || fail "unexpected MTU: $str_inst_mtu"
configure_install_nic_ipv6_nm \
xcat-eth0 eth0 "$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu"
configure_install_nic_ipv6_keyfile \
xcat-eth0 eth0 "$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu" "$KEYFILE"
discover_install_nic_ipv6 eth1 || fail 'IPv6 discovery with NetworkManager gateway fallback failed'
[ "$str_inst_ipv6_gateway" = 'fe80::2' ] || fail "unexpected fallback gateway: $str_inst_ipv6_gateway"
if discover_install_nic_ipv6 eth2; then
fail 'IPv6 discovery accepted an interface without a global address'
fi
SHELL
close($harness_fh);
my ( $log_fh, $log ) = tempfile();
close($log_fh);
my ( $keyfile_fh, $keyfile ) = tempfile();
close($keyfile_fh);
unlink($keyfile) or die "Unable to prepare $keyfile: $!";
is( system( 'bash', $harness, $log, $keyfile ), 0, 'IPv6 install-NIC discovery and persistence helpers execute successfully' );
open( my $log_fh_read, '<', $log ) or die "Unable to read $log: $!";
my @nmcli = <$log_fh_read>;
close($log_fh_read);
chomp(@nmcli);
is_deeply(
\@nmcli,
[
'con add type ethernet con-name xcat-eth0 ifname eth0 ipv4.method disabled ipv6.method manual ipv6.addresses 2001:db8:1::21/64 connection.autoconnect yes connection.autoconnect-priority 9 ipv6.gateway fe80::1 ipv6.dns 2001:db8::53,2001:db8::54 ipv6.dns-search cluster.example,lab.example 802-3-ethernet.mtu 9000',
],
'NetworkManager connection is IPv6-only and persists address, route, DNS, search domains, and MTU'
);
unlike(
join( "\n", @nmcli ),
qr/ipv4\.(?:addresses|dns)|ipv4\.method (?:auto|manual)/,
'IPv6-only persistence never configures or enables IPv4'
);
open( my $keyfile_fh_read, '<', $keyfile ) or die "Unable to read $keyfile: $!";
my $keyfile_content = do { local $/; <$keyfile_fh_read> };
close($keyfile_fh_read);
is(
$keyfile_content,
<<'KEYFILE',
[connection]
id=xcat-eth0
uuid=01234567-89ab-cdef-0123-456789abcdef
type=ethernet
autoconnect-priority=9
interface-name=eth0
[ethernet]
mtu=9000
[ipv4]
method=disabled
[ipv6]
addr-gen-mode=default
address1=2001:db8:1::21/64
dns=2001:db8::53;2001:db8::54;
dns-search=cluster.example;lab.example;
gateway=fe80::1
method=manual
[proxy]
KEYFILE
'Anaconda-stage fallback writes the equivalent native NetworkManager keyfile'
);
is(
( stat($keyfile) )[2] & oct('07777'),
oct('0600'),
'NetworkManager keyfile is private'
);
unlike( $keyfile_content, qr/^address1=\d+\.\d+\.\d+\.\d+/m, 'keyfile does not configure an IPv4 address' );
like(
$content,
qr/if \[ \$install_nic_is_ipv6 -ne 1 \]; then\n\s+str_inst_net=\$\(v4calcnet/,
'legacy IPv4 network calculation remains on the IPv4 path'
);
like(
$content,
qr/\[ \$install_nic_is_ipv6 -eq 1 \] && \[ \$networkmanager_active -eq 2 \].*?configure_install_nic_ipv6_keyfile/s,
'chrooted Anaconda path persists a keyfile instead of an obsolete ifcfg file'
);
like(
$content,
qr/Do not tear down the\n\s+# Anaconda-owned live connection from inside the chroot/,
'Anaconda-stage keyfile persistence leaves the live installer connection up'
);
like(
$content,
qr/nmcli con add type ethernet con-name \$con_name ifname \$\{str_inst_nic\} ipv4\.method manual ipv4\.addresses/,
'legacy IPv4 NetworkManager persistence remains available'
);
like(
$content,
qr/discover_install_nic_ipv6 "\$str_inst_nic" "\$str_requested_ipv6"/,
'configeth -s asks live discovery for the xCAT-defined IPv6 address when IPv4 lease data is absent'
);
like(
$content,
qr/\[ -n "\$NAMESERVERS" \] && nmcli con modify "\$con_name" ipv6\.dns "\$NAMESERVERS"/,
'restart path updates IPv6 DNS without writing IPv4 DNS properties'
);
done_testing();
+303
View File
@@ -0,0 +1,303 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use POSIX ();
use Time::HiRes qw(usleep);
use Test::More;
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../xCAT-server/lib/xcat";
my $source = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/credentials.pm";
require $source;
pass('credentials plugin loads successfully');
my $allowcred = "$FindBin::Bin/../../xCAT/postscripts/allowcred.awk";
open(my $allowcred_fh, '<', $allowcred) or die "Unable to read $allowcred: $!";
my $allowcred_source = do { local $/; <$allowcred_fh> };
close($allowcred_fh);
like(
$allowcred_source,
qr/"MASTER_IP" in ENVIRON/,
'shipped credential callback selects its listener family from the resolved master'
);
like(
$allowcred_source,
qr{listener = "/inet6/tcp/" port "/0/0"},
'shipped credential callback has an IPv6 listener path'
);
{
package CredentialsCallbackTest::Socket;
}
{
package CredentialsCallbackTest::Handle;
our $printed = '';
sub TIEHANDLE { return bless {}, shift; }
sub PRINT {
shift;
$printed .= join( '', @_ );
return 1;
}
sub READLINE { return "CREDOKBYME\n"; }
}
{
package CredentialsCallbackTest::Select;
sub add { return 1; }
sub can_read { return 1; }
}
{
package CredentialsCallbackTest::Browser;
our @uris;
sub timeout { return 1; }
sub request {
my ( $self, $request ) = @_;
push @uris, $request->uri->as_string;
return bless {
_content => 'Ciphers supported in s_server binary'
}, 'CredentialsCallbackTest::Response';
}
}
{
package CredentialsCallbackTest::Response;
sub is_success { return 1; }
}
is(
xCAT_plugin::credentials::_callback_https_uri( '192.0.2.21', 300 ),
'https://192.0.2.21:300/',
'IPv4 callback URI remains unchanged'
);
is(
xCAT_plugin::credentials::_callback_https_uri( 'node.example.test', 300 ),
'https://node.example.test:300/',
'hostname callback URI remains unchanged'
);
is(
xCAT_plugin::credentials::_callback_https_uri( '2001:db8::21', 300 ),
'https://[2001:db8::21]:300/',
'IPv6 callback URI uses a bracketed authority'
);
is(
xCAT_plugin::credentials::_callback_https_uri( '[2001:db8::21]', 300 ),
'https://[2001:db8::21]:300/',
'already-bracketed IPv6 callback URI is not double-bracketed'
);
ok(
!defined( xCAT_plugin::credentials::_callback_https_uri( '2001:db8::21', 70000 ) ),
'malformed callback endpoint is rejected'
);
my $has_inet6 = eval {
require Socket6;
require IO::Socket::INET6;
1;
};
SKIP: {
skip 'IO::Socket::INET6 and Socket6 are unavailable', 4 unless $has_inet6;
my ( %inet6_args, $inet4_calls );
no warnings 'redefine';
local *IO::Socket::INET6::new = sub {
shift;
%inet6_args = @_;
return bless {}, 'CredentialsCallbackTest::Socket';
};
local *IO::Socket::INET::new = sub {
$inet4_calls++;
return bless {}, 'CredentialsCallbackTest::Socket';
};
my $socket = xCAT_plugin::credentials::_open_callback_socket( '2001:db8::21', 300 );
isa_ok( $socket, 'CredentialsCallbackTest::Socket', 'IPv6 callback socket' );
is_deeply(
\%inet6_args,
{
PeerAddr => '2001:db8::21',
PeerPort => 300,
Proto => 'tcp',
},
'family-neutral constructor receives the complete IPv6 literal and privileged port'
);
is( $inet4_calls || 0, 0, 'successful IPv6 socket does not enter the IPv4 fallback' );
local *IO::Socket::INET6::new = sub { return; };
my %fallback_args;
local *IO::Socket::INET::new = sub {
shift;
%fallback_args = @_;
return bless {}, 'CredentialsCallbackTest::Socket';
};
$socket = xCAT_plugin::credentials::_open_callback_socket( '192.0.2.21', 300 );
is_deeply(
\%fallback_args,
{
PeerAddr => '192.0.2.21',
PeerPort => 300,
Proto => 'tcp',
},
'original IPv4 socket path remains the fallback'
);
}
SKIP: {
skip 'IPv6 loopback sockets are unavailable', 2 unless $has_inet6;
my $listener = IO::Socket::INET6->new(
LocalAddr => '::1',
LocalPort => 0,
Listen => 1,
Proto => 'tcp',
ReuseAddr => 1,
);
skip 'IPv6 loopback listener could not be created', 2 unless $listener;
my $port = $listener->sockport();
my $pid = fork();
skip 'fork is unavailable', 2 unless defined($pid);
if ($pid == 0) {
local $SIG{ALRM} = sub { POSIX::_exit(2); };
alarm(8);
my $peer = $listener->accept();
POSIX::_exit(3) unless $peer;
my $challenge = <$peer>;
if (defined($challenge) && $challenge eq "CREDOKBYYOU?\n") {
print {$peer} "CREDOKBYME\n";
close($peer);
POSIX::_exit(0);
}
POSIX::_exit(4);
}
close($listener);
is(
xCAT_plugin::credentials::ok_with_node( '::1', [ 0, $port ] ),
1,
'plain callback completes over a real IPv6 loopback socket'
);
waitpid( $pid, 0 );
is( $?, 0, 'IPv6 callback server received the unchanged challenge' );
}
{
no warnings qw(once redefine);
local *CALLBACK_SOCKET;
tie *CALLBACK_SOCKET, 'CredentialsCallbackTest::Handle';
local *xCAT_plugin::credentials::_open_callback_socket = sub {
is_deeply(
[@_],
[ '2001:db8::21', 300 ],
'plain callback probes the complete IPv6 address and port'
);
return \*CALLBACK_SOCKET;
};
local *IO::Select::new = sub {
return bless {}, 'CredentialsCallbackTest::Select';
};
$CredentialsCallbackTest::Handle::printed = '';
is(
xCAT_plugin::credentials::ok_with_node( '2001:db8::21', [ 0, 300 ] ),
1,
'plain IPv6 callback accepts the expected node response'
);
is(
$CredentialsCallbackTest::Handle::printed,
"CREDOKBYYOU?\n",
'plain callback sends the credential challenge unchanged'
);
untie *CALLBACK_SOCKET;
}
{
no warnings qw(once redefine);
local *LWP::UserAgent::new = sub {
return bless {}, 'CredentialsCallbackTest::Browser';
};
local $SIG{ALRM};
@CredentialsCallbackTest::Browser::uris = ();
is(
xCAT_plugin::credentials::ok_with_node( '2001:db8::21', [ 1, 300 ] ),
1,
'HTTPS IPv6 callback accepts the expected s_server response'
);
is_deeply(
\@CredentialsCallbackTest::Browser::uris,
['https://[2001:db8::21]:300/'],
'ok_with_node sends HTTPS probe to the bracketed IPv6 authority'
);
}
my $gawk;
for my $directory (split(/:/, $ENV{PATH} || '')) {
my $candidate = "$directory/gawk";
if (-x $candidate) {
$gawk = $candidate;
last;
}
}
SKIP: {
skip 'gawk IPv6 networking is unavailable', 2 unless $has_inet6 && $gawk;
my $reservation = IO::Socket::INET6->new(
LocalAddr => '::1',
LocalPort => 0,
Listen => 1,
Proto => 'tcp',
ReuseAddr => 1,
);
skip 'IPv6 loopback port reservation failed', 2 unless $reservation;
my $port = $reservation->sockport();
close($reservation);
my $pid = fork();
skip 'fork is unavailable', 2 unless defined($pid);
if ($pid == 0) {
$ENV{MASTER_IP} = '::1';
$ENV{XCAT_CREDENTIAL_CALLBACK_PORT} = $port;
open(STDOUT, '>', '/dev/null');
open(STDERR, '>', '/dev/null');
exec($gawk, '-f', $allowcred) or POSIX::_exit(127);
}
my $socket;
for (1 .. 40) {
$socket = IO::Socket::INET6->new(
PeerAddr => '::1',
PeerPort => $port,
Proto => 'tcp',
Timeout => 1,
);
last if $socket;
usleep(100_000);
}
ok($socket, 'actual shipped callback accepts an IPv6 loopback connection');
my $response;
if ($socket) {
print {$socket} "CREDOKBYYOU?\n";
local $SIG{ALRM} = sub { die "credential callback read timed out\n"; };
eval {
alarm(5);
$response = <$socket>;
alarm(0);
};
alarm(0);
close($socket);
}
is($response, "CREDOKBYME\n", 'actual shipped callback completes the credential challenge over IPv6');
kill('TERM', $pid);
waitpid($pid, 0);
}
done_testing();
+280
View File
@@ -0,0 +1,280 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use lib "$FindBin::Bin/../../xCAT-server/lib";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../perl-xCAT";
use File::Temp qw(tempdir);
use Socket ();
use Test::More;
$ENV{XCATCFG} ||= 'SQLite:/tmp';
my $source_ddns_plugin =
"$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/ddns.pm";
if (-f $source_ddns_plugin) {
require $source_ddns_plugin;
} else {
require xCAT_plugin::ddns;
}
ok(xCAT_plugin::ddns::isvalidip('192.0.2.10'), 'makedns accepts IPv4');
ok(!xCAT_plugin::ddns::isvalidip('192.0.2.999'), 'makedns rejects invalid IPv4');
ok(!xCAT_plugin::ddns::isvalidip('192.0.2x10'), 'makedns rejects malformed IPv4');
ok(
xCAT_plugin::ddns::isvalidip('192.0.2.010'),
'makedns preserves leading-zero detection for its caller'
);
is(
xCAT_plugin::ddns::_preferred_ip_address(
'2001:db8::10',
'192.0.2.10'
),
'192.0.2.10',
'dual-stack DNS host preserves IPv4 preference'
);
is(xCAT_plugin::ddns::_dns_record_type('192.0.2.10'), 'A', 'IPv4 uses an A record');
my $has_core_ipv6_parser = defined(&Socket::inet_pton)
&& eval { defined(Socket::inet_pton(Socket::AF_INET6(), '::1')) };
my $has_ipv6_parser = $has_core_ipv6_parser
|| eval { require Socket6; 1 };
{
no warnings qw(once redefine);
my @families;
local *xCAT::NetworkUtils::my_ip_facing = sub {
push @families, 4;
return (0, '192.0.2.1');
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my ($class, $peer, $family) = @_;
push @families, $family;
return (0, '2001:db8:1::1');
};
is_deeply(
[ xCAT_plugin::ddns::_local_addresses_for_network('192.0.2.0') ],
['192.0.2.1'],
'IPv4 DNS-network ownership retains the legacy facing-address path'
);
is_deeply(
[ xCAT_plugin::ddns::_local_addresses_for_network('2001:db8:1::/64') ],
['2001:db8:1::1'],
'IPv6 DNS-network ownership strips CIDR and uses the IPv6 facing path'
);
is_deeply(\@families, [4, 6], 'DNS-network ownership selects the matching address family');
}
SKIP: {
skip 'No IPv6 literal parser is available', 9 unless $has_ipv6_parser;
ok(xCAT_plugin::ddns::isvalidip('2001:db8::10'), 'makedns accepts IPv6');
ok(xCAT_plugin::ddns::isvalidip('2001:DB8::10'), 'makedns accepts uppercase IPv6');
ok(
xCAT_plugin::ddns::isvalidip('::ffff:192.0.2.10'),
'makedns accepts IPv4-mapped IPv6'
);
ok(!xCAT_plugin::ddns::isvalidip('2001:db8::g'), 'makedns rejects invalid IPv6');
is(
xCAT_plugin::ddns::_preferred_ip_address('2001:db8::10'),
'2001:db8::10',
'IPv6-only DNS host uses its IPv6 address'
);
is(
xCAT_plugin::ddns::_dns_record_type('2001:db8::10'),
'AAAA',
'IPv6 uses an AAAA record'
);
my $ctx = {
aliases => { node01 => {} },
currip => '2001:db8::10',
currname => 'node01.example.com',
currnode => 'node01',
currrevname => '0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.',
deletemode => 1,
nodeips => { node01 => {} },
nsmap => { 'example.com.' => 'dns.example.com' },
updatesbyzone => {},
};
xCAT_plugin::ddns::find_nameserver_for_dns($ctx, 'example.com.');
my $updates = $ctx->{updatesbyzone}->{'example.com.'};
ok(
grep($_ eq 'node01.example.com. IN AAAA 2001:db8::10', @{$updates}),
'IPv6 delete queues the current AAAA record'
);
ok(
grep($_ eq 'node01.example.com. AAAA', @{$updates}),
'IPv6 delete queues a wildcard AAAA cleanup'
);
my $dbdir = tempdir(CLEANUP => 1);
my $zone_context = {
adzones => {},
dbdir => $dbdir,
hoststab => { dns => [ { ip => '2001:db8::53' } ] },
zonestotouch => { 'example.com.' => 1 },
};
{
no warnings qw(once redefine);
local *xCAT_plugin::ddns::hostname = sub { return 'dns'; };
local *xCAT::NetworkUtils::getNodeDomains = sub {
return { dns => 'example.com' };
};
local *xCAT::SvrUtils::sendmsg = sub { return; };
xCAT_plugin::ddns::update_zones($zone_context);
}
open(my $zone_fh, '<', "$dbdir/db.example.com.")
or die "Cannot read generated IPv6 zone: $!";
my $zone_contents = do { local $/; <$zone_fh> };
close($zone_fh);
like(
$zone_contents,
qr/^dns\.example\.com\.\s+IN AAAA\s+2001:db8::53$/m,
'new static zone uses AAAA glue for an IPv6-only DNS server'
);
}
SKIP: {
skip 'No IPv6 literal parser is available for reverse-zone conversion', 11
unless $has_ipv6_parser;
is(
xCAT::NetworkUtils->getIPv6ReverseName('::'),
join('.', ('0') x 32) . '.ip6.arpa.',
'all-zero IPv6 PTR owner contains all 32 nibbles'
);
my @zero_network_zones =
xCAT_plugin::ddns::getzonesfornet({ net => '::/128' });
is(
$zero_network_zones[0],
join('.', ('0') x 32) . '.ip6.arpa.',
'all-zero IPv6 network produces its full reverse zone'
);
my @default_route_zones =
xCAT_plugin::ddns::getzonesfornet({ net => '::/0' });
is(
$default_route_zones[0],
'ip6.arpa.',
'IPv6 /0 produces the root reverse zone without looping'
);
my $default_route_ctx = {
hoststab => {
default01 => [ { ip => '2001:db8::1' } ],
},
nets => {
'::/0' => {
mask => xCAT::NetworkUtils->getipaddr('::', GetNumber => 1),
netn => xCAT::NetworkUtils->getipaddr('::', GetNumber => 1),
},
},
};
my @default_route_entity_zones =
xCAT_plugin::ddns::get_reverse_zones_for_entity(
$default_route_ctx,
'default01'
);
is(
$default_route_entity_zones[0],
'ip6.arpa.',
'IPv6 /0 associates an entity with the root reverse zone'
);
is(
xCAT::NetworkUtils->getIPv6ReverseName('::1'),
join('.', reverse(split(//, ('0' x 31) . '1'))) . '.ip6.arpa.',
'IPv6 PTR owner contains all 32 nibbles for a leading-zero address'
);
is(
xCAT_plugin::ddns::_dns_reverse_name('::ffff:192.0.2.10'),
join('.', reverse(split(//, '00000000000000000000ffffc000020a')))
. '.ip6.arpa.',
'IPv4-mapped IPv6 uses a 32-nibble IPv6 PTR owner'
);
xCAT::NetworkUtils->clearcache();
my $network_number = xCAT::NetworkUtils->getipaddr(
'2001:db8:7309::',
GetNumber => 1
);
my $network_mask = xCAT::NetworkUtils->getipaddr(
'ffff:ffff:ffff:ffff::',
GetNumber => 1
);
my @reverse_zones =
xCAT_plugin::ddns::getzonesfornet({ net => '2001:db8:7309::/64' });
is(
$reverse_zones[0],
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'IPv6 /64 produces the expected reverse zone'
);
my @split_mask_reverse_zones = xCAT_plugin::ddns::getzonesfornet(
{ net => '2001:db8:7309::', mask => '64' }
);
is(
$split_mask_reverse_zones[0],
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'IPv6 network with a separate numeric mask produces the expected reverse zone'
);
is_deeply(
[ xCAT_plugin::ddns::getzonesfornet({ net => '2001:db8:7309::' }) ],
[],
'IPv6 network without a prefix terminates without generating a reverse zone'
);
my $ctx = {
hoststab => {
node01 => [ { ip => '2001:db8:7309::1234' } ],
},
nets => {
'2001:db8:7309::/64' => {
mask => $network_mask,
netn => $network_number,
},
},
};
my @node_reverse_zones =
xCAT_plugin::ddns::get_reverse_zones_for_entity($ctx, 'node01');
is(
$node_reverse_zones[0],
$reverse_zones[0],
'zone generation preserves the network number used for PTR association'
);
my $mapped_network = '::ffff:192.0.2.0/120';
my $mapped_ctx = {
hoststab => {
mapped01 => [ { ip => '::ffff:192.0.2.10' } ],
},
nets => {
$mapped_network => {
mask => xCAT::NetworkUtils->getipaddr(
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00',
GetNumber => 1
),
netn => xCAT::NetworkUtils->getipaddr(
'::ffff:192.0.2.0',
GetNumber => 1
),
},
},
};
my @mapped_zones =
xCAT_plugin::ddns::get_reverse_zones_for_entity($mapped_ctx, 'mapped01');
my @expected_mapped_zones =
xCAT_plugin::ddns::getzonesfornet({ net => $mapped_network });
is(
$mapped_zones[0],
$expected_mapped_zones[0],
'IPv4-mapped IPv6 network is associated with its ip6.arpa zone'
);
}
done_testing();
+256 -1
View File
@@ -36,6 +36,29 @@ BEGIN {
}
sub getipaddr { return '10.0.0.1'; }
sub my_ip_facing { return ( 0, '10.0.0.1' ); }
sub my_ip_facing_family { return ( 0, '2001:db8::1' ); }
sub getIPv6PrefixLength {
my ( $class, $network, $mask ) = @_;
( $network, $mask ) = ( $class, $network ) if $class ne __PACKAGE__;
return $1 if defined($network) && $network =~ m{/([0-9]+)$} && $1 <= 128;
return $1 if defined($mask) && $mask =~ m{^/?([0-9]+)$} && $1 <= 128;
return;
}
sub getIPv6ReverseZone {
my ( $class, $network, $mask ) = @_;
( $network, $mask ) = ( $class, $network ) if $class ne __PACKAGE__;
my $prefix = getIPv6PrefixLength(__PACKAGE__, $network, $mask);
return unless defined($prefix);
return '0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.'
if $network =~ /^2001:db8:7309::/ && $prefix == 64;
return;
}
sub format_uri_host {
my ($host) = @_;
$host = $_[1] if defined($host) && $host eq __PACKAGE__;
return "[$host]" if defined($host) && $host =~ /:/;
return $host;
}
sub thishostisnot { return 0; }
sub ip_forwarding_enabled { return 0; }
sub nodeonmynet { return 1; }
@@ -223,6 +246,49 @@ foreach my $case (@sysconfig_policy_cases) {
is( $actual, $expected, "$description keeps the dhcpd sysconfig policy" );
}
{
# Regression: makenetworks stores some IPv6 networks as a literal in
# networks.net and a numeric prefix in networks.mask. Reverse-zone
# generation must consume that representation without looping.
no warnings 'redefine';
local *xCAT_plugin::dhcp::getipaddr = sub {
my ( $address, %options ) = @_;
return Math::BigInt->new('0x20010db8730900000000000000000000')
if $address eq '2001:db8:7309::' && $options{GetNumber};
return;
};
my ($zone, $error);
{
local $SIG{ALRM} = sub { die "IPv6 reverse-zone generation timed out\n" };
eval {
alarm 2;
$zone = xCAT_plugin::dhcp::getzonesfornet(
'2001:db8:7309::', '64'
);
alarm 0;
1;
} or $error = $@;
alarm 0;
}
is($error, undef, 'Kea DDNS reverse-zone generation terminates');
is(
$zone,
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'Kea DDNS accepts an IPv6 network with a separate numeric prefix mask'
);
is_deeply(
[ xCAT_plugin::dhcp::getzonesfornet('2001:db8:7309::', undef) ],
[],
'Kea DDNS rejects a missing IPv6 prefix without looping'
);
is_deeply(
[ xCAT_plugin::dhcp::getzonesfornet('2001:db8:7309::', '129') ],
[],
'Kea DDNS rejects an out-of-range IPv6 prefix without looping'
);
}
{
my $tmpdir = tempdir(CLEANUP => 1);
my $fake_ip = "$tmpdir/ip";
@@ -351,6 +417,50 @@ foreach my $case (@sysconfig_policy_cases) {
is( $intent->{subnets}[0]{subnet}, '10.0.0.0/24', 'rendered subnet comes from local route' );
}
{
package DHCPKeaControlSocketBackend;
sub control_socket_name {
my ( $self, $name ) = @_;
return "shared-$name";
}
sub host_cmds_hook_path { return '/usr/lib64/kea/hooks/libdhcp_host_cmds.so'; }
package main;
no warnings 'redefine';
local *xCAT_plugin::dhcp::kea_ipv4_routes = sub {
return ([ '10.0.0.0', 'eth0', '255.255.255.0', '' ]);
};
local *xCAT_plugin::dhcp::kea_boot_client_classes = sub { return []; };
local *xCAT_plugin::dhcp::kea_option_defs = sub { return []; };
local *xCAT_plugin::dhcp::kea_global_option_data = sub { return []; };
local *xCAT_plugin::dhcp::kea_dhcp_lease_time = sub { return 43200; };
local *xCAT_plugin::dhcp::kea_control_agent_enabled = sub { return 1; };
my $backend = bless {}, 'DHCPKeaControlSocketBackend';
local $xCAT::Table::networks = DHCPKeaIntentNetTable->new( \%network_entry );
my $intent4 = xCAT_plugin::dhcp::kea_build_dhcp4_intent($backend, { eth0 => 1 });
is(
$intent4->{'control-socket'}{'socket-name'},
'shared-kea4-ctrl-socket',
'DHCPv4 and Control Agent use the shared Kea socket-name policy'
);
local $xCAT::Table::networks = DHCPKeaIntentNetTable->new(
{
net => '2001:db8:7309::',
mask => '64',
mgtifname => 'eth0',
domain => 'cluster.test',
}
);
my $intent6 = xCAT_plugin::dhcp::kea_build_dhcp6_intent($backend, { eth0 => 1 });
is(
$intent6->{'control-socket'}{'socket-name'},
'shared-kea6-ctrl-socket',
'DHCPv6 and Control Agent use the shared Kea socket-name policy'
);
}
{
no warnings 'redefine';
local *xCAT::NetworkUtils::thishostisnot = sub { return 0; };
@@ -581,6 +691,56 @@ foreach my $case (@sysconfig_policy_cases) {
}
}
{
# The same placeholder resolution and reverse-zone path must work when an
# IPv6 network stores its prefix in networks.mask instead of CIDR notation.
no warnings 'redefine';
local *xCAT_plugin::dhcp::kea_ddns_enabled = sub { 1 };
local *xCAT_plugin::dhcp::kea_ddns_key = sub { ( 'HMAC-SHA256', 'YWJjMTIz' ); };
local *xCAT_plugin::dhcp::getipaddr = sub {
my ( $address, %options ) = @_;
return Math::BigInt->new('0x20010db8730900000000000000000000')
if $address eq '2001:db8:7309::' && $options{GetNumber};
return;
};
local $xCAT::Table::networks = DHCPKeaIntentNetTable->new(
{
net => '2001:db8:7309::',
mask => '64',
nameservers => '<xcatmaster>',
domain => 'cluster.test',
}
);
my ($ddns_intent, $error);
{
local $SIG{ALRM} = sub { die "IPv6 Kea DDNS intent timed out\n" };
eval {
alarm 2;
$ddns_intent = xCAT_plugin::dhcp::kea_build_ddns_intent();
alarm 0;
1;
} or $error = $@;
alarm 0;
}
is($error, undef, 'IPv6 Kea DDNS intent generation terminates');
ok(
$ddns_intent && !$ddns_intent->{error},
'IPv6 Kea DDNS intent accepts a separate numeric prefix mask'
);
is(
$ddns_intent->{reverse_domains}[0]{name},
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'IPv6 Kea DDNS intent renders the expected reverse zone'
);
is(
$ddns_intent->{reverse_domains}[0]{'dns-servers'}[0]{'ip-address'},
'2001:db8::1',
'IPv6 Kea DDNS resolves <xcatmaster> to the IPv6-facing management address'
);
}
{
# Regression: a service node (noderes.servicenode set, groups=service) must
# get a Kea host reservation exactly like a regular compute node. The Kea
@@ -599,7 +759,10 @@ foreach my $case (@sysconfig_policy_cases) {
sub getNodesAttribs {
my ( $self, $nodes, $attrs ) = @_;
my %out;
$out{$_} = [ $self->{rows}{$_} || {} ] for @$nodes;
foreach my $node (@$nodes) {
my $row = $self->{rows}{$node} || {};
$out{$node} = [ { map { exists($row->{$_}) ? ($_ => $row->{$_}) : () } @$attrs } ];
}
return \%out;
}
sub close { return; }
@@ -1931,4 +2094,96 @@ for my $case (['80', ''], ['080', ':080'], ['8080', ':8080']) {
'subnet generation preserves the supplied port');
}
{
my %res_tables = (
noderes => DHCPKeaResTable->new(
{
'nodev6' => { netboot => 'grub2', tftpserver => '<xcatmaster>' },
'nodev6http' => { netboot => 'grub2-http', tftpserver => 'boot6.example.test' },
'nodev6tftp' => { netboot => 'grub2-tftp', tftpserver => 'boot6.example.test' },
'nodev6xnba' => { netboot => 'xnba', tftpserver => 'boot6.example.test' },
}
),
mac => DHCPKeaResTable->new(
{
'nodev6' => { mac => '02:00:00:00:00:61' },
'nodev6http' => { mac => '02:00:00:00:00:62' },
'nodev6tftp' => { mac => '02:00:00:00:00:64' },
'nodev6xnba' => { mac => '02:00:00:00:00:63' },
}
),
vpd => DHCPKeaResTable->new(
{
'nodev6' => { uuid => '00112233-4455-6677-8899-aabbccddeeff' },
'nodev6http' => {},
'nodev6tftp' => {},
'nodev6xnba' => {},
}
),
);
no warnings 'redefine';
local *xCAT::Table::new = sub {
my ( $class, $name ) = @_;
return $res_tables{$name};
};
my %node_addresses = (
nodev6 => '2001:db8:61::50',
nodev6http => '2001:db8:62::50',
nodev6tftp => '2001:db8:64::50',
nodev6xnba => '2001:db8:63::50',
'boot6.example.test' => '2001:db8::10',
);
my $v6_getipaddr = sub {
my ( $host, %opt ) = @_;
return unless $opt{OnlyV6};
return $node_addresses{$host};
};
local *xCAT::NetworkUtils::getipaddr = $v6_getipaddr;
local *xCAT_plugin::dhcp::getipaddr = $v6_getipaddr;
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my ( $class, $peer, $family ) = @_;
return ( 1, 'unexpected address family' ) unless $family == 6;
return ( 0, '2001:db8::1' );
};
local *xCAT_plugin::dhcp::ipIsDynamic = sub { return 0; };
my @errors;
local $xCAT_plugin::dhcp::callback = sub {
my $resp = shift;
push @errors, @{ $resp->{error} } if $resp->{error};
};
my $backend = bless {}, 'DHCPKeaRes6Backend';
{
package DHCPKeaRes6Backend;
sub subnet_id_for_ip { return 61; }
}
my $reservations = xCAT_plugin::dhcp::kea_build_node_reservations6(
$backend,
{},
[qw(nodev6 nodev6http nodev6tftp nodev6xnba)]
);
is( scalar(@errors), 0, 'DHCPv6 reservations build without errors' );
is( scalar(@$reservations), 4, 'all known IPv6 nodes receive reservations' );
my %by_hostname = map { $_->{hostname} => $_ } @$reservations;
my $grub2 = $by_hostname{nodev6};
is( $grub2->{duid}, '00:04:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff', 'DHCPv6 reservation retains DUID-UUID matching' );
is( $grub2->{'option-data'}[0]{name}, 'bootfile-url', 'grub2 reservation carries RFC 5970 bootfile-url' );
is( $grub2->{'option-data'}[0]{data}, 'tftp://[2001:db8::1]/boot/grub2/grub2-nodev6', 'grub2 bootfile URL uses the IPv6-facing xCAT server and bracketed authority' );
ok( $grub2->{'option-data'}[0]{'always-send'}, 'grub2 bootfile URL is always sent' );
my $grub2_http = $by_hostname{nodev6http};
is( $grub2_http->{'hw-address'}, '02:00:00:00:00:62', 'DHCPv6 reservation retains hardware-address fallback' );
is( $grub2_http->{'option-data'}[0]{data}, 'tftp://[2001:db8::10]/boot/grub2/grub2-nodev6http', 'grub2-http firmware handoff still loads GRUB over TFTP from the configured IPv6 server' );
my $grub2_tftp = $by_hostname{nodev6tftp};
is( $grub2_tftp->{'option-data'}[0]{data}, 'tftp://[2001:db8::10]/boot/grub2/grub2-nodev6tftp', 'grub2-tftp receives the DHCPv6 bootfile URL advertised as supported on x86_64' );
ok( !exists($by_hostname{nodev6xnba}{'option-data'}), 'unsupported IPv6 netboot modes do not receive a GRUB bootfile URL' );
}
done_testing();
+46 -5
View File
@@ -4,6 +4,7 @@ use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use File::Path qw/make_path/;
use File::Temp qw/tempdir/;
use JSON;
use Test::More;
@@ -484,6 +485,13 @@ my $dhcp6_json = $backend->render_dhcp6_config(
duid => '00:04:52:54:00:12:34:56',
'ip-addresses' => ['2001:db8:1::50'],
hostname => 'nodev6',
'option-data' => [
{
name => 'bootfile-url',
data => 'tftp://[2001:db8:1::1]/boot/grub2/grub2-nodev6',
'always-send' => JSON::true,
},
],
},
],
},
@@ -497,6 +505,10 @@ is( $dhcp6_config->{Dhcp6}{'valid-lifetime'}, 700, 'DHCPv6 valid lifetime is num
is( $dhcp6_config->{Dhcp6}{'preferred-lifetime'}, 500, 'DHCPv6 preferred lifetime is numeric' );
is( $dhcp6_config->{Dhcp6}{subnet6}[0]{id}, 11, 'DHCPv6 subnet id is numeric' );
is( $dhcp6_config->{Dhcp6}{subnet6}[0]{reservations}[0]{duid}, '00:04:52:54:00:12:34:56', 'DHCPv6 DUID reservation is rendered' );
my $dhcp6_bootfile = $dhcp6_config->{Dhcp6}{subnet6}[0]{reservations}[0]{'option-data'}[0];
is( $dhcp6_bootfile->{name}, 'bootfile-url', 'DHCPv6 reservation bootfile option is rendered' );
is( $dhcp6_bootfile->{data}, 'tftp://[2001:db8:1::1]/boot/grub2/grub2-nodev6', 'DHCPv6 reservation bootfile URL is preserved' );
ok( $dhcp6_bootfile->{'always-send'}, 'DHCPv6 reservation bootfile option preserves always-send' );
my $ddns_json = $backend->render_ddns_config(
{
@@ -532,14 +544,20 @@ my $ctrl_agent_config = decode_json($ctrl_agent_backend->render_ctrl_agent_confi
is( $ctrl_agent_config->{'Control-agent'}{'http-port'}, 8000, 'Control Agent HTTP port is numeric' );
my $runtime_socket_dir = "$unit_dir/run/kea";
mkdir "$unit_dir/run" or die "Unable to create $unit_dir/run: $!";
mkdir $runtime_socket_dir or die "Unable to create $runtime_socket_dir: $!";
my $legacy_runtime_socket_dir = "$unit_dir/var/run/kea";
make_path($runtime_socket_dir, $legacy_runtime_socket_dir);
my $runtime_socket_backend = xCAT::DHCP::Backend::Kea->new( kea_socket_dirs => [ $runtime_socket_dir, "$unit_dir/var/run/kea" ] );
my $runtime_socket_backend = xCAT::DHCP::Backend::Kea->new(
kea_version => '2.4.1',
kea_socket_dirs => [ $runtime_socket_dir, $legacy_runtime_socket_dir ],
);
my $runtime_socket_config = decode_json($runtime_socket_backend->render_ctrl_agent_config({}));
is( $runtime_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'socket-name'}, "$runtime_socket_dir/kea4-ctrl-socket", 'Control Agent socket uses the detected runtime directory' );
is( $runtime_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'socket-name'}, "$runtime_socket_dir/kea4-ctrl-socket", 'Control Agent prefers the canonical runtime directory when both paths exist' );
my $legacy_socket_backend = xCAT::DHCP::Backend::Kea->new( kea_socket_dirs => [] );
my $legacy_socket_backend = xCAT::DHCP::Backend::Kea->new(
kea_version => '2.4.1',
kea_socket_dirs => [],
);
my $legacy_socket_config = decode_json($legacy_socket_backend->render_ctrl_agent_config({}));
is( $legacy_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'socket-name'}, '/var/run/kea/kea4-ctrl-socket', 'Control Agent socket falls back to the legacy runtime path when no runtime directory exists' );
@@ -640,6 +658,29 @@ is( $ctrl_agent_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'sock
is( $ctrl_agent_socket_config->{'Control-agent'}{'control-sockets'}{dhcp6}{'socket-name'}, '/run/kea/kea6-ctrl-socket', 'Control Agent DHCPv6 socket uses the detected Kea socket directory' );
is( $ctrl_agent_socket_config->{'Control-agent'}{'control-sockets'}{d2}{'socket-name'}, '/run/kea/kea-ddns-ctrl-socket', 'Control Agent DDNS socket uses the detected Kea socket directory' );
my $restricted_socket_backend = xCAT::DHCP::Backend::Kea->new( kea_version => '3.0.1' );
my $restricted_socket_config = decode_json($restricted_socket_backend->render_ctrl_agent_config({ dhcp6 => 1, ddns => 1 }));
is( $restricted_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'socket-name'}, 'kea4-ctrl-socket', 'path-restricted Kea uses a DHCPv4 socket basename' );
is( $restricted_socket_config->{'Control-agent'}{'control-sockets'}{dhcp6}{'socket-name'}, 'kea6-ctrl-socket', 'path-restricted Kea uses a DHCPv6 socket basename' );
is( $restricted_socket_config->{'Control-agent'}{'control-sockets'}{d2}{'socket-name'}, 'kea-ddns-ctrl-socket', 'path-restricted Kea uses a DDNS socket basename' );
foreach my $case (
[ '2.4.1', 0 ],
[ '2.4.2', 1 ],
[ '2.6.2', 0 ],
[ '2.6.3', 1 ],
[ '2.7.8', 0 ],
[ '2.7.9', 1 ],
) {
my ( $version, $uses_basename ) = @$case;
my $versioned_backend = xCAT::DHCP::Backend::Kea->new(
kea_version => $version,
kea_socket_dirs => [],
);
my $expected = $uses_basename ? 'kea4-ctrl-socket' : '/var/run/kea/kea4-ctrl-socket';
is( $versioned_backend->control_socket_name('kea4-ctrl-socket'), $expected, "Kea $version selects the compatible control-socket form" );
}
my $explicit_socket_config = decode_json($socket_backend->render_ctrl_agent_config({ 'dhcp4-socket' => '/tmp/kea4.sock' }));
is( $explicit_socket_config->{'Control-agent'}{'control-sockets'}{dhcp4}{'socket-name'}, '/tmp/kea4.sock', 'explicit Control Agent socket path overrides the default' );
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $repo_root = File::Spec->rel2abs( File::Spec->catdir( $FindBin::Bin, '..', '..' ) );
sub read_file {
my ($relative_path) = @_;
my $path = File::Spec->catfile( $repo_root, split( '/', $relative_path ) );
open( my $fh, '<', $path ) or die "Unable to read $path: $!";
my $contents = do { local $/; <$fh> };
close($fh);
return ( $path, $contents );
}
sub shell_function {
my ( $script, $name ) = @_;
my ($definition) = $script =~ /((?:function\s+)?\Q$name\E\(\)\s*\n\{.*?^\})/ms;
return $definition;
}
sub run_shell_function {
my ( $definitions, $invocation, @args ) = @_;
my $program = "$definitions\n$invocation";
open( my $pipe, '-|', 'bash', '-c', $program, 'bash', @args )
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is( $?, 0, "$invocation exits successfully" );
chomp($output);
return $output;
}
my ( $pre_path, $pre ) = read_file('xCAT-server/share/xcat/install/scripts/pre.rhels10');
my ( $post_path, $post ) = read_file('xCAT-server/share/xcat/install/scripts/post.xcat.rhels10');
my ( $updateflag_path, $updateflag ) = read_file('xCAT/postscripts/updateflag.awk');
is( system( 'bash', '-n', $pre_path ), 0, 'EL10 pre-install script has valid bash syntax' );
is( system( 'bash', '-n', $post_path ), 0, 'EL10 post-install script has valid bash syntax' );
unlike(
$pre,
qr/socket\.socket\(socket\.AF_INET,\s*socket\.SOCK_STREAM\)/,
'EL10 installer callbacks do not hard-code IPv4 sockets'
);
is(
scalar( () = $pre =~ /socket\.create_connection\(\('#ENV:MASTER_IP#'/g ),
2,
'both EL10 installer callback clients use family-neutral connections to the facing master address'
);
like( $pre, qr/socket\.getaddrinfo\(master, None, socket\.AF_UNSPEC,/, 'install monitor selects the listener family from the master address' );
like( $pre, qr/None, port, master_family, socket\.SOCK_STREAM, 0, socket\.AI_PASSIVE/, 'install monitor requests a passive listener only in the provisioning family' );
like( $pre, qr/socket\.IPV6_V6ONLY, 1/, 'IPv6 monitor listener rejects IPv4-mapped clients' );
like( $pre, qr/if address\[0\] not in allowed_peers:/, 'install monitor rejects callback clients other than the configured master' );
unlike( $pre, qr/os\.popen\(newcommand\)/, 'screen capture does not construct a shell command from network input' );
like( $pre, qr/screen and not screen\.isdigit\(\)/, 'screen capture accepts only a numeric virtual-console suffix' );
my $extract_url_host = shell_function( $pre, 'extract_url_host' );
ok( defined($extract_url_host), 'pre-install URL host helper is present' );
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'http://192.0.2.10:8080/install/repo' ),
'192.0.2.10',
'pre-install repository discovery preserves an IPv4 host'
);
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'http://[2001:db8::10]:8080/install/repo' ),
'2001:db8::10',
'pre-install repository discovery extracts a complete bracketed IPv6 literal'
);
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'https://provision.example.test/install/repo' ),
'provision.example.test',
'pre-install repository discovery preserves a hostname'
);
like(
$pre,
qr/grep -oE 'https\?:\/\/\(\\\[\[\^\]\]\+\\\]\|\[\^\[:space:\]\/?:\]\+\)\(:\[0-9\]\+\)\?'/,
'kernel command-line URL discovery recognizes bracketed IPv6 authorities'
);
my $python = `command -v python3 2>/dev/null`;
chomp($python);
SKIP: {
skip 'python3 is unavailable', 4 unless $python;
foreach my $name (qw(baz foo)) {
my ($source) = $pre =~ /cat >\/tmp\/\Q$name\E\.py <<'EOF'\n(.*?)\nEOF/ms;
ok( defined($source), "$name.py installer helper is embedded" ) or next;
$source =~ s/#ENV:MASTER_IP#/2001:db8::1/g;
$source =~ s/#TABLE:site:key=xcatiport:value#/3002/g;
my ( $fh, $path ) = tempfile();
print {$fh} $source;
close($fh);
is(
system( $python, '-c', 'import sys; compile(open(sys.argv[1]).read(), sys.argv[1], "exec")', $path ),
0,
"$name.py remains valid Python after template expansion"
);
}
}
my $format_uri_host = shell_function( $post, 'format_uri_host' );
my $format_host_port = shell_function( $post, 'format_host_port' );
ok( defined($format_uri_host), 'post-install URI host helper is present' );
ok( defined($format_host_port), 'post-install host-port helper is present' );
my $post_helpers = "$format_uri_host\n$format_host_port";
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '192.0.2.10' ),
'192.0.2.10',
'IPv4 URL hosts remain byte-for-byte unchanged'
);
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '2001:db8::10' ),
'[2001:db8::10]',
'IPv6 URL hosts are bracketed'
);
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '[2001:db8::10]' ),
'[2001:db8::10]',
'an already-bracketed IPv6 URL host is not double-bracketed'
);
is(
run_shell_function( $post_helpers, 'format_host_port "$1" "$2"', '2001:db8::10', '3001' ),
'[2001:db8::10]:3001',
'OpenSSL receives an unambiguous IPv6 host-port endpoint'
);
like( $post, qr{http://\$\{MASTER_HTTP_HOST\}:\$\{HTTPPORT\}\$INSTALLDIR/postscripts/}, 'postscript tree URL uses the formatted master host' );
like( $post, qr{http://\$\{MASTER_HTTP_HOST\}:\$\{HTTPPORT\}\$TFTPDIR/mypostscripts/}, 'node postscript URL uses the formatted master host' );
unlike( $post, qr{http://\$MASTER_IP:}, 'post-install HTTP URLs never append a port to a raw master address' );
unlike( $post, qr/updateflag(?:\.awk)?\s+"\$MASTER"\s/, 'status callbacks do not depend on a possibly unresolved master hostname' );
is(
scalar( () = $post =~ /updateflag(?:\.awk)?\s+"\$MASTER_IP"\s/g ),
6,
'every EL10 status callback uses the facing master address'
);
like( $updateflag, qr/netfamily = index\(xcatdhost, ":"\) \? "inet6" : "inet"/, 'updateflag selects the gawk IPv6 socket namespace for IPv6 literals' );
like( $updateflag, qr{ns = "/" netfamily "/tcp/0/" xcatdhost "/" xcatdport}, 'updateflag constructs the socket path from the selected family' );
like( $updateflag, qr/xcatdhost ~ \/\^\\\[\.\*\\\]\$\//, 'updateflag accepts a bracketed IPv6 host as input' );
done_testing();
@@ -0,0 +1,182 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(make_path);
use File::Spec;
use File::Temp qw(tempdir tempfile);
use FindBin;
use Test::More;
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
my $xcatroot = File::Spec->catfile(
$repo_root,
'xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot'
);
open( my $source_fh, '<', $xcatroot ) or die "Unable to read $xcatroot: $!";
my $source = do { local $/; <$source_fh> };
close($source_fh);
is( system( 'bash', '-n', $xcatroot ), 0, 'EL10 stateless xcatroot passes bash syntax validation' );
my ($helpers) = $source =~ m{\A\#!/bin/bash\n(.*?)^log_label=}ms;
ok( defined($helpers), 'test harness extracts the production helper functions' );
my ( $helper_fh, $helper_path ) = tempfile( SUFFIX => '.sh', UNLINK => 1 );
print {$helper_fh} <<'HEADER';
#!/bin/bash
set -u
ip() {
case "$*" in
"-6 -o addr show dev eth1 scope global")
echo "3: eth1 inet6 2001:db8:2::21/64 scope global"
;;
"-6 route show default dev eth1")
echo "default via fe80::1 dev eth1 metric 1024"
;;
*)
return 1
;;
esac
}
HEADER
print {$helper_fh} $helpers;
print {$helper_fh} <<'DISPATCH';
case "$1" in
endpoint)
shift
xcat_endpoint_host "$@"
;;
is-ipv6)
shift
xcat_is_ipv6_boot "$@"
;;
persist)
shift
persist_ipv6_nm_connection "$@"
;;
*)
exit 64
;;
esac
DISPATCH
close($helper_fh);
sub run_helper {
my @args = @_;
open( my $fh, '-|', 'bash', $helper_path, @args )
or die "Unable to run helper harness: $!";
my $output = do { local $/; <$fh> };
close($fh);
return ( $output // '', $? >> 8 );
}
my @endpoint_cases = (
[ '192.0.2.10:3001', '192.0.2.10', 'IPv4 endpoint keeps the legacy host value' ],
[ 'head.example.test:3001', 'head.example.test', 'hostname endpoint keeps the legacy host value' ],
[ '[2001:db8::10]:3001', '2001:db8::10', 'bracketed IPv6 endpoint yields the raw server address' ],
[ '[2001:db8::10]', '2001:db8::10', 'bracketed IPv6 host without a port is accepted' ],
[ '2001:db8::10', '2001:db8::10', 'unbracketed IPv6 host is not truncated at a colon' ],
);
foreach my $case (@endpoint_cases) {
my ( $output, $rc ) = run_helper( 'endpoint', $case->[0] );
is( $rc, 0, "$case->[2] succeeds" );
chomp($output);
is( $output, $case->[1], $case->[2] );
}
for my $iparg ( 'dhcp6', 'eth0:dhcp6', 'eth0:dhcp6:1500' ) {
my ( undef, $rc ) = run_helper( 'is-ipv6', $iparg, 'eth0' );
is( $rc, 0, "ip=$iparg is recognized as an IPv6 boot" );
}
my ( undef, $ipv4_rc ) = run_helper( 'is-ipv6', 'dhcp', '' );
isnt( $ipv4_rc, 0, 'the legacy ip=dhcp argument is not treated as IPv6' );
my $tmpdir = tempdir( CLEANUP => 1 );
my $runtime_connections = File::Spec->catdir( $tmpdir, 'runtime-connections' );
my $copied_root = File::Spec->catdir( $tmpdir, 'copied-root' );
make_path($runtime_connections);
my $runtime_profile = File::Spec->catfile( $runtime_connections, 'initrd.nmconnection' );
open( my $profile_fh, '>', $runtime_profile ) or die "Unable to write $runtime_profile: $!";
print {$profile_fh} "[connection]\nid=initrd\n[ipv6]\nmethod=dhcp\n";
close($profile_fh);
my ( undef, $copy_rc ) = run_helper(
'persist', $copied_root, 'eth0', '02:00:00:00:00:10', $runtime_connections
);
is( $copy_rc, 0, 'runtime NetworkManager profile persistence succeeds' );
my $copied_profile = File::Spec->catfile(
$copied_root, 'etc', 'NetworkManager', 'system-connections', 'initrd.nmconnection'
);
ok( -f $copied_profile, 'the initrd NetworkManager profile is copied into the stateless root' );
is(
( stat($copied_profile) )[2] & oct('07777'),
oct('0600'),
'the persisted NetworkManager profile has private permissions'
);
my $fallback_root = File::Spec->catdir( $tmpdir, 'fallback-root' );
my $empty_source = File::Spec->catdir( $tmpdir, 'empty-connections' );
make_path($empty_source);
my ( undef, $fallback_rc ) = run_helper(
'persist', $fallback_root, 'eth1', '02:00:00:00:00:11', $empty_source
);
is( $fallback_rc, 0, 'IPv6 NetworkManager fallback profile generation succeeds' );
my $fallback_profile = File::Spec->catfile(
$fallback_root, 'etc', 'NetworkManager', 'system-connections', 'xcat-eth1.nmconnection'
);
open( my $fallback_fh, '<', $fallback_profile ) or die "Unable to read $fallback_profile: $!";
my $fallback = do { local $/; <$fallback_fh> };
close($fallback_fh);
like( $fallback, qr/^interface-name=eth1$/m, 'fallback profile binds to the boot interface' );
like( $fallback, qr/^mac-address=02:00:00:00:00:11$/m, 'fallback profile binds to the boot MAC' );
like( $fallback, qr/^\[ipv4\]\nmethod=disabled$/m, 'fallback profile does not enable IPv4' );
like( $fallback, qr/^\[ipv6\]\nmethod=manual$/m, 'fallback profile keeps the static IPv6 handoff after pivot' );
like( $fallback, qr/^address1=2001:db8:2::21\/64$/m, 'fallback profile persists the live IPv6 address and prefix' );
like( $fallback, qr/^gateway=fe80::1$/m, 'fallback profile persists the live IPv6 default gateway' );
unlike( $fallback, qr/^method=dhcp$/m, 'fallback profile does not reintroduce DHCPv6 identity drift' );
is(
( stat($fallback_profile) )[2] & oct('07777'),
oct('0600'),
'fallback NetworkManager profile has private permissions'
);
like(
$source,
qr/^MASTER="\$\(xcat_endpoint_host "\$XCATMASTER"\)"$/m,
'the runtime derives logger and updateflag host from the endpoint parser'
);
like(
$source,
qr{/tmp/updateflag "\$MASTER" "\$XCATIPORT" "installstatus netbooting"},
'updateflag receives the raw server host and the independent install port'
);
like(
$source,
qr/SYSLOGHOST=\(-n "\$MASTER"\)/,
'remote logger receives the raw server host as one argument'
);
like(
$source,
qr/curl --fail --output "\$FILENAME" -- "\$imgurl"/,
'curl receives the bracketed IPv6 URL and output filename as quoted arguments'
);
unlike(
$source,
qr/DHCPV6C=yes/,
'the EL10 stateless pivot does not create a competing DHCPv6 ifcfg profile'
);
like(
$source,
qr/rm -f "\$NEWROOT\/etc\/sysconfig\/network-scripts\/ifcfg-\$ETHX"/,
'the IPv6 path removes a stale legacy ifcfg profile'
);
like(
$source,
qr/echo "BOOTPROTO=dhcp" >> "\$NEWROOT\/etc\/sysconfig\/network-scripts\/ifcfg-\$ETHX"/,
'the existing IPv4 DHCP fallback remains intact'
);
done_testing();
+303
View File
@@ -0,0 +1,303 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use Cwd qw(getcwd);
use FindBin;
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More;
BEGIN {
package xCAT::Scope;
$INC{'xCAT/Scope.pm'} = __FILE__;
package xCAT::Utils;
sub parseMacTabEntry {
my ($class, $macstring) = @_;
my ($mac) = split(/\|/, $macstring || '');
$mac =~ s/!.*// if defined($mac);
return $mac;
}
$INC{'xCAT/Utils.pm'} = __FILE__;
package xCAT::TableUtils;
our $httpport = 8080;
sub getTftpDir { return '/tftpboot'; }
sub get_site_attribute {
my ($class, $attribute) = @_;
return $httpport if $attribute eq 'httpport';
return;
}
$INC{'xCAT/TableUtils.pm'} = __FILE__;
package xCAT::ServiceNodeUtils;
$INC{'xCAT/ServiceNodeUtils.pm'} = __FILE__;
package xCAT::NetworkUtils;
our %addresses = (
nodev4 => { 4 => '192.0.2.50' },
nodev6 => { 6 => '2001:db8:1::50' },
nodedual => { 4 => '192.0.2.60', 6 => '2001:db8:1::60' },
'boot4.example.test' => { 4 => '192.0.2.10' },
'boot6.example.test' => { 6 => '2001:db8::10' },
);
our @legacy_facing_calls;
our @family_facing_calls;
sub getipaddr {
my $host = shift;
$host = shift if defined($host) && $host eq __PACKAGE__;
my %opts = @_;
my $entry = $addresses{$host} || {};
return $entry->{6} if $opts{OnlyV6};
return $entry->{4} if $opts{OnlyV4};
return $entry->{4} || $entry->{6};
}
sub node_address_family {
my $node = shift;
$node = shift if defined($node) && $node eq __PACKAGE__;
return 4 if getipaddr($node, OnlyV4 => 1);
return 6 if getipaddr($node, OnlyV6 => 1);
return;
}
sub my_ip_facing {
my $node = shift;
$node = shift if defined($node) && $node eq __PACKAGE__;
push @legacy_facing_calls, $node;
return (0, '192.0.2.1');
}
sub my_ip_facing_family {
my $node = shift;
$node = shift if defined($node) && $node eq __PACKAGE__;
my $family = shift;
push @family_facing_calls, [$node, $family];
return (0, '2001:db8::1');
}
sub format_uri_host {
my $host = shift;
$host = shift if defined($host) && $host eq __PACKAGE__;
return "[$host]" if defined($host) && $host =~ /:/;
return $host;
}
sub format_host_port {
my $host = shift;
$host = shift if defined($host) && $host eq __PACKAGE__;
my $port = shift;
my $formatted = format_uri_host($host);
return "$formatted:$port";
}
sub isIpaddr {
my $ip = shift;
$ip = shift if defined($ip) && $ip eq __PACKAGE__;
return defined($ip) && $ip =~ /^\d{1,3}(?:\.\d{1,3}){3}$/;
}
$INC{'xCAT/NetworkUtils.pm'} = __FILE__;
package xCAT::MsgUtils;
$INC{'xCAT/MsgUtils.pm'} = __FILE__;
package xCAT::Table;
sub new { return; }
$INC{'xCAT/Table.pm'} = __FILE__;
package xCAT::Usage;
$INC{'xCAT/Usage.pm'} = __FILE__;
}
my $source = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/grub2.pm";
require $source;
is(
xCAT_plugin::grub2::grub2_root_spec('http', '192.0.2.1', 80),
'http,192.0.2.1',
'default-port IPv4 HTTP root remains byte-for-byte unchanged'
);
is(
xCAT_plugin::grub2::grub2_root_spec('http', '192.0.2.1', 8080),
'http,192.0.2.1:8080',
'custom-port IPv4 HTTP root remains byte-for-byte unchanged'
);
is(
xCAT_plugin::grub2::grub2_root_spec('http', '2001:db8::1', 80),
'http,[2001:db8::1]',
'default-port IPv6 HTTP root brackets the address'
);
is(
xCAT_plugin::grub2::grub2_root_spec('http', '2001:db8::1', 8080),
'http,[2001:db8::1]:8080',
'custom-port IPv6 HTTP root brackets the address before the port'
);
@xCAT::NetworkUtils::legacy_facing_calls = ();
@xCAT::NetworkUtils::family_facing_calls = ();
is_deeply(
[ xCAT_plugin::grub2::grub2_server_for_node('nodev6', '<xcatmaster>') ],
[ 0, '2001:db8::1' ],
'IPv6-only node selects the IPv6-facing xCAT server'
);
is_deeply(
$xCAT::NetworkUtils::family_facing_calls[0],
[ 'nodev6', 6 ],
'IPv6-only server selection uses the shared family helper'
);
is(
scalar(@xCAT::NetworkUtils::legacy_facing_calls),
0,
'IPv6-only server selection does not use the legacy IPv4 helper'
);
@xCAT::NetworkUtils::legacy_facing_calls = ();
@xCAT::NetworkUtils::family_facing_calls = ();
is_deeply(
[ xCAT_plugin::grub2::grub2_server_for_node('nodev4', '<xcatmaster>') ],
[ 0, '192.0.2.1' ],
'IPv4 node retains legacy facing-server selection'
);
is_deeply(
\@xCAT::NetworkUtils::legacy_facing_calls,
['nodev4'],
'IPv4 node still invokes the legacy helper'
);
is(
scalar(@xCAT::NetworkUtils::family_facing_calls),
0,
'IPv4 node does not invoke the new family helper'
);
@xCAT::NetworkUtils::legacy_facing_calls = ();
@xCAT::NetworkUtils::family_facing_calls = ();
is_deeply(
[ xCAT_plugin::grub2::grub2_server_for_node('nodedual', '<xcatmaster>') ],
[ 0, '192.0.2.1' ],
'dual-stack node retains the legacy IPv4 server preference'
);
is(
scalar(@xCAT::NetworkUtils::family_facing_calls),
0,
'dual-stack node does not switch existing provisioning to IPv6'
);
{
no warnings 'redefine';
local *xCAT::NetworkUtils::my_ip_facing = sub {
return (2, 'node is in an undefined subnet');
};
is_deeply(
[ xCAT_plugin::grub2::grub2_server_for_node('nodev4', '<xcatmaster>') ],
[ 1, 'node is in an undefined subnet' ],
'legacy IPv4 facing-server failures retain the setstate error code'
);
}
is_deeply(
[ xCAT_plugin::grub2::grub2_server_for_node('nodev6', 'boot6.example.test') ],
[ 0, '2001:db8::10' ],
'IPv6-only node resolves an explicit boot server in IPv6'
);
sub exercise_setstate {
my ($node, $mac) = @_;
my $tftpdir = tempdir(CLEANUP => 1);
my $bootloader_root = "$tftpdir/boot/grub2";
make_path($bootloader_root);
open(my $binary, '>', "$bootloader_root/grub2.x86_64")
or die "Unable to create test GRUB binary: $!";
print {$binary} "test grub binary\n";
close($binary);
my %bootparams = (
$node => [
{
kernel => '/install/rhels10/x86_64/vmlinuz',
initrd => '/install/rhels10/x86_64/initrd.img',
kcmdline => 'inst.ks=http://example.test/autoinst/node',
},
],
);
my %chain = ($node => [{ currstate => 'install' }]);
my %macs = ($node => [{ mac => $mac }]);
my %noderes = (
$node => [
{
netboot => 'grub2-http',
tftpserver => '<xcatmaster>',
},
],
);
my $oldcwd = getcwd();
local $::XCATSITEVALS{xcatdebugmode} = '0';
my @result = xCAT_plugin::grub2::setstate(
$node,
\%bootparams,
\%chain,
\%macs,
$tftpdir,
\%noderes,
undef,
'x86_64',
'rhels10',
);
chdir($oldcwd) or die "Unable to restore test working directory: $!";
open(my $config, '<', "$bootloader_root/$node")
or die "Unable to read generated GRUB config: $!";
local $/;
my $content = <$config>;
close($config);
return ($tftpdir, $bootloader_root, $content, @result);
}
$xCAT::TableUtils::httpport = 8080;
@xCAT::NetworkUtils::legacy_facing_calls = ();
@xCAT::NetworkUtils::family_facing_calls = ();
my ($v6_tftpdir, $v6_root, $v6_config, $v6_rc, $v6_message) =
exercise_setstate('nodev6', '02:00:00:00:00:61');
is($v6_rc, 0, "IPv6-only GRUB config generation succeeds: $v6_message");
like(
$v6_config,
qr/^ set root=http,\[2001:db8::1\]:8080$/m,
'generated IPv6 GRUB HTTP root uses a bracketed authority'
);
ok(
-e "$v6_root/grub.cfg-01-02-00-00-00-00-61",
'IPv6-only node retains its MAC-specific GRUB config alias'
);
my @v6_ip_aliases = grep { $_ !~ /grub\.cfg-01-02-00-00-00-00-61$/ } glob("$v6_root/grub.cfg-*");
is_deeply(
\@v6_ip_aliases,
[],
'IPv6-only node does not create an IPv4-hex GRUB config alias'
);
@xCAT::NetworkUtils::legacy_facing_calls = ();
@xCAT::NetworkUtils::family_facing_calls = ();
my ($v4_tftpdir, $v4_root, $v4_config, $v4_rc, $v4_message) =
exercise_setstate('nodev4', '02:00:00:00:00:41');
is($v4_rc, 0, "IPv4 GRUB config generation succeeds: $v4_message");
like(
$v4_config,
qr/^ set root=http,192\.0\.2\.1:8080$/m,
'generated IPv4 GRUB HTTP root remains byte-for-byte unchanged'
);
ok(
-e "$v4_root/grub.cfg-C0000232",
'IPv4 node retains its IPv4-hex GRUB config alias'
);
ok(
-e "$v4_root/grub.cfg-01-02-00-00-00-00-41",
'IPv4 node retains its MAC-specific GRUB config alias'
);
done_testing();
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $source = File::Spec->catfile(
$FindBin::Bin, '..', '..',
'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh'
);
open(my $source_fh, '<', $source) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
is(system('sh', '-n', $source), 0, 'initrd rsyslog launcher has valid shell syntax');
sub shell_function {
my ($name) = @_;
my ($definition) = $content =~ /(^\Q$name\E\(\)\s*\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($definition);
return $definition;
}
my $format = shell_function('format_syslog_server');
my $configure = shell_function('rsyslog_config');
my ($template_fh, $template_path) = tempfile();
print {$template_fh} "# base config\n";
close($template_fh);
sub render_config {
my ($server) = @_;
open(
my $pipe, '-|', 'sh', '-c',
"$format\n$configure\nrsyslog_config \"\$1\" \"\$2\" '*.*'",
'sh', $server, $template_path
) or die "Unable to run initrd rsyslog helper: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is($?, 0, "rsyslog configuration renders for $server");
return $output;
}
like(
render_config('192.0.2.10'),
qr/^\*\.\* \@192\.0\.2\.10$/m,
'IPv4 initrd forwarding target remains unchanged'
);
like(
render_config('logs.example.test'),
qr/^\*\.\* \@logs\.example\.test$/m,
'hostname initrd forwarding target remains unchanged'
);
like(
render_config('2001:db8::10'),
qr/^\*\.\* \@\[2001:db8::10\]$/m,
'IPv6 initrd forwarding target is bracketed'
);
like(
render_config('[2001:db8::10]'),
qr/^\*\.\* \@\[2001:db8::10\]$/m,
'already-bracketed IPv6 initrd target is not double-bracketed'
);
done_testing();
@@ -0,0 +1,91 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
use xCAT::InstUtils;
{
package InstUtilsNodeResTable;
sub new { return bless {}, shift; }
sub getNodesAttribs {
my ($self, $nodes) = @_;
return {
v6fallback => [ {} ],
v6explicit => [ { xcatmaster => 'masterdual.example.test' } ],
v6explicitbad => [ { xcatmaster => 'master4only.example.test' } ],
v6facingbad => [ {} ],
v4fallback => [ {} ],
};
}
sub close { return; }
}
my %addresses = (
v6fallback => { OnlyV6 => '2001:db8:1::20' },
v6explicit => { OnlyV6 => '2001:db8:1::21' },
v6explicitbad => { OnlyV6 => '2001:db8:1::22' },
v6facingbad => { OnlyV6 => '2001:db8:1::23' },
v4fallback => { OnlyV4 => '192.0.2.20' },
'masterdual.example.test' => {
OnlyV4 => '192.0.2.1',
OnlyV6 => '2001:db8:1::1',
},
'master4only.example.test' => { OnlyV4 => '192.0.2.2' },
);
my @facing_calls;
{
no warnings 'redefine';
local *xCAT::Table::new = sub { return InstUtilsNodeResTable->new(); };
local *xCAT::NetworkUtils::getipaddr = sub {
my $host = shift;
$host = shift if defined($host) && $host eq 'xCAT::NetworkUtils';
my %options = @_;
my $entry = $addresses{$host} || {};
return $entry->{OnlyV6} if $options{OnlyV6};
return $entry->{OnlyV4} if $options{OnlyV4};
return $entry->{OnlyV4} || $entry->{OnlyV6};
};
local *xCAT::NetworkUtils::my_ip_facing = sub {
my $node = pop @_;
push @facing_calls, [$node, 4];
return (0, '192.0.2.1');
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my ($class, $node, $family) = @_;
push @facing_calls, [$node, $family];
return (1, 'no IPv6-facing server') if $node eq 'v6facingbad';
return (0, '2001:db8:1::1');
};
my $servers = xCAT::InstUtils->get_server_nodes(
sub { }, [qw(v6fallback v6explicit v6explicitbad v6facingbad v4fallback)]
);
is_deeply(
$servers->{'2001:db8:1::1'},
[qw(v6fallback v6explicit)],
'IPv6-only nodes select an IPv6-facing or explicitly configured master'
);
is_deeply(
$servers->{'192.0.2.1'},
[qw(v4fallback)],
'IPv4 nodes retain the legacy IPv4-facing master'
);
is_deeply(
$servers->{''},
[qw(v6explicitbad v6facingbad)],
'unresolved explicit and facing masters remain in the caller error bucket'
);
is_deeply(
\@facing_calls,
[ [v6fallback => 6], [v6facingbad => 6], [v4fallback => 4] ],
'fallback master discovery follows each node address family'
);
}
done_testing();
+131
View File
@@ -0,0 +1,131 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use lib "$FindBin::Bin/../../xCAT-server/lib";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../perl-xCAT";
use Socket ();
use Test::More;
$ENV{XCATCFG} ||= 'SQLite:/tmp';
my $source_hosts_plugin =
"$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/hosts.pm";
if (-f $source_hosts_plugin) {
require $source_hosts_plugin;
} else {
require xCAT_plugin::hosts;
}
ok(
xCAT_plugin::hosts::_host_entry_matches(
'192.0.2.10 node01 node01.example.com',
'node01',
'192.0.2.10'
),
'host-entry matching preserves IPv4 behavior'
);
ok(
!xCAT_plugin::hosts::_host_entry_matches('', 'node01', '192.0.2.10'),
'blank host entry does not match'
);
ok(
xCAT_plugin::hosts::_host_entry_matches(
'010.1.1.1 node01 node01.example.com',
'node01',
'192.0.2.10'
),
'legacy numeric-quad entries remain replaceable and deletable by node'
);
my $has_core_ipv6_parser = defined(&Socket::inet_pton)
&& eval { defined(Socket::inet_pton(Socket::AF_INET6(), '::1')) };
my $has_ipv6_parser = $has_core_ipv6_parser
|| eval { require Socket6; 1 };
SKIP: {
skip 'No IPv6 literal parser is available', 8 unless $has_ipv6_parser;
ok(
xCAT_plugin::hosts::_host_entry_matches(
'2001:db8::10 node01 node01.example.com',
'node01',
'2001:db8::10'
),
'IPv6 host entry matches its address and node'
);
ok(
xCAT_plugin::hosts::_host_entry_matches(
'2001:0db8:0000:0000:0000:0000:0000:0010 old-name',
'node01',
'2001:db8::10'
),
'equivalent expanded and compressed IPv6 addresses are deduplicated'
);
ok(
xCAT_plugin::hosts::_host_entry_matches(
'2001:db8::20 node01.example.com node01',
'node01',
'2001:db8::10'
),
'same-node IPv6 entry matches after an address change'
);
ok(
!xCAT_plugin::hosts::_host_entry_matches(
'2001:db8::20 node010 node010.example.com',
'node01',
'2001:db8::10'
),
'similarly prefixed IPv6 node does not match'
);
ok(
!xCAT_plugin::hosts::_host_entry_matches(
'2001:db8::20 node010 node01',
'node01',
'2001:db8::10'
),
'an alias alone does not identify a host entry for replacement'
);
ok(
!xCAT_plugin::hosts::_host_entry_matches(
'not-an-address node01 node01.example.com',
'node01',
'2001:db8::10'
),
'a hostname-like first field is not treated as a host address'
);
my @addnode_args;
{
no warnings qw(once redefine);
local *xCAT_plugin::hosts::getIPdomain = sub {
return ('example.com', 'v6net');
};
local *xCAT_plugin::hosts::addnode = sub {
@addnode_args = @_;
return;
};
xCAT_plugin::hosts::addotherinterfaces(
undef,
'node01',
'node01-v6!2001:db8::10',
'example.com'
);
}
is(
$addnode_args[1],
'node01-v6',
'otherinterfaces parses an IPv6 interface hostname with !'
);
is(
$addnode_args[2],
'2001:db8::10',
'otherinterfaces passes the IPv6 literal to addnode'
);
}
done_testing();
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
use xCAT::Utils;
is(
xCAT::Utils->lookupNetboot('alma10.1', 'x86_64', 'Linux'),
'xnba,pxe,grub2,grub2-tftp,grub2-http',
'x86_64 Linux exposes GRUB TFTP and HTTP transport variants'
);
is(
xCAT::Utils->lookupNetboot('alma10.1', 'aarch64', 'Linux'),
'grub2',
'other architecture choices remain unchanged'
);
done_testing();
@@ -0,0 +1,636 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use FindBin;
use lib "$FindBin::Bin/../../xCAT-server/lib";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../perl-xCAT";
use Socket ();
use Test::More;
use xCAT::NetworkUtils;
ok(
xCAT::NetworkUtils->isValidIp('192.0.2.10'),
'dual-stack validator accepts IPv4'
);
ok(
!xCAT::NetworkUtils->isValidIp('192.0.2.999'),
'dual-stack validator rejects invalid IPv4'
);
ok(
!xCAT::NetworkUtils->isValidIp('192.0.2.010'),
'dual-stack validator preserves strict IPv4 octet syntax'
);
ok(
!xCAT::NetworkUtils->isIpaddr('2001:db8::10'),
'legacy IPv4-only validator remains IPv4-only'
);
my $has_core_ipv6_parser = defined(&Socket::inet_pton)
&& eval { defined(Socket::inet_pton(Socket::AF_INET6(), '::1')) };
my $has_socket6 = eval { require Socket6; 1 };
my $has_ipv6_parser = $has_core_ipv6_parser || $has_socket6;
my $has_core_resolver = defined(&Socket::getaddrinfo)
&& defined(&Socket::getnameinfo)
&& $has_core_ipv6_parser;
SKIP: {
skip 'No IPv6 literal parser is available', 15 unless $has_ipv6_parser;
foreach my $address (
'2001:db8::10',
'2001:0DB8:0000:0000:0000:0000:0000:0010',
'::',
'::1',
'::ffff:192.0.2.10'
)
{
ok(
xCAT::NetworkUtils->isValidIp($address),
"accepts IPv6 literal $address"
);
}
foreach my $address (
'2001:db8::g',
'2001:db8::1::2',
'2001:db8::10/64',
'fe80::1%eth0',
'[2001:db8::10]',
" 2001:db8::10",
"2001:db8::10\n",
'node01.example.com'
)
{
ok(
!xCAT::NetworkUtils->isValidIp($address),
"rejects non-literal address $address"
);
}
ok(
xCAT::NetworkUtils->isSameIPAddress(
'2001:0db8:0000:0000:0000:0000:0000:0010',
'2001:db8::10'
),
'compares equivalent IPv6 spellings by packed address'
);
ok(
!xCAT::NetworkUtils->isSameIPAddress('2001:db8::10', '2001:db8::11'),
'distinguishes different IPv6 addresses'
);
}
is(
xCAT::NetworkUtils->getIPv6PrefixLength('2001:db8:7309::/64'),
64,
'extracts an IPv6 prefix from CIDR notation'
);
is(
xCAT::NetworkUtils->getIPv6PrefixLength('2001:db8:7309::', '/64'),
64,
'accepts a separate numeric IPv6 prefix'
);
ok(
!defined(xCAT::NetworkUtils->getIPv6PrefixLength('2001:db8::', 129)),
'rejects an out-of-range IPv6 prefix'
);
SKIP: {
skip 'No IPv6 literal parser is available', 6 unless $has_ipv6_parser;
is(
xCAT::NetworkUtils->getIPv6ReverseZone('2001:db8:7309::/64'),
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'formats an IPv6 reverse zone from packed address bytes'
);
is(
xCAT::NetworkUtils->getIPv6ReverseZone('2001:db8:7309::', 64),
'0.0.0.0.9.0.3.7.8.b.d.0.1.0.0.2.ip6.arpa.',
'formats a reverse zone with a separate prefix'
);
is(
xCAT::NetworkUtils->getIPv6ReverseZone('::/0'),
'ip6.arpa.',
'formats the IPv6 root reverse zone'
);
is(
xCAT::NetworkUtils->getIPv6ReverseName('::1'),
join('.', reverse(split(//, ('0' x 31) . '1'))) . '.ip6.arpa.',
'formats a complete IPv6 PTR owner name'
);
is(
xCAT::NetworkUtils->getIPv6ReverseName('::ffff:192.0.2.10'),
join('.', reverse(split(//, '00000000000000000000ffffc000020a')))
. '.ip6.arpa.',
'formats an IPv4-mapped IPv6 PTR owner name'
);
ok(
!defined(xCAT::NetworkUtils->getIPv6ReverseZone('2001:db8::/63')),
'rejects a non-nibble-aligned reverse zone'
);
}
{
no warnings 'redefine';
my %addresses = (
nodev4 => { 4 => '192.0.2.10' },
nodev6 => { 6 => '2001:db8::10' },
nodedual => { 4 => '192.0.2.20', 6 => '2001:db8::20' },
server6 => { 6 => '2001:db8::53' },
);
local *xCAT::NetworkUtils::getipaddr = sub {
my $host = shift;
$host = shift if defined($host) && $host eq 'xCAT::NetworkUtils';
my %options = @_;
return $addresses{$host}{4} if $options{OnlyV4};
return $addresses{$host}{6} if $options{OnlyV6};
return;
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
return (0, '2001:db8::1');
};
is(xCAT::NetworkUtils->node_address_family('nodev4'), 4, 'detects an IPv4 node');
is(xCAT::NetworkUtils->node_address_family('nodev6'), 6, 'detects an IPv6-only node');
is(xCAT::NetworkUtils->node_address_family('nodedual'), 4, 'preserves IPv4 preference for a dual-stack node');
ok(xCAT::NetworkUtils->node_is_ipv6_only('nodev6'), 'identifies an IPv6-only node');
ok(!xCAT::NetworkUtils->node_is_ipv6_only('nodedual'), 'does not classify a dual-stack node as IPv6-only');
is(
xCAT::NetworkUtils->ipv6_server_for_node('nodev6', 'server6'),
'2001:db8::53',
'resolves an explicit server in the IPv6 family'
);
is(
xCAT::NetworkUtils->ipv6_server_for_node('nodev6', '2001:db8::54'),
'2001:db8::54',
'preserves a valid IPv6 server literal without resolver lookup'
);
is(
xCAT::NetworkUtils->ipv6_server_for_node('nodev6', '<xcatmaster>'),
'2001:db8::1',
'selects the IPv6-facing address for the xCAT master token'
);
}
is(
xCAT::NetworkUtils->format_uri_host('192.0.2.10'),
'192.0.2.10',
'URI host formatting preserves IPv4'
);
is(
xCAT::NetworkUtils->format_uri_host('node01.example.com'),
'node01.example.com',
'URI host formatting preserves hostnames'
);
is(
xCAT::NetworkUtils->format_uri_host('_service.node01.example.com'),
'_service.node01.example.com',
'URI host formatting preserves xCAT-compatible underscore labels'
);
foreach my $host (
'bad\\host',
'foo%ZZ',
'node..example.com',
'-node.example.com',
'192.0.2.999'
)
{
ok(
!defined(xCAT::NetworkUtils->format_uri_host($host)),
"URI host formatting rejects malformed host $host"
);
}
is(
xCAT::NetworkUtils->format_host_port('192.0.2.10', 3001),
'192.0.2.10:3001',
'host-port formatting preserves the IPv4 endpoint form'
);
{
local %::hostiphash;
is(
xCAT::NetworkUtils->getipaddr('192.0.2.10', OnlyV4 => 1),
'192.0.2.10',
'OnlyV4 preserves an IPv4 literal'
);
ok(
!exists($::hostiphash{'192.0.2.10'}{hostip}),
'an OnlyV4 lookup does not populate the legacy cache'
);
is(
xCAT::NetworkUtils->getipaddr('192.0.2.10'),
'192.0.2.10',
'legacy unrestricted lookup still returns the same IPv4 literal'
);
}
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('192.0.2.10:3001') ],
[ '192.0.2.10', '3001' ],
'parses an IPv4 endpoint'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('node01.example.com', 3002) ],
[ 'node01.example.com', 3002 ],
'applies a default port to a hostname'
);
ok(
!defined(xCAT::NetworkUtils->format_host_port('192.0.2.10', 70000)),
'rejects an out-of-range port'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('node01.example.com:70000') ],
[],
'rejects an endpoint with an out-of-range port'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('bad\\host:3001') ],
[],
'rejects an endpoint with a malformed hostname'
);
SKIP: {
skip 'No IPv6 literal parser is available', 7 unless $has_ipv6_parser;
is(
xCAT::NetworkUtils->format_uri_host('2001:db8::10'),
'[2001:db8::10]',
'brackets an IPv6 URI host'
);
is(
xCAT::NetworkUtils->format_uri_host('[2001:db8::10]'),
'[2001:db8::10]',
'does not double-bracket an IPv6 URI host'
);
is(
xCAT::NetworkUtils->format_host_port('2001:db8::10', 3001),
'[2001:db8::10]:3001',
'formats a bracketed IPv6 endpoint'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('[2001:db8::10]:3001') ],
[ '2001:db8::10', '3001' ],
'parses a bracketed IPv6 endpoint'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('2001:db8::10', 3002) ],
[ '2001:db8::10', 3002 ],
'treats an unbracketed IPv6 literal as a host only'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('[2001:db8::10]') ],
[ '2001:db8::10', undef ],
'parses a bracketed IPv6 host without a port'
);
is_deeply(
[ xCAT::NetworkUtils->parse_host_port('[2001:db8::10]:70000') ],
[],
'rejects an IPv6 endpoint with an out-of-range port'
);
}
SKIP: {
skip 'No IPv6 literal parser is available', 4 unless $has_ipv6_parser;
ok(
xCAT::NetworkUtils::isInSameSubnet(
'2001:db8:1::10', '2001:db8:1::', 64, 1
),
'IPv6 subnet matching accepts addresses in the same prefix'
);
ok(
!xCAT::NetworkUtils::isInSameSubnet(
'2001:db8:2::10', '2001:db8:1::', 64, 1
),
'IPv6 subnet matching rejects addresses outside the prefix'
);
ok(
xCAT::NetworkUtils->ishostinsubnet(
'2001:db8:1::10', '', '2001:db8:1::/64'
),
'CIDR IPv6 membership works without Net::IP'
);
ok(
!xCAT::NetworkUtils->ishostinsubnet(
'2001:db8:2::10', '', '2001:db8:1::/64'
),
'CIDR IPv6 non-membership works without Net::IP'
);
}
{
local %::hostiphash = (
'cached.example.com' => {
hostip => '2001:db8::50',
hostip_v4 => '192.0.2.50',
},
);
is(
xCAT::NetworkUtils->getipaddr('cached.example.com', OnlyV4 => 1),
'192.0.2.50',
'OnlyV4 reads only the IPv4-specific cache entry'
);
}
{
local %::hostiphash = (
'cached-v4.example' => { hostip => '192.0.2.50' },
);
is(
xCAT::NetworkUtils->getipaddr('cached-v4.example', OnlyV4 => 1),
'192.0.2.50',
'OnlyV4 preserves reuse of a valid legacy IPv4 cache entry'
);
is(
$::hostiphash{'cached-v4.example'}{hostip_v4},
'192.0.2.50',
'legacy IPv4 cache reuse seeds the family-specific cache'
);
}
SKIP: {
skip 'Socket6 is required for family-specific resolution', 6 unless $has_socket6;
local %::hostiphash;
is(
xCAT::NetworkUtils->getipaddr('2001:db8::10', OnlyV6 => 1),
'2001:db8::10',
'resolves an IPv6 literal with OnlyV6'
);
ok(
!defined(xCAT::NetworkUtils->getipaddr('2001:db8::10', OnlyV4 => 1)),
'an OnlyV6 cache entry cannot satisfy an OnlyV4 lookup'
);
is(
$::hostiphash{'2001:db8::10'}{hostip_v6},
'2001:db8::10',
'stores an OnlyV6 result in the IPv6-specific cache'
);
ok(
!exists($::hostiphash{'2001:db8::10'}{hostip}),
'an OnlyV6 lookup does not contaminate the legacy cache'
);
isa_ok(
xCAT::NetworkUtils->getipaddr(
'2001:db8::10', OnlyV6 => 1, GetNumber => 1
),
'Math::BigInt',
'OnlyV6 numeric result'
);
ok(
!defined(
xCAT::NetworkUtils->getipaddr(
'2001:db8::10', OnlyV4 => 1, GetNumber => 1
)
),
'an OnlyV6 numeric cache entry cannot satisfy an OnlyV4 lookup'
);
}
SKIP: {
skip 'Socket6 is required for multi-address cache tests', 4 unless $has_socket6;
no warnings 'redefine';
local *Socket6::getaddrinfo = sub {
return (
Socket::AF_INET(), Socket::SOCK_STREAM(), 6, 'first', '',
Socket::AF_INET(), Socket::SOCK_STREAM(), 6, 'second', '',
);
};
local *Socket6::getnameinfo = sub {
return $_[0] eq 'first' ? '192.0.2.10' : '192.0.2.20';
};
local %::hostiphash;
is_deeply(
[
xCAT::NetworkUtils->getipaddr(
'multi.socket6.example', GetAllAddresses => 1
)
],
[ '192.0.2.10', '192.0.2.20' ],
'Socket6 returns all addresses in resolver order'
);
is(
xCAT::NetworkUtils->getipaddr(
'multi.socket6.example', OnlyV4 => 1
),
'192.0.2.10',
'Socket6 family cache preserves the first address'
);
my @numbers = xCAT::NetworkUtils->getipaddr(
'multi-number.socket6.example',
GetAllAddresses => 1,
GetNumber => 1
);
is(scalar(@numbers), 2, 'Socket6 returns all numeric addresses');
is(
xCAT::NetworkUtils->getipaddr(
'multi-number.socket6.example', OnlyV4 => 1, GetNumber => 1
)->bcmp($numbers[0]),
0,
'Socket6 numeric family cache preserves the first address'
);
}
SKIP: {
skip 'Core Socket IPv6 resolver is unavailable', 2 unless $has_core_resolver;
my $child_code = <<'PERL';
BEGIN {
unshift @INC, sub {
die "Socket6 intentionally disabled\n" if $_[1] eq 'Socket6.pm';
return;
};
}
use xCAT::NetworkUtils;
die "core IPv6 validation failed\n"
unless xCAT::NetworkUtils->isValidIPAddress('2001:db8::10');
my $v6 = xCAT::NetworkUtils->getipaddr('2001:db8::10', OnlyV6 => 1);
die "core IPv6 lookup failed\n" unless defined($v6) && $v6 eq '2001:db8::10';
my $number = xCAT::NetworkUtils->getipaddr(
'2001:db8::10', OnlyV6 => 1, GetNumber => 1
);
die "core numeric lookup failed\n" unless ref($number) eq 'Math::BigInt';
my $v4 = xCAT::NetworkUtils->getipaddr('2001:db8::10', OnlyV4 => 1);
die "core family filter failed\n" if defined($v4);
my @missing = xCAT::NetworkUtils->getipaddr(
'2001:db8::g', OnlyV6 => 1, GetAllAddresses => 1
);
die "core failed lookup returned a phantom address\n" if @missing;
{
no warnings 'redefine';
local *xCAT::NetworkUtils::_local_ip_prefixes = sub {
return ([ '2001:db8::1', 64 ]);
};
my @facing = xCAT::NetworkUtils->my_ip_facing_family('2001:db8::50', 6);
die "core same-subnet selection failed\n"
unless @facing == 2 && $facing[0] == 0 && $facing[1] eq '2001:db8::1';
}
{
no warnings 'redefine';
local *Socket::getaddrinfo = sub {
return (
'',
{ family => Socket::AF_INET(), addr => 'first' },
{ family => Socket::AF_INET(), addr => 'second' },
);
};
local *Socket::getnameinfo = sub {
my $ip = $_[0] eq 'first' ? '192.0.2.10' : '192.0.2.20';
return ('', $ip, 0);
};
local %::hostiphash;
my @all = xCAT::NetworkUtils->getipaddr(
'multi.core.example', GetAllAddresses => 1
);
die "core address ordering failed\n"
unless join(',', @all) eq '192.0.2.10,192.0.2.20';
my $first = xCAT::NetworkUtils->getipaddr(
'multi.core.example', OnlyV4 => 1
);
die "core family cache ordering failed\n"
unless defined($first) && $first eq '192.0.2.10';
my @numbers = xCAT::NetworkUtils->getipaddr(
'multi-number.core.example',
GetAllAddresses => 1,
GetNumber => 1
);
my $first_number = xCAT::NetworkUtils->getipaddr(
'multi-number.core.example', OnlyV4 => 1, GetNumber => 1
);
die "core numeric family cache ordering failed\n"
unless @numbers == 2 && $first_number->bcmp($numbers[0]) == 0;
}
print "core-socket-ok\n";
PERL
open(
my $child,
'-|',
$^X,
"-I$FindBin::Bin/../../xCAT-server/lib",
"-I$FindBin::Bin/../../xCAT-server/lib/perl",
"-I$FindBin::Bin/../../perl-xCAT",
'-e',
$child_code
) or die "Unable to start core Socket resolver test: $!";
my $output = do { local $/; <$child> };
ok(close($child), 'core Socket resolver works when Socket6 cannot load');
is($output, "core-socket-ok\n", 'core Socket fallback preserves family filtering');
}
{
no warnings 'redefine';
local *xCAT::NetworkUtils::_local_ip_prefixes = sub {
return (
[ '192.0.2.1', 24 ],
[ '198.51.100.1', 24 ],
[ '203.0.113.129', 25 ],
);
};
is_deeply(
[ xCAT::NetworkUtils->my_ip_facing_family('192.0.2.80', 4) ],
[ 0, '192.0.2.1' ],
'selects a same-subnet local IPv4 address without changing its form'
);
is(
(xCAT::NetworkUtils->my_ip_facing_family('203.0.113.80', 4))[0],
2,
'reports when no local IPv4 address shares the peer subnet'
);
is_deeply(
[ xCAT::NetworkUtils->my_ip_facing_family('203.0.113.200', 4) ],
[ 0, '203.0.113.129' ],
'handles a non-byte-aligned IPv4 prefix'
);
}
SKIP: {
skip 'An IPv6 resolver is required for IPv6 same-subnet selection', 5
unless $has_socket6 || $has_core_resolver;
no warnings 'redefine';
local *xCAT::NetworkUtils::_local_ip_prefixes = sub {
return (
[ '2001:db8:100::1', 64 ],
[ '2001:db8:100::2', 64 ],
[ '2001:db8:200::1', 64 ],
[ '2001:db8:400:0:8000::1', 65 ],
[ '2001:db8:500::2', 127 ],
);
};
is_deeply(
[ xCAT::NetworkUtils->my_ip_facing_family('2001:db8:100::80', 6) ],
[ 0, '2001:db8:100::1', '2001:db8:100::2' ],
'selects all same-subnet local IPv6 addresses'
);
is(
(xCAT::NetworkUtils->my_ip_facing_family('2001:db8:300::80', 6))[0],
2,
'reports when no local IPv6 address shares the peer subnet'
);
is(
(xCAT::NetworkUtils->my_ip_facing_family('192.0.2.80', 6))[0],
1,
'rejects a peer that cannot resolve in the requested family'
);
is_deeply(
[
xCAT::NetworkUtils->my_ip_facing_family(
'2001:db8:400:0:ffff::80', 6
)
],
[ 0, '2001:db8:400:0:8000::1' ],
'handles a non-byte-aligned IPv6 prefix'
);
is_deeply(
[ xCAT::NetworkUtils->my_ip_facing_family('2001:db8:500::3', 6) ],
[ 0, '2001:db8:500::2' ],
'handles an IPv6 /127 prefix'
);
}
{
package NetworkUtilsIPv6NetworksTable;
sub new { return bless { closed => 0 }, shift; }
sub getAllAttribs {
return (
{ net => '192.0.2.0', mask => '255.255.255.0', gateway => '192.0.2.1' },
{ net => '2001:db8:2::/64', mask => undef, gateway => '2001:db8:2::1' },
{ net => '2001:db8:1::', mask => '/64', gateway => '<xcatmaster>' },
);
}
sub close { $_[0]->{closed} = 1; }
}
{
no warnings 'redefine';
my $table = NetworkUtilsIPv6NetworksTable->new();
local *xCAT::Table::new = sub { return $table; };
local *xCAT::NetworkUtils::getipaddr = sub {
my $candidate = shift;
$candidate = shift if defined($candidate) && $candidate eq 'xCAT::NetworkUtils';
my %opts = @_;
return '2001:db8:1::50' if $candidate eq 'nodev6' && $opts{OnlyV6};
return;
};
is_deeply(
[ xCAT::NetworkUtils->getNodeNetworkCfg6('nodev6') ],
[ '2001:db8:1::50', 'nodev6', '<xcatmaster>', '64' ],
'IPv6 node network lookup returns the address, gateway, and normalized prefix'
);
ok($table->{closed}, 'IPv6 node network lookup closes the networks table');
is_deeply(
[ xCAT::NetworkUtils->getNodeNetworkCfg6('missing') ],
[ undef, 'missing', undef, undef ],
'IPv6 node network lookup reports a missing IPv6 address without inventing configuration'
);
}
done_testing();
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More;
use xCAT::Postage;
my %addresses = (
nodev4 => { OnlyV4 => '192.0.2.20' },
nodev6 => { OnlyV6 => '2001:db8:1::20' },
nodedual => { OnlyV4 => '192.0.2.30', OnlyV6 => '2001:db8:1::30' },
'masterdual.example.test' => { OnlyV4 => '192.0.2.1', OnlyV6 => '2001:db8:1::1' },
);
my @facing_calls;
{
no warnings 'redefine';
local *xCAT::NetworkUtils::getipaddr = sub {
my $host = shift;
$host = shift if defined($host) && $host eq 'xCAT::NetworkUtils';
my %options = @_;
my $entry = $addresses{$host} || {};
return $entry->{OnlyV6} if $options{OnlyV6};
return $entry->{OnlyV4} if $options{OnlyV4};
return $entry->{OnlyV4} || $entry->{OnlyV6};
};
local *xCAT::NetworkUtils::my_ip_facing = sub {
my $node = pop @_;
push @facing_calls, [$node, 4];
return (0, '192.0.2.1');
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my ($class, $node, $family) = @_;
push @facing_calls, [$node, $family];
return (0, '2001:db8:1::1');
};
is_deeply(
[ xCAT::Postage::_facing_addresses_for_node('nodev6') ],
[0, '2001:db8:1::1'],
'IPv6-only postscript generation selects an IPv6-facing master'
);
is_deeply(
[ xCAT::Postage::_facing_addresses_for_node('nodev4') ],
[0, '192.0.2.1'],
'IPv4 postscript generation retains the legacy facing-master path'
);
is(
xCAT::Postage::_resolve_server_for_node(
'nodev6', 'masterdual.example.test'
),
'2001:db8:1::1',
'IPv6-only mypostscript resolves a dual-stack master in the node family'
);
is(
xCAT::Postage::_resolve_server_for_node(
'nodedual', 'masterdual.example.test'
),
'192.0.2.1',
'dual-stack mypostscript preserves IPv4 preference'
);
is_deeply(
\@facing_calls,
[ [nodev6 => 6], [nodev4 => 4] ],
'facing-master discovery records the expected family decisions'
);
}
done_testing();
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Test::More;
sub read_file {
my ($path) = @_;
open(my $fh, '<', $path) or die "Unable to read $path: $!";
my $contents = do { local $/; <$fh> };
close($fh);
return $contents;
}
sub shell_function {
my ($script, $name) = @_;
my ($definition) = $script =~ /(^\Q$name\E\(\)\n\{.*?^\})/ms;
return $definition;
}
sub run_function {
my ($definitions, $invocation, @args) = @_;
open(my $pipe, '-|', 'bash', '-c', "$definitions\n$invocation", 'bash', @args)
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is($?, 0, "$invocation exits successfully");
chomp($output);
return $output;
}
my $postinit_path = "$FindBin::Bin/../../xCAT/postscripts/xcatpostinit1.netboot";
my $installpost_path = "$FindBin::Bin/../../xCAT/postscripts/xcatinstallpost";
my $postinit = read_file($postinit_path);
my $installpost = read_file($installpost_path);
is(system('bash', '-n', $postinit_path), 0, 'stateless post-init script has valid bash syntax');
is(system('bash', '-n', $installpost_path), 0, 'stateful install-post script has valid bash syntax');
my $postinit_endpoint_host = shell_function($postinit, 'xcat_endpoint_host');
ok(defined($postinit_endpoint_host), 'stateless post-init endpoint parser is present');
is(
run_function($postinit_endpoint_host, 'xcat_endpoint_host "$1"', '[2001:db8::1]:3001'),
'2001:db8::1',
'stateless post-init extracts a complete IPv6 host from XCAT'
);
is(
run_function($postinit_endpoint_host, 'xcat_endpoint_host "$1"', '192.0.2.1:3001'),
'192.0.2.1',
'stateless post-init preserves IPv4 endpoint parsing'
);
my $install_endpoint_host = shell_function($installpost, 'xcat_endpoint_host');
my $install_format_host_port = shell_function($installpost, 'format_host_port');
ok(defined($install_endpoint_host), 'stateful postboot endpoint parser is present');
ok(defined($install_format_host_port), 'stateful postboot endpoint formatter is present');
is(
run_function(
"$install_endpoint_host\n$install_format_host_port",
'format_host_port "$1" "$2"',
q{'2001:db8::1'}, 3001
),
'[2001:db8::1]:3001',
'stateful postboot formats an OpenSSL-safe IPv6 endpoint'
);
is(
run_function(
"$install_endpoint_host\n$install_format_host_port",
'format_host_port "$1" "$2"',
'192.0.2.1', 3001
),
'192.0.2.1:3001',
'stateful postboot preserves the IPv4 endpoint form'
);
unlike(
$installpost,
qr/XCATSERVER="\$SIP:3001"/,
'stateful postboot never appends a port to a raw server address'
);
is(
scalar(() = $installpost =~ /updateflag\.awk \\"\\\$MASTER_IP\\" 3002/g),
2,
'stateful boot completion callbacks use the quoted resolved master address'
);
unlike(
$installpost,
qr/updateflag\.awk \\\$MASTER 3002/,
'stateful boot completion callbacks do not use an unresolved master hostname'
);
done_testing();
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
use xCAT::DSHCore;
my %addresses = (
v4only => { OnlyV4 => '192.0.2.10' },
v6only => { OnlyV6 => '2001:db8::20' },
dual => {
OnlyV4 => '192.0.2.30',
OnlyV6 => '2001:db8::30',
},
);
{
no warnings 'redefine';
local *xCAT::NetworkUtils::getipaddr = sub {
my ($class, $target, $family) = @_;
return unless exists($addresses{$target});
return $addresses{$target}{$family};
};
my ($ipv4, $ipv6, $unresolved) =
xCAT::DSHCore->partition_ping_targets(qw(v4only v6only dual missing));
is_deeply(
$ipv4,
[qw(v4only dual)],
'IPv4-only and dual-stack targets use the existing IPv4 probe path'
);
is_deeply(
$ipv6,
[qw(v6only)],
'an IPv6-only target is assigned to the IPv6 probe path'
);
is_deeply(
$unresolved,
[qw(missing)],
'an unresolved target is not passed to either address-family probe'
);
my @nmap_output = (
"Nmap scan report for v4only (192.0.2.10)\n",
"Host is up (0.00012s latency).\n",
"Nmap scan report for 2001:db8::20\n",
"Host is up.\n",
"Host dual.example.test (192.0.2.30) appears to be up ... good.\n",
);
is_deeply(
[ xCAT::DSHCore->nmap_alive_targets(
[qw(v4only v6only dual missing)],
\@nmap_output
) ],
[qw(v4only v6only dual)],
'old and current nmap output maps IPv4 and IPv6 reports to original targets'
);
my @literal_nmap_output = (
"Nmap scan report for head.example.test (192.0.2.40)\n",
"Host is up (0.00010s latency).\n",
"Nmap scan report for head.example.test (2001:db8::40)\n",
"Host is up.\n",
);
is_deeply(
[ xCAT::DSHCore->nmap_alive_targets(
[ '192.0.2.40', '2001:db8::40' ],
\@literal_nmap_output
) ],
[ '192.0.2.40', '2001:db8::40' ],
'reverse-resolved nmap reports retain IPv4 and IPv6 literal targets'
);
is_deeply(
[ xCAT::DSHCore->nmap_alive_targets(
[ '2001:db8::40' ],
[
"Host head.example.test (2001:db8::40) "
. "appears to be up ... good.\n"
]
) ],
[ '2001:db8::40' ],
'legacy nmap output retains a reverse-resolved IPv6 literal target'
);
}
is_deeply(
[ xCAT::DSHCore->parse_pping_result_line('v4only: ping') ],
[qw(v4only ping)],
'pping result parser accepts the IPv4 and hostname output form'
);
is_deeply(
[ xCAT::DSHCore->parse_pping_result_line('2001:db8::20: noping') ],
[ '2001:db8::20', 'noping' ],
'pping result parser preserves a complete IPv6 literal target'
);
is_deeply(
[ xCAT::DSHCore->parse_pping_result_line('nmap diagnostic') ],
[],
'pping result parser ignores non-result diagnostics'
);
my $pping_source = "$FindBin::Bin/../../xCAT-client/bin/pping";
open(my $fh, '<', $pping_source) or die "Unable to read $pping_source: $!";
my $content = do { local $/; <$fh> };
close($fh);
like(
$content,
qr/nmap_pping\(\$ipv6_nodes,\s*6\)/,
'pping sends its IPv6 target partition through the IPv6 nmap path'
);
like(
$content,
qr/push \@command, '-6' if \$family == 6;/,
'the IPv6 nmap path explicitly selects nmap -6'
);
like(
$content,
qr/push \@command, shellwords\(\$more_options\)/,
'site nmap options are parsed into list-form command arguments'
);
like(
$content,
qr/open\(my \$nmap_output, '-\|'\)/,
'nmap output uses a lexical pipe'
);
like(
$content,
qr/exec \{ \$command\[0\] \} \@command;/,
'nmap executes without an interpolated shell command'
);
unlike(
$content,
qr/open\(NMAP,/,
'pping no longer uses the legacy bareword two-argument nmap pipe'
);
done_testing();
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use FindBin;
use Test::More;
my $source = File::Spec->catfile(
$FindBin::Bin, '..', '..', 'xCAT', 'postscripts', 'syslog'
);
open( my $source_fh, '<', $source ) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($definition) =
$content =~ /(^\Q$name\E\(\)\s*\n\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($definition);
return $definition;
}
sub run_shell_function {
my ( $definition, $invocation, @args ) = @_;
open( my $pipe, '-|', 'bash', '-c', "$definition\n$invocation", 'bash', @args )
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is( $?, 0, "$invocation exits successfully" );
chomp($output);
return $output;
}
is( system( 'bash', '-n', $source ), 0, 'syslog postscript has valid bash syntax' );
my $format_target = shell_function('format_syslog_forward_target');
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '192.0.2.10' ),
'192.0.2.10',
'IPv4 rsyslog targets remain byte-for-byte unchanged'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', 'logs.example.test' ),
'logs.example.test',
'hostname rsyslog targets remain byte-for-byte unchanged'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '2001:db8::10' ),
'[2001:db8::10]',
'IPv6 rsyslog targets are bracketed to disambiguate address colons from a port'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '[2001:db8::10]' ),
'[2001:db8::10]',
'an already-bracketed IPv6 rsyslog target is not double-bracketed'
);
my $syslog_ng_driver = shell_function('syslog_ng_udp_driver');
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', '192.0.2.10' ),
'udp',
'syslog-ng keeps its legacy IPv4 UDP destination for IPv4 targets'
);
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', 'logs.example.test' ),
'udp',
'syslog-ng keeps name resolution behavior for hostname targets'
);
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', '2001:db8::10' ),
'udp6',
'syslog-ng selects its IPv6 UDP destination for an IPv6 literal'
);
unlike(
$content,
qr/echo\s+"[^"\n]*@\$master/,
'no rsyslog or traditional syslog forwarding rule appends a raw master address'
);
is(
scalar( () = $content =~ /echo\s+"[^"\n]*@\$syslog_forward_target/g ),
5,
'all selector-style forwarding paths use the family-safe target'
);
like(
$content,
qr/syslog_ng_driver=\$\(syslog_ng_udp_driver "\$master"\).*?\$\{syslog_ng_driver\}\(\\"\$master\\"\)/s,
'syslog-ng emits the selected address-family-specific destination driver'
);
done_testing();
+172
View File
@@ -0,0 +1,172 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use File::Spec;
use File::Temp qw(tempdir);
use FindBin;
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; }
use Test::More;
my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..');
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use xCAT::Template;
my %addresses = (
nodev4 => { 4 => '192.0.2.50' },
nodev6 => { 6 => '2001:db8:1::50' },
nodedual => { 4 => '192.0.2.60', 6 => '2001:db8:1::60' },
'master4.example.test' => { 4 => '192.0.2.1' },
'master6.example.test' => { 6 => '2001:db8::1' },
'dns6.example.test' => { 6 => '2001:db8::53' },
);
my @facing_calls;
no warnings 'redefine';
local *xCAT::NetworkUtils::getipaddr = sub {
my $host = shift;
$host = shift if defined($host) && $host eq 'xCAT::NetworkUtils';
my %opts = @_;
my $entry = $addresses{$host} || {};
return $entry->{6} if $opts{OnlyV6};
return $entry->{4} if $opts{OnlyV4};
return $entry->{4} || $entry->{6};
};
local *xCAT::NetworkUtils::my_ip_facing_family = sub {
my $node = shift;
$node = shift if defined($node) && $node eq 'xCAT::NetworkUtils';
my $family = shift;
push @facing_calls, [$node, $family];
return (0, '2001:db8::1');
};
local *xCAT::NetworkUtils::getNodeNetworkCfg6 = sub {
my $candidate = shift;
$candidate = shift if defined($candidate) && $candidate eq 'xCAT::NetworkUtils';
return ('2001:db8:1::50', $candidate, '<xcatmaster>', 64);
};
local *xCAT::NetworkUtils::getNodeNameservers = sub {
my $nodes = shift;
$nodes = shift if defined($nodes) && $nodes eq 'xCAT::NetworkUtils';
return { $nodes->[0] => 'dns6.example.test,192.0.2.53' };
};
is(
xCAT::Template::_dynamic_kickstart_network('02:00:00:00:00:41', 0),
'dhcp --device=02:00:00:00:00:41',
'IPv4 dynamic Kickstart network fragment remains unchanged'
);
is(
xCAT::Template::_dynamic_kickstart_network('02:00:00:00:00:61', 1),
'dhcp --device=02:00:00:00:00:61 --noipv4 --ipv6=dhcp',
'IPv6-only Kickstart network fragment disables IPv4 and enables DHCPv6'
);
{
package TemplateIPv6MacTable;
sub new { return bless {}, shift; }
sub getNodeAttribs {
my ($self, $node) = @_;
my $mac = $node eq 'nodev6' ? '02:00:00:00:00:61' : '02:00:00:00:00:41';
return { mac => $mac };
}
}
local *xCAT::Template::getPersistentKcmdline = sub { return ''; };
local *xCAT::Table::new = sub {
my ($class, $name) = @_;
return TemplateIPv6MacTable->new() if $name eq 'mac';
return;
};
local *xCAT::TableUtils::get_site_attribute = sub {
my ($class, $attribute) = @_;
return 8080 if $attribute eq 'httpport';
return '/install' if $attribute eq 'installdir';
return;
};
local *xCAT::Utils::parseMacTabEntry = sub {
my ($class, $mac) = @_;
return lc($mac);
};
local $::XCATSITEVALS{managedaddressmode} = 'dhcp';
local $::XCATSITEVALS{xcatdebugmode} = '0';
sub render_minimal_template {
my ($node, $master) = @_;
my $tmpdir = tempdir(CLEANUP => 1);
my $input = "$tmpdir/input.tmpl";
my $output = "$tmpdir/output";
open(my $template, '>', $input) or die "Unable to write template: $!";
print {$template} "#KICKSTARTNET#\n#INSTALL_SOURCES_IN_PRE#\n";
close($template);
my $error = xCAT::Template->subvars(
$input,
$output,
$node,
undef,
'/install/rhels10/x86_64',
'rh',
undef,
{ xcatmaster => $master },
os => 'alma10.1',
);
is($error, 0, "$node minimal EL10 template renders without error");
open(my $rendered, '<', $output) or die "Unable to read rendered template: $!";
local $/;
my $content = <$rendered>;
close($rendered);
return $content;
}
my $v6_rendered = render_minimal_template('nodev6', 'master6.example.test');
like(
$v6_rendered,
qr/^network --onboot=yes --bootproto=static --device=02:00:00:00:00:61 --activate --noipv4 --ipv6=2001:db8:1::50\/64 --ipv6gateway=2001:db8::1 --hostname=nodev6 --nameserver=2001:db8::53$/m,
'rendered EL10 IPv6-only Kickstart uses the node address and IPv6-only static configuration'
);
like(
$v6_rendered,
qr/^nextserver_uri_host="\[\$nextserver\]"$/m,
'IPv6-only repository renderer brackets the raw NEXTSERVER value'
);
like(
$v6_rendered,
qr{http://\'\$nextserver_uri_host\':8080/},
'IPv6-only repository URL uses the bracketed NEXTSERVER authority'
);
is($ENV{MASTER_IP}, '2001:db8::1', 'IPv6-only template resolves the explicit master as IPv6');
{
local $::XCATSITEVALS{managedaddressmode} = 'static';
my $v6_static_rendered =
render_minimal_template('nodev6', 'master6.example.test');
like(
$v6_static_rendered,
qr/^network --onboot=yes --bootproto=static --device=02:00:00:00:00:61 --activate --noipv4 --ipv6=2001:db8:1::50\/64 --ipv6gateway=2001:db8::1 --hostname=nodev6 --nameserver=2001:db8::53$/m,
'site static mode keeps an EL10 IPv6-only node on the native IPv6 path'
);
unlike(
$v6_static_rendered,
qr/--ip=|--netmask=/,
'site static mode does not fall through to legacy IPv4 Kickstart options'
);
}
my $v4_rendered = render_minimal_template('nodev4', 'master4.example.test');
like(
$v4_rendered,
qr/^network --onboot=yes --bootproto=dhcp --device=02:00:00:00:00:41$/m,
'rendered IPv4 Kickstart network command remains unchanged'
);
unlike($v4_rendered, qr/nextserver_uri_host/, 'IPv4 repository rendering adds no IPv6 helper variable');
like(
$v4_rendered,
qr{http://\'\$nextserver\':8080/},
'IPv4 repository URL retains the original NEXTSERVER expression'
);
is($ENV{MASTER_IP}, '192.0.2.1', 'IPv4 template keeps legacy master resolution');
done_testing();
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Test::More;
my $source = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/updatenode.pm";
open(my $fh, '<', $source) or die "Unable to read $source: $!";
my $content = do { local $/; <$fh> };
close($fh);
my @formatted = $content =~ /my \$httpendpoint = xCAT::NetworkUtils->format_host_port\(\$snkey, \$httpport\);/g;
is(
scalar(@formatted),
2,
'postscript and software-update paths format the HTTP endpoint centrally'
);
my @commands = $content =~ /xcatdsklspost [^\n]+ -[mM] '\$httpendpoint' /g;
is(
scalar(@commands),
3,
'all updatenode xcatdsklspost commands quote the IPv6-safe endpoint'
);
unlike(
$content,
qr/xcatdsklspost [^\n]+ -[mM] \$snkey:\$httpport /,
'updatenode does not concatenate an unbracketed IPv6 host and HTTP port'
);
is(
scalar(() = $content =~ /unless \(defined\(\$httpendpoint\)\)/g),
2,
'both endpoint-building paths reject an invalid server authority'
);
done_testing();
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Temp qw(tempfile);
use Test::More;
my $source = "$FindBin::Bin/../../xCAT/postscripts/xcatdsklspost";
open(my $source_fh, '<', $source) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($function) = $content =~ /^(\Q$name\E \(\)\n\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($function);
return $function;
}
my ($fh, $script) = tempfile();
print {$fh} shell_function('parsehttpserver'), "\n";
print {$fh} shell_function('format_host_port'), "\n";
print {$fh} <<'SHELL';
set -e
check() {
expected=$1
shift
actual="$($@)"
[ "$actual" = "$expected" ] || {
echo "expected '$expected', got '$actual' from: $*" >&2
exit 1
}
}
check 192.0.2.10 parsehttpserver 192.0.2.10 server
check 80 parsehttpserver 192.0.2.10 port
check manager.example.test parsehttpserver manager.example.test:8080 server
check 8080 parsehttpserver manager.example.test:8080 port
check 2001:db8::10 parsehttpserver '[2001:db8::10]:8443' server
check 8443 parsehttpserver '[2001:db8::10]:8443' port
check 2001:db8::10 parsehttpserver 2001:db8::10 server
check 80 parsehttpserver 2001:db8::10 port
check 2001:db8::10 parsehttpserver '[2001:db8::10]' server
check 80 parsehttpserver '[2001:db8::10]' port
check 192.0.2.10:3001 format_host_port 192.0.2.10 3001
check manager.example.test:3001 format_host_port manager.example.test 3001
check '[2001:db8::10]:3001' format_host_port 2001:db8::10 3001
check '[2001:db8::10]:3001' format_host_port '[2001:db8::10]' 3001
SHELL
close($fh);
is(system('bash', $script), 0, 'endpoint helpers preserve IPv4 and support bracketed IPv6');
like(
$content,
qr/wget .*"http:\/\/\$authority\$INSTALLDIR\/postscripts\/"/,
'recursive postscript download quotes the normalized HTTP authority'
);
like(
$content,
qr/XCATSERVER=\$\(format_host_port "\$SIP" 3001\)/,
'runtime xCAT endpoint is formatted with IPv6 brackets when needed'
);
unlike(
$content,
qr/(?:XCATSERVER|SIP)=`echo \$(?:TMP|i) \| cut -d: -f1`/,
'kernel XCAT endpoint is not truncated at the first IPv6 colon'
);
is(
scalar(() = $content =~ /updateflag\.awk \\\"\\\$MASTER_IP\\\" 3002/g),
4,
'all generated boot completion callbacks use the quoted resolved master address'
);
unlike(
$content,
qr/updateflag\.awk \\\$MASTER 3002/,
'generated boot completion callbacks do not use an unresolved master hostname'
);
done_testing();
+14 -3
View File
@@ -1,9 +1,20 @@
#!/usr/bin/awk -f
BEGIN {
listener = "/inet/tcp/300/0/0"
quit = "no"
port = ("XCAT_CREDENTIAL_CALLBACK_PORT" in ENVIRON) ? ENVIRON["XCAT_CREDENTIAL_CALLBACK_PORT"] : 300
if (port !~ /^[0-9]+$/ || port < 1 || port > 65535) {
port = 300
}
print $0
master = ("MASTER_IP" in ENVIRON) ? ENVIRON["MASTER_IP"] : ""
if (master == "") {
master = ("MASTER" in ENVIRON) ? ENVIRON["MASTER"] : ""
}
if (master ~ /:/) {
listener = "/inet6/tcp/" port "/0/0"
} else {
listener = "/inet/tcp/" port "/0/0"
}
quit = "no"
while (match(quit,"no")) {
while ((listener |& getline) > 0) {
if (match($0,"CREDOKBYYOU?")) {
+253 -45
View File
@@ -352,6 +352,138 @@ write_netplan_param(){
fi
_netplan_render "$nic"
}
# Capture the active IPv6 configuration of an install NIC before replacing the
# installer-created NetworkManager connection. DHCPv6 leases are not recorded
# in the legacy dhclient lease format used by the IPv4 path below, so use the
# kernel and NetworkManager runtime state as the source of truth.
function discover_install_nic_ipv6(){
local str_if_name=$1
local str_preferred_addr=${2:-}
local str_addr_cidr
str_addr_cidr=`ip -6 -o addr show dev "$str_if_name" scope global 2>/dev/null | awk -v preferred="$str_preferred_addr" '
$3 == "inet6" {
unusable = 0
for (i = 5; i <= NF; i++) {
if ($i == "temporary" || $i == "tentative" ||
$i == "deprecated" || $i == "dadfailed") {
unusable = 1
}
}
if (!unusable) {
split($4, addr, "/")
if (preferred && addr[1] == preferred) {
print $4
found = 1
exit
}
if (!candidate) candidate = $4
}
}
END { if (!found && candidate) print candidate }'`
[ -z "$str_addr_cidr" ] && return 1
str_inst_ipv6=${str_addr_cidr%/*}
str_inst_ipv6_prefix=${str_addr_cidr##*/}
str_inst_ipv6_gateway=`ip -6 route show default dev "$str_if_name" 2>/dev/null | awk '$1 == "default" && $2 == "via" { print $3; exit }'`
str_inst_mtu=`ip -o link show dev "$str_if_name" 2>/dev/null | awk '{ for (i = 1; i <= NF; i++) if ($i == "mtu") { print $(i + 1); exit } }'`
if command -v nmcli >/dev/null 2>&1; then
if [ -z "$str_inst_ipv6_gateway" ]; then
str_inst_ipv6_gateway=`nmcli --escape no -g IP6.GATEWAY device show "$str_if_name" 2>/dev/null | awk 'NF && $0 != "--" { print; exit }'`
fi
str_inst_ipv6_dns=`nmcli --escape no -g IP6.DNS device show "$str_if_name" 2>/dev/null | awk '
NF && $0 != "--" && index($0, ":") {
if (dns) dns = dns "," $0
else dns = $0
}
END { print dns }'`
str_inst_ipv6_dns_search=`nmcli --escape no -g IP6.SEARCHES device show "$str_if_name" 2>/dev/null | awk '
NF && $0 != "--" {
if (search) search = search "," $0
else search = $0
}
END { print search }'`
fi
# NetworkManager's runtime resolv.conf is a useful fallback when the device
# did not receive DNS information directly (for example, DNS supplied by a
# local resolver or another RA/DHCPv6 component).
if [ -z "$str_inst_ipv6_dns" ] && [ -f /var/run/NetworkManager/resolv.conf ]; then
str_inst_ipv6_dns=`awk '
$1 == "nameserver" && index($2, ":") {
if (dns) dns = dns "," $2
else dns = $2
}
END { print dns }' /var/run/NetworkManager/resolv.conf`
fi
if [ -z "$str_inst_ipv6_dns_search" ] && [ -f /var/run/NetworkManager/resolv.conf ]; then
str_inst_ipv6_dns_search=`awk '$1 == "search" { $1 = ""; sub(/^ /, ""); gsub(/ +/, ","); print; exit }' /var/run/NetworkManager/resolv.conf`
fi
return 0
}
# Build the install NIC connection once, then either apply it to the running
# NetworkManager instance or render the equivalent keyfile for a target root.
function configure_install_nic_ipv6_connection(){
local str_con_name=$1
local str_if_name=$2
local str_v6ip=$3
local str_v6prefix=$4
local str_v6gateway=$5
local str_v6dns=$6
local str_v6dns_search=$7
local str_nic_mtu=$8
local str_keyfile=$9
local -a nm_args=(
con add type ethernet
con-name "$str_con_name"
ifname "$str_if_name"
ipv4.method disabled
ipv6.method manual
ipv6.addresses "${str_v6ip}/${str_v6prefix}"
connection.autoconnect yes
connection.autoconnect-priority 9
)
[ -n "$str_v6gateway" ] && nm_args+=(ipv6.gateway "$str_v6gateway")
[ -n "$str_v6dns" ] && nm_args+=(ipv6.dns "$str_v6dns")
[ -n "$str_v6dns_search" ] && nm_args+=(ipv6.dns-search "$str_v6dns_search")
[ -n "$str_nic_mtu" ] && nm_args+=(802-3-ethernet.mtu "$str_nic_mtu")
if [ -z "$str_keyfile" ]; then
nmcli "${nm_args[@]}"
return $?
fi
# During Anaconda's chrooted %post, NetworkManager is running but nmcli
# cannot persist a connection in the target root. Render it offline.
local str_keyfile_dir=${str_keyfile%/*}
local str_tmp_keyfile="${str_keyfile}.xcat.$$"
mkdir -p "$str_keyfile_dir" || return $?
(
umask 077
LC_ALL=C nmcli --offline "${nm_args[@]}" > "$str_tmp_keyfile" &&
mv -f "$str_tmp_keyfile" "$str_keyfile"
)
local int_rc=$?
[ $int_rc -ne 0 ] && rm -f "$str_tmp_keyfile"
return $int_rc
}
# Persist an IPv6-only install connection on a running node.
function configure_install_nic_ipv6_nm(){
configure_install_nic_ipv6_connection "$@" ""
}
# Persist the same connection as a native NetworkManager keyfile.
function configure_install_nic_ipv6_keyfile(){
configure_install_nic_ipv6_connection "$@"
}
function configipv4(){
str_if_name=$1
str_v4ip=$2
@@ -926,6 +1058,15 @@ elif [ "$1" = "-s" ];then
str_inst_gateway=''
str_inst_mtu=''
str_inst_dns=''
str_inst_dns_search=''
str_inst_ipv6=''
str_inst_ipv6_prefix=''
str_inst_ipv6_gateway=''
str_inst_ipv6_dns=''
str_inst_ipv6_dns_search=''
str_requested_ipv6=''
str_requested_ipv6_prefix=''
install_nic_is_ipv6=0
if [ "$str_os_type" = "aix" ];then
log_error "configeth on $NODE: aix does not support -s flag"
exit 1
@@ -1005,7 +1146,16 @@ elif [ "$1" = "-s" ];then
fi
fi
if [ -n "$IPADDR" ];then
str_inst_ip=$IPADDR
if [[ "$IPADDR" == *:* ]]; then
str_requested_ipv6=${IPADDR%/*}
if [[ "$IPADDR" == */* ]]; then
str_requested_ipv6_prefix=${IPADDR##*/}
fi
str_inst_ip=''
str_inst_mask=''
else
str_inst_ip=$IPADDR
fi
fi
if [ -n "$MACADDRESS" ];then
@@ -1015,20 +1165,38 @@ elif [ "$1" = "-s" ];then
str_inst_mac=`ip link show $netdev | grep ether | awk '{print $2}'`
fi
if [ -z "$str_inst_ip" -o -z "$str_inst_mask" ];then
log_info "configeth on $NODE: config install nic, can not find information from dhcp lease file, return."
exit 1
fi
str_inst_net=$(v4calcnet $str_inst_ip $str_inst_mask)
num_index=1
while [ $num_index -le $NETWORKS_LINES ];do
eval str_tmp=\$NETWORKS_LINE$num_index
str_tmp_name=`echo $str_tmp | awk -F'net=' '{print $2}' | awk -F'|' '{print $1}'`
if [ "$str_tmp_name" = "$str_inst_net" ];then
str_inst_mtu=`echo $str_tmp | awk -F'mtu=' '{print $2}' | awk -F'|' '{print $1}'`
break
# EL10 uses NetworkManager's internal DHCPv6 client, so there may be no
# dhclient lease file. Recover the live global address and its route
# metadata before replacing the installer-created connection.
if [ "$str_os_type" = "redhat" ] && \
[[ $networkmanager_active -eq 1 || $networkmanager_active -eq 2 ]] && \
discover_install_nic_ipv6 "$str_inst_nic" "$str_requested_ipv6"; then
[ -n "$str_requested_ipv6" ] && str_inst_ipv6=$str_requested_ipv6
[ -n "$str_requested_ipv6_prefix" ] && str_inst_ipv6_prefix=$str_requested_ipv6_prefix
if [ -n "$str_inst_ipv6" ] && [ -n "$str_inst_ipv6_prefix" ]; then
install_nic_is_ipv6=1
fi
fi
num_index=$((num_index+1))
done
if [ $install_nic_is_ipv6 -ne 1 ]; then
log_info "configeth on $NODE: config install nic, can not find active IPv4 or IPv6 address information, return."
exit 1
fi
fi
if [ $install_nic_is_ipv6 -ne 1 ]; then
str_inst_net=$(v4calcnet $str_inst_ip $str_inst_mask)
num_index=1
while [ $num_index -le $NETWORKS_LINES ];do
eval str_tmp=\$NETWORKS_LINE$num_index
str_tmp_name=`echo $str_tmp | awk -F'net=' '{print $2}' | awk -F'|' '{print $1}'`
if [ "$str_tmp_name" = "$str_inst_net" ];then
str_inst_mtu=`echo $str_tmp | awk -F'mtu=' '{print $2}' | awk -F'|' '{print $1}'`
break
fi
num_index=$((num_index+1))
done
fi
#get extra configration parameters for each nic
@@ -1138,28 +1306,51 @@ elif [ "$1" = "-s" ];then
#write ifcfg-* file for redhat
con_name="xcat-"${str_inst_nic}
str_inst_prefix=$(v4mask2prefix ${str_inst_mask})
if [ $install_nic_is_ipv6 -ne 1 ]; then
str_inst_prefix=$(v4mask2prefix ${str_inst_mask})
fi
str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_inst_nic}"
if [ $networkmanager_active -eq 2 ]; then
str_conf_file="/etc/sysconfig/network-scripts/ifcfg-$con_name"
fi
if [ $networkmanager_active -eq 1 ]; then
if [ $install_nic_is_ipv6 -eq 1 ] && [ $networkmanager_active -eq 2 ]; then
str_keyfile="/etc/NetworkManager/system-connections/${con_name}.nmconnection"
configure_install_nic_ipv6_keyfile "$con_name" "$str_inst_nic" \
"$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu" "$str_keyfile"
if [ $? -ne 0 ]; then
log_error "configeth on $NODE: failed to persist the IPv6 install NIC keyfile."
error_code=1
fi
elif [ $networkmanager_active -eq 1 ]; then
is_nmcli_connection_exist "$con_name"
if [ $? -eq 0 ]; then
tmp_con_name=${str_inst_nic}"-tmp"
nmcli con modify $con_name connection.id $tmp_con_name
fi
if [ -z "$str_inst_gateway" ]; then
# EL10/NM: during updatenode the dhclient lease and MACADDRESS may be
# absent, leaving the gateway empty. Recover it from the live default
# route so the install NIC keeps its default route.
str_inst_gateway=`ip route show default | awk '{print $3}' | head -1`
if [ $install_nic_is_ipv6 -eq 1 ]; then
configure_install_nic_ipv6_nm "$con_name" "$str_inst_nic" \
"$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu"
if [ $? -ne 0 ]; then
log_error "configeth on $NODE: failed to persist the IPv6 install NIC connection."
error_code=1
fi
else
if [ -z "$str_inst_gateway" ]; then
# EL10/NM: during updatenode the dhclient lease and MACADDRESS may be
# absent, leaving the gateway empty. Recover it from the live default
# route so the install NIC keeps its default route.
str_inst_gateway=`ip route show default | awk '{print $3}' | head -1`
fi
gw4_arg=""
# Never pass an empty gw4: nmcli rejects "value for 'gw4' is missing", the
# connection is not created, and the later down+reload leaves the NIC down.
[ -n "$str_inst_gateway" ] && gw4_arg="gw4 $str_inst_gateway"
nmcli con add type ethernet con-name $con_name ifname ${str_inst_nic} ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} connection.autoconnect-priority 9 $gw4_arg
fi
gw4_arg=""
# Never pass an empty gw4: nmcli rejects "value for 'gw4' is missing", the
# connection is not created, and the later down+reload leaves the NIC down.
[ -n "$str_inst_gateway" ] && gw4_arg="gw4 $str_inst_gateway"
nmcli con add type ethernet con-name $con_name ifname ${str_inst_nic} ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} connection.autoconnect-priority 9 $gw4_arg
str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_inst_nic}-1"
if [ -f $str_conf_file_1 ]; then
grep $con_name $str_conf_file_1 >/dev/null 2>/dev/null
@@ -1182,25 +1373,25 @@ elif [ "$1" = "-s" ];then
echo "GATEWAY=${str_inst_gateway}" >> $str_conf_file
fi
fi
if [ $networkmanager_active -eq 2 ]; then
if [ $install_nic_is_ipv6 -ne 1 ] && [ $networkmanager_active -eq 2 ]; then
echo "AUTOCONNECT_PRIORITY=9" >> $str_conf_file
fi
if [ -n "${str_inst_dns}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name ipv4.dns ${str_inst_dns}
fi
if [ $install_nic_is_ipv6 -ne 1 ] && [ -n "${str_inst_dns}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name ipv4.dns ${str_inst_dns}
fi
fi
if [ -n "${str_inst_dns_search}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name ipv4.dns-search "${str_inst_dns_search}"
fi
if [ $install_nic_is_ipv6 -ne 1 ] && [ -n "${str_inst_dns_search}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name ipv4.dns-search "${str_inst_dns_search}"
fi
fi
if [ -n "${str_inst_mtu}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name mtu ${str_inst_mtu}
if [ $install_nic_is_ipv6 -ne 1 ] && [ -n "${str_inst_mtu}" ];then
if [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name mtu ${str_inst_mtu}
else
echo "MTU=${str_inst_mtu}" >> $str_conf_file
fi
fi
fi
# Add GATEWAY to the network file only if the OS version is RHEL 7.x or below.
@@ -1220,7 +1411,11 @@ elif [ "$1" = "-s" ];then
do
name="${array_extra_param_names[$i]}"
value="${array_extra_param_values[$i]}"
if xcat_uses_nm_keyfile "$OSVER" "$con_name"; then
if [ $install_nic_is_ipv6 -eq 1 ] && [ $networkmanager_active -eq 2 ]; then
# The target-root keyfile already carries the live MTU. nmcli
# cannot apply its other properties from the Anaconda chroot.
:
elif xcat_uses_nm_keyfile "$OSVER" "$con_name"; then
nmcli con modify $con_name $name $value
else
echo "$i: name=$name value=$value"
@@ -1249,20 +1444,33 @@ elif [ "$1" = "-s" ];then
if [ "$UPDATENODE" = "1" ] || [ "$NODESETSTATE" = "netboot" ] || [ "$NODESETSTATE" = "statelite" ] || grep "REBOOT=TRUE" /opt/xcat/xcatinfo >/dev/null 2>&1; then
if_state=0
if [ "$str_os_type" = "debian" ] && [ "$netplan_active" = "1" ];then
skip_nic_restart=0
if [ $install_nic_is_ipv6 -eq 1 ] && [ $networkmanager_active -eq 2 ]; then
# This keyfile belongs to the target system. Do not tear down the
# Anaconda-owned live connection from inside the chroot.
log_info "configeth on $NODE: IPv6 install NIC keyfile takes effect on first boot."
skip_nic_restart=1
fi
if [ $skip_nic_restart -eq 0 ] && [ "$str_os_type" = "debian" ] && [ "$netplan_active" = "1" ];then
: # netplan apply below reconfigures the interface; no ifdown needed
elif [ "$str_os_type" = "debian" ];then
elif [ $skip_nic_restart -eq 0 ] && [ "$str_os_type" = "debian" ];then
ifdown --force $str_inst_nic
else
elif [ $skip_nic_restart -eq 0 ]; then
ip link set dev $str_inst_nic down
fi
#tested before NetworkManager: on an NM-rendered netplan node this is the correct arm,
#and as an elif after it, it was dead code that fell through to an nmcli call with an
#unset connection name
if [ "$str_os_type" = "debian" ] && [ "$netplan_active" = "1" ]; then
if [ $skip_nic_restart -eq 1 ]; then
:
elif [ "$str_os_type" = "debian" ] && [ "$netplan_active" = "1" ]; then
netplan_apply "$str_inst_nic" || error_code=1
elif [ $networkmanager_active -eq 1 ]; then
nmcli con modify $con_name ipv4.dns "${NAMESERVERS}"
if [ $install_nic_is_ipv6 -eq 1 ]; then
[ -n "$NAMESERVERS" ] && nmcli con modify "$con_name" ipv6.dns "$NAMESERVERS"
else
nmcli con modify $con_name ipv4.dns "${NAMESERVERS}"
fi
nmcli con reload
nmcli con up $con_name
else
+31 -6
View File
@@ -32,6 +32,30 @@ if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then
fi
master=$MASTER
# The legacy rsyslog forwarding syntax treats a colon after the target as the
# port separator. Bracket IPv6 literals so the complete address is passed to
# the resolver, while preserving the existing output for hostnames and IPv4.
format_syslog_forward_target()
{
case "$1" in
\[*\]) printf '%s\n' "$1" ;;
*:*) printf '[%s]\n' "$1" ;;
*) printf '%s\n' "$1" ;;
esac
}
# The legacy syslog-ng udp() destination is IPv4-only. Its udp6() companion
# accepts an IPv6 literal directly (without URI-style brackets).
syslog_ng_udp_driver()
{
case "$1" in
*:*) printf '%s\n' 'udp6' ;;
*) printf '%s\n' 'udp' ;;
esac
}
syslog_forward_target=$(format_syslog_forward_target "$master")
conf_file="/etc/syslog.conf"
sysconfig="/etc/sysconfig/syslog"
init="/etc/init.d/syslog"
@@ -132,7 +156,7 @@ config_Rsyslog_C3()
else
sed -i 's/^\(\*\..*\)/\#\1/;
s/^\(news\|local7\|mail\|authpriv\|cron\|kern\)\./\#\1\./' $2
echo "*.* @$master" >> $2
echo "*.* @$syslog_forward_target" >> $2
fi
# Mark the end of xCAT section
echo "# $xCATSettingsEND" >> $2
@@ -368,7 +392,7 @@ config_rsyslog_V8()
if [ $isSN -eq 1 ] && xcat_is_openeuler "$OSVER"; then
config_native_rsyslog_receiver "$remoteconf" || return $?
fi
echo "*.* @$master" >> $remoteconf
echo "*.* @$syslog_forward_target" >> $remoteconf
echo "# $xCATSettingsEND" >> $remoteconf
fi
if xcat_is_openeuler "$OSVER"; then
@@ -567,7 +591,8 @@ else
sed -i "/# xCAT settings/,$ d" $conf_file
fi
echo "# xCAT settings" >> $conf_file
echo "destination loghost { udp(\"$master\"); };" >> $conf_file
syslog_ng_driver=$(syslog_ng_udp_driver "$master")
echo "destination loghost { ${syslog_ng_driver}(\"$master\"); };" >> $conf_file
echo 'log { source(src); destination(loghost); };' >> $conf_file
# remove the settings that will log to local files
@@ -583,13 +608,13 @@ else
fi
echo "# xCAT settings" > $conf_file
if [ $isLinux -eq 0 ]; then
echo "*.debug @$master" >> $conf_file
echo "*.debug @$syslog_forward_target" >> $conf_file
else
if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ) || ( pmatch $OSVER "debian*" ); then
echo "\$ModLoad imuxsock" >> $conf_file
echo "*.* @$master" >> $conf_file
echo "*.* @$syslog_forward_target" >> $conf_file
else
echo "*.* @$master" >> $conf_file
echo "*.* @$syslog_forward_target" >> $conf_file
fi
fi
fi
+6 -2
View File
@@ -8,7 +8,12 @@ BEGIN {
if (!flag) flag = "next"
ns = "/inet/tcp/0/" xcatdhost "/" xcatdport
if (xcatdhost ~ /^\[.*\]$/) {
sub(/^\[/, "", xcatdhost)
sub(/\]$/, "", xcatdhost)
}
netfamily = index(xcatdhost, ":") ? "inet6" : "inet"
ns = "/" netfamily "/tcp/0/" xcatdhost "/" xcatdport
loop = 0
while(1) {
@@ -37,4 +42,3 @@ BEGIN {
exit 0
}
+60 -34
View File
@@ -132,10 +132,16 @@ download_mypostscript()
download_postscripts()
{
server=$1
if [ -z $server ]; then
local rawserver=$1
local server
local port
local authority
if [ -z "$rawserver" ]; then
return 1;
fi
server=$(parsehttpserver "$rawserver" 'server')
port=$(parsehttpserver "$rawserver" 'port')
authority=$(format_host_port "$server" "$port")
# Do not override the parameter --installdir
if [ -z "$INSTALLDIR" ]; then
@@ -146,7 +152,7 @@ download_postscripts()
INSTALLDIR="/install"
fi
fi
echolog "debug" "trying to download postscripts from http://$server$INSTALLDIR/postscripts/"
echolog "debug" "trying to download postscripts from http://$authority$INSTALLDIR/postscripts/"
max_retries=5
retry=0
rc=1 # this is a fail return
@@ -158,7 +164,7 @@ download_postscripts()
# These dispatcher scripts are not needed by the legacy netboot post
# path. Newer wget parses HTML-looking regex strings inside downloaded
# scripts and fails the whole recursive download on bogus URLs.
export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*,post.xcat.ng,post.xcat.rhels10" --no-parent http://$server$INSTALLDIR/postscripts/ -P /$xcatpost 2> "$XCAT_WGET_LOG"
export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*,post.xcat.ng,post.xcat.rhels10" --no-parent "http://$authority$INSTALLDIR/postscripts/" -P "/$xcatpost" 2> "$XCAT_WGET_LOG"
rc=$?
if [ $rc -eq 0 ]; then
# return from wget was 0 but some OS do not return errors, so we
@@ -171,7 +177,7 @@ download_postscripts()
rc2=$?
# check to see no errors at all, grep returns 1
if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then
echolog "debug" "postscripts are downloaded from $server successfully."
echolog "debug" "postscripts are downloaded from $authority successfully."
return 0
fi
fi
@@ -179,7 +185,7 @@ download_postscripts()
retry=$(($retry+1))
echolog "debug" "download_postscripts retry $retry"
if [ $retry -eq $max_retries ]; then
echolog "debug" "failed to download postscripts from http://$server$INSTALLDIR/postscripts/ after several retries."
echolog "debug" "failed to download postscripts from http://$authority$INSTALLDIR/postscripts/ after several retries."
break
fi
@@ -201,18 +207,22 @@ pmatch ()
return 1 # non-zero return code means string not matched by pattern
}
#parse the http server "<ip/hostname>:<port>"
#usgae: parsehttpserver(<http server string>,<what to return? 'server' or 'port'>)
# Parse an HTTP authority. IPv6 with a port must use RFC 3986 brackets;
# an unbracketed value containing multiple colons is treated as a bare address.
# usage: parsehttpserver(<http server string>, <'server' or 'port'>)
parsehttpserver ()
{
rawserver=$1
option=$2
server=$(echo "$rawserver"|cut -d: -f1 -s 2>/dev/null)
port="80"
if [ -z "$server" ];then
server=$rawserver
else
port=$(echo "$rawserver"|cut -d: -f2 -s 2>/dev/null)
local rawserver="$1"
local option="$2"
local server="$rawserver"
local port="80"
if [[ "$rawserver" =~ ^\[([^]]+)\](:([0-9]+))?$ ]]; then
server="${BASH_REMATCH[1]}"
[ -n "${BASH_REMATCH[3]}" ] && port="${BASH_REMATCH[3]}"
elif [[ "$rawserver" != *:*:* && "$rawserver" == *:* ]]; then
server="${rawserver%:*}"
port="${rawserver##*:}"
fi
if [ "$option" = "server" ];then
@@ -278,6 +288,21 @@ XCATPOST_CLEANUP
fi
}
# Format a host and port for URLs and xCAT endpoint variables.
format_host_port ()
{
local server="$1"
local port="$2"
server="${server#[}"
server="${server%]}"
if [[ "$server" == *:* ]]; then
printf '[%s]:%s\n' "$server" "$port"
else
printf '%s:%s\n' "$server" "$port"
fi
}
if [ "$XCATDSKLSPOST_SOURCE_ONLY" = "1" ]; then
return 0 2>/dev/null || exit 0
fi
@@ -477,8 +502,8 @@ if [ "$MODE" = "4" ]; then # for statelite mode
for i in `cat /proc/cmdline`; do
KEY=`echo $i | awk -F= '{print $1}'`
if [ "$KEY" = "XCAT" ]; then
TMP=`echo $i | awk -F= '{print $2}'`
XCATSERVER=`echo $TMP | cut -d: -f1`
TMP=${i#XCAT=}
XCATSERVER=$(parsehttpserver "$TMP" 'server')
grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1
if [ $? -eq 0 ]; then
sed -i "s/XCATSERVER=.*/XCATSERVER=$XCATSERVER/" /opt/xcat/xcatinfo
@@ -499,8 +524,9 @@ if [ "$MODE" = "4" ]; then # for statelite mode
if [ -f /opt/xcat/xcatinfo ]; then
SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2 | sed "s/'//g"`
HTTPPORT=`grep 'HTTPPORT' /opt/xcat/xcatinfo |cut -d= -f2 | sed "s/'//g"`
[ -z "$HTTPPORT" ] && HTTPPORT="80"
if [ -n "$SIP" ]; then
download_postscripts $SIP:${HTTPPORT}
download_postscripts "$(format_host_port "$SIP" "$HTTPPORT")"
if [ $? -eq 0 ]; then
downloaded=1
fi
@@ -543,7 +569,7 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment)
if [ -n "$P_SIP" ]; then # passed in with updatenode on -M/-m
#SIP="${P_SIP}:${HTTPPORT}"
SIP=${P_SIP}
download_postscripts ${P_SIP}:${HTTPPORT}
download_postscripts "$(format_host_port "$P_SIP" "$HTTPPORT")"
if [ $? -eq 0 ]; then
downloaded=1
fi
@@ -570,7 +596,7 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment)
HTTPPORT=`grep 'HTTPPORT' /opt/xcat/xcatinfo |cut -d= -f2 | sed "s/'//g"`
[ -z "$HTTPPORT" ] && HTTPPORT="80"
if [ -n "$SIP" ]; then
download_postscripts ${SIP}:${HTTPPORT}
download_postscripts "$(format_host_port "$SIP" "$HTTPPORT")"
if [ $? -eq 0 ]; then
downloaded=1
fi
@@ -585,8 +611,8 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment)
for i in `cat /proc/cmdline`; do
KEY=`echo $i | awk -F= '{print $1}'`
if [ "$KEY" = "XCAT" ]; then
TMP=`echo $i | awk -F= '{print $2}'`
SIP=`echo $TMP | cut -d: -f1`
TMP=${i#XCAT=}
SIP=$(parsehttpserver "$TMP" 'server')
elif [ "$KEY" = "XCATHTTPPORT" ];then
HTTPPORT=$(echo $i | awk -F= '{print $2}')
@@ -595,7 +621,7 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment)
done
if [ -n "$SIP" ]; then
download_postscripts "${SIP}:${HTTPPORT}"
download_postscripts "$(format_host_port "$SIP" "$HTTPPORT")"
if [ $? -eq 0 ]; then
downloaded=1
fi
@@ -668,15 +694,15 @@ else
#get node name and download the mypostscript.$node file
#try to get the node ip address that connects to the server.
#then resolve the name of the ip
real_SIP=`getent hosts $SIP |awk {'print $1'}`
real_SIP=`getent hosts "$SIP" |awk {'print $1'}`
if [ $? -ne 0 ]; then
real_SIP=$SIP
fi
NIP=`ip route get $real_SIP | head -n 1 | sed 's/^.*src//g' | awk {'print $1'}`
NIP=`ip route get "$real_SIP" | head -n 1 | sed 's/^.*src//g' | awk {'print $1'}`
if [ $? -eq 0 ] && [ -n "$NIP" ]; then
#resolve the name of the node from ip address
result=`getent hosts $NIP`
result=`getent hosts "$NIP"`
if [ $? -eq 0 ]; then
node1=`echo $result | awk {'print $2'}`
node2=`echo $result | awk {'print $3'}`
@@ -706,11 +732,11 @@ echolog "info" "trying to get mypostscript from $SIP..."
max_retries=2
# try short hostname first
if [ -n "$node_short" ]; then
download_mypostscript "${SIP}:${HTTPPORT}" $node_short $max_retries $TFTPDIR
download_mypostscript "$(format_host_port "$SIP" "$HTTPPORT")" "$node_short" "$max_retries" "$TFTPDIR"
if [ $? -ne 0 ]; then
# try long hostname
if [ "$node" != "$node_short" ]; then
download_mypostscript "${SIP}:${HTTPPORT}" $node $postfix $max_retries $TFTPDIR
download_mypostscript "$(format_host_port "$SIP" "$HTTPPORT")" "$node" "$postfix" "$max_retries" "$TFTPDIR"
fi
fi
fi
@@ -734,7 +760,7 @@ PATH=/$xcatpost:$PATH
export PATH
if [ -x /usr/bin/openssl ]; then
XCATSERVER="$SIP:3001"
XCATSERVER=$(format_host_port "$SIP" 3001)
export XCATSERVER
USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images
export USEOPENSSLFORXCAT
@@ -1115,21 +1141,21 @@ if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then
echo "
if [ \"\$return_value\" -eq \"0\" ]; then
msgutil_r \$MASTER_IP \"debug\" \"node booted successfully, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
updateflag.awk \$MASTER 3002 \"installstatus booted\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus booted\"
else
msgutil_r \$MASTER_IP \"debug\" \"node boot failed, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
updateflag.awk \$MASTER 3002 \"installstatus failed\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus failed\"
fi
" >> /$xcatpost/mypostscript
else
echo "
if [ \"\$return_value\" -eq \"0\" ]; then
msgutil_r \$MASTER_IP \"debug\" \"node booted successfully, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
updateflag.awk \$MASTER 3002 \"installstatus booted\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus booted\"
msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
else
msgutil_r \$MASTER_IP \"debug\" \"node boot failed, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
updateflag.awk \$MASTER 3002 \"installstatus failed\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus failed\"
msgutil_r \$MASTER_IP \"error\" \"provision completed with error.(\$NODE)\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
fi
" >> /$xcatpost/mypostscript
+46 -6
View File
@@ -7,6 +7,45 @@
. /xcatpost/xcatlib.sh
log_label="xcat.deployment"
xcat_endpoint_host()
{
local endpoint="$1"
local remainder
endpoint=${endpoint#\'}
endpoint=${endpoint%\'}
endpoint=${endpoint#\"}
endpoint=${endpoint%\"}
case "$endpoint" in
\[*\]:*)
endpoint=${endpoint#\[}
printf '%s\n' "${endpoint%%\]*}"
;;
*:*)
remainder=${endpoint#*:}
if [[ "$remainder" == *:* ]]; then
printf '%s\n' "$endpoint"
else
printf '%s\n' "${endpoint%%:*}"
fi
;;
*)
printf '%s\n' "$endpoint"
;;
esac
}
format_host_port()
{
local host
host=$(xcat_endpoint_host "$1") || return 1
if [[ "$host" == *:* ]]; then
printf '[%s]:%s\n' "$host" "$2"
else
printf '%s:%s\n' "$host" "$2"
fi
}
if [ -f /xcatpost/mypostscript.post ]; then
XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z `
MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g`
@@ -26,7 +65,8 @@ sleep $SLI
XCATINFOFILE=/opt/xcat/xcatinfo
if [ -z "$MASTER_IP" ] && [ -f "$XCATINFOFILE" ]; then
MASTER_IP=`grep '^XCATSERVER=' "$XCATINFOFILE" | head -n 1 | cut -d= -f2 | cut -d: -f1 | tr -d \'\"`
XCATINFOENDPOINT=`grep '^XCATSERVER=' "$XCATINFOFILE" | head -n 1 | cut -d= -f2-`
MASTER_IP=$(xcat_endpoint_host "$XCATINFOENDPOINT")
fi
if [ -z "$MASTER_IP" ]; then
@@ -43,7 +83,7 @@ INSTALLNIC=`ip -o link | grep -i "$MACADDR" | awk '{ print $2 }' | sed "s/://"`
RETRY=0
while true; do
#check whether the network access between MN/CN and the node is ready
ping -c 1 $MASTER_IP >/dev/null && break
ping -c 1 "$MASTER_IP" >/dev/null && break
RETRY=$[ $RETRY + 1 ]
@@ -68,8 +108,8 @@ chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcat
POST_IN_DIR="/xcatpost"
if [ -x /usr/bin/openssl ]; then
SIP=`grep "^MASTER=" ${POST_IN_DIR}/mypostscript.post |cut -d= -f2`
XCATSERVER="$SIP:3001"
SIP=`grep "^MASTER=" ${POST_IN_DIR}/mypostscript.post | cut -d= -f2-`
XCATSERVER=$(format_host_port "$SIP" 3001)
export XCATSERVER
USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images
export USEOPENSSLFORXCAT
@@ -137,13 +177,13 @@ if [ \"\$return_value\" -eq \"0\" ]; then
if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then
msgutil_r \"\$MASTER_IP\" \"debug\" \"node booted, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
fi
updateflag.awk \$MASTER 3002 \"installstatus booted\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus booted\"
msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
else
if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then
msgutil_r \"\$MASTER_IP\" \"debug\" \"node boot failed, reporting status...\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
fi
updateflag.awk \$MASTER 3002 \"installstatus failed\"
updateflag.awk \"\$MASTER_IP\" 3002 \"installstatus failed\"
msgutil_r \$MASTER_IP \"error\" \"provision completed with error.(\$NODE)\" \"/var/log/xcat/xcat.log\" \"\$log_label\"
fi
" >> /xcatpost/mypostscript.post
+29 -4
View File
@@ -25,7 +25,32 @@ else
log_label="xcat.deployment"
fi
XCATSERVER=$(grep --only-matching "\<XCAT=[^ ]*\>" /proc/cmdline |cut -d= -f2 |cut -d: -f1 2>/dev/null)
xcat_endpoint_host()
{
local endpoint="$1"
local remainder
case "$endpoint" in
\[*\]:*)
endpoint=${endpoint#\[}
printf '%s\n' "${endpoint%%\]*}"
;;
*:*)
remainder=${endpoint#*:}
if [[ "$remainder" == *:* ]]; then
printf '%s\n' "$endpoint"
else
printf '%s\n' "${endpoint%%:*}"
fi
;;
*)
printf '%s\n' "$endpoint"
;;
esac
}
XCATENDPOINT=$(grep --only-matching "\<XCAT=[^ ]*\>" /proc/cmdline | cut -d= -f2 2>/dev/null)
XCATSERVER=$(xcat_endpoint_host "$XCATENDPOINT")
logger -t $log_label -p local4.info "$0: action is $1"
case $1 in
@@ -40,7 +65,7 @@ status)
stop)
echo -n "nothing to stop "
logger -t $log_label -p local4.info "nothing to stop"
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus powering-off"
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk "$XCATSERVER" 3002 "installstatus powering-off"
;;
start)
# Node is stateless by default
@@ -62,12 +87,12 @@ start)
# Test for script existance
if ! [ -x "$SCRIPT" ]; then
logger -t $log_label -p local4.info "Unable to locate script $SCRIPT."
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus failed"
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk "$XCATSERVER" 3002 "installstatus failed"
exit -1
fi
# Run $SCRIPT according to node type
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus postbooting"
grep nonodestatus /proc/cmdline 2>/dev/null || [ -n "$XCATSERVER" ] && /xcatpost/updateflag.awk "$XCATSERVER" 3002 "installstatus postbooting"
if [ $STATELITE -ne 0 ]; then
logger -t $log_label -p local4.info "Call $SCRIPT for statelite mode"
"$SCRIPT" 4