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@whistle.com> 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; /* must == NG_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 #define NG_VERSION 1 69 #define NGF_ORIG 0x0000 /* the msg is the original request */ 70 #define NGF_RESP 0x0001 /* the message is a response */ 71 72 /* 73 * Here we describe the "generic" messages that all nodes inherently 74 * understand. With the exception of NGM_TEXT_STATUS, these are handled 75 * automatically by the base netgraph code. 76 */ 77 78 /* Generic message type cookie */ 79 #define NGM_GENERIC_COOKIE 851672668 80 81 /* Generic messages defined for this type cookie */ 82 #define NGM_SHUTDOWN 0x0001 /* no args */ 83 #define NGM_MKPEER 0x0002 84 #define NGM_CONNECT 0x0003 85 #define NGM_NAME 0x0004 86 #define NGM_RMHOOK 0x0005 87 #define NGM_NODEINFO 0x0006 /* get nodeinfo for the target */ 88 #define NGM_LISTHOOKS 0x0007 /* get nodeinfo for the target + hook info */ 89 #define NGM_LISTNAMES 0x0008 /* list all globally named nodes */ 90 #define NGM_LISTNODES 0x0009 /* list all nodes, named and unnamed */ 91 #define NGM_LISTTYPES 0x000a /* list all installed node types */ 92 #define NGM_TEXT_STATUS 0x000b /* (optional) returns human readable status */ 93 94 /* 95 * Args sections for generic NG commands. All strings are NUL-terminated. 96 */ 97 struct ngm_mkpeer { 98 char type[NG_TYPELEN + 1]; /* peer type */ 99 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 100 char peerhook[NG_HOOKLEN + 1]; /* peer hook name */ 101 }; 102 103 struct ngm_connect { 104 char path[NG_PATHLEN + 1]; /* peer path */ 105 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 106 char peerhook[NG_HOOKLEN + 1]; /* peer hook name */ 107 }; 108 109 struct ngm_name { 110 char name[NG_NODELEN + 1]; /* node name */ 111 }; 112 113 struct ngm_rmhook { 114 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 115 }; 116 117 #define ng_ID_t unsigned int 118 /* Structures used in response to NGM_NODEINFO and NGM_LISTHOOKS */ 119 struct nodeinfo { 120 char name[NG_NODELEN + 1]; /* node name (if any) */ 121 char type[NG_TYPELEN + 1]; /* peer type */ 122 ng_ID_t id; /* unique identifier */ 123 u_int32_t hooks; /* number of active hooks */ 124 }; 125 126 struct linkinfo { 127 char ourhook[NG_HOOKLEN + 1]; /* hook name */ 128 char peerhook[NG_HOOKLEN + 1]; /* peer hook */ 129 struct nodeinfo nodeinfo; 130 }; 131 132 struct hooklist { 133 struct nodeinfo nodeinfo; /* node information */ 134 struct linkinfo link[0]; /* info about each hook */ 135 }; 136 137 /* Structure used for NGM_LISTNAMES/NGM_LISTNODES (not node specific) */ 138 struct namelist { 139 u_int32_t numnames; 140 struct nodeinfo nodeinfo[0]; 141 }; 142 143 /* Structures used for NGM_LISTTYPES (not node specific) */ 144 struct typeinfo { 145 char typename[NG_TYPELEN + 1]; /* name of type */ 146 u_int32_t numnodes; /* number alive */ 147 }; 148 149 struct typelist { 150 u_int32_t numtypes; 151 struct typeinfo typeinfo[0]; 152 }; 153 154 /* 155 * For netgraph nodes that are somehow associated with file descriptors 156 * (e.g., a device that has a /dev entry and is also a netgraph node), 157 * we define a generic ioctl for requesting the corresponding nodeinfo 158 * structure and for assigning a name (if there isn't one already). 159 * 160 * For these to you need to also #include <sys/ioccom.h>. 161 */ 162 163 #define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */ 164 #define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */ 165 166 #ifdef KERNEL 167 /* 168 * Allocate and initialize a netgraph message "msg" with "len" 169 * extra bytes of argument. Sets "msg" to NULL if fails. 170 * Does not initialize token. 171 */ 172 #define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \ 173 do { \ 174 MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg) \ 175 + (len), M_NETGRAPH, (how)); \ 176 if ((msg) == NULL) \ 177 break; \ 178 bzero((msg), sizeof(struct ng_mesg) + (len)); \ 179 (msg)->header.version = NG_VERSION; \ 180 (msg)->header.typecookie = (cookie); \ 181 (msg)->header.cmd = (cmdid); \ 182 (msg)->header.arglen = (len); \ 183 strncpy((msg)->header.cmdstr, #cmdid, \ 184 sizeof((msg)->header.cmdstr) - 1); \ 185 } while (0) 186 187 /* 188 * Allocate and initialize a response "rsp" to a message "msg" 189 * with "len" extra bytes of argument. Sets "rsp" to NULL if fails. 190 */ 191 #define NG_MKRESPONSE(rsp, msg, len, how) \ 192 do { \ 193 MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg) \ 194 + (len), M_NETGRAPH, (how)); \ 195 if ((rsp) == NULL) \ 196 break; \ 197 bzero((rsp), sizeof(struct ng_mesg) + (len)); \ 198 (rsp)->header.version = NG_VERSION; \ 199 (rsp)->header.arglen = (len); \ 200 (rsp)->header.token = (msg)->header.token; \ 201 (rsp)->header.typecookie = (msg)->header.typecookie; \ 202 (rsp)->header.cmd = (msg)->header.cmd; \ 203 bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \ 204 sizeof((rsp)->header.cmdstr)); \ 205 (rsp)->header.flags |= NGF_RESP; \ 206 } while (0) 207 #endif /* KERNEL */ 208 209 #endif /* _NETGRAPH_NG_MESSAGE_H_ */ 210 211