{"id":2773,"date":"2022-12-20T15:17:15","date_gmt":"2022-12-20T18:17:15","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/flow-filter-in-tc-man8\/"},"modified":"2022-12-20T15:17:15","modified_gmt":"2022-12-20T18:17:15","slug":"flow-filter-in-tc-man8","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/flow-filter-in-tc-man8\/","title":{"rendered":"Flow filter in tc (man8)"},"content":{"rendered":"<h1 align=\"center\">Flow filter in tc<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#OPTIONS\">OPTIONS<\/a><br \/> <a href=\"#KEYS\">KEYS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">flow \u2212 flow based traffic control filter<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Mapping mode:<\/p>\n<p style=\"margin-left:34%; margin-top: 1em\"><b>tc filter<\/b> &#8230; <b>flow map key<\/b> <i>KEY<\/i> [ <i>OPS<\/i> ] [ <i>OPTIONS<\/i> ]<\/p>\n<p style=\"margin-left:11%;\">Hashing mode:<\/p>\n<p style=\"margin-left:34%; margin-top: 1em\"><b>tc filter<\/b> &#8230; <b>flow hash keys<\/b> <i>KEY_LIST<\/i> [ <b>perturb<\/b> <i>secs<\/i> ] [ <i>OPTIONS<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>OPS<\/i> := [ <i>OPS<\/i> ] <i>OP<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>OPTIONS<\/i> := [ <b>divisor<\/b> <i>NUM<\/i> ] [ <b>baseclass<\/b> <i>ID<\/i> ] [ <b>match<\/b> <i>EMATCH_TREE<\/i> ] [ <b>action<\/b> <i>ACTION_SPEC<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>KEY_LIST<\/i> := [ <i>KEY_LIST<\/i> ] <i>KEY<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>OP<\/i> := { <b>or<\/b> | <b>and<\/b> | <b>xor<\/b> | <b>rshift<\/b> | <b>addend<\/b> } <i>NUM<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>ID<\/i> := <i>X<\/i>:<i>Y<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>KEY<\/i> := { <b>src<\/b> | <b>dst<\/b> | <b>proto<\/b> | <b>proto-src<\/b> | <b>proto-dst<\/b> | <b>iif<\/b> | <b>priority<\/b> | <b>mark<\/b> | <b>nfct<\/b> | <b>nfct-src<\/b> | <b>nfct-dst<\/b> | <b>nfct-proto-src<\/b> | <b>nfct-proto-dst<\/b> | <b>rt-classid<\/b> | <b>sk-uid<\/b> | <b>sk-gid<\/b> | <b>vlan-tag<\/b> | <b>rxhash<\/b> }<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>flow<\/b> classifier is meant to extend the <b>SFQ<\/b> hashing capabilities without hard-coding new hash functions. It also allows deterministic mappings of keys to classes.<\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>action<\/b> <i>ACTION_SPEC<\/i><\/p>\n<p style=\"margin-left:22%;\">Apply an action from the generic actions framework on matching packets.<\/p>\n<p style=\"margin-left:11%;\"><b>baseclass<\/b> <i>ID<\/i><\/p>\n<p style=\"margin-left:22%;\">An offset for the resulting class ID. <i>ID<\/i> may be <b>root<\/b>, <b>none<\/b> or a hexadecimal class ID in the form [<i>X<\/i><b>:<\/b>]<i>Y<\/i>. <i>X<\/i> must match qdisc\u2019s\/class\u2019s major handle (if omitted, the correct value is chosen automatically). If the whole <b>baseclass<\/b> is omitted, <i>Y<\/i> defaults to 1.<\/p>\n<p style=\"margin-left:11%;\"><b>divisor<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:22%;\">Number of buckets to use for sorting into. Keys are calculated modulo <i>NUM<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>hash keys<\/b> <i>KEY-LIST<\/i><\/p>\n<p style=\"margin-left:22%;\">Perform a <b>jhash2<\/b> operation over the keys in <i>KEY-LIST<\/i>, the result (modulo the <b>divisor<\/b> if given) is taken as class ID, optionally offset by the value of <b>baseclass<\/b>. It is possible to specify an interval (in seconds) after which <b>jhash2<\/b>\u2019s entropy source is recreated using the <b>perturb<\/b> parameter.<\/p>\n<p style=\"margin-left:11%;\"><b>map key<\/b> <i>KEY<\/i><\/p>\n<p style=\"margin-left:22%;\">Packet data identified by <i>KEY<\/i> is translated into class IDs to push the packet into. The value may be mangled by <i>OPS<\/i> before using it for the mapping. They are applied in the order listed here: <b><br \/> and<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:28%;\">Perform bitwise <b>AND<\/b> operation with numeric value <i>NUM<\/i>.<\/p>\n<p style=\"margin-left:22%;\"><b>or<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:28%;\">Perform bitwise <b>OR<\/b> operation with numeric value <i>NUM<\/i>.<\/p>\n<p style=\"margin-left:22%;\"><b>xor<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:28%;\">Perform bitwise <b>XOR<\/b> operation with numeric value <i>NUM<\/i>.<\/p>\n<p style=\"margin-left:22%;\"><b>rshift<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:28%;\">Shift the value of <i>KEY<\/i> to the right by <i>NUM<\/i> bits.<\/p>\n<p style=\"margin-left:22%;\"><b>addend<\/b> <i>NUM<\/i><\/p>\n<p style=\"margin-left:28%;\">Add <i>NUM<\/i> to the value of <i>KEY<\/i>.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">For the <b>or<\/b>, <b>and<\/b>, <b>xor<\/b> and <b>rshift<\/b> operations, <i>NUM<\/i> is assumed to be an unsigned, 32bit integer value. For the <b>addend<\/b> operation, <i>NUM<\/i> may be much more complex: It may be prefixed by a minus (\u2019-\u2019) sign to cause subtraction instead of addition and for keys of <b>src<\/b>, <b>dst<\/b>, <b>nfct-src<\/b> and <b>nfct-dst<\/b> it may be given in IP address notation. See below for an illustrating example.<\/p>\n<p style=\"margin-left:11%;\"><b>match<\/b> <i>EMATCH_TREE<\/i><\/p>\n<p style=\"margin-left:22%;\">Match packets using the extended match infrastructure. See <b>tc-ematch<\/b>(8) for a detailed description of the allowed syntax in <i>EMATCH_TREE<\/i>.<\/p>\n<h2>KEYS <a name=\"KEYS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">In mapping mode, a single key is used (after optional permutation) to build a class ID. The resulting ID is deducible in most cases. In hashing more, a number of keys may be specified which are then hashed and the output used as class ID. This ID is not deducible in beforehand, and may even change over time for a given flow if a <b>perturb<\/b> interval has been given.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The range of class IDs can be limited by the <b>divisor<\/b> option, which is used for a modulus. <b><br \/> src<\/b>, <b>dst<\/b><\/p>\n<p style=\"margin-left:22%;\">Use source or destination address as key. In case of IPv4 and TIPC, this is the actual address value. For IPv6, the 128bit address is folded into a 32bit value by XOR\u2019ing the four 32bit words. In all other cases, the kernel-internal socket address is used (after folding into 32bits on 64bit systems).<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>proto<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"64%\">\n<p>Use the layer four protocol number as key.<\/p>\n<\/td>\n<td width=\"14%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>proto-src<\/b><\/p>\n<p style=\"margin-left:22%;\">Use the layer four source port as key. If not available, the kernel-internal socket address is used instead.<\/p>\n<p style=\"margin-left:11%;\"><b>proto-dst<\/b><\/p>\n<p style=\"margin-left:22%;\">Use the layer four destination port as key. If not available, the associated kernel-internal dst_entry address is used after XOR\u2019ing with the packet\u2019s layer three protocol number.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"4%\">\n<p><b>iif<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"61%\">\n<p>Use the incoming interface index as key.<\/p>\n<\/td>\n<td width=\"17%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>priority<\/b><\/p>\n<p style=\"margin-left:22%;\">Use the packet\u2019s priority as key. Usually this is the IP header\u2019s DSCP\/ECN value.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"6%\">\n<p><b>mark<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"76%\">\n<p>Use the netfilter <b>fwmark<\/b> as key.<\/p>\n<\/td>\n<td width=\"2%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"6%\">\n<p><b>nfct<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"76%\">\n<p>Use the associated conntrack entry address as key.<\/p>\n<\/td>\n<td width=\"2%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>nfct-src<\/b>, <b>nfct-dst<\/b>, <b>nfct-proto-src<\/b>, <b>nfct-proto-dst<\/b><\/p>\n<p style=\"margin-left:22%;\">These are conntrack-aware variants of <b>src<\/b>, <b>dst<\/b>, <b>proto-src<\/b> and <b>proto-dst<\/b>. In case of NAT, these are basically the packet header\u2019s values before NAT was applied.<\/p>\n<p style=\"margin-left:11%;\"><b>rt-classid<\/b><\/p>\n<p style=\"margin-left:22%;\">Use the packet\u2019s destination routing table entry\u2019s realm as key.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>sk-uid<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>sk-gid<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>For locally generated packets, use the user or group ID the originating socket belongs to as key.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>vlan-tag<\/b><\/p>\n<p style=\"margin-left:22%;\">Use the packet\u2019s vlan ID as key.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>rxhash<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"38%\">\n<p>Use the flow hash as key.<\/p>\n<\/td>\n<td width=\"40%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Classic SFQ hash:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add &#8230; flow hash <\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>keys src,dst,proto,proto-src,proto-dst divisor 1024<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">Classic SFQ hash, but using information from conntrack to work properly <br \/> in combination with NAT:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add &#8230; flow hash <\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>keys nfct-src,nfct-dst,proto,nfct-proto-src,nfct-proto-dst <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>divisor 1024<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">Map destination IPs of 192.168.0.0\/24 to classids 1-256:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add &#8230; flow map <\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>key dst addend -192.168.0.0 divisor 256<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">Alternative to the above:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add &#8230; flow map <\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>key dst and 0xff<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">The same, but in reverse order:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add &#8230; flow map <\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"85%\">\n<p>key dst and 0xff xor 0xff<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>tc<\/b>(8), <b>tc-ematch<\/b>(8), <b>tc-sfq<\/b>(8)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  flow \u2212 flow based traffic control filter <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,52,4,127],"class_list":["post-2773","post","type-post","status-publish","format-standard","hentry","category-8-administracion-del-sistema","tag-5","tag-administracion","tag-man8","tag-tc-flow"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/2773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=2773"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/2773\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=2773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=2773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=2773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}