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) 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 */ 142df8bae1dSRodney W. Grimes #define DLT_NULL 0 /* no link-layer 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 /* 18346da4bc6SBill Fenner * This value was defined by libpcap 0.5; platforms that have defined 18446da4bc6SBill Fenner * it with a different value should define it here with that value - 18546da4bc6SBill Fenner * a link type of 104 in a save file will be mapped to DLT_C_HDLC, 18646da4bc6SBill Fenner * whatever value that happens to be, so programs will correctly 18746da4bc6SBill Fenner * handle files with that link type regardless of the value of 18846da4bc6SBill Fenner * DLT_C_HDLC. 18946da4bc6SBill Fenner * 19046da4bc6SBill Fenner * The name DLT_C_HDLC was used by BSD/OS; we use that name for source 19146da4bc6SBill Fenner * compatibility with programs written for BSD/OS. 19246da4bc6SBill Fenner * 19346da4bc6SBill Fenner * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well, 19446da4bc6SBill Fenner * for source compatibility with programs written for libpcap 0.5. 19546da4bc6SBill Fenner */ 19646da4bc6SBill Fenner #define DLT_C_HDLC 104 /* Cisco HDLC */ 19746da4bc6SBill Fenner #define DLT_CHDLC DLT_C_HDLC 19846da4bc6SBill Fenner 19946da4bc6SBill Fenner #define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ 20046da4bc6SBill Fenner 20146da4bc6SBill Fenner /* 20246da4bc6SBill Fenner * Values between 106 and 107 are used in capture file headers as 20346da4bc6SBill Fenner * link-layer types corresponding to DLT_ types that might differ 20446da4bc6SBill Fenner * between platforms; don't use those values for new DLT_ new types. 20546da4bc6SBill Fenner */ 20646da4bc6SBill Fenner 20746da4bc6SBill Fenner /* 20846da4bc6SBill Fenner * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except 20946da4bc6SBill Fenner * that the AF_ type in the link-layer header is in network byte order. 21046da4bc6SBill Fenner * 21146da4bc6SBill Fenner * OpenBSD defines it as 12, but that collides with DLT_RAW, so we 21246da4bc6SBill Fenner * define it as 108 here. If OpenBSD picks up this file, it should 21346da4bc6SBill Fenner * define DLT_LOOP as 12 in its version, as per the comment above - 21494413c0dSBill Fenner * and should not use 108 as a DLT_ value. 21546da4bc6SBill Fenner */ 21646da4bc6SBill Fenner #define DLT_LOOP 108 21746da4bc6SBill Fenner 21846da4bc6SBill Fenner /* 21946da4bc6SBill Fenner * Values between 109 and 112 are used in capture file headers as 22046da4bc6SBill Fenner * link-layer types corresponding to DLT_ types that might differ 22146da4bc6SBill Fenner * between platforms; don't use those values for new DLT_ new types. 22246da4bc6SBill Fenner */ 22346da4bc6SBill Fenner 22446da4bc6SBill Fenner /* 22546da4bc6SBill Fenner * This is for Linux cooked sockets. 22646da4bc6SBill Fenner */ 22746da4bc6SBill Fenner #define DLT_LINUX_SLL 113 228df8bae1dSRodney W. Grimes 229df8bae1dSRodney W. Grimes /* 23094413c0dSBill Fenner * Apple LocalTalk hardware. 23194413c0dSBill Fenner */ 23294413c0dSBill Fenner #define DLT_LTALK 114 23394413c0dSBill Fenner 23494413c0dSBill Fenner /* 23594413c0dSBill Fenner * Acorn Econet. 23694413c0dSBill Fenner */ 23794413c0dSBill Fenner #define DLT_ECONET 115 23894413c0dSBill Fenner 23994413c0dSBill Fenner /* 24094413c0dSBill Fenner * Reserved for use with OpenBSD ipfilter. 24194413c0dSBill Fenner */ 24294413c0dSBill Fenner #define DLT_IPFILTER 116 24394413c0dSBill Fenner 24494413c0dSBill Fenner /* 24594413c0dSBill Fenner * Reserved for use in capture-file headers as a link-layer type 24694413c0dSBill Fenner * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD, 24794413c0dSBill Fenner * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it 24894413c0dSBill Fenner * in capture-file headers. 24994413c0dSBill Fenner */ 25094413c0dSBill Fenner #define DLT_PFLOG 117 25194413c0dSBill Fenner 25294413c0dSBill Fenner /* 25394413c0dSBill Fenner * Registered for Cisco-internal use. 25494413c0dSBill Fenner */ 25594413c0dSBill Fenner #define DLT_CISCO_IOS 118 25694413c0dSBill Fenner 25794413c0dSBill Fenner /* 25894413c0dSBill Fenner * Reserved for 802.11 cards using the Prism II chips, with a link-layer 25994413c0dSBill Fenner * header including Prism monitor mode information plus an 802.11 26094413c0dSBill Fenner * header. 26194413c0dSBill Fenner */ 26294413c0dSBill Fenner #define DLT_PRISM_HEADER 119 26394413c0dSBill Fenner 26494413c0dSBill Fenner /* 26594413c0dSBill Fenner * Reserved for Aironet 802.11 cards, with an Aironet link-layer header 26694413c0dSBill Fenner * (see Doug Ambrisko's FreeBSD patches). 26794413c0dSBill Fenner */ 26894413c0dSBill Fenner #define DLT_AIRONET_HEADER 120 26994413c0dSBill Fenner 27094413c0dSBill Fenner /* 2716c5e9bbdSMike Pritchard * The instruction encodings. 272df8bae1dSRodney W. Grimes */ 273df8bae1dSRodney W. Grimes /* instruction classes */ 274df8bae1dSRodney W. Grimes #define BPF_CLASS(code) ((code) & 0x07) 275df8bae1dSRodney W. Grimes #define BPF_LD 0x00 276df8bae1dSRodney W. Grimes #define BPF_LDX 0x01 277df8bae1dSRodney W. Grimes #define BPF_ST 0x02 278df8bae1dSRodney W. Grimes #define BPF_STX 0x03 279df8bae1dSRodney W. Grimes #define BPF_ALU 0x04 280df8bae1dSRodney W. Grimes #define BPF_JMP 0x05 281df8bae1dSRodney W. Grimes #define BPF_RET 0x06 282df8bae1dSRodney W. Grimes #define BPF_MISC 0x07 283df8bae1dSRodney W. Grimes 284df8bae1dSRodney W. Grimes /* ld/ldx fields */ 285df8bae1dSRodney W. Grimes #define BPF_SIZE(code) ((code) & 0x18) 286df8bae1dSRodney W. Grimes #define BPF_W 0x00 287df8bae1dSRodney W. Grimes #define BPF_H 0x08 288df8bae1dSRodney W. Grimes #define BPF_B 0x10 289df8bae1dSRodney W. Grimes #define BPF_MODE(code) ((code) & 0xe0) 290df8bae1dSRodney W. Grimes #define BPF_IMM 0x00 291df8bae1dSRodney W. Grimes #define BPF_ABS 0x20 292df8bae1dSRodney W. Grimes #define BPF_IND 0x40 293df8bae1dSRodney W. Grimes #define BPF_MEM 0x60 294df8bae1dSRodney W. Grimes #define BPF_LEN 0x80 295df8bae1dSRodney W. Grimes #define BPF_MSH 0xa0 296df8bae1dSRodney W. Grimes 297df8bae1dSRodney W. Grimes /* alu/jmp fields */ 298df8bae1dSRodney W. Grimes #define BPF_OP(code) ((code) & 0xf0) 299df8bae1dSRodney W. Grimes #define BPF_ADD 0x00 300df8bae1dSRodney W. Grimes #define BPF_SUB 0x10 301df8bae1dSRodney W. Grimes #define BPF_MUL 0x20 302df8bae1dSRodney W. Grimes #define BPF_DIV 0x30 303df8bae1dSRodney W. Grimes #define BPF_OR 0x40 304df8bae1dSRodney W. Grimes #define BPF_AND 0x50 305df8bae1dSRodney W. Grimes #define BPF_LSH 0x60 306df8bae1dSRodney W. Grimes #define BPF_RSH 0x70 307df8bae1dSRodney W. Grimes #define BPF_NEG 0x80 308df8bae1dSRodney W. Grimes #define BPF_JA 0x00 309df8bae1dSRodney W. Grimes #define BPF_JEQ 0x10 310df8bae1dSRodney W. Grimes #define BPF_JGT 0x20 311df8bae1dSRodney W. Grimes #define BPF_JGE 0x30 312df8bae1dSRodney W. Grimes #define BPF_JSET 0x40 313df8bae1dSRodney W. Grimes #define BPF_SRC(code) ((code) & 0x08) 314df8bae1dSRodney W. Grimes #define BPF_K 0x00 315df8bae1dSRodney W. Grimes #define BPF_X 0x08 316df8bae1dSRodney W. Grimes 317df8bae1dSRodney W. Grimes /* ret - BPF_K and BPF_X also apply */ 318df8bae1dSRodney W. Grimes #define BPF_RVAL(code) ((code) & 0x18) 319df8bae1dSRodney W. Grimes #define BPF_A 0x10 320df8bae1dSRodney W. Grimes 321df8bae1dSRodney W. Grimes /* misc */ 322df8bae1dSRodney W. Grimes #define BPF_MISCOP(code) ((code) & 0xf8) 323df8bae1dSRodney W. Grimes #define BPF_TAX 0x00 324df8bae1dSRodney W. Grimes #define BPF_TXA 0x80 325df8bae1dSRodney W. Grimes 326df8bae1dSRodney W. Grimes /* 327df8bae1dSRodney W. Grimes * The instruction data structure. 328df8bae1dSRodney W. Grimes */ 329df8bae1dSRodney W. Grimes struct bpf_insn { 330df8bae1dSRodney W. Grimes u_short code; 331df8bae1dSRodney W. Grimes u_char jt; 332df8bae1dSRodney W. Grimes u_char jf; 33311a53ef3SPaul Traina bpf_u_int32 k; 334df8bae1dSRodney W. Grimes }; 335df8bae1dSRodney W. Grimes 336df8bae1dSRodney W. Grimes /* 337df8bae1dSRodney W. Grimes * Macros for insn array initializers. 338df8bae1dSRodney W. Grimes */ 339df8bae1dSRodney W. Grimes #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } 340df8bae1dSRodney W. Grimes #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } 341df8bae1dSRodney W. Grimes 342664a31e4SPeter Wemm #ifdef _KERNEL 34324a229f4SSam Leffler struct bpf_if; 344929ddbbbSAlfred Perlstein int bpf_validate(const struct bpf_insn *, int); 34524a229f4SSam Leffler void bpf_tap(struct bpf_if *, u_char *, u_int); 34624a229f4SSam Leffler void bpf_mtap(struct bpf_if *, struct mbuf *); 347929ddbbbSAlfred Perlstein void bpfattach(struct ifnet *, u_int, u_int); 34824a229f4SSam Leffler void bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **); 349929ddbbbSAlfred Perlstein void bpfdetach(struct ifnet *); 350de5d9935SRobert Watson 351929ddbbbSAlfred Perlstein void bpfilterattach(int); 352929ddbbbSAlfred Perlstein u_int bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int); 35324a229f4SSam Leffler 35424a229f4SSam Leffler #define BPF_TAP(_ifp,_pkt,_pktlen) do { \ 35524a229f4SSam Leffler if ((_ifp)->if_bpf) \ 35624a229f4SSam Leffler bpf_tap((_ifp)->if_bpf, (_pkt), (_pktlen)); \ 35724a229f4SSam Leffler } while (0) 35824a229f4SSam Leffler #define BPF_MTAP(_ifp,_m) do { \ 35924a229f4SSam Leffler if ((_ifp)->if_bpf) \ 36024a229f4SSam Leffler bpf_mtap((_ifp)->if_bpf, (_m)); \ 36124a229f4SSam Leffler } while (0) 362df8bae1dSRodney W. Grimes #endif 363df8bae1dSRodney W. Grimes 364df8bae1dSRodney W. Grimes /* 365df8bae1dSRodney W. Grimes * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). 366df8bae1dSRodney W. Grimes */ 367df8bae1dSRodney W. Grimes #define BPF_MEMWORDS 16 368df8bae1dSRodney W. Grimes 36924a229f4SSam Leffler #endif /* _NET_BPF_H_ */ 370