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