Deleted Added
full compact
grammar.y (162015) grammar.y (172680)
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)

--- 5 unchanged lines hidden (view full) ---

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 *
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)

--- 5 unchanged lines hidden (view full) ---

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 * $FreeBSD: head/contrib/libpcap/grammar.y 162015 2006-09-04 19:54:21Z sam $
22 * $FreeBSD: head/contrib/libpcap/grammar.y 172680 2007-10-16 02:07:55Z mlaier $
23 */
24#ifndef lint
25static const char rcsid[] _U_ =
23 */
24#ifndef lint
25static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.5 2005/09/05 09:08:06 guy Exp $ (LBL)";
26 "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.9 2007/09/12 19:17:25 guy Exp $ (LBL)";
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#ifdef WIN32
34#include <pcap-stdinc.h>

--- 13 unchanged lines hidden (view full) ---

48#include <netinet/in.h>
49#endif /* WIN32 */
50
51#include <stdio.h>
52
53#include "pcap-int.h"
54
55#include "gencode.h"
27#endif
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#ifdef WIN32
34#include <pcap-stdinc.h>

--- 13 unchanged lines hidden (view full) ---

48#include <netinet/in.h>
49#endif /* WIN32 */
50
51#include <stdio.h>
52
53#include "pcap-int.h"
54
55#include "gencode.h"
56#include "pf.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
57#include <pcap-namedb.h>
58
59#ifdef HAVE_OS_PROTO_H
60#include "os-proto.h"
61#endif
62
63#define QSET(q, p, d, a) (q).proto = (p),\
64 (q).dir = (d),\
65 (q).addr = (a)
66
67int n_errors = 0;
68
69static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
70
71static void
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
71int n_errors = 0;
72
73static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
74
75static void
72yyerror(char *msg)
76yyerror(const char *msg)
73{
74 ++n_errors;
75 bpf_error("%s", msg);
76 /* NOTREACHED */
77}
78
79#ifndef YYBISON
80int yyparse(void);
81
82int
83pcap_parse()
84{
85 return (yyparse());
86}
87#endif
88
77{
78 ++n_errors;
79 bpf_error("%s", msg);
80 /* NOTREACHED */
81}
82
83#ifndef YYBISON
84int yyparse(void);
85
86int
87pcap_parse()
88{
89 return (yyparse());
90}
91#endif
92
93#ifdef HAVE_NET_PFVAR_H
94static int
95pfreason_to_num(const char *reason)
96{
97 const char *reasons[] = PFRES_NAMES;
98 int i;
99
100 for (i = 0; reasons[i]; i++) {
101 if (pcap_strcasecmp(reason, reasons[i]) == 0)
102 return (i);
103 }
104 bpf_error("unknown PF reason");
105 /*NOTREACHED*/
106}
107
108static int
109pfaction_to_num(const char *action)
110{
111 if (pcap_strcasecmp(action, "pass") == 0 ||
112 pcap_strcasecmp(action, "accept") == 0)
113 return (PF_PASS);
114 else if (pcap_strcasecmp(action, "drop") == 0 ||
115 pcap_strcasecmp(action, "block") == 0)
116 return (PF_DROP);
117 else {
118 bpf_error("unknown PF action");
119 /*NOTREACHED*/
120 }
121}
122#else /* !HAVE_NET_PFVAR_H */
123static int
124pfreason_to_num(const char *reason)
125{
126 bpf_error("libpcap was compiled on a machine without pf support");
127 /*NOTREACHED*/
128}
129
130static int
131pfaction_to_num(const char *action)
132{
133 bpf_error("libpcap was compiled on a machine without pf support");
134 /*NOTREACHED*/
135}
136#endif /* HAVE_NET_PFVAR_H */
89%}
90
91%union {
92 int i;
93 bpf_u_int32 h;
94 u_char *e;
95 char *s;
96 struct stmt *stmt;

--- 12 unchanged lines hidden (view full) ---

109%type <i> pqual dqual aqual ndaqual
110%type <a> arth narth
111%type <i> byteop pname pnum relop irelop
112%type <blk> and or paren not null prog
113%type <rblk> other pfvar
114%type <i> atmtype atmmultitype
115%type <blk> atmfield
116%type <blk> atmfieldvalue atmvalue atmlistvalue
137%}
138
139%union {
140 int i;
141 bpf_u_int32 h;
142 u_char *e;
143 char *s;
144 struct stmt *stmt;

--- 12 unchanged lines hidden (view full) ---

157%type <i> pqual dqual aqual ndaqual
158%type <a> arth narth
159%type <i> byteop pname pnum relop irelop
160%type <blk> and or paren not null prog
161%type <rblk> other pfvar
162%type <i> atmtype atmmultitype
163%type <blk> atmfield
164%type <blk> atmfieldvalue atmvalue atmlistvalue
117%type <blk> mtp3field
118%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
165%type <i> mtp2type
166%type <blk> mtp3field
167%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
119
120
121%token DST SRC HOST GATEWAY
122%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
123%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
124%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
125%token TK_BROADCAST TK_MULTICAST
126%token NUM INBOUND OUTBOUND

--- 9 unchanged lines hidden (view full) ---

136%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
137%token STP
138%token IPX
139%token NETBEUI
140%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
141%token OAM OAMF4 CONNECTMSG METACONNECT
142%token VPI VCI
143%token RADIO
168
169
170%token DST SRC HOST GATEWAY
171%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
172%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP
173%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
174%token TK_BROADCAST TK_MULTICAST
175%token NUM INBOUND OUTBOUND

--- 9 unchanged lines hidden (view full) ---

185%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
186%token STP
187%token IPX
188%token NETBEUI
189%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
190%token OAM OAMF4 CONNECTMSG METACONNECT
191%token VPI VCI
192%token RADIO
144%token SIO OPC DPC SLS
193%token FISU LSSU MSU
194%token SIO OPC DPC SLS
145
146%type <s> ID
147%type <e> EID
148%type <e> AID
149%type <s> HID HID6
150%type <i> NUM action reason
151
152%left OR AND

--- 104 unchanged lines hidden (view full) ---

257 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
258 $$.q = qerr; }
259 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
260 $$.q = qerr; }
261 | other { $$.b = $1; $$.q = qerr; }
262 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
263 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
264 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
195
196%type <s> ID
197%type <e> EID
198%type <e> AID
199%type <s> HID HID6
200%type <i> NUM action reason
201
202%left OR AND

--- 104 unchanged lines hidden (view full) ---

307 | arth relop arth { $$.b = gen_relation($2, $1, $3, 0);
308 $$.q = qerr; }
309 | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1);
310 $$.q = qerr; }
311 | other { $$.b = $1; $$.q = qerr; }
312 | atmtype { $$.b = gen_atmtype_abbrev($1); $$.q = qerr; }
313 | atmmultitype { $$.b = gen_atmmulti_abbrev($1); $$.q = qerr; }
314 | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
315 | mtp2type { $$.b = gen_mtp2type_abbrev($1); $$.q = qerr; }
265 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
266 ;
267/* protocol level qualifiers */
268pqual: pname
269 | { $$ = Q_DEFAULT; }
270 ;
271/* 'direction' qualifiers */
272dqual: SRC { $$ = Q_SRC; }

--- 71 unchanged lines hidden (view full) ---

344 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
345 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
346 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
347 | PF_REASON reason { $$ = gen_pf_reason($2); }
348 | PF_ACTION action { $$ = gen_pf_action($2); }
349 ;
350
351reason: NUM { $$ = $1; }
316 | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
317 ;
318/* protocol level qualifiers */
319pqual: pname
320 | { $$ = Q_DEFAULT; }
321 ;
322/* 'direction' qualifiers */
323dqual: SRC { $$ = Q_SRC; }

--- 71 unchanged lines hidden (view full) ---

395 | PF_RSET ID { $$ = gen_pf_ruleset($2); }
396 | PF_RNR NUM { $$ = gen_pf_rnr($2); }
397 | PF_SRNR NUM { $$ = gen_pf_srnr($2); }
398 | PF_REASON reason { $$ = gen_pf_reason($2); }
399 | PF_ACTION action { $$ = gen_pf_action($2); }
400 ;
401
402reason: NUM { $$ = $1; }
352 | ID { const char *reasons[] = PFRES_NAMES;
353 int i;
354 for (i = 0; reasons[i]; i++) {
355 if (pcap_strcasecmp($1, reasons[i]) == 0) {
356 $$ = i;
357 break;
358 }
359 }
360 if (reasons[i] == NULL)
361 bpf_error("unknown PF reason");
362 }
403 | ID { $$ = pfreason_to_num($1); }
363 ;
364
404 ;
405
365action: ID { if (pcap_strcasecmp($1, "pass") == 0 ||
366 pcap_strcasecmp($1, "accept") == 0)
367 $$ = PF_PASS;
368 else if (pcap_strcasecmp($1, "drop") == 0 ||
369 pcap_strcasecmp($1, "block") == 0)
370 $$ = PF_DROP;
371 else
372 bpf_error("unknown PF action");
373 }
406action: ID { $$ = pfaction_to_num($1); }
374 ;
375
376relop: '>' { $$ = BPF_JGT; }
377 | GEQ { $$ = BPF_JGE; }
378 | '=' { $$ = BPF_JEQ; }
379 ;
380irelop: LEQ { $$ = BPF_JGT; }
381 | '<' { $$ = BPF_JGE; }

--- 53 unchanged lines hidden (view full) ---

435 if ($$.atmfieldtype == A_VPI ||
436 $$.atmfieldtype == A_VCI)
437 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
438 }
439 ;
440atmlistvalue: atmfieldvalue
441 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
442 ;
407 ;
408
409relop: '>' { $$ = BPF_JGT; }
410 | GEQ { $$ = BPF_JGE; }
411 | '=' { $$ = BPF_JEQ; }
412 ;
413irelop: LEQ { $$ = BPF_JGT; }
414 | '<' { $$ = BPF_JGE; }

--- 53 unchanged lines hidden (view full) ---

468 if ($$.atmfieldtype == A_VPI ||
469 $$.atmfieldtype == A_VCI)
470 $$.b = gen_atmfield_code($$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
471 }
472 ;
473atmlistvalue: atmfieldvalue
474 | atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
475 ;
476 /* MTP2 types quantifier */
477mtp2type: FISU { $$ = M_FISU; }
478 | LSSU { $$ = M_LSSU; }
479 | MSU { $$ = M_MSU; }
480 ;
443 /* MTP3 field types quantifier */
444mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
445 | OPC { $$.mtp3fieldtype = M_OPC; }
446 | DPC { $$.mtp3fieldtype = M_DPC; }
447 | SLS { $$.mtp3fieldtype = M_SLS; }
448 ;
449mtp3value: mtp3fieldvalue
450 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }

--- 16 unchanged lines hidden ---
481 /* MTP3 field types quantifier */
482mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
483 | OPC { $$.mtp3fieldtype = M_OPC; }
484 | DPC { $$.mtp3fieldtype = M_DPC; }
485 | SLS { $$.mtp3fieldtype = M_SLS; }
486 ;
487mtp3value: mtp3fieldvalue
488 | relop NUM { $$.b = gen_mtp3field_code($<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }

--- 16 unchanged lines hidden ---