public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3]  fix #3893: make bridge vids configurable
@ 2024-07-03  8:01 Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 1/3] tools: add check_list_empty function Aaron Lauterer
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

this version reworks a few parts since v2.

* renamed format in JSONSchema to a more generic `pve-vlan-id-or-range`
* explicitly use spaces when writing interfaces file. This is one
  possible approach to deal with the fact, that the generic `-list`
  format will accept quite a few delimiters and we need spaces.
* code style improvements such as naming the regex results.
* add parameter verification to the web ui

With the changes to the JSONSchema we can then work on using it too for
the guest trunk option. This hasn't been started yet though.

common: Aaron Lauterer (3):
  tools: add check_list_empty function
  fix #3893: network: add vlan id and range parameter definitions
  inotify: interfaces: make sure bridge_vids use space as separator

 src/PVE/INotify.pm    |  2 +-
 src/PVE/JSONSchema.pm | 34 ++++++++++++++++++++++++++++++++++
 src/PVE/Tools.pm      |  8 ++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)


widget-toolkit: Aaron Lauterer (1):
  fix #3892: Network: add bridge vids field for bridge_vids

 src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
 src/node/NetworkView.js |  5 ++++
 2 files changed, 67 insertions(+)


manager: Aaron Lauterer (2):
  fix #3893: api: network: add bridge_vids parameter
  fix #3893: ui: network: enable bridge_vids field

 PVE/API2/Network.pm         | 15 ++++++++++++++-
 www/manager6/node/Config.js |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)

-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH common v3 1/3] tools: add check_list_empty function
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions Aaron Lauterer
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

In some situations we don't want a total empty list. I opted for a
dedicated function instead of integrating it as error in the
`split_list` function. It is used in many places and the potential
fallout from unintended behavior changes is too big.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2:
* newly added

 src/PVE/Tools.pm | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 766c809..c8ac6f0 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -718,6 +718,14 @@ sub split_list {
     return @data;
 }
 
+sub check_list_empty {
+    my ($list) = @_;
+    if (scalar(PVE::Tools::split_list($list)) < 1) {
+	return 0;
+    }
+    return 1;
+}
+
 sub trim {
     my $txt = shift;
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 1/3] tools: add check_list_empty function Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-26 12:22   ` Shannon Sterz
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 3/3] inotify: interfaces: make sure bridge_vids use space as separator Aaron Lauterer
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

This is one step to make it possible to define the VLAN IDs and ranges
for bridges.

It is expected to be used in combination with the `-list` magic
property. Therefore it defines and checks the validity of a single list
item that could just be a single VLAN tag ID or a range.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2:
* renamed schema to a more generic one with the use case of the guest
  trunk config in mind

 src/PVE/JSONSchema.pm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 115f811..22fe048 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -81,6 +81,12 @@ register_standard_option('pve-iface', {
     minLength => 2, maxLength => 20,
 });
 
+register_standard_option('pve-vlan-id-or-range', {
+    description => "VLAN ID or range.",
+    type => 'string', format => 'pve-vlan-id-or-range',
+    minLength => 1, maxLength => 9,
+});
+
 register_standard_option('pve-storage-id', {
     description => "The storage identifier.",
     type => 'string', format => 'pve-storage-id',
@@ -595,6 +601,34 @@ sub pve_verify_iface {
     return $id;
 }
 
+# vlan id (vids), single or range
+register_format('pve-vlan-id-or-range', \&pve_verify_vlan_id_or_range);
+sub pve_verify_vlan_id_or_range {
+    my ($vlan, $noerr) = @_;
+
+    my $check_vid = sub {
+	my $tag = shift;
+	if ( $tag < 2 || $tag > 4094) {
+	    return undef if $noerr;
+	    die "invalid VLAN tag '$tag'\n";
+	}
+    };
+
+    if ($vlan !~ m/^(\d+)([-](\d+))?$/i) {
+	return undef if $noerr;
+	die "invalid VLAN configuration '$vlan'\n";
+    }
+    my $start = $1;
+    my $end = $3;
+    return  undef if (!defined $check_vid->($start));
+    if ($end) {
+	return undef if (!defined $check_vid->($end));
+	die "VLAN range must go from lower to higher tag '$vlan'" if $start >= $end && !$noerr;
+    }
+
+    return $vlan;
+}
+
 # general addresses by name or IP
 register_format('address', \&pve_verify_address);
 sub pve_verify_address {
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH common v3 3/3] inotify: interfaces: make sure bridge_vids use space as separator
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 1/3] tools: add check_list_empty function Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-03  8:01 ` [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids Aaron Lauterer
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

Because the API accepts multiple possible list separators we need to
make sure that we write the bridge_vids with space as separator, no
matter which separator was used when passing it to the API.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2:
* added to make sure the format works as expected, no matter what
  delimiter might have been used in the API call

 src/PVE/INotify.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 8a4a810..bf580c5 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1315,7 +1315,7 @@ sub __interface_to_string {
 
 	if (defined($d->{bridge_vlan_aware})) {
 	    $raw .= "\tbridge-vlan-aware yes\n";
-	    my $vlans = defined($d->{bridge_vids}) ? $d->{bridge_vids} : "2-4094";
+	    my $vlans = length($d->{bridge_vids}) ? join(" ", PVE::Tools::split_list($d->{bridge_vids})) : "2-4094";
 	    $raw .= "\tbridge-vids $vlans\n";
 	}
 	$done->{bridge_vlan_aware} = 1;
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (2 preceding siblings ...)
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 3/3] inotify: interfaces: make sure bridge_vids use space as separator Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-26 12:22   ` Shannon Sterz
  2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

The new optional bridge_vids field allows to set that property via the
GUI. Since the backend needs to support it, the field needs to be
explicitly enabled.

For now, Proxmox VE (PVE) is the use case.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2:
* added validation code following how it is implemented in the API

 src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
 src/node/NetworkView.js |  5 ++++
 2 files changed, 67 insertions(+)

diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
index 27c1baf..8c1b135 100644
--- a/src/node/NetworkEdit.js
+++ b/src/node/NetworkEdit.js
@@ -2,6 +2,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
     extend: 'Proxmox.window.Edit',
     alias: ['widget.proxmoxNodeNetworkEdit'],
 
+    // Enable to show the VLAN ID field
+    bridge_set_vids: false,
+
     initComponent: function() {
 	let me = this;
 
@@ -57,11 +60,67 @@ Ext.define('Proxmox.node.NetworkEdit', {
 	}
 
 	if (me.iftype === 'bridge') {
+	    let vids = Ext.create('Ext.form.field.Text', {
+		fieldLabel: gettext('Bridge VIDS'),
+		name: 'bridge_vids',
+		emptyText: '2-4094',
+		disabled: true,
+		autoEl: {
+		    tag: 'div',
+		    'data-qtip': gettext('Space-separated list of VLANs and ranges, for example: 2 4 100-200'),
+		},
+		validator: function(value) {
+		    if (!value) { return true; } // Empty
+		    let result = true;
+
+		    let vid_list = value.split(' ');
+
+		    let checkVid = function(tag) {
+			if (tag < 2 || tag > 4094) {
+			    return `not a valid VLAN ID '${tag}'`;
+			}
+			return true;
+		    };
+
+		    for (const vid of vid_list) {
+			if (!vid) {
+			    continue;
+			}
+			let res = vid.match(/^(\d+)([-](\d+))?$/i);
+			if (!res) {
+			    return `not a valid VLAN configuration '${vid}'`;
+			}
+			let start = Number(res[1]);
+			let end = Number(res[3]);
+
+			if (start) {
+			    result = checkVid(start);
+			    if (result !== true) { return result; }
+			}
+			if (end) {
+			    result = checkVid(end);
+			    if (result !== true) { return result; }
+			}
+
+			if (start >= end) {
+			    return `VID range must go from lower to higher tag: '${vid}'`;
+			}
+		    }
+		    return true;
+		},
+	    });
 	    column2.push({
 		xtype: 'proxmoxcheckbox',
 		fieldLabel: gettext('VLAN aware'),
 		name: 'bridge_vlan_aware',
 		deleteEmpty: !me.isCreate,
+		listeners: {
+		    change: function(f, newVal) {
+			if (me.bridge_set_vids) {
+			    vids.setDisabled(!newVal);
+			}
+		    },
+		},
 	    });
 	    column2.push({
 		xtype: 'textfield',
@@ -72,6 +131,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
 		    'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
 		},
 	    });
+	    if (me.bridge_set_vids) {
+		advancedColumn2.push(vids);
+	    }
 	} else if (me.iftype === 'OVSBridge') {
 	    column2.push({
 		xtype: 'textfield',
diff --git a/src/node/NetworkView.js b/src/node/NetworkView.js
index 1d67ac8..c08cbfa 100644
--- a/src/node/NetworkView.js
+++ b/src/node/NetworkView.js
@@ -33,6 +33,9 @@ Ext.define('Proxmox.node.NetworkView', {
 
     showApplyBtn: false,
 
+    // decides if VLAN IDs field for bridges is shown, depends on the product if needed
+    bridge_set_vids: false,
+
     initComponent: function() {
 	let me = this;
 
@@ -100,6 +103,7 @@ Ext.define('Proxmox.node.NetworkView', {
 		nodename: me.nodename,
 		iface: rec.data.iface,
 		iftype: rec.data.type,
+		bridge_set_vids: me.bridge_set_vids,
 		listeners: {
 		    destroy: () => reload(),
 		},
@@ -170,6 +174,7 @@ Ext.define('Proxmox.node.NetworkView', {
 		    nodename: me.nodename,
 		    iftype: iType,
 		    iface_default: findNextFreeInterfaceId(iDefault ?? iType),
+		    bridge_set_vids: me.bridge_set_vids,
 		    onlineHelp: 'sysadmin_network_configuration',
 		    listeners: {
 			destroy: () => reload(),
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (3 preceding siblings ...)
  2024-07-03  8:01 ` [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-26 12:23   ` Shannon Sterz
  2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 6/6] fix #3893: ui: network: enable bridge_vids field Aaron Lauterer
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2:
* added checks to handle empty lists

 PVE/API2/Network.pm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
index f39f04f5..dd3855d1 100644
--- a/PVE/API2/Network.pm
+++ b/PVE/API2/Network.pm
@@ -66,6 +66,11 @@ my $confdesc = {
 	type => 'boolean',
 	optional => 1,
     },
+    bridge_vids => {
+	description => "Specify the allowed vlans. For example: '2 4 100-200'. Only used if the bridge is VLAN aware.",
+	optional => 1,
+	type => 'string', format => 'pve-vlan-id-or-range-list',
+    },
     bridge_ports => {
 	description => "Specify the interfaces you want to add to your bridge.",
 	optional => 1,
@@ -469,6 +474,10 @@ __PACKAGE__->register_method({
 		    if ! grep { $_ eq $iface } @ports;
 	    }
 
+	    if ($param->{bridge_vids} && !PVE::Tools::check_list_empty($param->{bridge_vids})) {
+		raise_param_exc({ bridge_vids => "VLAN list items are empty" });
+	    }
+
 	    $ifaces->{$iface} = $param;
 
 	    PVE::INotify::write_file('interfaces', $config);
@@ -558,7 +567,11 @@ __PACKAGE__->register_method({
 	    foreach my $k (keys %$param) {
 		$ifaces->{$iface}->{$k} = $param->{$k};
 	    }
-	    
+
+	    if ($param->{bridge_vids} && !PVE::Tools::check_list_empty($param->{bridge_vids})) {
+		raise_param_exc({ bridge_vids => "VLAN list items are empty" });
+	    }
+
 	    PVE::INotify::write_file('interfaces', $config);
 	};
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH manager v3 6/6] fix #3893: ui: network: enable bridge_vids field
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (4 preceding siblings ...)
  2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
@ 2024-07-03  8:01 ` Aaron Lauterer
  2024-07-23 11:24 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Stefan Hanreich
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-03  8:01 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since v2: none

 www/manager6/node/Config.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index d27592ce..7bdfb6d9 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -194,6 +194,7 @@ Ext.define('PVE.node.Config', {
 		    showApplyBtn: true,
 		    groups: ['services'],
 		    nodename: nodename,
+		    bridge_set_vids: true,
 		    onlineHelp: 'sysadmin_network_configuration',
 		},
 		{
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (5 preceding siblings ...)
  2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 6/6] fix #3893: ui: network: enable bridge_vids field Aaron Lauterer
@ 2024-07-23 11:24 ` Stefan Hanreich
  2024-07-23 13:33 ` [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field Aaron Lauterer
  2024-07-26 12:22 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Shannon Sterz
  8 siblings, 0 replies; 16+ messages in thread
From: Stefan Hanreich @ 2024-07-23 11:24 UTC (permalink / raw)
  To: Proxmox VE development discussion, Aaron Lauterer

Tested the patches on my machine and everything worked as advertised.

It might make sense to note that this setting currently only applies to
the bridge_ports specified in the configuration, not the bridge
interface itself. Not sure if this is an ifupdown2 bug or intended. I
think it is actually a bug when reading the docs of the bridge-vids
parameter:

> Denotes the space separated list of VLANs to be allowed tagged
> ingress/egress on this interface.

It doesn't make a practical difference for our use case though.

It might make sense to note that this only applies to north-south
traffic (due to the bridge_ports getting the VLAN tags set), but not
east-west. One can still create two network devices on two guests with a
tag that is not specified in the bridge-vids and they can still
communicate (This is actually not a bug, but intended behavior of the
linux bridge when vlan_filtering is on!). This behavior might be
conterintuitive for users.

Consider this:
Tested-By: Stefan Hanreich <s.hanreich@proxmox.com>


On 7/3/24 10:01, Aaron Lauterer wrote:
> this version reworks a few parts since v2.
> 
> * renamed format in JSONSchema to a more generic `pve-vlan-id-or-range`
> * explicitly use spaces when writing interfaces file. This is one
>   possible approach to deal with the fact, that the generic `-list`
>   format will accept quite a few delimiters and we need spaces.
> * code style improvements such as naming the regex results.
> * add parameter verification to the web ui
> 
> With the changes to the JSONSchema we can then work on using it too for
> the guest trunk option. This hasn't been started yet though.
> 
> common: Aaron Lauterer (3):
>   tools: add check_list_empty function
>   fix #3893: network: add vlan id and range parameter definitions
>   inotify: interfaces: make sure bridge_vids use space as separator
> 
>  src/PVE/INotify.pm    |  2 +-
>  src/PVE/JSONSchema.pm | 34 ++++++++++++++++++++++++++++++++++
>  src/PVE/Tools.pm      |  8 ++++++++
>  3 files changed, 43 insertions(+), 1 deletion(-)
> 
> 
> widget-toolkit: Aaron Lauterer (1):
>   fix #3892: Network: add bridge vids field for bridge_vids
> 
>  src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
>  src/node/NetworkView.js |  5 ++++
>  2 files changed, 67 insertions(+)
> 
> 
> manager: Aaron Lauterer (2):
>   fix #3893: api: network: add bridge_vids parameter
>   fix #3893: ui: network: enable bridge_vids field
> 
>  PVE/API2/Network.pm         | 15 ++++++++++++++-
>  www/manager6/node/Config.js |  1 +
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (6 preceding siblings ...)
  2024-07-23 11:24 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Stefan Hanreich
@ 2024-07-23 13:33 ` Aaron Lauterer
  2024-07-26 12:23   ` Shannon Sterz
  2024-07-26 12:22 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Shannon Sterz
  8 siblings, 1 reply; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-23 13:33 UTC (permalink / raw)
  To: pve-devel

Make clear that it affects only out-/inbound traffic and can be used if
the underlying physical NICs support only a limited number of VLANs when
offloading is possible.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
After some off-list discussion with @Stefan Hanreich after his review,
we came to the conclusion that some explanation is needed to avoid
confusion.
I am not too happy with how long the explanation is, if someone has a
better idea to transport that information, I am absolutely not opposed
to it.

 src/node/NetworkEdit.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
index 8c1b135..1149dee 100644
--- a/src/node/NetworkEdit.js
+++ b/src/node/NetworkEdit.js
@@ -109,6 +109,12 @@ Ext.define('Proxmox.node.NetworkEdit', {
 		    return true;
 		},
 	    });
+	    let vidsExplanation = Ext.create('Ext.form.field.Display', {
+		    disabled: true,
+		    userCls: 'pmx-hint',
+		    value: 'Use if you want the bridge ports to only forward a limited number of ' +
+			   'VLANs or the physical NICs support a limited number of offloaded VLANs.',
+	    });
 	    column2.push({
 		xtype: 'proxmoxcheckbox',
 		fieldLabel: gettext('VLAN aware'),
@@ -118,6 +124,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
 		    change: function(f, newVal) {
 			if (me.bridge_set_vids) {
 			    vids.setDisabled(!newVal);
+			    vidsExplanation.setDisabled(!newVal);
 			}
 		    },
 		},
@@ -133,6 +140,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
 	    });
 	    if (me.bridge_set_vids) {
 		advancedColumn2.push(vids);
+		advancedColumn2.push(vidsExplanation);
 	    }
 	} else if (me.iftype === 'OVSBridge') {
 	    column2.push({
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3]  fix #3893: make bridge vids configurable
  2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
                   ` (7 preceding siblings ...)
  2024-07-23 13:33 ` [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field Aaron Lauterer
@ 2024-07-26 12:22 ` Shannon Sterz
  8 siblings, 0 replies; 16+ messages in thread
From: Shannon Sterz @ 2024-07-26 12:22 UTC (permalink / raw)
  To: Proxmox VE development discussion

On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
> this version reworks a few parts since v2.
>
> * renamed format in JSONSchema to a more generic `pve-vlan-id-or-range`
> * explicitly use spaces when writing interfaces file. This is one
>   possible approach to deal with the fact, that the generic `-list`
>   format will accept quite a few delimiters and we need spaces.
> * code style improvements such as naming the regex results.
> * add parameter verification to the web ui
>
> With the changes to the JSONSchema we can then work on using it too for
> the guest trunk option. This hasn't been started yet though.
>
> common: Aaron Lauterer (3):
>   tools: add check_list_empty function
>   fix #3893: network: add vlan id and range parameter definitions
>   inotify: interfaces: make sure bridge_vids use space as separator
>
>  src/PVE/INotify.pm    |  2 +-
>  src/PVE/JSONSchema.pm | 34 ++++++++++++++++++++++++++++++++++
>  src/PVE/Tools.pm      |  8 ++++++++
>  3 files changed, 43 insertions(+), 1 deletion(-)
>
>
> widget-toolkit: Aaron Lauterer (1):
>   fix #3892: Network: add bridge vids field for bridge_vids
>
>  src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
>  src/node/NetworkView.js |  5 ++++
>  2 files changed, 67 insertions(+)
>
>
> manager: Aaron Lauterer (2):
>   fix #3893: api: network: add bridge_vids parameter
>   fix #3893: ui: network: enable bridge_vids field
>
>  PVE/API2/Network.pm         | 15 ++++++++++++++-
>  www/manager6/node/Config.js |  1 +
>  2 files changed, 15 insertions(+), 1 deletion(-)

thanks for this, i did a short review of the code. i have a couple of
minor issue, but other than that this series:

Reviewed-by: Shannon Sterz <s.sterz@proxmox.com>




_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions
  2024-07-03  8:01 ` [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions Aaron Lauterer
@ 2024-07-26 12:22   ` Shannon Sterz
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Sterz @ 2024-07-26 12:22 UTC (permalink / raw)
  To: Proxmox VE development discussion

On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
> This is one step to make it possible to define the VLAN IDs and ranges
> for bridges.
>
> It is expected to be used in combination with the `-list` magic
> property. Therefore it defines and checks the validity of a single list
> item that could just be a single VLAN tag ID or a range.
>
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> changes since v2:
> * renamed schema to a more generic one with the use case of the guest
>   trunk config in mind
>
>  src/PVE/JSONSchema.pm | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
> index 115f811..22fe048 100644
> --- a/src/PVE/JSONSchema.pm
> +++ b/src/PVE/JSONSchema.pm
> @@ -81,6 +81,12 @@ register_standard_option('pve-iface', {
>      minLength => 2, maxLength => 20,
>  });
>
> +register_standard_option('pve-vlan-id-or-range', {
> +    description => "VLAN ID or range.",
> +    type => 'string', format => 'pve-vlan-id-or-range',
> +    minLength => 1, maxLength => 9,
> +});
> +
>  register_standard_option('pve-storage-id', {
>      description => "The storage identifier.",
>      type => 'string', format => 'pve-storage-id',
> @@ -595,6 +601,34 @@ sub pve_verify_iface {
>      return $id;
>  }
>
> +# vlan id (vids), single or range
> +register_format('pve-vlan-id-or-range', \&pve_verify_vlan_id_or_range);
> +sub pve_verify_vlan_id_or_range {
> +    my ($vlan, $noerr) = @_;
> +
> +    my $check_vid = sub {
> +	my $tag = shift;
> +	if ( $tag < 2 || $tag > 4094) {
> +	    return undef if $noerr;
> +	    die "invalid VLAN tag '$tag'\n";
> +	}
> +    };
> +
> +    if ($vlan !~ m/^(\d+)([-](\d+))?$/i) {

nit: pretty sure you can ommit the [] brackets here and you could use a
non-capturing group to get this somewhat cleaner regex:

^(\d+)(?:-(\d+))?$

also not sure this needs to be case insensitive, but it's probably fine.

by using a non capturing group you don't get the useless "-" in the
second group...

> +	return undef if $noerr;
> +	die "invalid VLAN configuration '$vlan'\n";
> +    }
> +    my $start = $1;
> +    my $end = $3;

... so this becomes:

    my $end = $2;

> +    return  undef if (!defined $check_vid->($start));

nit: there is an extra space here.

> +    if ($end) {
> +	return undef if (!defined $check_vid->($end));
> +	die "VLAN range must go from lower to higher tag '$vlan'" if $start >= $end && !$noerr;
> +    }
> +
> +    return $vlan;
> +}
> +
>  # general addresses by name or IP
>  register_format('address', \&pve_verify_address);
>  sub pve_verify_address {



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids
  2024-07-03  8:01 ` [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids Aaron Lauterer
@ 2024-07-26 12:22   ` Shannon Sterz
  2024-07-29 10:25     ` Aaron Lauterer
  0 siblings, 1 reply; 16+ messages in thread
From: Shannon Sterz @ 2024-07-26 12:22 UTC (permalink / raw)
  To: Proxmox VE development discussion

On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
> The new optional bridge_vids field allows to set that property via the
> GUI. Since the backend needs to support it, the field needs to be
> explicitly enabled.
>
> For now, Proxmox VE (PVE) is the use case.
>
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> changes since v2:
> * added validation code following how it is implemented in the API
>
>  src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
>  src/node/NetworkView.js |  5 ++++
>  2 files changed, 67 insertions(+)
>
> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
> index 27c1baf..8c1b135 100644
> --- a/src/node/NetworkEdit.js
> +++ b/src/node/NetworkEdit.js
> @@ -2,6 +2,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
>      extend: 'Proxmox.window.Edit',
>      alias: ['widget.proxmoxNodeNetworkEdit'],
>
> +    // Enable to show the VLAN ID field
> +    bridge_set_vids: false,
> +
>      initComponent: function() {
>  	let me = this;
>
> @@ -57,11 +60,67 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  	}
>
>  	if (me.iftype === 'bridge') {
> +	    let vids = Ext.create('Ext.form.field.Text', {
> +		fieldLabel: gettext('Bridge VIDS'),
> +		name: 'bridge_vids',
> +		emptyText: '2-4094',
> +		disabled: true,
> +		autoEl: {
> +		    tag: 'div',
> +		    'data-qtip': gettext('Space-separated list of VLANs and ranges, for example: 2 4 100-200'),
> +		},
> +		validator: function(value) {
> +		    if (!value) { return true; } // Empty

nit: our js style guide state that single line ifs should be avoided

> +		    let result = true;
> +
> +		    let vid_list = value.split(' ');
> +
> +		    let checkVid = function(tag) {
> +			if (tag < 2 || tag > 4094) {
> +			    return `not a valid VLAN ID '${tag}'`;
> +			}
> +			return true;
> +		    };
> +
> +		    for (const vid of vid_list) {
> +			if (!vid) {
> +			    continue;
> +			}
> +			let res = vid.match(/^(\d+)([-](\d+))?$/i);

nit: see my comment for patch 2.

> +			if (!res) {
> +			    return `not a valid VLAN configuration '${vid}'`;
> +			}
> +			let start = Number(res[1]);
> +			let end = Number(res[3]);
> +
> +			if (start) {
> +			    result = checkVid(start);
> +			    if (result !== true) { return result; }

same here...

> +			}
> +			if (end) {
> +			    result = checkVid(end);
> +			    if (result !== true) { return result; }

and here. it might be more elegant to do this:

    let invalidVid = function(tag) {
        if (!isNaN(tag) && (tag < 2 || tag > 4094)) {
            return `not a valid VLAN ID '${tag}'`;
        }

        return false;
    };

// [..]

        if (res = invalidVid(start)) {
            return res;
        }

        if (res = invalidVid(end)) {
            return res;
        }

`Number(res[n])` should return `NaN` if `res[n]` is undefined, this
shouldn't be the case for start ever but is relevant for `end`.

> +			}
> +
> +			if (start >= end) {
> +			    return `VID range must go from lower to higher tag: '${vid}'`;
> +			}
> +		    }
> +		    return true;
> +		},
> +	    });
>  	    column2.push({
>  		xtype: 'proxmoxcheckbox',
>  		fieldLabel: gettext('VLAN aware'),
>  		name: 'bridge_vlan_aware',
>  		deleteEmpty: !me.isCreate,
> +		listeners: {
> +		    change: function(f, newVal) {
> +			if (me.bridge_set_vids) {
> +			    vids.setDisabled(!newVal);
> +			}
> +		    },
> +		},
>  	    });
>  	    column2.push({
>  		xtype: 'textfield',
> @@ -72,6 +131,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  		    'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
>  		},
>  	    });
> +	    if (me.bridge_set_vids) {
> +		advancedColumn2.push(vids);
> +	    }
>  	} else if (me.iftype === 'OVSBridge') {
>  	    column2.push({
>  		xtype: 'textfield',
> diff --git a/src/node/NetworkView.js b/src/node/NetworkView.js
> index 1d67ac8..c08cbfa 100644
> --- a/src/node/NetworkView.js
> +++ b/src/node/NetworkView.js
> @@ -33,6 +33,9 @@ Ext.define('Proxmox.node.NetworkView', {
>
>      showApplyBtn: false,
>
> +    // decides if VLAN IDs field for bridges is shown, depends on the product if needed
> +    bridge_set_vids: false,
> +
>      initComponent: function() {
>  	let me = this;
>
> @@ -100,6 +103,7 @@ Ext.define('Proxmox.node.NetworkView', {
>  		nodename: me.nodename,
>  		iface: rec.data.iface,
>  		iftype: rec.data.type,
> +		bridge_set_vids: me.bridge_set_vids,
>  		listeners: {
>  		    destroy: () => reload(),
>  		},
> @@ -170,6 +174,7 @@ Ext.define('Proxmox.node.NetworkView', {
>  		    nodename: me.nodename,
>  		    iftype: iType,
>  		    iface_default: findNextFreeInterfaceId(iDefault ?? iType),
> +		    bridge_set_vids: me.bridge_set_vids,
>  		    onlineHelp: 'sysadmin_network_configuration',
>  		    listeners: {
>  			destroy: () => reload(),



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter
  2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
@ 2024-07-26 12:23   ` Shannon Sterz
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Sterz @ 2024-07-26 12:23 UTC (permalink / raw)
  To: Proxmox VE development discussion

On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> changes since v2:
> * added checks to handle empty lists
>
>  PVE/API2/Network.pm | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
> index f39f04f5..dd3855d1 100644
> --- a/PVE/API2/Network.pm
> +++ b/PVE/API2/Network.pm
> @@ -66,6 +66,11 @@ my $confdesc = {
>  	type => 'boolean',
>  	optional => 1,
>      },
> +    bridge_vids => {
> +	description => "Specify the allowed vlans. For example: '2 4 100-200'. Only used if the bridge is VLAN aware.",

nit: i think this should be "VLANs" as you seem to capitalize this
abbreviation everywhere else.

> +	optional => 1,
> +	type => 'string', format => 'pve-vlan-id-or-range-list',
> +    },
>      bridge_ports => {
>  	description => "Specify the interfaces you want to add to your bridge.",
>  	optional => 1,
> @@ -469,6 +474,10 @@ __PACKAGE__->register_method({
>  		    if ! grep { $_ eq $iface } @ports;
>  	    }
>
> +	    if ($param->{bridge_vids} && !PVE::Tools::check_list_empty($param->{bridge_vids})) {
> +		raise_param_exc({ bridge_vids => "VLAN list items are empty" });
> +	    }
> +
>  	    $ifaces->{$iface} = $param;
>
>  	    PVE::INotify::write_file('interfaces', $config);
> @@ -558,7 +567,11 @@ __PACKAGE__->register_method({
>  	    foreach my $k (keys %$param) {
>  		$ifaces->{$iface}->{$k} = $param->{$k};
>  	    }
> -
> +
> +	    if ($param->{bridge_vids} && !PVE::Tools::check_list_empty($param->{bridge_vids})) {
> +		raise_param_exc({ bridge_vids => "VLAN list items are empty" });
> +	    }
> +
>  	    PVE::INotify::write_file('interfaces', $config);
>  	};
>



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field
  2024-07-23 13:33 ` [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field Aaron Lauterer
@ 2024-07-26 12:23   ` Shannon Sterz
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Sterz @ 2024-07-26 12:23 UTC (permalink / raw)
  To: Proxmox VE development discussion

On Tue Jul 23, 2024 at 3:33 PM CEST, Aaron Lauterer wrote:
> Make clear that it affects only out-/inbound traffic and can be used if
> the underlying physical NICs support only a limited number of VLANs when
> offloading is possible.
>
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> After some off-list discussion with @Stefan Hanreich after his review,
> we came to the conclusion that some explanation is needed to avoid
> confusion.
> I am not too happy with how long the explanation is, if someone has a
> better idea to transport that information, I am absolutely not opposed
> to it.
>
>  src/node/NetworkEdit.js | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
> index 8c1b135..1149dee 100644
> --- a/src/node/NetworkEdit.js
> +++ b/src/node/NetworkEdit.js
> @@ -109,6 +109,12 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  		    return true;
>  		},
>  	    });
> +	    let vidsExplanation = Ext.create('Ext.form.field.Display', {
> +		    disabled: true,
> +		    userCls: 'pmx-hint',
> +		    value: 'Use if you want the bridge ports to only forward a limited number of ' +
> +			   'VLANs or the physical NICs support a limited number of offloaded VLANs.',

Maybe:

Limits the number of VLANs forwarded by the bridge ports. Useful if the
physical NICs only support a limited number of offloaded VLANs.

> +	    });
>  	    column2.push({
>  		xtype: 'proxmoxcheckbox',
>  		fieldLabel: gettext('VLAN aware'),
> @@ -118,6 +124,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  		    change: function(f, newVal) {
>  			if (me.bridge_set_vids) {
>  			    vids.setDisabled(!newVal);
> +			    vidsExplanation.setDisabled(!newVal);
>  			}
>  		    },
>  		},
> @@ -133,6 +140,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  	    });
>  	    if (me.bridge_set_vids) {
>  		advancedColumn2.push(vids);
> +		advancedColumn2.push(vidsExplanation);
>  	    }
>  	} else if (me.iftype === 'OVSBridge') {
>  	    column2.push({



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids
  2024-07-26 12:22   ` Shannon Sterz
@ 2024-07-29 10:25     ` Aaron Lauterer
  2024-07-29 10:42       ` Shannon Sterz
  0 siblings, 1 reply; 16+ messages in thread
From: Aaron Lauterer @ 2024-07-29 10:25 UTC (permalink / raw)
  To: Proxmox VE development discussion, Shannon Sterz



On  2024-07-26  14:22, Shannon Sterz wrote:
> On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
>> The new optional bridge_vids field allows to set that property via the
>> GUI. Since the backend needs to support it, the field needs to be
>> explicitly enabled.
>>
>> For now, Proxmox VE (PVE) is the use case.
>>
>> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
>> ---
>> changes since v2:
>> * added validation code following how it is implemented in the API
>>
>>   src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
>>   src/node/NetworkView.js |  5 ++++
>>   2 files changed, 67 insertions(+)
>>
>> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
>> index 27c1baf..8c1b135 100644
>> --- a/src/node/NetworkEdit.js
>> +++ b/src/node/NetworkEdit.js
>> @@ -2,6 +2,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
>>       extend: 'Proxmox.window.Edit',
>>       alias: ['widget.proxmoxNodeNetworkEdit'],
>>
>> +    // Enable to show the VLAN ID field
>> +    bridge_set_vids: false,
>> +
>>       initComponent: function() {
>>   	let me = this;
>>
>> @@ -57,11 +60,67 @@ Ext.define('Proxmox.node.NetworkEdit', {
>>   	}
>>
>>   	if (me.iftype === 'bridge') {
>> +	    let vids = Ext.create('Ext.form.field.Text', {
>> +		fieldLabel: gettext('Bridge VIDS'),
>> +		name: 'bridge_vids',
>> +		emptyText: '2-4094',
>> +		disabled: true,
>> +		autoEl: {
>> +		    tag: 'div',
>> +		    'data-qtip': gettext('Space-separated list of VLANs and ranges, for example: 2 4 100-200'),
>> +		},
>> +		validator: function(value) {
>> +		    if (!value) { return true; } // Empty
> 
> nit: our js style guide state that single line ifs should be avoided
> 
>> +		    let result = true;
>> +
>> +		    let vid_list = value.split(' ');
>> +
>> +		    let checkVid = function(tag) {
>> +			if (tag < 2 || tag > 4094) {
>> +			    return `not a valid VLAN ID '${tag}'`;
>> +			}
>> +			return true;
>> +		    };
>> +
>> +		    for (const vid of vid_list) {
>> +			if (!vid) {
>> +			    continue;
>> +			}
>> +			let res = vid.match(/^(\d+)([-](\d+))?$/i);
> 
> nit: see my comment for patch 2.
> 
>> +			if (!res) {
>> +			    return `not a valid VLAN configuration '${vid}'`;
>> +			}
>> +			let start = Number(res[1]);
>> +			let end = Number(res[3]);
>> +
>> +			if (start) {
>> +			    result = checkVid(start);
>> +			    if (result !== true) { return result; }
> 
> same here...
> 
>> +			}
>> +			if (end) {
>> +			    result = checkVid(end);
>> +			    if (result !== true) { return result; }
> 
> and here. it might be more elegant to do this:
> 
>      let invalidVid = function(tag) {
>          if (!isNaN(tag) && (tag < 2 || tag > 4094)) {
>              return `not a valid VLAN ID '${tag}'`;
>          }
> 
>          return false;
>      };
> 
> // [..]
> 
>          if (res = invalidVid(start)) {
>              return res;
>          }
> 
>          if (res = invalidVid(end)) {
>              return res;
>          }
> 
> `Number(res[n])` should return `NaN` if `res[n]` is undefined, this
> shouldn't be the case for start ever but is relevant for `end`.
> 

Thanks for the overall review and these suggestions!

The above example won't work exactly like that, as eslint will throw an 
error due to assignments inside the if-clause.

I opted for
res = invalidVid(start);
if (res) {
	return res;
}

Not quite as succinct, but it does the same job and adheres to our 
eslint rules.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids
  2024-07-29 10:25     ` Aaron Lauterer
@ 2024-07-29 10:42       ` Shannon Sterz
  0 siblings, 0 replies; 16+ messages in thread
From: Shannon Sterz @ 2024-07-29 10:42 UTC (permalink / raw)
  To: Aaron Lauterer, Proxmox VE development discussion

On Mon Jul 29, 2024 at 12:25 PM CEST, Aaron Lauterer wrote:
>
>
> On  2024-07-26  14:22, Shannon Sterz wrote:
> > On Wed Jul 3, 2024 at 10:01 AM CEST, Aaron Lauterer wrote:
> >> The new optional bridge_vids field allows to set that property via the
> >> GUI. Since the backend needs to support it, the field needs to be
> >> explicitly enabled.
> >>
> >> For now, Proxmox VE (PVE) is the use case.
> >>
> >> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> >> ---
> >> changes since v2:
> >> * added validation code following how it is implemented in the API
> >>
> >>   src/node/NetworkEdit.js | 62 +++++++++++++++++++++++++++++++++++++++++
> >>   src/node/NetworkView.js |  5 ++++
> >>   2 files changed, 67 insertions(+)
> >>
> >> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
> >> index 27c1baf..8c1b135 100644
> >> --- a/src/node/NetworkEdit.js
> >> +++ b/src/node/NetworkEdit.js
> >> @@ -2,6 +2,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
> >>       extend: 'Proxmox.window.Edit',
> >>       alias: ['widget.proxmoxNodeNetworkEdit'],
> >>
> >> +    // Enable to show the VLAN ID field
> >> +    bridge_set_vids: false,
> >> +
> >>       initComponent: function() {
> >>   	let me = this;
> >>
> >> @@ -57,11 +60,67 @@ Ext.define('Proxmox.node.NetworkEdit', {
> >>   	}
> >>
> >>   	if (me.iftype === 'bridge') {
> >> +	    let vids = Ext.create('Ext.form.field.Text', {
> >> +		fieldLabel: gettext('Bridge VIDS'),
> >> +		name: 'bridge_vids',
> >> +		emptyText: '2-4094',
> >> +		disabled: true,
> >> +		autoEl: {
> >> +		    tag: 'div',
> >> +		    'data-qtip': gettext('Space-separated list of VLANs and ranges, for example: 2 4 100-200'),
> >> +		},
> >> +		validator: function(value) {
> >> +		    if (!value) { return true; } // Empty
> >
> > nit: our js style guide state that single line ifs should be avoided
> >
> >> +		    let result = true;
> >> +
> >> +		    let vid_list = value.split(' ');
> >> +
> >> +		    let checkVid = function(tag) {
> >> +			if (tag < 2 || tag > 4094) {
> >> +			    return `not a valid VLAN ID '${tag}'`;
> >> +			}
> >> +			return true;
> >> +		    };
> >> +
> >> +		    for (const vid of vid_list) {
> >> +			if (!vid) {
> >> +			    continue;
> >> +			}
> >> +			let res = vid.match(/^(\d+)([-](\d+))?$/i);
> >
> > nit: see my comment for patch 2.
> >
> >> +			if (!res) {
> >> +			    return `not a valid VLAN configuration '${vid}'`;
> >> +			}
> >> +			let start = Number(res[1]);
> >> +			let end = Number(res[3]);
> >> +
> >> +			if (start) {
> >> +			    result = checkVid(start);
> >> +			    if (result !== true) { return result; }
> >
> > same here...
> >
> >> +			}
> >> +			if (end) {
> >> +			    result = checkVid(end);
> >> +			    if (result !== true) { return result; }
> >
> > and here. it might be more elegant to do this:
> >
> >      let invalidVid = function(tag) {
> >          if (!isNaN(tag) && (tag < 2 || tag > 4094)) {
> >              return `not a valid VLAN ID '${tag}'`;
> >          }
> >
> >          return false;
> >      };
> >
> > // [..]
> >
> >          if (res = invalidVid(start)) {
> >              return res;
> >          }
> >
> >          if (res = invalidVid(end)) {
> >              return res;
> >          }
> >
> > `Number(res[n])` should return `NaN` if `res[n]` is undefined, this
> > shouldn't be the case for start ever but is relevant for `end`.
> >
>
> Thanks for the overall review and these suggestions!
>
> The above example won't work exactly like that, as eslint will throw an
> error due to assignments inside the if-clause.
>
> I opted for
> res = invalidVid(start);
> if (res) {
> 	return res;
> }
>
> Not quite as succinct, but it does the same job and adheres to our
> eslint rules.

a fair enough, yeah didn't check with eslint, sorry my bad


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-07-29 10:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-03  8:01 [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Aaron Lauterer
2024-07-03  8:01 ` [pve-devel] [PATCH common v3 1/3] tools: add check_list_empty function Aaron Lauterer
2024-07-03  8:01 ` [pve-devel] [PATCH common v3 2/3] fix #3893: network: add vlan id and range parameter definitions Aaron Lauterer
2024-07-26 12:22   ` Shannon Sterz
2024-07-03  8:01 ` [pve-devel] [PATCH common v3 3/3] inotify: interfaces: make sure bridge_vids use space as separator Aaron Lauterer
2024-07-03  8:01 ` [pve-devel] [PATCH widget-toolkit v3] fix #3892: Network: add bridge vids field for bridge_vids Aaron Lauterer
2024-07-26 12:22   ` Shannon Sterz
2024-07-29 10:25     ` Aaron Lauterer
2024-07-29 10:42       ` Shannon Sterz
2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 5/6] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
2024-07-26 12:23   ` Shannon Sterz
2024-07-03  8:01 ` [pve-devel] [PATCH manager v3 6/6] fix #3893: ui: network: enable bridge_vids field Aaron Lauterer
2024-07-23 11:24 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Stefan Hanreich
2024-07-23 13:33 ` [pve-devel] [PATCH widget-toolkit v3 7/6 follow-up] Network: add explanation for bridge vids field Aaron Lauterer
2024-07-26 12:23   ` Shannon Sterz
2024-07-26 12:22 ` [pve-devel] [PATCH common, widget-toolkit, manager v3 0/3] fix #3893: make bridge vids configurable Shannon Sterz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal