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