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