Merge branch 'vendor/LIBPCAP'
[dragonfly.git] / contrib / libpcap / grammar.y
CommitLineData
23fa89e6
PA
1%{
2/*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 */
23#ifndef lint
24static const char rcsid[] _U_ =
a85e14b0 25 "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.101 2007-11-18 02:03:52 guy Exp $ (LBL)";
23fa89e6
PA
26#endif
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#ifdef WIN32
33#include <pcap-stdinc.h>
34#else /* WIN32 */
35#include <sys/types.h>
36#include <sys/socket.h>
37#endif /* WIN32 */
38
39#include <stdlib.h>
40
41#ifndef WIN32
42#if __STDC__
43struct mbuf;
44struct rtentry;
45#endif
46
47#include <netinet/in.h>
a85e14b0 48#include <arpa/inet.h>
23fa89e6
PA
49#endif /* WIN32 */
50
51#include <stdio.h>
52
53#include "pcap-int.h"
54
55#include "gencode.h"
084fe320
PA
56#ifdef HAVE_NET_PFVAR_H
57#include <net/if.h>
9320aa5c
PA
58#include <net/if_var.h>
59#include <net/pf/pfvar.h>
60#include <net/pf/if_pflog.h>
084fe320 61#endif
ac0eb610 62#include <netproto/802_11/ieee80211.h>
de0d3203 63#include <pcap/namedb.h>
ac0eb610 64
23fa89e6
PA
65#ifdef HAVE_OS_PROTO_H
66#include "os-proto.h"
67#endif
68
69#define QSET(q, p, d, a) (q).proto = (p),\
70 (q).dir = (d),\
71 (q).addr = (a)
72
de0d3203
PA
73struct tok {
74 int v; /* value */
75 const char *s; /* string */
76};
77
78static const struct tok ieee80211_types[] = {
79 { IEEE80211_FC0_TYPE_DATA, "data" },
80 { IEEE80211_FC0_TYPE_MGT, "mgt" },
81 { IEEE80211_FC0_TYPE_MGT, "management" },
82 { IEEE80211_FC0_TYPE_CTL, "ctl" },
83 { IEEE80211_FC0_TYPE_CTL, "control" },
84 { 0, NULL }
85};
86static const struct tok ieee80211_mgt_subtypes[] = {
87 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
88 { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
89 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
90 { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
91 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
92 { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
93 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
94 { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
95 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
96 { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
97 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
98 { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
99 { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
100 { IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
101 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
102 { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
103 { IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
104 { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
105 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
106 { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
107 { 0, NULL }
108};
109static const struct tok ieee80211_ctl_subtypes[] = {
110 { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
111 { IEEE80211_FC0_SUBTYPE_RTS, "rts" },
112 { IEEE80211_FC0_SUBTYPE_CTS, "cts" },
113 { IEEE80211_FC0_SUBTYPE_ACK, "ack" },
114 { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
115 { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
116 { 0, NULL }
117};
118static const struct tok ieee80211_data_subtypes[] = {
119 { IEEE80211_FC0_SUBTYPE_DATA, "data" },
120 { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
121 { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
122 { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
123 { IEEE80211_FC0_SUBTYPE_NODATA, "null" },
42bcdd13
PA
124 { IEEE80211_FC0_SUBTYPE_CFACK, "cf-ack" },
125 { IEEE80211_FC0_SUBTYPE_CFPOLL, "cf-poll" },
126 { IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK, "cf-ack-poll" },
de0d3203
PA
127 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
128 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
129 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
130 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
131 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
42bcdd13
PA
132 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CFPOLL, "qos-cf-poll" },
133 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK, "qos-cf-ack-poll" },
de0d3203
PA
134 { 0, NULL }
135};
136struct type2tok {
137 int type;
138 const struct tok *tok;
139};
140static const struct type2tok ieee80211_type_subtypes[] = {
141 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
142 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
143 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
144 { 0, NULL }
145};
146
147static int
148str2tok(const char *str, const struct tok *toks)
149{
150 int i;
151
152 for (i = 0; toks[i].s != NULL; i++) {
153 if (pcap_strcasecmp(toks[i].s, str) == 0)
154 return (toks[i].v);
155 }
156 return (-1);
157}
ac0eb610 158
23fa89e6
PA
159int n_errors = 0;
160
161static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
162
163static void
dfcad8d8 164yyerror(const char *msg)
23fa89e6
PA
165{
166 ++n_errors;
167 bpf_error("%s", msg);
168 /* NOTREACHED */
169}
170
171#ifndef YYBISON
172int yyparse(void);
173
174int
175pcap_parse()
176{
177 return (yyparse());
178}
179#endif
180
084fe320
PA
181#ifdef HAVE_NET_PFVAR_H
182static int
183pfreason_to_num(const char *reason)
184{
185 const char *reasons[] = PFRES_NAMES;
186 int i;
187
188 for (i = 0; reasons[i]; i++) {
189 if (pcap_strcasecmp(reason, reasons[i]) == 0)
190 return (i);
191 }
192 bpf_error("unknown PF reason");
193 /*NOTREACHED*/
194}
195
196static int
197pfaction_to_num(const char *action)
198{
199 if (pcap_strcasecmp(action, "pass") == 0 ||
200 pcap_strcasecmp(action, "accept") == 0)
201 return (PF_PASS);
202 else if (pcap_strcasecmp(action, "drop") == 0 ||
203 pcap_strcasecmp(action, "block") == 0)
204 return (PF_DROP);
de0d3203
PA
205#if HAVE_PF_NAT_THROUGH_PF_NORDR
206 else if (pcap_strcasecmp(action, "rdr") == 0)
207 return (PF_RDR);
208 else if (pcap_strcasecmp(action, "nat") == 0)
209 return (PF_NAT);
210 else if (pcap_strcasecmp(action, "binat") == 0)
211 return (PF_BINAT);
212 else if (pcap_strcasecmp(action, "nordr") == 0)
213 return (PF_NORDR);
214#endif
084fe320
PA
215 else {
216 bpf_error("unknown PF action");
217 /*NOTREACHED*/
218 }
219}
220#else /* !HAVE_NET_PFVAR_H */
221static int
222pfreason_to_num(const char *reason)
223{
224 bpf_error("libpcap was compiled on a machine without pf support");
225 /*NOTREACHED*/
de0d3203
PA
226
227 /* this is to make the VC compiler happy */
228 return -1;
084fe320
PA
229}
230
231static int
232pfaction_to_num(const char *action)
233{
234 bpf_error("libpcap was compiled on a machine without pf support");
235 /*NOTREACHED*/
de0d3203
PA
236
237 /* this is to make the VC compiler happy */
238 return -1;
084fe320
PA
239}
240#endif /* HAVE_NET_PFVAR_H */
23fa89e6
PA
241%}
242
243%union {
244 int i;
245 bpf_u_int32 h;
246 u_char *e;
247 char *s;
248 struct stmt *stmt;
249 struct arth *a;
250 struct {
251 struct qual q;
252 int atmfieldtype;
253 int mtp3fieldtype;
254 struct block *b;
255 } blk;
256 struct block *rblk;
257}
258
259%type <blk> expr id nid pid term rterm qid
260%type <blk> head
261%type <i> pqual dqual aqual ndaqual
262%type <a> arth narth
263%type <i> byteop pname pnum relop irelop
264%type <blk> and or paren not null prog
ac0eb610 265%type <rblk> other pfvar p80211
23fa89e6
PA
266%type <i> atmtype atmmultitype
267%type <blk> atmfield
268%type <blk> atmfieldvalue atmvalue atmlistvalue
dfcad8d8
PA
269%type <i> mtp2type
270%type <blk> mtp3field
271%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
23fa89e6
PA
272
273
274%token DST SRC HOST GATEWAY
275%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
a85e14b0 276%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
23fa89e6
PA
277%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
278%token TK_BROADCAST TK_MULTICAST
279%token NUM INBOUND OUTBOUND
280%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
a85e14b0 281%token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
23fa89e6
PA
282%token LINK
283%token GEQ LEQ NEQ
284%token ID EID HID HID6 AID
285%token LSH RSH
286%token LEN
287%token IPV6 ICMPV6 AH ESP
288%token VLAN MPLS
289%token PPPOED PPPOES
290%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
291%token STP
292%token IPX
293%token NETBEUI
294%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
295%token OAM OAMF4 CONNECTMSG METACONNECT
296%token VPI VCI
297%token RADIO
dfcad8d8
PA
298%token FISU LSSU MSU
299%token SIO OPC DPC SLS
23fa89e6
PA
300
301%type <s> ID
302%type <e> EID
303%type <e> AID
304%type <s> HID HID6
de0d3203 305%type <i> NUM action reason type subtype type_subtype dir
23fa89e6
PA
306
307%left OR AND
308%nonassoc '!'
309%left '|'
310%left '&'
311%left LSH RSH
312%left '+' '-'
313%left '*' '/'
314%nonassoc UMINUS
315%%
316prog: null expr
317{
318 finish_parse($2.b);
319}
320 | null
321 ;
322null: /* null */ { $$.q = qerr; }
323 ;
324expr: term
325 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
326 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
327 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
328 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
329 ;
330and: AND { $$ = $<blk>0; }
331 ;
332or: OR { $$ = $<blk>0; }
333 ;
334id: nid
335 | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
336 $$.q = $<blk>0.q); }
337 | paren pid ')' { $$ = $2; }
338 ;
339nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
340 | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
341 $$.q = $<blk>0.q); }
342 | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
343 $$.q = $<blk>0.q); }
344 | HID {
345 /* Decide how to parse HID based on proto */
346 $$.q = $<blk>0.q;
de0d3203
PA
347 if ($$.q.addr == Q_PORT)
348 bpf_error("'port' modifier applied to ip host");
349 else if ($$.q.addr == Q_PORTRANGE)
350 bpf_error("'portrange' modifier applied to ip host");
351 else if ($$.q.addr == Q_PROTO)
352 bpf_error("'proto' modifier applied to ip host");
353 else if ($$.q.addr == Q_PROTOCHAIN)
354 bpf_error("'protochain' modifier applied to ip host");
23fa89e6
PA
355 $$.b = gen_ncode($1, 0, $$.q);
356 }
357 | HID6 '/' NUM {
358#ifdef INET6
359 $$.b = gen_mcode6($1, NULL, $3,
360 $$.q = $<blk>0.q);
361#else
362 bpf_error("'ip6addr/prefixlen' not supported "
363 "in this configuration");
364#endif /*INET6*/
365 }
366 | HID6 {
367#ifdef INET6
368 $$.b = gen_mcode6($1, 0, 128,
369 $$.q = $<blk>0.q);
370#else
371 bpf_error("'ip6addr' not supported "
372 "in this configuration");
373#endif /*INET6*/
374 }
375 | EID {
376 $$.b = gen_ecode($1, $$.q = $<blk>0.q);
377 /*
378 * $1 was allocated by "pcap_ether_aton()",
379 * so we must free it now that we're done
380 * with it.
381 */
382 free($1);
383 }
384 | AID {
385 $$.b = gen_acode($1, $$.q = $<blk>0.q);
386 /*
387 * $1 was allocated by "pcap_ether_aton()",
388 * so we must free it now that we're done
389 * with it.
390 */
391 free($1);
392 }
393 | not id { gen_not($2.b); $$ = $2; }
394 ;
395not: '!' { $$ = $<blk>0; }
396 ;
397paren: '(' { $$ = $<blk>0; }
398 ;
399pid: nid
400 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
401 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
402 ;
403qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
404 $$.q = $<blk>0.q); }
405 | pid
406 ;
407term: rterm
408 | not term { gen_not($2.b); $$ = $2; }
409 ;
410head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
411 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
412 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
413 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
414 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
415 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
416 ;
417rterm: head id { $$ = $2; }
418 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
419 | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
420 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
421 $$.q = qerr; }
422 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
423 $$.q = qerr; }
424 | other { $$.b = $1; $$.q = qerr; }
425 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
426 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
427 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
dfcad8d8 428 | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
23fa89e6
PA
429 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
430 ;
431/* protocol level qualifiers */
432pqual: pname
433 | { $$ = Q_DEFAULT; }
434 ;
435/* 'direction' qualifiers */
436dqual: SRC { $$ = Q_SRC; }
437 | DST { $$ = Q_DST; }
438 | SRC OR DST { $$ = Q_OR; }
439 | DST OR SRC { $$ = Q_OR; }
440 | SRC AND DST { $$ = Q_AND; }
441 | DST AND SRC { $$ = Q_AND; }
de0d3203
PA
442 | ADDR1 { $$ = Q_ADDR1; }
443 | ADDR2 { $$ = Q_ADDR2; }
444 | ADDR3 { $$ = Q_ADDR3; }
445 | ADDR4 { $$ = Q_ADDR4; }
a85e14b0
PA
446 | RA { $$ = Q_RA; }
447 | TA { $$ = Q_TA; }
23fa89e6
PA
448 ;
449/* address type qualifiers */
450aqual: HOST { $$ = Q_HOST; }
451 | NET { $$ = Q_NET; }
452 | PORT { $$ = Q_PORT; }
453 | PORTRANGE { $$ = Q_PORTRANGE; }
454 ;
455/* non-directional address type qualifiers */
456ndaqual: GATEWAY { $$ = Q_GATEWAY; }
457 ;
458pname: LINK { $$ = Q_LINK; }
459 | IP { $$ = Q_IP; }
460 | ARP { $$ = Q_ARP; }
461 | RARP { $$ = Q_RARP; }
462 | SCTP { $$ = Q_SCTP; }
463 | TCP { $$ = Q_TCP; }
464 | UDP { $$ = Q_UDP; }
465 | ICMP { $$ = Q_ICMP; }
466 | IGMP { $$ = Q_IGMP; }
467 | IGRP { $$ = Q_IGRP; }
468 | PIM { $$ = Q_PIM; }
469 | VRRP { $$ = Q_VRRP; }
a85e14b0 470 | CARP { $$ = Q_CARP; }
23fa89e6
PA
471 | ATALK { $$ = Q_ATALK; }
472 | AARP { $$ = Q_AARP; }
473 | DECNET { $$ = Q_DECNET; }
474 | LAT { $$ = Q_LAT; }
475 | SCA { $$ = Q_SCA; }
476 | MOPDL { $$ = Q_MOPDL; }
477 | MOPRC { $$ = Q_MOPRC; }
478 | IPV6 { $$ = Q_IPV6; }
479 | ICMPV6 { $$ = Q_ICMPV6; }
480 | AH { $$ = Q_AH; }
481 | ESP { $$ = Q_ESP; }
482 | ISO { $$ = Q_ISO; }
483 | ESIS { $$ = Q_ESIS; }
484 | ISIS { $$ = Q_ISIS; }
485 | L1 { $$ = Q_ISIS_L1; }
486 | L2 { $$ = Q_ISIS_L2; }
487 | IIH { $$ = Q_ISIS_IIH; }
488 | LSP { $$ = Q_ISIS_LSP; }
489 | SNP { $$ = Q_ISIS_SNP; }
490 | PSNP { $$ = Q_ISIS_PSNP; }
491 | CSNP { $$ = Q_ISIS_CSNP; }
492 | CLNP { $$ = Q_CLNP; }
493 | STP { $$ = Q_STP; }
494 | IPX { $$ = Q_IPX; }
495 | NETBEUI { $$ = Q_NETBEUI; }
496 | RADIO { $$ = Q_RADIO; }
497 ;
498other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
499 | pqual TK_MULTICAST { $$ = gen_multicast($1); }
500 | LESS NUM { $$ = gen_less($2); }
501 | GREATER NUM { $$ = gen_greater($2); }
502 | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
503 | INBOUND { $$ = gen_inbound(0); }
504 | OUTBOUND { $$ = gen_inbound(1); }
505 | VLAN pnum { $$ = gen_vlan($2); }
506 | VLAN { $$ = gen_vlan(-1); }
507 | MPLS pnum { $$ = gen_mpls($2); }
508 | MPLS { $$ = gen_mpls(-1); }
509 | PPPOED { $$ = gen_pppoed(); }
510 | PPPOES { $$ = gen_pppoes(); }
511 | pfvar { $$ = $1; }
ac0eb610 512 | pqual p80211 { $$ = $2; }
23fa89e6
PA
513 ;
514
515pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
516 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
517 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
518 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
519 | PF_REASON reason { $$ = gen_pf_reason($2); }
520 | PF_ACTION action { $$ = gen_pf_action($2); }
521 ;
522
ac0eb610
PA
523p80211: TYPE type SUBTYPE subtype
524 { $$ = gen_p80211_type($2 | $4,
525 IEEE80211_FC0_TYPE_MASK |
526 IEEE80211_FC0_SUBTYPE_MASK);
527 }
528 | TYPE type { $$ = gen_p80211_type($2,
529 IEEE80211_FC0_TYPE_MASK);
530 }
531 | SUBTYPE type_subtype { $$ = gen_p80211_type($2,
532 IEEE80211_FC0_TYPE_MASK |
533 IEEE80211_FC0_SUBTYPE_MASK);
534 }
de0d3203 535 | DIR dir { $$ = gen_p80211_fcdir($2); }
ac0eb610
PA
536 ;
537
538type: NUM
de0d3203
PA
539 | ID { $$ = str2tok($1, ieee80211_types);
540 if ($$ == -1)
ac0eb610
PA
541 bpf_error("unknown 802.11 type name");
542 }
543 ;
544
545subtype: NUM
de0d3203
PA
546 | ID { const struct tok *types = NULL;
547 int i;
548 for (i = 0;; i++) {
549 if (ieee80211_type_subtypes[i].tok == NULL) {
550 /* Ran out of types */
551 bpf_error("unknown 802.11 type");
552 break;
553 }
554 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
555 types = ieee80211_type_subtypes[i].tok;
ac0eb610
PA
556 break;
557 }
558 }
de0d3203
PA
559
560 $$ = str2tok($1, types);
561 if ($$ == -1)
562 bpf_error("unknown 802.11 subtype name");
ac0eb610
PA
563 }
564 ;
565
de0d3203
PA
566type_subtype: ID { int i;
567 for (i = 0;; i++) {
568 if (ieee80211_type_subtypes[i].tok == NULL) {
569 /* Ran out of types */
570 bpf_error("unknown 802.11 type name");
571 break;
ac0eb610 572 }
de0d3203
PA
573 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
574 if ($$ != -1) {
575 $$ |= ieee80211_type_subtypes[i].type;
ac0eb610
PA
576 break;
577 }
578 }
ac0eb610
PA
579 }
580 ;
581
de0d3203
PA
582dir: NUM
583 | ID { if (pcap_strcasecmp($1, "nods") == 0)
584 $$ = IEEE80211_FC1_DIR_NODS;
585 else if (pcap_strcasecmp($1, "tods") == 0)
586 $$ = IEEE80211_FC1_DIR_TODS;
587 else if (pcap_strcasecmp($1, "fromds") == 0)
588 $$ = IEEE80211_FC1_DIR_FROMDS;
589 else if (pcap_strcasecmp($1, "dstods") == 0)
590 $$ = IEEE80211_FC1_DIR_DSTODS;
591 else
592 bpf_error("unknown 802.11 direction");
593 }
594 ;
595
23fa89e6 596reason: NUM { $$ = $1; }
084fe320 597 | ID { $$ = pfreason_to_num($1); }
23fa89e6
PA
598 ;
599
084fe320 600action: ID { $$ = pfaction_to_num($1); }
23fa89e6
PA
601 ;
602
603relop: '>' { $$ = BPF_JGT; }
604 | GEQ { $$ = BPF_JGE; }
605 | '=' { $$ = BPF_JEQ; }
606 ;
607irelop: LEQ { $$ = BPF_JGT; }
608 | '<' { $$ = BPF_JGE; }
609 | NEQ { $$ = BPF_JEQ; }
610 ;
611arth: pnum { $$ = gen_loadi($1); }
612 | narth
613 ;
614narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
615 | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
616 | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
617 | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
618 | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
619 | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
620 | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
621 | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
622 | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
623 | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
624 | '-' arth %prec UMINUS { $$ = gen_neg($2); }
625 | paren narth ')' { $$ = $2; }
626 | LEN { $$ = gen_loadlen(); }
627 ;
628byteop: '&' { $$ = '&'; }
629 | '|' { $$ = '|'; }
630 | '<' { $$ = '<'; }
631 | '>' { $$ = '>'; }
632 | '=' { $$ = '='; }
633 ;
634pnum: NUM
635 | paren pnum ')' { $$ = $2; }
636 ;
637atmtype: LANE { $$ = A_LANE; }
638 | LLC { $$ = A_LLC; }
639 | METAC { $$ = A_METAC; }
640 | BCC { $$ = A_BCC; }
641 | OAMF4EC { $$ = A_OAMF4EC; }
642 | OAMF4SC { $$ = A_OAMF4SC; }
643 | SC { $$ = A_SC; }
644 | ILMIC { $$ = A_ILMIC; }
645 ;
646atmmultitype: OAM { $$ = A_OAM; }
647 | OAMF4 { $$ = A_OAMF4; }
648 | CONNECTMSG { $$ = A_CONNECTMSG; }
649 | METACONNECT { $$ = A_METACONNECT; }
650 ;
651 /* ATM field types quantifier */
652atmfield: VPI { $$.atmfieldtype = A_VPI; }
653 | VCI { $$.atmfieldtype = A_VCI; }
654 ;
655atmvalue: atmfieldvalue
656 | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
657 | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
658 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
659 ;
660atmfieldvalue: NUM {
661 $$.atmfieldtype = $<blk>0.atmfieldtype;
662 if ($$.atmfieldtype == A_VPI ||
663 $$.atmfieldtype == A_VCI)
664 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
665 }
666 ;
667atmlistvalue: atmfieldvalue
668 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
669 ;
dfcad8d8
PA
670 /* MTP2 types quantifier */
671mtp2type: FISU { $$ = M_FISU; }
672 | LSSU { $$ = M_LSSU; }
673 | MSU { $$ = M_MSU; }
674 ;
23fa89e6
PA
675 /* MTP3 field types quantifier */
676mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
677 | OPC { $$.mtp3fieldtype = M_OPC; }
678 | DPC { $$.mtp3fieldtype = M_DPC; }
679 | SLS { $$.mtp3fieldtype = M_SLS; }
680 ;
681mtp3value: mtp3fieldvalue
682 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
683 | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
684 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
685 ;
686mtp3fieldvalue: NUM {
687 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
688 if ($$.mtp3fieldtype == M_SIO ||
689 $$.mtp3fieldtype == M_OPC ||
690 $$.mtp3fieldtype == M_DPC ||
691 $$.mtp3fieldtype == M_SLS )
692 $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
693 }
694 ;
695mtp3listvalue: mtp3fieldvalue
696 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
697 ;
698%%