From: Stefan Hanreich <s.hanreich@proxmox.com>
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 [thread overview]
Message-ID: <20261119194547.674512-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261119194547.674512-1-s.hanreich@proxmox.com>
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 <s.hanreich@proxmox.com>
---
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<DhcpType>,
+ #[serde(
+ default,
+ rename = "ct-zone",
+ deserialize_with = "proxmox_serde::perl::deserialize_u16"
+ )]
+ ct_zone: Option<u16>,
}
/// Struct for deserializing the zones of the SDN running config
@@ -391,6 +397,8 @@ pub struct ZoneConfig {
name: ZoneName,
ty: ZoneType,
vnets: BTreeMap<VnetName, VnetConfig>,
+ #[serde(default)]
+ ct_zone: Option<VrfCtZone>,
}
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<VrfCtZone> {
+ self.ct_zone
+ }
+
+ pub fn set_ct_zone(&mut self, ct_zone: Option<VrfCtZone>) {
+ self.ct_zone = ct_zone;
+ }
}
/// Representation of a Proxmox VE SDN configuration
@@ -649,12 +667,18 @@ impl TryFrom<RunningConfig> 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> {
+ (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<u16> for VrfCtZone {
+ type Error = String;
+
+ fn try_from(ct_zone: u16) -> Result<Self, Self::Error> {
+ 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
next prev parent reply other threads:[~2026-11-19 19:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:45 [PATCH docs/manager/network/proxmox{,-ve-rs,-firewall} 00/14] sdn: conntrack zones and SNAT for simple zones with a dedicated VRF Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox 01/14] network-api: expose the master device of a link Stefan Hanreich
2026-11-19 19:45 ` Stefan Hanreich [this message]
2026-11-19 19:45 ` [PATCH proxmox-ve-rs 03/14] sdn: conntrack: map the interfaces of zone VRFs to their conntrack zone Stefan Hanreich
2026-11-19 19:45 ` [PATCH pve-network 04/14] sdn: simple: SNAT via the uplinks of zone VRFs Stefan Hanreich
2026-11-19 19:45 ` [PATCH pve-network 05/14] sdn: zones: assign a conntrack zone to zones with a dedicated VRF Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 06/14] firewall: apply vnet rules to host traffic from vnets in a VRF Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 07/14] nftables: expression: add a constructor for map lookups Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 08/14] nftables: statement: add a helper for setting the conntrack zone Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 09/14] nftables: expression: convert the conntrack zones of zone VRFs Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 10/14] firewall: add a command applying " Stefan Hanreich
2026-11-19 19:45 ` [PATCH proxmox-firewall 11/14] firewall: put guest traffic of zone VRFs into their conntrack zone Stefan Hanreich
2026-11-19 19:45 ` [PATCH pve-manager 12/14] network: apply the conntrack zones of zone VRFs Stefan Hanreich
2026-11-19 19:45 ` [PATCH pve-manager 13/14] network: warn if pve-firewall cannot isolate guests in " Stefan Hanreich
2026-11-19 19:45 ` [PATCH pve-docs 14/14] pvesdn: simple zones: document dedicated VRFs Stefan Hanreich
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=20261119194547.674512-3-s.hanreich@proxmox.com \
--to=s.hanreich@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox