mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 17:02:15 +00:00
fix(ipv6): makedhcp reports an error for a node whose boot server is IPv6
makedhcp answers "Error: Unable to resolve the tftpserver for node" for a node whose tftpserver or xcatmaster is an IPv6 address, and exits non-zero. Measured on an AlmaLinux 10.2 management node with tftpserver=2001:db8:7309::1: the DHCPv6 reservation and its bootfile-url were written correctly and makedhcp still reported the error. next_server_for_node reads both attributes with inet_aton, which cannot parse an IPv6 literal, and treats the failure as a misconfiguration. An IPv6 boot server is named in the DHCPv6 reservation rather than in a DHCPv4 next-server, so there is no DHCPv4 answer due and nothing to report. Both branches now return without a value when the attribute is an IPv6 address. A name that does not resolve is still reported, which is the behaviour the new assertions would otherwise be satisfied by removing. dhcp_kea_plugin_intent.t covers all three: removing either guard fails the matching "reports no error" assertion, and removing the error path fails the assertion that names the attribute. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -4580,6 +4580,9 @@ sub next_server_for_node
|
||||
#check the value of inet_ntoa(inet_aton("")),if the hostname cannot be resolved,
|
||||
#the value of inet_ntoa() will be "undef", which will cause fatal error
|
||||
if ( $nrent and $nrent->{tftpserver} and $nrent->{tftpserver} ne '<xcatmaster>' ) {
|
||||
# An IPv6 boot server is named in the DHCPv6 reservation, not in a
|
||||
# DHCPv4 next-server, so there is no answer to give and nothing wrong.
|
||||
return if xCAT::NetworkUtils->isIpv6addr( $nrent->{tftpserver} );
|
||||
my $tmp_name = inet_aton( $nrent->{tftpserver} );
|
||||
unless ($tmp_name) {
|
||||
|
||||
@@ -4592,6 +4595,7 @@ sub next_server_for_node
|
||||
}
|
||||
|
||||
if ( $nrent and $nrent->{xcatmaster} ) {
|
||||
return if xCAT::NetworkUtils->isIpv6addr( $nrent->{xcatmaster} );
|
||||
my $tmp_server = inet_aton( $nrent->{xcatmaster} );
|
||||
unless ($tmp_server) {
|
||||
$callback->({ error => ["Unable to resolve the tftpserver for $node, verify \"xcatmaster\" is set correctly"], errorcode => [1] });
|
||||
|
||||
@@ -53,6 +53,13 @@ BEGIN {
|
||||
return $server if $server =~ /:/ && isValidIp(__PACKAGE__, $server);
|
||||
return getipaddr($server, OnlyV6 => 1);
|
||||
}
|
||||
sub isIpv6addr {
|
||||
my $addr = $_[-1];
|
||||
return 0 unless defined($addr) && length($addr);
|
||||
return 0 if $addr =~ /%/;
|
||||
return 0 unless $addr =~ /:/;
|
||||
return $addr =~ /^[0-9a-fA-F:.]+$/ ? 1 : 0;
|
||||
}
|
||||
sub isValidIp {
|
||||
my $addr = $_[-1];
|
||||
return 0 unless defined($addr) && length($addr);
|
||||
@@ -1147,6 +1154,32 @@ foreach my $case (@sysconfig_policy_cases) {
|
||||
my @unresolvable = xCAT_plugin::dhcp::next_server_for_node( 'n1', { xcatmaster => 'no.such.host.invalid' } );
|
||||
is( scalar(@unresolvable), 0, 'an unresolvable xcatmaster yields no address' );
|
||||
like( ( $errors[0] || '' ), qr/xcatmaster/, 'and says which attribute to look at' );
|
||||
|
||||
# An IPv6 tftpserver or xcatmaster is not a DHCPv4 next-server. inet_aton
|
||||
# cannot read it, and reporting that as an error makes makedhcp fail for a
|
||||
# node whose boot server is named in the DHCPv6 reservation instead.
|
||||
@errors = ();
|
||||
my @v6_tftp = xCAT_plugin::dhcp::next_server_for_node(
|
||||
'n1', { tftpserver => '2001:db8:7309::1' } );
|
||||
is( scalar(@v6_tftp), 0, 'an IPv6 tftpserver yields no DHCPv4 next-server' );
|
||||
is_deeply( \@errors, [],
|
||||
'and reports no error, because a DHCPv4 answer was never due' );
|
||||
|
||||
@errors = ();
|
||||
my @v6_master = xCAT_plugin::dhcp::next_server_for_node(
|
||||
'n1', { xcatmaster => '2001:db8:7309::1' } );
|
||||
is( scalar(@v6_master), 0, 'an IPv6 xcatmaster yields no DHCPv4 next-server' );
|
||||
is_deeply( \@errors, [], 'and reports no error either' );
|
||||
|
||||
# A name that genuinely does not resolve still has to be reported, or the
|
||||
# check above would be satisfied by removing the error path altogether.
|
||||
@errors = ();
|
||||
my @broken = xCAT_plugin::dhcp::next_server_for_node(
|
||||
'n1', { tftpserver => 'no.such.host.invalid' } );
|
||||
is( scalar(@broken), 0, 'an unresolvable tftpserver yields no next-server' );
|
||||
like( ( $errors[0] || '' ), qr/tftpserver/,
|
||||
'and says which attribute to look at' );
|
||||
|
||||
}
|
||||
|
||||
my @normalized_mac_cases = (
|
||||
|
||||
Reference in New Issue
Block a user