public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable
@ 2023-04-13 15:10 Aaron Lauterer
  2023-04-13 15:10 ` [pve-devel] [PATCH manager 2/3] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Aaron Lauterer @ 2023-04-13 15:10 UTC (permalink / raw)
  To: pve-devel

For that we need to add a new format option that checks against valid
VLAN tags and ranges, for example: 2 4 100-200

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.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---

Notes:
    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.
    
    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'.

 src/PVE/INotify.pm    |  2 +-
 src/PVE/JSONSchema.pm | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

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 {
 
 	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}) ? $d->{bridge_vids} : "2-4094";
 	    $raw .= "\tbridge-vids $vlans\n";
 	}
 	$done->{bridge_vlan_aware} = 1;
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 527e409..d81a567 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -78,6 +78,12 @@ register_standard_option('pve-iface', {
     minLength => 2, maxLength => 20,
 });
 
+register_standard_option('pve-bridge-vid', {
+    description => "Bridge VLAN ID.",
+    type => 'string', format => 'pve-bridge-vid',
+    minLength => 1, maxLength => 9,
+});
+
 register_standard_option('pve-storage-id', {
     description => "The storage identifier.",
     type => 'string', format => 'pve-storage-id',
@@ -588,6 +594,32 @@ sub pve_verify_iface {
     return $id;
 }
 
+# bridge vlan id (vids)
+register_format('pve-bridge-vid', \&pve_verify_bridge_vid);
+sub pve_verify_bridge_vid {
+    my ($vlan, $noerr) = @_;
+
+    my $check_vid = sub {
+	my $id = shift;
+	if ( $id < 2 || $id > 4094) {
+	    return undef if $noerr;
+	    die "invalid VLAN tag '$id'\n";
+	}
+    };
+
+    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;
+    }
+
+    return $vlan;
+}
+
 # general addresses by name or IP
 register_format('address', \&pve_verify_address);
 sub pve_verify_address {
-- 
2.30.2





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

* [pve-devel] [PATCH manager 2/3] fix #3893: api: network: add bridge_vids parameter
  2023-04-13 15:10 [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
@ 2023-04-13 15:10 ` Aaron Lauterer
  2023-04-13 15:10 ` [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids Aaron Lauterer
  2023-05-26  8:33 ` [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
  2 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2023-04-13 15:10 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
 PVE/API2/Network.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
index a43579fa..0ca892de 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-bridge-vid-list',
+    },
     bridge_ports => {
 	description => "Specify the interfaces you want to add to your bridge.",
 	optional => 1,
-- 
2.30.2





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

* [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids
  2023-04-13 15:10 [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
  2023-04-13 15:10 ` [pve-devel] [PATCH manager 2/3] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
@ 2023-04-13 15:10 ` Aaron Lauterer
  2023-06-01 14:24   ` Thomas Lamprecht
  2023-05-26  8:33 ` [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
  2 siblings, 1 reply; 7+ messages in thread
From: Aaron Lauterer @ 2023-04-13 15:10 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
 src/node/NetworkEdit.js | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
index bb9add3..e4ab158 100644
--- a/src/node/NetworkEdit.js
+++ b/src/node/NetworkEdit.js
@@ -57,11 +57,26 @@ 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'),
+		},
+	    });
 	    column2.push({
 		xtype: 'proxmoxcheckbox',
 		fieldLabel: gettext('VLAN aware'),
 		name: 'bridge_vlan_aware',
 		deleteEmpty: !me.isCreate,
+		listeners: {
+		    change: function(f, newVal) {
+			vids.setDisabled(!newVal);
+		    },
+		},
 	    });
 	    column2.push({
 		xtype: 'textfield',
@@ -72,6 +87,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
 		    'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
 		},
 	    });
+	    advancedColumn2.push(vids);
 	} else if (me.iftype === 'OVSBridge') {
 	    column2.push({
 		xtype: 'textfield',
-- 
2.30.2





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

* Re: [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable
  2023-04-13 15:10 [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
  2023-04-13 15:10 ` [pve-devel] [PATCH manager 2/3] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
  2023-04-13 15:10 ` [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids Aaron Lauterer
@ 2023-05-26  8:33 ` Aaron Lauterer
  2 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2023-05-26  8:33 UTC (permalink / raw)
  To: pve-devel

ping?

On 4/13/23 17:10, 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
> 
> 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.
> 
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> 
> Notes:
>      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.
>      
>      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'.
> 
>   src/PVE/INotify.pm    |  2 +-
>   src/PVE/JSONSchema.pm | 32 ++++++++++++++++++++++++++++++++
>   2 files changed, 33 insertions(+), 1 deletion(-)
> 
> 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 {
>   
>   	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}) ? $d->{bridge_vids} : "2-4094";
>   	    $raw .= "\tbridge-vids $vlans\n";
>   	}
>   	$done->{bridge_vlan_aware} = 1;
> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
> index 527e409..d81a567 100644
> --- a/src/PVE/JSONSchema.pm
> +++ b/src/PVE/JSONSchema.pm
> @@ -78,6 +78,12 @@ register_standard_option('pve-iface', {
>       minLength => 2, maxLength => 20,
>   });
>   
> +register_standard_option('pve-bridge-vid', {
> +    description => "Bridge VLAN ID.",
> +    type => 'string', format => 'pve-bridge-vid',
> +    minLength => 1, maxLength => 9,
> +});
> +
>   register_standard_option('pve-storage-id', {
>       description => "The storage identifier.",
>       type => 'string', format => 'pve-storage-id',
> @@ -588,6 +594,32 @@ sub pve_verify_iface {
>       return $id;
>   }
>   
> +# bridge vlan id (vids)
> +register_format('pve-bridge-vid', \&pve_verify_bridge_vid);
> +sub pve_verify_bridge_vid {
> +    my ($vlan, $noerr) = @_;
> +
> +    my $check_vid = sub {
> +	my $id = shift;
> +	if ( $id < 2 || $id > 4094) {
> +	    return undef if $noerr;
> +	    die "invalid VLAN tag '$id'\n";
> +	}
> +    };
> +
> +    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;
> +    }
> +
> +    return $vlan;
> +}
> +
>   # general addresses by name or IP
>   register_format('address', \&pve_verify_address);
>   sub pve_verify_address {




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

* Re: [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids
  2023-04-13 15:10 ` [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids Aaron Lauterer
@ 2023-06-01 14:24   ` Thomas Lamprecht
  2023-06-02 13:10     ` Aaron Lauterer
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Lamprecht @ 2023-06-01 14:24 UTC (permalink / raw)
  To: Proxmox VE development discussion, Aaron Lauterer

Don't we reuse that on PBS/PMG too, and if is it working there?

The commit message isn't excactly telling... ;-)


Am 13/04/2023 um 17:10 schrieb Aaron Lauterer:
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
>  src/node/NetworkEdit.js | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
> index bb9add3..e4ab158 100644
> --- a/src/node/NetworkEdit.js
> +++ b/src/node/NetworkEdit.js
> @@ -57,11 +57,26 @@ 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'),
> +		},
> +	    });
>  	    column2.push({
>  		xtype: 'proxmoxcheckbox',
>  		fieldLabel: gettext('VLAN aware'),
>  		name: 'bridge_vlan_aware',
>  		deleteEmpty: !me.isCreate,
> +		listeners: {
> +		    change: function(f, newVal) {
> +			vids.setDisabled(!newVal);
> +		    },
> +		},
>  	    });
>  	    column2.push({
>  		xtype: 'textfield',
> @@ -72,6 +87,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
>  		    'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
>  		},
>  	    });
> +	    advancedColumn2.push(vids);
>  	} else if (me.iftype === 'OVSBridge') {
>  	    column2.push({
>  		xtype: 'textfield',





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

* Re: [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids
  2023-06-01 14:24   ` Thomas Lamprecht
@ 2023-06-02 13:10     ` Aaron Lauterer
  2023-06-07 16:12       ` Thomas Lamprecht
  0 siblings, 1 reply; 7+ messages in thread
From: Aaron Lauterer @ 2023-06-02 13:10 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion



On 6/1/23 16:24, Thomas Lamprecht wrote:
> Don't we reuse that on PBS/PMG too, and if is it working there?
> 
> The commit message isn't excactly telling... ;-)
> 

on PMG we only allow creating bonds in the GUI. On PBS we allow bonds and 
bridges. Though that makes we wonder what the use case for a bridge on PBS is.

What about safeguarding the vids to only be added/used if we are on PVE?
Something like `if (PVE) {`?

> 
> Am 13/04/2023 um 17:10 schrieb Aaron Lauterer:
>> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
>> ---
>>   src/node/NetworkEdit.js | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
>> index bb9add3..e4ab158 100644
>> --- a/src/node/NetworkEdit.js
>> +++ b/src/node/NetworkEdit.js
>> @@ -57,11 +57,26 @@ 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'),
>> +		},
>> +	    });
>>   	    column2.push({
>>   		xtype: 'proxmoxcheckbox',
>>   		fieldLabel: gettext('VLAN aware'),
>>   		name: 'bridge_vlan_aware',
>>   		deleteEmpty: !me.isCreate,
>> +		listeners: {
>> +		    change: function(f, newVal) {
>> +			vids.setDisabled(!newVal);
>> +		    },
>> +		},
>>   	    });
>>   	    column2.push({
>>   		xtype: 'textfield',
>> @@ -72,6 +87,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
>>   		    'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
>>   		},
>>   	    });
>> +	    advancedColumn2.push(vids);
>>   	} else if (me.iftype === 'OVSBridge') {
>>   	    column2.push({
>>   		xtype: 'textfield',
> 




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

* Re: [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids
  2023-06-02 13:10     ` Aaron Lauterer
@ 2023-06-07 16:12       ` Thomas Lamprecht
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2023-06-07 16:12 UTC (permalink / raw)
  To: Proxmox VE development discussion, Aaron Lauterer

Am 02/06/2023 um 15:10 schrieb Aaron Lauterer:
> What about safeguarding the vids to only be added/used if we are on PVE?
> Something like `if (PVE) {`?

We normally use config flags and set them only in those products that support
this, that would be a bit cleaner than `typeof PVE === "object"` or the like.

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

end of thread, other threads:[~2023-06-07 16:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 15:10 [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer
2023-04-13 15:10 ` [pve-devel] [PATCH manager 2/3] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
2023-04-13 15:10 ` [pve-devel] [PATCH widget-toolkit 3/3] fix #3892: NetworkEdit: add bridge vids field for bridge_vids Aaron Lauterer
2023-06-01 14:24   ` Thomas Lamprecht
2023-06-02 13:10     ` Aaron Lauterer
2023-06-07 16:12       ` Thomas Lamprecht
2023-05-26  8:33 ` [pve-devel] [PATCH common 1/3] fix #3893: network: make bridge vids configurable Aaron Lauterer

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