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