From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D84701FF13C for ; Thu, 11 Jun 2026 17:00:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B1643F794; Thu, 11 Jun 2026 17:00:07 +0200 (CEST) From: David Riley To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network 5/9] fix #7294: sdn: register api formats for zones and vnets Date: Thu, 11 Jun 2026 16:59:31 +0200 Message-ID: <20260611145935.147788-6-d.riley@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260611145935.147788-1-d.riley@proxmox.com> References: <20260611145935.147788-1-d.riley@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1781189942427 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.187 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 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: TBSMZD32T42L6URFHEMYPGMMQ5ZHDWAV X-Message-ID-Hash: TBSMZD32T42L6URFHEMYPGMMQ5ZHDWAV X-MailFrom: d.riley@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: Register JSONSchema format validators for both SDN zones and VNets, enabling the pool members API to verify these network identifiers. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7294 Signed-off-by: David Riley --- src/PVE/Network/SDN/VnetPlugin.pm | 23 ++++++++++++++++++++--- src/PVE/Network/SDN/Zones/Plugin.pm | 23 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/PVE/Network/SDN/VnetPlugin.pm b/src/PVE/Network/SDN/VnetPlugin.pm index e041575..2299b46 100644 --- a/src/PVE/Network/SDN/VnetPlugin.pm +++ b/src/PVE/Network/SDN/VnetPlugin.pm @@ -16,17 +16,34 @@ PVE::Cluster::cfs_register_file( sub { __PACKAGE__->write_config(@_); }, ); +my $sdn_vnet_id_pattern = '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]'; +my $vnet_min_length = 2; +my $vnet_max_length = 8; + PVE::JSONSchema::register_standard_option( 'pve-sdn-vnet-id', { description => "The SDN vnet object identifier.", type => 'string', - pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]', - minLength => 2, - maxLength => 8, + pattern => $sdn_vnet_id_pattern, + minLength => $vnet_min_length, + maxLength => $vnet_max_length, }, ); +sub pve_verify_sdn_vnet_id { + my ($vnet, $noerr) = @_; + + if ($vnet !~ m/^$sdn_vnet_id_pattern$/) { + return undef if $noerr; + die "invalid SDN VNet '$vnet' - must be $vnet_min_length-$vnet_max_length characters" + . " long, start with a letter, and contain only alphanumeric characters\n"; + } + return $vnet; +} + +PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&pve_verify_sdn_vnet_id); + my $defaultData = { propertyList => { diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm index 74a3384..cd761e0 100644 --- a/src/PVE/Network/SDN/Zones/Plugin.pm +++ b/src/PVE/Network/SDN/Zones/Plugin.pm @@ -19,17 +19,34 @@ PVE::Cluster::cfs_register_file( sub { __PACKAGE__->write_config(@_); }, ); +my $sdn_zone_id_pattern = '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]'; +my $zone_min_length = 2; +my $zone_max_length = 8; + PVE::JSONSchema::register_standard_option( 'pve-sdn-zone-id', { description => "The SDN zone object identifier.", type => 'string', - pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]', - minLength => 2, - maxLength => 8, + pattern => $sdn_zone_id_pattern, + minLength => $zone_min_length, + maxLength => $zone_max_length, }, ); +sub pve_verify_sdn_zone_id { + my ($zone, $noerr) = @_; + + if ($zone !~ m/^$sdn_zone_id_pattern$/) { + return undef if $noerr; + die "invalid SDN zone '$zone' - must be $zone_min_length-$zone_max_length characters" + . " long, start with a letter, and contain only alphanumeric characters\n"; + } + return $zone; +} + +PVE::JSONSchema::register_format('pve-sdn-zone-id', \&pve_verify_sdn_zone_id); + my $defaultData = { propertyList => { -- 2.47.3