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