TC flower¶
About TC flower filters¶
When compared with Ethtool ntuples filters ntuples, TC filters are applied higher in the Linux stack. Socket buffers have been assigned and provide a number of offsets that can help matching packets, which results in a number of additional filtering options that can be supported.
Some of them are supported by libkefir, in order to quickly generate rules from TC flower expressions.
Example¶
The following rule can be used to filter out incoming IPv4 HTTP packets:
# tc flower protocol ip flower ip_proto tcp dst_port 80 action drop
The same line, starting after tc flower, can be passed to the library to
create a new rule. In our example, it would be the following string:
protocol ip flower ip_proto tcp dst_port 80 action drop
So a call to the kefir_rule_load_l(), used to build rules from a string
containing the whole expression, would look like this:
if (kefir_rule_load_l(filter,
KEFIR_RULE_TYPE_TC_FLOWER,
"protocol ip flower ip_proto tcp dst_port 80 action drop",
0)) {
printf("Error: %s\n", kefir_strerror());
return -1;
}
Other example rules displaying the various supported options can be found in the tests for TC flower-based filters. For details on the syntax and the semantics of the different keywords in TC flower expressions, please refer to the tc-flower manual page.
Current support¶
Supported keywords:
dst_mac MASKED_LLADDRsrc_mac MASKED_LLADDRvlan_id VIDvlan_prio PRIORITYvlan_ethtype VLAN_ETH_TYPEcvlan_id VIDcvlan_prio PRIORITYcvlan_ethtype VLAN_ETH_TYPEip_proto IP_PROTOip_tos MASKED_IP_TOSip_ttl MASKED_IP_TTLdst_ip PREFIXsrc_ip PREFIXdst_port NUMBERsrc_port NUMBERaction ACTION_SPEC
Unsupported keywords:
mpls_label LABELmpls_tc TCmpls_bos BOSmpls_ttl TTLdst_port MIN_VALUE-MAX_VALUEsrc_port MIN_VALUE-MAX_VALUEtcp_flags MASKED_TCP_FLAGStype MASKED_TYPEcode MASKED_CODEarp_tip IPV4_PREFIXarp_sip IPV4_PREFIXarp_op ARP_OParp_sha MASKED_LLADDRarp_tha MASKED_LLADDRenc_key_id NUMBERenc_dst_ip PREFIXenc_src_ip PREFIXenc_dst_port NUMBERenc_tos NUMBERenc_ttl NUMBERgeneve_opts OPTIONSip_flags IP_FLAGS
Non-relevant keywords:
classid CLASSIDhw_tc TCIDindev ifnameverboseskip_swskip_hw