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