From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 29E221FF0AA for ; Tue, 17 Nov 2026 19:36:47 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 800B8216CB; Tue, 17 Nov 2026 19:35:47 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs v2 07/11] sdn status: fabrics: check interfaces and peers for wireguard status Date: Tue, 17 Nov 2026 19:34:54 +0100 Message-ID: <20261117183500.750636-8-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117183500.750636-1-s.hanreich@proxmox.com> References: <20261117183500.750636-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: 1794940507566 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.246 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: Z25N3MYPMX3XDTIUUJ3I57T4N5MOO636 X-Message-ID-Hash: Z25N3MYPMX3XDTIUUJ3I57T4N5MOO636 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: Previously, a WireGuard fabric was always reported as ok, since there are no routes from a routing daemon that could be checked. Instead, report a WireGuard fabric as ok if all of its interfaces on the node are up and use their configured public key and listen port, and the running WireGuard configuration of each interface contains exactly the configured peers. The configuration is taken from the running configuration, so this catches nodes where it is not in effect, e.g. because applying it failed on this node. This includes interfaces that do not exist or are down, interfaces without a private key or with a different one (e.g. after a failed key rotation), interfaces listening on a different port, peers that are missing and stale peers that are still present. Handshakes are not considered, since peers do not exchange any if no traffic is sent and persistent keepalive is disabled, which would report healthy fabrics as not ok. `wg show` is only called if the node is part of a WireGuard fabric. If it fails, or its output cannot be parsed, only the WireGuard fabrics are reported as not ok, since their state cannot be determined, while the status of the other fabrics is still reported. Signed-off-by: Stefan Hanreich --- pve-rs/src/bindings/sdn/fabrics.rs | 22 +- pve-rs/src/sdn/status.rs | 373 ++++++++++++++++++++++++++++- 2 files changed, 386 insertions(+), 9 deletions(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 73fc898..6726045 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -1095,7 +1095,8 @@ pub mod pve_rs_sdn_fabrics { /// /// Go through all fabrics in the config, then filter out the ones that exist on this node. /// Check if there are any routes in the routing table that use the interface specified in the - /// config. If there are, show "ok" as status, otherwise "not ok". + /// config. If there are, show "ok" as status, otherwise "not ok". For WireGuard fabrics, check + /// whether all configured interfaces are up and all configured peers are present instead. #[export] fn status() -> Result, Error> { // This gets called every few seconds from pve to get the status of the fabrics into the @@ -1183,7 +1184,24 @@ pub mod pve_rs_sdn_fabrics { bgp: bgp_routes, }; - status::get_status(config, route_status, proxmox_sys::nodename()) + let node_name = proxmox_sys::nodename(); + + let has_wireguard_node = config.all_nodes().any(|(node_id, node)| { + node_id.as_str() == node_name && matches!(node, ConfigNode::WireGuard(_)) + }); + + // a failure only marks the WireGuard fabrics as not ok, instead of failing the status of + // all fabrics + let wireguard = has_wireguard_node + .then(|| -> Result { + Ok(status::WireGuardParsed { + dump: get_wireguard_dump()?, + network_interfaces: get_network_interfaces()?, + }) + }) + .and_then(Result::ok); + + status::get_status(config, route_status, wireguard.as_ref(), node_name) } /// Get all the L3 routes for the passed zone. diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs index ddbe797..64ffb98 100644 --- a/pve-rs/src/sdn/status.rs +++ b/pve-rs/src/sdn/status.rs @@ -6,6 +6,7 @@ use proxmox_network_types::mac_address::MacAddress; use serde::{Deserialize, Serialize}; use proxmox_frr::de::{self}; +use proxmox_network_api::IpLink; use proxmox_ve_config::sdn::fabric::section_config::protocol::bgp::BgpNode; use proxmox_ve_config::sdn::fabric::section_config::protocol::ospf::{ OspfNodeProperties, OspfProperties, @@ -13,7 +14,7 @@ use proxmox_ve_config::sdn::fabric::section_config::protocol::ospf::{ use proxmox_ve_config::{ common::valid::Valid, sdn::fabric::{ - Entry, FabricConfig, + Entry, FabricConfig, FabricEntry, section_config::{Section, fabric::FabricId, node::Node as ConfigNode, node::NodeId}, }, }; @@ -420,6 +421,82 @@ pub mod wireguard { Ok(neighbors) } + + /// 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 and + /// listen port, and the running WireGuard configuration of each interface contains exactly the + /// configured peers. Handshakes are not considered, since peers do not exchange any if no traffic is sent + /// and persistent keepalive is disabled. + pub fn is_node_ok( + wg_dump_output: &str, + node_section: &NodeSection, + fabric: &Entry, + network_interfaces: &HashMap, + ) -> Result { + let interfaces = + parse_wireguard_interfaces(wg_dump_output, node_section, network_interfaces)?; + + if interfaces + .iter() + .any(|interface| interface.state != WireGuardInterfaceState::Up) + { + return Ok(false); + } + + let WireGuardNode::Internal(wireguard_node) = node_section.properties() else { + anyhow::bail!("is not an internal node"); + }; + + let interface_names: HashSet<&str> = wireguard_node + .interfaces() + .map(|interface| interface.name().as_ref()) + .collect(); + + let running_interfaces = parse_running_interfaces(wg_dump_output, &interface_names)?; + + // peers only reach the interface with the configured public key and listen port, which can + // differ from the running ones if e.g. a key rotation failed to apply or the private key is + // unset + for interface in wireguard_node.interfaces() { + let Some((Some(public_key), listen_port)) = + running_interfaces.get(interface.name().as_ref()) + else { + return Ok(false); + }; + + if public_key != interface.public_key() || *listen_port != interface.listen_port() { + return Ok(false); + } + } + + let mut running_peers: HashMap> = HashMap::new(); + + for neighbor in parse_wireguard_neighbors(wg_dump_output, node_section, fabric)? { + running_peers + .entry(neighbor.interface) + .or_default() + .insert(neighbor.public_key); + } + + for interface in interfaces { + let configured_peers: HashSet = fabric + .interface_peers(node_section.id().node_id(), &interface.name)? + .into_iter() + .map(|peer| *peer.public_key()) + .collect(); + + let running_peers = running_peers.remove(&interface.name).unwrap_or_default(); + + // peers that are missing as well as stale ones, e.g. because applying the + // configuration failed on this node, mean that the configuration is not in effect + if configured_peers != running_peers { + return Ok(false); + } + } + + Ok(true) + } } mod bgp { @@ -527,12 +604,14 @@ pub enum Protocol { } /// The status of a fabric. -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, PartialEq, Eq)] pub enum FabricStatus { - /// The fabric exists and has a route + /// The fabric exists and has a route, or for WireGuard, all interfaces are up and all peers + /// are present #[serde(rename = "ok")] Ok, - /// The fabric does not exist or doesn't distribute any routes + /// The fabric does not exist or doesn't distribute any routes, or for WireGuard, an interface + /// is not up or a peer is missing #[serde(rename = "not ok")] NotOk, } @@ -552,6 +631,15 @@ pub struct Status { network_type: String, } +/// Runtime state of WireGuard on this node +/// +/// Consists of the output of `wg show all dump` and the network interfaces as reported by +/// `ip link`. +pub struct WireGuardParsed { + pub dump: String, + pub network_interfaces: HashMap, +} + /// Parsed routes for all protocols /// /// These are the routes parsed from the json output of: @@ -868,6 +956,7 @@ pub struct BgpNeighborInfo { pub fn get_status( config: Valid, routes: RoutesParsed, + wireguard: Option<&WireGuardParsed>, hostname: &str, ) -> Result, anyhow::Error> { let mut stats: HashMap = HashMap::new(); @@ -921,7 +1010,7 @@ pub fn get_status( Protocol::Openfabric if has_routes => FabricStatus::Ok, Protocol::Ospf if has_routes => FabricStatus::Ok, Protocol::Bgp if has_routes => FabricStatus::Ok, - Protocol::WireGuard => FabricStatus::Ok, + Protocol::WireGuard => get_wireguard_status(&config, node, wireguard), _ => FabricStatus::NotOk, }; @@ -937,6 +1026,35 @@ pub fn get_status( Ok(stats) } + +/// Determine the status of a WireGuard fabric on this node. +/// +/// Errors only mark the WireGuard fabric as not ok, so that they do not affect the status of the +/// other fabrics. +fn get_wireguard_status( + config: &FabricConfig, + node: &ConfigNode, + wireguard: Option<&WireGuardParsed>, +) -> FabricStatus { + let (ConfigNode::WireGuard(node_section), Some(wireguard)) = (node, wireguard) else { + return FabricStatus::NotOk; + }; + + let Ok(FabricEntry::WireGuard(fabric)) = config.get_fabric(node_section.id().fabric_id()) + else { + return FabricStatus::NotOk; + }; + + match wireguard::is_node_ok( + &wireguard.dump, + node_section, + fabric, + &wireguard.network_interfaces, + ) { + Ok(true) => FabricStatus::Ok, + _ => FabricStatus::NotOk, + } +} /// Common for nexthops, they can be either a interface name or a ip addr #[derive(Debug, Serialize, PartialEq, Eq)] #[serde(untagged)] @@ -3133,8 +3251,8 @@ mod tests { }; use super::super::wireguard::{ - InterfaceStatus, NeighborStatus, WireGuardInterfaceState, parse_wireguard_interfaces, - parse_wireguard_neighbors, + InterfaceStatus, NeighborStatus, WireGuardInterfaceState, is_node_ok, + parse_wireguard_interfaces, parse_wireguard_neighbors, }; use super::super::*; @@ -3593,5 +3711,246 @@ wg0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= (none) (none) (none) 0 0 0 off" .expect("can parse wireguard output") ); } + + #[test] + fn node_ok() { + // all interfaces are up and have exactly the configured peers + 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_interface_down() { + // wg1 is down + 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "UP", "LOWER_UP"]}, + {"ifname": "wg1", "ifindex": 24, "link_type": "none", "operstate": "DOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP"]} + ]"#, + ); + + let config = fabric_config(); + let fabric = wireguard_fabric(&config); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_interface_missing() { + // wg1 does not exist on the node + 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "UP", "LOWER_UP"]} + ]"#, + ); + + let config = fabric_config(); + let fabric = wireguard_fabric(&config); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_peer_missing() { + // chronomancer is missing from wg0 + 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_stale_peer() { + // wg0 has a peer that is not part of the configuration + 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 +wg0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= (none) (none) (none) 0 0 0 off"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_other_public_key() { + // wg0 uses a different key pair than the configured one + 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 YJ8M0XCvVUu1x1Y2fdLmSQ8w1qtlDgFr3cZyfW8ivUc= AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_without_private_key() { + // wg0 has no private 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) 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn node_not_ok_other_listen_port() { + // wg0 listens on 51899 instead of the configured 51820 + 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= 51899 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"#; + + let network_interfaces = network_interfaces( + r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "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); + + assert!( + !is_node_ok(wg_dump, elementalist(fabric), fabric, &network_interfaces) + .expect("can parse wireguard output") + ); + } + + #[test] + fn fabric_status_ok() { + // the running WireGuard state matches the configuration + let wireguard = WireGuardParsed { + 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"#.to_string(), + network_interfaces: network_interfaces(r#"[ + {"ifname": "wg0", "ifindex": 25, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "UP", "LOWER_UP"]}, + {"ifname": "wg1", "ifindex": 24, "link_type": "none", "operstate": "UNKNOWN", "linkinfo": {"info_kind": "wireguard"}, "flags": ["POINTOPOINT", "NOARP", "UP", "LOWER_UP"]} + ]"#), + }; + + let routes = RoutesParsed { + openfabric: de::Routes::default(), + ospf: de::Routes::default(), + bgp: de::Routes::default(), + }; + + let status = get_status(fabric_config(), routes, Some(&wireguard), "elementalist") + .expect("can determine fabric status"); + + let fabric_id = FabricId::from_str("test").expect("valid fabric id"); + assert_eq!(FabricStatus::Ok, status[&fabric_id].status); + } + + #[test] + fn fabric_status_not_ok_without_wireguard_state() { + // the WireGuard state could not be determined, e.g. because wg failed + let routes = RoutesParsed { + openfabric: de::Routes::default(), + ospf: de::Routes::default(), + bgp: de::Routes::default(), + }; + + let status = get_status(fabric_config(), routes, None, "elementalist") + .expect("can determine fabric status"); + + let fabric_id = FabricId::from_str("test").expect("valid fabric id"); + assert_eq!(FabricStatus::NotOk, status[&fabric_id].status); + } } } -- 2.47.3