1145519Sdarrenr/*	$FreeBSD$	*/
2145510Sdarrenr
3145510Sdarrenr/*-
4145510Sdarrenr * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
5145510Sdarrenr *	The Regents of the University of California.  All rights reserved.
6145510Sdarrenr *
7145510Sdarrenr * This code is derived from the Stanford/CMU enet packet filter,
8145510Sdarrenr * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9145510Sdarrenr * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10145510Sdarrenr * Berkeley Laboratory.
11145510Sdarrenr *
12145510Sdarrenr * Redistribution and use in source and binary forms, with or without
13145510Sdarrenr * modification, are permitted provided that the following conditions
14145510Sdarrenr * are met:
15145510Sdarrenr * 1. Redistributions of source code must retain the above copyright
16145510Sdarrenr *    notice, this list of conditions and the following disclaimer.
17145510Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright
18145510Sdarrenr *    notice, this list of conditions and the following disclaimer in the
19145510Sdarrenr *    documentation and/or other materials provided with the distribution.
20145510Sdarrenr * 3. All advertising materials mentioning features or use of this software
21145510Sdarrenr *    must display the following acknowledgement:
22145510Sdarrenr *      This product includes software developed by the University of
23145510Sdarrenr *      California, Berkeley and its contributors.
24145510Sdarrenr * 4. Neither the name of the University nor the names of its contributors
25145510Sdarrenr *    may be used to endorse or promote products derived from this software
26145510Sdarrenr *    without specific prior written permission.
27145510Sdarrenr *
28145510Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29145510Sdarrenr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30145510Sdarrenr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31145510Sdarrenr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32145510Sdarrenr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33145510Sdarrenr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34145510Sdarrenr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35145510Sdarrenr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36145510Sdarrenr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37145510Sdarrenr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38145510Sdarrenr * SUCH DAMAGE.
39145510Sdarrenr *
40145510Sdarrenr *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
41145510Sdarrenr *
42145510Sdarrenr * @(#) $Header: /devel/CVS/IP-Filter/bpf-ipf.h,v 2.1 2002/10/26 12:14:26 darrenr Exp $ (LBL)
43145510Sdarrenr */
44145510Sdarrenr
45145510Sdarrenr#ifndef BPF_MAJOR_VERSION
46145510Sdarrenr
47145510Sdarrenr#ifdef __cplusplus
48145510Sdarrenrextern "C" {
49145510Sdarrenr#endif
50145510Sdarrenr
51145510Sdarrenr/* BSD style release date */
52145510Sdarrenr#define BPF_RELEASE 199606
53145510Sdarrenr
54145510Sdarrenrtypedef	int bpf_int32;
55145510Sdarrenrtypedef	u_int bpf_u_int32;
56145510Sdarrenr
57145510Sdarrenr/*
58145510Sdarrenr * Alignment macros.  BPF_WORDALIGN rounds up to the next
59145510Sdarrenr * even multiple of BPF_ALIGNMENT.
60145510Sdarrenr */
61145510Sdarrenr#ifndef __NetBSD__
62145510Sdarrenr#define BPF_ALIGNMENT sizeof(bpf_int32)
63145510Sdarrenr#else
64145510Sdarrenr#define BPF_ALIGNMENT sizeof(long)
65145510Sdarrenr#endif
66145510Sdarrenr#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
67145510Sdarrenr
68145510Sdarrenr#define BPF_MAXINSNS 512
69145510Sdarrenr#define BPF_MAXBUFSIZE 0x8000
70145510Sdarrenr#define BPF_MINBUFSIZE 32
71145510Sdarrenr
72145510Sdarrenr/*
73145510Sdarrenr *  Structure for BIOCSETF.
74145510Sdarrenr */
75145510Sdarrenrstruct bpf_program {
76145510Sdarrenr	u_int bf_len;
77145510Sdarrenr	struct bpf_insn *bf_insns;
78145510Sdarrenr};
79145510Sdarrenr
80145510Sdarrenr/*
81145510Sdarrenr * Struct returned by BIOCGSTATS.
82145510Sdarrenr */
83145510Sdarrenrstruct bpf_stat {
84145510Sdarrenr	u_int bs_recv;		/* number of packets received */
85145510Sdarrenr	u_int bs_drop;		/* number of packets dropped */
86145510Sdarrenr};
87145510Sdarrenr
88145510Sdarrenr/*
89145510Sdarrenr * Struct return by BIOCVERSION.  This represents the version number of
90145510Sdarrenr * the filter language described by the instruction encodings below.
91145510Sdarrenr * bpf understands a program iff kernel_major == filter_major &&
92145510Sdarrenr * kernel_minor >= filter_minor, that is, if the value returned by the
93145510Sdarrenr * running kernel has the same major number and a minor number equal
94145510Sdarrenr * equal to or less than the filter being downloaded.  Otherwise, the
95145510Sdarrenr * results are undefined, meaning an error may be returned or packets
96145510Sdarrenr * may be accepted haphazardly.
97145510Sdarrenr * It has nothing to do with the source code version.
98145510Sdarrenr */
99145510Sdarrenrstruct bpf_version {
100145510Sdarrenr	u_short bv_major;
101145510Sdarrenr	u_short bv_minor;
102145510Sdarrenr};
103145510Sdarrenr/* Current version number of filter architecture. */
104145510Sdarrenr#define BPF_MAJOR_VERSION 1
105145510Sdarrenr#define BPF_MINOR_VERSION 1
106145510Sdarrenr
107145510Sdarrenr/*
108145510Sdarrenr * BPF ioctls
109145510Sdarrenr *
110145510Sdarrenr * The first set is for compatibility with Sun's pcc style
111145510Sdarrenr * header files.  If your using gcc, we assume that you
112145510Sdarrenr * have run fixincludes so the latter set should work.
113145510Sdarrenr */
114145510Sdarrenr#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
115145510Sdarrenr#define	BIOCGBLEN	_IOR(B,102, u_int)
116145510Sdarrenr#define	BIOCSBLEN	_IOWR(B,102, u_int)
117145510Sdarrenr#define	BIOCSETF	_IOW(B,103, struct bpf_program)
118145510Sdarrenr#define	BIOCFLUSH	_IO(B,104)
119145510Sdarrenr#define BIOCPROMISC	_IO(B,105)
120145510Sdarrenr#define	BIOCGDLT	_IOR(B,106, u_int)
121145510Sdarrenr#define BIOCGETIF	_IOR(B,107, struct ifreq)
122145510Sdarrenr#define BIOCSETIF	_IOW(B,108, struct ifreq)
123145510Sdarrenr#define BIOCSRTIMEOUT	_IOW(B,109, struct timeval)
124145510Sdarrenr#define BIOCGRTIMEOUT	_IOR(B,110, struct timeval)
125145510Sdarrenr#define BIOCGSTATS	_IOR(B,111, struct bpf_stat)
126145510Sdarrenr#define BIOCIMMEDIATE	_IOW(B,112, u_int)
127145510Sdarrenr#define BIOCVERSION	_IOR(B,113, struct bpf_version)
128145510Sdarrenr#define BIOCSTCPF	_IOW(B,114, struct bpf_program)
129145510Sdarrenr#define BIOCSUDPF	_IOW(B,115, struct bpf_program)
130145510Sdarrenr#else
131145510Sdarrenr#define	BIOCGBLEN	_IOR('B',102, u_int)
132145510Sdarrenr#define	BIOCSBLEN	_IOWR('B',102, u_int)
133145510Sdarrenr#define	BIOCSETF	_IOW('B',103, struct bpf_program)
134145510Sdarrenr#define	BIOCFLUSH	_IO('B',104)
135145510Sdarrenr#define BIOCPROMISC	_IO('B',105)
136145510Sdarrenr#define	BIOCGDLT	_IOR('B',106, u_int)
137145510Sdarrenr#define BIOCGETIF	_IOR('B',107, struct ifreq)
138145510Sdarrenr#define BIOCSETIF	_IOW('B',108, struct ifreq)
139145510Sdarrenr#define BIOCSRTIMEOUT	_IOW('B',109, struct timeval)
140145510Sdarrenr#define BIOCGRTIMEOUT	_IOR('B',110, struct timeval)
141145510Sdarrenr#define BIOCGSTATS	_IOR('B',111, struct bpf_stat)
142145510Sdarrenr#define BIOCIMMEDIATE	_IOW('B',112, u_int)
143145510Sdarrenr#define BIOCVERSION	_IOR('B',113, struct bpf_version)
144145510Sdarrenr#define BIOCSTCPF	_IOW('B',114, struct bpf_program)
145145510Sdarrenr#define BIOCSUDPF	_IOW('B',115, struct bpf_program)
146145510Sdarrenr#endif
147145510Sdarrenr
148145510Sdarrenr/*
149145510Sdarrenr * Structure prepended to each packet.
150145510Sdarrenr */
151145510Sdarrenrstruct bpf_hdr {
152145510Sdarrenr	struct timeval	bh_tstamp;	/* time stamp */
153145510Sdarrenr	bpf_u_int32	bh_caplen;	/* length of captured portion */
154145510Sdarrenr	bpf_u_int32	bh_datalen;	/* original length of packet */
155145510Sdarrenr	u_short		bh_hdrlen;	/* length of bpf header (this struct
156145510Sdarrenr					   plus alignment padding) */
157145510Sdarrenr};
158145510Sdarrenr/*
159145510Sdarrenr * Because the structure above is not a multiple of 4 bytes, some compilers
160145510Sdarrenr * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
161145510Sdarrenr * Only the kernel needs to know about it; applications use bh_hdrlen.
162145510Sdarrenr */
163145510Sdarrenr#if defined(KERNEL) || defined(_KERNEL)
164145510Sdarrenr#define SIZEOF_BPF_HDR 18
165145510Sdarrenr#endif
166145510Sdarrenr
167145510Sdarrenr/*
168145510Sdarrenr * Data-link level type codes.
169145510Sdarrenr */
170145510Sdarrenr
171145510Sdarrenr/*
172145510Sdarrenr * These are the types that are the same on all platforms; on other
173145510Sdarrenr * platforms, a <net/bpf.h> should be supplied that defines the additional
174145510Sdarrenr * DLT_* codes appropriately for that platform (the BSDs, for example,
175145510Sdarrenr * should not just pick up this version of "bpf.h"; they should also define
176145510Sdarrenr * the additional DLT_* codes used by their kernels, as well as the values
177145510Sdarrenr * defined here - and, if the values they use for particular DLT_ types
178145510Sdarrenr * differ from those here, they should use their values, not the ones
179145510Sdarrenr * here).
180145510Sdarrenr */
181145510Sdarrenr#define DLT_NULL	0	/* no link-layer encapsulation */
182145510Sdarrenr#define DLT_EN10MB	1	/* Ethernet (10Mb) */
183145510Sdarrenr#define DLT_EN3MB	2	/* Experimental Ethernet (3Mb) */
184145510Sdarrenr#define DLT_AX25	3	/* Amateur Radio AX.25 */
185145510Sdarrenr#define DLT_PRONET	4	/* Proteon ProNET Token Ring */
186145510Sdarrenr#define DLT_CHAOS	5	/* Chaos */
187145510Sdarrenr#define DLT_IEEE802	6	/* IEEE 802 Networks */
188145510Sdarrenr#define DLT_ARCNET	7	/* ARCNET */
189145510Sdarrenr#define DLT_SLIP	8	/* Serial Line IP */
190145510Sdarrenr#define DLT_PPP		9	/* Point-to-point Protocol */
191145510Sdarrenr#define DLT_FDDI	10	/* FDDI */
192145510Sdarrenr
193145510Sdarrenr/*
194145510Sdarrenr * These are values from the traditional libpcap "bpf.h".
195145510Sdarrenr * Ports of this to particular platforms should replace these definitions
196145510Sdarrenr * with the ones appropriate to that platform, if the values are
197145510Sdarrenr * different on that platform.
198145510Sdarrenr */
199145510Sdarrenr#define DLT_ATM_RFC1483	11	/* LLC/SNAP encapsulated atm */
200145510Sdarrenr#define DLT_RAW		12	/* raw IP */
201145510Sdarrenr
202145510Sdarrenr/*
203145510Sdarrenr * These are values from BSD/OS's "bpf.h".
204145510Sdarrenr * These are not the same as the values from the traditional libpcap
205145510Sdarrenr * "bpf.h"; however, these values shouldn't be generated by any
206145510Sdarrenr * OS other than BSD/OS, so the correct values to use here are the
207145510Sdarrenr * BSD/OS values.
208145510Sdarrenr *
209145510Sdarrenr * Platforms that have already assigned these values to other
210145510Sdarrenr * DLT_ codes, however, should give these codes the values
211145510Sdarrenr * from that platform, so that programs that use these codes will
212145510Sdarrenr * continue to compile - even though they won't correctly read
213145510Sdarrenr * files of these types.
214145510Sdarrenr */
215145510Sdarrenr#ifdef __NetBSD__
216145510Sdarrenr#ifndef DLT_SLIP_BSDOS
217145510Sdarrenr#define DLT_SLIP_BSDOS	13	/* BSD/OS Serial Line IP */
218145510Sdarrenr#define DLT_PPP_BSDOS	14	/* BSD/OS Point-to-point Protocol */
219145510Sdarrenr#endif
220145510Sdarrenr#else
221145510Sdarrenr#define DLT_SLIP_BSDOS	15	/* BSD/OS Serial Line IP */
222145510Sdarrenr#define DLT_PPP_BSDOS	16	/* BSD/OS Point-to-point Protocol */
223145510Sdarrenr#endif
224145510Sdarrenr
225145510Sdarrenr#define DLT_ATM_CLIP	19	/* Linux Classical-IP over ATM */
226145510Sdarrenr
227145510Sdarrenr/*
228145510Sdarrenr * These values are defined by NetBSD; other platforms should refrain from
229145510Sdarrenr * using them for other purposes, so that NetBSD savefiles with link
230145510Sdarrenr * types of 50 or 51 can be read as this type on all platforms.
231145510Sdarrenr */
232145510Sdarrenr#define DLT_PPP_SERIAL	50	/* PPP over serial with HDLC encapsulation */
233145510Sdarrenr#define DLT_PPP_ETHER	51	/* PPP over Ethernet */
234145510Sdarrenr
235145510Sdarrenr/*
236145510Sdarrenr * Values between 100 and 103 are used in capture file headers as
237145510Sdarrenr * link-layer types corresponding to DLT_ types that differ
238145510Sdarrenr * between platforms; don't use those values for new DLT_ new types.
239145510Sdarrenr */
240145510Sdarrenr
241145510Sdarrenr/*
242145510Sdarrenr * This value was defined by libpcap 0.5; platforms that have defined
243145510Sdarrenr * it with a different value should define it here with that value -
244145510Sdarrenr * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
245145510Sdarrenr * whatever value that happens to be, so programs will correctly
246145510Sdarrenr * handle files with that link type regardless of the value of
247145510Sdarrenr * DLT_C_HDLC.
248145510Sdarrenr *
249145510Sdarrenr * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
250145510Sdarrenr * compatibility with programs written for BSD/OS.
251145510Sdarrenr *
252145510Sdarrenr * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
253145510Sdarrenr * for source compatibility with programs written for libpcap 0.5.
254145510Sdarrenr */
255145510Sdarrenr#define DLT_C_HDLC	104	/* Cisco HDLC */
256145510Sdarrenr#define DLT_CHDLC	DLT_C_HDLC
257145510Sdarrenr
258145510Sdarrenr#define DLT_IEEE802_11	105	/* IEEE 802.11 wireless */
259145510Sdarrenr
260145510Sdarrenr/*
261145510Sdarrenr * Values between 106 and 107 are used in capture file headers as
262145510Sdarrenr * link-layer types corresponding to DLT_ types that might differ
263145510Sdarrenr * between platforms; don't use those values for new DLT_ new types.
264145510Sdarrenr */
265145510Sdarrenr
266145510Sdarrenr/*
267145510Sdarrenr * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
268145510Sdarrenr * that the AF_ type in the link-layer header is in network byte order.
269145510Sdarrenr *
270145510Sdarrenr * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
271145510Sdarrenr * define it as 108 here.  If OpenBSD picks up this file, it should
272145510Sdarrenr * define DLT_LOOP as 12 in its version, as per the comment above -
273145510Sdarrenr * and should not use 108 as a DLT_ value.
274145510Sdarrenr */
275145510Sdarrenr#define DLT_LOOP	108
276145510Sdarrenr
277145510Sdarrenr/*
278145510Sdarrenr * Values between 109 and 112 are used in capture file headers as
279145510Sdarrenr * link-layer types corresponding to DLT_ types that might differ
280145510Sdarrenr * between platforms; don't use those values for new DLT_ types
281145510Sdarrenr * other than the corresponding DLT_ types.
282145510Sdarrenr */
283145510Sdarrenr
284145510Sdarrenr/*
285145510Sdarrenr * This is for Linux cooked sockets.
286145510Sdarrenr */
287145510Sdarrenr#define DLT_LINUX_SLL	113
288145510Sdarrenr
289145510Sdarrenr/*
290145510Sdarrenr * Apple LocalTalk hardware.
291145510Sdarrenr */
292145510Sdarrenr#define DLT_LTALK	114
293145510Sdarrenr
294145510Sdarrenr/*
295145510Sdarrenr * Acorn Econet.
296145510Sdarrenr */
297145510Sdarrenr#define DLT_ECONET	115
298145510Sdarrenr
299145510Sdarrenr/*
300145510Sdarrenr * Reserved for use with OpenBSD ipfilter.
301145510Sdarrenr */
302145510Sdarrenr#define DLT_IPFILTER	116
303145510Sdarrenr
304145510Sdarrenr/*
305145510Sdarrenr * Reserved for use in capture-file headers as a link-layer type
306145510Sdarrenr * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
307145510Sdarrenr * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
308145510Sdarrenr * in capture-file headers.
309145510Sdarrenr */
310145510Sdarrenr#define DLT_PFLOG	117
311145510Sdarrenr
312145510Sdarrenr/*
313145510Sdarrenr * Registered for Cisco-internal use.
314145510Sdarrenr */
315145510Sdarrenr#define DLT_CISCO_IOS	118
316145510Sdarrenr
317145510Sdarrenr/*
318145510Sdarrenr * Reserved for 802.11 cards using the Prism II chips, with a link-layer
319145510Sdarrenr * header including Prism monitor mode information plus an 802.11
320145510Sdarrenr * header.
321145510Sdarrenr */
322145510Sdarrenr#define DLT_PRISM_HEADER	119
323145510Sdarrenr
324145510Sdarrenr/*
325145510Sdarrenr * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
326145510Sdarrenr * (see Doug Ambrisko's FreeBSD patches).
327145510Sdarrenr */
328145510Sdarrenr#define DLT_AIRONET_HEADER	120
329145510Sdarrenr
330145510Sdarrenr/*
331145510Sdarrenr * Reserved for Siemens HiPath HDLC.
332145510Sdarrenr */
333145510Sdarrenr#define DLT_HHDLC		121
334145510Sdarrenr
335145510Sdarrenr/*
336145510Sdarrenr * Reserved for RFC 2625 IP-over-Fibre Channel, as per a request from
337145510Sdarrenr * Don Lee <donlee@cray.com>.
338145510Sdarrenr *
339145510Sdarrenr * This is not for use with raw Fibre Channel, where the link-layer
340145510Sdarrenr * header starts with a Fibre Channel frame header; it's for IP-over-FC,
341145510Sdarrenr * where the link-layer header starts with an RFC 2625 Network_Header
342145510Sdarrenr * field.
343145510Sdarrenr */
344145510Sdarrenr#define DLT_IP_OVER_FC		122
345145510Sdarrenr
346145510Sdarrenr/*
347145510Sdarrenr * The instruction encodings.
348145510Sdarrenr */
349145510Sdarrenr/* instruction classes */
350145510Sdarrenr#define BPF_CLASS(code) ((code) & 0x07)
351145510Sdarrenr#define		BPF_LD		0x00
352145510Sdarrenr#define		BPF_LDX		0x01
353145510Sdarrenr#define		BPF_ST		0x02
354145510Sdarrenr#define		BPF_STX		0x03
355145510Sdarrenr#define		BPF_ALU		0x04
356145510Sdarrenr#define		BPF_JMP		0x05
357145510Sdarrenr#define		BPF_RET		0x06
358145510Sdarrenr#define		BPF_MISC	0x07
359145510Sdarrenr
360145510Sdarrenr/* ld/ldx fields */
361145510Sdarrenr#define BPF_SIZE(code)	((code) & 0x18)
362145510Sdarrenr#define		BPF_W		0x00
363145510Sdarrenr#define		BPF_H		0x08
364145510Sdarrenr#define		BPF_B		0x10
365145510Sdarrenr#define BPF_MODE(code)	((code) & 0xe0)
366145510Sdarrenr#define		BPF_IMM 	0x00
367145510Sdarrenr#define		BPF_ABS		0x20
368145510Sdarrenr#define		BPF_IND		0x40
369145510Sdarrenr#define		BPF_MEM		0x60
370145510Sdarrenr#define		BPF_LEN		0x80
371145510Sdarrenr#define		BPF_MSH		0xa0
372145510Sdarrenr
373145510Sdarrenr/* alu/jmp fields */
374145510Sdarrenr#define BPF_OP(code)	((code) & 0xf0)
375145510Sdarrenr#define		BPF_ADD		0x00
376145510Sdarrenr#define		BPF_SUB		0x10
377145510Sdarrenr#define		BPF_MUL		0x20
378145510Sdarrenr#define		BPF_DIV		0x30
379145510Sdarrenr#define		BPF_OR		0x40
380145510Sdarrenr#define		BPF_AND		0x50
381145510Sdarrenr#define		BPF_LSH		0x60
382145510Sdarrenr#define		BPF_RSH		0x70
383145510Sdarrenr#define		BPF_NEG		0x80
384145510Sdarrenr#define		BPF_JA		0x00
385145510Sdarrenr#define		BPF_JEQ		0x10
386145510Sdarrenr#define		BPF_JGT		0x20
387145510Sdarrenr#define		BPF_JGE		0x30
388145510Sdarrenr#define		BPF_JSET	0x40
389145510Sdarrenr#define BPF_SRC(code)	((code) & 0x08)
390145510Sdarrenr#define		BPF_K		0x00
391145510Sdarrenr#define		BPF_X		0x08
392145510Sdarrenr
393145510Sdarrenr/* ret - BPF_K and BPF_X also apply */
394145510Sdarrenr#define BPF_RVAL(code)	((code) & 0x18)
395145510Sdarrenr#define		BPF_A		0x10
396145510Sdarrenr
397145510Sdarrenr/* misc */
398145510Sdarrenr#define BPF_MISCOP(code) ((code) & 0xf8)
399145510Sdarrenr#define		BPF_TAX		0x00
400145510Sdarrenr#define		BPF_TXA		0x80
401145510Sdarrenr
402145510Sdarrenr/*
403145510Sdarrenr * The instruction data structure.
404145510Sdarrenr */
405145510Sdarrenrstruct bpf_insn {
406145510Sdarrenr	u_short	code;
407145510Sdarrenr	u_char 	jt;
408145510Sdarrenr	u_char 	jf;
409145510Sdarrenr	bpf_int32 k;
410145510Sdarrenr};
411145510Sdarrenr
412145510Sdarrenr/*
413145510Sdarrenr * Macros for insn array initializers.
414145510Sdarrenr */
415145510Sdarrenr#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
416145510Sdarrenr#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
417145510Sdarrenr
418145510Sdarrenr#if defined(BSD) && (defined(KERNEL) || defined(_KERNEL))
419145510Sdarrenr/*
420145510Sdarrenr * Systems based on non-BSD kernels don't have ifnet's (or they don't mean
421145510Sdarrenr * anything if it is in <net/if.h>) and won't work like this.
422145510Sdarrenr */
423145510Sdarrenr# if __STDC__
424145510Sdarrenrextern void bpf_tap(struct ifnet *, u_char *, u_int);
425145510Sdarrenrextern void bpf_mtap(struct ifnet *, struct mbuf *);
426145510Sdarrenrextern void bpfattach(struct ifnet *, u_int, u_int);
427145510Sdarrenrextern void bpfilterattach(int);
428145510Sdarrenr# else
429145510Sdarrenrextern void bpf_tap();
430145510Sdarrenrextern void bpf_mtap();
431145510Sdarrenrextern void bpfattach();
432145510Sdarrenrextern void bpfilterattach();
433145510Sdarrenr# endif /* __STDC__ */
434145510Sdarrenr#endif /* BSD && (_KERNEL || KERNEL) */
435145510Sdarrenr#if __STDC__ || defined(__cplusplus)
436145510Sdarrenrextern int bpf_validate(struct bpf_insn *, int);
437145510Sdarrenrextern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
438145510Sdarrenr#else
439145510Sdarrenrextern int bpf_validate();
440145510Sdarrenrextern u_int bpf_filter();
441145510Sdarrenr#endif
442145510Sdarrenr
443145510Sdarrenr/*
444145510Sdarrenr * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
445145510Sdarrenr */
446145510Sdarrenr#define BPF_MEMWORDS 16
447145510Sdarrenr
448145510Sdarrenr#ifdef __cplusplus
449145510Sdarrenr}
450145510Sdarrenr#endif
451145510Sdarrenr
452145510Sdarrenr#endif
453