1*3b2bd0f6Slogwang /*
2*3b2bd0f6Slogwang  * ng_message.h
3*3b2bd0f6Slogwang  */
4*3b2bd0f6Slogwang 
5*3b2bd0f6Slogwang /*-
6*3b2bd0f6Slogwang  * Copyright (c) 1996-1999 Whistle Communications, Inc.
7*3b2bd0f6Slogwang  * All rights reserved.
8*3b2bd0f6Slogwang  *
9*3b2bd0f6Slogwang  * Subject to the following obligations and disclaimer of warranty, use and
10*3b2bd0f6Slogwang  * redistribution of this software, in source or object code forms, with or
11*3b2bd0f6Slogwang  * without modifications are expressly permitted by Whistle Communications;
12*3b2bd0f6Slogwang  * provided, however, that:
13*3b2bd0f6Slogwang  * 1. Any and all reproductions of the source or object code must include the
14*3b2bd0f6Slogwang  *    copyright notice above and the following disclaimer of warranties; and
15*3b2bd0f6Slogwang  * 2. No rights are granted, in any manner or form, to use Whistle
16*3b2bd0f6Slogwang  *    Communications, Inc. trademarks, including the mark "WHISTLE
17*3b2bd0f6Slogwang  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
18*3b2bd0f6Slogwang  *    such appears in the above copyright notice or in the software.
19*3b2bd0f6Slogwang  *
20*3b2bd0f6Slogwang  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
21*3b2bd0f6Slogwang  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
22*3b2bd0f6Slogwang  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
23*3b2bd0f6Slogwang  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
24*3b2bd0f6Slogwang  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
25*3b2bd0f6Slogwang  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
26*3b2bd0f6Slogwang  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
27*3b2bd0f6Slogwang  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
28*3b2bd0f6Slogwang  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
29*3b2bd0f6Slogwang  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
30*3b2bd0f6Slogwang  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31*3b2bd0f6Slogwang  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
32*3b2bd0f6Slogwang  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33*3b2bd0f6Slogwang  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34*3b2bd0f6Slogwang  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35*3b2bd0f6Slogwang  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36*3b2bd0f6Slogwang  * OF SUCH DAMAGE.
37*3b2bd0f6Slogwang  *
38*3b2bd0f6Slogwang  * Author: Julian Elischer <[email protected]>
39*3b2bd0f6Slogwang  *
40*3b2bd0f6Slogwang  * $FreeBSD$
41*3b2bd0f6Slogwang  * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
42*3b2bd0f6Slogwang  */
43*3b2bd0f6Slogwang 
44*3b2bd0f6Slogwang #ifndef _NETGRAPH_NG_MESSAGE_H_
45*3b2bd0f6Slogwang #define _NETGRAPH_NG_MESSAGE_H_
46*3b2bd0f6Slogwang 
47*3b2bd0f6Slogwang #include <stdint.h>
48*3b2bd0f6Slogwang 
49*3b2bd0f6Slogwang /* ASCII string size limits */
50*3b2bd0f6Slogwang #define	NG_TYPESIZ	32	/* max type name len (including null) */
51*3b2bd0f6Slogwang #define	NG_HOOKSIZ	32	/* max hook name len (including null) */
52*3b2bd0f6Slogwang #define	NG_NODESIZ	32	/* max node name len (including null) */
53*3b2bd0f6Slogwang #define	NG_PATHSIZ	512	/* max path len (including null) */
54*3b2bd0f6Slogwang #define	NG_CMDSTRSIZ	32	/* max command string (including null) */
55*3b2bd0f6Slogwang 
56*3b2bd0f6Slogwang #define NG_TEXTRESPONSE 1024	/* allow this length for a text response */
57*3b2bd0f6Slogwang 
58*3b2bd0f6Slogwang /* A netgraph message */
59*3b2bd0f6Slogwang struct ng_mesg {
60*3b2bd0f6Slogwang 	struct	ng_msghdr {
61*3b2bd0f6Slogwang 		u_char		version;		/*  == NGM_VERSION */
62*3b2bd0f6Slogwang 		u_char		spare;			/* pad to 4 bytes */
63*3b2bd0f6Slogwang 		u_int16_t	spare2;
64*3b2bd0f6Slogwang 		u_int32_t	arglen;			/* length of data */
65*3b2bd0f6Slogwang 		u_int32_t	cmd;			/* command identifier */
66*3b2bd0f6Slogwang 		u_int32_t	flags;			/* message status */
67*3b2bd0f6Slogwang 		u_int32_t	token;			/* match with reply */
68*3b2bd0f6Slogwang 		u_int32_t	typecookie;		/* node's type cookie */
69*3b2bd0f6Slogwang 		u_char		cmdstr[NG_CMDSTRSIZ];	/* cmd string + \0 */
70*3b2bd0f6Slogwang 	} header;
71*3b2bd0f6Slogwang 	char	data[];			/* placeholder for actual data */
72*3b2bd0f6Slogwang };
73*3b2bd0f6Slogwang 
74*3b2bd0f6Slogwang /* This command is guaranteed to not alter data (or'd into the command). */
75*3b2bd0f6Slogwang #define NGM_READONLY	0x10000000
76*3b2bd0f6Slogwang /* This command is guaranteed to have a reply (or'd into the command). */
77*3b2bd0f6Slogwang #define NGM_HASREPLY	0x20000000
78*3b2bd0f6Slogwang 
79*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
80*3b2bd0f6Slogwang #define NG_GENERIC_NG_MESG_INFO(dtype)	{			\
81*3b2bd0f6Slogwang 	  { "version",		&ng_parse_uint8_type	},	\
82*3b2bd0f6Slogwang 	  { "spare",		&ng_parse_uint8_type	},	\
83*3b2bd0f6Slogwang 	  { "spare2",		&ng_parse_uint16_type	},	\
84*3b2bd0f6Slogwang 	  { "arglen",		&ng_parse_uint32_type	},	\
85*3b2bd0f6Slogwang 	  { "cmd",		&ng_parse_uint32_type	},	\
86*3b2bd0f6Slogwang 	  { "flags",		&ng_parse_hint32_type	},	\
87*3b2bd0f6Slogwang 	  { "token",		&ng_parse_uint32_type	},	\
88*3b2bd0f6Slogwang 	  { "typecookie",	&ng_parse_uint32_type	},	\
89*3b2bd0f6Slogwang 	  { "cmdstr",		&ng_parse_cmdbuf_type	},	\
90*3b2bd0f6Slogwang 	  { "data",		(dtype)			},	\
91*3b2bd0f6Slogwang 	  { NULL }						\
92*3b2bd0f6Slogwang }
93*3b2bd0f6Slogwang 
94*3b2bd0f6Slogwang /*
95*3b2bd0f6Slogwang  * Netgraph message header compatibility field
96*3b2bd0f6Slogwang  * Interfaces within the kernel are defined by a different
97*3b2bd0f6Slogwang  * value (see NG_ABI_VERSION in netgraph.h)
98*3b2bd0f6Slogwang  */
99*3b2bd0f6Slogwang #define NG_VERSION	8
100*3b2bd0f6Slogwang 
101*3b2bd0f6Slogwang /* Flags field flags */
102*3b2bd0f6Slogwang #define NGF_ORIG	0x00000000	/* the msg is the original request */
103*3b2bd0f6Slogwang #define NGF_RESP	0x00000001	/* the message is a response */
104*3b2bd0f6Slogwang 
105*3b2bd0f6Slogwang /* Type of a unique node ID. */
106*3b2bd0f6Slogwang #define ng_ID_t uint32_t
107*3b2bd0f6Slogwang 
108*3b2bd0f6Slogwang /*
109*3b2bd0f6Slogwang  * Here we describe the "generic" messages that all nodes inherently
110*3b2bd0f6Slogwang  * understand. With the exception of NGM_TEXT_STATUS, these are handled
111*3b2bd0f6Slogwang  * automatically by the base netgraph code.
112*3b2bd0f6Slogwang  */
113*3b2bd0f6Slogwang 
114*3b2bd0f6Slogwang /* Generic message type cookie */
115*3b2bd0f6Slogwang #define NGM_GENERIC_COOKIE	1137070366
116*3b2bd0f6Slogwang 
117*3b2bd0f6Slogwang /* Generic messages defined for this type cookie. */
118*3b2bd0f6Slogwang enum {
119*3b2bd0f6Slogwang 	NGM_SHUTDOWN	= 1,	/* Shut down node. */
120*3b2bd0f6Slogwang 	NGM_MKPEER	= 2,	/* Create and attach a peer node. */
121*3b2bd0f6Slogwang 	NGM_CONNECT	= 3,	/* Connect two nodes. */
122*3b2bd0f6Slogwang 	NGM_NAME	= 4,	/* Give a node a name. */
123*3b2bd0f6Slogwang 	NGM_RMHOOK	= 5,	/* Break a connection between two nodes. */
124*3b2bd0f6Slogwang 
125*3b2bd0f6Slogwang 	/* Get nodeinfo for target. */
126*3b2bd0f6Slogwang 	NGM_NODEINFO	= (6|NGM_READONLY|NGM_HASREPLY),
127*3b2bd0f6Slogwang 	/* Get list of hooks on node. */
128*3b2bd0f6Slogwang 	NGM_LISTHOOKS	= (7|NGM_READONLY|NGM_HASREPLY),
129*3b2bd0f6Slogwang 	/* List globally named nodes. */
130*3b2bd0f6Slogwang 	NGM_LISTNAMES	= (8|NGM_READONLY|NGM_HASREPLY),
131*3b2bd0f6Slogwang 	/* List all nodes. */
132*3b2bd0f6Slogwang 	NGM_LISTNODES	= (9|NGM_READONLY|NGM_HASREPLY),
133*3b2bd0f6Slogwang 	/* List installed node types. */
134*3b2bd0f6Slogwang 	NGM_LISTTYPES	= (10|NGM_READONLY|NGM_HASREPLY),
135*3b2bd0f6Slogwang 	/* (optional) Get text status. */
136*3b2bd0f6Slogwang 	NGM_TEXT_STATUS	= (11|NGM_READONLY|NGM_HASREPLY),
137*3b2bd0f6Slogwang 	/* Convert struct ng_mesg to ASCII. */
138*3b2bd0f6Slogwang 	NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
139*3b2bd0f6Slogwang 	/* Convert ASCII to struct ng_mesg. */
140*3b2bd0f6Slogwang 	NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
141*3b2bd0f6Slogwang 	/* (optional) Get/set text config. */
142*3b2bd0f6Slogwang 	NGM_TEXT_CONFIG	= 14,
143*3b2bd0f6Slogwang };
144*3b2bd0f6Slogwang 
145*3b2bd0f6Slogwang /*
146*3b2bd0f6Slogwang  * Flow control and intra node control messages.
147*3b2bd0f6Slogwang  * These are routed between nodes to allow flow control and to allow
148*3b2bd0f6Slogwang  * events to be passed around the graph.
149*3b2bd0f6Slogwang  * There will be some form of default handling for these but I
150*3b2bd0f6Slogwang  * do not yet know what it is..
151*3b2bd0f6Slogwang  */
152*3b2bd0f6Slogwang 
153*3b2bd0f6Slogwang /* Generic message type cookie */
154*3b2bd0f6Slogwang #define NGM_FLOW_COOKIE	851672669 /* temp for debugging */
155*3b2bd0f6Slogwang 
156*3b2bd0f6Slogwang /* Upstream messages */
157*3b2bd0f6Slogwang #define NGM_LINK_IS_UP		32	/* e.g. carrier found - no data */
158*3b2bd0f6Slogwang #define NGM_LINK_IS_DOWN	33	/* carrier lost, includes queue state */
159*3b2bd0f6Slogwang #define NGM_HIGH_WATER_PASSED	34	/* includes queue state */
160*3b2bd0f6Slogwang #define NGM_LOW_WATER_PASSED	35	/* includes queue state */
161*3b2bd0f6Slogwang #define NGM_SYNC_QUEUE_STATE	36	/* sync response from sending packet */
162*3b2bd0f6Slogwang 
163*3b2bd0f6Slogwang /* Downstream messages */
164*3b2bd0f6Slogwang #define NGM_DROP_LINK		41	/* drop DTR, etc. - stay in the graph */
165*3b2bd0f6Slogwang #define NGM_RAISE_LINK		42	/* if you previously dropped it */
166*3b2bd0f6Slogwang #define NGM_FLUSH_QUEUE		43	/* no data */
167*3b2bd0f6Slogwang #define NGM_GET_BANDWIDTH	(44|NGM_READONLY)	/* either real or measured */
168*3b2bd0f6Slogwang #define NGM_SET_XMIT_Q_LIMITS	45	/* includes queue state */
169*3b2bd0f6Slogwang #define NGM_GET_XMIT_Q_LIMITS	(46|NGM_READONLY)	/* returns queue state */
170*3b2bd0f6Slogwang #define NGM_MICROMANAGE		47	/* We want sync. queue state
171*3b2bd0f6Slogwang 						reply for each packet sent */
172*3b2bd0f6Slogwang #define NGM_SET_FLOW_MANAGER	48	/* send flow control here */
173*3b2bd0f6Slogwang /* Structure used for NGM_MKPEER */
174*3b2bd0f6Slogwang struct ngm_mkpeer {
175*3b2bd0f6Slogwang 	char	type[NG_TYPESIZ];		/* peer type */
176*3b2bd0f6Slogwang 	char	ourhook[NG_HOOKSIZ];		/* hook name */
177*3b2bd0f6Slogwang 	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
178*3b2bd0f6Slogwang };
179*3b2bd0f6Slogwang 
180*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
181*3b2bd0f6Slogwang #define NG_GENERIC_MKPEER_INFO()	{			\
182*3b2bd0f6Slogwang 	  { "type",		&ng_parse_typebuf_type	},	\
183*3b2bd0f6Slogwang 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
184*3b2bd0f6Slogwang 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
185*3b2bd0f6Slogwang 	  { NULL }						\
186*3b2bd0f6Slogwang }
187*3b2bd0f6Slogwang 
188*3b2bd0f6Slogwang /* Structure used for NGM_CONNECT */
189*3b2bd0f6Slogwang struct ngm_connect {
190*3b2bd0f6Slogwang 	char	path[NG_PATHSIZ];		/* peer path */
191*3b2bd0f6Slogwang 	char	ourhook[NG_HOOKSIZ];		/* hook name */
192*3b2bd0f6Slogwang 	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
193*3b2bd0f6Slogwang };
194*3b2bd0f6Slogwang 
195*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
196*3b2bd0f6Slogwang #define NG_GENERIC_CONNECT_INFO()	{			\
197*3b2bd0f6Slogwang 	  { "path",		&ng_parse_pathbuf_type	},	\
198*3b2bd0f6Slogwang 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
199*3b2bd0f6Slogwang 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
200*3b2bd0f6Slogwang 	  { NULL }						\
201*3b2bd0f6Slogwang }
202*3b2bd0f6Slogwang 
203*3b2bd0f6Slogwang /* Structure used for NGM_NAME */
204*3b2bd0f6Slogwang struct ngm_name {
205*3b2bd0f6Slogwang 	char	name[NG_NODESIZ];			/* node name */
206*3b2bd0f6Slogwang };
207*3b2bd0f6Slogwang 
208*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
209*3b2bd0f6Slogwang #define NG_GENERIC_NAME_INFO()	{				\
210*3b2bd0f6Slogwang 	  { "name",		&ng_parse_nodebuf_type	},	\
211*3b2bd0f6Slogwang 	  { NULL }						\
212*3b2bd0f6Slogwang }
213*3b2bd0f6Slogwang 
214*3b2bd0f6Slogwang /* Structure used for NGM_RMHOOK */
215*3b2bd0f6Slogwang struct ngm_rmhook {
216*3b2bd0f6Slogwang 	char	ourhook[NG_HOOKSIZ];		/* hook name */
217*3b2bd0f6Slogwang };
218*3b2bd0f6Slogwang 
219*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
220*3b2bd0f6Slogwang #define NG_GENERIC_RMHOOK_INFO()	{			\
221*3b2bd0f6Slogwang 	  { "hook",		&ng_parse_hookbuf_type	},	\
222*3b2bd0f6Slogwang 	  { NULL }						\
223*3b2bd0f6Slogwang }
224*3b2bd0f6Slogwang 
225*3b2bd0f6Slogwang /* Structure used for NGM_NODEINFO */
226*3b2bd0f6Slogwang struct nodeinfo {
227*3b2bd0f6Slogwang 	char		name[NG_NODESIZ];	/* node name (if any) */
228*3b2bd0f6Slogwang         char    	type[NG_TYPESIZ];	/* peer type */
229*3b2bd0f6Slogwang 	ng_ID_t		id;			/* unique identifier */
230*3b2bd0f6Slogwang 	u_int32_t	hooks;			/* number of active hooks */
231*3b2bd0f6Slogwang };
232*3b2bd0f6Slogwang 
233*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
234*3b2bd0f6Slogwang #define NG_GENERIC_NODEINFO_INFO()	{			\
235*3b2bd0f6Slogwang 	  { "name",		&ng_parse_nodebuf_type	},	\
236*3b2bd0f6Slogwang 	  { "type",		&ng_parse_typebuf_type	},	\
237*3b2bd0f6Slogwang 	  { "id",		&ng_parse_hint32_type	},	\
238*3b2bd0f6Slogwang 	  { "hooks",		&ng_parse_uint32_type	},	\
239*3b2bd0f6Slogwang 	  { NULL }						\
240*3b2bd0f6Slogwang }
241*3b2bd0f6Slogwang 
242*3b2bd0f6Slogwang /* Structure used for NGM_LISTHOOKS */
243*3b2bd0f6Slogwang struct linkinfo {
244*3b2bd0f6Slogwang 	char		ourhook[NG_HOOKSIZ];	/* hook name */
245*3b2bd0f6Slogwang 	char		peerhook[NG_HOOKSIZ];	/* peer hook */
246*3b2bd0f6Slogwang 	struct nodeinfo	nodeinfo;
247*3b2bd0f6Slogwang };
248*3b2bd0f6Slogwang 
249*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
250*3b2bd0f6Slogwang #define NG_GENERIC_LINKINFO_INFO(nitype)	{		\
251*3b2bd0f6Slogwang 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
252*3b2bd0f6Slogwang 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
253*3b2bd0f6Slogwang 	  { "nodeinfo",		(nitype)		},	\
254*3b2bd0f6Slogwang 	  { NULL }						\
255*3b2bd0f6Slogwang }
256*3b2bd0f6Slogwang 
257*3b2bd0f6Slogwang struct hooklist {
258*3b2bd0f6Slogwang 	struct nodeinfo nodeinfo;		/* node information */
259*3b2bd0f6Slogwang 	struct linkinfo link[];			/* info about each hook */
260*3b2bd0f6Slogwang };
261*3b2bd0f6Slogwang 
262*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
263*3b2bd0f6Slogwang #define NG_GENERIC_HOOKLIST_INFO(nitype,litype)	{		\
264*3b2bd0f6Slogwang 	  { "nodeinfo",		(nitype)		},	\
265*3b2bd0f6Slogwang 	  { "linkinfo",		(litype)		},	\
266*3b2bd0f6Slogwang 	  { NULL }						\
267*3b2bd0f6Slogwang }
268*3b2bd0f6Slogwang 
269*3b2bd0f6Slogwang /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
270*3b2bd0f6Slogwang struct namelist {
271*3b2bd0f6Slogwang 	u_int32_t	numnames;
272*3b2bd0f6Slogwang 	struct nodeinfo	nodeinfo[];
273*3b2bd0f6Slogwang };
274*3b2bd0f6Slogwang 
275*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
276*3b2bd0f6Slogwang #define NG_GENERIC_LISTNODES_INFO(niarraytype)	{		\
277*3b2bd0f6Slogwang 	  { "numnames",		&ng_parse_uint32_type	},	\
278*3b2bd0f6Slogwang 	  { "nodeinfo",		(niarraytype)		},	\
279*3b2bd0f6Slogwang 	  { NULL }						\
280*3b2bd0f6Slogwang }
281*3b2bd0f6Slogwang 
282*3b2bd0f6Slogwang /* Structure used for NGM_LISTTYPES */
283*3b2bd0f6Slogwang struct typeinfo {
284*3b2bd0f6Slogwang 	char		type_name[NG_TYPESIZ];	/* name of type */
285*3b2bd0f6Slogwang 	u_int32_t	numnodes;		/* number alive */
286*3b2bd0f6Slogwang };
287*3b2bd0f6Slogwang 
288*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
289*3b2bd0f6Slogwang #define NG_GENERIC_TYPEINFO_INFO()		{		\
290*3b2bd0f6Slogwang 	  { "typename",		&ng_parse_typebuf_type	},	\
291*3b2bd0f6Slogwang 	  { "numnodes",		&ng_parse_uint32_type	},	\
292*3b2bd0f6Slogwang 	  { NULL }						\
293*3b2bd0f6Slogwang }
294*3b2bd0f6Slogwang 
295*3b2bd0f6Slogwang struct typelist {
296*3b2bd0f6Slogwang 	u_int32_t	numtypes;
297*3b2bd0f6Slogwang 	struct typeinfo	typeinfo[];
298*3b2bd0f6Slogwang };
299*3b2bd0f6Slogwang 
300*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
301*3b2bd0f6Slogwang #define NG_GENERIC_TYPELIST_INFO(tiarraytype)	{		\
302*3b2bd0f6Slogwang 	  { "numtypes",		&ng_parse_uint32_type	},	\
303*3b2bd0f6Slogwang 	  { "typeinfo",		(tiarraytype)		},	\
304*3b2bd0f6Slogwang 	  { NULL }						\
305*3b2bd0f6Slogwang }
306*3b2bd0f6Slogwang 
307*3b2bd0f6Slogwang struct ngm_bandwidth {
308*3b2bd0f6Slogwang 	u_int64_t	nominal_in;
309*3b2bd0f6Slogwang 	u_int64_t	seen_in;
310*3b2bd0f6Slogwang 	u_int64_t	nominal_out;
311*3b2bd0f6Slogwang 	u_int64_t	seen_out;
312*3b2bd0f6Slogwang };
313*3b2bd0f6Slogwang 
314*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
315*3b2bd0f6Slogwang #define NG_GENERIC_BANDWIDTH_INFO()	{			\
316*3b2bd0f6Slogwang 	  { "nominal_in",	&ng_parse_uint64_type	},	\
317*3b2bd0f6Slogwang 	  { "seen_in",		&ng_parse_uint64_type	},	\
318*3b2bd0f6Slogwang 	  { "nominal_out",	&ng_parse_uint64_type	},	\
319*3b2bd0f6Slogwang 	  { "seen_out",		&ng_parse_uint64_type	},	\
320*3b2bd0f6Slogwang 	  { NULL }						\
321*3b2bd0f6Slogwang }
322*3b2bd0f6Slogwang 
323*3b2bd0f6Slogwang /*
324*3b2bd0f6Slogwang  * Information about a node's 'output' queue.
325*3b2bd0f6Slogwang  * This is NOT the netgraph input queueing mechanism,
326*3b2bd0f6Slogwang  * but rather any queue the node may implement internally
327*3b2bd0f6Slogwang  * This has to consider ALTQ if we are to work with it.
328*3b2bd0f6Slogwang  * As far as I can see, ALTQ counts PACKETS, not bytes.
329*3b2bd0f6Slogwang  * If ALTQ has several queues and one has passed a watermark
330*3b2bd0f6Slogwang  * we should have the priority of that queue be real (and not -1)
331*3b2bd0f6Slogwang  * XXX ALTQ stuff is just an idea.....
332*3b2bd0f6Slogwang  */
333*3b2bd0f6Slogwang struct ngm_queue_state {
334*3b2bd0f6Slogwang 	u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
335*3b2bd0f6Slogwang 	u_int	max_queuelen_bytes;
336*3b2bd0f6Slogwang 	u_int	max_queuelen_packets;
337*3b2bd0f6Slogwang 	u_int	low_watermark;
338*3b2bd0f6Slogwang 	u_int	high_watermark;
339*3b2bd0f6Slogwang 	u_int	current;
340*3b2bd0f6Slogwang };
341*3b2bd0f6Slogwang 
342*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
343*3b2bd0f6Slogwang #define NG_GENERIC_QUEUE_INFO()	{				\
344*3b2bd0f6Slogwang 	  { "max_queuelen_bytes", &ng_parse_uint_type	},	\
345*3b2bd0f6Slogwang 	  { "max_queuelen_packets", &ng_parse_uint_type	},	\
346*3b2bd0f6Slogwang 	  { "high_watermark",	&ng_parse_uint_type	},	\
347*3b2bd0f6Slogwang 	  { "low_watermark",	&ng_parse_uint_type	},	\
348*3b2bd0f6Slogwang 	  { "current",		&ng_parse_uint_type	},	\
349*3b2bd0f6Slogwang 	  { NULL }						\
350*3b2bd0f6Slogwang }
351*3b2bd0f6Slogwang 
352*3b2bd0f6Slogwang /* Tell a node who to send async flow control info to. */
353*3b2bd0f6Slogwang struct flow_manager {
354*3b2bd0f6Slogwang 	ng_ID_t		id;			/* unique identifier */
355*3b2bd0f6Slogwang };
356*3b2bd0f6Slogwang 
357*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
358*3b2bd0f6Slogwang #define NG_GENERIC_FLOW_MANAGER_INFO()	{			\
359*3b2bd0f6Slogwang 	  { "id",		&ng_parse_hint32_type	},	\
360*3b2bd0f6Slogwang 	  { NULL }						\
361*3b2bd0f6Slogwang }
362*3b2bd0f6Slogwang 
363*3b2bd0f6Slogwang 
364*3b2bd0f6Slogwang /*
365*3b2bd0f6Slogwang  * For netgraph nodes that are somehow associated with file descriptors
366*3b2bd0f6Slogwang  * (e.g., a device that has a /dev entry and is also a netgraph node),
367*3b2bd0f6Slogwang  * we define a generic ioctl for requesting the corresponding nodeinfo
368*3b2bd0f6Slogwang  * structure and for assigning a name (if there isn't one already).
369*3b2bd0f6Slogwang  *
370*3b2bd0f6Slogwang  * For these to you need to also #include <sys/ioccom.h>.
371*3b2bd0f6Slogwang  */
372*3b2bd0f6Slogwang 
373*3b2bd0f6Slogwang #define NGIOCGINFO	_IOR('N', 40, struct nodeinfo)	/* get node info */
374*3b2bd0f6Slogwang #define NGIOCSETNAME	_IOW('N', 41, struct ngm_name)	/* set node name */
375*3b2bd0f6Slogwang 
376*3b2bd0f6Slogwang #ifdef _KERNEL
377*3b2bd0f6Slogwang /*
378*3b2bd0f6Slogwang  * Allocate and initialize a netgraph message "msg" with "len"
379*3b2bd0f6Slogwang  * extra bytes of argument. Sets "msg" to NULL if fails.
380*3b2bd0f6Slogwang  * Does not initialize token.
381*3b2bd0f6Slogwang  */
382*3b2bd0f6Slogwang #define NG_MKMESSAGE(msg, cookie, cmdid, len, how)			\
383*3b2bd0f6Slogwang 	do {								\
384*3b2bd0f6Slogwang 	  (msg) = malloc(sizeof(struct ng_mesg)				\
385*3b2bd0f6Slogwang 	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
386*3b2bd0f6Slogwang 	  if ((msg) == NULL)						\
387*3b2bd0f6Slogwang 	    break;							\
388*3b2bd0f6Slogwang 	  (msg)->header.version = NG_VERSION;				\
389*3b2bd0f6Slogwang 	  (msg)->header.typecookie = (cookie);				\
390*3b2bd0f6Slogwang 	  (msg)->header.cmd = (cmdid);					\
391*3b2bd0f6Slogwang 	  (msg)->header.arglen = (len);					\
392*3b2bd0f6Slogwang 	  strncpy((msg)->header.cmdstr, #cmdid,				\
393*3b2bd0f6Slogwang 	    sizeof((msg)->header.cmdstr) - 1);				\
394*3b2bd0f6Slogwang 	} while (0)
395*3b2bd0f6Slogwang 
396*3b2bd0f6Slogwang /*
397*3b2bd0f6Slogwang  * Allocate and initialize a response "rsp" to a message "msg"
398*3b2bd0f6Slogwang  * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
399*3b2bd0f6Slogwang  */
400*3b2bd0f6Slogwang #define NG_MKRESPONSE(rsp, msg, len, how)				\
401*3b2bd0f6Slogwang 	do {								\
402*3b2bd0f6Slogwang 	  (rsp) = malloc(sizeof(struct ng_mesg)				\
403*3b2bd0f6Slogwang 	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
404*3b2bd0f6Slogwang 	  if ((rsp) == NULL)						\
405*3b2bd0f6Slogwang 	    break;							\
406*3b2bd0f6Slogwang 	  (rsp)->header.version = NG_VERSION;				\
407*3b2bd0f6Slogwang 	  (rsp)->header.arglen = (len);					\
408*3b2bd0f6Slogwang 	  (rsp)->header.token = (msg)->header.token;			\
409*3b2bd0f6Slogwang 	  (rsp)->header.typecookie = (msg)->header.typecookie;		\
410*3b2bd0f6Slogwang 	  (rsp)->header.cmd = (msg)->header.cmd;			\
411*3b2bd0f6Slogwang 	  bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr,		\
412*3b2bd0f6Slogwang 	    sizeof((rsp)->header.cmdstr));				\
413*3b2bd0f6Slogwang 	  (rsp)->header.flags |= NGF_RESP;				\
414*3b2bd0f6Slogwang 	} while (0)
415*3b2bd0f6Slogwang 
416*3b2bd0f6Slogwang /*
417*3b2bd0f6Slogwang  * Make a copy of message. Sets "copy" to NULL if fails.
418*3b2bd0f6Slogwang  */
419*3b2bd0f6Slogwang #define	NG_COPYMESSAGE(copy, msg, how)					\
420*3b2bd0f6Slogwang 	do {								\
421*3b2bd0f6Slogwang 	  (copy) = malloc(sizeof(struct ng_mesg)			\
422*3b2bd0f6Slogwang 	    + (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO);	\
423*3b2bd0f6Slogwang 	  if ((copy) == NULL)						\
424*3b2bd0f6Slogwang 	    break;							\
425*3b2bd0f6Slogwang 	  (copy)->header.version = NG_VERSION;				\
426*3b2bd0f6Slogwang 	  (copy)->header.arglen = (msg)->header.arglen;			\
427*3b2bd0f6Slogwang 	  (copy)->header.token = (msg)->header.token;			\
428*3b2bd0f6Slogwang 	  (copy)->header.typecookie = (msg)->header.typecookie;		\
429*3b2bd0f6Slogwang 	  (copy)->header.cmd = (msg)->header.cmd;			\
430*3b2bd0f6Slogwang 	  (copy)->header.flags = (msg)->header.flags;			\
431*3b2bd0f6Slogwang 	  bcopy((msg)->header.cmdstr, (copy)->header.cmdstr,		\
432*3b2bd0f6Slogwang 	    sizeof((copy)->header.cmdstr));				\
433*3b2bd0f6Slogwang 	  if ((msg)->header.arglen > 0)					\
434*3b2bd0f6Slogwang 	    bcopy((msg)->data, (copy)->data, (msg)->header.arglen);	\
435*3b2bd0f6Slogwang 	} while (0)
436*3b2bd0f6Slogwang 
437*3b2bd0f6Slogwang #endif /* _KERNEL */
438*3b2bd0f6Slogwang 
439*3b2bd0f6Slogwang #endif /* _NETGRAPH_NG_MESSAGE_H_ */
440