[pve-devel] [PATCH v3 pve-common 4/5] Inotify : add check vlan

Alexandre Derumier aderumier at odiso.com
Thu Jul 5 02:56:33 CEST 2018


verify than parent interface exist
verify than parent interface type is eth,bond,bridge
verify than parent bridge is vlan aware if type bridge
---
 src/PVE/INotify.pm                              | 19 ++++++++++++++++
 test/etc_network_interfaces/t.create_network.pl | 30 ++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index f4a5945..f0f3144 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1358,6 +1358,25 @@ sub __write_etc_network_interfaces {
 	}
     }
 
+    # check vlan
+    foreach my $iface (keys %$ifaces) {
+	my $d = $ifaces->{$iface};
+	if ($d->{type} eq 'vlan' && $iface =~ m/^(\S+)\.\d+$/) {
+	    my $p = $1;
+	    my $n = $ifaces->{$p};
+
+	    die "vlan '$iface' - unable to find parent '$p'\n"
+		if $n->{exists} eq 0;
+
+	    if ($n->{type} eq 'bridge' && !$n->{bridge_vlan_aware}) {
+		die "vlan '$iface' - bridge vlan aware is not enabled on parent '$p'\n";
+	    } elsif ($n->{type} ne 'eth' && $n->{type} ne 'bridge' && $n->{type} ne 'bond') {
+		die "vlan '$iface' - wrong interface type on parent '$p' " .
+		    "('$n->{type}' != 'eth|bond|bridge' )\n";
+	    }
+	}
+    }
+
     # check bridgeport option
     my $bridgeports = {};
     my $bridges = {};
diff --git a/test/etc_network_interfaces/t.create_network.pl b/test/etc_network_interfaces/t.create_network.pl
index da47999..fda7237 100644
--- a/test/etc_network_interfaces/t.create_network.pl
+++ b/test/etc_network_interfaces/t.create_network.pl
@@ -60,7 +60,6 @@ $config->{ifaces}->{vmbr1} = {
     autostart => 1
 };
 
-
 $config->{ifaces}->{vmbr2} = {
     type => 'bridge',
     method => 'manual',
@@ -116,6 +115,26 @@ $config->{ifaces}->{vxlan3} = {
     autostart => 1
 };
 
+$config->{ifaces}->{'vmbr1.100'} = {
+    type => 'vlan',
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
+
+$config->{ifaces}->{'bond0.100'} = {
+    type => 'vlan',
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
+
+$config->{ifaces}->{'eth1.100'} = {
+    type => 'vlan',
+    method => 'manual',
+    families => ['inet'],
+    autostart => 1
+};
 
 expect load('loopback') . <<"CHECK";
 source-directory interfaces.d
@@ -134,6 +153,9 @@ iface eth2 inet manual
 auto eth3
 iface eth3 inet manual
 
+auto eth1.100
+iface eth1.100 inet manual
+
 auto bond0
 iface bond0 inet manual
 	bond-slaves eth2 eth3
@@ -141,6 +163,9 @@ iface bond0 inet manual
 	bond-mode 802.3ad
 	bond-xmit-hash-policy layer3+4
 
+auto bond0.100
+iface bond0.100 inet manual
+
 auto vmbr0
 iface vmbr0 inet static
 	address  10.0.0.2
@@ -172,6 +197,9 @@ iface vmbr3 inet manual
 	bridge-vlan-aware yes
 	bridge-vids 2-10
 
+auto vmbr1.100
+iface vmbr1.100 inet manual
+
 auto vxlan1
 iface vxlan1 inet manual
 	vxlan-id 1
-- 
2.11.0




More information about the pve-devel mailing list