NetBSD/external/bsd/libpcap/dist/grammar.y.in

872 lines
27 KiB
Plaintext
Raw Normal View History

Import libpcap-1.10.4 (previous was 1.9.1) Friday, April 7, 2023 / The Tcpdump Group Summary for 1.10.4 libpcap release Source code: Fix spaces before tabs in indentation. rpcap: Fix name of launchd service. Documentation: Document use of rpcapd with systemd, launchd, inetd, and xinetd. Building and testing: Require at least pkg-config 0.17.0, as we use --static. Get rid of the remains of gnuc.h. Require at least autoconf 2.69. Update config.{guess,sub}, timestamps 2023-01-01,2023-01-21. Thursday, January 12, 2023 / The Tcpdump Group Summary for 1.10.3 libpcap release Source code: Sort the PUBHDR variable in Makefile.in in "ls" order. Fix typo in comment in pflog.h. Remove two no-longer-present files from .gitignore. Update code and comments for handling failure to set promiscuous mode based on new information. Building and testing: install: Fixed not to install the non-public pcap-util.h header. pcap-config: add a --version flag. Makefile.in: Add some missing files in the distclean target. Saturday, December 31, 2022 / The Tcpdump Group Summary for 1.10.2 libpcap release Source code: Use __builtin_unreachable() in PCAP_UNREACHABLE. Use AS_HELP_STRING macro instead of AC_HELP_STRING in the configure scripts, to avoid deprecation warnings. Change availability tags in pcap.h to make it easier to arrange for it to be used in Darwin releases. Use AS_HELP_STRING for --enable-remote. Fix some formatting string issues found by cppcheck. Various small code and comment cleanups. Use PCAP_ERROR (defined as -1) rather than explicit -1 for functions the documentation says return PCAP_ERROR. Remove unused code from the filter compiler. Use _declspec(deprecated(msg)) rather than __pragma(deprecated) for Windows deprecation warnings, so the message that was specified shows up. diag-control.h: define PCAP_DO_PRAGMA() iff we're going to use it. Use "%d" to print some signed ints. Use the Wayback Machine for a removed document in a comment. Add some const qualifiers. RDMA: Use PRIu64 to print a uint64_t. "Dead" pcap_ts from pcap_open_dead() and ..._with_tstamp_precision(): Don't crash if pcap_breakloop() is called. Savefiles: Fix pcap_dispatch() to return number of packets processed, rather than 0, even at EOF. If we get an error writing the packet header, don't write the packet data. Put PFLOG UID and PID values in the header into host byte order when reading a LINKTYPE_PFLOG file. Put CAN ID field in CAN pseudo-headers for LINUX_SLL2, as we do for LINUX_SLL. Fix inorrectly-computed "real" length for isochronous USB transfers when reading savefiles. Don't crash if pcap_can_set_rfmon() is called. Fix pcap_offline_read() loop. Capture: Never process more than INT_MAX packets in a pcap_dispatch() call, to avoid integer overflow (issue #1087). Improve error messages for "no such device" and "permission denied" errors. SITA: Fix a typo in a variable name. Packet filtering: Get PFLOG header length from the length value in the header. Support all the direction, reason, and action types supported by all systems that support PFLOG. Don't require PFLOG support on the target machine in order to support PFLOG filtering (also fixes issue #1076). Expand abbreviations into "proto X" properly. gencode.c: Update a comment about the VLAN TPID test. Add the minimum and maximum matching DLTs to an error message. Linux: Fix memory leak in capture device open (pull request #1038). Fix detection of CAN/CAN FD packets in direction check (issue #1051). Fix double-free crashes on errors such as running on a kernel with CONFIG_PACKET_MMAP not configured (issue #1054). Use DLT_CAN_SOCKETCAN for CANbus interfaces (issue #1052; includes changes from pull request #1035). Make sure the CANFD_FDF can be relied on to indicate whether a CANbus packet is a CAN frame or a CAN FD frame Improve error message for "out of memory" errors for kernel filters (see issue #1089). Fix pcap_findalldevs() to find usbmon devices. Fix handling of VLAN tagged packets if the link-layer type is changed from DLT_LINUX_SLL to DLT_LINUX_SLL2 (see issue #1105). Always turn on PACKET_AUXDATA (see issue #1105). We require 2.6.27 or later, so PACKET_RESERVE is available. Make sure there's reserved space for a DLT_LINUX_SLL2 header when capturing. Correctly compute the "real" length for isochronous USB transfers. Don't have an eventfd descriptor open in non-blocking mode, so as not to waste descriptors. netfilter: Squelch a narrowing warning (To be look at before 2038). BPF capture (*BSD, macOS, AIX, Solaris 11): Fix case where a device open might fail, rather than falling back to a smaller buffer size, when the initial buffer size is too big. Use an unsigned device number to iterate over BPF devices, to squelch a compiler warning. NetBSD: Fix handling of LINKTYPE_HDLC/DLT_HDLC. rpcap: Fix unaligned accesses in rpcapd (pull request #1037). Fix code to process port number. Clean up findalldevs code in rpcapd. Clean up bufferizing code. Fix a file descriptor/handle leak in pcap_findalldevs_ex() (Coverity CID 1507240). Improve error messages for host and port resolution errors. Fix connect code not to fail if both IPv4 and IPv6 addresses are tried. Improve connect failure error message. Provide an error message for a bad authentication reply size. For link-layer types with host-endian fields in the header, fix those fields if capturing from a server with a different byte order. Suppress temporarily the warnings with "enable remote packet capture". Windows: Add support for NdisMediumIP (pull request #1027). Don't require applications using pcap to be built with VS 2015 or later. Use the correct string for the DLL VersionInfo. Remove unnecessary DllMain() function. Correctly handle ERROR_INVALID_FUNCTION from PacketGetTimestampModes() (indicate that WinPcap or an older version of Npcap is probably installed). Fix use-after-free in some cases when a pcap_t is closed. Make sure an error is returned by pcap_create_interface() if PacketOpenAdapter() fails. Return an error if the driver reports 0 timestamp modes supported. Close the ADAPTER handle for some errors in pcap_create_interface(). Get rid of old umaintained VS project files. Fix deprecation warning for pcap_handle(). Npcap is now at npcap.com, not npcap.org. Make sure "no such device" and "no permission to open device" errors show up in pcap_activate(), not pcap_create() (fixes, among other things, tcpdump -i <interface-number>). npcap: squelch deprecation warnings for kernel dump mode. Haiku: Implement pcap_lib_version(), as now required. Handle negative or too-large snaplen values. Fix various build issues and warnings. Building and testing: Update configure-time universal build checks for macOS. Update config.guess and config.sub. If we look for an SSL library with pkg-config in configure script, try pkg-config first. If we have pkg-config and Homebrew, try to set pkg-config up to find Homebrew packages. Handle some Autoconf/make errors better. Use "git archive" for the "make releasetar" process. Remove the release candidate rcX targets. Fix compiling on Solaris 9/SPARC and 11/AMD64. Address assorted compiler warnings. Fix cross-building on Linux for Windows with mingw32 for Win64 (pull request #1031). Properly set installation directory on Windows when not compiling with MSVC. Fix configure script checks for compiler flags. Give more details if check for usable (F)Lex fails. Fix compiling with GCC 4.6.4. Don't use add_compile_options() with CMake, as we currently don't require 2.8.12, where it first appeared. Don't provide -L/usr/lib for pkg-config --libs in pkg-config. Fix error message for inadequate Bison/Berkeley YACC. configure: correctly do some DPDK checks. Only use pkg-config when checking for DPDK. Allow the path in which DPDK is installed to be specified. Use pkg-config first when checking for libibverbs. CMake: fix check for libibverbs with Sun's C compiler. Have CMake warn if no capture mechanism can be found. Don't do stuff requiring 3.19 or later on earlier CMakes. Squelch some CMake warnings. Fix diag-control.h to handle compiling with clang-cl (issues #1101 and #1115). Cleanup various leftover cruft in the configure script. Fix building without protochain support. (GH #852) Check for a usable YACC (or Bison) and {F}lex in CMake, as we do in autotools. Only check for a C++ compiler on Haiku, as that's the only platform with C++ code, and make sure they generate code for the same instruction set bit-width (both 32-bit or both 64-bit) (issue #1112). On Solaris, check the target bit-width and set PKG_CONFIG_PATH appropriately, to handle the mess that is the D-Bus library package (issue #1112). Fix generation of pcap-config and libpcap.pc files (issue #1062). pcap-config: don't assume the system library directory is /usr/lib. pcap-config: add a --static-pcap-only flag. Cirrus CI: Use the same configuration as for the main branch. Add four libpcap test files. Update Npcap SDK to 1.13. Makefile.in: Use TEST_DIST, like for tcpdump. Remove awk code from mkdep. Cirrus CI: Add the libssl-dev package in the Linux task. Cirrus CI: Add the openssl@3 brew package in the macOS task. Get "make shellcheck" to pass again. CMake: Build valgrindtest only if Autoconf would. CMake: use ${CMAKE_INSTALL_SBINDIR} rather than just sbin. CMake: use NUL: as the null device on Windows. autoconf: fix typo in test of macOS version. Makefile.in: Add two missing files in EXTRA_DIST. autotools, cmake: provide an rpath option if necessary. configure: get rid of the attempt to auto-run PKG_PROG_PKG_CONFIG. configure: use PKG_CHECK_MODULES to run pkg-config. Documentation: Add README.solaris.md. Add SCTP to pcap-filter(7). Note that = and == are the same operator in filters (issue #1044). Update INSTALL.md, README.md, and README.solaris.md. Update and clean up CONTRIBUTING.md. Trim documentation of support for now-dead UN*Xe and older versions of other UN*Xes. Move the "how to allocate a LINKTYPE_/DLT_ value" documentation to the web site. Clean up man pages. Move README.capture-module to the web site. Improve some protocol details in pcap-filter(7). Refine "relop" notes in pcap-filter(7). In pcap-filter(7) "domain" is an id. Discuss backward compatibility in pcap-filter(7). Other improvements to pcap-filter(7). Document pcap_breakloop(3PCAP) interaction with threads better. Document PCAP_ERROR_NOT_ACTIVATED for more routines. Wednesday, June 9, 2021: Summary for 1.10.1 libpcap release: Packet filtering: Fix "type XXX subtype YYY" giving a parse error Source code: Add PCAP_AVAILABLE_1_11. Building and testing: Rename struct bpf_aux_data to avoid NetBSD compile errors Squelch some compiler warnings Squelch some Bison warnings Fix cross-builds with older kernels lacking BPF_MOD and BPF_XOR Fix Bison detection for minor version 0. Fix parallel build with FreeBSD make. Get DLT_MATCHING_MAX right in gencode.c on NetBSD. Define timeradd() and timersub() if necessary. Fix Cygwin/MSYS target directories. Fix symlinking with DESTDIR. Fix generation of libpcap.pc with CMake when not building a shared library. Check for Arm64 as well as x86-64 when looking for packet.lib on Windows. Documentation: Refine Markdown in README.md. Improve the description of portrange in filters. README.linux.md isn't Markdown, rename it just README.linux. pcapng: Support reading version 1.2, which some writers produce, and which is the same as 1.0 (some new block types were added, but that's not sufficient reason to bump the minor version number, as code that understands those new block types can handle them in a 1.0 file) Linux: Drop support for text-mode USB captures, as we require a 2.6.27 or later kernel (credit to Chaoyuan Peng for noting the sscanf vulnerabilities in the text-mode code that got me to realize that we didn't need this code any more) Bluetooth: fix non-blocking mode. Don't assume that all compilers used to build for Linux support the __atomic builtins Windows: Add more information in "interface disappeared" error messages, in the hopes of trying to figure out the cause. Treat ERROR_DEVICE_REMOVED as "device was removed". Indicate in the error message which "device was removed" error occurred. Report the Windows error status if PacketSendPacket() fails. Use %lu for ULONGs in error message formats. Don't treat the inability to find airpcap.dll as an error. Ignore spurious error reports by Microsoft Surface mobile telephony modem driver rpcap: Clean up error checking and error messages for server address lookup. Tuesday, December 29, 2020 Summary for 1.10.0 libpcap release Add support for capturing on DPDK devices Label most APIs by the first release in which they're available Fix some memory leaks, including in pcap_compile() Add pcap_datalink_val_to_description_or_dlt() Handle the pcap private data in a fashion that makes fewer assumptions about memory layouts (might fix GitHub issue #940 on ARM) Fix some thread safety issues pcap_findalldevs(): don't sort interfaces by unit number Always return a list of supported time-stamp types, even if only host time stamps are supported Increase the maximum snaplen for LINKTYPE_USBPCAP/DLT_USBPCAP Report the DLT description in error messages Add pcap_init() for first-time initialization and global option setting; it's not required, but may be used Remove (unused) SITA support Capture file reading: Correctly handle pcapng captures with more than one IDB with a snspshot length greater than the supported maximum Capture file writing: Create the file in pcap_dump_open_append() if it doesn't exist Packet filtering: Fix "unknown ether proto 'aarp'" Add a new filter "ifindex" for DLT_LINUX_SLL2 files on all platforms and live Linux captures Add a hack to the optimizer to try to catch certain optimizer loops (should prevent GitHub issue #112) Show special Linux BPF offsets symbolically in bpf_image() and bpf_dump() Added support for ICMPv6 types 1-4 as tokens with names Remove undocumented and rather old "ether proto" protocols Catch invalid IPv4 addresses in filters Don't assume ARM supports unaligned accesses Security and other issues found by analysis: Fix various security issues reported by Charles Smith at Tangible Security Fix various security issues reported by Include Security Fix some issues found by cppcheck. Add some overflow checks in the optimizer rpcap: Support rpcap-over-TLS Redo protocol version negotiation to avoid problems with old servers (it still works with servers using the old negotiation, as well as servers not supporting negotiation) Error handling cleanups Add some new authentication libpcap error codes for specific errors Fix some inetd issues in rpcapd Fix rpcapd core dumps with invalid configuration file On UN*X, don't have rpcapd tell the client why authentication failed, so a brute-force attacker can't distinguish between "unknown user name" and "known user name, wrong password" Allow rpcapd to rebind more rapidly (GitHub issue #765) Documentation: Improve man pages, including adding backward compatibility notes Building and testing: Require, and assume, some level of C99 support in the C compiler Require Visual Studio 2015 or later if using Visual Studio Fix configure script issues, including with libnl on Linux Fix CMake issues Squelch complaints from Bison about "%define api.pure" being deprecated Fix compilation of pcap-tc.c Linux: Require PF_PACKET support, and kernel 2.6.27 or later Handle systems without AF_INET or AF_UNIX socket support Get rid of Wireless Extensions for turning monitor mode on Proper memory sync for PACKET_MMAP (may prevent GitHub issue #898) Drop support for libnl 1 and 2. Return error on interface going away, but not if it just went down but is still present Set socket protocol only after packet ring configured, reducing bogus packet drop reports Get ifdrop stats from sysfs. When adjusting BPF programs, do not subtract the SLL[2]_HDR_LEN if the location is negative (special metadata offset), to preserve references to metadata; see https://github.com/the-tcpdump-group/tcpdump/issues/480#issuecomment-486827278 Report a warning for unknown ARPHRD types Have pcap_breakloop() forcibly break out of a sleeping capture loop Add support for DSA data link types For raw USB bus capture, use the snapshot length to set the buffer size, and set the len field to reflect the length in the URB (GitHub issue #808) With a timeout of zero, wait indefinitely Clean up support for some non-GNU libc C libraries Add DLT_LINUX_SLL2 for cooked-mode captures Probe CONFIGURATION descriptor of connected USB devices Treat EPERM on ethtool ioctls as meaning "not supported", as permissions checks are done before checking whether the ioctl is supported at all macOS: Cope with getting EPWROFF from SIOCGIFMEDIA Treat EPERM on SIOCGIFMEDIA as meaning "not supported", as permissions checks are done before checking whether the ioctl is supported at all Treat ENXIO when reading packets as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture FreeBSD: Treat ENXIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture NetBSD: Treat ENXIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture OpenBSD: Treat EIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture DragonFly BSD: Treat ENXIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture Solaris: Treat ENXIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture AIX: Fix loading of BPF kernel extension Treat ENXIO as meaning "the interface was removed" Report "the interface disappeared", not "the interface went down", if the interface was removed during a capture Windows: Make the snapshot length work even if pcap_setfilter() isn't called Fix compilation on Cygwin/MSYS Add pcap_handle(), and deprecate pcap_fileno() Report PCAP_ERROR_NO_SUCH_DEVICE for a non-existent device Return an appropriate error message for device removed or device unusable due to a suspend/resume Report a warning for unknown NdisMedium types Have pcap_breakloop() forcibly break out of a sleeping capture loop Clean up building DLL Handle CRT mismatch for pcap_dump_fopen() Map NdisMediumWirelessWan to DLT_RAW Add AirPcap support in a module, rather than using WinPcap/Npcap's support for it Report the system error for PacketSetHwFilter() failures Add support for getting and setting packet time stamp types with Npcap Have pcap_init() allow selecting whether the API should use local code page strings or UTF-8 strings (including error messages) Haiku: Add capture support
2023-08-17 16:11:01 +03:00
/*
* We want a reentrant parser.
*/
@REENTRANT_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}
/*
* According to bison documentation, shift/reduce conflicts are not an issue
* in most parsers as long as the number does not evolve over time:
* https://www.gnu.org/software/bison/manual/html_node/Expect-Decl.html
* So, following the advice use %expect to check the amount of shift/reduce
* warnings.
*
* This doesn't appear to work in Berkeley YACC - 1.9 20170709; it still
* warns of 38 shift/reduce conflicts.
*
* The Berkeley YACC documentation:
*
* https://invisible-island.net/byacc/manpage/yacc.html
*
* claims that "Bison's support for "%expect" is broken in more than one
* release.", but doesn't give details. Hopefully, that only means that
* you get warnings even if you have the expected number of shift/reduce
* conflicts, not that anything else fails.
*/
%expect 38
/*
* And we need to pass the compiler state to the scanner.
*/
%parse-param { compiler_state_t *cstate }
%{
/*
* 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.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* grammar.h requires gencode.h and sometimes breaks in a polluted namespace
* (see ftmacros.h), so include it early.
*/
#include "gencode.h"
#include "grammar.h"
#include <stdlib.h>
#ifndef _WIN32
#include <sys/types.h>
#include <sys/socket.h>
#if __STDC__
struct mbuf;
struct rtentry;
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#endif /* _WIN32 */
#include <stdio.h>
#include "diag-control.h"
#include "pcap-int.h"
#include "scanner.h"
#include "llc.h"
#include "ieee80211.h"
#include "pflog.h"
#include <pcap/namedb.h>
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#ifdef YYBYACC
/*
* Both Berkeley YACC and Bison define yydebug (under whatever name
* it has) as a global, but Bison does so only if YYDEBUG is defined.
* Berkeley YACC define it even if YYDEBUG isn't defined; declare it
* here to suppress a warning.
*/
#if !defined(YYDEBUG)
extern int yydebug;
#endif
/*
* In Berkeley YACC, yynerrs (under whatever name it has) is global,
* even if it's building a reentrant parser. In Bison, it's local
* in reentrant parsers.
*
* Declare it to squelch a warning.
*/
extern int yynerrs;
#endif
#define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\
(q).dir = (unsigned char)(d),\
(q).addr = (unsigned char)(a)
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 }
};
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 }
};
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) {
/*
* Just in case somebody is using this to
* generate values of -1/0xFFFFFFFF.
* That won't work, as it's indistinguishable
* from an error.
*/
if (toks[i].v == -1)
abort();
return (toks[i].v);
}
}
return (-1);
}
static const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF };
static void
yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg)
{
bpf_set_error(cstate, "can't parse filter expression: %s", msg);
}
static const struct tok pflog_reasons[] = {
{ PFRES_MATCH, "match" },
{ PFRES_BADOFF, "bad-offset" },
{ PFRES_FRAG, "fragment" },
{ PFRES_SHORT, "short" },
{ PFRES_NORM, "normalize" },
{ PFRES_MEMORY, "memory" },
{ PFRES_TS, "bad-timestamp" },
{ PFRES_CONGEST, "congestion" },
{ PFRES_IPOPTIONS, "ip-option" },
{ PFRES_PROTCKSUM, "proto-cksum" },
{ PFRES_BADSTATE, "state-mismatch" },
{ PFRES_STATEINS, "state-insert" },
{ PFRES_MAXSTATES, "state-limit" },
{ PFRES_SRCLIMIT, "src-limit" },
{ PFRES_SYNPROXY, "synproxy" },
#if defined(__FreeBSD__)
{ PFRES_MAPFAILED, "map-failed" },
#elif defined(__NetBSD__)
{ PFRES_STATELOCKED, "state-locked" },
#elif defined(__OpenBSD__)
{ PFRES_TRANSLATE, "translate" },
{ PFRES_NOROUTE, "no-route" },
#elif defined(__APPLE__)
{ PFRES_DUMMYNET, "dummynet" },
#endif
{ 0, NULL }
};
static int
pfreason_to_num(compiler_state_t *cstate, const char *reason)
{
int i;
i = str2tok(reason, pflog_reasons);
if (i == -1)
bpf_set_error(cstate, "unknown PF reason \"%s\"", reason);
return (i);
}
static const struct tok pflog_actions[] = {
{ PF_PASS, "pass" },
{ PF_PASS, "accept" }, /* alias for "pass" */
{ PF_DROP, "drop" },
{ PF_DROP, "block" }, /* alias for "drop" */
{ PF_SCRUB, "scrub" },
{ PF_NOSCRUB, "noscrub" },
{ PF_NAT, "nat" },
{ PF_NONAT, "nonat" },
{ PF_BINAT, "binat" },
{ PF_NOBINAT, "nobinat" },
{ PF_RDR, "rdr" },
{ PF_NORDR, "nordr" },
{ PF_SYNPROXY_DROP, "synproxy-drop" },
#if defined(__FreeBSD__)
{ PF_DEFER, "defer" },
#elif defined(__OpenBSD__)
{ PF_DEFER, "defer" },
{ PF_MATCH, "match" },
{ PF_DIVERT, "divert" },
{ PF_RT, "rt" },
{ PF_AFRT, "afrt" },
#elif defined(__APPLE__)
{ PF_DUMMYNET, "dummynet" },
{ PF_NODUMMYNET, "nodummynet" },
{ PF_NAT64, "nat64" },
{ PF_NONAT64, "nonat64" },
#endif
{ 0, NULL },
};
static int
pfaction_to_num(compiler_state_t *cstate, const char *action)
{
int i;
i = str2tok(action, pflog_actions);
if (i == -1)
bpf_set_error(cstate, "unknown PF action \"%s\"", action);
return (i);
}
/*
* For calls that might return an "an error occurred" value.
*/
#define CHECK_INT_VAL(val) if (val == -1) YYABORT
#define CHECK_PTR_VAL(val) if (val == NULL) YYABORT
DIAG_OFF_BISON_BYACC
%}
%union {
int i;
bpf_u_int32 h;
char *s;
struct stmt *stmt;
struct arth *a;
struct {
struct qual q;
int atmfieldtype;
int mtp3fieldtype;
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 relop irelop
%type <h> pnum
%type <blk> and or paren not null prog
%type <rblk> other pfvar p80211 pllc
%type <i> atmtype atmmultitype
%type <blk> atmfield
%type <blk> atmfieldvalue atmvalue atmlistvalue
%type <i> mtp2type
%type <blk> mtp3field
%type <blk> mtp3fieldvalue mtp3value mtp3listvalue
%token DST SRC HOST GATEWAY
%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
%token TK_BROADCAST TK_MULTICAST
%token NUM INBOUND OUTBOUND
%token IFINDEX
%token PF_IFNAME PF_RSET PF_RNR PF_SRNR PF_REASON PF_ACTION
%token TYPE SUBTYPE DIR ADDR1 ADDR2 ADDR3 ADDR4 RA TA
%token LINK
%token GEQ LEQ NEQ
%token ID EID HID HID6 AID
%token LSH RSH
%token LEN
%token IPV6 ICMPV6 AH ESP
%token VLAN MPLS
%token PPPOED PPPOES GENEVE
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
%token STP
%token IPX
%token NETBEUI
%token LANE LLC METAC BCC SC ILMIC OAMF4EC OAMF4SC
%token OAM OAMF4 CONNECTMSG METACONNECT
%token VPI VCI
%token RADIO
%token FISU LSSU MSU HFISU HLSSU HMSU
%token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
%token LEX_ERROR
%type <s> ID EID AID
%type <s> HID HID6
%type <h> NUM
%type <i> action reason type subtype type_subtype dir
%left OR AND
%nonassoc '!'
%left '|'
%left '&'
%left LSH RSH
%left '+' '-'
%left '*' '/'
%nonassoc UMINUS
%%
prog: null expr
{
CHECK_INT_VAL(finish_parse(cstate, $2.b));
}
| 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
| pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
$$.q = $<blk>0.q))); }
| paren pid ')' { $$ = $2; }
;
nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
| HID '/' NUM { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
$$.q = $<blk>0.q))); }
| HID NETMASK HID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
$$.q = $<blk>0.q))); }
| HID {
CHECK_PTR_VAL($1);
/* Decide how to parse HID based on proto */
$$.q = $<blk>0.q;
if ($$.q.addr == Q_PORT) {
bpf_set_error(cstate, "'port' modifier applied to ip host");
YYABORT;
} else if ($$.q.addr == Q_PORTRANGE) {
bpf_set_error(cstate, "'portrange' modifier applied to ip host");
YYABORT;
} else if ($$.q.addr == Q_PROTO) {
bpf_set_error(cstate, "'proto' modifier applied to ip host");
YYABORT;
} else if ($$.q.addr == Q_PROTOCHAIN) {
bpf_set_error(cstate, "'protochain' modifier applied to ip host");
YYABORT;
}
CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
}
| HID6 '/' NUM {
CHECK_PTR_VAL($1);
#ifdef INET6
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
$$.q = $<blk>0.q)));
#else
bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
"in this configuration");
YYABORT;
#endif /*INET6*/
}
| HID6 {
CHECK_PTR_VAL($1);
#ifdef INET6
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
$$.q = $<blk>0.q)));
#else
bpf_set_error(cstate, "'ip6addr' not supported "
"in this configuration");
YYABORT;
#endif /*INET6*/
}
| EID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $<blk>0.q))); }
| AID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $<blk>0.q))); }
| 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; }
;
qid: pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, $1,
$$.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); }
| pqual PROTOCHAIN {
#ifdef NO_PROTOCHAIN
bpf_set_error(cstate, "protochain not supported");
YYABORT;
#else
QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN);
#endif
}
| pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); }
;
rterm: head id { $$ = $2; }
| paren expr ')' { $$.b = $2.b; $$.q = $1.q; }
| pname { CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; }
| arth relop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0)));
$$.q = qerr; }
| arth irelop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1)));
$$.q = qerr; }
| other { $$.b = $1; $$.q = qerr; }
| atmtype { CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; }
| atmmultitype { CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; }
| atmfield atmvalue { $$.b = $2.b; $$.q = qerr; }
| mtp2type { CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; }
| mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; }
;
/* 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; }
| ADDR1 { $$ = Q_ADDR1; }
| ADDR2 { $$ = Q_ADDR2; }
| ADDR3 { $$ = Q_ADDR3; }
| ADDR4 { $$ = Q_ADDR4; }
| RA { $$ = Q_RA; }
| TA { $$ = Q_TA; }
;
/* address type qualifiers */
aqual: HOST { $$ = Q_HOST; }
| NET { $$ = Q_NET; }
| PORT { $$ = Q_PORT; }
| PORTRANGE { $$ = Q_PORTRANGE; }
;
/* non-directional address type qualifiers */
ndaqual: GATEWAY { $$ = Q_GATEWAY; }
;
pname: LINK { $$ = Q_LINK; }
| IP { $$ = Q_IP; }
| ARP { $$ = Q_ARP; }
| RARP { $$ = Q_RARP; }
| SCTP { $$ = Q_SCTP; }
| TCP { $$ = Q_TCP; }
| UDP { $$ = Q_UDP; }
| ICMP { $$ = Q_ICMP; }
| IGMP { $$ = Q_IGMP; }
| IGRP { $$ = Q_IGRP; }
| PIM { $$ = Q_PIM; }
| VRRP { $$ = Q_VRRP; }
| CARP { $$ = Q_CARP; }
| ATALK { $$ = Q_ATALK; }
| AARP { $$ = Q_AARP; }
| DECNET { $$ = Q_DECNET; }
| LAT { $$ = Q_LAT; }
| SCA { $$ = Q_SCA; }
| MOPDL { $$ = Q_MOPDL; }
| MOPRC { $$ = Q_MOPRC; }
| IPV6 { $$ = Q_IPV6; }
| ICMPV6 { $$ = Q_ICMPV6; }
| AH { $$ = Q_AH; }
| ESP { $$ = Q_ESP; }
| ISO { $$ = Q_ISO; }
| ESIS { $$ = Q_ESIS; }
| ISIS { $$ = Q_ISIS; }
| 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; }
| CLNP { $$ = Q_CLNP; }
| STP { $$ = Q_STP; }
| IPX { $$ = Q_IPX; }
| NETBEUI { $$ = Q_NETBEUI; }
| RADIO { $$ = Q_RADIO; }
;
other: pqual TK_BROADCAST { CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); }
| pqual TK_MULTICAST { CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); }
| LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); }
| GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); }
| CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); }
| INBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); }
| OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); }
| IFINDEX NUM { CHECK_PTR_VAL(($$ = gen_ifindex(cstate, $2))); }
| VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, $2, 1))); }
| VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); }
| MPLS pnum { CHECK_PTR_VAL(($$ = gen_mpls(cstate, $2, 1))); }
| MPLS { CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); }
| PPPOED { CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); }
| PPPOES pnum { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, $2, 1))); }
| PPPOES { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
| GENEVE pnum { CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
| GENEVE { CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
| pfvar { $$ = $1; }
| pqual p80211 { $$ = $2; }
| pllc { $$ = $1; }
;
pfvar: PF_IFNAME ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
| PF_RSET ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
| PF_RNR NUM { CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
| PF_SRNR NUM { CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); }
| PF_REASON reason { CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); }
| PF_ACTION action { CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); }
;
p80211: TYPE type SUBTYPE subtype
{ CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4,
IEEE80211_FC0_TYPE_MASK |
IEEE80211_FC0_SUBTYPE_MASK)));
}
| TYPE type { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
IEEE80211_FC0_TYPE_MASK)));
}
| SUBTYPE type_subtype { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2,
IEEE80211_FC0_TYPE_MASK |
IEEE80211_FC0_SUBTYPE_MASK)));
}
| DIR dir { CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); }
;
type: NUM { if (($1 & (~IEEE80211_FC0_TYPE_MASK)) != 0) {
bpf_set_error(cstate, "invalid 802.11 type value 0x%02x", $1);
YYABORT;
}
$$ = (int)$1;
}
| ID { CHECK_PTR_VAL($1);
$$ = str2tok($1, ieee80211_types);
if ($$ == -1) {
bpf_set_error(cstate, "unknown 802.11 type name \"%s\"", $1);
YYABORT;
}
}
;
subtype: NUM { if (($1 & (~IEEE80211_FC0_SUBTYPE_MASK)) != 0) {
bpf_set_error(cstate, "invalid 802.11 subtype value 0x%02x", $1);
YYABORT;
}
$$ = (int)$1;
}
| ID { const struct tok *types = NULL;
int i;
CHECK_PTR_VAL($1);
for (i = 0;; i++) {
if (ieee80211_type_subtypes[i].tok == NULL) {
/* Ran out of types */
bpf_set_error(cstate, "unknown 802.11 type");
YYABORT;
}
if ($<i>-1 == ieee80211_type_subtypes[i].type) {
types = ieee80211_type_subtypes[i].tok;
break;
}
}
$$ = str2tok($1, types);
if ($$ == -1) {
bpf_set_error(cstate, "unknown 802.11 subtype name \"%s\"", $1);
YYABORT;
}
}
;
type_subtype: ID { int i;
CHECK_PTR_VAL($1);
for (i = 0;; i++) {
if (ieee80211_type_subtypes[i].tok == NULL) {
/* Ran out of types */
bpf_set_error(cstate, "unknown 802.11 type name");
YYABORT;
}
$$ = str2tok($1, ieee80211_type_subtypes[i].tok);
if ($$ != -1) {
$$ |= ieee80211_type_subtypes[i].type;
break;
}
}
}
;
pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
| LLC ID { CHECK_PTR_VAL($2);
if (pcap_strcasecmp($2, "i") == 0) {
CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
} else if (pcap_strcasecmp($2, "s") == 0) {
CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
} else if (pcap_strcasecmp($2, "u") == 0) {
CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
} else {
int subtype;
subtype = str2tok($2, llc_s_subtypes);
if (subtype != -1) {
CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype)));
} else {
subtype = str2tok($2, llc_u_subtypes);
if (subtype == -1) {
bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2);
YYABORT;
}
CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype)));
}
}
}
/* sigh, "rnr" is already a keyword for PF */
| LLC PF_RNR { CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); }
;
dir: NUM { $$ = (int)$1; }
| ID { CHECK_PTR_VAL($1);
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 {
bpf_set_error(cstate, "unknown 802.11 direction");
YYABORT;
}
}
;
reason: NUM { $$ = $1; }
| ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); }
;
action: ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); }
;
relop: '>' { $$ = BPF_JGT; }
| GEQ { $$ = BPF_JGE; }
| '=' { $$ = BPF_JEQ; }
;
irelop: LEQ { $$ = BPF_JGT; }
| '<' { $$ = BPF_JGE; }
| NEQ { $$ = BPF_JEQ; }
;
arth: pnum { CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); }
| narth
;
narth: pname '[' arth ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); }
| pname '[' arth ':' NUM ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); }
| arth '+' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); }
| arth '-' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); }
| arth '*' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); }
| arth '/' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); }
| arth '%' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); }
| arth '&' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); }
| arth '|' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); }
| arth '^' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); }
| arth LSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); }
| arth RSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); }
| '-' arth %prec UMINUS { CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); }
| paren narth ')' { $$ = $2; }
| LEN { CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); }
;
byteop: '&' { $$ = '&'; }
| '|' { $$ = '|'; }
| '<' { $$ = '<'; }
| '>' { $$ = '>'; }
| '=' { $$ = '='; }
;
pnum: NUM
| paren pnum ')' { $$ = $2; }
;
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
| relop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 0))); }
| irelop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $<blk>0.atmfieldtype, $2, $1, 1))); }
| paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; }
;
atmfieldvalue: NUM {
$$.atmfieldtype = $<blk>0.atmfieldtype;
if ($$.atmfieldtype == A_VPI ||
$$.atmfieldtype == A_VCI)
CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, $1, BPF_JEQ, 0)));
}
;
atmlistvalue: atmfieldvalue
| atmlistvalue or atmfieldvalue { gen_or($1.b, $3.b); $$ = $3; }
;
/* MTP2 types quantifier */
mtp2type: FISU { $$ = M_FISU; }
| LSSU { $$ = M_LSSU; }
| MSU { $$ = M_MSU; }
| HFISU { $$ = MH_FISU; }
| HLSSU { $$ = MH_LSSU; }
| HMSU { $$ = MH_MSU; }
;
/* MTP3 field types quantifier */
mtp3field: SIO { $$.mtp3fieldtype = M_SIO; }
| OPC { $$.mtp3fieldtype = M_OPC; }
| DPC { $$.mtp3fieldtype = M_DPC; }
| SLS { $$.mtp3fieldtype = M_SLS; }
| HSIO { $$.mtp3fieldtype = MH_SIO; }
| HOPC { $$.mtp3fieldtype = MH_OPC; }
| HDPC { $$.mtp3fieldtype = MH_DPC; }
| HSLS { $$.mtp3fieldtype = MH_SLS; }
;
mtp3value: mtp3fieldvalue
| relop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 0))); }
| irelop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $<blk>0.mtp3fieldtype, $2, $1, 1))); }
| paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; }
;
mtp3fieldvalue: NUM {
$$.mtp3fieldtype = $<blk>0.mtp3fieldtype;
if ($$.mtp3fieldtype == M_SIO ||
$$.mtp3fieldtype == M_OPC ||
$$.mtp3fieldtype == M_DPC ||
$$.mtp3fieldtype == M_SLS ||
$$.mtp3fieldtype == MH_SIO ||
$$.mtp3fieldtype == MH_OPC ||
$$.mtp3fieldtype == MH_DPC ||
$$.mtp3fieldtype == MH_SLS)
CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, $1, BPF_JEQ, 0)));
}
;
mtp3listvalue: mtp3fieldvalue
| mtp3listvalue or mtp3fieldvalue { gen_or($1.b, $3.b); $$ = $3; }
;
%%