192a3e552SArchie Cobbs /* 292a3e552SArchie Cobbs * ng_bpf.h 3c398230bSWarner Losh */ 4c398230bSWarner Losh 5c398230bSWarner Losh /*- 692a3e552SArchie Cobbs * Copyright (c) 1996-1999 Whistle Communications, Inc. 792a3e552SArchie Cobbs * All rights reserved. 892a3e552SArchie Cobbs * 992a3e552SArchie Cobbs * Subject to the following obligations and disclaimer of warranty, use and 1092a3e552SArchie Cobbs * redistribution of this software, in source or object code forms, with or 1192a3e552SArchie Cobbs * without modifications are expressly permitted by Whistle Communications; 1292a3e552SArchie Cobbs * provided, however, that: 1392a3e552SArchie Cobbs * 1. Any and all reproductions of the source or object code must include the 1492a3e552SArchie Cobbs * copyright notice above and the following disclaimer of warranties; and 1592a3e552SArchie Cobbs * 2. No rights are granted, in any manner or form, to use Whistle 1692a3e552SArchie Cobbs * Communications, Inc. trademarks, including the mark "WHISTLE 1792a3e552SArchie Cobbs * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 1892a3e552SArchie Cobbs * such appears in the above copyright notice or in the software. 1992a3e552SArchie Cobbs * 2092a3e552SArchie Cobbs * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 2192a3e552SArchie Cobbs * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 2292a3e552SArchie Cobbs * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 2392a3e552SArchie Cobbs * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 2492a3e552SArchie Cobbs * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 25d2a57575SJulian Elischer * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 2692a3e552SArchie Cobbs * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 2792a3e552SArchie Cobbs * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 2892a3e552SArchie Cobbs * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 2992a3e552SArchie Cobbs * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 3092a3e552SArchie Cobbs * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 3192a3e552SArchie Cobbs * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 3292a3e552SArchie Cobbs * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 3392a3e552SArchie Cobbs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3492a3e552SArchie Cobbs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3592a3e552SArchie Cobbs * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 3692a3e552SArchie Cobbs * OF SUCH DAMAGE. 3792a3e552SArchie Cobbs * 38cc3bbd68SJulian Elischer * Author: Archie Cobbs <archie@freebsd.org> 3992a3e552SArchie Cobbs * 4092a3e552SArchie Cobbs * $FreeBSD$ 4192a3e552SArchie Cobbs * $Whistle: ng_bpf.h,v 1.3 1999/12/03 20:30:23 archie Exp $ 4292a3e552SArchie Cobbs */ 4392a3e552SArchie Cobbs 44e20480bfSRuslan Ermilov #ifndef _NETGRAPH_NG_BPF_H_ 45e20480bfSRuslan Ermilov #define _NETGRAPH_NG_BPF_H_ 4692a3e552SArchie Cobbs 4792a3e552SArchie Cobbs /* Node type name and magic cookie */ 4892a3e552SArchie Cobbs #define NG_BPF_NODE_TYPE "bpf" 4992a3e552SArchie Cobbs #define NGM_BPF_COOKIE 944100792 5092a3e552SArchie Cobbs 5192a3e552SArchie Cobbs /* Program structure for one hook */ 5292a3e552SArchie Cobbs struct ng_bpf_hookprog { 5387e2c66aSHartmut Brandt char thisHook[NG_HOOKSIZ]; /* name of hook */ 5487e2c66aSHartmut Brandt char ifMatch[NG_HOOKSIZ]; /* match dest hook */ 5587e2c66aSHartmut Brandt char ifNotMatch[NG_HOOKSIZ]; /* !match dest hook */ 5692a3e552SArchie Cobbs int32_t bpf_prog_len; /* #isns in program */ 57f3bfd2edSAlfred Perlstein struct bpf_insn bpf_prog[]; /* bpf program */ 5892a3e552SArchie Cobbs }; 5992a3e552SArchie Cobbs 60ab0d3c94SArchie Cobbs #define NG_BPF_HOOKPROG_SIZE(numInsn) \ 61ab0d3c94SArchie Cobbs (sizeof(struct ng_bpf_hookprog) + (numInsn) * sizeof(struct bpf_insn)) 6292a3e552SArchie Cobbs 6392a3e552SArchie Cobbs /* Keep this in sync with the above structure definition */ 6492a3e552SArchie Cobbs #define NG_BPF_HOOKPROG_TYPE_INFO(bptype) { \ 6592a3e552SArchie Cobbs { "thisHook", &ng_parse_hookbuf_type }, \ 6692a3e552SArchie Cobbs { "ifMatch", &ng_parse_hookbuf_type }, \ 6792a3e552SArchie Cobbs { "ifNotMatch", &ng_parse_hookbuf_type }, \ 6892a3e552SArchie Cobbs { "bpf_prog_len", &ng_parse_int32_type }, \ 6992a3e552SArchie Cobbs { "bpf_prog", (bptype) }, \ 70f0184ff8SArchie Cobbs { NULL } \ 7192a3e552SArchie Cobbs } 7292a3e552SArchie Cobbs 7392a3e552SArchie Cobbs /* Statistics structure for one hook */ 7492a3e552SArchie Cobbs struct ng_bpf_hookstat { 7592a3e552SArchie Cobbs u_int64_t recvFrames; 7692a3e552SArchie Cobbs u_int64_t recvOctets; 7792a3e552SArchie Cobbs u_int64_t recvMatchFrames; 7892a3e552SArchie Cobbs u_int64_t recvMatchOctets; 7992a3e552SArchie Cobbs u_int64_t xmitFrames; 8092a3e552SArchie Cobbs u_int64_t xmitOctets; 8192a3e552SArchie Cobbs }; 8292a3e552SArchie Cobbs 8392a3e552SArchie Cobbs /* Keep this in sync with the above structure definition */ 8492a3e552SArchie Cobbs #define NG_BPF_HOOKSTAT_TYPE_INFO { \ 8557b57be3SArchie Cobbs { "recvFrames", &ng_parse_uint64_type }, \ 8657b57be3SArchie Cobbs { "recvOctets", &ng_parse_uint64_type }, \ 8757b57be3SArchie Cobbs { "recvMatchFrames", &ng_parse_uint64_type }, \ 8857b57be3SArchie Cobbs { "recvMatchOctets", &ng_parse_uint64_type }, \ 8957b57be3SArchie Cobbs { "xmitFrames", &ng_parse_uint64_type }, \ 9057b57be3SArchie Cobbs { "xmitOctets", &ng_parse_uint64_type }, \ 91f0184ff8SArchie Cobbs { NULL } \ 9292a3e552SArchie Cobbs } 9392a3e552SArchie Cobbs 9492a3e552SArchie Cobbs /* Netgraph commands */ 9592a3e552SArchie Cobbs enum { 9692a3e552SArchie Cobbs NGM_BPF_SET_PROGRAM = 1, /* supply a struct ng_bpf_hookprog */ 9792a3e552SArchie Cobbs NGM_BPF_GET_PROGRAM, /* returns a struct ng_bpf_hookprog */ 9887e2c66aSHartmut Brandt NGM_BPF_GET_STATS, /* supply name as char[NG_HOOKSIZ] */ 9987e2c66aSHartmut Brandt NGM_BPF_CLR_STATS, /* supply name as char[NG_HOOKSIZ] */ 10087e2c66aSHartmut Brandt NGM_BPF_GETCLR_STATS, /* supply name as char[NG_HOOKSIZ] */ 10192a3e552SArchie Cobbs }; 10292a3e552SArchie Cobbs 103e20480bfSRuslan Ermilov #endif /* _NETGRAPH_NG_BPF_H_ */ 104