Blame man/man8/tc-pedit.8

Packit Service 3880ab
.TH "Generic packet editor action in tc" 8 "12 Jan 2015" "iproute2" "Linux"
Packit Service 3880ab
Packit Service 3880ab
.SH NAME
Packit Service 3880ab
pedit - generic packet editor action
Packit Service 3880ab
.SH SYNOPSIS
Packit Service 3880ab
.in +8
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.BR tc " ... " "action pedit [ex] munge " {
Packit Service 3880ab
.IR RAW_OP " | " LAYERED_OP " | " EXTENDED_LAYERED_OP " } [ " CONTROL " ]"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR RAW_OP " := "
Packit Service 3880ab
.BI offset " OFFSET"
Packit Service 3880ab
.RB "{ " u8 " | " u16 " | " u32 " } ["
Packit Service 3880ab
.IR AT_SPEC " ] " CMD_SPEC
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR AT_SPEC " := "
Packit Service 3880ab
.BI at " AT " offmask " MASK " shift " SHIFT"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR LAYERED_OP " := { "
Packit Service 3880ab
.BI ip " IPHDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI ip " BEYOND_IPHDR_FIELD"
Packit Service 3880ab
.RI } " CMD_SPEC"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR EXTENDED_LAYERED_OP " := { "
Packit Service 3880ab
.BI eth " ETHHDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI ip " IPHDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI ip " EX_IPHDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI ip6 " IP6HDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI tcp " TCPHDR_FIELD"
Packit Service 3880ab
|
Packit Service 3880ab
.BI udp " UDPHDR_FIELD"
Packit Service 3880ab
.RI } " CMD_SPEC"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR ETHHDR_FIELD " := { "
Packit Service 3880ab
.BR src " | " dst " | " type " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR IPHDR_FIELD " := { "
Packit Service 3880ab
.BR src " | " dst " | " tos " | " dsfield " | " ihl " | " protocol " |"
Packit Service 3880ab
.BR precedence " | " nofrag " | " firstfrag " | " ce " | " df " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR BEYOND_IPHDR_FIELD " := { "
Packit Service 3880ab
.BR dport " | " sport " | " icmp_type " | " icmp_code " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR EX_IPHDR_FIELD " := { "
Packit Service 3880ab
.BR ttl " }"
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR IP6HDR_FIELD " := { "
Packit Service 3880ab
.BR src " | " dst " | " traffic_class " | " flow_lbl " | " payload_len " | "
Packit Service 3880ab
.BR nexthdr " | " hoplimit " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR TCPHDR_FIELD " := { "
Packit Service 3880ab
.BR sport " | " dport " | " flags " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR UDPHDR_FIELD " := { "
Packit Service 3880ab
.BR sport " | " dport " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR CMD_SPEC " := {"
Packit Service 3880ab
.BR clear " | " invert " | " set
Packit Service 3880ab
.IR VAL " | "
Packit Service 3880ab
.BR add
Packit Service 3880ab
.IR VAL " | "
Packit Service 3880ab
.BR preserve " } [ " retain
Packit Service 3880ab
.IR RVAL " ]"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR CONTROL " := {"
Packit Service 3880ab
.BR reclassify " | " pipe " | " drop " | " shot " | " continue " | " pass " | " goto " " chain " " CHAIN_INDEX " }"
Packit Service 3880ab
.SH DESCRIPTION
Packit Service 3880ab
The
Packit Service 3880ab
.B pedit
Packit Service 3880ab
action can be used to change arbitrary packet data. The location of data to
Packit Service 3880ab
change can either be specified by giving an offset and size as in
Packit Service 3880ab
.IR RAW_OP ,
Packit Service 3880ab
or for header values by naming the header and field to edit the size is then
Packit Service 3880ab
chosen automatically based on the header field size.
Packit Service 3880ab
.SH OPTIONS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ex
Packit Service 3880ab
Use extended pedit.
Packit Service 3880ab
.I EXTENDED_LAYERED_OP
Packit Service 3880ab
and the add
Packit Service 3880ab
.I CMD_SPEC
Packit Service 3880ab
are allowed only in this mode.
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI offset " OFFSET " "\fR{ \fBu32 \fR| \fBu16 \fR| \fBu8 \fR}"
Packit Service 3880ab
Specify the offset at which to change data.
Packit Service 3880ab
.I OFFSET
Packit Service 3880ab
is a signed integer, it's base is automatically chosen (e.g. hex if prefixed by
Packit Service 3880ab
.B 0x
Packit Service 3880ab
or octal if prefixed by
Packit Service 3880ab
.BR 0 ).
Packit Service 3880ab
The second argument specifies the length of data to change, that is four bytes
Packit Service 3880ab
.RB ( u32 ),
Packit Service 3880ab
two bytes
Packit Service 3880ab
.RB ( u16 )
Packit Service 3880ab
or a single byte
Packit Service 3880ab
.RB ( u8 ).
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI at " AT " offmask " MASK " shift " SHIFT"
Packit Service 3880ab
This is an optional part of
Packit Service 3880ab
.IR RAW_OP
Packit Service 3880ab
which allows to have a variable
Packit Service 3880ab
.I OFFSET
Packit Service 3880ab
depending on packet data at offset
Packit Service 3880ab
.IR AT ,
Packit Service 3880ab
which is binary ANDed with
Packit Service 3880ab
.I MASK
Packit Service 3880ab
and right-shifted by
Packit Service 3880ab
.I SHIFT
Packit Service 3880ab
before adding it to
Packit Service 3880ab
.IR OFFSET .
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI eth " ETHHDR_FIELD"
Packit Service 3880ab
Change an ETH header field. The supported keywords for
Packit Service 3880ab
.I ETHHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B src
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dst
Packit Service 3880ab
Source or destination MAC address in the standard format: XX:XX:XX:XX:XX:XX
Packit Service 3880ab
.TP
Packit Service 3880ab
.B type
Packit Service 3880ab
Ether-type in numeric value
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI ip " IPHDR_FIELD"
Packit Service 3880ab
Change an IPv4 header field. The supported keywords for
Packit Service 3880ab
.I IPHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B src
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dst
Packit Service 3880ab
Source or destination IP address, a four-byte value.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B tos
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dsfield
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B precedence
Packit Service 3880ab
Type Of Service field, an eight-bit value.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ihl
Packit Service 3880ab
Change the IP Header Length field, a four-bit value.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B protocol
Packit Service 3880ab
Next-layer Protocol field, an eight-bit value.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B nofrag
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B firstfrag
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B ce
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B df
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B mf
Packit Service 3880ab
Change IP header flags. Note that the value to pass to the
Packit Service 3880ab
.B set
Packit Service 3880ab
command is not just a bit value, but the full byte including the flags field.
Packit Service 3880ab
Though only the relevant bits of that value are respected, the rest ignored.
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI ip " BEYOND_IPHDR_FIELD"
Packit Service 3880ab
Supported only for non-extended layered op. It is passed to the kernel as
Packit Service 3880ab
offsets relative to the beginning of the IP header and assumes the IP header is
Packit Service 3880ab
of minimum size (20 bytes). The supported keywords for
Packit Service 3880ab
.I BEYOND_IPHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B dport
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B sport
Packit Service 3880ab
Destination or source port numbers, a 16-bit value. Indeed, IPv4 headers don't
Packit Service 3880ab
contain this information. Instead, this will set an offset which suits at least
Packit Service 3880ab
TCP and UDP if the IP header is of minimum size (20 bytes). If not, this will do
Packit Service 3880ab
unexpected things.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B icmp_type
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B icmp_code
Packit Service 3880ab
Again, this allows to change data past the actual IP header itself. It assumes
Packit Service 3880ab
an ICMP header is present immediately following the (minimal sized) IP header.
Packit Service 3880ab
If it is not or the latter is bigger than the minimum of 20 bytes, this will do
Packit Service 3880ab
unexpected things. These fields are eight-bit values.
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI ip " EX_IPHDR_FIELD"
Packit Service 3880ab
Supported only when
Packit Service 3880ab
.I ex
Packit Service 3880ab
is used. The supported keywords for
Packit Service 3880ab
.I EX_IPHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ttl
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI ip6 " IP6HDR_FIELD"
Packit Service 3880ab
The supported keywords for
Packit Service 3880ab
.I IP6HDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B src
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dst
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B traffic_class
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B flow_lbl
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B payload_len
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B nexthdr
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B hoplimit
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI tcp " TCPHDR_FIELD"
Packit Service 3880ab
The supported keywords for
Packit Service 3880ab
.I TCPHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B sport
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dport
Packit Service 3880ab
Source or destination TCP port number, a 16-bit value.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B flags
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI udp " UDPHDR_FIELD"
Packit Service 3880ab
The supported keywords for
Packit Service 3880ab
.I UDPHDR_FIELD
Packit Service 3880ab
are:
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B sport
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B dport
Packit Service 3880ab
Source or destination TCP port number, a 16-bit value.
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.B clear
Packit Service 3880ab
Clear the addressed data (i.e., set it to zero).
Packit Service 3880ab
.TP
Packit Service 3880ab
.B invert
Packit Service 3880ab
Swap every bit in the addressed data.
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI set " VAL"
Packit Service 3880ab
Set the addressed data to a specific value. The size of
Packit Service 3880ab
.I VAL
Packit Service 3880ab
is defined by either one of the
Packit Service 3880ab
.BR u32 ", " u16 " or " u8
Packit Service 3880ab
keywords in
Packit Service 3880ab
.IR RAW_OP ,
Packit Service 3880ab
or the size of the addressed header field in
Packit Service 3880ab
.IR LAYERED_OP .
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI add " VAL"
Packit Service 3880ab
Add the addressed data by a specific value. The size of
Packit Service 3880ab
.I VAL
Packit Service 3880ab
is defined by the size of the addressed header field in
Packit Service 3880ab
.IR EXTENDED_LAYERED_OP .
Packit Service 3880ab
This operation is supported only for extended layered op.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B preserve
Packit Service 3880ab
Keep the addressed data as is.
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI retain " RVAL"
Packit Service 3880ab
This optional extra part of
Packit Service 3880ab
.I CMD_SPEC
Packit Service 3880ab
allows to exclude bits from being changed. Supported only for 32 bits fields
Packit Service 3880ab
or smaller.
Packit Service 3880ab
.TP
Packit Service 3880ab
.I CONTROL
Packit Service 3880ab
The following keywords allow to control how the tree of qdisc, classes,
Packit Service 3880ab
filters and actions is further traversed after this action.
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.B reclassify
Packit Service 3880ab
Restart with the first filter in the current list.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B pipe
Packit Service 3880ab
Continue with the next action attached to the same filter.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B drop
Packit Service 3880ab
.TQ
Packit Service 3880ab
.B shot
Packit Service 3880ab
Drop the packet.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B continue
Packit Service 3880ab
Continue classification with the next filter in line.
Packit Service 3880ab
.TP
Packit Service 3880ab
.B pass
Packit Service 3880ab
Finish classification process and return to calling qdisc for further packet
Packit Service 3880ab
processing. This is the default.
Packit Service 3880ab
.RE
Packit Service 3880ab
.SH EXAMPLES
Packit Service 3880ab
Being able to edit packet data, one could do all kinds of things, such as e.g.
Packit Service 3880ab
implementing port redirection. Certainly not the most useful application, but
Packit Service 3880ab
as an example it should do:
Packit Service 3880ab
Packit Service 3880ab
First, qdiscs need to be set up to attach filters to. For the receive path, a simple
Packit Service 3880ab
.B ingress
Packit Service 3880ab
qdisc will do, for transmit path a classful qdisc
Packit Service 3880ab
.RB ( HTB
Packit Service 3880ab
in this case) is necessary:
Packit Service 3880ab
Packit Service 3880ab
.RS
Packit Service 3880ab
.EX
Packit Service 3880ab
tc qdisc replace dev eth0 root handle 1: htb
Packit Service 3880ab
tc qdisc add dev eth0 ingress handle ffff:
Packit Service 3880ab
.EE
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
Finally, a filter with
Packit Service 3880ab
.B pedit
Packit Service 3880ab
action can be added for each direction. In this case,
Packit Service 3880ab
.B u32
Packit Service 3880ab
is used matching on the port number to redirect from, while
Packit Service 3880ab
.B pedit
Packit Service 3880ab
then does the actual rewriting:
Packit Service 3880ab
Packit Service 3880ab
.RS
Packit Service 3880ab
.EX
Packit Service 3880ab
tc filter add dev eth0 parent 1: u32 \\
Packit Service 3880ab
	match ip dport 23 0xffff \\
Packit Service 3880ab
	action pedit pedit munge ip dport set 22
Packit Service 3880ab
tc filter add dev eth0 parent ffff: u32 \\
Packit Service 3880ab
	match ip sport 22 0xffff \\
Packit Service 3880ab
	action pedit pedit munge ip sport set 23
Packit Service 3880ab
tc filter add dev eth0 parent ffff: u32 \\
Packit Service 3880ab
	match ip sport 22 0xffff \\
Packit Service 3880ab
	action pedit ex munge ip dst set 192.168.1.199
Packit Service 3880ab
tc filter add dev eth0 parent ffff: u32 \\
Packit Service 3880ab
	match ip sport 22 0xffff \\
Packit Service 3880ab
	action pedit ex munge ip6 dst set fe80::dacb:8aff:fec7:320e
Packit Service 3880ab
tc filter add dev eth0 parent ffff: u32 \\
Packit Service 3880ab
	match ip sport 22 0xffff \\
Packit Service 3880ab
	action pedit ex munge eth dst set 11:22:33:44:55:66
Packit Service 3880ab
tc filter add dev eth0 parent ffff: u32 \\
Packit Service 3880ab
	match ip dport 23 0xffff \\
Packit Service 3880ab
	action pedit ex munge tcp dport set 22
Packit Service 3880ab
.EE
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
To rewrite just part of a field, use the
Packit Service 3880ab
.B retain
Packit Service 3880ab
directive. E.g. to overwrite the DSCP part of a dsfield with $DSCP, without
Packit Service 3880ab
touching ECN:
Packit Service 3880ab
Packit Service 3880ab
.RS
Packit Service 3880ab
.EX
Packit Service 3880ab
tc filter add dev eth0 ingress flower ... \\
Packit Service 3880ab
	action pedit ex munge ip dsfield set $((DSCP << 2)) retain 0xfc
Packit Service 3880ab
.EE
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
And vice versa, to set ECN to e.g. 1 without impacting DSCP:
Packit Service 3880ab
Packit Service 3880ab
.RS
Packit Service 3880ab
.EX
Packit Service 3880ab
tc filter add dev eth0 ingress flower ... \\
Packit Service 3880ab
	action pedit ex munge ip dsfield set 1 retain 0x3
Packit Service 3880ab
.EE
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
.SH SEE ALSO
Packit Service 3880ab
.BR tc (8),
Packit Service 3880ab
.BR tc-htb (8),
Packit Service 3880ab
.BR tc-u32 (8)