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 9BA911FF0AF for ; Fri, 20 Nov 2026 17:01:08 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 98E30217EC; Fri, 20 Nov 2026 17:00:39 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs 01/10] pve-rs: sdn: fabrics: wireguard: return empty status for non-member nodes Date: Fri, 20 Nov 2026 17:00:16 +0100 Message-ID: <20261120160026.512565-2-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120160026.512565-1-s.hanreich@proxmox.com> References: <20261120160026.512565-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: 1795190432974 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.206 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: 7MY7BIYHTP4ROQ454SOU3ZCUS4WYNDEP X-Message-ID-Hash: 7MY7BIYHTP4ROQ454SOU3ZCUS4WYNDEP 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: Querying the interfaces or neighbors of a WireGuard fabric on a node that is not part of the fabric failed, since looking up the node section of the local node returned an error. Return an empty list instead, as the OSPF status already does. Look up the node section before querying WireGuard and the network interfaces, so neither is queried on nodes outside of the fabric. For this, the status functions now take callbacks for querying WireGuard and the network interfaces, which also makes them mockable in tests. Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 43 ++++++------------ pve-rs/src/sdn/status.rs | 71 ++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 98c132d..2471287 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -1048,20 +1048,13 @@ pub mod pve_rs_sdn_fabrics { ) .map(|v| v.into()) } - FabricEntry::WireGuard(fabric_entry) => { - let wg_dump = get_wireguard_dump()?; - - let node_name = proxmox_sys::nodename(); - let current_node_id = NodeId::from_string(node_name.to_string())?; - - status::wireguard::parse_wireguard_neighbors( - &wg_dump, - fabric_entry.node_section(¤t_node_id)?, - fabric_entry, - proxmox_time::epoch_i64(), - ) - .map(Into::into) - } + FabricEntry::WireGuard(fabric_entry) => status::wireguard::get_neighbors( + fabric_entry, + &NodeId::from_string(proxmox_sys::nodename().to_string())?, + get_wireguard_dump, + proxmox_time::epoch_i64(), + ) + .map(Into::into), FabricEntry::Bgp(_) => { let command = match &vrf { Some(vrf) => format!("show bgp vrf {vrf} neighbors json"), @@ -1139,21 +1132,13 @@ pub mod pve_rs_sdn_fabrics { ) .map(|v| v.into()) } - FabricEntry::WireGuard(fabric_entry) => { - let wg_dump = get_wireguard_dump()?; - - let network_interfaces = get_network_interfaces()?; - - let node_name = proxmox_sys::nodename(); - let current_node_id = NodeId::from_string(node_name.to_string())?; - - status::wireguard::parse_wireguard_interfaces( - &wg_dump, - fabric_entry.node_section(¤t_node_id)?, - &network_interfaces, - ) - .map(Into::into) - } + FabricEntry::WireGuard(fabric_entry) => status::wireguard::get_interfaces( + fabric_entry, + &NodeId::from_string(proxmox_sys::nodename().to_string())?, + get_wireguard_dump, + get_network_interfaces, + ) + .map(Into::into), FabricEntry::Bgp(_) => { let command = match &vrf { Some(vrf) => format!("show bgp vrf {vrf} neighbors json"), diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs index 2e29e6d..881b97f 100644 --- a/pve-rs/src/sdn/status.rs +++ b/pve-rs/src/sdn/status.rs @@ -90,7 +90,7 @@ pub mod wireguard { use proxmox_ve_config::sdn::fabric::{ Entry, WireGuardInterfacePeer, section_config::{ - node::NodeSection, + node::{NodeId, NodeSection}, protocol::wireguard::{WireGuardNode, WireGuardProperties}, }, }; @@ -340,6 +340,23 @@ pub mod wireguard { Ok(interface_status) } + /// Returns the status of the interfaces of the node `node_id` in the fabric. + /// + /// If the node is not part of the fabric, an empty list is returned without querying WireGuard + /// or the network interfaces. + pub fn get_interfaces( + fabric: &Entry, + node_id: &NodeId, + wg_dump: impl FnOnce() -> Result, + network_interfaces: impl FnOnce() -> Result, anyhow::Error>, + ) -> Result, anyhow::Error> { + let Ok(node_section) = fabric.node_section(node_id) else { + return Ok(Vec::new()); + }; + + parse_wireguard_interfaces(&wg_dump()?, node_section, &network_interfaces()?) + } + /// Returns `None` for values that wg prints as "(none)". fn optional_value(value: &str) -> Option<&str> { (value != "(none)").then_some(value) @@ -499,6 +516,22 @@ pub mod wireguard { Ok(neighbors) } + /// Returns the status of the neighbors of the node `node_id` in the fabric. + /// + /// If the node is not part of the fabric, an empty list is returned without querying WireGuard. + pub fn get_neighbors( + fabric: &Entry, + node_id: &NodeId, + wg_dump: impl FnOnce() -> Result, + now: i64, + ) -> Result, anyhow::Error> { + let Ok(node_section) = fabric.node_section(node_id) else { + return Ok(Vec::new()); + }; + + parse_wireguard_neighbors(&wg_dump()?, node_section, fabric, now) + } + /// Checks whether WireGuard on this node matches the fabric configuration. /// /// This is the case if all configured interfaces are up and use their configured public key @@ -3430,8 +3463,8 @@ mod tests { }; use super::super::wireguard::{ - InterfaceStatus, NeighborStatus, PeerStatus, WireGuardInterfaceState, is_node_ok, - parse_wireguard_interfaces, parse_wireguard_neighbors, + InterfaceStatus, NeighborStatus, PeerStatus, WireGuardInterfaceState, get_interfaces, + get_neighbors, is_node_ok, parse_wireguard_interfaces, parse_wireguard_neighbors, }; use super::super::*; @@ -3740,6 +3773,22 @@ wg0 8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA= (none) 172.31.1.4:51820 198.51. ); } + #[test] + fn interfaces_non_member_node() { + let config = fabric_config(); + let fabric = wireguard_fabric(&config); + + let interfaces = get_interfaces( + fabric, + &NodeId::from_str("summoner").expect("valid node id"), + || panic!("wg must not be queried"), + || panic!("network interfaces must not be queried"), + ) + .expect("can get interfaces"); + + assert!(interfaces.is_empty()); + } + #[test] fn neighbors() { // all configured peers are present, but there was no handshake yet @@ -3804,6 +3853,22 @@ wg0 8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA= (none) 172.31.1.4:51820 198.51. ); } + #[test] + fn neighbors_non_member_node() { + let config = fabric_config(); + let fabric = wireguard_fabric(&config); + + let neighbors = get_neighbors( + fabric, + &NodeId::from_str("summoner").expect("valid node id"), + || panic!("wg must not be queried"), + 1781234627, + ) + .expect("can get neighbors"); + + assert!(neighbors.is_empty()); + } + #[test] fn neighbor_roamed() { // occultist is reachable via a different address than its configured endpoint, e.g. due to NAT -- 2.47.3