1PCAP-FILTER(7)         Miscellaneous Information Manual         PCAP-FILTER(7)
2
3
4

NAME

6       pcap-filter - packet filter syntax
7

DESCRIPTION

9       pcap_compile(3PCAP)  is used to compile a string into a filter program.
10       The resulting filter program can then be  applied  to  some  stream  of
11       packets    to   determine   which   packets   will   be   supplied   to
12       pcap_loop(3PCAP),    pcap_dispatch(3PCAP),     pcap_next(3PCAP),     or
13       pcap_next_ex(3PCAP).
14
15       The  filter  expression consists of one or more primitives.  Primitives
16       usually consist of an id (name or number) preceded by one or more qual‐
17       ifiers.  There are three different kinds of qualifier:
18
19       type   type  qualifiers  say  what  kind of thing the id name or number
20              refers to.  Possible types are host, net,  port  and  portrange.
21              E.g., `host foo', `net 128.3', `port 20', `portrange 6000-6008'.
22              If there is no type qualifier, host is assumed.
23
24       dir    dir qualifiers specify a particular transfer direction to and/or
25              from  id.  Possible directions are src, dst, src or dst, src and
26              dst, ra, ta, addr1, addr2, addr3, and addr4.  E.g.,  `src  foo',
27              `dst net 128.3', `src or dst port ftp-data'.  If there is no dir
28              qualifier, `src or dst' is assumed.  The ra, ta,  addr1,  addr2,
29              addr3, and addr4 qualifiers are only valid for IEEE 802.11 Wire‐
30              less LAN link layers.
31
32       proto  proto qualifiers restrict the match to  a  particular  protocol.
33              Possible  protocols  are:  ether,  fddi, tr, wlan, ip, ip6, arp,
34              rarp, decnet, sctp, tcp and udp.  E.g., `ether  src  foo',  `arp
35              net  128.3',  `tcp  port  21',  `udp portrange 7000-7009', `wlan
36              addr2 0:2:3:4:5:6'.  If there is no proto qualifier, all  proto‐
37              cols  consistent  with  the  type  are assumed.  E.g., `src foo'
38              means `(ip or arp or rarp) src foo', `net bar' means `(ip or arp
39              or rarp) net bar' and `port 53' means `(tcp or udp or sctp) port
40              53' (note that these examples use invalid syntax  to  illustrate
41              the principle).
42
43       [fddi  is  actually  an alias for ether; the parser treats them identi‐
44       cally as meaning ``the data link level used on  the  specified  network
45       interface''.  FDDI headers contain Ethernet-like source and destination
46       addresses, and often contain Ethernet-like packet  types,  so  you  can
47       filter on these FDDI fields just as with the analogous Ethernet fields.
48       FDDI headers also contain other fields, but you cannot  name  them  ex‐
49       plicitly in a filter expression.
50
51       Similarly,  tr and wlan are aliases for ether; the previous paragraph's
52       statements about FDDI headers also apply to Token Ring and 802.11 wire‐
53       less  LAN  headers.  For 802.11 headers, the destination address is the
54       DA field and the source address is the SA field; the BSSID, RA, and  TA
55       fields aren't tested.]
56
57       In  addition  to the above, there are some special `primitive' keywords
58       that don't follow the pattern: gateway, broadcast,  less,  greater  and
59       arithmetic expressions.  All of these are described below.
60
61       More complex filter expressions are built up by using the words and, or
62       and not (or equivalently: `&&', `||' and `!' respectively)  to  combine
63       primitives.   E.g.,  `host foo and not port ftp and not port ftp-data'.
64       To save typing, identical qualifier lists can be omitted.   E.g.,  `tcp
65       dst  port  ftp  or  ftp-data or domain' is exactly the same as `tcp dst
66       port ftp or tcp dst port ftp-data or tcp dst port domain'.
67
68       Allowable primitives are:
69
70       dst host hostnameaddr
71              True if the IPv4/v6 destination field of  the  packet  is  host‐
72              nameaddr, which may be either an address or a name.
73
74       src host hostnameaddr
75              True if the IPv4/v6 source field of the packet is hostnameaddr.
76
77       host hostnameaddr
78              True  if  either the IPv4/v6 source or destination of the packet
79              is hostnameaddr.
80
81              Any of the above host expressions can be prepended with the key‐
82              words, ip, arp, rarp, or ip6 as in:
83                   ip host hostnameaddr
84              which is equivalent to:
85                   ether proto \ip and host hostnameaddr
86              If  hostnameaddr is a name with multiple IPv4/v6 addresses, each
87              address will be checked for a match.
88
89       ether dst ethernameaddr
90              True if the Ethernet destination address is ethernameaddr.  eth‐
91              ernameaddr  may be either a name from /etc/ethers or a numerical
92              MAC     address     of     the     form     "xx:xx:xx:xx:xx:xx",
93              "xx.xx.xx.xx.xx.xx",    "xx-xx-xx-xx-xx-xx",   "xxxx.xxxx.xxxx",
94              "xxxxxxxxxxxx", or various mixes of ':',  '.',  and  '-',  where
95              each "x" is a hex digit (0-9, a-f, or A-F).
96
97       ether src ethernameaddr
98              True if the Ethernet source address is ethernameaddr.
99
100       ether host ethernameaddr
101              True  if  either  the  Ethernet source or destination address is
102              ethernameaddr.
103
104       gateway host
105              True if the packet used host as a gateway.  I.e.,  the  Ethernet
106              source or destination address was host but neither the IP source
107              nor the IP destination was host.  Host must be a name  and  must
108              be  found  both by the machine's host-name-to-IP-address resolu‐
109              tion mechanisms (host name file, DNS, NIS, etc.) and by the  ma‐
110              chine's   host-name-to-Ethernet-address   resolution   mechanism
111              (/etc/ethers, etc.).  (An equivalent expression is
112                   ether host ethernameaddr and not host hostnameaddr
113              which can be used with either names or numbers for  hostnameaddr
114              /  ethernameaddr.)   This  syntax  does not work in IPv6-enabled
115              configuration at this moment.
116
117       dst net netnameaddr
118              True if the IPv4/v6 destination address of the packet has a net‐
119              work  number  of netnameaddr.  Net may be either a name from the
120              networks database (/etc/networks, etc.) or a network number.  An
121              IPv4  network  number  can  be  written  as a dotted quad (e.g.,
122              192.168.1.0), dotted triple (e.g., 192.168.1), dotted pair (e.g,
123              172.16),   or   single   number   (e.g.,  10);  the  netmask  is
124              255.255.255.255 for a dotted quad (which means that it's  really
125              a  host  match),  255.255.255.0 for a dotted triple, 255.255.0.0
126              for a dotted pair, or 255.0.0.0 for a single  number.   An  IPv6
127              network  number  must  be  written  out  fully;  the  netmask is
128              ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network"  matches  are  really
129              always  host  matches,  and  a  network match requires a netmask
130              length.
131
132       src net netnameaddr
133              True if the IPv4/v6 source address of the packet has  a  network
134              number of netnameaddr.
135
136       net netnameaddr
137              True  if either the IPv4/v6 source or destination address of the
138              packet has a network number of netnameaddr.
139
140       net netaddr mask netmask
141              True if the IPv4 address matches netaddr with the specific  net‐
142              mask.   May be qualified with src or dst.  Note that this syntax
143              is not valid for IPv6 netaddr.
144
145       net netaddr/len
146              True if the IPv4/v6 address matches netaddr with a  netmask  len
147              bits wide.  May be qualified with src or dst.
148
149       dst port portnamenum
150              True  if the packet is IPv4/v6 TCP, UDP or SCTP and has a desti‐
151              nation port value of portnamenum.  The portnamenum can be a num‐
152              ber  or  a name used in /etc/services (see tcp(4P) and udp(4P)).
153              If a name is  used,  both  the  port  number  and  protocol  are
154              checked.   If  a number or ambiguous name is used, only the port
155              number is checked (e.g., `dst port 513' will print both  tcp/lo‐
156              gin  traffic  and  udp/who traffic, and `port domain' will print
157              both tcp/domain and udp/domain traffic).
158
159       src port portnamenum
160              True if the packet has a source port value of portnamenum.
161
162       port portnamenum
163              True if either the source or destination port of the  packet  is
164              portnamenum.
165
166       dst portrange portnamenum1-portnamenum2
167              True  if the packet is IPv4/v6 TCP, UDP or SCTP and has a desti‐
168              nation port value between portnamenum1  and  portnamenum2  (both
169              inclusive).   portnamenum1  and  portnamenum2 are interpreted in
170              the same fashion as the portnamenum parameter for port.
171
172       src portrange portnamenum1-portnamenum2
173              True if the packet has a source port value between  portnamenum1
174              and portnamenum2 (both inclusive).
175
176       portrange portnamenum1-portnamenum2
177              True  if  either the source or destination port of the packet is
178              between portnamenum1 and portnamenum2 (both inclusive).
179
180              Any of the above port or port range expressions can be prepended
181              with the keywords, tcp, udp or sctp, as in:
182                   tcp src port portnamenum
183              which matches only TCP packets whose source port is portnamenum.
184
185       less length
186              True  if  the  packet has a length less than or equal to length.
187              This is equivalent to:
188                   len <= length
189
190       greater length
191              True if the packet has a length greater than or equal to length.
192              This is equivalent to:
193                   len >= length
194
195       ip proto protocol
196              True  if  the  packet is an IPv4 packet (see ip(4P)) of protocol
197              type protocol.  Protocol can be a number or  one  of  the  names
198              recognized  by  getprotobyname(3)  (as in e.g. `getent(1) proto‐
199              cols'), typically from an entry in /etc/protocols, for  example:
200              ah,  esp,  eigrp (only in Linux, FreeBSD, NetBSD, DragonFly BSD,
201              and macOS), icmp, igmp, igrp (only in OpenBSD), pim, sctp,  tcp,
202              udp  or  vrrp.   Note that most of these example identifiers are
203              also keywords and must be escaped via backslash (\).  Note  that
204              this primitive does not chase the protocol header chain.
205
206       icmp   Abbreviation for:
207                   ip proto 1
208
209       ip6 proto protocol
210              True  if the packet is an IPv6 packet of protocol type protocol.
211              (See `ip proto' above for the meaning of protocol.)   Note  that
212              the IPv6 variant of ICMP uses a different protocol number, named
213              ipv6-icmp in AIX, FreeBSD, illumos, Linux, macOS, NetBSD,  Open‐
214              BSD,  Solaris  and  Windows.   Note that this primitive does not
215              chase the protocol header chain.
216
217       icmp6  Abbreviation for:
218                   ip6 proto 58
219
220       proto protocol
221              True if the packet is an IPv4 or IPv6 packet  of  protocol  type
222              protocol.   (See  `ip proto' above for the meaning of protocol.)
223              Note that this primitive does  not  chase  the  protocol  header
224              chain.
225
226       ah, esp, pim, sctp, tcp, udp
227              Abbreviations for:
228                   proto \protocol
229              where protocol is one of the above protocols.
230
231       ip6 protochain protocol
232              True  if the packet is IPv6 packet, and contains protocol header
233              with type protocol in  its  protocol  header  chain.   (See  `ip
234              proto' above for the meaning of protocol.)  For example,
235                   ip6 protochain 6
236              matches any IPv6 packet with TCP protocol header in the protocol
237              header chain.  The packet may contain, for example,  authentica‐
238              tion  header,  routing  header, or hop-by-hop option header, be‐
239              tween IPv6 header and TCP header.  The BPF code emitted by  this
240              primitive  is  complex  and cannot be optimized by the BPF opti‐
241              mizer code, and is not supported by filter engines in  the  ker‐
242              nel, so this can be somewhat slow, and may cause more packets to
243              be dropped.
244
245       ip protochain protocol
246              Equivalent to ip6 protochain protocol, but  this  is  for  IPv4.
247              (See `ip proto' above for the meaning of protocol.)
248
249       protochain protocol
250              True  if  the  packet is an IPv4 or IPv6 packet of protocol type
251              protocol.  (See `ip proto' above for the meaning  of  protocol.)
252              Note that this primitive chases the protocol header chain.
253
254       ether broadcast
255              True  if  the packet is an Ethernet broadcast packet.  The ether
256              keyword is optional.
257
258       ip broadcast
259              True if the packet is an IPv4 broadcast packet.  It  checks  for
260              both  the  all-zeroes  and  all-ones  broadcast conventions, and
261              looks up the subnet mask on the interface on which  the  capture
262              is being done.
263
264              If  the subnet mask of the interface on which the capture is be‐
265              ing done is not available, either because the interface on which
266              capture  is  being done has no netmask or because the capture is
267              being done on the Linux "any" interface, which  can  capture  on
268              more than one interface, this check will not work correctly.
269
270       ether multicast
271              True  if  the packet is an Ethernet multicast packet.  The ether
272              keyword is optional.  This is shorthand for `ether[0] & 1 != 0'.
273
274       ip multicast
275              True if the packet is an IPv4 multicast packet.
276
277       ip6 multicast
278              True if the packet is an IPv6 multicast packet.
279
280       ether proto protocol
281              True if the packet is of ether type protocol.  Protocol can be a
282              number  or  one  of the names aarp, arp, atalk, decnet, ip, ip6,
283              ipx, iso, lat, loopback, mopdl, moprc,  netbeui,  rarp,  sca  or
284              stp.  Note these identifiers (except loopback) are also keywords
285              and must be escaped via backslash (\).
286
287              [In the case of FDDI  (e.g.,  `fddi  proto  \arp'),  Token  Ring
288              (e.g.,  `tr  proto  \arp'), and IEEE 802.11 wireless LANs (e.g.,
289              `wlan proto \arp'), for most of those  protocols,  the  protocol
290              identification  comes  from the 802.2 Logical Link Control (LLC)
291              header, which is usually layered on top of the FDDI, Token Ring,
292              or 802.11 header.
293
294              When  filtering  for  most  protocol  identifiers on FDDI, Token
295              Ring, or 802.11, the filter checks only the protocol ID field of
296              an  LLC  header  in so-called SNAP format with an Organizational
297              Unit Identifier (OUI) of 0x000000, for encapsulated Ethernet; it
298              doesn't  check  whether the packet is in SNAP format with an OUI
299              of 0x000000.  The exceptions are:
300
301              iso    the filter checks the DSAP  (Destination  Service  Access
302                     Point)  and  SSAP (Source Service Access Point) fields of
303                     the LLC header;
304
305              stp and netbeui
306                     the filter checks the DSAP of the LLC header;
307
308              atalk  the filter checks for a SNAP-format packet with an OUI of
309                     0x080007 and the AppleTalk etype.
310
311              In  the  case  of  Ethernet, the filter checks the Ethernet type
312              field for most of those protocols.  The exceptions are:
313
314              iso, stp, and netbeui
315                     the filter checks for an 802.3 frame and then checks  the
316                     LLC header as it does for FDDI, Token Ring, and 802.11;
317
318              atalk  the filter checks both for the AppleTalk etype in an Eth‐
319                     ernet frame and for a SNAP-format packet as it  does  for
320                     FDDI, Token Ring, and 802.11;
321
322              aarp   the  filter  checks for the AppleTalk ARP etype in either
323                     an Ethernet frame or an 802.2 SNAP frame with an  OUI  of
324                     0x000000;
325
326              ipx    the filter checks for the IPX etype in an Ethernet frame,
327                     the IPX DSAP in the LLC  header,  the  802.3-with-no-LLC-
328                     header  encapsulation of IPX, and the IPX etype in a SNAP
329                     frame.
330
331       ip, ip6, arp, rarp, atalk, aarp, decnet, iso, stp, ipx, netbeui
332              Abbreviations for:
333                   ether proto \protocol
334              where protocol is one of the above protocols.
335
336       lat, moprc, mopdl
337              Abbreviations for:
338                   ether proto \protocol
339              where protocol is one of the above protocols.  Note that not all
340              applications using pcap(3PCAP) currently know how to parse these
341              protocols.
342
343       decnet src decnetaddr
344              True if the DECnet source address is decnetaddr, which may be an
345              address  of the form ``10.123'', or a DECnet host name.  [DECnet
346              host name support is only available on ULTRIX systems  that  are
347              configured to run DECnet.]
348
349       decnet dst decnetaddr
350              True if the DECnet destination address is decnetaddr.
351
352       decnet host decnetaddr
353              True  if either the DECnet source or destination address is dec‐
354              netaddr.
355
356       llc    True if the packet has an 802.2 LLC header.  This includes:
357
358              Ethernet packets with a length field rather than  a  type  field
359              that aren't raw NetWare-over-802.3 packets;
360
361              IEEE 802.11 data packets;
362
363              Token Ring packets (no check is done for LLC frames);
364
365              FDDI packets (no check is done for LLC frames);
366
367              LLC-encapsulated ATM packets, for SunATM on Solaris.
368
369       llc type
370              True if the packet has an 802.2 LLC header and has the specified
371              type.  type can be one of:
372
373              i      Information (I) PDUs
374
375              s      Supervisory (S) PDUs
376
377              u      Unnumbered (U) PDUs
378
379              rr     Receiver Ready (RR) S PDUs
380
381              rnr    Receiver Not Ready (RNR) S PDUs
382
383              rej    Reject (REJ) S PDUs
384
385              ui     Unnumbered Information (UI) U PDUs
386
387              ua     Unnumbered Acknowledgment (UA) U PDUs
388
389              disc   Disconnect (DISC) U PDUs
390
391              sabme  Set Asynchronous Balanced Mode Extended (SABME) U PDUs
392
393              test   Test (TEST) U PDUs
394
395              xid    Exchange Identification (XID) U PDUs
396
397              frmr   Frame Reject (FRMR) U PDUs
398
399       inbound
400              Packet was received by the host performing  the  capture  rather
401              than  being  sent by that host.  This is only supported for cer‐
402              tain link-layer types, such as SLIP  and  the  ``cooked''  Linux
403              capture  mode used for the ``any'' device and for some other de‐
404              vice types.
405
406       outbound
407              Packet was sent by the host performing the capture  rather  than
408              being received by that host.  This is only supported for certain
409              link-layer types, such as SLIP and the ``cooked'' Linux  capture
410              mode  used  for  the  ``any''  device  and for some other device
411              types.
412
413       ifname interface
414              True if the packet was logged as coming from the  specified  in‐
415              terface  (applies  only  to packets logged by OpenBSD's or Free‐
416              BSD's pf(4)).
417
418       on interface
419              Synonymous with the ifname modifier.
420
421       rnr num
422              True if the packet was logged as matching the specified PF  rule
423              number (applies only to packets logged by OpenBSD's or FreeBSD's
424              pf(4)).
425
426       rulenum num
427              Synonymous with the rnr modifier.
428
429       reason code
430              True if the packet was logged with the specified PF reason code.
431              The   known  codes  are:  match,  bad-offset,  fragment,  short,
432              normalize, and memory (applies only to packets logged  by  Open‐
433              BSD's or FreeBSD's pf(4)).
434
435       rset name
436              True if the packet was logged as matching the specified PF rule‐
437              set name of an anchored ruleset (applies only to packets  logged
438              by OpenBSD's or FreeBSD's pf(4)).
439
440       ruleset name
441              Synonymous with the rset modifier.
442
443       srnr num
444              True  if the packet was logged as matching the specified PF rule
445              number of an anchored ruleset (applies only to packets logged by
446              OpenBSD's or FreeBSD's pf(4)).
447
448       subrulenum num
449              Synonymous with the srnr modifier.
450
451       action act
452              True if PF took the specified action when the packet was logged.
453              Known actions are: pass and block and, with  later  versions  of
454              pf(4), nat, rdr, binat and scrub (applies only to packets logged
455              by OpenBSD's or FreeBSD's pf(4)).
456
457       wlan ra ehost
458              True if the IEEE 802.11 RA is ehost.  The RA field  is  used  in
459              all frames except for management frames.
460
461       wlan ta ehost
462              True  if  the  IEEE 802.11 TA is ehost.  The TA field is used in
463              all frames except for management frames and CTS (Clear To  Send)
464              and ACK (Acknowledgment) control frames.
465
466       wlan addr1 ehost
467              True if the first IEEE 802.11 address is ehost.
468
469       wlan addr2 ehost
470              True  if  the  second IEEE 802.11 address, if present, is ehost.
471              The second address field is used in all frames  except  for  CTS
472              (Clear To Send) and ACK (Acknowledgment) control frames.
473
474       wlan addr3 ehost
475              True  if  the  third  IEEE 802.11 address, if present, is ehost.
476              The third address field is used in management and  data  frames,
477              but not in control frames.
478
479       wlan addr4 ehost
480              True  if  the  fourth IEEE 802.11 address, if present, is ehost.
481              The fourth address field is only used for WDS (Wireless  Distri‐
482              bution System) frames.
483
484       type wlan_type
485              True  if  the  IEEE  802.11  frame  type  matches  the specified
486              wlan_type.  Valid wlan_types are: mgt, ctl and data.
487
488       type wlan_type subtype wlan_subtype
489              True if  the  IEEE  802.11  frame  type  matches  the  specified
490              wlan_type and frame subtype matches the specified wlan_subtype.
491
492              If the specified wlan_type is mgt, then valid wlan_subtypes are:
493              assoc-req,  assoc-resp,  reassoc-req,  reassoc-resp,  probe-req,
494              probe-resp, beacon, atim, disassoc, auth and deauth.
495
496              If the specified wlan_type is ctl, then valid wlan_subtypes are:
497              ps-poll, rts, cts, ack, cf-end and cf-end-ack.
498
499              If the specified wlan_type is  data,  then  valid  wlan_subtypes
500              are:  data,  data-cf-ack,  data-cf-poll, data-cf-ack-poll, null,
501              cf-ack,   cf-poll,   cf-ack-poll,   qos-data,   qos-data-cf-ack,
502              qos-data-cf-poll,  qos-data-cf-ack-poll,  qos,  qos-cf-poll  and
503              qos-cf-ack-poll.
504
505       subtype wlan_subtype
506              True if the IEEE 802.11  frame  subtype  matches  the  specified
507              wlan_subtype  and  frame  has  the  type  to which the specified
508              wlan_subtype belongs.
509
510       dir direction
511              True if the IEEE 802.11 frame direction  matches  the  specified
512              direction.  Valid directions are: nods, tods, fromds, dstods, or
513              a numeric value.
514
515       vlan [vlan_id]
516              True if the packet is an IEEE 802.1Q VLAN packet.   If  the  op‐
517              tional  vlan_id  is  specified,  only true if the packet has the
518              specified vlan_id.  Note that the first vlan keyword encountered
519              in  an expression changes the decoding offsets for the remainder
520              of the expression on the assumption that the packet  is  a  VLAN
521              packet.   The  `vlan  [vlan_id]`  keyword  may be used more than
522              once, to filter on VLAN hierarchies.  Each use of  that  keyword
523              increments the filter offsets by 4.
524
525              For example:
526                   vlan 100 && vlan 200
527              filters on VLAN 200 encapsulated within VLAN 100, and
528                   vlan && vlan 300 && ip
529              filters  IPv4  protocol  encapsulated  in  VLAN 300 encapsulated
530              within any higher order VLAN.
531
532       mpls [label_num]
533              True if the packet is an MPLS packet.  If the optional label_num
534              is  specified,  only  true  if  the packet has the specified la‐
535              bel_num.  Note that the first mpls keyword encountered in an ex‐
536              pression  changes  the decoding offsets for the remainder of the
537              expression on the assumption that the packet is a  MPLS-encapsu‐
538              lated  IP  packet.   The  `mpls [label_num]` keyword may be used
539              more than once, to filter on MPLS hierarchies.  Each use of that
540              keyword increments the filter offsets by 4.
541
542              For example:
543                   mpls 100000 && mpls 1024
544              filters packets with an outer label of 100000 and an inner label
545              of 1024, and
546                   mpls && mpls 1024 && host 192.9.200.1
547              filters packets to or from 192.9.200.1 with an  inner  label  of
548              1024 and any outer label.
549
550       pppoed True if the packet is a PPP-over-Ethernet Discovery packet (Eth‐
551              ernet type 0x8863).
552
553       pppoes [session_id]
554              True if the packet is a PPP-over-Ethernet Session packet (Ether‐
555              net type 0x8864).  If the optional session_id is specified, only
556              true if the packet has the specified session_id.  Note that  the
557              first  pppoes  keyword  encountered in an expression changes the
558              decoding offsets for the remainder of the expression on the  as‐
559              sumption that the packet is a PPPoE session packet.
560
561              For example:
562                   pppoes 0x27 && ip
563              filters IPv4 protocol encapsulated in PPPoE session id 0x27.
564
565       geneve [vni]
566              True  if  the  packet is a Geneve packet (UDP port 6081). If the
567              optional vni is specified, only true if the packet has the spec‐
568              ified  vni.  Note that when the geneve keyword is encountered in
569              an expression, it changes the decoding offsets for the remainder
570              of  the expression on the assumption that the packet is a Geneve
571              packet.
572
573              For example:
574                   geneve 0xb && ip
575              filters IPv4 protocol encapsulated in Geneve with VNI 0xb.  This
576              will  match both IPv4 directly encapsulated in Geneve as well as
577              IPv4 contained inside an Ethernet frame.
578
579       iso proto protocol
580              True if the packet is an OSI packet of protocol  type  protocol.
581              Protocol  can  be  a  number  or one of the names clnp, esis, or
582              isis.
583
584       clnp, esis, isis
585              Abbreviations for:
586                   iso proto \protocol
587              where protocol is one of the above protocols.
588
589       l1, l2, iih, lsp, snp, csnp, psnp
590              Abbreviations for IS-IS PDU types.
591
592       vpi n  True if the packet is an ATM packet, for SunATM on Solaris, with
593              a virtual path identifier of n.
594
595       vci n  True if the packet is an ATM packet, for SunATM on Solaris, with
596              a virtual channel identifier of n.
597
598       lane   True if the packet is an ATM packet, for SunATM on Solaris,  and
599              is an ATM LANE packet.  Note that the first lane keyword encoun‐
600              tered in an expression changes the tests done in  the  remainder
601              of  the expression on the assumption that the packet is either a
602              LANE emulated Ethernet packet or a LANE LE Control  packet.   If
603              lane  isn't  specified,  the tests are done under the assumption
604              that the packet is an LLC-encapsulated packet.
605
606       oamf4s True if the packet is an ATM packet, for SunATM on Solaris,  and
607              is a segment OAM F4 flow cell (VPI=0 & VCI=3).
608
609       oamf4e True  if the packet is an ATM packet, for SunATM on Solaris, and
610              is an end-to-end OAM F4 flow cell (VPI=0 & VCI=4).
611
612       oamf4  True if the packet is an ATM packet, for SunATM on Solaris,  and
613              is  a  segment  or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 |
614              VCI=4)).
615
616       oam    True if the packet is an ATM packet, for SunATM on Solaris,  and
617              is  a  segment  or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 |
618              VCI=4)).
619
620       metac  True if the packet is an ATM packet, for SunATM on Solaris,  and
621              is on a meta signaling circuit (VPI=0 & VCI=1).
622
623       bcc    True  if the packet is an ATM packet, for SunATM on Solaris, and
624              is on a broadcast signaling circuit (VPI=0 & VCI=2).
625
626       sc     True if the packet is an ATM packet, for SunATM on Solaris,  and
627              is on a signaling circuit (VPI=0 & VCI=5).
628
629       ilmic  True  if the packet is an ATM packet, for SunATM on Solaris, and
630              is on an ILMI circuit (VPI=0 & VCI=16).
631
632       connectmsg
633              True if the packet is an ATM packet, for SunATM on Solaris,  and
634              is  on  a signaling circuit and is a Q.2931 Setup, Call Proceed‐
635              ing, Connect, Connect Ack, Release, or Release Done message.
636
637       metaconnect
638              True if the packet is an ATM packet, for SunATM on Solaris,  and
639              is  on a meta signaling circuit and is a Q.2931 Setup, Call Pro‐
640              ceeding, Connect, Release, or Release Done message.
641
642       expr1 relop expr2
643              True if the relation holds.  Relop is one of {>, <, >=,  <=,  =,
644              ==, !=} (where = means the same as ==).  Each of expr1 and expr2
645              is an arithmetic expression composed of integer  constants  (ex‐
646              pressed  in  standard C syntax), the normal binary operators {+,
647              -, *, /, %, &, |, ^, <<, >>}, a  length  operator,  and  special
648              packet  data accessors.  Note that all comparisons are unsigned,
649              so that, for example, 0x80000000 and 0xffffffff are > 0.
650
651              The % and ^ operators are currently only supported for filtering
652              in  the  kernel  on  particular  operating systems (for example:
653              FreeBSD, Linux with 3.7 and later kernels, NetBSD); on all other
654              systems  (for example: AIX, illumos, Solaris, OpenBSD), if those
655              operators are used, filtering will be done in user  mode,  which
656              will  increase  the  overhead of capturing packets and may cause
657              more packets to be dropped.
658
659              The length operator, indicated by the  keyword  len,  gives  the
660              length of the packet.
661
662              To access data inside the packet, use the following syntax:
663                   proto [ expr : size ]
664              Proto  is  one  of  arp, atalk, carp, decnet, ether, fddi, icmp,
665              icmp6, igmp, igrp, ip, ip6, lat, link, mopdl, moprc,  pim,  ppp,
666              radio,  rarp,  sca,  sctp, slip, tcp, tr, udp, vrrp or wlan, and
667              indicates the protocol layer for the index  operation.   (ether,
668              fddi,  link, ppp, slip, tr and wlan all refer to the link layer.
669              radio refers to the "radio header" added  to  some  802.11  cap‐
670              tures.)  Note that tcp, udp and other upper-layer protocol types
671              only apply to IPv4, not IPv6 (this will be fixed in the future).
672              The  byte  offset,  relative to the indicated protocol layer, is
673              given by expr.  Size is optional and  indicates  the  number  of
674              bytes  in  the  field of interest; it can be either one, two, or
675              four, and defaults to one.
676
677              For example, `ether[0] & 1 != 0' catches all multicast  traffic.
678              The  expression `ip[0] & 0xf != 5' catches all IPv4 packets with
679              options.  The expression `ip[6:2] & 0x1fff = 0' catches only un‐
680              fragmented IPv4 datagrams and frag zero of fragmented IPv4 data‐
681              grams.  This check is implicitly applied to the tcp and udp  in‐
682              dex  operations.   For  instance,  tcp[0] always means the first
683              byte of the TCP header, and never means the first byte of an in‐
684              tervening fragment.
685
686              Some  offsets  and field values may be expressed as names rather
687              than as numeric values.  The  following  protocol  header  field
688              offsets  are  available:  icmptype  (ICMP type field), icmp6type
689              (ICMPv6 type  field),  icmpcode  (ICMP  code  field),  icmp6code
690              (ICMPv6 code field) and tcpflags (TCP flags field).
691
692              The   following   ICMP   type   field   values   are  available:
693              icmp-echoreply, icmp-unreach, icmp-sourcequench,  icmp-redirect,
694              icmp-echo, icmp-routeradvert, icmp-routersolicit, icmp-timxceed,
695              icmp-paramprob,   icmp-tstamp,   icmp-tstampreply,    icmp-ireq,
696              icmp-ireqreply, icmp-maskreq, icmp-maskreply.
697
698              The   following   ICMPv6   type   field  values  are  available:
699              icmp6-destinationunreach,                    icmp6-packettoobig,
700              icmp6-timeexceeded,      icmp6-parameterproblem,     icmp6-echo,
701              icmp6-echoreply,                   icmp6-multicastlistenerquery,
702              icmp6-multicastlistenerreportv1,    icmp6-multicastlistenerdone,
703              icmp6-routersolicit, icmp6-routeradvert,  icmp6-neighborsolicit,
704              icmp6-neighboradvert,     icmp6-redirect,     icmp6-routerrenum,
705              icmp6-nodeinformationquery,       icmp6-nodeinformationresponse,
706              icmp6-ineighbordiscoverysolicit, icmp6-ineighbordiscoveryadvert,
707              icmp6-multicastlistenerreportv2,
708              icmp6-homeagentdiscoveryrequest,  icmp6-homeagentdiscoveryreply,
709              icmp6-mobileprefixsolicit,             icmp6-mobileprefixadvert,
710              icmp6-certpathsolicit,                     icmp6-certpathadvert,
711              icmp6-multicastrouteradvert,       icmp6-multicastroutersolicit,
712              icmp6-multicastrouterterm.
713
714              The  following  TCP  flags  field values are available: tcp-fin,
715              tcp-syn, tcp-rst, tcp-push, tcp-ack, tcp-urg, tcp-ece, tcp-cwr.
716
717       Primitives may be combined using:
718
719              A parenthesized group of primitives and operators.
720
721              Negation (`!' or `not').
722
723              Concatenation (`&&' or `and').
724
725              Alternation (`||' or `or').
726
727       Negation has the highest  precedence.   Alternation  and  concatenation
728       have  equal precedence and associate left to right.  Note that explicit
729       and tokens, not juxtaposition, are now required for concatenation.
730
731       If an identifier is given without a keyword, the most recent keyword is
732       assumed.  For example,
733            not host vs and ace
734       is short for
735            not host vs and host ace
736       which should not be confused with
737            not (host vs or ace)
738

EXAMPLES

740       To select all packets arriving at or departing from `sundown':
741              host sundown
742
743       To select traffic between `helios' and either `hot' or `ace':
744              host helios and (hot or ace)
745
746       To select all IPv4 packets between `ace' and any host except `helios':
747              ip host ace and not helios
748
749       To select all traffic between local hosts and hosts at Berkeley:
750              net ucb-ether
751
752       To select all FTP traffic through Internet gateway `snup':
753              gateway snup and (port ftp or ftp-data)
754
755       To  select  IPv4  traffic  neither  sourced from nor destined for local
756       hosts (if you gateway to one other net, this stuff should never make it
757       onto your local net).
758              ip and not net localnet
759
760       To  select  the start and end packets (the SYN and FIN packets) of each
761       TCP conversation that involves a non-local host.
762              tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
763
764       To select the TCP packets with flags RST and ACK both set.   (i.e.  se‐
765       lect  only  the RST and ACK flags in the flags field, and if the result
766       is "RST and ACK both set", match)
767              tcp[tcpflags] & (tcp-rst|tcp-ack) == (tcp-rst|tcp-ack)
768
769       To select all IPv4 HTTP packets to and from port 80,  i.e.  print  only
770       packets  that  contain  data, not, for example, SYN and FIN packets and
771       ACK-only packets.  (IPv6 is left as an exercise for the reader.)
772              tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
773
774       To select IPv4 packets longer  than  576  bytes  sent  through  gateway
775       `snup':
776              gateway snup and ip[2:2] > 576
777
778       To  select  IPv4  broadcast or multicast packets that were not sent via
779       Ethernet broadcast or multicast:
780              ether[0] & 1 = 0 and ip[16] >= 224
781
782       To select all ICMP packets that are not  echo  requests/replies  (i.e.,
783       not ping packets):
784              icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
785              icmp6[icmp6type] != icmp6-echo and icmp6[icmp6type] != icmp6-echoreply
786

BACKWARD COMPATIBILITY

788       The ICMPv6 type code names, as well as the tcp-ece and tcp-cwr TCP flag
789       names became available in libpcap 1.9.0.
790
791       The geneve keyword became available in libpcap 1.8.0.
792

SEE ALSO

794       pcap(3PCAP)
795

BUGS

797       To   report   a   security   issue   please   send   an    e-mail    to
798       security@tcpdump.org.
799
800       To  report  bugs and other problems, contribute patches, request a fea‐
801       ture, provide generic feedback etc please see the file  CONTRIBUTING.md
802       in the libpcap source tree root.
803
804       Filter  expressions  on  fields  other than those in Token Ring headers
805       will not correctly handle source-routed Token Ring packets.
806
807       Filter expressions on fields other than those in  802.11  headers  will
808       not  correctly  handle  802.11 data packets with both To DS and From DS
809       set.
810
811       `ip6 proto' should chase header chain, but at this moment it does  not.
812       `ip6  protochain' is supplied for this behavior.  For example, to match
813       IPv6 fragments: `ip6 protochain 44'
814
815       Arithmetic expression against transport  layer  headers,  like  tcp[0],
816       does not work against IPv6 packets.  It only looks at IPv4 packets.
817
818
819
820                               19 November 2022                 PCAP-FILTER(7)
Impressum