]> The Tcpdump Group git mirrors - libpcap/blob - gencode.h
Support checking for protocols specified by an LLC SAP on FDDI, Token
[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.48 2001-01-14 04:34:51 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
61 #define Q_AARP 21
62
63 #define Q_ISO 22
64 #define Q_ESIS 23
65 #define Q_ISIS 24
66 #define Q_CLNP 25
67
68 #define Q_STP 26
69
70 /* Directional qualifiers. */
71
72 #define Q_SRC 1
73 #define Q_DST 2
74 #define Q_OR 3
75 #define Q_AND 4
76
77 #define Q_DEFAULT 0
78 #define Q_UNDEF 255
79
80 struct slist;
81
82 struct stmt {
83 int code;
84 struct slist *jt; /*only for relative jump in block*/
85 struct slist *jf; /*only for relative jump in block*/
86 bpf_int32 k;
87 };
88
89 struct slist {
90 struct stmt s;
91 struct slist *next;
92 };
93
94 /*
95 * A bit vector to represent definition sets. We assume TOT_REGISTERS
96 * is smaller than 8*sizeof(atomset).
97 */
98 typedef bpf_u_int32 atomset;
99 #define ATOMMASK(n) (1 << (n))
100 #define ATOMELEM(d, n) (d & ATOMMASK(n))
101
102 /*
103 * An unbounded set.
104 */
105 typedef bpf_u_int32 *uset;
106
107 /*
108 * Total number of atomic entities, including accumulator (A) and index (X).
109 * We treat all these guys similarly during flow analysis.
110 */
111 #define N_ATOMS (BPF_MEMWORDS+2)
112
113 struct edge {
114 int id;
115 int code;
116 uset edom;
117 struct block *succ;
118 struct block *pred;
119 struct edge *next; /* link list of incoming edges for a node */
120 };
121
122 struct block {
123 int id;
124 struct slist *stmts; /* side effect stmts */
125 struct stmt s; /* branch stmt */
126 int mark;
127 int longjt; /* jt branch requires long jump */
128 int longjf; /* jf branch requires long jump */
129 int level;
130 int offset;
131 int sense;
132 struct edge et;
133 struct edge ef;
134 struct block *head;
135 struct block *link; /* link field used by optimizer */
136 uset dom;
137 uset closure;
138 struct edge *in_edges;
139 atomset def, kill;
140 atomset in_use;
141 atomset out_use;
142 int oval;
143 int val[N_ATOMS];
144 };
145
146 struct arth {
147 struct block *b; /* protocol checks */
148 struct slist *s; /* stmt list */
149 int regno; /* virtual register number of result */
150 };
151
152 struct qual {
153 unsigned char addr;
154 unsigned char proto;
155 unsigned char dir;
156 unsigned char pad;
157 };
158
159 struct arth *gen_loadi(int);
160 struct arth *gen_load(int, struct arth *, int);
161 struct arth *gen_loadlen(void);
162 struct arth *gen_neg(struct arth *);
163 struct arth *gen_arth(int, struct arth *, struct arth *);
164
165 void gen_and(struct block *, struct block *);
166 void gen_or(struct block *, struct block *);
167 void gen_not(struct block *);
168
169 struct block *gen_scode(const char *, struct qual);
170 struct block *gen_ecode(const u_char *, struct qual);
171 struct block *gen_mcode(const char *, const char *, int, struct qual);
172 #ifdef INET6
173 struct block *gen_mcode6(const char *, const char *, int, struct qual);
174 #endif
175 struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
176 struct block *gen_proto_abbrev(int);
177 struct block *gen_relation(int, struct arth *, struct arth *, int);
178 struct block *gen_less(int);
179 struct block *gen_greater(int);
180 struct block *gen_byteop(int, int, int);
181 struct block *gen_broadcast(int);
182 struct block *gen_multicast(int);
183 struct block *gen_inbound(int);
184
185 struct block *gen_vlan(int);
186
187 void bpf_optimize(struct block **);
188 void bpf_error(const char *, ...)
189 #if HAVE___ATTRIBUTE__
190 __attribute__((noreturn, format (printf, 1, 2)))
191 #endif
192 ;
193
194 void finish_parse(struct block *);
195 char *sdup(const char *);
196
197 struct bpf_insn *icode_to_fcode(struct block *, int *);
198 int pcap_parse(void);
199 void lex_init(char *);
200 void lex_cleanup(void);
201 void sappend(struct slist *, struct slist *);
202
203 /* XXX */
204 #define JT(b) ((b)->et.succ)
205 #define JF(b) ((b)->ef.succ)
206
207 extern int no_optimize;