From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id AB1F6A0FC4 for ; Fri, 10 Nov 2023 12:04:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 91D9F1ED4B for ; Fri, 10 Nov 2023 12:04:21 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 10 Nov 2023 12:04:20 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B9958478F8 for ; Fri, 10 Nov 2023 12:04:20 +0100 (CET) Date: Fri, 10 Nov 2023 12:04:13 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20230614093033.820848-1-a.lauterer@proxmox.com> In-Reply-To: <20230614093033.820848-1-a.lauterer@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1699611727.xcoag2n7lq.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.067 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v2 common 1/4] fix #3893: network: make bridge vids configurable X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Nov 2023 11:04:51 -0000 On June 14, 2023 11:30 am, Aaron Lauterer wrote: > For that we need to add a new format option that checks against valid > VLAN tags and ranges, for example: 2 4 100-200 >=20 > The check, if the default value should be used, needs to fail not just > when not defined, but also in case it is an empty string. >=20 > Signed-off-by: Aaron Lauterer > --- > no changes since v1. >=20 > I think replacing the 'defined' check with 'length' should be fine. We > need to also handle the situation that the parameter is defined, but an > empty string. There should be no autovivification happening. If I missed > a side effect, let me know. >=20 > For the new format option I went with singular for the name as it only > checks a single VLAN ID/range from the list, 'pve-bridge-vid', but I am > not sure if it wouldn't be better to call it the actual parameter name > 'pve-bridge-vids'. I think the "count" of the name is fine, if at all, you might want to add the "or range" part. ifupdown2 calls the (full) format ;) > src/PVE/INotify.pm | 2 +- > src/PVE/JSONSchema.pm | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 33 insertions(+), 1 deletion(-) >=20 > diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm > index bc33a8f..14f40ac 100644 > --- a/src/PVE/INotify.pm > +++ b/src/PVE/INotify.pm > @@ -1270,7 +1270,7 @@ sub __interface_to_string { > =20 > if (defined($d->{bridge_vlan_aware})) { > $raw .=3D "\tbridge-vlan-aware yes\n"; > - my $vlans =3D defined($d->{bridge_vids}) ? $d->{bridge_vids} : "2-4= 094"; > + my $vlans =3D length($d->{bridge_vids}) ? $d->{bridge_vids} : "2-40= 94"; > $raw .=3D "\tbridge-vids $vlans\n"; > } > $done->{bridge_vlan_aware} =3D 1; > diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm > index 85d47f2..1051a45 100644 > --- a/src/PVE/JSONSchema.pm > +++ b/src/PVE/JSONSchema.pm > @@ -78,6 +78,12 @@ register_standard_option('pve-iface', { > minLength =3D> 2, maxLength =3D> 20, > }); > =20 > +register_standard_option('pve-bridge-vid', { > + description =3D> "Bridge VLAN ID.", > + type =3D> 'string', format =3D> 'pve-bridge-vid', > + minLength =3D> 1, maxLength =3D> 9, > +}); > + > register_standard_option('pve-storage-id', { > description =3D> "The storage identifier.", > type =3D> 'string', format =3D> 'pve-storage-id', > @@ -588,6 +594,32 @@ sub pve_verify_iface { > return $id; > } > =20 > +# bridge vlan id (vids) > +register_format('pve-bridge-vid', \&pve_verify_bridge_vid); > +sub pve_verify_bridge_vid { > + my ($vlan, $noerr) =3D @_; > + > + my $check_vid =3D sub { > + my $id =3D shift; > + if ( $id < 2 || $id > 4094) { nit style (spacing around ()) > + return undef if $noerr; this does not work - the undef would not be propagated up since you don't check the return value below.. > + die "invalid VLAN tag '$id'\n"; tag vs ID - it's a bit weird that both are used interchangably.. > + } > + }; > + > + if ($vlan !~ m/^(\d+)([-](\d+))?$/i) { > + return undef if $noerr; > + die "invalid VLAN configuration '$vlan'\n"; > + } > + $check_vid->($1); > + if ($3) { > + $check_vid->($3); > + die "VLAN range must go from lower to higher tag '$vlan'" if $1 > $3 &&= !$noerr; > + } not a huge fan of all the $N here.. could we get named variables please? $start, $end; or $first, $last ;) > + > + return $vlan; > +} > + > # general addresses by name or IP > register_format('address', \&pve_verify_address); > sub pve_verify_address { > --=20 > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20