]> git.saurik.com Git - apple/network_cmds.git/blob - pcap/gencode.h
network_cmds-76.tar.gz
[apple/network_cmds.git] / pcap / gencode.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /* $OpenBSD: gencode.h,v 1.4 1996/07/12 13:19:08 mickey Exp $ */
25
26 /*
27 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
28 * The Regents of the University of California. All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that: (1) source code distributions
32 * retain the above copyright notice and this paragraph in its entirety, (2)
33 * distributions including binary code include the above copyright notice and
34 * this paragraph in its entirety in the documentation or other materials
35 * provided with the distribution, and (3) all advertising materials mentioning
36 * features or use of this software display the following acknowledgement:
37 * ``This product includes software developed by the University of California,
38 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
39 * the University nor the names of its contributors may be used to endorse
40 * or promote products derived from this software without specific prior
41 * written permission.
42 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
43 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
44 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
45 *
46 * @(#) Header: gencode.h,v 1.33 96/06/23 02:21:09 leres Exp (LBL)
47 */
48
49 /* Address qualifiers. */
50
51 #define Q_HOST 1
52 #define Q_NET 2
53 #define Q_PORT 3
54 #define Q_GATEWAY 4
55 #define Q_PROTO 5
56
57 /* Protocol qualifiers. */
58
59 #define Q_LINK 1
60 #define Q_IP 2
61 #define Q_ARP 3
62 #define Q_RARP 4
63 #define Q_TCP 5
64 #define Q_UDP 6
65 #define Q_ICMP 7
66 #define Q_IGMP 8
67
68 #define Q_DECNET 9
69 #define Q_LAT 10
70 #define Q_MOPRC 11
71 #define Q_MOPDL 12
72
73 /* Directional qualifiers. */
74
75 #define Q_SRC 1
76 #define Q_DST 2
77 #define Q_OR 3
78 #define Q_AND 4
79
80 #define Q_DEFAULT 0
81 #define Q_UNDEF 255
82
83 struct stmt {
84 int code;
85 bpf_int32 k;
86 };
87
88 struct slist {
89 struct stmt s;
90 struct slist *next;
91 };
92
93 /*
94 * A bit vector to represent definition sets. We assume TOT_REGISTERS
95 * is smaller than 8*sizeof(atomset).
96 */
97 typedef bpf_u_int32 atomset;
98 #define ATOMMASK(n) (1 << (n))
99 #define ATOMELEM(d, n) (d & ATOMMASK(n))
100
101 /*
102 * An unbounded set.
103 */
104 typedef bpf_u_int32 *uset;
105
106 /*
107 * Total number of atomic entities, including accumulator (A) and index (X).
108 * We treat all these guys similarly during flow analysis.
109 */
110 #define N_ATOMS (BPF_MEMWORDS+2)
111
112 struct edge {
113 int id;
114 int code;
115 uset edom;
116 struct block *succ;
117 struct block *pred;
118 struct edge *next; /* link list of incoming edges for a node */
119 };
120
121 struct block {
122 int id;
123 struct slist *stmts; /* side effect stmts */
124 struct stmt s; /* branch stmt */
125 int mark;
126 int longjt; /* jt branch requires long jump */
127 int longjf; /* jf branch requires long jump */
128 int level;
129 int offset;
130 int sense;
131 struct edge et;
132 struct edge ef;
133 struct block *head;
134 struct block *link; /* link field used by optimizer */
135 uset dom;
136 uset closure;
137 struct edge *in_edges;
138 atomset def, kill;
139 atomset in_use;
140 atomset out_use;
141 int oval;
142 int val[N_ATOMS];
143 };
144
145 struct arth {
146 struct block *b; /* protocol checks */
147 struct slist *s; /* stmt list */
148 int regno; /* virtual register number of result */
149 };
150
151 struct qual {
152 unsigned char addr;
153 unsigned char proto;
154 unsigned char dir;
155 unsigned char pad;
156 };
157
158 struct arth *gen_loadi(int);
159 struct arth *gen_load(int, struct arth *, int);
160 struct arth *gen_loadlen(void);
161 struct arth *gen_neg(struct arth *);
162 struct arth *gen_arth(int, struct arth *, struct arth *);
163
164 void gen_and(struct block *, struct block *);
165 void gen_or(struct block *, struct block *);
166 void gen_not(struct block *);
167
168 struct block *gen_scode(char *, struct qual);
169 struct block *gen_ecode(u_char *, struct qual);
170 struct block *gen_ncode(bpf_u_int32, struct qual);
171 struct block *gen_proto_abbrev(int);
172 struct block *gen_relation(int, struct arth *, struct arth *, int);
173 struct block *gen_less(int);
174 struct block *gen_greater(int);
175 struct block *gen_byteop(int, int, int);
176 struct block *gen_broadcast(int);
177 struct block *gen_multicast(int);
178 struct block *gen_inbound(int);
179
180 void bpf_optimize(struct block **);
181 #if __STDC__
182 __dead void bpf_error(const char *, ...)
183 __attribute__((volatile, format (printf, 1, 2)));
184 #endif
185
186 void finish_parse(struct block *);
187 char *sdup(char *);
188
189 struct bpf_insn *icode_to_fcode(struct block *, int *);
190 int pcap_parse(void);
191 void lex_init(char *);
192 void sappend(struct slist *, struct slist *);
193
194 /* XXX */
195 #define JT(b) ((b)->et.succ)
196 #define JF(b) ((b)->ef.succ)