all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v5 04/13] sdn: dhcp: replace a stale dnsmasq reservation instead of dropping it
Date: Wed,  4 Nov 2026 10:55:11 +0100	[thread overview]
Message-ID: <20261104095520.398544-5-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261104095520.398544-1-h.laimer@proxmox.com>

Adding a reservation rewrote the zone's dnsmasq reservation file and
dropped every line that no longer matched the MAC cache. Since dnsmasq
answers only MACs with a reservation, the guest behind such a line got
no DHCP answer until its next start. Such a line now gets the
addresses the cache holds for its MAC, and is dropped only when the
cache holds none.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich@proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 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 dc70b9a99a2e..c736d02d8f23 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, a dropped one would leave 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 be4c581e414e..90241268077c 100755
--- a/src/test/run_test_vnets_blackbox.pl
+++ b/src/test/run_test_vnets_blackbox.pl
@@ -1107,4 +1107,32 @@ sub test_update_vnet_without_zone {
 }
 run_test(\&test_update_vnet_without_zone);
 
+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





  parent reply	other threads:[~2026-11-04  9:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  9:55 [PATCH docs/manager/network/qemu-server v5 00/13] sdn: improve MAC cache, DHCP reservations and scope both to the vnet Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 01/13] sdn: ipam: stop caching IPAM misses Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 02/13] sdn: ipam: cache a MAC lookup's answer under the cluster lock Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 03/13] sdn: ipam: read the MAC cache case-insensitively Hannes Laimer
2026-11-04  9:55 ` Hannes Laimer [this message]
2026-11-04  9:55 ` [PATCH pve-network v5 05/13] sdn: ipam: release an address the built-in IPAM no longer holds Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 06/13] sdn: dhcp: update reservations when IP mappings change Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 07/13] sdn: ipam: look a MAC up within the vnet's subnets Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 08/13] sdn: ipam: keep the MAC cache per vnet Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-network v5 09/13] sdn: ipam: give each zone a VRF in NetBox and a section in phpIPAM Hannes Laimer
2026-11-04  9:55 ` [PATCH qemu-server v5 10/13] network: sdn: push the DHCP mappings of a guest when it resumes Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-manager v5 11/13] ui: sdn: dhcp tree: do not merge the same subnet in different zones Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-manager v5 12/13] ui: sdn: ipam: add the zone namespace options Hannes Laimer
2026-11-04  9:55 ` [PATCH pve-docs v5 13/13] sdn: ipam: document zone namespaces in NetBox and phpIPAM Hannes Laimer
2026-11-05  9:36 ` superseded: [PATCH docs/manager/network/qemu-server v5 00/13] sdn: improve MAC cache, DHCP reservations and scope both to the vnet Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104095520.398544-5-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal