From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-ve-rs 6/9] ve-config: frr: implement frr config generation for prefix lists
Date: Wed, 25 Mar 2026 10:41:19 +0100 [thread overview]
Message-ID: <20260325094142.174364-9-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20260325094142.174364-1-s.hanreich@proxmox.com>
Implements conversion traits for all the section config types, so they
can be converted into their respective FRR template counterpart.
Also add a helper that adds a list of prefix lists to an existing FRR
configuration. This will be used by perl-rs to generate the FRR
configuration from the section configuration. The helper will
overwrite existing prefix lists in the FRR configuration, allowing
users to override pre-defined prefix lists generated by our stack.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
proxmox-ve-config/src/sdn/prefix_list.rs | 187 +++++++++++++++++++++++
1 file changed, 187 insertions(+)
diff --git a/proxmox-ve-config/src/sdn/prefix_list.rs b/proxmox-ve-config/src/sdn/prefix_list.rs
index f4988d9..f371c8d 100644
--- a/proxmox-ve-config/src/sdn/prefix_list.rs
+++ b/proxmox-ve-config/src/sdn/prefix_list.rs
@@ -123,6 +123,193 @@ pub enum PrefixList {
PrefixList(PrefixListSection),
}
+#[cfg(feature = "frr")]
+pub mod frr {
+ use core::{convert::Into, iter::IntoIterator};
+
+ use super::*;
+
+ use proxmox_frr::ser::{
+ route_map::{
+ self, PrefixList as FrrPrefixList, PrefixListName, PrefixListRule as FrrPrefixListRule,
+ },
+ FrrConfig,
+ };
+
+ impl Into<PrefixListName> for PrefixListId {
+ fn into(self) -> PrefixListName {
+ PrefixListName::new(self.into_string())
+ }
+ }
+
+ impl Into<FrrPrefixListRule> for PrefixListEntry {
+ fn into(self) -> FrrPrefixListRule {
+ FrrPrefixListRule {
+ action: match self.action {
+ PrefixListAction::Permit => route_map::AccessAction::Permit,
+ PrefixListAction::Deny => route_map::AccessAction::Deny,
+ },
+ network: self.prefix,
+ seq: self.seq,
+ le: self.le,
+ ge: self.ge,
+ is_ipv6: self.prefix.is_ipv6(),
+ }
+ }
+ }
+
+ impl Into<FrrPrefixList> for PrefixListSection {
+ fn into(self) -> FrrPrefixList {
+ FrrPrefixList {
+ name: PrefixListName::new(self.id.to_string()),
+ rules: self
+ .entries
+ .into_iter()
+ .map(|rule| rule.into_inner().into())
+ .collect(),
+ }
+ }
+ }
+
+ /// Add a list of Prefix Lists to an [`FrrConfig`].
+ ///
+ /// This will overwrite existing Prefix Lists in the [`FrrConfig`]. Since this will be used for
+ /// generating the FRR configuration from the SDN stack, this enables users to override Prefix
+ /// Lists that are predefined by our stack.
+ pub fn build_frr_prefix_lists(
+ prefix_lists: impl IntoIterator<Item = PrefixList>,
+ frr_config: &mut FrrConfig,
+ ) -> Result<(), anyhow::Error> {
+ for prefix_list in prefix_lists.into_iter() {
+ let PrefixList::PrefixList(prefix_list) = prefix_list;
+ let prefix_list_name = PrefixListName::new(prefix_list.id.0);
+
+ frr_config.prefix_lists.insert(
+ prefix_list_name,
+ prefix_list
+ .entries
+ .into_iter()
+ .map(|prefix_list| prefix_list.into_inner().into())
+ .collect(),
+ );
+ }
+
+ Ok(())
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use super::*;
+
+ use proxmox_frr::ser::route_map::{AccessAction, PrefixListName};
+ use proxmox_frr::ser::serializer::dump;
+
+ use proxmox_section_config::typed::ApiSectionDataEntry;
+
+ #[test]
+ fn test_build_prefix_list() -> Result<(), anyhow::Error> {
+ let section_config = r#"
+prefix-list: example-1
+ entries action=permit,prefix=192.0.2.0/24
+ entries action=permit,prefix=192.0.2.0/24,le=32
+ entries action=permit,prefix=192.0.2.0/24,le=32,ge=24,seq=123
+ entries action=permit,prefix=192.0.2.0/24,ge=24
+ entries action=permit,prefix=192.0.2.0/24,ge=24,le=31
+
+prefix-list: example-3
+ entries action=permit,prefix=192.0.2.0/24,seq=333
+ entries action=permit,prefix=198.51.100.0/24,seq=222
+ entries action=permit,prefix=203.0.113.0/24,seq=111
+
+prefix-list: example-2
+ entries action=deny,prefix=192.0.2.0/24,le=25
+ entries action=permit,prefix=192.0.2.0/24
+"#;
+
+ let config = PrefixList::parse_section_config("prefix-lists.cfg", section_config)?;
+ let mut frr_config = FrrConfig::default();
+
+ build_frr_prefix_lists(
+ config
+ .into_iter()
+ .map(|(_, route_map_entry)| route_map_entry),
+ &mut frr_config,
+ )?;
+
+ assert_eq!(
+ dump(&frr_config)?,
+ r#"!
+ip prefix-list example-1 permit 192.0.2.0/24
+ip prefix-list example-1 permit 192.0.2.0/24 le 32
+ip prefix-list example-1 seq 123 permit 192.0.2.0/24 le 32 ge 24
+ip prefix-list example-1 permit 192.0.2.0/24 ge 24
+ip prefix-list example-1 permit 192.0.2.0/24 le 31 ge 24
+!
+ip prefix-list example-2 deny 192.0.2.0/24 le 25
+ip prefix-list example-2 permit 192.0.2.0/24
+!
+ip prefix-list example-3 seq 333 permit 192.0.2.0/24
+ip prefix-list example-3 seq 222 permit 198.51.100.0/24
+ip prefix-list example-3 seq 111 permit 203.0.113.0/24
+"#
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn test_build_prefix_list_overwrite() -> Result<(), anyhow::Error> {
+ let section_config = r#"
+prefix-list: example-1
+ entries action=permit,prefix=192.0.2.0/24
+"#;
+
+ let config = PrefixList::parse_section_config("prefix-lists.cfg", section_config)?;
+
+ let example_1_prefix_list = vec![FrrPrefixListRule {
+ action: AccessAction::Deny,
+ network: Cidr::new_v4([198, 51, 100, 0], 24).unwrap(),
+ seq: None,
+ le: None,
+ ge: None,
+ is_ipv6: false,
+ }];
+
+ let mut frr_config = FrrConfig::default();
+
+ frr_config.prefix_lists.insert(
+ PrefixListName::new("example-1".to_string()),
+ example_1_prefix_list.clone(),
+ );
+
+ build_frr_prefix_lists(
+ config
+ .into_iter()
+ .map(|(_, route_map_entry)| route_map_entry),
+ &mut frr_config,
+ )?;
+
+ let new_prefix_list = frr_config
+ .prefix_lists
+ .get(&PrefixListName::new("example-1".to_string()))
+ .expect("'example-1' prefix list exists");
+
+ assert_ne!(&example_1_prefix_list, new_prefix_list);
+
+ let generated_frr_config = dump(&frr_config)?;
+
+ assert_eq!(
+ generated_frr_config,
+ r#"!
+ip prefix-list example-1 permit 192.0.2.0/24
+"#
+ );
+
+ Ok(())
+ }
+ }
+}
+
pub mod api {
use super::*;
--
2.47.3
next prev parent reply other threads:[~2026-03-25 9:44 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 9:41 [PATCH cluster/network/proxmox{-ve-rs,-perl-rs} 00/27] Add support for route maps / prefix lists to SDN Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-cluster 1/2] cfs: add 'sdn/route-maps.cfg' to observed files Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-cluster 2/2] cfs: add 'sdn/prefix-lists.cfg' " Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 1/9] sdn-types: add common route-map helper types Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 2/9] frr: implement routemap match/set statements via adjacent tagging Stefan Hanreich
2026-03-26 14:44 ` Hannes Laimer
2026-03-27 9:02 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 3/9] frr: allow rendering prefix-lists/route-maps separately Stefan Hanreich
2026-03-25 14:32 ` Gabriel Goller
2026-03-26 12:17 ` Stefan Hanreich
2026-03-27 10:50 ` Hannes Laimer
2026-03-27 11:34 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 4/9] frr-templates: change route maps template to adapt to new types Stefan Hanreich
2026-03-25 14:33 ` Gabriel Goller
2026-03-25 14:58 ` Gabriel Goller
2026-03-27 11:01 ` Hannes Laimer
2026-03-27 11:17 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 5/9] ve-config: add prefix list section config Stefan Hanreich
2026-03-25 9:41 ` Stefan Hanreich [this message]
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 7/9] ve-config: add route map " Stefan Hanreich
2026-03-25 14:35 ` Gabriel Goller
2026-03-26 13:49 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 8/9] ve-config: frr: implement frr config generation for route maps Stefan Hanreich
2026-03-25 15:03 ` Gabriel Goller
2026-03-26 13:50 ` Stefan Hanreich
2026-03-27 11:17 ` Hannes Laimer
2026-03-27 11:21 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-ve-rs 9/9] ve-config: fabrics: adapt frr config generation to new format Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-perl-rs 1/3] pve-rs: sdn: add route maps module Stefan Hanreich
2026-03-26 10:32 ` Wolfgang Bumiller
2026-03-26 13:57 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-perl-rs 2/3] pve-rs: sdn: add prefix lists module Stefan Hanreich
2026-03-25 9:41 ` [PATCH proxmox-perl-rs 3/3] sdn: add prefix list / route maps to frr config generation helper Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 01/13] controller: bgp: evpn: adapt to new match / set frr config syntax Stefan Hanreich
2026-03-26 15:19 ` Hannes Laimer
2026-03-27 10:05 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 02/13] sdn: add prefix lists module Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 03/13] api2: add prefix list module Stefan Hanreich
2026-03-26 15:01 ` Hannes Laimer
2026-03-27 9:57 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 04/13] sdn: add route map module Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 05/13] api2: add route maps api module Stefan Hanreich
2026-03-26 15:05 ` Hannes Laimer
2026-03-27 9:57 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 06/13] api2: add route map module Stefan Hanreich
2026-03-26 15:07 ` Hannes Laimer
2026-03-27 9:57 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 07/13] api2: add route map entry module Stefan Hanreich
2026-03-26 15:13 ` Hannes Laimer
2026-03-27 10:01 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 08/13] evpn controller: add route_map_{in,out} parameter Stefan Hanreich
2026-03-27 10:44 ` Hannes Laimer
2026-03-27 11:12 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 09/13] sdn: generate route map / prefix list configuration on sdn apply Stefan Hanreich
2026-03-27 10:47 ` Hannes Laimer
2026-03-27 11:13 ` Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 10/13] tests: add simple route map test case Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 11/13] tests: add bgp evpn route map/prefix list testcase Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 12/13] tests: add route map with prefix " Stefan Hanreich
2026-03-25 9:41 ` [PATCH pve-network 13/13] bgp controller: allow configuring custom route maps Stefan Hanreich
2026-03-25 11:38 ` [PATCH cluster/network/proxmox{-ve-rs,-perl-rs} 00/27] Add support for route maps / prefix lists to SDN Stefan Hanreich
2026-03-27 10:17 ` 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=20260325094142.174364-9-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.