2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-27 12:52:16 +00:00

fix(debian): an IPv6-only node is given [<xcatmaster>] as its gateway

mknetboot read networks.gateway and passed it to dracut_static_ip6 as it
stood. '<xcatmaster>' is the common value of that column, and it reached the
kernel command line as "[<xcatmaster>]", which is not an address. A node whose
image server sits off its own link then had no route to it.

static_ip6_boot_arg resolves the gateway through ipv6_server_for_node, which
already knew the placeholder and which the AutoYaST path already used. A
gateway that does not resolve is dropped rather than written as a bad address:
an address with no route still reaches a server on the same link.

The composition is its own sub, taking its two lookups as coderefs, because
the helpers were covered while nothing connected them to the call site.
debian_static_ip6_gateway.t drives it with the real dracut_static_ip6.
Passing the gateway unresolved puts "[<xcatmaster>]" in the argument, which
two of its checks report.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-30 13:18:14 -03:00
parent 7f8fc5a937
commit 2ac19d7202
2 changed files with 109 additions and 4 deletions
+35 -4
View File
@@ -750,6 +750,40 @@ sub copycd
#-------------------------------------------------------------------------------
=head3 static_ip6_boot_arg
The dracut ip= argument that gives an IPv6-only node a static address.
networks.gateway holds what the administrator wrote, and '<xcatmaster>' is the common
value. Unresolved it reaches the boot argument as "[<xcatmaster>]", and the node has no
route to a server off its own link. A gateway that does not resolve is dropped: an
address with no route still reaches an image server on the same link.
Arguments:
$node the node being installed
$nicname the name of the provisioning NIC
$cfg6 optional coderef, for tests; defaults to getNodeNetworkCfg6
$resolve optional coderef, for tests; defaults to ipv6_server_for_node
Returns:
the argument, or undef when the node has no usable address
=cut
#-------------------------------------------------------------------------------
sub static_ip6_boot_arg {
my ($node, $nicname, $cfg6, $resolve) = @_;
$cfg6 ||= sub { return xCAT::NetworkUtils->getNodeNetworkCfg6($_[0]); };
$resolve ||= sub { return xCAT::NetworkUtils->ipv6_server_for_node($_[0], $_[1]); };
my ($address, undef, $gateway, $prefix) = $cfg6->($node);
$gateway = $resolve->($node, $gateway)
if defined($gateway) && length($gateway);
return xCAT::NetworkUtils::dracut_static_ip6($address, $gateway, $prefix, $nicname);
}
#-------------------------------------------------------------------------------
=head3 install_iso_name
The name the install ISO takes inside the install tree.
@@ -2118,10 +2152,7 @@ sub mknetboot
# advertisement, so a node that takes the DHCPv6 answer alone cannot reach its
# server.
if (xCAT::NetworkUtils->node_is_ipv6_only($node)) {
my ($v6addr, undef, $v6gateway, $v6prefix) =
xCAT::NetworkUtils->getNodeNetworkCfg6($node);
my $ip6 = xCAT::NetworkUtils::dracut_static_ip6(
$v6addr, $v6gateway, $v6prefix, $net_params->{nicname})
my $ip6 = static_ip6_boot_arg($node, $net_params->{nicname})
|| $net_params->{ip6};
$kcmdline .= "$ip6 " if $ip6;
}
@@ -0,0 +1,74 @@
#!/usr/bin/env perl
# The static IPv6 boot argument debian.pm gives an IPv6-only node.
#
# networks.gateway holds what the administrator wrote, and '<xcatmaster>' is the common value.
# It was passed to dracut_static_ip6 unresolved, so the command line carried
# "[<xcatmaster>]" in the gateway field. That is not an address, and a node whose image
# server sits off its own link had no route to it.
#
# static_ip6_boot_arg takes its two lookups as coderefs, so the composition is driven here
# while the real dracut_static_ip6 formats the result.
use strict;
use warnings;
use File::Spec;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More;
use xCAT::NetworkUtils;
my $plugin = File::Spec->catfile(
$FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'xcat', 'plugins', 'debian.pm'
);
plan skip_all => "debian.pm not found" unless -f $plugin;
my $src = do { local $/; open my $fh, '<', $plugin or die $!; <$fh> };
my ($sub) = $src =~ /\n(sub static_ip6_boot_arg \{.*?\n\})\n/s;
die "could not extract static_ip6_boot_arg from debian.pm" unless defined $sub;
{
package T;
eval "$sub; 1" or main::BAIL_OUT("could not eval static_ip6_boot_arg: $@");
}
# The placeholder is resolved before it reaches the boot argument.
{
my @asked;
my $cfg6 = sub { return ( '2001:db8::10', $_[0], '<xcatmaster>', 64 ) };
my $resolve = sub { push @asked, [@_]; return '2001:db8::1' };
is( T::static_ip6_boot_arg( 'cn1', 'ens3', $cfg6, $resolve ),
'ip=[2001:db8::10]::[2001:db8::1]:64::ens3:none',
'the gateway is resolved before it reaches the boot argument' );
is_deeply( \@asked, [ [ 'cn1', '<xcatmaster>' ] ],
'... through the helper that knows the placeholder' );
}
# A gateway that does not resolve is dropped, not written as a bad address.
{
my $cfg6 = sub { return ( '2001:db8::10', $_[0], '<xcatmaster>', 64 ) };
my $resolve = sub { return };
my $arg = T::static_ip6_boot_arg( 'cn1', 'ens3', $cfg6, $resolve );
is( $arg, 'ip=[2001:db8::10]:::64::ens3:none',
'an unresolvable gateway leaves the field empty' );
unlike( $arg, qr/xcatmaster/, '... and the placeholder does not reach the command line' );
}
# A literal address is passed through and bracketed.
{
my $cfg6 = sub { return ( '2001:db8::10', $_[0], '2001:db8::fe', 64 ) };
my $resolve = sub { return $_[1] };
like( T::static_ip6_boot_arg( 'cn1', 'ens3', $cfg6, $resolve ),
qr/\Q::[2001:db8::fe]:\E/,
'a literal gateway reaches the boot argument bracketed' );
}
# A node with no IPv6 address gets no argument, and the caller falls back.
{
my $cfg6 = sub { return ( undef, $_[0], undef, undef ) };
my $resolve = sub { return $_[1] };
is( T::static_ip6_boot_arg( 'cn1', 'ens3', $cfg6, $resolve ), undef,
'a node with no address gets no argument' );
}
done_testing();