xref: /freebsd/sys/net/bpf.h (revision 8eab61f3def6c67c312857f519c6f1efabad1ed0)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1990, 1991, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from the Stanford/CMU enet packet filter,
6df8bae1dSRodney W. Grimes  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7df8bae1dSRodney W. Grimes  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8df8bae1dSRodney W. Grimes  * Berkeley Laboratory.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  *      @(#)bpf.h	8.1 (Berkeley) 6/10/93
3911a53ef3SPaul Traina  *	@(#)bpf.h	1.34 (LBL)     6/16/96
40df8bae1dSRodney W. Grimes  *
41c3aac50fSPeter Wemm  * $FreeBSD$
42df8bae1dSRodney W. Grimes  */
43df8bae1dSRodney W. Grimes 
44cea1da3bSPaul Richards #ifndef _NET_BPF_H_
45cea1da3bSPaul Richards #define _NET_BPF_H_
46cea1da3bSPaul Richards 
4711a53ef3SPaul Traina /* BSD style release date */
4811a53ef3SPaul Traina #define	BPF_RELEASE 199606
4911a53ef3SPaul Traina 
5011a53ef3SPaul Traina typedef	int32_t	  bpf_int32;
5111a53ef3SPaul Traina typedef	u_int32_t bpf_u_int32;
5211a53ef3SPaul Traina 
53df8bae1dSRodney W. Grimes /*
54df8bae1dSRodney W. Grimes  * Alignment macros.  BPF_WORDALIGN rounds up to the next
55df8bae1dSRodney W. Grimes  * even multiple of BPF_ALIGNMENT.
56df8bae1dSRodney W. Grimes  */
57ba136d4fSAlexander Langer #define BPF_ALIGNMENT sizeof(long)
58df8bae1dSRodney W. Grimes #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
59df8bae1dSRodney W. Grimes 
60df8bae1dSRodney W. Grimes #define BPF_MAXINSNS 512
61eba2a1aeSPoul-Henning Kamp #define BPF_MAXBUFSIZE 0x80000
62df8bae1dSRodney W. Grimes #define BPF_MINBUFSIZE 32
63df8bae1dSRodney W. Grimes 
64df8bae1dSRodney W. Grimes /*
65df8bae1dSRodney W. Grimes  *  Structure for BIOCSETF.
66df8bae1dSRodney W. Grimes  */
67df8bae1dSRodney W. Grimes struct bpf_program {
68df8bae1dSRodney W. Grimes 	u_int bf_len;
69df8bae1dSRodney W. Grimes 	struct bpf_insn *bf_insns;
70df8bae1dSRodney W. Grimes };
71df8bae1dSRodney W. Grimes 
72df8bae1dSRodney W. Grimes /*
73df8bae1dSRodney W. Grimes  * Struct returned by BIOCGSTATS.
74df8bae1dSRodney W. Grimes  */
75df8bae1dSRodney W. Grimes struct bpf_stat {
76df8bae1dSRodney W. Grimes 	u_int bs_recv;		/* number of packets received */
77df8bae1dSRodney W. Grimes 	u_int bs_drop;		/* number of packets dropped */
78df8bae1dSRodney W. Grimes };
79df8bae1dSRodney W. Grimes 
80df8bae1dSRodney W. Grimes /*
81df8bae1dSRodney W. Grimes  * Struct return by BIOCVERSION.  This represents the version number of
82df8bae1dSRodney W. Grimes  * the filter language described by the instruction encodings below.
83df8bae1dSRodney W. Grimes  * bpf understands a program iff kernel_major == filter_major &&
84df8bae1dSRodney W. Grimes  * kernel_minor >= filter_minor, that is, if the value returned by the
85df8bae1dSRodney W. Grimes  * running kernel has the same major number and a minor number equal
86df8bae1dSRodney W. Grimes  * equal to or less than the filter being downloaded.  Otherwise, the
87df8bae1dSRodney W. Grimes  * results are undefined, meaning an error may be returned or packets
88df8bae1dSRodney W. Grimes  * may be accepted haphazardly.
89df8bae1dSRodney W. Grimes  * It has nothing to do with the source code version.
90df8bae1dSRodney W. Grimes  */
91df8bae1dSRodney W. Grimes struct bpf_version {
92df8bae1dSRodney W. Grimes 	u_short bv_major;
93df8bae1dSRodney W. Grimes 	u_short bv_minor;
94df8bae1dSRodney W. Grimes };
9511a53ef3SPaul Traina /* Current version number of filter architecture. */
96df8bae1dSRodney W. Grimes #define BPF_MAJOR_VERSION 1
97df8bae1dSRodney W. Grimes #define BPF_MINOR_VERSION 1
98df8bae1dSRodney W. Grimes 
99df8bae1dSRodney W. Grimes #define	BIOCGBLEN	_IOR('B',102, u_int)
100df8bae1dSRodney W. Grimes #define	BIOCSBLEN	_IOWR('B',102, u_int)
101df8bae1dSRodney W. Grimes #define	BIOCSETF	_IOW('B',103, struct bpf_program)
102df8bae1dSRodney W. Grimes #define	BIOCFLUSH	_IO('B',104)
103df8bae1dSRodney W. Grimes #define BIOCPROMISC	_IO('B',105)
104df8bae1dSRodney W. Grimes #define	BIOCGDLT	_IOR('B',106, u_int)
105df8bae1dSRodney W. Grimes #define BIOCGETIF	_IOR('B',107, struct ifreq)
106df8bae1dSRodney W. Grimes #define BIOCSETIF	_IOW('B',108, struct ifreq)
107df8bae1dSRodney W. Grimes #define BIOCSRTIMEOUT	_IOW('B',109, struct timeval)
108df8bae1dSRodney W. Grimes #define BIOCGRTIMEOUT	_IOR('B',110, struct timeval)
109df8bae1dSRodney W. Grimes #define BIOCGSTATS	_IOR('B',111, struct bpf_stat)
110df8bae1dSRodney W. Grimes #define BIOCIMMEDIATE	_IOW('B',112, u_int)
111df8bae1dSRodney W. Grimes #define BIOCVERSION	_IOR('B',113, struct bpf_version)
11200a83887SPaul Traina #define BIOCGRSIG	_IOR('B',114, u_int)
11300a83887SPaul Traina #define BIOCSRSIG	_IOW('B',115, u_int)
114114ae644SMike Smith #define BIOCGHDRCMPLT	_IOR('B',116, u_int)
115114ae644SMike Smith #define BIOCSHDRCMPLT	_IOW('B',117, u_int)
1168ed3828cSRobert Watson #define BIOCGSEESENT	_IOR('B',118, u_int)
1178ed3828cSRobert Watson #define BIOCSSEESENT	_IOW('B',119, u_int)
1188eab61f3SSam Leffler #define	BIOCSDLT	_IOW('B',120, u_int)
1198eab61f3SSam Leffler #define	BIOCGDLTLIST	_IOWR('B',121, struct bpf_dltlist)
120df8bae1dSRodney W. Grimes 
121df8bae1dSRodney W. Grimes /*
122df8bae1dSRodney W. Grimes  * Structure prepended to each packet.
123df8bae1dSRodney W. Grimes  */
124df8bae1dSRodney W. Grimes struct bpf_hdr {
125df8bae1dSRodney W. Grimes 	struct timeval	bh_tstamp;	/* time stamp */
12611a53ef3SPaul Traina 	bpf_u_int32	bh_caplen;	/* length of captured portion */
12711a53ef3SPaul Traina 	bpf_u_int32	bh_datalen;	/* original length of packet */
128df8bae1dSRodney W. Grimes 	u_short		bh_hdrlen;	/* length of bpf header (this struct
129df8bae1dSRodney W. Grimes 					   plus alignment padding) */
130df8bae1dSRodney W. Grimes };
131df8bae1dSRodney W. Grimes /*
132df8bae1dSRodney W. Grimes  * Because the structure above is not a multiple of 4 bytes, some compilers
133df8bae1dSRodney W. Grimes  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
134df8bae1dSRodney W. Grimes  * Only the kernel needs to know about it; applications use bh_hdrlen.
135df8bae1dSRodney W. Grimes  */
136664a31e4SPeter Wemm #ifdef _KERNEL
137c086febeSBruce Evans #define	SIZEOF_BPF_HDR	(sizeof(struct bpf_hdr) <= 20 ? 18 : \
138c086febeSBruce Evans     sizeof(struct bpf_hdr))
139df8bae1dSRodney W. Grimes #endif
140df8bae1dSRodney W. Grimes 
141df8bae1dSRodney W. Grimes /*
142df8bae1dSRodney W. Grimes  * Data-link level type codes.
143df8bae1dSRodney W. Grimes  */
144df8bae1dSRodney W. Grimes #define DLT_NULL	0	/* no link-layer encapsulation */
145df8bae1dSRodney W. Grimes #define DLT_EN10MB	1	/* Ethernet (10Mb) */
146df8bae1dSRodney W. Grimes #define DLT_EN3MB	2	/* Experimental Ethernet (3Mb) */
147df8bae1dSRodney W. Grimes #define DLT_AX25	3	/* Amateur Radio AX.25 */
148df8bae1dSRodney W. Grimes #define DLT_PRONET	4	/* Proteon ProNET Token Ring */
149df8bae1dSRodney W. Grimes #define DLT_CHAOS	5	/* Chaos */
150df8bae1dSRodney W. Grimes #define DLT_IEEE802	6	/* IEEE 802 Networks */
151df8bae1dSRodney W. Grimes #define DLT_ARCNET	7	/* ARCNET */
152df8bae1dSRodney W. Grimes #define DLT_SLIP	8	/* Serial Line IP */
153df8bae1dSRodney W. Grimes #define DLT_PPP		9	/* Point-to-point Protocol */
154df8bae1dSRodney W. Grimes #define DLT_FDDI	10	/* FDDI */
15511a53ef3SPaul Traina #define DLT_ATM_RFC1483	11	/* LLC/SNAP encapsulated atm */
15622f05c43SAndrey A. Chernov #define DLT_RAW		12	/* raw IP */
15746da4bc6SBill Fenner 
15846da4bc6SBill Fenner /*
15946da4bc6SBill Fenner  * These are values from BSD/OS's "bpf.h".
16046da4bc6SBill Fenner  * These are not the same as the values from the traditional libpcap
16146da4bc6SBill Fenner  * "bpf.h"; however, these values shouldn't be generated by any
16246da4bc6SBill Fenner  * OS other than BSD/OS, so the correct values to use here are the
16346da4bc6SBill Fenner  * BSD/OS values.
16446da4bc6SBill Fenner  *
16546da4bc6SBill Fenner  * Platforms that have already assigned these values to other
16646da4bc6SBill Fenner  * DLT_ codes, however, should give these codes the values
16746da4bc6SBill Fenner  * from that platform, so that programs that use these codes will
16846da4bc6SBill Fenner  * continue to compile - even though they won't correctly read
16946da4bc6SBill Fenner  * files of these types.
17046da4bc6SBill Fenner  */
17146da4bc6SBill Fenner #define DLT_SLIP_BSDOS	15	/* BSD/OS Serial Line IP */
17246da4bc6SBill Fenner #define DLT_PPP_BSDOS	16	/* BSD/OS Point-to-point Protocol */
17346da4bc6SBill Fenner 
17446da4bc6SBill Fenner #define DLT_ATM_CLIP	19	/* Linux Classical-IP over ATM */
17546da4bc6SBill Fenner 
17646da4bc6SBill Fenner /*
17794413c0dSBill Fenner  * These values are defined by NetBSD; other platforms should refrain from
17894413c0dSBill Fenner  * using them for other purposes, so that NetBSD savefiles with link
17994413c0dSBill Fenner  * types of 50 or 51 can be read as this type on all platforms.
18046da4bc6SBill Fenner  */
18146da4bc6SBill Fenner #define DLT_PPP_SERIAL	50	/* PPP over serial with HDLC encapsulation */
18294413c0dSBill Fenner #define DLT_PPP_ETHER	51	/* PPP over Ethernet */
18346da4bc6SBill Fenner 
18446da4bc6SBill Fenner /*
18546da4bc6SBill Fenner  * This value was defined by libpcap 0.5; platforms that have defined
18646da4bc6SBill Fenner  * it with a different value should define it here with that value -
18746da4bc6SBill Fenner  * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
18846da4bc6SBill Fenner  * whatever value that happens to be, so programs will correctly
18946da4bc6SBill Fenner  * handle files with that link type regardless of the value of
19046da4bc6SBill Fenner  * DLT_C_HDLC.
19146da4bc6SBill Fenner  *
19246da4bc6SBill Fenner  * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
19346da4bc6SBill Fenner  * compatibility with programs written for BSD/OS.
19446da4bc6SBill Fenner  *
19546da4bc6SBill Fenner  * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
19646da4bc6SBill Fenner  * for source compatibility with programs written for libpcap 0.5.
19746da4bc6SBill Fenner  */
19846da4bc6SBill Fenner #define DLT_C_HDLC	104	/* Cisco HDLC */
19946da4bc6SBill Fenner #define DLT_CHDLC	DLT_C_HDLC
20046da4bc6SBill Fenner 
20146da4bc6SBill Fenner #define DLT_IEEE802_11	105	/* IEEE 802.11 wireless */
20246da4bc6SBill Fenner 
20346da4bc6SBill Fenner /*
20446da4bc6SBill Fenner  * Values between 106 and 107 are used in capture file headers as
20546da4bc6SBill Fenner  * link-layer types corresponding to DLT_ types that might differ
20646da4bc6SBill Fenner  * between platforms; don't use those values for new DLT_ new types.
20746da4bc6SBill Fenner  */
20846da4bc6SBill Fenner 
20946da4bc6SBill Fenner /*
21046da4bc6SBill Fenner  * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
21146da4bc6SBill Fenner  * that the AF_ type in the link-layer header is in network byte order.
21246da4bc6SBill Fenner  *
21346da4bc6SBill Fenner  * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
21446da4bc6SBill Fenner  * define it as 108 here.  If OpenBSD picks up this file, it should
21546da4bc6SBill Fenner  * define DLT_LOOP as 12 in its version, as per the comment above -
21694413c0dSBill Fenner  * and should not use 108 as a DLT_ value.
21746da4bc6SBill Fenner  */
21846da4bc6SBill Fenner #define DLT_LOOP	108
21946da4bc6SBill Fenner 
22046da4bc6SBill Fenner /*
22146da4bc6SBill Fenner  * Values between 109 and 112 are used in capture file headers as
22246da4bc6SBill Fenner  * link-layer types corresponding to DLT_ types that might differ
22346da4bc6SBill Fenner  * between platforms; don't use those values for new DLT_ new types.
22446da4bc6SBill Fenner  */
22546da4bc6SBill Fenner 
22646da4bc6SBill Fenner /*
22746da4bc6SBill Fenner  * This is for Linux cooked sockets.
22846da4bc6SBill Fenner  */
22946da4bc6SBill Fenner #define DLT_LINUX_SLL	113
230df8bae1dSRodney W. Grimes 
231df8bae1dSRodney W. Grimes /*
23294413c0dSBill Fenner  * Apple LocalTalk hardware.
23394413c0dSBill Fenner  */
23494413c0dSBill Fenner #define DLT_LTALK	114
23594413c0dSBill Fenner 
23694413c0dSBill Fenner /*
23794413c0dSBill Fenner  * Acorn Econet.
23894413c0dSBill Fenner  */
23994413c0dSBill Fenner #define DLT_ECONET	115
24094413c0dSBill Fenner 
24194413c0dSBill Fenner /*
24294413c0dSBill Fenner  * Reserved for use with OpenBSD ipfilter.
24394413c0dSBill Fenner  */
24494413c0dSBill Fenner #define DLT_IPFILTER	116
24594413c0dSBill Fenner 
24694413c0dSBill Fenner /*
24794413c0dSBill Fenner  * Reserved for use in capture-file headers as a link-layer type
24894413c0dSBill Fenner  * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
24994413c0dSBill Fenner  * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
25094413c0dSBill Fenner  * in capture-file headers.
25194413c0dSBill Fenner  */
25294413c0dSBill Fenner #define DLT_PFLOG	117
25394413c0dSBill Fenner 
25494413c0dSBill Fenner /*
25594413c0dSBill Fenner  * Registered for Cisco-internal use.
25694413c0dSBill Fenner  */
25794413c0dSBill Fenner #define DLT_CISCO_IOS	118
25894413c0dSBill Fenner 
25994413c0dSBill Fenner /*
26094413c0dSBill Fenner  * Reserved for 802.11 cards using the Prism II chips, with a link-layer
26194413c0dSBill Fenner  * header including Prism monitor mode information plus an 802.11
26294413c0dSBill Fenner  * header.
26394413c0dSBill Fenner  */
26494413c0dSBill Fenner #define DLT_PRISM_HEADER	119
26594413c0dSBill Fenner 
26694413c0dSBill Fenner /*
26794413c0dSBill Fenner  * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
26894413c0dSBill Fenner  * (see Doug Ambrisko's FreeBSD patches).
26994413c0dSBill Fenner  */
27094413c0dSBill Fenner #define DLT_AIRONET_HEADER	120
27194413c0dSBill Fenner 
27294413c0dSBill Fenner /*
2736c5e9bbdSMike Pritchard  * The instruction encodings.
274df8bae1dSRodney W. Grimes  */
275df8bae1dSRodney W. Grimes /* instruction classes */
276df8bae1dSRodney W. Grimes #define BPF_CLASS(code) ((code) & 0x07)
277df8bae1dSRodney W. Grimes #define		BPF_LD		0x00
278df8bae1dSRodney W. Grimes #define		BPF_LDX		0x01
279df8bae1dSRodney W. Grimes #define		BPF_ST		0x02
280df8bae1dSRodney W. Grimes #define		BPF_STX		0x03
281df8bae1dSRodney W. Grimes #define		BPF_ALU		0x04
282df8bae1dSRodney W. Grimes #define		BPF_JMP		0x05
283df8bae1dSRodney W. Grimes #define		BPF_RET		0x06
284df8bae1dSRodney W. Grimes #define		BPF_MISC	0x07
285df8bae1dSRodney W. Grimes 
286df8bae1dSRodney W. Grimes /* ld/ldx fields */
287df8bae1dSRodney W. Grimes #define BPF_SIZE(code)	((code) & 0x18)
288df8bae1dSRodney W. Grimes #define		BPF_W		0x00
289df8bae1dSRodney W. Grimes #define		BPF_H		0x08
290df8bae1dSRodney W. Grimes #define		BPF_B		0x10
291df8bae1dSRodney W. Grimes #define BPF_MODE(code)	((code) & 0xe0)
292df8bae1dSRodney W. Grimes #define		BPF_IMM 	0x00
293df8bae1dSRodney W. Grimes #define		BPF_ABS		0x20
294df8bae1dSRodney W. Grimes #define		BPF_IND		0x40
295df8bae1dSRodney W. Grimes #define		BPF_MEM		0x60
296df8bae1dSRodney W. Grimes #define		BPF_LEN		0x80
297df8bae1dSRodney W. Grimes #define		BPF_MSH		0xa0
298df8bae1dSRodney W. Grimes 
299df8bae1dSRodney W. Grimes /* alu/jmp fields */
300df8bae1dSRodney W. Grimes #define BPF_OP(code)	((code) & 0xf0)
301df8bae1dSRodney W. Grimes #define		BPF_ADD		0x00
302df8bae1dSRodney W. Grimes #define		BPF_SUB		0x10
303df8bae1dSRodney W. Grimes #define		BPF_MUL		0x20
304df8bae1dSRodney W. Grimes #define		BPF_DIV		0x30
305df8bae1dSRodney W. Grimes #define		BPF_OR		0x40
306df8bae1dSRodney W. Grimes #define		BPF_AND		0x50
307df8bae1dSRodney W. Grimes #define		BPF_LSH		0x60
308df8bae1dSRodney W. Grimes #define		BPF_RSH		0x70
309df8bae1dSRodney W. Grimes #define		BPF_NEG		0x80
310df8bae1dSRodney W. Grimes #define		BPF_JA		0x00
311df8bae1dSRodney W. Grimes #define		BPF_JEQ		0x10
312df8bae1dSRodney W. Grimes #define		BPF_JGT		0x20
313df8bae1dSRodney W. Grimes #define		BPF_JGE		0x30
314df8bae1dSRodney W. Grimes #define		BPF_JSET	0x40
315df8bae1dSRodney W. Grimes #define BPF_SRC(code)	((code) & 0x08)
316df8bae1dSRodney W. Grimes #define		BPF_K		0x00
317df8bae1dSRodney W. Grimes #define		BPF_X		0x08
318df8bae1dSRodney W. Grimes 
319df8bae1dSRodney W. Grimes /* ret - BPF_K and BPF_X also apply */
320df8bae1dSRodney W. Grimes #define BPF_RVAL(code)	((code) & 0x18)
321df8bae1dSRodney W. Grimes #define		BPF_A		0x10
322df8bae1dSRodney W. Grimes 
323df8bae1dSRodney W. Grimes /* misc */
324df8bae1dSRodney W. Grimes #define BPF_MISCOP(code) ((code) & 0xf8)
325df8bae1dSRodney W. Grimes #define		BPF_TAX		0x00
326df8bae1dSRodney W. Grimes #define		BPF_TXA		0x80
327df8bae1dSRodney W. Grimes 
328df8bae1dSRodney W. Grimes /*
329df8bae1dSRodney W. Grimes  * The instruction data structure.
330df8bae1dSRodney W. Grimes  */
331df8bae1dSRodney W. Grimes struct bpf_insn {
332df8bae1dSRodney W. Grimes 	u_short		code;
333df8bae1dSRodney W. Grimes 	u_char		jt;
334df8bae1dSRodney W. Grimes 	u_char		jf;
33511a53ef3SPaul Traina 	bpf_u_int32	k;
336df8bae1dSRodney W. Grimes };
337df8bae1dSRodney W. Grimes 
338df8bae1dSRodney W. Grimes /*
339df8bae1dSRodney W. Grimes  * Macros for insn array initializers.
340df8bae1dSRodney W. Grimes  */
341df8bae1dSRodney W. Grimes #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
342df8bae1dSRodney W. Grimes #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
343df8bae1dSRodney W. Grimes 
3448eab61f3SSam Leffler /*
3458eab61f3SSam Leffler  * Structure to retrieve available DLTs for the interface.
3468eab61f3SSam Leffler  */
3478eab61f3SSam Leffler struct bpf_dltlist {
3488eab61f3SSam Leffler 	u_int	bfl_len;	/* number of bfd_list array */
3498eab61f3SSam Leffler 	u_int	*bfl_list;	/* array of DLTs */
3508eab61f3SSam Leffler };
3518eab61f3SSam Leffler 
352664a31e4SPeter Wemm #ifdef _KERNEL
35324a229f4SSam Leffler struct bpf_if;
354929ddbbbSAlfred Perlstein int	 bpf_validate(const struct bpf_insn *, int);
35524a229f4SSam Leffler void	 bpf_tap(struct bpf_if *, u_char *, u_int);
35624a229f4SSam Leffler void	 bpf_mtap(struct bpf_if *, struct mbuf *);
357929ddbbbSAlfred Perlstein void	 bpfattach(struct ifnet *, u_int, u_int);
35824a229f4SSam Leffler void	 bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **);
359929ddbbbSAlfred Perlstein void	 bpfdetach(struct ifnet *);
360de5d9935SRobert Watson 
361929ddbbbSAlfred Perlstein void	 bpfilterattach(int);
362929ddbbbSAlfred Perlstein u_int	 bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int);
36324a229f4SSam Leffler 
36424a229f4SSam Leffler #define	BPF_TAP(_ifp,_pkt,_pktlen) do {				\
36524a229f4SSam Leffler 	if ((_ifp)->if_bpf)					\
36624a229f4SSam Leffler 		bpf_tap((_ifp)->if_bpf, (_pkt), (_pktlen));	\
36724a229f4SSam Leffler } while (0)
36824a229f4SSam Leffler #define	BPF_MTAP(_ifp,_m) do {					\
36924a229f4SSam Leffler 	if ((_ifp)->if_bpf)					\
37024a229f4SSam Leffler 		bpf_mtap((_ifp)->if_bpf, (_m));			\
37124a229f4SSam Leffler } while (0)
372df8bae1dSRodney W. Grimes #endif
373df8bae1dSRodney W. Grimes 
374df8bae1dSRodney W. Grimes /*
375df8bae1dSRodney W. Grimes  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
376df8bae1dSRodney W. Grimes  */
377df8bae1dSRodney W. Grimes #define BPF_MEMWORDS 16
378df8bae1dSRodney W. Grimes 
37924a229f4SSam Leffler #endif /* _NET_BPF_H_ */
380