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