133965Sjdp%{ 2218822Sdim/* 3218822Sdim * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 433965Sjdp * The Regents of the University of California. All rights reserved. 533965Sjdp * 6218822Sdim * Redistribution and use in source and binary forms, with or without 733965Sjdp * modification, are permitted provided that: (1) source code distributions 8218822Sdim * retain the above copyright notice and this paragraph in its entirety, (2) 9218822Sdim * distributions including binary code include the above copyright notice and 10218822Sdim * this paragraph in its entirety in the documentation or other materials 11218822Sdim * provided with the distribution, and (3) all advertising materials mentioning 1233965Sjdp * features or use of this software display the following acknowledgement: 13218822Sdim * ``This product includes software developed by the University of California, 14218822Sdim * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15218822Sdim * the University nor the names of its contributors may be used to endorse 16218822Sdim * or promote products derived from this software without specific prior 1733965Sjdp * written permission. 18218822Sdim * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19218822Sdim * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20218822Sdim * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2133965Sjdp * 22218822Sdim * $FreeBSD$ 2333965Sjdp */ 2433965Sjdp#ifndef lint 2533965Sjdpstatic const char rcsid[] _U_ = 26218822Sdim "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.101 2007-11-18 02:03:52 guy Exp $ (LBL)"; 2733965Sjdp#endif 2833965Sjdp 2933965Sjdp#ifdef HAVE_CONFIG_H 3033965Sjdp#include "config.h" 3133965Sjdp#endif 3233965Sjdp 3333965Sjdp#ifdef WIN32 3433965Sjdp#include <pcap-stdinc.h> 3533965Sjdp#else /* WIN32 */ 3633965Sjdp#include <sys/types.h> 3733965Sjdp#include <sys/socket.h> 3833965Sjdp#endif /* WIN32 */ 3933965Sjdp 4033965Sjdp#include <stdlib.h> 4133965Sjdp 4233965Sjdp#ifndef WIN32 4333965Sjdp#if __STDC__ 4433965Sjdpstruct mbuf; 4533965Sjdpstruct rtentry; 4633965Sjdp#endif 4733965Sjdp 4833965Sjdp#include <netinet/in.h> 4933965Sjdp#include <arpa/inet.h> 5033965Sjdp#endif /* WIN32 */ 5133965Sjdp 5233965Sjdp#include <stdio.h> 5333965Sjdp 5433965Sjdp#include "pcap-int.h" 5533965Sjdp 5633965Sjdp#include "gencode.h" 5733965Sjdp#ifdef HAVE_NET_PFVAR_H 5833965Sjdp#include <net/if.h> 5933965Sjdp#include <net/pfvar.h> 6033965Sjdp#include <net/if_pflog.h> 6133965Sjdp#endif 6233965Sjdp#include "ieee80211.h" 6333965Sjdp#include <pcap/namedb.h> 6433965Sjdp 6533965Sjdp#ifdef HAVE_OS_PROTO_H 6633965Sjdp#include "os-proto.h" 6733965Sjdp#endif 6833965Sjdp 6933965Sjdp#define QSET(q, p, d, a) (q).proto = (p),\ 7033965Sjdp (q).dir = (d),\ 71130561Sobrien (q).addr = (a) 7233965Sjdp 7333965Sjdpstruct tok { 7433965Sjdp int v; /* value */ 7533965Sjdp const char *s; /* string */ 7633965Sjdp}; 7733965Sjdp 7860484Sobrienstatic const struct tok ieee80211_types[] = { 7933965Sjdp { IEEE80211_FC0_TYPE_DATA, "data" }, 8033965Sjdp { IEEE80211_FC0_TYPE_MGT, "mgt" }, 8133965Sjdp { IEEE80211_FC0_TYPE_MGT, "management" }, 8233965Sjdp { IEEE80211_FC0_TYPE_CTL, "ctl" }, 8333965Sjdp { IEEE80211_FC0_TYPE_CTL, "control" }, 8433965Sjdp { 0, NULL } 8533965Sjdp}; 8633965Sjdpstatic const struct tok ieee80211_mgt_subtypes[] = { 8733965Sjdp { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" }, 8833965Sjdp { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" }, 8933965Sjdp { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" }, 9033965Sjdp { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" }, 91218822Sdim { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" }, 92218822Sdim { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" }, 93218822Sdim { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" }, 94218822Sdim { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" }, 9533965Sjdp { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" }, 9633965Sjdp { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" }, 9733965Sjdp { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" }, 9833965Sjdp { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" }, 9933965Sjdp { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" }, 10033965Sjdp { IEEE80211_FC0_SUBTYPE_ATIM, "atim" }, 10133965Sjdp { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" }, 10233965Sjdp { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" }, 10333965Sjdp { IEEE80211_FC0_SUBTYPE_AUTH, "auth" }, 104130561Sobrien { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" }, 10533965Sjdp { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" }, 10633965Sjdp { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" }, 10733965Sjdp { 0, NULL } 10833965Sjdp}; 10933965Sjdpstatic const struct tok ieee80211_ctl_subtypes[] = { 11033965Sjdp { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" }, 111130561Sobrien { IEEE80211_FC0_SUBTYPE_RTS, "rts" }, 11233965Sjdp { IEEE80211_FC0_SUBTYPE_CTS, "cts" }, 11333965Sjdp { IEEE80211_FC0_SUBTYPE_ACK, "ack" }, 11433965Sjdp { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" }, 11533965Sjdp { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" }, 11633965Sjdp { 0, NULL } 11733965Sjdp}; 118130561Sobrienstatic const struct tok ieee80211_data_subtypes[] = { 11933965Sjdp { IEEE80211_FC0_SUBTYPE_DATA, "data" }, 12033965Sjdp { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" }, 121130561Sobrien { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" }, 12233965Sjdp { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" }, 12333965Sjdp { IEEE80211_FC0_SUBTYPE_NODATA, "null" }, 12433965Sjdp { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" }, 12533965Sjdp { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" }, 12633965Sjdp { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" }, 12733965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" }, 12833965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" }, 12933965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" }, 13033965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" }, 13133965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" }, 13233965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" }, 13333965Sjdp { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" }, 13433965Sjdp { 0, NULL } 13533965Sjdp}; 13633965Sjdpstruct type2tok { 13733965Sjdp int type; 13833965Sjdp const struct tok *tok; 13933965Sjdp}; 14033965Sjdpstatic const struct type2tok ieee80211_type_subtypes[] = { 141130561Sobrien { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes }, 14233965Sjdp { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes }, 14333965Sjdp { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes }, 14433965Sjdp { 0, NULL } 14533965Sjdp}; 14633965Sjdp 14733965Sjdpstatic int 14833965Sjdpstr2tok(const char *str, const struct tok *toks) 14933965Sjdp{ 15033965Sjdp int i; 15133965Sjdp 15233965Sjdp for (i = 0; toks[i].s != NULL; i++) { 15333965Sjdp if (pcap_strcasecmp(toks[i].s, str) == 0) 15433965Sjdp return (toks[i].v); 15533965Sjdp } 15633965Sjdp return (-1); 15733965Sjdp} 15833965Sjdp 15933965Sjdpint n_errors = 0; 16033965Sjdp 16133965Sjdpstatic struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; 16233965Sjdp 16333965Sjdpstatic void 16433965Sjdpyyerror(const char *msg) 16533965Sjdp{ 16633965Sjdp ++n_errors; 16733965Sjdp bpf_error("%s", msg); 16833965Sjdp /* NOTREACHED */ 16933965Sjdp} 17033965Sjdp 17133965Sjdp#ifdef NEED_YYPARSE_WRAPPER 17233965Sjdpint yyparse(void); 17333965Sjdp 17433965Sjdpint 17533965Sjdppcap_parse() 17633965Sjdp{ 17733965Sjdp return (yyparse()); 17833965Sjdp} 17933965Sjdp#endif 18033965Sjdp 18133965Sjdp#ifdef HAVE_NET_PFVAR_H 18233965Sjdpstatic int 18333965Sjdppfreason_to_num(const char *reason) 18433965Sjdp{ 18533965Sjdp const char *reasons[] = PFRES_NAMES; 18633965Sjdp int i; 18733965Sjdp 18833965Sjdp for (i = 0; reasons[i]; i++) { 18933965Sjdp if (pcap_strcasecmp(reason, reasons[i]) == 0) 19033965Sjdp return (i); 19133965Sjdp } 19233965Sjdp bpf_error("unknown PF reason"); 19333965Sjdp /*NOTREACHED*/ 19433965Sjdp} 19533965Sjdp 19633965Sjdpstatic int 19733965Sjdppfaction_to_num(const char *action) 19833965Sjdp{ 19933965Sjdp if (pcap_strcasecmp(action, "pass") == 0 || 20033965Sjdp pcap_strcasecmp(action, "accept") == 0) 20133965Sjdp return (PF_PASS); 20233965Sjdp else if (pcap_strcasecmp(action, "drop") == 0 || 20333965Sjdp pcap_strcasecmp(action, "block") == 0) 20433965Sjdp return (PF_DROP); 20533965Sjdp#if HAVE_PF_NAT_THROUGH_PF_NORDR 20633965Sjdp else if (pcap_strcasecmp(action, "rdr") == 0) 20733965Sjdp return (PF_RDR); 20833965Sjdp else if (pcap_strcasecmp(action, "nat") == 0) 20933965Sjdp return (PF_NAT); 21033965Sjdp else if (pcap_strcasecmp(action, "binat") == 0) 21133965Sjdp return (PF_BINAT); 21233965Sjdp else if (pcap_strcasecmp(action, "nordr") == 0) 21333965Sjdp return (PF_NORDR); 21433965Sjdp#endif 21533965Sjdp else { 21633965Sjdp bpf_error("unknown PF action"); 21733965Sjdp /*NOTREACHED*/ 21833965Sjdp } 21933965Sjdp} 22033965Sjdp#else /* !HAVE_NET_PFVAR_H */ 22133965Sjdpstatic int 22233965Sjdppfreason_to_num(const char *reason) 22333965Sjdp{ 22433965Sjdp bpf_error("libpcap was compiled on a machine without pf support"); 22533965Sjdp /*NOTREACHED*/ 22633965Sjdp 22733965Sjdp /* this is to make the VC compiler happy */ 22833965Sjdp return -1; 22933965Sjdp} 23033965Sjdp 23133965Sjdpstatic int 23233965Sjdppfaction_to_num(const char *action) 233218822Sdim{ 234218822Sdim bpf_error("libpcap was compiled on a machine without pf support"); 235218822Sdim /*NOTREACHED*/ 23633965Sjdp 23733965Sjdp /* this is to make the VC compiler happy */ 23833965Sjdp return -1; 23933965Sjdp} 24033965Sjdp#endif /* HAVE_NET_PFVAR_H */ 241218822Sdim%} 24233965Sjdp 243218822Sdim%union { 244218822Sdim int i; 24533965Sjdp bpf_u_int32 h; 24633965Sjdp u_char *e; 24733965Sjdp char *s; 24833965Sjdp struct stmt *stmt; 24933965Sjdp struct arth *a; 25033965Sjdp struct { 25133965Sjdp struct qual q; 25233965Sjdp int atmfieldtype; 25333965Sjdp int mtp3fieldtype; 25433965Sjdp struct block *b; 25533965Sjdp } blk; 25633965Sjdp struct block *rblk; 25733965Sjdp} 25833965Sjdp 25933965Sjdp%type <blk> expr id nid pid term rterm qid 26033965Sjdp%type <blk> head 26133965Sjdp%type <i> pqual dqual aqual ndaqual 26233965Sjdp%type <a> arth narth 26333965Sjdp%type <i> byteop pname pnum relop irelop 26433965Sjdp%type <blk> and or paren not null prog 26533965Sjdp%type <rblk> other pfvar p80211 26633965Sjdp%type <i> atmtype atmmultitype 26733965Sjdp%type <blk> atmfield 26833965Sjdp%type <blk> atmfieldvalue atmvalue atmlistvalue 26933965Sjdp%type <i> mtp2type 27033965Sjdp%type <blk> mtp3field 27133965Sjdp%type <blk> mtp3fieldvalue mtp3value mtp3listvalue 27233965Sjdp 27333965Sjdp 27433965Sjdp%token DST SRC HOST GATEWAY 27577298Sobrien%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE 27633965Sjdp%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP 27733965Sjdp%token ATALK AARP DECNET LAT SCA MOPRC MOPDL 27833965Sjdp%token TK_BROADCAST TK_MULTICAST 27933965Sjdp%token NUM INBOUND OUTBOUND 28033965Sjdp%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION 28133965Sjdp%token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA 28233965Sjdp%token LINK 28333965Sjdp%token GEQ LEQ NEQ 28433965Sjdp%token ID EID HID HID6 AID 28533965Sjdp%token LSH RSH 28633965Sjdp%token LEN 28733965Sjdp%token IPV6 ICMPV6 AH ESP 28833965Sjdp%token VLAN MPLS 28933965Sjdp%token PPPOED PPPOES 29033965Sjdp%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP 29133965Sjdp%token STP 29233965Sjdp%token IPX 29333965Sjdp%token NETBEUI 29433965Sjdp%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC 29533965Sjdp%token OAM OAMF4 CONNECTMSG METACONNECT 29633965Sjdp%token VPI VCI 29733965Sjdp%token RADIO 29833965Sjdp%token FISU LSSU MSU 29933965Sjdp%token SIO OPC DPC SLS 30033965Sjdp 301218822Sdim%type <s> ID 30233965Sjdp%type <e> EID 303218822Sdim%type <e> AID 304218822Sdim%type <s> HID HID6 305218822Sdim%type <i> NUM action reason type subtype type_subtype dir 306218822Sdim 307218822Sdim%left OR AND 308218822Sdim%nonassoc '!' 309218822Sdim%left '|' 310218822Sdim%left '&' 311218822Sdim%left LSH RSH 312218822Sdim%left '+' '-' 313218822Sdim%left '*' '/' 314218822Sdim%nonassoc UMINUS 315218822Sdim%% 316218822Sdimprog: null expr 317218822Sdim{ 318218822Sdim finish_parse($2.b); 319218822Sdim} 320218822Sdim | null 321218822Sdim ; 322218822Sdimnull: /* null */ { $$.q = qerr; } 323218822Sdim ; 324218822Sdimexpr: term 325218822Sdim | expr and term { gen_and($1.b, $3.b); $$ = $3; } 326218822Sdim | expr and id { gen_and($1.b, $3.b); $$ = $3; } 327218822Sdim | expr or term { gen_or($1.b, $3.b); $$ = $3; } 328218822Sdim | expr or id { gen_or($1.b, $3.b); $$ = $3; } 329218822Sdim ; 330218822Sdimand: AND { $$ = $<blk>0; } 331218822Sdim ; 332218822Sdimor: OR { $$ = $<blk>0; } 333218822Sdim ; 334218822Sdimid: nid 335218822Sdim | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1, 336218822Sdim $$.q = $<blk>0.q); } 337218822Sdim | paren pid ')' { $$ = $2; } 338218822Sdim ; 339218822Sdimnid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); } 340218822Sdim | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3, 341218822Sdim $$.q = $<blk>0.q); } 342218822Sdim | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0, 343218822Sdim $$.q = $<blk>0.q); } 344218822Sdim | HID { 345218822Sdim /* Decide how to parse HID based on proto */ 346218822Sdim $$.q = $<blk>0.q; 347218822Sdim if ($$.q.addr == Q_PORT) 348218822Sdim bpf_error("'port' modifier applied to ip host"); 349218822Sdim else if ($$.q.addr == Q_PORTRANGE) 350218822Sdim bpf_error("'portrange' modifier applied to ip host"); 351218822Sdim else if ($$.q.addr == Q_PROTO) 352218822Sdim bpf_error("'proto' modifier applied to ip host"); 353218822Sdim else if ($$.q.addr == Q_PROTOCHAIN) 354218822Sdim bpf_error("'protochain' modifier applied to ip host"); 355218822Sdim $$.b = gen_ncode($1, 0, $$.q); 35633965Sjdp } 35733965Sjdp | HID6 '/' NUM { 358130561Sobrien#ifdef INET6 359218822Sdim $$.b = gen_mcode6($1, NULL, $3, 360218822Sdim $$.q = $<blk>0.q); 361218822Sdim#else 362218822Sdim bpf_error("'ip6addr/prefixlen' not supported " 363218822Sdim "in this configuration"); 364218822Sdim#endif /*INET6*/ 36533965Sjdp } 36633965Sjdp | HID6 { 36733965Sjdp#ifdef INET6 36833965Sjdp $$.b = gen_mcode6($1, 0, 128, 36933965Sjdp $$.q = $<blk>0.q); 370218822Sdim#else 37133965Sjdp bpf_error("'ip6addr' not supported " 37233965Sjdp "in this configuration"); 37333965Sjdp#endif /*INET6*/ 374130561Sobrien } 37533965Sjdp | EID { 376218822Sdim $$.b = gen_ecode($1, $$.q = $<blk>0.q); 37733965Sjdp /* 37833965Sjdp * $1 was allocated by "pcap_ether_aton()", 37933965Sjdp * so we must free it now that we're done 380130561Sobrien * with it. 38133965Sjdp */ 382218822Sdim free($1); 38333965Sjdp } 384218822Sdim | AID { 385218822Sdim $$.b = gen_acode($1, $$.q = $<blk>0.q); 386218822Sdim /* 38733965Sjdp * $1 was allocated by "pcap_ether_aton()", 388130561Sobrien * so we must free it now that we're done 38933965Sjdp * with it. 39033965Sjdp */ 39133965Sjdp free($1); 39233965Sjdp } 393130561Sobrien | not id { gen_not($2.b); $$ = $2; } 394218822Sdim ; 395218822Sdimnot: '!' { $$ = $<blk>0; } 396218822Sdim ; 397218822Sdimparen: '(' { $$ = $<blk>0; } 398218822Sdim ; 39933965Sjdppid: nid 400218822Sdim | qid and id { gen_and($1.b, $3.b); $$ = $3; } 401218822Sdim | qid or id { gen_or($1.b, $3.b); $$ = $3; } 40233965Sjdp ; 40333965Sjdpqid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1, 40433965Sjdp $$.q = $<blk>0.q); } 40533965Sjdp | pid 40633965Sjdp ; 407218822Sdimterm: rterm 40833965Sjdp | not term { gen_not($2.b); $$ = $2; } 409218822Sdim ; 41033965Sjdphead: pqual dqual aqual { QSET($$.q, $1, $2, $3); } 41133965Sjdp | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); } 41233965Sjdp | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); } 41333965Sjdp | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); } 41433965Sjdp | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); } 41533965Sjdp | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); } 416218822Sdim ; 417218822Sdimrterm: head id { $$ = $2; } 418218822Sdim | paren expr ')' { $$.b = $2.b; $$.q = $1.q; } 419218822Sdim | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; } 42033965Sjdp | arth relop arth { $$.b = gen_relation($2, $1, $3, 0); 421218822Sdim $$.q = qerr; } 422218822Sdim | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1); 423218822Sdim $$.q = qerr; } 42433965Sjdp | other { $$.b = $1; $$.q = qerr; } 42533965Sjdp | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; } 42633965Sjdp | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; } 42777298Sobrien | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; } 42833965Sjdp | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; } 42933965Sjdp | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; } 43033965Sjdp ; 43133965Sjdp/* protocol level qualifiers */ 43233965Sjdppqual: pname 43333965Sjdp | { $$ = Q_DEFAULT; } 43433965Sjdp ; 43533965Sjdp/* 'direction' qualifiers */ 436104834Sobriendqual: SRC { $$ = Q_SRC; } 43733965Sjdp | DST { $$ = Q_DST; } 43833965Sjdp | SRC OR DST { $$ = Q_OR; } 43933965Sjdp | DST OR SRC { $$ = Q_OR; } 44033965Sjdp | SRC AND DST { $$ = Q_AND; } 44133965Sjdp | DST AND SRC { $$ = Q_AND; } 442218822Sdim | ADDR1 { $$ = Q_ADDR1; } 44333965Sjdp | ADDR2 { $$ = Q_ADDR2; } 44433965Sjdp | ADDR3 { $$ = Q_ADDR3; } 44533965Sjdp | ADDR4 { $$ = Q_ADDR4; } 44633965Sjdp | RA { $$ = Q_RA; } 44733965Sjdp | TA { $$ = Q_TA; } 44833965Sjdp ; 44933965Sjdp/* address type qualifiers */ 45033965Sjdpaqual: HOST { $$ = Q_HOST; } 451218822Sdim | NET { $$ = Q_NET; } 45233965Sjdp | PORT { $$ = Q_PORT; } 453218822Sdim | PORTRANGE { $$ = Q_PORTRANGE; } 454218822Sdim ; 455218822Sdim/* non-directional address type qualifiers */ 45633965Sjdpndaqual: GATEWAY { $$ = Q_GATEWAY; } 45733965Sjdp ; 45833965Sjdppname: LINK { $$ = Q_LINK; } 45933965Sjdp | IP { $$ = Q_IP; } 460218822Sdim | ARP { $$ = Q_ARP; } 46133965Sjdp | RARP { $$ = Q_RARP; } 46233965Sjdp | SCTP { $$ = Q_SCTP; } 46333965Sjdp | TCP { $$ = Q_TCP; } 464218822Sdim | UDP { $$ = Q_UDP; } 46533965Sjdp | ICMP { $$ = Q_ICMP; } 466104834Sobrien | IGMP { $$ = Q_IGMP; } 46733965Sjdp | IGRP { $$ = Q_IGRP; } 46833965Sjdp | PIM { $$ = Q_PIM; } 46933965Sjdp | VRRP { $$ = Q_VRRP; } 47033965Sjdp | CARP { $$ = Q_CARP; } 47133965Sjdp | ATALK { $$ = Q_ATALK; } 47233965Sjdp | AARP { $$ = Q_AARP; } 473218822Sdim | DECNET { $$ = Q_DECNET; } 47433965Sjdp | LAT { $$ = Q_LAT; } 475218822Sdim | SCA { $$ = Q_SCA; } 476218822Sdim | MOPDL { $$ = Q_MOPDL; } 477218822Sdim | MOPRC { $$ = Q_MOPRC; } 478218822Sdim | IPV6 { $$ = Q_IPV6; } 479218822Sdim | ICMPV6 { $$ = Q_ICMPV6; } 480218822Sdim | AH { $$ = Q_AH; } 481218822Sdim | ESP { $$ = Q_ESP; } 482218822Sdim | ISO { $$ = Q_ISO; } 483218822Sdim | ESIS { $$ = Q_ESIS; } 484218822Sdim | ISIS { $$ = Q_ISIS; } 485218822Sdim | L1 { $$ = Q_ISIS_L1; } 486218822Sdim | L2 { $$ = Q_ISIS_L2; } 487218822Sdim | IIH { $$ = Q_ISIS_IIH; } 488218822Sdim | LSP { $$ = Q_ISIS_LSP; } 489218822Sdim | SNP { $$ = Q_ISIS_SNP; } 490218822Sdim | PSNP { $$ = Q_ISIS_PSNP; } 491218822Sdim | CSNP { $$ = Q_ISIS_CSNP; } 492218822Sdim | CLNP { $$ = Q_CLNP; } 493218822Sdim | STP { $$ = Q_STP; } 494218822Sdim | IPX { $$ = Q_IPX; } 495218822Sdim | NETBEUI { $$ = Q_NETBEUI; } 496218822Sdim | RADIO { $$ = Q_RADIO; } 497218822Sdim ; 498218822Sdimother: pqual TK_BROADCAST { $$ = gen_broadcast($1); } 499218822Sdim | pqual TK_MULTICAST { $$ = gen_multicast($1); } 500218822Sdim | LESS NUM { $$ = gen_less($2); } 501218822Sdim | GREATER NUM { $$ = gen_greater($2); } 502218822Sdim | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); } 503218822Sdim | INBOUND { $$ = gen_inbound(0); } 504218822Sdim | OUTBOUND { $$ = gen_inbound(1); } 505218822Sdim | VLAN pnum { $$ = gen_vlan($2); } 506218822Sdim | VLAN { $$ = gen_vlan(-1); } 507218822Sdim | MPLS pnum { $$ = gen_mpls($2); } 508218822Sdim | MPLS { $$ = gen_mpls(-1); } 509218822Sdim | PPPOED { $$ = gen_pppoed(); } 510218822Sdim | PPPOES { $$ = gen_pppoes(); } 511218822Sdim | pfvar { $$ = $1; } 512218822Sdim | pqual p80211 { $$ = $2; } 51333965Sjdp ; 51433965Sjdp 51533965Sjdppfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); } 51633965Sjdp | PF_RSET ID { $$ = gen_pf_ruleset($2); } 51733965Sjdp | PF_RNR NUM { $$ = gen_pf_rnr($2); } 51833965Sjdp | PF_SRNR NUM { $$ = gen_pf_srnr($2); } 519218822Sdim | PF_REASON reason { $$ = gen_pf_reason($2); } 520218822Sdim | PF_ACTION action { $$ = gen_pf_action($2); } 521218822Sdim ; 52233965Sjdp 52333965Sjdpp80211: TYPE type SUBTYPE subtype 52433965Sjdp { $$ = gen_p80211_type($2 | $4, 52533965Sjdp IEEE80211_FC0_TYPE_MASK | 52633965Sjdp IEEE80211_FC0_SUBTYPE_MASK); 52733965Sjdp } 528218822Sdim | TYPE type { $$ = gen_p80211_type($2, 52933965Sjdp IEEE80211_FC0_TYPE_MASK); 53033965Sjdp } 53133965Sjdp | SUBTYPE type_subtype { $$ = gen_p80211_type($2, 53233965Sjdp IEEE80211_FC0_TYPE_MASK | 53333965Sjdp IEEE80211_FC0_SUBTYPE_MASK); 53433965Sjdp } 53533965Sjdp | DIR dir { $$ = gen_p80211_fcdir($2); } 53633965Sjdp ; 53733965Sjdp 53833965Sjdptype: NUM 53933965Sjdp | ID { $$ = str2tok($1, ieee80211_types); 54033965Sjdp if ($$ == -1) 54133965Sjdp bpf_error("unknown 802.11 type name"); 54233965Sjdp } 543218822Sdim ; 544218822Sdim 545218822Sdimsubtype: NUM 54633965Sjdp | ID { const struct tok *types = NULL; 547218822Sdim int i; 54833965Sjdp for (i = 0;; i++) { 54933965Sjdp if (ieee80211_type_subtypes[i].tok == NULL) { 55033965Sjdp /* Ran out of types */ 55133965Sjdp bpf_error("unknown 802.11 type"); 55233965Sjdp break; 55333965Sjdp } 55433965Sjdp if ($<i>-1 == ieee80211_type_subtypes[i].type) { 555218822Sdim types = ieee80211_type_subtypes[i].tok; 556218822Sdim break; 557218822Sdim } 558218822Sdim } 559218822Sdim 560218822Sdim $$ = str2tok($1, types); 561218822Sdim if ($$ == -1) 562218822Sdim bpf_error("unknown 802.11 subtype name"); 563218822Sdim } 564218822Sdim ; 565218822Sdim 566218822Sdimtype_subtype: ID { int i; 56733965Sjdp for (i = 0;; i++) { 56833965Sjdp if (ieee80211_type_subtypes[i].tok == NULL) { 56933965Sjdp /* Ran out of types */ 570218822Sdim bpf_error("unknown 802.11 type name"); 571218822Sdim break; 572218822Sdim } 57333965Sjdp $$ = str2tok($1, ieee80211_type_subtypes[i].tok); 57433965Sjdp if ($$ != -1) { 57533965Sjdp $$ |= ieee80211_type_subtypes[i].type; 576218822Sdim break; 57733965Sjdp } 57833965Sjdp } 57933965Sjdp } 58033965Sjdp ; 58133965Sjdp 582218822Sdimdir: NUM 583218822Sdim | ID { if (pcap_strcasecmp($1, "nods") == 0) 58433965Sjdp $$ = IEEE80211_FC1_DIR_NODS; 585218822Sdim else if (pcap_strcasecmp($1, "tods") == 0) 586218822Sdim $$ = IEEE80211_FC1_DIR_TODS; 58733965Sjdp else if (pcap_strcasecmp($1, "fromds") == 0) 58833965Sjdp $$ = IEEE80211_FC1_DIR_FROMDS; 589218822Sdim else if (pcap_strcasecmp($1, "dstods") == 0) 590218822Sdim $$ = IEEE80211_FC1_DIR_DSTODS; 591218822Sdim else 592218822Sdim bpf_error("unknown 802.11 direction"); 593218822Sdim } 594218822Sdim ; 595218822Sdim 596218822Sdimreason: NUM { $$ = $1; } 597218822Sdim | ID { $$ = pfreason_to_num($1); } 598218822Sdim ; 599218822Sdim 600218822Sdimaction: ID { $$ = pfaction_to_num($1); } 601218822Sdim ; 602218822Sdim 603218822Sdimrelop: '>' { $$ = BPF_JGT; } 604218822Sdim | GEQ { $$ = BPF_JGE; } 605218822Sdim | '=' { $$ = BPF_JEQ; } 606218822Sdim ; 60733965Sjdpirelop: LEQ { $$ = BPF_JGT; } 60833965Sjdp | '<' { $$ = BPF_JGE; } 60933965Sjdp | NEQ { $$ = BPF_JEQ; } 61033965Sjdp ; 61133965Sjdparth: pnum { $$ = gen_loadi($1); } 61233965Sjdp | narth 61333965Sjdp ; 61433965Sjdpnarth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); } 61533965Sjdp | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); } 61633965Sjdp | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); } 61733965Sjdp | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); } 61833965Sjdp | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); } 61933965Sjdp | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); } 62033965Sjdp | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); } 62133965Sjdp | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); } 62233965Sjdp | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); } 62333965Sjdp | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); } 62433965Sjdp | '-' arth %prec UMINUS { $$ = gen_neg($2); } 62533965Sjdp | paren narth ')' { $$ = $2; } 62633965Sjdp | LEN { $$ = gen_loadlen(); } 62733965Sjdp ; 62833965Sjdpbyteop: '&' { $$ = '&'; } 62933965Sjdp | '|' { $$ = '|'; } 63033965Sjdp | '<' { $$ = '<'; } 63133965Sjdp | '>' { $$ = '>'; } 63233965Sjdp | '=' { $$ = '='; } 63333965Sjdp ; 63433965Sjdppnum: NUM 63533965Sjdp | paren pnum ')' { $$ = $2; } 63633965Sjdp ; 63733965Sjdpatmtype: LANE { $$ = A_LANE; } 63833965Sjdp | LLC { $$ = A_LLC; } 63933965Sjdp | METAC { $$ = A_METAC; } 64033965Sjdp | BCC { $$ = A_BCC; } 64133965Sjdp | OAMF4EC { $$ = A_OAMF4EC; } 64233965Sjdp | OAMF4SC { $$ = A_OAMF4SC; } 643130561Sobrien | SC { $$ = A_SC; } 64433965Sjdp | ILMIC { $$ = A_ILMIC; } 64533965Sjdp ; 64633965Sjdpatmmultitype: OAM { $$ = A_OAM; } 64733965Sjdp | OAMF4 { $$ = A_OAMF4; } 64833965Sjdp | CONNECTMSG { $$ = A_CONNECTMSG; } 649218822Sdim | METACONNECT { $$ = A_METACONNECT; } 650218822Sdim ; 651218822Sdim /* ATM field types quantifier */ 65233965Sjdpatmfield: VPI { $$.atmfieldtype = A_VPI; } 65333965Sjdp | VCI { $$.atmfieldtype = A_VCI; } 65433965Sjdp ; 65533965Sjdpatmvalue: atmfieldvalue 65633965Sjdp | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); } 657218822Sdim | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); } 658218822Sdim | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; } 659218822Sdim ; 66033965Sjdpatmfieldvalue: NUM { 66133965Sjdp $$.atmfieldtype = $<blk>0.atmfieldtype; 66233965Sjdp if ($$.atmfieldtype == A_VPI || 663218822Sdim $$.atmfieldtype == A_VCI) 664218822Sdim $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0); 66533965Sjdp } 66633965Sjdp ; 66733965Sjdpatmlistvalue: atmfieldvalue 66833965Sjdp | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; } 66933965Sjdp ; 67033965Sjdp /* MTP2 types quantifier */ 67133965Sjdpmtp2type: FISU { $$ = M_FISU; } 67233965Sjdp | LSSU { $$ = M_LSSU; } 67333965Sjdp | MSU { $$ = M_MSU; } 67433965Sjdp ; 67533965Sjdp /* MTP3 field types quantifier */ 67633965Sjdpmtp3field: SIO { $$.mtp3fieldtype = M_SIO; } 67733965Sjdp | OPC { $$.mtp3fieldtype = M_OPC; } 67833965Sjdp | DPC { $$.mtp3fieldtype = M_DPC; } 67933965Sjdp | SLS { $$.mtp3fieldtype = M_SLS; } 68033965Sjdp ; 68133965Sjdpmtp3value: mtp3fieldvalue 68233965Sjdp | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); } 68333965Sjdp | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); } 68433965Sjdp | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; } 685218822Sdim ; 68633965Sjdpmtp3fieldvalue: NUM { 68733965Sjdp $$.mtp3fieldtype = $<blk>0.mtp3fieldtype; 688218822Sdim if ($$.mtp3fieldtype == M_SIO || 68933965Sjdp $$.mtp3fieldtype == M_OPC || 690218822Sdim $$.mtp3fieldtype == M_DPC || 69133965Sjdp $$.mtp3fieldtype == M_SLS ) 69233965Sjdp $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0); 69333965Sjdp } 694218822Sdim ; 695218822Sdimmtp3listvalue: mtp3fieldvalue 69633965Sjdp | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; } 69733965Sjdp ; 69833965Sjdp%% 69933965Sjdp