[PATCH proxmox-ve-rs v5 12/46] ve-config: frr: implement frr config generation for prefix lists

Stefan Hanreich
2026-05-05T15:40:29Z

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 | 60 ++++++++++++++++++++++++
1 file changed, 60 insertions(+)

diff --git a/proxmox-ve-config/src/sdn/prefix_list.rs b/proxmox-ve-config/src/sdn/prefix_list.rs
index 33dbbe4..d250a8e 100644
--- a/proxmox-ve-config/src/sdn/prefix_list.rs
+++ b/proxmox-ve-config/src/sdn/prefix_list.rs
@@ -125,6 +125,66 @@ pub enum PrefixList {
PrefixList(PrefixListSection),
}

+#[cfg(feature = "frr")]
+pub mod frr {
+ use super::*;
+
+ use proxmox_frr::ser::{
+ route_map::{
+ self, PrefixListName as FrrPrefixListName, PrefixListRule as FrrPrefixListRule,
+ },
+ FrrConfig,
+ };
+
+ impl From<PrefixListId> for FrrPrefixListName {
+ fn from(value: PrefixListId) -> Self {
+ FrrPrefixListName::new(value.0)
+ }
+ }
+
+ impl From<PrefixListEntry> for FrrPrefixListRule {
+ fn from(value: PrefixListEntry) -> Self {
+ FrrPrefixListRule {
+ action: match value.action {
+ PrefixListAction::Permit => route_map::AccessAction::Permit,
+ PrefixListAction::Deny => route_map::AccessAction::Deny,
+ },
+ network: value.prefix,
+ seq: value.seq,
+ le: value.le,
+ ge: value.ge,
+ is_ipv6: value.prefix.is_ipv6(),
+ }
+ }
+ }
+
+ /// 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 {
+ let PrefixList::PrefixList(prefix_list) = prefix_list;
+ let prefix_list_name = FrrPrefixListName::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(())
+ }
+}
+
pub mod api {
use super::*;

--
2.47.3