Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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