xref: /freebsd/contrib/libpcap/grammar.y.in (revision 6f9cba8f)
1*6f9cba8fSJoseph Mingrone/*
2*6f9cba8fSJoseph Mingrone * We want a reentrant parser.
3*6f9cba8fSJoseph Mingrone */
4*6f9cba8fSJoseph Mingrone@REENTRANT_PARSER@
5*6f9cba8fSJoseph Mingrone
6*6f9cba8fSJoseph Mingrone/*
7*6f9cba8fSJoseph Mingrone * We also want a reentrant scanner, so we have to pass the
8*6f9cba8fSJoseph Mingrone * handle for the reentrant scanner to the parser, and the
9*6f9cba8fSJoseph Mingrone * parser has to pass it to the lexical analyzer.
10*6f9cba8fSJoseph Mingrone *
11*6f9cba8fSJoseph Mingrone * We use void * rather than yyscan_t because, at least with some
12*6f9cba8fSJoseph Mingrone * versions of Flex and Bison, if you use yyscan_t in %parse-param and
13*6f9cba8fSJoseph Mingrone * %lex-param, you have to include scanner.h before grammar.h to get
14*6f9cba8fSJoseph Mingrone * yyscan_t declared, and you have to include grammar.h before scanner.h
15*6f9cba8fSJoseph Mingrone * to get YYSTYPE declared.  Using void * breaks the cycle; the Flex
16*6f9cba8fSJoseph Mingrone * documentation says yyscan_t is just a void *.
17*6f9cba8fSJoseph Mingrone */
18*6f9cba8fSJoseph Mingrone%parse-param   {void *yyscanner}
19*6f9cba8fSJoseph Mingrone%lex-param   {void *yyscanner}
20*6f9cba8fSJoseph Mingrone
21*6f9cba8fSJoseph Mingrone/*
22*6f9cba8fSJoseph Mingrone * According to bison documentation, shift/reduce conflicts are not an issue
23*6f9cba8fSJoseph Mingrone * in most parsers as long as the number does not evolve over time:
24*6f9cba8fSJoseph Mingrone * https://www.gnu.org/software/bison/manual/html_node/Expect-Decl.html
25*6f9cba8fSJoseph Mingrone * So, following the advice use %expect to check the amount of shift/reduce
26*6f9cba8fSJoseph Mingrone * warnings.
27*6f9cba8fSJoseph Mingrone *
28*6f9cba8fSJoseph Mingrone * This doesn't appear to work in Berkeley YACC - 1.9 20170709; it still
29*6f9cba8fSJoseph Mingrone * warns of 38 shift/reduce conflicts.
30*6f9cba8fSJoseph Mingrone *
31*6f9cba8fSJoseph Mingrone * The Berkeley YACC documentation:
32*6f9cba8fSJoseph Mingrone *
33*6f9cba8fSJoseph Mingrone *    https://invisible-island.net/byacc/manpage/yacc.html
34*6f9cba8fSJoseph Mingrone *
35*6f9cba8fSJoseph Mingrone * claims that "Bison's support for "%expect" is broken in more than one
36*6f9cba8fSJoseph Mingrone * release.", but doesn't give details.  Hopefully, that only means that
37*6f9cba8fSJoseph Mingrone * you get warnings even if you have the expected number of shift/reduce
38*6f9cba8fSJoseph Mingrone * conflicts, not that anything else fails.
39*6f9cba8fSJoseph Mingrone */
40*6f9cba8fSJoseph Mingrone%expect 38
41*6f9cba8fSJoseph Mingrone
42*6f9cba8fSJoseph Mingrone/*
43*6f9cba8fSJoseph Mingrone * And we need to pass the compiler state to the scanner.
44*6f9cba8fSJoseph Mingrone */
45*6f9cba8fSJoseph Mingrone%parse-param { compiler_state_t *cstate }
46*6f9cba8fSJoseph Mingrone
47*6f9cba8fSJoseph Mingrone%{
48*6f9cba8fSJoseph Mingrone/*
49*6f9cba8fSJoseph Mingrone * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
50*6f9cba8fSJoseph Mingrone *	The Regents of the University of California.  All rights reserved.
51*6f9cba8fSJoseph Mingrone *
52*6f9cba8fSJoseph Mingrone * Redistribution and use in source and binary forms, with or without
53*6f9cba8fSJoseph Mingrone * modification, are permitted provided that: (1) source code distributions
54*6f9cba8fSJoseph Mingrone * retain the above copyright notice and this paragraph in its entirety, (2)
55*6f9cba8fSJoseph Mingrone * distributions including binary code include the above copyright notice and
56*6f9cba8fSJoseph Mingrone * this paragraph in its entirety in the documentation or other materials
57*6f9cba8fSJoseph Mingrone * provided with the distribution, and (3) all advertising materials mentioning
58*6f9cba8fSJoseph Mingrone * features or use of this software display the following acknowledgement:
59*6f9cba8fSJoseph Mingrone * ``This product includes software developed by the University of California,
60*6f9cba8fSJoseph Mingrone * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
61*6f9cba8fSJoseph Mingrone * the University nor the names of its contributors may be used to endorse
62*6f9cba8fSJoseph Mingrone * or promote products derived from this software without specific prior
63*6f9cba8fSJoseph Mingrone * written permission.
64*6f9cba8fSJoseph Mingrone * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
65*6f9cba8fSJoseph Mingrone * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
66*6f9cba8fSJoseph Mingrone * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
67*6f9cba8fSJoseph Mingrone *
68*6f9cba8fSJoseph Mingrone */
69*6f9cba8fSJoseph Mingrone
70*6f9cba8fSJoseph Mingrone#ifdef HAVE_CONFIG_H
71*6f9cba8fSJoseph Mingrone#include <config.h>
72*6f9cba8fSJoseph Mingrone#endif
73*6f9cba8fSJoseph Mingrone
74*6f9cba8fSJoseph Mingrone/*
75*6f9cba8fSJoseph Mingrone * grammar.h requires gencode.h and sometimes breaks in a polluted namespace
76*6f9cba8fSJoseph Mingrone * (see ftmacros.h), so include it early.
77*6f9cba8fSJoseph Mingrone */
78*6f9cba8fSJoseph Mingrone#include "gencode.h"
79*6f9cba8fSJoseph Mingrone#include "grammar.h"
80*6f9cba8fSJoseph Mingrone
81*6f9cba8fSJoseph Mingrone#include <stdlib.h>
82*6f9cba8fSJoseph Mingrone
83*6f9cba8fSJoseph Mingrone#ifndef _WIN32
84*6f9cba8fSJoseph Mingrone#include <sys/types.h>
85*6f9cba8fSJoseph Mingrone#include <sys/socket.h>
86*6f9cba8fSJoseph Mingrone
87*6f9cba8fSJoseph Mingrone#if __STDC__
88*6f9cba8fSJoseph Mingronestruct mbuf;
89*6f9cba8fSJoseph Mingronestruct rtentry;
90*6f9cba8fSJoseph Mingrone#endif
91*6f9cba8fSJoseph Mingrone
92*6f9cba8fSJoseph Mingrone#include <netinet/in.h>
93*6f9cba8fSJoseph Mingrone#include <arpa/inet.h>
94*6f9cba8fSJoseph Mingrone#endif /* _WIN32 */
95*6f9cba8fSJoseph Mingrone
96*6f9cba8fSJoseph Mingrone#include <stdio.h>
97*6f9cba8fSJoseph Mingrone
98*6f9cba8fSJoseph Mingrone#include "diag-control.h"
99*6f9cba8fSJoseph Mingrone
100*6f9cba8fSJoseph Mingrone#include "pcap-int.h"
101*6f9cba8fSJoseph Mingrone
102*6f9cba8fSJoseph Mingrone#include "scanner.h"
103*6f9cba8fSJoseph Mingrone
104*6f9cba8fSJoseph Mingrone#include "llc.h"
105*6f9cba8fSJoseph Mingrone#include "ieee80211.h"
106*6f9cba8fSJoseph Mingrone#include "pflog.h"
107*6f9cba8fSJoseph Mingrone#include <pcap/namedb.h>
108*6f9cba8fSJoseph Mingrone
109*6f9cba8fSJoseph Mingrone#ifdef HAVE_OS_PROTO_H
110*6f9cba8fSJoseph Mingrone#include "os-proto.h"
111*6f9cba8fSJoseph Mingrone#endif
112*6f9cba8fSJoseph Mingrone
113*6f9cba8fSJoseph Mingrone#ifdef YYBYACC
114*6f9cba8fSJoseph Mingrone/*
115*6f9cba8fSJoseph Mingrone * Both Berkeley YACC and Bison define yydebug (under whatever name
116*6f9cba8fSJoseph Mingrone * it has) as a global, but Bison does so only if YYDEBUG is defined.
117*6f9cba8fSJoseph Mingrone * Berkeley YACC define it even if YYDEBUG isn't defined; declare it
118*6f9cba8fSJoseph Mingrone * here to suppress a warning.
119*6f9cba8fSJoseph Mingrone */
120*6f9cba8fSJoseph Mingrone#if !defined(YYDEBUG)
121*6f9cba8fSJoseph Mingroneextern int yydebug;
122*6f9cba8fSJoseph Mingrone#endif
123*6f9cba8fSJoseph Mingrone
124*6f9cba8fSJoseph Mingrone/*
125*6f9cba8fSJoseph Mingrone * In Berkeley YACC, yynerrs (under whatever name it has) is global,
126*6f9cba8fSJoseph Mingrone * even if it's building a reentrant parser.  In Bison, it's local
127*6f9cba8fSJoseph Mingrone * in reentrant parsers.
128*6f9cba8fSJoseph Mingrone *
129*6f9cba8fSJoseph Mingrone * Declare it to squelch a warning.
130*6f9cba8fSJoseph Mingrone */
131*6f9cba8fSJoseph Mingroneextern int yynerrs;
132*6f9cba8fSJoseph Mingrone#endif
133*6f9cba8fSJoseph Mingrone
134*6f9cba8fSJoseph Mingrone#define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
135*6f9cba8fSJoseph Mingrone			 (q).dir = (unsigned char)(d),\
136*6f9cba8fSJoseph Mingrone			 (q).addr = (unsigned char)(a)
137*6f9cba8fSJoseph Mingrone
138*6f9cba8fSJoseph Mingronestruct tok {
139*6f9cba8fSJoseph Mingrone	int v;			/* value */
140*6f9cba8fSJoseph Mingrone	const char *s;		/* string */
141*6f9cba8fSJoseph Mingrone};
142*6f9cba8fSJoseph Mingrone
143*6f9cba8fSJoseph Mingronestatic const struct tok ieee80211_types[] = {
144*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_DATA, "data" },
145*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_MGT, "mgt" },
146*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_MGT, "management" },
147*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_CTL, "ctl" },
148*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_CTL, "control" },
149*6f9cba8fSJoseph Mingrone	{ 0, NULL }
150*6f9cba8fSJoseph Mingrone};
151*6f9cba8fSJoseph Mingronestatic const struct tok ieee80211_mgt_subtypes[] = {
152*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
153*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
154*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
155*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
156*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
157*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
158*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
159*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
160*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
161*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
162*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
163*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
164*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
165*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
166*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
167*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
168*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
169*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
170*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
171*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
172*6f9cba8fSJoseph Mingrone	{ 0, NULL }
173*6f9cba8fSJoseph Mingrone};
174*6f9cba8fSJoseph Mingronestatic const struct tok ieee80211_ctl_subtypes[] = {
175*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
176*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_RTS, "rts" },
177*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CTS, "cts" },
178*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_ACK, "ack" },
179*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
180*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
181*6f9cba8fSJoseph Mingrone	{ 0, NULL }
182*6f9cba8fSJoseph Mingrone};
183*6f9cba8fSJoseph Mingronestatic const struct tok ieee80211_data_subtypes[] = {
184*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_DATA, "data" },
185*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
186*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
187*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
188*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_NODATA, "null" },
189*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
190*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll"  },
191*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
192*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
193*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
194*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
195*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
196*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
197*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
198*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
199*6f9cba8fSJoseph Mingrone	{ 0, NULL }
200*6f9cba8fSJoseph Mingrone};
201*6f9cba8fSJoseph Mingronestatic const struct tok llc_s_subtypes[] = {
202*6f9cba8fSJoseph Mingrone	{ LLC_RR, "rr" },
203*6f9cba8fSJoseph Mingrone	{ LLC_RNR, "rnr" },
204*6f9cba8fSJoseph Mingrone	{ LLC_REJ, "rej" },
205*6f9cba8fSJoseph Mingrone	{ 0, NULL }
206*6f9cba8fSJoseph Mingrone};
207*6f9cba8fSJoseph Mingronestatic const struct tok llc_u_subtypes[] = {
208*6f9cba8fSJoseph Mingrone	{ LLC_UI, "ui" },
209*6f9cba8fSJoseph Mingrone	{ LLC_UA, "ua" },
210*6f9cba8fSJoseph Mingrone	{ LLC_DISC, "disc" },
211*6f9cba8fSJoseph Mingrone	{ LLC_DM, "dm" },
212*6f9cba8fSJoseph Mingrone	{ LLC_SABME, "sabme" },
213*6f9cba8fSJoseph Mingrone	{ LLC_TEST, "test" },
214*6f9cba8fSJoseph Mingrone	{ LLC_XID, "xid" },
215*6f9cba8fSJoseph Mingrone	{ LLC_FRMR, "frmr" },
216*6f9cba8fSJoseph Mingrone	{ 0, NULL }
217*6f9cba8fSJoseph Mingrone};
218*6f9cba8fSJoseph Mingronestruct type2tok {
219*6f9cba8fSJoseph Mingrone	int type;
220*6f9cba8fSJoseph Mingrone	const struct tok *tok;
221*6f9cba8fSJoseph Mingrone};
222*6f9cba8fSJoseph Mingronestatic const struct type2tok ieee80211_type_subtypes[] = {
223*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
224*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
225*6f9cba8fSJoseph Mingrone	{ IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
226*6f9cba8fSJoseph Mingrone	{ 0, NULL }
227*6f9cba8fSJoseph Mingrone};
228*6f9cba8fSJoseph Mingrone
229*6f9cba8fSJoseph Mingronestatic int
230*6f9cba8fSJoseph Mingronestr2tok(const char *str, const struct tok *toks)
231*6f9cba8fSJoseph Mingrone{
232*6f9cba8fSJoseph Mingrone	int i;
233*6f9cba8fSJoseph Mingrone
234*6f9cba8fSJoseph Mingrone	for (i = 0; toks[i].s != NULL; i++) {
235*6f9cba8fSJoseph Mingrone		if (pcap_strcasecmp(toks[i].s, str) == 0) {
236*6f9cba8fSJoseph Mingrone			/*
237*6f9cba8fSJoseph Mingrone			 * Just in case somebody is using this to
238*6f9cba8fSJoseph Mingrone			 * generate values of -1/0xFFFFFFFF.
239*6f9cba8fSJoseph Mingrone			 * That won't work, as it's indistinguishable
240*6f9cba8fSJoseph Mingrone			 * from an error.
241*6f9cba8fSJoseph Mingrone			 */
242*6f9cba8fSJoseph Mingrone			if (toks[i].v == -1)
243*6f9cba8fSJoseph Mingrone				abort();
244*6f9cba8fSJoseph Mingrone			return (toks[i].v);
245*6f9cba8fSJoseph Mingrone		}
246*6f9cba8fSJoseph Mingrone	}
247*6f9cba8fSJoseph Mingrone	return (-1);
248*6f9cba8fSJoseph Mingrone}
249*6f9cba8fSJoseph Mingrone
250*6f9cba8fSJoseph Mingronestatic const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
251*6f9cba8fSJoseph Mingrone
252*6f9cba8fSJoseph Mingronestatic void
253*6f9cba8fSJoseph Mingroneyyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
254*6f9cba8fSJoseph Mingrone{
255*6f9cba8fSJoseph Mingrone	bpf_set_error(cstate, "can't parse filter expression: %s", msg);
256*6f9cba8fSJoseph Mingrone}
257*6f9cba8fSJoseph Mingrone
258*6f9cba8fSJoseph Mingronestatic const struct tok pflog_reasons[] = {
259*6f9cba8fSJoseph Mingrone	{ PFRES_MATCH,		"match" },
260*6f9cba8fSJoseph Mingrone	{ PFRES_BADOFF,		"bad-offset" },
261*6f9cba8fSJoseph Mingrone	{ PFRES_FRAG,		"fragment" },
262*6f9cba8fSJoseph Mingrone	{ PFRES_SHORT,		"short" },
263*6f9cba8fSJoseph Mingrone	{ PFRES_NORM,		"normalize" },
264*6f9cba8fSJoseph Mingrone	{ PFRES_MEMORY,		"memory" },
265*6f9cba8fSJoseph Mingrone	{ PFRES_TS,		"bad-timestamp" },
266*6f9cba8fSJoseph Mingrone	{ PFRES_CONGEST,	"congestion" },
267*6f9cba8fSJoseph Mingrone	{ PFRES_IPOPTIONS,	"ip-option" },
268*6f9cba8fSJoseph Mingrone	{ PFRES_PROTCKSUM,	"proto-cksum" },
269*6f9cba8fSJoseph Mingrone	{ PFRES_BADSTATE,	"state-mismatch" },
270*6f9cba8fSJoseph Mingrone	{ PFRES_STATEINS,	"state-insert" },
271*6f9cba8fSJoseph Mingrone	{ PFRES_MAXSTATES,	"state-limit" },
272*6f9cba8fSJoseph Mingrone	{ PFRES_SRCLIMIT,	"src-limit" },
273*6f9cba8fSJoseph Mingrone	{ PFRES_SYNPROXY,	"synproxy" },
274*6f9cba8fSJoseph Mingrone#if defined(__FreeBSD__)
275*6f9cba8fSJoseph Mingrone	{ PFRES_MAPFAILED,	"map-failed" },
276*6f9cba8fSJoseph Mingrone#elif defined(__NetBSD__)
277*6f9cba8fSJoseph Mingrone	{ PFRES_STATELOCKED,	"state-locked" },
278*6f9cba8fSJoseph Mingrone#elif defined(__OpenBSD__)
279*6f9cba8fSJoseph Mingrone	{ PFRES_TRANSLATE,	"translate" },
280*6f9cba8fSJoseph Mingrone	{ PFRES_NOROUTE,	"no-route" },
281*6f9cba8fSJoseph Mingrone#elif defined(__APPLE__)
282*6f9cba8fSJoseph Mingrone	{ PFRES_DUMMYNET,	"dummynet" },
283*6f9cba8fSJoseph Mingrone#endif
284*6f9cba8fSJoseph Mingrone	{ 0, NULL }
285*6f9cba8fSJoseph Mingrone};
286*6f9cba8fSJoseph Mingrone
287*6f9cba8fSJoseph Mingronestatic int
288*6f9cba8fSJoseph Mingronepfreason_to_num(compiler_state_t *cstate, const char *reason)
289*6f9cba8fSJoseph Mingrone{
290*6f9cba8fSJoseph Mingrone	int i;
291*6f9cba8fSJoseph Mingrone
292*6f9cba8fSJoseph Mingrone	i = str2tok(reason, pflog_reasons);
293*6f9cba8fSJoseph Mingrone	if (i == -1)
294*6f9cba8fSJoseph Mingrone		bpf_set_error(cstate, "unknown PF reason \"%s\"", reason);
295*6f9cba8fSJoseph Mingrone	return (i);
296*6f9cba8fSJoseph Mingrone}
297*6f9cba8fSJoseph Mingrone
298*6f9cba8fSJoseph Mingronestatic const struct tok pflog_actions[] = {
299*6f9cba8fSJoseph Mingrone	{ PF_PASS,		"pass" },
300*6f9cba8fSJoseph Mingrone	{ PF_PASS,		"accept" },	/* alias for "pass" */
301*6f9cba8fSJoseph Mingrone	{ PF_DROP,		"drop" },
302*6f9cba8fSJoseph Mingrone	{ PF_DROP,		"block" },	/* alias for "drop" */
303*6f9cba8fSJoseph Mingrone	{ PF_SCRUB,		"scrub" },
304*6f9cba8fSJoseph Mingrone	{ PF_NOSCRUB,		"noscrub" },
305*6f9cba8fSJoseph Mingrone	{ PF_NAT,		"nat" },
306*6f9cba8fSJoseph Mingrone	{ PF_NONAT,		"nonat" },
307*6f9cba8fSJoseph Mingrone	{ PF_BINAT,		"binat" },
308*6f9cba8fSJoseph Mingrone	{ PF_NOBINAT,		"nobinat" },
309*6f9cba8fSJoseph Mingrone	{ PF_RDR,		"rdr" },
310*6f9cba8fSJoseph Mingrone	{ PF_NORDR,		"nordr" },
311*6f9cba8fSJoseph Mingrone	{ PF_SYNPROXY_DROP,	"synproxy-drop" },
312*6f9cba8fSJoseph Mingrone#if defined(__FreeBSD__)
313*6f9cba8fSJoseph Mingrone	{ PF_DEFER,		"defer" },
314*6f9cba8fSJoseph Mingrone#elif defined(__OpenBSD__)
315*6f9cba8fSJoseph Mingrone	{ PF_DEFER,		"defer" },
316*6f9cba8fSJoseph Mingrone	{ PF_MATCH,		"match" },
317*6f9cba8fSJoseph Mingrone	{ PF_DIVERT,		"divert" },
318*6f9cba8fSJoseph Mingrone	{ PF_RT,		"rt" },
319*6f9cba8fSJoseph Mingrone	{ PF_AFRT,		"afrt" },
320*6f9cba8fSJoseph Mingrone#elif defined(__APPLE__)
321*6f9cba8fSJoseph Mingrone	{ PF_DUMMYNET,		"dummynet" },
322*6f9cba8fSJoseph Mingrone	{ PF_NODUMMYNET,	"nodummynet" },
323*6f9cba8fSJoseph Mingrone	{ PF_NAT64,		"nat64" },
324*6f9cba8fSJoseph Mingrone	{ PF_NONAT64,		"nonat64" },
325*6f9cba8fSJoseph Mingrone#endif
326*6f9cba8fSJoseph Mingrone	{ 0, NULL },
327*6f9cba8fSJoseph Mingrone};
328*6f9cba8fSJoseph Mingrone
329*6f9cba8fSJoseph Mingronestatic int
330*6f9cba8fSJoseph Mingronepfaction_to_num(compiler_state_t *cstate, const char *action)
331*6f9cba8fSJoseph Mingrone{
332*6f9cba8fSJoseph Mingrone	int i;
333*6f9cba8fSJoseph Mingrone
334*6f9cba8fSJoseph Mingrone	i = str2tok(action, pflog_actions);
335*6f9cba8fSJoseph Mingrone	if (i == -1)
336*6f9cba8fSJoseph Mingrone		bpf_set_error(cstate, "unknown PF action \"%s\"", action);
337*6f9cba8fSJoseph Mingrone	return (i);
338*6f9cba8fSJoseph Mingrone}
339*6f9cba8fSJoseph Mingrone
340*6f9cba8fSJoseph Mingrone/*
341*6f9cba8fSJoseph Mingrone * For calls that might return an "an error occurred" value.
342*6f9cba8fSJoseph Mingrone */
343*6f9cba8fSJoseph Mingrone#define CHECK_INT_VAL(val)	if (val == -1) YYABORT
344*6f9cba8fSJoseph Mingrone#define CHECK_PTR_VAL(val)	if (val == NULL) YYABORT
345*6f9cba8fSJoseph Mingrone
346*6f9cba8fSJoseph MingroneDIAG_OFF_BISON_BYACC
347*6f9cba8fSJoseph Mingrone%}
348*6f9cba8fSJoseph Mingrone
349*6f9cba8fSJoseph Mingrone%union {
350*6f9cba8fSJoseph Mingrone	int i;
351*6f9cba8fSJoseph Mingrone	bpf_u_int32 h;
352*6f9cba8fSJoseph Mingrone	char *s;
353*6f9cba8fSJoseph Mingrone	struct stmt *stmt;
354*6f9cba8fSJoseph Mingrone	struct arth *a;
355*6f9cba8fSJoseph Mingrone	struct {
356*6f9cba8fSJoseph Mingrone		struct qual q;
357*6f9cba8fSJoseph Mingrone		int atmfieldtype;
358*6f9cba8fSJoseph Mingrone		int mtp3fieldtype;
359*6f9cba8fSJoseph Mingrone		struct block *b;
360*6f9cba8fSJoseph Mingrone	} blk;
361*6f9cba8fSJoseph Mingrone	struct block *rblk;
362*6f9cba8fSJoseph Mingrone}
363*6f9cba8fSJoseph Mingrone
364*6f9cba8fSJoseph Mingrone%type	<blk>	expr id nid pid term rterm qid
365*6f9cba8fSJoseph Mingrone%type	<blk>	head
366*6f9cba8fSJoseph Mingrone%type	<i>	pqual dqual aqual ndaqual
367*6f9cba8fSJoseph Mingrone%type	<a>	arth narth
368*6f9cba8fSJoseph Mingrone%type	<i>	byteop pname relop irelop
369*6f9cba8fSJoseph Mingrone%type	<h>	pnum
370*6f9cba8fSJoseph Mingrone%type	<blk>	and or paren not null prog
371*6f9cba8fSJoseph Mingrone%type	<rblk>	other pfvar p80211 pllc
372*6f9cba8fSJoseph Mingrone%type	<i>	atmtype atmmultitype
373*6f9cba8fSJoseph Mingrone%type	<blk>	atmfield
374*6f9cba8fSJoseph Mingrone%type	<blk>	atmfieldvalue atmvalue atmlistvalue
375*6f9cba8fSJoseph Mingrone%type	<i>	mtp2type
376*6f9cba8fSJoseph Mingrone%type	<blk>	mtp3field
377*6f9cba8fSJoseph Mingrone%type	<blk>	mtp3fieldvalue mtp3value mtp3listvalue
378*6f9cba8fSJoseph Mingrone
379*6f9cba8fSJoseph Mingrone
380*6f9cba8fSJoseph Mingrone%token  DST SRC HOST GATEWAY
381*6f9cba8fSJoseph Mingrone%token  NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
382*6f9cba8fSJoseph Mingrone%token  ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
383*6f9cba8fSJoseph Mingrone%token  ATALK AARP DECNET LAT SCA MOPRC MOPDL
384*6f9cba8fSJoseph Mingrone%token  TK_BROADCAST TK_MULTICAST
385*6f9cba8fSJoseph Mingrone%token  NUM INBOUND OUTBOUND
386*6f9cba8fSJoseph Mingrone%token  IFINDEX
387*6f9cba8fSJoseph Mingrone%token  PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
388*6f9cba8fSJoseph Mingrone%token	TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
389*6f9cba8fSJoseph Mingrone%token  LINK
390*6f9cba8fSJoseph Mingrone%token	GEQ LEQ NEQ
391*6f9cba8fSJoseph Mingrone%token	ID EID HID HID6 AID
392*6f9cba8fSJoseph Mingrone%token	LSH RSH
393*6f9cba8fSJoseph Mingrone%token  LEN
394*6f9cba8fSJoseph Mingrone%token  IPV6 ICMPV6 AH ESP
395*6f9cba8fSJoseph Mingrone%token	VLAN MPLS
396*6f9cba8fSJoseph Mingrone%token	PPPOED PPPOES GENEVE
397*6f9cba8fSJoseph Mingrone%token  ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
398*6f9cba8fSJoseph Mingrone%token  STP
399*6f9cba8fSJoseph Mingrone%token  IPX
400*6f9cba8fSJoseph Mingrone%token  NETBEUI
401*6f9cba8fSJoseph Mingrone%token	LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
402*6f9cba8fSJoseph Mingrone%token	OAM OAMF4 CONNECTMSG METACONNECT
403*6f9cba8fSJoseph Mingrone%token	VPI VCI
404*6f9cba8fSJoseph Mingrone%token	RADIO
405*6f9cba8fSJoseph Mingrone%token	FISU LSSU MSU HFISU HLSSU HMSU
406*6f9cba8fSJoseph Mingrone%token	SIO OPC DPC SLS HSIO HOPC HDPC HSLS
407*6f9cba8fSJoseph Mingrone%token	LEX_ERROR
408*6f9cba8fSJoseph Mingrone
409*6f9cba8fSJoseph Mingrone%type	<s> ID EID AID
410*6f9cba8fSJoseph Mingrone%type	<s> HID HID6
411*6f9cba8fSJoseph Mingrone%type	<h> NUM
412*6f9cba8fSJoseph Mingrone%type	<i> action reason type subtype type_subtype dir
413*6f9cba8fSJoseph Mingrone
414*6f9cba8fSJoseph Mingrone%left OR AND
415*6f9cba8fSJoseph Mingrone%nonassoc  '!'
416*6f9cba8fSJoseph Mingrone%left '|'
417*6f9cba8fSJoseph Mingrone%left '&'
418*6f9cba8fSJoseph Mingrone%left LSH RSH
419*6f9cba8fSJoseph Mingrone%left '+' '-'
420*6f9cba8fSJoseph Mingrone%left '*' '/'
421*6f9cba8fSJoseph Mingrone%nonassoc UMINUS
422*6f9cba8fSJoseph Mingrone%%
423*6f9cba8fSJoseph Mingroneprog:	  null expr
424*6f9cba8fSJoseph Mingrone{
425*6f9cba8fSJoseph Mingrone	CHECK_INT_VAL(finish_parse(cstate, $2.b));
426*6f9cba8fSJoseph Mingrone}
427*6f9cba8fSJoseph Mingrone	| null
428*6f9cba8fSJoseph Mingrone	;
429*6f9cba8fSJoseph Mingronenull:	  /* null */		{ $$.q = qerr; }
430*6f9cba8fSJoseph Mingrone	;
431*6f9cba8fSJoseph Mingroneexpr:	  term
432*6f9cba8fSJoseph Mingrone	| expr and term		{ gen_and($1.b, $3.b); $$ = $3; }
433*6f9cba8fSJoseph Mingrone	| expr and id		{ gen_and($1.b, $3.b); $$ = $3; }
434*6f9cba8fSJoseph Mingrone	| expr or term		{ gen_or($1.b, $3.b); $$ = $3; }
435*6f9cba8fSJoseph Mingrone	| expr or id		{ gen_or($1.b, $3.b); $$ = $3; }
436*6f9cba8fSJoseph Mingrone	;
437*6f9cba8fSJoseph Mingroneand:	  AND			{ $$ = $<blk>0; }
438*6f9cba8fSJoseph Mingrone	;
439*6f9cba8fSJoseph Mingroneor:	  OR			{ $$ = $<blk>0; }
440*6f9cba8fSJoseph Mingrone	;
441*6f9cba8fSJoseph Mingroneid:	  nid
442*6f9cba8fSJoseph Mingrone	| pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
443*6f9cba8fSJoseph Mingrone						   $$.q = $<blk>0.q))); }
444*6f9cba8fSJoseph Mingrone	| paren pid ')'		{ $$ = $2; }
445*6f9cba8fSJoseph Mingrone	;
446*6f9cba8fSJoseph Mingronenid:	  ID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
447*6f9cba8fSJoseph Mingrone	| HID '/' NUM		{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
448*6f9cba8fSJoseph Mingrone				    $$.q = $<blk>0.q))); }
449*6f9cba8fSJoseph Mingrone	| HID NETMASK HID	{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
450*6f9cba8fSJoseph Mingrone				    $$.q = $<blk>0.q))); }
451*6f9cba8fSJoseph Mingrone	| HID			{
452*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL($1);
453*6f9cba8fSJoseph Mingrone				  /* Decide how to parse HID based on proto */
454*6f9cba8fSJoseph Mingrone				  $$.q = $<blk>0.q;
455*6f9cba8fSJoseph Mingrone				  if ($$.q.addr == Q_PORT) {
456*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "'port' modifier applied to ip host");
457*6f9cba8fSJoseph Mingrone					YYABORT;
458*6f9cba8fSJoseph Mingrone				  } else if ($$.q.addr == Q_PORTRANGE) {
459*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "'portrange' modifier applied to ip host");
460*6f9cba8fSJoseph Mingrone					YYABORT;
461*6f9cba8fSJoseph Mingrone				  } else if ($$.q.addr == Q_PROTO) {
462*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "'proto' modifier applied to ip host");
463*6f9cba8fSJoseph Mingrone					YYABORT;
464*6f9cba8fSJoseph Mingrone				  } else if ($$.q.addr == Q_PROTOCHAIN) {
465*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "'protochain' modifier applied to ip host");
466*6f9cba8fSJoseph Mingrone					YYABORT;
467*6f9cba8fSJoseph Mingrone				  }
468*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
469*6f9cba8fSJoseph Mingrone				}
470*6f9cba8fSJoseph Mingrone	| HID6 '/' NUM		{
471*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL($1);
472*6f9cba8fSJoseph Mingrone#ifdef INET6
473*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
474*6f9cba8fSJoseph Mingrone				    $$.q = $<blk>0.q)));
475*6f9cba8fSJoseph Mingrone#else
476*6f9cba8fSJoseph Mingrone				  bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
477*6f9cba8fSJoseph Mingrone					"in this configuration");
478*6f9cba8fSJoseph Mingrone				  YYABORT;
479*6f9cba8fSJoseph Mingrone#endif /*INET6*/
480*6f9cba8fSJoseph Mingrone				}
481*6f9cba8fSJoseph Mingrone	| HID6			{
482*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL($1);
483*6f9cba8fSJoseph Mingrone#ifdef INET6
484*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
485*6f9cba8fSJoseph Mingrone				    $$.q = $<blk>0.q)));
486*6f9cba8fSJoseph Mingrone#else
487*6f9cba8fSJoseph Mingrone				  bpf_set_error(cstate, "'ip6addr' not supported "
488*6f9cba8fSJoseph Mingrone					"in this configuration");
489*6f9cba8fSJoseph Mingrone				  YYABORT;
490*6f9cba8fSJoseph Mingrone#endif /*INET6*/
491*6f9cba8fSJoseph Mingrone				}
492*6f9cba8fSJoseph Mingrone	| EID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
493*6f9cba8fSJoseph Mingrone	| AID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
494*6f9cba8fSJoseph Mingrone	| not id		{ gen_not($2.b); $$ = $2; }
495*6f9cba8fSJoseph Mingrone	;
496*6f9cba8fSJoseph Mingronenot:	  '!'			{ $$ = $<blk>0; }
497*6f9cba8fSJoseph Mingrone	;
498*6f9cba8fSJoseph Mingroneparen:	  '('			{ $$ = $<blk>0; }
499*6f9cba8fSJoseph Mingrone	;
500*6f9cba8fSJoseph Mingronepid:	  nid
501*6f9cba8fSJoseph Mingrone	| qid and id		{ gen_and($1.b, $3.b); $$ = $3; }
502*6f9cba8fSJoseph Mingrone	| qid or id		{ gen_or($1.b, $3.b); $$ = $3; }
503*6f9cba8fSJoseph Mingrone	;
504*6f9cba8fSJoseph Mingroneqid:	  pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
505*6f9cba8fSJoseph Mingrone						   $$.q = $<blk>0.q))); }
506*6f9cba8fSJoseph Mingrone	| pid
507*6f9cba8fSJoseph Mingrone	;
508*6f9cba8fSJoseph Mingroneterm:	  rterm
509*6f9cba8fSJoseph Mingrone	| not term		{ gen_not($2.b); $$ = $2; }
510*6f9cba8fSJoseph Mingrone	;
511*6f9cba8fSJoseph Mingronehead:	  pqual dqual aqual	{ QSET($$.q, $1, $2, $3); }
512*6f9cba8fSJoseph Mingrone	| pqual dqual		{ QSET($$.q, $1, $2, Q_DEFAULT); }
513*6f9cba8fSJoseph Mingrone	| pqual aqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
514*6f9cba8fSJoseph Mingrone	| pqual PROTO		{ QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
515*6f9cba8fSJoseph Mingrone	| pqual PROTOCHAIN	{
516*6f9cba8fSJoseph Mingrone#ifdef NO_PROTOCHAIN
517*6f9cba8fSJoseph Mingrone				  bpf_set_error(cstate, "protochain not supported");
518*6f9cba8fSJoseph Mingrone				  YYABORT;
519*6f9cba8fSJoseph Mingrone#else
520*6f9cba8fSJoseph Mingrone				  QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
521*6f9cba8fSJoseph Mingrone#endif
522*6f9cba8fSJoseph Mingrone				}
523*6f9cba8fSJoseph Mingrone	| pqual ndaqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
524*6f9cba8fSJoseph Mingrone	;
525*6f9cba8fSJoseph Mingronerterm:	  head id		{ $$ = $2; }
526*6f9cba8fSJoseph Mingrone	| paren expr ')'	{ $$.b = $2.b; $$.q = $1.q; }
527*6f9cba8fSJoseph Mingrone	| pname			{ CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
528*6f9cba8fSJoseph Mingrone	| arth relop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
529*6f9cba8fSJoseph Mingrone				  $$.q = qerr; }
530*6f9cba8fSJoseph Mingrone	| arth irelop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
531*6f9cba8fSJoseph Mingrone				  $$.q = qerr; }
532*6f9cba8fSJoseph Mingrone	| other			{ $$.b = $1; $$.q = qerr; }
533*6f9cba8fSJoseph Mingrone	| atmtype		{ CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
534*6f9cba8fSJoseph Mingrone	| atmmultitype		{ CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
535*6f9cba8fSJoseph Mingrone	| atmfield atmvalue	{ $$.b = $2.b; $$.q = qerr; }
536*6f9cba8fSJoseph Mingrone	| mtp2type		{ CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
537*6f9cba8fSJoseph Mingrone	| mtp3field mtp3value	{ $$.b = $2.b; $$.q = qerr; }
538*6f9cba8fSJoseph Mingrone	;
539*6f9cba8fSJoseph Mingrone/* protocol level qualifiers */
540*6f9cba8fSJoseph Mingronepqual:	  pname
541*6f9cba8fSJoseph Mingrone	|			{ $$ = Q_DEFAULT; }
542*6f9cba8fSJoseph Mingrone	;
543*6f9cba8fSJoseph Mingrone/* 'direction' qualifiers */
544*6f9cba8fSJoseph Mingronedqual:	  SRC			{ $$ = Q_SRC; }
545*6f9cba8fSJoseph Mingrone	| DST			{ $$ = Q_DST; }
546*6f9cba8fSJoseph Mingrone	| SRC OR DST		{ $$ = Q_OR; }
547*6f9cba8fSJoseph Mingrone	| DST OR SRC		{ $$ = Q_OR; }
548*6f9cba8fSJoseph Mingrone	| SRC AND DST		{ $$ = Q_AND; }
549*6f9cba8fSJoseph Mingrone	| DST AND SRC		{ $$ = Q_AND; }
550*6f9cba8fSJoseph Mingrone	| ADDR1			{ $$ = Q_ADDR1; }
551*6f9cba8fSJoseph Mingrone	| ADDR2			{ $$ = Q_ADDR2; }
552*6f9cba8fSJoseph Mingrone	| ADDR3			{ $$ = Q_ADDR3; }
553*6f9cba8fSJoseph Mingrone	| ADDR4			{ $$ = Q_ADDR4; }
554*6f9cba8fSJoseph Mingrone	| RA			{ $$ = Q_RA; }
555*6f9cba8fSJoseph Mingrone	| TA			{ $$ = Q_TA; }
556*6f9cba8fSJoseph Mingrone	;
557*6f9cba8fSJoseph Mingrone/* address type qualifiers */
558*6f9cba8fSJoseph Mingroneaqual:	  HOST			{ $$ = Q_HOST; }
559*6f9cba8fSJoseph Mingrone	| NET			{ $$ = Q_NET; }
560*6f9cba8fSJoseph Mingrone	| PORT			{ $$ = Q_PORT; }
561*6f9cba8fSJoseph Mingrone	| PORTRANGE		{ $$ = Q_PORTRANGE; }
562*6f9cba8fSJoseph Mingrone	;
563*6f9cba8fSJoseph Mingrone/* non-directional address type qualifiers */
564*6f9cba8fSJoseph Mingronendaqual:  GATEWAY		{ $$ = Q_GATEWAY; }
565*6f9cba8fSJoseph Mingrone	;
566*6f9cba8fSJoseph Mingronepname:	  LINK			{ $$ = Q_LINK; }
567*6f9cba8fSJoseph Mingrone	| IP			{ $$ = Q_IP; }
568*6f9cba8fSJoseph Mingrone	| ARP			{ $$ = Q_ARP; }
569*6f9cba8fSJoseph Mingrone	| RARP			{ $$ = Q_RARP; }
570*6f9cba8fSJoseph Mingrone	| SCTP			{ $$ = Q_SCTP; }
571*6f9cba8fSJoseph Mingrone	| TCP			{ $$ = Q_TCP; }
572*6f9cba8fSJoseph Mingrone	| UDP			{ $$ = Q_UDP; }
573*6f9cba8fSJoseph Mingrone	| ICMP			{ $$ = Q_ICMP; }
574*6f9cba8fSJoseph Mingrone	| IGMP			{ $$ = Q_IGMP; }
575*6f9cba8fSJoseph Mingrone	| IGRP			{ $$ = Q_IGRP; }
576*6f9cba8fSJoseph Mingrone	| PIM			{ $$ = Q_PIM; }
577*6f9cba8fSJoseph Mingrone	| VRRP			{ $$ = Q_VRRP; }
578*6f9cba8fSJoseph Mingrone	| CARP			{ $$ = Q_CARP; }
579*6f9cba8fSJoseph Mingrone	| ATALK			{ $$ = Q_ATALK; }
580*6f9cba8fSJoseph Mingrone	| AARP			{ $$ = Q_AARP; }
581*6f9cba8fSJoseph Mingrone	| DECNET		{ $$ = Q_DECNET; }
582*6f9cba8fSJoseph Mingrone	| LAT			{ $$ = Q_LAT; }
583*6f9cba8fSJoseph Mingrone	| SCA			{ $$ = Q_SCA; }
584*6f9cba8fSJoseph Mingrone	| MOPDL			{ $$ = Q_MOPDL; }
585*6f9cba8fSJoseph Mingrone	| MOPRC			{ $$ = Q_MOPRC; }
586*6f9cba8fSJoseph Mingrone	| IPV6			{ $$ = Q_IPV6; }
587*6f9cba8fSJoseph Mingrone	| ICMPV6		{ $$ = Q_ICMPV6; }
588*6f9cba8fSJoseph Mingrone	| AH			{ $$ = Q_AH; }
589*6f9cba8fSJoseph Mingrone	| ESP			{ $$ = Q_ESP; }
590*6f9cba8fSJoseph Mingrone	| ISO			{ $$ = Q_ISO; }
591*6f9cba8fSJoseph Mingrone	| ESIS			{ $$ = Q_ESIS; }
592*6f9cba8fSJoseph Mingrone	| ISIS			{ $$ = Q_ISIS; }
593*6f9cba8fSJoseph Mingrone	| L1			{ $$ = Q_ISIS_L1; }
594*6f9cba8fSJoseph Mingrone	| L2			{ $$ = Q_ISIS_L2; }
595*6f9cba8fSJoseph Mingrone	| IIH			{ $$ = Q_ISIS_IIH; }
596*6f9cba8fSJoseph Mingrone	| LSP			{ $$ = Q_ISIS_LSP; }
597*6f9cba8fSJoseph Mingrone	| SNP			{ $$ = Q_ISIS_SNP; }
598*6f9cba8fSJoseph Mingrone	| PSNP			{ $$ = Q_ISIS_PSNP; }
599*6f9cba8fSJoseph Mingrone	| CSNP			{ $$ = Q_ISIS_CSNP; }
600*6f9cba8fSJoseph Mingrone	| CLNP			{ $$ = Q_CLNP; }
601*6f9cba8fSJoseph Mingrone	| STP			{ $$ = Q_STP; }
602*6f9cba8fSJoseph Mingrone	| IPX			{ $$ = Q_IPX; }
603*6f9cba8fSJoseph Mingrone	| NETBEUI		{ $$ = Q_NETBEUI; }
604*6f9cba8fSJoseph Mingrone	| RADIO			{ $$ = Q_RADIO; }
605*6f9cba8fSJoseph Mingrone	;
606*6f9cba8fSJoseph Mingroneother:	  pqual TK_BROADCAST	{ CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
607*6f9cba8fSJoseph Mingrone	| pqual TK_MULTICAST	{ CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
608*6f9cba8fSJoseph Mingrone	| LESS NUM		{ CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
609*6f9cba8fSJoseph Mingrone	| GREATER NUM		{ CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
610*6f9cba8fSJoseph Mingrone	| CBYTE NUM byteop NUM	{ CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
611*6f9cba8fSJoseph Mingrone	| INBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
612*6f9cba8fSJoseph Mingrone	| OUTBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
613*6f9cba8fSJoseph Mingrone	| IFINDEX NUM		{ CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
614*6f9cba8fSJoseph Mingrone	| VLAN pnum		{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
615*6f9cba8fSJoseph Mingrone	| VLAN			{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
616*6f9cba8fSJoseph Mingrone	| MPLS pnum		{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, $2, 1))); }
617*6f9cba8fSJoseph Mingrone	| MPLS			{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
618*6f9cba8fSJoseph Mingrone	| PPPOED		{ CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
619*6f9cba8fSJoseph Mingrone	| PPPOES pnum		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, $2, 1))); }
620*6f9cba8fSJoseph Mingrone	| PPPOES		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
621*6f9cba8fSJoseph Mingrone	| GENEVE pnum		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
622*6f9cba8fSJoseph Mingrone	| GENEVE		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
623*6f9cba8fSJoseph Mingrone	| pfvar			{ $$ = $1; }
624*6f9cba8fSJoseph Mingrone	| pqual p80211		{ $$ = $2; }
625*6f9cba8fSJoseph Mingrone	| pllc			{ $$ = $1; }
626*6f9cba8fSJoseph Mingrone	;
627*6f9cba8fSJoseph Mingrone
628*6f9cba8fSJoseph Mingronepfvar:	  PF_IFNAME ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
629*6f9cba8fSJoseph Mingrone	| PF_RSET ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
630*6f9cba8fSJoseph Mingrone	| PF_RNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
631*6f9cba8fSJoseph Mingrone	| PF_SRNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
632*6f9cba8fSJoseph Mingrone	| PF_REASON reason	{ CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
633*6f9cba8fSJoseph Mingrone	| PF_ACTION action	{ CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
634*6f9cba8fSJoseph Mingrone	;
635*6f9cba8fSJoseph Mingrone
636*6f9cba8fSJoseph Mingronep80211:   TYPE type SUBTYPE subtype
637*6f9cba8fSJoseph Mingrone				{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
638*6f9cba8fSJoseph Mingrone					IEEE80211_FC0_TYPE_MASK |
639*6f9cba8fSJoseph Mingrone					IEEE80211_FC0_SUBTYPE_MASK)));
640*6f9cba8fSJoseph Mingrone				}
641*6f9cba8fSJoseph Mingrone	| TYPE type		{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
642*6f9cba8fSJoseph Mingrone					IEEE80211_FC0_TYPE_MASK)));
643*6f9cba8fSJoseph Mingrone				}
644*6f9cba8fSJoseph Mingrone	| SUBTYPE type_subtype	{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
645*6f9cba8fSJoseph Mingrone					IEEE80211_FC0_TYPE_MASK |
646*6f9cba8fSJoseph Mingrone					IEEE80211_FC0_SUBTYPE_MASK)));
647*6f9cba8fSJoseph Mingrone				}
648*6f9cba8fSJoseph Mingrone	| DIR dir		{ CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
649*6f9cba8fSJoseph Mingrone	;
650*6f9cba8fSJoseph Mingrone
651*6f9cba8fSJoseph Mingronetype:	  NUM			{ if (($1 & (~IEEE80211_FC0_TYPE_MASK)) != 0) {
652*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "invalid 802.11 type value 0x%02x", $1);
653*6f9cba8fSJoseph Mingrone					YYABORT;
654*6f9cba8fSJoseph Mingrone				  }
655*6f9cba8fSJoseph Mingrone				  $$ = (int)$1;
656*6f9cba8fSJoseph Mingrone				}
657*6f9cba8fSJoseph Mingrone	| ID			{ CHECK_PTR_VAL($1);
658*6f9cba8fSJoseph Mingrone				  $$ = str2tok($1, ieee80211_types);
659*6f9cba8fSJoseph Mingrone				  if ($$ == -1) {
660*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "unknown 802.11 type name \"%s\"", $1);
661*6f9cba8fSJoseph Mingrone					YYABORT;
662*6f9cba8fSJoseph Mingrone				  }
663*6f9cba8fSJoseph Mingrone				}
664*6f9cba8fSJoseph Mingrone	;
665*6f9cba8fSJoseph Mingrone
666*6f9cba8fSJoseph Mingronesubtype:  NUM			{ if (($1 & (~IEEE80211_FC0_SUBTYPE_MASK)) != 0) {
667*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "invalid 802.11 subtype value 0x%02x", $1);
668*6f9cba8fSJoseph Mingrone					YYABORT;
669*6f9cba8fSJoseph Mingrone				  }
670*6f9cba8fSJoseph Mingrone				  $$ = (int)$1;
671*6f9cba8fSJoseph Mingrone				}
672*6f9cba8fSJoseph Mingrone	| ID			{ const struct tok *types = NULL;
673*6f9cba8fSJoseph Mingrone				  int i;
674*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL($1);
675*6f9cba8fSJoseph Mingrone				  for (i = 0;; i++) {
676*6f9cba8fSJoseph Mingrone					if (ieee80211_type_subtypes[i].tok == NULL) {
677*6f9cba8fSJoseph Mingrone						/* Ran out of types */
678*6f9cba8fSJoseph Mingrone						bpf_set_error(cstate, "unknown 802.11 type");
679*6f9cba8fSJoseph Mingrone						YYABORT;
680*6f9cba8fSJoseph Mingrone					}
681*6f9cba8fSJoseph Mingrone					if ($<i>-1 == ieee80211_type_subtypes[i].type) {
682*6f9cba8fSJoseph Mingrone						types = ieee80211_type_subtypes[i].tok;
683*6f9cba8fSJoseph Mingrone						break;
684*6f9cba8fSJoseph Mingrone					}
685*6f9cba8fSJoseph Mingrone				  }
686*6f9cba8fSJoseph Mingrone
687*6f9cba8fSJoseph Mingrone				  $$ = str2tok($1, types);
688*6f9cba8fSJoseph Mingrone				  if ($$ == -1) {
689*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "unknown 802.11 subtype name \"%s\"", $1);
690*6f9cba8fSJoseph Mingrone					YYABORT;
691*6f9cba8fSJoseph Mingrone				  }
692*6f9cba8fSJoseph Mingrone				}
693*6f9cba8fSJoseph Mingrone	;
694*6f9cba8fSJoseph Mingrone
695*6f9cba8fSJoseph Mingronetype_subtype:	ID		{ int i;
696*6f9cba8fSJoseph Mingrone				  CHECK_PTR_VAL($1);
697*6f9cba8fSJoseph Mingrone				  for (i = 0;; i++) {
698*6f9cba8fSJoseph Mingrone					if (ieee80211_type_subtypes[i].tok == NULL) {
699*6f9cba8fSJoseph Mingrone						/* Ran out of types */
700*6f9cba8fSJoseph Mingrone						bpf_set_error(cstate, "unknown 802.11 type name");
701*6f9cba8fSJoseph Mingrone						YYABORT;
702*6f9cba8fSJoseph Mingrone					}
703*6f9cba8fSJoseph Mingrone					$$ = str2tok($1, ieee80211_type_subtypes[i].tok);
704*6f9cba8fSJoseph Mingrone					if ($$ != -1) {
705*6f9cba8fSJoseph Mingrone						$$ |= ieee80211_type_subtypes[i].type;
706*6f9cba8fSJoseph Mingrone						break;
707*6f9cba8fSJoseph Mingrone					}
708*6f9cba8fSJoseph Mingrone				  }
709*6f9cba8fSJoseph Mingrone				}
710*6f9cba8fSJoseph Mingrone		;
711*6f9cba8fSJoseph Mingrone
712*6f9cba8fSJoseph Mingronepllc:	LLC			{ CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
713*6f9cba8fSJoseph Mingrone	| LLC ID		{ CHECK_PTR_VAL($2);
714*6f9cba8fSJoseph Mingrone				  if (pcap_strcasecmp($2, "i") == 0) {
715*6f9cba8fSJoseph Mingrone					CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
716*6f9cba8fSJoseph Mingrone				  } else if (pcap_strcasecmp($2, "s") == 0) {
717*6f9cba8fSJoseph Mingrone					CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
718*6f9cba8fSJoseph Mingrone				  } else if (pcap_strcasecmp($2, "u") == 0) {
719*6f9cba8fSJoseph Mingrone					CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
720*6f9cba8fSJoseph Mingrone				  } else {
721*6f9cba8fSJoseph Mingrone					int subtype;
722*6f9cba8fSJoseph Mingrone
723*6f9cba8fSJoseph Mingrone					subtype = str2tok($2, llc_s_subtypes);
724*6f9cba8fSJoseph Mingrone					if (subtype != -1) {
725*6f9cba8fSJoseph Mingrone						CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
726*6f9cba8fSJoseph Mingrone					} else {
727*6f9cba8fSJoseph Mingrone						subtype = str2tok($2, llc_u_subtypes);
728*6f9cba8fSJoseph Mingrone						if (subtype == -1) {
729*6f9cba8fSJoseph Mingrone							bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
730*6f9cba8fSJoseph Mingrone							YYABORT;
731*6f9cba8fSJoseph Mingrone						}
732*6f9cba8fSJoseph Mingrone						CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
733*6f9cba8fSJoseph Mingrone					}
734*6f9cba8fSJoseph Mingrone				  }
735*6f9cba8fSJoseph Mingrone				}
736*6f9cba8fSJoseph Mingrone				/* sigh, "rnr" is already a keyword for PF */
737*6f9cba8fSJoseph Mingrone	| LLC PF_RNR		{ CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
738*6f9cba8fSJoseph Mingrone	;
739*6f9cba8fSJoseph Mingrone
740*6f9cba8fSJoseph Mingronedir:	  NUM			{ $$ = (int)$1; }
741*6f9cba8fSJoseph Mingrone	| ID			{ CHECK_PTR_VAL($1);
742*6f9cba8fSJoseph Mingrone				  if (pcap_strcasecmp($1, "nods") == 0)
743*6f9cba8fSJoseph Mingrone					$$ = IEEE80211_FC1_DIR_NODS;
744*6f9cba8fSJoseph Mingrone				  else if (pcap_strcasecmp($1, "tods") == 0)
745*6f9cba8fSJoseph Mingrone					$$ = IEEE80211_FC1_DIR_TODS;
746*6f9cba8fSJoseph Mingrone				  else if (pcap_strcasecmp($1, "fromds") == 0)
747*6f9cba8fSJoseph Mingrone					$$ = IEEE80211_FC1_DIR_FROMDS;
748*6f9cba8fSJoseph Mingrone				  else if (pcap_strcasecmp($1, "dstods") == 0)
749*6f9cba8fSJoseph Mingrone					$$ = IEEE80211_FC1_DIR_DSTODS;
750*6f9cba8fSJoseph Mingrone				  else {
751*6f9cba8fSJoseph Mingrone					bpf_set_error(cstate, "unknown 802.11 direction");
752*6f9cba8fSJoseph Mingrone					YYABORT;
753*6f9cba8fSJoseph Mingrone				  }
754*6f9cba8fSJoseph Mingrone				}
755*6f9cba8fSJoseph Mingrone	;
756*6f9cba8fSJoseph Mingrone
757*6f9cba8fSJoseph Mingronereason:	  NUM			{ $$ = $1; }
758*6f9cba8fSJoseph Mingrone	| ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
759*6f9cba8fSJoseph Mingrone	;
760*6f9cba8fSJoseph Mingrone
761*6f9cba8fSJoseph Mingroneaction:	  ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
762*6f9cba8fSJoseph Mingrone	;
763*6f9cba8fSJoseph Mingrone
764*6f9cba8fSJoseph Mingronerelop:	  '>'			{ $$ = BPF_JGT; }
765*6f9cba8fSJoseph Mingrone	| GEQ			{ $$ = BPF_JGE; }
766*6f9cba8fSJoseph Mingrone	| '='			{ $$ = BPF_JEQ; }
767*6f9cba8fSJoseph Mingrone	;
768*6f9cba8fSJoseph Mingroneirelop:	  LEQ			{ $$ = BPF_JGT; }
769*6f9cba8fSJoseph Mingrone	| '<'			{ $$ = BPF_JGE; }
770*6f9cba8fSJoseph Mingrone	| NEQ			{ $$ = BPF_JEQ; }
771*6f9cba8fSJoseph Mingrone	;
772*6f9cba8fSJoseph Mingronearth:	  pnum			{ CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
773*6f9cba8fSJoseph Mingrone	| narth
774*6f9cba8fSJoseph Mingrone	;
775*6f9cba8fSJoseph Mingronenarth:	  pname '[' arth ']'		{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
776*6f9cba8fSJoseph Mingrone	| pname '[' arth ':' NUM ']'	{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
777*6f9cba8fSJoseph Mingrone	| arth '+' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
778*6f9cba8fSJoseph Mingrone	| arth '-' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
779*6f9cba8fSJoseph Mingrone	| arth '*' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
780*6f9cba8fSJoseph Mingrone	| arth '/' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
781*6f9cba8fSJoseph Mingrone	| arth '%' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
782*6f9cba8fSJoseph Mingrone	| arth '&' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
783*6f9cba8fSJoseph Mingrone	| arth '|' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
784*6f9cba8fSJoseph Mingrone	| arth '^' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
785*6f9cba8fSJoseph Mingrone	| arth LSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
786*6f9cba8fSJoseph Mingrone	| arth RSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
787*6f9cba8fSJoseph Mingrone	| '-' arth %prec UMINUS		{ CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
788*6f9cba8fSJoseph Mingrone	| paren narth ')'		{ $$ = $2; }
789*6f9cba8fSJoseph Mingrone	| LEN				{ CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
790*6f9cba8fSJoseph Mingrone	;
791*6f9cba8fSJoseph Mingronebyteop:	  '&'			{ $$ = '&'; }
792*6f9cba8fSJoseph Mingrone	| '|'			{ $$ = '|'; }
793*6f9cba8fSJoseph Mingrone	| '<'			{ $$ = '<'; }
794*6f9cba8fSJoseph Mingrone	| '>'			{ $$ = '>'; }
795*6f9cba8fSJoseph Mingrone	| '='			{ $$ = '='; }
796*6f9cba8fSJoseph Mingrone	;
797*6f9cba8fSJoseph Mingronepnum:	  NUM
798*6f9cba8fSJoseph Mingrone	| paren pnum ')'	{ $$ = $2; }
799*6f9cba8fSJoseph Mingrone	;
800*6f9cba8fSJoseph Mingroneatmtype: LANE			{ $$ = A_LANE; }
801*6f9cba8fSJoseph Mingrone	| METAC			{ $$ = A_METAC;	}
802*6f9cba8fSJoseph Mingrone	| BCC			{ $$ = A_BCC; }
803*6f9cba8fSJoseph Mingrone	| OAMF4EC		{ $$ = A_OAMF4EC; }
804*6f9cba8fSJoseph Mingrone	| OAMF4SC		{ $$ = A_OAMF4SC; }
805*6f9cba8fSJoseph Mingrone	| SC			{ $$ = A_SC; }
806*6f9cba8fSJoseph Mingrone	| ILMIC			{ $$ = A_ILMIC; }
807*6f9cba8fSJoseph Mingrone	;
808*6f9cba8fSJoseph Mingroneatmmultitype: OAM		{ $$ = A_OAM; }
809*6f9cba8fSJoseph Mingrone	| OAMF4			{ $$ = A_OAMF4; }
810*6f9cba8fSJoseph Mingrone	| CONNECTMSG		{ $$ = A_CONNECTMSG; }
811*6f9cba8fSJoseph Mingrone	| METACONNECT		{ $$ = A_METACONNECT; }
812*6f9cba8fSJoseph Mingrone	;
813*6f9cba8fSJoseph Mingrone	/* ATM field types quantifier */
814*6f9cba8fSJoseph Mingroneatmfield: VPI			{ $$.atmfieldtype = A_VPI; }
815*6f9cba8fSJoseph Mingrone	| VCI			{ $$.atmfieldtype = A_VCI; }
816*6f9cba8fSJoseph Mingrone	;
817*6f9cba8fSJoseph Mingroneatmvalue: atmfieldvalue
818*6f9cba8fSJoseph Mingrone	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 0))); }
819*6f9cba8fSJoseph Mingrone	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 1))); }
820*6f9cba8fSJoseph Mingrone	| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
821*6f9cba8fSJoseph Mingrone	;
822*6f9cba8fSJoseph Mingroneatmfieldvalue: NUM {
823*6f9cba8fSJoseph Mingrone	$$.atmfieldtype = $<blk>0.atmfieldtype;
824*6f9cba8fSJoseph Mingrone	if ($$.atmfieldtype == A_VPI ||
825*6f9cba8fSJoseph Mingrone	    $$.atmfieldtype == A_VCI)
826*6f9cba8fSJoseph Mingrone		CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, $1, BPF_JEQ, 0)));
827*6f9cba8fSJoseph Mingrone	}
828*6f9cba8fSJoseph Mingrone	;
829*6f9cba8fSJoseph Mingroneatmlistvalue: atmfieldvalue
830*6f9cba8fSJoseph Mingrone	| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
831*6f9cba8fSJoseph Mingrone	;
832*6f9cba8fSJoseph Mingrone	/* MTP2 types quantifier */
833*6f9cba8fSJoseph Mingronemtp2type: FISU			{ $$ = M_FISU; }
834*6f9cba8fSJoseph Mingrone	| LSSU			{ $$ = M_LSSU; }
835*6f9cba8fSJoseph Mingrone	| MSU			{ $$ = M_MSU; }
836*6f9cba8fSJoseph Mingrone	| HFISU			{ $$ = MH_FISU; }
837*6f9cba8fSJoseph Mingrone	| HLSSU			{ $$ = MH_LSSU; }
838*6f9cba8fSJoseph Mingrone	| HMSU			{ $$ = MH_MSU; }
839*6f9cba8fSJoseph Mingrone	;
840*6f9cba8fSJoseph Mingrone	/* MTP3 field types quantifier */
841*6f9cba8fSJoseph Mingronemtp3field: SIO			{ $$.mtp3fieldtype = M_SIO; }
842*6f9cba8fSJoseph Mingrone	| OPC			{ $$.mtp3fieldtype = M_OPC; }
843*6f9cba8fSJoseph Mingrone	| DPC			{ $$.mtp3fieldtype = M_DPC; }
844*6f9cba8fSJoseph Mingrone	| SLS                   { $$.mtp3fieldtype = M_SLS; }
845*6f9cba8fSJoseph Mingrone	| HSIO			{ $$.mtp3fieldtype = MH_SIO; }
846*6f9cba8fSJoseph Mingrone	| HOPC			{ $$.mtp3fieldtype = MH_OPC; }
847*6f9cba8fSJoseph Mingrone	| HDPC			{ $$.mtp3fieldtype = MH_DPC; }
848*6f9cba8fSJoseph Mingrone	| HSLS                  { $$.mtp3fieldtype = MH_SLS; }
849*6f9cba8fSJoseph Mingrone	;
850*6f9cba8fSJoseph Mingronemtp3value: mtp3fieldvalue
851*6f9cba8fSJoseph Mingrone	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 0))); }
852*6f9cba8fSJoseph Mingrone	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 1))); }
853*6f9cba8fSJoseph Mingrone	| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
854*6f9cba8fSJoseph Mingrone	;
855*6f9cba8fSJoseph Mingronemtp3fieldvalue: NUM {
856*6f9cba8fSJoseph Mingrone	$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
857*6f9cba8fSJoseph Mingrone	if ($$.mtp3fieldtype == M_SIO ||
858*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == M_OPC ||
859*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == M_DPC ||
860*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == M_SLS ||
861*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == MH_SIO ||
862*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == MH_OPC ||
863*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == MH_DPC ||
864*6f9cba8fSJoseph Mingrone	    $$.mtp3fieldtype == MH_SLS)
865*6f9cba8fSJoseph Mingrone		CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, $1, BPF_JEQ, 0)));
866*6f9cba8fSJoseph Mingrone	}
867*6f9cba8fSJoseph Mingrone	;
868*6f9cba8fSJoseph Mingronemtp3listvalue: mtp3fieldvalue
869*6f9cba8fSJoseph Mingrone	| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
870*6f9cba8fSJoseph Mingrone	;
871*6f9cba8fSJoseph Mingrone%%
872