xref: /dflybsd-src/contrib/libpcap/grammar.y (revision 3f75611e55cda2794a40d4231ecca0f75812a7dd)
197a9217aSAntonio Huete Jimenez /*
297a9217aSAntonio Huete Jimenez  * We want a reentrant parser.
397a9217aSAntonio Huete Jimenez  */
497a9217aSAntonio Huete Jimenez %pure-parser
597a9217aSAntonio Huete Jimenez 
697a9217aSAntonio Huete Jimenez /*
797a9217aSAntonio Huete Jimenez  * We also want a reentrant scanner, so we have to pass the
897a9217aSAntonio Huete Jimenez  * handle for the reentrant scanner to the parser, and the
997a9217aSAntonio Huete Jimenez  * parser has to pass it to the lexical analyzer.
1097a9217aSAntonio Huete Jimenez  *
1197a9217aSAntonio Huete Jimenez  * We use void * rather than yyscan_t because, at least with some
1297a9217aSAntonio Huete Jimenez  * versions of Flex and Bison, if you use yyscan_t in %parse-param and
1397a9217aSAntonio Huete Jimenez  * %lex-param, you have to include scanner.h before grammar.h to get
1497a9217aSAntonio Huete Jimenez  * yyscan_t declared, and you have to include grammar.h before scanner.h
1597a9217aSAntonio Huete Jimenez  * to get YYSTYPE declared.  Using void * breaks the cycle; the Flex
1697a9217aSAntonio Huete Jimenez  * documentation says yyscan_t is just a void *.
1797a9217aSAntonio Huete Jimenez  */
1897a9217aSAntonio Huete Jimenez %parse-param   {void *yyscanner}
1997a9217aSAntonio Huete Jimenez %lex-param   {void *yyscanner}
2097a9217aSAntonio Huete Jimenez 
2197a9217aSAntonio Huete Jimenez /*
22ea16f64eSAntonio Huete Jimenez  * According to bison documentation, shift/reduce conflicts are not an issue
23ea16f64eSAntonio Huete Jimenez  * in most parsers as long as the number does not evolve over time:
24ea16f64eSAntonio Huete Jimenez  * https://www.gnu.org/software/bison/manual/html_node/Expect-Decl.html
25ea16f64eSAntonio Huete Jimenez  * So, following the advice use %expect to check the amount of shift/reduce
26ea16f64eSAntonio Huete Jimenez  * warnings.
27ea16f64eSAntonio Huete Jimenez  *
28ea16f64eSAntonio Huete Jimenez  * This doesn't appear to work in Berkeley YACC - 1.9 20170709; it still
29ea16f64eSAntonio Huete Jimenez  * warns of 38 shift/reduce conflicts.
30ea16f64eSAntonio Huete Jimenez  *
31ea16f64eSAntonio Huete Jimenez  * The Berkeley YACC documentation:
32ea16f64eSAntonio Huete Jimenez  *
33ea16f64eSAntonio Huete Jimenez  *    https://invisible-island.net/byacc/manpage/yacc.html
34ea16f64eSAntonio Huete Jimenez  *
35ea16f64eSAntonio Huete Jimenez  * claims that "Bison's support for "%expect" is broken in more than one
36ea16f64eSAntonio Huete Jimenez  * release.", but doesn't give details.  Hopefully, that only means that
37ea16f64eSAntonio Huete Jimenez  * you get warnings even if you have the expected number of shift/reduce
38ea16f64eSAntonio Huete Jimenez  * conflicts, not that anything else fails.
39ea16f64eSAntonio Huete Jimenez  */
40ea16f64eSAntonio Huete Jimenez %expect 38
41ea16f64eSAntonio Huete Jimenez 
42ea16f64eSAntonio Huete Jimenez /*
4397a9217aSAntonio Huete Jimenez  * And we need to pass the compiler state to the scanner.
4497a9217aSAntonio Huete Jimenez  */
4597a9217aSAntonio Huete Jimenez %parse-param { compiler_state_t *cstate }
4697a9217aSAntonio Huete Jimenez 
471077d0bdSPeter Avalos %{
481077d0bdSPeter Avalos /*
491077d0bdSPeter Avalos  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
501077d0bdSPeter Avalos  *	The Regents of the University of California.  All rights reserved.
511077d0bdSPeter Avalos  *
521077d0bdSPeter Avalos  * Redistribution and use in source and binary forms, with or without
531077d0bdSPeter Avalos  * modification, are permitted provided that: (1) source code distributions
541077d0bdSPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
551077d0bdSPeter Avalos  * distributions including binary code include the above copyright notice and
561077d0bdSPeter Avalos  * this paragraph in its entirety in the documentation or other materials
571077d0bdSPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
581077d0bdSPeter Avalos  * features or use of this software display the following acknowledgement:
591077d0bdSPeter Avalos  * ``This product includes software developed by the University of California,
601077d0bdSPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
611077d0bdSPeter Avalos  * the University nor the names of its contributors may be used to endorse
621077d0bdSPeter Avalos  * or promote products derived from this software without specific prior
631077d0bdSPeter Avalos  * written permission.
641077d0bdSPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
651077d0bdSPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
661077d0bdSPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
671077d0bdSPeter Avalos  *
681077d0bdSPeter Avalos  */
691077d0bdSPeter Avalos 
701077d0bdSPeter Avalos #ifdef HAVE_CONFIG_H
713a289941SAaron LI #include <config.h>
721077d0bdSPeter Avalos #endif
731077d0bdSPeter Avalos 
741077d0bdSPeter Avalos #include <stdlib.h>
751077d0bdSPeter Avalos 
7697a9217aSAntonio Huete Jimenez #ifndef _WIN32
773a289941SAaron LI #include <sys/types.h>
783a289941SAaron LI #include <sys/socket.h>
793a289941SAaron LI 
801077d0bdSPeter Avalos #if __STDC__
811077d0bdSPeter Avalos struct mbuf;
821077d0bdSPeter Avalos struct rtentry;
831077d0bdSPeter Avalos #endif
841077d0bdSPeter Avalos 
851077d0bdSPeter Avalos #include <netinet/in.h>
86a85e14b0SPeter Avalos #include <arpa/inet.h>
8797a9217aSAntonio Huete Jimenez #endif /* _WIN32 */
881077d0bdSPeter Avalos 
891077d0bdSPeter Avalos #include <stdio.h>
901077d0bdSPeter Avalos 
913a289941SAaron LI #include "diag-control.h"
923a289941SAaron LI 
931077d0bdSPeter Avalos #include "pcap-int.h"
941077d0bdSPeter Avalos 
951077d0bdSPeter Avalos #include "gencode.h"
9697a9217aSAntonio Huete Jimenez #include "grammar.h"
9797a9217aSAntonio Huete Jimenez #include "scanner.h"
9897a9217aSAntonio Huete Jimenez 
99*3f75611eSAntonio Huete Jimenez /*
100*3f75611eSAntonio Huete Jimenez  * TODO(tuxillo): Upstream this change to libpcap since our pfvar.h headers
101*3f75611eSAntonio Huete Jimenez  * are in a different path.
102*3f75611eSAntonio Huete Jimenez  *
103*3f75611eSAntonio Huete Jimenez  */
104*3f75611eSAntonio Huete Jimenez #ifdef HAVE_NET_PF_PFVAR_H
1051077d0bdSPeter Avalos #include <net/if.h>
106*3f75611eSAntonio Huete Jimenez #include <net/pf/pfvar.h>
107*3f75611eSAntonio Huete Jimenez #include <net/pf/if_pflog.h>
1081077d0bdSPeter Avalos #endif
10997a9217aSAntonio Huete Jimenez #include "llc.h"
110de0d3203SPeter Avalos #include "ieee80211.h"
111de0d3203SPeter Avalos #include <pcap/namedb.h>
1121077d0bdSPeter Avalos 
1131077d0bdSPeter Avalos #ifdef HAVE_OS_PROTO_H
1141077d0bdSPeter Avalos #include "os-proto.h"
1151077d0bdSPeter Avalos #endif
1161077d0bdSPeter Avalos 
1173a289941SAaron LI #ifdef YYBYACC
1183a289941SAaron LI /*
1193a289941SAaron LI  * Both Berkeley YACC and Bison define yydebug (under whatever name
1203a289941SAaron LI  * it has) as a global, but Bison does so only if YYDEBUG is defined.
1213a289941SAaron LI  * Berkeley YACC define it even if YYDEBUG isn't defined; declare it
1223a289941SAaron LI  * here to suppress a warning.
1233a289941SAaron LI  */
1243a289941SAaron LI #if !defined(YYDEBUG)
1253a289941SAaron LI extern int yydebug;
1263a289941SAaron LI #endif
1273a289941SAaron LI 
1283a289941SAaron LI /*
1293a289941SAaron LI  * In Berkeley YACC, yynerrs (under whatever name it has) is global,
1303a289941SAaron LI  * even if it's building a reentrant parser.  In Bison, it's local
1313a289941SAaron LI  * in reentrant parsers.
1323a289941SAaron LI  *
1333a289941SAaron LI  * Declare it to squelch a warning.
1343a289941SAaron LI  */
1353a289941SAaron LI extern int yynerrs;
1363a289941SAaron LI #endif
1373a289941SAaron LI 
1383a289941SAaron LI #define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
1393a289941SAaron LI 			 (q).dir = (unsigned char)(d),\
1403a289941SAaron LI 			 (q).addr = (unsigned char)(a)
1411077d0bdSPeter Avalos 
142de0d3203SPeter Avalos struct tok {
143de0d3203SPeter Avalos 	int v;			/* value */
144de0d3203SPeter Avalos 	const char *s;		/* string */
145de0d3203SPeter Avalos };
146de0d3203SPeter Avalos 
147de0d3203SPeter Avalos static const struct tok ieee80211_types[] = {
148de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_DATA, "data" },
149de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_MGT, "mgt" },
150de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_MGT, "management" },
151de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_CTL, "ctl" },
152de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_CTL, "control" },
153de0d3203SPeter Avalos 	{ 0, NULL }
154de0d3203SPeter Avalos };
155de0d3203SPeter Avalos static const struct tok ieee80211_mgt_subtypes[] = {
156de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
157de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
158de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
159de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
160de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
161de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
162de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
163de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
164de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
165de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
166de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
167de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
168de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
169de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
170de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
171de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
172de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
173de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
174de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
175de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
176de0d3203SPeter Avalos 	{ 0, NULL }
177de0d3203SPeter Avalos };
178de0d3203SPeter Avalos static const struct tok ieee80211_ctl_subtypes[] = {
179de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
180de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_RTS, "rts" },
181de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CTS, "cts" },
182de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_ACK, "ack" },
183de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
184de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
185de0d3203SPeter Avalos 	{ 0, NULL }
186de0d3203SPeter Avalos };
187de0d3203SPeter Avalos static const struct tok ieee80211_data_subtypes[] = {
188de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_DATA, "data" },
189de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
190de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
191de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
192de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_NODATA, "null" },
193de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
194de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll"  },
195de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
196de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
197de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
198de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
199de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
200de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
201de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
202de0d3203SPeter Avalos 	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
203de0d3203SPeter Avalos 	{ 0, NULL }
204de0d3203SPeter Avalos };
20597a9217aSAntonio Huete Jimenez static const struct tok llc_s_subtypes[] = {
20697a9217aSAntonio Huete Jimenez 	{ LLC_RR, "rr" },
20797a9217aSAntonio Huete Jimenez 	{ LLC_RNR, "rnr" },
20897a9217aSAntonio Huete Jimenez 	{ LLC_REJ, "rej" },
20997a9217aSAntonio Huete Jimenez 	{ 0, NULL }
21097a9217aSAntonio Huete Jimenez };
21197a9217aSAntonio Huete Jimenez static const struct tok llc_u_subtypes[] = {
21297a9217aSAntonio Huete Jimenez 	{ LLC_UI, "ui" },
21397a9217aSAntonio Huete Jimenez 	{ LLC_UA, "ua" },
21497a9217aSAntonio Huete Jimenez 	{ LLC_DISC, "disc" },
21597a9217aSAntonio Huete Jimenez 	{ LLC_DM, "dm" },
21697a9217aSAntonio Huete Jimenez 	{ LLC_SABME, "sabme" },
21797a9217aSAntonio Huete Jimenez 	{ LLC_TEST, "test" },
21897a9217aSAntonio Huete Jimenez 	{ LLC_XID, "xid" },
21997a9217aSAntonio Huete Jimenez 	{ LLC_FRMR, "frmr" },
22097a9217aSAntonio Huete Jimenez 	{ 0, NULL }
22197a9217aSAntonio Huete Jimenez };
222de0d3203SPeter Avalos struct type2tok {
223de0d3203SPeter Avalos 	int type;
224de0d3203SPeter Avalos 	const struct tok *tok;
225de0d3203SPeter Avalos };
226de0d3203SPeter Avalos static const struct type2tok ieee80211_type_subtypes[] = {
227de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
228de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
229de0d3203SPeter Avalos 	{ IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
230de0d3203SPeter Avalos 	{ 0, NULL }
231de0d3203SPeter Avalos };
232de0d3203SPeter Avalos 
233de0d3203SPeter Avalos static int
str2tok(const char * str,const struct tok * toks)234de0d3203SPeter Avalos str2tok(const char *str, const struct tok *toks)
235de0d3203SPeter Avalos {
236de0d3203SPeter Avalos 	int i;
237de0d3203SPeter Avalos 
238de0d3203SPeter Avalos 	for (i = 0; toks[i].s != NULL; i++) {
239ea16f64eSAntonio Huete Jimenez 		if (pcap_strcasecmp(toks[i].s, str) == 0) {
240ea16f64eSAntonio Huete Jimenez 			/*
241ea16f64eSAntonio Huete Jimenez 			 * Just in case somebody is using this to
242ea16f64eSAntonio Huete Jimenez 			 * generate values of -1/0xFFFFFFFF.
243ea16f64eSAntonio Huete Jimenez 			 * That won't work, as it's indistinguishable
244ea16f64eSAntonio Huete Jimenez 			 * from an error.
245ea16f64eSAntonio Huete Jimenez 			 */
246ea16f64eSAntonio Huete Jimenez 			if (toks[i].v == -1)
247ea16f64eSAntonio Huete Jimenez 				abort();
248de0d3203SPeter Avalos 			return (toks[i].v);
249de0d3203SPeter Avalos 		}
250ea16f64eSAntonio Huete Jimenez 	}
251de0d3203SPeter Avalos 	return (-1);
252de0d3203SPeter Avalos }
253de0d3203SPeter Avalos 
2543a289941SAaron LI static const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
2551077d0bdSPeter Avalos 
2561077d0bdSPeter Avalos static void
yyerror(void * yyscanner _U_,compiler_state_t * cstate,const char * msg)2573a289941SAaron LI yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
2581077d0bdSPeter Avalos {
2593a289941SAaron LI 	bpf_set_error(cstate, "can't parse filter expression: %s", msg);
2601077d0bdSPeter Avalos }
2611077d0bdSPeter Avalos 
2621077d0bdSPeter Avalos #ifdef HAVE_NET_PFVAR_H
2631077d0bdSPeter Avalos static int
pfreason_to_num(compiler_state_t * cstate,const char * reason)26497a9217aSAntonio Huete Jimenez pfreason_to_num(compiler_state_t *cstate, const char *reason)
2651077d0bdSPeter Avalos {
2661077d0bdSPeter Avalos 	const char *reasons[] = PFRES_NAMES;
2671077d0bdSPeter Avalos 	int i;
2681077d0bdSPeter Avalos 
2691077d0bdSPeter Avalos 	for (i = 0; reasons[i]; i++) {
2701077d0bdSPeter Avalos 		if (pcap_strcasecmp(reason, reasons[i]) == 0)
2711077d0bdSPeter Avalos 			return (i);
2721077d0bdSPeter Avalos 	}
273ea16f64eSAntonio Huete Jimenez 	bpf_set_error(cstate, "unknown PF reason \"%s\"", reason);
2743a289941SAaron LI 	return (-1);
2751077d0bdSPeter Avalos }
2761077d0bdSPeter Avalos 
2771077d0bdSPeter Avalos static int
pfaction_to_num(compiler_state_t * cstate,const char * action)27897a9217aSAntonio Huete Jimenez pfaction_to_num(compiler_state_t *cstate, const char *action)
2791077d0bdSPeter Avalos {
2801077d0bdSPeter Avalos 	if (pcap_strcasecmp(action, "pass") == 0 ||
2811077d0bdSPeter Avalos 	    pcap_strcasecmp(action, "accept") == 0)
2821077d0bdSPeter Avalos 		return (PF_PASS);
2831077d0bdSPeter Avalos 	else if (pcap_strcasecmp(action, "drop") == 0 ||
2841077d0bdSPeter Avalos 		pcap_strcasecmp(action, "block") == 0)
2851077d0bdSPeter Avalos 		return (PF_DROP);
286de0d3203SPeter Avalos #if HAVE_PF_NAT_THROUGH_PF_NORDR
287de0d3203SPeter Avalos 	else if (pcap_strcasecmp(action, "rdr") == 0)
288de0d3203SPeter Avalos 		return (PF_RDR);
289de0d3203SPeter Avalos 	else if (pcap_strcasecmp(action, "nat") == 0)
290de0d3203SPeter Avalos 		return (PF_NAT);
291de0d3203SPeter Avalos 	else if (pcap_strcasecmp(action, "binat") == 0)
292de0d3203SPeter Avalos 		return (PF_BINAT);
293de0d3203SPeter Avalos 	else if (pcap_strcasecmp(action, "nordr") == 0)
294de0d3203SPeter Avalos 		return (PF_NORDR);
295de0d3203SPeter Avalos #endif
2961077d0bdSPeter Avalos 	else {
297ea16f64eSAntonio Huete Jimenez 		bpf_set_error(cstate, "unknown PF action \"%s\"", action);
2983a289941SAaron LI 		return (-1);
2991077d0bdSPeter Avalos 	}
3001077d0bdSPeter Avalos }
3011077d0bdSPeter Avalos #else /* !HAVE_NET_PFVAR_H */
3021077d0bdSPeter Avalos static int
pfreason_to_num(compiler_state_t * cstate,const char * reason _U_)3033a289941SAaron LI pfreason_to_num(compiler_state_t *cstate, const char *reason _U_)
3041077d0bdSPeter Avalos {
3053a289941SAaron LI 	bpf_set_error(cstate, "libpcap was compiled on a machine without pf support");
3063a289941SAaron LI 	return (-1);
3071077d0bdSPeter Avalos }
3081077d0bdSPeter Avalos 
3091077d0bdSPeter Avalos static int
pfaction_to_num(compiler_state_t * cstate,const char * action _U_)3103a289941SAaron LI pfaction_to_num(compiler_state_t *cstate, const char *action _U_)
3111077d0bdSPeter Avalos {
3123a289941SAaron LI 	bpf_set_error(cstate, "libpcap was compiled on a machine without pf support");
3133a289941SAaron LI 	return (-1);
3141077d0bdSPeter Avalos }
3151077d0bdSPeter Avalos #endif /* HAVE_NET_PFVAR_H */
3163a289941SAaron LI 
3173a289941SAaron LI /*
3183a289941SAaron LI  * For calls that might return an "an error occurred" value.
3193a289941SAaron LI  */
3203a289941SAaron LI #define CHECK_INT_VAL(val)	if (val == -1) YYABORT
3213a289941SAaron LI #define CHECK_PTR_VAL(val)	if (val == NULL) YYABORT
3223a289941SAaron LI 
3233a289941SAaron LI DIAG_OFF_BISON_BYACC
3241077d0bdSPeter Avalos %}
3251077d0bdSPeter Avalos 
3261077d0bdSPeter Avalos %union {
3271077d0bdSPeter Avalos 	int i;
3281077d0bdSPeter Avalos 	bpf_u_int32 h;
3291077d0bdSPeter Avalos 	char *s;
3301077d0bdSPeter Avalos 	struct stmt *stmt;
3311077d0bdSPeter Avalos 	struct arth *a;
3321077d0bdSPeter Avalos 	struct {
3331077d0bdSPeter Avalos 		struct qual q;
3341077d0bdSPeter Avalos 		int atmfieldtype;
3351077d0bdSPeter Avalos 		int mtp3fieldtype;
3361077d0bdSPeter Avalos 		struct block *b;
3371077d0bdSPeter Avalos 	} blk;
3381077d0bdSPeter Avalos 	struct block *rblk;
3391077d0bdSPeter Avalos }
3401077d0bdSPeter Avalos 
3411077d0bdSPeter Avalos %type	<blk>	expr id nid pid term rterm qid
3421077d0bdSPeter Avalos %type	<blk>	head
3431077d0bdSPeter Avalos %type	<i>	pqual dqual aqual ndaqual
3441077d0bdSPeter Avalos %type	<a>	arth narth
345ea16f64eSAntonio Huete Jimenez %type	<i>	byteop pname relop irelop
346ea16f64eSAntonio Huete Jimenez %type	<h>	pnum
3471077d0bdSPeter Avalos %type	<blk>	and or paren not null prog
34897a9217aSAntonio Huete Jimenez %type	<rblk>	other pfvar p80211 pllc
3491077d0bdSPeter Avalos %type	<i>	atmtype atmmultitype
3501077d0bdSPeter Avalos %type	<blk>	atmfield
3511077d0bdSPeter Avalos %type	<blk>	atmfieldvalue atmvalue atmlistvalue
3521077d0bdSPeter Avalos %type	<i>	mtp2type
3531077d0bdSPeter Avalos %type	<blk>	mtp3field
3541077d0bdSPeter Avalos %type	<blk>	mtp3fieldvalue mtp3value mtp3listvalue
3551077d0bdSPeter Avalos 
3561077d0bdSPeter Avalos 
3571077d0bdSPeter Avalos %token  DST SRC HOST GATEWAY
3581077d0bdSPeter Avalos %token  NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
359a85e14b0SPeter Avalos %token  ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
3601077d0bdSPeter Avalos %token  ATALK AARP DECNET LAT SCA MOPRC MOPDL
3611077d0bdSPeter Avalos %token  TK_BROADCAST TK_MULTICAST
3621077d0bdSPeter Avalos %token  NUM INBOUND OUTBOUND
363ea16f64eSAntonio Huete Jimenez %token  IFINDEX
3641077d0bdSPeter Avalos %token  PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
365a85e14b0SPeter Avalos %token	TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
3661077d0bdSPeter Avalos %token  LINK
3671077d0bdSPeter Avalos %token	GEQ LEQ NEQ
3681077d0bdSPeter Avalos %token	ID EID HID HID6 AID
3691077d0bdSPeter Avalos %token	LSH RSH
3701077d0bdSPeter Avalos %token  LEN
3711077d0bdSPeter Avalos %token  IPV6 ICMPV6 AH ESP
3721077d0bdSPeter Avalos %token	VLAN MPLS
37397a9217aSAntonio Huete Jimenez %token	PPPOED PPPOES GENEVE
3741077d0bdSPeter Avalos %token  ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
3751077d0bdSPeter Avalos %token  STP
3761077d0bdSPeter Avalos %token  IPX
3771077d0bdSPeter Avalos %token  NETBEUI
3781077d0bdSPeter Avalos %token	LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
3791077d0bdSPeter Avalos %token	OAM OAMF4 CONNECTMSG METACONNECT
3801077d0bdSPeter Avalos %token	VPI VCI
3811077d0bdSPeter Avalos %token	RADIO
38297a9217aSAntonio Huete Jimenez %token	FISU LSSU MSU HFISU HLSSU HMSU
38397a9217aSAntonio Huete Jimenez %token	SIO OPC DPC SLS HSIO HOPC HDPC HSLS
3843a289941SAaron LI %token	LEX_ERROR
38597a9217aSAntonio Huete Jimenez 
3863a289941SAaron LI %type	<s> ID EID AID
3871077d0bdSPeter Avalos %type	<s> HID HID6
388ea16f64eSAntonio Huete Jimenez %type	<h> NUM
389ea16f64eSAntonio Huete Jimenez %type	<i> action reason type subtype type_subtype dir
3901077d0bdSPeter Avalos 
3911077d0bdSPeter Avalos %left OR AND
3921077d0bdSPeter Avalos %nonassoc  '!'
3931077d0bdSPeter Avalos %left '|'
3941077d0bdSPeter Avalos %left '&'
3951077d0bdSPeter Avalos %left LSH RSH
3961077d0bdSPeter Avalos %left '+' '-'
3971077d0bdSPeter Avalos %left '*' '/'
3981077d0bdSPeter Avalos %nonassoc UMINUS
3991077d0bdSPeter Avalos %%
4001077d0bdSPeter Avalos prog:	  null expr
4011077d0bdSPeter Avalos {
4023a289941SAaron LI 	CHECK_INT_VAL(finish_parse(cstate, $2.b));
4031077d0bdSPeter Avalos }
4041077d0bdSPeter Avalos 	| null
4051077d0bdSPeter Avalos 	;
4061077d0bdSPeter Avalos null:	  /* null */		{ $$.q = qerr; }
4071077d0bdSPeter Avalos 	;
4081077d0bdSPeter Avalos expr:	  term
4091077d0bdSPeter Avalos 	| expr and term		{ gen_and($1.b, $3.b); $$ = $3; }
4101077d0bdSPeter Avalos 	| expr and id		{ gen_and($1.b, $3.b); $$ = $3; }
4111077d0bdSPeter Avalos 	| expr or term		{ gen_or($1.b, $3.b); $$ = $3; }
4121077d0bdSPeter Avalos 	| expr or id		{ gen_or($1.b, $3.b); $$ = $3; }
4131077d0bdSPeter Avalos 	;
4141077d0bdSPeter Avalos and:	  AND			{ $$ = $<blk>0; }
4151077d0bdSPeter Avalos 	;
4161077d0bdSPeter Avalos or:	  OR			{ $$ = $<blk>0; }
4171077d0bdSPeter Avalos 	;
4181077d0bdSPeter Avalos id:	  nid
419ea16f64eSAntonio Huete Jimenez 	| pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
4203a289941SAaron LI 						   $$.q = $<blk>0.q))); }
4211077d0bdSPeter Avalos 	| paren pid ')'		{ $$ = $2; }
4221077d0bdSPeter Avalos 	;
4233a289941SAaron LI nid:	  ID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
4243a289941SAaron LI 	| HID '/' NUM		{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
4253a289941SAaron LI 				    $$.q = $<blk>0.q))); }
4263a289941SAaron LI 	| HID NETMASK HID	{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
4273a289941SAaron LI 				    $$.q = $<blk>0.q))); }
4281077d0bdSPeter Avalos 	| HID			{
4293a289941SAaron LI 				  CHECK_PTR_VAL($1);
4301077d0bdSPeter Avalos 				  /* Decide how to parse HID based on proto */
4311077d0bdSPeter Avalos 				  $$.q = $<blk>0.q;
4323a289941SAaron LI 				  if ($$.q.addr == Q_PORT) {
4333a289941SAaron LI 					bpf_set_error(cstate, "'port' modifier applied to ip host");
4343a289941SAaron LI 					YYABORT;
4353a289941SAaron LI 				  } else if ($$.q.addr == Q_PORTRANGE) {
4363a289941SAaron LI 					bpf_set_error(cstate, "'portrange' modifier applied to ip host");
4373a289941SAaron LI 					YYABORT;
4383a289941SAaron LI 				  } else if ($$.q.addr == Q_PROTO) {
4393a289941SAaron LI 					bpf_set_error(cstate, "'proto' modifier applied to ip host");
4403a289941SAaron LI 					YYABORT;
4413a289941SAaron LI 				  } else if ($$.q.addr == Q_PROTOCHAIN) {
4423a289941SAaron LI 					bpf_set_error(cstate, "'protochain' modifier applied to ip host");
4433a289941SAaron LI 					YYABORT;
4443a289941SAaron LI 				  }
4453a289941SAaron LI 				  CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
4461077d0bdSPeter Avalos 				}
4471077d0bdSPeter Avalos 	| HID6 '/' NUM		{
4483a289941SAaron LI 				  CHECK_PTR_VAL($1);
4491077d0bdSPeter Avalos #ifdef INET6
4503a289941SAaron LI 				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
4513a289941SAaron LI 				    $$.q = $<blk>0.q)));
4521077d0bdSPeter Avalos #else
4533a289941SAaron LI 				  bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
4541077d0bdSPeter Avalos 					"in this configuration");
4553a289941SAaron LI 				  YYABORT;
4561077d0bdSPeter Avalos #endif /*INET6*/
4571077d0bdSPeter Avalos 				}
4581077d0bdSPeter Avalos 	| HID6			{
4593a289941SAaron LI 				  CHECK_PTR_VAL($1);
4601077d0bdSPeter Avalos #ifdef INET6
4613a289941SAaron LI 				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
4623a289941SAaron LI 				    $$.q = $<blk>0.q)));
4631077d0bdSPeter Avalos #else
4643a289941SAaron LI 				  bpf_set_error(cstate, "'ip6addr' not supported "
4651077d0bdSPeter Avalos 					"in this configuration");
4663a289941SAaron LI 				  YYABORT;
4671077d0bdSPeter Avalos #endif /*INET6*/
4681077d0bdSPeter Avalos 				}
4693a289941SAaron LI 	| EID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
4703a289941SAaron LI 	| AID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
4711077d0bdSPeter Avalos 	| not id		{ gen_not($2.b); $$ = $2; }
4721077d0bdSPeter Avalos 	;
4731077d0bdSPeter Avalos not:	  '!'			{ $$ = $<blk>0; }
4741077d0bdSPeter Avalos 	;
4751077d0bdSPeter Avalos paren:	  '('			{ $$ = $<blk>0; }
4761077d0bdSPeter Avalos 	;
4771077d0bdSPeter Avalos pid:	  nid
4781077d0bdSPeter Avalos 	| qid and id		{ gen_and($1.b, $3.b); $$ = $3; }
4791077d0bdSPeter Avalos 	| qid or id		{ gen_or($1.b, $3.b); $$ = $3; }
4801077d0bdSPeter Avalos 	;
481ea16f64eSAntonio Huete Jimenez qid:	  pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
4823a289941SAaron LI 						   $$.q = $<blk>0.q))); }
4831077d0bdSPeter Avalos 	| pid
4841077d0bdSPeter Avalos 	;
4851077d0bdSPeter Avalos term:	  rterm
4861077d0bdSPeter Avalos 	| not term		{ gen_not($2.b); $$ = $2; }
4871077d0bdSPeter Avalos 	;
4881077d0bdSPeter Avalos head:	  pqual dqual aqual	{ QSET($$.q, $1, $2, $3); }
4891077d0bdSPeter Avalos 	| pqual dqual		{ QSET($$.q, $1, $2, Q_DEFAULT); }
4901077d0bdSPeter Avalos 	| pqual aqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
4911077d0bdSPeter Avalos 	| pqual PROTO		{ QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
4923a289941SAaron LI 	| pqual PROTOCHAIN	{
4933a289941SAaron LI #ifdef NO_PROTOCHAIN
4943a289941SAaron LI 				  bpf_set_error(cstate, "protochain not supported");
4953a289941SAaron LI 				  YYABORT;
4963a289941SAaron LI #else
4973a289941SAaron LI 				  QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
4983a289941SAaron LI #endif
4993a289941SAaron LI 				}
5001077d0bdSPeter Avalos 	| pqual ndaqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
5011077d0bdSPeter Avalos 	;
5021077d0bdSPeter Avalos rterm:	  head id		{ $$ = $2; }
5031077d0bdSPeter Avalos 	| paren expr ')'	{ $$.b = $2.b; $$.q = $1.q; }
5043a289941SAaron LI 	| pname			{ CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
5053a289941SAaron LI 	| arth relop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
5061077d0bdSPeter Avalos 				  $$.q = qerr; }
5073a289941SAaron LI 	| arth irelop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
5081077d0bdSPeter Avalos 				  $$.q = qerr; }
5091077d0bdSPeter Avalos 	| other			{ $$.b = $1; $$.q = qerr; }
5103a289941SAaron LI 	| atmtype		{ CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
5113a289941SAaron LI 	| atmmultitype		{ CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
5121077d0bdSPeter Avalos 	| atmfield atmvalue	{ $$.b = $2.b; $$.q = qerr; }
5133a289941SAaron LI 	| mtp2type		{ CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
5141077d0bdSPeter Avalos 	| mtp3field mtp3value	{ $$.b = $2.b; $$.q = qerr; }
5151077d0bdSPeter Avalos 	;
5161077d0bdSPeter Avalos /* protocol level qualifiers */
5171077d0bdSPeter Avalos pqual:	  pname
5181077d0bdSPeter Avalos 	|			{ $$ = Q_DEFAULT; }
5191077d0bdSPeter Avalos 	;
5201077d0bdSPeter Avalos /* 'direction' qualifiers */
5211077d0bdSPeter Avalos dqual:	  SRC			{ $$ = Q_SRC; }
5221077d0bdSPeter Avalos 	| DST			{ $$ = Q_DST; }
5231077d0bdSPeter Avalos 	| SRC OR DST		{ $$ = Q_OR; }
5241077d0bdSPeter Avalos 	| DST OR SRC		{ $$ = Q_OR; }
5251077d0bdSPeter Avalos 	| SRC AND DST		{ $$ = Q_AND; }
5261077d0bdSPeter Avalos 	| DST AND SRC		{ $$ = Q_AND; }
527de0d3203SPeter Avalos 	| ADDR1			{ $$ = Q_ADDR1; }
528de0d3203SPeter Avalos 	| ADDR2			{ $$ = Q_ADDR2; }
529de0d3203SPeter Avalos 	| ADDR3			{ $$ = Q_ADDR3; }
530de0d3203SPeter Avalos 	| ADDR4			{ $$ = Q_ADDR4; }
531a85e14b0SPeter Avalos 	| RA			{ $$ = Q_RA; }
532a85e14b0SPeter Avalos 	| TA			{ $$ = Q_TA; }
5331077d0bdSPeter Avalos 	;
5341077d0bdSPeter Avalos /* address type qualifiers */
5351077d0bdSPeter Avalos aqual:	  HOST			{ $$ = Q_HOST; }
5361077d0bdSPeter Avalos 	| NET			{ $$ = Q_NET; }
5371077d0bdSPeter Avalos 	| PORT			{ $$ = Q_PORT; }
5381077d0bdSPeter Avalos 	| PORTRANGE		{ $$ = Q_PORTRANGE; }
5391077d0bdSPeter Avalos 	;
5401077d0bdSPeter Avalos /* non-directional address type qualifiers */
5411077d0bdSPeter Avalos ndaqual:  GATEWAY		{ $$ = Q_GATEWAY; }
5421077d0bdSPeter Avalos 	;
5431077d0bdSPeter Avalos pname:	  LINK			{ $$ = Q_LINK; }
5441077d0bdSPeter Avalos 	| IP			{ $$ = Q_IP; }
5451077d0bdSPeter Avalos 	| ARP			{ $$ = Q_ARP; }
5461077d0bdSPeter Avalos 	| RARP			{ $$ = Q_RARP; }
5471077d0bdSPeter Avalos 	| SCTP			{ $$ = Q_SCTP; }
5481077d0bdSPeter Avalos 	| TCP			{ $$ = Q_TCP; }
5491077d0bdSPeter Avalos 	| UDP			{ $$ = Q_UDP; }
5501077d0bdSPeter Avalos 	| ICMP			{ $$ = Q_ICMP; }
5511077d0bdSPeter Avalos 	| IGMP			{ $$ = Q_IGMP; }
5521077d0bdSPeter Avalos 	| IGRP			{ $$ = Q_IGRP; }
5531077d0bdSPeter Avalos 	| PIM			{ $$ = Q_PIM; }
5541077d0bdSPeter Avalos 	| VRRP			{ $$ = Q_VRRP; }
555a85e14b0SPeter Avalos 	| CARP			{ $$ = Q_CARP; }
5561077d0bdSPeter Avalos 	| ATALK			{ $$ = Q_ATALK; }
5571077d0bdSPeter Avalos 	| AARP			{ $$ = Q_AARP; }
5581077d0bdSPeter Avalos 	| DECNET		{ $$ = Q_DECNET; }
5591077d0bdSPeter Avalos 	| LAT			{ $$ = Q_LAT; }
5601077d0bdSPeter Avalos 	| SCA			{ $$ = Q_SCA; }
5611077d0bdSPeter Avalos 	| MOPDL			{ $$ = Q_MOPDL; }
5621077d0bdSPeter Avalos 	| MOPRC			{ $$ = Q_MOPRC; }
5631077d0bdSPeter Avalos 	| IPV6			{ $$ = Q_IPV6; }
5641077d0bdSPeter Avalos 	| ICMPV6		{ $$ = Q_ICMPV6; }
5651077d0bdSPeter Avalos 	| AH			{ $$ = Q_AH; }
5661077d0bdSPeter Avalos 	| ESP			{ $$ = Q_ESP; }
5671077d0bdSPeter Avalos 	| ISO			{ $$ = Q_ISO; }
5681077d0bdSPeter Avalos 	| ESIS			{ $$ = Q_ESIS; }
5691077d0bdSPeter Avalos 	| ISIS			{ $$ = Q_ISIS; }
5701077d0bdSPeter Avalos 	| L1			{ $$ = Q_ISIS_L1; }
5711077d0bdSPeter Avalos 	| L2			{ $$ = Q_ISIS_L2; }
5721077d0bdSPeter Avalos 	| IIH			{ $$ = Q_ISIS_IIH; }
5731077d0bdSPeter Avalos 	| LSP			{ $$ = Q_ISIS_LSP; }
5741077d0bdSPeter Avalos 	| SNP			{ $$ = Q_ISIS_SNP; }
5751077d0bdSPeter Avalos 	| PSNP			{ $$ = Q_ISIS_PSNP; }
5761077d0bdSPeter Avalos 	| CSNP			{ $$ = Q_ISIS_CSNP; }
5771077d0bdSPeter Avalos 	| CLNP			{ $$ = Q_CLNP; }
5781077d0bdSPeter Avalos 	| STP			{ $$ = Q_STP; }
5791077d0bdSPeter Avalos 	| IPX			{ $$ = Q_IPX; }
5801077d0bdSPeter Avalos 	| NETBEUI		{ $$ = Q_NETBEUI; }
5811077d0bdSPeter Avalos 	| RADIO			{ $$ = Q_RADIO; }
5821077d0bdSPeter Avalos 	;
5833a289941SAaron LI other:	  pqual TK_BROADCAST	{ CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
5843a289941SAaron LI 	| pqual TK_MULTICAST	{ CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
5853a289941SAaron LI 	| LESS NUM		{ CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
5863a289941SAaron LI 	| GREATER NUM		{ CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
5873a289941SAaron LI 	| CBYTE NUM byteop NUM	{ CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
5883a289941SAaron LI 	| INBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
5893a289941SAaron LI 	| OUTBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
590ea16f64eSAntonio Huete Jimenez 	| IFINDEX NUM		{ CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
591ea16f64eSAntonio Huete Jimenez 	| VLAN pnum		{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
5923a289941SAaron LI 	| VLAN			{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
593ea16f64eSAntonio Huete Jimenez 	| MPLS pnum		{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, $2, 1))); }
5943a289941SAaron LI 	| MPLS			{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
5953a289941SAaron LI 	| PPPOED		{ CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
596ea16f64eSAntonio Huete Jimenez 	| PPPOES pnum		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, $2, 1))); }
5973a289941SAaron LI 	| PPPOES		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
598ea16f64eSAntonio Huete Jimenez 	| GENEVE pnum		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
5993a289941SAaron LI 	| GENEVE		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
6001077d0bdSPeter Avalos 	| pfvar			{ $$ = $1; }
601de0d3203SPeter Avalos 	| pqual p80211		{ $$ = $2; }
60297a9217aSAntonio Huete Jimenez 	| pllc			{ $$ = $1; }
6031077d0bdSPeter Avalos 	;
6041077d0bdSPeter Avalos 
6053a289941SAaron LI pfvar:	  PF_IFNAME ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
6063a289941SAaron LI 	| PF_RSET ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
6073a289941SAaron LI 	| PF_RNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
6083a289941SAaron LI 	| PF_SRNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
6093a289941SAaron LI 	| PF_REASON reason	{ CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
6103a289941SAaron LI 	| PF_ACTION action	{ CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
6111077d0bdSPeter Avalos 	;
6121077d0bdSPeter Avalos 
613de0d3203SPeter Avalos p80211:   TYPE type SUBTYPE subtype
6143a289941SAaron LI 				{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
615de0d3203SPeter Avalos 					IEEE80211_FC0_TYPE_MASK |
6163a289941SAaron LI 					IEEE80211_FC0_SUBTYPE_MASK)));
617de0d3203SPeter Avalos 				}
6183a289941SAaron LI 	| TYPE type		{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
6193a289941SAaron LI 					IEEE80211_FC0_TYPE_MASK)));
620de0d3203SPeter Avalos 				}
6213a289941SAaron LI 	| SUBTYPE type_subtype	{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
622de0d3203SPeter Avalos 					IEEE80211_FC0_TYPE_MASK |
6233a289941SAaron LI 					IEEE80211_FC0_SUBTYPE_MASK)));
624de0d3203SPeter Avalos 				}
6253a289941SAaron LI 	| DIR dir		{ CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
626de0d3203SPeter Avalos 	;
627de0d3203SPeter Avalos 
628ea16f64eSAntonio Huete Jimenez type:	  NUM			{ if (($1 & (~IEEE80211_FC0_TYPE_MASK)) != 0) {
629ea16f64eSAntonio Huete Jimenez 					bpf_set_error(cstate, "invalid 802.11 type value 0x%02x", $1);
630ea16f64eSAntonio Huete Jimenez 					YYABORT;
631ea16f64eSAntonio Huete Jimenez 				  }
632ea16f64eSAntonio Huete Jimenez 				  $$ = (int)$1;
633ea16f64eSAntonio Huete Jimenez 				}
6343a289941SAaron LI 	| ID			{ CHECK_PTR_VAL($1);
6353a289941SAaron LI 				  $$ = str2tok($1, ieee80211_types);
6363a289941SAaron LI 				  if ($$ == -1) {
637ea16f64eSAntonio Huete Jimenez 					bpf_set_error(cstate, "unknown 802.11 type name \"%s\"", $1);
6383a289941SAaron LI 					YYABORT;
6393a289941SAaron LI 				  }
640de0d3203SPeter Avalos 				}
641de0d3203SPeter Avalos 	;
642de0d3203SPeter Avalos 
643ea16f64eSAntonio Huete Jimenez subtype:  NUM			{ if (($1 & (~IEEE80211_FC0_SUBTYPE_MASK)) != 0) {
644ea16f64eSAntonio Huete Jimenez 					bpf_set_error(cstate, "invalid 802.11 subtype value 0x%02x", $1);
645ea16f64eSAntonio Huete Jimenez 					YYABORT;
646ea16f64eSAntonio Huete Jimenez 				  }
647ea16f64eSAntonio Huete Jimenez 				  $$ = (int)$1;
648ea16f64eSAntonio Huete Jimenez 				}
649de0d3203SPeter Avalos 	| ID			{ const struct tok *types = NULL;
650de0d3203SPeter Avalos 				  int i;
6513a289941SAaron LI 				  CHECK_PTR_VAL($1);
652de0d3203SPeter Avalos 				  for (i = 0;; i++) {
653de0d3203SPeter Avalos 					if (ieee80211_type_subtypes[i].tok == NULL) {
654de0d3203SPeter Avalos 						/* Ran out of types */
6553a289941SAaron LI 						bpf_set_error(cstate, "unknown 802.11 type");
6563a289941SAaron LI 						YYABORT;
657de0d3203SPeter Avalos 					}
658de0d3203SPeter Avalos 					if ($<i>-1 == ieee80211_type_subtypes[i].type) {
659de0d3203SPeter Avalos 						types = ieee80211_type_subtypes[i].tok;
660de0d3203SPeter Avalos 						break;
661de0d3203SPeter Avalos 					}
662de0d3203SPeter Avalos 				  }
663de0d3203SPeter Avalos 
664de0d3203SPeter Avalos 				  $$ = str2tok($1, types);
6653a289941SAaron LI 				  if ($$ == -1) {
666ea16f64eSAntonio Huete Jimenez 					bpf_set_error(cstate, "unknown 802.11 subtype name \"%s\"", $1);
6673a289941SAaron LI 					YYABORT;
6683a289941SAaron LI 				  }
669de0d3203SPeter Avalos 				}
670de0d3203SPeter Avalos 	;
671de0d3203SPeter Avalos 
672de0d3203SPeter Avalos type_subtype:	ID		{ int i;
6733a289941SAaron LI 				  CHECK_PTR_VAL($1);
674de0d3203SPeter Avalos 				  for (i = 0;; i++) {
675de0d3203SPeter Avalos 					if (ieee80211_type_subtypes[i].tok == NULL) {
676de0d3203SPeter Avalos 						/* Ran out of types */
6773a289941SAaron LI 						bpf_set_error(cstate, "unknown 802.11 type name");
6783a289941SAaron LI 						YYABORT;
679de0d3203SPeter Avalos 					}
680de0d3203SPeter Avalos 					$$ = str2tok($1, ieee80211_type_subtypes[i].tok);
681de0d3203SPeter Avalos 					if ($$ != -1) {
682de0d3203SPeter Avalos 						$$ |= ieee80211_type_subtypes[i].type;
683de0d3203SPeter Avalos 						break;
684de0d3203SPeter Avalos 					}
685de0d3203SPeter Avalos 				  }
686de0d3203SPeter Avalos 				}
687de0d3203SPeter Avalos 		;
688de0d3203SPeter Avalos 
6893a289941SAaron LI pllc:	LLC			{ CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
6903a289941SAaron LI 	| LLC ID		{ CHECK_PTR_VAL($2);
6913a289941SAaron LI 				  if (pcap_strcasecmp($2, "i") == 0) {
6923a289941SAaron LI 					CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
6933a289941SAaron LI 				  } else if (pcap_strcasecmp($2, "s") == 0) {
6943a289941SAaron LI 					CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
6953a289941SAaron LI 				  } else if (pcap_strcasecmp($2, "u") == 0) {
6963a289941SAaron LI 					CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
6973a289941SAaron LI 				  } else {
69897a9217aSAntonio Huete Jimenez 					int subtype;
69997a9217aSAntonio Huete Jimenez 
70097a9217aSAntonio Huete Jimenez 					subtype = str2tok($2, llc_s_subtypes);
7013a289941SAaron LI 					if (subtype != -1) {
7023a289941SAaron LI 						CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
7033a289941SAaron LI 					} else {
70497a9217aSAntonio Huete Jimenez 						subtype = str2tok($2, llc_u_subtypes);
7053a289941SAaron LI 						if (subtype == -1) {
7063a289941SAaron LI 							bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
7073a289941SAaron LI 							YYABORT;
7083a289941SAaron LI 						}
7093a289941SAaron LI 						CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
71097a9217aSAntonio Huete Jimenez 					}
71197a9217aSAntonio Huete Jimenez 				  }
71297a9217aSAntonio Huete Jimenez 				}
71397a9217aSAntonio Huete Jimenez 				/* sigh, "rnr" is already a keyword for PF */
7143a289941SAaron LI 	| LLC PF_RNR		{ CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
71597a9217aSAntonio Huete Jimenez 	;
71697a9217aSAntonio Huete Jimenez 
717ea16f64eSAntonio Huete Jimenez dir:	  NUM			{ $$ = (int)$1; }
7183a289941SAaron LI 	| ID			{ CHECK_PTR_VAL($1);
7193a289941SAaron LI 				  if (pcap_strcasecmp($1, "nods") == 0)
720de0d3203SPeter Avalos 					$$ = IEEE80211_FC1_DIR_NODS;
721de0d3203SPeter Avalos 				  else if (pcap_strcasecmp($1, "tods") == 0)
722de0d3203SPeter Avalos 					$$ = IEEE80211_FC1_DIR_TODS;
723de0d3203SPeter Avalos 				  else if (pcap_strcasecmp($1, "fromds") == 0)
724de0d3203SPeter Avalos 					$$ = IEEE80211_FC1_DIR_FROMDS;
725de0d3203SPeter Avalos 				  else if (pcap_strcasecmp($1, "dstods") == 0)
726de0d3203SPeter Avalos 					$$ = IEEE80211_FC1_DIR_DSTODS;
7273a289941SAaron LI 				  else {
7283a289941SAaron LI 					bpf_set_error(cstate, "unknown 802.11 direction");
7293a289941SAaron LI 					YYABORT;
7303a289941SAaron LI 				  }
731de0d3203SPeter Avalos 				}
732de0d3203SPeter Avalos 	;
733de0d3203SPeter Avalos 
7341077d0bdSPeter Avalos reason:	  NUM			{ $$ = $1; }
7353a289941SAaron LI 	| ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
7361077d0bdSPeter Avalos 	;
7371077d0bdSPeter Avalos 
7383a289941SAaron LI action:	  ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
7391077d0bdSPeter Avalos 	;
7401077d0bdSPeter Avalos 
7411077d0bdSPeter Avalos relop:	  '>'			{ $$ = BPF_JGT; }
7421077d0bdSPeter Avalos 	| GEQ			{ $$ = BPF_JGE; }
7431077d0bdSPeter Avalos 	| '='			{ $$ = BPF_JEQ; }
7441077d0bdSPeter Avalos 	;
7451077d0bdSPeter Avalos irelop:	  LEQ			{ $$ = BPF_JGT; }
7461077d0bdSPeter Avalos 	| '<'			{ $$ = BPF_JGE; }
7471077d0bdSPeter Avalos 	| NEQ			{ $$ = BPF_JEQ; }
7481077d0bdSPeter Avalos 	;
7493a289941SAaron LI arth:	  pnum			{ CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
7501077d0bdSPeter Avalos 	| narth
7511077d0bdSPeter Avalos 	;
7523a289941SAaron LI narth:	  pname '[' arth ']'		{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
7533a289941SAaron LI 	| pname '[' arth ':' NUM ']'	{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
7543a289941SAaron LI 	| arth '+' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
7553a289941SAaron LI 	| arth '-' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
7563a289941SAaron LI 	| arth '*' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
7573a289941SAaron LI 	| arth '/' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
7583a289941SAaron LI 	| arth '%' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
7593a289941SAaron LI 	| arth '&' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
7603a289941SAaron LI 	| arth '|' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
7613a289941SAaron LI 	| arth '^' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
7623a289941SAaron LI 	| arth LSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
7633a289941SAaron LI 	| arth RSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
7643a289941SAaron LI 	| '-' arth %prec UMINUS		{ CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
7651077d0bdSPeter Avalos 	| paren narth ')'		{ $$ = $2; }
7663a289941SAaron LI 	| LEN				{ CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
7671077d0bdSPeter Avalos 	;
7681077d0bdSPeter Avalos byteop:	  '&'			{ $$ = '&'; }
7691077d0bdSPeter Avalos 	| '|'			{ $$ = '|'; }
7701077d0bdSPeter Avalos 	| '<'			{ $$ = '<'; }
7711077d0bdSPeter Avalos 	| '>'			{ $$ = '>'; }
7721077d0bdSPeter Avalos 	| '='			{ $$ = '='; }
7731077d0bdSPeter Avalos 	;
7741077d0bdSPeter Avalos pnum:	  NUM
7751077d0bdSPeter Avalos 	| paren pnum ')'	{ $$ = $2; }
7761077d0bdSPeter Avalos 	;
7771077d0bdSPeter Avalos atmtype: LANE			{ $$ = A_LANE; }
7781077d0bdSPeter Avalos 	| METAC			{ $$ = A_METAC;	}
7791077d0bdSPeter Avalos 	| BCC			{ $$ = A_BCC; }
7801077d0bdSPeter Avalos 	| OAMF4EC		{ $$ = A_OAMF4EC; }
7811077d0bdSPeter Avalos 	| OAMF4SC		{ $$ = A_OAMF4SC; }
7821077d0bdSPeter Avalos 	| SC			{ $$ = A_SC; }
7831077d0bdSPeter Avalos 	| ILMIC			{ $$ = A_ILMIC; }
7841077d0bdSPeter Avalos 	;
7851077d0bdSPeter Avalos atmmultitype: OAM		{ $$ = A_OAM; }
7861077d0bdSPeter Avalos 	| OAMF4			{ $$ = A_OAMF4; }
7871077d0bdSPeter Avalos 	| CONNECTMSG		{ $$ = A_CONNECTMSG; }
7881077d0bdSPeter Avalos 	| METACONNECT		{ $$ = A_METACONNECT; }
7891077d0bdSPeter Avalos 	;
7901077d0bdSPeter Avalos 	/* ATM field types quantifier */
7911077d0bdSPeter Avalos atmfield: VPI			{ $$.atmfieldtype = A_VPI; }
7921077d0bdSPeter Avalos 	| VCI			{ $$.atmfieldtype = A_VCI; }
7931077d0bdSPeter Avalos 	;
7941077d0bdSPeter Avalos atmvalue: atmfieldvalue
795ea16f64eSAntonio Huete Jimenez 	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 0))); }
796ea16f64eSAntonio Huete Jimenez 	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 1))); }
7971077d0bdSPeter Avalos 	| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
7981077d0bdSPeter Avalos 	;
7991077d0bdSPeter Avalos atmfieldvalue: NUM {
8001077d0bdSPeter Avalos 	$$.atmfieldtype = $<blk>0.atmfieldtype;
8011077d0bdSPeter Avalos 	if ($$.atmfieldtype == A_VPI ||
8021077d0bdSPeter Avalos 	    $$.atmfieldtype == A_VCI)
803ea16f64eSAntonio Huete Jimenez 		CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, $1, BPF_JEQ, 0)));
8041077d0bdSPeter Avalos 	}
8051077d0bdSPeter Avalos 	;
8061077d0bdSPeter Avalos atmlistvalue: atmfieldvalue
8071077d0bdSPeter Avalos 	| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
8081077d0bdSPeter Avalos 	;
8091077d0bdSPeter Avalos 	/* MTP2 types quantifier */
8101077d0bdSPeter Avalos mtp2type: FISU			{ $$ = M_FISU; }
8111077d0bdSPeter Avalos 	| LSSU			{ $$ = M_LSSU; }
8121077d0bdSPeter Avalos 	| MSU			{ $$ = M_MSU; }
81397a9217aSAntonio Huete Jimenez 	| HFISU			{ $$ = MH_FISU; }
81497a9217aSAntonio Huete Jimenez 	| HLSSU			{ $$ = MH_LSSU; }
81597a9217aSAntonio Huete Jimenez 	| HMSU			{ $$ = MH_MSU; }
8161077d0bdSPeter Avalos 	;
8171077d0bdSPeter Avalos 	/* MTP3 field types quantifier */
8181077d0bdSPeter Avalos mtp3field: SIO			{ $$.mtp3fieldtype = M_SIO; }
8191077d0bdSPeter Avalos 	| OPC			{ $$.mtp3fieldtype = M_OPC; }
8201077d0bdSPeter Avalos 	| DPC			{ $$.mtp3fieldtype = M_DPC; }
8211077d0bdSPeter Avalos 	| SLS                   { $$.mtp3fieldtype = M_SLS; }
82297a9217aSAntonio Huete Jimenez 	| HSIO			{ $$.mtp3fieldtype = MH_SIO; }
82397a9217aSAntonio Huete Jimenez 	| HOPC			{ $$.mtp3fieldtype = MH_OPC; }
82497a9217aSAntonio Huete Jimenez 	| HDPC			{ $$.mtp3fieldtype = MH_DPC; }
82597a9217aSAntonio Huete Jimenez 	| HSLS                  { $$.mtp3fieldtype = MH_SLS; }
8261077d0bdSPeter Avalos 	;
8271077d0bdSPeter Avalos mtp3value: mtp3fieldvalue
828ea16f64eSAntonio Huete Jimenez 	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 0))); }
829ea16f64eSAntonio Huete Jimenez 	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 1))); }
8301077d0bdSPeter Avalos 	| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
8311077d0bdSPeter Avalos 	;
8321077d0bdSPeter Avalos mtp3fieldvalue: NUM {
8331077d0bdSPeter Avalos 	$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
8341077d0bdSPeter Avalos 	if ($$.mtp3fieldtype == M_SIO ||
8351077d0bdSPeter Avalos 	    $$.mtp3fieldtype == M_OPC ||
8361077d0bdSPeter Avalos 	    $$.mtp3fieldtype == M_DPC ||
83797a9217aSAntonio Huete Jimenez 	    $$.mtp3fieldtype == M_SLS ||
83897a9217aSAntonio Huete Jimenez 	    $$.mtp3fieldtype == MH_SIO ||
83997a9217aSAntonio Huete Jimenez 	    $$.mtp3fieldtype == MH_OPC ||
84097a9217aSAntonio Huete Jimenez 	    $$.mtp3fieldtype == MH_DPC ||
84197a9217aSAntonio Huete Jimenez 	    $$.mtp3fieldtype == MH_SLS)
842ea16f64eSAntonio Huete Jimenez 		CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, $1, BPF_JEQ, 0)));
8431077d0bdSPeter Avalos 	}
8441077d0bdSPeter Avalos 	;
8451077d0bdSPeter Avalos mtp3listvalue: mtp3fieldvalue
8461077d0bdSPeter Avalos 	| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
8471077d0bdSPeter Avalos 	;
8481077d0bdSPeter Avalos %%
849