]> The Tcpdump Group git mirrors - libpcap/blob - pcap-filter.manmisc.in
Add SCTP to pcap-filter(7). [skip ci]
[libpcap] / pcap-filter.manmisc.in
1 .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
2 .\" The Regents of the University of California. All rights reserved.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that: (1) source code distributions
7 .\" retain the above copyright notice and this paragraph in its entirety, (2)
8 .\" distributions including binary code include the above copyright notice and
9 .\" this paragraph in its entirety in the documentation or other materials
10 .\" provided with the distribution, and (3) all advertising materials mentioning
11 .\" features or use of this software display the following acknowledgement:
12 .\" ``This product includes software developed by the University of California,
13 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 .\" the University nor the names of its contributors may be used to endorse
15 .\" or promote products derived from this software without specific prior
16 .\" written permission.
17 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 .\"
21 .TH PCAP-FILTER @MAN_MISC_INFO@ "4 January 2022"
22 .SH NAME
23 pcap-filter \- packet filter syntax
24 .br
25 .ad
26 .SH DESCRIPTION
27 .LP
28 .BR pcap_compile (3PCAP)
29 is used to compile a string into a filter program.
30 The resulting filter program can then be applied to
31 some stream of packets to determine which packets will be supplied to
32 .BR pcap_loop (3PCAP),
33 .BR pcap_dispatch (3PCAP),
34 .BR pcap_next (3PCAP),
35 or
36 .BR pcap_next_ex (3PCAP).
37 .LP
38 The \fIfilter expression\fP consists of one or more
39 .IR primitives .
40 Primitives usually consist of an
41 .I id
42 (name or number) preceded by one or more qualifiers.
43 There are three
44 different kinds of qualifier:
45 .IP \fItype\fP
46 .I type
47 qualifiers say what kind of thing the id name or number refers to.
48 Possible types are
49 .BR host ,
50 .BR net ,
51 .B port
52 and
53 .BR portrange .
54 E.g., `\fBhost\fP foo', `\fBnet\fP 128.3', `\fBport\fP 20', `\fBportrange\fP 6000-6008'.
55 If there is no type
56 qualifier,
57 .B host
58 is assumed.
59 .IP \fIdir\fP
60 .I dir
61 qualifiers specify a particular transfer direction to and/or from
62 .IR id .
63 Possible directions are
64 .BR src ,
65 .BR dst ,
66 .BR "src or dst" ,
67 .BR "src and dst" ,
68 .BR ra ,
69 .BR ta ,
70 .BR addr1 ,
71 .BR addr2 ,
72 .BR addr3 ,
73 and
74 .BR addr4 .
75 E.g., `\fBsrc\fP foo', `\fBdst net\fP 128.3', `\fBsrc or dst port\fP ftp-data'.
76 If
77 there is no dir qualifier, `\fBsrc or dst\fP' is assumed.
78 The
79 .BR ra ,
80 .BR ta ,
81 .BR addr1 ,
82 .BR addr2 ,
83 .BR addr3 ,
84 and
85 .B addr4
86 qualifiers are only valid for IEEE 802.11 Wireless LAN link layers.
87 .IP \fIproto\fP
88 .I proto
89 qualifiers restrict the match to a particular protocol.
90 Possible
91 protocols are:
92 .BR ether ,
93 .BR fddi ,
94 .BR tr ,
95 .BR wlan ,
96 .BR ip ,
97 .BR ip6 ,
98 .BR arp ,
99 .BR rarp ,
100 .BR decnet ,
101 .BR sctp ,
102 .B tcp
103 and
104 .BR udp .
105 E.g., `\fBether src\fP foo', `\fBarp net\fP 128.3', `\fBtcp port\fP 21',
106 `\fBudp portrange\fP 7000-7009', `\fBwlan addr2\fP 0:2:3:4:5:6'.
107 If there is no
108 .I proto
109 qualifier, all protocols consistent with the type are assumed.
110 E.g., `\fBsrc\fP foo' means `\fB(ip or arp or rarp) src\fP foo',
111 `\fBnet\fP bar' means `\fB(ip or arp or rarp) net\fP bar' and
112 `\fBport\fP 53' means `\fB(tcp or udp or sctp) port\fP 53'
113 (note that these examples use invalid syntax to illustrate the principle).
114 .LP
115 [\fBfddi\fP is actually an alias for \fBether\fP; the parser treats them
116 identically as meaning ``the data link level used on the specified
117 network interface''. FDDI headers contain Ethernet-like source
118 and destination addresses, and often contain Ethernet-like packet
119 types, so you can filter on these FDDI fields just as with the
120 analogous Ethernet fields.
121 FDDI headers also contain other fields,
122 but you cannot name them explicitly in a filter expression.
123 .LP
124 Similarly, \fBtr\fP and \fBwlan\fP are aliases for \fBether\fP; the previous
125 paragraph's statements about FDDI headers also apply to Token Ring
126 and 802.11 wireless LAN headers. For 802.11 headers, the destination
127 address is the DA field and the source address is the SA field; the
128 BSSID, RA, and TA fields aren't tested.]
129 .LP
130 In addition to the above, there are some special `primitive' keywords
131 that don't follow the pattern:
132 .BR gateway ,
133 .BR broadcast ,
134 .BR less ,
135 .B greater
136 and arithmetic expressions.
137 All of these are described below.
138 .LP
139 More complex filter expressions are built up by using the words
140 .BR and ,
141 .B or
142 and
143 .B not
144 (or equivalently: `\fB&&\fP', `\fB||\fP' and `\fB!\fP' respectively)
145 to combine primitives.
146 E.g., `\fBhost\fP foo \fBand not port\fP ftp \fBand not port\fP ftp-data'.
147 To save typing, identical qualifier lists can be omitted.
148 E.g.,
149 `\fBtcp dst port\fP ftp \fBor\fP ftp-data \fBor\fP domain' is exactly the same as
150 `\fBtcp dst port\fP ftp \fBor tcp dst port\fP ftp-data \fBor tcp dst port\fP domain'.
151 .LP
152 Allowable primitives are:
153 .IP "\fBdst host \fIhost\fR"
154 True if the IPv4/v6 destination field of the packet is \fIhost\fP,
155 which may be either an address or a name.
156 .IP "\fBsrc host \fIhost\fR"
157 True if the IPv4/v6 source field of the packet is \fIhost\fP.
158 .IP "\fBhost \fIhost\fP"
159 True if either the IPv4/v6 source or destination of the packet is \fIhost\fP.
160 .IP
161 Any of the above host expressions can be prepended with the keywords,
162 \fBip\fP, \fBarp\fP, \fBrarp\fP, or \fBip6\fP as in:
163 .in +.5i
164 .nf
165 \fBip host \fIhost\fR
166 .fi
167 .in -.5i
168 which is equivalent to:
169 .in +.5i
170 .nf
171 \fBether proto \\ip and host \fIhost\fR
172 .fi
173 .in -.5i
174 If \fIhost\fR is a name with multiple IPv4 addresses, each address will
175 be checked for a match.
176 .IP "\fBether dst \fIehost\fP"
177 True if the Ethernet destination address is \fIehost\fP.
178 \fIEhost\fP
179 may be either a name from /etc/ethers or a numerical MAC address of the
180 form "xx:xx:xx:xx:xx:xx", "xx.xx.xx.xx.xx.xx", "xx-xx-xx-xx-xx-xx",
181 "xxxx.xxxx.xxxx", "xxxxxxxxxxxx", or various mixes of ':', '.', and '-',
182 where each "x" is a hex digit (0-9, a-f, or A-F).
183 .IP "\fBether src \fIehost\fP"
184 True if the Ethernet source address is \fIehost\fP.
185 .IP "\fBether host \fIehost\fP"
186 True if either the Ethernet source or destination address is \fIehost\fP.
187 .IP "\fBgateway\fP \fIhost\fP"
188 True if the packet used \fIhost\fP as a gateway.
189 I.e., the Ethernet
190 source or destination address was \fIhost\fP but neither the IP source
191 nor the IP destination was \fIhost\fP.
192 \fIHost\fP must be a name and
193 must be found both by the machine's host-name-to-IP-address resolution
194 mechanisms (host name file, DNS, NIS, etc.) and by the machine's
195 host-name-to-Ethernet-address resolution mechanism (/etc/ethers, etc.).
196 (An equivalent expression is
197 .in +.5i
198 .nf
199 \fBether host \fIehost \fBand not host \fIhost\fR
200 .fi
201 .in -.5i
202 which can be used with either names or numbers for \fIhost / ehost\fP.)
203 This syntax does not work in IPv6-enabled configuration at this moment.
204 .IP "\fBdst net \fInet\fR"
205 True if the IPv4/v6 destination address of the packet has a network
206 number of \fInet\fP.
207 \fINet\fP may be either a name from the networks database
208 (/etc/networks, etc.) or a network number.
209 An IPv4 network number can be written as a dotted quad (e.g., 192.168.1.0),
210 dotted triple (e.g., 192.168.1), dotted pair (e.g, 172.16), or single
211 number (e.g., 10); the netmask is 255.255.255.255 for a dotted quad
212 (which means that it's really a host match), 255.255.255.0 for a dotted
213 triple, 255.255.0.0 for a dotted pair, or 255.0.0.0 for a single number.
214 An IPv6 network number must be written out fully; the netmask is
215 ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network" matches are really always
216 host matches, and a network match requires a netmask length.
217 .IP "\fBsrc net \fInet\fR"
218 True if the IPv4/v6 source address of the packet has a network
219 number of \fInet\fP.
220 .IP "\fBnet \fInet\fR"
221 True if either the IPv4/v6 source or destination address of the packet has a network
222 number of \fInet\fP.
223 .IP "\fBnet \fInet\fR \fBmask \fInetmask\fR"
224 True if the IPv4 address matches \fInet\fR with the specific \fInetmask\fR.
225 May be qualified with \fBsrc\fR or \fBdst\fR.
226 Note that this syntax is not valid for IPv6 \fInet\fR.
227 .IP "\fBnet \fInet\fR/\fIlen\fR"
228 True if the IPv4/v6 address matches \fInet\fR with a netmask \fIlen\fR
229 bits wide.
230 May be qualified with \fBsrc\fR or \fBdst\fR.
231 .IP "\fBdst port \fIport\fR"
232 True if the packet is IPv4/v6 TCP, UDP or SCTP and has a
233 destination port value of \fIport\fP.
234 The \fIport\fP can be a number or a name used in /etc/services (see
235 .BR tcp (4P)
236 and
237 .BR udp (4P)).
238 If a name is used, both the port
239 number and protocol are checked.
240 If a number or ambiguous name is used,
241 only the port number is checked (e.g., `\fBdst port\fR 513' will print both
242 tcp/login traffic and udp/who traffic, and `\fBport domain\fR' will print
243 both tcp/domain and udp/domain traffic).
244 .IP "\fBsrc port \fIport\fR"
245 True if the packet has a source port value of \fIport\fP.
246 .IP "\fBport \fIport\fR"
247 True if either the source or destination port of the packet is \fIport\fP.
248 .IP "\fBdst portrange \fIport1-port2\fR"
249 True if the packet is IPv4/v6 TCP, UDP or SCTP and has a
250 destination port value between \fIport1\fP and \fIport2\fP (both inclusive).
251 .I port1
252 and
253 .I port2
254 are interpreted in the same fashion as the
255 .I port
256 parameter for
257 .BR port .
258 .IP "\fBsrc portrange \fIport1-port2\fR"
259 True if the packet has a source port value between \fIport1\fP and
260 \fIport2\fP (both inclusive).
261 .IP "\fBportrange \fIport1-port2\fR"
262 True if either the source or destination port of the packet is between
263 \fIport1\fP and \fIport2\fP (both inclusive).
264 .IP
265 Any of the above port or port range expressions can be prepended with
266 the keywords, \fBtcp\fP, \fBudp\fP or \fBsctp\fP, as in:
267 .in +.5i
268 .nf
269 \fBtcp src port \fIport\fR
270 .fi
271 .in -.5i
272 which matches only TCP packets whose source port is \fIport\fP.
273 .IP "\fBless \fIlength\fR"
274 True if the packet has a length less than or equal to \fIlength\fP.
275 This is equivalent to:
276 .in +.5i
277 .nf
278 \fBlen <= \fIlength\fP
279 .fi
280 .in -.5i
281 .IP "\fBgreater \fIlength\fR"
282 True if the packet has a length greater than or equal to \fIlength\fP.
283 This is equivalent to:
284 .in +.5i
285 .nf
286 \fBlen >= \fIlength\fP
287 .fi
288 .in -.5i
289 .IP "\fBip proto \fIprotocol\fR"
290 True if the packet is an IPv4 packet (see
291 .BR ip (4P))
292 of protocol type \fIprotocol\fP.
293 \fIProtocol\fP can be a number or one of the names
294 \fBicmp\fP, \fBicmp6\fP, \fBigmp\fP, \fBigrp\fP, \fBpim\fP, \fBah\fP,
295 \fBesp\fP, \fBvrrp\fP, \fBsctp\fP, \fBudp\fP, or \fBtcp\fP.
296 Note that the identifiers \fBtcp\fP, \fBudp\fP, \fBsctp\fP and \fBicmp\fP
297 are also keywords and must be escaped via backslash (\\).
298 Note that this primitive does not chase the protocol header chain.
299 .IP "\fBip6 proto \fIprotocol\fR"
300 True if the packet is an IPv6 packet of protocol type \fIprotocol\fP.
301 Note that this primitive does not chase the protocol header chain.
302 .IP "\fBproto \fIprotocol\fR"
303 True if the packet is an IPv4 or IPv6 packet of protocol type
304 \fIprotocol\fP. Note that this primitive does not chase the protocol
305 header chain.
306 .IP "\fBtcp\fR, \fBudp\fR, \fBicmp\fR, \fBsctp\fR"
307 Abbreviations for:
308 .in +.5i
309 .nf
310 \fBproto \\\fIprotocol\fR
311 .fi
312 .in -.5i
313 where \fIprotocol\fR is one of the above protocols.
314 .IP "\fBip6 protochain \fIprotocol\fR"
315 True if the packet is IPv6 packet,
316 and contains protocol header with type \fIprotocol\fR
317 in its protocol header chain.
318 For example,
319 .in +.5i
320 .nf
321 \fBip6 protochain\fR 6
322 .fi
323 .in -.5i
324 matches any IPv6 packet with TCP protocol header in the protocol header chain.
325 The packet may contain, for example,
326 authentication header, routing header, or hop-by-hop option header,
327 between IPv6 header and TCP header.
328 The BPF code emitted by this primitive is complex and
329 cannot be optimized by the BPF optimizer code, and is not supported by
330 filter engines in the kernel, so this can be somewhat slow, and may
331 cause more packets to be dropped.
332 .IP "\fBip protochain \fIprotocol\fR"
333 Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
334 .IP "\fBprotochain \fIprotocol\fR"
335 True if the packet is an IPv4 or IPv6 packet of protocol type
336 \fIprotocol\fP. Note that this primitive chases the protocol
337 header chain.
338 .IP "\fBether broadcast\fR"
339 True if the packet is an Ethernet broadcast packet.
340 The \fBether\fP
341 keyword is optional.
342 .IP "\fBip broadcast\fR"
343 True if the packet is an IPv4 broadcast packet.
344 It checks for both the all-zeroes and all-ones broadcast conventions,
345 and looks up the subnet mask on the interface on which the capture is
346 being done.
347 .IP
348 If the subnet mask of the interface on which the capture is being done
349 is not available, either because the interface on which capture is being
350 done has no netmask or because the capture is being done on the Linux
351 "any" interface, which can capture on more than one interface, this
352 check will not work correctly.
353 .IP "\fBether multicast\fR"
354 True if the packet is an Ethernet multicast packet.
355 The \fBether\fP
356 keyword is optional.
357 This is shorthand for `\fBether[\fP0\fB] & \fP1\fB != \fP0'.
358 .IP "\fBip multicast\fR"
359 True if the packet is an IPv4 multicast packet.
360 .IP "\fBip6 multicast\fR"
361 True if the packet is an IPv6 multicast packet.
362 .IP "\fBether proto \fIprotocol\fR"
363 True if the packet is of ether type \fIprotocol\fR.
364 \fIProtocol\fP can be a number or one of the names
365 \fBaarp\fP, \fBarp\fP, \fBatalk\fP, \fBdecnet\fP, \fBip\fP, \fBip6\fP,
366 \fBipx\fP, \fBiso\fP, \fBlat\fP, \fBloopback\fP, \fBmopdl\fP, \fBmoprc\fP, \fBnetbeui\fP,
367 \fBrarp\fP, \fBsca\fP or \fBstp\fP.
368 Note these identifiers (except \fBloopback\fP) are also keywords
369 and must be escaped via backslash (\\).
370 .IP
371 [In the case of FDDI (e.g., `\fBfddi proto \\arp\fR'), Token Ring
372 (e.g., `\fBtr proto \\arp\fR'), and IEEE 802.11 wireless LANs (e.g.,
373 `\fBwlan proto \\arp\fR'), for most of those protocols, the
374 protocol identification comes from the 802.2 Logical Link Control (LLC)
375 header, which is usually layered on top of the FDDI, Token Ring, or
376 802.11 header.
377 .IP
378 When filtering for most protocol identifiers on FDDI, Token Ring, or
379 802.11, the filter checks only the protocol ID field of an LLC header
380 in so-called SNAP format with an Organizational Unit Identifier (OUI) of
381 0x000000, for encapsulated Ethernet; it doesn't check whether the packet
382 is in SNAP format with an OUI of 0x000000.
383 The exceptions are:
384 .RS
385 .TP
386 \fBiso\fP
387 the filter checks the DSAP (Destination Service Access Point) and
388 SSAP (Source Service Access Point) fields of the LLC header;
389 .TP
390 \fBstp\fP and \fBnetbeui\fP
391 the filter checks the DSAP of the LLC header;
392 .TP
393 \fBatalk\fP
394 the filter checks for a SNAP-format packet with an OUI of 0x080007
395 and the AppleTalk etype.
396 .RE
397 .IP
398 In the case of Ethernet, the filter checks the Ethernet type field
399 for most of those protocols. The exceptions are:
400 .RS
401 .TP
402 \fBiso\fP, \fBstp\fP, and \fBnetbeui\fP
403 the filter checks for an 802.3 frame and then checks the LLC header as
404 it does for FDDI, Token Ring, and 802.11;
405 .TP
406 \fBatalk\fP
407 the filter checks both for the AppleTalk etype in an Ethernet frame and
408 for a SNAP-format packet as it does for FDDI, Token Ring, and 802.11;
409 .TP
410 \fBaarp\fP
411 the filter checks for the AppleTalk ARP etype in either an Ethernet
412 frame or an 802.2 SNAP frame with an OUI of 0x000000;
413 .TP
414 \fBipx\fP
415 the filter checks for the IPX etype in an Ethernet frame, the IPX
416 DSAP in the LLC header, the 802.3-with-no-LLC-header encapsulation of
417 IPX, and the IPX etype in a SNAP frame.
418 .RE
419 .IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fBnetbeui\fP"
420 Abbreviations for:
421 .in +.5i
422 .nf
423 \fBether proto \\\fIprotocol\fR
424 .fi
425 .in -.5i
426 where \fIprotocol\fR is one of the above protocols.
427 .IP "\fBlat\fR, \fBmoprc\fR, \fBmopdl\fR"
428 Abbreviations for:
429 .in +.5i
430 .nf
431 \fBether proto \\\fIprotocol\fR
432 .fi
433 .in -.5i
434 where \fIprotocol\fR is one of the above protocols.
435 Note that not all applications using
436 .BR pcap (3PCAP)
437 currently know how to parse these protocols.
438 .IP "\fBdecnet src \fIhost\fR"
439 True if the DECnet source address is
440 .IR host ,
441 which may be an address of the form ``10.123'', or a DECnet host
442 name.
443 [DECnet host name support is only available on ULTRIX systems
444 that are configured to run DECnet.]
445 .IP "\fBdecnet dst \fIhost\fR"
446 True if the DECnet destination address is
447 .IR host .
448 .IP "\fBdecnet host \fIhost\fR"
449 True if either the DECnet source or destination address is
450 .IR host .
451 .IP \fBllc\fP
452 True if the packet has an 802.2 LLC header. This includes:
453 .IP
454 Ethernet packets with a length field rather than a type field that
455 aren't raw NetWare-over-802.3 packets;
456 .IP
457 IEEE 802.11 data packets;
458 .IP
459 Token Ring packets (no check is done for LLC frames);
460 .IP
461 FDDI packets (no check is done for LLC frames);
462 .IP
463 LLC-encapsulated ATM packets, for SunATM on Solaris.
464 .IP "\fBllc\fP \fItype\fR"
465 True if the packet has an 802.2 LLC header and has the specified
466 .IR type .
467 .I type
468 can be one of:
469 .RS
470 .TP
471 \fBi\fR
472 Information (I) PDUs
473 .TP
474 \fBs\fR
475 Supervisory (S) PDUs
476 .TP
477 \fBu\fR
478 Unnumbered (U) PDUs
479 .TP
480 \fBrr\fR
481 Receiver Ready (RR) S PDUs
482 .TP
483 \fBrnr\fR
484 Receiver Not Ready (RNR) S PDUs
485 .TP
486 \fBrej\fR
487 Reject (REJ) S PDUs
488 .TP
489 \fBui\fR
490 Unnumbered Information (UI) U PDUs
491 .TP
492 \fBua\fR
493 Unnumbered Acknowledgment (UA) U PDUs
494 .TP
495 \fBdisc\fR
496 Disconnect (DISC) U PDUs
497 .TP
498 \fBsabme\fR
499 Set Asynchronous Balanced Mode Extended (SABME) U PDUs
500 .TP
501 \fBtest\fR
502 Test (TEST) U PDUs
503 .TP
504 \fBxid\fR
505 Exchange Identification (XID) U PDUs
506 .TP
507 \fBfrmr\fR
508 Frame Reject (FRMR) U PDUs
509 .RE
510 .IP \fBinbound\fP
511 Packet was received by the host performing the capture rather than being
512 sent by that host. This is only supported for certain link-layer types,
513 such as SLIP and the ``cooked'' Linux capture mode
514 used for the ``any'' device and for some other device types.
515 .IP \fBoutbound\fP
516 Packet was sent by the host performing the capture rather than being
517 received by that host. This is only supported for certain link-layer types,
518 such as SLIP and the ``cooked'' Linux capture mode
519 used for the ``any'' device and for some other device types.
520 .IP "\fBifname \fIinterface\fR"
521 True if the packet was logged as coming from the specified interface (applies
522 only to packets logged by OpenBSD's or FreeBSD's
523 .BR pf (4)).
524 .IP "\fBon \fIinterface\fR"
525 Synonymous with the
526 .B ifname
527 modifier.
528 .IP "\fBrnr \fInum\fR"
529 True if the packet was logged as matching the specified PF rule number
530 (applies only to packets logged by OpenBSD's or FreeBSD's
531 .BR pf (4)).
532 .IP "\fBrulenum \fInum\fR"
533 Synonymous with the
534 .B rnr
535 modifier.
536 .IP "\fBreason \fIcode\fR"
537 True if the packet was logged with the specified PF reason code. The known
538 codes are:
539 .BR match ,
540 .BR bad-offset ,
541 .BR fragment ,
542 .BR short ,
543 .BR normalize ,
544 and
545 .B memory
546 (applies only to packets logged by OpenBSD's or FreeBSD's
547 .BR pf (4)).
548 .IP "\fBrset \fIname\fR"
549 True if the packet was logged as matching the specified PF ruleset
550 name of an anchored ruleset (applies only to packets logged by OpenBSD's
551 or FreeBSD's
552 .BR pf (4)).
553 .IP "\fBruleset \fIname\fR"
554 Synonymous with the
555 .B rset
556 modifier.
557 .IP "\fBsrnr \fInum\fR"
558 True if the packet was logged as matching the specified PF rule number
559 of an anchored ruleset (applies only to packets logged by OpenBSD's or
560 FreeBSD's
561 .BR pf (4)).
562 .IP "\fBsubrulenum \fInum\fR"
563 Synonymous with the
564 .B srnr
565 modifier.
566 .IP "\fBaction \fIact\fR"
567 True if PF took the specified action when the packet was logged. Known actions
568 are:
569 .B pass
570 and
571 .B block
572 and, with later versions of
573 .BR pf (4),
574 .BR nat ,
575 .BR rdr ,
576 .B binat
577 and
578 .B scrub
579 (applies only to packets logged by OpenBSD's or FreeBSD's
580 .BR pf (4)).
581 .IP "\fBwlan ra \fIehost\fR"
582 True if the IEEE 802.11 RA is
583 .IR ehost .
584 The RA field is used in all frames except for management frames.
585 .IP "\fBwlan ta \fIehost\fR"
586 True if the IEEE 802.11 TA is
587 .IR ehost .
588 The TA field is used in all frames except for management frames and
589 CTS (Clear To Send) and ACK (Acknowledgment) control frames.
590 .IP "\fBwlan addr1 \fIehost\fR"
591 True if the first IEEE 802.11 address is
592 .IR ehost .
593 .IP "\fBwlan addr2 \fIehost\fR"
594 True if the second IEEE 802.11 address, if present, is
595 .IR ehost .
596 The second address field is used in all frames except for CTS (Clear To
597 Send) and ACK (Acknowledgment) control frames.
598 .IP "\fBwlan addr3 \fIehost\fR"
599 True if the third IEEE 802.11 address, if present, is
600 .IR ehost .
601 The third address field is used in management and data frames, but not
602 in control frames.
603 .IP "\fBwlan addr4 \fIehost\fR"
604 True if the fourth IEEE 802.11 address, if present, is
605 .IR ehost .
606 The fourth address field is only used for
607 WDS (Wireless Distribution System) frames.
608 .IP "\fBtype \fIwlan_type\fR"
609 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR.
610 Valid \fIwlan_type\fRs are:
611 \fBmgt\fP,
612 \fBctl\fP
613 and \fBdata\fP.
614 .IP "\fBtype \fIwlan_type \fBsubtype \fIwlan_subtype\fR"
615 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR
616 and frame subtype matches the specified \fIwlan_subtype\fR.
617 .IP
618 If the specified \fIwlan_type\fR is \fBmgt\fP,
619 then valid \fIwlan_subtype\fRs are:
620 \fBassoc-req\fP,
621 \fBassoc-resp\fP,
622 \fBreassoc-req\fP,
623 \fBreassoc-resp\fP,
624 \fBprobe-req\fP,
625 \fBprobe-resp\fP,
626 \fBbeacon\fP,
627 \fBatim\fP,
628 \fBdisassoc\fP,
629 \fBauth\fP and
630 \fBdeauth\fP.
631 .IP
632 If the specified \fIwlan_type\fR is \fBctl\fP,
633 then valid \fIwlan_subtype\fRs are:
634 \fBps-poll\fP,
635 \fBrts\fP,
636 \fBcts\fP,
637 \fBack\fP,
638 \fBcf-end\fP and
639 \fBcf-end-ack\fP.
640 .IP
641 If the specified \fIwlan_type\fR is \fBdata\fP,
642 then valid \fIwlan_subtype\fRs are:
643 \fBdata\fP,
644 \fBdata-cf-ack\fP,
645 \fBdata-cf-poll\fP,
646 \fBdata-cf-ack-poll\fP,
647 \fBnull\fP,
648 \fBcf-ack\fP,
649 \fBcf-poll\fP,
650 \fBcf-ack-poll\fP,
651 \fBqos-data\fP,
652 \fBqos-data-cf-ack\fP,
653 \fBqos-data-cf-poll\fP,
654 \fBqos-data-cf-ack-poll\fP,
655 \fBqos\fP,
656 \fBqos-cf-poll\fP and
657 \fBqos-cf-ack-poll\fP.
658 .IP "\fBsubtype \fIwlan_subtype\fR"
659 True if the IEEE 802.11 frame subtype matches the specified \fIwlan_subtype\fR
660 and frame has the type to which the specified \fIwlan_subtype\fR belongs.
661 .IP "\fBdir \fIdir\fR"
662 True if the IEEE 802.11 frame direction matches the specified
663 .IR dir .
664 Valid directions are:
665 .BR nods ,
666 .BR tods ,
667 .BR fromds ,
668 .BR dstods ,
669 or a numeric value.
670 .IP "\fBvlan \fI[vlan_id]\fR"
671 True if the packet is an IEEE 802.1Q VLAN packet.
672 If the optional \fIvlan_id\fR is specified, only true if the packet has the specified
673 \fIvlan_id\fR.
674 Note that the first \fBvlan\fR keyword encountered in an expression
675 changes the decoding offsets for the remainder of the expression on
676 the assumption that the packet is a VLAN packet. The `\fBvlan
677 \fI[vlan_id]\fR` keyword may be used more than once, to filter on VLAN
678 hierarchies. Each use of that keyword increments the filter offsets
679 by 4.
680 .IP
681 For example:
682 .in +.5i
683 .nf
684 \fBvlan\fP 100 \fB&& vlan\fR 200
685 .fi
686 .in -.5i
687 filters on VLAN 200 encapsulated within VLAN 100, and
688 .in +.5i
689 .nf
690 \fBvlan && vlan \fP300 \fB&& ip\fR
691 .fi
692 .in -.5i
693 filters IPv4 protocol encapsulated in VLAN 300 encapsulated within any
694 higher order VLAN.
695 .IP "\fBmpls \fI[label_num]\fR"
696 True if the packet is an MPLS packet.
697 If the optional \fIlabel_num\fR is specified, only true if the packet has the specified
698 \fIlabel_num\fR.
699 Note that the first \fBmpls\fR keyword encountered in an expression
700 changes the decoding offsets for the remainder of the expression on
701 the assumption that the packet is a MPLS-encapsulated IP packet. The
702 `\fBmpls \fI[label_num]\fR` keyword may be used more than once, to
703 filter on MPLS hierarchies. Each use of that keyword increments the
704 filter offsets by 4.
705 .IP
706 For example:
707 .in +.5i
708 .nf
709 \fBmpls\fP 100000 \fB&& mpls\fR 1024
710 .fi
711 .in -.5i
712 filters packets with an outer label of 100000 and an inner label of
713 1024, and
714 .in +.5i
715 .nf
716 \fBmpls && mpls\fP 1024 \fB&& host\fR 192.9.200.1
717 .fi
718 .in -.5i
719 filters packets to or from 192.9.200.1 with an inner label of 1024 and
720 any outer label.
721 .IP \fBpppoed\fP
722 True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet
723 type 0x8863).
724 .IP "\fBpppoes \fI[session_id]\fR"
725 True if the packet is a PPP-over-Ethernet Session packet (Ethernet
726 type 0x8864).
727 If the optional \fIsession_id\fR is specified, only true if the packet has the specified
728 \fIsession_id\fR.
729 Note that the first \fBpppoes\fR keyword encountered in an expression
730 changes the decoding offsets for the remainder of the expression on
731 the assumption that the packet is a PPPoE session packet.
732 .IP
733 For example:
734 .in +.5i
735 .nf
736 \fBpppoes\fP 0x27 \fB&& ip\fR
737 .fi
738 .in -.5i
739 filters IPv4 protocol encapsulated in PPPoE session id 0x27.
740 .IP "\fBgeneve \fI[vni]\fR"
741 True if the packet is a Geneve packet (UDP port 6081). If the optional \fIvni\fR
742 is specified, only true if the packet has the specified \fIvni\fR.
743 Note that when the \fBgeneve\fR keyword is encountered in
744 an expression, it changes the decoding offsets for the remainder of
745 the expression on the assumption that the packet is a Geneve packet.
746 .IP
747 For example:
748 .in +.5i
749 .nf
750 \fBgeneve\fP 0xb \fB&& ip\fR
751 .fi
752 .in -.5i
753 filters IPv4 protocol encapsulated in Geneve with VNI 0xb. This will
754 match both IPv4 directly encapsulated in Geneve as well as IPv4 contained
755 inside an Ethernet frame.
756 .IP "\fBiso proto \fIprotocol\fR"
757 True if the packet is an OSI packet of protocol type \fIprotocol\fP.
758 \fIProtocol\fP can be a number or one of the names
759 \fBclnp\fP, \fBesis\fP, or \fBisis\fP.
760 .IP "\fBclnp\fR, \fBesis\fR, \fBisis\fR"
761 Abbreviations for:
762 .in +.5i
763 .nf
764 \fBiso proto \\\fIprotocol\fR
765 .fi
766 .in -.5i
767 where \fIprotocol\fR is one of the above protocols.
768 .IP "\fBl1\fR, \fBl2\fR, \fBiih\fR, \fBlsp\fR, \fBsnp\fR, \fBcsnp\fR, \fBpsnp\fR"
769 Abbreviations for IS-IS PDU types.
770 .IP "\fBvpi\fP \fIn\fR"
771 True if the packet is an ATM packet, for SunATM on Solaris, with a
772 virtual path identifier of
773 .IR n .
774 .IP "\fBvci\fP \fIn\fR"
775 True if the packet is an ATM packet, for SunATM on Solaris, with a
776 virtual channel identifier of
777 .IR n .
778 .IP \fBlane\fP
779 True if the packet is an ATM packet, for SunATM on Solaris, and is
780 an ATM LANE packet.
781 Note that the first \fBlane\fR keyword encountered in an expression
782 changes the tests done in the remainder of the expression
783 on the assumption that the packet is either a LANE emulated Ethernet
784 packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the
785 tests are done under the assumption that the packet is an
786 LLC-encapsulated packet.
787 .IP \fBoamf4s\fP
788 True if the packet is an ATM packet, for SunATM on Solaris, and is
789 a segment OAM F4 flow cell (VPI=0 & VCI=3).
790 .IP \fBoamf4e\fP
791 True if the packet is an ATM packet, for SunATM on Solaris, and is
792 an end-to-end OAM F4 flow cell (VPI=0 & VCI=4).
793 .IP \fBoamf4\fP
794 True if the packet is an ATM packet, for SunATM on Solaris, and is
795 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
796 .IP \fBoam\fP
797 True if the packet is an ATM packet, for SunATM on Solaris, and is
798 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
799 .IP \fBmetac\fP
800 True if the packet is an ATM packet, for SunATM on Solaris, and is
801 on a meta signaling circuit (VPI=0 & VCI=1).
802 .IP \fBbcc\fP
803 True if the packet is an ATM packet, for SunATM on Solaris, and is
804 on a broadcast signaling circuit (VPI=0 & VCI=2).
805 .IP \fBsc\fP
806 True if the packet is an ATM packet, for SunATM on Solaris, and is
807 on a signaling circuit (VPI=0 & VCI=5).
808 .IP \fBilmic\fP
809 True if the packet is an ATM packet, for SunATM on Solaris, and is
810 on an ILMI circuit (VPI=0 & VCI=16).
811 .IP \fBconnectmsg\fP
812 True if the packet is an ATM packet, for SunATM on Solaris, and is
813 on a signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
814 Connect Ack, Release, or Release Done message.
815 .IP \fBmetaconnect\fP
816 True if the packet is an ATM packet, for SunATM on Solaris, and is
817 on a meta signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
818 Release, or Release Done message.
819 .IP "\fIexpr relop expr\fR"
820 True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =
821 or ==, !=, and \fIexpr\fR is an arithmetic expression composed of integer
822 constants (expressed in standard C syntax), the normal binary operators
823 [+, -, *, /, %, &, |, ^, <<, >>], a length operator, and special packet data
824 accessors. Note that all comparisons are unsigned, so that, for example,
825 0x80000000 and 0xffffffff are > 0.
826 .IP
827 The % and ^ operators are currently only supported for filtering in the
828 kernel on Linux with 3.7 and later kernels; on all other systems, if
829 those operators are used, filtering will be done in user mode, which
830 will increase the overhead of capturing packets and may cause more
831 packets to be dropped.
832 .IP
833 To access data inside the packet, use the following syntax:
834 .in +.5i
835 .nf
836 \fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR
837 .fi
838 .in -.5i
839 \fIProto\fR is one of \fBether, fddi, tr, wlan, ppp, slip, link,
840 ip, arp, rarp, tcp, udp, sctp, icmp, ip6\fR or \fBradio\fR, and
841 indicates the protocol layer for the index operation.
842 (\fBether, fddi, wlan, tr, ppp, slip\fR and \fBlink\fR all refer to the
843 link layer. \fBradio\fR refers to the "radio header" added to some
844 802.11 captures.)
845 Note that \fBtcp\fR, \fBudp\fR and other upper-layer protocol types only
846 apply to IPv4, not IPv6 (this will be fixed in the future).
847 The byte offset, relative to the indicated protocol layer, is
848 given by \fIexpr\fR.
849 \fISize\fR is optional and indicates the number of bytes in the
850 field of interest; it can be either one, two, or four, and defaults to one.
851 The length operator, indicated by the keyword \fBlen\fP, gives the
852 length of the packet.
853
854 For example, `\fBether[\fP0\fB] &\fP 1 \fB!=\fP 0' catches all multicast traffic.
855 The expression `\fBip[\fP0\fB] &\fP 0xf \fB!=\fP 5'
856 catches all IPv4 packets with options.
857 The expression
858 `\fBip[\fP6:2\fB] &\fP 0x1fff \fB=\fP 0'
859 catches only unfragmented IPv4 datagrams and frag zero of fragmented
860 IPv4 datagrams.
861 This check is implicitly applied to the \fBtcp\fP and \fBudp\fP
862 index operations.
863 For instance, \fBtcp[\fP0\fB]\fP always means the first
864 byte of the TCP \fIheader\fP, and never means the first byte of an
865 intervening fragment.
866
867 Some offsets and field values may be expressed as names rather than
868 as numeric values.
869 The following protocol header field offsets are
870 available: \fBicmptype\fP (ICMP type field), \fBicmp6type\fP (ICMPv6 type field),
871 \fBicmpcode\fP (ICMP code field), \fBicmp6code\fP (ICMPv6 code field) and
872 \fBtcpflags\fP (TCP flags field).
873
874 The following ICMP type field values are available: \fBicmp-echoreply\fP,
875 \fBicmp-unreach\fP, \fBicmp-sourcequench\fP, \fBicmp-redirect\fP,
876 \fBicmp-echo\fP, \fBicmp-routeradvert\fP, \fBicmp-routersolicit\fP,
877 \fBicmp-timxceed\fP, \fBicmp-paramprob\fP, \fBicmp-tstamp\fP,
878 \fBicmp-tstampreply\fP, \fBicmp-ireq\fP, \fBicmp-ireqreply\fP,
879 \fBicmp-maskreq\fP, \fBicmp-maskreply\fP.
880
881 The following ICMPv6 type fields are available: \fBicmp6-destinationrunreach\fP,
882 \fBicmp6-packettoobig\fP, \fBicmp6-timeexceeded\fP,
883 \fBicmp6-parameterproblem\fP, \fBicmp6-echo\fP,
884 \fBicmp6-echoreply\fP, \fBicmp6-multicastlistenerquery\fP,
885 \fBicmp6-multicastlistenerreportv1\fP, \fBicmp6-multicastlistenerdone\fP,
886 \fBicmp6-routersolicit\fP, \fBicmp6-routeradvert\fP,
887 \fBicmp6-neighborsolicit\fP, \fBicmp6-neighboradvert\fP, \fBicmp6-redirect\fP,
888 \fBicmp6-routerrenum\fP, \fBicmp6-nodeinformationquery\fP,
889 \fBicmp6-nodeinformationresponse\fP, \fBicmp6-ineighbordiscoverysolicit\fP,
890 \fBicmp6-ineighbordiscoveryadvert\fP, \fBicmp6-multicastlistenerreportv2\fP,
891 \fBicmp6-homeagentdiscoveryrequest\fP, \fBicmp6-homeagentdiscoveryreply\fP,
892 \fBicmp6-mobileprefixsolicit\fP, \fBicmp6-mobileprefixadvert\fP,
893 \fBicmp6-certpathsolicit\fP, \fBicmp6-certpathadvert\fP,
894 \fBicmp6-multicastrouteradvert\fP, \fBicmp6-multicastroutersolicit\fP,
895 \fBicmp6-multicastrouterterm\fP.
896
897 The following TCP flags field values are available: \fBtcp-fin\fP,
898 \fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP,
899 \fBtcp-ack\fP, \fBtcp-urg\fP, \fBtcp-ece\fP,
900 \fBtcp-cwr\fP.
901 .LP
902 Primitives may be combined using:
903 .IP
904 A parenthesized group of primitives and operators.
905 .IP
906 Negation (`\fB!\fP' or `\fBnot\fP').
907 .IP
908 Concatenation (`\fB&&\fP' or `\fBand\fP').
909 .IP
910 Alternation (`\fB||\fP' or `\fBor\fP').
911 .LP
912 Negation has the highest precedence.
913 Alternation and concatenation have equal precedence and associate
914 left to right.
915 Note that explicit \fBand\fR tokens, not juxtaposition,
916 are now required for concatenation.
917 .LP
918 If an identifier is given without a keyword, the most recent keyword
919 is assumed.
920 For example,
921 .in +.5i
922 .nf
923 \fBnot host\fP vs \fBand\fR ace
924 .fi
925 .in -.5i
926 is short for
927 .in +.5i
928 .nf
929 \fBnot host\fP vs \fBand host\fR ace
930 .fi
931 .in -.5i
932 which should not be confused with
933 .in +.5i
934 .nf
935 \fBnot (host \fPvs\fB or \fPace\fB)\fR
936 .fi
937 .in -.5i
938 .SH EXAMPLES
939 .LP
940 To select all packets arriving at or departing from `sundown':
941 .RS
942 .nf
943 \fBhost\fP sundown
944 .fi
945 .RE
946 .LP
947 To select traffic between `helios' and either `hot' or `ace':
948 .RS
949 .nf
950 \fBhost\fP helios \fBand (\fPhot \fBor\fP ace\fB)\fP
951 .fi
952 .RE
953 .LP
954 To select all IPv4 packets between `ace' and any host except `helios':
955 .RS
956 .nf
957 \fBip host\fP ace \fBand not\fP helios
958 .fi
959 .RE
960 .LP
961 To select all traffic between local hosts and hosts at Berkeley:
962 .RS
963 .nf
964 \fBnet\fP ucb-ether
965 .fi
966 .RE
967 .LP
968 To select all FTP traffic through Internet gateway `snup':
969 .RS
970 .nf
971 \fBgateway\fP snup \fBand (port\fP ftp \fBor\fP ftp-data\fB)\fP
972 .fi
973 .RE
974 .LP
975 To select IPv4 traffic neither sourced from nor destined for local hosts
976 (if you gateway to one other net, this stuff should never make it
977 onto your local net).
978 .RS
979 .nf
980 \fBip and not net \fPlocalnet
981 .fi
982 .RE
983 .LP
984 To select the start and end packets (the SYN and FIN packets) of each
985 TCP conversation that involves a non-local host.
986 .RS
987 .nf
988 \fBtcp[tcpflags] & (tcp-syn|tcp-fin) !=\fP 0 \fBand not src and dst net\fP localnet
989 .fi
990 .RE
991 .LP
992 To select the TCP packets with flags RST and ACK both set.
993 (i.e. select only the RST and ACK flags in the flags field, and if the result
994 is "RST and ACK both set", match)
995 .RS
996 .nf
997 .B
998 tcp[tcpflags] & (tcp-rst|tcp-ack) == (tcp-rst|tcp-ack)
999 .fi
1000 .RE
1001 .LP
1002 To select all IPv4 HTTP packets to and from port 80, i.e. print only
1003 packets that contain data, not, for example, SYN and FIN packets and
1004 ACK-only packets. (IPv6 is left as an exercise for the reader.)
1005 .RS
1006 .nf
1007 \fBtcp port\fP 80 \fBand (((ip[\fP2:2\fB] - ((ip[\fP0\fB]&\fP0xf\fB)<<\fP2\fB)) - ((tcp[\fP12\fB]&\fP0xf0\fB)>>\fP2\fB)) != \fP0\fB)
1008 .fi
1009 .RE
1010 .LP
1011 To select IPv4 packets longer than 576 bytes sent through gateway `snup':
1012 .RS
1013 .nf
1014 \fBgateway\fP snup \fBand ip[\fP2:2\fB] >\fP 576
1015 .fi
1016 .RE
1017 .LP
1018 To select IPv4 broadcast or multicast packets that were
1019 .I not
1020 sent via Ethernet broadcast or multicast:
1021 .RS
1022 .nf
1023 \fBether[\fP0\fB] &\fP 1 \fB=\fP 0 \fBand ip[\fP16\fB] >=\fP 224
1024 .fi
1025 .RE
1026 .LP
1027 To select all ICMP packets that are not echo requests/replies (i.e., not
1028 ping packets):
1029 .RS
1030 .nf
1031 .B
1032 icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
1033 .B
1034 icmp6[icmp6type] != icmp6-echo and icmp6[icmp6type] != icmp6-echoreply
1035 .fi
1036 .RE
1037 .SH SEE ALSO
1038 .BR pcap (3PCAP)
1039 .SH BUGS
1040 To report a security issue please send an e-mail to \%security@tcpdump.org.
1041 .LP
1042 To report bugs and other problems, contribute patches, request a
1043 feature, provide generic feedback etc please see the file
1044 .I CONTRIBUTING.md
1045 in the libpcap source tree root.
1046 .LP
1047 Filter expressions on fields other than those in Token Ring headers will
1048 not correctly handle source-routed Token Ring packets.
1049 .LP
1050 Filter expressions on fields other than those in 802.11 headers will not
1051 correctly handle 802.11 data packets with both To DS and From DS set.
1052 .LP
1053 `\fBip6 proto\fP'
1054 should chase header chain, but at this moment it does not.
1055 `\fBip6 protochain\fP'
1056 is supplied for this behavior. For example, to match IPv6 fragments:
1057 `\fBip6 protochain\fP 44'
1058 .LP
1059 Arithmetic expression against transport layer headers, like \fBtcp[0]\fP,
1060 does not work against IPv6 packets.
1061 It only looks at IPv4 packets.