xref: /freebsd/sys/net/bpf.h (revision 16d878cc99efc07781a49b1db1a33ed09018d139)
1c398230bSWarner Losh /*-
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  * 4. Neither the name of the University nor the names of its contributors
19df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
20df8bae1dSRodney W. Grimes  *    without specific prior written permission.
21df8bae1dSRodney W. Grimes  *
22df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
33df8bae1dSRodney W. Grimes  *
34df8bae1dSRodney W. Grimes  *      @(#)bpf.h	8.1 (Berkeley) 6/10/93
3511a53ef3SPaul Traina  *	@(#)bpf.h	1.34 (LBL)     6/16/96
36df8bae1dSRodney W. Grimes  *
37c3aac50fSPeter Wemm  * $FreeBSD$
38df8bae1dSRodney W. Grimes  */
39df8bae1dSRodney W. Grimes 
40cea1da3bSPaul Richards #ifndef _NET_BPF_H_
41cea1da3bSPaul Richards #define _NET_BPF_H_
42cea1da3bSPaul Richards 
4311a53ef3SPaul Traina /* BSD style release date */
4411a53ef3SPaul Traina #define	BPF_RELEASE 199606
4511a53ef3SPaul Traina 
4611a53ef3SPaul Traina typedef	int32_t	  bpf_int32;
4711a53ef3SPaul Traina typedef	u_int32_t bpf_u_int32;
4811a53ef3SPaul Traina 
49df8bae1dSRodney W. Grimes /*
50df8bae1dSRodney W. Grimes  * Alignment macros.  BPF_WORDALIGN rounds up to the next
51df8bae1dSRodney W. Grimes  * even multiple of BPF_ALIGNMENT.
52df8bae1dSRodney W. Grimes  */
53ba136d4fSAlexander Langer #define BPF_ALIGNMENT sizeof(long)
54df8bae1dSRodney W. Grimes #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
55df8bae1dSRodney W. Grimes 
56df8bae1dSRodney W. Grimes #define BPF_MAXINSNS 512
57eba2a1aeSPoul-Henning Kamp #define BPF_MAXBUFSIZE 0x80000
58df8bae1dSRodney W. Grimes #define BPF_MINBUFSIZE 32
59df8bae1dSRodney W. Grimes 
60df8bae1dSRodney W. Grimes /*
61df8bae1dSRodney W. Grimes  *  Structure for BIOCSETF.
62df8bae1dSRodney W. Grimes  */
63df8bae1dSRodney W. Grimes struct bpf_program {
64df8bae1dSRodney W. Grimes 	u_int bf_len;
65df8bae1dSRodney W. Grimes 	struct bpf_insn *bf_insns;
66df8bae1dSRodney W. Grimes };
67df8bae1dSRodney W. Grimes 
68df8bae1dSRodney W. Grimes /*
69df8bae1dSRodney W. Grimes  * Struct returned by BIOCGSTATS.
70df8bae1dSRodney W. Grimes  */
71df8bae1dSRodney W. Grimes struct bpf_stat {
72df8bae1dSRodney W. Grimes 	u_int bs_recv;		/* number of packets received */
73df8bae1dSRodney W. Grimes 	u_int bs_drop;		/* number of packets dropped */
74df8bae1dSRodney W. Grimes };
75df8bae1dSRodney W. Grimes 
76df8bae1dSRodney W. Grimes /*
77df8bae1dSRodney W. Grimes  * Struct return by BIOCVERSION.  This represents the version number of
78df8bae1dSRodney W. Grimes  * the filter language described by the instruction encodings below.
79df8bae1dSRodney W. Grimes  * bpf understands a program iff kernel_major == filter_major &&
80df8bae1dSRodney W. Grimes  * kernel_minor >= filter_minor, that is, if the value returned by the
81df8bae1dSRodney W. Grimes  * running kernel has the same major number and a minor number equal
82df8bae1dSRodney W. Grimes  * equal to or less than the filter being downloaded.  Otherwise, the
83df8bae1dSRodney W. Grimes  * results are undefined, meaning an error may be returned or packets
84df8bae1dSRodney W. Grimes  * may be accepted haphazardly.
85df8bae1dSRodney W. Grimes  * It has nothing to do with the source code version.
86df8bae1dSRodney W. Grimes  */
87df8bae1dSRodney W. Grimes struct bpf_version {
88df8bae1dSRodney W. Grimes 	u_short bv_major;
89df8bae1dSRodney W. Grimes 	u_short bv_minor;
90df8bae1dSRodney W. Grimes };
9111a53ef3SPaul Traina /* Current version number of filter architecture. */
92df8bae1dSRodney W. Grimes #define BPF_MAJOR_VERSION 1
93df8bae1dSRodney W. Grimes #define BPF_MINOR_VERSION 1
94df8bae1dSRodney W. Grimes 
95df8bae1dSRodney W. Grimes #define	BIOCGBLEN	_IOR('B',102, u_int)
96df8bae1dSRodney W. Grimes #define	BIOCSBLEN	_IOWR('B',102, u_int)
97df8bae1dSRodney W. Grimes #define	BIOCSETF	_IOW('B',103, struct bpf_program)
98df8bae1dSRodney W. Grimes #define	BIOCFLUSH	_IO('B',104)
99df8bae1dSRodney W. Grimes #define BIOCPROMISC	_IO('B',105)
100df8bae1dSRodney W. Grimes #define	BIOCGDLT	_IOR('B',106, u_int)
101df8bae1dSRodney W. Grimes #define BIOCGETIF	_IOR('B',107, struct ifreq)
102df8bae1dSRodney W. Grimes #define BIOCSETIF	_IOW('B',108, struct ifreq)
103df8bae1dSRodney W. Grimes #define BIOCSRTIMEOUT	_IOW('B',109, struct timeval)
104df8bae1dSRodney W. Grimes #define BIOCGRTIMEOUT	_IOR('B',110, struct timeval)
105df8bae1dSRodney W. Grimes #define BIOCGSTATS	_IOR('B',111, struct bpf_stat)
106df8bae1dSRodney W. Grimes #define BIOCIMMEDIATE	_IOW('B',112, u_int)
107df8bae1dSRodney W. Grimes #define BIOCVERSION	_IOR('B',113, struct bpf_version)
10800a83887SPaul Traina #define BIOCGRSIG	_IOR('B',114, u_int)
10900a83887SPaul Traina #define BIOCSRSIG	_IOW('B',115, u_int)
110114ae644SMike Smith #define BIOCGHDRCMPLT	_IOR('B',116, u_int)
111114ae644SMike Smith #define BIOCSHDRCMPLT	_IOW('B',117, u_int)
1128ed3828cSRobert Watson #define BIOCGSEESENT	_IOR('B',118, u_int)
1138ed3828cSRobert Watson #define BIOCSSEESENT	_IOW('B',119, u_int)
1148eab61f3SSam Leffler #define	BIOCSDLT	_IOW('B',120, u_int)
1158eab61f3SSam Leffler #define	BIOCGDLTLIST	_IOWR('B',121, struct bpf_dltlist)
11693e39f0bSChristian S.J. Peron #define	BIOCLOCK	_IO('B', 122)
11793e39f0bSChristian S.J. Peron #define	BIOCSETWF	_IOW('B',123, struct bpf_program)
118df8bae1dSRodney W. Grimes 
119df8bae1dSRodney W. Grimes /*
120df8bae1dSRodney W. Grimes  * Structure prepended to each packet.
121df8bae1dSRodney W. Grimes  */
122df8bae1dSRodney W. Grimes struct bpf_hdr {
123df8bae1dSRodney W. Grimes 	struct timeval	bh_tstamp;	/* time stamp */
12411a53ef3SPaul Traina 	bpf_u_int32	bh_caplen;	/* length of captured portion */
12511a53ef3SPaul Traina 	bpf_u_int32	bh_datalen;	/* original length of packet */
126df8bae1dSRodney W. Grimes 	u_short		bh_hdrlen;	/* length of bpf header (this struct
127df8bae1dSRodney W. Grimes 					   plus alignment padding) */
128df8bae1dSRodney W. Grimes };
129df8bae1dSRodney W. Grimes /*
130df8bae1dSRodney W. Grimes  * Because the structure above is not a multiple of 4 bytes, some compilers
131df8bae1dSRodney W. Grimes  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
132df8bae1dSRodney W. Grimes  * Only the kernel needs to know about it; applications use bh_hdrlen.
133df8bae1dSRodney W. Grimes  */
134664a31e4SPeter Wemm #ifdef _KERNEL
135c086febeSBruce Evans #define	SIZEOF_BPF_HDR	(sizeof(struct bpf_hdr) <= 20 ? 18 : \
136c086febeSBruce Evans     sizeof(struct bpf_hdr))
137df8bae1dSRodney W. Grimes #endif
138df8bae1dSRodney W. Grimes 
139df8bae1dSRodney W. Grimes /*
140df8bae1dSRodney W. Grimes  * Data-link level type codes.
141df8bae1dSRodney W. Grimes  */
142bde800e6SDavid Malone #define DLT_NULL	0	/* BSD loopback encapsulation */
143df8bae1dSRodney W. Grimes #define DLT_EN10MB	1	/* Ethernet (10Mb) */
144df8bae1dSRodney W. Grimes #define DLT_EN3MB	2	/* Experimental Ethernet (3Mb) */
145df8bae1dSRodney W. Grimes #define DLT_AX25	3	/* Amateur Radio AX.25 */
146df8bae1dSRodney W. Grimes #define DLT_PRONET	4	/* Proteon ProNET Token Ring */
147df8bae1dSRodney W. Grimes #define DLT_CHAOS	5	/* Chaos */
148df8bae1dSRodney W. Grimes #define DLT_IEEE802	6	/* IEEE 802 Networks */
149df8bae1dSRodney W. Grimes #define DLT_ARCNET	7	/* ARCNET */
150df8bae1dSRodney W. Grimes #define DLT_SLIP	8	/* Serial Line IP */
151df8bae1dSRodney W. Grimes #define DLT_PPP		9	/* Point-to-point Protocol */
152df8bae1dSRodney W. Grimes #define DLT_FDDI	10	/* FDDI */
15311a53ef3SPaul Traina #define DLT_ATM_RFC1483	11	/* LLC/SNAP encapsulated atm */
15422f05c43SAndrey A. Chernov #define DLT_RAW		12	/* raw IP */
15546da4bc6SBill Fenner 
15646da4bc6SBill Fenner /*
15746da4bc6SBill Fenner  * These are values from BSD/OS's "bpf.h".
15846da4bc6SBill Fenner  * These are not the same as the values from the traditional libpcap
15946da4bc6SBill Fenner  * "bpf.h"; however, these values shouldn't be generated by any
16046da4bc6SBill Fenner  * OS other than BSD/OS, so the correct values to use here are the
16146da4bc6SBill Fenner  * BSD/OS values.
16246da4bc6SBill Fenner  *
16346da4bc6SBill Fenner  * Platforms that have already assigned these values to other
16446da4bc6SBill Fenner  * DLT_ codes, however, should give these codes the values
16546da4bc6SBill Fenner  * from that platform, so that programs that use these codes will
16646da4bc6SBill Fenner  * continue to compile - even though they won't correctly read
16746da4bc6SBill Fenner  * files of these types.
16846da4bc6SBill Fenner  */
16946da4bc6SBill Fenner #define DLT_SLIP_BSDOS	15	/* BSD/OS Serial Line IP */
17046da4bc6SBill Fenner #define DLT_PPP_BSDOS	16	/* BSD/OS Point-to-point Protocol */
17146da4bc6SBill Fenner 
17246da4bc6SBill Fenner #define DLT_ATM_CLIP	19	/* Linux Classical-IP over ATM */
17346da4bc6SBill Fenner 
17446da4bc6SBill Fenner /*
17594413c0dSBill Fenner  * These values are defined by NetBSD; other platforms should refrain from
17694413c0dSBill Fenner  * using them for other purposes, so that NetBSD savefiles with link
17794413c0dSBill Fenner  * types of 50 or 51 can be read as this type on all platforms.
17846da4bc6SBill Fenner  */
17946da4bc6SBill Fenner #define DLT_PPP_SERIAL	50	/* PPP over serial with HDLC encapsulation */
18094413c0dSBill Fenner #define DLT_PPP_ETHER	51	/* PPP over Ethernet */
18146da4bc6SBill Fenner 
18246da4bc6SBill Fenner /*
1831acc2f81SBruce M Simpson  * Reserved for the Symantec Enterprise Firewall.
1841acc2f81SBruce M Simpson  */
1851acc2f81SBruce M Simpson #define DLT_SYMANTEC_FIREWALL	99
1861acc2f81SBruce M Simpson 
1871acc2f81SBruce M Simpson 
1881acc2f81SBruce M Simpson /*
18946da4bc6SBill Fenner  * This value was defined by libpcap 0.5; platforms that have defined
19046da4bc6SBill Fenner  * it with a different value should define it here with that value -
19146da4bc6SBill Fenner  * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
19246da4bc6SBill Fenner  * whatever value that happens to be, so programs will correctly
19346da4bc6SBill Fenner  * handle files with that link type regardless of the value of
19446da4bc6SBill Fenner  * DLT_C_HDLC.
19546da4bc6SBill Fenner  *
19646da4bc6SBill Fenner  * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
19746da4bc6SBill Fenner  * compatibility with programs written for BSD/OS.
19846da4bc6SBill Fenner  *
19946da4bc6SBill Fenner  * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
20046da4bc6SBill Fenner  * for source compatibility with programs written for libpcap 0.5.
20146da4bc6SBill Fenner  */
20246da4bc6SBill Fenner #define DLT_C_HDLC	104	/* Cisco HDLC */
20346da4bc6SBill Fenner #define DLT_CHDLC	DLT_C_HDLC
20446da4bc6SBill Fenner 
20546da4bc6SBill Fenner #define DLT_IEEE802_11	105	/* IEEE 802.11 wireless */
20646da4bc6SBill Fenner 
20746da4bc6SBill Fenner /*
20846da4bc6SBill Fenner  * Values between 106 and 107 are used in capture file headers as
20946da4bc6SBill Fenner  * link-layer types corresponding to DLT_ types that might differ
21046da4bc6SBill Fenner  * between platforms; don't use those values for new DLT_ new types.
21146da4bc6SBill Fenner  */
21246da4bc6SBill Fenner 
21346da4bc6SBill Fenner /*
214a7135a62SBruce M Simpson  * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
215a7135a62SBruce M Simpson  * with other values.
216a7135a62SBruce M Simpson  * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
217a7135a62SBruce M Simpson  * (DLCI, etc.).
218a7135a62SBruce M Simpson  */
219a7135a62SBruce M Simpson #define DLT_FRELAY	107
220a7135a62SBruce M Simpson 
221a7135a62SBruce M Simpson /*
22246da4bc6SBill Fenner  * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
22346da4bc6SBill Fenner  * that the AF_ type in the link-layer header is in network byte order.
22446da4bc6SBill Fenner  *
22546da4bc6SBill Fenner  * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
22646da4bc6SBill Fenner  * define it as 108 here.  If OpenBSD picks up this file, it should
22746da4bc6SBill Fenner  * define DLT_LOOP as 12 in its version, as per the comment above -
22894413c0dSBill Fenner  * and should not use 108 as a DLT_ value.
22946da4bc6SBill Fenner  */
23046da4bc6SBill Fenner #define DLT_LOOP	108
23146da4bc6SBill Fenner 
23246da4bc6SBill Fenner /*
23346da4bc6SBill Fenner  * Values between 109 and 112 are used in capture file headers as
23446da4bc6SBill Fenner  * link-layer types corresponding to DLT_ types that might differ
23546da4bc6SBill Fenner  * between platforms; don't use those values for new DLT_ new types.
23646da4bc6SBill Fenner  */
23746da4bc6SBill Fenner 
23846da4bc6SBill Fenner /*
239a7135a62SBruce M Simpson  * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
240a7135a62SBruce M Simpson  * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
241a7135a62SBruce M Simpson  * than OpenBSD.
242a7135a62SBruce M Simpson  */
243a7135a62SBruce M Simpson #define DLT_ENC	109
244a7135a62SBruce M Simpson 
245a7135a62SBruce M Simpson /*
24646da4bc6SBill Fenner  * This is for Linux cooked sockets.
24746da4bc6SBill Fenner  */
24846da4bc6SBill Fenner #define DLT_LINUX_SLL	113
249df8bae1dSRodney W. Grimes 
250df8bae1dSRodney W. Grimes /*
25194413c0dSBill Fenner  * Apple LocalTalk hardware.
25294413c0dSBill Fenner  */
25394413c0dSBill Fenner #define DLT_LTALK	114
25494413c0dSBill Fenner 
25594413c0dSBill Fenner /*
25694413c0dSBill Fenner  * Acorn Econet.
25794413c0dSBill Fenner  */
25894413c0dSBill Fenner #define DLT_ECONET	115
25994413c0dSBill Fenner 
26094413c0dSBill Fenner /*
26194413c0dSBill Fenner  * Reserved for use with OpenBSD ipfilter.
26294413c0dSBill Fenner  */
26394413c0dSBill Fenner #define DLT_IPFILTER	116
26494413c0dSBill Fenner 
26594413c0dSBill Fenner /*
26694413c0dSBill Fenner  * Reserved for use in capture-file headers as a link-layer type
26794413c0dSBill Fenner  * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
26894413c0dSBill Fenner  * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
26994413c0dSBill Fenner  * in capture-file headers.
27094413c0dSBill Fenner  */
27194413c0dSBill Fenner #define DLT_PFLOG	117
27294413c0dSBill Fenner 
27394413c0dSBill Fenner /*
27494413c0dSBill Fenner  * Registered for Cisco-internal use.
27594413c0dSBill Fenner  */
27694413c0dSBill Fenner #define DLT_CISCO_IOS	118
27794413c0dSBill Fenner 
27894413c0dSBill Fenner /*
27994413c0dSBill Fenner  * Reserved for 802.11 cards using the Prism II chips, with a link-layer
28094413c0dSBill Fenner  * header including Prism monitor mode information plus an 802.11
28194413c0dSBill Fenner  * header.
28294413c0dSBill Fenner  */
28394413c0dSBill Fenner #define DLT_PRISM_HEADER	119
28494413c0dSBill Fenner 
28594413c0dSBill Fenner /*
28694413c0dSBill Fenner  * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
28794413c0dSBill Fenner  * (see Doug Ambrisko's FreeBSD patches).
28894413c0dSBill Fenner  */
28994413c0dSBill Fenner #define DLT_AIRONET_HEADER	120
29094413c0dSBill Fenner 
29194413c0dSBill Fenner /*
292a7135a62SBruce M Simpson  * Reserved for use by OpenBSD's pfsync device.
293a7135a62SBruce M Simpson  */
294a7135a62SBruce M Simpson #define DLT_PFSYNC	121
295a7135a62SBruce M Simpson 
296a7135a62SBruce M Simpson /*
2971acc2f81SBruce M Simpson  * Reserved for Siemens HiPath HDLC. XXX
2981acc2f81SBruce M Simpson  */
2991acc2f81SBruce M Simpson #define DLT_HHDLC	121
3001acc2f81SBruce M Simpson 
3011acc2f81SBruce M Simpson /*
302a7135a62SBruce M Simpson  * Reserved for RFC 2625 IP-over-Fibre Channel.
303a7135a62SBruce M Simpson  */
304a7135a62SBruce M Simpson #define DLT_IP_OVER_FC	122
305a7135a62SBruce M Simpson 
306a7135a62SBruce M Simpson /*
307a7135a62SBruce M Simpson  * Reserved for Full Frontal ATM on Solaris.
308a7135a62SBruce M Simpson  */
309a7135a62SBruce M Simpson #define DLT_SUNATM	123
310a7135a62SBruce M Simpson 
311a7135a62SBruce M Simpson /*
3121acc2f81SBruce M Simpson  * Reserved as per request from Kent Dahlgren <kent@praesum.com>
3131acc2f81SBruce M Simpson  * for private use.
3141acc2f81SBruce M Simpson  */
3151acc2f81SBruce M Simpson #define DLT_RIO		124	/* RapidIO */
3161acc2f81SBruce M Simpson #define DLT_PCI_EXP	125	/* PCI Express */
3171acc2f81SBruce M Simpson #define DLT_AURORA	126	/* Xilinx Aurora link layer */
3181acc2f81SBruce M Simpson 
3191acc2f81SBruce M Simpson /*
320a7135a62SBruce M Simpson  * BSD header for 802.11 plus a number of bits of link-layer information
321a7135a62SBruce M Simpson  * including radio information.
322a7135a62SBruce M Simpson  */
323a7135a62SBruce M Simpson #ifndef DLT_IEEE802_11_RADIO
324a7135a62SBruce M Simpson #define DLT_IEEE802_11_RADIO	127
325a7135a62SBruce M Simpson #endif
326a7135a62SBruce M Simpson 
327a7135a62SBruce M Simpson /*
3281acc2f81SBruce M Simpson  * Reserved for TZSP encapsulation.
3291acc2f81SBruce M Simpson  */
3301acc2f81SBruce M Simpson #define DLT_TZSP		128	/* Tazmen Sniffer Protocol */
3311acc2f81SBruce M Simpson 
3321acc2f81SBruce M Simpson /*
333a7135a62SBruce M Simpson  * Reserved for Linux ARCNET.
334a7135a62SBruce M Simpson  */
335a7135a62SBruce M Simpson #define DLT_ARCNET_LINUX	129
336a7135a62SBruce M Simpson 
337a7135a62SBruce M Simpson /*
3381acc2f81SBruce M Simpson  * Juniper-private data link types.
3391acc2f81SBruce M Simpson  */
3401acc2f81SBruce M Simpson #define DLT_JUNIPER_MLPPP	130
3411acc2f81SBruce M Simpson #define DLT_JUNIPER_MLFR	131
3421acc2f81SBruce M Simpson #define DLT_JUNIPER_ES		132
3431acc2f81SBruce M Simpson #define DLT_JUNIPER_GGSN	133
3441acc2f81SBruce M Simpson #define DLT_JUNIPER_MFR		134
3451acc2f81SBruce M Simpson #define DLT_JUNIPER_ATM2	135
3461acc2f81SBruce M Simpson #define DLT_JUNIPER_SERVICES	136
3471acc2f81SBruce M Simpson #define DLT_JUNIPER_ATM1	137
3481acc2f81SBruce M Simpson 
3491acc2f81SBruce M Simpson /*
350f6f1669cSSam Leffler  * Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund
351f6f1669cSSam Leffler  * <dieter@apple.com>.  The header that's presented is an Ethernet-like
352f6f1669cSSam Leffler  * header:
353f6f1669cSSam Leffler  *
354f6f1669cSSam Leffler  *	#define FIREWIRE_EUI64_LEN	8
355f6f1669cSSam Leffler  *	struct firewire_header {
356f6f1669cSSam Leffler  *		u_char  firewire_dhost[FIREWIRE_EUI64_LEN];
357f6f1669cSSam Leffler  *		u_char  firewire_shost[FIREWIRE_EUI64_LEN];
358f6f1669cSSam Leffler  *		u_short firewire_type;
359f6f1669cSSam Leffler  *	};
360f6f1669cSSam Leffler  *
361f6f1669cSSam Leffler  * with "firewire_type" being an Ethernet type value, rather than,
362f6f1669cSSam Leffler  * for example, raw GASP frames being handed up.
363a7135a62SBruce M Simpson  */
364a7135a62SBruce M Simpson #define DLT_APPLE_IP_OVER_IEEE1394	138
365a7135a62SBruce M Simpson 
366a7135a62SBruce M Simpson /*
367e0d80bffSSam Leffler  * Various SS7 encapsulations, as per a request from Jeff Morriss
368e0d80bffSSam Leffler  * <jeff.morriss[AT]ulticom.com> and subsequent discussions.
369f6f1669cSSam Leffler  */
370e0d80bffSSam Leffler #define DLT_MTP2_WITH_PHDR	139	/* pseudo-header with various info, followed by MTP2 */
371e0d80bffSSam Leffler #define DLT_MTP2		140	/* MTP2, without pseudo-header */
372e0d80bffSSam Leffler #define DLT_MTP3		141	/* MTP3, without pseudo-header or MTP2 */
373e0d80bffSSam Leffler #define DLT_SCCP		142	/* SCCP, without pseudo-header or MTP2 or MTP3 */
374f6f1669cSSam Leffler 
375f6f1669cSSam Leffler /*
3761acc2f81SBruce M Simpson  * Reserved for DOCSIS.
3771acc2f81SBruce M Simpson  */
3781acc2f81SBruce M Simpson #define DLT_DOCSIS	143
3791acc2f81SBruce M Simpson 
3801acc2f81SBruce M Simpson /*
381a7135a62SBruce M Simpson  * Reserved for Linux IrDA.
382a7135a62SBruce M Simpson  */
383a7135a62SBruce M Simpson #define DLT_LINUX_IRDA	144
384a7135a62SBruce M Simpson 
385a7135a62SBruce M Simpson /*
3861acc2f81SBruce M Simpson  * Reserved for IBM SP switch and IBM Next Federation switch.
3871acc2f81SBruce M Simpson  */
3881acc2f81SBruce M Simpson #define DLT_IBM_SP	145
3891acc2f81SBruce M Simpson #define DLT_IBM_SN	146
3901acc2f81SBruce M Simpson 
3911acc2f81SBruce M Simpson /*
392f6f1669cSSam Leffler  * Reserved for private use.  If you have some link-layer header type
393f6f1669cSSam Leffler  * that you want to use within your organization, with the capture files
394f6f1669cSSam Leffler  * using that link-layer header type not ever be sent outside your
395f6f1669cSSam Leffler  * organization, you can use these values.
396f6f1669cSSam Leffler  *
397f6f1669cSSam Leffler  * No libpcap release will use these for any purpose, nor will any
398f6f1669cSSam Leffler  * tcpdump release use them, either.
399f6f1669cSSam Leffler  *
400f6f1669cSSam Leffler  * Do *NOT* use these in capture files that you expect anybody not using
401f6f1669cSSam Leffler  * your private versions of capture-file-reading tools to read; in
402f6f1669cSSam Leffler  * particular, do *NOT* use them in products, otherwise you may find that
403f6f1669cSSam Leffler  * people won't be able to use tcpdump, or snort, or Ethereal, or... to
404f6f1669cSSam Leffler  * read capture files from your firewall/intrusion detection/traffic
405f6f1669cSSam Leffler  * monitoring/etc. appliance, or whatever product uses that DLT_ value,
406f6f1669cSSam Leffler  * and you may also find that the developers of those applications will
407f6f1669cSSam Leffler  * not accept patches to let them read those files.
408f6f1669cSSam Leffler  *
409f6f1669cSSam Leffler  * Also, do not use them if somebody might send you a capture using them
410f6f1669cSSam Leffler  * for *their* private type and tools using them for *your* private type
411f6f1669cSSam Leffler  * would have to read them.
412f6f1669cSSam Leffler  *
413f6f1669cSSam Leffler  * Instead, ask "tcpdump-workers@tcpdump.org" for a new DLT_ value,
414f6f1669cSSam Leffler  * as per the comment above, and use the type you're given.
415a7135a62SBruce M Simpson  */
416f6f1669cSSam Leffler #define DLT_USER0		147
417f6f1669cSSam Leffler #define DLT_USER1		148
418f6f1669cSSam Leffler #define DLT_USER2		149
419f6f1669cSSam Leffler #define DLT_USER3		150
420f6f1669cSSam Leffler #define DLT_USER4		151
421f6f1669cSSam Leffler #define DLT_USER5		152
422f6f1669cSSam Leffler #define DLT_USER6		153
423f6f1669cSSam Leffler #define DLT_USER7		154
424f6f1669cSSam Leffler #define DLT_USER8		155
425f6f1669cSSam Leffler #define DLT_USER9		156
426f6f1669cSSam Leffler #define DLT_USER10		157
427f6f1669cSSam Leffler #define DLT_USER11		158
428f6f1669cSSam Leffler #define DLT_USER12		159
429f6f1669cSSam Leffler #define DLT_USER13		160
430f6f1669cSSam Leffler #define DLT_USER14		161
431f6f1669cSSam Leffler #define DLT_USER15		162
432a7135a62SBruce M Simpson 
433a7135a62SBruce M Simpson /*
434f6f1669cSSam Leffler  * For future use with 802.11 captures - defined by AbsoluteValue
435f6f1669cSSam Leffler  * Systems to store a number of bits of link-layer information
436f6f1669cSSam Leffler  * including radio information:
437f6f1669cSSam Leffler  *
438f6f1669cSSam Leffler  *	http://www.shaftnet.org/~pizza/software/capturefrm.txt
439f6f1669cSSam Leffler  *
440f6f1669cSSam Leffler  * but it might be used by some non-AVS drivers now or in the
441f6f1669cSSam Leffler  * future.
442f6f1669cSSam Leffler  */
443f6f1669cSSam Leffler #define DLT_IEEE802_11_RADIO_AVS 163	/* 802.11 plus AVS radio header */
444f6f1669cSSam Leffler 
445f6f1669cSSam Leffler /*
446f6f1669cSSam Leffler  * Juniper-private data link type, as per request from
447f6f1669cSSam Leffler  * Hannes Gredler <hannes@juniper.net>.  The DLT_s are used
448f6f1669cSSam Leffler  * for passing on chassis-internal metainformation such as
449f6f1669cSSam Leffler  * QOS profiles, etc..
4501acc2f81SBruce M Simpson  */
4511acc2f81SBruce M Simpson #define DLT_JUNIPER_MONITOR     164
4521acc2f81SBruce M Simpson 
4531acc2f81SBruce M Simpson /*
454f6f1669cSSam Leffler  * Reserved for BACnet MS/TP.
455f6f1669cSSam Leffler  */
456f6f1669cSSam Leffler #define DLT_BACNET_MS_TP	165
457f6f1669cSSam Leffler 
458f6f1669cSSam Leffler /*
459f6f1669cSSam Leffler  * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
460f6f1669cSSam Leffler  *
461f6f1669cSSam Leffler  * This is used in some OSes to allow a kernel socket filter to distinguish
462f6f1669cSSam Leffler  * between incoming and outgoing packets, on a socket intended to
463f6f1669cSSam Leffler  * supply pppd with outgoing packets so it can do dial-on-demand and
464f6f1669cSSam Leffler  * hangup-on-lack-of-demand; incoming packets are filtered out so they
465f6f1669cSSam Leffler  * don't cause pppd to hold the connection up (you don't want random
466f6f1669cSSam Leffler  * input packets such as port scans, packets from old lost connections,
467f6f1669cSSam Leffler  * etc. to force the connection to stay up).
468f6f1669cSSam Leffler  *
469f6f1669cSSam Leffler  * The first byte of the PPP header (0xff03) is modified to accomodate
470f6f1669cSSam Leffler  * the direction - 0x00 = IN, 0x01 = OUT.
471f6f1669cSSam Leffler  */
472f6f1669cSSam Leffler #define DLT_PPP_PPPD		166
473f6f1669cSSam Leffler 
474f6f1669cSSam Leffler /*
475f6f1669cSSam Leffler  * Names for backwards compatibility with older versions of some PPP
476f6f1669cSSam Leffler  * software; new software should use DLT_PPP_PPPD.
477f6f1669cSSam Leffler  */
478f6f1669cSSam Leffler #define DLT_PPP_WITH_DIRECTION	DLT_PPP_PPPD
479f6f1669cSSam Leffler #define DLT_LINUX_PPP_WITHDIRECTION	DLT_PPP_PPPD
480f6f1669cSSam Leffler 
481f6f1669cSSam Leffler /*
482f6f1669cSSam Leffler  * Juniper-private data link type, as per request from
483f6f1669cSSam Leffler  * Hannes Gredler <hannes@juniper.net>.  The DLT_s are used
484f6f1669cSSam Leffler  * for passing on chassis-internal metainformation such as
485f6f1669cSSam Leffler  * QOS profiles, cookies, etc..
486f6f1669cSSam Leffler  */
487f6f1669cSSam Leffler #define DLT_JUNIPER_PPPOE       167
488f6f1669cSSam Leffler #define DLT_JUNIPER_PPPOE_ATM   168
489f6f1669cSSam Leffler 
490f6f1669cSSam Leffler #define DLT_GPRS_LLC		169	/* GPRS LLC */
491f6f1669cSSam Leffler #define DLT_GPF_T		170	/* GPF-T (ITU-T G.7041/Y.1303) */
492f6f1669cSSam Leffler #define DLT_GPF_F		171	/* GPF-F (ITU-T G.7041/Y.1303) */
493f6f1669cSSam Leffler 
494f6f1669cSSam Leffler /*
495f6f1669cSSam Leffler  * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
496f6f1669cSSam Leffler  * monitoring equipment.
497f6f1669cSSam Leffler  */
498f6f1669cSSam Leffler #define DLT_GCOM_T1E1		172
499f6f1669cSSam Leffler #define DLT_GCOM_SERIAL		173
500f6f1669cSSam Leffler 
501f6f1669cSSam Leffler /*
502f6f1669cSSam Leffler  * Juniper-private data link type, as per request from
503f6f1669cSSam Leffler  * Hannes Gredler <hannes@juniper.net>.  The DLT_ is used
504f6f1669cSSam Leffler  * for internal communication to Physical Interface Cards (PIC)
505f6f1669cSSam Leffler  */
506f6f1669cSSam Leffler #define DLT_JUNIPER_PIC_PEER    174
507f6f1669cSSam Leffler 
508f6f1669cSSam Leffler /*
509f6f1669cSSam Leffler  * Link types requested by Gregor Maier <gregor@endace.com> of Endace
510f6f1669cSSam Leffler  * Measurement Systems.  They add an ERF header (see
511f6f1669cSSam Leffler  * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
512f6f1669cSSam Leffler  * the link-layer header.
513f6f1669cSSam Leffler  */
514f6f1669cSSam Leffler #define DLT_ERF_ETH		175	/* Ethernet */
515f6f1669cSSam Leffler #define DLT_ERF_POS		176	/* Packet-over-SONET */
516f6f1669cSSam Leffler 
517f6f1669cSSam Leffler /*
518e0d80bffSSam Leffler  * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
519e0d80bffSSam Leffler  * for vISDN (http://www.orlandi.com/visdn/).  Its link-layer header
520e0d80bffSSam Leffler  * includes additional information before the LAPD header, so it's
521e0d80bffSSam Leffler  * not necessarily a generic LAPD header.
522e0d80bffSSam Leffler  */
523e0d80bffSSam Leffler #define DLT_LINUX_LAPD		177
524e0d80bffSSam Leffler 
525e0d80bffSSam Leffler /*
5266c5e9bbdSMike Pritchard  * The instruction encodings.
527df8bae1dSRodney W. Grimes  */
528df8bae1dSRodney W. Grimes /* instruction classes */
529df8bae1dSRodney W. Grimes #define BPF_CLASS(code) ((code) & 0x07)
530df8bae1dSRodney W. Grimes #define		BPF_LD		0x00
531df8bae1dSRodney W. Grimes #define		BPF_LDX		0x01
532df8bae1dSRodney W. Grimes #define		BPF_ST		0x02
533df8bae1dSRodney W. Grimes #define		BPF_STX		0x03
534df8bae1dSRodney W. Grimes #define		BPF_ALU		0x04
535df8bae1dSRodney W. Grimes #define		BPF_JMP		0x05
536df8bae1dSRodney W. Grimes #define		BPF_RET		0x06
537df8bae1dSRodney W. Grimes #define		BPF_MISC	0x07
538df8bae1dSRodney W. Grimes 
539df8bae1dSRodney W. Grimes /* ld/ldx fields */
540df8bae1dSRodney W. Grimes #define BPF_SIZE(code)	((code) & 0x18)
541df8bae1dSRodney W. Grimes #define		BPF_W		0x00
542df8bae1dSRodney W. Grimes #define		BPF_H		0x08
543df8bae1dSRodney W. Grimes #define		BPF_B		0x10
544df8bae1dSRodney W. Grimes #define BPF_MODE(code)	((code) & 0xe0)
545df8bae1dSRodney W. Grimes #define		BPF_IMM 	0x00
546df8bae1dSRodney W. Grimes #define		BPF_ABS		0x20
547df8bae1dSRodney W. Grimes #define		BPF_IND		0x40
548df8bae1dSRodney W. Grimes #define		BPF_MEM		0x60
549df8bae1dSRodney W. Grimes #define		BPF_LEN		0x80
550df8bae1dSRodney W. Grimes #define		BPF_MSH		0xa0
551df8bae1dSRodney W. Grimes 
552df8bae1dSRodney W. Grimes /* alu/jmp fields */
553df8bae1dSRodney W. Grimes #define BPF_OP(code)	((code) & 0xf0)
554df8bae1dSRodney W. Grimes #define		BPF_ADD		0x00
555df8bae1dSRodney W. Grimes #define		BPF_SUB		0x10
556df8bae1dSRodney W. Grimes #define		BPF_MUL		0x20
557df8bae1dSRodney W. Grimes #define		BPF_DIV		0x30
558df8bae1dSRodney W. Grimes #define		BPF_OR		0x40
559df8bae1dSRodney W. Grimes #define		BPF_AND		0x50
560df8bae1dSRodney W. Grimes #define		BPF_LSH		0x60
561df8bae1dSRodney W. Grimes #define		BPF_RSH		0x70
562df8bae1dSRodney W. Grimes #define		BPF_NEG		0x80
563df8bae1dSRodney W. Grimes #define		BPF_JA		0x00
564df8bae1dSRodney W. Grimes #define		BPF_JEQ		0x10
565df8bae1dSRodney W. Grimes #define		BPF_JGT		0x20
566df8bae1dSRodney W. Grimes #define		BPF_JGE		0x30
567df8bae1dSRodney W. Grimes #define		BPF_JSET	0x40
568df8bae1dSRodney W. Grimes #define BPF_SRC(code)	((code) & 0x08)
569df8bae1dSRodney W. Grimes #define		BPF_K		0x00
570df8bae1dSRodney W. Grimes #define		BPF_X		0x08
571df8bae1dSRodney W. Grimes 
572df8bae1dSRodney W. Grimes /* ret - BPF_K and BPF_X also apply */
573df8bae1dSRodney W. Grimes #define BPF_RVAL(code)	((code) & 0x18)
574df8bae1dSRodney W. Grimes #define		BPF_A		0x10
575df8bae1dSRodney W. Grimes 
576df8bae1dSRodney W. Grimes /* misc */
577df8bae1dSRodney W. Grimes #define BPF_MISCOP(code) ((code) & 0xf8)
578df8bae1dSRodney W. Grimes #define		BPF_TAX		0x00
579df8bae1dSRodney W. Grimes #define		BPF_TXA		0x80
580df8bae1dSRodney W. Grimes 
581df8bae1dSRodney W. Grimes /*
582df8bae1dSRodney W. Grimes  * The instruction data structure.
583df8bae1dSRodney W. Grimes  */
584df8bae1dSRodney W. Grimes struct bpf_insn {
585df8bae1dSRodney W. Grimes 	u_short		code;
586df8bae1dSRodney W. Grimes 	u_char		jt;
587df8bae1dSRodney W. Grimes 	u_char		jf;
58811a53ef3SPaul Traina 	bpf_u_int32	k;
589df8bae1dSRodney W. Grimes };
590df8bae1dSRodney W. Grimes 
591df8bae1dSRodney W. Grimes /*
592df8bae1dSRodney W. Grimes  * Macros for insn array initializers.
593df8bae1dSRodney W. Grimes  */
594df8bae1dSRodney W. Grimes #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
595df8bae1dSRodney W. Grimes #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
596df8bae1dSRodney W. Grimes 
5978eab61f3SSam Leffler /*
5988eab61f3SSam Leffler  * Structure to retrieve available DLTs for the interface.
5998eab61f3SSam Leffler  */
6008eab61f3SSam Leffler struct bpf_dltlist {
6018eab61f3SSam Leffler 	u_int	bfl_len;	/* number of bfd_list array */
6028eab61f3SSam Leffler 	u_int	*bfl_list;	/* array of DLTs */
6038eab61f3SSam Leffler };
6048eab61f3SSam Leffler 
605664a31e4SPeter Wemm #ifdef _KERNEL
60616d878ccSChristian S.J. Peron /*
60716d878ccSChristian S.J. Peron  * Descriptor associated with each attached hardware interface.
60816d878ccSChristian S.J. Peron  */
60916d878ccSChristian S.J. Peron struct bpf_if {
61016d878ccSChristian S.J. Peron 	LIST_ENTRY(bpf_if)	bif_next;	/* list of all interfaces */
61116d878ccSChristian S.J. Peron 	LIST_HEAD(, bpf_d)	bif_dlist;	/* descriptor list */
61216d878ccSChristian S.J. Peron 	u_int bif_dlt;				/* link layer type */
61316d878ccSChristian S.J. Peron 	u_int bif_hdrlen;		/* length of header (with padding) */
61416d878ccSChristian S.J. Peron 	struct ifnet *bif_ifp;		/* corresponding interface */
61516d878ccSChristian S.J. Peron 	struct mtx	bif_mtx;	/* mutex for interface */
61616d878ccSChristian S.J. Peron };
61716d878ccSChristian S.J. Peron 
618929ddbbbSAlfred Perlstein int	 bpf_validate(const struct bpf_insn *, int);
61924a229f4SSam Leffler void	 bpf_tap(struct bpf_if *, u_char *, u_int);
62024a229f4SSam Leffler void	 bpf_mtap(struct bpf_if *, struct mbuf *);
621437ffe18SSam Leffler void	 bpf_mtap2(struct bpf_if *, void *, u_int, struct mbuf *);
622929ddbbbSAlfred Perlstein void	 bpfattach(struct ifnet *, u_int, u_int);
62324a229f4SSam Leffler void	 bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **);
624929ddbbbSAlfred Perlstein void	 bpfdetach(struct ifnet *);
625de5d9935SRobert Watson 
626929ddbbbSAlfred Perlstein void	 bpfilterattach(int);
627929ddbbbSAlfred Perlstein u_int	 bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int);
62824a229f4SSam Leffler 
62916d878ccSChristian S.J. Peron static __inline int
63016d878ccSChristian S.J. Peron bpf_peers_present(struct bpf_if *bpf)
63116d878ccSChristian S.J. Peron {
63216d878ccSChristian S.J. Peron 
63316d878ccSChristian S.J. Peron 	return !LIST_EMPTY(&bpf->bif_dlist);
63416d878ccSChristian S.J. Peron }
63516d878ccSChristian S.J. Peron 
63624a229f4SSam Leffler #define	BPF_TAP(_ifp,_pkt,_pktlen) do {				\
63716d878ccSChristian S.J. Peron 	if (bpf_peers_present((_ifp)->if_bpf))			\
63824a229f4SSam Leffler 		bpf_tap((_ifp)->if_bpf, (_pkt), (_pktlen));	\
63924a229f4SSam Leffler } while (0)
64024a229f4SSam Leffler #define	BPF_MTAP(_ifp,_m) do {					\
64116d878ccSChristian S.J. Peron 	if (bpf_peers_present((_ifp)->if_bpf)) {		\
642437ffe18SSam Leffler 		M_ASSERTVALID(_m);				\
64324a229f4SSam Leffler 		bpf_mtap((_ifp)->if_bpf, (_m));			\
644437ffe18SSam Leffler 	}							\
645437ffe18SSam Leffler } while (0)
646437ffe18SSam Leffler #define	BPF_MTAP2(_ifp,_data,_dlen,_m) do {			\
64716d878ccSChristian S.J. Peron 	if (bpf_peers_present((_ifp)->if_bpf)) {		\
648437ffe18SSam Leffler 		M_ASSERTVALID(_m);				\
649437ffe18SSam Leffler 		bpf_mtap2((_ifp)->if_bpf,(_data),(_dlen),(_m));	\
650437ffe18SSam Leffler 	}							\
65124a229f4SSam Leffler } while (0)
652df8bae1dSRodney W. Grimes #endif
653df8bae1dSRodney W. Grimes 
654df8bae1dSRodney W. Grimes /*
655df8bae1dSRodney W. Grimes  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
656df8bae1dSRodney W. Grimes  */
657df8bae1dSRodney W. Grimes #define BPF_MEMWORDS 16
658df8bae1dSRodney W. Grimes 
65924a229f4SSam Leffler #endif /* _NET_BPF_H_ */
660