all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups
@ 2026-11-20 15:28 Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config Stefan Hanreich
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stefan Hanreich @ 2026-11-20 15:28 UTC (permalink / raw)
  To: pve-devel

The VRF device of a zone is only created on the nodes of the zone, but
proxmox-firewall set the conntrack zone for every interface with the
name of the VRF device and the interfaces enslaved to it on all nodes.
So on a node that is not part of the zone, a manually created interface
with that name and its members got the conntrack zone as well.

proxmox-ve-config now reads the nodes of a zone from the running config,
and the conntrack zones are only applied for the zones that exist on the
local node.

Additionally, proxmox-firewall queried the network interfaces twice when
generating the ruleset, once for the altname mapping and once for the
conntrack zones of bridges in zone VRFs. They are now queried once.

Dependencies:

proxmox-firewall needs proxmox-ve-config.


proxmox-ve-rs:

Stefan Hanreich (2):
  sdn: config: read the nodes of zones from the running config
  sdn: conntrack: only map the VRFs of zones that exist on the node

 proxmox-ve-config/src/sdn/config.rs    | 18 ++++++++
 proxmox-ve-config/src/sdn/conntrack.rs | 26 ++++++-----
 proxmox-ve-config/tests/sdn/main.rs    | 63 +++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 13 deletions(-)


proxmox-firewall:

Stefan Hanreich (2):
  firewall: config: query the network interfaces only once
  firewall: sdn: only apply the conntrack zones of zones on this node

 proxmox-firewall/Cargo.toml                  |  2 +-
 proxmox-firewall/src/bin/proxmox-firewall.rs |  9 +++-
 proxmox-firewall/src/config.rs               | 24 ++++------
 proxmox-firewall/src/sdn.rs                  | 46 +++++++++++++-------
 proxmox-firewall/tests/integration_tests.rs  |  6 +--
 5 files changed, 47 insertions(+), 40 deletions(-)


Summary over all repositories:
  8 files changed, 141 insertions(+), 53 deletions(-)

-- 
Generated by murpp 0.12.1




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config
  2026-11-20 15:28 [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups Stefan Hanreich
@ 2026-11-20 15:28 ` Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-ve-rs 2/4] sdn: conntrack: only map the VRFs of zones that exist on the node Stefan Hanreich
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2026-11-20 15:28 UTC (permalink / raw)
  To: pve-devel

A zone can be restricted to a set of nodes. Read the nodes of a zone,
so that users of the SDN config can tell if a zone exists on a node.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 proxmox-ve-config/src/sdn/config.rs | 18 +++++++++++++++++
 proxmox-ve-config/tests/sdn/main.rs | 30 +++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs
index 6a65ee11..d5b3926a 100644
--- a/proxmox-ve-config/src/sdn/config.rs
+++ b/proxmox-ve-config/src/sdn/config.rs
@@ -148,8 +148,15 @@ pub struct ZoneRunningConfig {
         deserialize_with = "proxmox_serde::perl::deserialize_u16"
     )]
     ct_zone: Option<u16>,
+    /// pve-network stores the nodes as object with the node names as keys
+    #[serde(default)]
+    nodes: Option<BTreeMap<String, PerlBool>>,
 }
 
+/// A boolean as stored by perl, which can also be a number or a string.
+#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
+struct PerlBool(#[serde(deserialize_with = "proxmox_serde::perl::deserialize_bool")] bool);
+
 /// Struct for deserializing the zones of the SDN running config
 #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Default)]
 pub struct ZonesRunningConfig {
@@ -399,6 +406,8 @@ pub struct ZoneConfig {
     vnets: BTreeMap<VnetName, VnetConfig>,
     #[serde(default)]
     ct_zone: Option<VrfCtZone>,
+    #[serde(default)]
+    nodes: Option<BTreeMap<String, PerlBool>>,
 }
 
 impl ZoneConfig {
@@ -408,6 +417,7 @@ impl ZoneConfig {
             ty,
             vnets: BTreeMap::default(),
             ct_zone: None,
+            nodes: None,
         }
     }
 
@@ -463,6 +473,13 @@ impl ZoneConfig {
     pub fn set_ct_zone(&mut self, ct_zone: Option<VrfCtZone>) {
         self.ct_zone = ct_zone;
     }
+
+    /// Whether the zone exists on the given node, a zone without nodes exists on all nodes.
+    pub fn is_on_node(&self, node: &str) -> bool {
+        self.nodes
+            .as_ref()
+            .is_none_or(|nodes| nodes.get(node).is_some_and(|enabled| enabled.0))
+    }
 }
 
 /// Representation of a Proxmox VE SDN configuration
@@ -677,6 +694,7 @@ impl TryFrom<RunningConfig> for SdnConfig {
 
                 let mut zone = ZoneConfig::new(name, running_config.ty);
                 zone.set_ct_zone(ct_zone);
+                zone.nodes = running_config.nodes;
                 zone
             }))?;
         }
diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs
index a58690e2..d1071771 100644
--- a/proxmox-ve-config/tests/sdn/main.rs
+++ b/proxmox-ve-config/tests/sdn/main.rs
@@ -184,6 +184,36 @@ fn parse_running_config_ct_zone() {
     );
 }
 
+#[test]
+fn parse_running_config_nodes() {
+    let running_config: RunningConfig = serde_json::from_value(serde_json::json!({
+        "zones": {
+            "ids": {
+                "zone0": { "type": "simple" },
+                "zone1": { "type": "simple", "nodes": { "pve1": 1, "pve2": "1", "pve3": 0 } },
+                "zone2": { "type": "simple", "nodes": {} },
+            },
+        },
+    }))
+    .expect("valid running config");
+
+    let sdn_config = SdnConfig::try_from(running_config).expect("valid SDN config");
+
+    let is_on_node = |zone: &str, node: &str| {
+        sdn_config
+            .zone(&ZoneName::from_str(zone).unwrap())
+            .expect("zone exists")
+            .is_on_node(node)
+    };
+
+    assert!(is_on_node("zone0", "pve1"));
+    assert!(is_on_node("zone1", "pve1"));
+    assert!(is_on_node("zone1", "pve2"));
+    assert!(!is_on_node("zone1", "pve3"));
+    assert!(!is_on_node("zone1", "pve4"));
+    assert!(!is_on_node("zone2", "pve1"));
+}
+
 #[test]
 fn sdn_config() {
     let mut sdn_config = SdnConfig::new();
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH proxmox-ve-rs 2/4] sdn: conntrack: only map the VRFs of zones that exist on the node
  2026-11-20 15:28 [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config Stefan Hanreich
@ 2026-11-20 15:28 ` Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-firewall 3/4] firewall: config: query the network interfaces only once Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-firewall 4/4] firewall: sdn: only apply the conntrack zones of zones on this node Stefan Hanreich
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2026-11-20 15:28 UTC (permalink / raw)
  To: pve-devel

If a zone is restricted to certain nodes, then proxmox-firewall would
still have put an interface on other nodes with the name of the VRF
device of the zone, and the interfaces enslaved to it, into the
conntrack zone of the zone. To prevent this, replace the conversion
from the SDN config with a constructor that only takes the zones that
exist on the given node.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 proxmox-ve-config/src/sdn/conntrack.rs | 26 ++++++++++----------
 proxmox-ve-config/tests/sdn/main.rs    | 33 +++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/proxmox-ve-config/src/sdn/conntrack.rs b/proxmox-ve-config/src/sdn/conntrack.rs
index a8f91658..c1a916cc 100644
--- a/proxmox-ve-config/src/sdn/conntrack.rs
+++ b/proxmox-ve-config/src/sdn/conntrack.rs
@@ -86,6 +86,20 @@ impl VrfCtZones {
         format!("vrf_{}", zone.name())
     }
 
+    /// The VRFs of the zones with a conntrack zone that exist on `node`.
+    ///
+    /// The VRF device of a zone is only created on the nodes of the zone, so an interface with the
+    /// same name on another node is not the VRF of the zone and must not get its conntrack zone.
+    pub fn for_node(config: &SdnConfig, node: &str) -> Self {
+        let mut ct_zones = Self::default();
+
+        for zone in config.zones().filter(|zone| zone.is_on_node(node)) {
+            ct_zones.add_zone(zone);
+        }
+
+        ct_zones
+    }
+
     /// Adds the VRF of a zone, if the zone has a conntrack zone.
     pub fn add_zone(&mut self, zone: &ZoneConfig) {
         if let Some(ct_zone) = zone.ct_zone() {
@@ -135,18 +149,6 @@ impl VrfCtZones {
     }
 }
 
-impl From<&SdnConfig> for VrfCtZones {
-    fn from(config: &SdnConfig) -> Self {
-        let mut ct_zones = Self::default();
-
-        for zone in config.zones() {
-            ct_zones.add_zone(zone);
-        }
-
-        ct_zones
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs
index d1071771..bd0b6dd9 100644
--- a/proxmox-ve-config/tests/sdn/main.rs
+++ b/proxmox-ve-config/tests/sdn/main.rs
@@ -170,7 +170,7 @@ fn parse_running_config_ct_zone() {
     assert_eq!(ct_zone("zone3"), None);
     assert_eq!(ct_zone("zone4"), None);
 
-    let vrfs: Vec<_> = VrfCtZones::from(&sdn_config)
+    let vrfs: Vec<_> = VrfCtZones::for_node(&sdn_config, "pve1")
         .iter()
         .map(|(vrf, entry)| (vrf.to_string(), entry.ct_zone().id()))
         .collect();
@@ -214,6 +214,37 @@ fn parse_running_config_nodes() {
     assert!(!is_on_node("zone2", "pve1"));
 }
 
+#[test]
+fn vrf_ct_zones_for_node() {
+    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": 16385,
+                    "nodes": { "pve1": 1 },
+                },
+                "zone2": { "type": "simple", "dedicated-vrf": 1, "ct-zone": 16386, "nodes": {} },
+            },
+        },
+    }))
+    .expect("valid running config");
+
+    let sdn_config = SdnConfig::try_from(running_config).expect("valid SDN config");
+
+    let vrfs = |node: &str| -> Vec<String> {
+        VrfCtZones::for_node(&sdn_config, node)
+            .iter()
+            .map(|(vrf, _)| vrf.to_string())
+            .collect()
+    };
+
+    assert_eq!(vrfs("pve1"), ["vrf_zone0", "vrf_zone1"]);
+    assert_eq!(vrfs("pve2"), ["vrf_zone0"]);
+}
+
 #[test]
 fn sdn_config() {
     let mut sdn_config = SdnConfig::new();
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH proxmox-firewall 3/4] firewall: config: query the network interfaces only once
  2026-11-20 15:28 [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-ve-rs 2/4] sdn: conntrack: only map the VRFs of zones that exist on the node Stefan Hanreich
@ 2026-11-20 15:28 ` Stefan Hanreich
  2026-11-20 15:28 ` [PATCH proxmox-firewall 4/4] firewall: sdn: only apply the conntrack zones of zones on this node Stefan Hanreich
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2026-11-20 15:28 UTC (permalink / raw)
  To: pve-devel

Generating the ruleset queried the network interfaces of the host via
'ip -details -json link show' twice when there is a zone with a
conntrack zone: once for the conntrack zones of bridges in zone VRFs
and once for the altname mapping. Besides running the command twice per
ruleset update, the kernel state could change in between, so both
could be built from different views of the interfaces.

Query the interfaces once and build both from the same list. Drop
interface_mapping() from the config loader, as it is now derived from
network_links().

As the interfaces are always queried now, build the conntrack zones of
bridges whenever there is an SDN config, instead of only if a zone has
a conntrack zone. Pass the interfaces by reference, so that they do not
need to be cloned for the altname mapping.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 proxmox-firewall/src/bin/proxmox-firewall.rs |  4 ++--
 proxmox-firewall/src/config.rs               | 23 ++++++--------------
 proxmox-firewall/src/sdn.rs                  | 23 +++++++++-----------
 proxmox-firewall/tests/integration_tests.rs  |  6 +----
 4 files changed, 20 insertions(+), 36 deletions(-)

diff --git a/proxmox-firewall/src/bin/proxmox-firewall.rs b/proxmox-firewall/src/bin/proxmox-firewall.rs
index 3281135..4ea3a76 100644
--- a/proxmox-firewall/src/bin/proxmox-firewall.rs
+++ b/proxmox-firewall/src/bin/proxmox-firewall.rs
@@ -81,9 +81,9 @@ fn handle_firewall() -> Result<(), Error> {
 
 fn handle_sdn_ct_zones(print: bool) -> Result<(), Error> {
     let sdn = load_sdn_config(&PveFirewallConfigLoader::new())?;
-    let links = get_network_interfaces()?.into_values();
+    let links = get_network_interfaces()?;
 
-    let ct_zones = vrf_ct_zones(sdn.as_ref().map(FirewallSdnConfig::config), links);
+    let ct_zones = vrf_ct_zones(sdn.as_ref().map(FirewallSdnConfig::config), links.values());
     let commands = vrf_ct_zones_commands(&ct_zones);
 
     if print {
diff --git a/proxmox-firewall/src/config.rs b/proxmox-firewall/src/config.rs
index 78ae162..587fcf9 100644
--- a/proxmox-firewall/src/config.rs
+++ b/proxmox-firewall/src/config.rs
@@ -26,7 +26,6 @@ use proxmox_nftables::types::ListChain;
 use proxmox_ve_config::sdn::{
     VnetName,
     config::{RunningConfig, SdnConfig},
-    conntrack::VrfCtZones,
     ipam::{Ipam, IpamJson},
 };
 
@@ -54,7 +53,6 @@ pub trait FirewallConfigLoader {
         &self,
         bridge_name: &BridgeName,
     ) -> Result<Option<Box<dyn io::BufRead>>, Error>;
-    fn interface_mapping(&self) -> Result<AltnameMapping, Error>;
     /// The network interfaces of the host, as reported by the kernel.
     fn network_links(&self) -> Result<Vec<IpLink>, Error>;
 }
@@ -283,12 +281,6 @@ impl FirewallConfigLoader for PveFirewallConfigLoader {
         Ok(None)
     }
 
-    fn interface_mapping(&self) -> Result<AltnameMapping, Error> {
-        Ok(AltnameMapping::from_iter(
-            get_network_interfaces()?.into_values(),
-        ))
-    }
-
     fn network_links(&self) -> Result<Vec<IpLink>, Error> {
         Ok(get_network_interfaces()?.into_values().collect())
     }
@@ -545,13 +537,12 @@ impl FirewallConfig {
         let bridge_config = Self::parse_bridges(firewall_loader)?;
         let (sdn_config, ipam_config, sdn_invalid) = Self::parse_sdn_and_ipam(firewall_loader)?;
 
-        // only query the kernel if there is any zone with a conntrack zone
-        let bridge_ct_zones = match &sdn_config {
-            Some(sdn) if !VrfCtZones::from(sdn.config()).is_empty() => {
-                BridgeCtZones::new(sdn.config(), firewall_loader.network_links()?)
-            }
-            _ => BridgeCtZones::default(),
-        };
+        let links = firewall_loader.network_links()?;
+
+        let bridge_ct_zones = sdn_config
+            .as_ref()
+            .map(|sdn| BridgeCtZones::new(sdn.config(), &links))
+            .unwrap_or_default();
 
         firewall_loader.check_mounted()?;
 
@@ -563,7 +554,7 @@ impl FirewallConfig {
             sdn_config,
             ipam_config,
             nft_config: Self::parse_nft(nft_loader)?,
-            interface_mapping: firewall_loader.interface_mapping()?,
+            interface_mapping: AltnameMapping::from_iter(links),
             sdn_invalid,
             bridge_ct_zones,
         })
diff --git a/proxmox-firewall/src/sdn.rs b/proxmox-firewall/src/sdn.rs
index ad86f85..3bcfdad 100644
--- a/proxmox-firewall/src/sdn.rs
+++ b/proxmox-firewall/src/sdn.rs
@@ -47,9 +47,9 @@ pub fn load_sdn_config(
 ///
 /// The members are taken from the kernel, which reflects all sources that put an interface into a
 /// VRF once the network configuration got applied.
-pub fn vrf_ct_zones(
+pub fn vrf_ct_zones<'a>(
     sdn: Option<&SdnConfig>,
-    links: impl IntoIterator<Item = IpLink>,
+    links: impl IntoIterator<Item = &'a IpLink>,
 ) -> VrfCtZones {
     let mut ct_zones = sdn.map(VrfCtZones::from).unwrap_or_default();
 
@@ -88,23 +88,20 @@ impl BridgeCtZones {
     /// Vnets are taken from the kernel as well, not from the SDN config, so that their conntrack
     /// zone follows the VRF their traffic is routed in, as for the inet hooks, and a bridge on a
     /// node that is not part of the zone does not get it just because of its name.
-    pub fn new(sdn: &SdnConfig, links: Vec<IpLink>) -> Self {
+    pub fn new(sdn: &SdnConfig, links: &[IpLink]) -> Self {
         let mut ct_zones = Self::default();
 
-        let links: HashMap<String, IpLink> = links
-            .into_iter()
-            .map(|link| (link.name().to_string(), link))
-            .collect();
+        let links: HashMap<&str, &IpLink> = links.iter().map(|link| (link.name(), link)).collect();
 
         let is_bridge = |name: &str| {
             links
                 .get(name)
-                .and_then(IpLink::linkinfo)
+                .and_then(|link| link.linkinfo())
                 .and_then(LinkInfo::info_kind)
                 .is_some_and(|kind| kind == "bridge")
         };
 
-        let vrf_ct_zones = vrf_ct_zones(Some(sdn), links.values().cloned());
+        let vrf_ct_zones = vrf_ct_zones(Some(sdn), links.values().copied());
 
         for (_, entry) in vrf_ct_zones.iter() {
             for name in entry.interfaces() {
@@ -240,7 +237,7 @@ mod tests {
             link("lo", None),
         ];
 
-        let interfaces: Vec<_> = vrf_ct_zones(Some(&sdn_config()), links)
+        let interfaces: Vec<_> = vrf_ct_zones(Some(&sdn_config()), &links)
             .interfaces()
             .map(|(interface, ct_zone)| (interface.to_string(), ct_zone.id()))
             .collect();
@@ -256,7 +253,7 @@ mod tests {
             ]
         );
 
-        assert!(vrf_ct_zones(None, [link("vnetr1", Some("vrf_red"))]).is_empty());
+        assert!(vrf_ct_zones(None, &[link("vnetr1", Some("vrf_red"))]).is_empty());
     }
 
     #[test]
@@ -308,7 +305,7 @@ mod tests {
             link("eth1.62", vlan("802.1Q", 62), Some("vrf_red")),
         ];
 
-        let ct_zones = BridgeCtZones::new(&sdn, links);
+        let ct_zones = BridgeCtZones::new(&sdn, &links);
 
         assert_eq!(
             ct_zones
@@ -341,7 +338,7 @@ mod tests {
 
     #[test]
     fn vrf_ct_zones_commands_with_zones() {
-        let ct_zones = vrf_ct_zones(Some(&sdn_config()), [link("vnetb", Some("vrf_blue"))]);
+        let ct_zones = vrf_ct_zones(Some(&sdn_config()), &[link("vnetb", Some("vrf_blue"))]);
 
         let elements = json!({"set": [
             ["vrf_blue", 16389],
diff --git a/proxmox-firewall/tests/integration_tests.rs b/proxmox-firewall/tests/integration_tests.rs
index 5b17e2e..ca557be 100644
--- a/proxmox-firewall/tests/integration_tests.rs
+++ b/proxmox-firewall/tests/integration_tests.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
 
 use proxmox_firewall::config::{FirewallConfig, FirewallConfigLoader, NftConfigLoader};
 use proxmox_firewall::firewall::Firewall;
-use proxmox_network_api::{AltnameMapping, IpLink};
+use proxmox_network_api::IpLink;
 use proxmox_nftables::command::CommandOutput;
 use proxmox_sys::nodename;
 use proxmox_ve_config::guest::types::Vmid;
@@ -135,10 +135,6 @@ impl FirewallConfigLoader for MockFirewallConfigLoader {
         Ok(None)
     }
 
-    fn interface_mapping(&self) -> Result<AltnameMapping, Error> {
-        Ok(AltnameMapping::from_iter(vec![]))
-    }
-
     fn network_links(&self) -> Result<Vec<IpLink>, Error> {
         let link = |name: &str, kind: Option<&str>, master: Option<&str>, parent: Option<&str>| {
             let linkinfo = kind.map(|kind| match kind {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH proxmox-firewall 4/4] firewall: sdn: only apply the conntrack zones of zones on this node
  2026-11-20 15:28 [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups Stefan Hanreich
                   ` (2 preceding siblings ...)
  2026-11-20 15:28 ` [PATCH proxmox-firewall 3/4] firewall: config: query the network interfaces only once Stefan Hanreich
@ 2026-11-20 15:28 ` Stefan Hanreich
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hanreich @ 2026-11-20 15:28 UTC (permalink / raw)
  To: pve-devel

The VRF device of a zone with a dedicated VRF only exists on the nodes
of the zone, but the conntrack zones were set for every interface with
the name of the VRF device and the interfaces enslaved to it, on all
nodes. So on a node that is not part of the zone, an interface that
happens to have that name, e.g. a VRF set up manually in
/etc/network/interfaces, and its members got the conntrack zone of the
zone, both in the inet hooks and for bridged traffic.

Only consider the zones that exist on this node.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 proxmox-firewall/Cargo.toml                  |  2 +-
 proxmox-firewall/src/bin/proxmox-firewall.rs |  7 +++-
 proxmox-firewall/src/config.rs               |  3 +-
 proxmox-firewall/src/sdn.rs                  | 35 +++++++++++++++-----
 4 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/proxmox-firewall/Cargo.toml b/proxmox-firewall/Cargo.toml
index 6ad7e79..2a99e04 100644
--- a/proxmox-firewall/Cargo.toml
+++ b/proxmox-firewall/Cargo.toml
@@ -22,8 +22,8 @@ proxmox-log.workspace = true
 proxmox-network-types.workspace = true
 proxmox-network-api = { workspace = true, features = [ "impl" ] }
 proxmox-nftables = { workspace = true, features = [ "config-ext" ] }
+proxmox-sys.workspace = true
 proxmox-ve-config.workspace = true
 
 [dev-dependencies]
 insta = { workspace = true, features = [ "json" ] }
-proxmox-sys.workspace = true
diff --git a/proxmox-firewall/src/bin/proxmox-firewall.rs b/proxmox-firewall/src/bin/proxmox-firewall.rs
index 4ea3a76..b3a1acd 100644
--- a/proxmox-firewall/src/bin/proxmox-firewall.rs
+++ b/proxmox-firewall/src/bin/proxmox-firewall.rs
@@ -14,6 +14,7 @@ use proxmox_log as log;
 use proxmox_log::{LevelFilter, Logger};
 use proxmox_network_api::get_network_interfaces;
 use proxmox_nftables::{NftClient, client::NftError};
+use proxmox_sys::nodename;
 use proxmox_ve_config::firewall::host::Config as HostConfig;
 
 const HELP: &str = r#"
@@ -83,7 +84,11 @@ fn handle_sdn_ct_zones(print: bool) -> Result<(), Error> {
     let sdn = load_sdn_config(&PveFirewallConfigLoader::new())?;
     let links = get_network_interfaces()?;
 
-    let ct_zones = vrf_ct_zones(sdn.as_ref().map(FirewallSdnConfig::config), links.values());
+    let ct_zones = vrf_ct_zones(
+        sdn.as_ref().map(FirewallSdnConfig::config),
+        nodename(),
+        links.values(),
+    );
     let commands = vrf_ct_zones_commands(&ct_zones);
 
     if print {
diff --git a/proxmox-firewall/src/config.rs b/proxmox-firewall/src/config.rs
index 587fcf9..505a88b 100644
--- a/proxmox-firewall/src/config.rs
+++ b/proxmox-firewall/src/config.rs
@@ -23,6 +23,7 @@ use proxmox_network_api::{AltnameMapping, IpLink, get_network_interfaces};
 use proxmox_nftables::NftClient;
 use proxmox_nftables::command::{CommandOutput, Commands, List, ListOutput};
 use proxmox_nftables::types::ListChain;
+use proxmox_sys::nodename;
 use proxmox_ve_config::sdn::{
     VnetName,
     config::{RunningConfig, SdnConfig},
@@ -541,7 +542,7 @@ impl FirewallConfig {
 
         let bridge_ct_zones = sdn_config
             .as_ref()
-            .map(|sdn| BridgeCtZones::new(sdn.config(), &links))
+            .map(|sdn| BridgeCtZones::new(sdn.config(), nodename(), &links))
             .unwrap_or_default();
 
         firewall_loader.check_mounted()?;
diff --git a/proxmox-firewall/src/sdn.rs b/proxmox-firewall/src/sdn.rs
index 3bcfdad..743ec7c 100644
--- a/proxmox-firewall/src/sdn.rs
+++ b/proxmox-firewall/src/sdn.rs
@@ -43,15 +43,19 @@ pub fn load_sdn_config(
     FirewallConfig::parse_sdn(data.as_deref())
 }
 
-/// Collects the zone VRFs with a conntrack zone and the interfaces that are enslaved to them.
+/// Collects the zone VRFs with a conntrack zone on `node` and the interfaces that are enslaved to
+/// them.
 ///
 /// The members are taken from the kernel, which reflects all sources that put an interface into a
 /// VRF once the network configuration got applied.
 pub fn vrf_ct_zones<'a>(
     sdn: Option<&SdnConfig>,
+    node: &str,
     links: impl IntoIterator<Item = &'a IpLink>,
 ) -> VrfCtZones {
-    let mut ct_zones = sdn.map(VrfCtZones::from).unwrap_or_default();
+    let mut ct_zones = sdn
+        .map(|sdn| VrfCtZones::for_node(sdn, node))
+        .unwrap_or_default();
 
     for link in links {
         if let Some(master) = link.master() {
@@ -83,12 +87,12 @@ pub struct BridgeCtZones {
 
 impl BridgeCtZones {
     /// Collects the conntrack zones from the interfaces that the kernel reports as enslaved to a
-    /// zone VRF.
+    /// zone VRF on `node`.
     ///
     /// Vnets are taken from the kernel as well, not from the SDN config, so that their conntrack
     /// zone follows the VRF their traffic is routed in, as for the inet hooks, and a bridge on a
     /// node that is not part of the zone does not get it just because of its name.
-    pub fn new(sdn: &SdnConfig, links: &[IpLink]) -> Self {
+    pub fn new(sdn: &SdnConfig, node: &str, links: &[IpLink]) -> Self {
         let mut ct_zones = Self::default();
 
         let links: HashMap<&str, &IpLink> = links.iter().map(|link| (link.name(), link)).collect();
@@ -101,7 +105,7 @@ impl BridgeCtZones {
                 .is_some_and(|kind| kind == "bridge")
         };
 
-        let vrf_ct_zones = vrf_ct_zones(Some(sdn), links.values().copied());
+        let vrf_ct_zones = vrf_ct_zones(Some(sdn), node, links.values().copied());
 
         for (_, entry) in vrf_ct_zones.iter() {
             for name in entry.interfaces() {
@@ -216,6 +220,12 @@ mod tests {
                     "red": { "type": "simple", "dedicated-vrf": 1, "ct-zone": 16384 },
                     "blue": { "type": "simple", "dedicated-vrf": 1, "ct-zone": "16389" },
                     "green": { "type": "simple" },
+                    "white": {
+                        "type": "simple",
+                        "dedicated-vrf": 1,
+                        "ct-zone": 16390,
+                        "nodes": { "pve2": 1 },
+                    },
                 },
             },
         }))
@@ -234,10 +244,13 @@ mod tests {
             link("ens18", Some("vmbr0")),
             link("eth5", Some("vrf_other")),
             link("vnetg", Some("vrf_green")),
+            // a VRF with the name of the VRF of a zone that does not exist on this node
+            link("vrf_white", None),
+            link("eth6", Some("vrf_white")),
             link("lo", None),
         ];
 
-        let interfaces: Vec<_> = vrf_ct_zones(Some(&sdn_config()), &links)
+        let interfaces: Vec<_> = vrf_ct_zones(Some(&sdn_config()), "pve1", &links)
             .interfaces()
             .map(|(interface, ct_zone)| (interface.to_string(), ct_zone.id()))
             .collect();
@@ -253,7 +266,7 @@ mod tests {
             ]
         );
 
-        assert!(vrf_ct_zones(None, &[link("vnetr1", Some("vrf_red"))]).is_empty());
+        assert!(vrf_ct_zones(None, "pve1", &[link("vnetr1", Some("vrf_red"))]).is_empty());
     }
 
     #[test]
@@ -305,7 +318,7 @@ mod tests {
             link("eth1.62", vlan("802.1Q", 62), Some("vrf_red")),
         ];
 
-        let ct_zones = BridgeCtZones::new(&sdn, &links);
+        let ct_zones = BridgeCtZones::new(&sdn, "pve1", &links);
 
         assert_eq!(
             ct_zones
@@ -338,7 +351,11 @@ mod tests {
 
     #[test]
     fn vrf_ct_zones_commands_with_zones() {
-        let ct_zones = vrf_ct_zones(Some(&sdn_config()), &[link("vnetb", Some("vrf_blue"))]);
+        let ct_zones = vrf_ct_zones(
+            Some(&sdn_config()),
+            "pve1",
+            &[link("vnetb", Some("vrf_blue"))],
+        );
 
         let elements = json!({"set": [
             ["vrf_blue", 16389],
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-20 15:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:28 [PATCH proxmox{-ve-rs,-firewall} 0/4] sdn: zone VRF conntrack zones: follow-ups Stefan Hanreich
2026-11-20 15:28 ` [PATCH proxmox-ve-rs 1/4] sdn: config: read the nodes of zones from the running config Stefan Hanreich
2026-11-20 15:28 ` [PATCH proxmox-ve-rs 2/4] sdn: conntrack: only map the VRFs of zones that exist on the node Stefan Hanreich
2026-11-20 15:28 ` [PATCH proxmox-firewall 3/4] firewall: config: query the network interfaces only once Stefan Hanreich
2026-11-20 15:28 ` [PATCH proxmox-firewall 4/4] firewall: sdn: only apply the conntrack zones of zones on this node Stefan Hanreich

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