From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 602181FF0AF for ; Fri, 20 Nov 2026 16:28:55 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id AEB062183C; Fri, 20 Nov 2026 16:28:25 +0100 (CET) From: Stefan Hanreich 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 Message-ID: <20261120152811.473269-5-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120152811.473269-1-s.hanreich@proxmox.com> References: <20261120152811.473269-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795188499696 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.213 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 3DILNTRUQ4NJ67Z3YVZCSK5F3J3ANAA3 X-Message-ID-Hash: 3DILNTRUQ4NJ67Z3YVZCSK5F3J3ANAA3 X-MailFrom: s.hanreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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, ) -> 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