]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/Network.pm
network : add tap_unplug
[pve-common.git] / data / PVE / Network.pm
index 4cc5fb8c11beafad3fb40a00261ec222895441bd..8f82686a8febf3c4493e1270403c1027fb76f75e 100644 (file)
@@ -52,6 +52,37 @@ sub tap_rate_limit {
     setup_tc_rate_limit($iface, $rate, $burst, $debug);
 }
 
     setup_tc_rate_limit($iface, $rate, $burst, $debug);
 }
 
+sub tap_create {
+    my ($iface, $bridge) = @_;
+
+    die "unable to get bridge setting\n" if !$bridge;
+
+    my $bridgemtu = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/mtu");
+       die "bridge '$bridge' does not exist\n" if !$bridgemtu;
+
+    eval{ PVE::Tools::run_command("/sbin/ifconfig $iface 0.0.0.0 promisc up mtu $bridgemtu");};
+       die "interface activation failed\n" if $@;
+}
+
+sub tap_plug {
+    my ($iface, $bridge, $tag) = @_;
+
+    my $newbridge = activate_bridge_vlan($bridge, $tag);
+    copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
+
+    system ("/usr/sbin/brctl addif $newbridge $iface") == 0 ||
+       die "can't add interface to bridge\n";
+}
+
+sub tap_unplug {
+    my ($iface, $bridge, $tag) = @_;
+
+    $bridge .= "v$tag" if $tag;
+
+    system ("/usr/sbin/brctl delif $bridge $iface") == 0 ||
+       die "can't del interface from bridge\n";
+}
+
 sub copy_bridge_config {
     my ($br0, $br1) = @_;
 
 sub copy_bridge_config {
     my ($br0, $br1) = @_;