TC-FLOWER(8)
๐ TC-FLOWER(8) ๐
okay so bestie, this is the manual for tc-flower โ the flower filter in tc(8), on Linux. It's giving flow-based traffic control realness. Let's get into it. ๐ฆ
โจ NAME โจ
flower - flow based traffic control filter
๐ธ SYNOPSIS ๐ธ
tc filter ... flower [ MATCH_LIST ] [ action ACTION_SPEC ] [ classid
CLASSID ] [ hw_tc TCID ]
MATCH_LIST := [ MATCH_LIST ] MATCH
MATCH := { indev ifname | verbose | skip_sw | skip_hw | { dst_mac |
src_mac } MASKED_LLADDR | vlan_id VID | vlan_prio PRIORITY |
vlan_ethtype { ipv4 | ipv6 | ETH_TYPE } | cvlan_id VID |
cvlan_prio PRIORITY | cvlan_ethtype { ipv4 | ipv6 | ETH_TYPE } |
pppoe_sid PSID | ppp_proto { ip | ipv6 | mpls_uc | mpls_mc |
PPP_PROTO } | mpls LSE_LIST | mpls_label LABEL | mpls_tc TC |
mpls_bos BOS | mpls_ttl TTL | l2tpv3_sid LSID | ip_proto { tcp |
udp | sctp | icmp | icmpv6 | l2tp | IP_PROTO } | ip_tos
MASKED_IP_TOS | ip_ttl MASKED_IP_TTL | { dst_ip | src_ip }
PREFIX | { dst_port | src_port } { MASKED_NUMBER |
min_port_number-max_port_number } | tcp_flags MASKED_TCP_FLAGS |
type MASKED_TYPE | code MASKED_CODE | { arp_tip | arp_sip }
IPV4_PREFIX | arp_op { request | reply | OP } | { arp_tha |
arp_sha } MASKED_LLADDR | enc_key_id KEY-ID | { enc_dst_ip |
enc_src_ip } { ipv4_address | ipv6_address } | enc_dst_port
port_number | enc_tos TOS | enc_ttl TTL | { geneve_opts |
vxlan_opts | erspan_opts | gtp_opts | pfcp_opts } OPTIONS |
ip_flags IP_FLAGS | l2_miss L2_MISS | cfm CFM_OPTIONS |
enc_flags ENCFLAG-LIST }
LSE_LIST := [ LSE_LIST ] LSE
LSE := lse depth DEPTH { label LABEL | tc TC | bos BOS | ttl TTL }
CFM := cfm mdl LEVEL | op OPCODE
ENCFLAG-LIST := [ ENCFLAG-LIST/ ] ENCFLAG
ENCFLAG := { [no]tuncsum | [no]tundf | [no]tunoam | [no]tuncrit }
๐ DESCRIPTION ๐
The flower filter is out here matching flows to the set of keys you specified, and then it assigns an arbitrarily chosen class ID to packets that belong to them. And if that wasn't enough? Additionally (or alternatively, bestie, you can pick), an action from the generic action framework may be called. It's giving multi-purpose. ๐
๐ OPTIONS ๐
action ACTION_SPECโ slaps an action from the generic actions framework onto matching packets. Go off. โจclassid CLASSIDโ says which class matching packets get passed on to.CLASSIDis in the formX:Y, andXandYare interpreted as numbers in hexadecimal format. Periodt.hw_tc TCIDโ picks a hardware traffic class for matching packets to go to.TCIDis in the range 0 through 15. ๐indev ifnameโ matches on the incoming interface name. Obviously this only makes sense for forwarded flows.ifnameis the name of an interface that must exist at the time oftcinvocation. No fake friends. ๐verboseโ turns on verbose logging, including offloading errors when you're not using theskip_swflag. Spill the tea. ๐ซskip_swโ do not process the filter by software. If hardware has no offload support for this filter, or TC offload is not enabled for the interface, the operation will fail. It's giving all-or-nothing. ๐ญskip_hwโ do not process the filter by hardware. Simple as that. ๐dst_mac MASKED_LLADDRโ match on source or destination MAC address. A mask may optionally be provided to limit the bits of the address that are matched. You give the mask by following the address with a slash and then the mask. It may be inLLADDRformat, in which case it's a bitwise mask, or as a number of high bits to match. If the mask is missing, a match on all bits is assumed. ๐src_mac MASKED_LLADDRโ match on source or destination MAC address. Same mask rules asdst_mac, bestie: optional slash mask,LLADDRformat means bitwise mask, or a number of high bits. No mask = match all bits. ๐ฆnum_of_vlans NUMโ match on the number of vlan tags in the packet.NUMcan be0or a small positive integer. Typically in the 0-4 range. ๐vlan_id VIDโ match on vlan tag id.VIDis an unsigned 12bit value in decimal format. โจvlan_prio PRIORITYโ match on vlan tag priority.PRIORITYis an unsigned 3bit value in decimal format. ๐ธvlan_ethtype VLAN_ETH_TYPEโ match on layer three protocol.VLAN_ETH_TYPEmay be eitheripv4,ipv6, or an unsigned 16bit value in hexadecimal format. To match on a QinQ packet, it must be802.1Qor802.1AD. Not me knowing QinQ lore. ๐cvlan_id VIDโ match on QinQ inner vlan tag id.VIDis an unsigned 12bit value in decimal format. ๐cvlan_prio PRIORITYโ match on QinQ inner vlan tag priority.PRIORITYis an unsigned 3bit value in decimal format. ๐cvlan_ethtype VLAN_ETH_TYPEโ match on QinQ layer three protocol.VLAN_ETH_TYPEmay be eitheripv4,ipv6, or an unsigned 16bit value in hexadecimal format. โจpppoe_sid PSIDโ match on PPPoE session id.PSIDis an unsigned 16bit value in decimal format. ๐ฆppp_proto PPP_PROTOโ match on PPP layer three protocol.PPP_PROTOmay be eitherip,ipv6,mpls_uc,mpls_mc, or an unsigned 16bit value in hexadecimal format. ๐mpls LSE_LISTโ match on the MPLS label stack.LSE_LISTis a list of Label Stack Entries, each introduced by thelsekeyword. This option can't be used together with the standalonempls_label,mpls_tc,mpls_bos, andmpls_ttloptions. Choose your fighter. ๐lse LSE_OPTIONSโ match on an MPLS Label Stack Entry.LSE_OPTIONSis a list of options that describe the properties of the LSE to match. ๐depth DEPTHโ the depth of the Label Stack Entry to consider. Depth starts at 1 (the outermost Label Stack Entry). The maximum usable depth may be limited by the kernel. This option is mandatory.DEPTHis an unsigned 8 bit value in decimal format. ๐ซถlabel LABELโ match on the MPLS Label field at the specified depth.LABELis an unsigned 20 bit value in decimal format. ๐tc TCโ match on the MPLS Traffic Class field at the specified depth.TCis an unsigned 3 bit value in decimal format. โจbos BOSโ match on the MPLS Bottom Of Stack field at the specified depth.BOSis a 1 bit value in decimal format. ๐ttl TTLโ match on the MPLS Time To Live field at the specified depth.TTLis an unsigned 8 bit value in decimal format. ๐ธ
mpls_label LABELโ match the label id in the outermost MPLS label stack entry.LABELis an unsigned 20 bit value in decimal format. ๐mpls_tc TCโ match on the MPLS TC field, which is typically used for packet priority, in the outermost MPLS label stack entry.TCis an unsigned 3 bit value in decimal format. ๐ฅmpls_bos BOSโ match on the MPLS Bottom Of Stack field in the outermost MPLS label stack entry.BOSis a 1 bit value in decimal format. ๐mpls_ttl TTLโ match on the MPLS Time To Live field in the outermost MPLS label stack entry.TTLis an unsigned 8 bit value in decimal format. ๐ฆl2tpv3_sid LSIDโ match on L2TPv3 session id field transported over IPv4 or IPv6.LSIDis an unsigned 32 bit value in decimal format. ๐ip_proto IP_PROTOโ match on layer four protocol.IP_PROTOmay betcp,udp,sctp,icmp,icmpv6,l2tp, or an unsigned 8bit value in hexadecimal format. โจip_tos MASKED_IP_TOSโ match on ipv4 TOS or ipv6 traffic-class โ eight bits in hexadecimal format. A mask may optionally be provided to limit the bits which are matched. A mask is provided by following the value with a slash and then the mask. If the mask is missing, a match on all bits is assumed. ๐ip_ttl MASKED_IP_TTLโ match on ipv4 TTL or ipv6 hop-limit โ eight bits value in decimal or hexadecimal format. A mask may optionally be provided to limit the bits which are matched. Same logic is used for the mask as with matching onip_tos. ๐ซถdst_ip PREFIXโ match on source or destination IP address.PREFIXmust be a valid IPv4 or IPv6 address, depending on the protocol option totc filter, optionally followed by a slash and the prefix length. If the prefix is missing,tcassumes a full-length host match. ๐src_ip PREFIXโ match on source or destination IP address. Same rules asdst_ip, bestie: valid IPv4 or IPv6 address depending on the protocol option totc filter, optional slash and prefix length, and if the prefix is missing,tcassumes a full-length host match. ๐dst_port { MASKED_NUMBER | MIN_VALUE-MAX_VALUE }โ match on layer 4 protocol source or destination port number, with an optional mask. Alternatively, the minimum and maximum values can be specified to match on a range of layer 4 protocol source or destination port numbers. Only available forip_protovaluesudp,tcp, andsctp, which have to be specified in beforehand. No cap. ๐ฅsrc_port { MASKED_NUMBER | MIN_VALUE-MAX_VALUE }โ match on layer 4 protocol source or destination port number, with an optional mask. Alternatively, the minimum and maximum values can be specified to match on a range of layer 4 protocol source or destination port numbers. Only available forip_protovaluesudp,tcp, andsctp, which have to be specified in beforehand. ๐ธtcp_flags MASKED_TCP_FLAGSโ match on TCP flags represented as a 12bit bitfield in hexadecimal format. A mask may optionally be provided to limit the bits which are matched. A mask is provided by following the value with a slash and then the mask. If the mask is missing, a match on all bits is assumed. ๐type MASKED_TYPEโ match on ICMP type or code. A mask may optionally be provided to limit the bits of the address which are matched. A mask is provided by following the address with a slash and then the mask. The mask must be as a number which represents a bitwise mask. If the mask is missing, a match on all bits is assumed. Only available forip_protovaluesicmpandicmpv6, which have to be specified in beforehand. ๐code MASKED_CODEโ match on ICMP type or code. A mask may optionally be provided to limit the bits of the address which are matched. A mask is provided by following the address with a slash and then the mask. The mask must be as a number which represents a bitwise mask. If the mask is missing, a match on all bits is assumed. Only available forip_protovaluesicmpandicmpv6, which have to be specified in beforehand. ๐ญarp_tip IPV4_PREFIXโ match on ARP or RARP sender or target IP address.IPV4_PREFIXmust be a valid IPv4 address optionally followed by a slash and the prefix length. If the prefix is missing,tcassumes a full-length host match. ๐ซถarp_sip IPV4_PREFIXโ match on ARP or RARP sender or target IP address.IPV4_PREFIXmust be a valid IPv4 address optionally followed by a slash and the prefix length. If the prefix is missing,tcassumes a full-length host match. ๐arp_op ARP_OPโ match on ARP or RARP operation.ARP_OPmay berequest,reply, or an integer value0,1, or2. A mask may optionally be provided to limit the bits of the operation which are matched. A mask is provided by following the address with a slash and then the mask. It may be provided as an unsigned 8 bit value representing a bitwise mask. If the mask is missing, a match on all bits is assumed. Periodt. ๐arp_shaMASKED_LLADDRarp_thaMASKED_LLADDR โ match on the ARP or RARP sender or target MAC address, bestie ๐
So here's the tea on the mask: you can optionally slap a mask on there to limit which bits of the address get matched. How? Follow the address with a / and then the mask. The mask can come in LLADDR format โ in which case it's a bitwise mask โ or you can just give a number of high bits to match. And if you don't give a mask at all? Match on all bits, assumed, periodt.
enc_key_idNUMBERenc_dst_ipPREFIXenc_src_ipPREFIXenc_dst_portNUMBERenc_tosNUMBERenc_ttlNUMBERgeneve_optsOPTIONSvxlan_optsOPTIONSerspan_optsOPTIONSgtp_optsOPTIONSpfcp_optsOPTIONS โ all of these match on IP tunnel metadata โจ
Okay so the shared lore for that whole little squad above, because it's giving "one description, many flags":
- Key id NUMBER is a 32 bit tunnel key id (like, the VNI for a VXLAN tunnel, iykyk).
- PREFIX has to be a valid IPv4 or IPv6 address, optionally followed by a
/and the prefix length. If the prefix is missing,tcassumes a full-length host match. - Dst port NUMBER is a 16 bit UDP dst port.
- Tos NUMBER is an 8 bit tos (
dscp+ecn) value, and ttl NUMBER is an 8 bit time-to-live value.
Now the individual vibes, one by one ๐
geneve_optsOPTIONS โ has to be a valid list of comma-separated geneve options, where each option is a key optionally followed by a/and the corresponding mask. No mask?tcassumes a full-length match. You can describe the options in the formCLASS:TYPE:DATA/CLASS_MASK:TYPE_MASK:DATA_MASK, whereCLASSis a 16bit hexadecimal value,TYPEis an 8bit hexadecimal value, andDATAis a variable length hexadecimal value. ๐vxlan_optsOPTIONS โ does not support multiple options, bestie. It's one key followed by a/and the corresponding mask. No mask = full-length match assumed. The option goes in the formGBP/GBP_MASK, whereGBPis a 32bit number.erspan_optsOPTIONS โ also does not support multiple options, and again it's a key followed by a/and the corresponding mask. Mask missing โ full-length match. Form isVERSION:INDEX:DIR:HWID/VERSION:INDEX_MASK:DIR_MASK:HWID_MASK, whereVERSIONis an 8bit number,INDEXis an 32bit number, andDIRandHWIDare 8bit numbers. Multiple options is not supported. Also important:INDEX/INDEX_MASKgets used whenVERSIONis1, andDIR/DIR_MASKandHWID/HWID_MASKget used whenVERSIONis2. ๐gtp_optsOPTIONS โ does not support multiple options, and yes, it's a key followed by a/and corresponding mask, and yes, no mask means full-length match. The form isPDU_TYPE:QFI/PDU_TYPE_MASK:QFI_MASKwhere bothPDU_TYPEandQFIare 8bit hexadecimal values.pfcp_optsOPTIONS โ does not support multiple options. It's a key followed by a/and corresponding mask. If the mask is missing,tcassumes a full-length match. The option goesTYPE:SEID/TYPE_MASK:SEID_MASKwhereTYPEis an 8bit number andSEIDis represented by 64bit. BothTYPEandSEIDcome in hex. ๐ซถ
ct_stateCT_STATEct_zoneCT_MASKED_ZONEct_markCT_MASKED_MARKct_labelCT_MASKED_LABEL โ matches on connection tracking info ๐ฆ
CT_STATE
Match the connection state, and it can be a combination of [{+|-}flag] flags, where flag can be one of:
trkโ tracked connection.newโ new connection.estโ established connection.rplโ the packet is in the reply direction, meaning it's going the opposite way from the packet that initiated the connection.invโ the state is invalid. The packet couldn't be associated to a connection.relโ the packet is related to an existing connection.
Example: +trk+est โจ
CT_MASKED_ZONE
Match the connection zone, and yeah, it can be masked. ๐
CT_MASKED_MARK
32bit match on the connection mark, and it can be masked too.
CT_MASKED_LABEL
128bit match on the connection label, and yes bestie, maskable. ๐
ip_flagsIP_FLAGS โ IP_FLAGS can be eitherfrag,nofrag,firstfragornofirstfrag, wherefragandnofragget used to match on fragmented packets or not, respectively.firstfragandnofirstfragare here to further distinguish fragmented packets:firstfragflags the first fragmented packet, andnofirstfragflags subsequent fragmented packets or non-fragmented packets. ๐ฅl2_missL2_MISS โ match on layer 2 miss in the bridge driver's FDB / MDB. L2_MISS may be0or1. When1, match on packets that hit a layer 2 miss. When0, match on packets that were forwarded using an FDB / MDB entry. > Heads up: broadcast packets do not encounter a miss, because a lookup isn't performed for them. ๐cfmCFM_OPTIONS โ match on Connectivity Fault Management (CFM) fields. CFM_OPTIONS is a list of options describing the properties of the CFM information fields to match. ๐
mdl LEVEL
Match on the Maintenance Domain (MD) level field. LEVEL is an unsigned 3 bit value in decimal format.
op OPCODE
Match on the CFM opcode field. OPCODE is an unsigned 8 bit value in decimal format.
enc_flagsENCFLAG-LIST โ match on tunnel control flags. ENCFLAG-LIST is a list of these tunnel control flags:[no]tuncsum,[no]tundf,[no]tunoam,[no]tuncrit, each one separated by/. ๐ธ
๐ญ NOTES ๐ญ
So, like we said above wherever it applies: matches of a certain layer implicitly depend on the matches of the next lower layer. Precisely, bestie, here's the dependency chart of the group chat:
- Layer one and two matches (
indev,dst_mac,src_macandenc_flags) have no dependency. Free spirits. ๐ฆ - MPLS and layer three matches (
mpls,mpls_label,mpls_tc,mpls_bos,mpls_ttl,ip_proto,dst_ip,src_ip,arp_tip,arp_sip,arp_op,arp_tha,arp_shaandip_flags) depend on the protocol option oftc filter. - Layer four port matches (
dst_portandsrc_port) depend onip_protobeing set totcp,udporsctp. - And finally, ICMP matches (
codeandtype) depend onip_protobeing set toicmporicmpv6. ๐
Also, and this is the one, okay: there can be only one mask per one prio. If a user needs to specify a different mask, they have to use a different prio. No cap. ๐ญ
๐ SEE ALSO ๐
And that's the whole page, bestie, you ate it ๐ It's from iproute2, dated 22 Oct 2015, and the title is Flower filter in tc(8). Go forth and filter, main character ๐ซถโจ๐
๐ฆ where this page comes from
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- nixpkgs unstable: iproute2 7.2.0
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms