Annotation of Gnu-Mach/include/device/bpf.h, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.