{"id":3448,"date":"2022-12-20T17:02:42","date_gmt":"2022-12-20T20:02:42","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/generic-packet-editor-action-in-tc-man8\/"},"modified":"2022-12-20T17:02:42","modified_gmt":"2022-12-20T20:02:42","slug":"generic-packet-editor-action-in-tc-man8","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/generic-packet-editor-action-in-tc-man8\/","title":{"rendered":"Generic packet editor action in tc (man8)"},"content":{"rendered":"<h1 align=\"center\">Generic packet editor action 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=\"#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\">pedit &#8211; generic packet editor action<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:23%; margin-top: 1em\"><b>tc<\/b> &#8230; <b>action pedit [ex] munge<\/b> { <i>RAW_OP<\/i> | <i>LAYERED_OP<\/i> | <i>EXTENDED_LAYERED_OP<\/i> } [ <i>CONTROL<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>RAW_OP<\/i> := <b>offset<\/b> <i>OFFSET<\/i> { <b>u8<\/b> | <b>u16<\/b> | <b>u32<\/b> } [ <i>AT_SPEC<\/i> ] <i>CMD_SPEC<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>AT_SPEC<\/i> := <b>at<\/b> <i>AT<\/i> <b>offmask<\/b> <i>MASK<\/i> <b>shift<\/b> <i>SHIFT<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>LAYERED_OP<\/i> := { <b>ip<\/b> <i>IPHDR_FIELD<\/i> | <b>ip<\/b> <i>BEYOND_IPHDR_FIELD<\/i> } <i>CMD_SPEC<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>EXTENDED_LAYERED_OP<\/i> := { <b>eth<\/b> <i>ETHHDR_FIELD<\/i> | <b>ip<\/b> <i>IPHDR_FIELD<\/i> | <b>ip<\/b> <i>EX_IPHDR_FIELD<\/i> | <b>ip6<\/b> <i>IP6HDR_FIELD<\/i> | <b>tcp<\/b> <i>TCPHDR_FIELD<\/i> | <b>udp<\/b> <i>UDPHDR_FIELD<\/i> } <i>CMD_SPEC<\/i><\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>ETHHDR_FIELD<\/i> := { <b>src<\/b> | <b>dst<\/b> | <b>type<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>IPHDR_FIELD<\/i> := { <b>src<\/b> | <b>dst<\/b> | <b>tos<\/b> | <b>dsfield<\/b> | <b>ihl<\/b> | <b>protocol<\/b> | <b>precedence<\/b> | <b>nofrag<\/b> | <b>firstfrag<\/b> | <b>ce<\/b> | <b>df<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>BEYOND_IPHDR_FIELD<\/i> := { <b>dport<\/b> | <b>sport<\/b> | <b>icmp_type<\/b> | <b>icmp_code<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>EX_IPHDR_FIELD<\/i> := { <b>ttl<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>IP6HDR_FIELD<\/i> := { <b>src<\/b> | <b>dst<\/b> | <b>traffic_class<\/b> | <b>flow_lbl<\/b> | <b>payload_len<\/b> | <b>nexthdr<\/b> | <b>hoplimit<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>TCPHDR_FIELD<\/i> := { <b>sport<\/b> | <b>dport<\/b> | <b>flags<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>UDPHDR_FIELD<\/i> := { <b>sport<\/b> | <b>dport<\/b> }<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>CMD_SPEC<\/i> := { <b>clear<\/b> | <b>invert<\/b> | <b>set<\/b> <i>VAL<\/i> | <b>add<\/b> <i>VAL<\/i> | <b>decrement<\/b> | <b>preserve<\/b> } [ <b>retain<\/b> <i>RVAL<\/i> ]<\/p>\n<p style=\"margin-left:23%; margin-top: 1em\"><i>CONTROL<\/i> := { <b>reclassify<\/b> | <b>pipe<\/b> | <b>drop<\/b> | <b>shot<\/b> | <b>continue<\/b> | <b>pass<\/b> | <b>goto chain CHAIN_INDEX<\/b> }<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>pedit<\/b> action can be used to change arbitrary packet data. The location of data to change can either be specified by giving an offset and size as in <i>RAW_OP<\/i>, or for header values by naming the header and field to edit the size is then chosen automatically based on the header field size.<\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\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=\"3%\">\n<p style=\"margin-top: 1em\"><b>ex<\/b><\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">Use extended pedit. <i>EXTENDED_LAYERED_OP<\/i> and the add\/decrement <i>CMD_SPEC<\/i> are allowed only in this mode.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>offset<\/b> <i>OFFSET<\/i> { <b>u32<\/b> | <b>u16<\/b> | <b>u8<\/b> }<\/p>\n<p style=\"margin-left:22%;\">Specify the offset at which to change data. <i>OFFSET<\/i> is a signed integer, it\u2019s base is automatically chosen (e.g. hex if prefixed by <b>0x<\/b> or octal if prefixed by <b>0<\/b>). The second argument specifies the length of data to change, that is four bytes (<b>u32<\/b>), two bytes (<b>u16<\/b>) or a single byte (<b>u8<\/b>).<\/p>\n<p style=\"margin-left:11%;\"><b>at<\/b> <i>AT<\/i> <b>offmask<\/b> <i>MASK<\/i> <b>shift<\/b> <i>SHIFT<\/i><\/p>\n<p style=\"margin-left:22%;\">This is an optional part of <i>RAW_OP<\/i> which allows to have a variable <i>OFFSET<\/i> depending on packet data at offset <i>AT<\/i>, which is binary ANDed with <i>MASK<\/i> and right-shifted by <i>SHIFT<\/i> before adding it to <i>OFFSET<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>eth<\/b> <i>ETHHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">Change an ETH header field. The supported keywords for <i>ETHHDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>src<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>dst<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\">\n<p>Source or destination MAC address in the standard format: XX:XX:XX:XX:XX:XX<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>type<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\">\n<p>Ether-type in numeric value<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ip<\/b> <i>IPHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">Change an IPv4 header field. The supported keywords for <i>IPHDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>src<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>dst<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"68%\">\n<p>Source or destination IP address, a four-byte value.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>tos<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>dsfield <br \/> precedence<\/b><\/p>\n<p style=\"margin-left:32%;\">Type Of Service field, an eight-bit 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=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>ihl<\/b><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"68%\">\n<p>Change the IP Header Length field, a four-bit value.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>protocol<\/b><\/p>\n<p style=\"margin-left:32%;\">Next-layer Protocol field, an eight-bit 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=\"22%\"><\/td>\n<td width=\"9%\">\n<p><b>nofrag<\/b><\/p>\n<\/td>\n<td width=\"69%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>firstfrag<\/b><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p><b>ce<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p><b>df<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p><b>mf<\/b><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"68%\">\n<p>Change IP header flags. Note that the value to pass to the <b>set<\/b> command is not just a bit value, but the full byte including the flags field. Though only the relevant bits of that value are respected, the rest ignored.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ip<\/b> <i>BEYOND_IPHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">Supported only for non-extended layered op. It is passed to the kernel as offsets relative to the beginning of the IP header and assumes the IP header is of minimum size (20 bytes). The supported keywords for <i>BEYOND_IPHDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"7%\">\n<p><b>dport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"7%\">\n<p><b>sport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\">\n<p>Destination or source port numbers, a 16-bit value. Indeed, IPv4 headers don\u2019t contain this information. Instead, this will set an offset which suits at least TCP and UDP if the IP header is of minimum size (20 bytes). If not, this will do unexpected things.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>icmp_type <br \/> icmp_code<\/b><\/p>\n<p style=\"margin-left:32%;\">Again, this allows to change data past the actual IP header itself. It assumes an ICMP header is present immediately following the (minimal sized) IP header. If it is not or the latter is bigger than the minimum of 20 bytes, this will do unexpected things. These fields are eight-bit values.<\/p>\n<p style=\"margin-left:11%;\"><b>ip<\/b> <i>EX_IPHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">Supported only when <i>ex<\/i> is used. The supported keywords for <i>EX_IPHDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>ttl<\/b><\/p>\n<\/td>\n<td width=\"74%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ip6<\/b> <i>IP6HDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">The supported keywords for <i>IP6HDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>src<\/b><\/p>\n<\/td>\n<td width=\"74%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"4%\">\n<p><b>dst<\/b><\/p>\n<\/td>\n<td width=\"74%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>traffic_class <br \/> flow_lbl <br \/> payload_len <br \/> nexthdr <br \/> hoplimit<\/b><\/p>\n<p style=\"margin-left:11%;\"><b>tcp<\/b> <i>TCPHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">The supported keywords for <i>TCPHDR_FIELD<\/i> are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"7%\">\n<p><b>sport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"7%\">\n<p><b>dport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\">\n<p>Source or destination TCP port number, a 16-bit value.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"7%\">\n<p><b>flags<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>udp<\/b> <i>UDPHDR_FIELD<\/i><\/p>\n<p style=\"margin-left:22%;\">The supported keywords for <i>UDPHDR_FIELD<\/i> are:<\/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=\"18%\">\n<p><b>sport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"18%\">\n<p><b>dport<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\">\n<p>Source or destination TCP port number, a 16-bit value.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"18%\">\n<p><b>clear<\/b><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%; margin-top: 1em\">Clear the addressed data (i.e., set it to zero).<\/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 style=\"margin-top: 1em\"><b>invert<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"56%\">\n<p style=\"margin-top: 1em\">Swap every bit in the addressed data.<\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>set<\/b> <i>VAL<\/i><\/p>\n<p style=\"margin-left:22%;\">Set the addressed data to a specific value. The size of <i>VAL<\/i> is defined by either one of the <b>u32<\/b>, <b>u16<\/b> or <b>u8<\/b> keywords in <i>RAW_OP<\/i>, or the size of the addressed header field in <i>LAYERED_OP<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>add<\/b> <i>VAL<\/i><\/p>\n<p style=\"margin-left:22%;\">Add the addressed data by a specific value. The size of <i>VAL<\/i> is defined by the size of the addressed header field in <i>EXTENDED_LAYERED_OP<\/i>. This operation is supported only for extended layered op.<\/p>\n<p style=\"margin-left:11%;\"><b>decrement<\/b><\/p>\n<p style=\"margin-left:22%;\">Decrease the addressed data by one. This operation is supported only for <b>ip ttl<\/b> and <b>ip6 hoplimit<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>preserve<\/b><\/p>\n<p style=\"margin-left:22%;\">Keep the addressed data as is.<\/p>\n<p style=\"margin-left:11%;\"><b>retain<\/b> <i>RVAL<\/i><\/p>\n<p style=\"margin-left:22%;\">This optional extra part of <i>CMD_SPEC<\/i> allows to exclude bits from being changed. Supported only for 32 bits fields or smaller.<\/p>\n<p style=\"margin-left:11%;\"><i>CONTROL<\/i><\/p>\n<p style=\"margin-left:22%;\">The following keywords allow to control how the tree of qdisc, classes, filters and actions is further traversed after this action. <b><br \/> reclassify<\/b><\/p>\n<p style=\"margin-left:32%;\">Restart with the first filter in the current list.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>pipe<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\">\n<p>Continue with the next action attached to the same filter.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>drop<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>shot<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\">\n<p>Drop the packet.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\"><b>continue<\/b><\/p>\n<p style=\"margin-left:32%;\">Continue classification with the next filter in line.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"6%\">\n<p><b>pass<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"68%\">\n<p>Finish classification process and return to calling qdisc for further packet processing. This is the default.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Being able to edit packet data, one could do all kinds of things, such as e.g. implementing port redirection. Certainly not the most useful application, but as an example it should do:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">First, qdiscs need to be set up to attach filters to. For the receive path, a simple <b>ingress<\/b> qdisc will do, for transmit path a classful qdisc (<b>HTB<\/b> in this case) is necessary:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc qdisc replace dev eth0 root handle 1: htb <br \/> tc qdisc add dev eth0 ingress handle ffff:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Finally, a filter with <b>pedit<\/b> action can be added for each direction. In this case, <b>u32<\/b> is used matching on the port number to redirect from, while <b>pedit<\/b> then does the actual rewriting:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add dev eth0 parent 1: u32 <\/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=\"92%\">\n<p>match ip dport 23 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit pedit munge ip dport set 22<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\">tc filter add dev eth0 parent ffff: u32 <\/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=\"92%\">\n<p>match ip sport 22 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit pedit munge ip sport set 23<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\">tc filter add dev eth0 parent ffff: u32 <\/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=\"92%\">\n<p>match ip sport 22 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit ex munge ip dst set 192.168.1.199<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\">tc filter add dev eth0 parent ffff: u32 <\/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=\"92%\">\n<p>match ip sport 22 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit ex munge ip6 dst set fe80::dacb:8aff:fec7:320e<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\">tc filter add dev eth0 parent ffff: u32 <\/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=\"92%\">\n<p>match ip sport 22 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit ex munge eth dst set 11:22:33:44:55:66<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%;\">tc filter add dev eth0 parent ffff: u32 <\/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=\"92%\">\n<p>match ip dport 23 0xffff <\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>action pedit ex munge tcp dport set 22<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">To rewrite just part of a field, use the <b>retain<\/b> directive. E.g. to overwrite the DSCP part of a dsfield with $DSCP, without touching ECN:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add dev eth0 ingress flower &#8230; <\/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=\"92%\">\n<p>action pedit ex munge ip dsfield set $((DSCP << 2)) retain 0xfc<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">And vice versa, to set ECN to e.g. 1 without impacting DSCP:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">tc filter add dev eth0 ingress flower &#8230; <\/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=\"92%\">\n<p>action pedit ex munge ip dsfield set 1 retain 0x3<\/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-htb<\/b>(8), <b>tc-u32<\/b>(8)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  pedit &#8211; generic packet editor action <\/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,574],"class_list":["post-3448","post","type-post","status-publish","format-standard","hentry","category-8-administracion-del-sistema","tag-5","tag-administracion","tag-man8","tag-tc-pedit"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3448","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=3448"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3448\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}