all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-firewall 4/4] firewall: sdn: only apply the conntrack zones of zones on this node
Date: Fri, 20 Nov 2026 16:28:09 +0100	[thread overview]
Message-ID: <20261120152811.473269-5-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120152811.473269-1-s.hanreich@proxmox.com>

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





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

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