From a2d889da3d6827cbe1a2e24846cd0da2615813e8 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 09:37:57 -0300 Subject: [PATCH 1/2] test(mknb): no test asks what mknb writes for an IPv6 network mknb writes the network boot scripts of an unknown client from my_nets and my_hexnets, both of which skip inet6 on Linux, and it builds every xcatd= value by concatenation. No test covers either, so an IPv6 management node gets no script, and an address written as xcatd=2001:db8:177::1:3001 reads as a valid literal with no port. mknb_xcatd_address.t stubbed the whole of xCAT::NetworkUtils, so the formatting helpers were absent from the harness and could not be measured. The three harnesses now load the real module and replace only the probes that read the running host's interfaces. The new assertions cover the nets/ scripts, the UEFI and elilo entries, the POWER URLs, the s390x APPEND line and the grub2 roots for one IPv6 network, and networkutils_my_nets6.t covers my_nets6 and the prefix masking. 16 of the mknb assertions fail on this commit, and the my_nets6 file does not run at all for lack of the subroutine. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/mknb_exported_genesis.t | 12 +- xCAT-test/unit/mknb_xcatd_address.t | 148 +++++++++++++++++++++-- xCAT-test/unit/networkutils_my_nets6.t | 100 +++++++++++++++ xCAT-test/unit/secureboot_genesis_shim.t | 15 ++- 4 files changed, 258 insertions(+), 17 deletions(-) create mode 100644 xCAT-test/unit/networkutils_my_nets6.t diff --git a/xCAT-test/unit/mknb_exported_genesis.t b/xCAT-test/unit/mknb_exported_genesis.t index 9c6959dee8..fe4d97622f 100644 --- a/xCAT-test/unit/mknb_exported_genesis.t +++ b/xCAT-test/unit/mknb_exported_genesis.t @@ -23,12 +23,16 @@ BEGIN { } $INC{'xCAT/TableUtils.pm'} = __FILE__; + # The real module is loaded so mknb's address formatting is the real one. + # Only the probes that read the running host's interfaces are replaced. + require xCAT::NetworkUtils; package xCAT::NetworkUtils; our ($normnet_addresses, $hexnet_addresses, @master_addresses); - sub my_nets { return $normnet_addresses; } - sub my_hexnets { return $hexnet_addresses; } - sub getipaddr { return @master_addresses; } - $INC{'xCAT/NetworkUtils.pm'} = __FILE__; + no warnings 'redefine'; ## no critic (TestingAndDebugging::ProhibitNoWarnings) + *my_nets = sub { return $normnet_addresses; }; + *my_nets6 = sub { return {}; }; + *my_hexnets = sub { return $hexnet_addresses; }; + *getipaddr = sub { return @master_addresses; }; package xCAT::NodeRange; sub import { diff --git a/xCAT-test/unit/mknb_xcatd_address.t b/xCAT-test/unit/mknb_xcatd_address.t index 5cbf80c6f2..4dd81988ab 100644 --- a/xCAT-test/unit/mknb_xcatd_address.t +++ b/xCAT-test/unit/mknb_xcatd_address.t @@ -29,22 +29,36 @@ BEGIN { } $INC{'xCAT/TableUtils.pm'} = __FILE__; + # The real xCAT::NetworkUtils is loaded, so format_uri_host and + # xcatd_cmdline_address are the implementations under test. Only the host + # probes are replaced: they read the running host's interfaces. + require xCAT::NetworkUtils; package xCAT::NetworkUtils; - our ($normnet_addresses, $hexnet_addresses, @master_addresses); - sub my_nets { + our ($normnet_addresses, $normnet6_addresses, $hexnet_addresses, + @master_addresses, @master6_addresses); + no warnings 'redefine'; ## no critic (TestingAndDebugging::ProhibitNoWarnings) + *my_nets = sub { die "mknb did not request all normalized-network addresses" unless $_[-1] eq 'all'; return $normnet_addresses; - } - sub my_hexnets { + }; + *my_nets6 = sub { + die "mknb did not request all IPv6-network addresses" + unless $_[-1] eq 'all'; + return $normnet6_addresses; + }; + *my_hexnets = sub { die "mknb did not request all hexadecimal-network addresses" unless $_[-1] eq 'all'; return $hexnet_addresses; - } - sub getipaddr { return @master_addresses; } + }; + *getipaddr = sub { + my %options = @_[ 2 .. $#_ ]; + return @master6_addresses if $options{OnlyV6}; + return @master_addresses; + }; our $nic_ips; - sub get_nic_ip { return $nic_ips || {}; } - $INC{'xCAT/NetworkUtils.pm'} = __FILE__; + *get_nic_ip = sub { return $nic_ips || {}; }; package xCAT::NodeRange; sub import { @@ -159,6 +173,11 @@ sub read_config { return $content; } +sub read_config_if { + my ($path) = @_; + return -s $path ? read_config($path) : ''; +} + sub generation_succeeded { my ($responses, $description) = @_; ok( @@ -168,6 +187,8 @@ sub generation_succeeded { } sub use_reporter_address_maps { + $xCAT::NetworkUtils::normnet6_addresses = {}; + @xCAT::NetworkUtils::master6_addresses = (); $xCAT::NetworkUtils::normnet_addresses = { '192.168.144.0/20' => [ '192.168.148.10', @@ -720,4 +741,115 @@ for my $case ([undef, ''], ['', ''], [0, ''], ['0', ''], ['80', ''], ['080', ':0 'GRUB discovery preserves HTTP port defaulting'); } + +$xCAT::TableUtils::site_httpport = undef; + +# An IPv6 provisioning network: mknb writes the same nets/ scripts for it, named after the +# network and its prefix length the way DHCP names them, and the xcatd= endpoint is bracketed. +# "xcatd=2001:db8:177::1:3001" is a valid IPv6 literal with no port, so an unbracketed value +# sends the node to a different address and nothing reports a problem. +use_reporter_address_maps(); +$xCAT::NetworkUtils::normnet_addresses = {}; +$xCAT::NetworkUtils::hexnet_addresses = {}; +$xCAT::NetworkUtils::normnet6_addresses = { + '2001:db8:177::/64' => ['2001:db8:177::1'], +}; +prepare_tftpdir($tmpdir, 'tftpboot-x86-v6', 'x86_64'); +$responses = run_mknb('x86_64'); +generation_succeeded($responses, 'x86 configuration generation succeeds for an IPv6 network'); + +foreach my $loader (qw(xnba ipxe)) { + my $path = "$xCAT::TableUtils::tftpdir/xcat/$loader/nets/2001:db8:177::_64"; + ok(-s $path, "mknb writes xcat/$loader/nets for an IPv6 network"); + my $script = read_config_if($path); + like( + $script, + qr/\Qxcatd=[2001:db8:177::1]:3001\E/, + "the $loader script brackets the IPv6 xcatd endpoint", + ); + unlike( + $script, + qr/xcatd=2001:db8:177::1:3001/, + "the $loader script does not write an IPv6 endpoint that parses as an address", + ); + my $uefi = "$xCAT::TableUtils::tftpdir/xcat/$loader/nets/2001:db8:177::_64.uefi"; + like( + read_config_if($uefi), + qr/\Qimgargs kernel xcatd=[2001:db8:177::1]:3001\E/, + "the $loader UEFI script brackets the IPv6 xcatd endpoint", + ); + my $elilo = "$xCAT::TableUtils::tftpdir/xcat/$loader/nets/2001:db8:177::_64.elilo"; + like( + read_config_if($elilo), + qr/\Qappend="xcatd=[2001:db8:177::1]:3001 destiny=discover\E/, + "the $loader elilo entry brackets the IPv6 xcatd endpoint", + ); +} + +# site.master resolves to an IPv6 address on an IPv6-only management node, and that address +# is the one the node has to reach. +$xCAT::NetworkUtils::normnet6_addresses = { + '2001:db8:177::/64' => ['2001:db8:177::1', '2001:db8:177::9'], +}; +@xCAT::NetworkUtils::master6_addresses = ('2001:db8:177::9'); +prepare_tftpdir($tmpdir, 'tftpboot-x86-v6-master', 'x86_64'); +generation_succeeded(run_mknb('x86_64'), 'x86 generation succeeds with an IPv6 site.master'); +like( + read_config_if("$xCAT::TableUtils::tftpdir/xcat/ipxe/nets/2001:db8:177::_64"), + qr/\Qxcatd=[2001:db8:177::9]:3001\E/, + 'an IPv6 site.master address is selected as the xcatd endpoint', +); +@xCAT::NetworkUtils::master6_addresses = (); + +# A POWER network puts the address in an HTTP URL as well, where an unbracketed literal +# makes the last group of the address read as the port. +use_reporter_address_maps(); +$xCAT::NetworkUtils::normnet_addresses = {}; +$xCAT::NetworkUtils::hexnet_addresses = {}; +$xCAT::NetworkUtils::normnet6_addresses = { + '2001:db8:177::/64' => ['2001:db8:177::1'], +}; +prepare_tftpdir($tmpdir, 'tftpboot-power-v6', 'ppc64'); +generation_succeeded(run_mknb('ppc64'), 'POWER configuration generation succeeds for an IPv6 network'); +my $power_v6 = read_config_if("$xCAT::TableUtils::tftpdir/pxelinux.cfg/p/2001:db8:177::_64"); +like($power_v6, qr{\Qkernel http://[2001:db8:177::1]/\E}, 'the POWER kernel URL brackets the IPv6 address'); +like($power_v6, qr{\Qinitrd http://[2001:db8:177::1]/\E}, 'the POWER initrd URL brackets the IPv6 address'); +like($power_v6, qr/\Qappend "xcatd=[2001:db8:177::1]:3001\E/, 'the POWER append line brackets the IPv6 xcatd endpoint'); +unlike($power_v6, qr{http://2001:db8:177::1/}, 'no POWER URL leaves the IPv6 address unbracketed'); + +# s390x and grub2 build their command line in their own helper, so each is asked directly. +my $s390x_v6_root = "$tmpdir/tftpboot-s390x-v6"; +make_path("$s390x_v6_root/pxelinux.cfg/s390x", "$s390x_v6_root/xcat"); +my ($s390x_v6_path, $s390x_v6_error) = xCAT_plugin::mknb::_write_s390x_discovery_config( + tftpdir => $s390x_v6_root, + network => '2001:db8:177::_64', + xcatd_address => '2001:db8:177::1', + xcatdport => 3001, + kernel => 'xcat/genesis.kernel.s390x', + initrd => "$s390x_v6_root/xcat/genesis.fs.s390x.gz", +); +is($s390x_v6_error, undef, 's390x writes a configuration for an IPv6 network'); +like( + read_config($s390x_v6_path), + qr/^ APPEND \Qxcatd=[2001:db8:177::1]:3001\E /m, + 's390x brackets the IPv6 xcatd endpoint', +); + +my $grub_v6_root = "$tmpdir/tftpboot-grub-v6"; +make_path("$grub_v6_root/boot/grub2", "$grub_v6_root/xcat"); +foreach my $artifact ('genesis.kernel.riscv64', 'genesis.fs.riscv64.gz') { + write_text("$grub_v6_root/xcat/$artifact", ''); +} +my $grub_v6_path = xCAT_plugin::mknb::_write_grub2_discovery_config( + tftpdir => $grub_v6_root, + hexnet => 'c0a89', + xcatd_address => '2001:db8:177::1', + xcatdport => 3001, +); +ok(defined($grub_v6_path), 'grub2 writes a discovery configuration for an IPv6 xcatd address'); +my $grub_v6 = read_config($grub_v6_path); +like($grub_v6, qr/\Qxcatd=[2001:db8:177::1]:3001\E/, 'grub2 brackets the IPv6 xcatd endpoint'); +like($grub_v6, qr/^ set root=\Qhttp,[2001:db8:177::1]\E$/m, 'the grub2 HTTP root brackets the IPv6 address'); +like($grub_v6, qr/^ set root=\Qtftp,[2001:db8:177::1]\E$/m, 'the grub2 TFTP root brackets the IPv6 address'); + done_testing(); diff --git a/xCAT-test/unit/networkutils_my_nets6.t b/xCAT-test/unit/networkutils_my_nets6.t new file mode 100644 index 0000000000..d9df6a2c02 --- /dev/null +++ b/xCAT-test/unit/networkutils_my_nets6.t @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +# my_nets6 answers the question my_nets cannot: which IPv6 networks does this host serve. +# my_nets stays IPv4-only because lsslp.pm and PPCdb.pm read its keys with dotted-quad +# arithmetic, so an IPv6 key there is a wrong answer and not a new one. +use strict; +use warnings; +## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoWarnings) + +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; +use Test::More; + +BEGIN { + package xCAT::Table; + sub new { return bless {}, shift; } + sub getAllAttribs { return; } + $INC{'xCAT/Table.pm'} = __FILE__; + + package xCAT::TableUtils; + sub get_site_attribute { return; } + $INC{'xCAT/TableUtils.pm'} = __FILE__; +} + +require xCAT::NetworkUtils; + +my @prefixes; +{ + no warnings 'redefine'; + # The address probe reads the running host's interfaces. The networks under test are + # the ones this list declares. + *xCAT::NetworkUtils::_local_ip_prefixes = sub { + my ($family) = @_; + return $family == 6 ? @prefixes : (); + }; +} + +# ipv6_network_address masks an address down to its prefix. +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8:177::1', 64), '2001:db8:177::', + 'a /64 address is masked to its network'); +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8:177:abcd::5', 60), '2001:db8:177:abc0::', + 'a prefix that is not a byte boundary masks the partial byte'); +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8:177::1', 128), '2001:db8:177::1', + 'a /128 address is its own network'); +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8:177::1', 0), '::', + 'a /0 address masks to the unspecified address'); +is(xCAT::NetworkUtils->ipv6_network_address('fe80::1%eth0', 10), 'fe80::', + 'a scoped literal is masked after the scope is removed'); +is(xCAT::NetworkUtils->ipv6_network_address('192.0.2.1', 24), undef, + 'an IPv4 address is not an IPv6 network'); +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8::1', 129), undef, + 'a prefix longer than 128 bits is refused'); +is(xCAT::NetworkUtils->ipv6_network_address('2001:db8::1', 'sixty-four'), undef, + 'a prefix that is not a number is refused'); +is(xCAT::NetworkUtils->ipv6_network_address(undef, 64), undef, + 'a missing address is refused'); + +# my_nets6 keys its entries the way my_nets keys its IPv4 entries, so mknb and DHCP +# name the same network boot script. +@prefixes = ( [ '2001:db8:177::1', 64 ] ); +is_deeply( + xCAT::NetworkUtils->my_nets6(), + { '2001:db8:177::/64' => '2001:db8:177::1' }, + 'one global address becomes one network keyed /', +); + +@prefixes = ( + [ '2001:db8:177::1', 64 ], + [ '2001:db8:177::9', 64 ], + [ '2001:db8:178::1', 64 ], +); +is_deeply( + xCAT::NetworkUtils->my_nets6(), + { + '2001:db8:177::/64' => '2001:db8:177::9', + '2001:db8:178::/64' => '2001:db8:178::1', + }, + 'the default behavior keeps the last address of each network, as my_nets does', +); +is_deeply( + xCAT::NetworkUtils->my_nets6('all'), + { + '2001:db8:177::/64' => [ '2001:db8:177::1', '2001:db8:177::9' ], + '2001:db8:178::/64' => ['2001:db8:178::1'], + }, + 'all mode keeps every address of each network in operating-system order', +); + +# A malformed entry is left out instead of becoming a network named after nothing. +@prefixes = ( [ '2001:db8:177::1', 64 ], [ 'not-an-address', 64 ] ); +is_deeply( + xCAT::NetworkUtils->my_nets6('all'), + { '2001:db8:177::/64' => ['2001:db8:177::1'] }, + 'an address that does not parse is skipped', +); + +@prefixes = (); +is(xCAT::NetworkUtils->my_nets6(), undef, 'a host with no global IPv6 address returns no networks'); +is(xCAT::NetworkUtils->my_nets6('all'), undef, 'all mode returns no networks either'); + +done_testing(); diff --git a/xCAT-test/unit/secureboot_genesis_shim.t b/xCAT-test/unit/secureboot_genesis_shim.t index aad0cc20a2..b84e93e004 100644 --- a/xCAT-test/unit/secureboot_genesis_shim.t +++ b/xCAT-test/unit/secureboot_genesis_shim.t @@ -11,6 +11,7 @@ use File::Path qw(make_path); use File::Slurper qw(read_text write_binary); use File::Temp qw(tempdir); use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; use Test::More; BEGIN { @@ -23,12 +24,16 @@ BEGIN { sub get_site_attribute { return $_[-1] eq 'master' ? ('master.example.com') : () } $INC{'xCAT/TableUtils.pm'} = __FILE__; + # The real module is loaded so mknb's address formatting is the real one. + # Only the probes that read the running host's interfaces are replaced. + require xCAT::NetworkUtils; package xCAT::NetworkUtils; - sub my_nets { return { '192.168.144.0/20' => ['192.168.148.10'] } } - sub my_hexnets { return { c0a89 => ['192.168.148.10'] } } - sub getipaddr { return ('203.0.113.10') } - sub get_nic_ip { return {} } - $INC{'xCAT/NetworkUtils.pm'} = __FILE__; + no warnings 'redefine'; ## no critic (TestingAndDebugging::ProhibitNoWarnings) + *my_nets = sub { return { '192.168.144.0/20' => ['192.168.148.10'] } }; + *my_nets6 = sub { return {} }; + *my_hexnets = sub { return { c0a89 => ['192.168.148.10'] } }; + *getipaddr = sub { return ('203.0.113.10') }; + *get_nic_ip = sub { return {} }; package xCAT::MsgUtils; sub trace { return } From 251822deae301093dd9db27ab91c6b16985241b6 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 09:38:09 -0300 Subject: [PATCH 2/2] fix(xcat-core): mknb writes no boot script for an IPv6 network, and an unbracketed xcatd= An unknown client on an IPv6 provisioning network gets no network boot script. mknb builds its list of networks from my_nets and my_hexnets, and both skip inet6 on Linux, so nothing is written under xcat/ipxe/nets and the client has nothing to fetch. Where an address does reach a script it is written as "xcatd=" . $address . ":$port". For 2001:db8:177::1 that is xcatd=2001:db8:177::1:3001, which parses as an IPv6 literal with no port, so Genesis contacts a different address and reports nothing. The same concatenation builds the POWER HTTP URLs and the grub2 roots. xnba.pm and destiny.pm already bracket an IPv6 address through NetworkUtils::xcatd_cmdline_address and format_uri_host, so the node files were correct and the net files were not. NetworkUtils gains my_nets6, which returns the host's global IPv6 networks keyed the way my_nets keys its IPv4 ones, and ipv6_network_address, which masks an address to its prefix. my_nets keeps its IPv4-only behaviour: lsslp.pm and PPCdb.pm read its keys with dotted-quad arithmetic, so an IPv6 key there would be a wrong answer rather than a new one. my_hexnets keeps its own, because a hexnet is a PXELINUX file name built from a hexadecimal IPv4 prefix and DHCPv6 has no equivalent. mknb merges my_nets6 into the networks it writes nets/ scripts for, asks getipaddr for the IPv6 addresses of site.master as well, and takes every xcatd= value and every HTTP authority from the two formatting helpers. mknb_xcatd_address.t and networkutils_my_nets6.t fail without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- perl-xCAT/xCAT/NetworkUtils.pm | 93 +++++++++++++++++++++++- xCAT-server/lib/xcat/plugins/mknb.pm | 54 ++++++++++---- xCAT-test/bats/fixtures/mknb-compress.pl | 2 + 3 files changed, 132 insertions(+), 17 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index c73c1527db..c1dbadfc7c 100644 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -1118,6 +1118,8 @@ sub my_hexnets foreach (@nets) { my @elems = split /\s+/; + # A hexnet is a PXELINUX file name built from a hexadecimal IPv4 prefix. DHCPv6 + # has no such file name, so inet6 is left out rather than given one. unless (/^\s*inet\s/) { next; @@ -1305,7 +1307,9 @@ sub my_nets { if ($elems[1] eq 'inet6') { - next; #Linux IPv6 TODO, do not return IPv6 networks on Linux for now + # my_nets stays IPv4-only on Linux. lsslp.pm and PPCdb.pm read its keys + # with dotted-quad arithmetic. The IPv6 networks are my_nets6. + next; } ($curnet, $maskbits) = split /\//, $elems[2]; } @@ -1356,6 +1360,93 @@ sub my_nets #------------------------------------------------------------------------------- +=head3 ipv6_network_address + + Description: + Masks an IPv6 address down to its network prefix. + + Arguments: + An IPv6 address literal and a prefix length (0-128). + Returns: + The network address, or undef when either argument is malformed. + + Example: + xCAT::NetworkUtils->ipv6_network_address('2001:db8:177::1', 64); + # 2001:db8:177:: + +=cut + +#------------------------------------------------------------------------------- +sub ipv6_network_address +{ + my $address = shift; + if (defined($address) && $address eq __PACKAGE__) + { + $address = shift; + } + my $prefix = shift; + + return unless defined($address) && defined($prefix); + return unless $prefix =~ /^\d+$/ && $prefix >= 0 && $prefix <= 128; + $address =~ s/\%.*//; # a scoped literal, as in fe80::1%eth0 + + my $packed = _pack_ip_address($address, 6); + return unless defined($packed) && length($packed) == 16; + + my $whole_bytes = int($prefix / 8); + my $remaining_bits = $prefix % 8; + my $masked = substr($packed, 0, $whole_bytes); + if ($remaining_bits) + { + my $mask = (0xff << (8 - $remaining_bits)) & 0xff; + $masked .= chr(ord(substr($packed, $whole_bytes, 1)) & $mask); + } + $masked .= "\0" x (16 - length($masked)); + + return _unpack_ip_address($masked, 6); +} + +#------------------------------------------------------------------------------- + +=head3 my_nets6 + + Description: + The IPv6 networks this host has a global address on. + + Arguments: + Optional: 'all' returns every address found for each network in order. + The default behavior returns the last address found. + Returns: + A hash ref keyed /, as my_nets keys its IPv4 + entries: { '2001:db8:177::/64' => '2001:db8:177::1' }. + + Comments: + my_nets stays IPv4-only on Linux. lsslp.pm and PPCdb.pm read its keys + with dotted-quad arithmetic, so an IPv6 key there is a wrong answer + rather than a new one. A caller that wants both families asks for both. + Link-local addresses are left out: _local_ip_prefixes reads global + scope only, and a provisioning network is not link-local. + +=cut + +#------------------------------------------------------------------------------- +sub my_nets6 +{ + my $returnall = @_ && $_[-1] eq 'all'; + my $rethash; + + foreach my $entry (_local_ip_prefixes(6)) + { + my ($address, $prefix) = @{$entry}; + my $net = ipv6_network_address($address, $prefix); + next unless defined($net); + _record_network_address(\$rethash, "$net/$prefix", $address, $returnall); + } + return $rethash; +} + +#------------------------------------------------------------------------------- + =head3 my_if_netmap Arguments: none diff --git a/xCAT-server/lib/xcat/plugins/mknb.pm b/xCAT-server/lib/xcat/plugins/mknb.pm index 081fc57eaf..1884303737 100644 --- a/xCAT-server/lib/xcat/plugins/mknb.pm +++ b/xCAT-server/lib/xcat/plugins/mknb.pm @@ -762,13 +762,25 @@ sub process_request { } } my $hexnet_addresses = xCAT::NetworkUtils->my_hexnets('all'); - my $normnet_addresses = xCAT::NetworkUtils->my_nets('all'); + my $normnet_addresses = xCAT::NetworkUtils->my_nets('all') || {}; + # my_hexnets names a PXELINUX file after a hexadecimal IPv4 prefix. DHCPv6 + # has no such file name, so the IPv6 networks reach only the nets/ scripts + # below, which DHCP names after the network and its prefix length. + my $normnet6_addresses = xCAT::NetworkUtils->my_nets6('all') || {}; + foreach my $net6 (keys %{$normnet6_addresses}) { + $normnet_addresses->{$net6} = $normnet6_addresses->{$net6}; + } my @masters = xCAT::TableUtils->get_site_attribute("master"); my @master_addresses; if ($masters[0]) { @master_addresses = xCAT::NetworkUtils->getipaddr( $masters[0], OnlyV4 => 1, GetAllAddresses => 1 ); + # A preferred address is only compared for equality, so the two families + # are kept in one list: no IPv4 network can select an IPv6 literal. + push @master_addresses, xCAT::NetworkUtils->getipaddr( + $masters[0], OnlyV6 => 1, GetAllAddresses => 1 + ); } my ($hexnets, $xcatdhexnets) = _select_network_addresses( $hexnet_addresses, \@master_addresses @@ -827,6 +839,10 @@ sub process_request { my $net = $_; my $nicip = $normnets->{$net}; my $xcatd_address = defined($xcatdnormnets->{$net}) ? $xcatdnormnets->{$net} : $nicip; + # "xcatd=2001:db8::1:3001" parses as a valid IPv6 literal with no port, so the + # node reads the wrong address and reports nothing. Bracket it. + my $xcatd_endpoint = xCAT::NetworkUtils::xcatd_cmdline_address($xcatd_address, $xcatdport); + my $xcatd_uri_host = xCAT::NetworkUtils->format_uri_host($xcatd_address); $net =~ s/\//_/; if (defined($nobootnicips{$nicip}) || ($arch eq 's390x' && defined($nobootnicips{$xcatd_address}))) { @@ -869,10 +885,10 @@ sub process_request { open($cfg, ">", "$nets/$net"); print $cfg "#!gpxe\n"; if ($invisibletouch) { - print $cfg 'imgfetch -n kernel http://${next-server}'.$portsuffix.'/tftpboot/xcat/genesis.kernel.' . "$arch xcatd=" . $xcatd_address . ":$xcatdport $consolecmdline BOOTIF=01-" . '${netX/mac:hexhyp}' . "\n"; + print $cfg 'imgfetch -n kernel http://${next-server}'.$portsuffix.'/tftpboot/xcat/genesis.kernel.' . "$arch xcatd=$xcatd_endpoint $consolecmdline BOOTIF=01-" . '${netX/mac:hexhyp}' . "\n"; print $cfg 'imgfetch -n nbfs http://${next-server}'.$portsuffix . "$initrd_file\n"; } else { - print $cfg 'imgfetch -n kernel http://${next-server}'.$portsuffix.'/tftpboot/xcat/nbk.' . "$arch xcatd=" . $xcatd_address . ":$xcatdport $consolecmdline\n"; + print $cfg 'imgfetch -n kernel http://${next-server}'.$portsuffix.'/tftpboot/xcat/nbk.' . "$arch xcatd=$xcatd_endpoint $consolecmdline\n"; print $cfg 'imgfetch -n nbfs http://${next-server}'.$portsuffix . "$initrd_file\n"; } print $cfg "imgload kernel\n"; @@ -885,7 +901,7 @@ sub process_request { print $cfg ' image=/tftpboot/xcat/genesis.kernel.' . "$arch\n"; print $cfg " label=\"xCAT Genesis (" . $normnets->{$_} . ")\"\n"; print $cfg " initrd=$initrd_file\n"; - print $cfg " append=\"xcatd=" . $xcatd_address . ":$xcatdport destiny=discover $consolecmdline BOOTIF=%B\"\n"; + print $cfg " append=\"xcatd=$xcatd_endpoint destiny=discover $consolecmdline BOOTIF=%B\"\n"; close($cfg); open($cfg, ">", "$nets/$net.uefi"); print $cfg "#!gpxe\n"; @@ -896,7 +912,7 @@ sub process_request { ? xCAT::SecureBoot->shim_url_path(arch => $arch, tftpdir => $tftpdir) : undef; print $cfg 'shim http://${next-server}' . $portsuffix . $shim . "\n" if ($shim); - print $cfg "imgargs kernel xcatd=" . $xcatd_address . ":$xcatdport $consolecmdline BOOTIF=01-" . '${netX/mac:hexhyp}' . " destiny=discover initrd=initrd\n"; + print $cfg "imgargs kernel xcatd=$xcatd_endpoint $consolecmdline BOOTIF=01-" . '${netX/mac:hexhyp}' . " destiny=discover initrd=initrd\n"; print $cfg 'imgfetch -n initrd http://${next-server}'.$portsuffix . "$initrd_file\nimgexec kernel\n"; close($cfg); } @@ -906,9 +922,9 @@ sub process_request { print $cfgfile "default \"xCAT Genesis (" . $normnets->{$_} . ")\"\n"; print $cfgfile " delay=10\n"; print $cfgfile " label \"xCAT Genesis (" . $normnets->{$_} . ")\"\n"; - print $cfgfile " kernel http://" . $xcatd_address . "$portsuffix/$tftpdir/xcat/genesis.kernel.$arch\n"; - print $cfgfile " initrd http://" . $xcatd_address . "$portsuffix/$initrd_file\n"; - print $cfgfile ' append "xcatd=' . $xcatd_address . ":$xcatdport $consolecmdline\"\n"; + print $cfgfile " kernel http://" . $xcatd_uri_host . "$portsuffix/$tftpdir/xcat/genesis.kernel.$arch\n"; + print $cfgfile " initrd http://" . $xcatd_uri_host . "$portsuffix/$initrd_file\n"; + print $cfgfile ' append "xcatd=' . $xcatd_endpoint . " $consolecmdline\"\n"; close($cfgfile); } elsif ($arch eq 's390x') { my (undef, $config_error) = _write_s390x_discovery_config( @@ -931,6 +947,8 @@ sub process_request { $dopxe = 0; foreach (keys %{$hexnets}) { my $xcatd_address = defined($xcatdhexnets->{$_}) ? $xcatdhexnets->{$_} : $hexnets->{$_}; + my $xcatd_endpoint = xCAT::NetworkUtils::xcatd_cmdline_address($xcatd_address, $xcatdport); + my $xcatd_uri_host = xCAT::NetworkUtils->format_uri_host($xcatd_address); $dopxe = 0; if ($arch =~ /x86/) { #only do pxe if just x86 or x86_64 and no x86 if ($arch =~ /x86_64/) { @@ -957,16 +975,16 @@ sub process_request { print $cfgfile "DEFAULT xCAT\n"; print $cfgfile " LABEL xCAT\n"; print $cfgfile " KERNEL xcat/$kernel_file\n"; - print $cfgfile " APPEND initrd=$tftp_initrd xcatd=" . $xcatd_address . ":$xcatdport $consolecmdline\n"; + print $cfgfile " APPEND initrd=$tftp_initrd xcatd=$xcatd_endpoint $consolecmdline\n"; close($cfgfile); } elsif ($arch =~ /ppc/) { open($cfgfile, ">", "$tftpdir/etc/" . lc($_)); print $cfgfile "default \"xCAT Genesis (" . $normnets->{$_} . ")\"\n"; print $cfgfile " delay=10\n"; print $cfgfile " label \"xCAT Genesis (" . $normnets->{$_} . ")\"\n"; - print $cfgfile " kernel http://" . $xcatd_address . "$portsuffix/$tftpdir/xcat/genesis.kernel.$arch\n"; - print $cfgfile " initrd http://" . $xcatd_address . "$portsuffix/$initrd_file\n"; - print $cfgfile ' append "xcatd=' . $xcatd_address . ":$xcatdport $consolecmdline\"\n"; + print $cfgfile " kernel http://" . $xcatd_uri_host . "$portsuffix/$tftpdir/xcat/genesis.kernel.$arch\n"; + print $cfgfile " initrd http://" . $xcatd_uri_host . "$portsuffix/$initrd_file\n"; + print $cfgfile ' append "xcatd=' . $xcatd_endpoint . " $consolecmdline\"\n"; close($cfgfile); } elsif (exists $GRUB2_DISCOVERY_ARCHES{$arch}) { # Also drop it when the xcatd address chosen for the network sits on a @@ -1000,7 +1018,9 @@ sub _write_s390x_discovery_config { my $tftpdir = $args{tftpdir}; my $initrd = $args{initrd}; $initrd =~ s{^\Q$tftpdir\E/?}{}xms; - my $cmdline = "xcatd=$args{xcatd_address}:$args{xcatdport} xcat.bootloader=s390-ccw"; + my $cmdline = "xcatd=" + . xCAT::NetworkUtils::xcatd_cmdline_address($args{xcatd_address}, $args{xcatdport}) + . " xcat.bootloader=s390-ccw"; if (defined $args{consolecmdline} and length $args{consolecmdline}) { $cmdline .= " $args{consolecmdline}"; } @@ -1104,7 +1124,8 @@ sub _write_grub2_discovery_config { unlink($cfgpath); return; } - my $cmdline = "xcatd=$args{xcatd_address}:$args{xcatdport}"; + my $cmdline = "xcatd=" + . xCAT::NetworkUtils::xcatd_cmdline_address($args{xcatd_address}, $args{xcatdport}); if (defined($args{consolecmdline}) and $args{consolecmdline} ne '') { $cmdline .= " $args{consolecmdline}"; } @@ -1112,9 +1133,10 @@ sub _write_grub2_discovery_config { # loads it over HTTP like netboot=grub2-http; the TFTP entry is for a management # node that does not serve the TFTP root over HTTP. my $httpport = $args{httpport} || '80'; - my $httproot = 'http,' . $args{xcatd_address} . httpport_suffix($httpport); + my $grub_uri_host = xCAT::NetworkUtils->format_uri_host($args{xcatd_address}); + my $httproot = 'http,' . $grub_uri_host . httpport_suffix($httpport); my $http_tftp_root = '/tftpboot'; - my $tftproot = 'tftp,' . $args{xcatd_address}; + my $tftproot = 'tftp,' . $grub_uri_host; my $content = "# xCAT Genesis discovery for network $hexnet - generated by mknb, do not edit\n"; $content .= "set default=0\n"; # Every architecture branch defines the HTTP entry first and the TFTP entry diff --git a/xCAT-test/bats/fixtures/mknb-compress.pl b/xCAT-test/bats/fixtures/mknb-compress.pl index b4ce4ef7c2..610ae6515a 100644 --- a/xCAT-test/bats/fixtures/mknb-compress.pl +++ b/xCAT-test/bats/fixtures/mknb-compress.pl @@ -26,6 +26,8 @@ local *xCAT::TableUtils::getTftpDir = sub { return '/tmp/fixture/tftp'; }; local *xCAT::TableUtils::get_site_attribute = sub { return; }; local *xCAT::NetworkUtils::my_nets = sub { return {}; }; local *xCAT::NetworkUtils::my_hexnets = sub { return {}; }; +# my_nets6 reads the running host's interfaces, so the fixture answers for it too. +local *xCAT::NetworkUtils::my_nets6 = sub { return {}; }; my @responses; umask oct($ARGV[0]);