diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index 77eb3750f0..09e7c05705 100644 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -252,10 +252,10 @@ sub get_reverse_zones_for_entity { } elsif ($net =~ /:/) { #v6/ip6.arpa case $net =~ /\/(.*)/; my $maskbits = $1; - unless (defined($maskbits) && (($maskbits % 4) == 0)) { - die "Never expected this, $net should have had CIDR / notation... and the mask should be a factor of 4, if not, need work..." + unless (defined($maskbits)) { + die "Never expected this, $net should have had CIDR / notation" } - push @revs, xCAT::NetworkUtils->getIPv6ReverseZone($net); + push @revs, _ipv6_reverse_zone_of_number($tvar, $maskbits); } } } @@ -263,6 +263,31 @@ sub get_reverse_zones_for_entity { return @revs; } +#------------------------------------------------------- + +=head3 _ipv6_reverse_zone_of_number + + Descriptions: The ip6.arpa zone that holds one IPv6 address of a network. + A reverse zone is delegated on a nibble, so for a prefix that is not a + multiple of 4 the zone is the one of the next nibble. getzonesfornet + creates the same zones for that network. + Arguments: the address as a number (getipaddr GetNumber), the prefix length + Returns: the zone name + +=cut + +#------------------------------------------------------- +sub _ipv6_reverse_zone_of_number { + my ($number, $prefix) = @_; + + my $nibbles = int(($prefix + 3) / 4); + return 'ip6.arpa.' unless $nibbles; + my $hex = Math::BigInt->new($number)->as_hex; + $hex =~ s/^0x//; + $hex = substr(('0' x 32) . $hex, -32, $nibbles); + return join('.', reverse(split(//, $hex))) . '.ip6.arpa.'; +} + sub process_request { my $request = shift; $callback = shift; @@ -1296,16 +1321,17 @@ sub update_namedconf { push @newnamed, "\t\t" . $_ . ";\n"; } push @newnamed, "\t};\n"; - } elsif (defined($ctx->{dnslistenonifs}) and defined($ctx->{dnslistenonifs}->{ipv4}) and $line =~ /listen-on \{/) { + } elsif (defined($ctx->{dnslistenonifs}) and defined($ctx->{dnslistenonifs}->{ipv4}) and $line =~ /listen-on\s[^{]*\{/) { + # The distribution file writes "listen-on port 53 { ... };" on one line. push @newnamed, "\tlisten-on \{\n"; - $skip = 1; + $skip = ($line !~ /\};/); foreach (@{ $ctx->{dnslistenonifs}->{ipv4} }) { push @newnamed, "\t\t" . $_ . ";\n"; } push @newnamed, "\t};\n"; - } elsif (defined($ctx->{dnslistenonifs}) and defined($ctx->{dnslistenonifs}->{ipv6}) and $line =~ /listen-on-v6 \{/) { + } elsif (defined($ctx->{dnslistenonifs}) and defined($ctx->{dnslistenonifs}->{ipv6}) and $line =~ /listen-on-v6\s[^{]*\{/) { push @newnamed, "\tlisten-on-v6 \{\n"; - $skip = 1; + $skip = ($line !~ /\};/); foreach (@{ $ctx->{dnslistenonifs}->{ipv6} }) { push @newnamed, "\t\t" . $_ . ";\n"; } @@ -1536,10 +1562,11 @@ sub update_namedconf { push @newnamed, "\ttype slave;\n"; push @newnamed, "\tmasters { $output[0]; };\n"; } else { - push @newnamed, "\ttype master;\n", "\tallow-update {\n", "\t\tkey $omapi_key_name;\n", "\t};\n"; + push @newnamed, "\ttype master;\n", "\tallow-update {\n", "\t\tkey $omapi_key_name;\n"; foreach (@{ $ctx->{dnsupdaters} }) { push @newnamed, "\t\t$_;\n"; } + push @newnamed, "\t};\n"; } if ($zone =~ /IN-ADDR\.ARPA/) { my $net = $zone; @@ -1709,7 +1736,11 @@ sub add_or_delete_records { unless ($name =~ /\.$domain\z/) { $name .= "." . $domain } # $name needs to represent fqdn, but must preserve $node as a nodename for cfg lookup if ($ctx->{hoststab} and $ctx->{hoststab}->{$node} and $ctx->{hoststab}->{$node}->[0]->{ip}) { - @ips = ($ctx->{hoststab}->{$node}->[0]->{ip}); + my $hostip = $ctx->{hoststab}->{$node}->[0]->{ip}; + + # hosts.ip holds one address. The other family of a dual-stack node comes from the + # makehosts content, and it needs its PTR too. + @ips = ($hostip, grep { $_ ne $hostip } sort keys %{ $ctx->{nodeips}->{$node} || {} }); } else { @ips = getipaddr($node, GetAllAddresses => 1); if (not @ips and keys %{ $ctx->{nodeips}->{$node} }) { @@ -1819,7 +1850,7 @@ sub find_nameserver_for_dns { } while ($zone) { unless (defined $ctx->{nsmap}->{$zone}) { #ok, we already thought about this zone and made a decision - if ($zone =~ /^\.*192.IN-ADDR.ARPA\.*/ or $zone =~ /^\.*172.IN-ADDR.ARPA\.*/ or $zone =~ /127.IN-ADDR.ARPA\.*/ or $zone =~ /^\.*IN-ADDR.ARPA\.*/ or $zone =~ /^\.*ARPA\.*/) { + if ($zone =~ /^\.*(?:ip6\.)?arpa\.*$/i or $zone =~ /^\.*192.IN-ADDR.ARPA\.*/ or $zone =~ /^\.*172.IN-ADDR.ARPA\.*/ or $zone =~ /127.IN-ADDR.ARPA\.*/ or $zone =~ /^\.*IN-ADDR.ARPA\.*/ or $zone =~ /^\.*ARPA\.*/) { $ctx->{nsmap}->{$zone} = 0; #ignore zones that are likely to appear, but probably not ours } elsif ($::XCATSITEVALS{ddnsserver}) { $ctx->{nsmap}->{$zone} = $::XCATSITEVALS{ddnsserver};