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 C95111FF0DA for ; Thu, 19 Nov 2026 20:47:16 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 01BF5218CB; Thu, 19 Nov 2026 20:46:24 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-firewall 09/14] nftables: expression: convert the conntrack zones of zone VRFs Date: Thu, 19 Nov 2026 20:45:41 +0100 Message-ID: <20261119194547.674512-10-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: 1795117557368 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.230 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: NZU7ZUQAF537SSOQJNO5TOGYLZGLJLXN X-Message-ID-Hash: NZU7ZUQAF537SSOQJNO5TOGYLZGLJLXN 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: The interfaces of zone VRFs need to be mapped to the conntrack zone of their VRF. Convert them into the data of an anonymous map, so that a rule can set the conntrack zone with a map lookup of the interface name. Signed-off-by: Stefan Hanreich --- proxmox-nftables/src/expression.rs | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/proxmox-nftables/src/expression.rs b/proxmox-nftables/src/expression.rs index 010c0c6..cfd6a97 100644 --- a/proxmox-nftables/src/expression.rs +++ b/proxmox-nftables/src/expression.rs @@ -14,6 +14,8 @@ use proxmox_ve_config::firewall::types::rule_match::{IcmpCode, IcmpType, Icmpv6C use proxmox_ve_config::guest::types::Vmid; #[cfg(feature = "config-ext")] use proxmox_ve_config::host::types::BridgeName; +#[cfg(feature = "config-ext")] +use proxmox_ve_config::sdn::conntrack::VrfCtZones; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "lowercase")] @@ -276,6 +278,16 @@ impl From for Expression { } } +/// The interfaces of the zone VRFs with their conntrack zone, for use as data of a map lookup. +#[cfg(feature = "config-ext")] +impl From<&VrfCtZones> for Expression { + fn from(value: &VrfCtZones) -> Self { + Expression::set(value.interfaces().map(|(interface, ct_zone)| { + Expression::List(vec![interface.into(), ct_zone.id().into()]) + })) + } +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Meta { key: String, @@ -432,3 +444,44 @@ pub struct Element { config: ElemConfig, val: Expression, } + +#[cfg(all(test, feature = "config-ext"))] +mod tests { + use std::str::FromStr; + + use proxmox_ve_config::sdn::ZoneName; + use proxmox_ve_config::sdn::config::{ZoneConfig, ZoneType}; + use proxmox_ve_config::sdn::conntrack::VrfCtZone; + use serde_json::json; + + use super::*; + + #[test] + fn vrf_ct_zones_map_data() { + let mut ct_zones = VrfCtZones::default(); + + assert_eq!( + serde_json::to_value(Expression::from(&ct_zones)).unwrap(), + json!({ "set": [] }) + ); + + for (name, ct_zone) in [("red", 16384), ("blue", 16389)] { + let mut zone = ZoneConfig::new(ZoneName::from_str(name).unwrap(), ZoneType::Simple); + zone.set_ct_zone(VrfCtZone::new(ct_zone)); + ct_zones.add_zone(&zone); + } + + ct_zones.add_interface("vrf_red", "vnetr1"); + ct_zones.add_interface("vrf_blue", "vnetb"); + + assert_eq!( + serde_json::to_value(Expression::from(&ct_zones)).unwrap(), + json!({ "set": [ + ["vrf_blue", 16389], + ["vnetb", 16389], + ["vrf_red", 16384], + ["vnetr1", 16384], + ]}) + ); + } +} -- 2.47.3