TC-CGROUP(8)

๐Ÿ’– CGROUP(8) โ€” Cgroup Classifier in tc(8) ๐Ÿ’–

โœจ NAME โœจ

okay so the manual name here is cgroup ๐ŸŽ€ and it's a control group based traffic control filter ๐Ÿ’…

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

tc filter ... cgroup [ match EMATCH_TREE ] [ action ACTION_SPEC ]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay bestie, this filter is basically a hint for tc ๐Ÿงš it tells tc to use the class ID of the net_cls control group that the process a packet came from belongs to, and to classify with that ๐Ÿ’œ it's giving targeted โœจ and obviously it only really matters for packets generated locally on the machine ๐Ÿ™ˆ

๐Ÿ“ OPTIONS ๐Ÿ“

  • action ACTION_SPEC โ€” slap an action from the generic actions framework onto packets that match ๐Ÿ”ฅ
  • match EMATCH_TREE โ€” match packets using the extended match infrastructure ๐Ÿ’… check out tc-ematch(8) for the full scoop on what syntax is allowed in EMATCH_TREE ๐Ÿซถ

๐Ÿงš EXAMPLES ๐Ÿงš

ngl this part is the main event ๐Ÿ˜ญ first you need a net_cls control group, and then you gotta give it a class and some process IDs. this makes a net_cls cgroup called "foobar" ๐ŸŽ€:

modprobe cls_cgroup
mkdir /sys/fs/cgroup/net_cls
mount -t cgroup -onet_cls net_cls /sys/fs/cgroup/net_cls
mkdir /sys/fs/cgroup/net_cls/foobar

next up, to give the cgroup a class ID you make a file called net_cls.classid that holds the class ID as a hexadecimal, 64bit wide number ๐ŸŒˆ the upper 32bits are for the major handle and the rest is the minor. so a class ID like ff:be gets written as 0xff00be (leading zeroes can be left off) โœจ continuing the example, this gives foobar class ID 1:2:

echo 0x10002 > /sys/fs/cgroup/net_cls/foobar/net_cls.classid

last step, toss some PIDs into the cgroup:

echo 1234 > /sys/fs/cgroup/net_cls/foobar/tasks
echo 5678 > /sys/fs/cgroup/net_cls/foobar/tasks

and that's it!! just attach a cgroup filter to a qdisc and packets from PIDs 1234 and 5678 get pushed into class 1:2 ๐Ÿ‘‘ iconic, periodt ๐Ÿ’€

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

tc(8), tc-ematch(8), and the file Documentation/cgroups/net_cls.txt of the Linux kernel tree ๐Ÿ“š


iproute2 ยท 21 Oct 2015 ยท Cgroup classifier in tc(8) ๐ŸŒˆ that's the source, version, and date for the receipts, bestie ๐Ÿ’œ love you, mean it ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from