From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 3439A1FF0AA for ; Tue, 20 Oct 2026 15:17:09 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E23D6216AC; Tue, 20 Oct 2026 15:17:07 +0200 (CEST) Message-ID: Date: Tue, 20 Oct 2026 15:17:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH pve-network v3 07/17] sdn: dhcp: make the lease time configurable per subnet To: pve-devel@lists.proxmox.com References: <20261020080005.470757-1-h.laimer@proxmox.com> <20261020080005.470757-8-h.laimer@proxmox.com> Content-Language: en-US From: Stefan Hanreich In-Reply-To: <20261020080005.470757-8-h.laimer@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.374 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: KYBN7VGZ7WEV6KY3P3U6YPBNAI4D5VQ5 X-Message-ID-Hash: KYBN7VGZ7WEV6KY3P3U6YPBNAI4D5VQ5 X-MailFrom: s.hanreich@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: Reviewed-by: Stefan Hanreich Tested-by: Stefan Hanreich On 10/20/26 10:00 AM, Hannes Laimer wrote: > 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 > --- > 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 57ce1f73..c6c9ce1d 100644 > --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm > +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm > @@ -200,7 +200,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 e2a0e50d..29edf7b6 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 476e7f8d..dc54bba3 100755 > --- a/src/test/run_test_vnets_blackbox.pl > +++ b/src/test/run_test_vnets_blackbox.pl > @@ -334,6 +334,11 @@ sub create_subnet { > PVE::API2::Network::SDN::Subnets->create($params); > } > > +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" }); > } > @@ -1118,6 +1123,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_ipam_cache_misses { > my $test_name = (split(/::/, (caller(0))[3]))[-1]; > my $zoneid = "TESTZONE";