all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v3 25/32] sdn: dhcp: run dnsmasq in the zone VRF
Date: Mon, 16 Nov 2026 17:11:45 +0100	[thread overview]
Message-ID: <20261116161154.343743-26-g.goller@proxmox.com> (raw)
In-Reply-To: <20261116161154.343743-1-g.goller@proxmox.com>

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 <g.goller@proxmox.com>
---
 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 = <<EOF;
+[Service]
+ExecStart=
+ExecStart=/usr/bin/ip vrf exec vrf_$dhcpid /usr/share/dnsmasq/systemd-helper exec "%i"
+EOF
+
+    PVE::Tools::file_set_contents("$dir/$VRF_DROPIN_NAME", $dropin);
+    $need_daemon_reload = 1;
+}
+
+my sub remove_vrf_dropins {
+    PVE::Tools::dir_glob_foreach(
+        $SYSTEMD_UNIT_ROOT,
+        'dnsmasq@.+\.service\.d',
+        sub {
+            my ($dir) = @_;
+            my $file = "$SYSTEMD_UNIT_ROOT/$dir/$VRF_DROPIN_NAME";
+            return if !-e $file;
+
+            unlink($file) or die "failed to remove $file - $!\n";
+            rmdir("$SYSTEMD_UNIT_ROOT/$dir"); # fails if other drop-ins are left
+            $need_daemon_reload = 1;
+        },
+    );
+}
+
 sub before_configure {
     my ($class, $dhcpid, $zone_cfg) = @_;
 
@@ -220,6 +270,8 @@ DBUSCFG
         "/etc/dbus-1/system.d/dnsmasq.$dhcpid.conf", $dbus_config,
     );
 
+    write_vrf_dropin($dhcpid) if $zone_cfg->{'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





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

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:11 [PATCH common/manager/network/proxmox{-ve-rs,-perl-rs,-widget-toolkit} v3 00/32] SDN VRF support Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-common v3 01/32] interfaces: preserve VRF membership across address family changes Gabriel Goller
2026-11-18 14:13   ` Stefan Hanreich
2026-11-18 15:41     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 02/32] frr: add VRF-aware OSPF rendering Gabriel Goller
2026-11-18 14:41   ` Stefan Hanreich
2026-11-18 16:21     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 03/32] sdn: add zone references to OSPF and BGP fabrics Gabriel Goller
2026-11-18 14:10   ` Stefan Hanreich
2026-11-18 16:55     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 04/32] sdn: generate fabric routing configuration in zone VRFs Gabriel Goller
2026-11-18 14:53   ` Stefan Hanreich
2026-11-18 17:26     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 05/32] sdn: fix VRF route-map scoping and zone ID validation Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 06/32] tests: fabrics: add test for fabrics in VRFs Gabriel Goller
2026-11-18 15:01   ` Stefan Hanreich
2026-11-18 17:33     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 07/32] sdn: allow static routes in simple zone VRFs Gabriel Goller
2026-11-18 15:29   ` Stefan Hanreich
2026-11-18 18:10     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-ve-rs v3 08/32] sdn: support static routes in EVPN " Gabriel Goller
2026-11-18 15:32   ` Stefan Hanreich
2026-11-19 13:12     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-perl-rs v3 09/32] pve-rs: fabrics: assign network interfaces to configured VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-perl-rs v3 10/32] pve-rs: fabrics: make per-fabric status queries VRF-aware Gabriel Goller
2026-11-18 15:42   ` Stefan Hanreich
2026-11-19 13:30     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-perl-rs v3 11/32] pve-rs: fabrics: include VRF routes in aggregate status Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-perl-rs v3 12/32] pve-rs: fabrics: expose host interface membership Gabriel Goller
2026-11-16 16:11 ` [PATCH proxmox-perl-rs v3 13/32] sdn: expose static routes for simple zone uplinks Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 14/32] sdn: evpn: add unreachable IPv6 default route to zone VRFs Gabriel Goller
2026-11-18 16:08   ` Stefan Hanreich
2026-11-18 16:39     ` Stefan Hanreich
2026-11-19 13:38       ` Gabriel Goller
2026-11-19 15:51         ` Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 15/32] sdn: add optional VRFs for simple zones Gabriel Goller
2026-11-18 16:18   ` Stefan Hanreich
2026-11-19 13:44     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 16/32] sdn: allow fabrics to use simple zone VRFs Gabriel Goller
2026-11-18 16:27   ` Stefan Hanreich
2026-11-19 14:14     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 17/32] sdn: require underlay fabrics to use the default VRF Gabriel Goller
2026-11-18 16:30   ` Stefan Hanreich
2026-11-19 14:33     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 18/32] sdn: always generate EVPN zone VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 19/32] api: sdn: allow EVPN zones as fabric VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 20/32] api: sdn: disallow BGP fabrics in EVPN zone VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 21/32] sdn: simple: support static routes in zone routing tables Gabriel Goller
2026-11-18 16:49   ` Stefan Hanreich
2026-11-19 14:53     ` Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 22/32] sdn: evpn: allow static routes Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-network v3 23/32] sdn: zones: SNAT via dedicated uplinks in zone VRFs Gabriel Goller
2026-11-18 18:07   ` Stefan Hanreich
2026-11-16 16:11 ` [PATCH pve-network v3 24/32] sdn: dhcp: only configure DHCP for zones on the local node Gabriel Goller
2026-11-16 16:11 ` Gabriel Goller [this message]
2026-11-16 16:11 ` [PATCH proxmox-widget-toolkit v3 26/32] ui: network: allow selecting a VRF for host interfaces Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 27/32] ui: sdn: add VRF zone selection for fabrics Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 28/32] ui: sdn: expose EVPN zones as fabric VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 29/32] network: allow setting the VRF of host interfaces Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 30/32] ui: sdn: allow static routes for Simple zone VRFs Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 31/32] ui: sdn: allow static routes in EVPN zones Gabriel Goller
2026-11-16 16:11 ` [PATCH pve-manager v3 32/32] network: generate SDN DHCP config after ifreload Gabriel Goller
2026-11-18 18:27 ` [PATCH common/manager/network/proxmox{-ve-rs,-perl-rs,-widget-toolkit} v3 00/32] SDN VRF support Stefan Hanreich
2026-11-19 15:33   ` Gabriel Goller
2026-11-19 20:10 ` Gabriel Goller

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=20261116161154.343743-26-g.goller@proxmox.com \
    --to=g.goller@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