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 268A01FF0C0 for ; Wed, 21 Oct 2026 10:45:52 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9D8F42160B; Wed, 21 Oct 2026 10:45:42 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v4 07/20] sdn: dhcp: replace a stale dnsmasq reservation instead of dropping it Date: Wed, 21 Oct 2026 10:44:32 +0200 Message-ID: <20261021084445.462195-8-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261021084445.462195-1-h.laimer@proxmox.com> References: <20261021084445.462195-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792572308709 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.375 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: SUETJ7ORAJC4UN6CI3GCWGSWDSLZPFUR X-Message-ID-Hash: SUETJ7ORAJC4UN6CI3GCWGSWDSLZPFUR X-MailFrom: h.laimer@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: A reservation rewrite dropped every line that no longer matched the MAC cache and wrote nothing in its place. The guest behind such a line was unknown to dnsmasq until its next start, so its requests were ignored. The line is now replaced by the cache's current one. Only a MAC the cache holds no address for is dropped. Signed-off-by: Hannes Laimer Reviewed-by: Stefan Hanreich Tested-by: Stefan Hanreich --- src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 11 ++++++++++- src/test/run_test_vnets_blackbox.pl | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index d3b78fe9..a1e4c70f 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -91,7 +91,9 @@ sub add_ip_mapping { } $parsed_ip6 = $1 if $parsed_ip6 && $parsed_ip6 =~ m/\[(\S+)\]/; - #delete changed + # a line that no longer matches the cache is replaced by the cache's + # current one. Dropping it left that guest unknown to dnsmasq until + # its next start if ( !defined($macdb->{macs}->{$parsed_mac}) || ($parsed_ip4 @@ -102,6 +104,13 @@ sub add_ip_mapping { && $macdb->{macs}->{$parsed_mac}->{'ip6'} ne $parsed_ip6) ) { $reload = 1; + # the MAC being added gets its line below, like a missing one + my $current = $macdb->{macs}->{$parsed_mac}; + next if $parsed_mac eq $mac || !$current; + my $replacement = $parsed_mac; + $replacement .= ",$current->{ip4}" if $current->{ip4}; + $replacement .= ",[$current->{ip6}]" if $current->{ip6}; + print $out "$replacement\n" if $replacement ne $parsed_mac; next; } diff --git a/src/test/run_test_vnets_blackbox.pl b/src/test/run_test_vnets_blackbox.pl index 6b89778f..adad5e9a 100755 --- a/src/test/run_test_vnets_blackbox.pl +++ b/src/test/run_test_vnets_blackbox.pl @@ -1095,4 +1095,32 @@ run_test( 2, ); +sub test_dnsmasq_stale_reservation_replaced { + my $test_name = (split(/::/, (caller(0))[3]))[-1]; + + my $stale = "da:65:8f:18:9b:01"; + my $gone = "da:65:8f:18:9b:02"; + my $added = "da:65:8f:18:9b:03"; + $test_state->{macdb} = { + macs => { + $stale => { ip4 => '10.0.1.11' }, + $added => { ip4 => '10.0.1.13' }, + }, + }; + PVE::Tools::file_set_contents($TMP_ETHERS_FILE, "$stale,10.0.1.10\n$gone,10.0.1.12\n"); + + PVE::Network::SDN::Dhcp::Dnsmasq->add_ip_mapping( + 'TESTZONE', $test_state->{macdb}, $added, '10.0.1.13', undef, + ); + + my @lines = sort grep { /\S/ } split(/\n/, PVE::Tools::file_get_contents($TMP_ETHERS_FILE)); + eq_or_diff( + \@lines, + ["$stale,10.0.1.11", "$added,10.0.1.13"], + "$test_name: the stale line is replaced, the unknown one dropped", + ); +} + +run_test(\&test_dnsmasq_stale_reservation_replaced); + done_testing(); -- 2.47.3