Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / sys / netgraph / ng_message.h
blob45ef0cc2e7ea310394aa4a2c8247e745e19a6795
2 /*
3 * ng_message.h
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and
9 * redistribution of this software, in source or object code forms, with or
10 * without modifications are expressly permitted by Whistle Communications;
11 * provided, however, that:
12 * 1. Any and all reproductions of the source or object code must include the
13 * copyright notice above and the following disclaimer of warranties; and
14 * 2. No rights are granted, in any manner or form, to use Whistle
15 * Communications, Inc. trademarks, including the mark "WHISTLE
16 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17 * such appears in the above copyright notice or in the software.
19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
37 * Author: Julian Elischer <julian@freebsd.org>
39 * $FreeBSD: src/sys/netgraph/ng_message.h,v 1.4.2.5 2002/07/02 23:44:02 archie Exp $
40 * $DragonFly: src/sys/netgraph/ng_message.h,v 1.6 2008/01/05 14:02:38 swildner Exp $
41 * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
44 #ifndef _NETGRAPH_NG_MESSAGE_H_
45 #define _NETGRAPH_NG_MESSAGE_H_
47 #ifndef _SYS_TYPES_H_
48 #include <sys/types.h>
49 #endif
51 /* ASCII string size limits */
52 #define NG_TYPESIZ 32 /* max type name len (including null) */
53 #define NG_HOOKSIZ 32 /* max hook name len (including null) */
54 #define NG_NODESIZ 32 /* max node name len (including null) */
55 #define NG_PATHSIZ 512 /* max path len (including null) */
56 #define NG_CMDSTRSIZ 32 /* max command string (including null) */
57 #define NG_TEXTRESPONSE 1024 /* allow this length for a text response */
59 /* A netgraph message */
60 struct ng_mesg {
61 struct ng_msghdr {
62 u_char version; /* must == NG_VERSION */
63 u_char spare; /* pad to 2 bytes */
64 u_int16_t arglen; /* length of data */
65 u_int32_t flags; /* message status */
66 u_int32_t token; /* match with reply */
67 u_int32_t typecookie; /* node's type cookie */
68 u_int32_t cmd; /* command identifier */
69 u_char cmdstr[NG_CMDSTRSIZ]; /* cmd string */
70 } header;
71 char data[0]; /* placeholder for actual data */
74 /* Keep this in sync with the above structure definition */
75 #define NG_GENERIC_NG_MESG_INFO(dtype) { \
76 { "version", &ng_parse_uint8_type }, \
77 { "spare", &ng_parse_uint8_type }, \
78 { "arglen", &ng_parse_uint16_type }, \
79 { "flags", &ng_parse_hint32_type }, \
80 { "token", &ng_parse_uint32_type }, \
81 { "typecookie", &ng_parse_uint32_type }, \
82 { "cmd", &ng_parse_uint32_type }, \
83 { "cmdstr", &ng_parse_cmdbuf_type }, \
84 { "data", (dtype) }, \
85 { NULL } \
88 /* Negraph type binary compatibility field */
89 #define NG_VERSION 2
91 /* Flags field flags */
92 #define NGF_ORIG 0x0000 /* the msg is the original request */
93 #define NGF_RESP 0x0001 /* the message is a response */
95 /* Type of a unique node ID */
96 #define ng_ID_t unsigned int
99 * Here we describe the "generic" messages that all nodes inherently
100 * understand. With the exception of NGM_TEXT_STATUS, these are handled
101 * automatically by the base netgraph code.
104 /* Generic message type cookie */
105 #define NGM_GENERIC_COOKIE 851672668
107 /* Generic messages defined for this type cookie */
108 #define NGM_SHUTDOWN 1 /* shut down node */
109 #define NGM_MKPEER 2 /* create and attach a peer node */
110 #define NGM_CONNECT 3 /* connect two nodes */
111 #define NGM_NAME 4 /* give a node a name */
112 #define NGM_RMHOOK 5 /* break a connection btw. two nodes */
113 #define NGM_NODEINFO 6 /* get nodeinfo for the target */
114 #define NGM_LISTHOOKS 7 /* get list of hooks on node */
115 #define NGM_LISTNAMES 8 /* list all globally named nodes */
116 #define NGM_LISTNODES 9 /* list all nodes, named and unnamed */
117 #define NGM_LISTTYPES 10 /* list all installed node types */
118 #define NGM_TEXT_STATUS 11 /* (optional) get text status report */
119 #define NGM_BINARY2ASCII 12 /* convert struct ng_mesg to ascii */
120 #define NGM_ASCII2BINARY 13 /* convert ascii to struct ng_mesg */
121 #define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */
123 /* Structure used for NGM_MKPEER */
124 struct ngm_mkpeer {
125 char type[NG_TYPESIZ]; /* peer type */
126 char ourhook[NG_HOOKSIZ]; /* hook name */
127 char peerhook[NG_HOOKSIZ]; /* peer hook name */
130 /* Keep this in sync with the above structure definition */
131 #define NG_GENERIC_MKPEER_INFO() { \
132 { "type", &ng_parse_typebuf_type }, \
133 { "ourhook", &ng_parse_hookbuf_type }, \
134 { "peerhook", &ng_parse_hookbuf_type }, \
135 { NULL } \
138 /* Structure used for NGM_CONNECT */
139 struct ngm_connect {
140 char path[NG_PATHSIZ]; /* peer path */
141 char ourhook[NG_HOOKSIZ]; /* hook name */
142 char peerhook[NG_HOOKSIZ]; /* peer hook name */
145 /* Keep this in sync with the above structure definition */
146 #define NG_GENERIC_CONNECT_INFO() { \
147 { "path", &ng_parse_pathbuf_type }, \
148 { "ourhook", &ng_parse_hookbuf_type }, \
149 { "peerhook", &ng_parse_hookbuf_type }, \
150 { NULL } \
153 /* Structure used for NGM_NAME */
154 struct ngm_name {
155 char name[NG_NODESIZ]; /* node name */
158 /* Keep this in sync with the above structure definition */
159 #define NG_GENERIC_NAME_INFO() { \
160 { "name", &ng_parse_nodebuf_type }, \
161 { NULL } \
164 /* Structure used for NGM_RMHOOK */
165 struct ngm_rmhook {
166 char ourhook[NG_HOOKSIZ]; /* hook name */
169 /* Keep this in sync with the above structure definition */
170 #define NG_GENERIC_RMHOOK_INFO() { \
171 { "hook", &ng_parse_hookbuf_type }, \
172 { NULL } \
175 /* Structure used for NGM_NODEINFO */
176 struct nodeinfo {
177 char name[NG_NODESIZ]; /* node name (if any) */
178 char type[NG_TYPESIZ]; /* peer type */
179 ng_ID_t id; /* unique identifier */
180 u_int32_t hooks; /* number of active hooks */
183 /* Keep this in sync with the above structure definition */
184 #define NG_GENERIC_NODEINFO_INFO() { \
185 { "name", &ng_parse_nodebuf_type }, \
186 { "type", &ng_parse_typebuf_type }, \
187 { "id", &ng_parse_hint32_type }, \
188 { "hooks", &ng_parse_uint32_type }, \
189 { NULL } \
192 /* Structure used for NGM_LISTHOOKS */
193 struct linkinfo {
194 char ourhook[NG_HOOKSIZ]; /* hook name */
195 char peerhook[NG_HOOKSIZ]; /* peer hook */
196 struct nodeinfo nodeinfo;
199 /* Keep this in sync with the above structure definition */
200 #define NG_GENERIC_LINKINFO_INFO(nitype) { \
201 { "ourhook", &ng_parse_hookbuf_type }, \
202 { "peerhook", &ng_parse_hookbuf_type }, \
203 { "nodeinfo", (nitype) }, \
204 { NULL } \
207 struct hooklist {
208 struct nodeinfo nodeinfo; /* node information */
209 struct linkinfo link[0]; /* info about each hook */
212 /* Keep this in sync with the above structure definition */
213 #define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \
214 { "nodeinfo", (nitype) }, \
215 { "linkinfo", (litype) }, \
216 { NULL } \
219 /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
220 struct namelist {
221 u_int32_t numnames;
222 struct nodeinfo nodeinfo[0];
225 /* Keep this in sync with the above structure definition */
226 #define NG_GENERIC_LISTNODES_INFO(niarraytype) { \
227 { "numnames", &ng_parse_uint32_type }, \
228 { "nodeinfo", (niarraytype) }, \
229 { NULL } \
232 /* Structure used for NGM_LISTTYPES */
233 struct typeinfo {
234 char type_name[NG_TYPESIZ]; /* name of type */
235 u_int32_t numnodes; /* number alive */
238 /* Keep this in sync with the above structure definition */
239 #define NG_GENERIC_TYPEINFO_INFO() { \
240 { "typename", &ng_parse_typebuf_type }, \
241 { "numnodes", &ng_parse_uint32_type }, \
242 { NULL } \
245 struct typelist {
246 u_int32_t numtypes;
247 struct typeinfo typeinfo[0];
250 /* Keep this in sync with the above structure definition */
251 #define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \
252 { "numtypes", &ng_parse_uint32_type }, \
253 { "typeinfo", (tiarraytype) }, \
254 { NULL } \
258 * For netgraph nodes that are somehow associated with file descriptors
259 * (e.g., a device that has a /dev entry and is also a netgraph node),
260 * we define a generic ioctl for requesting the corresponding nodeinfo
261 * structure and for assigning a name (if there isn't one already).
263 * For these to you need to also #include <sys/ioccom.h>.
266 #define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */
267 #define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */
269 #ifdef _KERNEL
271 * Allocate and initialize a netgraph message "msg" with "len"
272 * extra bytes of argument. Sets "msg" to NULL if fails.
273 * Does not initialize token.
275 #define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \
276 do { \
277 MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg) \
278 + (len), M_NETGRAPH, (how) | M_ZERO); \
279 if ((msg) == NULL) \
280 break; \
281 (msg)->header.version = NG_VERSION; \
282 (msg)->header.typecookie = (cookie); \
283 (msg)->header.cmd = (cmdid); \
284 (msg)->header.arglen = (len); \
285 strncpy((msg)->header.cmdstr, #cmdid, \
286 sizeof((msg)->header.cmdstr) - 1); \
287 } while (0)
290 * Allocate and initialize a response "rsp" to a message "msg"
291 * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
293 #define NG_MKRESPONSE(rsp, msg, len, how) \
294 do { \
295 MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg) \
296 + (len), M_NETGRAPH, (how) | M_ZERO); \
297 if ((rsp) == NULL) \
298 break; \
299 (rsp)->header.version = NG_VERSION; \
300 (rsp)->header.arglen = (len); \
301 (rsp)->header.token = (msg)->header.token; \
302 (rsp)->header.typecookie = (msg)->header.typecookie; \
303 (rsp)->header.cmd = (msg)->header.cmd; \
304 bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \
305 sizeof((rsp)->header.cmdstr)); \
306 (rsp)->header.flags |= NGF_RESP; \
307 } while (0)
308 #endif /* _KERNEL */
310 #endif /* _NETGRAPH_NG_MESSAGE_H_ */