From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3CA941FF0DA for ; Thu, 19 Nov 2026 20:43:38 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id EAEE92191B; Thu, 19 Nov 2026 20:42:09 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v3 21/28] sdn: dhcp: fix DNS server option for IPv4 subnets without gateway Date: Thu, 19 Nov 2026 20:41:07 +0100 Message-ID: <20261119194116.575520-22-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194116.575520-1-g.goller@proxmox.com> References: <20261119194116.575520-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795117282885 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.222 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: IQZNEFM2UBLZO5MQAB7CIWRUD2KS6QEA X-Message-ID-Hash: IQZNEFM2UBLZO5MQAB7CIWRUD2KS6QEA X-MailFrom: g.goller@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The option prefix was only set for IPv4 subnets with a gateway, so setting dhcp-dns-server on a subnet without one wrote an invalid line 'dhcp-option=tag:,:dns-server,' to the dnsmasq config. Signed-off-by: Gabriel Goller --- src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 11 +++----- src/PVE/Network/SDN/SubnetPlugin.pm | 8 +++++- src/test/run_test_vnets_blackbox.pl | 42 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index 9bf37307952f..a34883a97cf6 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -161,13 +161,10 @@ sub configure_subnet { push @{$config}, "dhcp-range=set:$tag,$network,static,$mask,infinite"; - my $option_string; - if (ip_is_ipv6($subnet_config->{network})) { - $option_string = 'option6'; - } elsif ($subnet_config->{gateway}) { - $option_string = 'option'; - push @{$config}, "dhcp-option=tag:$tag,$option_string:router,$subnet_config->{gateway}"; - } + my $option_string = $is_ipv4 ? 'option' : 'option6'; + + push @{$config}, "dhcp-option=tag:$tag,$option_string:router,$subnet_config->{gateway}" + if $is_ipv4 && $subnet_config->{gateway}; push @{$config}, "dhcp-option=tag:$tag,$option_string:dns-server,$subnet_config->{'dhcp-dns-server'}" diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm index 326c80ee3e90..8d4ad10b531f 100644 --- a/src/PVE/Network/SDN/SubnetPlugin.pm +++ b/src/PVE/Network/SDN/SubnetPlugin.pm @@ -180,7 +180,7 @@ sub properties { 'dhcp-dns-server' => { type => 'string', format => 'ip', - description => 'IP address for the DNS server', + description => 'DNS server IP address. Must use the same address family as the subnet.', optional => 1, }, }; @@ -229,6 +229,12 @@ sub on_update_hook { raise_param_exc({ gateway => "$gateway is not in subnet $cidr" }) if $gateway && !$subnet_matcher->($gateway) && !$pointopoint; + if (my $dns_server = $subnet->{'dhcp-dns-server'}) { + my ($network) = split('/', $cidr, 2); + raise_param_exc({ 'dhcp-dns-server' => 'Must use the same address family as the subnet' }) + if Net::IP::ip_get_version($dns_server) != Net::IP::ip_get_version($network); + } + validate_dhcp_ranges($subnet); if ($ipam) { diff --git a/src/test/run_test_vnets_blackbox.pl b/src/test/run_test_vnets_blackbox.pl index 067f4c1b9962..9b8091370267 100755 --- a/src/test/run_test_vnets_blackbox.pl +++ b/src/test/run_test_vnets_blackbox.pl @@ -1039,4 +1039,46 @@ sub test_update_vnet_without_zone { } run_test(\&test_update_vnet_without_zone); +sub test_dhcp_dns_server_family { + my $zoneid = 'TESTZONE'; + my $vnetid = 'testvnet'; + + create_zone({ type => 'simple', zone => $zoneid }); + create_vnet({ type => 'vnet', zone => $zoneid, vnet => $vnetid }); + + for my $case ( + ['192.0.2.0/24', '198.51.100.53', '2001:db8::53', '192.0.2.128/25'], + ['2001:db8::/64', '2001:db8:1::53', '198.51.100.53', '2001:db8:2::/64'], + ) { + my ($subnet, $dns, $wrong_dns, $other_subnet) = @$case; + my $id = "$zoneid-" . ($subnet =~ s!/!-!r); + + create_subnet({ + type => 'subnet', vnet => $vnetid, subnet => $subnet, 'dhcp-dns-server' => $dns, + }); + my $config = PVE::API2::Network::SDN::Subnets->read({ subnet => $id, vnet => $vnetid }); + is($config->{'dhcp-dns-server'}, $dns, "$subnet accepts a DNS server of its own family"); + + my $updated = eval { + PVE::API2::Network::SDN::Subnets->update({ + subnet => $id, vnet => $vnetid, 'dhcp-dns-server' => $wrong_dns, + }); + 1; + }; + ok(!$updated, "$subnet rejects a DNS server of the other family on update"); + + my $created = eval { + create_subnet({ + type => 'subnet', + vnet => $vnetid, + subnet => $other_subnet, + 'dhcp-dns-server' => $wrong_dns, + }); + 1; + }; + ok(!$created, "$other_subnet rejects a DNS server of the other family on create"); + } +} +run_test(\&test_dhcp_dns_server_family); + done_testing(); -- 2.47.3