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 002961FF164
	for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:22:07 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 34F099D61;
	Fri, 28 Mar 2025 18:21:51 +0100 (CET)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 28 Mar 2025 18:13:14 +0100
Message-Id: <20250328171340.885413-27-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.024 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 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 | 54 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/pve-rs/src/sdn/ospf.rs b/pve-rs/src/sdn/ospf.rs
index 63ce0d53ffb8..9f6a7302e0db 100644
--- a/pve-rs/src/sdn/ospf.rs
+++ b/pve-rs/src/sdn/ospf.rs
@@ -337,6 +337,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 == node {
+                    // create dummy interface for this fabric
+                    writeln!(interfaces)?;
+                    writeln!(interfaces, "auto dummy_{}", node_section.node_id.area)?;
+                    writeln!(
+                        interfaces,
+                        "iface dummy_{} inet static",
+                        node_section.node_id.area
+                    )?;
+                    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()
+                        .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")?;
+                            } 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