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 3107A1FF164
	for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:22:02 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 7726E9D16;
	Fri, 28 Mar 2025 18:21:48 +0100 (CET)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 28 Mar 2025 18:13:11 +0100
Message-Id: <20250328171340.885413-24-g.goller@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250328171340.885413-1-g.goller@proxmox.com>
References: <20250328171340.885413-1-g.goller@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.026 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
Subject: [pve-devel] [PATCH proxmox-perl-rs 4/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 OpenFabric nodes:
- Auto-create dummy interfaces with proper router-id
- Configure interface addresses and IP forwarding
- Support for both IPv4 and IPv6 addressing on both dummy and other
  interfaces

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pve-rs/src/sdn/openfabric.rs | 72 ++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/pve-rs/src/sdn/openfabric.rs b/pve-rs/src/sdn/openfabric.rs
index 680b3d081e47..2d21e6dae5e1 100644
--- a/pve-rs/src/sdn/openfabric.rs
+++ b/pve-rs/src/sdn/openfabric.rs
@@ -353,6 +353,78 @@ mod export {
             .ok_or(anyhow::anyhow!("node not found"))
     }
 
+    #[export]
+    fn get_interfaces_etc_network_config(
+        #[try_from_ref] this: &PerlSectionConfig<OpenFabricSectionConfig>,
+        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 OpenFabricSectionConfig::Node(node_section) = section.1 {
+                if node_section.node_id.node == node {
+                    // create dummy interface for this fabric
+                    writeln!(interfaces)?;
+                    writeln!(interfaces, "auto dummy_{}", node_section.node_id.fabric_id)?;
+                    match node_section.router_id {
+                        IpAddr::V4(_) => writeln!(
+                            interfaces,
+                            "iface dummy_{} inet static",
+                            node_section.node_id.fabric_id
+                        )?,
+                        IpAddr::V6(_) => writeln!(
+                            interfaces,
+                            "iface dummy_{} inet6 static",
+                            node_section.node_id.fabric_id
+                        )?,
+                    }
+                    writeln!(interfaces, "\tlink-type dummy")?;
+                    writeln!(interfaces, "\tip-forward 1")?;
+                    // add dummy interface address as /32
+                    match node_section.router_id {
+                        IpAddr::V4(ipv4_addr) => {
+                            writeln!(interfaces, "\taddress {}/32", ipv4_addr)?
+                        }
+                        IpAddr::V6(ipv6_addr) => {
+                            writeln!(interfaces, "\taddress {}/128", ipv6_addr)?
+                        }
+                    }
+
+                    // 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()
+                        .interface
+                        .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")?;
+                            }
+                            if let Some(ipv6) = i.ipv6.map(|i| i.to_string()) {
+                                writeln!(interfaces, "iface {interface_name} inet6 static")?;
+                                writeln!(interfaces, "\taddress {ipv6}")?;
+                                writeln!(interfaces, "\tip6-forward 1")?;
+                            }
+                            if i.ip.is_none() && i.ipv6.is_none() {
+                                writeln!(interfaces, "iface {interface_name} inet manual")?;
+                                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<OpenFabricSectionConfig>,
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel