xref: /freebsd/sys/netgraph/ng_bpf.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 92a3e552SArchie Cobbs /*
2 92a3e552SArchie Cobbs  * ng_bpf.h
3 c398230bSWarner Losh  */
4 c398230bSWarner Losh 
5 c398230bSWarner Losh /*-
6 92a3e552SArchie Cobbs  * Copyright (c) 1996-1999 Whistle Communications, Inc.
7 92a3e552SArchie Cobbs  * All rights reserved.
8 92a3e552SArchie Cobbs  *
9 92a3e552SArchie Cobbs  * Subject to the following obligations and disclaimer of warranty, use and
10 92a3e552SArchie Cobbs  * redistribution of this software, in source or object code forms, with or
11 92a3e552SArchie Cobbs  * without modifications are expressly permitted by Whistle Communications;
12 92a3e552SArchie Cobbs  * provided, however, that:
13 92a3e552SArchie Cobbs  * 1. Any and all reproductions of the source or object code must include the
14 92a3e552SArchie Cobbs  *    copyright notice above and the following disclaimer of warranties; and
15 92a3e552SArchie Cobbs  * 2. No rights are granted, in any manner or form, to use Whistle
16 92a3e552SArchie Cobbs  *    Communications, Inc. trademarks, including the mark "WHISTLE
17 92a3e552SArchie Cobbs  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
18 92a3e552SArchie Cobbs  *    such appears in the above copyright notice or in the software.
19 92a3e552SArchie Cobbs  *
20 92a3e552SArchie Cobbs  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
21 92a3e552SArchie Cobbs  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
22 92a3e552SArchie Cobbs  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
23 92a3e552SArchie Cobbs  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
24 92a3e552SArchie Cobbs  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
25 d2a57575SJulian Elischer  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
26 92a3e552SArchie Cobbs  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
27 92a3e552SArchie Cobbs  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
28 92a3e552SArchie Cobbs  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
29 92a3e552SArchie Cobbs  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
30 92a3e552SArchie Cobbs  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31 92a3e552SArchie Cobbs  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
32 92a3e552SArchie Cobbs  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33 92a3e552SArchie Cobbs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 92a3e552SArchie Cobbs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 92a3e552SArchie Cobbs  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36 92a3e552SArchie Cobbs  * OF SUCH DAMAGE.
37 92a3e552SArchie Cobbs  *
38 cc3bbd68SJulian Elischer  * Author: Archie Cobbs <archie@freebsd.org>
39 92a3e552SArchie Cobbs  * $Whistle: ng_bpf.h,v 1.3 1999/12/03 20:30:23 archie Exp $
40 92a3e552SArchie Cobbs  */
41 92a3e552SArchie Cobbs 
42 e20480bfSRuslan Ermilov #ifndef _NETGRAPH_NG_BPF_H_
43 e20480bfSRuslan Ermilov #define _NETGRAPH_NG_BPF_H_
44 92a3e552SArchie Cobbs 
45 92a3e552SArchie Cobbs /* Node type name and magic cookie */
46 92a3e552SArchie Cobbs #define NG_BPF_NODE_TYPE	"bpf"
47 92a3e552SArchie Cobbs #define NGM_BPF_COOKIE		944100792
48 92a3e552SArchie Cobbs 
49 92a3e552SArchie Cobbs /* Program structure for one hook */
50 92a3e552SArchie Cobbs struct ng_bpf_hookprog {
51 87e2c66aSHartmut Brandt 	char		thisHook[NG_HOOKSIZ];		/* name of hook */
52 87e2c66aSHartmut Brandt 	char		ifMatch[NG_HOOKSIZ];		/* match dest hook */
53 87e2c66aSHartmut Brandt 	char		ifNotMatch[NG_HOOKSIZ];		/* !match dest hook */
54 3667c04dSRuslan Ermilov 	int32_t		bpf_prog_len;			/* #insns in program */
55 f3bfd2edSAlfred Perlstein 	struct bpf_insn	bpf_prog[];			/* bpf program */
56 92a3e552SArchie Cobbs };
57 92a3e552SArchie Cobbs 
58 ab0d3c94SArchie Cobbs #define NG_BPF_HOOKPROG_SIZE(numInsn)	\
59 ab0d3c94SArchie Cobbs 	(sizeof(struct ng_bpf_hookprog) + (numInsn) * sizeof(struct bpf_insn))
60 92a3e552SArchie Cobbs 
61 92a3e552SArchie Cobbs /* Keep this in sync with the above structure definition */
62 92a3e552SArchie Cobbs #define NG_BPF_HOOKPROG_TYPE_INFO(bptype)	{		\
63 92a3e552SArchie Cobbs 	  { "thisHook",		&ng_parse_hookbuf_type	},	\
64 92a3e552SArchie Cobbs 	  { "ifMatch",		&ng_parse_hookbuf_type	},	\
65 92a3e552SArchie Cobbs 	  { "ifNotMatch",	&ng_parse_hookbuf_type	},	\
66 92a3e552SArchie Cobbs 	  { "bpf_prog_len",	&ng_parse_int32_type	},	\
67 92a3e552SArchie Cobbs 	  { "bpf_prog",		(bptype)		},	\
68 f0184ff8SArchie Cobbs 	  { NULL }						\
69 92a3e552SArchie Cobbs }
70 92a3e552SArchie Cobbs 
71 92a3e552SArchie Cobbs /* Statistics structure for one hook */
72 92a3e552SArchie Cobbs struct ng_bpf_hookstat {
73 92a3e552SArchie Cobbs 	u_int64_t	recvFrames;
74 92a3e552SArchie Cobbs 	u_int64_t	recvOctets;
75 92a3e552SArchie Cobbs 	u_int64_t	recvMatchFrames;
76 92a3e552SArchie Cobbs 	u_int64_t	recvMatchOctets;
77 92a3e552SArchie Cobbs 	u_int64_t	xmitFrames;
78 92a3e552SArchie Cobbs 	u_int64_t	xmitOctets;
79 92a3e552SArchie Cobbs };
80 92a3e552SArchie Cobbs 
81 92a3e552SArchie Cobbs /* Keep this in sync with the above structure definition */
82 92a3e552SArchie Cobbs #define NG_BPF_HOOKSTAT_TYPE_INFO	{			\
83 57b57be3SArchie Cobbs 	  { "recvFrames",	&ng_parse_uint64_type	},	\
84 57b57be3SArchie Cobbs 	  { "recvOctets",	&ng_parse_uint64_type	},	\
85 57b57be3SArchie Cobbs 	  { "recvMatchFrames",	&ng_parse_uint64_type	},	\
86 57b57be3SArchie Cobbs 	  { "recvMatchOctets",	&ng_parse_uint64_type	},	\
87 57b57be3SArchie Cobbs 	  { "xmitFrames",	&ng_parse_uint64_type	},	\
88 57b57be3SArchie Cobbs 	  { "xmitOctets",	&ng_parse_uint64_type	},	\
89 f0184ff8SArchie Cobbs 	  { NULL }						\
90 92a3e552SArchie Cobbs }
91 92a3e552SArchie Cobbs 
92 92a3e552SArchie Cobbs /* Netgraph commands */
93 92a3e552SArchie Cobbs enum {
94 92a3e552SArchie Cobbs 	NGM_BPF_SET_PROGRAM = 1,	/* supply a struct ng_bpf_hookprog */
95 92a3e552SArchie Cobbs 	NGM_BPF_GET_PROGRAM,		/* returns a struct ng_bpf_hookprog */
96 87e2c66aSHartmut Brandt 	NGM_BPF_GET_STATS,		/* supply name as char[NG_HOOKSIZ] */
97 87e2c66aSHartmut Brandt 	NGM_BPF_CLR_STATS,		/* supply name as char[NG_HOOKSIZ] */
98 87e2c66aSHartmut Brandt 	NGM_BPF_GETCLR_STATS,		/* supply name as char[NG_HOOKSIZ] */
99 92a3e552SArchie Cobbs };
100 92a3e552SArchie Cobbs 
101 e20480bfSRuslan Ermilov #endif /* _NETGRAPH_NG_BPF_H_ */
102