X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=data%2FPVE%2FNetwork.pm;h=e7521f7531c0b8edc65d39b7ef39bda703229653;hp=6b8af879f48a015b9791610efc93bd1fc9d26ef9;hb=ba4af65b3550c91782e2c1471f345d578aa4366b;hpb=fa49ab1a0875a89230378c99b4b6f9ccfa0edb6b diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm index 6b8af87..e7521f7 100644 --- a/data/PVE/Network.pm +++ b/data/PVE/Network.pm @@ -11,17 +11,21 @@ use File::Basename; 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; + run_command("/sbin/tc qdisc add dev $iface handle ffff: ingress"); - # virtio uses large packets 64K, so we need to set mtu to that - # value - else filter drops those packets and rate limit does not work. + # this does not work wit virtio - don't know why (setting "mtu 64kb" does not help) + #run_command("/sbin/tc filter add dev $iface parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate ${rate}bps burst ${burst}b drop flowid :1"); + # so we use avrate instead run_command("/sbin/tc filter add dev $iface parent ffff: " . - "protocol ip prio 50 u32 match ip src 0.0.0.0/0 " . - "police rate ${rate}bps burst ${burst}b " . - "mtu 64kb drop flowid :1"); + "protocol ip prio 50 estimator 1sec 8sec " . + "u32 match ip src 0.0.0.0/0 police avrate ${rate}bps drop flowid :1"); # tbf does not work for unknown reason #$TC qdisc add dev $DEV root tbf rate $RATE latency 100ms burst $BURST @@ -38,6 +42,46 @@ sub setup_tc_rate_limit { } } +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) = @_; @@ -45,7 +89,7 @@ sub copy_bridge_config { return if $br0 eq $br1; my $br_configs = [ 'ageing_time', 'stp_state', 'priority', 'forward_delay', - 'hello_time', 'max_age']; + 'hello_time', 'max_age', 'multicast_snooping', 'multicast_querier']; foreach my $sysname (@$br_configs) { eval { @@ -72,14 +116,28 @@ sub activate_bridge_vlan { 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