xref: /illumos-gate/usr/src/uts/common/inet/ipf/bpf-ipf.h (revision ab25eeb5)
17c478bd9Sstevel@tonic-gate /*-
27c478bd9Sstevel@tonic-gate  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
37c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * This code is derived from the Stanford/CMU enet packet filter,
67c478bd9Sstevel@tonic-gate  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
77c478bd9Sstevel@tonic-gate  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
87c478bd9Sstevel@tonic-gate  * Berkeley Laboratory.
97c478bd9Sstevel@tonic-gate  *
107c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
117c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
127c478bd9Sstevel@tonic-gate  * are met:
137c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
147c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
157c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
167c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
177c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
187c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
197c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
207c478bd9Sstevel@tonic-gate  *      This product includes software developed by the University of
217c478bd9Sstevel@tonic-gate  *      California, Berkeley and its contributors.
227c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
237c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
247c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
277c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
287c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
297c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
307c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
317c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
327c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
337c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
347c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
357c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
367c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * @(#) $Header: /devel/CVS/IP-Filter/bpf-ipf.h,v 2.1 2002/10/26 12:14:26 darrenr Exp $ (LBL)
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifndef BPF_MAJOR_VERSION
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifdef __cplusplus
467c478bd9Sstevel@tonic-gate extern "C" {
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /* BSD style release date */
507c478bd9Sstevel@tonic-gate #define BPF_RELEASE 199606
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef	int bpf_int32;
537c478bd9Sstevel@tonic-gate typedef	u_int bpf_u_int32;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Alignment macros.  BPF_WORDALIGN rounds up to the next
577c478bd9Sstevel@tonic-gate  * even multiple of BPF_ALIGNMENT.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate #ifndef __NetBSD__
607c478bd9Sstevel@tonic-gate #define BPF_ALIGNMENT sizeof(bpf_int32)
617c478bd9Sstevel@tonic-gate #else
627c478bd9Sstevel@tonic-gate #define BPF_ALIGNMENT sizeof(long)
637c478bd9Sstevel@tonic-gate #endif
647c478bd9Sstevel@tonic-gate #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define BPF_MAXINSNS 512
677c478bd9Sstevel@tonic-gate #define BPF_MAXBUFSIZE 0x8000
687c478bd9Sstevel@tonic-gate #define BPF_MINBUFSIZE 32
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  *  Structure for BIOCSETF.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate struct bpf_program {
747c478bd9Sstevel@tonic-gate 	u_int bf_len;
757c478bd9Sstevel@tonic-gate 	struct bpf_insn *bf_insns;
767c478bd9Sstevel@tonic-gate };
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * Struct returned by BIOCGSTATS.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate struct bpf_stat {
827c478bd9Sstevel@tonic-gate 	u_int bs_recv;		/* number of packets received */
837c478bd9Sstevel@tonic-gate 	u_int bs_drop;		/* number of packets dropped */
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * Struct return by BIOCVERSION.  This represents the version number of
887c478bd9Sstevel@tonic-gate  * the filter language described by the instruction encodings below.
897c478bd9Sstevel@tonic-gate  * bpf understands a program iff kernel_major == filter_major &&
907c478bd9Sstevel@tonic-gate  * kernel_minor >= filter_minor, that is, if the value returned by the
917c478bd9Sstevel@tonic-gate  * running kernel has the same major number and a minor number equal
927c478bd9Sstevel@tonic-gate  * equal to or less than the filter being downloaded.  Otherwise, the
937c478bd9Sstevel@tonic-gate  * results are undefined, meaning an error may be returned or packets
947c478bd9Sstevel@tonic-gate  * may be accepted haphazardly.
957c478bd9Sstevel@tonic-gate  * It has nothing to do with the source code version.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate struct bpf_version {
987c478bd9Sstevel@tonic-gate 	u_short bv_major;
997c478bd9Sstevel@tonic-gate 	u_short bv_minor;
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate /* Current version number of filter architecture. */
1027c478bd9Sstevel@tonic-gate #define BPF_MAJOR_VERSION 1
1037c478bd9Sstevel@tonic-gate #define BPF_MINOR_VERSION 1
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * BPF ioctls
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * The first set is for compatibility with Sun's pcc style
1097c478bd9Sstevel@tonic-gate  * header files.  If your using gcc, we assume that you
1107c478bd9Sstevel@tonic-gate  * have run fixincludes so the latter set should work.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
1137c478bd9Sstevel@tonic-gate #define	BIOCGBLEN	_IOR(B,102, u_int)
1147c478bd9Sstevel@tonic-gate #define	BIOCSBLEN	_IOWR(B,102, u_int)
1157c478bd9Sstevel@tonic-gate #define	BIOCSETF	_IOW(B,103, struct bpf_program)
1167c478bd9Sstevel@tonic-gate #define	BIOCFLUSH	_IO(B,104)
1177c478bd9Sstevel@tonic-gate #define BIOCPROMISC	_IO(B,105)
1187c478bd9Sstevel@tonic-gate #define	BIOCGDLT	_IOR(B,106, u_int)
1197c478bd9Sstevel@tonic-gate #define BIOCGETIF	_IOR(B,107, struct ifreq)
1207c478bd9Sstevel@tonic-gate #define BIOCSETIF	_IOW(B,108, struct ifreq)
1217c478bd9Sstevel@tonic-gate #define BIOCSRTIMEOUT	_IOW(B,109, struct timeval)
1227c478bd9Sstevel@tonic-gate #define BIOCGRTIMEOUT	_IOR(B,110, struct timeval)
1237c478bd9Sstevel@tonic-gate #define BIOCGSTATS	_IOR(B,111, struct bpf_stat)
1247c478bd9Sstevel@tonic-gate #define BIOCIMMEDIATE	_IOW(B,112, u_int)
1257c478bd9Sstevel@tonic-gate #define BIOCVERSION	_IOR(B,113, struct bpf_version)
1267c478bd9Sstevel@tonic-gate #define BIOCSTCPF	_IOW(B,114, struct bpf_program)
1277c478bd9Sstevel@tonic-gate #define BIOCSUDPF	_IOW(B,115, struct bpf_program)
1287c478bd9Sstevel@tonic-gate #else
1297c478bd9Sstevel@tonic-gate #define	BIOCGBLEN	_IOR('B',102, u_int)
1307c478bd9Sstevel@tonic-gate #define	BIOCSBLEN	_IOWR('B',102, u_int)
1317c478bd9Sstevel@tonic-gate #define	BIOCSETF	_IOW('B',103, struct bpf_program)
1327c478bd9Sstevel@tonic-gate #define	BIOCFLUSH	_IO('B',104)
1337c478bd9Sstevel@tonic-gate #define BIOCPROMISC	_IO('B',105)
1347c478bd9Sstevel@tonic-gate #define	BIOCGDLT	_IOR('B',106, u_int)
1357c478bd9Sstevel@tonic-gate #define BIOCGETIF	_IOR('B',107, struct ifreq)
1367c478bd9Sstevel@tonic-gate #define BIOCSETIF	_IOW('B',108, struct ifreq)
1377c478bd9Sstevel@tonic-gate #define BIOCSRTIMEOUT	_IOW('B',109, struct timeval)
1387c478bd9Sstevel@tonic-gate #define BIOCGRTIMEOUT	_IOR('B',110, struct timeval)
1397c478bd9Sstevel@tonic-gate #define BIOCGSTATS	_IOR('B',111, struct bpf_stat)
1407c478bd9Sstevel@tonic-gate #define BIOCIMMEDIATE	_IOW('B',112, u_int)
1417c478bd9Sstevel@tonic-gate #define BIOCVERSION	_IOR('B',113, struct bpf_version)
1427c478bd9Sstevel@tonic-gate #define BIOCSTCPF	_IOW('B',114, struct bpf_program)
1437c478bd9Sstevel@tonic-gate #define BIOCSUDPF	_IOW('B',115, struct bpf_program)
1447c478bd9Sstevel@tonic-gate #endif
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Structure prepended to each packet.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate struct bpf_hdr {
1507c478bd9Sstevel@tonic-gate 	struct timeval	bh_tstamp;	/* time stamp */
1517c478bd9Sstevel@tonic-gate 	bpf_u_int32	bh_caplen;	/* length of captured portion */
1527c478bd9Sstevel@tonic-gate 	bpf_u_int32	bh_datalen;	/* original length of packet */
1537c478bd9Sstevel@tonic-gate 	u_short		bh_hdrlen;	/* length of bpf header (this struct
1547c478bd9Sstevel@tonic-gate 					   plus alignment padding) */
1557c478bd9Sstevel@tonic-gate };
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * Because the structure above is not a multiple of 4 bytes, some compilers
1587c478bd9Sstevel@tonic-gate  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
1597c478bd9Sstevel@tonic-gate  * Only the kernel needs to know about it; applications use bh_hdrlen.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate #if defined(KERNEL) || defined(_KERNEL)
1627c478bd9Sstevel@tonic-gate #define SIZEOF_BPF_HDR 18
1637c478bd9Sstevel@tonic-gate #endif
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * Data-link level type codes.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * These are the types that are the same on all platforms; on other
1717c478bd9Sstevel@tonic-gate  * platforms, a <net/bpf.h> should be supplied that defines the additional
1727c478bd9Sstevel@tonic-gate  * DLT_* codes appropriately for that platform (the BSDs, for example,
1737c478bd9Sstevel@tonic-gate  * should not just pick up this version of "bpf.h"; they should also define
1747c478bd9Sstevel@tonic-gate  * the additional DLT_* codes used by their kernels, as well as the values
1757c478bd9Sstevel@tonic-gate  * defined here - and, if the values they use for particular DLT_ types
1767c478bd9Sstevel@tonic-gate  * differ from those here, they should use their values, not the ones
1777c478bd9Sstevel@tonic-gate  * here).
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate #define DLT_NULL	0	/* no link-layer encapsulation */
1807c478bd9Sstevel@tonic-gate #define DLT_EN10MB	1	/* Ethernet (10Mb) */
1817c478bd9Sstevel@tonic-gate #define DLT_EN3MB	2	/* Experimental Ethernet (3Mb) */
1827c478bd9Sstevel@tonic-gate #define DLT_AX25	3	/* Amateur Radio AX.25 */
1837c478bd9Sstevel@tonic-gate #define DLT_PRONET	4	/* Proteon ProNET Token Ring */
1847c478bd9Sstevel@tonic-gate #define DLT_CHAOS	5	/* Chaos */
1857c478bd9Sstevel@tonic-gate #define DLT_IEEE802	6	/* IEEE 802 Networks */
1867c478bd9Sstevel@tonic-gate #define DLT_ARCNET	7	/* ARCNET */
1877c478bd9Sstevel@tonic-gate #define DLT_SLIP	8	/* Serial Line IP */
1887c478bd9Sstevel@tonic-gate #define DLT_PPP		9	/* Point-to-point Protocol */
1897c478bd9Sstevel@tonic-gate #define DLT_FDDI	10	/* FDDI */
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * These are values from the traditional libpcap "bpf.h".
1937c478bd9Sstevel@tonic-gate  * Ports of this to particular platforms should replace these definitions
1947c478bd9Sstevel@tonic-gate  * with the ones appropriate to that platform, if the values are
1957c478bd9Sstevel@tonic-gate  * different on that platform.
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate #define DLT_ATM_RFC1483	11	/* LLC/SNAP encapsulated atm */
1987c478bd9Sstevel@tonic-gate #define DLT_RAW		12	/* raw IP */
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * These are values from BSD/OS's "bpf.h".
2027c478bd9Sstevel@tonic-gate  * These are not the same as the values from the traditional libpcap
2037c478bd9Sstevel@tonic-gate  * "bpf.h"; however, these values shouldn't be generated by any
2047c478bd9Sstevel@tonic-gate  * OS other than BSD/OS, so the correct values to use here are the
2057c478bd9Sstevel@tonic-gate  * BSD/OS values.
2067c478bd9Sstevel@tonic-gate  *
2077c478bd9Sstevel@tonic-gate  * Platforms that have already assigned these values to other
2087c478bd9Sstevel@tonic-gate  * DLT_ codes, however, should give these codes the values
2097c478bd9Sstevel@tonic-gate  * from that platform, so that programs that use these codes will
2107c478bd9Sstevel@tonic-gate  * continue to compile - even though they won't correctly read
2117c478bd9Sstevel@tonic-gate  * files of these types.
2127c478bd9Sstevel@tonic-gate  */
2137c478bd9Sstevel@tonic-gate #ifdef __NetBSD__
2147c478bd9Sstevel@tonic-gate #ifndef DLT_SLIP_BSDOS
2157c478bd9Sstevel@tonic-gate #define DLT_SLIP_BSDOS	13	/* BSD/OS Serial Line IP */
2167c478bd9Sstevel@tonic-gate #define DLT_PPP_BSDOS	14	/* BSD/OS Point-to-point Protocol */
2177c478bd9Sstevel@tonic-gate #endif
2187c478bd9Sstevel@tonic-gate #else
2197c478bd9Sstevel@tonic-gate #define DLT_SLIP_BSDOS	15	/* BSD/OS Serial Line IP */
2207c478bd9Sstevel@tonic-gate #define DLT_PPP_BSDOS	16	/* BSD/OS Point-to-point Protocol */
2217c478bd9Sstevel@tonic-gate #endif
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #define DLT_ATM_CLIP	19	/* Linux Classical-IP over ATM */
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * These values are defined by NetBSD; other platforms should refrain from
2277c478bd9Sstevel@tonic-gate  * using them for other purposes, so that NetBSD savefiles with link
2287c478bd9Sstevel@tonic-gate  * types of 50 or 51 can be read as this type on all platforms.
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate #define DLT_PPP_SERIAL	50	/* PPP over serial with HDLC encapsulation */
2317c478bd9Sstevel@tonic-gate #define DLT_PPP_ETHER	51	/* PPP over Ethernet */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * Values between 100 and 103 are used in capture file headers as
2357c478bd9Sstevel@tonic-gate  * link-layer types corresponding to DLT_ types that differ
2367c478bd9Sstevel@tonic-gate  * between platforms; don't use those values for new DLT_ new types.
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * This value was defined by libpcap 0.5; platforms that have defined
2417c478bd9Sstevel@tonic-gate  * it with a different value should define it here with that value -
2427c478bd9Sstevel@tonic-gate  * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
2437c478bd9Sstevel@tonic-gate  * whatever value that happens to be, so programs will correctly
2447c478bd9Sstevel@tonic-gate  * handle files with that link type regardless of the value of
2457c478bd9Sstevel@tonic-gate  * DLT_C_HDLC.
2467c478bd9Sstevel@tonic-gate  *
2477c478bd9Sstevel@tonic-gate  * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
2487c478bd9Sstevel@tonic-gate  * compatibility with programs written for BSD/OS.
2497c478bd9Sstevel@tonic-gate  *
2507c478bd9Sstevel@tonic-gate  * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
2517c478bd9Sstevel@tonic-gate  * for source compatibility with programs written for libpcap 0.5.
2527c478bd9Sstevel@tonic-gate  */
2537c478bd9Sstevel@tonic-gate #define DLT_C_HDLC	104	/* Cisco HDLC */
2547c478bd9Sstevel@tonic-gate #define DLT_CHDLC	DLT_C_HDLC
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate #define DLT_IEEE802_11	105	/* IEEE 802.11 wireless */
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * Values between 106 and 107 are used in capture file headers as
2607c478bd9Sstevel@tonic-gate  * link-layer types corresponding to DLT_ types that might differ
2617c478bd9Sstevel@tonic-gate  * between platforms; don't use those values for new DLT_ new types.
2627c478bd9Sstevel@tonic-gate  */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
2667c478bd9Sstevel@tonic-gate  * that the AF_ type in the link-layer header is in network byte order.
2677c478bd9Sstevel@tonic-gate  *
2687c478bd9Sstevel@tonic-gate  * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
2697c478bd9Sstevel@tonic-gate  * define it as 108 here.  If OpenBSD picks up this file, it should
2707c478bd9Sstevel@tonic-gate  * define DLT_LOOP as 12 in its version, as per the comment above -
2717c478bd9Sstevel@tonic-gate  * and should not use 108 as a DLT_ value.
2727c478bd9Sstevel@tonic-gate  */
2737c478bd9Sstevel@tonic-gate #define DLT_LOOP	108
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate /*
2767c478bd9Sstevel@tonic-gate  * Values between 109 and 112 are used in capture file headers as
2777c478bd9Sstevel@tonic-gate  * link-layer types corresponding to DLT_ types that might differ
2787c478bd9Sstevel@tonic-gate  * between platforms; don't use those values for new DLT_ types
2797c478bd9Sstevel@tonic-gate  * other than the corresponding DLT_ types.
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate  * This is for Linux cooked sockets.
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate #define DLT_LINUX_SLL	113
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * Apple LocalTalk hardware.
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate #define DLT_LTALK	114
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate  * Acorn Econet.
2947c478bd9Sstevel@tonic-gate  */
2957c478bd9Sstevel@tonic-gate #define DLT_ECONET	115
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate  * Reserved for use with OpenBSD ipfilter.
2997c478bd9Sstevel@tonic-gate  */
3007c478bd9Sstevel@tonic-gate #define DLT_IPFILTER	116
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * Reserved for use in capture-file headers as a link-layer type
3047c478bd9Sstevel@tonic-gate  * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
3057c478bd9Sstevel@tonic-gate  * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
3067c478bd9Sstevel@tonic-gate  * in capture-file headers.
3077c478bd9Sstevel@tonic-gate  */
3087c478bd9Sstevel@tonic-gate #define DLT_PFLOG	117
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate  * Registered for Cisco-internal use.
3127c478bd9Sstevel@tonic-gate  */
3137c478bd9Sstevel@tonic-gate #define DLT_CISCO_IOS	118
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate  * Reserved for 802.11 cards using the Prism II chips, with a link-layer
3177c478bd9Sstevel@tonic-gate  * header including Prism monitor mode information plus an 802.11
3187c478bd9Sstevel@tonic-gate  * header.
3197c478bd9Sstevel@tonic-gate  */
3207c478bd9Sstevel@tonic-gate #define DLT_PRISM_HEADER	119
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
3247c478bd9Sstevel@tonic-gate  * (see Doug Ambrisko's FreeBSD patches).
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate #define DLT_AIRONET_HEADER	120
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate /*
3297c478bd9Sstevel@tonic-gate  * Reserved for Siemens HiPath HDLC.
3307c478bd9Sstevel@tonic-gate  */
3317c478bd9Sstevel@tonic-gate #define DLT_HHDLC		121
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate  * Reserved for RFC 2625 IP-over-Fibre Channel, as per a request from
3357c478bd9Sstevel@tonic-gate  * Don Lee <donlee@cray.com>.
3367c478bd9Sstevel@tonic-gate  *
3377c478bd9Sstevel@tonic-gate  * This is not for use with raw Fibre Channel, where the link-layer
3387c478bd9Sstevel@tonic-gate  * header starts with a Fibre Channel frame header; it's for IP-over-FC,
3397c478bd9Sstevel@tonic-gate  * where the link-layer header starts with an RFC 2625 Network_Header
3407c478bd9Sstevel@tonic-gate  * field.
3417c478bd9Sstevel@tonic-gate  */
3427c478bd9Sstevel@tonic-gate #define DLT_IP_OVER_FC		122
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  * The instruction encodings.
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate /* instruction classes */
3487c478bd9Sstevel@tonic-gate #define BPF_CLASS(code) ((code) & 0x07)
3497c478bd9Sstevel@tonic-gate #define		BPF_LD		0x00
3507c478bd9Sstevel@tonic-gate #define		BPF_LDX		0x01
3517c478bd9Sstevel@tonic-gate #define		BPF_ST		0x02
3527c478bd9Sstevel@tonic-gate #define		BPF_STX		0x03
3537c478bd9Sstevel@tonic-gate #define		BPF_ALU		0x04
3547c478bd9Sstevel@tonic-gate #define		BPF_JMP		0x05
3557c478bd9Sstevel@tonic-gate #define		BPF_RET		0x06
3567c478bd9Sstevel@tonic-gate #define		BPF_MISC	0x07
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /* ld/ldx fields */
3597c478bd9Sstevel@tonic-gate #define BPF_SIZE(code)	((code) & 0x18)
3607c478bd9Sstevel@tonic-gate #define		BPF_W		0x00
3617c478bd9Sstevel@tonic-gate #define		BPF_H		0x08
3627c478bd9Sstevel@tonic-gate #define		BPF_B		0x10
3637c478bd9Sstevel@tonic-gate #define BPF_MODE(code)	((code) & 0xe0)
3647c478bd9Sstevel@tonic-gate #define		BPF_IMM 	0x00
3657c478bd9Sstevel@tonic-gate #define		BPF_ABS		0x20
3667c478bd9Sstevel@tonic-gate #define		BPF_IND		0x40
3677c478bd9Sstevel@tonic-gate #define		BPF_MEM		0x60
3687c478bd9Sstevel@tonic-gate #define		BPF_LEN		0x80
3697c478bd9Sstevel@tonic-gate #define		BPF_MSH		0xa0
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /* alu/jmp fields */
3727c478bd9Sstevel@tonic-gate #define BPF_OP(code)	((code) & 0xf0)
3737c478bd9Sstevel@tonic-gate #define		BPF_ADD		0x00
3747c478bd9Sstevel@tonic-gate #define		BPF_SUB		0x10
3757c478bd9Sstevel@tonic-gate #define		BPF_MUL		0x20
3767c478bd9Sstevel@tonic-gate #define		BPF_DIV		0x30
3777c478bd9Sstevel@tonic-gate #define		BPF_OR		0x40
3787c478bd9Sstevel@tonic-gate #define		BPF_AND		0x50
3797c478bd9Sstevel@tonic-gate #define		BPF_LSH		0x60
3807c478bd9Sstevel@tonic-gate #define		BPF_RSH		0x70
3817c478bd9Sstevel@tonic-gate #define		BPF_NEG		0x80
3827c478bd9Sstevel@tonic-gate #define		BPF_JA		0x00
3837c478bd9Sstevel@tonic-gate #define		BPF_JEQ		0x10
3847c478bd9Sstevel@tonic-gate #define		BPF_JGT		0x20
3857c478bd9Sstevel@tonic-gate #define		BPF_JGE		0x30
3867c478bd9Sstevel@tonic-gate #define		BPF_JSET	0x40
3877c478bd9Sstevel@tonic-gate #define BPF_SRC(code)	((code) & 0x08)
3887c478bd9Sstevel@tonic-gate #define		BPF_K		0x00
3897c478bd9Sstevel@tonic-gate #define		BPF_X		0x08
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate /* ret - BPF_K and BPF_X also apply */
3927c478bd9Sstevel@tonic-gate #define BPF_RVAL(code)	((code) & 0x18)
3937c478bd9Sstevel@tonic-gate #define		BPF_A		0x10
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate /* misc */
3967c478bd9Sstevel@tonic-gate #define BPF_MISCOP(code) ((code) & 0xf8)
3977c478bd9Sstevel@tonic-gate #define		BPF_TAX		0x00
3987c478bd9Sstevel@tonic-gate #define		BPF_TXA		0x80
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate /*
4017c478bd9Sstevel@tonic-gate  * The instruction data structure.
4027c478bd9Sstevel@tonic-gate  */
4037c478bd9Sstevel@tonic-gate struct bpf_insn {
4047c478bd9Sstevel@tonic-gate 	u_short	code;
4057c478bd9Sstevel@tonic-gate 	u_char 	jt;
4067c478bd9Sstevel@tonic-gate 	u_char 	jf;
4077c478bd9Sstevel@tonic-gate 	bpf_int32 k;
4087c478bd9Sstevel@tonic-gate };
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate  * Macros for insn array initializers.
4127c478bd9Sstevel@tonic-gate  */
4137c478bd9Sstevel@tonic-gate #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
4147c478bd9Sstevel@tonic-gate #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #if defined(BSD) && (defined(KERNEL) || defined(_KERNEL))
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * Systems based on non-BSD kernels don't have ifnet's (or they don't mean
4197c478bd9Sstevel@tonic-gate  * anything if it is in <net/if.h>) and won't work like this.
4207c478bd9Sstevel@tonic-gate  */
4217c478bd9Sstevel@tonic-gate # if __STDC__
4227c478bd9Sstevel@tonic-gate extern void bpf_tap(struct ifnet *, u_char *, u_int);
4237c478bd9Sstevel@tonic-gate extern void bpf_mtap(struct ifnet *, struct mbuf *);
4247c478bd9Sstevel@tonic-gate extern void bpfattach(struct ifnet *, u_int, u_int);
4257c478bd9Sstevel@tonic-gate extern void bpfilterattach(int);
4267c478bd9Sstevel@tonic-gate # else
4277c478bd9Sstevel@tonic-gate extern void bpf_tap();
4287c478bd9Sstevel@tonic-gate extern void bpf_mtap();
4297c478bd9Sstevel@tonic-gate extern void bpfattach();
4307c478bd9Sstevel@tonic-gate extern void bpfilterattach();
4317c478bd9Sstevel@tonic-gate # endif /* __STDC__ */
4327c478bd9Sstevel@tonic-gate #endif /* BSD && (_KERNEL || KERNEL) */
4337c478bd9Sstevel@tonic-gate #if __STDC__ || defined(__cplusplus)
4347c478bd9Sstevel@tonic-gate extern int bpf_validate(struct bpf_insn *, int);
4357c478bd9Sstevel@tonic-gate extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
4367c478bd9Sstevel@tonic-gate #else
4377c478bd9Sstevel@tonic-gate extern int bpf_validate();
4387c478bd9Sstevel@tonic-gate extern u_int bpf_filter();
4397c478bd9Sstevel@tonic-gate #endif
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
4437c478bd9Sstevel@tonic-gate  */
4447c478bd9Sstevel@tonic-gate #define BPF_MEMWORDS 16
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate #endif
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate #endif
451