Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 199 lines (167 sloc) 5.042 kb
b11ddf8 Initial revision
mcr authored
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 *
98a503e @yuguy Improved VLAN support, from Peter Jeremy - "vlan" filtering keyword,
yuguy authored
21 * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.42 2000-10-22 04:15:56 guy Exp $ (LBL)
b11ddf8 Initial revision
mcr authored
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
7fe3c11 IPv6 packet filtering code.
itojun authored
31 #define Q_PROTOCHAIN 6
b11ddf8 Initial revision
mcr authored
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
7fe3c11 IPv6 packet filtering code.
itojun authored
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
b11ddf8 Initial revision
mcr authored
61 /* Directional qualifiers. */
62
63 #define Q_SRC 1
64 #define Q_DST 2
65 #define Q_OR 3
66 #define Q_AND 4
67
68 #define Q_DEFAULT 0
69 #define Q_UNDEF 255
70
7fe3c11 IPv6 packet filtering code.
itojun authored
71 struct slist;
72
b11ddf8 Initial revision
mcr authored
73 struct stmt {
74 int code;
7fe3c11 IPv6 packet filtering code.
itojun authored
75 struct slist *jt; /*only for relative jump in block*/
76 struct slist *jf; /*only for relative jump in block*/
b11ddf8 Initial revision
mcr authored
77 bpf_int32 k;
78 };
79
80 struct slist {
81 struct stmt s;
82 struct slist *next;
83 };
84
85 /*
86 * A bit vector to represent definition sets. We assume TOT_REGISTERS
87 * is smaller than 8*sizeof(atomset).
88 */
89 typedef bpf_u_int32 atomset;
90 #define ATOMMASK(n) (1 << (n))
91 #define ATOMELEM(d, n) (d & ATOMMASK(n))
92
93 /*
94 * An unbounded set.
95 */
96 typedef bpf_u_int32 *uset;
97
98 /*
99 * Total number of atomic entities, including accumulator (A) and index (X).
100 * We treat all these guys similarly during flow analysis.
101 */
102 #define N_ATOMS (BPF_MEMWORDS+2)
103
104 struct edge {
105 int id;
106 int code;
107 uset edom;
108 struct block *succ;
109 struct block *pred;
110 struct edge *next; /* link list of incoming edges for a node */
111 };
112
113 struct block {
114 int id;
115 struct slist *stmts; /* side effect stmts */
116 struct stmt s; /* branch stmt */
117 int mark;
118 int longjt; /* jt branch requires long jump */
119 int longjf; /* jf branch requires long jump */
120 int level;
121 int offset;
122 int sense;
123 struct edge et;
124 struct edge ef;
125 struct block *head;
126 struct block *link; /* link field used by optimizer */
127 uset dom;
128 uset closure;
129 struct edge *in_edges;
130 atomset def, kill;
131 atomset in_use;
132 atomset out_use;
133 int oval;
134 int val[N_ATOMS];
135 };
136
137 struct arth {
138 struct block *b; /* protocol checks */
139 struct slist *s; /* stmt list */
140 int regno; /* virtual register number of result */
141 };
142
143 struct qual {
144 unsigned char addr;
145 unsigned char proto;
146 unsigned char dir;
147 unsigned char pad;
148 };
149
150 struct arth *gen_loadi(int);
151 struct arth *gen_load(int, struct arth *, int);
152 struct arth *gen_loadlen(void);
153 struct arth *gen_neg(struct arth *);
154 struct arth *gen_arth(int, struct arth *, struct arth *);
155
156 void gen_and(struct block *, struct block *);
157 void gen_or(struct block *, struct block *);
158 void gen_not(struct block *);
159
160 struct block *gen_scode(const char *, struct qual);
161 struct block *gen_ecode(const u_char *, struct qual);
162 struct block *gen_mcode(const char *, const char *, int, struct qual);
7fe3c11 IPv6 packet filtering code.
itojun authored
163 #ifdef INET6
164 struct block *gen_mcode6(const char *, const char *, int, struct qual);
165 #endif
b11ddf8 Initial revision
mcr authored
166 struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
167 struct block *gen_proto_abbrev(int);
168 struct block *gen_relation(int, struct arth *, struct arth *, int);
169 struct block *gen_less(int);
170 struct block *gen_greater(int);
171 struct block *gen_byteop(int, int, int);
172 struct block *gen_broadcast(int);
173 struct block *gen_multicast(int);
174 struct block *gen_inbound(int);
175
98a503e @yuguy Improved VLAN support, from Peter Jeremy - "vlan" filtering keyword,
yuguy authored
176 struct block *gen_vlan(int);
177
b11ddf8 Initial revision
mcr authored
178 void bpf_optimize(struct block **);
0e2f8c8 add config.h, remove gnuc.h. remove __dead
assar authored
179 void bpf_error(const char *, ...)
417d093 (bpf_error): conditionalize __attribute__
assar authored
180 #if HAVE___ATTRIBUTE__
0e2f8c8 add config.h, remove gnuc.h. remove __dead
assar authored
181 __attribute__((noreturn, format (printf, 1, 2)))
417d093 (bpf_error): conditionalize __attribute__
assar authored
182 #endif
183 ;
b11ddf8 Initial revision
mcr authored
184
185 void finish_parse(struct block *);
186 char *sdup(const char *);
187
188 struct bpf_insn *icode_to_fcode(struct block *, int *);
189 int pcap_parse(void);
190 void lex_init(char *);
0d0297b @yuguy Older versions of Flex (e.g., 2.5.2, which at least one user had) dump
yuguy authored
191 void lex_cleanup(void);
b11ddf8 Initial revision
mcr authored
192 void sappend(struct slist *, struct slist *);
193
194 /* XXX */
195 #define JT(b) ((b)->et.succ)
196 #define JF(b) ((b)->ef.succ)
7fe3c11 IPv6 packet filtering code.
itojun authored
197
198 extern int no_optimize;
Something went wrong with that request. Please try again.