From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-perl-rs v4 20/47] pve-rs: sdn: add route maps module
Date: Mon, 4 May 2026 18:03:17 +0200 [thread overview]
Message-ID: <20260504160350.395470-21-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20260504160350.395470-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 c66ee23..6d75e94 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 = "2"
+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 c2f9b73..0a7f700 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -32,6 +32,7 @@ PERLMOD_PACKAGES := \
PVE::RS::ResourceScheduling::Static \
PVE::RS::ResourceScheduling::Dynamic \
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-05-04 16:07 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 16:02 [PATCH access-control/cluster/manager/network/proxmox{-ve-rs,-perl-rs} v4 00/47] Add support for route maps / prefix lists to SDN Stefan Hanreich
2026-05-04 16:02 ` [PATCH pve-cluster v4 01/47] cfs: add 'sdn/route-maps.cfg' to observed files Stefan Hanreich
2026-05-04 16:02 ` [PATCH pve-cluster v4 02/47] cfs: add 'sdn/prefix-lists.cfg' " Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-access-control v4 03/47] permissions: add ACL path for prefix-lists and route-maps Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 04/47] frr: add constructor to prefix list name Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 05/47] sdn-types: add common route-map helper types Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 06/47] frr: change order type to u16 Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 07/47] frr: implement routemap match/set statements via adjacent tagging Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 08/47] frr: implement support for call and exit action Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 09/47] frr-templates: change route maps template to adapt to new frr types Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 10/47] ve-config: fabrics: adapt frr config generation Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 11/47] ve-config: add prefix list section config Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 12/47] ve-config: frr: implement frr config generation for prefix lists Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 13/47] ve-config: add route map section config Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 14/47] ve-config: frr: implement frr config generation for route maps Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 15/47] ve-config: add prefix lists integration tests Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 16/47] ve-config: add route maps " Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 17/47] fabrics: ospf: fix deserializing OspfDeletableProperties Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 18/47] fabrics: ospf: openfabric: allow user-defined route filter Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-ve-rs v4 19/47] frr: fabrics: apply route_filter setting Stefan Hanreich
2026-05-04 16:03 ` Stefan Hanreich [this message]
2026-05-04 16:03 ` [PATCH proxmox-perl-rs v4 21/47] pve-rs: sdn: add prefix lists module Stefan Hanreich
2026-05-04 16:03 ` [PATCH proxmox-perl-rs v4 22/47] sdn: add prefix list / route maps to frr config generation helper Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 23/47] controller: bgp: evpn: adapt to new match / set frr config syntax Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 24/47] sdn: add prefix lists module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 25/47] sdn: add route map module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 26/47] api2: add prefix list module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 27/47] api2: add route maps module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 28/47] api2: add route map module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 29/47] api2: add route map entry module Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 30/47] evpn controller: add route_map_{in,out} parameter Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 31/47] bgp controller: allow configuring custom route maps Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 32/47] sdn: change detection for route maps / prefix lists Stefan Hanreich
2026-05-05 9:07 ` Hannes Laimer
2026-05-04 16:03 ` [PATCH pve-network v4 33/47] sdn: generate route map / prefix list configuration on sdn apply Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 34/47] sdn: frr: consider route maps and prefix lists in dry-run Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 35/47] fabrics: ospf: openfabric: add route_filter property Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 36/47] tests: add simple route map test case Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 37/47] tests: add bgp evpn route map/prefix list testcase Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 38/47] tests: add route map with prefix " Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-network v4 39/47] tests: add exit node with custom route map testcase Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 40/47] ui: sdn: add route map selector Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 41/47] ui: sdn: add prefix list selector Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 42/47] ui: sdn: add panel for managing prefix lists Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 43/47] ui: sdn: add panel for managing route map entries Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 44/47] ui: sdn: bgp controller: allow configuring route maps Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 45/47] ui: sdn: evpn " Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 46/47] ui: sdn: openfabric: add route filter Stefan Hanreich
2026-05-04 16:03 ` [PATCH pve-manager v4 47/47] ui: sdn: ospf: add route filter setting 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=20260504160350.395470-21-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox