public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices
@ 2023-12-21 15:30 Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 1/4] network tests: switch to ifupdown2 Fabian Grünbichler
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Fabian Grünbichler @ 2023-12-21 15:30 UTC (permalink / raw)
  To: pve-devel

patches 1 and 2 are just to make writing the test case in 4 possible in the
first place. 3 is the actual fix.

Fabian Grünbichler (4):
  network tests: switch to ifupdown2
  network parser: iterate deterministically
  fix #5141: network parser: fix accidental RE result re-use
  network tests: test #5141

 src/PVE/INotify.pm                            | 21 ++++++--
 test/etc_network_interfaces/runtest.pl        |  2 +-
 .../t.bridge_eth_remove_auto.pl               | 24 ---------
 .../t.create_network.pl                       |  6 +--
 .../t.ovs_bridge_allow.pl                     | 12 ++---
 test/etc_network_interfaces/t.vlan-parsing.pl | 54 +++++++++++++++++++
 6 files changed, 80 insertions(+), 39 deletions(-)
 delete mode 100644 test/etc_network_interfaces/t.bridge_eth_remove_auto.pl
 create mode 100644 test/etc_network_interfaces/t.vlan-parsing.pl

-- 
2.39.2





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

* [pve-devel] [PATCH common 1/4] network tests: switch to ifupdown2
  2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
@ 2023-12-21 15:30 ` Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 2/4] network parser: iterate deterministically Fabian Grünbichler
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fabian Grünbichler @ 2023-12-21 15:30 UTC (permalink / raw)
  To: pve-devel

adapt allow-* to auto, and drop the one test where behaviour is not testable
anymore.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 test/etc_network_interfaces/runtest.pl        |  2 +-
 .../t.bridge_eth_remove_auto.pl               | 24 -------------------
 .../t.create_network.pl                       |  6 ++---
 .../t.ovs_bridge_allow.pl                     | 12 +++++-----
 4 files changed, 10 insertions(+), 34 deletions(-)
 delete mode 100644 test/etc_network_interfaces/t.bridge_eth_remove_auto.pl

diff --git a/test/etc_network_interfaces/runtest.pl b/test/etc_network_interfaces/runtest.pl
index f92f5ae..10fafae 100755
--- a/test/etc_network_interfaces/runtest.pl
+++ b/test/etc_network_interfaces/runtest.pl
@@ -78,7 +78,7 @@ sub r($;$$) {
 sub w() {
     # write shouldn't be able to change a previously parsed config
     my $config_clone = dclone($config);
-    return PVE::INotify::__write_etc_network_interfaces($config_clone);
+    return PVE::INotify::__write_etc_network_interfaces($config_clone, 1);
 }
 
 ##
diff --git a/test/etc_network_interfaces/t.bridge_eth_remove_auto.pl b/test/etc_network_interfaces/t.bridge_eth_remove_auto.pl
deleted file mode 100644
index 98f5df8..0000000
--- a/test/etc_network_interfaces/t.bridge_eth_remove_auto.pl
+++ /dev/null
@@ -1,24 +0,0 @@
-use strict;
-
-# access to the current config
-our $config;
-
-# replace proc_net_dev with one with a bunch of interfaces
-save('proc_net_dev', <<'/proc/net/dev');
-eth0:
-eth1:
-/proc/net/dev
-
-r('');
-update_iface('eth0', [], autostart => 1);
-update_iface('eth1', [], autostart => 1);
-r(w());
-die "autostart lost" if !$config->{ifaces}->{eth0}->{autostart};
-die "autostart lost" if !$config->{ifaces}->{eth1}->{autostart};
-new_iface("vmbr0", 'bridge', [{ family => 'inet' }], bridge_ports => 'eth0');
-new_iface("vmbr1", 'OVSBridge', [{ family => 'inet' }], ovs_ports => 'eth1');
-r(w());
-die "autostart wrongly removed for linux bridge port" if !$config->{ifaces}->{eth0}->{autostart};
-die "autostart not removed for ovs bridge port" if $config->{ifaces}->{eth1}->{autostart};
-
-1;
diff --git a/test/etc_network_interfaces/t.create_network.pl b/test/etc_network_interfaces/t.create_network.pl
index b8da513..6aad74c 100644
--- a/test/etc_network_interfaces/t.create_network.pl
+++ b/test/etc_network_interfaces/t.create_network.pl
@@ -420,7 +420,7 @@ auto eth1.100
 iface eth1.100 inet manual
 	mtu 1400
 
-allow-vmbr6 ovsintvlan
+auto ovsintvlan
 iface ovsintvlan inet manual
 	ovs_type OVSIntPort
 	ovs_bridge vmbr6
@@ -429,7 +429,7 @@ iface ovsintvlan inet manual
 
 $bond0_part
 
-allow-vmbr6 bond1
+auto bond1
 iface bond1 inet manual
 	ovs_bonds eth4 eth5
 	ovs_type OVSBond
@@ -464,7 +464,7 @@ iface vmbr5 inet manual
 	bridge-fd 0
 	mtu 1100
 
-allow-ovs vmbr6
+auto vmbr6
 iface vmbr6 inet manual
 	ovs_type OVSBridge
 	ovs_ports bond1 ovsintvlan
diff --git a/test/etc_network_interfaces/t.ovs_bridge_allow.pl b/test/etc_network_interfaces/t.ovs_bridge_allow.pl
index 9479ff5..742c9ef 100644
--- a/test/etc_network_interfaces/t.ovs_bridge_allow.pl
+++ b/test/etc_network_interfaces/t.ovs_bridge_allow.pl
@@ -37,7 +37,7 @@ iface eth2 inet manual
 
 iface eth3 inet manual
 
-allow-ovs vmbr0
+auto vmbr0
 iface vmbr0 inet static
 	address $ip
 	gateway $gw
@@ -52,19 +52,19 @@ expect load('loopback') . <<"/etc/network/interfaces";
 auto eth0
 iface eth0 inet manual
 
-allow-vmbr0 eth1
+auto eth1
 iface eth1 inet manual
 	ovs_type OVSPort
 	ovs_bridge vmbr0
 
-allow-vmbr0 eth2
+auto eth2
 iface eth2 inet manual
 	ovs_type OVSPort
 	ovs_bridge vmbr0
 
 iface eth3 inet manual
 
-allow-ovs vmbr0
+auto vmbr0
 iface vmbr0 inet static
 	address $ip
 	gateway $gw
@@ -89,7 +89,7 @@ expect load('loopback') . <<"/etc/network/interfaces";
 auto eth0
 iface eth0 inet manual
 
-allow-vmbr0 eth1
+auto eth1
 iface eth1 inet manual
 	ovs_type OVSPort
 	ovs_bridge vmbr0
@@ -98,7 +98,7 @@ iface eth3 inet manual
 
 iface eth2 inet manual
 
-allow-ovs vmbr0
+auto vmbr0
 iface vmbr0 inet static
 	address $ip
 	gateway $gw
-- 
2.39.2





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

* [pve-devel] [PATCH common 2/4] network parser: iterate deterministically
  2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 1/4] network tests: switch to ifupdown2 Fabian Grünbichler
@ 2023-12-21 15:30 ` Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 3/4] fix #5141: network parser: fix accidental RE result re-use Fabian Grünbichler
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fabian Grünbichler @ 2023-12-21 15:30 UTC (permalink / raw)
  To: pve-devel

makes the behaviour easier to analyze, and also helps when testing since it
allows constructing test cases that trigger certain order of parsing.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 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 bc33a8f..601e651 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1030,7 +1030,7 @@ sub __read_etc_network_interfaces {
 	};
     }
 
-    foreach my $iface (keys %$ifaces) {
+    foreach my $iface (sort keys %$ifaces) {
 	my $d = $ifaces->{$iface};
 	$d->{type} = 'unknown';
 	if ($iface =~ m/^bond\d+$/) {
-- 
2.39.2





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

* [pve-devel] [PATCH common 3/4] fix #5141: network parser: fix accidental RE result re-use
  2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 1/4] network tests: switch to ifupdown2 Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 2/4] network parser: iterate deterministically Fabian Grünbichler
@ 2023-12-21 15:30 ` Fabian Grünbichler
  2023-12-21 15:30 ` [pve-devel] [PATCH common 4/4] network tests: test #5141 Fabian Grünbichler
  2024-01-03 11:19 ` [pve-devel] applied: [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Wolfgang Bumiller
  4 siblings, 0 replies; 6+ messages in thread
From: Fabian Grünbichler @ 2023-12-21 15:30 UTC (permalink / raw)
  To: pve-devel

$1 and friends are not cleared if a RE fails to match, in which case they will
contain the captured values from a previous successful match in the same scope.

deduplicate the two branches to avoid accidental re-introduction.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 src/PVE/INotify.pm | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 601e651..6432295 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1073,16 +1073,27 @@ sub __read_etc_network_interfaces {
 		$ifaces->{$1}->{exists} = 0;
 		$d->{exists} = 0;
 	    }
-	} elsif ($iface =~ m/^(\S+)\.(\d+)$/ || $d->{'vlan-raw-device'}) {
+	} elsif ($iface =~ m/^(\S+)\.(\d+)$/) {
 	    $d->{type} = 'vlan';
 
 	    my ($dev, $id) = ($1, $2);
 	    $d->{'vlan-raw-device'} = $dev if defined($dev) && !$d->{'vlan-raw-device'};
+	    $d->{'vlan-id'} = $id if $id; # VLAN id 0 is not valid, so truthy check it is
 
-	    if (!$id && $iface =~ m/^vlan(\d+)$/) { # VLAN id 0 is not valid, so truthy check it is
-		$id = $1;
+	    my $raw_iface = $d->{'vlan-raw-device'};
+
+	    if (defined ($ifaces->{$raw_iface})) {
+		$d->{exists} = $ifaces->{$raw_iface}->{exists};
+	    } else {
+		$ifaces->{$raw_iface}->{exists} = 0;
+		$d->{exists} = 0;
+	    }
+	} elsif ($d->{'vlan-raw-device'}) {
+	    $d->{type} = 'vlan';
+
+	    if ($iface =~ m/^vlan(\d+)$/) {
+		$d->{'vlan-id'} = $1 if $1; # VLAN id 0 is not valid, so truthy check it is
 	    }
-	    $d->{'vlan-id'} = $id if $id;
 
 	    my $raw_iface = $d->{'vlan-raw-device'};
 
-- 
2.39.2





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

* [pve-devel] [PATCH common 4/4] network tests: test #5141
  2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
                   ` (2 preceding siblings ...)
  2023-12-21 15:30 ` [pve-devel] [PATCH common 3/4] fix #5141: network parser: fix accidental RE result re-use Fabian Grünbichler
@ 2023-12-21 15:30 ` Fabian Grünbichler
  2024-01-03 11:19 ` [pve-devel] applied: [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Wolfgang Bumiller
  4 siblings, 0 replies; 6+ messages in thread
From: Fabian Grünbichler @ 2023-12-21 15:30 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---

Notes:
    apply this before the fix to show problematic behaviour

 test/etc_network_interfaces/t.vlan-parsing.pl | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 test/etc_network_interfaces/t.vlan-parsing.pl

diff --git a/test/etc_network_interfaces/t.vlan-parsing.pl b/test/etc_network_interfaces/t.vlan-parsing.pl
new file mode 100644
index 0000000..6646683
--- /dev/null
+++ b/test/etc_network_interfaces/t.vlan-parsing.pl
@@ -0,0 +1,54 @@
+save('proc_net_dev', <<'/proc/net/dev');
+eth0:
+eth1:
+/proc/net/dev
+
+# Check for dropped or duplicated options
+
+my $ip = '192.168.0.2';
+my $nm = '255.255.255.0';
+my $gw = '192.168.0.1';
+my $ip6 = 'fc05::2';
+my $nm6 = '112';
+my $gw6 = 'fc05::1';
+
+# Load
+my $cfg = load('base') . <<"CHECK";
+iface eth1 inet manual
+
+auto vmbr0
+iface vmbr0 inet static
+	address 10.0.0.2/24
+	gateway 10.0.0.1
+	bridge-ports eth0
+	bridge-stp off
+	bridge-fd 0
+	bridge-vlan-aware yes
+	bridge-vids 2-4094
+
+auto vmbr0.10
+iface vmbr0.10 inet static
+
+auto vmbr0.20
+iface vmbr0.20 inet static
+
+auto vmbr0.30
+iface vmbr0.30 inet static
+
+auto vmbr0.40
+iface vmbr0.40 inet static
+
+auto vmbr0.100
+iface vmbr0.100 inet static
+
+auto zmgmt
+iface zmgmt inet static
+	vlan-id 1
+	vlan-raw-device vmbr0
+
+CHECK
+
+r $cfg;
+expect $cfg;
+
+1;
-- 
2.39.2





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

* [pve-devel] applied: [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices
  2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
                   ` (3 preceding siblings ...)
  2023-12-21 15:30 ` [pve-devel] [PATCH common 4/4] network tests: test #5141 Fabian Grünbichler
@ 2024-01-03 11:19 ` Wolfgang Bumiller
  4 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bumiller @ 2024-01-03 11:19 UTC (permalink / raw)
  To: Fabian Grünbichler; +Cc: pve-devel

applied series, thanks




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

end of thread, other threads:[~2024-01-03 11:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 15:30 [pve-devel] [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Fabian Grünbichler
2023-12-21 15:30 ` [pve-devel] [PATCH common 1/4] network tests: switch to ifupdown2 Fabian Grünbichler
2023-12-21 15:30 ` [pve-devel] [PATCH common 2/4] network parser: iterate deterministically Fabian Grünbichler
2023-12-21 15:30 ` [pve-devel] [PATCH common 3/4] fix #5141: network parser: fix accidental RE result re-use Fabian Grünbichler
2023-12-21 15:30 ` [pve-devel] [PATCH common 4/4] network tests: test #5141 Fabian Grünbichler
2024-01-03 11:19 ` [pve-devel] applied: [PATCH common 0/4] fix #5141: fix parsing of explicit vlan devices Wolfgang Bumiller

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