2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-29 13:52:20 +00:00

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>
This commit is contained in:
Daniel Hilst
2026-11-05 09:38:09 -03:00
parent a2d889da3d
commit 251822deae
3 changed files with 132 additions and 17 deletions
+92 -1
View File
@@ -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 <network>/<prefixlen>, 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
+38 -16
View File
@@ -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
+2
View File
@@ -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]);