From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id EAE2E1FF0DA for ; Thu, 19 Nov 2026 20:41:43 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 95D4321778; Thu, 19 Nov 2026 20:41:27 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-ve-rs v3 04/28] sdn: generate fabric routing configuration in zone VRFs Date: Thu, 19 Nov 2026 20:40:50 +0100 Message-ID: <20261119194116.575520-5-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194116.575520-1-g.goller@proxmox.com> References: <20261119194116.575520-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795117281497 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.239 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: DMADPTFTKAZDJEESO53XG4542CIMQLBE X-Message-ID-Hash: DMADPTFTKAZDJEESO53XG4542CIMQLBE X-MailFrom: g.goller@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: Map a fabric zone to the corresponding vrf_ FRR instance. Generate OSPF routers and interfaces in that VRF, and store BGP routers under the same VRF name. Keep fabrics without a zone in the default routing table. Collect OSPF redistribution rules on the router for the selected VRF so that several fabrics in one VRF contribute to the same OSPF instance. This keeps protocol configuration and interface configuration in the routing table selected by the zone. Signed-off-by: Gabriel Goller --- proxmox-ve-config/src/sdn/fabric/frr.rs | 71 +++++++++++++++---------- proxmox-ve-config/src/sdn/fabric/mod.rs | 10 ++++ 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/proxmox-ve-config/src/sdn/fabric/frr.rs b/proxmox-ve-config/src/sdn/fabric/frr.rs index 462ee72ad38e..ea042b2fea01 100644 --- a/proxmox-ve-config/src/sdn/fabric/frr.rs +++ b/proxmox-ve-config/src/sdn/fabric/frr.rs @@ -1,3 +1,4 @@ +use std::collections::{BTreeMap, btree_map}; use std::net::{IpAddr, Ipv4Addr}; use tracing; @@ -18,6 +19,7 @@ use proxmox_sdn_types::net::Net; use crate::common::valid::Valid; +use crate::sdn::ZoneName; use crate::sdn::fabric::section_config::protocol::bgp::{BgpNode, bgp_router_id}; use crate::sdn::fabric::section_config::protocol::{ bgp::BgpRedistributionSource, @@ -27,7 +29,7 @@ use crate::sdn::fabric::section_config::protocol::{ use crate::sdn::fabric::section_config::{fabric::FabricId, node::NodeId}; use crate::sdn::fabric::{FabricConfig, FabricEntry}; -/// Constructs the FRR config from the the passed [`Valid`]. +/// Constructs the FRR config from the passed [`Valid`]. /// /// Iterates over the [`FabricConfig`] and constructs all the FRR routers, interfaces, route-maps, /// etc. @@ -37,7 +39,9 @@ pub fn build_fabric( frr_config: &mut FrrConfig, ) -> Result<(), anyhow::Error> { let mut routemap_seq = 100; - let mut current_router_id: Option = None; + // OSPF router IDs only need to be unique within a VRF, and node addresses are only unique + // within a VRF, so pick the router ID per VRF. + let mut ospf_router_ids: BTreeMap = BTreeMap::new(); let mut current_net: Option = None; for (fabric_id, entry) in config.into_inner().iter() { @@ -199,34 +203,37 @@ pub fn build_fabric( continue; }; - let router_id = current_router_id - .get_or_insert(node.ip().expect("node must have an ipv4 address")); - let fabric = ospf_entry.fabric_section(); + let vrf_name = fabric_vrf_name(fabric.properties().zone())?; + + let router_id = ospf_router_ids + .entry(vrf_name.clone()) + .or_insert(node.ip().expect("node must have an ipv4 address")); let frr_word_area = ser::FrrWord::new(fabric.properties().area.to_string())?; let frr_area = ser::ospf::Area::new(frr_word_area)?; - if !frr_config.ospf.vrf_router.contains_key(&VrfName::Default) { - let mut ospf_router = build_ospf_router(*router_id)?; - - ospf_router.redistribute = fabric - .properties() - .redistributions() - .into_iter() - .cloned() - .map(OspfRedistribution::from) - .collect(); + let redistributions = fabric + .properties() + .redistributions() + .into_iter() + .cloned() + .map(OspfRedistribution::from); + + let ospf_router = match frr_config.ospf.vrf_router.entry(vrf_name.clone()) { + btree_map::Entry::Occupied(entry) => entry.into_mut(), + btree_map::Entry::Vacant(entry) => entry.insert(build_ospf_router(*router_id)?), + }; + ospf_router.redistribute.extend(redistributions); - frr_config - .ospf - .vrf_router - .insert(VrfName::Default, ospf_router); - } + let interface_vrf = match &vrf_name { + VrfName::Default => None, + custom => Some(custom.clone()), + }; // Add dummy interface let (interface, interface_name) = - build_ospf_dummy_interface(fabric_id, frr_area.clone())?; + build_ospf_dummy_interface(fabric_id, frr_area.clone(), interface_vrf.clone())?; if frr_config .ospf @@ -241,7 +248,7 @@ pub fn build_fabric( for interface in node.properties().interfaces.iter() { let (interface, interface_name) = - build_ospf_interface(frr_area.clone(), interface)?; + build_ospf_interface(frr_area.clone(), interface, interface_vrf.clone())?; if frr_config .ospf @@ -308,6 +315,7 @@ pub fn build_fabric( }; let fabric = bgp_entry.fabric_section(); + let vrf_name = fabric_vrf_name(fabric.properties().zone())?; let local_asn = properties.asn().as_u32(); @@ -322,7 +330,7 @@ pub fn build_fabric( let local_as = frr_config .bgp .vrf_router - .get(&VrfName::Default) + .get(&vrf_name) .filter(|existing| existing.asn != local_asn) .map(|_| LocalAsSettings { asn: local_asn, @@ -557,10 +565,10 @@ pub fn build_fabric( custom_frr_config: Default::default(), }; - if let Some(existing) = frr_config.bgp.vrf_router.get_mut(&VrfName::Default) { + if let Some(existing) = frr_config.bgp.vrf_router.get_mut(&vrf_name) { existing.merge_fabric(router); } else { - frr_config.bgp.vrf_router.insert(VrfName::Default, router); + frr_config.bgp.vrf_router.insert(vrf_name, router); } } } @@ -590,6 +598,13 @@ pub fn build_fabric( Ok(()) } +fn fabric_vrf_name(zone: Option<&ZoneName>) -> Result { + Ok(match zone { + Some(zone) => VrfName::Custom(FrrWord::new(format!("vrf_{zone}"))?), + None => VrfName::Default, + }) +} + /// Helper that builds a OSPF router with a the router_id. fn build_ospf_router(router_id: Ipv4Addr) -> Result { Ok(OspfRouter::new(router_id)) @@ -610,6 +625,7 @@ fn build_openfabric_router( fn build_ospf_interface( area: ser::ospf::Area, interface: &OspfInterfaceProperties, + vrf: Option, ) -> Result<(Interface, InterfaceName), anyhow::Error> { let frr_interface = ser::ospf::OspfInterface { area, @@ -625,7 +641,7 @@ fn build_ospf_interface( } Some(network_type) => Some(network_type), }, - vrf: None, + vrf, }; let interface_name = interface.name.as_ref().try_into()?; @@ -636,12 +652,13 @@ fn build_ospf_interface( fn build_ospf_dummy_interface( fabric_id: &FabricId, area: ospf::Area, + vrf: Option, ) -> Result<(Interface, InterfaceName), anyhow::Error> { let frr_interface = ser::ospf::OspfInterface { area, passive: Some(true), network_type: None, - vrf: None, + vrf, }; let interface_name = format!("dummy_{}", fabric_id).try_into()?; Ok((frr_interface.into(), interface_name)) diff --git a/proxmox-ve-config/src/sdn/fabric/mod.rs b/proxmox-ve-config/src/sdn/fabric/mod.rs index ae74b981f285..9915ebdf7a3f 100644 --- a/proxmox-ve-config/src/sdn/fabric/mod.rs +++ b/proxmox-ve-config/src/sdn/fabric/mod.rs @@ -541,6 +541,16 @@ impl FabricEntry { FabricEntry::Bgp(entry) => &mut entry.fabric, } } + + pub fn fabric_vrf_name(&self) -> Option { + let zone = match self { + FabricEntry::Ospf(entry) => entry.fabric_section().properties().zone(), + FabricEntry::Bgp(entry) => entry.fabric_section().properties().zone(), + FabricEntry::Openfabric(_) | FabricEntry::WireGuard(_) => None, + }; + + zone.map(|zone| format!("vrf_{zone}")) + } } impl From for FabricEntry { -- 2.47.3