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-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	[thread overview]
Message-ID: <20261120160026.512565-2-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120160026.512565-1-s.hanreich@proxmox.com>

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 <s.hanreich@proxmox.com>
---
 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(&current_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(&current_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<WireGuardProperties, WireGuardNode>,
+        node_id: &NodeId,
+        wg_dump: impl FnOnce() -> Result<String, anyhow::Error>,
+        network_interfaces: impl FnOnce() -> Result<HashMap<String, IpLink>, anyhow::Error>,
+    ) -> Result<Vec<InterfaceStatus>, 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<WireGuardProperties, WireGuardNode>,
+        node_id: &NodeId,
+        wg_dump: impl FnOnce() -> Result<String, anyhow::Error>,
+        now: i64,
+    ) -> Result<Vec<NeighborStatus>, 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





  reply	other threads:[~2026-11-20 16:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:00 [PATCH docs/manager/network/proxmox-perl-rs 00/10] WireGuard fabric follow-ups Stefan Hanreich
2026-11-20 16:00 ` Stefan Hanreich [this message]
2026-11-20 16:00 ` [PATCH proxmox-perl-rs 02/10] pve-rs: sdn: status: wireguard: only report type of WireGuard interfaces Stefan Hanreich
2026-11-20 16:00 ` [PATCH proxmox-perl-rs 03/10] pve-rs: sdn: status: wireguard: only report running interface keys and ports Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-network 04/10] api: fabric status: document omitted WireGuard interface values Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-manager 05/10] ui: sdn: fabrics: wireguard: block saving invalid " Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-manager 06/10] ui: sdn: fabrics: wireguard: show persistent keepalive of neighbors Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-manager 07/10] ui: sdn: fabrics: wireguard: show '-' for unknown status values Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-manager 08/10] ui: sdn: fabrics: wireguard: add reload button to status grids Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-manager 09/10] ui: sdn: fabrics: wireguard: support resetting the interfaces Stefan Hanreich
2026-11-20 16:00 ` [PATCH pve-docs 10/10] sdn: fabrics: wireguard: document status values and keepalive column 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=20261120160026.512565-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