]> The Tcpdump Group git mirrors - libpcap/blob - gencode.h
ARCNet support, from NetBSD.
[libpcap] / gencode.h
1 /*
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.52 2001-04-17 08:25:22 guy Exp $ (LBL)
22 */
23
24 /* Address qualifiers. */
25
26 #define Q_HOST 1
27 #define Q_NET 2
28 #define Q_PORT 3
29 #define Q_GATEWAY 4
30 #define Q_PROTO 5
31 #define Q_PROTOCHAIN 6
32
33 /* Protocol qualifiers. */
34
35 #define Q_LINK 1
36 #define Q_IP 2
37 #define Q_ARP 3
38 #define Q_RARP 4
39 #define Q_TCP 5
40 #define Q_UDP 6
41 #define Q_ICMP 7
42 #define Q_IGMP 8
43 #define Q_IGRP 9
44
45
46 #define Q_ATALK 10
47 #define Q_DECNET 11
48 #define Q_LAT 12
49 #define Q_SCA 13
50 #define Q_MOPRC 14
51 #define Q_MOPDL 15
52
53
54 #define Q_IPV6 16
55 #define Q_ICMPV6 17
56 #define Q_AH 18
57 #define Q_ESP 19
58
59 #define Q_PIM 20
60 #define Q_VRRP 21
61
62 #define Q_AARP 22
63
64 #define Q_ISO 23
65 #define Q_ESIS 24
66 #define Q_ISIS 25
67 #define Q_CLNP 26
68
69 #define Q_STP 27
70
71 #define Q_IPX 28
72
73 #define Q_NETBEUI 29
74
75 /* Directional qualifiers. */
76
77 #define Q_SRC 1
78 #define Q_DST 2
79 #define Q_OR 3
80 #define Q_AND 4
81
82 #define Q_DEFAULT 0
83 #define Q_UNDEF 255
84
85 struct slist;
86
87 struct stmt {
88 int code;
89 struct slist *jt; /*only for relative jump in block*/
90 struct slist *jf; /*only for relative jump in block*/
91 bpf_int32 k;
92 };
93
94 struct slist {
95 struct stmt s;
96 struct slist *next;
97 };
98
99 /*
100 * A bit vector to represent definition sets. We assume TOT_REGISTERS
101 * is smaller than 8*sizeof(atomset).
102 */
103 typedef bpf_u_int32 atomset;
104 #define ATOMMASK(n) (1 << (n))
105 #define ATOMELEM(d, n) (d & ATOMMASK(n))
106
107 /*
108 * An unbounded set.
109 */
110 typedef bpf_u_int32 *uset;
111
112 /*
113 * Total number of atomic entities, including accumulator (A) and index (X).
114 * We treat all these guys similarly during flow analysis.
115 */
116 #define N_ATOMS (BPF_MEMWORDS+2)
117
118 struct edge {
119 int id;
120 int code;
121 uset edom;
122 struct block *succ;
123 struct block *pred;
124 struct edge *next; /* link list of incoming edges for a node */
125 };
126
127 struct block {
128 int id;
129 struct slist *stmts; /* side effect stmts */
130 struct stmt s; /* branch stmt */
131 int mark;
132 int longjt; /* jt branch requires long jump */
133 int longjf; /* jf branch requires long jump */
134 int level;
135 int offset;
136 int sense;
137 struct edge et;
138 struct edge ef;
139 struct block *head;
140 struct block *link; /* link field used by optimizer */
141 uset dom;
142 uset closure;
143 struct edge *in_edges;
144 atomset def, kill;
145 atomset in_use;
146 atomset out_use;
147 int oval;
148 int val[N_ATOMS];
149 };
150
151 struct arth {
152 struct block *b; /* protocol checks */
153 struct slist *s; /* stmt list */
154 int regno; /* virtual register number of result */
155 };
156
157 struct qual {
158 unsigned char addr;
159 unsigned char proto;
160 unsigned char dir;
161 unsigned char pad;
162 };
163
164 struct arth *gen_loadi(int);
165 struct arth *gen_load(int, struct arth *, int);
166 struct arth *gen_loadlen(void);
167 struct arth *gen_neg(struct arth *);
168 struct arth *gen_arth(int, struct arth *, struct arth *);
169
170 void gen_and(struct block *, struct block *);
171 void gen_or(struct block *, struct block *);
172 void gen_not(struct block *);
173
174 struct block *gen_scode(const char *, struct qual);
175 struct block *gen_ecode(const u_char *, struct qual);
176 struct block *gen_acode(const u_char *, struct qual);
177 struct block *gen_mcode(const char *, const char *, int, struct qual);
178 #ifdef INET6
179 struct block *gen_mcode6(const char *, const char *, int, struct qual);
180 #endif
181 struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
182 struct block *gen_proto_abbrev(int);
183 struct block *gen_relation(int, struct arth *, struct arth *, int);
184 struct block *gen_less(int);
185 struct block *gen_greater(int);
186 struct block *gen_byteop(int, int, int);
187 struct block *gen_broadcast(int);
188 struct block *gen_multicast(int);
189 struct block *gen_inbound(int);
190
191 struct block *gen_vlan(int);
192
193 void bpf_optimize(struct block **);
194 void bpf_error(const char *, ...)
195 #if HAVE___ATTRIBUTE__
196 __attribute__((noreturn, format (printf, 1, 2)))
197 #endif
198 ;
199
200 void finish_parse(struct block *);
201 char *sdup(const char *);
202
203 struct bpf_insn *icode_to_fcode(struct block *, int *);
204 int pcap_parse(void);
205 void lex_init(char *);
206 void lex_cleanup(void);
207 void sappend(struct slist *, struct slist *);
208
209 /* XXX */
210 #define JT(b) ((b)->et.succ)
211 #define JF(b) ((b)->ef.succ)
212
213 extern int no_optimize;