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 22A0B1FF0DA for ; Thu, 19 Nov 2026 20:48:02 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id DB28A21946; Thu, 19 Nov 2026 20:46:56 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-firewall 11/14] firewall: put guest traffic of zone VRFs into their conntrack zone Date: Thu, 19 Nov 2026 20:45:43 +0100 Message-ID: <20261119194547.674512-12-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194547.674512-1-s.hanreich@proxmox.com> References: <20261119194547.674512-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795117557494 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: LP4MVFBMD5AVMUYDPOT5PXILOBVK4FON X-Message-ID-Hash: LP4MVFBMD5AVMUYDPOT5PXILOBVK4FON 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: Bridge conntrack tracks the connections of guests as soon as the guest table uses conntrack, and routed packets keep that entry in the inet hooks. The conntrack zones set by the sdn-ct-zones command therefore come too late for guest traffic. Set the conntrack zone of the VRF for the traffic of its vnets in a chain of the guest table that runs before bridge conntrack. As the chain is part of the guest table, it exists exactly when bridge conntrack is in use. The conntrack zones are taken from the SDN running config. Signed-off-by: Stefan Hanreich --- .../resources/proxmox-firewall.nft | 13 ++++++++ proxmox-firewall/src/config.rs | 8 +++++ proxmox-firewall/src/firewall.rs | 30 +++++++++++++++++++ .../tests/input/.running-config.json | 4 ++- .../integration_tests__firewall.snap | 24 +++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/proxmox-firewall/resources/proxmox-firewall.nft b/proxmox-firewall/resources/proxmox-firewall.nft index 2675727..af69248 100644 --- a/proxmox-firewall/resources/proxmox-firewall.nft +++ b/proxmox-firewall/resources/proxmox-firewall.nft @@ -44,6 +44,7 @@ add chain bridge proxmox-firewall-guests pre-vm-in add chain bridge proxmox-firewall-guests vm-in {type filter hook postrouting priority 0; policy accept;} add chain bridge proxmox-firewall-guests before-bridge add chain bridge proxmox-firewall-guests forward {type filter hook forward priority 0; policy accept;} +add chain bridge proxmox-firewall-guests sdn-ct-zone {type filter hook prerouting priority -310; policy accept;} flush chain inet proxmox-firewall do-reject flush chain inet proxmox-firewall accept-management @@ -84,6 +85,7 @@ flush chain bridge proxmox-firewall-guests pre-vm-in flush chain bridge proxmox-firewall-guests vm-in flush chain bridge proxmox-firewall-guests before-bridge flush chain bridge proxmox-firewall-guests forward +flush chain bridge proxmox-firewall-guests sdn-ct-zone table inet proxmox-firewall { chain do-reject { @@ -296,6 +298,17 @@ table bridge proxmox-firewall-guests { typeof iifname : verdict } + map sdn-ct-zones { + typeof meta ibrname : ct zone + } + + # Bridge conntrack tracks the connections of the guests, and routed packets keep the entry in + # the inet hooks, so the conntrack zone of their VRF has to be set before it (priority -200). + chain sdn-ct-zone { + type filter hook prerouting priority -310; policy accept; + ct zone set meta ibrname map @sdn-ct-zones + } + chain allow-dhcp-in { udp sport . udp dport { 67 . 68, 547 . 546 } accept } diff --git a/proxmox-firewall/src/config.rs b/proxmox-firewall/src/config.rs index 7e055c0..cf82bc6 100644 --- a/proxmox-firewall/src/config.rs +++ b/proxmox-firewall/src/config.rs @@ -26,6 +26,7 @@ use proxmox_nftables::types::ListChain; use proxmox_ve_config::sdn::{ VnetName, config::{RunningConfig, SdnConfig}, + conntrack::VrfCtZone, ipam::{Ipam, IpamJson}, }; @@ -319,6 +320,13 @@ impl FirewallSdnConfig { &self.config } + /// The vnets of zones with a dedicated VRF, together with the conntrack zone of the VRF. + pub fn vnet_ct_zones(&self) -> impl Iterator + '_ { + self.config + .vnets() + .filter_map(|(zone, vnet)| Some((vnet.name(), zone.ct_zone()?))) + } + pub fn ipsets(&self) -> &BTreeMap { &self.ipsets } diff --git a/proxmox-firewall/src/firewall.rs b/proxmox-firewall/src/firewall.rs index d620a2e..d80a463 100644 --- a/proxmox-firewall/src/firewall.rs +++ b/proxmox-firewall/src/firewall.rs @@ -82,6 +82,10 @@ impl Firewall { SetName::new(Self::guest_table(), format!("vm-map-{dir}")) } + fn sdn_ct_zone_map() -> SetName { + SetName::new(Self::guest_table(), "sdn-ct-zones") + } + fn cluster_chain(dir: Direction) -> ChainPart { ChainPart::new(Self::cluster_table(), format!("cluster-{dir}")) } @@ -156,6 +160,7 @@ impl Firewall { Flush::map(Self::guest_vmap(Direction::Out)), Flush::map(Self::bridge_vmap(Self::guest_table())), Flush::map(Self::bridge_vmap(Self::host_table())), + Flush::map(Self::sdn_ct_zone_map()), Flush::chain(Self::host_conntrack_chain()), Flush::chain(Self::synflood_limit_chain()), Flush::chain(Self::log_invalid_tcp_chain()), @@ -331,6 +336,7 @@ impl Firewall { if !(enabled_guests.is_empty() && enabled_bridges.is_empty()) { log::info!("creating guest configuration"); + self.create_sdn_ct_zones(&mut commands); self.create_management_ipset(&mut commands, &guest_table)?; self.create_ipsets( @@ -455,6 +461,30 @@ impl Firewall { Ok(()) } + /// Puts the traffic of vnets in zones with a dedicated VRF into the conntrack zone of the VRF. + fn create_sdn_ct_zones(&self, commands: &mut Commands) { + let Some(sdn) = self.config.sdn() else { + return; + }; + + let elements: Vec<(Expression, MapValue)> = sdn + .vnet_ct_zones() + .map(|(vnet, ct_zone)| { + ( + Expression::from(vnet.as_ref()), + MapValue::from(Expression::from(ct_zone.id())), + ) + }) + .collect(); + + if !elements.is_empty() { + commands.push(Add::element(AddElement::map_from_expressions( + Self::sdn_ct_zone_map(), + elements, + ))); + } + } + fn handle_host_options(&self, commands: &mut Commands) -> Result<(), Error> { log::info!("setting host options"); diff --git a/proxmox-firewall/tests/input/.running-config.json b/proxmox-firewall/tests/input/.running-config.json index a4511f0..c674352 100644 --- a/proxmox-firewall/tests/input/.running-config.json +++ b/proxmox-firewall/tests/input/.running-config.json @@ -35,7 +35,9 @@ "test": { "dhcp": "dnsmasq", "ipam": "pve", - "type": "simple" + "type": "simple", + "dedicated-vrf": 1, + "ct-zone": 16384 } } }, diff --git a/proxmox-firewall/tests/snapshots/integration_tests__firewall.snap b/proxmox-firewall/tests/snapshots/integration_tests__firewall.snap index 69fb10a..a434586 100644 --- a/proxmox-firewall/tests/snapshots/integration_tests__firewall.snap +++ b/proxmox-firewall/tests/snapshots/integration_tests__firewall.snap @@ -148,6 +148,15 @@ expression: "firewall.full_host_fw().expect(\"firewall can be generated\")" } } }, + { + "flush": { + "map": { + "family": "bridge", + "table": "proxmox-firewall-guests", + "name": "sdn-ct-zones" + } + } + }, { "flush": { "chain": { @@ -4366,6 +4375,21 @@ expression: "firewall.full_host_fw().expect(\"firewall can be generated\")" } } }, + { + "add": { + "element": { + "family": "bridge", + "table": "proxmox-firewall-guests", + "name": "sdn-ct-zones", + "elem": [ + [ + "public", + 16384 + ] + ] + } + } + }, { "add": { "set": { -- 2.47.3