]> The Tcpdump Group git mirrors - libpcap/blob - pcap-bpf.h
Check for OpenBSD and, if we're building on OpenBSD, #define various
[libpcap] / pcap-bpf.h
1 /*-
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
8 * Berkeley Laboratory.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
25 *
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
36 * SUCH DAMAGE.
37 *
38 * @(#)bpf.h 7.1 (Berkeley) 5/7/91
39 *
40 * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.4 2003-03-08 09:13:39 guy Exp $ (LBL)
41 */
42
43 /*
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..
47 *
48 * "pcap-bpf.c" will include the native OS version, as it deals with
49 * the OS's BPF implementation.
50 *
51 * XXX - should this all just be moved to "pcap.h"?
52 */
53
54 #ifndef BPF_MAJOR_VERSION
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /* BSD style release date */
61 #define BPF_RELEASE 199606
62
63 typedef int bpf_int32;
64 typedef u_int bpf_u_int32;
65
66 /*
67 * Alignment macros. BPF_WORDALIGN rounds up to the next
68 * even multiple of BPF_ALIGNMENT.
69 */
70 #ifndef __NetBSD__
71 #define BPF_ALIGNMENT sizeof(bpf_int32)
72 #else
73 #define BPF_ALIGNMENT sizeof(long)
74 #endif
75 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
76
77 #define BPF_MAXINSNS 512
78 #define BPF_MAXBUFSIZE 0x8000
79 #define BPF_MINBUFSIZE 32
80
81 /*
82 * Structure for "pcap_compile()", "pcap_setfilter()", etc..
83 */
84 struct bpf_program {
85 u_int bf_len;
86 struct bpf_insn *bf_insns;
87 };
88
89 /*
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.
99 */
100 struct bpf_version {
101 u_short bv_major;
102 u_short bv_minor;
103 };
104 /* Current version number of filter architecture. */
105 #define BPF_MAJOR_VERSION 1
106 #define BPF_MINOR_VERSION 1
107
108 /*
109 * Data-link level type codes.
110 */
111
112 /*
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
120 * here).
121 */
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 */
133
134 /*
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.
139 *
140 * XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS,
141 * but I don't know what the right #define is for BSD/OS.
142 */
143 #define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
144 #ifdef __OpenBSD__
145 #define DLT_RAW 14 /* raw IP */
146 #else
147 #define DLT_RAW 12 /* raw IP */
148 #endif
149
150 /*
151 * These are values from BSD/OS's "bpf.h".
152 * These are not the same as the values from the traditional libpcap
153 * "bpf.h"; however, these values shouldn't be generated by any
154 * OS other than BSD/OS, so the correct values to use here are the
155 * BSD/OS values.
156 *
157 * Platforms that have already assigned these values to other
158 * DLT_ codes, however, should give these codes the values
159 * from that platform, so that programs that use these codes will
160 * continue to compile - even though they won't correctly read
161 * files of these types.
162 */
163 #ifdef __NetBSD__
164 #ifndef DLT_SLIP_BSDOS
165 #define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
166 #define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
167 #endif
168 #else
169 #define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
170 #define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
171 #endif
172
173 #define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
174
175 /*
176 * These values are defined by NetBSD; other platforms should refrain from
177 * using them for other purposes, so that NetBSD savefiles with link
178 * types of 50 or 51 can be read as this type on all platforms.
179 */
180 #define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
181 #define DLT_PPP_ETHER 51 /* PPP over Ethernet */
182
183 /*
184 * Values between 100 and 103 are used in capture file headers as
185 * link-layer types corresponding to DLT_ types that differ
186 * between platforms; don't use those values for new DLT_ new types.
187 */
188
189 /*
190 * This value was defined by libpcap 0.5; platforms that have defined
191 * it with a different value should define it here with that value -
192 * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
193 * whatever value that happens to be, so programs will correctly
194 * handle files with that link type regardless of the value of
195 * DLT_C_HDLC.
196 *
197 * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
198 * compatibility with programs written for BSD/OS.
199 *
200 * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
201 * for source compatibility with programs written for libpcap 0.5.
202 */
203 #define DLT_C_HDLC 104 /* Cisco HDLC */
204 #define DLT_CHDLC DLT_C_HDLC
205
206 #define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
207
208 /*
209 * 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW,
210 * except when it isn't. (I.e., sometimes it's just raw IP, and
211 * sometimes it isn't.) We currently handle it as DLT_LINUX_SLL,
212 * so that we don't have to worry about the link-layer header.)
213 */
214
215 /*
216 * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
217 * with other values.
218 * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
219 * (DLCI, etc.).
220 */
221 #define DLT_FRELAY 107
222
223 /*
224 * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
225 * that the AF_ type in the link-layer header is in network byte order.
226 *
227 * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
228 * define it as 108 here. If OpenBSD picks up this file, it should
229 * define DLT_LOOP as 12 in its version, as per the comment above -
230 * and should not use 108 as a DLT_ value.
231 */
232 #define DLT_LOOP 108
233
234 /*
235 * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
236 * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
237 * than OpenBSD.
238 */
239 #ifdef __OpenBSD__
240 #define DLT_ENC 13
241 #else
242 #define DLT_ENC 109
243 #endif
244
245 /*
246 * Values between 110 and 112 are reserved for use in capture file headers
247 * as link-layer types corresponding to DLT_ types that might differ
248 * between platforms; don't use those values for new DLT_ types
249 * other than the corresponding DLT_ types.
250 */
251
252 /*
253 * This is for Linux cooked sockets.
254 */
255 #define DLT_LINUX_SLL 113
256
257 /*
258 * Apple LocalTalk hardware.
259 */
260 #define DLT_LTALK 114
261
262 /*
263 * Acorn Econet.
264 */
265 #define DLT_ECONET 115
266
267 /*
268 * Reserved for use with OpenBSD ipfilter.
269 */
270 #define DLT_IPFILTER 116
271
272 /*
273 * Reserved for use in capture-file headers as a link-layer type
274 * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
275 * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
276 * in capture-file headers.
277 */
278 #define DLT_PFLOG 117
279
280 /*
281 * Registered for Cisco-internal use.
282 */
283 #define DLT_CISCO_IOS 118
284
285 /*
286 * Reserved for 802.11 cards using the Prism II chips, with a link-layer
287 * header including Prism monitor mode information plus an 802.11
288 * header.
289 */
290 #define DLT_PRISM_HEADER 119
291
292 /*
293 * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
294 * (see Doug Ambrisko's FreeBSD patches).
295 */
296 #define DLT_AIRONET_HEADER 120
297
298 /*
299 * Reserved for Siemens HiPath HDLC.
300 */
301 #define DLT_HHDLC 121
302
303 /*
304 * This is for RFC 2625 IP-over-Fibre Channel.
305 *
306 * This is not for use with raw Fibre Channel, where the link-layer
307 * header starts with a Fibre Channel frame header; it's for IP-over-FC,
308 * where the link-layer header starts with an RFC 2625 Network_Header
309 * field.
310 */
311 #define DLT_IP_OVER_FC 122
312
313 /*
314 * This is for Full Frontal ATM on Solaris with SunATM, with a
315 * pseudo-header followed by an AALn PDU.
316 *
317 * There may be other forms of Full Frontal ATM on other OSes,
318 * with different pseudo-headers.
319 *
320 * If ATM software returns a pseudo-header with VPI/VCI information
321 * (and, ideally, packet type information, e.g. signalling, ILMI,
322 * LANE, LLC-multiplexed traffic, etc.), it should not use
323 * DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump
324 * and the like don't have to infer the presence or absence of a
325 * pseudo-header and the form of the pseudo-header.
326 */
327 #define DLT_SUNATM 123 /* Solaris+SunATM */
328
329 /*
330 * Reserved as per request from Kent Dahlgren <kent@praesum.com>
331 * for private use.
332 */
333 #define DLT_RIO 124 /* RapidIO */
334 #define DLT_PCI_EXP 125 /* PCI Express */
335 #define DLT_AURORA 126 /* Xilinx Aurora link layer */
336
337 /*
338 * For future use with 802.11 captures - defined by AbsoluteValue
339 * Systems to store a number of bits of link-layer information:
340 *
341 * http://www.shaftnet.org/~pizza/software/capturefrm.txt
342 *
343 * but could and arguably should also be used by non-AVS Linux
344 * 802.11 drivers and BSD drivers; that may happen in the future.
345 */
346 #define DLT_IEEE802_11_RADIO 127 /* 802.11 plus WLAN header */
347
348 /*
349 * Reserved for the TZSP encapsulation, as per request from
350 * Chris Waters <chris.waters@networkchemistry.com>
351 * TZSP is a generic encapsulation for any other link type,
352 * which includes a means to include meta-information
353 * with the packet, e.g. signal strength and channel
354 * for 802.11 packets.
355 */
356 #define DLT_TZSP 128 /* Tazmen Sniffer Protocol */
357
358 /*
359 * BSD's ARCNET headers have the source host, destination host,
360 * and type at the beginning of the packet; that's what's handed
361 * up to userland via BPF.
362 *
363 * Linux's ARCNET headers, however, have a 2-byte offset field
364 * between the host IDs and the type; that's what's handed up
365 * to userland via PF_PACKET sockets.
366 *
367 * We therefore have to have separate DLT_ values for them.
368 */
369 #define DLT_ARCNET_LINUX 129 /* ARCNET */
370
371 /*
372 * juniper-private data link types, as per request from
373 * Hannes Gredler <hannes@juniper.net> the DLT_s are used
374 * for passing on chassis-internal metainformation like
375 * QOS profiles etc.
376 */
377 #define DLT_JUNIPER_MLPPP 130
378 #define DLT_JUNIPER_MLFR 131
379 #define DLT_JUNIPER_ES 132
380 #define DLT_JUNIPER_GGSN 133
381 #define DLT_JUNIPER_MFR 134
382 #define DLT_JUNIPER_ATM2 135
383 #define DLT_JUNIPER_SERVICES 136
384
385 /*
386 * The instruction encodings.
387 */
388 /* instruction classes */
389 #define BPF_CLASS(code) ((code) & 0x07)
390 #define BPF_LD 0x00
391 #define BPF_LDX 0x01
392 #define BPF_ST 0x02
393 #define BPF_STX 0x03
394 #define BPF_ALU 0x04
395 #define BPF_JMP 0x05
396 #define BPF_RET 0x06
397 #define BPF_MISC 0x07
398
399 /* ld/ldx fields */
400 #define BPF_SIZE(code) ((code) & 0x18)
401 #define BPF_W 0x00
402 #define BPF_H 0x08
403 #define BPF_B 0x10
404 #define BPF_MODE(code) ((code) & 0xe0)
405 #define BPF_IMM 0x00
406 #define BPF_ABS 0x20
407 #define BPF_IND 0x40
408 #define BPF_MEM 0x60
409 #define BPF_LEN 0x80
410 #define BPF_MSH 0xa0
411
412 /* alu/jmp fields */
413 #define BPF_OP(code) ((code) & 0xf0)
414 #define BPF_ADD 0x00
415 #define BPF_SUB 0x10
416 #define BPF_MUL 0x20
417 #define BPF_DIV 0x30
418 #define BPF_OR 0x40
419 #define BPF_AND 0x50
420 #define BPF_LSH 0x60
421 #define BPF_RSH 0x70
422 #define BPF_NEG 0x80
423 #define BPF_JA 0x00
424 #define BPF_JEQ 0x10
425 #define BPF_JGT 0x20
426 #define BPF_JGE 0x30
427 #define BPF_JSET 0x40
428 #define BPF_SRC(code) ((code) & 0x08)
429 #define BPF_K 0x00
430 #define BPF_X 0x08
431
432 /* ret - BPF_K and BPF_X also apply */
433 #define BPF_RVAL(code) ((code) & 0x18)
434 #define BPF_A 0x10
435
436 /* misc */
437 #define BPF_MISCOP(code) ((code) & 0xf8)
438 #define BPF_TAX 0x00
439 #define BPF_TXA 0x80
440
441 /*
442 * The instruction data structure.
443 */
444 struct bpf_insn {
445 u_short code;
446 u_char jt;
447 u_char jf;
448 bpf_int32 k;
449 };
450
451 /*
452 * Macros for insn array initializers.
453 */
454 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
455 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
456
457 #if __STDC__ || defined(__cplusplus)
458 extern int bpf_validate(struct bpf_insn *, int);
459 extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
460 #else
461 extern int bpf_validate();
462 extern u_int bpf_filter();
463 #endif
464
465 /*
466 * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
467 */
468 #define BPF_MEMWORDS 16
469
470 #ifdef __cplusplus
471 }
472 #endif
473
474 #endif