public inbox for pve-devel@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 05/15] sdn: dhcp: make the lease time configurable per subnet
Date: Mon,  2 Nov 2026 16:18:32 +0100	[thread overview]
Message-ID: <20261102151842.1605234-6-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261102151842.1605234-1-h.laimer@proxmox.com>

dnsmasq hands out infinite leases, so a guest asks for its address
again only at its next reboot or network restart. A finite lease makes
it renew within the lease time. An address changed in the IPAM goes to
dnsmasq on the node the change is made on, so a guest there picks up
the new address at its next renewal. Guests on other nodes get it only
at their next start there.

A subnet without a lease time keeps infinite leases.

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 |  3 +-
 src/PVE/Network/SDN/SubnetPlugin.pm | 11 +++++++
 src/test/run_test_vnets_blackbox.pl | 51 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
index 752588b98352..5ca16c8610e9 100644
--- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
+++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm
@@ -193,7 +193,8 @@ sub configure_subnet {
         $mask = join('.', unpack("C4", pack("N", $mask)));
     }
 
-    push @{$config}, "dhcp-range=set:$tag,$network,static,$mask,infinite";
+    my $lease = $subnet_config->{'dhcp-lease-time'} // 'infinite';
+    push @{$config}, "dhcp-range=set:$tag,$network,static,$mask,$lease";
 
     my $option_string;
     if (ip_is_ipv6($subnet_config->{network})) {
diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm
index e2a0e50d0211..29edf7b65330 100644
--- a/src/PVE/Network/SDN/SubnetPlugin.pm
+++ b/src/PVE/Network/SDN/SubnetPlugin.pm
@@ -177,6 +177,16 @@ sub properties {
             description => 'IP address for the DNS server',
             optional => 1,
         },
+        'dhcp-lease-time' => {
+            type => 'integer',
+            minimum => 60,
+            maximum => 4294967295,
+            description =>
+                'Lease time in seconds for DHCP answers. Without it dnsmasq hands out'
+                . ' infinite leases, and it raises anything below two minutes to two'
+                . ' minutes.',
+            optional => 1,
+        },
     };
 }
 
@@ -189,6 +199,7 @@ sub options {
         dnszoneprefix => { optional => 1 },
         'dhcp-range' => { optional => 1 },
         'dhcp-dns-server' => { optional => 1 },
+        'dhcp-lease-time' => { optional => 1 },
     };
 }
 
diff --git a/src/test/run_test_vnets_blackbox.pl b/src/test/run_test_vnets_blackbox.pl
index 7a16468c0eaa..5ba6485525c6 100755
--- a/src/test/run_test_vnets_blackbox.pl
+++ b/src/test/run_test_vnets_blackbox.pl
@@ -366,6 +366,11 @@ sub create_dhcp_subnet {
     });
 }
 
+sub update_subnet {
+    my ($params) = @_;
+    PVE::API2::Network::SDN::Subnets->update($params);
+}
+
 sub get_ipam_entries {
     return PVE::API2::Network::SDN::Ipams->ipamindex({ ipam => "pve" });
 }
@@ -1265,6 +1270,52 @@ sub test_dnsmasq_mapping_push {
 
 run_test(\&test_dnsmasq_mapping_push);
 
+sub test_dnsmasq_lease_time {
+    my $test_name = (split(/::/, (caller(0))[3]))[-1];
+    my $zoneid = "TESTZONE";
+    my $vnetid = "testvnet";
+
+    # the subnet's lease time reaches the range, and infinite stays the default
+    create_zone({
+        type => "simple",
+        dhcp => "dnsmasq",
+        ipam => "pve",
+        zone => $zoneid,
+    });
+    create_vnet({
+        type => "vnet",
+        zone => $zoneid,
+        vnet => $vnetid,
+    });
+    create_subnet({
+        type => "subnet",
+        vnet => $vnetid,
+        subnet => "10.0.0.0/24",
+        gateway => "10.0.0.1",
+        'dhcp-range' => ["start-address=10.0.0.100,end-address=10.0.0.200"],
+    });
+    my $range = sub {
+        my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
+        my $config = [];
+        for my $id (sort keys %$subnets) {
+            PVE::Network::SDN::Dhcp::Dnsmasq->configure_subnet(
+                $config, $zoneid, $vnetid, $subnets->{$id},
+            );
+        }
+        my ($line) = grep { m/^dhcp-range=/ } @$config;
+        return $line;
+    };
+    like($range->(), qr/,infinite$/, "$test_name: no lease time means infinite leases");
+    update_subnet({
+        vnet => $vnetid,
+        subnet => "$zoneid-10.0.0.0-24",
+        'dhcp-lease-time' => 300,
+    });
+    like($range->(), qr/,300$/, "$test_name: the lease time reaches the range");
+}
+
+run_test(\&test_dnsmasq_lease_time);
+
 sub test_mapping_edit_target {
     my $test_name = (split(/::/, (caller(0))[3]))[-1];
     my $zoneid = "TESTZONE";
-- 
2.47.3





  parent reply	other threads:[~2026-11-02 15:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 15:18 [PATCH container/docs/manager/network/proxmox{-ebpf,-perl-rs,-ve-rs}/qemu-server v5 00/15] sdn: implement DHCP for all zones using eBPF Hannes Laimer
2026-11-02 15:18 ` [PATCH proxmox-ebpf v5 01/15] dhcp: add the per-tap DHCPv4 responder program Hannes Laimer
2026-11-02 15:18 ` [PATCH proxmox-ebpf v5 02/15] dhcp: add the subsystem that loads the responder and keeps its records Hannes Laimer
2026-11-02 15:18 ` [PATCH proxmox-perl-rs v5 03/15] pve-rs: sdn: add bindings for the eBPF DHCP responder Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-network v5 04/15] sdn: zones: take the VXLAN and EVPN MTU from the underlay interface Hannes Laimer
2026-11-02 15:18 ` Hannes Laimer [this message]
2026-11-02 15:18 ` [PATCH pve-network v5 06/15] sdn: dhcp: require a backend only if a zone on this node uses it Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-network v5 07/15] sdn: dhcp: add an eBPF backend answering on each guest interface Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-network v5 08/15] sdn: zones: report interface plugs and unplugs to the DHCP backends Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-network v5 09/15] sdn: zones: allow the ebpf DHCP backend on every zone type Hannes Laimer
2026-11-02 15:18 ` [PATCH qemu-server v5 10/15] network: sdn: keep the DHCP backends current on guest NICs Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-container v5 11/15] net: report NIC plugs and removals to the SDN DHCP backends Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-manager v5 12/15] ui: sdn: add zone DHCP backend selector and subnet DHCP options Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-manager v5 13/15] sdn: bring up the DHCP backends at boot before the guests start Hannes Laimer
2026-11-02 15:18 ` [PATCH proxmox-ve-rs v5 14/15] ve-config: sdn: add the ebpf dhcp backend Hannes Laimer
2026-11-02 15:18 ` [PATCH pve-docs v5 15/15] sdn: dhcp: add eBPF backend section 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=20261102151842.1605234-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal