X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FNetwork.pm;h=0a984ad32f9e51bc0ab145c073253991edb5dcf1;hp=2d6781a4eb1c4aaa0bd4c9ce9b99260b36f2a252;hb=899f8c4aa54c59f01c7fa3c516a465b438edc172;hpb=bce2a5b34cf50c4139c6112633cdbcbc0b913d33 diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm index 2d6781a..0a984ad 100644 --- a/src/PVE/Network.pm +++ b/src/PVE/Network.pm @@ -76,10 +76,11 @@ our $ipv4_mask_hash_localnet = { sub setup_tc_rate_limit { my ($iface, $rate, $burst, $debug) = @_; - 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 all pref 50 u32 >/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"); + # these are allowed / expected to fail, e.g. when there is no previous rate limit to remove + eval { run_command("/sbin/tc class del dev $iface parent 1: classid 1:1 >/dev/null 2>&1"); }; + eval { run_command("/sbin/tc filter del dev $iface parent ffff: protocol all pref 50 u32 >/dev/null 2>&1"); }; + eval { run_command("/sbin/tc qdisc del dev $iface ingress >/dev/null 2>&1"); }; + eval { run_command("/sbin/tc qdisc del dev $iface root >/dev/null 2>&1"); }; return if !$rate; @@ -92,7 +93,7 @@ sub setup_tc_rate_limit { run_command("/sbin/tc qdisc add dev $iface handle ffff: ingress"); run_command("/sbin/tc filter add dev $iface parent ffff: " . - "protocol all prio 50 u32 match u32 0 0 " . + "prio 50 basic " . "police rate ${rate}bps burst ${burst}b mtu 64kb " . "drop flowid :1"); @@ -371,6 +372,8 @@ sub tap_unplug { } &$cleanup_firewall_bridge($iface); + #cleanup old port config from any openvswitch bridge + eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) }; } sub copy_bridge_config { @@ -437,7 +440,7 @@ sub activate_bridge_vlan { my @ifaces = (); my $dir = "/sys/class/net/$bridge/brif"; - PVE::Tools::dir_glob_foreach($dir, '((eth|bond)\d+(\.\d+)?)', sub { + PVE::Tools::dir_glob_foreach($dir, '(((eth|bond)\d+|en[^.]+)(\.\d+)?)', sub { push @ifaces, $_[0]; }); @@ -532,20 +535,22 @@ sub get_active_interfaces { open my $fh, '<', '/proc/net/dev' or die "failed to open /proc/net/dev: $!\n"; # And filter by IFF_UP flag fetched via a PF_INET6 socket ioctl: - socket my $sock, PF_INET6, SOCK_DGRAM, &IPPROTO_IP - or die "failed to open socket\n"; + my $sock; + socket($sock, PF_INET6, SOCK_DGRAM, &IPPROTO_IP) + or socket($sock, PF_INET, SOCK_DGRAM, &IPPROTO_IP) + or return []; my $ifaces = []; while(defined(my $line = <$fh>)) { next if $line !~ /^\s*([^:\s]+):/; my $ifname = $1; - my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $1, 0); + my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifname, 0); if (!defined(ioctl($sock, SIOCGIFFLAGS, $ifreq))) { warn "failed to get interface flags for: $ifname\n"; next; } my ($name, $flags) = unpack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifreq); - push @$ifaces, $1 if ($flags & IFF_UP); + push @$ifaces, $ifname if ($flags & IFF_UP); } close $fh; close $sock;