1*47638Smccanne /* 2*47638Smccanne * Copyright (c) 1990 The Regents of the University of California. 3*47638Smccanne * All rights reserved. 4*47638Smccanne * 5*47638Smccanne * Redistribution and use in source and binary forms, with or without 6*47638Smccanne * modification, are permitted provided that: (1) source code distributions 7*47638Smccanne * retain the above copyright notice and this paragraph in its entirety, (2) 8*47638Smccanne * distributions including binary code include the above copyright notice and 9*47638Smccanne * this paragraph in its entirety in the documentation or other materials 10*47638Smccanne * provided with the distribution, and (3) all advertising materials mentioning 11*47638Smccanne * features or use of this software display the following acknowledgement: 12*47638Smccanne * ``This product includes software developed by the University of California, 13*47638Smccanne * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14*47638Smccanne * the University nor the names of its contributors may be used to endorse 15*47638Smccanne * or promote products derived from this software without specific prior 16*47638Smccanne * written permission. 17*47638Smccanne * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18*47638Smccanne * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19*47638Smccanne * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20*47638Smccanne * 21*47638Smccanne * @(#) $Header: bpf.h,v 1.19 91/01/30 18:20:21 mccanne Exp $ (LBL) 22*47638Smccanne * 23*47638Smccanne * This code is derived from the Stanford/CMU enet packet filter, 24*47638Smccanne * (net/enet.h) distributed with 4.3BSD Unix. 25*47638Smccanne */ 26*47638Smccanne 27*47638Smccanne /* 28*47638Smccanne * Alignment macros. BPF_WORDALIGN rounds up to the next 29*47638Smccanne * even multiple of BPF_ALIGNMENT. 30*47638Smccanne */ 31*47638Smccanne #define BPF_ALIGNMENT sizeof(long) 32*47638Smccanne #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) 33*47638Smccanne 34*47638Smccanne /* 35*47638Smccanne * Structure for BIOCSETF. 36*47638Smccanne */ 37*47638Smccanne struct bpf_program { 38*47638Smccanne u_int bf_len; 39*47638Smccanne struct bpf_insn *bf_insns; 40*47638Smccanne }; 41*47638Smccanne 42*47638Smccanne /* 43*47638Smccanne * Struct returned by BIOCGSTATS. 44*47638Smccanne */ 45*47638Smccanne struct bpf_stat { 46*47638Smccanne u_int bs_recv; /* number of packets received */ 47*47638Smccanne u_int bs_drop; /* number of packets dropped */ 48*47638Smccanne }; 49*47638Smccanne 50*47638Smccanne /* 51*47638Smccanne * BPF ioctls 52*47638Smccanne * 53*47638Smccanne * The first set is for compatibility with Sun's pcc style 54*47638Smccanne * header files. If your using gcc, we assume that you 55*47638Smccanne * have run fixincludes so the latter set should work. 56*47638Smccanne */ 57*47638Smccanne #if defined(sun) && !defined(__GNUC__) 58*47638Smccanne #define BIOCGFLEN _IOR(B,101, u_int) 59*47638Smccanne #define BIOCGBLEN _IOR(B,102, u_int) 60*47638Smccanne #define BIOCSETF _IOW(B,103, struct bpf_program) 61*47638Smccanne #define BIOCFLUSH _IO(B,104) 62*47638Smccanne #define BIOCPROMISC _IO(B,105) 63*47638Smccanne #define BIOCDEVP _IOR(B,106, struct bpf_devp) 64*47638Smccanne #define BIOCGETIF _IOR(B,107, struct ifreq) 65*47638Smccanne #define BIOCSETIF _IOW(B,108, struct ifreq) 66*47638Smccanne #define BIOCSRTIMEOUT _IOW(B,109, struct timeval) 67*47638Smccanne #define BIOCGRTIMEOUT _IOR(B,110, struct timeval) 68*47638Smccanne #define BIOCGSTATS _IOR(B,111, struct bpf_stat) 69*47638Smccanne #define BIOCIMMEDIATE _IOW(B,112, u_int) 70*47638Smccanne #else 71*47638Smccanne #define BIOCGFLEN _IOR('B',101, u_int) 72*47638Smccanne #define BIOCGBLEN _IOR('B',102, u_int) 73*47638Smccanne #define BIOCSETF _IOW('B',103, struct bpf_program) 74*47638Smccanne #define BIOCFLUSH _IO('B',104) 75*47638Smccanne #define BIOCPROMISC _IO('B',105) 76*47638Smccanne #define BIOCDEVP _IOR('B',106, struct bpf_devp) 77*47638Smccanne #define BIOCGETIF _IOR('B',107, struct ifreq) 78*47638Smccanne #define BIOCSETIF _IOW('B',108, struct ifreq) 79*47638Smccanne #define BIOCSRTIMEOUT _IOW('B',109, struct timeval) 80*47638Smccanne #define BIOCGRTIMEOUT _IOR('B',110, struct timeval) 81*47638Smccanne #define BIOCGSTATS _IOR('B',111, struct bpf_stat) 82*47638Smccanne #define BIOCIMMEDIATE _IOW('B',112, u_int) 83*47638Smccanne #endif 84*47638Smccanne 85*47638Smccanne /* 86*47638Smccanne * The device parameters of a network interface. 87*47638Smccanne */ 88*47638Smccanne struct bpf_devp { 89*47638Smccanne u_short bdev_type; /* data link layer type, codes below */ 90*47638Smccanne u_short bdev_hdrlen; /* length of a hardware packet header */ 91*47638Smccanne }; 92*47638Smccanne 93*47638Smccanne /* 94*47638Smccanne * Structure prepended to each packet. 95*47638Smccanne */ 96*47638Smccanne struct bpf_hdr { 97*47638Smccanne struct timeval bh_tstamp; /* time stamp */ 98*47638Smccanne u_long bh_caplen; /* length of captured portion */ 99*47638Smccanne u_long bh_datalen; /* original length of packet */ 100*47638Smccanne u_short bh_hdrlen; /* length of bpf header (this struct 101*47638Smccanne plus alignment padding) */ 102*47638Smccanne }; 103*47638Smccanne /* 104*47638Smccanne * Because the structure above is not a multiple of 4 bytes, some compilers 105*47638Smccanne * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work. 106*47638Smccanne * Only the kernel needs to know about it; applications use bh_hdrlen. 107*47638Smccanne */ 108*47638Smccanne #ifdef KERNEL 109*47638Smccanne #define SIZEOF_BPF_HDR 18 110*47638Smccanne #endif 111*47638Smccanne 112*47638Smccanne /* 113*47638Smccanne * Data-link level type codes. 114*47638Smccanne * Currently, only ENDT_10MB and DLT_SLIP are supported. 115*47638Smccanne */ 116*47638Smccanne #define DLT_EN10MB 1 /* Ethernet (10Mb) */ 117*47638Smccanne #define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ 118*47638Smccanne #define DLT_AX25 3 /* Amateur Radio AX.25 */ 119*47638Smccanne #define DLT_PRONET 4 /* Proteon ProNET Token Ring */ 120*47638Smccanne #define DLT_CHAOS 5 /* Chaos */ 121*47638Smccanne #define DLT_IEEE802 6 /* IEEE 802 Networks */ 122*47638Smccanne #define DLT_ARCNET 7 /* ARCNET */ 123*47638Smccanne #define DLT_SLIP 8 /* Serial Line IP */ 124*47638Smccanne #define DLT_PPP 9 /* Point-to-point Protocol */ 125*47638Smccanne #define DLT_FDDI 10 /* FDDI */ 126*47638Smccanne 127*47638Smccanne /* 128*47638Smccanne * The opcodes are defined as an enumeration. However, they are stored 129*47638Smccanne * explicitly in the code array as 'u_short'. 130*47638Smccanne */ 131*47638Smccanne enum bpf_code { 132*47638Smccanne #define OPDEF(opcode, opstr) opcode , 133*47638Smccanne #include <net/bpfcodes.h> 134*47638Smccanne #undef OPDEF 135*47638Smccanne /* this idea is borrowed from gcc */ 136*47638Smccanne LAST_AND_UNUSED_ENUM 137*47638Smccanne }; 138*47638Smccanne 139*47638Smccanne #define BPF_NCODES ((unsigned)LAST_AND_UNUSED_ENUM) 140*47638Smccanne #define BPF_VALIDCODE(code) ((unsigned)(code) < BPF_NCODES) 141*47638Smccanne 142*47638Smccanne /* 143*47638Smccanne * The instruction data structure. 144*47638Smccanne */ 145*47638Smccanne struct bpf_insn { 146*47638Smccanne u_short code; 147*47638Smccanne u_char jt; 148*47638Smccanne u_char jf; 149*47638Smccanne long k; 150*47638Smccanne }; 151*47638Smccanne 152*47638Smccanne /* 153*47638Smccanne * Macros for array initializers. 154*47638Smccanne */ 155*47638Smccanne #define BPF_STMT(code, k) { (u_short)code, 0, 0, k } 156*47638Smccanne #define BPF_JUMP(code, k, jt, jf) { (u_short)code, jt, jf, k } 157*47638Smccanne 158*47638Smccanne #ifdef KERNEL 159*47638Smccanne extern u_int bpf_filter(); 160*47638Smccanne extern void bpfattach(); 161*47638Smccanne extern void bpf_tap(); 162*47638Smccanne extern void bpf_mtap(); 163*47638Smccanne #endif 164*47638Smccanne 165*47638Smccanne /* 166*47638Smccanne * These two macros are sensitive to the order in which the 167*47638Smccanne * opcodes appear in bpfcodes.h. 168*47638Smccanne */ 169*47638Smccanne #define BPF_ISJUMP(code) ((unsigned)(code) <= (unsigned)EQOp) 170*47638Smccanne #define BPF_ISLEAF(code) ((unsigned)(code) >= (unsigned)RetOp) 171*47638Smccanne 172*47638Smccanne /* 173*47638Smccanne * Number of scratch memory words. 174*47638Smccanne */ 175*47638Smccanne #define BPF_MEMWORDS 16 176