From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id EE6A01FF0DA for ; Thu, 19 Nov 2026 20:43:30 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 84472217DB; Thu, 19 Nov 2026 20:42:09 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v3 17/28] sdn: move full range CIDR formats into a separate module Date: Thu, 19 Nov 2026 20:41:03 +0100 Message-ID: <20261119194116.575520-18-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119194116.575520-1-g.goller@proxmox.com> References: <20261119194116.575520-1-g.goller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795117282541 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.224 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: GVO4ZMN2X2KOAPPSHMMJG6KQLUJCLESU X-Message-ID-Hash: GVO4ZMN2X2KOAPPSHMMJG6KQLUJCLESU X-MailFrom: g.goller@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: Zone plugins need FullRangeCIDR for static route prefixes, but using PrefixLists from Zones::Plugin creates a circular import through PVE::Network::SDN and Zones, so the format registration fails. Signed-off-by: Gabriel Goller --- src/PVE/Network/SDN/Fabrics.pm | 1 + src/PVE/Network/SDN/Formats.pm | 51 ++++++++++++++++++++++++++++++ src/PVE/Network/SDN/Makefile | 1 + src/PVE/Network/SDN/PrefixLists.pm | 40 +---------------------- 4 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 src/PVE/Network/SDN/Formats.pm diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm index d881937f42fd..8bb7fb65cfcf 100644 --- a/src/PVE/Network/SDN/Fabrics.pm +++ b/src/PVE/Network/SDN/Fabrics.pm @@ -11,6 +11,7 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::INotify; use PVE::ParseUtils qw($IPV4RE); +use PVE::Network::SDN::Formats; use PVE::Network::SDN::PrefixLists; use PVE::Network::SDN::RouteMaps; use PVE::Network::SDN::Zones; diff --git a/src/PVE/Network/SDN/Formats.pm b/src/PVE/Network/SDN/Formats.pm new file mode 100644 index 000000000000..5f826f225d29 --- /dev/null +++ b/src/PVE/Network/SDN/Formats.pm @@ -0,0 +1,51 @@ +package PVE::Network::SDN::Formats; + +# JSON schema formats shared by SDN modules. This module must not use other SDN +# modules, so that it can be loaded by all of them without circular imports. + +use strict; +use warnings; + +use PVE::JSONSchema; +use PVE::Tools; + +PVE::JSONSchema::register_format('FullRangeCIDRv6', \&pve_verify_fullrangecidrv6); + +sub pve_verify_fullrangecidrv6 { + my ($cidr, $noerr) = @_; + + if ($cidr =~ m!^(?:$PVE::Tools::IPV6RE)(?:/(\d+))\z! && ($1 >= 0) && ($1 <= 128)) { + return $cidr; + } + + return undef if $noerr; + die "value does not look like a valid IPv6 CIDR network\n"; +} + +PVE::JSONSchema::register_format('FullRangeCIDRv4', \&pve_verify_fullrangecidrv4); + +sub pve_verify_fullrangecidrv4 { + my ($cidr, $noerr) = @_; + + if ($cidr =~ m!^(?:$PVE::Tools::IPV4RE)(?:/(\d+))\z! && ($1 >= 0) && ($1 <= 32)) { + return $cidr; + } + + return undef if $noerr; + die "value does not look like a valid IPv4 CIDR network\n"; +} + +PVE::JSONSchema::register_format('FullRangeCIDR', \&pve_verify_fullrangecidr); + +sub pve_verify_fullrangecidr { + my ($cidr, $noerr) = @_; + + if (!(pve_verify_fullrangecidrv4($cidr, 1) || pve_verify_fullrangecidrv6($cidr, 1))) { + return undef if $noerr; + die "value does not look like a valid CIDR network\n"; + } + + return $cidr; +} + +1; diff --git a/src/PVE/Network/SDN/Makefile b/src/PVE/Network/SDN/Makefile index d0b4bce2d067..67237ca4b2ca 100644 --- a/src/PVE/Network/SDN/Makefile +++ b/src/PVE/Network/SDN/Makefile @@ -9,6 +9,7 @@ SOURCES=Vnets.pm\ Dhcp.pm\ Fabrics.pm\ Frr.pm\ + Formats.pm\ PrefixLists.pm\ RouteMaps.pm\ WireGuard.pm diff --git a/src/PVE/Network/SDN/PrefixLists.pm b/src/PVE/Network/SDN/PrefixLists.pm index d41c4ffcbc47..f825d208def5 100644 --- a/src/PVE/Network/SDN/PrefixLists.pm +++ b/src/PVE/Network/SDN/PrefixLists.pm @@ -7,6 +7,7 @@ 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::Tools; use PVE::INotify; +use PVE::Network::SDN::Formats; use PVE::Network::SDN; use PVE::Network::SDN::RouteMaps; use PVE::RS::SDN::PrefixLists; @@ -40,45 +41,6 @@ PVE::JSONSchema::register_standard_option( }, ); -PVE::JSONSchema::register_format('FullRangeCIDRv6', \&pve_verify_fullrangecidrv6); - -sub pve_verify_fullrangecidrv6 { - my ($cidr, $noerr) = @_; - - if ($cidr =~ m!^(?:$PVE::Tools::IPV6RE)(?:/(\d+))\z! && ($1 >= 0) && ($1 <= 128)) { - return $cidr; - } - - return undef if $noerr; - die "value does not look like a valid IPv6 CIDR network\n"; -} - -PVE::JSONSchema::register_format('FullRangeCIDRv4', \&pve_verify_fullrangecidrv4); - -sub pve_verify_fullrangecidrv4 { - my ($cidr, $noerr) = @_; - - if ($cidr =~ m!^(?:$PVE::Tools::IPV4RE)(?:/(\d+))\z! && ($1 >= 0) && ($1 <= 32)) { - return $cidr; - } - - return undef if $noerr; - die "value does not look like a valid IPv4 CIDR network\n"; -} - -PVE::JSONSchema::register_format('FullRangeCIDR', \&pve_verify_fullrangecidr); - -sub pve_verify_fullrangecidr { - my ($cidr, $noerr) = @_; - - if (!(pve_verify_fullrangecidrv4($cidr, 1) || pve_verify_fullrangecidrv6($cidr, 1))) { - return undef if $noerr; - die "value does not look like a valid CIDR network\n"; - } - - return $cidr; -} - cfs_register_file( 'sdn/prefix-lists.cfg', \&parse_prefix_lists_config, \&write_prefix_lists_config, ); -- 2.47.3