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 03/10] pve-rs: sdn: status: wireguard: only report running interface keys and ports
Date: Fri, 20 Nov 2026 17:00:18 +0100	[thread overview]
Message-ID: <20261120160026.512565-4-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120160026.512565-1-s.hanreich@proxmox.com>

If wg did not report the public key of an interface, the interface
status returned the configured public key and listen port instead.
This happened if the interface was missing, was not a WireGuard
interface, could not be read by wg, or had no private key. In the
latter case the configured listen port even replaced the running one
that wg did report.

The status should reflect what is actually running, so omit the
public key and listen port if wg does not report them.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 pve-rs/src/sdn/status.rs | 129 ++++++++++++++++++++-------------------
 1 file changed, 66 insertions(+), 63 deletions(-)

diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index 59be427..9d3534c 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -194,8 +194,10 @@ pub mod wireguard {
         #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
         pub ty: Option<String>,
         pub state: WireGuardInterfaceState,
-        pub public_key: PublicKey,
-        pub listen_port: u16,
+        #[serde(skip_serializing_if = "Option::is_none")]
+        pub public_key: Option<PublicKey>,
+        #[serde(skip_serializing_if = "Option::is_none")]
+        pub listen_port: Option<u16>,
     }
 
     fn is_wireguard_interface(network_interface: &IpLink) -> bool {
@@ -292,9 +294,9 @@ pub mod wireguard {
 
     /// Returns the status of every interface the fabric configuration defines for the node.
     ///
-    /// Interfaces that do not exist or whose state wg could not read are included as well. If wg
-    /// does not report a public key for an interface, the configured public key and listen port are
-    /// returned instead.
+    /// Interfaces that do not exist or whose state wg could not read are included as well.
+    /// Properties that cannot be determined from the running state are omitted instead of being
+    /// taken from the configuration.
     pub fn parse_wireguard_interfaces(
         wg_dump_output: &str,
         node_section: &NodeSection<WireGuardNode>,
@@ -329,8 +331,8 @@ pub mod wireguard {
                     .then(|| "wireguard".to_string());
 
                 let (public_key, listen_port) = match running_interface {
-                    Some((Some(public_key), listen_port)) => (*public_key, *listen_port),
-                    _ => (*interface.public_key(), interface.listen_port()),
+                    Some((public_key, listen_port)) => (*public_key, Some(*listen_port)),
+                    None => (None, None),
                 };
 
                 InterfaceStatus {
@@ -3573,19 +3575,23 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                     name: "wg1".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Down,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: Some(
+                        "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51821),
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: Some(
+                        "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51820),
                 },
             ];
 
@@ -3598,7 +3604,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
 
         #[test]
         fn interface_missing() {
-            // wg1 does not exist on the node, so its values are taken from the configuration
+            // wg1 does not exist on the node, so there is no public key or listen port to report
             let wg_dump = r#"wg0	GDHQ8ivFvwz53U0bSmQ7uTD2bJ8GpcFCCxGeU1G9m2U=	AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M=	51820	off
 wg0	+PA/xNCZ3G+Wy1DeqF251Us5mcZhBTGc9CT3AaJ89HI=	(none)	172.31.1.2:51820	198.51.100.2/32,203.0.113.0/28	0	0	0	off
 wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.100.4/32	0	0	0	off"#;
@@ -3617,19 +3623,19 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                     name: "wg1".to_string(),
                     ty: None,
                     state: WireGuardInterfaceState::Missing,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: None,
+                    listen_port: None,
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: Some(
+                        "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51820),
                 },
             ];
 
@@ -3662,19 +3668,19 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                     name: "wg1".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Unknown,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: None,
+                    listen_port: None,
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: Some(
+                        "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51820),
                 },
             ];
 
@@ -3687,10 +3693,10 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
 
         #[test]
         fn interface_without_private_key() {
-            // wg0 has no private key, so its public key and listen port are taken from the configuration
+            // wg0 has no private key, so wg reports no public key
             let wg_dump = r#"wg1	wF2D1my5Cj962/MOS2UXLvCddm3ozmCSSuBQ1Ey6v3I=	Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM=	51821	off
 wg1	aHnKVQ4yTtTdfwsk+r4Z12FrRlUnXXksjRcV7x41+G0=	(none)	172.31.1.10:51820	(none)	0	0	0	off
-wg0	(none)	(none)	0	off
+wg0	(none)	(none)	51820	off
 wg0	+PA/xNCZ3G+Wy1DeqF251Us5mcZhBTGc9CT3AaJ89HI=	(none)	172.31.1.2:51820	198.51.100.2/32,203.0.113.0/28	0	0	0	off
 wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.100.4/32	0	0	0	off"#;
 
@@ -3709,19 +3715,19 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                     name: "wg1".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: Some(
+                        "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51821),
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: None,
+                    listen_port: Some(51820),
                 },
             ];
 
@@ -3734,12 +3740,9 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
 
         #[test]
         fn interface_not_wireguard() {
-            // wg0 exists, but is not a WireGuard interface
+            // wg0 exists, but is not a WireGuard interface, so wg does not report it
             let wg_dump = r#"wg1	wF2D1my5Cj962/MOS2UXLvCddm3ozmCSSuBQ1Ey6v3I=	Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM=	51821	off
-wg1	aHnKVQ4yTtTdfwsk+r4Z12FrRlUnXXksjRcV7x41+G0=	(none)	172.31.1.10:51820	(none)	0	0	0	off
-wg0	GDHQ8ivFvwz53U0bSmQ7uTD2bJ8GpcFCCxGeU1G9m2U=	AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M=	51820	off
-wg0	+PA/xNCZ3G+Wy1DeqF251Us5mcZhBTGc9CT3AaJ89HI=	(none)	172.31.1.2:51820	198.51.100.2/32,203.0.113.0/28	0	0	0	off
-wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.100.4/32	0	0	0	off"#;
+wg1	aHnKVQ4yTtTdfwsk+r4Z12FrRlUnXXksjRcV7x41+G0=	(none)	172.31.1.10:51820	(none)	0	0	0	off"#;
 
             let network_interfaces = network_interfaces(
                 r#"[
@@ -3756,19 +3759,19 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                     name: "wg1".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: Some(
+                        "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51821),
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: None,
                     state: WireGuardInterfaceState::Error,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: None,
+                    listen_port: None,
                 },
             ];
 
@@ -3800,19 +3803,19 @@ wg1	aHnKVQ4yTtTdfwsk+r4Z12FrRlUnXXksjRcV7x41+G0=	(none)	172.31.1.10:51820	(none)
                     name: "wg1".to_string(),
                     ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
-                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51821,
+                    public_key: Some(
+                        "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
+                            .parse()
+                            .expect("valid public key"),
+                    ),
+                    listen_port: Some(51821),
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
                     ty: None,
                     state: WireGuardInterfaceState::Error,
-                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
-                        .parse()
-                        .expect("valid public key"),
-                    listen_port: 51820,
+                    public_key: None,
+                    listen_port: None,
                 },
             ];
 
-- 
2.47.3





  parent reply	other threads:[~2026-11-20 16:02 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 ` [PATCH proxmox-perl-rs 01/10] pve-rs: sdn: fabrics: wireguard: return empty status for non-member nodes Stefan Hanreich
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 ` Stefan Hanreich [this message]
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-4-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