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 9CAB41FF0AF for ; Fri, 20 Nov 2026 17:02:04 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 78A6E218D0; Fri, 20 Nov 2026 17:00:42 +0100 (CET) From: Stefan Hanreich 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 Message-ID: <20261120160026.512565-4-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: 1795190433134 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.199 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: T63UMNQ3ZE3QBDU2HE424OKN7AMJIBFW X-Message-ID-Hash: T63UMNQ3ZE3QBDU2HE424OKN7AMJIBFW 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: 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 --- 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, pub state: WireGuardInterfaceState, - pub public_key: PublicKey, - pub listen_port: u16, + #[serde(skip_serializing_if = "Option::is_none")] + pub public_key: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub listen_port: Option, } 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, @@ -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