The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/device/bpf.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1993 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        bpf.h,v $
   29  * Revision 2.3  93/11/17  16:27:38  dbg
   30  *      Changed 'long' to 'int' for 64-bit cleanup.
   31  *      (perhaps we should use int32?)
   32  *      [93/10/26            dbg]
   33  * 
   34  * Revision 2.2  93/08/10  15:11:16  mrt
   35  *      93/02/08 11:28  Masanobu Yuhara at Fujitsu Labs.
   36  *      Added BPF support.  Derived from tcpdump-2.2.1/bpf/net/bpf.h.
   37  *      Add: New BPF instructions and macros:
   38  *           BPF_MATCH_IMM, BPF_CKMATCH_IMM, BPF_MATCH_DATA, BPF_REG_DATA,
   39  *           BPF_POSTPONE, NETF_BPF, BPF_BEGIN, BPF_INSN_STMT, BPF_INSN_JUMP.
   40  *      Add: BPF_DLBASE for accessing a data link level header.
   41  *      Changed: BPF_RVAL mask value (0x18 -> 0x38)
   42  *      [93/02/08  11:28:23  yuhara]
   43  * 
   44  */
   45 
   46 /*
   47  * Berkeley Packet Filter Definitions from Berkeley
   48  */
   49 
   50 /*-
   51  * Copyright (c) 1990-1991 The Regents of the University of California.
   52  * All rights reserved.
   53  *
   54  * This code is derived from the Stanford/CMU enet packet filter,
   55  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
   56  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 
   57  * Berkeley Laboratory.
   58  *
   59  * Redistribution and use in source and binary forms, with or without
   60  * modification, are permitted provided that the following conditions
   61  * are met:
   62  * 1. Redistributions of source code must retain the above copyright
   63  *    notice, this list of conditions and the following disclaimer.
   64  * 2. Redistributions in binary form must reproduce the above copyright
   65  *    notice, this list of conditions and the following disclaimer in the
   66  *    documentation and/or other materials provided with the distribution.
   67  * 3. All advertising materials mentioning features or use of this software
   68  *    must display the following acknowledgement:
   69  *      This product includes software developed by the University of
   70  *      California, Berkeley and its contributors.
   71  * 4. Neither the name of the University nor the names of its contributors
   72  *    may be used to endorse or promote products derived from this software
   73  *    without specific prior written permission.
   74  *
   75  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   76  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   77  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   78  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   79  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   80  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   81  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   82  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   83  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   84  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   85  * SUCH DAMAGE.
   86  *
   87  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
   88  *
   89  * @(#) $Header: bpf.h,v 2.3 93/11/17 16:27:38 dbg Exp $ (LBL)
   90  */
   91 
   92 #ifndef _DEVICE_BPF_H_
   93 #define _DEVICE_BPF_H_
   94 
   95 #if 0   /* not used in MK now */
   96 /*
   97  * Alignment macros.  BPF_WORDALIGN rounds up to the next 
   98  * even multiple of BPF_ALIGNMENT. 
   99  */
  100 #define BPF_ALIGNMENT sizeof(int)
  101 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
  102 
  103 /*
  104  * Struct return by BIOCVERSION.  This represents the version number of 
  105  * the filter language described by the instruction encodings below.
  106  * bpf understands a program iff kernel_major == filter_major &&
  107  * kernel_minor >= filter_minor, that is, if the value returned by the
  108  * running kernel has the same major number and a minor number equal
  109  * equal to or less than the filter being downloaded.  Otherwise, the
  110  * results are undefined, meaning an error may be returned or packets
  111  * may be accepted haphazardly.
  112  * It has nothing to do with the source code version.
  113  */
  114 struct bpf_version {
  115         u_short bv_major;
  116         u_short bv_minor;
  117 };
  118 /* Current version number. */
  119 #define BPF_MAJOR_VERSION 1
  120 #define BPF_MINOR_VERSION 1
  121 
  122 /*
  123  * Data-link level type codes.
  124  * Currently, only DLT_EN10MB and DLT_SLIP are supported.
  125  */
  126 #define DLT_NULL        0       /* no link-layer encapsulation */
  127 #define DLT_EN10MB      1       /* Ethernet (10Mb) */
  128 #define DLT_EN3MB       2       /* Experimental Ethernet (3Mb) */
  129 #define DLT_AX25        3       /* Amateur Radio AX.25 */
  130 #define DLT_PRONET      4       /* Proteon ProNET Token Ring */
  131 #define DLT_CHAOS       5       /* Chaos */
  132 #define DLT_IEEE802     6       /* IEEE 802 Networks */
  133 #define DLT_ARCNET      7       /* ARCNET */
  134 #define DLT_SLIP        8       /* Serial Line IP */
  135 #define DLT_PPP         9       /* Point-to-point Protocol */
  136 #define DLT_FDDI        10      /* FDDI */
  137 
  138 #endif /* 0 */
  139 
  140 /*
  141  * The instruction encondings.
  142  */
  143 
  144 /* Magic number for the first instruction */
  145 #define BPF_BEGIN NETF_BPF
  146 
  147 /* instruction classes */
  148 #define BPF_CLASS(code) ((code) & 0x07)
  149 #define         BPF_LD          0x00
  150 #define         BPF_LDX         0x01
  151 #define         BPF_ST          0x02
  152 #define         BPF_STX         0x03
  153 #define         BPF_ALU         0x04
  154 #define         BPF_JMP         0x05
  155 #define         BPF_RET         0x06
  156 #define         BPF_MISC        0x07
  157 
  158 /* ld/ldx fields */
  159 #define BPF_SIZE(code)  ((code) & 0x18)
  160 #define         BPF_W           0x00
  161 #define         BPF_H           0x08
  162 #define         BPF_B           0x10
  163 #define BPF_MODE(code)  ((code) & 0xe0)
  164 #define         BPF_IMM         0x00
  165 #define         BPF_ABS         0x20
  166 #define         BPF_IND         0x40
  167 #define         BPF_MEM         0x60
  168 #define         BPF_LEN         0x80
  169 #define         BPF_MSH         0xa0
  170 
  171 /* alu/jmp fields */
  172 #define BPF_OP(code)    ((code) & 0xf0)
  173 #define         BPF_ADD         0x00
  174 #define         BPF_SUB         0x10
  175 #define         BPF_MUL         0x20
  176 #define         BPF_DIV         0x30
  177 #define         BPF_OR          0x40
  178 #define         BPF_AND         0x50
  179 #define         BPF_LSH         0x60
  180 #define         BPF_RSH         0x70
  181 #define         BPF_NEG         0x80
  182 #define         BPF_JA          0x00
  183 #define         BPF_JEQ         0x10
  184 #define         BPF_JGT         0x20
  185 #define         BPF_JGE         0x30
  186 #define         BPF_JSET        0x40
  187 #define         BPF_CKMATCH_IMM 0x50
  188 #define BPF_SRC(code)   ((code) & 0x08)
  189 #define         BPF_K           0x00
  190 #define         BPF_X           0x08
  191 
  192 /* ret - BPF_K and BPF_X also apply */
  193 #define BPF_RVAL(code)  ((code) & 0x38)
  194 #define         BPF_A           0x10
  195 #define         BPF_MATCH_IMM   0x18
  196 #define         BPF_MATCH_DATA  0x20
  197 
  198 /* misc */
  199 #define BPF_MISCOP(code) ((code) & 0xf8)
  200 #define         BPF_TAX         0x00
  201 #define         BPF_TXA         0x80
  202 #define         BPF_KEY         0x10
  203 #define         BPF_REG_DATA    0x18
  204 #define         BPF_POSTPONE    0x20
  205 
  206 /*
  207  * The instruction data structure.
  208  */
  209 struct bpf_insn {
  210         unsigned short  code;
  211         unsigned char   jt;
  212         unsigned char   jf;
  213         int     k;
  214 };
  215 typedef struct bpf_insn *bpf_insn_t;
  216 
  217 /*
  218  * largest bpf program size
  219  */
  220 #define NET_MAX_BPF ((NET_MAX_FILTER*sizeof(filter_t))/sizeof(struct bpf_insn))
  221 
  222 /*
  223  * Macros for insn array initializers.
  224  */
  225 #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
  226 #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
  227 #define BPF_RETMATCH(code, k, nkey) { (unsigned short)(code), nkey, 0, k }
  228 
  229 #define BPF_INSN_STMT(pc, c, n)  {\
  230         (pc)->code = (c);               \
  231         (pc)->jt = (pc)->jf = 0;        \
  232         (pc)->k = (n);                  \
  233         (pc)++;                         \
  234 }
  235 
  236 #define BPF_INSN_JUMP(pc, c, n, jtrue, jfalse) {\
  237         (pc)->code = (c);               \
  238         (pc)->jt = (jtrue);             \
  239         (pc)->jf = (jfalse);            \
  240         (pc)->k = (n);                  \
  241         (pc)++;                         \
  242 }
  243 
  244 #define BPF_INSN_RETMATCH(pc, c, n, nkey) {\
  245         (pc)->code = (c);               \
  246         (pc)->jt = (nkey);              \
  247         (pc)->jf = 0;                   \
  248         (pc)->k = (n);                  \
  249         (pc)++;                         \
  250 }
  251 
  252 /*
  253  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
  254  */
  255 #define BPF_MEMWORDS 16
  256 
  257 /*
  258  * Link level header can be accessed by adding BPF_DLBASE to an offset.
  259  */
  260 #define BPF_DLBASE      (1<<30)
  261 
  262 #define BPF_BYTES(n) ((n) * sizeof (struct bpf_insn))
  263 #define BPF_BYTES2LEN(n) ((n) / sizeof (struct bpf_insn))
  264 #define BPF_INSN_EQ(p,q) ((p)->code == (q)->code && \
  265                           (p)->jt == (q)->jt && \
  266                           (p)->jf == (q)->jf && \
  267                           (p)->k == (q)->k)
  268 
  269 #endif /* _DEVICE_BPF_H_ */

Cache object: 9a57bd8ecec46834af67d18aea078c47


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.