[pve-devel] [PATCH pve-container] lxc: add sdn veth_create|plug

Alexandre Derumier aderumier at odiso.com
Mon Mar 9 10:24:30 CET 2020


---
 src/PVE/LXC.pm  | 21 ++++++++++++++++++---
 src/lxcnetaddbr | 16 +++++++++++++++-
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 21bc9c6..be11d34 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -33,6 +33,11 @@ use PVE::GuestHelpers;
 use PVE::LXC::Tools;
 
 use Time::HiRes qw (gettimeofday);
+my $have_sdn;
+eval {
+    require PVE::Network::SDN::Zones;
+    $have_sdn = 1;
+};
 
 my $LXC_CONFIG_PATH = '/usr/share/lxc/config';
 
@@ -933,7 +938,12 @@ sub update_net {
 		    PVE::LXC::Config->write_config($vmid, $conf);
 		}
 
-		PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+		if($have_sdn) {
+		    PVE::Network::SDN::Zones::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+		} else {
+		    PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+		}
+
 		# This includes the rate:
 		foreach (qw(bridge tag firewall rate)) {
 		    $oldnet->{$_} = $newnet->{$_} if $newnet->{$_};
@@ -961,8 +971,13 @@ sub hotplug_net {
     my $vethpeer = $veth . "p";
     my $eth = $newnet->{name};
 
-    PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
-    PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+    if($have_sdn) {
+	PVE::Network::SDN::Zones::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
+	PVE::Network::SDN::Zones::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+    } else {
+	PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
+	PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+    }
 
     # attach peer in container
     my $cmd = ['lxc-device', '-n', $vmid, 'add', $vethpeer, "$eth" ];
diff --git a/src/lxcnetaddbr b/src/lxcnetaddbr
index 5cb6b0b..ddc87f7 100755
--- a/src/lxcnetaddbr
+++ b/src/lxcnetaddbr
@@ -9,6 +9,11 @@ use PVE::LXC;
 use PVE::Tools qw(run_command);
 use PVE::Network;
 use PVE::ProcFSTools;
+my $have_sdn;
+eval {
+    require PVE::Network::SDN::Zones;
+    $have_sdn = 1;
+};
 
 die "got unexpected argument count\n" if scalar(@ARGV) != 5;
 
@@ -47,6 +52,10 @@ die "missing bridge configuration" if !$bridge;
 
 if (-d "/sys/class/net/$iface") {
 
+    if($have_sdn) {
+       ($bridge, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
+    } 
+
     my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
     die "bridge '$bridge' does not exist\n" if !$bridgemtu;
     #avoid insecure dependency;
@@ -54,7 +63,12 @@ if (-d "/sys/class/net/$iface") {
 
     PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu");
     PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface");
-    PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate);
+
+    if($have_sdn) {
+	PVE::Network::SDN::Zones::tap_plug($iface, $net->{bridge}, $tag, $firewall, $trunks, $rate);
+    } else {
+	PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate);
+    }
 }
 
 exit 0;
-- 
2.20.1




More information about the pve-devel mailing list