ng_message.h revision 64508
1101282Smdodd 2204977Simp/* 3101282Smdodd * ng_message.h 4101282Smdodd * 5101282Smdodd * Copyright (c) 1996-1999 Whistle Communications, Inc. 6101282Smdodd * All rights reserved. 7101282Smdodd * 8101282Smdodd * Subject to the following obligations and disclaimer of warranty, use and 9101282Smdodd * redistribution of this software, in source or object code forms, with or 10101282Smdodd * without modifications are expressly permitted by Whistle Communications; 11101282Smdodd * provided, however, that: 12101282Smdodd * 1. Any and all reproductions of the source or object code must include the 13101282Smdodd * copyright notice above and the following disclaimer of warranties; and 14101282Smdodd * 2. No rights are granted, in any manner or form, to use Whistle 15101282Smdodd * Communications, Inc. trademarks, including the mark "WHISTLE 16101282Smdodd * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17101282Smdodd * such appears in the above copyright notice or in the software. 18101282Smdodd * 19101282Smdodd * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20101282Smdodd * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21101282Smdodd * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22101282Smdodd * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23101282Smdodd * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24101282Smdodd * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25101282Smdodd * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26101282Smdodd * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27101282Smdodd * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28288424Sjhb * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29168569Sdelphij * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30168569Sdelphij * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31240005Szont * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32240005Szont * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33240005Szont * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34240005Szont * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35240005Szont * OF SUCH DAMAGE. 36240005Szont * 37240005Szont * Author: Julian Elischer <julian@whistle.com> 38295930Sjhb * 39101282Smdodd * $FreeBSD: head/sys/netgraph/ng_message.h 64508 2000-08-10 22:45:54Z archie $ 40288424Sjhb * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $ 41288424Sjhb */ 42288424Sjhb 43288424Sjhb#ifndef _NETGRAPH_NG_MESSAGE_H_ 44288424Sjhb#define _NETGRAPH_NG_MESSAGE_H_ 1 45294849Sjhb 46288424Sjhb/* ASCII string size limits */ 47288424Sjhb#define NG_TYPELEN 15 /* max type name len (16 with null) */ 48288424Sjhb#define NG_HOOKLEN 15 /* max hook name len (16 with null) */ 49288424Sjhb#define NG_NODELEN 15 /* max node name len (16 with null) */ 50288424Sjhb#define NG_PATHLEN 511 /* max path len (512 with null) */ 51288424Sjhb#define NG_CMDSTRLEN 15 /* max command string (16 with null) */ 52288424Sjhb#define NG_TEXTRESPONSE 1024 /* allow this length for a text response */ 53288424Sjhb 54288997Sbdrewery/* A netgraph message */ 55288424Sjhbstruct ng_mesg { 56288424Sjhb struct ng_msghdr { 57288424Sjhb u_char version; /* must == NG_VERSION */ 58288424Sjhb u_char spare; /* pad to 2 bytes */ 59288424Sjhb u_int16_t arglen; /* length of data */ 60288424Sjhb u_int32_t flags; /* message status */ 61288424Sjhb u_int32_t token; /* match with reply */ 62288424Sjhb u_int32_t typecookie; /* node's type cookie */ 63288424Sjhb u_int32_t cmd; /* command identifier */ 64288424Sjhb u_char cmdstr[NG_CMDSTRLEN+1]; /* cmd string + \0 */ 65288424Sjhb } header; 66288424Sjhb char data[0]; /* placeholder for actual data */ 67288424Sjhb}; 68288424Sjhb 69288424Sjhb/* Keep this in sync with the above structure definition */ 70288424Sjhb#define NG_GENERIC_NG_MESG_INFO(dtype) { \ 71288424Sjhb { \ 72288424Sjhb { "version", &ng_parse_uint8_type }, \ 73288424Sjhb { "spare", &ng_parse_uint8_type }, \ 74168569Sdelphij { "arglen", &ng_parse_uint16_type }, \ 75168569Sdelphij { "flags", &ng_parse_hint32_type }, \ 76296571Sjhb { "token", &ng_parse_uint32_type }, \ 77288424Sjhb { "typecookie", &ng_parse_uint32_type }, \ 78168569Sdelphij { "cmd", &ng_parse_uint32_type }, \ 79168569Sdelphij { "cmdstr", &ng_parse_cmdbuf_type }, \ 80288424Sjhb { "data", (dtype) }, \ 81240562Szont { NULL }, \ 82240562Szont } \ 83168569Sdelphij} 84168569Sdelphij 85288424Sjhb/* Negraph type binary compatibility field */ 86288424Sjhb#define NG_VERSION 3 87288424Sjhb 88288424Sjhb/* Flags field flags */ 89288424Sjhb#define NGF_ORIG 0x0000 /* the msg is the original request */ 90296571Sjhb#define NGF_RESP 0x0001 /* the message is a response */ 91288424Sjhb 92288424Sjhb/* Type of a unique node ID */ 93101282Smdodd#define ng_ID_t unsigned int 94101282Smdodd 95101282Smdodd/* 96153963Sbrian * Here we describe the "generic" messages that all nodes inherently 97101282Smdodd * understand. With the exception of NGM_TEXT_STATUS, these are handled 98101285Smdodd * automatically by the base netgraph code. 99101373Smdodd */ 100168569Sdelphij 101168569Sdelphij/* Generic message type cookie */ 102240005Szont#define NGM_GENERIC_COOKIE 851672668 103288424Sjhb 104101282Smdodd/* Generic messages defined for this type cookie */ 105158630Spav#define NGM_SHUTDOWN 1 /* shut down node */ 106247338Sdelphij#define NGM_MKPEER 2 /* create and attach a peer node */ 107158630Spav#define NGM_CONNECT 3 /* connect two nodes */ 108158630Spav#define NGM_NAME 4 /* give a node a name */ 109158630Spav#define NGM_RMHOOK 5 /* break a connection btw. two nodes */ 110158630Spav#define NGM_NODEINFO 6 /* get nodeinfo for the target */ 111158630Spav#define NGM_LISTHOOKS 7 /* get list of hooks on node */ 112158630Spav#define NGM_LISTNAMES 8 /* list all globally named nodes */ 113158630Spav#define NGM_LISTNODES 9 /* list all nodes, named and unnamed */ 114158630Spav#define NGM_LISTTYPES 10 /* list all installed node types */ 115168569Sdelphij#define NGM_TEXT_STATUS 11 /* (optional) get text status report */ 116247338Sdelphij#define NGM_BINARY2ASCII 12 /* convert struct ng_mesg to ascii */ 117192025Sdds#define NGM_ASCII2BINARY 13 /* convert ascii to struct ng_mesg */ 118192025Sdds#define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */ 119192025Sdds 120192025Sdds/* Structure used for NGM_MKPEER */ 121192025Sddsstruct ngm_mkpeer { 122192025Sdds char type[NG_TYPELEN + 1]; /* peer type */ 123192025Sdds char ourhook[NG_HOOKLEN + 1]; /* hook name */ 124192025Sdds char peerhook[NG_HOOKLEN + 1]; /* peer hook name */ 125}; 126 127/* Keep this in sync with the above structure definition */ 128#define NG_GENERIC_MKPEER_INFO() { \ 129 { \ 130 { "type", &ng_parse_typebuf_type }, \ 131 { "ourhook", &ng_parse_hookbuf_type }, \ 132 { "peerhook", &ng_parse_hookbuf_type }, \ 133 { NULL }, \ 134 } \ 135} 136 137/* Structure used for NGM_CONNECT */ 138struct ngm_connect { 139 char path[NG_PATHLEN + 1]; /* peer path */ 140 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 141 char peerhook[NG_HOOKLEN + 1]; /* peer hook name */ 142}; 143 144/* Keep this in sync with the above structure definition */ 145#define NG_GENERIC_CONNECT_INFO() { \ 146 { \ 147 { "path", &ng_parse_pathbuf_type }, \ 148 { "ourhook", &ng_parse_hookbuf_type }, \ 149 { "peerhook", &ng_parse_hookbuf_type }, \ 150 { NULL }, \ 151 } \ 152} 153 154/* Structure used for NGM_NAME */ 155struct ngm_name { 156 char name[NG_NODELEN + 1]; /* node name */ 157}; 158 159/* Keep this in sync with the above structure definition */ 160#define NG_GENERIC_NAME_INFO() { \ 161 { \ 162 { "name", &ng_parse_nodebuf_type }, \ 163 { NULL }, \ 164 } \ 165} 166 167/* Structure used for NGM_RMHOOK */ 168struct ngm_rmhook { 169 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 170}; 171 172/* Keep this in sync with the above structure definition */ 173#define NG_GENERIC_RMHOOK_INFO() { \ 174 { \ 175 { "hook", &ng_parse_hookbuf_type }, \ 176 { NULL }, \ 177 } \ 178} 179 180/* Structure used for NGM_NODEINFO */ 181struct nodeinfo { 182 char name[NG_NODELEN + 1]; /* node name (if any) */ 183 char type[NG_TYPELEN + 1]; /* peer type */ 184 ng_ID_t id; /* unique identifier */ 185 u_int32_t hooks; /* number of active hooks */ 186}; 187 188/* Keep this in sync with the above structure definition */ 189#define NG_GENERIC_NODEINFO_INFO() { \ 190 { \ 191 { "name", &ng_parse_nodebuf_type }, \ 192 { "type", &ng_parse_typebuf_type }, \ 193 { "id", &ng_parse_hint32_type }, \ 194 { "hooks", &ng_parse_uint32_type }, \ 195 { NULL }, \ 196 } \ 197} 198 199/* Structure used for NGM_LISTHOOKS */ 200struct linkinfo { 201 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 202 char peerhook[NG_HOOKLEN + 1]; /* peer hook */ 203 struct nodeinfo nodeinfo; 204}; 205 206/* Keep this in sync with the above structure definition */ 207#define NG_GENERIC_LINKINFO_INFO(nitype) { \ 208 { \ 209 { "ourhook", &ng_parse_hookbuf_type }, \ 210 { "peerhook", &ng_parse_hookbuf_type }, \ 211 { "nodeinfo", (nitype) }, \ 212 { NULL }, \ 213 } \ 214} 215 216struct hooklist { 217 struct nodeinfo nodeinfo; /* node information */ 218 struct linkinfo link[0]; /* info about each hook */ 219}; 220 221/* Keep this in sync with the above structure definition */ 222#define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \ 223 { \ 224 { "nodeinfo", (nitype) }, \ 225 { "linkinfo", (litype) }, \ 226 { NULL }, \ 227 } \ 228} 229 230/* Structure used for NGM_LISTNAMES/NGM_LISTNODES */ 231struct namelist { 232 u_int32_t numnames; 233 struct nodeinfo nodeinfo[0]; 234}; 235 236/* Keep this in sync with the above structure definition */ 237#define NG_GENERIC_LISTNODES_INFO(niarraytype) { \ 238 { \ 239 { "numnames", &ng_parse_uint32_type }, \ 240 { "nodeinfo", (niarraytype) }, \ 241 { NULL }, \ 242 } \ 243} 244 245/* Structure used for NGM_LISTTYPES */ 246struct typeinfo { 247 char type_name[NG_TYPELEN + 1]; /* name of type */ 248 u_int32_t numnodes; /* number alive */ 249}; 250 251/* Keep this in sync with the above structure definition */ 252#define NG_GENERIC_TYPEINFO_INFO() { \ 253 { \ 254 { "typename", &ng_parse_typebuf_type }, \ 255 { "numnodes", &ng_parse_uint32_type }, \ 256 { NULL }, \ 257 } \ 258} 259 260struct typelist { 261 u_int32_t numtypes; 262 struct typeinfo typeinfo[0]; 263}; 264 265/* Keep this in sync with the above structure definition */ 266#define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \ 267 { \ 268 { "numtypes", &ng_parse_uint32_type }, \ 269 { "typeinfo", (tiarraytype) }, \ 270 { NULL }, \ 271 } \ 272} 273 274/* 275 * For netgraph nodes that are somehow associated with file descriptors 276 * (e.g., a device that has a /dev entry and is also a netgraph node), 277 * we define a generic ioctl for requesting the corresponding nodeinfo 278 * structure and for assigning a name (if there isn't one already). 279 * 280 * For these to you need to also #include <sys/ioccom.h>. 281 */ 282 283#define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */ 284#define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */ 285 286#ifdef _KERNEL 287/* 288 * Allocate and initialize a netgraph message "msg" with "len" 289 * extra bytes of argument. Sets "msg" to NULL if fails. 290 * Does not initialize token. 291 */ 292#define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \ 293 do { \ 294 MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg) \ 295 + (len), M_NETGRAPH, (how)); \ 296 if ((msg) == NULL) \ 297 break; \ 298 bzero((msg), sizeof(struct ng_mesg) + (len)); \ 299 (msg)->header.version = NG_VERSION; \ 300 (msg)->header.typecookie = (cookie); \ 301 (msg)->header.cmd = (cmdid); \ 302 (msg)->header.arglen = (len); \ 303 strncpy((msg)->header.cmdstr, #cmdid, \ 304 sizeof((msg)->header.cmdstr) - 1); \ 305 } while (0) 306 307/* 308 * Allocate and initialize a response "rsp" to a message "msg" 309 * with "len" extra bytes of argument. Sets "rsp" to NULL if fails. 310 */ 311#define NG_MKRESPONSE(rsp, msg, len, how) \ 312 do { \ 313 MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg) \ 314 + (len), M_NETGRAPH, (how)); \ 315 if ((rsp) == NULL) \ 316 break; \ 317 bzero((rsp), sizeof(struct ng_mesg) + (len)); \ 318 (rsp)->header.version = NG_VERSION; \ 319 (rsp)->header.arglen = (len); \ 320 (rsp)->header.token = (msg)->header.token; \ 321 (rsp)->header.typecookie = (msg)->header.typecookie; \ 322 (rsp)->header.cmd = (msg)->header.cmd; \ 323 bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \ 324 sizeof((rsp)->header.cmdstr)); \ 325 (rsp)->header.flags |= NGF_RESP; \ 326 } while (0) 327#endif /* _KERNEL */ 328 329#endif /* _NETGRAPH_NG_MESSAGE_H_ */ 330 331