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");
};
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 {}) };
&$ovs_bridge_add_port($bridge, $iface, $tag, undef, $trunks);
}
}
+
+ tap_rate_limit($iface, $rate);
}
sub tap_unplug {
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;