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 1/4] sdn: config: read the nodes of zones from the running config
Date: Fri, 20 Nov 2026 16:28:06 +0100	[thread overview]
Message-ID: <20261120152811.473269-2-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120152811.473269-1-s.hanreich@proxmox.com>

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





  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 ` Stefan Hanreich [this message]
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

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-2-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