[pve-devel] [PATCH proxmox-ve-rs 09/17] frr: add route-map types
Gabriel Goller
g.goller at proxmox.com
Fri Mar 28 18:12:58 CET 2025
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 at 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
More information about the pve-devel
mailing list