* [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets
@ 2026-11-23 16:48 Gabriel Goller
2026-11-24 9:22 ` Thomas Lamprecht
2026-11-24 9:28 ` Stefan Hanreich
0 siblings, 2 replies; 4+ messages in thread
From: Gabriel Goller @ 2026-11-23 16:48 UTC (permalink / raw)
To: pve-devel
A zone with DHCP enabled but no vnet with a subnet still got a dnsmasq
instance. The interface= line for a vnet is only written once the vnet
has a subnet, so the instance config only has except-interface=lo. With
bind-dynamic, dnsmasq then binds port 53 on every address of the host,
including the vnets of other zones. Zones are configured in sorted
order, so every DHCP zone after the empty one then fails to start:
dnsmasq: failed to create listening socket for fe80::d840:37ff:fea1:fa73%test2: Address already in use
dnsmasq: FAILED to start up
This was preexisting but zones with a dedicated VRF are affected too.
dnsmasq runs via "ip vrf exec", but it binds link-local addresses with
sin6_scope_id set to the interface. The kernel then replaces the VRF
binding of the socket with that interface, so the instance still binds
to host and other zone interfaces, and also answers DNS there.
Only enable and start dnsmasq for a zone if at least one of its vnets
has a subnet, and thus an interface= line. before_regenerate already
stops and disables all instances, so a skipped zone stays down.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
Note that with this patch, a DHCP zone without a vnet that has a subnet
no longer gets a dnsmasq instance, even if the user added custom config
files (e.g. 90-custom.conf) in etc/dnsmasq.d/<zone>. I don't expect
anyone to rely on this, since that instance would also bind to every
address on the host and break the other zones
---
src/PVE/Network/SDN/Dhcp.pm | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/PVE/Network/SDN/Dhcp.pm b/src/PVE/Network/SDN/Dhcp.pm
index 10d7ee917da5..47161208c802 100644
--- a/src/PVE/Network/SDN/Dhcp.pm
+++ b/src/PVE/Network/SDN/Dhcp.pm
@@ -97,6 +97,8 @@ sub regenerate_config {
eval { $dhcp_plugin->before_configure($zoneid, $zone) };
die "Could not run before_configure for DHCP server $zoneid $@\n" if $@;
+ my $has_dhcp_vnet = 0;
+
for my $vnetid (sort keys %{ $vnet_cfg->{ids} }) {
my $vnet = $vnet_cfg->{ids}->{$vnetid};
next if $vnet->{zone} ne $zoneid;
@@ -126,8 +128,13 @@ sub regenerate_config {
eval { $dhcp_plugin->configure_vnet($config, $zoneid, $vnetid, $vnet) };
warn "Could not configure vnet $vnetid: $@\n" if $@;
+ $has_dhcp_vnet = 1 if !$@ && @$config;
}
+ # Without a vnet to serve, the DHCP server isn't restricted to any interface and binds to
+ # every address on the host, including those on vnets of other zones.
+ next if !$has_dhcp_vnet;
+
eval { $dhcp_plugin->after_configure($zoneid, !$any_zone_needs_dhcp) };
warn "Could not run after_configure for DHCP server $zoneid $@\n" if $@;
---
base-commit: e933d383aebdff9f31f6d00986331fc6e6dd898b
change-id: 20261123-sdn_dhcp_do-02a78a052589
Best regards,
--
Gabriel Goller <g.goller@proxmox.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets
2026-11-23 16:48 [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets Gabriel Goller
@ 2026-11-24 9:22 ` Thomas Lamprecht
2026-11-24 9:33 ` Stefan Hanreich
2026-11-24 9:28 ` Stefan Hanreich
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Lamprecht @ 2026-11-24 9:22 UTC (permalink / raw)
To: pve-devel, Gabriel Goller
On Mon, 23 Nov 2026 17:48:03 +0100, Gabriel Goller wrote:
> A zone with DHCP enabled but no vnet with a subnet still got a dnsmasq
> instance. The interface= line for a vnet is only written once the vnet
> has a subnet, so the instance config only has except-interface=lo. With
> bind-dynamic, dnsmasq then binds port 53 on every address of the host,
> including the vnets of other zones. Zones are configured in sorted
> order, so every DHCP zone after the empty one then fails to start:
>
> [...]
Applied, thanks!
This caused a new case for guest start or vNIC hot-plug a vnet of a zone
that no longer gets a dnsmasq instance, as adding the IP mapping tried
to reload the stopped dnsmasq instance. So I applied a commit before
yours that only reloads dnsmasq and updates the lease if the instance is
actually enabled, and still writes the ethers entry otherwise. Please
double check that this fits how you want the DHCP code to work.
Also added a follow-up that configures dnsmasq with the applied subnets
instead of the pending ones.
FWIW, before_configure still writes the defaults, the D-Bus policy and
the VRF drop-in for the zones that are skipped now, but shouldn't really
hurt either, so I left it for now.
[1/1] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets
commit: 9274b07d1f5f75c5008b25a90183782c8c8fa769
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets
2026-11-23 16:48 [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets Gabriel Goller
2026-11-24 9:22 ` Thomas Lamprecht
@ 2026-11-24 9:28 ` Stefan Hanreich
1 sibling, 0 replies; 4+ messages in thread
From: Stefan Hanreich @ 2026-11-24 9:28 UTC (permalink / raw)
To: pve-devel
tested on a node with two simple zones that contain no vnets
applying without the patch failed and left a dnsmasq instance
on all ifaces, whereas with the patch it worked.
Another issue on guest startup was flagged, that we could
improve as well. We reload dnsmasq for guests after adding an
IP mapping which can make guest startup fail if the dnsmasq
instance is not running. Can reproduce by having a simple
zone with an IPv6 subnet but no gateway. Can be fixed
independently of this patch imo.
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich@proxmox.com>
On 11/23/26 5:48 PM, Gabriel Goller wrote:
> A zone with DHCP enabled but no vnet with a subnet still got a dnsmasq
> instance. The interface= line for a vnet is only written once the vnet
> has a subnet, so the instance config only has except-interface=lo. With
> bind-dynamic, dnsmasq then binds port 53 on every address of the host,
> including the vnets of other zones. Zones are configured in sorted
> order, so every DHCP zone after the empty one then fails to start:
>
> dnsmasq: failed to create listening socket for fe80::d840:37ff:fea1:fa73%test2: Address already in use
> dnsmasq: FAILED to start up
>
> This was preexisting but zones with a dedicated VRF are affected too.
> dnsmasq runs via "ip vrf exec", but it binds link-local addresses with
> sin6_scope_id set to the interface. The kernel then replaces the VRF
> binding of the socket with that interface, so the instance still binds
> to host and other zone interfaces, and also answers DNS there.
>
> Only enable and start dnsmasq for a zone if at least one of its vnets
> has a subnet, and thus an interface= line. before_regenerate already
> stops and disables all instances, so a skipped zone stays down.
>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> Note that with this patch, a DHCP zone without a vnet that has a subnet
> no longer gets a dnsmasq instance, even if the user added custom config
> files (e.g. 90-custom.conf) in etc/dnsmasq.d/<zone>. I don't expect
> anyone to rely on this, since that instance would also bind to every
> address on the host and break the other zones
> ---
> src/PVE/Network/SDN/Dhcp.pm | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/src/PVE/Network/SDN/Dhcp.pm b/src/PVE/Network/SDN/Dhcp.pm
> index 10d7ee917da5..47161208c802 100644
> --- a/src/PVE/Network/SDN/Dhcp.pm
> +++ b/src/PVE/Network/SDN/Dhcp.pm
> @@ -97,6 +97,8 @@ sub regenerate_config {
> eval { $dhcp_plugin->before_configure($zoneid, $zone) };
> die "Could not run before_configure for DHCP server $zoneid $@\n" if $@;
>
> + my $has_dhcp_vnet = 0;
> +
> for my $vnetid (sort keys %{ $vnet_cfg->{ids} }) {
> my $vnet = $vnet_cfg->{ids}->{$vnetid};
> next if $vnet->{zone} ne $zoneid;
> @@ -126,8 +128,13 @@ sub regenerate_config {
>
> eval { $dhcp_plugin->configure_vnet($config, $zoneid, $vnetid, $vnet) };
> warn "Could not configure vnet $vnetid: $@\n" if $@;
> + $has_dhcp_vnet = 1 if !$@ && @$config;
> }
>
> + # Without a vnet to serve, the DHCP server isn't restricted to any interface and binds to
> + # every address on the host, including those on vnets of other zones.
> + next if !$has_dhcp_vnet;
> +
> eval { $dhcp_plugin->after_configure($zoneid, !$any_zone_needs_dhcp) };
> warn "Could not run after_configure for DHCP server $zoneid $@\n" if $@;
>
>
> ---
> base-commit: e933d383aebdff9f31f6d00986331fc6e6dd898b
> change-id: 20261123-sdn_dhcp_do-02a78a052589
>
> Best regards,
> --
> Gabriel Goller <g.goller@proxmox.com>
>
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets
2026-11-24 9:22 ` Thomas Lamprecht
@ 2026-11-24 9:33 ` Stefan Hanreich
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hanreich @ 2026-11-24 9:33 UTC (permalink / raw)
To: pve-devel
On 11/24/26 10:26 AM, Thomas Lamprecht wrote:
> This caused a new case for guest start or vNIC hot-plug a vnet of a zone
> that no longer gets a dnsmasq instance, as adding the IP mapping tried
> to reload the stopped dnsmasq instance. So I applied a commit before
> yours that only reloads dnsmasq and updates the lease if the instance is
> actually enabled, and still writes the ethers entry otherwise. Please
> double check that this fits how you want the DHCP code to work.
Beat me to it. I was also thinking about how we want to handle this, imo
if the zone should be managed DHCP + IPAM, it seems reasonable to fail
in such a scenario. But there are probably other instance where we do not
hard fail on encountering an error. Should be made consistent one way or
the other imo.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 9:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 16:48 [PATCH network] sdn: dhcp: do not start dnsmasq for zones without a vnet with subnets Gabriel Goller
2026-11-24 9:22 ` Thomas Lamprecht
2026-11-24 9:33 ` Stefan Hanreich
2026-11-24 9:28 ` Stefan Hanreich
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.