152419Sjulian/*
252419Sjulian * ng_message.h
3139823Simp */
4139823Simp
5139823Simp/*-
652419Sjulian * Copyright (c) 1996-1999 Whistle Communications, Inc.
752419Sjulian * All rights reserved.
852419Sjulian *
952419Sjulian * Subject to the following obligations and disclaimer of warranty, use and
1052419Sjulian * redistribution of this software, in source or object code forms, with or
1152419Sjulian * without modifications are expressly permitted by Whistle Communications;
1252419Sjulian * provided, however, that:
1352419Sjulian * 1. Any and all reproductions of the source or object code must include the
1452419Sjulian *    copyright notice above and the following disclaimer of warranties; and
1552419Sjulian * 2. No rights are granted, in any manner or form, to use Whistle
1652419Sjulian *    Communications, Inc. trademarks, including the mark "WHISTLE
1752419Sjulian *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
1852419Sjulian *    such appears in the above copyright notice or in the software.
1952419Sjulian *
2052419Sjulian * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
2152419Sjulian * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
2252419Sjulian * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
2352419Sjulian * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
2452419Sjulian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
2552419Sjulian * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
2652419Sjulian * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
2752419Sjulian * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
2852419Sjulian * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
2952419Sjulian * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
3052419Sjulian * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
3152419Sjulian * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
3252419Sjulian * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
3352419Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3452419Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3552419Sjulian * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
3652419Sjulian * OF SUCH DAMAGE.
3752419Sjulian *
3867506Sjulian * Author: Julian Elischer <julian@freebsd.org>
3952419Sjulian *
4052419Sjulian * $FreeBSD$
4152419Sjulian * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
4252419Sjulian */
4352419Sjulian
4452419Sjulian#ifndef _NETGRAPH_NG_MESSAGE_H_
45122481Sru#define _NETGRAPH_NG_MESSAGE_H_
4652419Sjulian
4752419Sjulian/* ASCII string size limits */
48122548Sharti#define	NG_TYPESIZ	32	/* max type name len (including null) */
49122548Sharti#define	NG_HOOKSIZ	32	/* max hook name len (including null) */
50122548Sharti#define	NG_NODESIZ	32	/* max node name len (including null) */
51122548Sharti#define	NG_PATHSIZ	512	/* max path len (including null) */
52122548Sharti#define	NG_CMDSTRSIZ	32	/* max command string (including null) */
53122548Sharti
5452419Sjulian#define NG_TEXTRESPONSE 1024	/* allow this length for a text response */
5552419Sjulian
5652419Sjulian/* A netgraph message */
5752419Sjulianstruct ng_mesg {
5852419Sjulian	struct	ng_msghdr {
5970159Sjulian		u_char		version;		/*  == NGM_VERSION */
60141375Sglebius		u_char		spare;			/* pad to 4 bytes */
61141375Sglebius		u_int16_t	spare2;
62141375Sglebius		u_int32_t	arglen;			/* length of data */
63134057Sjulian		u_int32_t	cmd;			/* command identifier */
6452419Sjulian		u_int32_t	flags;			/* message status */
6552419Sjulian		u_int32_t	token;			/* match with reply */
6652419Sjulian		u_int32_t	typecookie;		/* node's type cookie */
67125028Sharti		u_char		cmdstr[NG_CMDSTRSIZ];	/* cmd string + \0 */
6852419Sjulian	} header;
69121325Sharti	char	data[];			/* placeholder for actual data */
7052419Sjulian};
7153913Sarchie
72154265Sglebius/* This command is guaranteed to not alter data (or'd into the command). */
7370700Sjulian#define NGM_READONLY	0x10000000
74154265Sglebius/* This command is guaranteed to have a reply (or'd into the command). */
75154265Sglebius#define NGM_HASREPLY	0x20000000
7670159Sjulian
7753913Sarchie/* Keep this in sync with the above structure definition */
7853913Sarchie#define NG_GENERIC_NG_MESG_INFO(dtype)	{			\
7964508Sarchie	  { "version",		&ng_parse_uint8_type	},	\
8064508Sarchie	  { "spare",		&ng_parse_uint8_type	},	\
81141375Sglebius	  { "spare2",		&ng_parse_uint16_type	},	\
82141375Sglebius	  { "arglen",		&ng_parse_uint32_type	},	\
83134057Sjulian	  { "cmd",		&ng_parse_uint32_type	},	\
8464508Sarchie	  { "flags",		&ng_parse_hint32_type	},	\
8564508Sarchie	  { "token",		&ng_parse_uint32_type	},	\
8664508Sarchie	  { "typecookie",	&ng_parse_uint32_type	},	\
8753913Sarchie	  { "cmdstr",		&ng_parse_cmdbuf_type	},	\
8853913Sarchie	  { "data",		(dtype)			},	\
8997685Sarchie	  { NULL }						\
9053913Sarchie}
9153913Sarchie
9270159Sjulian/*
9370159Sjulian * Netgraph message header compatibility field
9470159Sjulian * Interfaces within the kernel are defined by a different
95141375Sglebius * value (see NG_ABI_VERSION in netgraph.h)
9670159Sjulian */
97141375Sglebius#define NG_VERSION	8
9853913Sarchie
9953913Sarchie/* Flags field flags */
10070700Sjulian#define NGF_ORIG	0x00000000	/* the msg is the original request */
10170700Sjulian#define NGF_RESP	0x00000001	/* the message is a response */
10271849Sjulian
103163461Sglebius/* Type of a unique node ID. */
104163461Sglebius#define ng_ID_t uint32_t
10553913Sarchie
10652419Sjulian/*
10752419Sjulian * Here we describe the "generic" messages that all nodes inherently
10852419Sjulian * understand. With the exception of NGM_TEXT_STATUS, these are handled
10952419Sjulian * automatically by the base netgraph code.
11052419Sjulian */
11152419Sjulian
11252419Sjulian/* Generic message type cookie */
113154265Sglebius#define NGM_GENERIC_COOKIE	1137070366
11452419Sjulian
115154265Sglebius/* Generic messages defined for this type cookie. */
116154265Sglebiusenum {
117154265Sglebius	NGM_SHUTDOWN	= 1,	/* Shut down node. */
118154265Sglebius	NGM_MKPEER	= 2,	/* Create and attach a peer node. */
119154265Sglebius	NGM_CONNECT	= 3,	/* Connect two nodes. */
120154265Sglebius	NGM_NAME	= 4,	/* Give a node a name. */
121154265Sglebius	NGM_RMHOOK	= 5,	/* Break a connection between two nodes. */
12252419Sjulian
123154265Sglebius	/* Get nodeinfo for target. */
124154265Sglebius	NGM_NODEINFO	= (6|NGM_READONLY|NGM_HASREPLY),
125154265Sglebius	/* Get list of hooks on node. */
126154265Sglebius	NGM_LISTHOOKS	= (7|NGM_READONLY|NGM_HASREPLY),
127154265Sglebius	/* List globally named nodes. */
128154265Sglebius	NGM_LISTNAMES	= (8|NGM_READONLY|NGM_HASREPLY),
129154265Sglebius	/* List all nodes. */
130154265Sglebius	NGM_LISTNODES	= (9|NGM_READONLY|NGM_HASREPLY),
131154265Sglebius	/* List installed node types. */
132154265Sglebius	NGM_LISTTYPES	= (10|NGM_READONLY|NGM_HASREPLY),
133154265Sglebius	/* (optional) Get text status. */
134154265Sglebius	NGM_TEXT_STATUS	= (11|NGM_READONLY|NGM_HASREPLY),
135154265Sglebius	/* Convert struct ng_mesg to ASCII. */
136154265Sglebius	NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
137154265Sglebius	/* Convert ASCII to struct ng_mesg. */
138154265Sglebius	NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
139154265Sglebius	/* (optional) Get/set text config. */
140154265Sglebius	NGM_TEXT_CONFIG	= 14,
141154265Sglebius};
142154265Sglebius
14369922Sjulian/*
14469922Sjulian * Flow control and intra node control messages.
14569922Sjulian * These are routed between nodes to allow flow control and to allow
14669922Sjulian * events to be passed around the graph.
14769922Sjulian * There will be some form of default handling for these but I
14869922Sjulian * do not yet know what it is..
14969922Sjulian */
15069922Sjulian
15169922Sjulian/* Generic message type cookie */
15269922Sjulian#define NGM_FLOW_COOKIE	851672669 /* temp for debugging */
15369922Sjulian
15469922Sjulian/* Upstream messages */
15569922Sjulian#define NGM_LINK_IS_UP		32	/* e.g. carrier found - no data */
15669922Sjulian#define NGM_LINK_IS_DOWN	33	/* carrier lost, includes queue state */
15769922Sjulian#define NGM_HIGH_WATER_PASSED	34	/* includes queue state */
15869922Sjulian#define NGM_LOW_WATER_PASSED	35	/* includes queue state */
15969922Sjulian#define NGM_SYNC_QUEUE_STATE	36	/* sync response from sending packet */
16069922Sjulian
16169922Sjulian/* Downstream messages */
16269922Sjulian#define NGM_DROP_LINK		41	/* drop DTR, etc. - stay in the graph */
16371902Sjulian#define NGM_RAISE_LINK		42	/* if you previously dropped it */
16471902Sjulian#define NGM_FLUSH_QUEUE		43	/* no data */
16570700Sjulian#define NGM_GET_BANDWIDTH	(44|NGM_READONLY)	/* either real or measured */
16671902Sjulian#define NGM_SET_XMIT_Q_LIMITS	45	/* includes queue state */
16770700Sjulian#define NGM_GET_XMIT_Q_LIMITS	(46|NGM_READONLY)	/* returns queue state */
16871902Sjulian#define NGM_MICROMANAGE		47	/* We want sync. queue state
16970700Sjulian						reply for each packet sent */
17071902Sjulian#define NGM_SET_FLOW_MANAGER	48	/* send flow control here */
17153913Sarchie/* Structure used for NGM_MKPEER */
17252419Sjulianstruct ngm_mkpeer {
173125028Sharti	char	type[NG_TYPESIZ];		/* peer type */
174125028Sharti	char	ourhook[NG_HOOKSIZ];		/* hook name */
175125028Sharti	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
17652419Sjulian};
17752419Sjulian
17853913Sarchie/* Keep this in sync with the above structure definition */
17953913Sarchie#define NG_GENERIC_MKPEER_INFO()	{			\
18053913Sarchie	  { "type",		&ng_parse_typebuf_type	},	\
18153913Sarchie	  { "ourhook",		&ng_parse_hookbuf_type	},	\
18253913Sarchie	  { "peerhook",		&ng_parse_hookbuf_type	},	\
18397685Sarchie	  { NULL }						\
18453913Sarchie}
18553913Sarchie
18653913Sarchie/* Structure used for NGM_CONNECT */
18752419Sjulianstruct ngm_connect {
188125028Sharti	char	path[NG_PATHSIZ];		/* peer path */
189125028Sharti	char	ourhook[NG_HOOKSIZ];		/* hook name */
190125028Sharti	char	peerhook[NG_HOOKSIZ];		/* peer hook name */
19152419Sjulian};
19252419Sjulian
19353913Sarchie/* Keep this in sync with the above structure definition */
19453913Sarchie#define NG_GENERIC_CONNECT_INFO()	{			\
19553913Sarchie	  { "path",		&ng_parse_pathbuf_type	},	\
19653913Sarchie	  { "ourhook",		&ng_parse_hookbuf_type	},	\
19753913Sarchie	  { "peerhook",		&ng_parse_hookbuf_type	},	\
19897685Sarchie	  { NULL }						\
19953913Sarchie}
20053913Sarchie
20153913Sarchie/* Structure used for NGM_NAME */
20252419Sjulianstruct ngm_name {
203125028Sharti	char	name[NG_NODESIZ];			/* node name */
20452419Sjulian};
20552419Sjulian
20653913Sarchie/* Keep this in sync with the above structure definition */
20753913Sarchie#define NG_GENERIC_NAME_INFO()	{				\
20853913Sarchie	  { "name",		&ng_parse_nodebuf_type	},	\
20997685Sarchie	  { NULL }						\
21053913Sarchie}
21153913Sarchie
21253913Sarchie/* Structure used for NGM_RMHOOK */
21352419Sjulianstruct ngm_rmhook {
214125028Sharti	char	ourhook[NG_HOOKSIZ];		/* hook name */
21552419Sjulian};
21652419Sjulian
21753913Sarchie/* Keep this in sync with the above structure definition */
21853913Sarchie#define NG_GENERIC_RMHOOK_INFO()	{			\
21953913Sarchie	  { "hook",		&ng_parse_hookbuf_type	},	\
22097685Sarchie	  { NULL }						\
22153913Sarchie}
22253913Sarchie
22353913Sarchie/* Structure used for NGM_NODEINFO */
22452419Sjulianstruct nodeinfo {
225125028Sharti	char		name[NG_NODESIZ];	/* node name (if any) */
226125028Sharti        char    	type[NG_TYPESIZ];	/* peer type */
22752722Sjulian	ng_ID_t		id;			/* unique identifier */
22852419Sjulian	u_int32_t	hooks;			/* number of active hooks */
22952419Sjulian};
23052419Sjulian
23153913Sarchie/* Keep this in sync with the above structure definition */
23253913Sarchie#define NG_GENERIC_NODEINFO_INFO()	{			\
23353913Sarchie	  { "name",		&ng_parse_nodebuf_type	},	\
23453913Sarchie	  { "type",		&ng_parse_typebuf_type	},	\
23564508Sarchie	  { "id",		&ng_parse_hint32_type	},	\
23664508Sarchie	  { "hooks",		&ng_parse_uint32_type	},	\
23797685Sarchie	  { NULL }						\
23853913Sarchie}
23953913Sarchie
24053913Sarchie/* Structure used for NGM_LISTHOOKS */
24152419Sjulianstruct linkinfo {
242125028Sharti	char		ourhook[NG_HOOKSIZ];	/* hook name */
243125028Sharti	char		peerhook[NG_HOOKSIZ];	/* peer hook */
24452419Sjulian	struct nodeinfo	nodeinfo;
24552419Sjulian};
24652419Sjulian
24753913Sarchie/* Keep this in sync with the above structure definition */
24853913Sarchie#define NG_GENERIC_LINKINFO_INFO(nitype)	{		\
24953913Sarchie	  { "ourhook",		&ng_parse_hookbuf_type	},	\
25053913Sarchie	  { "peerhook",		&ng_parse_hookbuf_type	},	\
25153913Sarchie	  { "nodeinfo",		(nitype)		},	\
25297685Sarchie	  { NULL }						\
25353913Sarchie}
25453913Sarchie
25552419Sjulianstruct hooklist {
25652419Sjulian	struct nodeinfo nodeinfo;		/* node information */
257121325Sharti	struct linkinfo link[];			/* info about each hook */
25852419Sjulian};
25952419Sjulian
26053913Sarchie/* Keep this in sync with the above structure definition */
26153913Sarchie#define NG_GENERIC_HOOKLIST_INFO(nitype,litype)	{		\
26253913Sarchie	  { "nodeinfo",		(nitype)		},	\
26353913Sarchie	  { "linkinfo",		(litype)		},	\
26497685Sarchie	  { NULL }						\
26553913Sarchie}
26653913Sarchie
26753913Sarchie/* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
26852419Sjulianstruct namelist {
26952419Sjulian	u_int32_t	numnames;
270121325Sharti	struct nodeinfo	nodeinfo[];
27152419Sjulian};
27252419Sjulian
27353913Sarchie/* Keep this in sync with the above structure definition */
27453913Sarchie#define NG_GENERIC_LISTNODES_INFO(niarraytype)	{		\
27564508Sarchie	  { "numnames",		&ng_parse_uint32_type	},	\
27653913Sarchie	  { "nodeinfo",		(niarraytype)		},	\
27797685Sarchie	  { NULL }						\
27853913Sarchie}
27953913Sarchie
28053913Sarchie/* Structure used for NGM_LISTTYPES */
28152419Sjulianstruct typeinfo {
282125028Sharti	char		type_name[NG_TYPESIZ];	/* name of type */
283125028Sharti	u_int32_t	numnodes;		/* number alive */
28452419Sjulian};
28552419Sjulian
28653913Sarchie/* Keep this in sync with the above structure definition */
28753913Sarchie#define NG_GENERIC_TYPEINFO_INFO()		{		\
28853913Sarchie	  { "typename",		&ng_parse_typebuf_type	},	\
28964508Sarchie	  { "numnodes",		&ng_parse_uint32_type	},	\
29097685Sarchie	  { NULL }						\
29153913Sarchie}
29253913Sarchie
29352419Sjulianstruct typelist {
29452419Sjulian	u_int32_t	numtypes;
295121325Sharti	struct typeinfo	typeinfo[];
29652419Sjulian};
29752419Sjulian
29853913Sarchie/* Keep this in sync with the above structure definition */
29953913Sarchie#define NG_GENERIC_TYPELIST_INFO(tiarraytype)	{		\
30064508Sarchie	  { "numtypes",		&ng_parse_uint32_type	},	\
30153913Sarchie	  { "typeinfo",		(tiarraytype)		},	\
30297685Sarchie	  { NULL }						\
30353913Sarchie}
30453913Sarchie
30569922Sjulianstruct ngm_bandwidth {
30669922Sjulian	u_int64_t	nominal_in;
30769922Sjulian	u_int64_t	seen_in;
30869922Sjulian	u_int64_t	nominal_out;
30969922Sjulian	u_int64_t	seen_out;
31069922Sjulian};
31169922Sjulian
31269922Sjulian/* Keep this in sync with the above structure definition */
31369922Sjulian#define NG_GENERIC_BANDWIDTH_INFO()	{			\
31469922Sjulian	  { "nominal_in",	&ng_parse_uint64_type	},	\
31569922Sjulian	  { "seen_in",		&ng_parse_uint64_type	},	\
31669922Sjulian	  { "nominal_out",	&ng_parse_uint64_type	},	\
31769922Sjulian	  { "seen_out",		&ng_parse_uint64_type	},	\
31897685Sarchie	  { NULL }						\
31969922Sjulian}
32069922Sjulian
32152419Sjulian/*
32269922Sjulian * Information about a node's 'output' queue.
32369922Sjulian * This is NOT the netgraph input queueing mechanism,
32469922Sjulian * but rather any queue the node may implement internally
32569922Sjulian * This has to consider ALTQ if we are to work with it.
32669922Sjulian * As far as I can see, ALTQ counts PACKETS, not bytes.
32769922Sjulian * If ALTQ has several queues and one has passed a watermark
32869922Sjulian * we should have the priority of that queue be real (and not -1)
32969922Sjulian * XXX ALTQ stuff is just an idea.....
33069922Sjulian */
33169922Sjulianstruct ngm_queue_state {
33269922Sjulian	u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
33369922Sjulian	u_int	max_queuelen_bytes;
33469922Sjulian	u_int	max_queuelen_packets;
33569922Sjulian	u_int	low_watermark;
33669922Sjulian	u_int	high_watermark;
33769922Sjulian	u_int	current;
33869922Sjulian};
33969922Sjulian
34069922Sjulian/* Keep this in sync with the above structure definition */
34169922Sjulian#define NG_GENERIC_QUEUE_INFO()	{				\
34269922Sjulian	  { "max_queuelen_bytes", &ng_parse_uint_type	},	\
34369922Sjulian	  { "max_queuelen_packets", &ng_parse_uint_type	},	\
34469922Sjulian	  { "high_watermark",	&ng_parse_uint_type	},	\
34569922Sjulian	  { "low_watermark",	&ng_parse_uint_type	},	\
34669922Sjulian	  { "current",		&ng_parse_uint_type	},	\
34797685Sarchie	  { NULL }						\
34869922Sjulian}
34969922Sjulian
35069922Sjulian/* Tell a node who to send async flow control info to. */
35169922Sjulianstruct flow_manager {
35269922Sjulian	ng_ID_t		id;			/* unique identifier */
35369922Sjulian};
35469922Sjulian
35569922Sjulian/* Keep this in sync with the above structure definition */
35669922Sjulian#define NG_GENERIC_FLOW_MANAGER_INFO()	{			\
35769922Sjulian	  { "id",		&ng_parse_hint32_type	},	\
35897685Sarchie	  { NULL }						\
35969922Sjulian}
36069922Sjulian
36169922Sjulian
36269922Sjulian/*
36352419Sjulian * For netgraph nodes that are somehow associated with file descriptors
36452419Sjulian * (e.g., a device that has a /dev entry and is also a netgraph node),
36552419Sjulian * we define a generic ioctl for requesting the corresponding nodeinfo
36652419Sjulian * structure and for assigning a name (if there isn't one already).
36752419Sjulian *
36852419Sjulian * For these to you need to also #include <sys/ioccom.h>.
36952419Sjulian */
37052419Sjulian
37152419Sjulian#define NGIOCGINFO	_IOR('N', 40, struct nodeinfo)	/* get node info */
37252419Sjulian#define NGIOCSETNAME	_IOW('N', 41, struct ngm_name)	/* set node name */
37352419Sjulian
37455205Speter#ifdef _KERNEL
37552419Sjulian/*
37652419Sjulian * Allocate and initialize a netgraph message "msg" with "len"
37752419Sjulian * extra bytes of argument. Sets "msg" to NULL if fails.
37852419Sjulian * Does not initialize token.
37952419Sjulian */
38052419Sjulian#define NG_MKMESSAGE(msg, cookie, cmdid, len, how)			\
38152419Sjulian	do {								\
382184205Sdes	  (msg) = malloc(sizeof(struct ng_mesg)				\
38370700Sjulian	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
38452419Sjulian	  if ((msg) == NULL)						\
38552419Sjulian	    break;							\
38652419Sjulian	  (msg)->header.version = NG_VERSION;				\
38752419Sjulian	  (msg)->header.typecookie = (cookie);				\
38852419Sjulian	  (msg)->header.cmd = (cmdid);					\
38952419Sjulian	  (msg)->header.arglen = (len);					\
39052419Sjulian	  strncpy((msg)->header.cmdstr, #cmdid,				\
39152419Sjulian	    sizeof((msg)->header.cmdstr) - 1);				\
39252419Sjulian	} while (0)
39352419Sjulian
39452419Sjulian/*
39552419Sjulian * Allocate and initialize a response "rsp" to a message "msg"
39652419Sjulian * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
39752419Sjulian */
39852419Sjulian#define NG_MKRESPONSE(rsp, msg, len, how)				\
39952419Sjulian	do {								\
400184205Sdes	  (rsp) = malloc(sizeof(struct ng_mesg)				\
40170700Sjulian	    + (len), M_NETGRAPH_MSG, (how) | M_ZERO);			\
40252419Sjulian	  if ((rsp) == NULL)						\
40352419Sjulian	    break;							\
40452419Sjulian	  (rsp)->header.version = NG_VERSION;				\
40552419Sjulian	  (rsp)->header.arglen = (len);					\
40652419Sjulian	  (rsp)->header.token = (msg)->header.token;			\
40752419Sjulian	  (rsp)->header.typecookie = (msg)->header.typecookie;		\
40852419Sjulian	  (rsp)->header.cmd = (msg)->header.cmd;			\
40952419Sjulian	  bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr,		\
41052419Sjulian	    sizeof((rsp)->header.cmdstr));				\
41152419Sjulian	  (rsp)->header.flags |= NGF_RESP;				\
41252419Sjulian	} while (0)
413145324Sglebius
414145324Sglebius/*
415145324Sglebius * Make a copy of message. Sets "copy" to NULL if fails.
416145324Sglebius */
417145324Sglebius#define	NG_COPYMESSAGE(copy, msg, how)					\
418145324Sglebius	do {								\
419184205Sdes	  (copy) = malloc(sizeof(struct ng_mesg)			\
420184205Sdes	    + (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO);	\
421145324Sglebius	  if ((copy) == NULL)						\
422145324Sglebius	    break;							\
423145324Sglebius	  (copy)->header.version = NG_VERSION;				\
424145324Sglebius	  (copy)->header.arglen = (msg)->header.arglen;			\
425145324Sglebius	  (copy)->header.token = (msg)->header.token;			\
426145324Sglebius	  (copy)->header.typecookie = (msg)->header.typecookie;		\
427145324Sglebius	  (copy)->header.cmd = (msg)->header.cmd;			\
428145324Sglebius	  (copy)->header.flags = (msg)->header.flags;			\
429145324Sglebius	  bcopy((msg)->header.cmdstr, (copy)->header.cmdstr,		\
430145324Sglebius	    sizeof((copy)->header.cmdstr));				\
431145324Sglebius	  if ((msg)->header.arglen > 0)					\
432145324Sglebius	    bcopy((msg)->data, (copy)->data, (msg)->header.arglen);	\
433145324Sglebius	} while (0)
434145324Sglebius
43555205Speter#endif /* _KERNEL */
43652419Sjulian
43752419Sjulian#endif /* _NETGRAPH_NG_MESSAGE_H_ */
438