TC-FLOW(8)
๐ Flow filter in tc(8) ๐
Okay bestie, this is the manual page for the flow filter from tc(8), the traffic control tool. We're going through the whole thing so you can see how it works. ๐ฆ
โจ NAME โจ
flow is a flow based traffic control filter. It's lowkey iconic. ๐
๐ SYNOPSIS ๐
Mapping mode:
tc filter ... flow map key KEY [ OPS ] [ OPTIONS ]
Hashing mode:
tc filter ... flow hash keys KEY_LIST [ perturb secs ] [ OPTIONS
]
OPS := [ OPS ] OP
OPTIONS := [ divisor NUM ] [ baseclass ID ] [ match EMATCH_TREE ] [
action ACTION_SPEC ]
KEY_LIST := [ KEY_LIST ] KEY
OP := { or | and | xor | rshift | addend } NUM
ID := X:Y
KEY := { src | dst | proto | proto-src | proto-dst | iif | priority |
mark | nfct | nfct-src | nfct-dst | nfct-proto-src | nfct-proto-
dst | rt-classid | sk-uid | sk-gid | vlan-tag | rxhash }
๐ธ DESCRIPTION ๐ธ
Okay so the flow classifier is meant to level up the SFQ hashing capabilities without hard-coding brand new hash functions. โจ It also lets you do deterministic mappings of keys to classes, which is so satisfying. ๐ซถ
๐ OPTIONS ๐
action ACTION_SPECโ Slap an action from the generic actions framework onto matching packets. ๐baseclass IDโ An offset for the resulting class ID.IDcan beroot,none, or a hexadecimal class ID in the form[X:]Y. TheXhas to match the qdisc's or class's major handle, but if you leave it out, the right value gets picked automatically. If you skip the whole baseclass,Ydefaults to1. ๐งdivisor NUMโ The number of buckets to sort into. Keys get calculated moduloNUM. ๐hash keys KEY-LISTโ Runs a jhash2 operation over the keys inKEY-LIST. The result (modulo the divisor, if you gave one) becomes the class ID, optionally offset bybaseclass. You can also set an interval in seconds after which jhash2's entropy source gets recreated, using theperturbparameter. โฐmap key KEYโ Packet data identified byKEYgets translated into class IDs to push the packet into. The value can be mangled byOPSbefore it's used for the mapping. They get applied in the order listed here:and NUMโ Bitwise AND with the numeric valueNUM. ๐ฅor NUMโ Bitwise OR with the numeric valueNUM. ๐ฅxor NUMโ Bitwise XOR with the numeric valueNUM. ๐ฅrshift NUMโ Shifts the value ofKEYto the right byNUMbits. ๐addend NUMโ AddsNUMto the value ofKEY. โจ
For the or, and, xor, and rshift operations, NUM is assumed to be an unsigned, 32bit integer value. For addend, NUM can get much more complex: it can be prefixed with a minus (-) sign to subtract instead of add, and for the keys src, dst, nfct-src, and nfct-dst it can be written in IP address notation. There's an illustrating example down below in EXAMPLES. ๐
match EMATCH_TREEโ Matches packets using the extended match infrastructure. Check outtc-ematch(8)for the full scoop on the allowed syntax inEMATCH_TREE. ๐ฆ
๐ KEYS ๐
In mapping mode, a single key gets used (after an optional permutation) to build a class ID. The resulting ID is deducible in most cases. In hashing mode, you can specify a bunch of keys, which then get hashed together and the output is used as the class ID. That ID is not deducible beforehand, and it may even change over time for a given flow if you gave a perturb interval. ๐ฎ
The range of class IDs can be limited by the divisor option, which is used as a modulus. ๐งฎ
src,dstโ Uses the source or destination address as the key. For IPv4 and TIPC, this is the actual address value. For IPv6, the 128bit address gets folded into a 32bit value by XOR'ing the four 32bit words together. In all other cases, the kernel-internal socket address is used (after folding into 32bits on 64bit systems). ๐protoโ Uses the layer four protocol number as the key. ๐งproto-srcโ Uses the layer four source port as the key. If it's not available, the kernel-internal socket address gets used instead. ๐ชproto-dstโ Uses the layer four destination port as the key. If that's not available, the associated kernel-internal dst_entry address gets used after XOR'ing with the packet's layer three protocol number. ๐ชiifโ Uses the incoming interface index as the key. ๐ฃ๏ธpriorityโ Uses the packet's priority as the key. Usually this is the IP header's DSCP/ECN value. ๐โโ๏ธmarkโ Uses the netfilter fwmark as the key. ๐ท๏ธnfctโ Uses the associated conntrack entry address as the key. ๐ธ๏ธnfct-src,nfct-dst,nfct-proto-src,nfct-proto-dstโ These are the conntrack-aware versions ofsrc,dst,proto-src, andproto-dst. With NAT, these are basically the packet header's values from before NAT was applied. ๐ต๏ธโโ๏ธrt-classidโ Uses the realm of the packet's destination routing table entry as the key. ๐บ๏ธsk-uid,sk-gidโ For locally generated packets, uses the user or group ID of the originating socket as the key. ๐vlan-tagโ Uses the packet's vlan ID as the key. ๐rxhashโ Uses the flow hash as the key. ๐
๐ EXAMPLES ๐
Classic SFQ hash:
tc filter add ... flow hash \
keys src,dst,proto,proto-src,proto-dst divisor 1024
Classic SFQ hash, but using information from conntrack so it works properly in combination with NAT:
tc filter add ... flow hash \
keys nfct-src,nfct-dst,proto,nfct-proto-src,nfct-proto-dst \
divisor 1024
Map destination IPs of 192.168.0.0/24 to classids 1-256:
tc filter add ... flow map \
key dst addend -192.168.0.0 divisor 256
Alternative to the above:
tc filter add ... flow map \
key dst and 0xff
The same, but in reverse order:
tc filter add ... flow map \
key dst and 0xff xor 0xff
๐ฆ SEE ALSO ๐ฆ
tc(8), tc-ematch(8), tc-sfq(8)
That's a wrap, bestie! ๐ซถ This page came from iproute2, dated 20 Oct 2015, and it's giving "Flow filter in tc(8)" forever. ๐ โจ
๐ฆ where this page comes from
- alpine 3.22: iproute2-doc 6.15.0-r0 ยท GPL-2.0-or-later
- alpine 3.23: iproute2-doc 6.17.0-r0 ยท GPL-2.0-or-later
- alpine 3.24: iproute2-doc 7.0.0-r0 ยท GPL-2.0-or-later
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- centos-stream 10: iproute-tc 7.0.0-2.el10 ยท GPL-2.0-or-later
- centos-stream 9: iproute-tc 6.17.0-3.el9 ยท GPL-2.0-or-later
- debian bookworm: iproute2 6.1.0-3 ยท GPL-2.0-only
- debian trixie: iproute2 6.15.0-1 ยท GPL-2.0-only
- fedora 43: iproute-tc 6.14.0-2.fc43 ยท GPL-2.0-or-later
- fedora 44: iproute-tc 6.17.0-2.fc44 ยท GPL-2.0-or-later
- nixos 26.05: iproute2 7.0.0
- nixpkgs unstable: iproute2 7.2.0
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- ubuntu jammy: iproute2 5.15.0-1ubuntu2 ยท GPL-2.0-only
- ubuntu jammy: iproute2 5.15.0-1ubuntu2.2 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6.4 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2
- ubuntu questing: iproute2 6.16.0-1ubuntu2.1 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2.2
- ubuntu resolute: iproute2 6.19.0-1ubuntu1 ยท GPL-2.0-only
- ubuntu resolute: iproute2 6.19.0-1ubuntu1.1 ยท GPL-2.0-only
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms