sub setup_tc_rate_limit {
my ($iface, $rate, $burst, $debug) = @_;
- system("/sbin/tc qdisc del dev $iface ingres >/dev/null 2>&1");
+ system("/sbin/tc class del dev $iface parent 1: classid 1:1 >/dev/null 2>&1");
+ system("/sbin/tc filter del dev $iface parent ffff: protocol ip prio 50 estimator 1sec 8sec >/dev/null 2>&1");
+ system("/sbin/tc qdisc del dev $iface ingress >/dev/null 2>&1");
system("/sbin/tc qdisc del dev $iface root >/dev/null 2>&1");
+ return if (!$rate || ($rate && $rate == 0));
+
run_command("/sbin/tc qdisc add dev $iface handle ffff: ingress");
# this does not work wit virtio - don't know why (setting "mtu 64kb" does not help)
}
}
+sub tap_rate_limit {
+ my ($iface, $rate) = @_;
+
+ my $debug = 0;
+ $rate = int($rate*1024*1024);
+ my $burst = 1024*1024;
+
+ 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) = @_;
die "got strange vlan tag '$tag_param'\n" if $tag < 1 || $tag > 4094;
my $bridgevlan = "${bridge}v$tag";
- my $iface = $bridge;
+
+ my $dir = "/sys/class/net/$bridge/brif";
+
+ #check if we have an only one ethX or bondX interface in the bridge
+
+ my $iface;
+ PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+)', sub {
+ my ($slave) = @_;
+
+ die "more then one physical interfaces on bridge '$bridge'\n" if $iface;
+ $iface = $slave;
+
+ });
+
+ die "no physical interface on bridge '$bridge'\n" if !$iface;
+
my $ifacevlan = "${iface}.$tag";
- my $vlanflags = "reorder_hdr on gvrp on";
# create vlan on $iface is not already exist
if (! -d "/sys/class/net/$ifacevlan") {
- system("/sbin/ip link add link $iface name $ifacevlan type vlan id $tag $vlanflags") == 0 ||
- die "can't add vlan tag $tag to interface $iface\n";
+ system("/sbin/vconfig add $iface $tag") == 0 ||
+ die "can't add vlan tag $tag to interface $iface\n";
}
# be sure to have the $ifacevlan up