0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* $NetBSD: bpf.h,v 1.50 2009/01/13 19:10:52 christos Exp $ */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Copyright (c) 1990, 1991, 1993
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * The Regents of the University of California. All rights reserved.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed *
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * This code is derived from the Stanford/CMU enet packet filter,
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * (net/enet.c) distributed as part of 4.3BSD, and code contributed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Berkeley Laboratory.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed *
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Redistribution and use in source and binary forms, with or without
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * modification, are permitted provided that the following conditions
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * are met:
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * 1. Redistributions of source code must retain the above copyright
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * notice, this list of conditions and the following disclaimer.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * 2. Redistributions in binary form must reproduce the above copyright
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * notice, this list of conditions and the following disclaimer in the
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * documentation and/or other materials provided with the distribution.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * 3. Neither the name of the University nor the names of its contributors
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * may be used to endorse or promote products derived from this software
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * without specific prior written permission.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed *
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * SUCH DAMAGE.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed *
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * @(#)bpf.h 8.2 (Berkeley) 1/9/95
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * @(#) Header: bpf.h,v 1.36 97/06/12 14:29:53 leres Exp (LBL)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Use is subject to license terms.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#ifndef _NET_BPF_H_
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define _NET_BPF_H_
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <sys/time.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <sys/types32.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <sys/ioccom.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* BSD style release date */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_RELEASE 199606
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedtypedef int bpf_int32;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedtypedef uint_t bpf_uint_t32;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedtypedef uint_t bpf_u_int32;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Alignment macros. BPF_WORDALIGN rounds up to the next
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * even multiple of BPF_ALIGNMENT.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_ALIGNMENT sizeof (uint32_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MAXINSNS 512
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_DFLTBUFSIZE (1024*1024) /* default static upper limit */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MAXBUFSIZE (1024*1024*16) /* hard limit on sysctl'able value */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MINBUFSIZE 32
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Structure for BIOCSETF.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_program {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bf_len;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed struct bpf_insn *bf_insns;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_program32 {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bf_len;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed caddr32_t bf_insns;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Struct returned by BIOCGSTATS and net.bpf.stats sysctl.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_stat {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint64_t bs_recv; /* number of packets received */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint64_t bs_drop; /* number of packets dropped */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint64_t bs_capt; /* number of packets captured */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint64_t bs_padding[13];
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Struct returned by BIOCGSTATSOLD.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_stat_old {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bs_recv; /* number of packets received */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bs_drop; /* number of packets dropped */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Struct return by BIOCVERSION. This represents the version number of
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * the filter language described by the instruction encodings below.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * bpf understands a program iff kernel_major == filter_major &&
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * kernel_minor >= filter_minor, that is, if the value returned by the
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * running kernel has the same major number and a minor number equal
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * equal to or less than the filter being downloaded. Otherwise, the
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * results are undefined, meaning an error may be returned or packets
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * may be accepted haphazardly.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * It has nothing to do with the source code version.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_version {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed ushort_t bv_major;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed ushort_t bv_minor;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* Current version number of filter architecture. */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MAJOR_VERSION 1
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MINOR_VERSION 1
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * BPF ioctls
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed *
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * The first set is for compatibility with Sun's pcc style
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * header files. If your using gcc, we assume that you
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * have run fixincludes so the latter set should work.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGBLEN _IOR('B', 102, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSBLEN _IOWR('B', 102, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSETF _IOW('B', 103, struct bpf_program)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCFLUSH _IO('B', 104)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCPROMISC _IO('B', 105)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGDLT _IOR('B', 106, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGETIF _IOR('B', 107, struct ifreq)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGETLIF _IOR('B', 107, struct lifreq)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSETIF _IOW('B', 108, struct ifreq)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSETLIF _IOW('B', 108, struct lifreq)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGSTATS _IOR('B', 111, struct bpf_stat)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGSTATSOLD _IOR('B', 111, struct bpf_stat_old)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCIMMEDIATE _IOW('B', 112, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCVERSION _IOR('B', 113, struct bpf_version)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSTCPF _IOW('B', 114, struct bpf_program)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSUDPF _IOW('B', 115, struct bpf_program)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGHDRCMPLT _IOR('B', 116, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSHDRCMPLT _IOW('B', 117, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSDLT _IOW('B', 118, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGDLTLIST _IOWR('B', 119, struct bpf_dltlist)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGSEESENT _IOR('B', 120, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSSEESENT _IOW('B', 121, uint_t)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSRTIMEOUT _IOW('B', 122, struct timeval)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGRTIMEOUT _IOR('B', 123, struct timeval)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSETF32 _IOW('B', 103, struct bpf_program32)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGDLTLIST32 _IOWR('B', 119, struct bpf_dltlist32)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCSRTIMEOUT32 _IOW('B', 122, struct timeval32)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BIOCGRTIMEOUT32 _IOR('B', 123, struct timeval32)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Structure prepended to each packet. This is "wire" format, so we
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * cannot change it unfortunately to 64 bit times on 32 bit systems [yet].
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_timeval {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed int32_t tv_sec;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed int32_t tv_usec;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_hdr {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed struct bpf_timeval bh_tstamp; /* time stamp */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint32_t bh_caplen; /* length of captured portion */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint32_t bh_datalen; /* original length of packet */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint16_t bh_hdrlen; /* length of bpf header (this struct */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed /* plus alignment padding) */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Because the structure above is not a multiple of 4 bytes, some compilers
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Only the kernel needs to know about it; applications use bh_hdrlen.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * XXX To save a few bytes on 32-bit machines, we avoid end-of-struct
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * XXX padding by using the size of the header data elements. This is
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * XXX fail-safe: on new machines, we just use the 'safe' sizeof.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#ifdef _KERNEL
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#if defined(__arm32__) || defined(__i386__) || defined(__m68k__) || \
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed defined(__mips__) || defined(__ns32k__) || defined(__vax__) || \
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed defined(__sh__) || (defined(__sparc__) && !defined(__sparc64__))
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define SIZEOF_BPF_HDR 18
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#else
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define SIZEOF_BPF_HDR sizeof (struct bpf_hdr)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#endif
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#endif
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* Pull in data-link level type codes. */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <net/dlt.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * The instruction encodings.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* instruction classes */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_CLASS(code) ((code) & 0x07)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_LD 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_LDX 0x01
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_ST 0x02
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_STX 0x03
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_ALU 0x04
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JMP 0x05
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_RET 0x06
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MISC 0x07
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* ld/ldx fields */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_SIZE(code) ((code) & 0x18)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_W 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_H 0x08
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_B 0x10
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MODE(code) ((code) & 0xe0)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_IMM 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_ABS 0x20
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_IND 0x40
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MEM 0x60
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_LEN 0x80
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MSH 0xa0
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* alu/jmp fields */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_OP(code) ((code) & 0xf0)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_ADD 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_SUB 0x10
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MUL 0x20
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_DIV 0x30
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_OR 0x40
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_AND 0x50
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_LSH 0x60
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_RSH 0x70
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_NEG 0x80
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JA 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JEQ 0x10
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JGT 0x20
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JGE 0x30
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JSET 0x40
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_SRC(code) ((code) & 0x08)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_K 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_X 0x08
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* ret - BPF_K and BPF_X also apply */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_RVAL(code) ((code) & 0x18)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_A 0x10
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/* misc */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MISCOP(code) ((code) & 0xf8)
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_TAX 0x00
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_TXA 0x80
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * The instruction data structure.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_insn {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint16_t code;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint8_t jt;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint8_t jf;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint32_t k;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Macros for insn array initializers.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_STMT(code, k) { (uint16_t)(code), 0, 0, k }
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_JUMP(code, k, jt, jf) { (uint16_t)(code), jt, jf, k }
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Structure to retrieve available DLTs for the interface.
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_dltlist {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bfl_len; /* number of bfd_list array */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t *bfl_list; /* array of DLTs */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedstruct bpf_dltlist32 {
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed uint_t bfl_len;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed caddr32_t bfl_list;
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed};
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#ifdef _KERNEL
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <sys/mac.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#include <sys/dls_impl.h>
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedtypedef void (*bpf_itap_fn_t)(void *, mblk_t *, boolean_t, uint_t);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern void bpfattach(uintptr_t, int, zoneid_t, int);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern void bpfdetach(uintptr_t);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern uint_t bpf_filter(struct bpf_insn *, uchar_t *, uint_t, uint_t);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern void bpf_itap(void *, mblk_t *, boolean_t, uint_t);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern void bpf_mtap(void *, mac_resource_handle_t, mblk_t *, boolean_t);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reedextern int bpf_validate(struct bpf_insn *, int);
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#endif /* _KERNEL */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed/*
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed */
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#define BPF_MEMWORDS 16
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed
0a0e9771ca0211c15f3ac4466b661c145feeb9e4Darren Reed#endif /* !_NET_BPF_H_ */