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 4296D1FF164 for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:17:19 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 39C0A9247; Fri, 28 Mar 2025 18:14:23 +0100 (CET) From: Gabriel Goller <g.goller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 28 Mar 2025 18:12:58 +0100 Message-Id: <20250328171340.885413-11-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 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-ve-rs 09/17] frr: add route-map types 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> Only a very limited featureset of the route-maps is implemented here, only the stuff needed by the fabrics. Once standalone route-maps will make it into pve, we will build these out and maybe rework them a little. We need the RouteMaps for the Fabrics, because otherwise, the routes between to the route-ids will be distibuted, but won't be pingable, because because the source address is wrong. By rewriting the source we guarantee that a ping will always find it's way back to the source router-id. Signed-off-by: Gabriel Goller <g.goller@proxmox.com> --- proxmox-frr/src/lib.rs | 2 + proxmox-frr/src/route_map.rs | 128 +++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 proxmox-frr/src/route_map.rs diff --git a/proxmox-frr/src/lib.rs b/proxmox-frr/src/lib.rs index 1160a71b3d9c..1a657c087ff0 100644 --- a/proxmox-frr/src/lib.rs +++ b/proxmox-frr/src/lib.rs @@ -1,7 +1,9 @@ pub mod openfabric; pub mod ospf; +pub mod route_map; use std::{collections::BTreeMap, fmt::Display, str::FromStr}; +use route_map::{AccessList, AccessListName, ProtocolRouteMap, RouteMap}; use serde::{Deserialize, Serialize}; use serde_with::{DeserializeFromStr, SerializeDisplay}; use thiserror::Error; diff --git a/proxmox-frr/src/route_map.rs b/proxmox-frr/src/route_map.rs new file mode 100644 index 000000000000..16ff87bfa6aa --- /dev/null +++ b/proxmox-frr/src/route_map.rs @@ -0,0 +1,128 @@ +use std::{ + fmt::{self, Display}, + net::IpAddr, +}; + +use proxmox_network_types::address::Cidr; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum AccessAction { + Permit, + Deny, +} + +impl fmt::Display for AccessAction { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AccessAction::Permit => write!(f, "permit"), + AccessAction::Deny => write!(f, "deny"), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct AccessListRule { + pub action: AccessAction, + pub network: Cidr, + pub seq: Option<u32>, +} + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct AccessListName(String); + +impl AccessListName { + pub fn new(name: String) -> AccessListName { + AccessListName(name) + } +} + +impl Display for AccessListName { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct AccessList { + pub name: AccessListName, + pub rules: Vec<AccessListRule>, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum RouteMapMatch { + IpAddress(AccessListName), + IpNextHop(String), +} + +impl Display for RouteMapMatch { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RouteMapMatch::IpAddress(name) => write!(f, "match ip address {}", name), + RouteMapMatch::IpNextHop(name) => write!(f, "match ip next-hop {}", name), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum RouteMapSet { + LocalPreference(u32), + IpSrc(IpAddr), + Metric(u32), + Community(String), +} + +impl Display for RouteMapSet { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RouteMapSet::LocalPreference(pref) => write!(f, "set local-preference {}", pref), + RouteMapSet::IpSrc(addr) => write!(f, "set src {}", addr), + RouteMapSet::Metric(metric) => write!(f, "set metric {}", metric), + RouteMapSet::Community(community) => write!(f, "set community {}", community), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct RouteMapName(String); + +impl RouteMapName { + pub fn new(name: String) -> RouteMapName { + RouteMapName(name) + } +} + +impl Display for RouteMapName { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct RouteMap { + pub name: RouteMapName, + pub seq: u32, + pub action: AccessAction, + pub matches: Vec<RouteMapMatch>, + pub sets: Vec<RouteMapSet>, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ProtocolType { + OpenFabric, + Ospf, +} + +impl Display for ProtocolType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ProtocolType::OpenFabric => write!(f, "openfabric"), + ProtocolType::Ospf => write!(f, "ospf"), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ProtocolRouteMap { + pub protocol: ProtocolType, + pub routemap_name: RouteMapName, +} -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel