]> git.ozlabs.org Git - ppp.git/blob - include/net/bpf.h
updated
[ppp.git] / include / net / bpf.h
1 /*      From: NetBSD: bpf.h,v 1.12 1995/09/27 18:30:40 thorpej Exp */
2
3 /*
4  * Copyright (c) 1990, 1991, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from the Stanford/CMU enet packet filter,
8  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10  * Berkeley Laboratory.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *      This product includes software developed by the University of
23  *      California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *      @(#)bpf.h       8.1 (Berkeley) 6/10/93
41  */
42
43 #ifndef _NET_BPF_H_
44 #define _NET_BPF_H_
45
46 /*
47  * Alignment macros.  BPF_WORDALIGN rounds up to the next 
48  * even multiple of BPF_ALIGNMENT. 
49  */
50 #define BPF_ALIGNMENT sizeof(long)
51 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
52
53 #define BPF_MAXINSNS 512
54 #define BPF_MAXBUFSIZE 0x8000
55 #define BPF_MINBUFSIZE 32
56
57 /*
58  *  Structure for BIOCSETF.
59  */
60 struct bpf_program {
61         unsigned int bf_len;
62         struct bpf_insn *bf_insns;
63 };
64
65 /*
66  * The instruction encondings.
67  */
68 /* instruction classes */
69 #define BPF_CLASS(code) ((code) & 0x07)
70 #define         BPF_LD          0x00
71 #define         BPF_LDX         0x01
72 #define         BPF_ST          0x02
73 #define         BPF_STX         0x03
74 #define         BPF_ALU         0x04
75 #define         BPF_JMP         0x05
76 #define         BPF_RET         0x06
77 #define         BPF_MISC        0x07
78
79 /* ld/ldx fields */
80 #define BPF_SIZE(code)  ((code) & 0x18)
81 #define         BPF_W           0x00
82 #define         BPF_H           0x08
83 #define         BPF_B           0x10
84 #define BPF_MODE(code)  ((code) & 0xe0)
85 #define         BPF_IMM         0x00
86 #define         BPF_ABS         0x20
87 #define         BPF_IND         0x40
88 #define         BPF_MEM         0x60
89 #define         BPF_LEN         0x80
90 #define         BPF_MSH         0xa0
91
92 /* alu/jmp fields */
93 #define BPF_OP(code)    ((code) & 0xf0)
94 #define         BPF_ADD         0x00
95 #define         BPF_SUB         0x10
96 #define         BPF_MUL         0x20
97 #define         BPF_DIV         0x30
98 #define         BPF_OR          0x40
99 #define         BPF_AND         0x50
100 #define         BPF_LSH         0x60
101 #define         BPF_RSH         0x70
102 #define         BPF_NEG         0x80
103 #define         BPF_JA          0x00
104 #define         BPF_JEQ         0x10
105 #define         BPF_JGT         0x20
106 #define         BPF_JGE         0x30
107 #define         BPF_JSET        0x40
108 #define BPF_SRC(code)   ((code) & 0x08)
109 #define         BPF_K           0x00
110 #define         BPF_X           0x08
111
112 /* ret - BPF_K and BPF_X also apply */
113 #define BPF_RVAL(code)  ((code) & 0x18)
114 #define         BPF_A           0x10
115
116 /* misc */
117 #define BPF_MISCOP(code) ((code) & 0xf8)
118 #define         BPF_TAX         0x00
119 #define         BPF_TXA         0x80
120
121 /*
122  * The instruction data structure.
123  */
124 struct bpf_insn {
125         unsigned short  code;
126         unsigned char   jt;
127         unsigned char   jf;
128         int             k;
129 };
130
131 /*
132  * Macros for insn array initializers.
133  */
134 #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
135 #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
136
137 #ifdef _KERNEL
138 int      bpf_validate __P((struct bpf_insn *, int));
139 u_int    bpf_filter __P((struct bpf_insn *, u_char *, u_int, u_int));
140 #endif
141
142 /*
143  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
144  */
145 #define BPF_MEMWORDS 16
146
147 #endif /* _NET_BPF_H_ */