]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Network.pm
cleanup: regex match group reference
[pve-common.git] / src / PVE / Network.pm
index dd365051f4e8d17be4823520b09fe1201f36969e..56af2edae3382df2fcfd5a153448225294c8d34d 100644 (file)
@@ -11,11 +11,11 @@ use POSIX qw(ECONNREFUSED);
 
 use Net::IP;
 
-require "sys/ioctl.ph";
 use Socket qw(IPPROTO_IP);
 
 use constant IFF_UP => 1;
 use constant IFNAMSIZ => 16;
+use constant SIOCGIFFLAGS => 0x8913;
 
 # host network related utility functions
 
@@ -92,7 +92,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");
 
@@ -108,7 +108,7 @@ sub tap_rate_limit {
     my ($iface, $rate) = @_;
 
     my $debug = 0;
-    $rate = int($rate*1024*1024);
+    $rate = int($rate*1024*1024) if $rate;
     my $burst = 1024*1024;
 
     setup_tc_rate_limit($iface, $rate, $burst, $debug);
@@ -319,7 +319,7 @@ my $cleanup_firewall_bridge = sub {
 };
 
 sub tap_plug {
-    my ($iface, $bridge, $tag, $firewall, $trunks) = @_;
+    my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_;
 
     #cleanup old port config from any openvswitch bridge
     eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) };
@@ -352,6 +352,8 @@ sub tap_plug {
            &$ovs_bridge_add_port($bridge, $iface, $tag, undef, $trunks);
        }
     }
+
+    tap_rate_limit($iface, $rate);
 }
 
 sub tap_unplug {
@@ -537,13 +539,13 @@ sub get_active_interfaces {
     while(defined(my $line = <$fh>)) {
        next if $line !~ /^\s*([^:\s]+):/;
        my $ifname = $1;
-       my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $1, 0);
-       if (!defined(ioctl($sock, &SIOCGIFFLAGS, $ifreq))) {
+       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;