From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B0C8E1FF15C for <inbox@lore.proxmox.com>; Fri, 4 Apr 2025 18:33:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6481D279; Fri, 4 Apr 2025 18:29:59 +0200 (CEST) From: Gabriel Goller <g.goller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 4 Apr 2025 18:28:34 +0200 Message-Id: <20250404162908.563060-24-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250404162908.563060-1-g.goller@proxmox.com> References: <20250404162908.563060-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.023 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-perl-rs v2 7/7] perl-rs: sdn: implement OSPF interface file configuration generation X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Add function to generate /etc/network/interfaces configuration for OSPF nodes including: - Create dummy interfaces for each area with /32 addresses - Configure IP addresses on physical interfaces - Enable IP forwarding on all relevant interfaces - Support both numbered and unnumbered interface configurations Note that the `ospfd` daemon only supports IPv4 so we only have IPv4 addresses for OSPF. In a follow-up we could also support the `ospf6d` daemon, which supports IPv6. Signed-off-by: Gabriel Goller <g.goller@proxmox.com> --- pve-rs/src/sdn/ospf.rs | 56 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/pve-rs/src/sdn/ospf.rs b/pve-rs/src/sdn/ospf.rs index 2c83d638661a..744e663ac2ac 100644 --- a/pve-rs/src/sdn/ospf.rs +++ b/pve-rs/src/sdn/ospf.rs @@ -1,6 +1,6 @@ #[perlmod::package(name = "PVE::RS::SDN::Fabrics::Ospf", lib = "pve_rs")] mod export { - use std::{collections::HashMap, net::Ipv4Addr, str, sync::Mutex}; + use std::{collections::HashMap, fmt::Write, net::Ipv4Addr, str, sync::Mutex}; use anyhow::{Context, Error}; @@ -348,6 +348,60 @@ mod export { .ok_or(anyhow::anyhow!("node not found")) } + #[export] + fn get_interfaces_etc_network_config( + #[try_from_ref] this: &PerlSectionConfig<OspfSectionConfig>, + node: Hostname, + ) -> Result<String, Error> { + let guard = this.section_config.lock().unwrap(); + let mut interfaces = String::new(); + + guard.iter().try_for_each(|section| { + if let OspfSectionConfig::Node(node_section) = section.1 { + if node_section.node_id == node { + // create dummy interface for this fabric + writeln!(interfaces)?; + writeln!(interfaces, "auto dummy_{}", node_section.fabric_id)?; + writeln!( + interfaces, + "iface dummy_{} inet static", + node_section.fabric_id + )?; + writeln!(interfaces, "\tlink-type dummy")?; + writeln!(interfaces, "\tip-forward 1")?; + // add dummy interface address as /32 + writeln!(interfaces, "\taddress {}/32", node_section.router_id)?; + + // add ip-addrs to all other interfaces and ensure they exist + // also enable ip-forwarding on all interfaces as this is needed for unnumbered + // peering + node_section + .clone() + .interfaces + .into_iter() + .try_for_each(|i| { + let interface_name = i.name.clone(); + writeln!(interfaces)?; + writeln!(interfaces, "auto {interface_name}")?; + if let Some(ip) = i.ip.map(|i| i.to_string()) { + writeln!(interfaces, "iface {interface_name} inet static")?; + writeln!(interfaces, "\taddress {}", ip)?; + writeln!(interfaces, "\tip-forward 1")?; + } else { + // unnumbered interface needs ip addresses configured in ospf + writeln!(interfaces, "iface {interface_name} inet static")?; + writeln!(interfaces, "\taddress {}/32", node_section.router_id)?; + writeln!(interfaces, "\tip-forward 1")?; + } + Ok::<(), std::fmt::Error>(()) + })?; + } + } + Ok::<(), std::fmt::Error>(()) + })?; + Ok(interfaces) + } + #[export] pub fn enabled_daemons( #[try_from_ref] this: &PerlSectionConfig<OspfSectionConfig>, -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel