From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-perl-rs v2 17/34] pve-rs: sdn: add route maps module
Date: Wed, 1 Apr 2026 16:39:26 +0200 [thread overview]
Message-ID: <20260401143957.386809-18-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20260401143957.386809-1-s.hanreich@proxmox.com>
Exposes the functionality from ve-config to Perl by providing helpers
for instantiating the Rust configuration from Perl. The module also
contains the implementation for the CRUD API methods, which will be
used in the API methods in pve-network.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
pve-rs/Cargo.toml | 1 +
pve-rs/Makefile | 1 +
pve-rs/src/bindings/sdn/mod.rs | 3 +-
pve-rs/src/bindings/sdn/route_maps.rs | 262 ++++++++++++++++++++++++++
4 files changed, 266 insertions(+), 1 deletion(-)
create mode 100644 pve-rs/src/bindings/sdn/route_maps.rs
diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index 61be324..c97e1d5 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -42,6 +42,7 @@ proxmox-notify = { version = "1", features = ["pve-context"] }
proxmox-oci = "0.2.1"
proxmox-openid = "1.0.2"
proxmox-resource-scheduling = "1.0.1"
+proxmox-schema = "5"
proxmox-section-config = "3"
proxmox-shared-cache = "1"
proxmox-subscription = "1"
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index 3bbc464..d662b00 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -31,6 +31,7 @@ PERLMOD_PACKAGES := \
PVE::RS::OpenId \
PVE::RS::ResourceScheduling::Static \
PVE::RS::SDN::Fabrics \
+ PVE::RS::SDN::RouteMaps \
PVE::RS::SDN \
PVE::RS::TFA
diff --git a/pve-rs/src/bindings/sdn/mod.rs b/pve-rs/src/bindings/sdn/mod.rs
index fde3138..c571d28 100644
--- a/pve-rs/src/bindings/sdn/mod.rs
+++ b/pve-rs/src/bindings/sdn/mod.rs
@@ -1,4 +1,5 @@
pub(crate) mod fabrics;
+pub(crate) mod route_maps;
#[perlmod::package(name = "PVE::RS::SDN", lib = "pve_rs")]
pub mod pve_rs_sdn {
@@ -7,7 +8,7 @@ pub mod pve_rs_sdn {
//! This provides general methods for generating the frr config.
use anyhow::Error;
- use proxmox_frr::ser::{FrrConfig, serializer::to_raw_config};
+ use proxmox_frr::ser::{serializer::to_raw_config, FrrConfig};
use proxmox_ve_config::common::valid::Validatable;
use proxmox_ve_config::sdn::fabric::section_config::node::NodeId;
diff --git a/pve-rs/src/bindings/sdn/route_maps.rs b/pve-rs/src/bindings/sdn/route_maps.rs
new file mode 100644
index 0000000..efac7e1
--- /dev/null
+++ b/pve-rs/src/bindings/sdn/route_maps.rs
@@ -0,0 +1,262 @@
+#[perlmod::package(name = "PVE::RS::SDN::RouteMaps", lib = "pve_rs")]
+pub mod pve_rs_sdn_route_maps {
+ //! The `PVE::RS::SDN::RouteMaps` package.
+
+ use std::collections::hash_map::Entry;
+ use std::collections::HashMap;
+ use std::ops::Deref;
+ use std::sync::Mutex;
+
+ use anyhow::{anyhow, Error};
+ use openssl::hash::{hash, MessageDigest};
+ use serde::{Deserialize, Serialize};
+
+ use perlmod::Value;
+
+ use proxmox_schema::Updater;
+ use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
+ use proxmox_ve_config::sdn::route_map::api::RouteMapDeletableProperties;
+ use proxmox_ve_config::sdn::route_map::api::RouteMapEntry as ApiRouteMap;
+ use proxmox_ve_config::sdn::route_map::api::RouteMapEntryUpdater;
+ use proxmox_ve_config::sdn::route_map::RouteMap as ConfigRouteMap;
+ use proxmox_ve_config::sdn::route_map::RouteMapEntryId;
+ use proxmox_ve_config::sdn::route_map::RouteMapId;
+
+ /// A SDN RouteMap config instance.
+ #[derive(Serialize, Deserialize)]
+ pub struct PerlRouteMapConfig {
+ /// The route map config instance
+ pub route_maps: Mutex<HashMap<String, ConfigRouteMap>>,
+ }
+
+ perlmod::declare_magic!(Box<PerlRouteMapConfig> : &PerlRouteMapConfig as "PVE::RS::SDN::RouteMaps::Config");
+
+ /// Class method: Parse the raw configuration from `/etc/pve/sdn/route-maps.cfg`.
+ #[export]
+ pub fn config(#[raw] class: Value, raw_config: &[u8]) -> Result<perlmod::Value, Error> {
+ let raw_config = std::str::from_utf8(raw_config)?;
+ let config = ConfigRouteMap::parse_section_config("route-maps.cfg", raw_config)?;
+
+ Ok(
+ perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlRouteMapConfig {
+ route_maps: Mutex::new(config.deref().clone()),
+ })),
+ )
+ }
+
+ /// Class method: Parse the configuration from `/etc/pve/sdn/.running_config`.
+ #[export]
+ pub fn running_config(
+ #[raw] class: Value,
+ route_maps: HashMap<String, ConfigRouteMap>,
+ ) -> Result<perlmod::Value, Error> {
+ Ok(
+ perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlRouteMapConfig {
+ route_maps: Mutex::new(route_maps.clone()),
+ })),
+ )
+ }
+
+ /// Method: Used for writing the running configuration.
+ #[export]
+ pub fn to_sections(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ ) -> Result<HashMap<String, ConfigRouteMap>, Error> {
+ let config = this.route_maps.lock().unwrap();
+ Ok(config.deref().clone())
+ }
+
+ /// Method: Convert the configuration into the section config string.
+ ///
+ /// Used for writing `/etc/pve/sdn/route-maps.cfg`
+ #[export]
+ pub fn to_raw(#[try_from_ref] this: &PerlRouteMapConfig) -> Result<String, Error> {
+ let config = this.route_maps.lock().unwrap();
+ let route_maps: SectionConfigData<ConfigRouteMap> =
+ SectionConfigData::from_iter(config.deref().clone());
+
+ ConfigRouteMap::write_section_config("route-maps.cfg", &route_maps)
+ }
+
+ /// Method: Generate a digest for the whole configuration.
+ #[export]
+ pub fn digest(#[try_from_ref] this: &PerlRouteMapConfig) -> Result<String, Error> {
+ let config = to_raw(this)?;
+ let hash = hash(MessageDigest::sha256(), config.as_bytes())?;
+
+ Ok(hex::encode(hash))
+ }
+
+ /// Method: Returns all route map entries as a hash indexed with the IDs of the entries.
+ #[export]
+ pub fn list(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ ) -> Result<HashMap<String, ApiRouteMap>, Error> {
+ Ok(this
+ .route_maps
+ .lock()
+ .unwrap()
+ .iter()
+ .map(|(id, route_map_entry)| {
+ let ConfigRouteMap::RouteMapEntry(route_map) = route_map_entry;
+ (id.clone(), route_map.clone().into())
+ })
+ .collect())
+ }
+
+ /// Method: Returns all entries of a given route map as a hash indexed with the IDs of the
+ /// entries.
+ #[export]
+ pub fn list_route_map(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ route_map_id: RouteMapId,
+ ) -> Result<HashMap<String, ApiRouteMap>, Error> {
+ Ok(this
+ .route_maps
+ .lock()
+ .unwrap()
+ .iter()
+ .filter_map(|(id, route_map_entry)| {
+ let ConfigRouteMap::RouteMapEntry(route_map) = route_map_entry;
+
+ if route_map.id().route_map_id() == &route_map_id {
+ return Some((id.clone(), route_map.clone().into()));
+ }
+
+ None
+ })
+ .collect())
+ }
+
+ /// Method: Create a new RouteMap entry.
+ #[export]
+ pub fn create(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ route_map: ApiRouteMap,
+ ) -> Result<(), Error> {
+ let mut route_maps = this.route_maps.lock().unwrap();
+
+ let id =
+ RouteMapEntryId::new(route_map.route_map_id().clone(), route_map.order()).to_string();
+
+ match route_maps.entry(id) {
+ Entry::Occupied(entry) => {
+ anyhow::bail!(
+ "route map entry already exists in configuration: {}",
+ entry.key()
+ )
+ }
+ Entry::Vacant(vacancy) => {
+ vacancy.insert(ConfigRouteMap::RouteMapEntry(route_map.into()))
+ }
+ };
+
+ Ok(())
+ }
+
+ /// Method: Returns a specfic entry of a RouteMap.
+ #[export]
+ pub fn get(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ route_map_id: RouteMapId,
+ order: u16,
+ ) -> Result<Option<ApiRouteMap>, Error> {
+ let id = RouteMapEntryId::new(route_map_id, order).to_string();
+
+ Ok(this
+ .route_maps
+ .lock()
+ .unwrap()
+ .get(&id)
+ .map(|route_map_entry| {
+ let ConfigRouteMap::RouteMapEntry(route_map) = route_map_entry;
+ route_map.clone().into()
+ }))
+ }
+
+ /// Method: Update a RouteMap entry.
+ #[export]
+ pub fn update(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ route_map_id: RouteMapId,
+ order: u16,
+ updater: RouteMapEntryUpdater,
+ delete: Option<Vec<RouteMapDeletableProperties>>,
+ ) -> Result<(), Error> {
+ if updater.is_empty() && delete.is_empty() {
+ return Ok(());
+ }
+
+ let mut route_maps = this.route_maps.lock().unwrap();
+ let id = RouteMapEntryId::new(route_map_id, order).to_string();
+
+ let ConfigRouteMap::RouteMapEntry(route_map) = route_maps
+ .get_mut(&id)
+ .ok_or_else(|| anyhow!("Could not find route map with id: {}", id))?;
+
+ let RouteMapEntryUpdater {
+ action,
+ set_actions,
+ match_actions,
+ exit_action,
+ call,
+ } = updater;
+
+ if let Some(action) = action {
+ route_map.set_action(action);
+ }
+
+ if let Some(match_actions) = match_actions {
+ route_map.set_match_actions(match_actions);
+ }
+
+ if let Some(set_actions) = set_actions {
+ route_map.set_set_actions(set_actions);
+ }
+
+ if exit_action.is_some() {
+ route_map.set_exit_action(exit_action);
+ }
+
+ if call.is_some() {
+ route_map.set_call(call);
+ }
+
+ for deletable_property in delete.unwrap_or_default() {
+ match deletable_property {
+ RouteMapDeletableProperties::Set => {
+ route_map.set_set_actions(Vec::new());
+ }
+ RouteMapDeletableProperties::Match => {
+ route_map.set_match_actions(Vec::new());
+ }
+ RouteMapDeletableProperties::ExitAction => {
+ route_map.set_exit_action(None);
+ }
+ RouteMapDeletableProperties::Call => {
+ route_map.set_call(None);
+ }
+ }
+ }
+
+ Ok(())
+ }
+
+ /// Method: Delete an entry in a RouteMap.
+ #[export]
+ pub fn delete(
+ #[try_from_ref] this: &PerlRouteMapConfig,
+ route_map_id: RouteMapId,
+ order: u16,
+ ) -> Result<(), Error> {
+ let id = RouteMapEntryId::new(route_map_id, order).to_string();
+
+ this.route_maps
+ .lock()
+ .unwrap()
+ .remove(&id.to_string())
+ .ok_or_else(|| anyhow!("could not find route map entry with id: {id}"))?;
+
+ Ok(())
+ }
+}
--
2.47.3
next prev parent reply other threads:[~2026-04-01 14:42 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 14:39 [PATCH access-control/cluster/network/proxmox{-ve-rs,-perl-rs} v2 00/34] Add support for route maps / prefix lists to SDN Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-cluster v2 01/34] cfs: add 'sdn/route-maps.cfg' to observed files Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-cluster v2 02/34] cfs: add 'sdn/prefix-lists.cfg' " Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-access-control v2 03/34] permissions: add ACL path for prefix-lists and route-maps Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 04/34] frr: add constructor to prefix list name Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 05/34] sdn-types: add common route-map helper types Stefan Hanreich
2026-04-02 13:36 ` Wolfgang Bumiller
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 06/34] frr: change order type to u16 Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 07/34] frr: implement routemap match/set statements via adjacent tagging Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 08/34] frr: implement support for call and exit action Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 09/34] frr-templates: change route maps template to adapt to new frr types Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 10/34] ve-config: fabrics: adapt frr config generation Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 11/34] ve-config: add prefix list section config Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 12/34] ve-config: frr: implement frr config generation for prefix lists Stefan Hanreich
2026-04-03 7:42 ` Wolfgang Bumiller
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 13/34] ve-config: add route map section config Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 14/34] ve-config: frr: implement frr config generation for route maps Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 15/34] ve-config: add prefix lists integration tests Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-ve-rs v2 16/34] ve-config: add route maps " Stefan Hanreich
2026-04-01 14:39 ` Stefan Hanreich [this message]
2026-04-01 14:39 ` [PATCH proxmox-perl-rs v2 18/34] pve-rs: sdn: add prefix lists module Stefan Hanreich
2026-04-01 14:39 ` [PATCH proxmox-perl-rs v2 19/34] sdn: add prefix list / route maps to frr config generation helper Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 20/34] controller: bgp: evpn: adapt to new match / set frr config syntax Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 21/34] sdn: add prefix lists module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 22/34] api2: add prefix list module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 23/34] sdn: add route map module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 24/34] api2: add route maps api module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 25/34] api2: add route map module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 26/34] api2: add route map entry module Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 27/34] evpn controller: add route_map_{in,out} parameter Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 28/34] bgp controller: allow configuring custom route maps Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 29/34] sdn: change detection for route maps / prefix lists Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 30/34] sdn: generate route map / prefix list configuration on sdn apply Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 31/34] tests: add simple route map test case Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 32/34] tests: add bgp evpn route map/prefix list testcase Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 33/34] tests: add route map with prefix " Stefan Hanreich
2026-04-01 14:39 ` [PATCH pve-network v2 34/34] tests: add exit node with custom route map testcase Stefan Hanreich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260401143957.386809-18-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.