How to assign packages using tc and cgroups

I am trying to prioritize packages that are generated from a specific group of processes so that they are selected first for transmission from a PC. I am trying to do this using groups and tc, but it does not seem to work.

First I set up the groups on ubuntu as follows,

modprobe cls_cgroup # load this module to get net_cls mkdir /sys/fs/cgroup/net_cls # mount point mount -t cgroup net_cls -onet_cls /sys/fs/cgroup/net_cls/ mkdir /sys/fs/cgroup/net_cls/foo # new cgroup echo 0x00010001 > /sys/fs/cgroup/foo/net_cls.classid # echo in a class id echo 2348 > /sys/fs/cgroup/net_cls/foo/tasks # echo in pid of firefox tc qdisc add dev eth0 root handle 1: pri tc qdisc add dev eth0 parent 1:1 handle 10: sfq tc qdisc add dev eth0 parent 1:2 handle 20: sfq tc qdisc add dev eth0 parent 1:3 handle 30: sfq 

and after viewing in firefox and starting up,

 tc -s qdisc ls dev eth0 

I get

 qdisc prio 1: root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 Sent 29351 bytes 154 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 qdisc sfq 10: parent 1:1 limit 127p quantum 1514b divisor 1024 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 qdisc sfq 20: parent 1:2 limit 127p quantum 1514b divisor 1024 Sent 27873 bytes 143 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 qdisc sfq 30: parent 1:3 limit 127p quantum 1514b divisor 1024 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 

Instead, I want the traffic to go in descriptor 10, what am I doing wrong?

+4
source share
2 answers

The right way to do this requires informing tc that you should use groups. This has been tested on Ubuntu 12.04 with a 3.10 kernel.

Make sure you have net_cls support

 $ cat /proc/cgroups #subsys_name hierarchy num_cgroups enabled cpuset 1 2 1 cpu 1 2 1 cpuacct 1 2 1 memory 1 2 1 net_cls 1 2 1 blkio 1 2 1 

if not,

Compile a kernel with net_cls support

Just put all of these options in your .config. They do not seem to exist in menuconfig.

 CONFIG_NET_CLS=y CONFIG_NET_CLS_BASIC=m CONFIG_NET_CLS_TCINDEX=m CONFIG_NET_CLS_ROUTE4=m CONFIG_NET_CLS_FW=m CONFIG_NET_CLS_U32=m CONFIG_NET_CLS_RSVP=m CONFIG_NET_CLS_RSVP6=m CONFIG_NET_CLS_FLOW=m CONFIG_NET_CLS_CGROUP=y CONFIG_NET_CLS_ACT=y CONFIG_NET_CLS_IND=y 

then run and install.

Make sure you have the / etc / fstab entry

 # echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab # reboot 

Create a test group and configure it

Some cgroup settings complain about common errors if cpuset is not installed. You must also convert your primary and minor class identifier tc to the hex code 0xAAAABBBB, where AAAA is primary and BBBB is negligible.

 # mkdir /sys/fs/cgroup/clstest # /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.mems # /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.cpus # /bin/echo 0x100001 > /sys/fs/cgroup/clstest/net_cls.classid 

Configure tc

 # tc qdisc add dev eth2 root handle 10: htb # tc class add dev eth2 parent 10: classid 10:1 htb rate 10mbit # tc filter add dev eth2 parent 10: protocol ip prio 10 handle 1: cgroup 

Group echo tasks

(but only one at a time)

 # echo $FIREFOX_PID > /sys/fs/cgroup/clstest/tasks 

Change tc class

 # tc class change dev eth2 parent 10: classid 10:1 htb rate 40mbit 

EDIT:

I could not complete this work with access. Only the output seems to work (upload). tc does not seem to accept the cgroup parameter with access.

+3
source

You must add a class and filter to the traffic that you want to control (suppose you want to control HTTP traffic).

 # tc class add dev eth0 parent 1:1 classid 1:1 htb rate 500mbit ceil 800mbit burst 10k prio 10 # tc filter add dev eth0 parent 1:1 protocol ip prio 10 u32 match ip dport 80 0xffff flowid 1:1 

Then you can use iptraf to check the connection speed.

+1
source

Source: https://habr.com/ru/post/1403832/


All Articles