|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26:
27: /*
28: * Berkeley Packet Filter Definitions from Berkeley
29: */
30:
31: /*-
32: * Copyright (c) 1990-1991 The Regents of the University of California.
33: * All rights reserved.
34: *
35: * This code is derived from the Stanford/CMU enet packet filter,
36: * (net/enet.c) distributed as part of 4.3BSD, and code contributed
37: * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
38: * Berkeley Laboratory.
39: *
40: * Redistribution and use in source and binary forms, with or without
41: * modification, are permitted provided that the following conditions
42: * are met:
43: * 1. Redistributions of source code must retain the above copyright
44: * notice, this list of conditions and the following disclaimer.
45: * 2. Redistributions in binary form must reproduce the above copyright
46: * notice, this list of conditions and the following disclaimer in the
47: * documentation and/or other materials provided with the distribution.
48: * 4. Neither the name of the University nor the names of its contributors
49: * may be used to endorse or promote products derived from this software
50: * without specific prior written permission.
51: *
52: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62: * SUCH DAMAGE.
63: *
64: * @(#)bpf.h 7.1 (Berkeley) 5/7/91
65: *
66: */
67:
68: #ifndef _DEVICE_BPF_H_
69: #define _DEVICE_BPF_H_
70:
71: #if 0 /* not used in MK now */
72: /*
73: * Alignment macros. BPF_WORDALIGN rounds up to the next
74: * even multiple of BPF_ALIGNMENT.
75: */
76: #define BPF_ALIGNMENT sizeof(int)
77: #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
78:
79: /*
80: * Struct return by BIOCVERSION. This represents the version number of
81: * the filter language described by the instruction encodings below.
82: * bpf understands a program iff kernel_major == filter_major &&
83: * kernel_minor >= filter_minor, that is, if the value returned by the
84: * running kernel has the same major number and a minor number equal
85: * equal to or less than the filter being downloaded. Otherwise, the
86: * results are undefined, meaning an error may be returned or packets
87: * may be accepted haphazardly.
88: * It has nothing to do with the source code version.
89: */
90: struct bpf_version {
91: u_short bv_major;
92: u_short bv_minor;
93: };
94: /* Current version number. */
95: #define BPF_MAJOR_VERSION 1
96: #define BPF_MINOR_VERSION 1
97:
98: /*
99: * Data-link level type codes.
100: * Currently, only DLT_EN10MB and DLT_SLIP are supported.
101: */
102: #define DLT_NULL 0 /* no link-layer encapsulation */
103: #define DLT_EN10MB 1 /* Ethernet (10Mb) */
104: #define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
105: #define DLT_AX25 3 /* Amateur Radio AX.25 */
106: #define DLT_PRONET 4 /* Proteon ProNET Token Ring */
107: #define DLT_CHAOS 5 /* Chaos */
108: #define DLT_IEEE802 6 /* IEEE 802 Networks */
109: #define DLT_ARCNET 7 /* ARCNET */
110: #define DLT_SLIP 8 /* Serial Line IP */
111: #define DLT_PPP 9 /* Point-to-point Protocol */
112: #define DLT_FDDI 10 /* FDDI */
113:
114: #endif /* 0 */
115:
116: /*
117: * The instruction encondings.
118: */
119:
120: /* Magic number for the first instruction */
121: #define BPF_BEGIN NETF_BPF
122:
123: /* instruction classes */
124: #define BPF_CLASS(code) ((code) & 0x07)
125: #define BPF_LD 0x00
126: #define BPF_LDX 0x01
127: #define BPF_ST 0x02
128: #define BPF_STX 0x03
129: #define BPF_ALU 0x04
130: #define BPF_JMP 0x05
131: #define BPF_RET 0x06
132: #define BPF_MISC 0x07
133:
134: /* ld/ldx fields */
135: #define BPF_SIZE(code) ((code) & 0x18)
136: #define BPF_W 0x00
137: #define BPF_H 0x08
138: #define BPF_B 0x10
139: #define BPF_MODE(code) ((code) & 0xe0)
140: #define BPF_IMM 0x00
141: #define BPF_ABS 0x20
142: #define BPF_IND 0x40
143: #define BPF_MEM 0x60
144: #define BPF_LEN 0x80
145: #define BPF_MSH 0xa0
146:
147: /* alu/jmp fields */
148: #define BPF_OP(code) ((code) & 0xf0)
149: #define BPF_ADD 0x00
150: #define BPF_SUB 0x10
151: #define BPF_MUL 0x20
152: #define BPF_DIV 0x30
153: #define BPF_OR 0x40
154: #define BPF_AND 0x50
155: #define BPF_LSH 0x60
156: #define BPF_RSH 0x70
157: #define BPF_NEG 0x80
158: #define BPF_JA 0x00
159: #define BPF_JEQ 0x10
160: #define BPF_JGT 0x20
161: #define BPF_JGE 0x30
162: #define BPF_JSET 0x40
163: #define BPF_CKMATCH_IMM 0x50
164: #define BPF_SRC(code) ((code) & 0x08)
165: #define BPF_K 0x00
166: #define BPF_X 0x08
167:
168: /* ret - BPF_K and BPF_X also apply */
169: #define BPF_RVAL(code) ((code) & 0x38)
170: #define BPF_A 0x10
171: #define BPF_MATCH_IMM 0x18
172: #define BPF_MATCH_DATA 0x20
173:
174: /* misc */
175: #define BPF_MISCOP(code) ((code) & 0xf8)
176: #define BPF_TAX 0x00
177: #define BPF_TXA 0x80
178: #define BPF_KEY 0x10
179: #define BPF_REG_DATA 0x18
180: #define BPF_POSTPONE 0x20
181:
182: /*
183: * The instruction data structure.
184: */
185: struct bpf_insn {
186: unsigned short code;
187: unsigned char jt;
188: unsigned char jf;
189: int k;
190: };
191: typedef struct bpf_insn *bpf_insn_t;
192:
193: /*
194: * largest bpf program size
195: */
196: #define NET_MAX_BPF ((NET_MAX_FILTER*sizeof(filter_t))/sizeof(struct bpf_insn))
197:
198: /*
199: * Macros for insn array initializers.
200: */
201: #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
202: #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
203: #define BPF_RETMATCH(code, k, nkey) { (unsigned short)(code), nkey, 0, k }
204:
205: #define BPF_INSN_STMT(pc, c, n) {\
206: (pc)->code = (c); \
207: (pc)->jt = (pc)->jf = 0; \
208: (pc)->k = (n); \
209: (pc)++; \
210: }
211:
212: #define BPF_INSN_JUMP(pc, c, n, jtrue, jfalse) {\
213: (pc)->code = (c); \
214: (pc)->jt = (jtrue); \
215: (pc)->jf = (jfalse); \
216: (pc)->k = (n); \
217: (pc)++; \
218: }
219:
220: #define BPF_INSN_RETMATCH(pc, c, n, nkey) {\
221: (pc)->code = (c); \
222: (pc)->jt = (nkey); \
223: (pc)->jf = 0; \
224: (pc)->k = (n); \
225: (pc)++; \
226: }
227:
228: /*
229: * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
230: */
231: #define BPF_MEMWORDS 16
232:
233: /*
234: * Link level header can be accessed by adding BPF_DLBASE to an offset.
235: */
236: #define BPF_DLBASE (1<<30)
237:
238: #define BPF_BYTES(n) ((n) * sizeof (struct bpf_insn))
239: #define BPF_BYTES2LEN(n) ((n) / sizeof (struct bpf_insn))
240: #define BPF_INSN_EQ(p,q) ((p)->code == (q)->code && \
241: (p)->jt == (q)->jt && \
242: (p)->jf == (q)->jf && \
243: (p)->k == (q)->k)
244:
245: #endif /* _DEVICE_BPF_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.