]>
The Tcpdump Group git mirrors - libpcap/blob - pcap/bpf.h
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
42 * This is libpcap's cut-down version of bpf.h; it includes only
43 * the stuff needed for the code generator and the userland BPF
44 * interpreter, and the libpcap APIs for setting filters, etc..
46 * "pcap-bpf.c" will include the native OS version, as it deals with
47 * the OS's BPF implementation.
49 * At least two programs found by Google Code Search explicitly includes
50 * <pcap/bpf.h> (even though <pcap.h>/<pcap/pcap.h> includes it for you),
51 * so moving that stuff to <pcap/pcap.h> would break the build for some
56 * If we've already included <net/bpf.h>, don't re-define this stuff.
57 * We assume BSD-style multiple-include protection in <net/bpf.h>,
58 * which is true of all but the oldest versions of FreeBSD and NetBSD,
59 * or Tru64 UNIX-style multiple-include protection (or, at least,
60 * Tru64 UNIX 5.x-style; I don't have earlier versions available to check),
61 * or AIX-style multiple-include protection (or, at least, AIX 5.x-style;
62 * I don't have earlier versions available to check), or QNX-style
63 * multiple-include protection (as per GitHub pull request #394).
65 * We do not check for BPF_MAJOR_VERSION, as that's defined by
66 * <linux/filter.h>, which is directly or indirectly included in some
67 * programs that also include pcap.h, and <linux/filter.h> doesn't
68 * define stuff we need.
70 * This also provides our own multiple-include protection.
72 #if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h)
73 #define lib_pcap_bpf_h
79 /* BSD style release date */
80 #define BPF_RELEASE 199606
82 #ifdef MSDOS /* must be 32-bit */
83 typedef long bpf_int32
;
84 typedef unsigned long bpf_u_int32
;
86 typedef int bpf_int32
;
87 typedef u_int bpf_u_int32
;
91 * Alignment macros. BPF_WORDALIGN rounds up to the next
92 * even multiple of BPF_ALIGNMENT.
94 * Tcpdump's print-pflog.c uses this, so we define it here.
97 #define BPF_ALIGNMENT sizeof(bpf_int32)
99 #define BPF_ALIGNMENT sizeof(long)
101 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
104 * Structure for "pcap_compile()", "pcap_setfilter()", etc..
108 struct bpf_insn
*bf_insns
;
111 #include <pcap/dlt.h>
114 * The instruction encodings.
116 * Please inform tcpdump-workers@lists.tcpdump.org if you use any
117 * of the reserved values, so that we can note that they're used
118 * (and perhaps implement it in the reference BPF implementation
119 * and encourage its implementation elsewhere).
123 * The upper 8 bits of the opcode aren't used. BSD/OS used 0x8000.
126 /* instruction classes */
127 #define BPF_CLASS(code) ((code) & 0x07)
135 #define BPF_MISC 0x07
138 #define BPF_SIZE(code) ((code) & 0x18)
142 /* 0x18 reserved; used by BSD/OS */
143 #define BPF_MODE(code) ((code) & 0xe0)
150 /* 0xc0 reserved; used by BSD/OS */
151 /* 0xe0 reserved; used by BSD/OS */
154 #define BPF_OP(code) ((code) & 0xf0)
176 #define BPF_JSET 0x40
177 /* 0x50 reserved; used on BSD/OS */
188 #define BPF_SRC(code) ((code) & 0x08)
192 /* ret - BPF_K and BPF_X also apply */
193 #define BPF_RVAL(code) ((code) & 0x18)
198 #define BPF_MISCOP(code) ((code) & 0xf8)
203 /* #define BPF_COP 0x20 NetBSD "coprocessor" extensions */
207 /* #define BPF_COPX 0x40 NetBSD "coprocessor" extensions */
208 /* also used on BSD/OS */
224 /* 0xc0 reserved; used on BSD/OS */
234 * The instruction data structure.
244 * Auxiliary data, for use when interpreting a filter intended for the
245 * Linux kernel when the kernel rejects the filter (requiring us to
246 * run it in userland). It contains VLAN tag information.
248 struct bpf_aux_data
{
249 u_short vlan_tag_present
;
254 * Macros for insn array initializers.
256 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
257 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
259 #if __STDC__ || defined(__cplusplus)
260 extern int bpf_validate(const struct bpf_insn
*, int);
261 extern u_int
bpf_filter(const struct bpf_insn
*, const u_char
*, u_int
, u_int
);
262 extern u_int
bpf_filter_with_aux_data(const struct bpf_insn
*, const u_char
*, u_int
, u_int
, const struct bpf_aux_data
*);
264 extern int bpf_validate();
265 extern u_int
bpf_filter();
266 extern u_int
bpf_filter();
270 * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
272 #define BPF_MEMWORDS 16
278 #endif /* !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) */