]>
The Tcpdump Group git mirrors - libpcap/blob - pcap-bpf.h
dd53ceaf6272482b8fe0ae3e5c394e0968c0a028
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from the Stanford/CMU enet packet filter,
6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)bpf.h 7.1 (Berkeley) 5/7/91
40 * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.2 2003-02-11 17:03:22 hannes Exp $ (LBL)
44 * This is libpcap's cut-down version of bpf.h; it includes only
45 * the stuff needed for the code generator and the userland BPF
46 * interpreter, and the libpcap APIs for setting filters, etc..
48 * "pcap-bpf.c" will include the native OS version, as it deals with
49 * the OS's BPF implementation.
51 * XXX - should this all just be moved to "pcap.h"?
54 #ifndef BPF_MAJOR_VERSION
60 /* BSD style release date */
61 #define BPF_RELEASE 199606
63 typedef int bpf_int32
;
64 typedef u_int bpf_u_int32
;
67 * Alignment macros. BPF_WORDALIGN rounds up to the next
68 * even multiple of BPF_ALIGNMENT.
71 #define BPF_ALIGNMENT sizeof(bpf_int32)
73 #define BPF_ALIGNMENT sizeof(long)
75 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
77 #define BPF_MAXINSNS 512
78 #define BPF_MAXBUFSIZE 0x8000
79 #define BPF_MINBUFSIZE 32
82 * Structure for "pcap_compile()", "pcap_setfilter()", etc..
86 struct bpf_insn
*bf_insns
;
90 * Struct return by BIOCVERSION. This represents the version number of
91 * the filter language described by the instruction encodings below.
92 * bpf understands a program iff kernel_major == filter_major &&
93 * kernel_minor >= filter_minor, that is, if the value returned by the
94 * running kernel has the same major number and a minor number equal
95 * equal to or less than the filter being downloaded. Otherwise, the
96 * results are undefined, meaning an error may be returned or packets
97 * may be accepted haphazardly.
98 * It has nothing to do with the source code version.
104 /* Current version number of filter architecture. */
105 #define BPF_MAJOR_VERSION 1
106 #define BPF_MINOR_VERSION 1
109 * Data-link level type codes.
113 * These are the types that are the same on all platforms; on other
114 * platforms, a <net/bpf.h> should be supplied that defines the additional
115 * DLT_* codes appropriately for that platform (the BSDs, for example,
116 * should not just pick up this version of "bpf.h"; they should also define
117 * the additional DLT_* codes used by their kernels, as well as the values
118 * defined here - and, if the values they use for particular DLT_ types
119 * differ from those here, they should use their values, not the ones
122 #define DLT_NULL 0 /* no link-layer encapsulation */
123 #define DLT_EN10MB 1 /* Ethernet (10Mb) */
124 #define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
125 #define DLT_AX25 3 /* Amateur Radio AX.25 */
126 #define DLT_PRONET 4 /* Proteon ProNET Token Ring */
127 #define DLT_CHAOS 5 /* Chaos */
128 #define DLT_IEEE802 6 /* IEEE 802 Networks */
129 #define DLT_ARCNET 7 /* ARCNET, with BSD-style header */
130 #define DLT_SLIP 8 /* Serial Line IP */
131 #define DLT_PPP 9 /* Point-to-point Protocol */
132 #define DLT_FDDI 10 /* FDDI */
135 * These are values from the traditional libpcap "bpf.h".
136 * Ports of this to particular platforms should replace these definitions
137 * with the ones appropriate to that platform, if the values are
138 * different on that platform.
140 #define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
141 #define DLT_RAW 12 /* raw IP */
144 * These are values from BSD/OS's "bpf.h".
145 * These are not the same as the values from the traditional libpcap
146 * "bpf.h"; however, these values shouldn't be generated by any
147 * OS other than BSD/OS, so the correct values to use here are the
150 * Platforms that have already assigned these values to other
151 * DLT_ codes, however, should give these codes the values
152 * from that platform, so that programs that use these codes will
153 * continue to compile - even though they won't correctly read
154 * files of these types.
157 #ifndef DLT_SLIP_BSDOS
158 #define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
159 #define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
162 #define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
163 #define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
166 #define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
169 * These values are defined by NetBSD; other platforms should refrain from
170 * using them for other purposes, so that NetBSD savefiles with link
171 * types of 50 or 51 can be read as this type on all platforms.
173 #define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
174 #define DLT_PPP_ETHER 51 /* PPP over Ethernet */
177 * Values between 100 and 103 are used in capture file headers as
178 * link-layer types corresponding to DLT_ types that differ
179 * between platforms; don't use those values for new DLT_ new types.
183 * This value was defined by libpcap 0.5; platforms that have defined
184 * it with a different value should define it here with that value -
185 * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
186 * whatever value that happens to be, so programs will correctly
187 * handle files with that link type regardless of the value of
190 * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
191 * compatibility with programs written for BSD/OS.
193 * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
194 * for source compatibility with programs written for libpcap 0.5.
196 #define DLT_C_HDLC 104 /* Cisco HDLC */
197 #define DLT_CHDLC DLT_C_HDLC
199 #define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
202 * 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW,
203 * except when it isn't. (I.e., sometimes it's just raw IP, and
204 * sometimes it isn't.) We currently handle it as DLT_LINUX_SLL,
205 * so that we don't have to worry about the link-layer header.)
209 * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
211 * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
214 #define DLT_FRELAY 107
217 * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
218 * that the AF_ type in the link-layer header is in network byte order.
220 * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
221 * define it as 108 here. If OpenBSD picks up this file, it should
222 * define DLT_LOOP as 12 in its version, as per the comment above -
223 * and should not use 108 as a DLT_ value.
228 * Values between 109 and 112 are used in capture file headers as
229 * link-layer types corresponding to DLT_ types that might differ
230 * between platforms; don't use those values for new DLT_ types
231 * other than the corresponding DLT_ types.
235 * This is for Linux cooked sockets.
237 #define DLT_LINUX_SLL 113
240 * Apple LocalTalk hardware.
242 #define DLT_LTALK 114
247 #define DLT_ECONET 115
250 * Reserved for use with OpenBSD ipfilter.
252 #define DLT_IPFILTER 116
255 * Reserved for use in capture-file headers as a link-layer type
256 * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
257 * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
258 * in capture-file headers.
260 #define DLT_PFLOG 117
263 * Registered for Cisco-internal use.
265 #define DLT_CISCO_IOS 118
268 * Reserved for 802.11 cards using the Prism II chips, with a link-layer
269 * header including Prism monitor mode information plus an 802.11
272 #define DLT_PRISM_HEADER 119
275 * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
276 * (see Doug Ambrisko's FreeBSD patches).
278 #define DLT_AIRONET_HEADER 120
281 * Reserved for Siemens HiPath HDLC.
283 #define DLT_HHDLC 121
286 * This is for RFC 2625 IP-over-Fibre Channel.
288 * This is not for use with raw Fibre Channel, where the link-layer
289 * header starts with a Fibre Channel frame header; it's for IP-over-FC,
290 * where the link-layer header starts with an RFC 2625 Network_Header
293 #define DLT_IP_OVER_FC 122
296 * This is for Full Frontal ATM on Solaris with SunATM, with a
297 * pseudo-header followed by an AALn PDU.
299 * There may be other forms of Full Frontal ATM on other OSes,
300 * with different pseudo-headers.
302 * If ATM software returns a pseudo-header with VPI/VCI information
303 * (and, ideally, packet type information, e.g. signalling, ILMI,
304 * LANE, LLC-multiplexed traffic, etc.), it should not use
305 * DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump
306 * and the like don't have to infer the presence or absence of a
307 * pseudo-header and the form of the pseudo-header.
309 #define DLT_SUNATM 123 /* Solaris+SunATM */
312 * Reserved as per request from Kent Dahlgren <kent@praesum.com>
315 #define DLT_RIO 124 /* RapidIO */
316 #define DLT_PCI_EXP 125 /* PCI Express */
317 #define DLT_AURORA 126 /* Xilinx Aurora link layer */
320 * For future use with 802.11 captures - defined by AbsoluteValue
321 * Systems to store a number of bits of link-layer information:
323 * http://www.shaftnet.org/~pizza/software/capturefrm.txt
325 * but could and arguably should also be used by non-AVS Linux
326 * 802.11 drivers and BSD drivers; that may happen in the future.
328 #define DLT_IEEE802_11_RADIO 127 /* 802.11 plus WLAN header */
331 * Reserved for the TZSP encapsulation, as per request from
332 * Chris Waters <chris.waters@networkchemistry.com>
333 * TZSP is a generic encapsulation for any other link type,
334 * which includes a means to include meta-information
335 * with the packet, e.g. signal strength and channel
336 * for 802.11 packets.
338 #define DLT_TZSP 128 /* Tazmen Sniffer Protocol */
341 * BSD's ARCNET headers have the source host, destination host,
342 * and type at the beginning of the packet; that's what's handed
343 * up to userland via BPF.
345 * Linux's ARCNET headers, however, have a 2-byte offset field
346 * between the host IDs and the type; that's what's handed up
347 * to userland via PF_PACKET sockets.
349 * We therefore have to have separate DLT_ values for them.
351 #define DLT_ARCNET_LINUX 129 /* ARCNET */
354 * juniper-private data link types, as per request from
355 * Hannes Gredler <hannes@juniper.net> the DLT_s are used
356 * for passing on chassis-internal metainformation like
359 #define DLT_JUNIPER_MLPPP 130
360 #define DLT_JUNIPER_MLFR 131
361 #define DLT_JUNIPER_ES 132
362 #define DLT_JUNIPER_GGSN 133
363 #define DLT_JUNIPER_MFR 134
364 #define DLT_JUNIPER_ATM2 135
365 #define DLT_JUNIPER_SERVICES 136
368 * The instruction encodings.
370 /* instruction classes */
371 #define BPF_CLASS(code) ((code) & 0x07)
379 #define BPF_MISC 0x07
382 #define BPF_SIZE(code) ((code) & 0x18)
386 #define BPF_MODE(code) ((code) & 0xe0)
395 #define BPF_OP(code) ((code) & 0xf0)
409 #define BPF_JSET 0x40
410 #define BPF_SRC(code) ((code) & 0x08)
414 /* ret - BPF_K and BPF_X also apply */
415 #define BPF_RVAL(code) ((code) & 0x18)
419 #define BPF_MISCOP(code) ((code) & 0xf8)
424 * The instruction data structure.
434 * Macros for insn array initializers.
436 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
437 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
439 #if __STDC__ || defined(__cplusplus)
440 extern int bpf_validate(struct bpf_insn
*, int);
441 extern u_int
bpf_filter(struct bpf_insn
*, u_char
*, u_int
, u_int
);
443 extern int bpf_validate();
444 extern u_int
bpf_filter();
448 * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
450 #define BPF_MEMWORDS 16