xref: /freebsd/sys/netgraph/ng_message.h (revision 4064a1108b51b24903c8d67db21e8dbaf89b475f)
14cf49a43SJulian Elischer /*
24cf49a43SJulian Elischer  * ng_message.h
3c398230bSWarner Losh  */
4c398230bSWarner Losh 
5c398230bSWarner Losh /*-
64cf49a43SJulian Elischer  * Copyright (c) 1996-1999 Whistle Communications, Inc.
74cf49a43SJulian Elischer  * All rights reserved.
84cf49a43SJulian Elischer  *
94cf49a43SJulian Elischer  * Subject to the following obligations and disclaimer of warranty, use and
104cf49a43SJulian Elischer  * redistribution of this software, in source or object code forms, with or
114cf49a43SJulian Elischer  * without modifications are expressly permitted by Whistle Communications;
124cf49a43SJulian Elischer  * provided, however, that:
134cf49a43SJulian Elischer  * 1. Any and all reproductions of the source or object code must include the
144cf49a43SJulian Elischer  *    copyright notice above and the following disclaimer of warranties; and
154cf49a43SJulian Elischer  * 2. No rights are granted, in any manner or form, to use Whistle
164cf49a43SJulian Elischer  *    Communications, Inc. trademarks, including the mark "WHISTLE
174cf49a43SJulian Elischer  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
184cf49a43SJulian Elischer  *    such appears in the above copyright notice or in the software.
194cf49a43SJulian Elischer  *
204cf49a43SJulian Elischer  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
214cf49a43SJulian Elischer  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
224cf49a43SJulian Elischer  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
234cf49a43SJulian Elischer  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
244cf49a43SJulian Elischer  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
254cf49a43SJulian Elischer  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
264cf49a43SJulian Elischer  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
274cf49a43SJulian Elischer  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
284cf49a43SJulian Elischer  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
294cf49a43SJulian Elischer  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
304cf49a43SJulian Elischer  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
314cf49a43SJulian Elischer  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
324cf49a43SJulian Elischer  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
334cf49a43SJulian Elischer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
344cf49a43SJulian Elischer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
354cf49a43SJulian Elischer  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
364cf49a43SJulian Elischer  * OF SUCH DAMAGE.
374cf49a43SJulian Elischer  *
38cc3bbd68SJulian Elischer  * Author: Julian Elischer <julian@freebsd.org>
394cf49a43SJulian Elischer  * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
404cf49a43SJulian Elischer  */
414cf49a43SJulian Elischer 
424cf49a43SJulian Elischer #ifndef _NETGRAPH_NG_MESSAGE_H_
43e20480bfSRuslan Ermilov #define _NETGRAPH_NG_MESSAGE_H_
444cf49a43SJulian Elischer 
45*4064a110SGleb Smirnoff /*
46*4064a110SGleb Smirnoff  * ASCII string size limits
47*4064a110SGleb Smirnoff  * Check with struct sockaddr_ng if changing.
48*4064a110SGleb Smirnoff  */
49387ebc6dSHartmut Brandt #define	NG_TYPESIZ	32	/* max type name len (including null) */
50387ebc6dSHartmut Brandt #define	NG_HOOKSIZ	32	/* max hook name len (including null) */
51387ebc6dSHartmut Brandt #define	NG_NODESIZ	32	/* max node name len (including null) */
52387ebc6dSHartmut Brandt #define	NG_PATHSIZ	512	/* max path len (including null) */
53387ebc6dSHartmut Brandt #define	NG_CMDSTRSIZ	32	/* max command string (including null) */
54387ebc6dSHartmut Brandt 
554cf49a43SJulian Elischer #define NG_TEXTRESPONSE 1024	/* allow this length for a text response */
564cf49a43SJulian Elischer 
574cf49a43SJulian Elischer /* A netgraph message */
584cf49a43SJulian Elischer struct ng_mesg {
594cf49a43SJulian Elischer 	struct	ng_msghdr {
60589f6ed8SJulian Elischer 		u_char		version;		/*  == NGM_VERSION */
614feaf224SGleb Smirnoff 		u_char		spare;			/* pad to 4 bytes */
624feaf224SGleb Smirnoff 		u_int16_t	spare2;
634feaf224SGleb Smirnoff 		u_int32_t	arglen;			/* length of data */
64f036d408SJulian Elischer 		u_int32_t	cmd;			/* command identifier */
654cf49a43SJulian Elischer 		u_int32_t	flags;			/* message status */
664cf49a43SJulian Elischer 		u_int32_t	token;			/* match with reply */
674cf49a43SJulian Elischer 		u_int32_t	typecookie;		/* node's type cookie */
6887e2c66aSHartmut Brandt 		u_char		cmdstr[NG_CMDSTRSIZ];	/* cmd string + \0 */
694cf49a43SJulian Elischer 	} header;
700eecad8dSHartmut Brandt 	char	data[];			/* placeholder for actual data */
714cf49a43SJulian Elischer };
72f8307e12SArchie Cobbs 
732df050adSGleb Smirnoff /* This command is guaranteed to not alter data (or'd into the command). */
74069154d5SJulian Elischer #define NGM_READONLY	0x10000000
752df050adSGleb Smirnoff /* This command is guaranteed to have a reply (or'd into the command). */
762df050adSGleb Smirnoff #define NGM_HASREPLY	0x20000000
77589f6ed8SJulian Elischer 
78f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
79f8307e12SArchie Cobbs #define NG_GENERIC_NG_MESG_INFO(dtype)	{			\
8057b57be3SArchie Cobbs 	  { "version",		&ng_parse_uint8_type	},	\
8157b57be3SArchie Cobbs 	  { "spare",		&ng_parse_uint8_type	},	\
824feaf224SGleb Smirnoff 	  { "spare2",		&ng_parse_uint16_type	},	\
834feaf224SGleb Smirnoff 	  { "arglen",		&ng_parse_uint32_type	},	\
84f036d408SJulian Elischer 	  { "cmd",		&ng_parse_uint32_type	},	\
8557b57be3SArchie Cobbs 	  { "flags",		&ng_parse_hint32_type	},	\
8657b57be3SArchie Cobbs 	  { "token",		&ng_parse_uint32_type	},	\
8757b57be3SArchie Cobbs 	  { "typecookie",	&ng_parse_uint32_type	},	\
88f8307e12SArchie Cobbs 	  { "cmdstr",		&ng_parse_cmdbuf_type	},	\
89f8307e12SArchie Cobbs 	  { "data",		(dtype)			},	\
90f0184ff8SArchie Cobbs 	  { NULL }						\
91f8307e12SArchie Cobbs }
92f8307e12SArchie Cobbs 
93589f6ed8SJulian Elischer /*
94589f6ed8SJulian Elischer  * Netgraph message header compatibility field
95589f6ed8SJulian Elischer  * Interfaces within the kernel are defined by a different
964feaf224SGleb Smirnoff  * value (see NG_ABI_VERSION in netgraph.h)
97589f6ed8SJulian Elischer  */
984feaf224SGleb Smirnoff #define NG_VERSION	8
99f8307e12SArchie Cobbs 
100f8307e12SArchie Cobbs /* Flags field flags */
101069154d5SJulian Elischer #define NGF_ORIG	0x00000000	/* the msg is the original request */
102069154d5SJulian Elischer #define NGF_RESP	0x00000001	/* the message is a response */
1031acb27c6SJulian Elischer 
104bb964e74SGleb Smirnoff /* Type of a unique node ID. */
105bb964e74SGleb Smirnoff #define ng_ID_t uint32_t
106f8307e12SArchie Cobbs 
1074cf49a43SJulian Elischer /*
1084cf49a43SJulian Elischer  * Here we describe the "generic" messages that all nodes inherently
1094cf49a43SJulian Elischer  * understand. With the exception of NGM_TEXT_STATUS, these are handled
1104cf49a43SJulian Elischer  * automatically by the base netgraph code.
1114cf49a43SJulian Elischer  */
1124cf49a43SJulian Elischer 
1134cf49a43SJulian Elischer /* Generic message type cookie */
1142df050adSGleb Smirnoff #define NGM_GENERIC_COOKIE	1137070366
1154cf49a43SJulian Elischer 
1162df050adSGleb Smirnoff /* Generic messages defined for this type cookie. */
1172df050adSGleb Smirnoff enum {
1182df050adSGleb Smirnoff 	NGM_SHUTDOWN	= 1,	/* Shut down node. */
1192df050adSGleb Smirnoff 	NGM_MKPEER	= 2,	/* Create and attach a peer node. */
1202df050adSGleb Smirnoff 	NGM_CONNECT	= 3,	/* Connect two nodes. */
1212df050adSGleb Smirnoff 	NGM_NAME	= 4,	/* Give a node a name. */
1222df050adSGleb Smirnoff 	NGM_RMHOOK	= 5,	/* Break a connection between two nodes. */
1232df050adSGleb Smirnoff 
1242df050adSGleb Smirnoff 	/* Get nodeinfo for target. */
1252df050adSGleb Smirnoff 	NGM_NODEINFO	= (6|NGM_READONLY|NGM_HASREPLY),
1262df050adSGleb Smirnoff 	/* Get list of hooks on node. */
1272df050adSGleb Smirnoff 	NGM_LISTHOOKS	= (7|NGM_READONLY|NGM_HASREPLY),
1282df050adSGleb Smirnoff 	/* List globally named nodes. */
1292df050adSGleb Smirnoff 	NGM_LISTNAMES	= (8|NGM_READONLY|NGM_HASREPLY),
1302df050adSGleb Smirnoff 	/* List all nodes. */
1312df050adSGleb Smirnoff 	NGM_LISTNODES	= (9|NGM_READONLY|NGM_HASREPLY),
1322df050adSGleb Smirnoff 	/* List installed node types. */
1332df050adSGleb Smirnoff 	NGM_LISTTYPES	= (10|NGM_READONLY|NGM_HASREPLY),
1342df050adSGleb Smirnoff 	/* (optional) Get text status. */
1352df050adSGleb Smirnoff 	NGM_TEXT_STATUS	= (11|NGM_READONLY|NGM_HASREPLY),
1362df050adSGleb Smirnoff 	/* Convert struct ng_mesg to ASCII. */
1372df050adSGleb Smirnoff 	NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
1382df050adSGleb Smirnoff 	/* Convert ASCII to struct ng_mesg. */
1392df050adSGleb Smirnoff 	NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
1402df050adSGleb Smirnoff 	/* (optional) Get/set text config. */
1412df050adSGleb Smirnoff 	NGM_TEXT_CONFIG	= 14,
1422df050adSGleb Smirnoff };
1434cf49a43SJulian Elischer 
144859a4d16SJulian Elischer /*
145859a4d16SJulian Elischer  * Flow control and intra node control messages.
146859a4d16SJulian Elischer  * These are routed between nodes to allow flow control and to allow
147859a4d16SJulian Elischer  * events to be passed around the graph.
148859a4d16SJulian Elischer  * There will be some form of default handling for these but I
149859a4d16SJulian Elischer  * do not yet know what it is..
150859a4d16SJulian Elischer  */
151859a4d16SJulian Elischer 
152859a4d16SJulian Elischer /* Generic message type cookie */
153859a4d16SJulian Elischer #define NGM_FLOW_COOKIE	851672669 /* temp for debugging */
154859a4d16SJulian Elischer 
155859a4d16SJulian Elischer /* Upstream messages */
156859a4d16SJulian Elischer #define NGM_LINK_IS_UP		32	/* e.g. carrier found - no data */
157859a4d16SJulian Elischer #define NGM_LINK_IS_DOWN	33	/* carrier lost, includes queue state */
158859a4d16SJulian Elischer #define NGM_HIGH_WATER_PASSED	34	/* includes queue state */
159859a4d16SJulian Elischer #define NGM_LOW_WATER_PASSED	35	/* includes queue state */
160859a4d16SJulian Elischer #define NGM_SYNC_QUEUE_STATE	36	/* sync response from sending packet */
161859a4d16SJulian Elischer 
162859a4d16SJulian Elischer /* Downstream messages */
163859a4d16SJulian Elischer #define NGM_DROP_LINK		41	/* drop DTR, etc. - stay in the graph */
164b57a7965SJulian Elischer #define NGM_RAISE_LINK		42	/* if you previously dropped it */
165859a4d16SJulian Elischer #define NGM_FLUSH_QUEUE		43	/* no data */
166069154d5SJulian Elischer #define NGM_GET_BANDWIDTH	(44|NGM_READONLY)	/* either real or measured */
167859a4d16SJulian Elischer #define NGM_SET_XMIT_Q_LIMITS	45	/* includes queue state */
168069154d5SJulian Elischer #define NGM_GET_XMIT_Q_LIMITS	(46|NGM_READONLY)	/* returns queue state */
169069154d5SJulian Elischer #define NGM_MICROMANAGE		47	/* We want sync. queue state
170069154d5SJulian Elischer 						reply for each packet sent */
171859a4d16SJulian Elischer #define NGM_SET_FLOW_MANAGER	48	/* send flow control here */
172f8307e12SArchie Cobbs /* Structure used for NGM_MKPEER */
1734cf49a43SJulian Elischer struct ngm_mkpeer {
17487e2c66aSHartmut Brandt 	char	type[NG_TYPESIZ];		/* peer type */
17587e2c66aSHartmut Brandt 	char	ourhook[NG_HOOKSIZ];		/* hook name */
17687e2c66aSHartmut Brandt 	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
1774cf49a43SJulian Elischer };
1784cf49a43SJulian Elischer 
179f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
180f8307e12SArchie Cobbs #define NG_GENERIC_MKPEER_INFO()	{			\
181f8307e12SArchie Cobbs 	  { "type",		&ng_parse_typebuf_type	},	\
182f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
183f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
184f0184ff8SArchie Cobbs 	  { NULL }						\
185f8307e12SArchie Cobbs }
186f8307e12SArchie Cobbs 
187f8307e12SArchie Cobbs /* Structure used for NGM_CONNECT */
1884cf49a43SJulian Elischer struct ngm_connect {
18987e2c66aSHartmut Brandt 	char	path[NG_PATHSIZ];		/* peer path */
19087e2c66aSHartmut Brandt 	char	ourhook[NG_HOOKSIZ];		/* hook name */
19187e2c66aSHartmut Brandt 	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
1924cf49a43SJulian Elischer };
1934cf49a43SJulian Elischer 
194f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
195f8307e12SArchie Cobbs #define NG_GENERIC_CONNECT_INFO()	{			\
196f8307e12SArchie Cobbs 	  { "path",		&ng_parse_pathbuf_type	},	\
197f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
198f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
199f0184ff8SArchie Cobbs 	  { NULL }						\
200f8307e12SArchie Cobbs }
201f8307e12SArchie Cobbs 
202f8307e12SArchie Cobbs /* Structure used for NGM_NAME */
2034cf49a43SJulian Elischer struct ngm_name {
20487e2c66aSHartmut Brandt 	char	name[NG_NODESIZ];			/* node name */
2054cf49a43SJulian Elischer };
2064cf49a43SJulian Elischer 
207f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
208f8307e12SArchie Cobbs #define NG_GENERIC_NAME_INFO()	{				\
209f8307e12SArchie Cobbs 	  { "name",		&ng_parse_nodebuf_type	},	\
210f0184ff8SArchie Cobbs 	  { NULL }						\
211f8307e12SArchie Cobbs }
212f8307e12SArchie Cobbs 
213f8307e12SArchie Cobbs /* Structure used for NGM_RMHOOK */
2144cf49a43SJulian Elischer struct ngm_rmhook {
21587e2c66aSHartmut Brandt 	char	ourhook[NG_HOOKSIZ];		/* hook name */
2164cf49a43SJulian Elischer };
2174cf49a43SJulian Elischer 
218f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
219f8307e12SArchie Cobbs #define NG_GENERIC_RMHOOK_INFO()	{			\
220f8307e12SArchie Cobbs 	  { "hook",		&ng_parse_hookbuf_type	},	\
221f0184ff8SArchie Cobbs 	  { NULL }						\
222f8307e12SArchie Cobbs }
223f8307e12SArchie Cobbs 
224f8307e12SArchie Cobbs /* Structure used for NGM_NODEINFO */
2254cf49a43SJulian Elischer struct nodeinfo {
22687e2c66aSHartmut Brandt 	char		name[NG_NODESIZ];	/* node name (if any) */
22787e2c66aSHartmut Brandt         char    	type[NG_TYPESIZ];	/* peer type */
228dc90cad9SJulian Elischer 	ng_ID_t		id;			/* unique identifier */
2294cf49a43SJulian Elischer 	u_int32_t	hooks;			/* number of active hooks */
2304cf49a43SJulian Elischer };
2314cf49a43SJulian Elischer 
232f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
233f8307e12SArchie Cobbs #define NG_GENERIC_NODEINFO_INFO()	{			\
234f8307e12SArchie Cobbs 	  { "name",		&ng_parse_nodebuf_type	},	\
235f8307e12SArchie Cobbs 	  { "type",		&ng_parse_typebuf_type	},	\
23657b57be3SArchie Cobbs 	  { "id",		&ng_parse_hint32_type	},	\
23757b57be3SArchie Cobbs 	  { "hooks",		&ng_parse_uint32_type	},	\
238f0184ff8SArchie Cobbs 	  { NULL }						\
239f8307e12SArchie Cobbs }
240f8307e12SArchie Cobbs 
241f8307e12SArchie Cobbs /* Structure used for NGM_LISTHOOKS */
2424cf49a43SJulian Elischer struct linkinfo {
24387e2c66aSHartmut Brandt 	char		ourhook[NG_HOOKSIZ];	/* hook name */
24487e2c66aSHartmut Brandt 	char		peerhook[NG_HOOKSIZ];	/* peer hook */
2454cf49a43SJulian Elischer 	struct nodeinfo	nodeinfo;
2464cf49a43SJulian Elischer };
2474cf49a43SJulian Elischer 
248f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
249f8307e12SArchie Cobbs #define NG_GENERIC_LINKINFO_INFO(nitype)	{		\
250f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
251f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
252f8307e12SArchie Cobbs 	  { "nodeinfo",		(nitype)		},	\
253f0184ff8SArchie Cobbs 	  { NULL }						\
254f8307e12SArchie Cobbs }
255f8307e12SArchie Cobbs 
2564cf49a43SJulian Elischer struct hooklist {
2574cf49a43SJulian Elischer 	struct nodeinfo nodeinfo;		/* node information */
2580eecad8dSHartmut Brandt 	struct linkinfo link[];			/* info about each hook */
2594cf49a43SJulian Elischer };
2604cf49a43SJulian Elischer 
261f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
262f8307e12SArchie Cobbs #define NG_GENERIC_HOOKLIST_INFO(nitype,litype)	{		\
263f8307e12SArchie Cobbs 	  { "nodeinfo",		(nitype)		},	\
264f8307e12SArchie Cobbs 	  { "linkinfo",		(litype)		},	\
265f0184ff8SArchie Cobbs 	  { NULL }						\
266f8307e12SArchie Cobbs }
267f8307e12SArchie Cobbs 
268f8307e12SArchie Cobbs /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
2694cf49a43SJulian Elischer struct namelist {
2704cf49a43SJulian Elischer 	u_int32_t	numnames;
2710eecad8dSHartmut Brandt 	struct nodeinfo	nodeinfo[];
2724cf49a43SJulian Elischer };
2734cf49a43SJulian Elischer 
274f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
275f8307e12SArchie Cobbs #define NG_GENERIC_LISTNODES_INFO(niarraytype)	{		\
27657b57be3SArchie Cobbs 	  { "numnames",		&ng_parse_uint32_type	},	\
277f8307e12SArchie Cobbs 	  { "nodeinfo",		(niarraytype)		},	\
278f0184ff8SArchie Cobbs 	  { NULL }						\
279f8307e12SArchie Cobbs }
280f8307e12SArchie Cobbs 
281f8307e12SArchie Cobbs /* Structure used for NGM_LISTTYPES */
2824cf49a43SJulian Elischer struct typeinfo {
28387e2c66aSHartmut Brandt 	char		type_name[NG_TYPESIZ];	/* name of type */
2844cf49a43SJulian Elischer 	u_int32_t	numnodes;		/* number alive */
2854cf49a43SJulian Elischer };
2864cf49a43SJulian Elischer 
287f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
288f8307e12SArchie Cobbs #define NG_GENERIC_TYPEINFO_INFO()		{		\
289f8307e12SArchie Cobbs 	  { "typename",		&ng_parse_typebuf_type	},	\
29057b57be3SArchie Cobbs 	  { "numnodes",		&ng_parse_uint32_type	},	\
291f0184ff8SArchie Cobbs 	  { NULL }						\
292f8307e12SArchie Cobbs }
293f8307e12SArchie Cobbs 
2944cf49a43SJulian Elischer struct typelist {
2954cf49a43SJulian Elischer 	u_int32_t	numtypes;
2960eecad8dSHartmut Brandt 	struct typeinfo	typeinfo[];
2974cf49a43SJulian Elischer };
2984cf49a43SJulian Elischer 
299f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
300f8307e12SArchie Cobbs #define NG_GENERIC_TYPELIST_INFO(tiarraytype)	{		\
30157b57be3SArchie Cobbs 	  { "numtypes",		&ng_parse_uint32_type	},	\
302f8307e12SArchie Cobbs 	  { "typeinfo",		(tiarraytype)		},	\
303f0184ff8SArchie Cobbs 	  { NULL }						\
304f8307e12SArchie Cobbs }
305f8307e12SArchie Cobbs 
306859a4d16SJulian Elischer struct ngm_bandwidth {
307859a4d16SJulian Elischer 	u_int64_t	nominal_in;
308859a4d16SJulian Elischer 	u_int64_t	seen_in;
309859a4d16SJulian Elischer 	u_int64_t	nominal_out;
310859a4d16SJulian Elischer 	u_int64_t	seen_out;
311859a4d16SJulian Elischer };
312859a4d16SJulian Elischer 
313859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */
314859a4d16SJulian Elischer #define NG_GENERIC_BANDWIDTH_INFO()	{			\
315859a4d16SJulian Elischer 	  { "nominal_in",	&ng_parse_uint64_type	},	\
316859a4d16SJulian Elischer 	  { "seen_in",		&ng_parse_uint64_type	},	\
317859a4d16SJulian Elischer 	  { "nominal_out",	&ng_parse_uint64_type	},	\
318859a4d16SJulian Elischer 	  { "seen_out",		&ng_parse_uint64_type	},	\
319f0184ff8SArchie Cobbs 	  { NULL }						\
320859a4d16SJulian Elischer }
321859a4d16SJulian Elischer 
322859a4d16SJulian Elischer /*
323859a4d16SJulian Elischer  * Information about a node's 'output' queue.
324859a4d16SJulian Elischer  * This is NOT the netgraph input queueing mechanism,
325859a4d16SJulian Elischer  * but rather any queue the node may implement internally
326859a4d16SJulian Elischer  * This has to consider ALTQ if we are to work with it.
327859a4d16SJulian Elischer  * As far as I can see, ALTQ counts PACKETS, not bytes.
328859a4d16SJulian Elischer  * If ALTQ has several queues and one has passed a watermark
329859a4d16SJulian Elischer  * we should have the priority of that queue be real (and not -1)
330859a4d16SJulian Elischer  * XXX ALTQ stuff is just an idea.....
331859a4d16SJulian Elischer  */
332859a4d16SJulian Elischer struct ngm_queue_state {
333859a4d16SJulian Elischer 	u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
334859a4d16SJulian Elischer 	u_int	max_queuelen_bytes;
335859a4d16SJulian Elischer 	u_int	max_queuelen_packets;
336859a4d16SJulian Elischer 	u_int	low_watermark;
337859a4d16SJulian Elischer 	u_int	high_watermark;
338859a4d16SJulian Elischer 	u_int	current;
339859a4d16SJulian Elischer };
340859a4d16SJulian Elischer 
341859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */
342859a4d16SJulian Elischer #define NG_GENERIC_QUEUE_INFO()	{				\
343859a4d16SJulian Elischer 	  { "max_queuelen_bytes", &ng_parse_uint_type	},	\
344859a4d16SJulian Elischer 	  { "max_queuelen_packets", &ng_parse_uint_type	},	\
345859a4d16SJulian Elischer 	  { "high_watermark",	&ng_parse_uint_type	},	\
346859a4d16SJulian Elischer 	  { "low_watermark",	&ng_parse_uint_type	},	\
347859a4d16SJulian Elischer 	  { "current",		&ng_parse_uint_type	},	\
348f0184ff8SArchie Cobbs 	  { NULL }						\
349859a4d16SJulian Elischer }
350859a4d16SJulian Elischer 
351859a4d16SJulian Elischer /* Tell a node who to send async flow control info to. */
352859a4d16SJulian Elischer struct flow_manager {
353859a4d16SJulian Elischer 	ng_ID_t		id;			/* unique identifier */
354859a4d16SJulian Elischer };
355859a4d16SJulian Elischer 
356859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */
357859a4d16SJulian Elischer #define NG_GENERIC_FLOW_MANAGER_INFO()	{			\
358859a4d16SJulian Elischer 	  { "id",		&ng_parse_hint32_type	},	\
359f0184ff8SArchie Cobbs 	  { NULL }						\
360859a4d16SJulian Elischer }
361859a4d16SJulian Elischer 
3624cf49a43SJulian Elischer /*
3634cf49a43SJulian Elischer  * For netgraph nodes that are somehow associated with file descriptors
3644cf49a43SJulian Elischer  * (e.g., a device that has a /dev entry and is also a netgraph node),
3654cf49a43SJulian Elischer  * we define a generic ioctl for requesting the corresponding nodeinfo
3664cf49a43SJulian Elischer  * structure and for assigning a name (if there isn't one already).
3674cf49a43SJulian Elischer  *
3684cf49a43SJulian Elischer  * For these to you need to also #include <sys/ioccom.h>.
3694cf49a43SJulian Elischer  */
3704cf49a43SJulian Elischer 
3714cf49a43SJulian Elischer #define NGIOCGINFO	_IOR('N', 40, struct nodeinfo)	/* get node info */
3724cf49a43SJulian Elischer #define NGIOCSETNAME	_IOW('N', 41, struct ngm_name)	/* set node name */
3734cf49a43SJulian Elischer 
374664a31e4SPeter Wemm #ifdef _KERNEL
3754cf49a43SJulian Elischer /*
3764cf49a43SJulian Elischer  * Allocate and initialize a netgraph message "msg" with "len"
3774cf49a43SJulian Elischer  * extra bytes of argument. Sets "msg" to NULL if fails.
3784cf49a43SJulian Elischer  * Does not initialize token.
3794cf49a43SJulian Elischer  */
3804cf49a43SJulian Elischer #define NG_MKMESSAGE(msg, cookie, cmdid, len, how)			\
3814cf49a43SJulian Elischer 	do {								\
3821ede983cSDag-Erling Smørgrav 	  (msg) = malloc(sizeof(struct ng_mesg)				\
383069154d5SJulian Elischer 	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
3844cf49a43SJulian Elischer 	  if ((msg) == NULL)						\
3854cf49a43SJulian Elischer 	    break;							\
3864cf49a43SJulian Elischer 	  (msg)->header.version = NG_VERSION;				\
3874cf49a43SJulian Elischer 	  (msg)->header.typecookie = (cookie);				\
3884cf49a43SJulian Elischer 	  (msg)->header.cmd = (cmdid);					\
3894cf49a43SJulian Elischer 	  (msg)->header.arglen = (len);					\
3904cf49a43SJulian Elischer 	  strncpy((msg)->header.cmdstr, #cmdid,				\
3914cf49a43SJulian Elischer 	    sizeof((msg)->header.cmdstr) - 1);				\
3924cf49a43SJulian Elischer 	} while (0)
3934cf49a43SJulian Elischer 
3944cf49a43SJulian Elischer /*
3954cf49a43SJulian Elischer  * Allocate and initialize a response "rsp" to a message "msg"
3964cf49a43SJulian Elischer  * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
3974cf49a43SJulian Elischer  */
3984cf49a43SJulian Elischer #define NG_MKRESPONSE(rsp, msg, len, how)				\
3994cf49a43SJulian Elischer 	do {								\
4001ede983cSDag-Erling Smørgrav 	  (rsp) = malloc(sizeof(struct ng_mesg)				\
401069154d5SJulian Elischer 	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
4024cf49a43SJulian Elischer 	  if ((rsp) == NULL)						\
4034cf49a43SJulian Elischer 	    break;							\
4044cf49a43SJulian Elischer 	  (rsp)->header.version = NG_VERSION;				\
4054cf49a43SJulian Elischer 	  (rsp)->header.arglen = (len);					\
4064cf49a43SJulian Elischer 	  (rsp)->header.token = (msg)->header.token;			\
4074cf49a43SJulian Elischer 	  (rsp)->header.typecookie = (msg)->header.typecookie;		\
4084cf49a43SJulian Elischer 	  (rsp)->header.cmd = (msg)->header.cmd;			\
4094cf49a43SJulian Elischer 	  bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr,		\
4104cf49a43SJulian Elischer 	    sizeof((rsp)->header.cmdstr));				\
4114cf49a43SJulian Elischer 	  (rsp)->header.flags |= NGF_RESP;				\
4124cf49a43SJulian Elischer 	} while (0)
413644168eeSGleb Smirnoff 
414644168eeSGleb Smirnoff /*
415644168eeSGleb Smirnoff  * Make a copy of message. Sets "copy" to NULL if fails.
416644168eeSGleb Smirnoff  */
417644168eeSGleb Smirnoff #define	NG_COPYMESSAGE(copy, msg, how)					\
418644168eeSGleb Smirnoff 	do {								\
4191ede983cSDag-Erling Smørgrav 	  (copy) = malloc(sizeof(struct ng_mesg)			\
4201ede983cSDag-Erling Smørgrav 	    + (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO);	\
421644168eeSGleb Smirnoff 	  if ((copy) == NULL)						\
422644168eeSGleb Smirnoff 	    break;							\
423644168eeSGleb Smirnoff 	  (copy)->header.version = NG_VERSION;				\
424644168eeSGleb Smirnoff 	  (copy)->header.arglen = (msg)->header.arglen;			\
425644168eeSGleb Smirnoff 	  (copy)->header.token = (msg)->header.token;			\
426644168eeSGleb Smirnoff 	  (copy)->header.typecookie = (msg)->header.typecookie;		\
427644168eeSGleb Smirnoff 	  (copy)->header.cmd = (msg)->header.cmd;			\
428644168eeSGleb Smirnoff 	  (copy)->header.flags = (msg)->header.flags;			\
429644168eeSGleb Smirnoff 	  bcopy((msg)->header.cmdstr, (copy)->header.cmdstr,		\
430644168eeSGleb Smirnoff 	    sizeof((copy)->header.cmdstr));				\
431644168eeSGleb Smirnoff 	  if ((msg)->header.arglen > 0)					\
432644168eeSGleb Smirnoff 	    bcopy((msg)->data, (copy)->data, (msg)->header.arglen);	\
433644168eeSGleb Smirnoff 	} while (0)
434644168eeSGleb Smirnoff 
435664a31e4SPeter Wemm #endif /* _KERNEL */
4364cf49a43SJulian Elischer 
4374cf49a43SJulian Elischer #endif /* _NETGRAPH_NG_MESSAGE_H_ */
438