|
|
049c96 |
From be321a9a9608a4e9b85b5d1ab6606687a8a90cb0 Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Wed, 30 Mar 2016 16:43:19 +0200
|
|
|
049c96 |
Subject: [PATCH] man: Add a man page for the pedit action
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1275426
|
|
|
049c96 |
Upstream Status: iproute2.git commit 448800026ff71
|
|
|
049c96 |
|
|
|
049c96 |
commit 448800026ff7189f297233c6588457a7e9770183
|
|
|
049c96 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
049c96 |
Date: Fri Mar 4 13:11:40 2016 +0100
|
|
|
049c96 |
|
|
|
049c96 |
man: Add a man page for the pedit action
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
049c96 |
---
|
|
|
049c96 |
man/man8/tc-pedit.8 | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
049c96 |
1 file changed, 230 insertions(+)
|
|
|
049c96 |
create mode 100644 man/man8/tc-pedit.8
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/man/man8/tc-pedit.8 b/man/man8/tc-pedit.8
|
|
|
049c96 |
new file mode 100644
|
|
|
049c96 |
index 0000000..c30927e
|
|
|
049c96 |
--- /dev/null
|
|
|
049c96 |
+++ b/man/man8/tc-pedit.8
|
|
|
049c96 |
@@ -0,0 +1,230 @@
|
|
|
049c96 |
+.TH "Generic packet editor action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.SH NAME
|
|
|
049c96 |
+pedit - generic packet editor action
|
|
|
049c96 |
+.SH SYNOPSIS
|
|
|
049c96 |
+.in +8
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.BR tc " ... " "action pedit munge " {
|
|
|
049c96 |
+.IR RAW_OP " | " LAYERED_OP " } [ " BRANCH " ]"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR RAW_OP " := "
|
|
|
049c96 |
+.BI offset " OFFSET"
|
|
|
049c96 |
+.RB "{ " u8 " | " u16 " | " u32 " } ["
|
|
|
049c96 |
+.IR AT_SPEC " ] " CMD_SPEC
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR AT_SPEC " := "
|
|
|
049c96 |
+.BI at " AT " offmask " MASK " shift " SHIFT"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR LAYERED_OP " := { "
|
|
|
049c96 |
+.BI ip " IPHDR_FIELD"
|
|
|
049c96 |
+|
|
|
|
049c96 |
+.BI ip6 " IP6HDR_FIELD"
|
|
|
049c96 |
+|
|
|
|
049c96 |
+.BI udp " UDPHDR_FIELD"
|
|
|
049c96 |
+|
|
|
|
049c96 |
+.BI tcp " TCPHDR_FIELD"
|
|
|
049c96 |
+|
|
|
|
049c96 |
+.BI icmp " ICMPHDR_FIELD"
|
|
|
049c96 |
+.RI } " CMD_SPEC"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR IPHDR_FIELD " := { "
|
|
|
049c96 |
+.BR src " | " dst " | " tos " | " dsfield " | " ihl " | " protocol " |"
|
|
|
049c96 |
+.BR precedence " | " nofrag " | " firstfrag " | " ce " | " df " |"
|
|
|
049c96 |
+.BR mf " | " dport " | " sport " | " icmp_type " | " icmp_code " }"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR CMD_SPEC " := {"
|
|
|
049c96 |
+.BR clear " | " invert " | " set
|
|
|
049c96 |
+.IR VAL " | "
|
|
|
049c96 |
+.BR preserve " } [ " retain
|
|
|
049c96 |
+.IR RVAL " ]"
|
|
|
049c96 |
+
|
|
|
049c96 |
+.ti -8
|
|
|
049c96 |
+.IR BRANCH " := {"
|
|
|
049c96 |
+.BR reclassify " | " pipe " | " drop " | " shot " | " continue " | " pass " }"
|
|
|
049c96 |
+.SH DESCRIPTION
|
|
|
049c96 |
+The
|
|
|
049c96 |
+.B pedit
|
|
|
049c96 |
+action can be used to change arbitrary packet data. The location of data to
|
|
|
049c96 |
+change can either be specified by giving an offset and size as in
|
|
|
049c96 |
+.IR RAW_OP ,
|
|
|
049c96 |
+or for header values by naming the header and field to edit the size is then
|
|
|
049c96 |
+chosen automatically based on the header field size. Currently this is supported
|
|
|
049c96 |
+only for IPv4 headers.
|
|
|
049c96 |
+.SH OPTIONS
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI offset " OFFSET " "\fR{ \fBu32 \fR| \fBu16 \fR| \fBu8 \fR}"
|
|
|
049c96 |
+Specify the offset at which to change data.
|
|
|
049c96 |
+.I OFFSET
|
|
|
049c96 |
+is a signed integer, it's base is automatically chosen (e.g. hex if prefixed by
|
|
|
049c96 |
+.B 0x
|
|
|
049c96 |
+or octal if prefixed by
|
|
|
049c96 |
+.BR 0 ).
|
|
|
049c96 |
+The second argument specifies the length of data to change, that is four bytes
|
|
|
049c96 |
+.RB ( u32 ),
|
|
|
049c96 |
+two bytes
|
|
|
049c96 |
+.RB ( u16 )
|
|
|
049c96 |
+or a single byte
|
|
|
049c96 |
+.RB ( u8 ).
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI at " AT " offmask " MASK " shift " SHIFT"
|
|
|
049c96 |
+This is an optional part of
|
|
|
049c96 |
+.IR RAW_OP
|
|
|
049c96 |
+which allows to have a variable
|
|
|
049c96 |
+.I OFFSET
|
|
|
049c96 |
+depending on packet data at offset
|
|
|
049c96 |
+.IR AT ,
|
|
|
049c96 |
+which is binary ANDed with
|
|
|
049c96 |
+.I MASK
|
|
|
049c96 |
+and right-shifted by
|
|
|
049c96 |
+.I SHIFT
|
|
|
049c96 |
+before adding it to
|
|
|
049c96 |
+.IR OFFSET .
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI ip " IPHDR_FIELD"
|
|
|
049c96 |
+Change an IPv4 header field. The supported keywords for
|
|
|
049c96 |
+.I IPHDR_FIELD
|
|
|
049c96 |
+are:
|
|
|
049c96 |
+.RS
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B src
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B dst
|
|
|
049c96 |
+Source or destination IP address, a four-byte value.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B tos
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B dsfield
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B precedence
|
|
|
049c96 |
+Type Of Service field, an eight-bit value.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B ihl
|
|
|
049c96 |
+Change the IP Header Length field, a four-bit value.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B protocol
|
|
|
049c96 |
+Next-layer Protocol field, an eight-bit value.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B nofrag
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B firstfrag
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B ce
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B df
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B mf
|
|
|
049c96 |
+Change IP header flags. Note that the value to pass to the
|
|
|
049c96 |
+.B set
|
|
|
049c96 |
+command is not just a bit value, but the full byte including the flags field.
|
|
|
049c96 |
+Though only the relevant bits of that value are respected, the rest ignored.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B dport
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B sport
|
|
|
049c96 |
+Destination or source port numbers, a 16-bit value. Indeed, IPv4 headers don't
|
|
|
049c96 |
+contain this information. Instead, this will set an offset which suits at least
|
|
|
049c96 |
+TCP and UDP if the IP header is of minimum size (20 bytes). If not, this will do
|
|
|
049c96 |
+unexpected things.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B icmp_type
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B icmp_code
|
|
|
049c96 |
+Again, this allows to change data past the actual IP header itself. It assumes
|
|
|
049c96 |
+an ICMP header is present immediately following the (minimal sized) IP header.
|
|
|
049c96 |
+If it is not or the latter is bigger than the minimum of 20 bytes, this will do
|
|
|
049c96 |
+unexpected things. These fields are eight-bit values.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B clear
|
|
|
049c96 |
+Clear the addressed data (i.e., set it to zero).
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B invert
|
|
|
049c96 |
+Swap every bit in the addressed data.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI set " VAL"
|
|
|
049c96 |
+Set the addressed data to a specific value. The size of
|
|
|
049c96 |
+.I VAL
|
|
|
049c96 |
+is defined by either one of the
|
|
|
049c96 |
+.BR u32 ", " u16 " or " u8
|
|
|
049c96 |
+keywords in
|
|
|
049c96 |
+.IR RAW_OP ,
|
|
|
049c96 |
+or the size of the addressed header field in
|
|
|
049c96 |
+.IR LAYERED_OP .
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B preserve
|
|
|
049c96 |
+Keep the addressed data as is.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.BI retain " RVAL"
|
|
|
049c96 |
+This optional extra part of
|
|
|
049c96 |
+.I CMD_SPEC
|
|
|
049c96 |
+allows to exclude bits from being changed.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.I BRANCH
|
|
|
049c96 |
+The following keywords allow to control how the tree of qdisc, classes,
|
|
|
049c96 |
+filters and actions is further traversed after this action.
|
|
|
049c96 |
+.RS
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B reclassify
|
|
|
049c96 |
+Restart with the first filter in the current list.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B pipe
|
|
|
049c96 |
+Continue with the next action attached to the same filter.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B drop
|
|
|
049c96 |
+.TQ
|
|
|
049c96 |
+.B shot
|
|
|
049c96 |
+Drop the packet.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B continue
|
|
|
049c96 |
+Continue classification with the next filter in line.
|
|
|
049c96 |
+.TP
|
|
|
049c96 |
+.B pass
|
|
|
049c96 |
+Finish classification process and return to calling qdisc for further packet
|
|
|
049c96 |
+processing. This is the default.
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.SH EXAMPLES
|
|
|
049c96 |
+Being able to edit packet data, one could do all kinds of things, such as e.g.
|
|
|
049c96 |
+implementing port redirection. Certainly not the most useful application, but
|
|
|
049c96 |
+as an example it should do:
|
|
|
049c96 |
+
|
|
|
049c96 |
+First, qdiscs need to be set up to attach filters to. For the receive path, a simple
|
|
|
049c96 |
+.B ingress
|
|
|
049c96 |
+qdisc will do, for transmit path a classful qdisc
|
|
|
049c96 |
+.RB ( HTB
|
|
|
049c96 |
+in this case) is necessary:
|
|
|
049c96 |
+
|
|
|
049c96 |
+.RS
|
|
|
049c96 |
+.EX
|
|
|
049c96 |
+tc qdisc replace dev eth0 root handle 1: htb
|
|
|
049c96 |
+tc qdisc add dev eth0 ingress handle ffff:
|
|
|
049c96 |
+.EE
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+
|
|
|
049c96 |
+Finally, a filter with
|
|
|
049c96 |
+.B pedit
|
|
|
049c96 |
+action can be added for each direction. In this case,
|
|
|
049c96 |
+.B u32
|
|
|
049c96 |
+is used matching on the port number to redirect from, while
|
|
|
049c96 |
+.B pedit
|
|
|
049c96 |
+then does the actual rewriting:
|
|
|
049c96 |
+
|
|
|
049c96 |
+.RS
|
|
|
049c96 |
+.EX
|
|
|
049c96 |
+tc filter add dev eth0 parent 1: u32 \\
|
|
|
049c96 |
+ match ip dport 23 0xffff \\
|
|
|
049c96 |
+ action pedit pedit munge ip dport set 22
|
|
|
049c96 |
+tc filter add dev eth0 parent ffff: u32 \\
|
|
|
049c96 |
+ match ip sport 22 0xffff \\
|
|
|
049c96 |
+ action pedit pedit munge ip sport set 23
|
|
|
049c96 |
+.EE
|
|
|
049c96 |
+.RE
|
|
|
049c96 |
+.SH SEE ALSO
|
|
|
049c96 |
+.BR tc (8),
|
|
|
049c96 |
+.BR tc-htb (8),
|
|
|
049c96 |
+.BR tc-u32 (8)
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|