1335640Shselasky/*
2335640Shselasky * We want a reentrant parser.
3335640Shselasky */
4335640Shselasky%pure-parser
5335640Shselasky
6335640Shselasky/*
7335640Shselasky * We also want a reentrant scanner, so we have to pass the
8335640Shselasky * handle for the reentrant scanner to the parser, and the
9335640Shselasky * parser has to pass it to the lexical analyzer.
10335640Shselasky *
11335640Shselasky * We use void * rather than yyscan_t because, at least with some
12335640Shselasky * versions of Flex and Bison, if you use yyscan_t in %parse-param and
13335640Shselasky * %lex-param, you have to include scanner.h before grammar.h to get
14335640Shselasky * yyscan_t declared, and you have to include grammar.h before scanner.h
15335640Shselasky * to get YYSTYPE declared.  Using void * breaks the cycle; the Flex
16335640Shselasky * documentation says yyscan_t is just a void *.
17335640Shselasky */
18335640Shselasky%parse-param   {void *yyscanner}
19335640Shselasky%lex-param   {void *yyscanner}
20335640Shselasky
21335640Shselasky/*
22335640Shselasky * And we need to pass the compiler state to the scanner.
23335640Shselasky */
24335640Shselasky%parse-param { compiler_state_t *cstate }
25335640Shselasky
26335640Shselasky%{
27335640Shselasky/*
28335640Shselasky * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
29335640Shselasky *	The Regents of the University of California.  All rights reserved.
30335640Shselasky *
31335640Shselasky * Redistribution and use in source and binary forms, with or without
32335640Shselasky * modification, are permitted provided that: (1) source code distributions
33335640Shselasky * retain the above copyright notice and this paragraph in its entirety, (2)
34335640Shselasky * distributions including binary code include the above copyright notice and
35335640Shselasky * this paragraph in its entirety in the documentation or other materials
36335640Shselasky * provided with the distribution, and (3) all advertising materials mentioning
37335640Shselasky * features or use of this software display the following acknowledgement:
38335640Shselasky * ``This product includes software developed by the University of California,
39335640Shselasky * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
40335640Shselasky * the University nor the names of its contributors may be used to endorse
41335640Shselasky * or promote products derived from this software without specific prior
42335640Shselasky * written permission.
43335640Shselasky * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
44335640Shselasky * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
45335640Shselasky * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46335640Shselasky *
47335640Shselasky */
48335640Shselasky
49335640Shselasky#ifdef HAVE_CONFIG_H
50335640Shselasky#include <config.h>
51335640Shselasky#endif
52335640Shselasky
53335640Shselasky#include <stdlib.h>
54335640Shselasky
55335640Shselasky#ifndef _WIN32
56335640Shselasky#include <sys/types.h>
57335640Shselasky#include <sys/socket.h>
58335640Shselasky
59335640Shselasky#if __STDC__
60335640Shselaskystruct mbuf;
61335640Shselaskystruct rtentry;
62335640Shselasky#endif
63335640Shselasky
64335640Shselasky#include <netinet/in.h>
65335640Shselasky#include <arpa/inet.h>
66335640Shselasky#endif /* _WIN32 */
67335640Shselasky
68335640Shselasky#include <stdio.h>
69335640Shselasky
70335640Shselasky#include "diag-control.h"
71335640Shselasky
72335640Shselasky#include "pcap-int.h"
73335640Shselasky
74335640Shselasky#include "gencode.h"
75335640Shselasky#include "grammar.h"
76335640Shselasky#include "scanner.h"
77335640Shselasky
78335640Shselasky#ifdef HAVE_NET_PFVAR_H
79335640Shselasky#include <net/if.h>
80335640Shselasky#include <net/pfvar.h>
81335640Shselasky#include <net/if_pflog.h>
82335640Shselasky#endif
83335640Shselasky#include "llc.h"
84335640Shselasky#include "ieee80211.h"
85335640Shselasky#include <pcap/namedb.h>
86335640Shselasky
87335640Shselasky#ifdef HAVE_OS_PROTO_H
88335640Shselasky#include "os-proto.h"
89335640Shselasky#endif
90335640Shselasky
91335640Shselasky#ifdef YYBYACC
92335640Shselasky/*
93335640Shselasky * Both Berkeley YACC and Bison define yydebug (under whatever name
94335640Shselasky * it has) as a global, but Bison does so only if YYDEBUG is defined.
95335640Shselasky * Berkeley YACC define it even if YYDEBUG isn't defined; declare it
96335640Shselasky * here to suppress a warning.
97335640Shselasky */
98335640Shselasky#if !defined(YYDEBUG)
99335640Shselaskyextern int yydebug;
100335640Shselasky#endif
101335640Shselasky
102335640Shselasky/*
103335640Shselasky * In Berkeley YACC, yynerrs (under whatever name it has) is global,
104335640Shselasky * even if it's building a reentrant parser.  In Bison, it's local
105335640Shselasky * in reentrant parsers.
106335640Shselasky *
107335640Shselasky * Declare it to squelch a warning.
108335640Shselasky */
109335640Shselaskyextern int yynerrs;
110335640Shselasky#endif
111335640Shselasky
112335640Shselasky#define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
113335640Shselasky			 (q).dir = (unsigned char)(d),\
114335640Shselasky			 (q).addr = (unsigned char)(a)
115335640Shselasky
116335640Shselaskystruct tok {
117335640Shselasky	int v;			/* value */
118335640Shselasky	const char *s;		/* string */
119335640Shselasky};
120335640Shselasky
121335640Shselaskystatic const struct tok ieee80211_types[] = {
122335640Shselasky	{ IEEE80211_FC0_TYPE_DATA, "data" },
123335640Shselasky	{ IEEE80211_FC0_TYPE_MGT, "mgt" },
124335640Shselasky	{ IEEE80211_FC0_TYPE_MGT, "management" },
125335640Shselasky	{ IEEE80211_FC0_TYPE_CTL, "ctl" },
126335640Shselasky	{ IEEE80211_FC0_TYPE_CTL, "control" },
127335640Shselasky	{ 0, NULL }
128335640Shselasky};
129335640Shselaskystatic const struct tok ieee80211_mgt_subtypes[] = {
130335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
131335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
132335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
133335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
134335640Shselasky	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
135335640Shselasky	{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
136335640Shselasky	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
137335640Shselasky	{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
138335640Shselasky	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
139335640Shselasky	{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
140335640Shselasky	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
141335640Shselasky	{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
142335640Shselasky	{ IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
143335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
144335640Shselasky	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
145335640Shselasky	{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
146335640Shselasky	{ IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
147335640Shselasky	{ IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
148335640Shselasky	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
149335640Shselasky	{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
150335640Shselasky	{ 0, NULL }
151335640Shselasky};
152335640Shselaskystatic const struct tok ieee80211_ctl_subtypes[] = {
153335640Shselasky	{ IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
154335640Shselasky	{ IEEE80211_FC0_SUBTYPE_RTS, "rts" },
155335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CTS, "cts" },
156335640Shselasky	{ IEEE80211_FC0_SUBTYPE_ACK, "ack" },
157335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
158335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
159335640Shselasky	{ 0, NULL }
160335640Shselasky};
161335640Shselaskystatic const struct tok ieee80211_data_subtypes[] = {
162335640Shselasky	{ IEEE80211_FC0_SUBTYPE_DATA, "data" },
163335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
164335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
165335640Shselasky	{ IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
166335640Shselasky	{ IEEE80211_FC0_SUBTYPE_NODATA, "null" },
167335640Shselasky	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
168335640Shselasky	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll"  },
169335640Shselasky	{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
170335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
171335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
172335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
173335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
174335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
175335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
176335640Shselasky	{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
177335640Shselasky	{ 0, NULL }
178335640Shselasky};
179335640Shselaskystatic const struct tok llc_s_subtypes[] = {
180335640Shselasky	{ LLC_RR, "rr" },
181335640Shselasky	{ LLC_RNR, "rnr" },
182335640Shselasky	{ LLC_REJ, "rej" },
183335640Shselasky	{ 0, NULL }
184335640Shselasky};
185335640Shselaskystatic const struct tok llc_u_subtypes[] = {
186335640Shselasky	{ LLC_UI, "ui" },
187335640Shselasky	{ LLC_UA, "ua" },
188335640Shselasky	{ LLC_DISC, "disc" },
189335640Shselasky	{ LLC_DM, "dm" },
190335640Shselasky	{ LLC_SABME, "sabme" },
191335640Shselasky	{ LLC_TEST, "test" },
192335640Shselasky	{ LLC_XID, "xid" },
193335640Shselasky	{ LLC_FRMR, "frmr" },
194335640Shselasky	{ 0, NULL }
195335640Shselasky};
196335640Shselaskystruct type2tok {
197335640Shselasky	int type;
198335640Shselasky	const struct tok *tok;
199335640Shselasky};
200335640Shselaskystatic const struct type2tok ieee80211_type_subtypes[] = {
201335640Shselasky	{ IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
202335640Shselasky	{ IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
203335640Shselasky	{ IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
204335640Shselasky	{ 0, NULL }
205335640Shselasky};
206335640Shselasky
207335640Shselaskystatic int
208335640Shselaskystr2tok(const char *str, const struct tok *toks)
209335640Shselasky{
210335640Shselasky	int i;
211335640Shselasky
212335640Shselasky	for (i = 0; toks[i].s != NULL; i++) {
213335640Shselasky		if (pcap_strcasecmp(toks[i].s, str) == 0)
214335640Shselasky			return (toks[i].v);
215335640Shselasky	}
216335640Shselasky	return (-1);
217335640Shselasky}
218335640Shselasky
219356341Scystatic const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
220335640Shselasky
221356341Scystatic void
222335640Shselaskyyyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
223335640Shselasky{
224356341Scy	bpf_set_error(cstate, "can't parse filter expression: %s", msg);
225335640Shselasky}
226335640Shselasky
227335640Shselasky#ifdef HAVE_NET_PFVAR_H
228335640Shselaskystatic int
229335640Shselaskypfreason_to_num(compiler_state_t *cstate, const char *reason)
230335640Shselasky{
231335640Shselasky	const char *reasons[] = PFRES_NAMES;
232335640Shselasky	int i;
233335640Shselasky
234335640Shselasky	for (i = 0; reasons[i]; i++) {
235335640Shselasky		if (pcap_strcasecmp(reason, reasons[i]) == 0)
236335640Shselasky			return (i);
237335640Shselasky	}
238356341Scy	bpf_set_error(cstate, "unknown PF reason");
239356341Scy	return (-1);
240335640Shselasky}
241335640Shselasky
242335640Shselaskystatic int
243335640Shselaskypfaction_to_num(compiler_state_t *cstate, const char *action)
244335640Shselasky{
245335640Shselasky	if (pcap_strcasecmp(action, "pass") == 0 ||
246335640Shselasky	    pcap_strcasecmp(action, "accept") == 0)
247335640Shselasky		return (PF_PASS);
248335640Shselasky	else if (pcap_strcasecmp(action, "drop") == 0 ||
249335640Shselasky		pcap_strcasecmp(action, "block") == 0)
250335640Shselasky		return (PF_DROP);
251335640Shselasky#if HAVE_PF_NAT_THROUGH_PF_NORDR
252335640Shselasky	else if (pcap_strcasecmp(action, "rdr") == 0)
253335640Shselasky		return (PF_RDR);
254335640Shselasky	else if (pcap_strcasecmp(action, "nat") == 0)
255335640Shselasky		return (PF_NAT);
256335640Shselasky	else if (pcap_strcasecmp(action, "binat") == 0)
257335640Shselasky		return (PF_BINAT);
258335640Shselasky	else if (pcap_strcasecmp(action, "nordr") == 0)
259335640Shselasky		return (PF_NORDR);
260335640Shselasky#endif
261335640Shselasky	else {
262356341Scy		bpf_set_error(cstate, "unknown PF action");
263356341Scy		return (-1);
264335640Shselasky	}
265335640Shselasky}
266335640Shselasky#else /* !HAVE_NET_PFVAR_H */
267356341Scystatic int
268335640Shselaskypfreason_to_num(compiler_state_t *cstate, const char *reason _U_)
269335640Shselasky{
270356341Scy	bpf_set_error(cstate, "libpcap was compiled on a machine without pf support");
271356341Scy	return (-1);
272335640Shselasky}
273335640Shselasky
274356341Scystatic int
275335640Shselaskypfaction_to_num(compiler_state_t *cstate, const char *action _U_)
276335640Shselasky{
277356341Scy	bpf_set_error(cstate, "libpcap was compiled on a machine without pf support");
278356341Scy	return (-1);
279335640Shselasky}
280335640Shselasky#endif /* HAVE_NET_PFVAR_H */
281335640Shselasky
282356341Scy/*
283356341Scy * For calls that might return an "an error occurred" value.
284356341Scy */
285356341Scy#define CHECK_INT_VAL(val)	if (val == -1) YYABORT
286356341Scy#define CHECK_PTR_VAL(val)	if (val == NULL) YYABORT
287356341Scy
288335640ShselaskyDIAG_OFF_BISON_BYACC
289335640Shselasky%}
290335640Shselasky
291335640Shselasky%union {
292335640Shselasky	int i;
293335640Shselasky	bpf_u_int32 h;
294335640Shselasky	char *s;
295335640Shselasky	struct stmt *stmt;
296335640Shselasky	struct arth *a;
297335640Shselasky	struct {
298335640Shselasky		struct qual q;
299335640Shselasky		int atmfieldtype;
300335640Shselasky		int mtp3fieldtype;
301335640Shselasky		struct block *b;
302335640Shselasky	} blk;
303335640Shselasky	struct block *rblk;
304335640Shselasky}
305335640Shselasky
306335640Shselasky%type	<blk>	expr id nid pid term rterm qid
307335640Shselasky%type	<blk>	head
308335640Shselasky%type	<i>	pqual dqual aqual ndaqual
309335640Shselasky%type	<a>	arth narth
310335640Shselasky%type	<i>	byteop pname pnum relop irelop
311335640Shselasky%type	<blk>	and or paren not null prog
312335640Shselasky%type	<rblk>	other pfvar p80211 pllc
313335640Shselasky%type	<i>	atmtype atmmultitype
314335640Shselasky%type	<blk>	atmfield
315335640Shselasky%type	<blk>	atmfieldvalue atmvalue atmlistvalue
316335640Shselasky%type	<i>	mtp2type
317335640Shselasky%type	<blk>	mtp3field
318335640Shselasky%type	<blk>	mtp3fieldvalue mtp3value mtp3listvalue
319335640Shselasky
320335640Shselasky
321335640Shselasky%token  DST SRC HOST GATEWAY
322335640Shselasky%token  NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
323335640Shselasky%token  ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
324335640Shselasky%token  ATALK AARP DECNET LAT SCA MOPRC MOPDL
325335640Shselasky%token  TK_BROADCAST TK_MULTICAST
326335640Shselasky%token  NUM INBOUND OUTBOUND
327335640Shselasky%token  PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
328335640Shselasky%token	TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
329335640Shselasky%token  LINK
330335640Shselasky%token	GEQ LEQ NEQ
331335640Shselasky%token	ID EID HID HID6 AID
332335640Shselasky%token	LSH RSH
333335640Shselasky%token  LEN
334335640Shselasky%token  IPV6 ICMPV6 AH ESP
335335640Shselasky%token	VLAN MPLS
336335640Shselasky%token	PPPOED PPPOES GENEVE
337335640Shselasky%token  ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
338335640Shselasky%token  STP
339335640Shselasky%token  IPX
340335640Shselasky%token  NETBEUI
341335640Shselasky%token	LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
342335640Shselasky%token	OAM OAMF4 CONNECTMSG METACONNECT
343335640Shselasky%token	VPI VCI
344335640Shselasky%token	RADIO
345335640Shselasky%token	FISU LSSU MSU HFISU HLSSU HMSU
346335640Shselasky%token	SIO OPC DPC SLS HSIO HOPC HDPC HSLS
347356341Scy%token	LEX_ERROR
348335640Shselasky
349356341Scy%type	<s> ID EID AID
350335640Shselasky%type	<s> HID HID6
351335640Shselasky%type	<i> NUM action reason type subtype type_subtype dir
352335640Shselasky
353335640Shselasky%left OR AND
354335640Shselasky%nonassoc  '!'
355335640Shselasky%left '|'
356335640Shselasky%left '&'
357335640Shselasky%left LSH RSH
358335640Shselasky%left '+' '-'
359335640Shselasky%left '*' '/'
360335640Shselasky%nonassoc UMINUS
361335640Shselasky%%
362335640Shselaskyprog:	  null expr
363335640Shselasky{
364356341Scy	CHECK_INT_VAL(finish_parse(cstate, $2.b));
365335640Shselasky}
366335640Shselasky	| null
367335640Shselasky	;
368335640Shselaskynull:	  /* null */		{ $$.q = qerr; }
369335640Shselasky	;
370335640Shselaskyexpr:	  term
371335640Shselasky	| expr and term		{ gen_and($1.b, $3.b); $$ = $3; }
372335640Shselasky	| expr and id		{ gen_and($1.b, $3.b); $$ = $3; }
373335640Shselasky	| expr or term		{ gen_or($1.b, $3.b); $$ = $3; }
374335640Shselasky	| expr or id		{ gen_or($1.b, $3.b); $$ = $3; }
375335640Shselasky	;
376335640Shselaskyand:	  AND			{ $$ = $<blk>0; }
377335640Shselasky	;
378335640Shselaskyor:	  OR			{ $$ = $<blk>0; }
379335640Shselasky	;
380335640Shselaskyid:	  nid
381356341Scy	| pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
382356341Scy						   $$.q = $<blk>0.q))); }
383335640Shselasky	| paren pid ')'		{ $$ = $2; }
384335640Shselasky	;
385356341Scynid:	  ID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
386356341Scy	| HID '/' NUM		{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
387356341Scy				    $$.q = $<blk>0.q))); }
388356341Scy	| HID NETMASK HID	{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
389356341Scy				    $$.q = $<blk>0.q))); }
390335640Shselasky	| HID			{
391356341Scy				  CHECK_PTR_VAL($1);
392335640Shselasky				  /* Decide how to parse HID based on proto */
393335640Shselasky				  $$.q = $<blk>0.q;
394356341Scy				  if ($$.q.addr == Q_PORT) {
395356341Scy				  	bpf_set_error(cstate, "'port' modifier applied to ip host");
396356341Scy				  	YYABORT;
397356341Scy				  } else if ($$.q.addr == Q_PORTRANGE) {
398356341Scy				  	bpf_set_error(cstate, "'portrange' modifier applied to ip host");
399356341Scy				  	YYABORT;
400356341Scy				  } else if ($$.q.addr == Q_PROTO) {
401356341Scy				  	bpf_set_error(cstate, "'proto' modifier applied to ip host");
402356341Scy				  	YYABORT;
403356341Scy				  } else if ($$.q.addr == Q_PROTOCHAIN) {
404356341Scy				  	bpf_set_error(cstate, "'protochain' modifier applied to ip host");
405356341Scy				  	YYABORT;
406356341Scy				  }
407356341Scy				  CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
408335640Shselasky				}
409335640Shselasky	| HID6 '/' NUM		{
410356341Scy				  CHECK_PTR_VAL($1);
411335640Shselasky#ifdef INET6
412356341Scy				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
413356341Scy				    $$.q = $<blk>0.q)));
414335640Shselasky#else
415356341Scy				  bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
416335640Shselasky					"in this configuration");
417356341Scy				  YYABORT;
418335640Shselasky#endif /*INET6*/
419335640Shselasky				}
420335640Shselasky	| HID6			{
421356341Scy				  CHECK_PTR_VAL($1);
422335640Shselasky#ifdef INET6
423356341Scy				  CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
424356341Scy				    $$.q = $<blk>0.q)));
425335640Shselasky#else
426356341Scy				  bpf_set_error(cstate, "'ip6addr' not supported "
427335640Shselasky					"in this configuration");
428356341Scy				  YYABORT;
429335640Shselasky#endif /*INET6*/
430335640Shselasky				}
431356341Scy	| EID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
432356341Scy	| AID			{ CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
433335640Shselasky	| not id		{ gen_not($2.b); $$ = $2; }
434335640Shselasky	;
435335640Shselaskynot:	  '!'			{ $$ = $<blk>0; }
436335640Shselasky	;
437335640Shselaskyparen:	  '('			{ $$ = $<blk>0; }
438335640Shselasky	;
439335640Shselaskypid:	  nid
440335640Shselasky	| qid and id		{ gen_and($1.b, $3.b); $$ = $3; }
441335640Shselasky	| qid or id		{ gen_or($1.b, $3.b); $$ = $3; }
442335640Shselasky	;
443356341Scyqid:	  pnum			{ CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
444356341Scy						   $$.q = $<blk>0.q))); }
445335640Shselasky	| pid
446335640Shselasky	;
447335640Shselaskyterm:	  rterm
448335640Shselasky	| not term		{ gen_not($2.b); $$ = $2; }
449335640Shselasky	;
450335640Shselaskyhead:	  pqual dqual aqual	{ QSET($$.q, $1, $2, $3); }
451335640Shselasky	| pqual dqual		{ QSET($$.q, $1, $2, Q_DEFAULT); }
452335640Shselasky	| pqual aqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
453335640Shselasky	| pqual PROTO		{ QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
454356341Scy	| pqual PROTOCHAIN	{
455356341Scy#ifdef NO_PROTOCHAIN
456356341Scy				  bpf_set_error(cstate, "protochain not supported");
457356341Scy				  YYABORT;
458356341Scy#else
459356341Scy				  QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
460356341Scy#endif
461356341Scy				}
462335640Shselasky	| pqual ndaqual		{ QSET($$.q, $1, Q_DEFAULT, $2); }
463335640Shselasky	;
464335640Shselaskyrterm:	  head id		{ $$ = $2; }
465335640Shselasky	| paren expr ')'	{ $$.b = $2.b; $$.q = $1.q; }
466356341Scy	| pname			{ CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
467356341Scy	| arth relop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
468335640Shselasky				  $$.q = qerr; }
469356341Scy	| arth irelop arth	{ CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
470335640Shselasky				  $$.q = qerr; }
471335640Shselasky	| other			{ $$.b = $1; $$.q = qerr; }
472356341Scy	| atmtype		{ CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
473356341Scy	| atmmultitype		{ CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
474335640Shselasky	| atmfield atmvalue	{ $$.b = $2.b; $$.q = qerr; }
475356341Scy	| mtp2type		{ CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
476335640Shselasky	| mtp3field mtp3value	{ $$.b = $2.b; $$.q = qerr; }
477335640Shselasky	;
478335640Shselasky/* protocol level qualifiers */
479335640Shselaskypqual:	  pname
480335640Shselasky	|			{ $$ = Q_DEFAULT; }
481335640Shselasky	;
482335640Shselasky/* 'direction' qualifiers */
483335640Shselaskydqual:	  SRC			{ $$ = Q_SRC; }
484335640Shselasky	| DST			{ $$ = Q_DST; }
485335640Shselasky	| SRC OR DST		{ $$ = Q_OR; }
486335640Shselasky	| DST OR SRC		{ $$ = Q_OR; }
487335640Shselasky	| SRC AND DST		{ $$ = Q_AND; }
488335640Shselasky	| DST AND SRC		{ $$ = Q_AND; }
489335640Shselasky	| ADDR1			{ $$ = Q_ADDR1; }
490335640Shselasky	| ADDR2			{ $$ = Q_ADDR2; }
491335640Shselasky	| ADDR3			{ $$ = Q_ADDR3; }
492335640Shselasky	| ADDR4			{ $$ = Q_ADDR4; }
493335640Shselasky	| RA			{ $$ = Q_RA; }
494335640Shselasky	| TA			{ $$ = Q_TA; }
495335640Shselasky	;
496335640Shselasky/* address type qualifiers */
497335640Shselaskyaqual:	  HOST			{ $$ = Q_HOST; }
498335640Shselasky	| NET			{ $$ = Q_NET; }
499335640Shselasky	| PORT			{ $$ = Q_PORT; }
500335640Shselasky	| PORTRANGE		{ $$ = Q_PORTRANGE; }
501335640Shselasky	;
502335640Shselasky/* non-directional address type qualifiers */
503335640Shselaskyndaqual:  GATEWAY		{ $$ = Q_GATEWAY; }
504335640Shselasky	;
505335640Shselaskypname:	  LINK			{ $$ = Q_LINK; }
506335640Shselasky	| IP			{ $$ = Q_IP; }
507335640Shselasky	| ARP			{ $$ = Q_ARP; }
508335640Shselasky	| RARP			{ $$ = Q_RARP; }
509335640Shselasky	| SCTP			{ $$ = Q_SCTP; }
510335640Shselasky	| TCP			{ $$ = Q_TCP; }
511335640Shselasky	| UDP			{ $$ = Q_UDP; }
512335640Shselasky	| ICMP			{ $$ = Q_ICMP; }
513335640Shselasky	| IGMP			{ $$ = Q_IGMP; }
514335640Shselasky	| IGRP			{ $$ = Q_IGRP; }
515335640Shselasky	| PIM			{ $$ = Q_PIM; }
516335640Shselasky	| VRRP			{ $$ = Q_VRRP; }
517335640Shselasky	| CARP 			{ $$ = Q_CARP; }
518335640Shselasky	| ATALK			{ $$ = Q_ATALK; }
519335640Shselasky	| AARP			{ $$ = Q_AARP; }
520335640Shselasky	| DECNET		{ $$ = Q_DECNET; }
521335640Shselasky	| LAT			{ $$ = Q_LAT; }
522335640Shselasky	| SCA			{ $$ = Q_SCA; }
523335640Shselasky	| MOPDL			{ $$ = Q_MOPDL; }
524335640Shselasky	| MOPRC			{ $$ = Q_MOPRC; }
525335640Shselasky	| IPV6			{ $$ = Q_IPV6; }
526335640Shselasky	| ICMPV6		{ $$ = Q_ICMPV6; }
527335640Shselasky	| AH			{ $$ = Q_AH; }
528335640Shselasky	| ESP			{ $$ = Q_ESP; }
529335640Shselasky	| ISO			{ $$ = Q_ISO; }
530335640Shselasky	| ESIS			{ $$ = Q_ESIS; }
531335640Shselasky	| ISIS			{ $$ = Q_ISIS; }
532335640Shselasky	| L1			{ $$ = Q_ISIS_L1; }
533335640Shselasky	| L2			{ $$ = Q_ISIS_L2; }
534335640Shselasky	| IIH			{ $$ = Q_ISIS_IIH; }
535335640Shselasky	| LSP			{ $$ = Q_ISIS_LSP; }
536335640Shselasky	| SNP			{ $$ = Q_ISIS_SNP; }
537335640Shselasky	| PSNP			{ $$ = Q_ISIS_PSNP; }
538335640Shselasky	| CSNP			{ $$ = Q_ISIS_CSNP; }
539335640Shselasky	| CLNP			{ $$ = Q_CLNP; }
540335640Shselasky	| STP			{ $$ = Q_STP; }
541335640Shselasky	| IPX			{ $$ = Q_IPX; }
542335640Shselasky	| NETBEUI		{ $$ = Q_NETBEUI; }
543335640Shselasky	| RADIO			{ $$ = Q_RADIO; }
544335640Shselasky	;
545356341Scyother:	  pqual TK_BROADCAST	{ CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
546356341Scy	| pqual TK_MULTICAST	{ CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
547356341Scy	| LESS NUM		{ CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
548356341Scy	| GREATER NUM		{ CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
549356341Scy	| CBYTE NUM byteop NUM	{ CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
550356341Scy	| INBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
551356341Scy	| OUTBOUND		{ CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
552356341Scy	| VLAN pnum		{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, (bpf_u_int32)$2, 1))); }
553356341Scy	| VLAN			{ CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
554356341Scy	| MPLS pnum		{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, (bpf_u_int32)$2, 1))); }
555356341Scy	| MPLS			{ CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
556356341Scy	| PPPOED		{ CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
557356341Scy	| PPPOES pnum		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, (bpf_u_int32)$2, 1))); }
558356341Scy	| PPPOES		{ CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
559356341Scy	| GENEVE pnum		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, (bpf_u_int32)$2, 1))); }
560356341Scy	| GENEVE		{ CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
561335640Shselasky	| pfvar			{ $$ = $1; }
562335640Shselasky	| pqual p80211		{ $$ = $2; }
563335640Shselasky	| pllc			{ $$ = $1; }
564335640Shselasky	;
565335640Shselasky
566356341Scypfvar:	  PF_IFNAME ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
567356341Scy	| PF_RSET ID		{ CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
568356341Scy	| PF_RNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
569356341Scy	| PF_SRNR NUM		{ CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
570356341Scy	| PF_REASON reason	{ CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
571356341Scy	| PF_ACTION action	{ CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
572335640Shselasky	;
573335640Shselasky
574335640Shselaskyp80211:   TYPE type SUBTYPE subtype
575356341Scy				{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
576335640Shselasky					IEEE80211_FC0_TYPE_MASK |
577356341Scy					IEEE80211_FC0_SUBTYPE_MASK)));
578335640Shselasky				}
579356341Scy	| TYPE type		{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
580356341Scy					IEEE80211_FC0_TYPE_MASK)));
581335640Shselasky				}
582356341Scy	| SUBTYPE type_subtype	{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
583335640Shselasky					IEEE80211_FC0_TYPE_MASK |
584356341Scy					IEEE80211_FC0_SUBTYPE_MASK)));
585335640Shselasky				}
586356341Scy	| DIR dir		{ CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
587335640Shselasky	;
588335640Shselasky
589335640Shselaskytype:	  NUM
590356341Scy	| ID			{ CHECK_PTR_VAL($1);
591356341Scy				  $$ = str2tok($1, ieee80211_types);
592356341Scy				  if ($$ == -1) {
593356341Scy				  	bpf_set_error(cstate, "unknown 802.11 type name");
594356341Scy				  	YYABORT;
595356341Scy				  }
596335640Shselasky				}
597335640Shselasky	;
598335640Shselasky
599335640Shselaskysubtype:  NUM
600335640Shselasky	| ID			{ const struct tok *types = NULL;
601335640Shselasky				  int i;
602356341Scy				  CHECK_PTR_VAL($1);
603335640Shselasky				  for (i = 0;; i++) {
604335640Shselasky				  	if (ieee80211_type_subtypes[i].tok == NULL) {
605335640Shselasky				  		/* Ran out of types */
606356341Scy						bpf_set_error(cstate, "unknown 802.11 type");
607356341Scy						YYABORT;
608335640Shselasky					}
609335640Shselasky					if ($<i>-1 == ieee80211_type_subtypes[i].type) {
610335640Shselasky						types = ieee80211_type_subtypes[i].tok;
611335640Shselasky						break;
612335640Shselasky					}
613335640Shselasky				  }
614335640Shselasky
615335640Shselasky				  $$ = str2tok($1, types);
616356341Scy				  if ($$ == -1) {
617356341Scy					bpf_set_error(cstate, "unknown 802.11 subtype name");
618356341Scy					YYABORT;
619356341Scy				  }
620335640Shselasky				}
621335640Shselasky	;
622335640Shselasky
623335640Shselaskytype_subtype:	ID		{ int i;
624356341Scy				  CHECK_PTR_VAL($1);
625335640Shselasky				  for (i = 0;; i++) {
626335640Shselasky				  	if (ieee80211_type_subtypes[i].tok == NULL) {
627335640Shselasky				  		/* Ran out of types */
628356341Scy						bpf_set_error(cstate, "unknown 802.11 type name");
629356341Scy						YYABORT;
630335640Shselasky					}
631335640Shselasky					$$ = str2tok($1, ieee80211_type_subtypes[i].tok);
632335640Shselasky					if ($$ != -1) {
633335640Shselasky						$$ |= ieee80211_type_subtypes[i].type;
634335640Shselasky						break;
635335640Shselasky					}
636335640Shselasky				  }
637335640Shselasky				}
638335640Shselasky		;
639335640Shselasky
640356341Scypllc:	LLC			{ CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
641356341Scy	| LLC ID		{ CHECK_PTR_VAL($2);
642356341Scy				  if (pcap_strcasecmp($2, "i") == 0) {
643356341Scy					CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
644356341Scy				  } else if (pcap_strcasecmp($2, "s") == 0) {
645356341Scy					CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
646356341Scy				  } else if (pcap_strcasecmp($2, "u") == 0) {
647356341Scy					CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
648356341Scy				  } else {
649335640Shselasky					int subtype;
650335640Shselasky
651335640Shselasky					subtype = str2tok($2, llc_s_subtypes);
652356341Scy					if (subtype != -1) {
653356341Scy						CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
654356341Scy					} else {
655335640Shselasky						subtype = str2tok($2, llc_u_subtypes);
656356341Scy						if (subtype == -1) {
657356341Scy					  		bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
658356341Scy					  		YYABORT;
659356341Scy					  	}
660356341Scy						CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
661335640Shselasky					}
662335640Shselasky				  }
663335640Shselasky				}
664335640Shselasky				/* sigh, "rnr" is already a keyword for PF */
665356341Scy	| LLC PF_RNR		{ CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
666335640Shselasky	;
667335640Shselasky
668335640Shselaskydir:	  NUM
669356341Scy	| ID			{ CHECK_PTR_VAL($1);
670356341Scy				  if (pcap_strcasecmp($1, "nods") == 0)
671335640Shselasky					$$ = IEEE80211_FC1_DIR_NODS;
672335640Shselasky				  else if (pcap_strcasecmp($1, "tods") == 0)
673335640Shselasky					$$ = IEEE80211_FC1_DIR_TODS;
674335640Shselasky				  else if (pcap_strcasecmp($1, "fromds") == 0)
675335640Shselasky					$$ = IEEE80211_FC1_DIR_FROMDS;
676335640Shselasky				  else if (pcap_strcasecmp($1, "dstods") == 0)
677335640Shselasky					$$ = IEEE80211_FC1_DIR_DSTODS;
678356341Scy				  else {
679356341Scy					bpf_set_error(cstate, "unknown 802.11 direction");
680356341Scy					YYABORT;
681356341Scy				  }
682335640Shselasky				}
683335640Shselasky	;
684335640Shselasky
685335640Shselaskyreason:	  NUM			{ $$ = $1; }
686356341Scy	| ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
687335640Shselasky	;
688335640Shselasky
689356341Scyaction:	  ID			{ CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
690335640Shselasky	;
691335640Shselasky
692335640Shselaskyrelop:	  '>'			{ $$ = BPF_JGT; }
693335640Shselasky	| GEQ			{ $$ = BPF_JGE; }
694335640Shselasky	| '='			{ $$ = BPF_JEQ; }
695335640Shselasky	;
696335640Shselaskyirelop:	  LEQ			{ $$ = BPF_JGT; }
697335640Shselasky	| '<'			{ $$ = BPF_JGE; }
698335640Shselasky	| NEQ			{ $$ = BPF_JEQ; }
699335640Shselasky	;
700356341Scyarth:	  pnum			{ CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
701335640Shselasky	| narth
702335640Shselasky	;
703356341Scynarth:	  pname '[' arth ']'		{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
704356341Scy	| pname '[' arth ':' NUM ']'	{ CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
705356341Scy	| arth '+' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
706356341Scy	| arth '-' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
707356341Scy	| arth '*' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
708356341Scy	| arth '/' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
709356341Scy	| arth '%' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
710356341Scy	| arth '&' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
711356341Scy	| arth '|' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
712356341Scy	| arth '^' arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
713356341Scy	| arth LSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
714356341Scy	| arth RSH arth			{ CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
715356341Scy	| '-' arth %prec UMINUS		{ CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
716335640Shselasky	| paren narth ')'		{ $$ = $2; }
717356341Scy	| LEN				{ CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
718335640Shselasky	;
719335640Shselaskybyteop:	  '&'			{ $$ = '&'; }
720335640Shselasky	| '|'			{ $$ = '|'; }
721335640Shselasky	| '<'			{ $$ = '<'; }
722335640Shselasky	| '>'			{ $$ = '>'; }
723335640Shselasky	| '='			{ $$ = '='; }
724335640Shselasky	;
725335640Shselaskypnum:	  NUM
726335640Shselasky	| paren pnum ')'	{ $$ = $2; }
727335640Shselasky	;
728335640Shselaskyatmtype: LANE			{ $$ = A_LANE; }
729335640Shselasky	| METAC			{ $$ = A_METAC;	}
730335640Shselasky	| BCC			{ $$ = A_BCC; }
731335640Shselasky	| OAMF4EC		{ $$ = A_OAMF4EC; }
732335640Shselasky	| OAMF4SC		{ $$ = A_OAMF4SC; }
733335640Shselasky	| SC			{ $$ = A_SC; }
734335640Shselasky	| ILMIC			{ $$ = A_ILMIC; }
735335640Shselasky	;
736335640Shselaskyatmmultitype: OAM		{ $$ = A_OAM; }
737335640Shselasky	| OAMF4			{ $$ = A_OAMF4; }
738335640Shselasky	| CONNECTMSG		{ $$ = A_CONNECTMSG; }
739335640Shselasky	| METACONNECT		{ $$ = A_METACONNECT; }
740335640Shselasky	;
741335640Shselasky	/* ATM field types quantifier */
742335640Shselaskyatmfield: VPI			{ $$.atmfieldtype = A_VPI; }
743335640Shselasky	| VCI			{ $$.atmfieldtype = A_VCI; }
744335640Shselasky	;
745335640Shselaskyatmvalue: atmfieldvalue
746356341Scy	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0))); }
747356341Scy	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1))); }
748335640Shselasky	| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
749335640Shselasky	;
750335640Shselaskyatmfieldvalue: NUM {
751335640Shselasky	$$.atmfieldtype = $<blk>0.atmfieldtype;
752335640Shselasky	if ($$.atmfieldtype == A_VPI ||
753335640Shselasky	    $$.atmfieldtype == A_VCI)
754356341Scy		CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0)));
755335640Shselasky	}
756335640Shselasky	;
757335640Shselaskyatmlistvalue: atmfieldvalue
758335640Shselasky	| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
759335640Shselasky	;
760335640Shselasky	/* MTP2 types quantifier */
761335640Shselaskymtp2type: FISU			{ $$ = M_FISU; }
762335640Shselasky	| LSSU			{ $$ = M_LSSU; }
763335640Shselasky	| MSU			{ $$ = M_MSU; }
764335640Shselasky	| HFISU			{ $$ = MH_FISU; }
765335640Shselasky	| HLSSU			{ $$ = MH_LSSU; }
766335640Shselasky	| HMSU			{ $$ = MH_MSU; }
767335640Shselasky	;
768335640Shselasky	/* MTP3 field types quantifier */
769335640Shselaskymtp3field: SIO			{ $$.mtp3fieldtype = M_SIO; }
770335640Shselasky	| OPC			{ $$.mtp3fieldtype = M_OPC; }
771335640Shselasky	| DPC			{ $$.mtp3fieldtype = M_DPC; }
772335640Shselasky	| SLS                   { $$.mtp3fieldtype = M_SLS; }
773335640Shselasky	| HSIO			{ $$.mtp3fieldtype = MH_SIO; }
774335640Shselasky	| HOPC			{ $$.mtp3fieldtype = MH_OPC; }
775335640Shselasky	| HDPC			{ $$.mtp3fieldtype = MH_DPC; }
776335640Shselasky	| HSLS                  { $$.mtp3fieldtype = MH_SLS; }
777335640Shselasky	;
778335640Shselaskymtp3value: mtp3fieldvalue
779356341Scy	| relop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0))); }
780356341Scy	| irelop NUM		{ CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1))); }
781335640Shselasky	| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
782335640Shselasky	;
783335640Shselaskymtp3fieldvalue: NUM {
784335640Shselasky	$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
785335640Shselasky	if ($$.mtp3fieldtype == M_SIO ||
786335640Shselasky	    $$.mtp3fieldtype == M_OPC ||
787335640Shselasky	    $$.mtp3fieldtype == M_DPC ||
788335640Shselasky	    $$.mtp3fieldtype == M_SLS ||
789335640Shselasky	    $$.mtp3fieldtype == MH_SIO ||
790335640Shselasky	    $$.mtp3fieldtype == MH_OPC ||
791335640Shselasky	    $$.mtp3fieldtype == MH_DPC ||
792335640Shselasky	    $$.mtp3fieldtype == MH_SLS)
793356341Scy		CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0)));
794335640Shselasky	}
795335640Shselasky	;
796335640Shselaskymtp3listvalue: mtp3fieldvalue
797335640Shselasky	| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
798335640Shselasky	;
799335640Shselasky%%
800