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