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 * And we need to pass the compiler state to the scanner.
24 %parse-param {compiler_state_t *cstate}
28 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
29 * The Regents of the University of California. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that: (1) source code distributions
33 * retain the above copyright notice and this paragraph in its entirety, (2)
34 * distributions including binary code include the above copyright notice and
35 * this paragraph in its entirety in the documentation or other materials
36 * provided with the distribution, and (3) all advertising materials mentioning
37 * features or use of this software display the following acknowledgement:
38 * ``This product includes software developed by the University of California,
39 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
40 * the University nor the names of its contributors may be used to endorse
41 * or promote products derived from this software without specific prior
43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
44 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
55 #include <pcap-stdinc.h>
57 #include <sys/types.h>
58 #include <sys/socket.h>
69 #include <netinet/in.h>
70 #include <arpa/inet.h>
81 #ifdef HAVE_NET_PFVAR_H
83 #include <netpfil/pf/pf.h>
84 #include <net/if_pflog.h>
87 #include "ieee80211.h"
88 #include <pcap/namedb.h>
90 #ifdef HAVE_OS_PROTO_H
94 #define QSET(q, p, d, a) (q).proto = (p),\
100 const char *s; /* string */
103 static const struct tok ieee80211_types[] = {
104 { IEEE80211_FC0_TYPE_DATA, "data" },
105 { IEEE80211_FC0_TYPE_MGT, "mgt" },
106 { IEEE80211_FC0_TYPE_MGT, "management" },
107 { IEEE80211_FC0_TYPE_CTL, "ctl" },
108 { IEEE80211_FC0_TYPE_CTL, "control" },
111 static const struct tok ieee80211_mgt_subtypes[] = {
112 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
113 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
114 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
115 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
116 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
117 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
118 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
119 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
120 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
121 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
122 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
123 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
124 { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
125 { IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
126 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
127 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
128 { IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
129 { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
130 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
131 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
134 static const struct tok ieee80211_ctl_subtypes[] = {
135 { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
136 { IEEE80211_FC0_SUBTYPE_RTS, "rts" },
137 { IEEE80211_FC0_SUBTYPE_CTS, "cts" },
138 { IEEE80211_FC0_SUBTYPE_ACK, "ack" },
139 { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
140 { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
143 static const struct tok ieee80211_data_subtypes[] = {
144 { IEEE80211_FC0_SUBTYPE_DATA, "data" },
145 { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
146 { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
147 { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
148 { IEEE80211_FC0_SUBTYPE_NODATA, "null" },
149 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
150 { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
151 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
152 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
153 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
154 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
155 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
156 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
157 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
158 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
161 static const struct tok llc_s_subtypes[] = {
167 static const struct tok llc_u_subtypes[] = {
170 { LLC_DISC, "disc" },
172 { LLC_SABME, "sabme" },
173 { LLC_TEST, "test" },
175 { LLC_FRMR, "frmr" },
180 const struct tok *tok;
182 static const struct type2tok ieee80211_type_subtypes[] = {
183 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
184 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
185 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
190 str2tok(const char *str, const struct tok *toks)
194 for (i = 0; toks[i].s != NULL; i++) {
195 if (pcap_strcasecmp(toks[i].s, str) == 0)
201 static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
204 yyerror(void *yyscanner, compiler_state_t *cstate, const char *msg)
206 bpf_syntax_error(cstate, msg);
210 #ifdef HAVE_NET_PFVAR_H
212 pfreason_to_num(compiler_state_t *cstate, const char *reason)
214 const char *reasons[] = PFRES_NAMES;
217 for (i = 0; reasons[i]; i++) {
218 if (pcap_strcasecmp(reason, reasons[i]) == 0)
221 bpf_error(cstate, "unknown PF reason");
226 pfaction_to_num(compiler_state_t *cstate, const char *action)
228 if (pcap_strcasecmp(action, "pass") == 0 ||
229 pcap_strcasecmp(action, "accept") == 0)
231 else if (pcap_strcasecmp(action, "drop") == 0 ||
232 pcap_strcasecmp(action, "block") == 0)
234 #if HAVE_PF_NAT_THROUGH_PF_NORDR
235 else if (pcap_strcasecmp(action, "rdr") == 0)
237 else if (pcap_strcasecmp(action, "nat") == 0)
239 else if (pcap_strcasecmp(action, "binat") == 0)
241 else if (pcap_strcasecmp(action, "nordr") == 0)
245 bpf_error(cstate, "unknown PF action");
249 #else /* !HAVE_NET_PFVAR_H */
251 pfreason_to_num(compiler_state_t *cstate, const char *reason)
253 bpf_error(cstate, "libpcap was compiled on a machine without pf support");
256 /* this is to make the VC compiler happy */
261 pfaction_to_num(compiler_state_t *cstate, const char *action)
263 bpf_error(cstate, "libpcap was compiled on a machine without pf support");
266 /* this is to make the VC compiler happy */
269 #endif /* HAVE_NET_PFVAR_H */
288 %type <blk> expr id nid pid term rterm qid
290 %type <i> pqual dqual aqual ndaqual
292 %type <i> byteop pname pnum relop irelop
293 %type <blk> and or paren not null prog
294 %type <rblk> other pfvar p80211 pllc
295 %type <i> atmtype atmmultitype
297 %type <blk> atmfieldvalue atmvalue atmlistvalue
299 %type <blk> mtp3field
300 %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
303 %token DST SRC HOST GATEWAY
304 %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
305 %token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
306 %token ATALK AARP DECNET LAT SCA MOPRC MOPDL
307 %token TK_BROADCAST TK_MULTICAST
308 %token NUM INBOUND OUTBOUND
309 %token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
310 %token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
313 %token ID EID HID HID6 AID
316 %token IPV6 ICMPV6 AH ESP
318 %token PPPOED PPPOES GENEVE
319 %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
323 %token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
324 %token OAM OAMF4 CONNECTMSG METACONNECT
327 %token FISU LSSU MSU HFISU HLSSU HMSU
328 %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
335 %type <i> NUM action reason type subtype type_subtype dir
348 finish_parse(cstate, $2.b);
352 null: /* null */ { $$.q = qerr; }
355 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
356 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
357 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
358 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
360 and: AND { $$ = $<blk>0; }
362 or: OR { $$ = $<blk>0; }
365 | pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
367 | paren pid ')' { $$ = $2; }
369 nid: ID { $$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q); }
370 | HID '/' NUM { $$.b = gen_mcode(cstate, $1, NULL, $3,
372 | HID NETMASK HID { $$.b = gen_mcode(cstate, $1, $3, 0,
375 /* Decide how to parse HID based on proto */
377 if ($$.q.addr == Q_PORT)
378 bpf_error(cstate, "'port' modifier applied to ip host");
379 else if ($$.q.addr == Q_PORTRANGE)
380 bpf_error(cstate, "'portrange' modifier applied to ip host");
381 else if ($$.q.addr == Q_PROTO)
382 bpf_error(cstate, "'proto' modifier applied to ip host");
383 else if ($$.q.addr == Q_PROTOCHAIN)
384 bpf_error(cstate, "'protochain' modifier applied to ip host");
385 $$.b = gen_ncode(cstate, $1, 0, $$.q);
389 $$.b = gen_mcode6(cstate, $1, NULL, $3,
392 bpf_error(cstate, "'ip6addr/prefixlen' not supported "
393 "in this configuration");
398 $$.b = gen_mcode6(cstate, $1, 0, 128,
401 bpf_error(cstate, "'ip6addr' not supported "
402 "in this configuration");
406 $$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q);
408 * $1 was allocated by "pcap_ether_aton()",
409 * so we must free it now that we're done
415 $$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q);
417 * $1 was allocated by "pcap_ether_aton()",
418 * so we must free it now that we're done
423 | not id { gen_not($2.b); $$ = $2; }
425 not: '!' { $$ = $<blk>0; }
427 paren: '(' { $$ = $<blk>0; }
430 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
431 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
433 qid: pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
438 | not term { gen_not($2.b); $$ = $2; }
440 head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
441 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
442 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
443 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
444 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
445 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
447 rterm: head id { $$ = $2; }
448 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
449 | pname { $$.b = gen_proto_abbrev(cstate, $1); $$.q = qerr; }
450 | arth relop arth { $$.b = gen_relation(cstate, $2, $1, $3, 0);
452 | arth irelop arth { $$.b = gen_relation(cstate, $2, $1, $3, 1);
454 | other { $$.b = $1; $$.q = qerr; }
455 | atmtype { $$.b = gen_atmtype_abbrev(cstate, $1); $$.q = qerr; }
456 | atmmultitype { $$.b = gen_atmmulti_abbrev(cstate, $1); $$.q = qerr; }
457 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
458 | mtp2type { $$.b = gen_mtp2type_abbrev(cstate, $1); $$.q = qerr; }
459 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
461 /* protocol level qualifiers */
463 | { $$ = Q_DEFAULT; }
465 /* 'direction' qualifiers */
466 dqual: SRC { $$ = Q_SRC; }
467 | DST { $$ = Q_DST; }
468 | SRC OR DST { $$ = Q_OR; }
469 | DST OR SRC { $$ = Q_OR; }
470 | SRC AND DST { $$ = Q_AND; }
471 | DST AND SRC { $$ = Q_AND; }
472 | ADDR1 { $$ = Q_ADDR1; }
473 | ADDR2 { $$ = Q_ADDR2; }
474 | ADDR3 { $$ = Q_ADDR3; }
475 | ADDR4 { $$ = Q_ADDR4; }
479 /* address type qualifiers */
480 aqual: HOST { $$ = Q_HOST; }
481 | NET { $$ = Q_NET; }
482 | PORT { $$ = Q_PORT; }
483 | PORTRANGE { $$ = Q_PORTRANGE; }
485 /* non-directional address type qualifiers */
486 ndaqual: GATEWAY { $$ = Q_GATEWAY; }
488 pname: LINK { $$ = Q_LINK; }
490 | ARP { $$ = Q_ARP; }
491 | RARP { $$ = Q_RARP; }
492 | SCTP { $$ = Q_SCTP; }
493 | TCP { $$ = Q_TCP; }
494 | UDP { $$ = Q_UDP; }
495 | ICMP { $$ = Q_ICMP; }
496 | IGMP { $$ = Q_IGMP; }
497 | IGRP { $$ = Q_IGRP; }
498 | PIM { $$ = Q_PIM; }
499 | VRRP { $$ = Q_VRRP; }
500 | CARP { $$ = Q_CARP; }
501 | ATALK { $$ = Q_ATALK; }
502 | AARP { $$ = Q_AARP; }
503 | DECNET { $$ = Q_DECNET; }
504 | LAT { $$ = Q_LAT; }
505 | SCA { $$ = Q_SCA; }
506 | MOPDL { $$ = Q_MOPDL; }
507 | MOPRC { $$ = Q_MOPRC; }
508 | IPV6 { $$ = Q_IPV6; }
509 | ICMPV6 { $$ = Q_ICMPV6; }
511 | ESP { $$ = Q_ESP; }
512 | ISO { $$ = Q_ISO; }
513 | ESIS { $$ = Q_ESIS; }
514 | ISIS { $$ = Q_ISIS; }
515 | L1 { $$ = Q_ISIS_L1; }
516 | L2 { $$ = Q_ISIS_L2; }
517 | IIH { $$ = Q_ISIS_IIH; }
518 | LSP { $$ = Q_ISIS_LSP; }
519 | SNP { $$ = Q_ISIS_SNP; }
520 | PSNP { $$ = Q_ISIS_PSNP; }
521 | CSNP { $$ = Q_ISIS_CSNP; }
522 | CLNP { $$ = Q_CLNP; }
523 | STP { $$ = Q_STP; }
524 | IPX { $$ = Q_IPX; }
525 | NETBEUI { $$ = Q_NETBEUI; }
526 | RADIO { $$ = Q_RADIO; }
528 other: pqual TK_BROADCAST { $$ = gen_broadcast(cstate, $1); }
529 | pqual TK_MULTICAST { $$ = gen_multicast(cstate, $1); }
530 | LESS NUM { $$ = gen_less(cstate, $2); }
531 | GREATER NUM { $$ = gen_greater(cstate, $2); }
532 | CBYTE NUM byteop NUM { $$ = gen_byteop(cstate, $3, $2, $4); }
533 | INBOUND { $$ = gen_inbound(cstate, 0); }
534 | OUTBOUND { $$ = gen_inbound(cstate, 1); }
535 | VLAN pnum { $$ = gen_vlan(cstate, $2); }
536 | VLAN { $$ = gen_vlan(cstate, -1); }
537 | MPLS pnum { $$ = gen_mpls(cstate, $2); }
538 | MPLS { $$ = gen_mpls(cstate, -1); }
539 | PPPOED { $$ = gen_pppoed(cstate); }
540 | PPPOES pnum { $$ = gen_pppoes(cstate, $2); }
541 | PPPOES { $$ = gen_pppoes(cstate, -1); }
542 | GENEVE pnum { $$ = gen_geneve(cstate, $2); }
543 | GENEVE { $$ = gen_geneve(cstate, -1); }
545 | pqual p80211 { $$ = $2; }
549 pfvar: PF_IFNAME ID { $$ = gen_pf_ifname(cstate, $2); }
550 | PF_RSET ID { $$ = gen_pf_ruleset(cstate, $2); }
551 | PF_RNR NUM { $$ = gen_pf_rnr(cstate, $2); }
552 | PF_SRNR NUM { $$ = gen_pf_srnr(cstate, $2); }
553 | PF_REASON reason { $$ = gen_pf_reason(cstate, $2); }
554 | PF_ACTION action { $$ = gen_pf_action(cstate, $2); }
557 p80211: TYPE type SUBTYPE subtype
558 { $$ = gen_p80211_type(cstate, $2 | $4,
559 IEEE80211_FC0_TYPE_MASK |
560 IEEE80211_FC0_SUBTYPE_MASK);
562 | TYPE type { $$ = gen_p80211_type(cstate, $2,
563 IEEE80211_FC0_TYPE_MASK);
565 | SUBTYPE type_subtype { $$ = gen_p80211_type(cstate, $2,
566 IEEE80211_FC0_TYPE_MASK |
567 IEEE80211_FC0_SUBTYPE_MASK);
569 | DIR dir { $$ = gen_p80211_fcdir(cstate, $2); }
573 | ID { $$ = str2tok($1, ieee80211_types);
575 bpf_error(cstate, "unknown 802.11 type name");
580 | ID { const struct tok *types = NULL;
583 if (ieee80211_type_subtypes[i].tok == NULL) {
584 /* Ran out of types */
585 bpf_error(cstate, "unknown 802.11 type");
588 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
589 types = ieee80211_type_subtypes[i].tok;
594 $$ = str2tok($1, types);
596 bpf_error(cstate, "unknown 802.11 subtype name");
600 type_subtype: ID { int i;
602 if (ieee80211_type_subtypes[i].tok == NULL) {
603 /* Ran out of types */
604 bpf_error(cstate, "unknown 802.11 type name");
607 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
609 $$ |= ieee80211_type_subtypes[i].type;
616 pllc: LLC { $$ = gen_llc(cstate); }
617 | LLC ID { if (pcap_strcasecmp($2, "i") == 0)
618 $$ = gen_llc_i(cstate);
619 else if (pcap_strcasecmp($2, "s") == 0)
620 $$ = gen_llc_s(cstate);
621 else if (pcap_strcasecmp($2, "u") == 0)
622 $$ = gen_llc_u(cstate);
626 subtype = str2tok($2, llc_s_subtypes);
628 $$ = gen_llc_s_subtype(cstate, subtype);
630 subtype = str2tok($2, llc_u_subtypes);
632 bpf_error(cstate, "unknown LLC type name \"%s\"", $2);
633 $$ = gen_llc_u_subtype(cstate, subtype);
637 /* sigh, "rnr" is already a keyword for PF */
638 | LLC PF_RNR { $$ = gen_llc_s_subtype(cstate, LLC_RNR); }
642 | ID { if (pcap_strcasecmp($1, "nods") == 0)
643 $$ = IEEE80211_FC1_DIR_NODS;
644 else if (pcap_strcasecmp($1, "tods") == 0)
645 $$ = IEEE80211_FC1_DIR_TODS;
646 else if (pcap_strcasecmp($1, "fromds") == 0)
647 $$ = IEEE80211_FC1_DIR_FROMDS;
648 else if (pcap_strcasecmp($1, "dstods") == 0)
649 $$ = IEEE80211_FC1_DIR_DSTODS;
651 bpf_error(cstate, "unknown 802.11 direction");
655 reason: NUM { $$ = $1; }
656 | ID { $$ = pfreason_to_num(cstate, $1); }
659 action: ID { $$ = pfaction_to_num(cstate, $1); }
662 relop: '>' { $$ = BPF_JGT; }
663 | GEQ { $$ = BPF_JGE; }
664 | '=' { $$ = BPF_JEQ; }
666 irelop: LEQ { $$ = BPF_JGT; }
667 | '<' { $$ = BPF_JGE; }
668 | NEQ { $$ = BPF_JEQ; }
670 arth: pnum { $$ = gen_loadi(cstate, $1); }
673 narth: pname '[' arth ']' { $$ = gen_load(cstate, $1, $3, 1); }
674 | pname '[' arth ':' NUM ']' { $$ = gen_load(cstate, $1, $3, $5); }
675 | arth '+' arth { $$ = gen_arth(cstate, BPF_ADD, $1, $3); }
676 | arth '-' arth { $$ = gen_arth(cstate, BPF_SUB, $1, $3); }
677 | arth '*' arth { $$ = gen_arth(cstate, BPF_MUL, $1, $3); }
678 | arth '/' arth { $$ = gen_arth(cstate, BPF_DIV, $1, $3); }
679 | arth '%' arth { $$ = gen_arth(cstate, BPF_MOD, $1, $3); }
680 | arth '&' arth { $$ = gen_arth(cstate, BPF_AND, $1, $3); }
681 | arth '|' arth { $$ = gen_arth(cstate, BPF_OR, $1, $3); }
682 | arth '^' arth { $$ = gen_arth(cstate, BPF_XOR, $1, $3); }
683 | arth LSH arth { $$ = gen_arth(cstate, BPF_LSH, $1, $3); }
684 | arth RSH arth { $$ = gen_arth(cstate, BPF_RSH, $1, $3); }
685 | '-' arth %prec UMINUS { $$ = gen_neg(cstate, $2); }
686 | paren narth ')' { $$ = $2; }
687 | LEN { $$ = gen_loadlen(cstate); }
689 byteop: '&' { $$ = '&'; }
696 | paren pnum ')' { $$ = $2; }
698 atmtype: LANE { $$ = A_LANE; }
699 | METAC { $$ = A_METAC; }
700 | BCC { $$ = A_BCC; }
701 | OAMF4EC { $$ = A_OAMF4EC; }
702 | OAMF4SC { $$ = A_OAMF4SC; }
704 | ILMIC { $$ = A_ILMIC; }
706 atmmultitype: OAM { $$ = A_OAM; }
707 | OAMF4 { $$ = A_OAMF4; }
708 | CONNECTMSG { $$ = A_CONNECTMSG; }
709 | METACONNECT { $$ = A_METACONNECT; }
711 /* ATM field types quantifier */
712 atmfield: VPI { $$.atmfieldtype = A_VPI; }
713 | VCI { $$.atmfieldtype = A_VCI; }
715 atmvalue: atmfieldvalue
716 | relop NUM { $$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
717 | irelop NUM { $$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
718 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
721 $$.atmfieldtype = $<blk>0.atmfieldtype;
722 if ($$.atmfieldtype == A_VPI ||
723 $$.atmfieldtype == A_VCI)
724 $$.b = gen_atmfield_code(cstate, $$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
727 atmlistvalue: atmfieldvalue
728 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
730 /* MTP2 types quantifier */
731 mtp2type: FISU { $$ = M_FISU; }
732 | LSSU { $$ = M_LSSU; }
733 | MSU { $$ = M_MSU; }
734 | HFISU { $$ = MH_FISU; }
735 | HLSSU { $$ = MH_LSSU; }
736 | HMSU { $$ = MH_MSU; }
738 /* MTP3 field types quantifier */
739 mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
740 | OPC { $$.mtp3fieldtype = M_OPC; }
741 | DPC { $$.mtp3fieldtype = M_DPC; }
742 | SLS { $$.mtp3fieldtype = M_SLS; }
743 | HSIO { $$.mtp3fieldtype = MH_SIO; }
744 | HOPC { $$.mtp3fieldtype = MH_OPC; }
745 | HDPC { $$.mtp3fieldtype = MH_DPC; }
746 | HSLS { $$.mtp3fieldtype = MH_SLS; }
748 mtp3value: mtp3fieldvalue
749 | relop NUM { $$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
750 | irelop NUM { $$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
751 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
753 mtp3fieldvalue: NUM {
754 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
755 if ($$.mtp3fieldtype == M_SIO ||
756 $$.mtp3fieldtype == M_OPC ||
757 $$.mtp3fieldtype == M_DPC ||
758 $$.mtp3fieldtype == M_SLS ||
759 $$.mtp3fieldtype == MH_SIO ||
760 $$.mtp3fieldtype == MH_OPC ||
761 $$.mtp3fieldtype == MH_DPC ||
762 $$.mtp3fieldtype == MH_SLS)
763 $$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
766 mtp3listvalue: mtp3fieldvalue
767 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }