]> git.proxmox.com Git - pve-common.git/commitdiff
add openvswitch support to tap_plug / tap_unplug
authorAlexandre Derumier <aderumier@odiso.com>
Wed, 18 Dec 2013 14:13:11 +0000 (15:13 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 19 Dec 2013 11:43:03 +0000 (12:43 +0100)
Note: I force removal of openvswitch tap configuration at begin of tap_plug,
because openvswitch don't auto-delete tap config on tap interface deletion.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
data/PVE/Network.pm

index 1b755c0431dd8cf5f43ef5b581a4e05225a049ad..380b334af4dedac79f7e711e436d2473e016a3c5 100644 (file)
@@ -68,20 +68,36 @@ sub tap_create {
 sub tap_plug {
     my ($iface, $bridge, $tag) = @_;
 
-    my $newbridge = activate_bridge_vlan($bridge, $tag);
-    copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
-
-    system ("/sbin/brctl addif $newbridge $iface") == 0 ||
-       die "can't add interface to bridge\n";
+    #cleanup old port config from any openvswitch bridge
+    eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) };
+
+    if (-d "/sys/class/net/$bridge/bridge"){
+           my $newbridge = activate_bridge_vlan($bridge, $tag);
+           copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
+
+           system ("/sbin/brctl addif $newbridge $iface") == 0 ||
+               die "can't add interface to bridge\n";
+    }else{
+           my $cmd = "/usr/bin/ovs-vsctl add-port $bridge $iface";
+           $cmd .= " tag=$tag" if $tag;
+           system ($cmd) == 0 ||
+               die "can't add interface to bridge\n";
+    }
 }
 
 sub tap_unplug {
     my ($iface, $bridge, $tag) = @_;
 
-    $bridge .= "v$tag" if $tag;
+    if (-d "/sys/class/net/$bridge/bridge"){
 
-    system ("/sbin/brctl delif $bridge $iface") == 0 ||
-       die "can't del interface from bridge\n";
+       $bridge .= "v$tag" if $tag;
+
+           system ("/sbin/brctl delif $bridge $iface") == 0 ||
+               die "can't del interface from bridge\n";
+    }else{
+           system ("/usr/bin/ovs-vsctl del-port $iface") == 0 ||
+               die "can't del interface from bridge\n";
+    }
 }
 
 sub copy_bridge_config {