How to police ingress (input) packets belonging to a cgroup with iptables and tc?
1
vote
1
answer
732
views
I am trying to limit the download (ingress) rate for a certain app within a cgroup.
I was able to limit the upload (egress) rate successfully by marking app's OUTPUT packets in iptables and then set a tc filter to handle that marked packets.
However, when I did the same steps for ingress it didn't work.
------------------
steps I followed to limit **upload**:
1. Mark OUTPUT packets by their cgroup
$ sudo iptables -I OUTPUT -t mangle -m cgroup --path '/user.slice/.../app-firefox-...scope'\
-j MARK --set-mark 11
2. filter by fw mark (11) on the root qdisc
$ tc qdisc add dev $IFACE root handle 1: htb default 1
$ tc filter add dev $IFACE parent 1: protocol ip prio 1 handle 11 fw \
action police rate 1000kbit burst 10k drop
This limited the upload rate for firefox to 1000kbit successfully.
--------------
steps I followed trying to limit **download**:
1. Mark INPUT packets by their cgroup
$ sudo iptables -I INPUT -t mangle -m cgroup --path '/user.slice/.../app-firefox-...scope'\
-j MARK --set-mark 22
2. filter by fw mark (22) on the ingress qdisc
$ tc qdisc add dev $IFACE ingress handle ffff:
$ tc filter add dev $IFACE parent ffff: protocol ip prio 1 handle 22 fw \
action police rate 1000kbit burst 10k drop
-------
I am able to block app's download successfully with iptables:
$ sudo iptables -I INPUT -t mangle -m cgroup --path '/user.slice/.../app-firefox-....scope' -j DROP
So it seems like iptables is marking cgroup's input packets but for some reason, tc can't filter them or maybe the packets are being consumed before tc filter takes effect? if so, then what is the use of marking input packets?
If there is a way to block cgroup's input packets then there must be a way to limit them, right?
Asked by user216385
(63 rep)
Apr 29, 2023, 05:32 AM
Last activity: Apr 29, 2023, 11:47 PM
Last activity: Apr 29, 2023, 11:47 PM