]> The Tcpdump Group git mirrors - libpcap/blob - grammar.y
If parser debugging is enabled, ensure pcap_debug is exported.
[libpcap] / grammar.y
1 /*
2 * We want a reentrant parser.
3 */
4 %pure-parser
5
6 /*
7 * We also want a reentrant scanner, so we have to pass the
8 * handle for the reentrant scanner to the parser, and the
9 * parser has to pass it to the lexical analyzer.
10 *
11 * We use void * rather than yyscan_t because, at least with some
12 * versions of Flex and Bison, if you use yyscan_t in %parse-param and
13 * %lex-param, you have to include scanner.h before grammar.h to get
14 * yyscan_t declared, and you have to include grammar.h before scanner.h
15 * to get YYSTYPE declared. Using void * breaks the cycle; the Flex
16 * documentation says yyscan_t is just a void *.
17 */
18 %parse-param {void *yyscanner}
19 %lex-param {void *yyscanner}
20
21 %{
22 /*
23 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
24 * The Regents of the University of California. All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that: (1) source code distributions
28 * retain the above copyright notice and this paragraph in its entirety, (2)
29 * distributions including binary code include the above copyright notice and
30 * this paragraph in its entirety in the documentation or other materials
31 * provided with the distribution, and (3) all advertising materials mentioning
32 * features or use of this software display the following acknowledgement:
33 * ``This product includes software developed by the University of California,
34 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
35 * the University nor the names of its contributors may be used to endorse
36 * or promote products derived from this software without specific prior
37 * written permission.
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
39 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
40 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
41 *
42 */
43
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47
48 #ifdef _WIN32
49 #include <pcap-stdinc.h>
50 #else /* _WIN32 */
51 #include <sys/types.h>
52 #include <sys/socket.h>
53 #endif /* _WIN32 */
54
55 #include <stdlib.h>
56
57 #ifndef _WIN32
58 #if __STDC__
59 struct mbuf;
60 struct rtentry;
61 #endif
62
63 #include <netinet/in.h>
64 #include <arpa/inet.h>
65 #endif /* _WIN32 */
66
67 #include <stdio.h>
68
69 #include "pcap-int.h"
70
71 #include "gencode.h"
72 #include "grammar.h"
73 #include "scanner.h"
74
75 #if YYDEBUG
76 PCAP_API_DEF int pcap_debug;
77 #endif
78
79 #ifdef HAVE_NET_PFVAR_H
80 #include <net/if.h>
81 #include <net/pfvar.h>
82 #include <net/if_pflog.h>
83 #endif
84 #include "llc.h"
85 #include "ieee80211.h"
86 #include <pcap/namedb.h>
87
88 #ifdef HAVE_OS_PROTO_H
89 #include "os-proto.h"
90 #endif
91
92 #define QSET(q, p, d, a) (q).proto = (p),\
93 (q).dir = (d),\
94 (q).addr = (a)
95
96 struct tok {
97 int v; /* value */
98 const char *s; /* string */
99 };
100
101 static const struct tok ieee80211_types[] = {
102 { IEEE80211_FC0_TYPE_DATA, "data" },
103 { IEEE80211_FC0_TYPE_MGT, "mgt" },
104 { IEEE80211_FC0_TYPE_MGT, "management" },
105 { IEEE80211_FC0_TYPE_CTL, "ctl" },
106 { IEEE80211_FC0_TYPE_CTL, "control" },
107 { 0, NULL }
108 };
109 static const struct tok ieee80211_mgt_subtypes[] = {
110 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
111 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
112 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
113 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
114 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
115 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
116 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
117 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
118 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
119 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
120 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
121 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
122 { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
123 { IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
124 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
125 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
126 { IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
127 { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
128 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
129 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
130 { 0, NULL }
131 };
132 static const struct tok ieee80211_ctl_subtypes[] = {
133 { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
134 { IEEE80211_FC0_SUBTYPE_RTS, "rts" },
135 { IEEE80211_FC0_SUBTYPE_CTS, "cts" },
136 { IEEE80211_FC0_SUBTYPE_ACK, "ack" },
137 { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
138 { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
139 { 0, NULL }
140 };
141 static const struct tok ieee80211_data_subtypes[] = {
142 { IEEE80211_FC0_SUBTYPE_DATA, "data" },
143 { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
144 { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
145 { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
146 { IEEE80211_FC0_SUBTYPE_NODATA, "null" },
147 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
148 { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
149 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
150 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
151 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
152 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
153 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
154 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
155 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
156 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
157 { 0, NULL }
158 };
159 static const struct tok llc_s_subtypes[] = {
160 { LLC_RR, "rr" },
161 { LLC_RNR, "rnr" },
162 { LLC_REJ, "rej" },
163 { 0, NULL }
164 };
165 static const struct tok llc_u_subtypes[] = {
166 { LLC_UI, "ui" },
167 { LLC_UA, "ua" },
168 { LLC_DISC, "disc" },
169 { LLC_DM, "dm" },
170 { LLC_SABME, "sabme" },
171 { LLC_TEST, "test" },
172 { LLC_XID, "xid" },
173 { LLC_FRMR, "frmr" },
174 { 0, NULL }
175 };
176 struct type2tok {
177 int type;
178 const struct tok *tok;
179 };
180 static const struct type2tok ieee80211_type_subtypes[] = {
181 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
182 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
183 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
184 { 0, NULL }
185 };
186
187 static int
188 str2tok(const char *str, const struct tok *toks)
189 {
190 int i;
191
192 for (i = 0; toks[i].s != NULL; i++) {
193 if (pcap_strcasecmp(toks[i].s, str) == 0)
194 return (toks[i].v);
195 }
196 return (-1);
197 }
198
199 int n_errors = 0;
200
201 static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
202
203 static void
204 yyerror(void *yyscanner, const char *msg)
205 {
206 ++n_errors;
207 bpf_error("%s", msg);
208 /* NOTREACHED */
209 }
210
211 #ifdef HAVE_NET_PFVAR_H
212 static int
213 pfreason_to_num(const char *reason)
214 {
215 const char *reasons[] = PFRES_NAMES;
216 int i;
217
218 for (i = 0; reasons[i]; i++) {
219 if (pcap_strcasecmp(reason, reasons[i]) == 0)
220 return (i);
221 }
222 bpf_error("unknown PF reason");
223 /*NOTREACHED*/
224 }
225
226 static int
227 pfaction_to_num(const char *action)
228 {
229 if (pcap_strcasecmp(action, "pass") == 0 ||
230 pcap_strcasecmp(action, "accept") == 0)
231 return (PF_PASS);
232 else if (pcap_strcasecmp(action, "drop") == 0 ||
233 pcap_strcasecmp(action, "block") == 0)
234 return (PF_DROP);
235 #if HAVE_PF_NAT_THROUGH_PF_NORDR
236 else if (pcap_strcasecmp(action, "rdr") == 0)
237 return (PF_RDR);
238 else if (pcap_strcasecmp(action, "nat") == 0)
239 return (PF_NAT);
240 else if (pcap_strcasecmp(action, "binat") == 0)
241 return (PF_BINAT);
242 else if (pcap_strcasecmp(action, "nordr") == 0)
243 return (PF_NORDR);
244 #endif
245 else {
246 bpf_error("unknown PF action");
247 /*NOTREACHED*/
248 }
249 }
250 #else /* !HAVE_NET_PFVAR_H */
251 static int
252 pfreason_to_num(const char *reason)
253 {
254 bpf_error("libpcap was compiled on a machine without pf support");
255 /*NOTREACHED*/
256
257 /* this is to make the VC compiler happy */
258 return -1;
259 }
260
261 static int
262 pfaction_to_num(const char *action)
263 {
264 bpf_error("libpcap was compiled on a machine without pf support");
265 /*NOTREACHED*/
266
267 /* this is to make the VC compiler happy */
268 return -1;
269 }
270 #endif /* HAVE_NET_PFVAR_H */
271 %}
272
273 %union {
274 int i;
275 bpf_u_int32 h;
276 u_char *e;
277 char *s;
278 struct stmt *stmt;
279 struct arth *a;
280 struct {
281 struct qual q;
282 int atmfieldtype;
283 int mtp3fieldtype;
284 struct block *b;
285 } blk;
286 struct block *rblk;
287 }
288
289 %type <blk> expr id nid pid term rterm qid
290 %type <blk> head
291 %type <i> pqual dqual aqual ndaqual
292 %type <a> arth narth
293 %type <i> byteop pname pnum relop irelop
294 %type <blk> and or paren not null prog
295 %type <rblk> other pfvar p80211 pllc
296 %type <i> atmtype atmmultitype
297 %type <blk> atmfield
298 %type <blk> atmfieldvalue atmvalue atmlistvalue
299 %type <i> mtp2type
300 %type <blk> mtp3field
301 %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
302
303
304 %token DST SRC HOST GATEWAY
305 %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
306 %token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
307 %token ATALK AARP DECNET LAT SCA MOPRC MOPDL
308 %token TK_BROADCAST TK_MULTICAST
309 %token NUM INBOUND OUTBOUND
310 %token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
311 %token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
312 %token LINK
313 %token GEQ LEQ NEQ
314 %token ID EID HID HID6 AID
315 %token LSH RSH
316 %token LEN
317 %token IPV6 ICMPV6 AH ESP
318 %token VLAN MPLS
319 %token PPPOED PPPOES GENEVE
320 %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
321 %token STP
322 %token IPX
323 %token NETBEUI
324 %token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
325 %token OAM OAMF4 CONNECTMSG METACONNECT
326 %token VPI VCI
327 %token RADIO
328 %token FISU LSSU MSU HFISU HLSSU HMSU
329 %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
330
331
332 %type <s> ID
333 %type <e> EID
334 %type <e> AID
335 %type <s> HID HID6
336 %type <i> NUM action reason type subtype type_subtype dir
337
338 %left OR AND
339 %nonassoc '!'
340 %left '|'
341 %left '&'
342 %left LSH RSH
343 %left '+' '-'
344 %left '*' '/'
345 %nonassoc UMINUS
346 %%
347 prog: null expr
348 {
349 finish_parse($2.b);
350 }
351 | null
352 ;
353 null: /* null */ { $$.q = qerr; }
354 ;
355 expr: term
356 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
357 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
358 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
359 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
360 ;
361 and: AND { $$ = $<blk>0; }
362 ;
363 or: OR { $$ = $<blk>0; }
364 ;
365 id: nid
366 | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
367 $$.q = $<blk>0.q); }
368 | paren pid ')' { $$ = $2; }
369 ;
370 nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
371 | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
372 $$.q = $<blk>0.q); }
373 | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
374 $$.q = $<blk>0.q); }
375 | HID {
376 /* Decide how to parse HID based on proto */
377 $$.q = $<blk>0.q;
378 if ($$.q.addr == Q_PORT)
379 bpf_error("'port' modifier applied to ip host");
380 else if ($$.q.addr == Q_PORTRANGE)
381 bpf_error("'portrange' modifier applied to ip host");
382 else if ($$.q.addr == Q_PROTO)
383 bpf_error("'proto' modifier applied to ip host");
384 else if ($$.q.addr == Q_PROTOCHAIN)
385 bpf_error("'protochain' modifier applied to ip host");
386 $$.b = gen_ncode($1, 0, $$.q);
387 }
388 | HID6 '/' NUM {
389 #ifdef INET6
390 $$.b = gen_mcode6($1, NULL, $3,
391 $$.q = $<blk>0.q);
392 #else
393 bpf_error("'ip6addr/prefixlen' not supported "
394 "in this configuration");
395 #endif /*INET6*/
396 }
397 | HID6 {
398 #ifdef INET6
399 $$.b = gen_mcode6($1, 0, 128,
400 $$.q = $<blk>0.q);
401 #else
402 bpf_error("'ip6addr' not supported "
403 "in this configuration");
404 #endif /*INET6*/
405 }
406 | EID {
407 $$.b = gen_ecode($1, $$.q = $<blk>0.q);
408 /*
409 * $1 was allocated by "pcap_ether_aton()",
410 * so we must free it now that we're done
411 * with it.
412 */
413 free($1);
414 }
415 | AID {
416 $$.b = gen_acode($1, $$.q = $<blk>0.q);
417 /*
418 * $1 was allocated by "pcap_ether_aton()",
419 * so we must free it now that we're done
420 * with it.
421 */
422 free($1);
423 }
424 | not id { gen_not($2.b); $$ = $2; }
425 ;
426 not: '!' { $$ = $<blk>0; }
427 ;
428 paren: '(' { $$ = $<blk>0; }
429 ;
430 pid: nid
431 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
432 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
433 ;
434 qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
435 $$.q = $<blk>0.q); }
436 | pid
437 ;
438 term: rterm
439 | not term { gen_not($2.b); $$ = $2; }
440 ;
441 head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
442 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
443 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
444 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
445 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
446 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
447 ;
448 rterm: head id { $$ = $2; }
449 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
450 | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
451 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
452 $$.q = qerr; }
453 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
454 $$.q = qerr; }
455 | other { $$.b = $1; $$.q = qerr; }
456 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
457 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
458 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
459 | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
460 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
461 ;
462 /* protocol level qualifiers */
463 pqual: pname
464 | { $$ = Q_DEFAULT; }
465 ;
466 /* 'direction' qualifiers */
467 dqual: SRC { $$ = Q_SRC; }
468 | DST { $$ = Q_DST; }
469 | SRC OR DST { $$ = Q_OR; }
470 | DST OR SRC { $$ = Q_OR; }
471 | SRC AND DST { $$ = Q_AND; }
472 | DST AND SRC { $$ = Q_AND; }
473 | ADDR1 { $$ = Q_ADDR1; }
474 | ADDR2 { $$ = Q_ADDR2; }
475 | ADDR3 { $$ = Q_ADDR3; }
476 | ADDR4 { $$ = Q_ADDR4; }
477 | RA { $$ = Q_RA; }
478 | TA { $$ = Q_TA; }
479 ;
480 /* address type qualifiers */
481 aqual: HOST { $$ = Q_HOST; }
482 | NET { $$ = Q_NET; }
483 | PORT { $$ = Q_PORT; }
484 | PORTRANGE { $$ = Q_PORTRANGE; }
485 ;
486 /* non-directional address type qualifiers */
487 ndaqual: GATEWAY { $$ = Q_GATEWAY; }
488 ;
489 pname: LINK { $$ = Q_LINK; }
490 | IP { $$ = Q_IP; }
491 | ARP { $$ = Q_ARP; }
492 | RARP { $$ = Q_RARP; }
493 | SCTP { $$ = Q_SCTP; }
494 | TCP { $$ = Q_TCP; }
495 | UDP { $$ = Q_UDP; }
496 | ICMP { $$ = Q_ICMP; }
497 | IGMP { $$ = Q_IGMP; }
498 | IGRP { $$ = Q_IGRP; }
499 | PIM { $$ = Q_PIM; }
500 | VRRP { $$ = Q_VRRP; }
501 | CARP { $$ = Q_CARP; }
502 | ATALK { $$ = Q_ATALK; }
503 | AARP { $$ = Q_AARP; }
504 | DECNET { $$ = Q_DECNET; }
505 | LAT { $$ = Q_LAT; }
506 | SCA { $$ = Q_SCA; }
507 | MOPDL { $$ = Q_MOPDL; }
508 | MOPRC { $$ = Q_MOPRC; }
509 | IPV6 { $$ = Q_IPV6; }
510 | ICMPV6 { $$ = Q_ICMPV6; }
511 | AH { $$ = Q_AH; }
512 | ESP { $$ = Q_ESP; }
513 | ISO { $$ = Q_ISO; }
514 | ESIS { $$ = Q_ESIS; }
515 | ISIS { $$ = Q_ISIS; }
516 | L1 { $$ = Q_ISIS_L1; }
517 | L2 { $$ = Q_ISIS_L2; }
518 | IIH { $$ = Q_ISIS_IIH; }
519 | LSP { $$ = Q_ISIS_LSP; }
520 | SNP { $$ = Q_ISIS_SNP; }
521 | PSNP { $$ = Q_ISIS_PSNP; }
522 | CSNP { $$ = Q_ISIS_CSNP; }
523 | CLNP { $$ = Q_CLNP; }
524 | STP { $$ = Q_STP; }
525 | IPX { $$ = Q_IPX; }
526 | NETBEUI { $$ = Q_NETBEUI; }
527 | RADIO { $$ = Q_RADIO; }
528 ;
529 other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
530 | pqual TK_MULTICAST { $$ = gen_multicast($1); }
531 | LESS NUM { $$ = gen_less($2); }
532 | GREATER NUM { $$ = gen_greater($2); }
533 | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
534 | INBOUND { $$ = gen_inbound(0); }
535 | OUTBOUND { $$ = gen_inbound(1); }
536 | VLAN pnum { $$ = gen_vlan($2); }
537 | VLAN { $$ = gen_vlan(-1); }
538 | MPLS pnum { $$ = gen_mpls($2); }
539 | MPLS { $$ = gen_mpls(-1); }
540 | PPPOED { $$ = gen_pppoed(); }
541 | PPPOES pnum { $$ = gen_pppoes($2); }
542 | PPPOES { $$ = gen_pppoes(-1); }
543 | GENEVE pnum { $$ = gen_geneve($2); }
544 | GENEVE { $$ = gen_geneve(-1); }
545 | pfvar { $$ = $1; }
546 | pqual p80211 { $$ = $2; }
547 | pllc { $$ = $1; }
548 ;
549
550 pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
551 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
552 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
553 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
554 | PF_REASON reason { $$ = gen_pf_reason($2); }
555 | PF_ACTION action { $$ = gen_pf_action($2); }
556 ;
557
558 p80211: TYPE type SUBTYPE subtype
559 { $$ = gen_p80211_type($2 | $4,
560 IEEE80211_FC0_TYPE_MASK |
561 IEEE80211_FC0_SUBTYPE_MASK);
562 }
563 | TYPE type { $$ = gen_p80211_type($2,
564 IEEE80211_FC0_TYPE_MASK);
565 }
566 | SUBTYPE type_subtype { $$ = gen_p80211_type($2,
567 IEEE80211_FC0_TYPE_MASK |
568 IEEE80211_FC0_SUBTYPE_MASK);
569 }
570 | DIR dir { $$ = gen_p80211_fcdir($2); }
571 ;
572
573 type: NUM
574 | ID { $$ = str2tok($1, ieee80211_types);
575 if ($$ == -1)
576 bpf_error("unknown 802.11 type name");
577 }
578 ;
579
580 subtype: NUM
581 | ID { const struct tok *types = NULL;
582 int i;
583 for (i = 0;; i++) {
584 if (ieee80211_type_subtypes[i].tok == NULL) {
585 /* Ran out of types */
586 bpf_error("unknown 802.11 type");
587 break;
588 }
589 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
590 types = ieee80211_type_subtypes[i].tok;
591 break;
592 }
593 }
594
595 $$ = str2tok($1, types);
596 if ($$ == -1)
597 bpf_error("unknown 802.11 subtype name");
598 }
599 ;
600
601 type_subtype: ID { int i;
602 for (i = 0;; i++) {
603 if (ieee80211_type_subtypes[i].tok == NULL) {
604 /* Ran out of types */
605 bpf_error("unknown 802.11 type name");
606 break;
607 }
608 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
609 if ($$ != -1) {
610 $$ |= ieee80211_type_subtypes[i].type;
611 break;
612 }
613 }
614 }
615 ;
616
617 pllc: LLC { $$ = gen_llc(); }
618 | LLC ID { if (pcap_strcasecmp($2, "i") == 0)
619 $$ = gen_llc_i();
620 else if (pcap_strcasecmp($2, "s") == 0)
621 $$ = gen_llc_s();
622 else if (pcap_strcasecmp($2, "u") == 0)
623 $$ = gen_llc_u();
624 else {
625 u_int subtype;
626
627 subtype = str2tok($2, llc_s_subtypes);
628 if (subtype != -1)
629 $$ = gen_llc_s_subtype(subtype);
630 else {
631 subtype = str2tok($2, llc_u_subtypes);
632 if (subtype == -1)
633 bpf_error("unknown LLC type name \"%s\"", $2);
634 $$ = gen_llc_u_subtype(subtype);
635 }
636 }
637 }
638 /* sigh, "rnr" is already a keyword for PF */
639 | LLC PF_RNR { $$ = gen_llc_s_subtype(LLC_RNR); }
640 ;
641
642 dir: NUM
643 | ID { if (pcap_strcasecmp($1, "nods") == 0)
644 $$ = IEEE80211_FC1_DIR_NODS;
645 else if (pcap_strcasecmp($1, "tods") == 0)
646 $$ = IEEE80211_FC1_DIR_TODS;
647 else if (pcap_strcasecmp($1, "fromds") == 0)
648 $$ = IEEE80211_FC1_DIR_FROMDS;
649 else if (pcap_strcasecmp($1, "dstods") == 0)
650 $$ = IEEE80211_FC1_DIR_DSTODS;
651 else
652 bpf_error("unknown 802.11 direction");
653 }
654 ;
655
656 reason: NUM { $$ = $1; }
657 | ID { $$ = pfreason_to_num($1); }
658 ;
659
660 action: ID { $$ = pfaction_to_num($1); }
661 ;
662
663 relop: '>' { $$ = BPF_JGT; }
664 | GEQ { $$ = BPF_JGE; }
665 | '=' { $$ = BPF_JEQ; }
666 ;
667 irelop: LEQ { $$ = BPF_JGT; }
668 | '<' { $$ = BPF_JGE; }
669 | NEQ { $$ = BPF_JEQ; }
670 ;
671 arth: pnum { $$ = gen_loadi($1); }
672 | narth
673 ;
674 narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
675 | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
676 | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
677 | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
678 | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
679 | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
680 | arth '%' arth { $$ = gen_arth(BPF_MOD, $1, $3); }
681 | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
682 | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
683 | arth '^' arth { $$ = gen_arth(BPF_XOR, $1, $3); }
684 | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
685 | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
686 | '-' arth %prec UMINUS { $$ = gen_neg($2); }
687 | paren narth ')' { $$ = $2; }
688 | LEN { $$ = gen_loadlen(); }
689 ;
690 byteop: '&' { $$ = '&'; }
691 | '|' { $$ = '|'; }
692 | '<' { $$ = '<'; }
693 | '>' { $$ = '>'; }
694 | '=' { $$ = '='; }
695 ;
696 pnum: NUM
697 | paren pnum ')' { $$ = $2; }
698 ;
699 atmtype: LANE { $$ = A_LANE; }
700 | METAC { $$ = A_METAC; }
701 | BCC { $$ = A_BCC; }
702 | OAMF4EC { $$ = A_OAMF4EC; }
703 | OAMF4SC { $$ = A_OAMF4SC; }
704 | SC { $$ = A_SC; }
705 | ILMIC { $$ = A_ILMIC; }
706 ;
707 atmmultitype: OAM { $$ = A_OAM; }
708 | OAMF4 { $$ = A_OAMF4; }
709 | CONNECTMSG { $$ = A_CONNECTMSG; }
710 | METACONNECT { $$ = A_METACONNECT; }
711 ;
712 /* ATM field types quantifier */
713 atmfield: VPI { $$.atmfieldtype = A_VPI; }
714 | VCI { $$.atmfieldtype = A_VCI; }
715 ;
716 atmvalue: atmfieldvalue
717 | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
718 | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
719 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
720 ;
721 atmfieldvalue: NUM {
722 $$.atmfieldtype = $<blk>0.atmfieldtype;
723 if ($$.atmfieldtype == A_VPI ||
724 $$.atmfieldtype == A_VCI)
725 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
726 }
727 ;
728 atmlistvalue: atmfieldvalue
729 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
730 ;
731 /* MTP2 types quantifier */
732 mtp2type: FISU { $$ = M_FISU; }
733 | LSSU { $$ = M_LSSU; }
734 | MSU { $$ = M_MSU; }
735 | HFISU { $$ = MH_FISU; }
736 | HLSSU { $$ = MH_LSSU; }
737 | HMSU { $$ = MH_MSU; }
738 ;
739 /* MTP3 field types quantifier */
740 mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
741 | OPC { $$.mtp3fieldtype = M_OPC; }
742 | DPC { $$.mtp3fieldtype = M_DPC; }
743 | SLS { $$.mtp3fieldtype = M_SLS; }
744 | HSIO { $$.mtp3fieldtype = MH_SIO; }
745 | HOPC { $$.mtp3fieldtype = MH_OPC; }
746 | HDPC { $$.mtp3fieldtype = MH_DPC; }
747 | HSLS { $$.mtp3fieldtype = MH_SLS; }
748 ;
749 mtp3value: mtp3fieldvalue
750 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
751 | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
752 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
753 ;
754 mtp3fieldvalue: NUM {
755 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
756 if ($$.mtp3fieldtype == M_SIO ||
757 $$.mtp3fieldtype == M_OPC ||
758 $$.mtp3fieldtype == M_DPC ||
759 $$.mtp3fieldtype == M_SLS ||
760 $$.mtp3fieldtype == MH_SIO ||
761 $$.mtp3fieldtype == MH_OPC ||
762 $$.mtp3fieldtype == MH_DPC ||
763 $$.mtp3fieldtype == MH_SLS)
764 $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
765 }
766 ;
767 mtp3listvalue: mtp3fieldvalue
768 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
769 ;
770 %%