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