From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-ve-rs v2 05/11] ve-config: sdn: wireguard: add helper for resolving the peers of an interface
Date: Tue, 17 Nov 2026 19:34:52 +0100 [thread overview]
Message-ID: <20261117183500.750636-6-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261117183500.750636-1-s.hanreich@proxmox.com>
This function will be used by the status reporting, which requires the
ability to match a peer from the `wg show` output to the respective
node in the section config, in order to include the corresponding
node/interface in its informational output. This helps users matching
peers from the running WireGuard configuration to their respective
section config entry. It also allows checking whether the running
WireGuard configuration contains exactly the configured peers.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
proxmox-ve-config/src/sdn/fabric/mod.rs | 88 ++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/proxmox-ve-config/src/sdn/fabric/mod.rs b/proxmox-ve-config/src/sdn/fabric/mod.rs
index 79bb1fd9..d4687fb1 100644
--- a/proxmox-ve-config/src/sdn/fabric/mod.rs
+++ b/proxmox-ve-config/src/sdn/fabric/mod.rs
@@ -7,6 +7,7 @@ use std::marker::PhantomData;
use std::ops::Deref;
use anyhow::Error;
+use proxmox_wireguard::PublicKey;
use section_config::protocol::wireguard::WireGuardProperties;
use serde::{Deserialize, Serialize};
@@ -34,7 +35,8 @@ use crate::sdn::fabric::section_config::protocol::ospf::{
OspfNodePropertiesUpdater, OspfProperties, OspfPropertiesUpdater,
};
use crate::sdn::fabric::section_config::protocol::wireguard::{
- WireGuardDeletableProperties, WireGuardNode, WireGuardNodeDeletableProperties,
+ ExternalWireGuardNode, InternalWireGuardNode, WireGuardDeletableProperties,
+ WireGuardInterfaceProperties, WireGuardNode, WireGuardNodeDeletableProperties,
WireGuardNodePeer, WireGuardNodeUpdater, WireGuardPropertiesUpdater,
};
use crate::sdn::fabric::section_config::{FabricOrNode, Section};
@@ -215,6 +217,90 @@ impl_entry!(Ospf, OspfProperties, OspfNodeProperties);
impl_entry!(WireGuard, WireGuardProperties, WireGuardNode);
impl_entry!(Bgp, BgpProperties, BgpNode);
+/// A configured peer of a WireGuard interface, resolved to the node it refers to.
+pub enum WireGuardInterfacePeer<'a> {
+ /// A peer that refers to an interface of an internal node.
+ Internal {
+ node_id: &'a NodeId,
+ node: &'a InternalWireGuardNode,
+ interface: &'a WireGuardInterfaceProperties,
+ },
+ /// A peer that refers to an external node.
+ External {
+ node_id: &'a NodeId,
+ node: &'a ExternalWireGuardNode,
+ },
+}
+
+impl WireGuardInterfacePeer<'_> {
+ /// Returns the public key of the peer.
+ pub fn public_key(&self) -> &PublicKey {
+ match self {
+ Self::Internal { interface, .. } => interface.public_key(),
+ Self::External { node, .. } => &node.public_key,
+ }
+ }
+}
+
+impl Entry<WireGuardProperties, WireGuardNode> {
+ /// Resolve the configured peers of an interface on a node to the nodes they refer to.
+ ///
+ /// These are the same peers with the same public keys as in the generated WireGuard
+ /// configuration of the interface.
+ pub fn interface_peers(
+ &self,
+ local_node_id: &NodeId,
+ interface: &str,
+ ) -> Result<Vec<WireGuardInterfacePeer<'_>>, Error> {
+ let Node::WireGuard(wireguard_node) = self.get_node(local_node_id)? else {
+ anyhow::bail!("no wireguard node with id {local_node_id} found");
+ };
+
+ let WireGuardNode::Internal(internal_node) = wireguard_node.properties() else {
+ anyhow::bail!("wireguard node with id {local_node_id} is not an internal node");
+ };
+
+ let mut peers = Vec::new();
+
+ for peer in internal_node
+ .peers()
+ .filter(|peer| peer.iface().as_ref() == interface)
+ {
+ let referenced_wireguard_node = self.node_section(peer.node())?;
+
+ match (referenced_wireguard_node.properties(), peer) {
+ (
+ WireGuardNode::Internal(referenced_internal_node),
+ WireGuardNodePeer::Internal(internal_peer),
+ ) => {
+ let referenced_interface = referenced_internal_node
+ .interfaces()
+ .find(|interface| interface.name() == &internal_peer.node_iface)
+ .ok_or_else(|| anyhow::anyhow!("referenced interface does not exist"))?;
+
+ peers.push(WireGuardInterfacePeer::Internal {
+ node_id: peer.node(),
+ node: referenced_internal_node,
+ interface: referenced_interface,
+ });
+ }
+ (
+ WireGuardNode::External(referenced_external_node),
+ WireGuardNodePeer::External(_),
+ ) => {
+ peers.push(WireGuardInterfacePeer::External {
+ node_id: peer.node(),
+ node: referenced_external_node,
+ });
+ }
+ _ => anyhow::bail!("invalid combination of peer / node types"),
+ }
+ }
+
+ Ok(peers)
+ }
+}
+
/// All possible entries in a [`FabricConfig`].
///
/// It utilizes the [`Entry`] struct to validate proper combinations of [`FabricSection`] and
--
2.47.3
next prev parent reply other threads:[~2026-11-17 18:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 18:34 [PATCH docs/manager/network/proxmox{,-ve-rs,-perl-rs} v2 00/11] Status reporting for WireGuard fabrics Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox v2 01/11] network-api: add missing getters Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox v2 02/11] network-api: add support for parsing interface flags Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox v2 03/11] wireguard: derive additional traits for public key Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox-ve-rs v2 04/11] ve-config: sdn: wireguard: add getters for interface listen port and " Stefan Hanreich
2026-11-17 18:34 ` Stefan Hanreich [this message]
2026-11-17 18:34 ` [PATCH proxmox-perl-rs v2 06/11] sdn status: fabrics: add status reporting for wireguard Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox-perl-rs v2 07/11] sdn status: fabrics: check interfaces and peers for wireguard status Stefan Hanreich
2026-11-17 18:34 ` [PATCH proxmox-perl-rs v2 08/11] sdn status: fabrics: report status of wireguard neighbors Stefan Hanreich
2026-11-17 18:34 ` [PATCH pve-network v2 09/11] api: fabric status: add schema for wireguard properties Stefan Hanreich
2026-11-17 18:34 ` [PATCH pve-manager v2 10/11] ui: fabric content: add wireguard protocol Stefan Hanreich
2026-11-17 18:34 ` [PATCH pve-docs v2 11/11] sdn: add documentation for wireguard status reporting Stefan Hanreich
2026-11-18 15:20 ` [PATCH docs/manager/network/proxmox{,-ve-rs,-perl-rs} v2 00/11] Status reporting for WireGuard fabrics Arthur Bied-Charreton
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=20261117183500.750636-6-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