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