blob: b9bf70ca32062efa149013bba6c60c57f0fe8f1a [file] [log] [blame]
Andreas Henrikssoncaadda92012-12-12 12:23:48 +01001.TH ematch 8 "6 August 2012" iproute2 Linux
Florian Westphalc4873482012-08-09 09:18:51 +00002.
3.SH NAME
4ematch \- extended matches for use with "basic" or "flow" filters
5.
6.SH SYNOPSIS
7.sp
8.ad l
Florian Westphalc4873482012-08-09 09:18:51 +00009.B "tc filter add .. basic match"
10.RI EXPR
11.B .. flowid ..
12.sp
13
Florian Westphalc4873482012-08-09 09:18:51 +000014.IR EXPR " := " TERM " [ { "
15.B and | or
16}
17.IR EXPR
18]
19
Andreas Schwab1b3c1492012-09-06 03:09:58 +000020.IR TERM " := [ " \fBnot " ] { " MATCH " | '(' " EXPR " ')' } "
Florian Westphalc4873482012-08-09 09:18:51 +000021
Florian Westphalc4873482012-08-09 09:18:51 +000022.IR MATCH " := " module " '(' " ARGS " ')' "
23
Florian Westphalc4873482012-08-09 09:18:51 +000024.IR ARGS " := " ARG1 " " ARG2 " ..
25
26.SH MATCHES
27
28.SS cmp
29Simple comparison ematch: arithmetic compare of packet data to a given value.
esr@thyrsus.comee0b0a92013-07-09 20:13:06 -040030
Andreas Schwab1b3c1492012-09-06 03:09:58 +000031.IR cmp "( " ALIGN " at " OFFSET " [ " ATTRS " ] { " eq " | " lt " | " gt " } " VALUE " )
Florian Westphalc4873482012-08-09 09:18:51 +000032
Florian Westphalc4873482012-08-09 09:18:51 +000033.IR ALIGN " := { " u8 " | " u16 " | " u32 " } "
34
Andreas Schwab1b3c1492012-09-06 03:09:58 +000035.IR ATTRS " := [ layer " LAYER " ] [ mask " MASK " ] [ trans ]
Florian Westphalc4873482012-08-09 09:18:51 +000036
Andreas Schwab1b3c1492012-09-06 03:09:58 +000037.IR LAYER " := { " link " | " network " | " transport " | " 0..2 " }
Florian Westphalc4873482012-08-09 09:18:51 +000038
39.SS meta
40Metadata ematch
esr@thyrsus.comee0b0a92013-07-09 20:13:06 -040041
Andreas Schwab1b3c1492012-09-06 03:09:58 +000042.IR meta "( " OBJECT " { " eq " | " lt " |" gt " } " OBJECT " )
Florian Westphalc4873482012-08-09 09:18:51 +000043
Florian Westphalc4873482012-08-09 09:18:51 +000044.IR OBJECT " := { " META_ID " | " VALUE " }
45
Andreas Schwab1b3c1492012-09-06 03:09:58 +000046.IR META_ID " := " id " [ shift " SHIFT " ] [ mask " MASK " ]
Florian Westphalc4873482012-08-09 09:18:51 +000047
48.TP
49meta attributes:
50
51\fBrandom\fP 32 bit random value
52
53\fBloadavg_1\fP Load average in last 5 minutes
54
55\fBnf_mark\fP Netfilter mark
56
57\fBvlan\fP Vlan tag
58
59\fBsk_rcvbuf\fP Receive buffer size
60
61\fBsk_snd_queue\fP Send queue length
62
63.PP
64A full list of meta attributes can be obtained via
65
66# tc filter add dev eth1 basic match 'meta(list)'
67
68.SS nbyte
69match packet data byte sequence
esr@thyrsus.comee0b0a92013-07-09 20:13:06 -040070
Florian Westphalc4873482012-08-09 09:18:51 +000071.IR nbyte "( " NEEDLE " at " OFFSET " [ layer " LAYER " ] )
72
Florian Westphalc4873482012-08-09 09:18:51 +000073.IR NEEDLE " := { " string " | " c-escape-sequence " } "
74
Florian Westphalc4873482012-08-09 09:18:51 +000075.IR OFFSET " := " int
76
Andreas Schwab1b3c1492012-09-06 03:09:58 +000077.IR LAYER " := { " link " | " network " | " transport " | " 0..2 " }
Florian Westphalc4873482012-08-09 09:18:51 +000078
79.SS u32
80u32 ematch
esr@thyrsus.comee0b0a92013-07-09 20:13:06 -040081
Andreas Schwab1b3c1492012-09-06 03:09:58 +000082.IR u32 "( " ALIGN " " VALUE " " MASK " at [ nexthdr+ ] " OFFSET " )
Florian Westphalc4873482012-08-09 09:18:51 +000083
Andreas Schwab1b3c1492012-09-06 03:09:58 +000084.IR ALIGN " := { " u8 " | " u16 " | " u32 " }
Florian Westphalc4873482012-08-09 09:18:51 +000085
86.SS ipset
Petr Sabata6274b0b2013-04-04 03:36:57 +000087test packet against ipset membership
esr@thyrsus.comee0b0a92013-07-09 20:13:06 -040088
Andreas Schwab1b3c1492012-09-06 03:09:58 +000089.IR ipset "( " SETNAME " " FLAGS " )
Florian Westphalc4873482012-08-09 09:18:51 +000090
Florian Westphalc4873482012-08-09 09:18:51 +000091.IR SETNAME " := " string
92
Andreas Schwab1b3c1492012-09-06 03:09:58 +000093.IR FLAGS " := { " FLAG " [, " FLAGS "] }
Florian Westphalc4873482012-08-09 09:18:51 +000094
95The flag options are the same as those used by the iptables "set" match.
96
97When using the ipset ematch with the "ip_set_hash:net,iface" set type,
98the interface can be queried using "src,dst (source ip address, outgoing interface) or
99"src,src" (source ip address, incoming interface) syntax.
100
101.SH CAVEATS
102
103The ematch syntax uses '(' and ')' to group expressions. All braces need to be
104escaped properly to prevent shell commandline from interpreting these directly.
105
106When using the ipset ematch with the "ifb" device, the outgoing device will be the
107ifb device itself, e.g. "ifb0".
108The original interface (i.e. the device the packet arrived on) is treated as the incoming interface.
109
110.SH EXAMPLE & USAGE
111
112# tc filter add .. basic match ...
113
114# 'cmp(u16 at 3 layer 2 mask 0xff00 gt 20)'
115
116# 'meta(nfmark gt 24)' and 'meta(tcindex mask 0xf0 eq 0xf0)'
117
118# 'nbyte("ababa" at 12 layer 1)'
119
120# 'u32(u16 0x1122 0xffff at nexthdr+4)'
121
122Check if packet source ip address is member of set named \fBbulk\fP:
123
124# 'ipset(bulk src)'
125
126Check if packet source ip and the interface the packet arrived on is member of "hash:net,iface" set named \fBinteractive\fP:
127
128# 'ipset(interactive src,src)'
129
130.SH "AUTHOR"
131
132The extended match infrastructure was added by Thomas Graf.