]> git.puffer.fish Git - mirror/pve-network.git/commitdiff
dns: powerdns: correctly handle different records types (A / AAAA)
authorMatthieu Pignolet <m@mpgn.dev>
Thu, 27 Feb 2025 09:02:27 +0000 (13:02 +0400)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 25 Mar 2025 18:30:57 +0000 (19:30 +0100)
This fixes an issue with dual stacking, when using a zone with both a
IPv4 and IPv6 subnet and the same DNS suffix, pve-network will try to
set both DNS records (type A and AAAA) in the same powerdns rrset,
causing an API error, and effectively causing no forward DNS records
being created.

This change edits the `get_zone_rrset` function so that it takes the
DNS record type into account.

Signed-off-by: Matthieu Pignolet <m@mpgn.dev>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
 [TL: wrap commit message]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm

index 15afb4a7257874468a7ddbd9ba13bb7407829155..aad8b6f1fd9db87998a66a7032cdd02aea322535 100644 (file)
@@ -66,7 +66,7 @@ sub add_a_record {
     my $fqdn = $hostname.".".$zone.".";
 
     my $zonecontent = get_zone_content($plugin_config, $zone);
-    my $existing_rrset = get_zone_rrset($zonecontent, $fqdn);
+    my $existing_rrset = get_zone_rrset($zonecontent, $fqdn, $type);
 
     my $final_records = [];
     for my $record (@{$existing_rrset->{records}}) {
@@ -136,7 +136,7 @@ sub del_a_record {
     my $type = Net::IP::ip_is_ipv6($ip) ? "AAAA" : "A";
 
     my $zonecontent = get_zone_content($plugin_config, $zone);
-    my $existing_rrset = get_zone_rrset($zonecontent, $fqdn);
+    my $existing_rrset = get_zone_rrset($zonecontent, $fqdn, $type);
 
     my $final_records = [ grep { $_->{content} ne $ip } $existing_rrset->{records}->@* ];
     my $final_records_size = scalar($final_records->@*);
@@ -262,10 +262,10 @@ sub get_zone_content {
 }
 
 sub get_zone_rrset {
-    my ($zonecontent, $name) = @_;
+    my ($zonecontent, $name, $type) = @_;
 
     for my $rrset (@{$zonecontent->{rrsets}}) {
-       return $rrset if $rrset->{name} eq $name;
+       return $rrset if $rrset->{name} eq $name and ($rrset->{type} eq $type);
     }
     return; # not found
 }