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 714CF1FF15C
	for <inbox@lore.proxmox.com>; Fri,  4 Apr 2025 18:32:25 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id C330F37FF4;
	Fri,  4 Apr 2025 18:29:55 +0200 (CEST)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri,  4 Apr 2025 18:28:18 +0200
Message-Id: <20250404162908.563060-8-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-ve-rs v2 06/15] 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       |   1 +
 proxmox-frr/src/route_map.rs | 128 +++++++++++++++++++++++++++++++++++
 2 files changed, 129 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 750d7ea07326..42f0800c536a 100644
--- a/proxmox-frr/src/lib.rs
+++ b/proxmox-frr/src/lib.rs
@@ -1,5 +1,6 @@
 pub mod openfabric;
 pub mod ospf;
+pub mod route_map;
 use std::{fmt::Display, str::FromStr};
 
 use serde::{Deserialize, Serialize};
diff --git a/proxmox-frr/src/route_map.rs b/proxmox-frr/src/route_map.rs
new file mode 100644
index 000000000000..fd6a741d7039
--- /dev/null
+++ b/proxmox-frr/src/route_map.rs
@@ -0,0 +1,128 @@
+use std::{
+    fmt::{self, Display},
+    net::IpAddr,
+};
+
+use proxmox_network_types::ip_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