]> The Tcpdump Group git mirrors - libpcap/blob - gencode.h
(bpf_error): conditionalize __attribute__
[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.38 2000-04-01 12:27:28 assar Exp $ (LBL)
22 */
23
24 /*XXX*/
25 #include "gnuc.h"
26
27 /* Address qualifiers. */
28
29 #define Q_HOST 1
30 #define Q_NET 2
31 #define Q_PORT 3
32 #define Q_GATEWAY 4
33 #define Q_PROTO 5
34 #define Q_PROTOCHAIN 6
35
36 /* Protocol qualifiers. */
37
38 #define Q_LINK 1
39 #define Q_IP 2
40 #define Q_ARP 3
41 #define Q_RARP 4
42 #define Q_TCP 5
43 #define Q_UDP 6
44 #define Q_ICMP 7
45 #define Q_IGMP 8
46 #define Q_IGRP 9
47
48
49 #define Q_ATALK 10
50 #define Q_DECNET 11
51 #define Q_LAT 12
52 #define Q_SCA 13
53 #define Q_MOPRC 14
54 #define Q_MOPDL 15
55
56
57 #define Q_IPV6 16
58 #define Q_ICMPV6 17
59 #define Q_AH 18
60 #define Q_ESP 19
61
62 #define Q_PIM 20
63
64 /* Directional qualifiers. */
65
66 #define Q_SRC 1
67 #define Q_DST 2
68 #define Q_OR 3
69 #define Q_AND 4
70
71 #define Q_DEFAULT 0
72 #define Q_UNDEF 255
73
74 struct slist;
75
76 struct stmt {
77 int code;
78 struct slist *jt; /*only for relative jump in block*/
79 struct slist *jf; /*only for relative jump in block*/
80 bpf_int32 k;
81 };
82
83 struct slist {
84 struct stmt s;
85 struct slist *next;
86 };
87
88 /*
89 * A bit vector to represent definition sets. We assume TOT_REGISTERS
90 * is smaller than 8*sizeof(atomset).
91 */
92 typedef bpf_u_int32 atomset;
93 #define ATOMMASK(n) (1 << (n))
94 #define ATOMELEM(d, n) (d & ATOMMASK(n))
95
96 /*
97 * An unbounded set.
98 */
99 typedef bpf_u_int32 *uset;
100
101 /*
102 * Total number of atomic entities, including accumulator (A) and index (X).
103 * We treat all these guys similarly during flow analysis.
104 */
105 #define N_ATOMS (BPF_MEMWORDS+2)
106
107 struct edge {
108 int id;
109 int code;
110 uset edom;
111 struct block *succ;
112 struct block *pred;
113 struct edge *next; /* link list of incoming edges for a node */
114 };
115
116 struct block {
117 int id;
118 struct slist *stmts; /* side effect stmts */
119 struct stmt s; /* branch stmt */
120 int mark;
121 int longjt; /* jt branch requires long jump */
122 int longjf; /* jf branch requires long jump */
123 int level;
124 int offset;
125 int sense;
126 struct edge et;
127 struct edge ef;
128 struct block *head;
129 struct block *link; /* link field used by optimizer */
130 uset dom;
131 uset closure;
132 struct edge *in_edges;
133 atomset def, kill;
134 atomset in_use;
135 atomset out_use;
136 int oval;
137 int val[N_ATOMS];
138 };
139
140 struct arth {
141 struct block *b; /* protocol checks */
142 struct slist *s; /* stmt list */
143 int regno; /* virtual register number of result */
144 };
145
146 struct qual {
147 unsigned char addr;
148 unsigned char proto;
149 unsigned char dir;
150 unsigned char pad;
151 };
152
153 struct arth *gen_loadi(int);
154 struct arth *gen_load(int, struct arth *, int);
155 struct arth *gen_loadlen(void);
156 struct arth *gen_neg(struct arth *);
157 struct arth *gen_arth(int, struct arth *, struct arth *);
158
159 void gen_and(struct block *, struct block *);
160 void gen_or(struct block *, struct block *);
161 void gen_not(struct block *);
162
163 struct block *gen_scode(const char *, struct qual);
164 struct block *gen_ecode(const u_char *, struct qual);
165 struct block *gen_mcode(const char *, const char *, int, struct qual);
166 #ifdef INET6
167 struct block *gen_mcode6(const char *, const char *, int, struct qual);
168 #endif
169 struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
170 struct block *gen_proto_abbrev(int);
171 struct block *gen_relation(int, struct arth *, struct arth *, int);
172 struct block *gen_less(int);
173 struct block *gen_greater(int);
174 struct block *gen_byteop(int, int, int);
175 struct block *gen_broadcast(int);
176 struct block *gen_multicast(int);
177 struct block *gen_inbound(int);
178
179 void bpf_optimize(struct block **);
180 #if __STDC__
181 __dead void bpf_error(const char *, ...)
182 #if HAVE___ATTRIBUTE__
183 __attribute__((volatile, format (printf, 1, 2)))
184 #endif
185 ;
186 #endif
187
188 void finish_parse(struct block *);
189 char *sdup(const char *);
190
191 struct bpf_insn *icode_to_fcode(struct block *, int *);
192 int pcap_parse(void);
193 void lex_init(char *);
194 void sappend(struct slist *, struct slist *);
195
196 /* XXX */
197 #define JT(b) ((b)->et.succ)
198 #define JF(b) ((b)->ef.succ)
199
200 extern int no_optimize;