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 02/10] pve-rs: sdn: status: wireguard: only report type of WireGuard interfaces
Date: Fri, 20 Nov 2026 17:00:17 +0100	[thread overview]
Message-ID: <20261120160026.512565-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261120160026.512565-1-s.hanreich@proxmox.com>

The interface status always reported the type 'wireguard', even for
an interface that exists, but is not a WireGuard interface, which is
exactly what the 'error' state indicates.

Report the type 'wireguard' only if the interface on the node actually
is a WireGuard interface, and omit it otherwise. The state already
shows whether the interface is missing or is not a WireGuard interface.
The kind of other interfaces is not reported, since anyone who can
configure the fabric could otherwise query it for any interface on the
node.

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

diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs
index 881b97f..59be427 100644
--- a/pve-rs/src/sdn/status.rs
+++ b/pve-rs/src/sdn/status.rs
@@ -191,8 +191,8 @@ pub mod wireguard {
     #[serde(rename_all = "kebab-case")]
     pub struct InterfaceStatus {
         pub name: String,
-        #[serde(rename = "type")]
-        pub ty: String,
+        #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
+        pub ty: Option<String>,
         pub state: WireGuardInterfaceState,
         pub public_key: PublicKey,
         pub listen_port: u16,
@@ -318,9 +318,15 @@ pub mod wireguard {
             .map(|interface| {
                 let name = interface.name().as_ref();
                 let running_interface = running_interfaces.get(name);
+                let network_interface = network_interfaces.get(name);
+
+                let state = interface_state(network_interface, running_interface.is_some());
 
-                let state =
-                    interface_state(network_interfaces.get(name), running_interface.is_some());
+                // do not report the kind of other interfaces, since anyone who can configure the
+                // fabric could otherwise query it for any interface on the node
+                let ty = network_interface
+                    .is_some_and(is_wireguard_interface)
+                    .then(|| "wireguard".to_string());
 
                 let (public_key, listen_port) = match running_interface {
                     Some((Some(public_key), listen_port)) => (*public_key, *listen_port),
@@ -329,7 +335,7 @@ pub mod wireguard {
 
                 InterfaceStatus {
                     name: name.to_string(),
-                    ty: "wireguard".to_string(),
+                    ty,
                     state,
                     public_key,
                     listen_port,
@@ -3565,7 +3571,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
             let expected = vec![
                 InterfaceStatus {
                     name: "wg1".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Down,
                     public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
                         .parse()
@@ -3574,7 +3580,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
                         .parse()
@@ -3609,7 +3615,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
             let expected = vec![
                 InterfaceStatus {
                     name: "wg1".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: None,
                     state: WireGuardInterfaceState::Missing,
                     public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
                         .parse()
@@ -3618,7 +3624,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
                         .parse()
@@ -3654,7 +3660,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
             let expected = vec![
                 InterfaceStatus {
                     name: "wg1".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Unknown,
                     public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
                         .parse()
@@ -3663,7 +3669,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
                         .parse()
@@ -3701,7 +3707,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
             let expected = vec![
                 InterfaceStatus {
                     name: "wg1".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
                         .parse()
@@ -3710,7 +3716,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
                         .parse()
@@ -3748,7 +3754,51 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
             let expected = vec![
                 InterfaceStatus {
                     name: "wg1".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: Some("wireguard".to_string()),
+                    state: WireGuardInterfaceState::Up,
+                    public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
+                        .parse()
+                        .expect("valid public key"),
+                    listen_port: 51821,
+                },
+                InterfaceStatus {
+                    name: "wg0".to_string(),
+                    ty: None,
+                    state: WireGuardInterfaceState::Error,
+                    public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
+                        .parse()
+                        .expect("valid public key"),
+                    listen_port: 51820,
+                },
+            ];
+
+            assert_eq!(
+                expected,
+                parse_wireguard_interfaces(wg_dump, elementalist(fabric), &network_interfaces)
+                    .expect("can parse wireguard output")
+            );
+        }
+
+        #[test]
+        fn interface_without_link_kind() {
+            // wg0 is a physical NIC, which has no link kind and is not reported by wg
+            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"#;
+
+            let network_interfaces = network_interfaces(
+                r#"[
+                {"ifname": "wg0", "ifindex": 2, "link_type": "ether", "address": "bc:24:11:aa:bb:cc", "operstate": "UP", "flags": ["BROADCAST", "MULTICAST", "UP", "LOWER_UP"]},
+                {"ifname": "wg1", "ifindex": 24, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "UP", "LOWER_UP"]}
+            ]"#,
+            );
+
+            let config = fabric_config();
+            let fabric = wireguard_fabric(&config);
+
+            let expected = vec![
+                InterfaceStatus {
+                    name: "wg1".to_string(),
+                    ty: Some("wireguard".to_string()),
                     state: WireGuardInterfaceState::Up,
                     public_key: "Um+Z4Ymq3r24txH2itVVtC86ra1PIrFs9AeMebESdWM="
                         .parse()
@@ -3757,7 +3807,7 @@ wg0	8ybxvVfiWqpBG160nMgH14acR3z31ZeceW7ita0zonA=	(none)	172.31.1.4:51820	198.51.
                 },
                 InterfaceStatus {
                     name: "wg0".to_string(),
-                    ty: "wireguard".to_string(),
+                    ty: None,
                     state: WireGuardInterfaceState::Error,
                     public_key: "AQkUKUJXOxR/QH6fjZLx8GO1ZnnD8PueRYMJNOCzc2M="
                         .parse()
-- 
2.47.3





  parent 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 ` [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 ` Stefan Hanreich [this message]
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-3-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