From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 3DB521FF16F
	for <inbox@lore.proxmox.com>; Thu, 27 Feb 2025 10:10:20 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 81F5C2CF8A;
	Thu, 27 Feb 2025 10:10:18 +0100 (CET)
To: pve-devel@lists.proxmox.com
Date: Thu, 27 Feb 2025 13:02:27 +0400
MIME-Version: 1.0
Message-ID: <mailman.604.1740647417.293.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Matthieu Pignolet via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Matthieu Pignolet <m@mpgn.dev>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH] dns: powerdns: correctly handle different
 records types (A / AAAA)
Content-Type: multipart/mixed; boundary="===============4248749066387425876=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============4248749066387425876==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <m@mpgn.dev>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id 107B4D17FA
	for <pve-devel@lists.proxmox.com>; Thu, 27 Feb 2025 10:10:17 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id EE9802CF46
	for <pve-devel@lists.proxmox.com>; Thu, 27 Feb 2025 10:10:16 +0100 (CET)
Received: from tbjjbihbhdeb.turbo-smtp.net (tbjjbihbhdeb.turbo-smtp.net [199.187.173.41])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Thu, 27 Feb 2025 10:10:15 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mpgn.dev;
	s=turbo-smtp; x=1741252216; h=Received:Received:From:To:Cc:
	Subject:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:
	Feedback-Id; bh=TWA+rMRxmGZOda/xlsAp57wuYSXuywypmER7burc2Gc=;
	b=OjvycdefIvNT5Sf923xBRyReieuUmXYjqxgwefqoFcXZJfkBgihEQfQzOLACer
	Iuh9VHYm3WR2Q86rjYq2TRyiYU1UEGG3Hnuz6EryDmYgiFDTuGqkl8vnYFnicFPu
	CVGiYKnRLPiCDPbvpqVKvFCWB+L31bnGGhRpsodqOx32k=
Received: (qmail 1206664 invoked from network); 27 Feb 2025 09:03:34 -0000
Received: from ?UNAVAILABLE?  by turbo-smtp.com with SMTP; 27 Feb 2025 09:03:33 -0000
X-TurboSMTP-Tracking: 64-0162ab32-00001bd7ddc9d2016000-000-49b1698e
From: Matthieu Pignolet <m@mpgn.dev>
To: pve-devel@lists.proxmox.com
Subject: [PATCH] dns: powerdns: correctly handle different records types (A / AAAA)
Date: Thu, 27 Feb 2025 13:02:27 +0400
Message-ID: <20250227090227.180317-1-m@mpgn.dev>
X-Mailer: git-send-email 2.48.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Feedback-Id: 23243570
X-SPAM-LEVEL: Spam detection results:  0
	BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
	DKIM_SIGNED               0.1 Message has a DKIM or DK signature, not necessarily valid
	DKIM_VALID               -0.1 Message has at least one valid DKIM or DK signature
	DKIM_VALID_AU            -0.1 Message has a valid DKIM or DK signature from author's domain
	DKIM_VALID_EF            -0.1 Message has a valid DKIM or DK signature from envelope-from domain
	DMARC_PASS               -0.1 DMARC pass policy
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_PASS               -0.001 SPF: sender matches SPF record

This fixes an issue with dual stacking, when using a zone with both a V4 and V6
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>
---
 src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm b/src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm
index dae63d1..70b7b80 100644
--- a/src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm
+++ b/src/PVE/Network/SDN/Dns/PowerdnsPlugin.pm
@@ -57,7 +57,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}}) {
@@ -133,7 +133,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->@*);
@@ -278,10 +278,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
 }
-- 
2.48.1




--===============4248749066387425876==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============4248749066387425876==--