Commit | Line | Data |
---|---|---|
81c7b6ec SM |
1 | /* |
2 | * Copyright (c) 1990, 1991 Regents of the University of California. | |
11569edc SM |
3 | * All rights reserved. |
4 | * | |
6cfe221b KB |
5 | * This code is derived from the Stanford/CMU enet packet filter, |
6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed | |
81c7b6ec | 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence |
d9f44bf8 | 8 | * Berkeley Laboratory. |
11569edc | 9 | * |
81c7b6ec | 10 | * %sccs.include.redist.c% |
6cfe221b | 11 | * |
81c7b6ec | 12 | * @(#)bpf.h 7.3 (Berkeley) %G% |
d9f44bf8 SM |
13 | * |
14 | * @(#) $Header: bpf.h,v 1.24 91/10/27 21:22:32 mccanne Exp $ (LBL) | |
11569edc SM |
15 | */ |
16 | ||
17 | /* | |
18 | * Alignment macros. BPF_WORDALIGN rounds up to the next | |
19 | * even multiple of BPF_ALIGNMENT. | |
20 | */ | |
21 | #define BPF_ALIGNMENT sizeof(long) | |
22 | #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) | |
23 | ||
f8e186b1 SM |
24 | #define BPF_MAXINSNS 512 |
25 | #define BPF_MAXBUFSIZE 0x8000 | |
26 | ||
11569edc SM |
27 | /* |
28 | * Structure for BIOCSETF. | |
29 | */ | |
30 | struct bpf_program { | |
31 | u_int bf_len; | |
32 | struct bpf_insn *bf_insns; | |
33 | }; | |
34 | ||
35 | /* | |
36 | * Struct returned by BIOCGSTATS. | |
37 | */ | |
38 | struct bpf_stat { | |
39 | u_int bs_recv; /* number of packets received */ | |
40 | u_int bs_drop; /* number of packets dropped */ | |
41 | }; | |
42 | ||
43 | /* | |
44 | * BPF ioctls | |
45 | * | |
46 | * The first set is for compatibility with Sun's pcc style | |
47 | * header files. If your using gcc, we assume that you | |
48 | * have run fixincludes so the latter set should work. | |
49 | */ | |
d9f44bf8 | 50 | #if (defined(sun) || defined(ibm032)) && !defined(__GNUC__) |
11569edc | 51 | #define BIOCGBLEN _IOR(B,102, u_int) |
d9f44bf8 | 52 | #define BIOCSBLEN _IOWR(B,102, u_int) |
11569edc SM |
53 | #define BIOCSETF _IOW(B,103, struct bpf_program) |
54 | #define BIOCFLUSH _IO(B,104) | |
55 | #define BIOCPROMISC _IO(B,105) | |
732c04ca | 56 | #define BIOCGDLT _IOR(B,106, u_int) |
11569edc SM |
57 | #define BIOCGETIF _IOR(B,107, struct ifreq) |
58 | #define BIOCSETIF _IOW(B,108, struct ifreq) | |
59 | #define BIOCSRTIMEOUT _IOW(B,109, struct timeval) | |
60 | #define BIOCGRTIMEOUT _IOR(B,110, struct timeval) | |
61 | #define BIOCGSTATS _IOR(B,111, struct bpf_stat) | |
62 | #define BIOCIMMEDIATE _IOW(B,112, u_int) | |
63 | #else | |
11569edc | 64 | #define BIOCGBLEN _IOR('B',102, u_int) |
d9f44bf8 | 65 | #define BIOCSBLEN _IOWR('B',102, u_int) |
11569edc SM |
66 | #define BIOCSETF _IOW('B',103, struct bpf_program) |
67 | #define BIOCFLUSH _IO('B',104) | |
68 | #define BIOCPROMISC _IO('B',105) | |
732c04ca | 69 | #define BIOCGDLT _IOR('B',106, u_int) |
11569edc SM |
70 | #define BIOCGETIF _IOR('B',107, struct ifreq) |
71 | #define BIOCSETIF _IOW('B',108, struct ifreq) | |
72 | #define BIOCSRTIMEOUT _IOW('B',109, struct timeval) | |
73 | #define BIOCGRTIMEOUT _IOR('B',110, struct timeval) | |
74 | #define BIOCGSTATS _IOR('B',111, struct bpf_stat) | |
75 | #define BIOCIMMEDIATE _IOW('B',112, u_int) | |
76 | #endif | |
77 | ||
11569edc SM |
78 | /* |
79 | * Structure prepended to each packet. | |
80 | */ | |
81 | struct bpf_hdr { | |
82 | struct timeval bh_tstamp; /* time stamp */ | |
83 | u_long bh_caplen; /* length of captured portion */ | |
84 | u_long bh_datalen; /* original length of packet */ | |
85 | u_short bh_hdrlen; /* length of bpf header (this struct | |
86 | plus alignment padding) */ | |
87 | }; | |
88 | /* | |
89 | * Because the structure above is not a multiple of 4 bytes, some compilers | |
90 | * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work. | |
91 | * Only the kernel needs to know about it; applications use bh_hdrlen. | |
92 | */ | |
93 | #ifdef KERNEL | |
94 | #define SIZEOF_BPF_HDR 18 | |
95 | #endif | |
96 | ||
97 | /* | |
98 | * Data-link level type codes. | |
732c04ca | 99 | * Currently, only DLT_EN10MB and DLT_SLIP are supported. |
11569edc | 100 | */ |
d9f44bf8 | 101 | #define DLT_NULL 0 /* no link-layer encapsulation */ |
11569edc SM |
102 | #define DLT_EN10MB 1 /* Ethernet (10Mb) */ |
103 | #define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ | |
104 | #define DLT_AX25 3 /* Amateur Radio AX.25 */ | |
105 | #define DLT_PRONET 4 /* Proteon ProNET Token Ring */ | |
106 | #define DLT_CHAOS 5 /* Chaos */ | |
107 | #define DLT_IEEE802 6 /* IEEE 802 Networks */ | |
108 | #define DLT_ARCNET 7 /* ARCNET */ | |
109 | #define DLT_SLIP 8 /* Serial Line IP */ | |
110 | #define DLT_PPP 9 /* Point-to-point Protocol */ | |
111 | #define DLT_FDDI 10 /* FDDI */ | |
112 | ||
113 | /* | |
e6ce130c | 114 | * The instruction encondings. |
11569edc | 115 | */ |
e6ce130c SM |
116 | /* classes <2:0> */ |
117 | #define BPF_CLASS(code) ((code) & 0x07) | |
118 | #define BPF_LD 0x00 | |
119 | #define BPF_LDX 0x01 | |
120 | #define BPF_ST 0x02 | |
121 | #define BPF_STX 0x03 | |
122 | #define BPF_ALU 0x04 | |
123 | #define BPF_JMP 0x05 | |
124 | #define BPF_RET 0x06 | |
125 | #define BPF_MISC 0x07 | |
126 | ||
127 | /* ld/ldx fields */ | |
128 | #define BPF_SIZE(code) ((code) & 0x18) | |
129 | #define BPF_W 0x00 | |
130 | #define BPF_H 0x08 | |
131 | #define BPF_B 0x10 | |
132 | #define BPF_MODE(code) ((code) & 0xe0) | |
133 | #define BPF_IMM 0x00 | |
134 | #define BPF_ABS 0x20 | |
135 | #define BPF_IND 0x40 | |
136 | #define BPF_MEM 0x60 | |
137 | #define BPF_LEN 0x80 | |
138 | #define BPF_MSH 0xa0 | |
139 | ||
140 | /* alu/jmp fields */ | |
141 | #define BPF_OP(code) ((code) & 0xf0) | |
142 | #define BPF_ADD 0x00 | |
143 | #define BPF_SUB 0x10 | |
144 | #define BPF_MUL 0x20 | |
145 | #define BPF_DIV 0x30 | |
146 | #define BPF_OR 0x40 | |
147 | #define BPF_AND 0x50 | |
148 | #define BPF_LSH 0x60 | |
149 | #define BPF_RSH 0x70 | |
150 | #define BPF_NEG 0x80 | |
151 | #define BPF_JA 0x00 | |
152 | #define BPF_JEQ 0x10 | |
153 | #define BPF_JGT 0x20 | |
154 | #define BPF_JGE 0x30 | |
155 | #define BPF_JSET 0x40 | |
156 | #define BPF_SRC(code) ((code) & 0x08) | |
157 | #define BPF_K 0x00 | |
158 | #define BPF_X 0x08 | |
159 | ||
160 | /* ret - BPF_K and BPF_X also apply */ | |
161 | #define BPF_RVAL(code) ((code) & 0x18) | |
162 | #define BPF_A 0x10 | |
11569edc | 163 | |
e6ce130c SM |
164 | /* misc */ |
165 | #define BPF_MISCOP(code) ((code) & 0xf8) | |
166 | #define BPF_TAX 0x00 | |
167 | #define BPF_TXA 0x80 | |
11569edc SM |
168 | |
169 | /* | |
170 | * The instruction data structure. | |
171 | */ | |
172 | struct bpf_insn { | |
173 | u_short code; | |
174 | u_char jt; | |
175 | u_char jf; | |
176 | long k; | |
177 | }; | |
178 | ||
179 | /* | |
e6ce130c | 180 | * Macros for insn array initializers. |
11569edc | 181 | */ |
e6ce130c SM |
182 | #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } |
183 | #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } | |
11569edc SM |
184 | |
185 | #ifdef KERNEL | |
186 | extern u_int bpf_filter(); | |
187 | extern void bpfattach(); | |
188 | extern void bpf_tap(); | |
189 | extern void bpf_mtap(); | |
190 | #endif | |
191 | ||
192 | /* | |
e6ce130c | 193 | * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). |
11569edc SM |
194 | */ |
195 | #define BPF_MEMWORDS 16 | |
d9f44bf8 | 196 |