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