:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / net / packet / win_bpf.h
1 /*-
2  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3  *      The Regents of the University of California.  All rights reserved.
4  *
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
7  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 
8  * Berkeley Laboratory.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
39  *
40  * @(#) $Header$ (LBL)
41  */
42
43 #ifndef BPF_MAJOR_VERSION
44
45 /* BSD style release date */
46 #define BPF_RELEASE 199606
47
48 typedef UCHAR u_char;
49 typedef USHORT u_short;
50 typedef ULONG u_int;
51 typedef LONG bpf_int32;
52 typedef ULONG bpf_u_int32;
53 typedef ULONG u_int32;
54
55 #define BPF_MAXINSNS 512
56 #define BPF_MAXBUFSIZE 0x8000
57 #define BPF_MINBUFSIZE 32
58
59 #include "time_calls.h"
60
61 /*
62  * The instruction data structure.
63  */
64 struct bpf_insn {
65         u_short code;
66         u_char  jt;
67         u_char  jf;
68         bpf_int32 k;
69 };
70
71 /*
72  *  Structure for BIOCSETF.
73  */
74 struct bpf_program {
75         u_int bf_len;
76         struct bpf_insn *bf_insns;
77 };
78  
79 /*
80  * Struct returned by BIOCGSTATS.
81  */
82 struct bpf_stat {
83         u_int bs_recv;          /* number of packets received */
84         u_int bs_drop;          /* number of packets dropped */
85 };
86
87 /*
88  * Struct return by BIOCVERSION.  This represents the version number of 
89  * the filter language described by the instruction encodings below.
90  * bpf understands a program iff kernel_major == filter_major &&
91  * kernel_minor >= filter_minor, that is, if the value returned by the
92  * running kernel has the same major number and a minor number equal
93  * equal to or less than the filter being downloaded.  Otherwise, the
94  * results are undefined, meaning an error may be returned or packets
95  * may be accepted haphazardly.
96  * It has nothing to do with the source code version.
97  */
98 struct bpf_version {
99         u_short bv_major;
100         u_short bv_minor;
101 };
102 /* Current version number of filter architecture. */
103 #define BPF_MAJOR_VERSION 1
104 #define BPF_MINOR_VERSION 1
105
106
107 /*
108  * Structure prepended to each packet.
109  */
110 struct bpf_hdr {
111         struct timeval  bh_tstamp;      /* time stamp */
112         bpf_u_int32     bh_caplen;      /* length of captured portion */
113         bpf_u_int32     bh_datalen;     /* original length of packet */
114         u_short         bh_hdrlen;      /* length of bpf header (this struct
115                                            plus alignment padding) */
116 };
117
118 /*
119  * Data-link level type codes.
120  */
121
122 /*
123  * These are the types that are the same on all platforms; on other
124  * platforms, a <net/bpf.h> should be supplied that defines the additional
125  * DLT_* codes appropriately for that platform (the BSDs, for example,
126  * should not just pick up this version of "bpf.h"; they should also define
127  * the additional DLT_* codes used by their kernels, as well as the values
128  * defined here - and, if the values they use for particular DLT_ types
129  * differ from those here, they should use their values, not the ones
130  * here).
131  */
132 #define DLT_NULL        0       /* no link-layer encapsulation */
133 #define DLT_EN10MB      1       /* Ethernet (10Mb) */
134 #define DLT_EN3MB       2       /* Experimental Ethernet (3Mb) */
135 #define DLT_AX25        3       /* Amateur Radio AX.25 */
136 #define DLT_PRONET      4       /* Proteon ProNET Token Ring */
137 #define DLT_CHAOS       5       /* Chaos */
138 #define DLT_IEEE802     6       /* IEEE 802 Networks */
139 #define DLT_ARCNET      7       /* ARCNET */
140 #define DLT_SLIP        8       /* Serial Line IP */
141 #define DLT_PPP         9       /* Point-to-point Protocol */
142 #define DLT_FDDI        10      /* FDDI */
143
144 /*
145  * These are values from the traditional libpcap "bpf.h".
146  * Ports of this to particular platforms should replace these definitions
147  * with the ones appropriate to that platform, if the values are
148  * different on that platform.
149  */
150 #define DLT_ATM_RFC1483 11      /* LLC/SNAP encapsulated atm */
151 #define DLT_RAW         12      /* raw IP */
152
153 /*
154  * These are values from BSD/OS's "bpf.h".
155  * These are not the same as the values from the traditional libpcap
156  * "bpf.h"; however, these values shouldn't be generated by any
157  * OS other than BSD/OS, so the correct values to use here are the
158  * BSD/OS values.
159  *
160  * Platforms that have already assigned these values to other
161  * DLT_ codes, however, should give these codes the values
162  * from that platform, so that programs that use these codes will
163  * continue to compile - even though they won't correctly read
164  * files of these types.
165  */
166 #define DLT_SLIP_BSDOS  15      /* BSD/OS Serial Line IP */
167 #define DLT_PPP_BSDOS   16      /* BSD/OS Point-to-point Protocol */
168
169 #define DLT_ATM_CLIP    19      /* Linux Classical-IP over ATM */
170
171 /*
172  * This value is defined by NetBSD; other platforms should refrain from
173  * using it for other purposes, so that NetBSD savefiles with a link
174  * type of 50 can be read as this type on all platforms.
175  */
176 #define DLT_PPP_SERIAL  50      /* PPP over serial with HDLC encapsulation */
177
178 /*
179  * This value was defined by libpcap 0.5; platforms that have defined
180  * it with a different value should define it here with that value -
181  * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
182  * whatever value that happens to be, so programs will correctly
183  * handle files with that link type regardless of the value of
184  * DLT_C_HDLC.
185  *
186  * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
187  * compatibility with programs written for BSD/OS.
188  *
189  * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
190  * for source compatibility with programs written for libpcap 0.5.
191  */
192 #define DLT_C_HDLC      104     /* Cisco HDLC */
193 #define DLT_CHDLC       DLT_C_HDLC
194
195 /*
196  * Reserved for future use.
197  * Do not pick other numerical value for these unless you have also
198  * picked up the tcpdump.org top-of-CVS-tree version of "savefile.c",
199  * which will arrange that capture files for these DLT_ types have
200  * the same "network" value on all platforms, regardless of what
201  * value is chosen for their DLT_ type (thus allowing captures made
202  * on one platform to be read on other platforms, even if the two
203  * platforms don't use the same numerical values for all DLT_ types).
204  */
205 #define DLT_IEEE802_11  105     /* IEEE 802.11 wireless */
206
207 /*
208  * Values between 106 and 107 are used in capture file headers as
209  * link-layer types corresponding to DLT_ types that might differ
210  * between platforms; don't use those values for new DLT_ new types.
211  */
212
213 /*
214  * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
215  * that the AF_ type in the link-layer header is in network byte order.
216  *
217  * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
218  * define it as 108 here.  If OpenBSD picks up this file, it should
219  * define DLT_LOOP as 12 in its version, as per the comment above -
220  * and should not use 108 for any purpose.
221  */
222 #define DLT_LOOP        108
223
224 /*
225  * Values between 109 and 112 are used in capture file headers as
226  * link-layer types corresponding to DLT_ types that might differ
227  * between platforms; don't use those values for new DLT_ new types.
228  */
229
230 /*
231  * This is for Linux cooked sockets.
232  */
233 #define DLT_LINUX_SLL   113
234
235 /*
236  * The instruction encodings.
237  */
238 /* instruction classes */
239 #define BPF_CLASS(code) ((code) & 0x07)
240 #define         BPF_LD          0x00
241 #define         BPF_LDX         0x01
242 #define         BPF_ST          0x02
243 #define         BPF_STX         0x03
244 #define         BPF_ALU         0x04
245 #define         BPF_JMP         0x05
246 #define         BPF_RET         0x06
247 #define         BPF_MISC        0x07
248
249 /* ld/ldx fields */
250 #define BPF_SIZE(code)  ((code) & 0x18)
251 #define         BPF_W           0x00
252 #define         BPF_H           0x08
253 #define         BPF_B           0x10
254 #define BPF_MODE(code)  ((code) & 0xe0)
255 #define         BPF_IMM         0x00
256 #define         BPF_ABS         0x20
257 #define         BPF_IND         0x40
258 #define         BPF_MEM         0x60
259 #define         BPF_LEN         0x80
260 #define         BPF_MSH         0xa0
261
262 /* alu/jmp fields */
263 #define BPF_OP(code)    ((code) & 0xf0)
264 #define         BPF_ADD         0x00
265 #define         BPF_SUB         0x10
266 #define         BPF_MUL         0x20
267 #define         BPF_DIV         0x30
268 #define         BPF_OR          0x40
269 #define         BPF_AND         0x50
270 #define         BPF_LSH         0x60
271 #define         BPF_RSH         0x70
272 #define         BPF_NEG         0x80
273 #define         BPF_JA          0x00
274 #define         BPF_JEQ         0x10
275 #define         BPF_JGT         0x20
276 #define         BPF_JGE         0x30
277 #define         BPF_JSET        0x40
278 #define BPF_SRC(code)   ((code) & 0x08)
279 #define         BPF_K           0x00
280 #define         BPF_X           0x08
281
282 /* ret - BPF_K and BPF_X also apply */
283 #define BPF_RVAL(code)  ((code) & 0x18)
284 #define         BPF_A           0x10
285
286 /* misc */
287 #define BPF_MISCOP(code) ((code) & 0xf8)
288 #define         BPF_TAX         0x00
289 #define         BPF_TXA         0x80
290
291 /* TME instructions */
292 #define         BPF_TME                                 0x08
293
294 #define         BPF_LOOKUP                              0x90   
295 #define         BPF_EXECUTE                             0xa0
296 #define         BPF_INIT                                0xb0
297 #define         BPF_VALIDATE                    0xc0
298 #define         BPF_SET_ACTIVE                  0xd0
299 #define         BPF_RESET                               0xe0
300 #define         BPF_SET_MEMORY                  0x80
301 #define         BPF_GET_REGISTER_VALUE  0x70
302 #define         BPF_SET_REGISTER_VALUE  0x60
303 #define         BPF_SET_WORKING                 0x50
304 #define         BPF_SET_ACTIVE_READ             0x40
305 #define         BPF_SET_AUTODELETION    0x30
306 #define         BPF_SEPARATION                  0xff
307
308 #define         BPF_MEM_EX_IMM  0xc0
309 #define         BPF_MEM_EX_IND  0xe0
310 /*used for ST */
311 #define         BPF_MEM_EX              0xc0
312
313
314 /*
315  * Macros for insn array initializers.
316  */
317 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
318 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
319
320 /*
321  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
322  */
323 #define BPF_MEMWORDS 16
324
325 #endif