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.
75 * grammar.h requires gencode.h and sometimes breaks in a polluted namespace
76 * (see ftmacros.h), so include it early.
84 #include <sys/types.h>
85 #include <sys/socket.h>
92 #include <netinet/in.h>
93 #include <arpa/inet.h>
98 #include "diag-control.h"
100 #include "pcap-int.h"
105 #include "ieee80211.h"
107 #include <pcap/namedb.h>
109 #ifdef HAVE_OS_PROTO_H
110 #include "os-proto.h"
115 * Both Berkeley YACC and Bison define yydebug (under whatever name
116 * it has) as a global, but Bison does so only if YYDEBUG is defined.
117 * Berkeley YACC define it even if YYDEBUG isn't defined; declare it
118 * here to suppress a warning.
120 #if !defined(YYDEBUG)
125 * In Berkeley YACC, yynerrs (under whatever name it has) is global,
126 * even if it's building a reentrant parser. In Bison, it's local
127 * in reentrant parsers.
129 * Declare it to squelch a warning.
134 #define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
135 (q).dir = (unsigned char)(d),\
136 (q).addr = (unsigned char)(a)
140 const char *s; /* string */
143 static const struct tok ieee80211_types[] = {
144 { IEEE80211_FC0_TYPE_DATA, "data" },
145 { IEEE80211_FC0_TYPE_MGT, "mgt" },
146 { IEEE80211_FC0_TYPE_MGT, "management" },
147 { IEEE80211_FC0_TYPE_CTL, "ctl" },
148 { IEEE80211_FC0_TYPE_CTL, "control" },
151 static const struct tok ieee80211_mgt_subtypes[] = {
152 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
153 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
154 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
155 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
156 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
157 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
158 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
159 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
160 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
161 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
162 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
163 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
164 { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
165 { IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
166 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
167 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
168 { IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
169 { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
170 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
171 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
174 static const struct tok ieee80211_ctl_subtypes[] = {
175 { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
176 { IEEE80211_FC0_SUBTYPE_RTS, "rts" },
177 { IEEE80211_FC0_SUBTYPE_CTS, "cts" },
178 { IEEE80211_FC0_SUBTYPE_ACK, "ack" },
179 { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
180 { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
183 static const struct tok ieee80211_data_subtypes[] = {
184 { IEEE80211_FC0_SUBTYPE_DATA, "data" },
185 { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
186 { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
187 { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
188 { IEEE80211_FC0_SUBTYPE_NODATA, "null" },
189 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
190 { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
191 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
192 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
193 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
194 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
195 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
196 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
197 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
198 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
201 static const struct tok llc_s_subtypes[] = {
207 static const struct tok llc_u_subtypes[] = {
210 { LLC_DISC, "disc" },
212 { LLC_SABME, "sabme" },
213 { LLC_TEST, "test" },
215 { LLC_FRMR, "frmr" },
220 const struct tok *tok;
222 static const struct type2tok ieee80211_type_subtypes[] = {
223 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
224 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
225 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
230 str2tok(const char *str, const struct tok *toks)
234 for (i = 0; toks[i].s != NULL; i++) {
235 if (pcap_strcasecmp(toks[i].s, str) == 0) {
237 * Just in case somebody is using this to
238 * generate values of -1/0xFFFFFFFF.
239 * That won't work, as it's indistinguishable
250 static const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
253 yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
255 bpf_set_error(cstate, "can't parse filter expression: %s", msg);
258 static const struct tok pflog_reasons[] = {
259 { PFRES_MATCH, "match" },
260 { PFRES_BADOFF, "bad-offset" },
261 { PFRES_FRAG, "fragment" },
262 { PFRES_SHORT, "short" },
263 { PFRES_NORM, "normalize" },
264 { PFRES_MEMORY, "memory" },
265 { PFRES_TS, "bad-timestamp" },
266 { PFRES_CONGEST, "congestion" },
267 { PFRES_IPOPTIONS, "ip-option" },
268 { PFRES_PROTCKSUM, "proto-cksum" },
269 { PFRES_BADSTATE, "state-mismatch" },
270 { PFRES_STATEINS, "state-insert" },
271 { PFRES_MAXSTATES, "state-limit" },
272 { PFRES_SRCLIMIT, "src-limit" },
273 { PFRES_SYNPROXY, "synproxy" },
274 #if defined(__FreeBSD__)
275 { PFRES_MAPFAILED, "map-failed" },
276 #elif defined(__NetBSD__)
277 { PFRES_STATELOCKED, "state-locked" },
278 #elif defined(__OpenBSD__)
279 { PFRES_TRANSLATE, "translate" },
280 { PFRES_NOROUTE, "no-route" },
281 #elif defined(__APPLE__)
282 { PFRES_DUMMYNET, "dummynet" },
288 pfreason_to_num(compiler_state_t *cstate, const char *reason)
292 i = str2tok(reason, pflog_reasons);
294 bpf_set_error(cstate, "unknown PF reason \"%s\"", reason);
298 static const struct tok pflog_actions[] = {
300 { PF_PASS, "accept" }, /* alias for "pass" */
302 { PF_DROP, "block" }, /* alias for "drop" */
303 { PF_SCRUB, "scrub" },
304 { PF_NOSCRUB, "noscrub" },
306 { PF_NONAT, "nonat" },
307 { PF_BINAT, "binat" },
308 { PF_NOBINAT, "nobinat" },
310 { PF_NORDR, "nordr" },
311 { PF_SYNPROXY_DROP, "synproxy-drop" },
312 #if defined(__FreeBSD__)
313 { PF_DEFER, "defer" },
314 #elif defined(__OpenBSD__)
315 { PF_DEFER, "defer" },
316 { PF_MATCH, "match" },
317 { PF_DIVERT, "divert" },
320 #elif defined(__APPLE__)
321 { PF_DUMMYNET, "dummynet" },
322 { PF_NODUMMYNET, "nodummynet" },
323 { PF_NAT64, "nat64" },
324 { PF_NONAT64, "nonat64" },
330 pfaction_to_num(compiler_state_t *cstate, const char *action)
334 i = str2tok(action, pflog_actions);
336 bpf_set_error(cstate, "unknown PF action \"%s\"", action);
341 * For calls that might return an "an error occurred" value.
343 #define CHECK_INT_VAL(val) if (val == -1) YYABORT
344 #define CHECK_PTR_VAL(val) if (val == NULL) YYABORT
364 %type <blk> expr id nid pid term rterm qid
366 %type <i> pqual dqual aqual ndaqual
368 %type <i> byteop pname relop irelop
370 %type <blk> and or paren not null prog
371 %type <rblk> other pfvar p80211 pllc
372 %type <i> atmtype atmmultitype
374 %type <blk> atmfieldvalue atmvalue atmlistvalue
376 %type <blk> mtp3field
377 %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
380 %token DST SRC HOST GATEWAY
381 %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
382 %token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
383 %token ATALK AARP DECNET LAT SCA MOPRC MOPDL
384 %token TK_BROADCAST TK_MULTICAST
385 %token NUM INBOUND OUTBOUND
387 %token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
388 %token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
391 %token ID EID HID HID6 AID
394 %token IPV6 ICMPV6 AH ESP
396 %token PPPOED PPPOES GENEVE
397 %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
401 %token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
402 %token OAM OAMF4 CONNECTMSG METACONNECT
405 %token FISU LSSU MSU HFISU HLSSU HMSU
406 %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
412 %type <i> action reason type subtype type_subtype dir
425 CHECK_INT_VAL(finish_parse(cstate, $2.b));
429 null: /* null */ { $$.q = qerr; }
432 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
433 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
434 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
435 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
437 and: AND { $$ = $<blk>0; }
439 or: OR { $$ = $<blk>0; }
442 | pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
443 $$.q = $<blk>0.q))); }
444 | paren pid ')' { $$ = $2; }
446 nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
447 | HID '/' NUM { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
448 $$.q = $<blk>0.q))); }
449 | HID NETMASK HID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
450 $$.q = $<blk>0.q))); }
453 /* Decide how to parse HID based on proto */
455 if ($$.q.addr == Q_PORT) {
456 bpf_set_error(cstate, "'port' modifier applied to ip host");
458 } else if ($$.q.addr == Q_PORTRANGE) {
459 bpf_set_error(cstate, "'portrange' modifier applied to ip host");
461 } else if ($$.q.addr == Q_PROTO) {
462 bpf_set_error(cstate, "'proto' modifier applied to ip host");
464 } else if ($$.q.addr == Q_PROTOCHAIN) {
465 bpf_set_error(cstate, "'protochain' modifier applied to ip host");
468 CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
473 CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
476 bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
477 "in this configuration");
484 CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
487 bpf_set_error(cstate, "'ip6addr' not supported "
488 "in this configuration");
492 | EID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
493 | AID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
494 | not id { gen_not($2.b); $$ = $2; }
496 not: '!' { $$ = $<blk>0; }
498 paren: '(' { $$ = $<blk>0; }
501 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
502 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
504 qid: pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
505 $$.q = $<blk>0.q))); }
509 | not term { gen_not($2.b); $$ = $2; }
511 head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
512 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
513 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
514 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
517 bpf_set_error(cstate, "protochain not supported");
520 QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
523 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
525 rterm: head id { $$ = $2; }
526 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
527 | pname { CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
528 | arth relop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
530 | arth irelop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
532 | other { $$.b = $1; $$.q = qerr; }
533 | atmtype { CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
534 | atmmultitype { CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
535 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
536 | mtp2type { CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
537 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
539 /* protocol level qualifiers */
541 | { $$ = Q_DEFAULT; }
543 /* 'direction' qualifiers */
544 dqual: SRC { $$ = Q_SRC; }
545 | DST { $$ = Q_DST; }
546 | SRC OR DST { $$ = Q_OR; }
547 | DST OR SRC { $$ = Q_OR; }
548 | SRC AND DST { $$ = Q_AND; }
549 | DST AND SRC { $$ = Q_AND; }
550 | ADDR1 { $$ = Q_ADDR1; }
551 | ADDR2 { $$ = Q_ADDR2; }
552 | ADDR3 { $$ = Q_ADDR3; }
553 | ADDR4 { $$ = Q_ADDR4; }
557 /* address type qualifiers */
558 aqual: HOST { $$ = Q_HOST; }
559 | NET { $$ = Q_NET; }
560 | PORT { $$ = Q_PORT; }
561 | PORTRANGE { $$ = Q_PORTRANGE; }
563 /* non-directional address type qualifiers */
564 ndaqual: GATEWAY { $$ = Q_GATEWAY; }
566 pname: LINK { $$ = Q_LINK; }
568 | ARP { $$ = Q_ARP; }
569 | RARP { $$ = Q_RARP; }
570 | SCTP { $$ = Q_SCTP; }
571 | TCP { $$ = Q_TCP; }
572 | UDP { $$ = Q_UDP; }
573 | ICMP { $$ = Q_ICMP; }
574 | IGMP { $$ = Q_IGMP; }
575 | IGRP { $$ = Q_IGRP; }
576 | PIM { $$ = Q_PIM; }
577 | VRRP { $$ = Q_VRRP; }
578 | CARP { $$ = Q_CARP; }
579 | ATALK { $$ = Q_ATALK; }
580 | AARP { $$ = Q_AARP; }
581 | DECNET { $$ = Q_DECNET; }
582 | LAT { $$ = Q_LAT; }
583 | SCA { $$ = Q_SCA; }
584 | MOPDL { $$ = Q_MOPDL; }
585 | MOPRC { $$ = Q_MOPRC; }
586 | IPV6 { $$ = Q_IPV6; }
587 | ICMPV6 { $$ = Q_ICMPV6; }
589 | ESP { $$ = Q_ESP; }
590 | ISO { $$ = Q_ISO; }
591 | ESIS { $$ = Q_ESIS; }
592 | ISIS { $$ = Q_ISIS; }
593 | L1 { $$ = Q_ISIS_L1; }
594 | L2 { $$ = Q_ISIS_L2; }
595 | IIH { $$ = Q_ISIS_IIH; }
596 | LSP { $$ = Q_ISIS_LSP; }
597 | SNP { $$ = Q_ISIS_SNP; }
598 | PSNP { $$ = Q_ISIS_PSNP; }
599 | CSNP { $$ = Q_ISIS_CSNP; }
600 | CLNP { $$ = Q_CLNP; }
601 | STP { $$ = Q_STP; }
602 | IPX { $$ = Q_IPX; }
603 | NETBEUI { $$ = Q_NETBEUI; }
604 | RADIO { $$ = Q_RADIO; }
606 other: pqual TK_BROADCAST { CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
607 | pqual TK_MULTICAST { CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
608 | LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
609 | GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
610 | CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
611 | INBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
612 | OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
613 | IFINDEX NUM { CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
614 | VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
615 | VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
616 | MPLS pnum { CHECK_PTR_VAL(($$ = gen_mpls(cstate, $2, 1))); }
617 | MPLS { CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
618 | PPPOED { CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
619 | PPPOES pnum { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, $2, 1))); }
620 | PPPOES { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
621 | GENEVE pnum { CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
622 | GENEVE { CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
624 | pqual p80211 { $$ = $2; }
628 pfvar: PF_IFNAME ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
629 | PF_RSET ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
630 | PF_RNR NUM { CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
631 | PF_SRNR NUM { CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
632 | PF_REASON reason { CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
633 | PF_ACTION action { CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
636 p80211: TYPE type SUBTYPE subtype
637 { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
638 IEEE80211_FC0_TYPE_MASK |
639 IEEE80211_FC0_SUBTYPE_MASK)));
641 | TYPE type { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
642 IEEE80211_FC0_TYPE_MASK)));
644 | SUBTYPE type_subtype { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
645 IEEE80211_FC0_TYPE_MASK |
646 IEEE80211_FC0_SUBTYPE_MASK)));
648 | DIR dir { CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
651 type: NUM { if (($1 & (~IEEE80211_FC0_TYPE_MASK)) != 0) {
652 bpf_set_error(cstate, "invalid 802.11 type value 0x%02x", $1);
657 | ID { CHECK_PTR_VAL($1);
658 $$ = str2tok($1, ieee80211_types);
660 bpf_set_error(cstate, "unknown 802.11 type name \"%s\"", $1);
666 subtype: NUM { if (($1 & (~IEEE80211_FC0_SUBTYPE_MASK)) != 0) {
667 bpf_set_error(cstate, "invalid 802.11 subtype value 0x%02x", $1);
672 | ID { const struct tok *types = NULL;
676 if (ieee80211_type_subtypes[i].tok == NULL) {
677 /* Ran out of types */
678 bpf_set_error(cstate, "unknown 802.11 type");
681 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
682 types = ieee80211_type_subtypes[i].tok;
687 $$ = str2tok($1, types);
689 bpf_set_error(cstate, "unknown 802.11 subtype name \"%s\"", $1);
695 type_subtype: ID { int i;
698 if (ieee80211_type_subtypes[i].tok == NULL) {
699 /* Ran out of types */
700 bpf_set_error(cstate, "unknown 802.11 type name");
703 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
705 $$ |= ieee80211_type_subtypes[i].type;
712 pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
713 | LLC ID { CHECK_PTR_VAL($2);
714 if (pcap_strcasecmp($2, "i") == 0) {
715 CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
716 } else if (pcap_strcasecmp($2, "s") == 0) {
717 CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
718 } else if (pcap_strcasecmp($2, "u") == 0) {
719 CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
723 subtype = str2tok($2, llc_s_subtypes);
725 CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
727 subtype = str2tok($2, llc_u_subtypes);
729 bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
732 CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
736 /* sigh, "rnr" is already a keyword for PF */
737 | LLC PF_RNR { CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
740 dir: NUM { $$ = (int)$1; }
741 | ID { CHECK_PTR_VAL($1);
742 if (pcap_strcasecmp($1, "nods") == 0)
743 $$ = IEEE80211_FC1_DIR_NODS;
744 else if (pcap_strcasecmp($1, "tods") == 0)
745 $$ = IEEE80211_FC1_DIR_TODS;
746 else if (pcap_strcasecmp($1, "fromds") == 0)
747 $$ = IEEE80211_FC1_DIR_FROMDS;
748 else if (pcap_strcasecmp($1, "dstods") == 0)
749 $$ = IEEE80211_FC1_DIR_DSTODS;
751 bpf_set_error(cstate, "unknown 802.11 direction");
757 reason: NUM { $$ = $1; }
758 | ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
761 action: ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
764 relop: '>' { $$ = BPF_JGT; }
765 | GEQ { $$ = BPF_JGE; }
766 | '=' { $$ = BPF_JEQ; }
768 irelop: LEQ { $$ = BPF_JGT; }
769 | '<' { $$ = BPF_JGE; }
770 | NEQ { $$ = BPF_JEQ; }
772 arth: pnum { CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
775 narth: pname '[' arth ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
776 | pname '[' arth ':' NUM ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
777 | arth '+' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
778 | arth '-' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
779 | arth '*' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
780 | arth '/' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
781 | arth '%' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
782 | arth '&' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
783 | arth '|' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
784 | arth '^' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
785 | arth LSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
786 | arth RSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
787 | '-' arth %prec UMINUS { CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
788 | paren narth ')' { $$ = $2; }
789 | LEN { CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
791 byteop: '&' { $$ = '&'; }
798 | paren pnum ')' { $$ = $2; }
800 atmtype: LANE { $$ = A_LANE; }
801 | METAC { $$ = A_METAC; }
802 | BCC { $$ = A_BCC; }
803 | OAMF4EC { $$ = A_OAMF4EC; }
804 | OAMF4SC { $$ = A_OAMF4SC; }
806 | ILMIC { $$ = A_ILMIC; }
808 atmmultitype: OAM { $$ = A_OAM; }
809 | OAMF4 { $$ = A_OAMF4; }
810 | CONNECTMSG { $$ = A_CONNECTMSG; }
811 | METACONNECT { $$ = A_METACONNECT; }
813 /* ATM field types quantifier */
814 atmfield: VPI { $$.atmfieldtype = A_VPI; }
815 | VCI { $$.atmfieldtype = A_VCI; }
817 atmvalue: atmfieldvalue
818 | relop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 0))); }
819 | irelop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 1))); }
820 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
823 $$.atmfieldtype = $<blk>0.atmfieldtype;
824 if ($$.atmfieldtype == A_VPI ||
825 $$.atmfieldtype == A_VCI)
826 CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, $1, BPF_JEQ, 0)));
829 atmlistvalue: atmfieldvalue
830 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
832 /* MTP2 types quantifier */
833 mtp2type: FISU { $$ = M_FISU; }
834 | LSSU { $$ = M_LSSU; }
835 | MSU { $$ = M_MSU; }
836 | HFISU { $$ = MH_FISU; }
837 | HLSSU { $$ = MH_LSSU; }
838 | HMSU { $$ = MH_MSU; }
840 /* MTP3 field types quantifier */
841 mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
842 | OPC { $$.mtp3fieldtype = M_OPC; }
843 | DPC { $$.mtp3fieldtype = M_DPC; }
844 | SLS { $$.mtp3fieldtype = M_SLS; }
845 | HSIO { $$.mtp3fieldtype = MH_SIO; }
846 | HOPC { $$.mtp3fieldtype = MH_OPC; }
847 | HDPC { $$.mtp3fieldtype = MH_DPC; }
848 | HSLS { $$.mtp3fieldtype = MH_SLS; }
850 mtp3value: mtp3fieldvalue
851 | relop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 0))); }
852 | irelop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 1))); }
853 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
855 mtp3fieldvalue: NUM {
856 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
857 if ($$.mtp3fieldtype == M_SIO ||
858 $$.mtp3fieldtype == M_OPC ||
859 $$.mtp3fieldtype == M_DPC ||
860 $$.mtp3fieldtype == M_SLS ||
861 $$.mtp3fieldtype == MH_SIO ||
862 $$.mtp3fieldtype == MH_OPC ||
863 $$.mtp3fieldtype == MH_DPC ||
864 $$.mtp3fieldtype == MH_SLS)
865 CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, $1, BPF_JEQ, 0)));
868 mtp3listvalue: mtp3fieldvalue
869 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }