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