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