Deleted Added
full compact
grammar.y (162015) grammar.y (172680)
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * $FreeBSD: head/contrib/libpcap/grammar.y 162015 2006-09-04 19:54:21Z sam $
22 * $FreeBSD: head/contrib/libpcap/grammar.y 172680 2007-10-16 02:07:55Z mlaier $
23 */
24#ifndef lint
25static const char rcsid[] _U_ =
23 */
24#ifndef lint
25static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.5 2005/09/05 09:08:06 guy Exp $ (LBL)";
26 "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.9 2007/09/12 19:17:25 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#ifdef WIN32
34#include <pcap-stdinc.h>
35#else /* WIN32 */
36#include <sys/types.h>
37#include <sys/socket.h>
38#endif /* WIN32 */
39
40#include <stdlib.h>
41
42#ifndef WIN32
43#if __STDC__
44struct mbuf;
45struct rtentry;
46#endif
47
48#include <netinet/in.h>
49#endif /* WIN32 */
50
51#include <stdio.h>
52
53#include "pcap-int.h"
54
55#include "gencode.h"
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#ifdef WIN32
34#include <pcap-stdinc.h>
35#else /* WIN32 */
36#include <sys/types.h>
37#include <sys/socket.h>
38#endif /* WIN32 */
39
40#include <stdlib.h>
41
42#ifndef WIN32
43#if __STDC__
44struct mbuf;
45struct rtentry;
46#endif
47
48#include <netinet/in.h>
49#endif /* WIN32 */
50
51#include <stdio.h>
52
53#include "pcap-int.h"
54
55#include "gencode.h"
56#include "pf.h"
56#ifdef HAVE_NET_PFVAR_H
57#include <net/if.h>
58#include <net/pfvar.h>
59#include <net/if_pflog.h>
60#endif
57#include <pcap-namedb.h>
58
59#ifdef HAVE_OS_PROTO_H
60#include "os-proto.h"
61#endif
62
63#define QSET(q, p, d, a) (q).proto = (p),\
64 (q).dir = (d),\
65 (q).addr = (a)
66
67int n_errors = 0;
68
69static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
70
71static void
61#include <pcap-namedb.h>
62
63#ifdef HAVE_OS_PROTO_H
64#include "os-proto.h"
65#endif
66
67#define QSET(q, p, d, a) (q).proto = (p),\
68 (q).dir = (d),\
69 (q).addr = (a)
70
71int n_errors = 0;
72
73static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
74
75static void
72yyerror(char *msg)
76yyerror(const char *msg)
73{
74 ++n_errors;
75 bpf_error("%s", msg);
76 /* NOTREACHED */
77}
78
79#ifndef YYBISON
80int yyparse(void);
81
82int
83pcap_parse()
84{
85 return (yyparse());
86}
87#endif
88
77{
78 ++n_errors;
79 bpf_error("%s", msg);
80 /* NOTREACHED */
81}
82
83#ifndef YYBISON
84int yyparse(void);
85
86int
87pcap_parse()
88{
89 return (yyparse());
90}
91#endif
92
93#ifdef HAVE_NET_PFVAR_H
94static int
95pfreason_to_num(const char *reason)
96{
97 const char *reasons[] = PFRES_NAMES;
98 int i;
99
100 for (i = 0; reasons[i]; i++) {
101 if (pcap_strcasecmp(reason, reasons[i]) == 0)
102 return (i);
103 }
104 bpf_error("unknown PF reason");
105 /*NOTREACHED*/
106}
107
108static int
109pfaction_to_num(const char *action)
110{
111 if (pcap_strcasecmp(action, "pass") == 0 ||
112 pcap_strcasecmp(action, "accept") == 0)
113 return (PF_PASS);
114 else if (pcap_strcasecmp(action, "drop") == 0 ||
115 pcap_strcasecmp(action, "block") == 0)
116 return (PF_DROP);
117 else {
118 bpf_error("unknown PF action");
119 /*NOTREACHED*/
120 }
121}
122#else /* !HAVE_NET_PFVAR_H */
123static int
124pfreason_to_num(const char *reason)
125{
126 bpf_error("libpcap was compiled on a machine without pf support");
127 /*NOTREACHED*/
128}
129
130static int
131pfaction_to_num(const char *action)
132{
133 bpf_error("libpcap was compiled on a machine without pf support");
134 /*NOTREACHED*/
135}
136#endif /* HAVE_NET_PFVAR_H */
89%}
90
91%union {
92 int i;
93 bpf_u_int32 h;
94 u_char *e;
95 char *s;
96 struct stmt *stmt;
97 struct arth *a;
98 struct {
99 struct qual q;
100 int atmfieldtype;
101 int mtp3fieldtype;
102 struct block *b;
103 } blk;
104 struct block *rblk;
105}
106
107%type <blk> expr id nid pid term rterm qid
108%type <blk> head
109%type <i> pqual dqual aqual ndaqual
110%type <a> arth narth
111%type <i> byteop pname pnum relop irelop
112%type <blk> and or paren not null prog
113%type <rblk> other pfvar
114%type <i> atmtype atmmultitype
115%type <blk> atmfield
116%type <blk> atmfieldvalue atmvalue atmlistvalue
137%}
138
139%union {
140 int i;
141 bpf_u_int32 h;
142 u_char *e;
143 char *s;
144 struct stmt *stmt;
145 struct arth *a;
146 struct {
147 struct qual q;
148 int atmfieldtype;
149 int mtp3fieldtype;
150 struct block *b;
151 } blk;
152 struct block *rblk;
153}
154
155%type <blk> expr id nid pid term rterm qid
156%type <blk> head
157%type <i> pqual dqual aqual ndaqual
158%type <a> arth narth
159%type <i> byteop pname pnum relop irelop
160%type <blk> and or paren not null prog
161%type <rblk> other pfvar
162%type <i> atmtype atmmultitype
163%type <blk> atmfield
164%type <blk> atmfieldvalue atmvalue atmlistvalue
117%type <blk> mtp3field
118%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
165%type <i> mtp2type
166%type <blk> mtp3field
167%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
119
120
121%token DST SRC HOST GATEWAY
122%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
123%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
124%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
125%token TK_BROADCAST TK_MULTICAST
126%token NUM INBOUND OUTBOUND
127%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
128%token LINK
129%token GEQ LEQ NEQ
130%token ID EID HID HID6 AID
131%token LSH RSH
132%token LEN
133%token IPV6 ICMPV6 AH ESP
134%token VLAN MPLS
135%token PPPOED PPPOES
136%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
137%token STP
138%token IPX
139%token NETBEUI
140%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
141%token OAM OAMF4 CONNECTMSG METACONNECT
142%token VPI VCI
143%token RADIO
168
169
170%token DST SRC HOST GATEWAY
171%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
172%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
173%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
174%token TK_BROADCAST TK_MULTICAST
175%token NUM INBOUND OUTBOUND
176%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
177%token LINK
178%token GEQ LEQ NEQ
179%token ID EID HID HID6 AID
180%token LSH RSH
181%token LEN
182%token IPV6 ICMPV6 AH ESP
183%token VLAN MPLS
184%token PPPOED PPPOES
185%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
186%token STP
187%token IPX
188%token NETBEUI
189%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
190%token OAM OAMF4 CONNECTMSG METACONNECT
191%token VPI VCI
192%token RADIO
144%token SIO OPC DPC SLS
193%token FISU LSSU MSU
194%token SIO OPC DPC SLS
145
146%type <s> ID
147%type <e> EID
148%type <e> AID
149%type <s> HID HID6
150%type <i> NUM action reason
151
152%left OR AND
153%nonassoc '!'
154%left '|'
155%left '&'
156%left LSH RSH
157%left '+' '-'
158%left '*' '/'
159%nonassoc UMINUS
160%%
161prog: null expr
162{
163 finish_parse($2.b);
164}
165 | null
166 ;
167null: /* null */ { $$.q = qerr; }
168 ;
169expr: term
170 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
171 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
172 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
173 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
174 ;
175and: AND { $$ = $<blk>0; }
176 ;
177or: OR { $$ = $<blk>0; }
178 ;
179id: nid
180 | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
181 $$.q = $<blk>0.q); }
182 | paren pid ')' { $$ = $2; }
183 ;
184nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
185 | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
186 $$.q = $<blk>0.q); }
187 | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
188 $$.q = $<blk>0.q); }
189 | HID {
190 /* Decide how to parse HID based on proto */
191 $$.q = $<blk>0.q;
192 $$.b = gen_ncode($1, 0, $$.q);
193 }
194 | HID6 '/' NUM {
195#ifdef INET6
196 $$.b = gen_mcode6($1, NULL, $3,
197 $$.q = $<blk>0.q);
198#else
199 bpf_error("'ip6addr/prefixlen' not supported "
200 "in this configuration");
201#endif /*INET6*/
202 }
203 | HID6 {
204#ifdef INET6
205 $$.b = gen_mcode6($1, 0, 128,
206 $$.q = $<blk>0.q);
207#else
208 bpf_error("'ip6addr' not supported "
209 "in this configuration");
210#endif /*INET6*/
211 }
212 | EID {
213 $$.b = gen_ecode($1, $$.q = $<blk>0.q);
214 /*
215 * $1 was allocated by "pcap_ether_aton()",
216 * so we must free it now that we're done
217 * with it.
218 */
219 free($1);
220 }
221 | AID {
222 $$.b = gen_acode($1, $$.q = $<blk>0.q);
223 /*
224 * $1 was allocated by "pcap_ether_aton()",
225 * so we must free it now that we're done
226 * with it.
227 */
228 free($1);
229 }
230 | not id { gen_not($2.b); $$ = $2; }
231 ;
232not: '!' { $$ = $<blk>0; }
233 ;
234paren: '(' { $$ = $<blk>0; }
235 ;
236pid: nid
237 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
238 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
239 ;
240qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
241 $$.q = $<blk>0.q); }
242 | pid
243 ;
244term: rterm
245 | not term { gen_not($2.b); $$ = $2; }
246 ;
247head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
248 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
249 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
250 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
251 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
252 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
253 ;
254rterm: head id { $$ = $2; }
255 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
256 | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
257 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
258 $$.q = qerr; }
259 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
260 $$.q = qerr; }
261 | other { $$.b = $1; $$.q = qerr; }
262 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
263 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
264 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
195
196%type <s> ID
197%type <e> EID
198%type <e> AID
199%type <s> HID HID6
200%type <i> NUM action reason
201
202%left OR AND
203%nonassoc '!'
204%left '|'
205%left '&'
206%left LSH RSH
207%left '+' '-'
208%left '*' '/'
209%nonassoc UMINUS
210%%
211prog: null expr
212{
213 finish_parse($2.b);
214}
215 | null
216 ;
217null: /* null */ { $$.q = qerr; }
218 ;
219expr: term
220 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
221 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
222 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
223 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
224 ;
225and: AND { $$ = $<blk>0; }
226 ;
227or: OR { $$ = $<blk>0; }
228 ;
229id: nid
230 | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
231 $$.q = $<blk>0.q); }
232 | paren pid ')' { $$ = $2; }
233 ;
234nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
235 | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
236 $$.q = $<blk>0.q); }
237 | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
238 $$.q = $<blk>0.q); }
239 | HID {
240 /* Decide how to parse HID based on proto */
241 $$.q = $<blk>0.q;
242 $$.b = gen_ncode($1, 0, $$.q);
243 }
244 | HID6 '/' NUM {
245#ifdef INET6
246 $$.b = gen_mcode6($1, NULL, $3,
247 $$.q = $<blk>0.q);
248#else
249 bpf_error("'ip6addr/prefixlen' not supported "
250 "in this configuration");
251#endif /*INET6*/
252 }
253 | HID6 {
254#ifdef INET6
255 $$.b = gen_mcode6($1, 0, 128,
256 $$.q = $<blk>0.q);
257#else
258 bpf_error("'ip6addr' not supported "
259 "in this configuration");
260#endif /*INET6*/
261 }
262 | EID {
263 $$.b = gen_ecode($1, $$.q = $<blk>0.q);
264 /*
265 * $1 was allocated by "pcap_ether_aton()",
266 * so we must free it now that we're done
267 * with it.
268 */
269 free($1);
270 }
271 | AID {
272 $$.b = gen_acode($1, $$.q = $<blk>0.q);
273 /*
274 * $1 was allocated by "pcap_ether_aton()",
275 * so we must free it now that we're done
276 * with it.
277 */
278 free($1);
279 }
280 | not id { gen_not($2.b); $$ = $2; }
281 ;
282not: '!' { $$ = $<blk>0; }
283 ;
284paren: '(' { $$ = $<blk>0; }
285 ;
286pid: nid
287 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
288 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
289 ;
290qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
291 $$.q = $<blk>0.q); }
292 | pid
293 ;
294term: rterm
295 | not term { gen_not($2.b); $$ = $2; }
296 ;
297head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
298 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
299 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
300 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
301 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
302 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
303 ;
304rterm: head id { $$ = $2; }
305 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
306 | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
307 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
308 $$.q = qerr; }
309 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
310 $$.q = qerr; }
311 | other { $$.b = $1; $$.q = qerr; }
312 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
313 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
314 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
315 | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
265 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
266 ;
267/* protocol level qualifiers */
268pqual: pname
269 | { $$ = Q_DEFAULT; }
270 ;
271/* 'direction' qualifiers */
272dqual: SRC { $$ = Q_SRC; }
273 | DST { $$ = Q_DST; }
274 | SRC OR DST { $$ = Q_OR; }
275 | DST OR SRC { $$ = Q_OR; }
276 | SRC AND DST { $$ = Q_AND; }
277 | DST AND SRC { $$ = Q_AND; }
278 ;
279/* address type qualifiers */
280aqual: HOST { $$ = Q_HOST; }
281 | NET { $$ = Q_NET; }
282 | PORT { $$ = Q_PORT; }
283 | PORTRANGE { $$ = Q_PORTRANGE; }
284 ;
285/* non-directional address type qualifiers */
286ndaqual: GATEWAY { $$ = Q_GATEWAY; }
287 ;
288pname: LINK { $$ = Q_LINK; }
289 | IP { $$ = Q_IP; }
290 | ARP { $$ = Q_ARP; }
291 | RARP { $$ = Q_RARP; }
292 | SCTP { $$ = Q_SCTP; }
293 | TCP { $$ = Q_TCP; }
294 | UDP { $$ = Q_UDP; }
295 | ICMP { $$ = Q_ICMP; }
296 | IGMP { $$ = Q_IGMP; }
297 | IGRP { $$ = Q_IGRP; }
298 | PIM { $$ = Q_PIM; }
299 | VRRP { $$ = Q_VRRP; }
300 | ATALK { $$ = Q_ATALK; }
301 | AARP { $$ = Q_AARP; }
302 | DECNET { $$ = Q_DECNET; }
303 | LAT { $$ = Q_LAT; }
304 | SCA { $$ = Q_SCA; }
305 | MOPDL { $$ = Q_MOPDL; }
306 | MOPRC { $$ = Q_MOPRC; }
307 | IPV6 { $$ = Q_IPV6; }
308 | ICMPV6 { $$ = Q_ICMPV6; }
309 | AH { $$ = Q_AH; }
310 | ESP { $$ = Q_ESP; }
311 | ISO { $$ = Q_ISO; }
312 | ESIS { $$ = Q_ESIS; }
313 | ISIS { $$ = Q_ISIS; }
314 | L1 { $$ = Q_ISIS_L1; }
315 | L2 { $$ = Q_ISIS_L2; }
316 | IIH { $$ = Q_ISIS_IIH; }
317 | LSP { $$ = Q_ISIS_LSP; }
318 | SNP { $$ = Q_ISIS_SNP; }
319 | PSNP { $$ = Q_ISIS_PSNP; }
320 | CSNP { $$ = Q_ISIS_CSNP; }
321 | CLNP { $$ = Q_CLNP; }
322 | STP { $$ = Q_STP; }
323 | IPX { $$ = Q_IPX; }
324 | NETBEUI { $$ = Q_NETBEUI; }
325 | RADIO { $$ = Q_RADIO; }
326 ;
327other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
328 | pqual TK_MULTICAST { $$ = gen_multicast($1); }
329 | LESS NUM { $$ = gen_less($2); }
330 | GREATER NUM { $$ = gen_greater($2); }
331 | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
332 | INBOUND { $$ = gen_inbound(0); }
333 | OUTBOUND { $$ = gen_inbound(1); }
334 | VLAN pnum { $$ = gen_vlan($2); }
335 | VLAN { $$ = gen_vlan(-1); }
336 | MPLS pnum { $$ = gen_mpls($2); }
337 | MPLS { $$ = gen_mpls(-1); }
338 | PPPOED { $$ = gen_pppoed(); }
339 | PPPOES { $$ = gen_pppoes(); }
340 | pfvar { $$ = $1; }
341 ;
342
343pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
344 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
345 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
346 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
347 | PF_REASON reason { $$ = gen_pf_reason($2); }
348 | PF_ACTION action { $$ = gen_pf_action($2); }
349 ;
350
351reason: NUM { $$ = $1; }
316 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
317 ;
318/* protocol level qualifiers */
319pqual: pname
320 | { $$ = Q_DEFAULT; }
321 ;
322/* 'direction' qualifiers */
323dqual: SRC { $$ = Q_SRC; }
324 | DST { $$ = Q_DST; }
325 | SRC OR DST { $$ = Q_OR; }
326 | DST OR SRC { $$ = Q_OR; }
327 | SRC AND DST { $$ = Q_AND; }
328 | DST AND SRC { $$ = Q_AND; }
329 ;
330/* address type qualifiers */
331aqual: HOST { $$ = Q_HOST; }
332 | NET { $$ = Q_NET; }
333 | PORT { $$ = Q_PORT; }
334 | PORTRANGE { $$ = Q_PORTRANGE; }
335 ;
336/* non-directional address type qualifiers */
337ndaqual: GATEWAY { $$ = Q_GATEWAY; }
338 ;
339pname: LINK { $$ = Q_LINK; }
340 | IP { $$ = Q_IP; }
341 | ARP { $$ = Q_ARP; }
342 | RARP { $$ = Q_RARP; }
343 | SCTP { $$ = Q_SCTP; }
344 | TCP { $$ = Q_TCP; }
345 | UDP { $$ = Q_UDP; }
346 | ICMP { $$ = Q_ICMP; }
347 | IGMP { $$ = Q_IGMP; }
348 | IGRP { $$ = Q_IGRP; }
349 | PIM { $$ = Q_PIM; }
350 | VRRP { $$ = Q_VRRP; }
351 | ATALK { $$ = Q_ATALK; }
352 | AARP { $$ = Q_AARP; }
353 | DECNET { $$ = Q_DECNET; }
354 | LAT { $$ = Q_LAT; }
355 | SCA { $$ = Q_SCA; }
356 | MOPDL { $$ = Q_MOPDL; }
357 | MOPRC { $$ = Q_MOPRC; }
358 | IPV6 { $$ = Q_IPV6; }
359 | ICMPV6 { $$ = Q_ICMPV6; }
360 | AH { $$ = Q_AH; }
361 | ESP { $$ = Q_ESP; }
362 | ISO { $$ = Q_ISO; }
363 | ESIS { $$ = Q_ESIS; }
364 | ISIS { $$ = Q_ISIS; }
365 | L1 { $$ = Q_ISIS_L1; }
366 | L2 { $$ = Q_ISIS_L2; }
367 | IIH { $$ = Q_ISIS_IIH; }
368 | LSP { $$ = Q_ISIS_LSP; }
369 | SNP { $$ = Q_ISIS_SNP; }
370 | PSNP { $$ = Q_ISIS_PSNP; }
371 | CSNP { $$ = Q_ISIS_CSNP; }
372 | CLNP { $$ = Q_CLNP; }
373 | STP { $$ = Q_STP; }
374 | IPX { $$ = Q_IPX; }
375 | NETBEUI { $$ = Q_NETBEUI; }
376 | RADIO { $$ = Q_RADIO; }
377 ;
378other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
379 | pqual TK_MULTICAST { $$ = gen_multicast($1); }
380 | LESS NUM { $$ = gen_less($2); }
381 | GREATER NUM { $$ = gen_greater($2); }
382 | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
383 | INBOUND { $$ = gen_inbound(0); }
384 | OUTBOUND { $$ = gen_inbound(1); }
385 | VLAN pnum { $$ = gen_vlan($2); }
386 | VLAN { $$ = gen_vlan(-1); }
387 | MPLS pnum { $$ = gen_mpls($2); }
388 | MPLS { $$ = gen_mpls(-1); }
389 | PPPOED { $$ = gen_pppoed(); }
390 | PPPOES { $$ = gen_pppoes(); }
391 | pfvar { $$ = $1; }
392 ;
393
394pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
395 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
396 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
397 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
398 | PF_REASON reason { $$ = gen_pf_reason($2); }
399 | PF_ACTION action { $$ = gen_pf_action($2); }
400 ;
401
402reason: NUM { $$ = $1; }
352 | ID { const char *reasons[] = PFRES_NAMES;
353 int i;
354 for (i = 0; reasons[i]; i++) {
355 if (pcap_strcasecmp($1, reasons[i]) == 0) {
356 $$ = i;
357 break;
358 }
359 }
360 if (reasons[i] == NULL)
361 bpf_error("unknown PF reason");
362 }
403 | ID { $$ = pfreason_to_num($1); }
363 ;
364
404 ;
405
365action: ID { if (pcap_strcasecmp($1, "pass") == 0 ||
366 pcap_strcasecmp($1, "accept") == 0)
367 $$ = PF_PASS;
368 else if (pcap_strcasecmp($1, "drop") == 0 ||
369 pcap_strcasecmp($1, "block") == 0)
370 $$ = PF_DROP;
371 else
372 bpf_error("unknown PF action");
373 }
406action: ID { $$ = pfaction_to_num($1); }
374 ;
375
376relop: '>' { $$ = BPF_JGT; }
377 | GEQ { $$ = BPF_JGE; }
378 | '=' { $$ = BPF_JEQ; }
379 ;
380irelop: LEQ { $$ = BPF_JGT; }
381 | '<' { $$ = BPF_JGE; }
382 | NEQ { $$ = BPF_JEQ; }
383 ;
384arth: pnum { $$ = gen_loadi($1); }
385 | narth
386 ;
387narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
388 | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
389 | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
390 | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
391 | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
392 | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
393 | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
394 | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
395 | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
396 | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
397 | '-' arth %prec UMINUS { $$ = gen_neg($2); }
398 | paren narth ')' { $$ = $2; }
399 | LEN { $$ = gen_loadlen(); }
400 ;
401byteop: '&' { $$ = '&'; }
402 | '|' { $$ = '|'; }
403 | '<' { $$ = '<'; }
404 | '>' { $$ = '>'; }
405 | '=' { $$ = '='; }
406 ;
407pnum: NUM
408 | paren pnum ')' { $$ = $2; }
409 ;
410atmtype: LANE { $$ = A_LANE; }
411 | LLC { $$ = A_LLC; }
412 | METAC { $$ = A_METAC; }
413 | BCC { $$ = A_BCC; }
414 | OAMF4EC { $$ = A_OAMF4EC; }
415 | OAMF4SC { $$ = A_OAMF4SC; }
416 | SC { $$ = A_SC; }
417 | ILMIC { $$ = A_ILMIC; }
418 ;
419atmmultitype: OAM { $$ = A_OAM; }
420 | OAMF4 { $$ = A_OAMF4; }
421 | CONNECTMSG { $$ = A_CONNECTMSG; }
422 | METACONNECT { $$ = A_METACONNECT; }
423 ;
424 /* ATM field types quantifier */
425atmfield: VPI { $$.atmfieldtype = A_VPI; }
426 | VCI { $$.atmfieldtype = A_VCI; }
427 ;
428atmvalue: atmfieldvalue
429 | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
430 | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
431 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
432 ;
433atmfieldvalue: NUM {
434 $$.atmfieldtype = $<blk>0.atmfieldtype;
435 if ($$.atmfieldtype == A_VPI ||
436 $$.atmfieldtype == A_VCI)
437 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
438 }
439 ;
440atmlistvalue: atmfieldvalue
441 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
442 ;
407 ;
408
409relop: '>' { $$ = BPF_JGT; }
410 | GEQ { $$ = BPF_JGE; }
411 | '=' { $$ = BPF_JEQ; }
412 ;
413irelop: LEQ { $$ = BPF_JGT; }
414 | '<' { $$ = BPF_JGE; }
415 | NEQ { $$ = BPF_JEQ; }
416 ;
417arth: pnum { $$ = gen_loadi($1); }
418 | narth
419 ;
420narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
421 | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
422 | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
423 | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
424 | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
425 | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
426 | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
427 | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
428 | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
429 | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
430 | '-' arth %prec UMINUS { $$ = gen_neg($2); }
431 | paren narth ')' { $$ = $2; }
432 | LEN { $$ = gen_loadlen(); }
433 ;
434byteop: '&' { $$ = '&'; }
435 | '|' { $$ = '|'; }
436 | '<' { $$ = '<'; }
437 | '>' { $$ = '>'; }
438 | '=' { $$ = '='; }
439 ;
440pnum: NUM
441 | paren pnum ')' { $$ = $2; }
442 ;
443atmtype: LANE { $$ = A_LANE; }
444 | LLC { $$ = A_LLC; }
445 | METAC { $$ = A_METAC; }
446 | BCC { $$ = A_BCC; }
447 | OAMF4EC { $$ = A_OAMF4EC; }
448 | OAMF4SC { $$ = A_OAMF4SC; }
449 | SC { $$ = A_SC; }
450 | ILMIC { $$ = A_ILMIC; }
451 ;
452atmmultitype: OAM { $$ = A_OAM; }
453 | OAMF4 { $$ = A_OAMF4; }
454 | CONNECTMSG { $$ = A_CONNECTMSG; }
455 | METACONNECT { $$ = A_METACONNECT; }
456 ;
457 /* ATM field types quantifier */
458atmfield: VPI { $$.atmfieldtype = A_VPI; }
459 | VCI { $$.atmfieldtype = A_VCI; }
460 ;
461atmvalue: atmfieldvalue
462 | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
463 | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
464 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
465 ;
466atmfieldvalue: NUM {
467 $$.atmfieldtype = $<blk>0.atmfieldtype;
468 if ($$.atmfieldtype == A_VPI ||
469 $$.atmfieldtype == A_VCI)
470 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
471 }
472 ;
473atmlistvalue: atmfieldvalue
474 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
475 ;
476 /* MTP2 types quantifier */
477mtp2type: FISU { $$ = M_FISU; }
478 | LSSU { $$ = M_LSSU; }
479 | MSU { $$ = M_MSU; }
480 ;
443 /* MTP3 field types quantifier */
444mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
445 | OPC { $$.mtp3fieldtype = M_OPC; }
446 | DPC { $$.mtp3fieldtype = M_DPC; }
447 | SLS { $$.mtp3fieldtype = M_SLS; }
448 ;
449mtp3value: mtp3fieldvalue
450 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
451 | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
452 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
453 ;
454mtp3fieldvalue: NUM {
455 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
456 if ($$.mtp3fieldtype == M_SIO ||
457 $$.mtp3fieldtype == M_OPC ||
458 $$.mtp3fieldtype == M_DPC ||
459 $$.mtp3fieldtype == M_SLS )
460 $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
461 }
462 ;
463mtp3listvalue: mtp3fieldvalue
464 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
465 ;
466%%
481 /* MTP3 field types quantifier */
482mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
483 | OPC { $$.mtp3fieldtype = M_OPC; }
484 | DPC { $$.mtp3fieldtype = M_DPC; }
485 | SLS { $$.mtp3fieldtype = M_SLS; }
486 ;
487mtp3value: mtp3fieldvalue
488 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
489 | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
490 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
491 ;
492mtp3fieldvalue: NUM {
493 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
494 if ($$.mtp3fieldtype == M_SIO ||
495 $$.mtp3fieldtype == M_OPC ||
496 $$.mtp3fieldtype == M_DPC ||
497 $$.mtp3fieldtype == M_SLS )
498 $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
499 }
500 ;
501mtp3listvalue: mtp3fieldvalue
502 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
503 ;
504%%