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 *
40 * $FreeBSD: releng/6.4/sys/netgraph/ng_message.h 154615 2006-01-21 10:04:40Z glebius $
41 * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
42 */
43
44 #ifndef _NETGRAPH_NG_MESSAGE_H_
45 #define _NETGRAPH_NG_MESSAGE_H_
46
47 /* ASCII string size limits */
48 #define NG_TYPESIZ 32 /* max type name len (including null) */
49 #define NG_HOOKSIZ 32 /* max hook name len (including null) */
50 #define NG_NODESIZ 32 /* max node name len (including null) */
51 #define NG_PATHSIZ 512 /* max path len (including null) */
52 #define NG_CMDSTRSIZ 32 /* max command string (including null) */
53
54 #ifndef BURN_BRIDGES
55 /* don't use these - they will go away */
56 #define NG_TYPELEN (NG_TYPESIZ - 1)
57 #define NG_HOOKLEN (NG_HOOKSIZ - 1)
58 #define NG_NODELEN (NG_NODESIZ - 1)
59 #define NG_PATHLEN (NG_PATHSIZ - 1)
60 #define NG_CMDSTRLEN (NG_CMDSTRSIZ - 1)
61 #endif
62
63 #define NG_TEXTRESPONSE 1024 /* allow this length for a text response */
64
65 /* A netgraph message */
66 struct ng_mesg {
67 struct ng_msghdr {
68 u_char version; /* == NGM_VERSION */
69 u_char spare; /* pad to 4 bytes */
70 u_int16_t spare2;
71 u_int32_t arglen; /* length of data */
72 u_int32_t cmd; /* command identifier */
73 u_int32_t flags; /* message status */
74 u_int32_t token; /* match with reply */
75 u_int32_t typecookie; /* node's type cookie */
76 u_char cmdstr[NG_CMDSTRSIZ]; /* cmd string + \0 */
77 } header;
78 char data[]; /* placeholder for actual data */
79 };
80
81 /* This command is guaranteed to not alter data (or'd into the command). */
82 #define NGM_READONLY 0x10000000
83 /* This command is guaranteed to have a reply (or'd into the command). */
84 #define NGM_HASREPLY 0x20000000
85
86 /* Keep this in sync with the above structure definition */
87 #define NG_GENERIC_NG_MESG_INFO(dtype) { \
88 { "version", &ng_parse_uint8_type }, \
89 { "spare", &ng_parse_uint8_type }, \
90 { "spare2", &ng_parse_uint16_type }, \
91 { "arglen", &ng_parse_uint32_type }, \
92 { "cmd", &ng_parse_uint32_type }, \
93 { "flags", &ng_parse_hint32_type }, \
94 { "token", &ng_parse_uint32_type }, \
95 { "typecookie", &ng_parse_uint32_type }, \
96 { "cmdstr", &ng_parse_cmdbuf_type }, \
97 { "data", (dtype) }, \
98 { NULL } \
99 }
100
101 /*
102 * Netgraph message header compatibility field
103 * Interfaces within the kernel are defined by a different
104 * value (see NG_ABI_VERSION in netgraph.h)
105 */
106 #define NG_VERSION 8
107
108 /* Flags field flags */
109 #define NGF_ORIG 0x00000000 /* the msg is the original request */
110 #define NGF_RESP 0x00000001 /* the message is a response */
111
112 /* Type of a unique node ID */
113 #define ng_ID_t unsigned int
114
115 /*
116 * Here we describe the "generic" messages that all nodes inherently
117 * understand. With the exception of NGM_TEXT_STATUS, these are handled
118 * automatically by the base netgraph code.
119 */
120
121 /* Generic message type cookie */
122 #define NGM_GENERIC_COOKIE 977674408
123
124 /* Generic messages defined for this type cookie */
125 #define NGM_SHUTDOWN 1 /* shut down node */
126 #define NGM_MKPEER 2 /* create and attach a peer node */
127 #define NGM_CONNECT 3 /* connect two nodes */
128 #define NGM_NAME 4 /* give a node a name */
129 #define NGM_RMHOOK 5 /* break a connection btw. two nodes */
130 #define NGM_NODEINFO (6|NGM_READONLY)/* get nodeinfo for target */
131 #define NGM_LISTHOOKS (7|NGM_READONLY)/* get list of hooks on node */
132 #define NGM_LISTNAMES (8|NGM_READONLY)/* list globally named nodes */
133 #define NGM_LISTNODES (9|NGM_READONLY)/* list nodes, named & not */
134 #define NGM_LISTTYPES (10|NGM_READONLY)/* list installed node types */
135 #define NGM_TEXT_STATUS (11|NGM_READONLY)/* (optional) get txt status */
136 #define NGM_BINARY2ASCII (12|NGM_READONLY)/* convert ng_mesg to ascii */
137 #define NGM_ASCII2BINARY (13|NGM_READONLY)/* convert ascii to ng_mesg */
138 #define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */
139
140 /*
141 * Flow control and intra node control messages.
142 * These are routed between nodes to allow flow control and to allow
143 * events to be passed around the graph.
144 * There will be some form of default handling for these but I
145 * do not yet know what it is..
146 */
147
148 /* Generic message type cookie */
149 #define NGM_FLOW_COOKIE 851672669 /* temp for debugging */
150
151 /* Upstream messages */
152 #define NGM_LINK_IS_UP 32 /* e.g. carrier found - no data */
153 #define NGM_LINK_IS_DOWN 33 /* carrier lost, includes queue state */
154 #define NGM_HIGH_WATER_PASSED 34 /* includes queue state */
155 #define NGM_LOW_WATER_PASSED 35 /* includes queue state */
156 #define NGM_SYNC_QUEUE_STATE 36 /* sync response from sending packet */
157
158 /* Downstream messages */
159 #define NGM_DROP_LINK 41 /* drop DTR, etc. - stay in the graph */
160 #define NGM_RAISE_LINK 42 /* if you previously dropped it */
161 #define NGM_FLUSH_QUEUE 43 /* no data */
162 #define NGM_GET_BANDWIDTH (44|NGM_READONLY) /* either real or measured */
163 #define NGM_SET_XMIT_Q_LIMITS 45 /* includes queue state */
164 #define NGM_GET_XMIT_Q_LIMITS (46|NGM_READONLY) /* returns queue state */
165 #define NGM_MICROMANAGE 47 /* We want sync. queue state
166 reply for each packet sent */
167 #define NGM_SET_FLOW_MANAGER 48 /* send flow control here */
168 /* Structure used for NGM_MKPEER */
169 struct ngm_mkpeer {
170 char type[NG_TYPESIZ]; /* peer type */
171 char ourhook[NG_HOOKSIZ]; /* hook name */
172 char peerhook[NG_HOOKSIZ]; /* peer hook name */
173 };
174
175 /* Keep this in sync with the above structure definition */
176 #define NG_GENERIC_MKPEER_INFO() { \
177 { "type", &ng_parse_typebuf_type }, \
178 { "ourhook", &ng_parse_hookbuf_type }, \
179 { "peerhook", &ng_parse_hookbuf_type }, \
180 { NULL } \
181 }
182
183 /* Structure used for NGM_CONNECT */
184 struct ngm_connect {
185 char path[NG_PATHSIZ]; /* peer path */
186 char ourhook[NG_HOOKSIZ]; /* hook name */
187 char peerhook[NG_HOOKSIZ]; /* peer hook name */
188 };
189
190 /* Keep this in sync with the above structure definition */
191 #define NG_GENERIC_CONNECT_INFO() { \
192 { "path", &ng_parse_pathbuf_type }, \
193 { "ourhook", &ng_parse_hookbuf_type }, \
194 { "peerhook", &ng_parse_hookbuf_type }, \
195 { NULL } \
196 }
197
198 /* Structure used for NGM_NAME */
199 struct ngm_name {
200 char name[NG_NODESIZ]; /* node name */
201 };
202
203 /* Keep this in sync with the above structure definition */
204 #define NG_GENERIC_NAME_INFO() { \
205 { "name", &ng_parse_nodebuf_type }, \
206 { NULL } \
207 }
208
209 /* Structure used for NGM_RMHOOK */
210 struct ngm_rmhook {
211 char ourhook[NG_HOOKSIZ]; /* hook name */
212 };
213
214 /* Keep this in sync with the above structure definition */
215 #define NG_GENERIC_RMHOOK_INFO() { \
216 { "hook", &ng_parse_hookbuf_type }, \
217 { NULL } \
218 }
219
220 /* Structure used for NGM_NODEINFO */
221 struct nodeinfo {
222 char name[NG_NODESIZ]; /* node name (if any) */
223 char type[NG_TYPESIZ]; /* peer type */
224 ng_ID_t id; /* unique identifier */
225 u_int32_t hooks; /* number of active hooks */
226 };
227
228 /* Keep this in sync with the above structure definition */
229 #define NG_GENERIC_NODEINFO_INFO() { \
230 { "name", &ng_parse_nodebuf_type }, \
231 { "type", &ng_parse_typebuf_type }, \
232 { "id", &ng_parse_hint32_type }, \
233 { "hooks", &ng_parse_uint32_type }, \
234 { NULL } \
235 }
236
237 /* Structure used for NGM_LISTHOOKS */
238 struct linkinfo {
239 char ourhook[NG_HOOKSIZ]; /* hook name */
240 char peerhook[NG_HOOKSIZ]; /* peer hook */
241 struct nodeinfo nodeinfo;
242 };
243
244 /* Keep this in sync with the above structure definition */
245 #define NG_GENERIC_LINKINFO_INFO(nitype) { \
246 { "ourhook", &ng_parse_hookbuf_type }, \
247 { "peerhook", &ng_parse_hookbuf_type }, \
248 { "nodeinfo", (nitype) }, \
249 { NULL } \
250 }
251
252 struct hooklist {
253 struct nodeinfo nodeinfo; /* node information */
254 struct linkinfo link[]; /* info about each hook */
255 };
256
257 /* Keep this in sync with the above structure definition */
258 #define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \
259 { "nodeinfo", (nitype) }, \
260 { "linkinfo", (litype) }, \
261 { NULL } \
262 }
263
264 /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
265 struct namelist {
266 u_int32_t numnames;
267 struct nodeinfo nodeinfo[];
268 };
269
270 /* Keep this in sync with the above structure definition */
271 #define NG_GENERIC_LISTNODES_INFO(niarraytype) { \
272 { "numnames", &ng_parse_uint32_type }, \
273 { "nodeinfo", (niarraytype) }, \
274 { NULL } \
275 }
276
277 /* Structure used for NGM_LISTTYPES */
278 struct typeinfo {
279 char type_name[NG_TYPESIZ]; /* name of type */
280 u_int32_t numnodes; /* number alive */
281 };
282
283 /* Keep this in sync with the above structure definition */
284 #define NG_GENERIC_TYPEINFO_INFO() { \
285 { "typename", &ng_parse_typebuf_type }, \
286 { "numnodes", &ng_parse_uint32_type }, \
287 { NULL } \
288 }
289
290 struct typelist {
291 u_int32_t numtypes;
292 struct typeinfo typeinfo[];
293 };
294
295 /* Keep this in sync with the above structure definition */
296 #define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \
297 { "numtypes", &ng_parse_uint32_type }, \
298 { "typeinfo", (tiarraytype) }, \
299 { NULL } \
300 }
301
302 struct ngm_bandwidth {
303 u_int64_t nominal_in;
304 u_int64_t seen_in;
305 u_int64_t nominal_out;
306 u_int64_t seen_out;
307 };
308
309 /* Keep this in sync with the above structure definition */
310 #define NG_GENERIC_BANDWIDTH_INFO() { \
311 { "nominal_in", &ng_parse_uint64_type }, \
312 { "seen_in", &ng_parse_uint64_type }, \
313 { "nominal_out", &ng_parse_uint64_type }, \
314 { "seen_out", &ng_parse_uint64_type }, \
315 { NULL } \
316 }
317
318 /*
319 * Information about a node's 'output' queue.
320 * This is NOT the netgraph input queueing mechanism,
321 * but rather any queue the node may implement internally
322 * This has to consider ALTQ if we are to work with it.
323 * As far as I can see, ALTQ counts PACKETS, not bytes.
324 * If ALTQ has several queues and one has passed a watermark
325 * we should have the priority of that queue be real (and not -1)
326 * XXX ALTQ stuff is just an idea.....
327 */
328 struct ngm_queue_state {
329 u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
330 u_int max_queuelen_bytes;
331 u_int max_queuelen_packets;
332 u_int low_watermark;
333 u_int high_watermark;
334 u_int current;
335 };
336
337 /* Keep this in sync with the above structure definition */
338 #define NG_GENERIC_QUEUE_INFO() { \
339 { "max_queuelen_bytes", &ng_parse_uint_type }, \
340 { "max_queuelen_packets", &ng_parse_uint_type }, \
341 { "high_watermark", &ng_parse_uint_type }, \
342 { "low_watermark", &ng_parse_uint_type }, \
343 { "current", &ng_parse_uint_type }, \
344 { NULL } \
345 }
346
347 /* Tell a node who to send async flow control info to. */
348 struct flow_manager {
349 ng_ID_t id; /* unique identifier */
350 };
351
352 /* Keep this in sync with the above structure definition */
353 #define NG_GENERIC_FLOW_MANAGER_INFO() { \
354 { "id", &ng_parse_hint32_type }, \
355 { NULL } \
356 }
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 MALLOC((msg), struct ng_mesg *, 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 MALLOC((rsp), struct ng_mesg *, 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 MALLOC((copy), struct ng_mesg *, 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_ */
Cache object: d409c4dc1aba5dd7f11c26aeae5a0e4b
|