2017-02-12 07:04:44 +00:00
|
|
|
/*
|
|
|
|
* We want a reentrant parser.
|
|
|
|
*/
|
|
|
|
%pure-parser
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We also want a reentrant scanner, so we have to pass the
|
|
|
|
* handle for the reentrant scanner to the parser, and the
|
|
|
|
* parser has to pass it to the lexical analyzer.
|
|
|
|
*
|
|
|
|
* We use void * rather than yyscan_t because, at least with some
|
|
|
|
* versions of Flex and Bison, if you use yyscan_t in %parse-param and
|
|
|
|
* %lex-param, you have to include scanner.h before grammar.h to get
|
|
|
|
* yyscan_t declared, and you have to include grammar.h before scanner.h
|
|
|
|
* to get YYSTYPE declared. Using void * breaks the cycle; the Flex
|
|
|
|
* documentation says yyscan_t is just a void *.
|
|
|
|
*/
|
|
|
|
%parse-param {void *yyscanner}
|
|
|
|
%lex-param {void *yyscanner}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And we need to pass the compiler state to the scanner.
|
|
|
|
*/
|
|
|
|
%parse-param {compiler_state_t *cstate}
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
2000-01-30 00:43:38 +00:00
|
|
|
* $FreeBSD$
|
1996-08-19 20:36:34 +00:00
|
|
|
*/
|
2001-04-03 04:32:48 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
1996-08-19 20:36:34 +00:00
|
|
|
#endif
|
|
|
|
|
2017-02-12 07:04:44 +00:00
|
|
|
#ifdef _WIN32
|
2004-03-31 09:15:09 +00:00
|
|
|
#include <pcap-stdinc.h>
|
2017-02-12 07:04:44 +00:00
|
|
|
#else /* _WIN32 */
|
1996-08-19 20:36:34 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
2017-02-12 07:04:44 +00:00
|
|
|
#endif /* _WIN32 */
|
2004-03-31 09:15:09 +00:00
|
|
|
|
2001-04-03 04:32:48 +00:00
|
|
|
#include <stdlib.h>
|
1996-08-19 20:36:34 +00:00
|
|
|
|
2017-02-12 07:04:44 +00:00
|
|
|
#ifndef _WIN32
|
1996-08-19 20:36:34 +00:00
|
|
|
#if __STDC__
|
|
|
|
struct mbuf;
|
|
|
|
struct rtentry;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
Update libpcap to 1.1.1.
Changes:
Thu. April 1, 2010. guy@alum.mit.edu.
Summary for 1.1.1 libpcap release
Update CHANGES to reflect more of the changes in 1.1.0.
Fix build on RHEL5.
Fix shared library build on AIX.
Thu. March 11, 2010. ken@netfunctional.ca/guy@alum.mit.edu.
Summary for 1.1.0 libpcap release
Add SocketCAN capture support
Add Myricom SNF API support
Update Endace DAG and ERF support
Add support for shared libraries on Solaris, HP-UX, and AIX
Build, install, and un-install shared libraries by default;
don't build/install shared libraries on platforms we don't support
Fix building from a directory other than the source directory
Fix compiler warnings and builds on some platforms
Update config.guess and config.sub
Support monitor mode on mac80211 devices on Linux
Fix USB memory-mapped capturing on Linux; it requires a new DLT_
value
On Linux, scan /sys/class/net for devices if we have it; scan
it, or /proc/net/dev if we don't have /sys/class/net, even if
we have getifaddrs(), as it'll find interfaces with no
addresses
Add limited support for reading pcap-ng files
Fix BPF driver-loading error handling on AIX
Support getting the full-length interface description on FreeBSD
In the lexical analyzer, free up any addrinfo structure we got back
from getaddrinfo().
Add support for BPF and libdlpi in OpenSolaris (and SXCE)
Hyphenate "link-layer" everywhere
Add /sys/kernel/debug/usb/usbmon to the list of usbmon locations
In pcap_read_linux_mmap(), if there are no frames available, call
poll() even if we're in non-blocking mode, so we pick up
errors, and check for the errors in question.
Note that poll() works on BPF devices is Snow Leopard
If an ENXIO or ENETDOWN is received, it may mean the device has
gone away. Deal with it.
For BPF, raise the default capture buffer size to from 32k to 512k
Support ps_ifdrop on Linux
Added a bunch of #ifdef directives to make wpcap.dll (WinPcap) compile
under cygwin.
Changes to Linux mmapped captures.
Fix bug where create_ring would fail for particular snaplen and
buffer size combinations
Update pcap-config so that it handles libpcap requiring
additional libraries
Add workaround for threadsafeness on Windows
Add missing mapping for DLT_ENC <-> LINKTYPE_ENC
DLT: Add DLT_CAN_SOCKETCAN
DLT: Add Solaris ipnet
Don't check for DLT_IPNET if it's not defined
Add link-layer types for Fibre Channel FC-2
Add link-layer types for Wireless HART
Add link-layer types for AOS
Add link-layer types for DECT
Autoconf fixes (AIX, HP-UX, OSF/1, Tru64 cleanups)
Install headers unconditionally, and include vlan.h/bluetooth.h if
enabled
Autoconf fixes+cleanup
Support enabling/disabling bluetooth (--{en,dis}able-bluetooth)
Support disabling SITA support (--without-sita)
Return -1 on failure to create packet ring (if supported but
creation failed)
Fix handling of 'any' device, so that it can be opened, and no longer
attempt to open it in Monitor mode
Add support for snapshot length for USB Memory-Mapped Interface
Fix configure and build on recent Linux kernels
Fix memory-mapped Linux capture to support pcap_next() and
pcap_next_ex()
Fixes for Linux USB capture
DLT: Add DLT_LINUX_EVDEV
DLT: Add DLT_GSMTAP_UM
DLT: Add DLT_GSMTAP_ABIS
2010-10-28 16:22:13 +00:00
|
|
|
#include <arpa/inet.h>
|
2017-02-12 07:04:44 +00:00
|
|
|
#endif /* _WIN32 */
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "pcap-int.h"
|
|
|
|
|
|
|
|
#include "gencode.h"
|
2017-02-12 07:04:44 +00:00
|
|
|
#include "grammar.h"
|
|
|
|
#include "scanner.h"
|
|
|
|
|
2007-10-16 02:07:55 +00:00
|
|
|
#ifdef HAVE_NET_PFVAR_H
|
|
|
|
#include <net/if.h>
|
2013-10-27 16:25:57 +00:00
|
|
|
#include <netpfil/pf/pf.h>
|
2007-10-16 02:07:55 +00:00
|
|
|
#include <net/if_pflog.h>
|
|
|
|
#endif
|
2015-01-06 18:58:31 +00:00
|
|
|
#include "llc.h"
|
2009-03-21 20:43:56 +00:00
|
|
|
#include "ieee80211.h"
|
|
|
|
#include <pcap/namedb.h>
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OS_PROTO_H
|
|
|
|
#include "os-proto.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define QSET(q, p, d, a) (q).proto = (p),\
|
|
|
|
(q).dir = (d),\
|
|
|
|
(q).addr = (a)
|
|
|
|
|
2009-03-21 20:43:56 +00:00
|
|
|
struct tok {
|
|
|
|
int v; /* value */
|
|
|
|
const char *s; /* string */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tok ieee80211_types[] = {
|
|
|
|
{ IEEE80211_FC0_TYPE_DATA, "data" },
|
|
|
|
{ IEEE80211_FC0_TYPE_MGT, "mgt" },
|
|
|
|
{ IEEE80211_FC0_TYPE_MGT, "management" },
|
|
|
|
{ IEEE80211_FC0_TYPE_CTL, "ctl" },
|
|
|
|
{ IEEE80211_FC0_TYPE_CTL, "control" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
static const struct tok ieee80211_mgt_subtypes[] = {
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_BEACON, "beacon" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ATIM, "atim" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_AUTH, "auth" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_AUTH, "authentication" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
static const struct tok ieee80211_ctl_subtypes[] = {
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_RTS, "rts" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CTS, "cts" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_ACK, "ack" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
static const struct tok ieee80211_data_subtypes[] = {
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_DATA, "data" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_NODATA, "null" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" },
|
|
|
|
{ IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2015-01-06 18:58:31 +00:00
|
|
|
static const struct tok llc_s_subtypes[] = {
|
|
|
|
{ LLC_RR, "rr" },
|
|
|
|
{ LLC_RNR, "rnr" },
|
|
|
|
{ LLC_REJ, "rej" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
static const struct tok llc_u_subtypes[] = {
|
|
|
|
{ LLC_UI, "ui" },
|
|
|
|
{ LLC_UA, "ua" },
|
|
|
|
{ LLC_DISC, "disc" },
|
|
|
|
{ LLC_DM, "dm" },
|
|
|
|
{ LLC_SABME, "sabme" },
|
|
|
|
{ LLC_TEST, "test" },
|
|
|
|
{ LLC_XID, "xid" },
|
|
|
|
{ LLC_FRMR, "frmr" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2009-03-21 20:43:56 +00:00
|
|
|
struct type2tok {
|
|
|
|
int type;
|
|
|
|
const struct tok *tok;
|
|
|
|
};
|
|
|
|
static const struct type2tok ieee80211_type_subtypes[] = {
|
|
|
|
{ IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes },
|
|
|
|
{ IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes },
|
|
|
|
{ IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
str2tok(const char *str, const struct tok *toks)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; toks[i].s != NULL; i++) {
|
|
|
|
if (pcap_strcasecmp(toks[i].s, str) == 0)
|
|
|
|
return (toks[i].v);
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
|
|
|
|
|
|
|
|
static void
|
2017-02-12 07:04:44 +00:00
|
|
|
yyerror(void *yyscanner, compiler_state_t *cstate, const char *msg)
|
1996-08-19 20:36:34 +00:00
|
|
|
{
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_syntax_error(cstate, msg);
|
1996-08-19 20:36:34 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:07:55 +00:00
|
|
|
#ifdef HAVE_NET_PFVAR_H
|
|
|
|
static int
|
2017-02-12 07:04:44 +00:00
|
|
|
pfreason_to_num(compiler_state_t *cstate, const char *reason)
|
2007-10-16 02:07:55 +00:00
|
|
|
{
|
|
|
|
const char *reasons[] = PFRES_NAMES;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; reasons[i]; i++) {
|
|
|
|
if (pcap_strcasecmp(reason, reasons[i]) == 0)
|
|
|
|
return (i);
|
|
|
|
}
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown PF reason");
|
2007-10-16 02:07:55 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-12 07:04:44 +00:00
|
|
|
pfaction_to_num(compiler_state_t *cstate, const char *action)
|
2007-10-16 02:07:55 +00:00
|
|
|
{
|
|
|
|
if (pcap_strcasecmp(action, "pass") == 0 ||
|
|
|
|
pcap_strcasecmp(action, "accept") == 0)
|
|
|
|
return (PF_PASS);
|
|
|
|
else if (pcap_strcasecmp(action, "drop") == 0 ||
|
|
|
|
pcap_strcasecmp(action, "block") == 0)
|
|
|
|
return (PF_DROP);
|
2009-03-21 20:43:56 +00:00
|
|
|
#if HAVE_PF_NAT_THROUGH_PF_NORDR
|
|
|
|
else if (pcap_strcasecmp(action, "rdr") == 0)
|
|
|
|
return (PF_RDR);
|
|
|
|
else if (pcap_strcasecmp(action, "nat") == 0)
|
|
|
|
return (PF_NAT);
|
|
|
|
else if (pcap_strcasecmp(action, "binat") == 0)
|
|
|
|
return (PF_BINAT);
|
|
|
|
else if (pcap_strcasecmp(action, "nordr") == 0)
|
|
|
|
return (PF_NORDR);
|
|
|
|
#endif
|
2007-10-16 02:07:55 +00:00
|
|
|
else {
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown PF action");
|
2007-10-16 02:07:55 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* !HAVE_NET_PFVAR_H */
|
|
|
|
static int
|
2017-02-12 07:04:44 +00:00
|
|
|
pfreason_to_num(compiler_state_t *cstate, const char *reason)
|
2007-10-16 02:07:55 +00:00
|
|
|
{
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "libpcap was compiled on a machine without pf support");
|
2007-10-16 02:07:55 +00:00
|
|
|
/*NOTREACHED*/
|
2009-03-21 20:43:56 +00:00
|
|
|
|
|
|
|
/* this is to make the VC compiler happy */
|
|
|
|
return -1;
|
2007-10-16 02:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-12 07:04:44 +00:00
|
|
|
pfaction_to_num(compiler_state_t *cstate, const char *action)
|
2007-10-16 02:07:55 +00:00
|
|
|
{
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "libpcap was compiled on a machine without pf support");
|
2007-10-16 02:07:55 +00:00
|
|
|
/*NOTREACHED*/
|
2009-03-21 20:43:56 +00:00
|
|
|
|
|
|
|
/* this is to make the VC compiler happy */
|
|
|
|
return -1;
|
2007-10-16 02:07:55 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_NET_PFVAR_H */
|
1996-08-19 20:36:34 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
int i;
|
|
|
|
bpf_u_int32 h;
|
|
|
|
u_char *e;
|
|
|
|
char *s;
|
|
|
|
struct stmt *stmt;
|
|
|
|
struct arth *a;
|
|
|
|
struct {
|
|
|
|
struct qual q;
|
2004-03-31 09:15:09 +00:00
|
|
|
int atmfieldtype;
|
2005-07-11 03:43:25 +00:00
|
|
|
int mtp3fieldtype;
|
1996-08-19 20:36:34 +00:00
|
|
|
struct block *b;
|
|
|
|
} blk;
|
|
|
|
struct block *rblk;
|
|
|
|
}
|
|
|
|
|
|
|
|
%type <blk> expr id nid pid term rterm qid
|
|
|
|
%type <blk> head
|
|
|
|
%type <i> pqual dqual aqual ndaqual
|
|
|
|
%type <a> arth narth
|
|
|
|
%type <i> byteop pname pnum relop irelop
|
|
|
|
%type <blk> and or paren not null prog
|
2015-01-06 18:58:31 +00:00
|
|
|
%type <rblk> other pfvar p80211 pllc
|
2004-03-31 09:15:09 +00:00
|
|
|
%type <i> atmtype atmmultitype
|
|
|
|
%type <blk> atmfield
|
|
|
|
%type <blk> atmfieldvalue atmvalue atmlistvalue
|
2007-10-16 02:07:55 +00:00
|
|
|
%type <i> mtp2type
|
|
|
|
%type <blk> mtp3field
|
|
|
|
%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
|
2005-07-11 03:43:25 +00:00
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
%token DST SRC HOST GATEWAY
|
2005-07-11 03:43:25 +00:00
|
|
|
%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
|
2012-01-31 17:22:07 +00:00
|
|
|
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
|
2001-04-03 04:32:48 +00:00
|
|
|
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
|
1996-08-19 20:36:34 +00:00
|
|
|
%token TK_BROADCAST TK_MULTICAST
|
|
|
|
%token NUM INBOUND OUTBOUND
|
2004-03-31 09:15:09 +00:00
|
|
|
%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
|
2012-01-31 17:22:07 +00:00
|
|
|
%token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
|
1996-08-19 20:36:34 +00:00
|
|
|
%token LINK
|
|
|
|
%token GEQ LEQ NEQ
|
2002-06-21 01:38:14 +00:00
|
|
|
%token ID EID HID HID6 AID
|
1996-08-19 20:36:34 +00:00
|
|
|
%token LSH RSH
|
|
|
|
%token LEN
|
2000-01-30 00:43:38 +00:00
|
|
|
%token IPV6 ICMPV6 AH ESP
|
2005-05-29 18:09:04 +00:00
|
|
|
%token VLAN MPLS
|
2017-02-12 07:04:44 +00:00
|
|
|
%token PPPOED PPPOES GENEVE
|
|
|
|
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
|
2002-06-21 01:38:14 +00:00
|
|
|
%token STP
|
|
|
|
%token IPX
|
|
|
|
%token NETBEUI
|
2004-03-31 09:15:09 +00:00
|
|
|
%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
|
|
|
|
%token OAM OAMF4 CONNECTMSG METACONNECT
|
|
|
|
%token VPI VCI
|
2005-07-11 03:43:25 +00:00
|
|
|
%token RADIO
|
2015-01-06 18:58:31 +00:00
|
|
|
%token FISU LSSU MSU HFISU HLSSU HMSU
|
|
|
|
%token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
|
2017-02-12 07:04:44 +00:00
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
%type <s> ID
|
|
|
|
%type <e> EID
|
2002-06-21 01:38:14 +00:00
|
|
|
%type <e> AID
|
2000-01-30 00:43:38 +00:00
|
|
|
%type <s> HID HID6
|
2009-03-21 20:43:56 +00:00
|
|
|
%type <i> NUM action reason type subtype type_subtype dir
|
1996-08-19 20:36:34 +00:00
|
|
|
|
|
|
|
%left OR AND
|
|
|
|
%nonassoc '!'
|
|
|
|
%left '|'
|
|
|
|
%left '&'
|
|
|
|
%left LSH RSH
|
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/'
|
|
|
|
%nonassoc UMINUS
|
|
|
|
%%
|
|
|
|
prog: null expr
|
|
|
|
{
|
2017-02-12 07:04:44 +00:00
|
|
|
finish_parse(cstate, $2.b);
|
1996-08-19 20:36:34 +00:00
|
|
|
}
|
|
|
|
| null
|
|
|
|
;
|
|
|
|
null: /* null */ { $$.q = qerr; }
|
|
|
|
;
|
|
|
|
expr: term
|
|
|
|
| expr and term { gen_and($1.b, $3.b); $$ = $3; }
|
|
|
|
| expr and id { gen_and($1.b, $3.b); $$ = $3; }
|
|
|
|
| expr or term { gen_or($1.b, $3.b); $$ = $3; }
|
|
|
|
| expr or id { gen_or($1.b, $3.b); $$ = $3; }
|
|
|
|
;
|
|
|
|
and: AND { $$ = $<blk>0; }
|
|
|
|
;
|
|
|
|
or: OR { $$ = $<blk>0; }
|
|
|
|
;
|
|
|
|
id: nid
|
2017-02-12 07:04:44 +00:00
|
|
|
| pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = $<blk>0.q); }
|
|
|
|
| paren pid ')' { $$ = $2; }
|
|
|
|
;
|
2017-02-12 07:04:44 +00:00
|
|
|
nid: ID { $$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q); }
|
|
|
|
| HID '/' NUM { $$.b = gen_mcode(cstate, $1, NULL, $3,
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = $<blk>0.q); }
|
2017-02-12 07:04:44 +00:00
|
|
|
| HID NETMASK HID { $$.b = gen_mcode(cstate, $1, $3, 0,
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = $<blk>0.q); }
|
|
|
|
| HID {
|
|
|
|
/* Decide how to parse HID based on proto */
|
|
|
|
$$.q = $<blk>0.q;
|
2009-03-21 20:43:56 +00:00
|
|
|
if ($$.q.addr == Q_PORT)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'port' modifier applied to ip host");
|
2009-03-21 20:43:56 +00:00
|
|
|
else if ($$.q.addr == Q_PORTRANGE)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'portrange' modifier applied to ip host");
|
2009-03-21 20:43:56 +00:00
|
|
|
else if ($$.q.addr == Q_PROTO)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'proto' modifier applied to ip host");
|
2009-03-21 20:43:56 +00:00
|
|
|
else if ($$.q.addr == Q_PROTOCHAIN)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'protochain' modifier applied to ip host");
|
|
|
|
$$.b = gen_ncode(cstate, $1, 0, $$.q);
|
1996-08-19 20:36:34 +00:00
|
|
|
}
|
2000-01-30 00:43:38 +00:00
|
|
|
| HID6 '/' NUM {
|
|
|
|
#ifdef INET6
|
2017-02-12 07:04:44 +00:00
|
|
|
$$.b = gen_mcode6(cstate, $1, NULL, $3,
|
2000-01-30 00:43:38 +00:00
|
|
|
$$.q = $<blk>0.q);
|
|
|
|
#else
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'ip6addr/prefixlen' not supported "
|
2000-01-30 00:43:38 +00:00
|
|
|
"in this configuration");
|
|
|
|
#endif /*INET6*/
|
|
|
|
}
|
|
|
|
| HID6 {
|
|
|
|
#ifdef INET6
|
2017-02-12 07:04:44 +00:00
|
|
|
$$.b = gen_mcode6(cstate, $1, 0, 128,
|
2000-01-30 00:43:38 +00:00
|
|
|
$$.q = $<blk>0.q);
|
|
|
|
#else
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "'ip6addr' not supported "
|
2000-01-30 00:43:38 +00:00
|
|
|
"in this configuration");
|
|
|
|
#endif /*INET6*/
|
|
|
|
}
|
2017-02-12 07:04:44 +00:00
|
|
|
| EID {
|
|
|
|
$$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q);
|
2002-06-21 01:38:14 +00:00
|
|
|
/*
|
|
|
|
* $1 was allocated by "pcap_ether_aton()",
|
|
|
|
* so we must free it now that we're done
|
|
|
|
* with it.
|
|
|
|
*/
|
|
|
|
free($1);
|
|
|
|
}
|
|
|
|
| AID {
|
2017-02-12 07:04:44 +00:00
|
|
|
$$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q);
|
2002-06-21 01:38:14 +00:00
|
|
|
/*
|
|
|
|
* $1 was allocated by "pcap_ether_aton()",
|
|
|
|
* so we must free it now that we're done
|
|
|
|
* with it.
|
|
|
|
*/
|
|
|
|
free($1);
|
|
|
|
}
|
1996-08-19 20:36:34 +00:00
|
|
|
| not id { gen_not($2.b); $$ = $2; }
|
|
|
|
;
|
|
|
|
not: '!' { $$ = $<blk>0; }
|
|
|
|
;
|
|
|
|
paren: '(' { $$ = $<blk>0; }
|
|
|
|
;
|
|
|
|
pid: nid
|
|
|
|
| qid and id { gen_and($1.b, $3.b); $$ = $3; }
|
|
|
|
| qid or id { gen_or($1.b, $3.b); $$ = $3; }
|
|
|
|
;
|
2017-02-12 07:04:44 +00:00
|
|
|
qid: pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1,
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = $<blk>0.q); }
|
|
|
|
| pid
|
|
|
|
;
|
|
|
|
term: rterm
|
|
|
|
| not term { gen_not($2.b); $$ = $2; }
|
|
|
|
;
|
|
|
|
head: pqual dqual aqual { QSET($$.q, $1, $2, $3); }
|
|
|
|
| pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); }
|
|
|
|
| pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); }
|
|
|
|
| pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); }
|
2000-01-30 00:43:38 +00:00
|
|
|
| pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); }
|
1996-08-19 20:36:34 +00:00
|
|
|
| pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
|
|
|
|
;
|
|
|
|
rterm: head id { $$ = $2; }
|
|
|
|
| paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| pname { $$.b = gen_proto_abbrev(cstate, $1); $$.q = qerr; }
|
|
|
|
| arth relop arth { $$.b = gen_relation(cstate, $2, $1, $3, 0);
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = qerr; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| arth irelop arth { $$.b = gen_relation(cstate, $2, $1, $3, 1);
|
1996-08-19 20:36:34 +00:00
|
|
|
$$.q = qerr; }
|
|
|
|
| other { $$.b = $1; $$.q = qerr; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| atmtype { $$.b = gen_atmtype_abbrev(cstate, $1); $$.q = qerr; }
|
|
|
|
| atmmultitype { $$.b = gen_atmmulti_abbrev(cstate, $1); $$.q = qerr; }
|
2004-03-31 09:15:09 +00:00
|
|
|
| atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| mtp2type { $$.b = gen_mtp2type_abbrev(cstate, $1); $$.q = qerr; }
|
2005-07-11 03:43:25 +00:00
|
|
|
| mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
|
|
|
/* protocol level qualifiers */
|
|
|
|
pqual: pname
|
|
|
|
| { $$ = Q_DEFAULT; }
|
|
|
|
;
|
|
|
|
/* 'direction' qualifiers */
|
|
|
|
dqual: SRC { $$ = Q_SRC; }
|
|
|
|
| DST { $$ = Q_DST; }
|
|
|
|
| SRC OR DST { $$ = Q_OR; }
|
|
|
|
| DST OR SRC { $$ = Q_OR; }
|
|
|
|
| SRC AND DST { $$ = Q_AND; }
|
|
|
|
| DST AND SRC { $$ = Q_AND; }
|
2009-03-21 20:43:56 +00:00
|
|
|
| ADDR1 { $$ = Q_ADDR1; }
|
|
|
|
| ADDR2 { $$ = Q_ADDR2; }
|
|
|
|
| ADDR3 { $$ = Q_ADDR3; }
|
|
|
|
| ADDR4 { $$ = Q_ADDR4; }
|
2012-01-31 17:22:07 +00:00
|
|
|
| RA { $$ = Q_RA; }
|
|
|
|
| TA { $$ = Q_TA; }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
|
|
|
/* address type qualifiers */
|
|
|
|
aqual: HOST { $$ = Q_HOST; }
|
|
|
|
| NET { $$ = Q_NET; }
|
|
|
|
| PORT { $$ = Q_PORT; }
|
2005-07-11 03:43:25 +00:00
|
|
|
| PORTRANGE { $$ = Q_PORTRANGE; }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
|
|
|
/* non-directional address type qualifiers */
|
|
|
|
ndaqual: GATEWAY { $$ = Q_GATEWAY; }
|
|
|
|
;
|
|
|
|
pname: LINK { $$ = Q_LINK; }
|
|
|
|
| IP { $$ = Q_IP; }
|
|
|
|
| ARP { $$ = Q_ARP; }
|
|
|
|
| RARP { $$ = Q_RARP; }
|
2002-06-21 01:38:14 +00:00
|
|
|
| SCTP { $$ = Q_SCTP; }
|
1996-08-19 20:36:34 +00:00
|
|
|
| TCP { $$ = Q_TCP; }
|
|
|
|
| UDP { $$ = Q_UDP; }
|
|
|
|
| ICMP { $$ = Q_ICMP; }
|
|
|
|
| IGMP { $$ = Q_IGMP; }
|
|
|
|
| IGRP { $$ = Q_IGRP; }
|
2000-01-30 00:43:38 +00:00
|
|
|
| PIM { $$ = Q_PIM; }
|
2002-06-21 01:38:14 +00:00
|
|
|
| VRRP { $$ = Q_VRRP; }
|
2012-01-31 17:22:07 +00:00
|
|
|
| CARP { $$ = Q_CARP; }
|
1996-08-19 20:36:34 +00:00
|
|
|
| ATALK { $$ = Q_ATALK; }
|
2001-04-03 04:32:48 +00:00
|
|
|
| AARP { $$ = Q_AARP; }
|
1996-08-19 20:36:34 +00:00
|
|
|
| DECNET { $$ = Q_DECNET; }
|
|
|
|
| LAT { $$ = Q_LAT; }
|
|
|
|
| SCA { $$ = Q_SCA; }
|
|
|
|
| MOPDL { $$ = Q_MOPDL; }
|
|
|
|
| MOPRC { $$ = Q_MOPRC; }
|
2000-01-30 00:43:38 +00:00
|
|
|
| IPV6 { $$ = Q_IPV6; }
|
|
|
|
| ICMPV6 { $$ = Q_ICMPV6; }
|
|
|
|
| AH { $$ = Q_AH; }
|
|
|
|
| ESP { $$ = Q_ESP; }
|
1996-08-21 20:01:08 +00:00
|
|
|
| ISO { $$ = Q_ISO; }
|
|
|
|
| ESIS { $$ = Q_ESIS; }
|
|
|
|
| ISIS { $$ = Q_ISIS; }
|
2004-03-31 09:15:09 +00:00
|
|
|
| L1 { $$ = Q_ISIS_L1; }
|
|
|
|
| L2 { $$ = Q_ISIS_L2; }
|
|
|
|
| IIH { $$ = Q_ISIS_IIH; }
|
|
|
|
| LSP { $$ = Q_ISIS_LSP; }
|
|
|
|
| SNP { $$ = Q_ISIS_SNP; }
|
|
|
|
| PSNP { $$ = Q_ISIS_PSNP; }
|
|
|
|
| CSNP { $$ = Q_ISIS_CSNP; }
|
2001-04-03 04:32:48 +00:00
|
|
|
| CLNP { $$ = Q_CLNP; }
|
2002-06-21 01:38:14 +00:00
|
|
|
| STP { $$ = Q_STP; }
|
|
|
|
| IPX { $$ = Q_IPX; }
|
|
|
|
| NETBEUI { $$ = Q_NETBEUI; }
|
2005-07-11 03:43:25 +00:00
|
|
|
| RADIO { $$ = Q_RADIO; }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
2017-02-12 07:04:44 +00:00
|
|
|
other: pqual TK_BROADCAST { $$ = gen_broadcast(cstate, $1); }
|
|
|
|
| pqual TK_MULTICAST { $$ = gen_multicast(cstate, $1); }
|
|
|
|
| LESS NUM { $$ = gen_less(cstate, $2); }
|
|
|
|
| GREATER NUM { $$ = gen_greater(cstate, $2); }
|
|
|
|
| CBYTE NUM byteop NUM { $$ = gen_byteop(cstate, $3, $2, $4); }
|
|
|
|
| INBOUND { $$ = gen_inbound(cstate, 0); }
|
|
|
|
| OUTBOUND { $$ = gen_inbound(cstate, 1); }
|
|
|
|
| VLAN pnum { $$ = gen_vlan(cstate, $2); }
|
|
|
|
| VLAN { $$ = gen_vlan(cstate, -1); }
|
|
|
|
| MPLS pnum { $$ = gen_mpls(cstate, $2); }
|
|
|
|
| MPLS { $$ = gen_mpls(cstate, -1); }
|
|
|
|
| PPPOED { $$ = gen_pppoed(cstate); }
|
|
|
|
| PPPOES pnum { $$ = gen_pppoes(cstate, $2); }
|
|
|
|
| PPPOES { $$ = gen_pppoes(cstate, -1); }
|
|
|
|
| GENEVE pnum { $$ = gen_geneve(cstate, $2); }
|
|
|
|
| GENEVE { $$ = gen_geneve(cstate, -1); }
|
2004-03-31 09:15:09 +00:00
|
|
|
| pfvar { $$ = $1; }
|
2009-03-21 20:43:56 +00:00
|
|
|
| pqual p80211 { $$ = $2; }
|
2015-01-06 18:58:31 +00:00
|
|
|
| pllc { $$ = $1; }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
2004-03-31 09:15:09 +00:00
|
|
|
|
2017-02-12 07:04:44 +00:00
|
|
|
pfvar: PF_IFNAME ID { $$ = gen_pf_ifname(cstate, $2); }
|
|
|
|
| PF_RSET ID { $$ = gen_pf_ruleset(cstate, $2); }
|
|
|
|
| PF_RNR NUM { $$ = gen_pf_rnr(cstate, $2); }
|
|
|
|
| PF_SRNR NUM { $$ = gen_pf_srnr(cstate, $2); }
|
|
|
|
| PF_REASON reason { $$ = gen_pf_reason(cstate, $2); }
|
|
|
|
| PF_ACTION action { $$ = gen_pf_action(cstate, $2); }
|
2004-03-31 09:15:09 +00:00
|
|
|
;
|
|
|
|
|
2009-03-21 20:43:56 +00:00
|
|
|
p80211: TYPE type SUBTYPE subtype
|
2017-02-12 07:04:44 +00:00
|
|
|
{ $$ = gen_p80211_type(cstate, $2 | $4,
|
2009-03-21 20:43:56 +00:00
|
|
|
IEEE80211_FC0_TYPE_MASK |
|
|
|
|
IEEE80211_FC0_SUBTYPE_MASK);
|
|
|
|
}
|
2017-02-12 07:04:44 +00:00
|
|
|
| TYPE type { $$ = gen_p80211_type(cstate, $2,
|
2009-03-21 20:43:56 +00:00
|
|
|
IEEE80211_FC0_TYPE_MASK);
|
|
|
|
}
|
2017-02-12 07:04:44 +00:00
|
|
|
| SUBTYPE type_subtype { $$ = gen_p80211_type(cstate, $2,
|
2009-03-21 20:43:56 +00:00
|
|
|
IEEE80211_FC0_TYPE_MASK |
|
|
|
|
IEEE80211_FC0_SUBTYPE_MASK);
|
|
|
|
}
|
2017-02-12 07:04:44 +00:00
|
|
|
| DIR dir { $$ = gen_p80211_fcdir(cstate, $2); }
|
2009-03-21 20:43:56 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type: NUM
|
|
|
|
| ID { $$ = str2tok($1, ieee80211_types);
|
|
|
|
if ($$ == -1)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown 802.11 type name");
|
2009-03-21 20:43:56 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
subtype: NUM
|
|
|
|
| ID { const struct tok *types = NULL;
|
|
|
|
int i;
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if (ieee80211_type_subtypes[i].tok == NULL) {
|
|
|
|
/* Ran out of types */
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown 802.11 type");
|
2009-03-21 20:43:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($<i>-1 == ieee80211_type_subtypes[i].type) {
|
|
|
|
types = ieee80211_type_subtypes[i].tok;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = str2tok($1, types);
|
|
|
|
if ($$ == -1)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown 802.11 subtype name");
|
2009-03-21 20:43:56 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
type_subtype: ID { int i;
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if (ieee80211_type_subtypes[i].tok == NULL) {
|
|
|
|
/* Ran out of types */
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown 802.11 type name");
|
2009-03-21 20:43:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$$ = str2tok($1, ieee80211_type_subtypes[i].tok);
|
|
|
|
if ($$ != -1) {
|
|
|
|
$$ |= ieee80211_type_subtypes[i].type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2017-02-12 07:04:44 +00:00
|
|
|
pllc: LLC { $$ = gen_llc(cstate); }
|
2015-01-06 18:58:31 +00:00
|
|
|
| LLC ID { if (pcap_strcasecmp($2, "i") == 0)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$ = gen_llc_i(cstate);
|
2015-01-06 18:58:31 +00:00
|
|
|
else if (pcap_strcasecmp($2, "s") == 0)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$ = gen_llc_s(cstate);
|
2015-01-06 18:58:31 +00:00
|
|
|
else if (pcap_strcasecmp($2, "u") == 0)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$ = gen_llc_u(cstate);
|
2015-01-06 18:58:31 +00:00
|
|
|
else {
|
2017-02-12 07:04:44 +00:00
|
|
|
int subtype;
|
2015-01-06 18:58:31 +00:00
|
|
|
|
|
|
|
subtype = str2tok($2, llc_s_subtypes);
|
|
|
|
if (subtype != -1)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$ = gen_llc_s_subtype(cstate, subtype);
|
2015-01-06 18:58:31 +00:00
|
|
|
else {
|
|
|
|
subtype = str2tok($2, llc_u_subtypes);
|
|
|
|
if (subtype == -1)
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown LLC type name \"%s\"", $2);
|
|
|
|
$$ = gen_llc_u_subtype(cstate, subtype);
|
2015-01-06 18:58:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* sigh, "rnr" is already a keyword for PF */
|
2017-02-12 07:04:44 +00:00
|
|
|
| LLC PF_RNR { $$ = gen_llc_s_subtype(cstate, LLC_RNR); }
|
2015-01-06 18:58:31 +00:00
|
|
|
;
|
|
|
|
|
2009-03-21 20:43:56 +00:00
|
|
|
dir: NUM
|
|
|
|
| ID { if (pcap_strcasecmp($1, "nods") == 0)
|
|
|
|
$$ = IEEE80211_FC1_DIR_NODS;
|
|
|
|
else if (pcap_strcasecmp($1, "tods") == 0)
|
|
|
|
$$ = IEEE80211_FC1_DIR_TODS;
|
|
|
|
else if (pcap_strcasecmp($1, "fromds") == 0)
|
|
|
|
$$ = IEEE80211_FC1_DIR_FROMDS;
|
|
|
|
else if (pcap_strcasecmp($1, "dstods") == 0)
|
|
|
|
$$ = IEEE80211_FC1_DIR_DSTODS;
|
|
|
|
else
|
2017-02-12 07:04:44 +00:00
|
|
|
bpf_error(cstate, "unknown 802.11 direction");
|
2009-03-21 20:43:56 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-03-31 09:15:09 +00:00
|
|
|
reason: NUM { $$ = $1; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| ID { $$ = pfreason_to_num(cstate, $1); }
|
2004-03-31 09:15:09 +00:00
|
|
|
;
|
|
|
|
|
2017-02-12 07:04:44 +00:00
|
|
|
action: ID { $$ = pfaction_to_num(cstate, $1); }
|
2004-03-31 09:15:09 +00:00
|
|
|
;
|
|
|
|
|
1996-08-19 20:36:34 +00:00
|
|
|
relop: '>' { $$ = BPF_JGT; }
|
|
|
|
| GEQ { $$ = BPF_JGE; }
|
|
|
|
| '=' { $$ = BPF_JEQ; }
|
|
|
|
;
|
|
|
|
irelop: LEQ { $$ = BPF_JGT; }
|
|
|
|
| '<' { $$ = BPF_JGE; }
|
|
|
|
| NEQ { $$ = BPF_JEQ; }
|
|
|
|
;
|
2017-02-12 07:04:44 +00:00
|
|
|
arth: pnum { $$ = gen_loadi(cstate, $1); }
|
1996-08-19 20:36:34 +00:00
|
|
|
| narth
|
|
|
|
;
|
2017-02-12 07:04:44 +00:00
|
|
|
narth: pname '[' arth ']' { $$ = gen_load(cstate, $1, $3, 1); }
|
|
|
|
| pname '[' arth ':' NUM ']' { $$ = gen_load(cstate, $1, $3, $5); }
|
|
|
|
| arth '+' arth { $$ = gen_arth(cstate, BPF_ADD, $1, $3); }
|
|
|
|
| arth '-' arth { $$ = gen_arth(cstate, BPF_SUB, $1, $3); }
|
|
|
|
| arth '*' arth { $$ = gen_arth(cstate, BPF_MUL, $1, $3); }
|
|
|
|
| arth '/' arth { $$ = gen_arth(cstate, BPF_DIV, $1, $3); }
|
|
|
|
| arth '%' arth { $$ = gen_arth(cstate, BPF_MOD, $1, $3); }
|
|
|
|
| arth '&' arth { $$ = gen_arth(cstate, BPF_AND, $1, $3); }
|
|
|
|
| arth '|' arth { $$ = gen_arth(cstate, BPF_OR, $1, $3); }
|
|
|
|
| arth '^' arth { $$ = gen_arth(cstate, BPF_XOR, $1, $3); }
|
|
|
|
| arth LSH arth { $$ = gen_arth(cstate, BPF_LSH, $1, $3); }
|
|
|
|
| arth RSH arth { $$ = gen_arth(cstate, BPF_RSH, $1, $3); }
|
|
|
|
| '-' arth %prec UMINUS { $$ = gen_neg(cstate, $2); }
|
1996-08-19 20:36:34 +00:00
|
|
|
| paren narth ')' { $$ = $2; }
|
2017-02-12 07:04:44 +00:00
|
|
|
| LEN { $$ = gen_loadlen(cstate); }
|
1996-08-19 20:36:34 +00:00
|
|
|
;
|
|
|
|
byteop: '&' { $$ = '&'; }
|
|
|
|
| '|' { $$ = '|'; }
|
|
|
|
| '<' { $$ = '<'; }
|
|
|
|
| '>' { $$ = '>'; }
|
|
|
|
| '=' { $$ = '='; }
|
|
|
|
;
|
|
|
|
pnum: NUM
|
|
|
|
| paren pnum ')' { $$ = $2; }
|
|
|
|
;
|
2004-03-31 09:15:09 +00:00
|
|
|
atmtype: LANE { $$ = A_LANE; }
|
|
|
|
| METAC { $$ = A_METAC; }
|
|
|
|
| BCC { $$ = A_BCC; }
|
|
|
|
| OAMF4EC { $$ = A_OAMF4EC; }
|
|
|
|
| OAMF4SC { $$ = A_OAMF4SC; }
|
|
|
|
| SC { $$ = A_SC; }
|
|
|
|
| ILMIC { $$ = A_ILMIC; }
|
|
|
|
;
|
|
|
|
atmmultitype: OAM { $$ = A_OAM; }
|
|
|
|
| OAMF4 { $$ = A_OAMF4; }
|
|
|
|
| CONNECTMSG { $$ = A_CONNECTMSG; }
|
|
|
|
| METACONNECT { $$ = A_METACONNECT; }
|
|
|
|
;
|
|
|
|
/* ATM field types quantifier */
|
|
|
|
atmfield: VPI { $$.atmfieldtype = A_VPI; }
|
|
|
|
| VCI { $$.atmfieldtype = A_VCI; }
|
|
|
|
;
|
|
|
|
atmvalue: atmfieldvalue
|
2017-02-12 07:04:44 +00:00
|
|
|
| relop NUM { $$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); }
|
|
|
|
| irelop NUM { $$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); }
|
2004-03-31 09:15:09 +00:00
|
|
|
| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
|
|
|
|
;
|
|
|
|
atmfieldvalue: NUM {
|
|
|
|
$$.atmfieldtype = $<blk>0.atmfieldtype;
|
|
|
|
if ($$.atmfieldtype == A_VPI ||
|
|
|
|
$$.atmfieldtype == A_VCI)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$.b = gen_atmfield_code(cstate, $$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0);
|
2004-03-31 09:15:09 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
atmlistvalue: atmfieldvalue
|
|
|
|
| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
|
|
|
|
;
|
2007-10-16 02:07:55 +00:00
|
|
|
/* MTP2 types quantifier */
|
|
|
|
mtp2type: FISU { $$ = M_FISU; }
|
|
|
|
| LSSU { $$ = M_LSSU; }
|
|
|
|
| MSU { $$ = M_MSU; }
|
2015-01-06 18:58:31 +00:00
|
|
|
| HFISU { $$ = MH_FISU; }
|
|
|
|
| HLSSU { $$ = MH_LSSU; }
|
|
|
|
| HMSU { $$ = MH_MSU; }
|
2007-10-16 02:07:55 +00:00
|
|
|
;
|
2005-07-11 03:43:25 +00:00
|
|
|
/* MTP3 field types quantifier */
|
|
|
|
mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
|
|
|
|
| OPC { $$.mtp3fieldtype = M_OPC; }
|
|
|
|
| DPC { $$.mtp3fieldtype = M_DPC; }
|
|
|
|
| SLS { $$.mtp3fieldtype = M_SLS; }
|
2015-01-06 18:58:31 +00:00
|
|
|
| HSIO { $$.mtp3fieldtype = MH_SIO; }
|
|
|
|
| HOPC { $$.mtp3fieldtype = MH_OPC; }
|
|
|
|
| HDPC { $$.mtp3fieldtype = MH_DPC; }
|
|
|
|
| HSLS { $$.mtp3fieldtype = MH_SLS; }
|
2005-07-11 03:43:25 +00:00
|
|
|
;
|
|
|
|
mtp3value: mtp3fieldvalue
|
2017-02-12 07:04:44 +00:00
|
|
|
| relop NUM { $$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); }
|
|
|
|
| irelop NUM { $$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); }
|
2005-07-11 03:43:25 +00:00
|
|
|
| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
|
|
|
|
;
|
|
|
|
mtp3fieldvalue: NUM {
|
|
|
|
$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
|
|
|
|
if ($$.mtp3fieldtype == M_SIO ||
|
|
|
|
$$.mtp3fieldtype == M_OPC ||
|
|
|
|
$$.mtp3fieldtype == M_DPC ||
|
2015-01-06 18:58:31 +00:00
|
|
|
$$.mtp3fieldtype == M_SLS ||
|
|
|
|
$$.mtp3fieldtype == MH_SIO ||
|
|
|
|
$$.mtp3fieldtype == MH_OPC ||
|
|
|
|
$$.mtp3fieldtype == MH_DPC ||
|
|
|
|
$$.mtp3fieldtype == MH_SLS)
|
2017-02-12 07:04:44 +00:00
|
|
|
$$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0);
|
2005-07-11 03:43:25 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
mtp3listvalue: mtp3fieldvalue
|
|
|
|
| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
|
|
|
|
;
|
1996-08-19 20:36:34 +00:00
|
|
|
%%
|