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