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