etc/protocols - sync with NetBSD-8
[minix.git] / external / bsd / libpcap / dist / grammar.y
blob3f3ec29ed6b40b4d756bb5c4fd31718f375468e4
1 /* $NetBSD: grammar.y,v 1.6 2015/03/31 21:39:42 christos Exp $ */
3 %{
4 /*
5 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
19 * written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #include <sys/cdefs.h>
26 __RCSID("$NetBSD: grammar.y,v 1.6 2015/03/31 21:39:42 christos Exp $");
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
32 #ifdef WIN32
33 #include <pcap-stdinc.h>
34 #else /* WIN32 */
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #endif /* WIN32 */
39 #include <stdlib.h>
41 #ifndef WIN32
42 #if __STDC__
43 struct mbuf;
44 struct rtentry;
45 #endif
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #endif /* WIN32 */
51 #include <stdio.h>
53 #include "pcap-int.h"
55 #include "gencode.h"
56 #ifdef HAVE_NET_PFVAR_H
57 #include <net/if.h>
58 #include <net/pfvar.h>
59 #include <net/if_pflog.h>
60 #endif
61 #include "llc.h"
62 #include "ieee80211.h"
63 #include <pcap/namedb.h>
65 #ifdef HAVE_OS_PROTO_H
66 #include "os-proto.h"
67 #endif
69 #define QSET(q, p, d, a) (q).proto = (p),\
70 (q).dir = (d),\
71 (q).addr = (a)
73 struct tok {
74 int v; /* value */
75 const char *s; /* string */
78 static 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 }
86 static 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 }
109 static 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 }
118 static 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" },
124 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
125 { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
126 { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
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" },
132 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
133 { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
134 { 0, NULL }
136 static const struct tok llc_s_subtypes[] = {
137 { LLC_RR, "rr" },
138 { LLC_RNR, "rnr" },
139 { LLC_REJ, "rej" },
140 { 0, NULL }
142 static const struct tok llc_u_subtypes[] = {
143 { LLC_UI, "ui" },
144 { LLC_UA, "ua" },
145 { LLC_DISC, "disc" },
146 { LLC_DM, "dm" },
147 { LLC_SABME, "sabme" },
148 { LLC_TEST, "test" },
149 { LLC_XID, "xid" },
150 { LLC_FRMR, "frmr" },
151 { 0, NULL }
153 struct type2tok {
154 int type;
155 const struct tok *tok;
157 static const struct type2tok ieee80211_type_subtypes[] = {
158 { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
159 { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
160 { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
161 { 0, NULL }
164 static int
165 str2tok(const char *str, const struct tok *toks)
167 int i;
169 for (i = 0; toks[i].s != NULL; i++) {
170 if (pcap_strcasecmp(toks[i].s, str) == 0)
171 return (toks[i].v);
173 return (-1);
176 int n_errors = 0;
178 static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
180 __dead static void
181 yyerror(const char *msg)
183 ++n_errors;
184 bpf_error("%s", msg);
185 /* NOTREACHED */
188 #ifdef NEED_YYPARSE_WRAPPER
189 int yyparse(void);
192 pcap_parse()
194 return (yyparse());
196 #endif
198 #ifdef HAVE_NET_PFVAR_H
199 static int
200 pfreason_to_num(const char *reason)
202 const char *reasons[] = PFRES_NAMES;
203 int i;
205 for (i = 0; reasons[i]; i++) {
206 if (pcap_strcasecmp(reason, reasons[i]) == 0)
207 return (i);
209 bpf_error("unknown PF reason");
210 /*NOTREACHED*/
213 static int
214 pfaction_to_num(const char *action)
216 if (pcap_strcasecmp(action, "pass") == 0 ||
217 pcap_strcasecmp(action, "accept") == 0)
218 return (PF_PASS);
219 else if (pcap_strcasecmp(action, "drop") == 0 ||
220 pcap_strcasecmp(action, "block") == 0)
221 return (PF_DROP);
222 #if HAVE_PF_NAT_THROUGH_PF_NORDR
223 else if (pcap_strcasecmp(action, "rdr") == 0)
224 return (PF_RDR);
225 else if (pcap_strcasecmp(action, "nat") == 0)
226 return (PF_NAT);
227 else if (pcap_strcasecmp(action, "binat") == 0)
228 return (PF_BINAT);
229 else if (pcap_strcasecmp(action, "nordr") == 0)
230 return (PF_NORDR);
231 #endif
232 else {
233 bpf_error("unknown PF action");
234 /*NOTREACHED*/
237 #else /* !HAVE_NET_PFVAR_H */
238 static int
239 pfreason_to_num(const char *reason)
241 bpf_error("libpcap was compiled on a machine without pf support");
242 /*NOTREACHED*/
244 /* this is to make the VC compiler happy */
245 return -1;
248 static int
249 pfaction_to_num(const char *action)
251 bpf_error("libpcap was compiled on a machine without pf support");
252 /*NOTREACHED*/
254 /* this is to make the VC compiler happy */
255 return -1;
257 #endif /* HAVE_NET_PFVAR_H */
260 %union {
261 int i;
262 bpf_u_int32 h;
263 u_char *e;
264 char *s;
265 struct stmt *stmt;
266 struct arth *a;
267 struct {
268 struct qual q;
269 int atmfieldtype;
270 int mtp3fieldtype;
271 struct block *b;
272 } blk;
273 struct block *rblk;
276 %type <blk> expr id nid pid term rterm qid
277 %type <blk> head
278 %type <i> pqual dqual aqual ndaqual
279 %type <a> arth narth
280 %type <i> byteop pname pnum relop irelop
281 %type <blk> and or paren not null prog
282 %type <rblk> other pfvar p80211 pllc
283 %type <i> atmtype atmmultitype
284 %type <blk> atmfield
285 %type <blk> atmfieldvalue atmvalue atmlistvalue
286 %type <i> mtp2type
287 %type <blk> mtp3field
288 %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
291 %token DST SRC HOST GATEWAY
292 %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
293 %token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
294 %token ATALK AARP DECNET LAT SCA MOPRC MOPDL
295 %token TK_BROADCAST TK_MULTICAST
296 %token NUM INBOUND OUTBOUND
297 %token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
298 %token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
299 %token LINK
300 %token GEQ LEQ NEQ
301 %token ID EID HID HID6 AID
302 %token LSH RSH
303 %token LEN
304 %token IPV6 ICMPV6 AH ESP
305 %token VLAN MPLS
306 %token PPPOED PPPOES GENEVE
307 %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
308 %token STP
309 %token IPX
310 %token NETBEUI
311 %token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
312 %token OAM OAMF4 CONNECTMSG METACONNECT
313 %token VPI VCI
314 %token RADIO
315 %token FISU LSSU MSU HFISU HLSSU HMSU
316 %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
319 %type <s> ID
320 %type <e> EID
321 %type <e> AID
322 %type <s> HID HID6
323 %type <i> NUM action reason type subtype type_subtype dir
325 %left OR AND
326 %nonassoc '!'
327 %left '|'
328 %left '&'
329 %left LSH RSH
330 %left '+' '-'
331 %left '*' '/'
332 %nonassoc UMINUS
334 prog: null expr
336 finish_parse($2.b);
338 | null
340 null: /* null */ { $$.q = qerr; }
342 expr: term
343 | expr and term { gen_and($1.b, $3.b); $$ = $3; }
344 | expr and id { gen_and($1.b, $3.b); $$ = $3; }
345 | expr or term { gen_or($1.b, $3.b); $$ = $3; }
346 | expr or id { gen_or($1.b, $3.b); $$ = $3; }
348 and: AND { $$ = $<blk>0; }
350 or: OR { $$ = $<blk>0; }
352 id: nid
353 | pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
354 $$.q = $<blk>0.q); }
355 | paren pid ')' { $$ = $2; }
357 nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
358 | HID '/' NUM { $$.b = gen_mcode($1, NULL, $3,
359 $$.q = $<blk>0.q); }
360 | HID NETMASK HID { $$.b = gen_mcode($1, $3, 0,
361 $$.q = $<blk>0.q); }
362 | HID {
363 /* Decide how to parse HID based on proto */
364 $$.q = $<blk>0.q;
365 if ($$.q.addr == Q_PORT)
366 bpf_error("'port' modifier applied to ip host");
367 else if ($$.q.addr == Q_PORTRANGE)
368 bpf_error("'portrange' modifier applied to ip host");
369 else if ($$.q.addr == Q_PROTO)
370 bpf_error("'proto' modifier applied to ip host");
371 else if ($$.q.addr == Q_PROTOCHAIN)
372 bpf_error("'protochain' modifier applied to ip host");
373 $$.b = gen_ncode($1, 0, $$.q);
375 | HID6 '/' NUM {
376 #ifdef INET6
377 $$.b = gen_mcode6($1, NULL, $3,
378 $$.q = $<blk>0.q);
379 #else
380 bpf_error("'ip6addr/prefixlen' not supported "
381 "in this configuration");
382 #endif /*INET6*/
384 | HID6 {
385 #ifdef INET6
386 $$.b = gen_mcode6($1, 0, 128,
387 $$.q = $<blk>0.q);
388 #else
389 bpf_error("'ip6addr' not supported "
390 "in this configuration");
391 #endif /*INET6*/
393 | EID {
394 $$.b = gen_ecode($1, $$.q = $<blk>0.q);
396 * $1 was allocated by "pcap_ether_aton()",
397 * so we must free it now that we're done
398 * with it.
400 free($1);
402 | AID {
403 $$.b = gen_acode($1, $$.q = $<blk>0.q);
405 * $1 was allocated by "pcap_ether_aton()",
406 * so we must free it now that we're done
407 * with it.
409 free($1);
411 | not id { gen_not($2.b); $$ = $2; }
413 not: '!' { $$ = $<blk>0; }
415 paren: '(' { $$ = $<blk>0; }
417 pid: nid
418 | qid and id { gen_and($1.b, $3.b); $$ = $3; }
419 | qid or id { gen_or($1.b, $3.b); $$ = $3; }
421 qid: pnum { $$.b = gen_ncode(NULL, (bpf_u_int32)$1,
422 $$.q = $<blk>0.q); }
423 | pid
425 term: rterm
426 | not term { gen_not($2.b); $$ = $2; }
428 head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
429 | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
430 | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
431 | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
432 | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
433 | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
435 rterm: head id { $$ = $2; }
436 | paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
437 | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; }
438 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
439 $$.q = qerr; }
440 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
441 $$.q = qerr; }
442 | other { $$.b = $1; $$.q = qerr; }
443 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
444 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
445 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
446 | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
447 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
449 /* protocol level qualifiers */
450 pqual: pname
451 | { $$ = Q_DEFAULT; }
453 /* 'direction' qualifiers */
454 dqual: SRC { $$ = Q_SRC; }
455 | DST { $$ = Q_DST; }
456 | SRC OR DST { $$ = Q_OR; }
457 | DST OR SRC { $$ = Q_OR; }
458 | SRC AND DST { $$ = Q_AND; }
459 | DST AND SRC { $$ = Q_AND; }
460 | ADDR1 { $$ = Q_ADDR1; }
461 | ADDR2 { $$ = Q_ADDR2; }
462 | ADDR3 { $$ = Q_ADDR3; }
463 | ADDR4 { $$ = Q_ADDR4; }
464 | RA { $$ = Q_RA; }
465 | TA { $$ = Q_TA; }
467 /* address type qualifiers */
468 aqual: HOST { $$ = Q_HOST; }
469 | NET { $$ = Q_NET; }
470 | PORT { $$ = Q_PORT; }
471 | PORTRANGE { $$ = Q_PORTRANGE; }
473 /* non-directional address type qualifiers */
474 ndaqual: GATEWAY { $$ = Q_GATEWAY; }
476 pname: LINK { $$ = Q_LINK; }
477 | IP { $$ = Q_IP; }
478 | ARP { $$ = Q_ARP; }
479 | RARP { $$ = Q_RARP; }
480 | SCTP { $$ = Q_SCTP; }
481 | TCP { $$ = Q_TCP; }
482 | UDP { $$ = Q_UDP; }
483 | ICMP { $$ = Q_ICMP; }
484 | IGMP { $$ = Q_IGMP; }
485 | IGRP { $$ = Q_IGRP; }
486 | PIM { $$ = Q_PIM; }
487 | VRRP { $$ = Q_VRRP; }
488 | CARP { $$ = Q_CARP; }
489 | ATALK { $$ = Q_ATALK; }
490 | AARP { $$ = Q_AARP; }
491 | DECNET { $$ = Q_DECNET; }
492 | LAT { $$ = Q_LAT; }
493 | SCA { $$ = Q_SCA; }
494 | MOPDL { $$ = Q_MOPDL; }
495 | MOPRC { $$ = Q_MOPRC; }
496 | IPV6 { $$ = Q_IPV6; }
497 | ICMPV6 { $$ = Q_ICMPV6; }
498 | AH { $$ = Q_AH; }
499 | ESP { $$ = Q_ESP; }
500 | ISO { $$ = Q_ISO; }
501 | ESIS { $$ = Q_ESIS; }
502 | ISIS { $$ = Q_ISIS; }
503 | L1 { $$ = Q_ISIS_L1; }
504 | L2 { $$ = Q_ISIS_L2; }
505 | IIH { $$ = Q_ISIS_IIH; }
506 | LSP { $$ = Q_ISIS_LSP; }
507 | SNP { $$ = Q_ISIS_SNP; }
508 | PSNP { $$ = Q_ISIS_PSNP; }
509 | CSNP { $$ = Q_ISIS_CSNP; }
510 | CLNP { $$ = Q_CLNP; }
511 | STP { $$ = Q_STP; }
512 | IPX { $$ = Q_IPX; }
513 | NETBEUI { $$ = Q_NETBEUI; }
514 | RADIO { $$ = Q_RADIO; }
516 other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
517 | pqual TK_MULTICAST { $$ = gen_multicast($1); }
518 | LESS NUM { $$ = gen_less($2); }
519 | GREATER NUM { $$ = gen_greater($2); }
520 | CBYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); }
521 | INBOUND { $$ = gen_inbound(0); }
522 | OUTBOUND { $$ = gen_inbound(1); }
523 | VLAN pnum { $$ = gen_vlan($2); }
524 | VLAN { $$ = gen_vlan(-1); }
525 | MPLS pnum { $$ = gen_mpls($2); }
526 | MPLS { $$ = gen_mpls(-1); }
527 | PPPOED { $$ = gen_pppoed(); }
528 | PPPOES pnum { $$ = gen_pppoes($2); }
529 | PPPOES { $$ = gen_pppoes(-1); }
530 | GENEVE pnum { $$ = gen_geneve($2); }
531 | GENEVE { $$ = gen_geneve(-1); }
532 | pfvar { $$ = $1; }
533 | pqual p80211 { $$ = $2; }
534 | pllc { $$ = $1; }
537 pfvar: PF_IFNAME ID { $$ = gen_pf_ifname($2); }
538 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
539 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
540 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
541 | PF_REASON reason { $$ = gen_pf_reason($2); }
542 | PF_ACTION action { $$ = gen_pf_action($2); }
545 p80211: TYPE type SUBTYPE subtype
546 { $$ = gen_p80211_type($2 | $4,
547 IEEE80211_FC0_TYPE_MASK |
548 IEEE80211_FC0_SUBTYPE_MASK);
550 | TYPE type { $$ = gen_p80211_type($2,
551 IEEE80211_FC0_TYPE_MASK);
553 | SUBTYPE type_subtype { $$ = gen_p80211_type($2,
554 IEEE80211_FC0_TYPE_MASK |
555 IEEE80211_FC0_SUBTYPE_MASK);
557 | DIR dir { $$ = gen_p80211_fcdir($2); }
560 type: NUM
561 | ID { $$ = str2tok($1, ieee80211_types);
562 if ($$ == -1)
563 bpf_error("unknown 802.11 type name");
567 subtype: NUM
568 | ID { const struct tok *types = NULL;
569 int i;
570 for (i = 0;; i++) {
571 if (ieee80211_type_subtypes[i].tok == NULL) {
572 /* Ran out of types */
573 bpf_error("unknown 802.11 type");
574 break;
576 if ($<i>-1 == ieee80211_type_subtypes[i].type) {
577 types = ieee80211_type_subtypes[i].tok;
578 break;
582 $$ = str2tok($1, types);
583 if ($$ == -1)
584 bpf_error("unknown 802.11 subtype name");
588 type_subtype: ID { int i;
589 for (i = 0;; i++) {
590 if (ieee80211_type_subtypes[i].tok == NULL) {
591 /* Ran out of types */
592 bpf_error("unknown 802.11 type name");
593 break;
595 $$ = str2tok($1, ieee80211_type_subtypes[i].tok);
596 if ($$ != -1) {
597 $$ |= ieee80211_type_subtypes[i].type;
598 break;
604 pllc: LLC { $$ = gen_llc(); }
605 | LLC ID { if (pcap_strcasecmp($2, "i") == 0)
606 $$ = gen_llc_i();
607 else if (pcap_strcasecmp($2, "s") == 0)
608 $$ = gen_llc_s();
609 else if (pcap_strcasecmp($2, "u") == 0)
610 $$ = gen_llc_u();
611 else {
612 u_int subtype;
614 subtype = str2tok($2, llc_s_subtypes);
615 if (subtype != (u_int)-1)
616 $$ = gen_llc_s_subtype(subtype);
617 else {
618 subtype = str2tok($2, llc_u_subtypes);
619 if (subtype == (u_int)-1)
620 bpf_error("unknown LLC type name \"%s\"", $2);
621 $$ = gen_llc_u_subtype(subtype);
625 /* sigh, "rnr" is already a keyword for PF */
626 | LLC PF_RNR { $$ = gen_llc_s_subtype(LLC_RNR); }
629 dir: NUM
630 | ID { if (pcap_strcasecmp($1, "nods") == 0)
631 $$ = IEEE80211_FC1_DIR_NODS;
632 else if (pcap_strcasecmp($1, "tods") == 0)
633 $$ = IEEE80211_FC1_DIR_TODS;
634 else if (pcap_strcasecmp($1, "fromds") == 0)
635 $$ = IEEE80211_FC1_DIR_FROMDS;
636 else if (pcap_strcasecmp($1, "dstods") == 0)
637 $$ = IEEE80211_FC1_DIR_DSTODS;
638 else
639 bpf_error("unknown 802.11 direction");
643 reason: NUM { $$ = $1; }
644 | ID { $$ = pfreason_to_num($1); }
647 action: ID { $$ = pfaction_to_num($1); }
650 relop: '>' { $$ = BPF_JGT; }
651 | GEQ { $$ = BPF_JGE; }
652 | '=' { $$ = BPF_JEQ; }
654 irelop: LEQ { $$ = BPF_JGT; }
655 | '<' { $$ = BPF_JGE; }
656 | NEQ { $$ = BPF_JEQ; }
658 arth: pnum { $$ = gen_loadi($1); }
659 | narth
661 narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); }
662 | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); }
663 | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); }
664 | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); }
665 | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); }
666 | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); }
667 | arth '%' arth { $$ = gen_arth(BPF_MOD, $1, $3); }
668 | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); }
669 | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); }
670 | arth '^' arth { $$ = gen_arth(BPF_XOR, $1, $3); }
671 | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); }
672 | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); }
673 | '-' arth %prec UMINUS { $$ = gen_neg($2); }
674 | paren narth ')' { $$ = $2; }
675 | LEN { $$ = gen_loadlen(); }
677 byteop: '&' { $$ = '&'; }
678 | '|' { $$ = '|'; }
679 | '<' { $$ = '<'; }
680 | '>' { $$ = '>'; }
681 | '=' { $$ = '='; }
683 pnum: NUM
684 | paren pnum ')' { $$ = $2; }
686 atmtype: LANE { $$ = A_LANE; }
687 | METAC { $$ = A_METAC; }
688 | BCC { $$ = A_BCC; }
689 | OAMF4EC { $$ = A_OAMF4EC; }
690 | OAMF4SC { $$ = A_OAMF4SC; }
691 | SC { $$ = A_SC; }
692 | ILMIC { $$ = A_ILMIC; }
694 atmmultitype: OAM { $$ = A_OAM; }
695 | OAMF4 { $$ = A_OAMF4; }
696 | CONNECTMSG { $$ = A_CONNECTMSG; }
697 | METACONNECT { $$ = A_METACONNECT; }
699 /* ATM field types quantifier */
700 atmfield: VPI { $$.atmfieldtype = A_VPI; }
701 | VCI { $$.atmfieldtype = A_VCI; }
703 atmvalue: atmfieldvalue
704 | relop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
705 | irelop NUM { $$.b = gen_atmfield_code($<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
706 | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
708 atmfieldvalue: NUM {
709 $$.atmfieldtype = $<blk>0.atmfieldtype;
710 if ($$.atmfieldtype == A_VPI ||
711 $$.atmfieldtype == A_VCI)
712 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
715 atmlistvalue: atmfieldvalue
716 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
718 /* MTP2 types quantifier */
719 mtp2type: FISU { $$ = M_FISU; }
720 | LSSU { $$ = M_LSSU; }
721 | MSU { $$ = M_MSU; }
722 | HFISU { $$ = MH_FISU; }
723 | HLSSU { $$ = MH_LSSU; }
724 | HMSU { $$ = MH_MSU; }
726 /* MTP3 field types quantifier */
727 mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
728 | OPC { $$.mtp3fieldtype = M_OPC; }
729 | DPC { $$.mtp3fieldtype = M_DPC; }
730 | SLS { $$.mtp3fieldtype = M_SLS; }
731 | HSIO { $$.mtp3fieldtype = MH_SIO; }
732 | HOPC { $$.mtp3fieldtype = MH_OPC; }
733 | HDPC { $$.mtp3fieldtype = MH_DPC; }
734 | HSLS { $$.mtp3fieldtype = MH_SLS; }
736 mtp3value: mtp3fieldvalue
737 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
738 | irelop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
739 | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
741 mtp3fieldvalue: NUM {
742 $$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
743 if ($$.mtp3fieldtype == M_SIO ||
744 $$.mtp3fieldtype == M_OPC ||
745 $$.mtp3fieldtype == M_DPC ||
746 $$.mtp3fieldtype == M_SLS ||
747 $$.mtp3fieldtype == MH_SIO ||
748 $$.mtp3fieldtype == MH_OPC ||
749 $$.mtp3fieldtype == MH_DPC ||
750 $$.mtp3fieldtype == MH_SLS)
751 $$.b = gen_mtp3field_code($$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
754 mtp3listvalue: mtp3fieldvalue
755 | mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }