public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-ve-rs 2/4] sdn: conntrack: only map the VRFs of zones that exist on the node
Date: Fri, 20 Nov 2026 16:28:07 +0100	[thread overview]
Message-ID: <20261120152811.473269-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120152811.473269-1-s.hanreich@proxmox.com>

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





  parent reply	other threads:[~2026-11-20 15:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20261120152811.473269-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal