From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E96D81FF13B for ; Wed, 25 Mar 2026 10:49:21 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B229D10EFE; Wed, 25 Mar 2026 10:49:40 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network 04/13] sdn: add route map module Date: Wed, 25 Mar 2026 10:41:29 +0100 Message-ID: <20260325094142.174364-19-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260325094142.174364-1-s.hanreich@proxmox.com> References: <20260325094142.174364-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1774431664336 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.715 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WARBXASDAEK6DUBM3MKU6Q5PWCBDKHGB X-Message-ID-Hash: WARBXASDAEK6DUBM3MKU6Q5PWCBDKHGB X-MailFrom: s.hanreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Defines helpers for common operations (reading / writing configuration) as well as the required formats / schema definitions for the route map API. The Route Map ID format currently rejects all IDs that could be auto-generated by PVE entities, to prevent accidental overrides of built-in route maps. Instead of re-defining route maps, users can create a new custom route map and select that in the EVPN / BGP controller, if they want to override the auto-generated route map. Signed-off-by: Stefan Hanreich --- src/PVE/API2/Network/SDN/Makefile | 4 +- src/PVE/API2/Network/SDN/RouteMaps/Makefile | 8 + src/PVE/Network/SDN/RouteMaps.pm | 173 ++++++++++++++++++++ 3 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 src/PVE/API2/Network/SDN/RouteMaps/Makefile create mode 100644 src/PVE/Network/SDN/RouteMaps.pm diff --git a/src/PVE/API2/Network/SDN/Makefile b/src/PVE/API2/Network/SDN/Makefile index 4349c17..770eef2 100644 --- a/src/PVE/API2/Network/SDN/Makefile +++ b/src/PVE/API2/Network/SDN/Makefile @@ -6,7 +6,8 @@ SOURCES=Vnets.pm\ Dns.pm\ Ips.pm\ Fabrics.pm\ - PrefixLists.pm + PrefixLists.pm\ + RouteMaps.pm PERL5DIR=${DESTDIR}/usr/share/perl5 @@ -15,4 +16,5 @@ install: for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/SDN/$$i; done make -C Fabrics install make -C Nodes install + make -C RouteMaps install diff --git a/src/PVE/API2/Network/SDN/RouteMaps/Makefile b/src/PVE/API2/Network/SDN/RouteMaps/Makefile new file mode 100644 index 0000000..3d0a928 --- /dev/null +++ b/src/PVE/API2/Network/SDN/RouteMaps/Makefile @@ -0,0 +1,8 @@ +SOURCES=RouteMap.pm\ + + +PERL5DIR=${DESTDIR}/usr/share/perl5 + +.PHONY: install +install: + for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/SDN/RouteMaps/$$i; done diff --git a/src/PVE/Network/SDN/RouteMaps.pm b/src/PVE/Network/SDN/RouteMaps.pm new file mode 100644 index 0000000..1d2f495 --- /dev/null +++ b/src/PVE/Network/SDN/RouteMaps.pm @@ -0,0 +1,173 @@ +package PVE::Network::SDN::RouteMaps; + +use strict; +use warnings; + +use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_lock_file cfs_write_file); +use PVE::JSONSchema qw(get_standard_option); +use PVE::INotify; +use PVE::Network::SDN; +use PVE::RS::SDN::RouteMaps; + +PVE::JSONSchema::register_format( + 'pve-sdn-route-map-id', + sub { + my ($id, $noerr) = @_; + + if ($id =~ m/^(pve_.*|MAP_VTEP_IN|MAP_VTEP_OUT|correct_src)$/) { + return undef if $noerr; + die "route map ID '$id' is currently reserved and cannot be used\n"; + } + + if ($id !~ m/^[a-zA-Z0-9][a-zA-Z0-9-_]{0,30}[a-zA-Z0-9]?$/i) { + return undef if $noerr; + die "route map ID '$id' contains illegal characters\n"; + } + + return $id; + }, +); + +PVE::JSONSchema::register_standard_option( + 'pve-sdn-route-map-id', + { + description => "The SDN route map identifier", + type => 'string', + format => 'pve-sdn-route-map-id', + }, +); + +PVE::JSONSchema::register_standard_option( + 'pve-sdn-route-map-order', + { + description => 'The index of this route map entry', + type => 'integer', + minimum => 0, + maximum => 2 ** 32 - 1, + }, +); + +cfs_register_file( + 'sdn/route-maps.cfg', \&parse_route_maps_config, \&write_route_maps_config, +); + +sub parse_route_maps_config { + my ($filename, $raw) = @_; + return $raw // ''; +} + +sub write_route_maps_config { + my ($filename, $config) = @_; + return $config // ''; +} + +sub config { + my ($running) = @_; + + if ($running) { + my $running_config = PVE::Network::SDN::running_config(); + + # if the config hasn't yet been applied after the introduction of + # route maps then the key does not exist in the running config so we + # default to an empty hash + my $route_maps_config = $running_config->{'route-maps'}->{ids} // {}; + return PVE::RS::SDN::RouteMaps->running_config($route_maps_config); + } + + my $route_map_config = cfs_read_file("sdn/route-maps.cfg"); + return PVE::RS::SDN::RouteMaps->config($route_map_config); +} + +sub write_config { + my ($config) = @_; + cfs_write_file("sdn/route-maps.cfg", $config->to_raw(), 1); +} + +sub route_map_properties { + my ($update) = @_; + + my $properties = { + 'route-map-id' => get_standard_option('pve-sdn-route-map-id'), + 'order' => get_standard_option('pve-sdn-route-map-order'), + digest => get_standard_option('pve-config-digest'), + action => { + description => 'Matching policy of a route map entry.', + type => 'string', + enum => ['permit', 'deny'], + optional => $update, + }, + set => { + type => 'array', + items => { + type => 'string', + format => { + key => { + type => 'string', + enum => [ + 'ip-next-hop-peer-address', + 'ip-next-hop', + 'ip-next-hop-unchanged', + 'ip6-next-hop-peer-address', + 'ip6-next-hop-prefer-global', + 'ip6-next-hop', + 'local-preference', + 'tag', + 'weight', + 'metric', + 'src', + ] + }, + value => { + type => 'string', + optional => 1, + } + }, + }, + optional => 1, + }, + match => { + type => 'array', + items => { + type => 'string', + format => { + key => { + type => 'string', + enum => [ + 'route-type', + 'vni', + 'ip-address-prefix-list', + 'ip6-address-prefix-list', + 'ip-next-hop-prefix-list', + 'ip6-next-hop-prefix-list', + 'ip-next-hop-address', + 'ip6-next-hop-address', + 'metric', + 'local-preference', + 'peer', + ] + }, + value => { + type => 'string', + optional => 1, + } + }, + }, + optional => 1, + }, + }; + + if ($update) { + $properties->{delete} = { + type => 'array', + optional => 1, + items => { + type => 'string', + enum => ['set', 'match'], + } + }; + } + + return $properties; +} + +1; -- 2.47.3