2 * We want a reentrant parser.
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.
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 *.
18 %parse-param {void *yyscanner}
19 %lex-param {void *yyscanner}
22 * According to bison documentation, shift/reduce conflicts are not an issue
23 * in most parsers as long as the number does not evolve over time:
24 * https://www.gnu.org/software/bison/manual/html_node/Expect-Decl.html
25 * So, following the advice use %expect to check the amount of shift/reduce
28 * This doesn't appear to work in Berkeley YACC - 1.9 20170709; it still
29 * warns of 38 shift/reduce conflicts.
31 * The Berkeley YACC documentation:
33 * https://invisible-island.net/byacc/manpage/yacc.html
35 * claims that "Bison's support for "%expect" is broken in more than one
36 * release.", but doesn't give details. Hopefully, that only means that
37 * you get warnings even if you have the expected number of shift/reduce
38 * conflicts, not that anything else fails.
43 * And we need to pass the compiler state to the scanner.
45 %parse-param { compiler_state_t *cstate }
49 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
50 * The Regents of the University of California. All rights reserved.
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that: (1) source code distributions
54 * retain the above copyright notice and this paragraph in its entirety, (2)
55 * distributions including binary code include the above copyright notice and
56 * this paragraph in its entirety in the documentation or other materials
57 * provided with the distribution, and (3) all advertising materials mentioning
58 * features or use of this software display the following acknowledgement:
59 * ``This product includes software developed by the University of California,
60 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
61 * the University nor the names of its contributors may be used to endorse
62 * or promote products derived from this software without specific prior
64 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
65 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
66 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
73 * grammar.h requires gencode.h and sometimes breaks in a polluted namespace
74 * (see ftmacros.h), so include it early.
83 #include "diag-control.h"
90 #include "ieee80211.h"
92 #include <pcap/namedb.h>
94 #ifdef HAVE_OS_PROTO_H
99 * Work around some bugs in Berkeley YACC prior to the 2017-07-09
102 * The 2005-05-05 release was the first one to define YYPATCH, so
103 * we treat any release that either 1) doesn't define YYPATCH or
104 * 2) defines it to a value < 20170709 as being buggy.
106 #if defined(YYBYACC) && (!defined(YYPATCH) || YYPATCH < 20170709)
108 * Both Berkeley YACC and Bison define yydebug (under whatever name
109 * it has) as a global, but Bison does so only if YYDEBUG is defined.
110 * Berkeley YACC, prior to the 2017-07-09 release, defines it even if
111 * YYDEBUG isn't defined; declare it here to suppress a warning. The
112 * 2017-07-09 release fixes that.
114 #if !defined(YYDEBUG)
119 * In Berkeley YACC, prior to the 2017-07-09 release, yynerrs (under
120 * whatever name it has) is global, even if it's building a reentrant
121 * parser. In Bison, and in the Berkeley YACC 2017-07-09 release and
122 * later, it's local in reentrant parsers.
124 * Declare it to squelch a warning.
129 #define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
130 (q).dir = (unsigned char)(d),\
131 (q).addr = (unsigned char)(a)
135 const char *s; /* string */
138 static const struct tok ieee80211_types[] = {
139 { IEEE80211_FC0_TYPE_DATA, "data" },
140 { IEEE80211_FC0_TYPE_MGT, "mgt" },
141 { IEEE80211_FC0_TYPE_MGT, "management" },
142 { IEEE80211_FC0_TYPE_CTL, "ctl" },
143 { IEEE80211_FC0_TYPE_CTL, "control" },
146 static const struct tok ieee80211_mgt_subtypes[] = {
147 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
148 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
149 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
150 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
151 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
152 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
153 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
154 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
155 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
156 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
157 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
158 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
159 { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
160 { IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
161 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
162 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
163 { IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
164 { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
165 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
166 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
169 static const struct tok ieee80211_ctl_subtypes[] = {
170 { IEEE80211_FC0_SUBTYPE_BAR, "bar" },
171 { IEEE80211_FC0_SUBTYPE_BA, "ba" },
172 { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
173 { IEEE80211_FC0_SUBTYPE_RTS, "rts" },
174 { IEEE80211_FC0_SUBTYPE_CTS, "cts" },
175 { IEEE80211_FC0_SUBTYPE_ACK, "ack" },
176 { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
177 { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
180 static const struct tok ieee80211_data_subtypes[] = {
181 { IEEE80211_FC0_SUBTYPE_DATA, "data" },
182 { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
183 { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
184 { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
185 { IEEE80211_FC0_SUBTYPE_NODATA, "null" },
186 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
187 { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
188 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
189 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
190 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
191 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
192 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
193 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
194 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
195 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
198 static const struct tok llc_s_subtypes[] = {
204 static const struct tok llc_u_subtypes[] = {
207 { LLC_DISC, "disc" },
209 { LLC_SABME, "sabme" },
210 { LLC_TEST, "test" },
212 { LLC_FRMR, "frmr" },
217 const struct tok *tok;
219 static const struct type2tok ieee80211_type_subtypes[] = {
220 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
221 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
222 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
227 str2tok(const char *str, const struct tok *toks)
231 for (i = 0; toks[i].s != NULL; i++) {
232 if (pcapint_strcasecmp(toks[i].s, str) == 0) {
234 * Just in case somebody is using this to
235 * generate values of -1/0xFFFFFFFF.
236 * That won't work, as it's indistinguishable
247 static const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
250 yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
252 bpf_set_error(cstate, "can't parse filter expression: %s", msg);
255 static const struct tok pflog_reasons[] = {
256 { PFRES_MATCH, "match" },
257 { PFRES_BADOFF, "bad-offset" },
258 { PFRES_FRAG, "fragment" },
259 { PFRES_SHORT, "short" },
260 { PFRES_NORM, "normalize" },
261 { PFRES_MEMORY, "memory" },
262 { PFRES_TS, "bad-timestamp" },
263 { PFRES_CONGEST, "congestion" },
264 { PFRES_IPOPTIONS, "ip-option" },
265 { PFRES_PROTCKSUM, "proto-cksum" },
266 { PFRES_BADSTATE, "state-mismatch" },
267 { PFRES_STATEINS, "state-insert" },
268 { PFRES_MAXSTATES, "state-limit" },
269 { PFRES_SRCLIMIT, "src-limit" },
270 { PFRES_SYNPROXY, "synproxy" },
271 #if defined(__FreeBSD__)
272 { PFRES_MAPFAILED, "map-failed" },
273 #elif defined(__NetBSD__)
274 { PFRES_STATELOCKED, "state-locked" },
275 #elif defined(__OpenBSD__)
276 { PFRES_TRANSLATE, "translate" },
277 { PFRES_NOROUTE, "no-route" },
278 #elif defined(__APPLE__)
279 { PFRES_DUMMYNET, "dummynet" },
285 pfreason_to_num(compiler_state_t *cstate, const char *reason)
289 i = str2tok(reason, pflog_reasons);
291 bpf_set_error(cstate, "unknown PF reason \"%s\"", reason);
295 static const struct tok pflog_actions[] = {
297 { PF_PASS, "accept" }, /* alias for "pass" */
299 { PF_DROP, "block" }, /* alias for "drop" */
300 { PF_SCRUB, "scrub" },
301 { PF_NOSCRUB, "noscrub" },
303 { PF_NONAT, "nonat" },
304 { PF_BINAT, "binat" },
305 { PF_NOBINAT, "nobinat" },
307 { PF_NORDR, "nordr" },
308 { PF_SYNPROXY_DROP, "synproxy-drop" },
309 #if defined(__FreeBSD__)
310 { PF_DEFER, "defer" },
311 #elif defined(__OpenBSD__)
312 { PF_DEFER, "defer" },
313 { PF_MATCH, "match" },
314 { PF_DIVERT, "divert" },
317 #elif defined(__APPLE__)
318 { PF_DUMMYNET, "dummynet" },
319 { PF_NODUMMYNET, "nodummynet" },
320 { PF_NAT64, "nat64" },
321 { PF_NONAT64, "nonat64" },
327 pfaction_to_num(compiler_state_t *cstate, const char *action)
331 i = str2tok(action, pflog_actions);
333 bpf_set_error(cstate, "unknown PF action \"%s\"", action);
338 * For calls that might return an "an error occurred" value.
340 #define CHECK_INT_VAL(val) if (val == -1) YYABORT
341 #define CHECK_PTR_VAL(val) if (val == NULL) YYABORT
361 %type <blk> expr id nid pid term rterm qid
363 %type <i> pqual dqual aqual ndaqual
365 %type <i> byteop pname relop irelop
367 %type <blk> and or paren not null prog
368 %type <rblk> other pfvar p80211 pllc
369 %type <i> atmtype atmmultitype
371 %type <blk> atmfieldvalue atmvalue atmlistvalue
373 %type <blk> mtp3field
374 %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
377 %token DST SRC HOST GATEWAY
378 %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
379 %token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
380 %token ATALK AARP DECNET LAT SCA MOPRC MOPDL
381 %token TK_BROADCAST TK_MULTICAST
382 %token NUM INBOUND OUTBOUND
384 %token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
385 %token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
388 %token ID EID HID HID6 AID
391 %token IPV6 ICMPV6 AH ESP
393 %token PPPOED PPPOES GENEVE VXLAN
394 %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
398 %token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
399 %token OAM OAMF4 CONNECTMSG METACONNECT
402 %token FISU LSSU MSU HFISU HLSSU HMSU
403 %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
409 %type <i> action reason type subtype type_subtype dir
423 * I'm not sure we have a reason to use yynerrs, but it's
424 * declared, and incremented, whether we need it or not,
425 * which means that Clang 15 will give a "set but not
426 * used" warning. This should suppress the warning for
427 * yynerrs without suppressing it for other variables.
430 CHECK_INT_VAL(finish_parse(cstate, $2.b));
434 null: /* null */ { $$.q = qerr; }
437 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
438 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
439 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
440 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
442 and: AND { $$ = $<blk>0; }
444 or: OR { $$ = $<blk>0; }
447 | pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
448 $$.q = $<blk>0.q))); }
449 | paren pid ')' { $$ = $2; }
451 nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
454 /* Check whether HID/NUM is being used when appropriate */
456 if ($$.q.addr == Q_PORT) {
457 bpf_set_error(cstate, "'port' qualifier applied to IPv4 address and prefix length");
459 } else if ($$.q.addr == Q_PORTRANGE) {
460 bpf_set_error(cstate, "'portrange' qualifier applied to IPv4 address and prefix length");
462 } else if ($$.q.addr == Q_PROTO) {
463 bpf_set_error(cstate, "'proto' qualifier applied to IPv4 address and prefix length");
465 } else if ($$.q.addr == Q_PROTOCHAIN) {
466 bpf_set_error(cstate, "'protochain' qualifier applied to IPv4 address and prefix length");
469 /* The default case in gen_mcode() catches Q_HOST and Q_GATEWAY. */
470 CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3, $$.q)));
474 /* Check whether HID mask HID is being used when appropriate */
476 if ($$.q.addr == Q_PORT) {
477 bpf_set_error(cstate, "'port' qualifier applied to IPv4 address and netmask");
479 } else if ($$.q.addr == Q_PORTRANGE) {
480 bpf_set_error(cstate, "'portrange' qualifier applied to IPv4 address and netmask");
482 } else if ($$.q.addr == Q_PROTO) {
483 bpf_set_error(cstate, "'proto' qualifier applied to IPv4 address and netmask");
485 } else if ($$.q.addr == Q_PROTOCHAIN) {
486 bpf_set_error(cstate, "'protochain' qualifier applied to IPv4 address and netmask");
489 /* The default case in gen_mcode() catches Q_HOST and Q_GATEWAY. */
490 CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0, $$.q)));
494 /* Check whether HID is being used when appropriate */
496 if ($$.q.addr == Q_PORT) {
497 bpf_set_error(cstate, "'port' qualifier applied to IPv4 address");
499 } else if ($$.q.addr == Q_PORTRANGE) {
500 bpf_set_error(cstate, "'portrange' qualifier applied to IPv4 address");
502 } else if ($$.q.addr == Q_PROTO) {
503 bpf_set_error(cstate, "'proto' qualifier applied to IPv4 address");
505 } else if ($$.q.addr == Q_PROTOCHAIN) {
506 bpf_set_error(cstate, "'protochain' qualifier applied to IPv4 address");
509 CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
513 /* Check whether HID6/NUM is being used when appropriate */
515 if ($$.q.addr == Q_PORT) {
516 bpf_set_error(cstate, "'port' qualifier applied to IPv6 address and prefix length");
518 } else if ($$.q.addr == Q_PORTRANGE) {
519 bpf_set_error(cstate, "'portrange' qualifier applied to IPv6 address and prefix length");
521 } else if ($$.q.addr == Q_PROTO) {
522 bpf_set_error(cstate, "'proto' qualifier applied to IPv6 address and prefix length ");
524 } else if ($$.q.addr == Q_PROTOCHAIN) {
525 bpf_set_error(cstate, "'protochain' qualifier applied to IPv6 address and prefix length");
528 /* The default case in gen_mcode6() catches Q_GATEWAY. */
529 CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, $3, $$.q)));
533 /* Check whether HID6 is being used when appropriate */
535 if ($$.q.addr == Q_PORT) {
536 bpf_set_error(cstate, "'port' qualifier applied to IPv6 address");
538 } else if ($$.q.addr == Q_PORTRANGE) {
539 bpf_set_error(cstate, "'portrange' qualifier applied to IPv6 address");
541 } else if ($$.q.addr == Q_PROTO) {
542 bpf_set_error(cstate, "'proto' qualifier applied to IPv6 address");
544 } else if ($$.q.addr == Q_PROTOCHAIN) {
545 bpf_set_error(cstate, "'protochain' qualifier applied to IPv6 address");
548 /* The default case in gen_mcode6() catches Q_GATEWAY. */
549 CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 128, $$.q)));
551 | EID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
552 | AID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
553 | not id { gen_not($2.b); $$ = $2; }
555 not: '!' { $$ = $<blk>0; }
557 paren: '(' { $$ = $<blk>0; }
560 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
561 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
563 qid: pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
564 $$.q = $<blk>0.q))); }
568 | not term { gen_not($2.b); $$ = $2; }
570 head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
571 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
572 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
573 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
576 bpf_set_error(cstate, "protochain not supported");
579 QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
582 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
584 rterm: head id { $$ = $2; }
585 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
586 | pname { CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
587 | arth relop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
589 | arth irelop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
591 | other { $$.b = $1; $$.q = qerr; }
592 | atmtype { CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
593 | atmmultitype { CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
594 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
595 | mtp2type { CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
596 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
598 /* protocol level qualifiers */
600 | { $$ = Q_DEFAULT; }
602 /* 'direction' qualifiers */
603 dqual: SRC { $$ = Q_SRC; }
604 | DST { $$ = Q_DST; }
605 | SRC OR DST { $$ = Q_OR; }
606 | DST OR SRC { $$ = Q_OR; }
607 | SRC AND DST { $$ = Q_AND; }
608 | DST AND SRC { $$ = Q_AND; }
609 | ADDR1 { $$ = Q_ADDR1; }
610 | ADDR2 { $$ = Q_ADDR2; }
611 | ADDR3 { $$ = Q_ADDR3; }
612 | ADDR4 { $$ = Q_ADDR4; }
616 /* address type qualifiers */
617 aqual: HOST { $$ = Q_HOST; }
618 | NET { $$ = Q_NET; }
619 | PORT { $$ = Q_PORT; }
620 | PORTRANGE { $$ = Q_PORTRANGE; }
622 /* non-directional address type qualifiers */
623 ndaqual: GATEWAY { $$ = Q_GATEWAY; }
625 pname: LINK { $$ = Q_LINK; }
627 | ARP { $$ = Q_ARP; }
628 | RARP { $$ = Q_RARP; }
629 | SCTP { $$ = Q_SCTP; }
630 | TCP { $$ = Q_TCP; }
631 | UDP { $$ = Q_UDP; }
632 | ICMP { $$ = Q_ICMP; }
633 | IGMP { $$ = Q_IGMP; }
634 | IGRP { $$ = Q_IGRP; }
635 | PIM { $$ = Q_PIM; }
636 | VRRP { $$ = Q_VRRP; }
637 | CARP { $$ = Q_CARP; }
638 | ATALK { $$ = Q_ATALK; }
639 | AARP { $$ = Q_AARP; }
640 | DECNET { $$ = Q_DECNET; }
641 | LAT { $$ = Q_LAT; }
642 | SCA { $$ = Q_SCA; }
643 | MOPDL { $$ = Q_MOPDL; }
644 | MOPRC { $$ = Q_MOPRC; }
645 | IPV6 { $$ = Q_IPV6; }
646 | ICMPV6 { $$ = Q_ICMPV6; }
648 | ESP { $$ = Q_ESP; }
649 | ISO { $$ = Q_ISO; }
650 | ESIS { $$ = Q_ESIS; }
651 | ISIS { $$ = Q_ISIS; }
652 | L1 { $$ = Q_ISIS_L1; }
653 | L2 { $$ = Q_ISIS_L2; }
654 | IIH { $$ = Q_ISIS_IIH; }
655 | LSP { $$ = Q_ISIS_LSP; }
656 | SNP { $$ = Q_ISIS_SNP; }
657 | PSNP { $$ = Q_ISIS_PSNP; }
658 | CSNP { $$ = Q_ISIS_CSNP; }
659 | CLNP { $$ = Q_CLNP; }
660 | STP { $$ = Q_STP; }
661 | IPX { $$ = Q_IPX; }
662 | NETBEUI { $$ = Q_NETBEUI; }
663 | RADIO { $$ = Q_RADIO; }
665 other: pqual TK_BROADCAST { CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
666 | pqual TK_MULTICAST { CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
667 | LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
668 | GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
669 | CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
670 | INBOUND { CHECK_PTR_VAL(($$ = gen_inbound_outbound(cstate, 0))); }
671 | OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound_outbound(cstate, 1))); }
672 | IFINDEX NUM { CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
673 | VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
674 | VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
675 | MPLS pnum { CHECK_PTR_VAL(($$ = gen_mpls(cstate, $2, 1))); }
676 | MPLS { CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
677 | PPPOED { CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
678 | PPPOES pnum { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, $2, 1))); }
679 | PPPOES { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
680 | GENEVE pnum { CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
681 | GENEVE { CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
682 | VXLAN pnum { CHECK_PTR_VAL(($$ = gen_vxlan(cstate, $2, 1))); }
683 | VXLAN { CHECK_PTR_VAL(($$ = gen_vxlan(cstate, 0, 0))); }
685 | pqual p80211 { $$ = $2; }
689 pfvar: PF_IFNAME ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
690 | PF_RSET ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
691 | PF_RNR NUM { CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
692 | PF_SRNR NUM { CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
693 | PF_REASON reason { CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
694 | PF_ACTION action { CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
697 p80211: TYPE type SUBTYPE subtype
698 { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
699 IEEE80211_FC0_TYPE_MASK |
700 IEEE80211_FC0_SUBTYPE_MASK)));
702 | TYPE type { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
703 IEEE80211_FC0_TYPE_MASK)));
705 | SUBTYPE type_subtype { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
706 IEEE80211_FC0_TYPE_MASK |
707 IEEE80211_FC0_SUBTYPE_MASK)));
709 | DIR dir { CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
712 type: NUM { if (($1 & (~IEEE80211_FC0_TYPE_MASK)) != 0) {
713 bpf_set_error(cstate, "invalid 802.11 type value 0x%02x", $1);
718 | ID { CHECK_PTR_VAL($1);
719 $$ = str2tok($1, ieee80211_types);
721 bpf_set_error(cstate, "unknown 802.11 type name \"%s\"", $1);
727 subtype: NUM { if (($1 & (~IEEE80211_FC0_SUBTYPE_MASK)) != 0) {
728 bpf_set_error(cstate, "invalid 802.11 subtype value 0x%02x", $1);
733 | ID { const struct tok *types = NULL;
737 if (ieee80211_type_subtypes[i].tok == NULL) {
738 /* Ran out of types */
739 bpf_set_error(cstate, "unknown 802.11 type");
742 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
743 types = ieee80211_type_subtypes[i].tok;
748 $$ = str2tok($1, types);
750 bpf_set_error(cstate, "unknown 802.11 subtype name \"%s\"", $1);
756 type_subtype: ID { int i;
759 if (ieee80211_type_subtypes[i].tok == NULL) {
760 /* Ran out of types */
761 bpf_set_error(cstate, "unknown 802.11 type name");
764 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
766 $$ |= ieee80211_type_subtypes[i].type;
773 pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
774 | LLC ID { CHECK_PTR_VAL($2);
775 if (pcapint_strcasecmp($2, "i") == 0) {
776 CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
777 } else if (pcapint_strcasecmp($2, "s") == 0) {
778 CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
779 } else if (pcapint_strcasecmp($2, "u") == 0) {
780 CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
784 subtype = str2tok($2, llc_s_subtypes);
786 CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
788 subtype = str2tok($2, llc_u_subtypes);
790 bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
793 CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
797 /* sigh, "rnr" is already a keyword for PF */
798 | LLC PF_RNR { CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
801 dir: NUM { if (($1 & (~IEEE80211_FC1_DIR_MASK)) != 0) {
802 bpf_set_error(cstate, "invalid 802.11 direction value 0x%x", $1);
807 | ID { CHECK_PTR_VAL($1);
808 if (pcapint_strcasecmp($1, "nods") == 0)
809 $$ = IEEE80211_FC1_DIR_NODS;
810 else if (pcapint_strcasecmp($1, "tods") == 0)
811 $$ = IEEE80211_FC1_DIR_TODS;
812 else if (pcapint_strcasecmp($1, "fromds") == 0)
813 $$ = IEEE80211_FC1_DIR_FROMDS;
814 else if (pcapint_strcasecmp($1, "dstods") == 0)
815 $$ = IEEE80211_FC1_DIR_DSTODS;
817 bpf_set_error(cstate, "unknown 802.11 direction");
823 reason: NUM { $$ = $1; }
824 | ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
827 action: ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
830 relop: '>' { $$ = BPF_JGT; }
831 | GEQ { $$ = BPF_JGE; }
832 | '=' { $$ = BPF_JEQ; }
834 irelop: LEQ { $$ = BPF_JGT; }
835 | '<' { $$ = BPF_JGE; }
836 | NEQ { $$ = BPF_JEQ; }
838 arth: pnum { CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
841 narth: pname '[' arth ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
842 | pname '[' arth ':' NUM ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
843 | arth '+' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
844 | arth '-' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
845 | arth '*' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
846 | arth '/' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
847 | arth '%' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
848 | arth '&' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
849 | arth '|' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
850 | arth '^' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
851 | arth LSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
852 | arth RSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
853 | '-' arth %prec UMINUS { CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
854 | paren narth ')' { $$ = $2; }
855 | LEN { CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
857 byteop: '&' { $$ = '&'; }
864 | paren pnum ')' { $$ = $2; }
866 atmtype: LANE { $$ = A_LANE; }
867 | METAC { $$ = A_METAC; }
868 | BCC { $$ = A_BCC; }
869 | OAMF4EC { $$ = A_OAMF4EC; }
870 | OAMF4SC { $$ = A_OAMF4SC; }
872 | ILMIC { $$ = A_ILMIC; }
874 atmmultitype: OAM { $$ = A_OAM; }
875 | OAMF4 { $$ = A_OAMF4; }
876 | CONNECTMSG { $$ = A_CONNECTMSG; }
877 | METACONNECT { $$ = A_METACONNECT; }
879 /* ATM field types quantifier */
880 atmfield: VPI { $$.atmfieldtype = A_VPI; }
881 | VCI { $$.atmfieldtype = A_VCI; }
883 atmvalue: atmfieldvalue
884 | relop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 0))); }
885 | irelop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 1))); }
886 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
889 $$.atmfieldtype = $<blk>0.atmfieldtype;
890 if ($$.atmfieldtype == A_VPI ||
891 $$.atmfieldtype == A_VCI)
892 CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, $1, BPF_JEQ, 0)));
895 atmlistvalue: atmfieldvalue
896 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
898 /* MTP2 types quantifier */
899 mtp2type: FISU { $$ = M_FISU; }
900 | LSSU { $$ = M_LSSU; }
901 | MSU { $$ = M_MSU; }
902 | HFISU { $$ = MH_FISU; }
903 | HLSSU { $$ = MH_LSSU; }
904 | HMSU { $$ = MH_MSU; }
906 /* MTP3 field types quantifier */
907 mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
908 | OPC { $$.mtp3fieldtype = M_OPC; }
909 | DPC { $$.mtp3fieldtype = M_DPC; }
910 | SLS { $$.mtp3fieldtype = M_SLS; }
911 | HSIO { $$.mtp3fieldtype = MH_SIO; }
912 | HOPC { $$.mtp3fieldtype = MH_OPC; }
913 | HDPC { $$.mtp3fieldtype = MH_DPC; }
914 | HSLS { $$.mtp3fieldtype = MH_SLS; }
916 mtp3value: mtp3fieldvalue
917 | relop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 0))); }
918 | irelop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 1))); }
919 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
921 mtp3fieldvalue: NUM {
922 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
923 if ($$.mtp3fieldtype == M_SIO ||
924 $$.mtp3fieldtype == M_OPC ||
925 $$.mtp3fieldtype == M_DPC ||
926 $$.mtp3fieldtype == M_SLS ||
927 $$.mtp3fieldtype == MH_SIO ||
928 $$.mtp3fieldtype == MH_OPC ||
929 $$.mtp3fieldtype == MH_DPC ||
930 $$.mtp3fieldtype == MH_SLS)
931 CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, $1, BPF_JEQ, 0)));
934 mtp3listvalue: mtp3fieldvalue
935 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }