5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
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
37 * Author: Julian Elischer <julian@freebsd.org>
40 * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
43 #ifndef _NETGRAPH_NG_MESSAGE_H_
44 #define _NETGRAPH_NG_MESSAGE_H_ 1
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 */
54 /* A netgraph message */
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 */
66 char data[0]; /* placeholder for actual data */
69 /* this command is guaranteed to not alter data or'd into the command */
70 #define NGM_READONLY 0x10000000
72 /* Keep this in sync with the above structure definition */
73 #define NG_GENERIC_NG_MESG_INFO(dtype) { \
74 { "version", &ng_parse_uint8_type }, \
75 { "spare", &ng_parse_uint8_type }, \
76 { "arglen", &ng_parse_uint16_type }, \
77 { "flags", &ng_parse_hint32_type }, \
78 { "token", &ng_parse_uint32_type }, \
79 { "typecookie", &ng_parse_uint32_type }, \
80 { "cmd", &ng_parse_uint32_type }, \
81 { "cmdstr", &ng_parse_cmdbuf_type }, \
82 { "data", (dtype) }, \
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)
93 /* Flags field flags */
94 #define NGF_ORIG 0x00000000 /* the msg is the original request */
95 #define NGF_RESP 0x00000001 /* the message is a response */
97 /* Type of a unique node ID */
98 #define ng_ID_t unsigned int
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.
106 /* Generic message type cookie */
107 #define NGM_GENERIC_COOKIE 977674408
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|NGM_READONLY)/* get nodeinfo for target */
116 #define NGM_LISTHOOKS (7|NGM_READONLY)/* get list of hooks on node */
117 #define NGM_LISTNAMES (8|NGM_READONLY)/* list globally named nodes */
118 #define NGM_LISTNODES (9|NGM_READONLY)/* list nodes, named & not */
119 #define NGM_LISTTYPES (10|NGM_READONLY)/* list installed node types */
120 #define NGM_TEXT_STATUS (11|NGM_READONLY)/* (optional) get txt status */
121 #define NGM_BINARY2ASCII (12|NGM_READONLY)/* convert ng_mesg to ascii */
122 #define NGM_ASCII2BINARY (13|NGM_READONLY)/* convert ascii to ng_mesg */
123 #define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */
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..
133 /* Generic message type cookie */
134 #define NGM_FLOW_COOKIE 851672669 /* temp for debugging */
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 */
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|NGM_READONLY) /* either real or measured */
148 #define NGM_SET_XMIT_Q_LIMITS 45 /* includes queue state */
149 #define NGM_GET_XMIT_Q_LIMITS (46|NGM_READONLY) /* returns queue state */
150 #define NGM_MICROMANAGE 47 /* We want sync. queue state
151 reply for each packet sent */
152 #define NGM_SET_FLOW_MANAGER 48 /* send flow control here */
153 /* Structure used for 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 */
160 /* Keep this in sync with the above structure definition */
161 #define NG_GENERIC_MKPEER_INFO() { \
162 { "type", &ng_parse_typebuf_type }, \
163 { "ourhook", &ng_parse_hookbuf_type }, \
164 { "peerhook", &ng_parse_hookbuf_type }, \
168 /* Structure used for NGM_CONNECT */
170 char path[NG_PATHLEN + 1]; /* peer path */
171 char ourhook[NG_HOOKLEN + 1]; /* hook name */
172 char peerhook[NG_HOOKLEN + 1]; /* peer hook name */
175 /* Keep this in sync with the above structure definition */
176 #define NG_GENERIC_CONNECT_INFO() { \
177 { "path", &ng_parse_pathbuf_type }, \
178 { "ourhook", &ng_parse_hookbuf_type }, \
179 { "peerhook", &ng_parse_hookbuf_type }, \
183 /* Structure used for NGM_NAME */
185 char name[NG_NODELEN + 1]; /* node name */
188 /* Keep this in sync with the above structure definition */
189 #define NG_GENERIC_NAME_INFO() { \
190 { "name", &ng_parse_nodebuf_type }, \
194 /* Structure used for NGM_RMHOOK */
196 char ourhook[NG_HOOKLEN + 1]; /* hook name */
199 /* Keep this in sync with the above structure definition */
200 #define NG_GENERIC_RMHOOK_INFO() { \
201 { "hook", &ng_parse_hookbuf_type }, \
205 /* Structure used for NGM_NODEINFO */
207 char name[NG_NODELEN + 1]; /* node name (if any) */
208 char type[NG_TYPELEN + 1]; /* peer type */
209 ng_ID_t id; /* unique identifier */
210 u_int32_t hooks; /* number of active hooks */
213 /* Keep this in sync with the above structure definition */
214 #define NG_GENERIC_NODEINFO_INFO() { \
215 { "name", &ng_parse_nodebuf_type }, \
216 { "type", &ng_parse_typebuf_type }, \
217 { "id", &ng_parse_hint32_type }, \
218 { "hooks", &ng_parse_uint32_type }, \
222 /* Structure used for NGM_LISTHOOKS */
224 char ourhook[NG_HOOKLEN + 1]; /* hook name */
225 char peerhook[NG_HOOKLEN + 1]; /* peer hook */
226 struct nodeinfo nodeinfo;
229 /* Keep this in sync with the above structure definition */
230 #define NG_GENERIC_LINKINFO_INFO(nitype) { \
231 { "ourhook", &ng_parse_hookbuf_type }, \
232 { "peerhook", &ng_parse_hookbuf_type }, \
233 { "nodeinfo", (nitype) }, \
238 struct nodeinfo nodeinfo; /* node information */
239 struct linkinfo link[0]; /* info about each hook */
242 /* Keep this in sync with the above structure definition */
243 #define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \
244 { "nodeinfo", (nitype) }, \
245 { "linkinfo", (litype) }, \
249 /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
252 struct nodeinfo nodeinfo[0];
255 /* Keep this in sync with the above structure definition */
256 #define NG_GENERIC_LISTNODES_INFO(niarraytype) { \
257 { "numnames", &ng_parse_uint32_type }, \
258 { "nodeinfo", (niarraytype) }, \
262 /* Structure used for NGM_LISTTYPES */
264 char type_name[NG_TYPELEN + 1]; /* name of type */
265 u_int32_t numnodes; /* number alive */
268 /* Keep this in sync with the above structure definition */
269 #define NG_GENERIC_TYPEINFO_INFO() { \
270 { "typename", &ng_parse_typebuf_type }, \
271 { "numnodes", &ng_parse_uint32_type }, \
277 struct typeinfo typeinfo[0];
280 /* Keep this in sync with the above structure definition */
281 #define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \
282 { "numtypes", &ng_parse_uint32_type }, \
283 { "typeinfo", (tiarraytype) }, \
287 struct ngm_bandwidth {
288 u_int64_t nominal_in;
290 u_int64_t nominal_out;
294 /* Keep this in sync with the above structure definition */
295 #define NG_GENERIC_BANDWIDTH_INFO() { \
296 { "nominal_in", &ng_parse_uint64_type }, \
297 { "seen_in", &ng_parse_uint64_type }, \
298 { "nominal_out", &ng_parse_uint64_type }, \
299 { "seen_out", &ng_parse_uint64_type }, \
304 * Information about a node's 'output' queue.
305 * This is NOT the netgraph input queueing mechanism,
306 * but rather any queue the node may implement internally
307 * This has to consider ALTQ if we are to work with it.
308 * As far as I can see, ALTQ counts PACKETS, not bytes.
309 * If ALTQ has several queues and one has passed a watermark
310 * we should have the priority of that queue be real (and not -1)
311 * XXX ALTQ stuff is just an idea.....
313 struct ngm_queue_state {
314 u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
315 u_int max_queuelen_bytes;
316 u_int max_queuelen_packets;
318 u_int high_watermark;
322 /* Keep this in sync with the above structure definition */
323 #define NG_GENERIC_QUEUE_INFO() { \
324 { "max_queuelen_bytes", &ng_parse_uint_type }, \
325 { "max_queuelen_packets", &ng_parse_uint_type }, \
326 { "high_watermark", &ng_parse_uint_type }, \
327 { "low_watermark", &ng_parse_uint_type }, \
328 { "current", &ng_parse_uint_type }, \
332 /* Tell a node who to send async flow control info to. */
333 struct flow_manager {
334 ng_ID_t id; /* unique identifier */
337 /* Keep this in sync with the above structure definition */
338 #define NG_GENERIC_FLOW_MANAGER_INFO() { \
339 { "id", &ng_parse_hint32_type }, \
345 * For netgraph nodes that are somehow associated with file descriptors
346 * (e.g., a device that has a /dev entry and is also a netgraph node),
347 * we define a generic ioctl for requesting the corresponding nodeinfo
348 * structure and for assigning a name (if there isn't one already).
350 * For these to you need to also #include <sys/ioccom.h>.
353 #define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */
354 #define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */
358 * Allocate and initialize a netgraph message "msg" with "len"
359 * extra bytes of argument. Sets "msg" to NULL if fails.
360 * Does not initialize token.
362 #define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \
364 MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg) \
365 + (len), M_NETGRAPH_MSG, (how) | M_ZERO); \
368 (msg)->header.version = NG_VERSION; \
369 (msg)->header.typecookie = (cookie); \
370 (msg)->header.cmd = (cmdid); \
371 (msg)->header.arglen = (len); \
372 strncpy((msg)->header.cmdstr, #cmdid, \
373 sizeof((msg)->header.cmdstr) - 1); \
377 * Allocate and initialize a response "rsp" to a message "msg"
378 * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
380 #define NG_MKRESPONSE(rsp, msg, len, how) \
382 MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg) \
383 + (len), M_NETGRAPH_MSG, (how) | M_ZERO); \
386 (rsp)->header.version = NG_VERSION; \
387 (rsp)->header.arglen = (len); \
388 (rsp)->header.token = (msg)->header.token; \
389 (rsp)->header.typecookie = (msg)->header.typecookie; \
390 (rsp)->header.cmd = (msg)->header.cmd; \
391 bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \
392 sizeof((rsp)->header.cmdstr)); \
393 (rsp)->header.flags |= NGF_RESP; \
397 #endif /* _NETGRAPH_NG_MESSAGE_H_ */