xref: /freebsd/sys/netgraph/ng_message.h (revision cc3bbd68c54fab5539ff1cfa5f7bfb454633239c)
14cf49a43SJulian Elischer 
24cf49a43SJulian Elischer /*
34cf49a43SJulian Elischer  * ng_message.h
44cf49a43SJulian Elischer  *
54cf49a43SJulian Elischer  * Copyright (c) 1996-1999 Whistle Communications, Inc.
64cf49a43SJulian Elischer  * All rights reserved.
74cf49a43SJulian Elischer  *
84cf49a43SJulian Elischer  * Subject to the following obligations and disclaimer of warranty, use and
94cf49a43SJulian Elischer  * redistribution of this software, in source or object code forms, with or
104cf49a43SJulian Elischer  * without modifications are expressly permitted by Whistle Communications;
114cf49a43SJulian Elischer  * provided, however, that:
124cf49a43SJulian Elischer  * 1. Any and all reproductions of the source or object code must include the
134cf49a43SJulian Elischer  *    copyright notice above and the following disclaimer of warranties; and
144cf49a43SJulian Elischer  * 2. No rights are granted, in any manner or form, to use Whistle
154cf49a43SJulian Elischer  *    Communications, Inc. trademarks, including the mark "WHISTLE
164cf49a43SJulian Elischer  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
174cf49a43SJulian Elischer  *    such appears in the above copyright notice or in the software.
184cf49a43SJulian Elischer  *
194cf49a43SJulian Elischer  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
204cf49a43SJulian Elischer  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
214cf49a43SJulian Elischer  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
224cf49a43SJulian Elischer  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
234cf49a43SJulian Elischer  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
244cf49a43SJulian Elischer  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
254cf49a43SJulian Elischer  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
264cf49a43SJulian Elischer  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
274cf49a43SJulian Elischer  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
284cf49a43SJulian Elischer  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
294cf49a43SJulian Elischer  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
304cf49a43SJulian Elischer  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
314cf49a43SJulian Elischer  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
324cf49a43SJulian Elischer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
334cf49a43SJulian Elischer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
344cf49a43SJulian Elischer  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
354cf49a43SJulian Elischer  * OF SUCH DAMAGE.
364cf49a43SJulian Elischer  *
37cc3bbd68SJulian Elischer  * Author: Julian Elischer <julian@freebsd.org>
384cf49a43SJulian Elischer  *
394cf49a43SJulian Elischer  * $FreeBSD$
404cf49a43SJulian Elischer  * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
414cf49a43SJulian Elischer  */
424cf49a43SJulian Elischer 
434cf49a43SJulian Elischer #ifndef _NETGRAPH_NG_MESSAGE_H_
444cf49a43SJulian Elischer #define _NETGRAPH_NG_MESSAGE_H_ 1
454cf49a43SJulian Elischer 
464cf49a43SJulian Elischer /* ASCII string size limits */
474cf49a43SJulian Elischer #define NG_TYPELEN	15	/* max type name len (16 with null) */
484cf49a43SJulian Elischer #define NG_HOOKLEN	15	/* max hook name len (16 with null) */
494cf49a43SJulian Elischer #define NG_NODELEN	15	/* max node name len (16 with null) */
504cf49a43SJulian Elischer #define NG_PATHLEN	511	/* max path len     (512 with null) */
514cf49a43SJulian Elischer #define NG_CMDSTRLEN	15	/* max command string (16 with null) */
524cf49a43SJulian Elischer #define NG_TEXTRESPONSE 1024	/* allow this length for a text response */
534cf49a43SJulian Elischer 
544cf49a43SJulian Elischer /* A netgraph message */
554cf49a43SJulian Elischer struct ng_mesg {
564cf49a43SJulian Elischer 	struct	ng_msghdr {
574cf49a43SJulian Elischer 		u_char		version;		/* must == NG_VERSION */
584cf49a43SJulian Elischer 		u_char		spare;			/* pad to 2 bytes */
594cf49a43SJulian Elischer 		u_int16_t	arglen;			/* length of data */
604cf49a43SJulian Elischer 		u_int32_t	flags;			/* message status */
614cf49a43SJulian Elischer 		u_int32_t	token;			/* match with reply */
624cf49a43SJulian Elischer 		u_int32_t	typecookie;		/* node's type cookie */
634cf49a43SJulian Elischer 		u_int32_t	cmd;			/* command identifier */
644cf49a43SJulian Elischer 		u_char		cmdstr[NG_CMDSTRLEN+1];	/* cmd string + \0 */
654cf49a43SJulian Elischer 	} header;
664cf49a43SJulian Elischer 	char	data[0];		/* placeholder for actual data */
674cf49a43SJulian Elischer };
68f8307e12SArchie Cobbs 
69f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
70f8307e12SArchie Cobbs #define NG_GENERIC_NG_MESG_INFO(dtype)	{			\
71f8307e12SArchie Cobbs 	{							\
7257b57be3SArchie Cobbs 	  { "version",		&ng_parse_uint8_type	},	\
7357b57be3SArchie Cobbs 	  { "spare",		&ng_parse_uint8_type	},	\
7457b57be3SArchie Cobbs 	  { "arglen",		&ng_parse_uint16_type	},	\
7557b57be3SArchie Cobbs 	  { "flags",		&ng_parse_hint32_type	},	\
7657b57be3SArchie Cobbs 	  { "token",		&ng_parse_uint32_type	},	\
7757b57be3SArchie Cobbs 	  { "typecookie",	&ng_parse_uint32_type	},	\
7857b57be3SArchie Cobbs 	  { "cmd",		&ng_parse_uint32_type	},	\
79f8307e12SArchie Cobbs 	  { "cmdstr",		&ng_parse_cmdbuf_type	},	\
80f8307e12SArchie Cobbs 	  { "data",		(dtype)			},	\
81f8307e12SArchie Cobbs 	  { NULL },						\
82f8307e12SArchie Cobbs 	}							\
83f8307e12SArchie Cobbs }
84f8307e12SArchie Cobbs 
85f8307e12SArchie Cobbs /* Negraph type binary compatibility field */
86a4ec03cfSJulian Elischer #define NG_VERSION	3
87f8307e12SArchie Cobbs 
88f8307e12SArchie Cobbs /* Flags field flags */
894cf49a43SJulian Elischer #define NGF_ORIG	0x0000		/* the msg is the original request */
904cf49a43SJulian Elischer #define NGF_RESP	0x0001		/* the message is a response */
914cf49a43SJulian Elischer 
92f8307e12SArchie Cobbs /* Type of a unique node ID */
93f8307e12SArchie Cobbs #define ng_ID_t unsigned int
94f8307e12SArchie Cobbs 
954cf49a43SJulian Elischer /*
964cf49a43SJulian Elischer  * Here we describe the "generic" messages that all nodes inherently
974cf49a43SJulian Elischer  * understand. With the exception of NGM_TEXT_STATUS, these are handled
984cf49a43SJulian Elischer  * automatically by the base netgraph code.
994cf49a43SJulian Elischer  */
1004cf49a43SJulian Elischer 
1014cf49a43SJulian Elischer /* Generic message type cookie */
1024cf49a43SJulian Elischer #define NGM_GENERIC_COOKIE	851672668
1034cf49a43SJulian Elischer 
1044cf49a43SJulian Elischer /* Generic messages defined for this type cookie */
105f8307e12SArchie Cobbs #define	NGM_SHUTDOWN		1	/* shut down node */
106f8307e12SArchie Cobbs #define NGM_MKPEER		2	/* create and attach a peer node */
107f8307e12SArchie Cobbs #define NGM_CONNECT		3	/* connect two nodes */
108f8307e12SArchie Cobbs #define NGM_NAME		4	/* give a node a name */
109f8307e12SArchie Cobbs #define NGM_RMHOOK		5	/* break a connection btw. two nodes */
110f8307e12SArchie Cobbs #define	NGM_NODEINFO		6	/* get nodeinfo for the target */
111f8307e12SArchie Cobbs #define	NGM_LISTHOOKS		7	/* get list of hooks on node */
112f8307e12SArchie Cobbs #define	NGM_LISTNAMES		8	/* list all globally named nodes */
113f8307e12SArchie Cobbs #define	NGM_LISTNODES		9	/* list all nodes, named and unnamed */
114f8307e12SArchie Cobbs #define	NGM_LISTTYPES		10	/* list all installed node types */
115f8307e12SArchie Cobbs #define	NGM_TEXT_STATUS		11	/* (optional) get text status report */
116f8307e12SArchie Cobbs #define	NGM_BINARY2ASCII	12	/* convert struct ng_mesg to ascii */
117f8307e12SArchie Cobbs #define	NGM_ASCII2BINARY	13	/* convert ascii to struct ng_mesg */
1187095e097SPoul-Henning Kamp #define	NGM_TEXT_CONFIG		14	/* (optional) get/set text config */
1194cf49a43SJulian Elischer 
120f8307e12SArchie Cobbs /* Structure used for NGM_MKPEER */
1214cf49a43SJulian Elischer struct ngm_mkpeer {
1224cf49a43SJulian Elischer 	char	type[NG_TYPELEN + 1];			/* peer type */
1234cf49a43SJulian Elischer 	char	ourhook[NG_HOOKLEN + 1];		/* hook name */
1244cf49a43SJulian Elischer 	char	peerhook[NG_HOOKLEN + 1];		/* peer hook name */
1254cf49a43SJulian Elischer };
1264cf49a43SJulian Elischer 
127f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
128f8307e12SArchie Cobbs #define NG_GENERIC_MKPEER_INFO()	{			\
129f8307e12SArchie Cobbs 	{							\
130f8307e12SArchie Cobbs 	  { "type",		&ng_parse_typebuf_type	},	\
131f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
132f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
133f8307e12SArchie Cobbs 	  { NULL },						\
134f8307e12SArchie Cobbs 	}							\
135f8307e12SArchie Cobbs }
136f8307e12SArchie Cobbs 
137f8307e12SArchie Cobbs /* Structure used for NGM_CONNECT */
1384cf49a43SJulian Elischer struct ngm_connect {
1394cf49a43SJulian Elischer 	char	path[NG_PATHLEN + 1];			/* peer path */
1404cf49a43SJulian Elischer 	char	ourhook[NG_HOOKLEN + 1];		/* hook name */
1414cf49a43SJulian Elischer 	char	peerhook[NG_HOOKLEN + 1];		/* peer hook name */
1424cf49a43SJulian Elischer };
1434cf49a43SJulian Elischer 
144f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
145f8307e12SArchie Cobbs #define NG_GENERIC_CONNECT_INFO()	{			\
146f8307e12SArchie Cobbs 	{							\
147f8307e12SArchie Cobbs 	  { "path",		&ng_parse_pathbuf_type	},	\
148f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
149f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
150f8307e12SArchie Cobbs 	  { NULL },						\
151f8307e12SArchie Cobbs 	}							\
152f8307e12SArchie Cobbs }
153f8307e12SArchie Cobbs 
154f8307e12SArchie Cobbs /* Structure used for NGM_NAME */
1554cf49a43SJulian Elischer struct ngm_name {
1564cf49a43SJulian Elischer 	char	name[NG_NODELEN + 1];			/* node name */
1574cf49a43SJulian Elischer };
1584cf49a43SJulian Elischer 
159f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
160f8307e12SArchie Cobbs #define NG_GENERIC_NAME_INFO()	{				\
161f8307e12SArchie Cobbs 	{							\
162f8307e12SArchie Cobbs 	  { "name",		&ng_parse_nodebuf_type	},	\
163f8307e12SArchie Cobbs 	  { NULL },						\
164f8307e12SArchie Cobbs 	}							\
165f8307e12SArchie Cobbs }
166f8307e12SArchie Cobbs 
167f8307e12SArchie Cobbs /* Structure used for NGM_RMHOOK */
1684cf49a43SJulian Elischer struct ngm_rmhook {
1694cf49a43SJulian Elischer 	char	ourhook[NG_HOOKLEN + 1];		/* hook name */
1704cf49a43SJulian Elischer };
1714cf49a43SJulian Elischer 
172f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
173f8307e12SArchie Cobbs #define NG_GENERIC_RMHOOK_INFO()	{			\
174f8307e12SArchie Cobbs 	{							\
175f8307e12SArchie Cobbs 	  { "hook",		&ng_parse_hookbuf_type	},	\
176f8307e12SArchie Cobbs 	  { NULL },						\
177f8307e12SArchie Cobbs 	}							\
178f8307e12SArchie Cobbs }
179f8307e12SArchie Cobbs 
180f8307e12SArchie Cobbs /* Structure used for NGM_NODEINFO */
1814cf49a43SJulian Elischer struct nodeinfo {
1824cf49a43SJulian Elischer 	char		name[NG_NODELEN + 1];	/* node name (if any) */
1834cf49a43SJulian Elischer         char    	type[NG_TYPELEN + 1];   /* peer type */
184dc90cad9SJulian Elischer 	ng_ID_t		id;			/* unique identifier */
1854cf49a43SJulian Elischer 	u_int32_t	hooks;			/* number of active hooks */
1864cf49a43SJulian Elischer };
1874cf49a43SJulian Elischer 
188f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
189f8307e12SArchie Cobbs #define NG_GENERIC_NODEINFO_INFO()	{			\
190f8307e12SArchie Cobbs 	{							\
191f8307e12SArchie Cobbs 	  { "name",		&ng_parse_nodebuf_type	},	\
192f8307e12SArchie Cobbs 	  { "type",		&ng_parse_typebuf_type	},	\
19357b57be3SArchie Cobbs 	  { "id",		&ng_parse_hint32_type	},	\
19457b57be3SArchie Cobbs 	  { "hooks",		&ng_parse_uint32_type	},	\
195f8307e12SArchie Cobbs 	  { NULL },						\
196f8307e12SArchie Cobbs 	}							\
197f8307e12SArchie Cobbs }
198f8307e12SArchie Cobbs 
199f8307e12SArchie Cobbs /* Structure used for NGM_LISTHOOKS */
2004cf49a43SJulian Elischer struct linkinfo {
2014cf49a43SJulian Elischer 	char		ourhook[NG_HOOKLEN + 1];	/* hook name */
2024cf49a43SJulian Elischer 	char		peerhook[NG_HOOKLEN + 1];	/* peer hook */
2034cf49a43SJulian Elischer 	struct nodeinfo	nodeinfo;
2044cf49a43SJulian Elischer };
2054cf49a43SJulian Elischer 
206f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
207f8307e12SArchie Cobbs #define NG_GENERIC_LINKINFO_INFO(nitype)	{		\
208f8307e12SArchie Cobbs 	{							\
209f8307e12SArchie Cobbs 	  { "ourhook",		&ng_parse_hookbuf_type	},	\
210f8307e12SArchie Cobbs 	  { "peerhook",		&ng_parse_hookbuf_type	},	\
211f8307e12SArchie Cobbs 	  { "nodeinfo",		(nitype)		},	\
212f8307e12SArchie Cobbs 	  { NULL },						\
213f8307e12SArchie Cobbs 	}							\
214f8307e12SArchie Cobbs }
215f8307e12SArchie Cobbs 
2164cf49a43SJulian Elischer struct hooklist {
2174cf49a43SJulian Elischer 	struct nodeinfo nodeinfo;		/* node information */
2184cf49a43SJulian Elischer 	struct linkinfo link[0];		/* info about each hook */
2194cf49a43SJulian Elischer };
2204cf49a43SJulian Elischer 
221f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
222f8307e12SArchie Cobbs #define NG_GENERIC_HOOKLIST_INFO(nitype,litype)	{		\
223f8307e12SArchie Cobbs 	{							\
224f8307e12SArchie Cobbs 	  { "nodeinfo",		(nitype)		},	\
225f8307e12SArchie Cobbs 	  { "linkinfo",		(litype)		},	\
226f8307e12SArchie Cobbs 	  { NULL },						\
227f8307e12SArchie Cobbs 	}							\
228f8307e12SArchie Cobbs }
229f8307e12SArchie Cobbs 
230f8307e12SArchie Cobbs /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
2314cf49a43SJulian Elischer struct namelist {
2324cf49a43SJulian Elischer 	u_int32_t	numnames;
2334cf49a43SJulian Elischer 	struct nodeinfo	nodeinfo[0];
2344cf49a43SJulian Elischer };
2354cf49a43SJulian Elischer 
236f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
237f8307e12SArchie Cobbs #define NG_GENERIC_LISTNODES_INFO(niarraytype)	{		\
238f8307e12SArchie Cobbs 	{							\
23957b57be3SArchie Cobbs 	  { "numnames",		&ng_parse_uint32_type	},	\
240f8307e12SArchie Cobbs 	  { "nodeinfo",		(niarraytype)		},	\
241f8307e12SArchie Cobbs 	  { NULL },						\
242f8307e12SArchie Cobbs 	}							\
243f8307e12SArchie Cobbs }
244f8307e12SArchie Cobbs 
245f8307e12SArchie Cobbs /* Structure used for NGM_LISTTYPES */
2464cf49a43SJulian Elischer struct typeinfo {
247a096e45aSArchie Cobbs 	char		type_name[NG_TYPELEN + 1];	/* name of type */
2484cf49a43SJulian Elischer 	u_int32_t	numnodes;			/* number alive */
2494cf49a43SJulian Elischer };
2504cf49a43SJulian Elischer 
251f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
252f8307e12SArchie Cobbs #define NG_GENERIC_TYPEINFO_INFO()		{		\
253f8307e12SArchie Cobbs 	{							\
254f8307e12SArchie Cobbs 	  { "typename",		&ng_parse_typebuf_type	},	\
25557b57be3SArchie Cobbs 	  { "numnodes",		&ng_parse_uint32_type	},	\
256f8307e12SArchie Cobbs 	  { NULL },						\
257f8307e12SArchie Cobbs 	}							\
258f8307e12SArchie Cobbs }
259f8307e12SArchie Cobbs 
2604cf49a43SJulian Elischer struct typelist {
2614cf49a43SJulian Elischer 	u_int32_t	numtypes;
2624cf49a43SJulian Elischer 	struct typeinfo	typeinfo[0];
2634cf49a43SJulian Elischer };
2644cf49a43SJulian Elischer 
265f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */
266f8307e12SArchie Cobbs #define NG_GENERIC_TYPELIST_INFO(tiarraytype)	{		\
267f8307e12SArchie Cobbs 	{							\
26857b57be3SArchie Cobbs 	  { "numtypes",		&ng_parse_uint32_type	},	\
269f8307e12SArchie Cobbs 	  { "typeinfo",		(tiarraytype)		},	\
270f8307e12SArchie Cobbs 	  { NULL },						\
271f8307e12SArchie Cobbs 	}							\
272f8307e12SArchie Cobbs }
273f8307e12SArchie Cobbs 
2744cf49a43SJulian Elischer /*
2754cf49a43SJulian Elischer  * For netgraph nodes that are somehow associated with file descriptors
2764cf49a43SJulian Elischer  * (e.g., a device that has a /dev entry and is also a netgraph node),
2774cf49a43SJulian Elischer  * we define a generic ioctl for requesting the corresponding nodeinfo
2784cf49a43SJulian Elischer  * structure and for assigning a name (if there isn't one already).
2794cf49a43SJulian Elischer  *
2804cf49a43SJulian Elischer  * For these to you need to also #include <sys/ioccom.h>.
2814cf49a43SJulian Elischer  */
2824cf49a43SJulian Elischer 
2834cf49a43SJulian Elischer #define NGIOCGINFO	_IOR('N', 40, struct nodeinfo)	/* get node info */
2844cf49a43SJulian Elischer #define NGIOCSETNAME	_IOW('N', 41, struct ngm_name)	/* set node name */
2854cf49a43SJulian Elischer 
286664a31e4SPeter Wemm #ifdef _KERNEL
2874cf49a43SJulian Elischer /*
2884cf49a43SJulian Elischer  * Allocate and initialize a netgraph message "msg" with "len"
2894cf49a43SJulian Elischer  * extra bytes of argument. Sets "msg" to NULL if fails.
2904cf49a43SJulian Elischer  * Does not initialize token.
2914cf49a43SJulian Elischer  */
2924cf49a43SJulian Elischer #define NG_MKMESSAGE(msg, cookie, cmdid, len, how)			\
2934cf49a43SJulian Elischer 	do {								\
2944cf49a43SJulian Elischer 	  MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg)	\
2954cf49a43SJulian Elischer 	    + (len), M_NETGRAPH, (how));				\
2964cf49a43SJulian Elischer 	  if ((msg) == NULL)						\
2974cf49a43SJulian Elischer 	    break;							\
2984cf49a43SJulian Elischer 	  bzero((msg), sizeof(struct ng_mesg) + (len));			\
2994cf49a43SJulian Elischer 	  (msg)->header.version = NG_VERSION;				\
3004cf49a43SJulian Elischer 	  (msg)->header.typecookie = (cookie);				\
3014cf49a43SJulian Elischer 	  (msg)->header.cmd = (cmdid);					\
3024cf49a43SJulian Elischer 	  (msg)->header.arglen = (len);					\
3034cf49a43SJulian Elischer 	  strncpy((msg)->header.cmdstr, #cmdid,				\
3044cf49a43SJulian Elischer 	    sizeof((msg)->header.cmdstr) - 1);				\
3054cf49a43SJulian Elischer 	} while (0)
3064cf49a43SJulian Elischer 
3074cf49a43SJulian Elischer /*
3084cf49a43SJulian Elischer  * Allocate and initialize a response "rsp" to a message "msg"
3094cf49a43SJulian Elischer  * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
3104cf49a43SJulian Elischer  */
3114cf49a43SJulian Elischer #define NG_MKRESPONSE(rsp, msg, len, how)				\
3124cf49a43SJulian Elischer 	do {								\
3134cf49a43SJulian Elischer 	  MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg)	\
3144cf49a43SJulian Elischer 	    + (len), M_NETGRAPH, (how));				\
3154cf49a43SJulian Elischer 	  if ((rsp) == NULL)						\
3164cf49a43SJulian Elischer 	    break;							\
3174cf49a43SJulian Elischer 	  bzero((rsp), sizeof(struct ng_mesg) + (len));			\
3184cf49a43SJulian Elischer 	  (rsp)->header.version = NG_VERSION;				\
3194cf49a43SJulian Elischer 	  (rsp)->header.arglen = (len);					\
3204cf49a43SJulian Elischer 	  (rsp)->header.token = (msg)->header.token;			\
3214cf49a43SJulian Elischer 	  (rsp)->header.typecookie = (msg)->header.typecookie;		\
3224cf49a43SJulian Elischer 	  (rsp)->header.cmd = (msg)->header.cmd;			\
3234cf49a43SJulian Elischer 	  bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr,		\
3244cf49a43SJulian Elischer 	    sizeof((rsp)->header.cmdstr));				\
3254cf49a43SJulian Elischer 	  (rsp)->header.flags |= NGF_RESP;				\
3264cf49a43SJulian Elischer 	} while (0)
327664a31e4SPeter Wemm #endif /* _KERNEL */
3284cf49a43SJulian Elischer 
3294cf49a43SJulian Elischer #endif /* _NETGRAPH_NG_MESSAGE_H_ */
3304cf49a43SJulian Elischer 
331