From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 837CE1FF183 for ; Wed, 13 Aug 2025 15:29:04 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3AE7935F7C; Wed, 13 Aug 2025 15:30:33 +0200 (CEST) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Wed, 13 Aug 2025 15:30:08 +0200 Message-ID: <20250813133023.288351-3-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250813133023.288351-1-g.goller@proxmox.com> References: <20250813133023.288351-1-g.goller@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755091796795 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.009 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [fabrics.rs] Subject: [pve-devel] [PATCH proxmox-perl-rs 2/3] fabrics: add function to get all routes distributed by the fabrics X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Add a function that returns a list of all the routes which are distributed using the fabrics. For this we again need to read the config (in order to get the interface names and thus connect the fabric to the discovered route) and we need to query frr (using vtysh) for all the routes (ipv4 and ipv6) distributed by a specific protocol (once for openfabric and once for ospf). This method is used in the FabricContentView so that clicking on the fabric resource shows the routes distributed by the fabric. Signed-off-by: Gabriel Goller --- pve-rs/src/bindings/sdn/fabrics.rs | 156 +++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index 03bc597e13ef..e211ce4af92f 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -597,6 +597,18 @@ pub mod pve_rs_sdn_fabrics { use serde::{Deserialize, Serialize}; + /// The status of a route. + /// + /// Contains the route, the fabric and protocol it belongs to and some extra nexthop + /// information. + #[derive(Debug, Serialize)] + pub struct RouteStatus { + route: String, + via: Vec, + fabric_id: FabricId, + protocol: Protocol, + } + /// Protocol #[derive(Debug, Serialize, Clone, Copy)] pub enum Protocol { @@ -642,6 +654,94 @@ pub mod pve_rs_sdn_fabrics { pub ospf: Routes, } + impl TryInto> for RoutesParsed { + type Error = anyhow::Error; + + fn try_into(self) -> Result, Self::Error> { + let hostname = proxmox_sys::nodename(); + + // to associate a route to a fabric, we get all the interfaces which are associated + // with a fabric on this node and compare them with the interfaces on the route. + let raw_config = std::fs::read_to_string("/etc/pve/sdn/fabrics.cfg")?; + let config = FabricConfig::parse_section_config(&raw_config)?; + + let mut stats: Vec = Vec::new(); + + for (nodeid, node) in config.values().flat_map(|entry| { + entry + .nodes() + .map(|(id, node)| (id.to_string(), node.clone())) + }) { + if nodeid != hostname { + continue; + } + let fabric_id = node.id().fabric_id().clone(); + + let current_protocol = match &node { + ConfigNode::Openfabric(_) => Protocol::Openfabric, + ConfigNode::Ospf(_) => Protocol::Ospf, + }; + + // get interfaces + let interface_names: HashSet = match node { + ConfigNode::Openfabric(n) => n + .properties() + .interfaces() + .map(|i| i.name().to_string()) + .collect(), + ConfigNode::Ospf(n) => n + .properties() + .interfaces() + .map(|i| i.name().to_string()) + .collect(), + }; + + let mut all_routes = HashMap::new(); + match current_protocol { + Protocol::Openfabric => all_routes.extend(&self.openfabric.0), + Protocol::Ospf => all_routes.extend(&self.ospf.0), + } + + for (route_key, route_list) in all_routes { + let mut route_belongs_to_fabric = false; + for route in route_list { + for nexthop in &route.nexthops { + if interface_names.contains(&nexthop.interface_name) { + route_belongs_to_fabric = true; + break; + } + } + if route_belongs_to_fabric { + break; + } + } + + if route_belongs_to_fabric { + let mut via_list = Vec::new(); + for route in route_list { + for nexthop in &route.nexthops { + let via = if let Some(ip) = nexthop.ip { + ip.to_string() + } else { + nexthop.interface_name.clone() + }; + via_list.push(via); + } + } + + stats.push(RouteStatus { + route: route_key.to_string(), + via: via_list, + protocol: current_protocol, + fabric_id: fabric_id.clone(), + }); + } + } + } + Ok(stats) + } + } + impl TryInto> for RoutesParsed { type Error = anyhow::Error; @@ -816,6 +916,62 @@ pub mod pve_rs_sdn_fabrics { pub struct Routes(pub HashMap>); } + /// Get all the routes for all the fabrics on this node. + /// + /// Use FRR to get all the routes that have been inserted by either `openfabric` or 'ospf` and + /// associate them with the respective fabric by checking the interface they point to. Return a + /// single array with all routes. + #[export] + fn routes() -> Result, Error> { + let openfabric_ipv4_routes_string = String::from_utf8( + Command::new("sh") + .args(["-c", "vtysh -c 'show ip route openfabric json'"]) + .output()? + .stdout, + )?; + + let openfabric_ipv6_routes_string = String::from_utf8( + Command::new("sh") + .args(["-c", "vtysh -c 'show ipv6 route openfabric json'"]) + .output()? + .stdout, + )?; + + let ospf_routes_string = String::from_utf8( + Command::new("sh") + .args(["-c", "vtysh -c 'show ip route ospf json'"]) + .output()? + .stdout, + )?; + + let mut openfabric_routes: status::Routes = if openfabric_ipv4_routes_string.is_empty() { + status::Routes::default() + } else { + serde_json::from_str(&openfabric_ipv4_routes_string) + .with_context(|| "error parsing openfabric ipv4 routes")? + }; + if !openfabric_ipv6_routes_string.is_empty() { + let openfabric_ipv6_routes: status::Routes = + serde_json::from_str(&openfabric_ipv6_routes_string) + .with_context(|| "error parsing openfabric ipv6 routes")?; + openfabric_routes.0.extend(openfabric_ipv6_routes.0); + } + + let ospf_routes: status::Routes = if ospf_routes_string.is_empty() { + status::Routes::default() + } else { + serde_json::from_str(&ospf_routes_string) + .with_context(|| "error parsing ospf routes")? + }; + + let route_status = status::RoutesParsed { + openfabric: openfabric_routes, + ospf: ospf_routes, + }; + + route_status.try_into() + } + /// Return the status of all fabrics on this node. /// /// Go through all fabrics in the config, then filter out the ones that exist on this node. -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel