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

fix(xcat-core): radvd ignores dhcpinterfaces=* and outlives the last IPv6 network

ra_interface_is_served looked up the interface name literally. With
dhcpinterfaces=*, which Kea accepts, no interface was served and
makedhcp wrote no advertisement.

configure_router_advertisements returned when no IPv6 network was
left, and the Kea callers ran it only with a DHCPv6 subnet. radvd then
kept announcing the old prefix and default route.

The wildcard now serves every interface. radvd_config starts its output
with a marker line. When no IPv6 network remains and the file carries
that marker, makedhcp stops and disables radvd and removes the file.
radvd sends a router lifetime of zero when it stops. A radvd
configuration without the marker is left alone. Both Kea paths now
call configure_router_advertisements on every run.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-11-06 17:36:32 -03:00
parent 0c394c3c6e
commit 99619fe205
2 changed files with 76 additions and 5 deletions
+23 -1
View File
@@ -4137,6 +4137,28 @@ sub ipxe_script_server_for_node {
#-------------------------------------------------------------------------------
=head3 radvd_config_is_xcat
Descriptions: Says whether a radvd configuration is one that radvd_config
wrote. makedhcp withdraws only such a configuration, because
radvd can also serve networks that xCAT does not manage.
Arguments: $text the content of the configuration file, or undef
Returns: 1 when xCAT wrote it, 0 when it did not
=cut
#-------------------------------------------------------------------------------
our $RADVD_MARKER = '# Written by xCAT makedhcp. makedhcp replaces or removes this file.';
sub radvd_config_is_xcat {
my ($text) = @_;
return 0 unless defined($text);
return index( $text, $RADVD_MARKER . "\n" ) == 0 ? 1 : 0;
}
#-------------------------------------------------------------------------------
=head3 radvd_config
Descriptions: The radvd configuration for the IPv6 networks xCAT serves.
@@ -4184,7 +4206,7 @@ sub radvd_config {
}
return unless @order;
my $text = '';
my $text = $RADVD_MARKER . "\n";
foreach my $interface (@order) {
$text .= "interface $interface\n{\n";
$text .= " AdvSendAdvert on;\n";
+53 -4
View File
@@ -2961,7 +2961,7 @@ sub kea_process_request
if ($restart->{error}) {
$callback->({ error => [ $restart->{error} ], errorcode => [1] });
}
configure_router_advertisements($callback, $activenics) if $using_dhcp6;
configure_router_advertisements($callback, $activenics);
flock($dhcplockfd, LOCK_UN);
return;
}
@@ -3099,7 +3099,8 @@ sub kea_process_request
$callback->({ error => [ $restart->{error} ], errorcode => [1] });
}
}
configure_router_advertisements($callback, $activenics) if $using_dhcp6;
# Also without a DHCPv6 subnet, which is when an advertisement left from before is withdrawn.
configure_router_advertisements($callback, $activenics);
flock($dhcplockfd, LOCK_UN);
}
@@ -5416,7 +5417,8 @@ sub enable_ipv6_forwarding {
site.dhcpinterfaces names the interfaces this server answers on. An
advertisement on any other interface would offer this host as a router to a
LAN the administrator kept it off. An empty or absent set is no restriction.
LAN the administrator kept it off. An empty or absent set is no restriction,
and neither is the wildcard *, which Kea also accepts.
=cut
@@ -5426,6 +5428,7 @@ sub ra_interface_is_served {
return 0 unless defined($interface) && length($interface);
return 1 unless ref($activenics) eq 'HASH' && scalar(keys %$activenics);
return 1 if $activenics->{'*'};
return $activenics->{$interface} ? 1 : 0;
}
@@ -5453,6 +5456,49 @@ sub radvd_needs_restart {
#-----------------------------------------------------------------------------
=head3 withdraw_router_advertisements
Stops the advertisements of an earlier makedhcp when no IPv6 network is
left to announce.
Arguments:
$callback - the response callback
Returns:
nothing.
radvd announces a router lifetime of zero when it stops, so the clients
drop the route at once. The file is removed so that a restart does not
announce the old prefix again. A file that xCAT did not write is left alone.
=cut
#-----------------------------------------------------------------------------
sub withdraw_router_advertisements
{
my ($callback) = @_;
my $current;
if (open(my $fh, '<', $radvdconffile)) {
local $/;
$current = <$fh>;
close($fh);
}
return unless xCAT::NetworkUtils::radvd_config_is_xcat($current);
my $rc = xCAT::Utils->stopservice('radvd');
if ($rc) {
$callback->({ warning => ["radvd did not stop (exit $rc), so it still announces the IPv6 networks that were removed."] });
return;
}
xCAT::Utils->disableservice('radvd');
unless (unlink($radvdconffile)) {
$callback->({ warning => ["Cannot remove $radvdconffile, so a restart of radvd announces the removed IPv6 networks again: $!"] });
}
return;
}
#-----------------------------------------------------------------------------
sub configure_router_advertisements
{
my ($callback, $activenics) = @_;
@@ -5487,7 +5533,10 @@ sub configure_router_advertisements
}
my $config = xCAT::NetworkUtils::radvd_config(\@wanted);
return unless defined $config;
unless (defined $config) {
withdraw_router_advertisements($callback);
return;
}
foreach my $net (@wanted) {
enable_ipv6_forwarding($net->{interface});