[pve-devel] [PATCH pve-network 7/7] add get_bridge_vlan

Alexandre Derumier aderumier at odiso.com
Mon Feb 10 17:26:10 CET 2020


return correct bridge/vlan from sdn for tap/veth create/plug
---
 PVE/Network/SDN/Zones.pm            | 20 ++++++++++++++++++++
 PVE/Network/SDN/Zones/Plugin.pm     | 13 +++++++++++++
 PVE/Network/SDN/Zones/QinQPlugin.pm | 15 +++++++++++++++
 PVE/Network/SDN/Zones/VlanPlugin.pm | 14 ++++++++++++++
 4 files changed, 62 insertions(+)

diff --git a/PVE/Network/SDN/Zones.pm b/PVE/Network/SDN/Zones.pm
index e3d72e8..4a154f4 100644
--- a/PVE/Network/SDN/Zones.pm
+++ b/PVE/Network/SDN/Zones.pm
@@ -214,5 +214,25 @@ sub status {
     return($zone_status, $vnet_status);
 }
 
+sub get_bridge_vlan {
+    my ($vnetid) = @_;
+
+    my $vnet_cfg = PVE::Cluster::cfs_read_file('sdn/vnets.cfg');
+    my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
+    my $nodename = PVE::INotify::nodename();
+
+    my $vnet = $vnet_cfg->{ids}->{$vnetid};
+    return if !$vnet;
+
+    my $zoneid = $vnet->{zone};
+    my $tag = $vnet->{tag};
+
+    die "vnet $vnetid is not allowed on this node" if defined($zone_cfg->{ids}->{$zoneid}->{nodes}) && !$zone_cfg->{ids}->{$zoneid}->{nodes}->{$nodename};
+
+    my $plugin_config = $zone_cfg->{ids}->{$zoneid};
+    my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+    return $plugin->get_bridge_vlan($plugin_config, $zoneid, $vnetid, $tag);
+}
+
 1;
 
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 5aeff19..13a6e57 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -206,6 +206,19 @@ sub status {
     }
 }
 
+
+sub get_bridge_vlan {
+    my ($class, $plugin_config, $zoneid, $vnetid, $tag) = @_;
+
+    my $bridge = $plugin_config->{bridge};
+    die "bridge $bridge is missing" if !-d "/sys/class/net/$bridge/";
+
+    $bridge = $vnetid;
+    $tag = undef;
+
+    return ($bridge, $tag);
+}
+
 #helper
 
 sub get_uplink_iface {
diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/QinQPlugin.pm
index 28527b6..0557499 100644
--- a/PVE/Network/SDN/Zones/QinQPlugin.pm
+++ b/PVE/Network/SDN/Zones/QinQPlugin.pm
@@ -82,6 +82,21 @@ sub status {
     }
 }
 
+sub get_bridge_vlan {
+    my ($class, $plugin_config, $zoneid, $vnetid, $tag) = @_;
+
+    my $bridge = $plugin_config->{bridge};
+    die "bridge $bridge is missing" if !-d "/sys/class/net/$bridge/";
+
+    my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
+    my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
+
+    die "ovs $bridge is not supported by qinq" if $is_ovs;
+    die "bridge $bridge is not vlan aware" if !$vlan_aware;
+
+    return ($bridge, $tag);
+}
+
 1;
 
 
diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm
index b5f00ca..bc13e67 100644
--- a/PVE/Network/SDN/Zones/VlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VlanPlugin.pm
@@ -61,6 +61,20 @@ sub status {
     }
 }
 
+sub get_bridge_vlan {
+    my ($class, $plugin_config, $zoneid, $vnetid, $tag) = @_;
+
+    my $bridge = $plugin_config->{bridge};
+    die "bridge $bridge is missing" if !-d "/sys/class/net/$bridge/";
+
+    my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
+    my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
+
+    die "bridge $bridge is not vlan aware" if !$is_ovs && !$vlan_aware;
+
+    return ($bridge, $tag);
+}
+
 1;
 
 
-- 
2.20.1




More information about the pve-devel mailing list