bpf_filter.c revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync/* $NetBSD: bpf_filter.c,v 1.35 2008/08/20 13:01:54 joerg Exp $ */
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
ee83d548adae5c628ab0799ceae14ad7895a0590vboxsync * The Regents of the University of California. All rights reserved.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * This code is derived from the Stanford/CMU enet packet filter,
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (net/enet.c) distributed as part of 4.3BSD, and code contributed
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Berkeley Laboratory.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Redistribution and use in source and binary forms, with or without
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * modification, are permitted provided that the following conditions
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * 1. Redistributions of source code must retain the above copyright
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * notice, this list of conditions and the following disclaimer.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * 2. Redistributions in binary form must reproduce the above copyright
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * notice, this list of conditions and the following disclaimer in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * documentation and/or other materials provided with the distribution.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * 3. Neither the name of the University nor the names of its contributors
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * may be used to endorse or promote products derived from this software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * without specific prior written permission.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ee83d548adae5c628ab0799ceae14ad7895a0590vboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
668c89ac2522d866021f5af374fac5bbed1c05aevboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * SUCH DAMAGE.
e61bf890078c22f4e1a4ff8caa05e0209d548426vboxsync * @(#)bpf_filter.c 8.1 (Berkeley) 6/10/93
668c89ac2522d866021f5af374fac5bbed1c05aevboxsync * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
668c89ac2522d866021f5af374fac5bbed1c05aevboxsync * Use is subject to license terms.
#ifdef _KERNEL
while (k >= len) { \
k -= len; \
m = m->b_cont; \
int len;
*err = 0;
*err = 0;
switch (len - k) {
int len;
*err = 0;
if (m0 == 0) {
*err = 0;
#include <stdlib.h>
uint32_t A, X, k;
if (pc == 0)
--pc;
++pc;
#ifdef _KERNEL
abort();
return ((uint_t)A);
k = pc->k;
#ifdef _KERNEL
int merr = 0;
if (buflen != 0)
if (merr != 0)
A = EXTRACT_LONG(&p[k]);
k = pc->k;
#ifdef _KERNEL
int merr;
if (buflen != 0)
if (merr != 0)
A = EXTRACT_SHORT(&p[k]);
k = pc->k;
if (k >= buflen) {
#ifdef _KERNEL
mblk_t *m;
int len;
if (buflen != 0)
m = (mblk_t *)p;
A = wirelen;
X = wirelen;
k = X + pc->k;
#ifdef _KERNEL
int merr = 0;
if (buflen != 0)
if (merr != 0)
A = EXTRACT_LONG(&p[k]);
k = X + pc->k;
#ifdef _KERNEL
int merr = 0;
if (buflen != 0)
if (merr != 0)
A = EXTRACT_SHORT(&p[k]);
k = X + pc->k;
if (k >= buflen) {
#ifdef _KERNEL
mblk_t *m;
int len;
if (buflen != 0)
m = (mblk_t *)p;
k = pc->k;
if (k >= buflen) {
#ifdef _KERNEL
mblk_t *m;
int len;
if (buflen != 0)
m = (mblk_t *)p;
A = pc->k;
X = pc->k;
case BPF_ST:
case BPF_STX:
A += pc->k;
A -= pc->k;
A *= pc->k;
A /= pc->k;
A &= pc->k;
A |= pc->k;
A <<= pc->k;
A >>= pc->k;
#ifdef _KERNEL
struct bpf_insn *p;
for (i = 0; i < len; ++i) {
case BPF_LD:
case BPF_LDX:
case BPF_MEM:
if (p->k >= BPF_MEMWORDS)
case BPF_ABS:
case BPF_IND:
case BPF_MSH:
case BPF_IMM:
case BPF_LEN:
case BPF_ST:
case BPF_STX:
if (p->k >= BPF_MEMWORDS)
case BPF_ALU:
case BPF_ADD:
case BPF_SUB:
case BPF_MUL:
case BPF_OR:
case BPF_AND:
case BPF_LSH:
case BPF_RSH:
case BPF_NEG:
case BPF_DIV:
case BPF_JMP:
case BPF_JA:
case BPF_JEQ:
case BPF_JGT:
case BPF_JGE:
case BPF_JSET:
case BPF_RET:
case BPF_MISC: