Uh oh!
There was an error while loading. Please reload this page.
forked from the-tcpdump-group/libpcap
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgencode.h
More file actions
Latest commit
416 lines (352 loc) · 12.7 KB
/
Copy pathgencode.h
File metadata and controls
416 lines (352 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndefgencode_h
#definegencode_h
#include"pcap/funcattrs.h"
/*
* pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be
* made available via either pcap-types.h (a private header) or pcap/pcap.h
* (a public header), none of which pcap/bpf.h includes. Include the private
* header to keep things simple, this way this private header should compile
* even if included early from another file.
*/
#include"pcap-types.h"
#include"pcap/bpf.h"/* bpf_u_int32 and BPF_MEMWORDS */
/*
* ATM support:
*
* Copyright (c) 1997 Yen Yen Lim and North Dakota State University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Yen Yen Lim and
* North Dakota State University
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Address qualifiers. */
#defineQ_HOST 1
#defineQ_NET 2
#defineQ_PORT 3
#defineQ_GATEWAY 4
#defineQ_PROTO 5
#defineQ_PROTOCHAIN 6
#defineQ_PORTRANGE 7
/* Protocol qualifiers. */
#defineQ_LINK 1
#defineQ_IP 2
#defineQ_ARP 3
#defineQ_RARP 4
#defineQ_SCTP 5
#defineQ_TCP 6
#defineQ_UDP 7
#defineQ_ICMP 8
#defineQ_IGMP 9
#defineQ_IGRP 10
#defineQ_ATALK 11
#defineQ_DECNET 12
#defineQ_LAT 13
#defineQ_SCA 14
#defineQ_MOPRC 15
#defineQ_MOPDL 16
#defineQ_IPV6 17
#defineQ_ICMPV6 18
#defineQ_AH 19
#defineQ_ESP 20
#defineQ_PIM 21
#defineQ_VRRP 22
#defineQ_AARP 23
#defineQ_ISO 24
#defineQ_ESIS 25
#defineQ_ISIS 26
#defineQ_CLNP 27
#defineQ_STP 28
#defineQ_IPX 29
#defineQ_NETBEUI 30
/* IS-IS Levels */
#defineQ_ISIS_L1 31
#defineQ_ISIS_L2 32
/* PDU types */
#defineQ_ISIS_IIH 33
#defineQ_ISIS_SNP 34
#defineQ_ISIS_CSNP 35
#defineQ_ISIS_PSNP 36
#defineQ_ISIS_LSP 37
#defineQ_RADIO 38
#defineQ_CARP 39
/* Directional qualifiers. */
#defineQ_SRC 1
#defineQ_DST 2
#defineQ_OR 3
#defineQ_AND 4
#defineQ_ADDR1 5
#defineQ_ADDR2 6
#defineQ_ADDR3 7
#defineQ_ADDR4 8
#defineQ_RA 9
#defineQ_TA 10
#defineQ_DEFAULT 0
#defineQ_UNDEF 255
/* ATM types */
#defineA_METAC 22 /* Meta signalling Circuit */
#defineA_BCC 23 /* Broadcast Circuit */
#defineA_OAMF4SC 24 /* Segment OAM F4 Circuit */
#defineA_OAMF4EC 25 /* End-to-End OAM F4 Circuit */
#defineA_SC 26 /* Signalling Circuit*/
#defineA_ILMIC 27 /* ILMI Circuit */
#defineA_OAM 28 /* OAM cells : F4 only */
#defineA_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */
#defineA_LANE 30 /* LANE traffic */
#defineA_LLC 31 /* LLC-encapsulated traffic */
/* Based on Q.2931 signalling protocol */
#defineA_SETUP 41 /* Setup message */
#defineA_CALLPROCEED 42 /* Call proceeding message */
#defineA_CONNECT 43 /* Connect message */
#defineA_CONNECTACK 44 /* Connect Ack message */
#defineA_RELEASE 45 /* Release message */
#defineA_RELEASE_DONE 46 /* Release message */
/* ATM field types */
#defineA_VPI 51
#defineA_VCI 52
#defineA_PROTOTYPE 53
#defineA_MSGTYPE 54
#defineA_CALLREFTYPE 55
#defineA_CONNECTMSG 70 /* returns Q.2931 signalling messages for
establishing and destroying switched
virtual connection */
#defineA_METACONNECT 71 /* returns Q.2931 signalling messages for
establishing and destroying predefined
virtual circuits, such as broadcast
circuit, oamf4 segment circuit, oamf4
end-to-end circuits, ILMI circuits or
connection signalling circuit. */
/* MTP2 types */
#defineM_FISU 22 /* FISU */
#defineM_LSSU 23 /* LSSU */
#defineM_MSU 24 /* MSU */
/* MTP2 HSL types */
#defineMH_FISU 25 /* FISU for HSL */
#defineMH_LSSU 26 /* LSSU */
#defineMH_MSU 27 /* MSU */
/* MTP3 field types */
#defineM_SIO 1
#defineM_OPC 2
#defineM_DPC 3
#defineM_SLS 4
/* MTP3 field types in case of MTP2 HSL */
#defineMH_SIO 5
#defineMH_OPC 6
#defineMH_DPC 7
#defineMH_SLS 8
structslist;
/*
* A single statement, corresponding to an instruction in a block.
*/
structstmt {
intcode; /* opcode */
structslist*jt; /* only for relative jump in block */
structslist*jf; /* only for relative jump in block */
bpf_u_int32k; /* k field */
};
structslist {
structstmts;
structslist*next;
};
/*
* A bit vector to represent definition sets. We assume TOT_REGISTERS
* is smaller than 8*sizeof(atomset).
*/
typedefbpf_u_int32atomset;
#defineATOMMASK(n) (1 << (n))
#defineATOMELEM(d, n) (d & ATOMMASK(n))
/*
* An unbounded set.
*/
typedefbpf_u_int32*uset;
/*
* Total number of atomic entities, including accumulator (A) and index (X).
* We treat all these guys similarly during flow analysis.
*/
#defineN_ATOMS (BPF_MEMWORDS+2)
/*
* Control flow graph of a program.
* This corresponds to an edge in the CFG.
* It's a directed graph, so an edge has a predecessor and a successor.
*/
structedge {
u_intid;
intcode; /* opcode for branch corresponding to this edge */
usetedom;
structblock*succ; /* successor vertex */
structblock*pred; /* predecessor vertex */
structedge*next; /* link list of incoming edges for a node */
};
/*
* A block is a vertex in the CFG.
* It has a list of statements, with the final statement being a
* branch to successor blocks.
*/
structblock {
u_intid;
structslist*stmts; /* side effect stmts */
structstmts; /* branch stmt */
intmark;
u_intlongjt; /* jt branch requires long jump */
u_intlongjf; /* jf branch requires long jump */
intlevel;
intoffset;
intsense;
structedgeet; /* edge corresponding to the jt branch */
structedgeef; /* edge corresponding to the jf branch */
structblock*head;
structblock*link; /* link field used by optimizer */
usetdom;
usetclosure;
structedge*in_edges; /* first edge in the set (linked list) of edges with this as a successor */
atomsetdef, kill;
atomsetin_use;
atomsetout_use;
intoval; /* value ID for value tested in branch stmt */
bpf_u_int32val[N_ATOMS];
};
/*
* A value of 0 for val[i] means the value is unknown.
*/
#defineVAL_UNKNOWN 0
structarth {
structblock*b; /* protocol checks */
structslist*s; /* stmt list */
intregno; /* virtual register number of result */
};
structqual {
unsigned charaddr;
unsigned charproto;
unsigned chardir;
unsigned charpad;
};
struct_compiler_state;
typedefstruct_compiler_statecompiler_state_t;
structarth*gen_loadi(compiler_state_t*, bpf_u_int32);
structarth*gen_load(compiler_state_t*, int, structarth*, bpf_u_int32);
structarth*gen_loadlen(compiler_state_t*);
structarth*gen_neg(compiler_state_t*, structarth*);
structarth*gen_arth(compiler_state_t*, int, structarth*, structarth*);
voidgen_and(structblock*, structblock*);
voidgen_or(structblock*, structblock*);
voidgen_not(structblock*);
structblock*gen_scode(compiler_state_t*, constchar*, structqual);
structblock*gen_ecode(compiler_state_t*, constchar*, structqual);
structblock*gen_acode(compiler_state_t*, constchar*, structqual);
structblock*gen_mcode(compiler_state_t*, constchar*, constchar*,
bpf_u_int32, structqual);
#ifdefINET6
structblock*gen_mcode6(compiler_state_t*, constchar*, constchar*,
bpf_u_int32, structqual);
#endif
structblock*gen_ncode(compiler_state_t*, constchar*, bpf_u_int32,
structqual);
structblock*gen_proto_abbrev(compiler_state_t*, int);
structblock*gen_relation(compiler_state_t*, int, structarth*,
structarth*, int);
structblock*gen_less(compiler_state_t*, int);
structblock*gen_greater(compiler_state_t*, int);
structblock*gen_byteop(compiler_state_t*, int, int, bpf_u_int32);
structblock*gen_broadcast(compiler_state_t*, int);
structblock*gen_multicast(compiler_state_t*, int);
structblock*gen_ifindex(compiler_state_t*, int);
structblock*gen_inbound(compiler_state_t*, int);
structblock*gen_llc(compiler_state_t*);
structblock*gen_llc_i(compiler_state_t*);
structblock*gen_llc_s(compiler_state_t*);
structblock*gen_llc_u(compiler_state_t*);
structblock*gen_llc_s_subtype(compiler_state_t*, bpf_u_int32);
structblock*gen_llc_u_subtype(compiler_state_t*, bpf_u_int32);
structblock*gen_vlan(compiler_state_t*, bpf_u_int32, int);
structblock*gen_mpls(compiler_state_t*, bpf_u_int32, int);
structblock*gen_pppoed(compiler_state_t*);
structblock*gen_pppoes(compiler_state_t*, bpf_u_int32, int);
structblock*gen_geneve(compiler_state_t*, bpf_u_int32, int);
structblock*gen_atmfield_code(compiler_state_t*, int, bpf_u_int32,
int, int);
structblock*gen_atmtype_abbrev(compiler_state_t*, int);
structblock*gen_atmmulti_abbrev(compiler_state_t*, int);
structblock*gen_mtp2type_abbrev(compiler_state_t*, int);
structblock*gen_mtp3field_code(compiler_state_t*, int, bpf_u_int32,
int, int);
structblock*gen_pf_ifname(compiler_state_t*, constchar*);
structblock*gen_pf_rnr(compiler_state_t*, int);
structblock*gen_pf_srnr(compiler_state_t*, int);
structblock*gen_pf_ruleset(compiler_state_t*, char*);
structblock*gen_pf_reason(compiler_state_t*, int);
structblock*gen_pf_action(compiler_state_t*, int);
structblock*gen_p80211_type(compiler_state_t*, bpf_u_int32, bpf_u_int32);
structblock*gen_p80211_fcdir(compiler_state_t*, bpf_u_int32);
/*
* Representation of a program as a tree of blocks, plus current mark.
* A block is marked if only if its mark equals the current mark.
* Rather than traverse the code array, marking each item, 'cur_mark'
* is incremented. This automatically makes each element unmarked.
*/
#defineisMarked(icp, p) ((p)->mark == (icp)->cur_mark)
#defineunMarkAll(icp) (icp)->cur_mark += 1
#defineMark(icp, p) ((p)->mark = (icp)->cur_mark)
structicode {
structblock*root;
intcur_mark;
};
intbpf_optimize(structicode*, char*);
voidbpf_set_error(compiler_state_t*, constchar*, ...)
PCAP_PRINTFLIKE(2, 3);
intfinish_parse(compiler_state_t*, structblock*);
char*sdup(compiler_state_t*, constchar*);
structbpf_insn*icode_to_fcode(structicode*, structblock*, u_int*,
char*);
voidsappend(structslist*, structslist*);
/*
* Older versions of Bison don't put this declaration in
* grammar.h.
*/
intpcap_parse(void*, compiler_state_t*);
/* XXX */
#defineJT(b) ((b)->et.succ)
#defineJF(b) ((b)->ef.succ)
#endif/* gencode_h */