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 9498C1FF0DA for ; Thu, 19 Nov 2026 20:43:22 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3D846217E8; Thu, 19 Nov 2026 20:42:09 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v3 20/28] sdn: dhcp: run dnsmasq in the zone VRF Date: Thu, 19 Nov 2026 20:41:06 +0100 Message-ID: <20261119194116.575520-21-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194116.575520-1-g.goller@proxmox.com> References: <20261119194116.575520-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795117282779 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.223 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: G3LGHL4GHNBUOBQYT7RAPJ5ABT2BMUYA X-Message-ID-Hash: G3LGHL4GHNBUOBQYT7RAPJ5ABT2BMUYA X-MailFrom: g.goller@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: DHCP and DNS did not work in Simple zones with a dedicated VRF. If a zone has more than one vnet with subnets, dnsmasq serves DHCP on a single socket that is not bound to any interface, and the kernel does not deliver packets from VRF slaves to such sockets unless net.ipv4.udp_l3mdev_accept is set. The DNS sockets are bound to the gateway addresses, which fails silently because the local routes of those addresses are only in the VRF table, so guests got a resolver that never answered. Start the dnsmasq instance of such zones through 'ip vrf exec' using a systemd drop-in, which binds all of its sockets to the zone VRF. This avoids changing the host-wide sysctl, which would also expose unbound host services to the zone. Upstream DNS servers have to be reachable from within the VRF. The VRF has to exist before dnsmasq starts, so the DHCP config must be generated after ifreload. pve-manager needs a matching change. Signed-off-by: Gabriel Goller --- src/PVE/Network/SDN/Dhcp/Dnsmasq.pm | 59 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm index 477b700f2429..9bf37307952f 100644 --- a/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm +++ b/src/PVE/Network/SDN/Dhcp/Dnsmasq.pm @@ -16,6 +16,10 @@ use PVE::RESTEnvironment qw(log_warn); my $DNSMASQ_CONFIG_ROOT = '/etc/dnsmasq.d'; my $DNSMASQ_DEFAULT_ROOT = '/etc/default'; my $DNSMASQ_LEASE_ROOT = '/var/lib/misc'; +my $SYSTEMD_UNIT_ROOT = '/etc/systemd/system'; +my $VRF_DROPIN_NAME = '00-pve-sdn-vrf.conf'; + +my $need_daemon_reload = 0; sub type { return 'dnsmasq'; @@ -193,6 +197,52 @@ sub systemctl_service { PVE::Tools::run_command(['systemctl', $action, $service]); } +my sub daemon_reload_if_needed { + return if !$need_daemon_reload; + PVE::Tools::run_command(['systemctl', 'daemon-reload']); + $need_daemon_reload = 0; +} + +my sub vrf_dropin_dir { + my ($dhcpid) = @_; + return "$SYSTEMD_UNIT_ROOT/dnsmasq\@$dhcpid.service.d"; +} + +# dnsmasq's DHCP and DNS sockets are not bound to a device, so they don't see +# traffic from VRF slaves. Starting it via 'ip vrf exec' binds every socket it +# creates to the zone VRF. +my sub write_vrf_dropin { + my ($dhcpid) = @_; + + my $dir = vrf_dropin_dir($dhcpid); + mkdir($dir, 0755) if !-d $dir; + + my $dropin = <{'dedicated-vrf'}; + my $config_directory = "$DNSMASQ_CONFIG_ROOT/$dhcpid"; mkdir($config_directory, 0755) if !-d $config_directory; @@ -286,6 +338,7 @@ sub after_configure { my $service_name = "dnsmasq\@$dhcpid"; + daemon_reload_if_needed(); systemctl_service('reload', 'dbus'); systemctl_service('enable', $service_name); systemctl_service('restart', $service_name); @@ -294,6 +347,8 @@ sub after_configure { sub before_regenerate { my ($class, $noerr) = @_; + remove_vrf_dropins(); + return if !assert_dnsmasq_installed($noerr); systemctl_service('stop', "dnsmasq@*"); @@ -302,7 +357,9 @@ sub before_regenerate { sub after_regenerate { my ($class) = @_; - # noop + + # a drop-in may have been removed without any DHCP zone left to reload + daemon_reload_if_needed(); } 1; -- 2.47.3