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 F3AD11FF0DA for ; Thu, 19 Nov 2026 20:46:46 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id F04D821874; Thu, 19 Nov 2026 20:46:13 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs 02/14] sdn: config: read the conntrack zone of zones with a dedicated VRF Date: Thu, 19 Nov 2026 20:45:34 +0100 Message-ID: <20261119194547.674512-3-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: 1795117556840 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.235 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: BFLMYGR5LBH37NDONMEPPRKKKR4CJHNZ X-Message-ID-Hash: BFLMYGR5LBH37NDONMEPPRKKKR4CJHNZ 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: Proxmox VE reserves the conntrack zones 16384 to 32767 (0x4000 to 0x7fff). These are all zones whose two most significant bits are 01, so the whole block can be matched with a single bitmask (ct zone & 0xc000 == 0x4000). Zones with a dedicated VRF get their conntrack zone from the first 1024 zones of this block, 16384 to 17407, which leaves the rest of the block for future use. Add the VrfCtZone type, which only accepts conntrack zones from that range, and read the ct-zone property of zones from the running config. A conntrack zone out of range is ignored with a warning, so that it does not prevent reading the rest of the SDN configuration. Signed-off-by: Stefan Hanreich --- proxmox-ve-config/src/sdn/config.rs | 38 ++++++++++++--- proxmox-ve-config/src/sdn/conntrack.rs | 65 ++++++++++++++++++++++++++ proxmox-ve-config/src/sdn/mod.rs | 1 + proxmox-ve-config/tests/sdn/main.rs | 34 ++++++++++++++ 4 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 proxmox-ve-config/src/sdn/conntrack.rs diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs index 55df9dd2..db61094e 100644 --- a/proxmox-ve-config/src/sdn/config.rs +++ b/proxmox-ve-config/src/sdn/config.rs @@ -17,7 +17,7 @@ use crate::{ Ipset, ipset::{IpsetEntry, IpsetName, IpsetScope}, }, - sdn::{SdnNameError, SubnetName, VnetName, ZoneName}, + sdn::{SdnNameError, SubnetName, VnetName, ZoneName, conntrack::VrfCtZone}, }; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -142,6 +142,12 @@ pub struct ZoneRunningConfig { #[serde(rename = "type")] ty: ZoneType, dhcp: Option, + #[serde( + default, + rename = "ct-zone", + deserialize_with = "proxmox_serde::perl::deserialize_u16" + )] + ct_zone: Option, } /// Struct for deserializing the zones of the SDN running config @@ -391,6 +397,8 @@ pub struct ZoneConfig { name: ZoneName, ty: ZoneType, vnets: BTreeMap, + #[serde(default)] + ct_zone: Option, } impl ZoneConfig { @@ -399,6 +407,7 @@ impl ZoneConfig { name, ty, vnets: BTreeMap::default(), + ct_zone: None, } } @@ -445,6 +454,15 @@ impl ZoneConfig { pub fn ty(&self) -> &ZoneType { &self.ty } + + /// The conntrack zone of a zone with a dedicated VRF. + pub fn ct_zone(&self) -> Option { + self.ct_zone + } + + pub fn set_ct_zone(&mut self, ct_zone: Option) { + self.ct_zone = ct_zone; + } } /// Representation of a Proxmox VE SDN configuration @@ -649,12 +667,18 @@ impl TryFrom for SdnConfig { let mut config = SdnConfig::default(); if let Some(running_zones) = value.zones.take() { - config.add_zones( - running_zones - .ids - .into_iter() - .map(|(name, running_config)| ZoneConfig::new(name, running_config.ty)), - )?; + config.add_zones(running_zones.ids.into_iter().map(|(name, running_config)| { + // an invalid conntrack zone must not prevent reading the rest of the configuration + let ct_zone = running_config.ct_zone.and_then(|ct_zone| { + VrfCtZone::try_from(ct_zone) + .inspect_err(|err| log::warn!("zone {name}: ignoring the {err}")) + .ok() + }); + + let mut zone = ZoneConfig::new(name, running_config.ty); + zone.set_ct_zone(ct_zone); + zone + }))?; } if let Some(running_vnets) = value.vnets.take() { diff --git a/proxmox-ve-config/src/sdn/conntrack.rs b/proxmox-ve-config/src/sdn/conntrack.rs new file mode 100644 index 00000000..ff363646 --- /dev/null +++ b/proxmox-ve-config/src/sdn/conntrack.rs @@ -0,0 +1,65 @@ +//! Conntrack zones of SDN zones. +//! +//! Proxmox VE reserves the conntrack zones 16384 to 32767 (0x4000 to 0x7fff). These are all zones +//! whose two most significant bits are 01, so the whole block can be matched with a single bitmask +//! (`ct zone & 0xc000 == 0x4000`). Zones with a dedicated VRF get their conntrack zone from the +//! first 1024 zones of this block. + +use serde::Deserialize; + +/// The conntrack zone of an SDN zone with a dedicated VRF. +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize)] +#[serde(try_from = "u16")] +pub struct VrfCtZone(u16); + +impl VrfCtZone { + /// The first conntrack zone for zones with a dedicated VRF, the start of the reserved block. + pub const FIRST: u16 = 16384; + + /// The number of conntrack zones for zones with a dedicated VRF. + pub const COUNT: u16 = 1024; + + /// Returns `None` if `ct_zone` is not in the range for zones with a dedicated VRF. + pub fn new(ct_zone: u16) -> Option { + (Self::FIRST..Self::FIRST + Self::COUNT) + .contains(&ct_zone) + .then_some(Self(ct_zone)) + } + + /// The conntrack zone ID. + pub fn id(self) -> u16 { + self.0 + } + + /// The position of the conntrack zone within the range for zones with a dedicated VRF. + pub fn index(self) -> u16 { + self.0 - Self::FIRST + } +} + +impl TryFrom for VrfCtZone { + type Error = String; + + fn try_from(ct_zone: u16) -> Result { + Self::new(ct_zone).ok_or_else(|| { + format!( + "conntrack zone {ct_zone} is out of range ({} - {})", + Self::FIRST, + Self::FIRST + Self::COUNT - 1 + ) + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn vrf_ct_zone_range() { + assert_eq!(VrfCtZone::new(16384).map(VrfCtZone::index), Some(0)); + assert_eq!(VrfCtZone::new(17407).map(VrfCtZone::index), Some(1023)); + assert_eq!(VrfCtZone::new(16383), None); + assert_eq!(VrfCtZone::new(17408), None); + } +} diff --git a/proxmox-ve-config/src/sdn/mod.rs b/proxmox-ve-config/src/sdn/mod.rs index 88987cd5..3b96ec18 100644 --- a/proxmox-ve-config/src/sdn/mod.rs +++ b/proxmox-ve-config/src/sdn/mod.rs @@ -1,4 +1,5 @@ pub mod config; +pub mod conntrack; pub mod fabric; pub mod ipam; pub mod prefix_list; diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs index 7d29d69f..ad982bd1 100644 --- a/proxmox-ve-config/tests/sdn/main.rs +++ b/proxmox-ve-config/tests/sdn/main.rs @@ -11,6 +11,7 @@ use proxmox_ve_config::sdn::{ config::{ RunningConfig, SdnConfig, SdnConfigError, SubnetConfig, VnetConfig, ZoneConfig, ZoneType, }, + conntrack::VrfCtZone, ipam::{Ipam, IpamDataVm, IpamEntry, IpamJson}, }; @@ -137,6 +138,39 @@ fn parse_running_config_from_newer_pve_network() { assert_eq!(subnet_v6.gateway(), None); } +#[test] +fn parse_running_config_ct_zone() { + // perl may store the zone as string, a zone out of range is ignored + let running_config: RunningConfig = serde_json::from_value(serde_json::json!({ + "zones": { + "ids": { + "zone0": { "type": "simple", "dedicated-vrf": 1, "ct-zone": 16384 }, + "zone1": { "type": "simple", "dedicated-vrf": 1, "ct-zone": "17407" }, + "zone2": { "type": "simple", "dedicated-vrf": 1, "ct-zone": 17408 }, + "zone3": { "type": "simple", "dedicated-vrf": 1, "ct-zone": 5 }, + "zone4": { "type": "simple" }, + }, + }, + })) + .expect("valid running config"); + + let sdn_config = SdnConfig::try_from(running_config).expect("valid SDN config"); + + let ct_zone = |zone: &str| { + sdn_config + .zone(&ZoneName::from_str(zone).unwrap()) + .expect("zone exists") + .ct_zone() + .map(VrfCtZone::id) + }; + + assert_eq!(ct_zone("zone0"), Some(16384)); + assert_eq!(ct_zone("zone1"), Some(17407)); + assert_eq!(ct_zone("zone2"), None); + assert_eq!(ct_zone("zone3"), None); + assert_eq!(ct_zone("zone4"), None); +} + #[test] fn sdn_config() { let mut sdn_config = SdnConfig::new(); -- 2.47.3