From: Alexandre Derumier Date: Wed, 18 Dec 2013 14:13:11 +0000 (+0100) Subject: add openvswitch support to tap_plug / tap_unplug X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=4cbabd40a7db4f810c3383b13555e9502a0b9382;hp=f0a10afc25d71c4f5e88fb559c94c17f0fb21961 add openvswitch support to tap_plug / tap_unplug 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 --- diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm index 1b755c0..380b334 100644 --- a/data/PVE/Network.pm +++ b/data/PVE/Network.pm @@ -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 {