14cf49a43SJulian Elischer /* 24cf49a43SJulian Elischer * ng_message.h 3c398230bSWarner Losh */ 4c398230bSWarner Losh 5c398230bSWarner Losh /*- 64cf49a43SJulian Elischer * Copyright (c) 1996-1999 Whistle Communications, Inc. 74cf49a43SJulian Elischer * All rights reserved. 84cf49a43SJulian Elischer * 94cf49a43SJulian Elischer * Subject to the following obligations and disclaimer of warranty, use and 104cf49a43SJulian Elischer * redistribution of this software, in source or object code forms, with or 114cf49a43SJulian Elischer * without modifications are expressly permitted by Whistle Communications; 124cf49a43SJulian Elischer * provided, however, that: 134cf49a43SJulian Elischer * 1. Any and all reproductions of the source or object code must include the 144cf49a43SJulian Elischer * copyright notice above and the following disclaimer of warranties; and 154cf49a43SJulian Elischer * 2. No rights are granted, in any manner or form, to use Whistle 164cf49a43SJulian Elischer * Communications, Inc. trademarks, including the mark "WHISTLE 174cf49a43SJulian Elischer * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 184cf49a43SJulian Elischer * such appears in the above copyright notice or in the software. 194cf49a43SJulian Elischer * 204cf49a43SJulian Elischer * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 214cf49a43SJulian Elischer * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 224cf49a43SJulian Elischer * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 234cf49a43SJulian Elischer * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 244cf49a43SJulian Elischer * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 254cf49a43SJulian Elischer * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 264cf49a43SJulian Elischer * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 274cf49a43SJulian Elischer * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 284cf49a43SJulian Elischer * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 294cf49a43SJulian Elischer * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 304cf49a43SJulian Elischer * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 314cf49a43SJulian Elischer * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 324cf49a43SJulian Elischer * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 334cf49a43SJulian Elischer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 344cf49a43SJulian Elischer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 354cf49a43SJulian Elischer * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 364cf49a43SJulian Elischer * OF SUCH DAMAGE. 374cf49a43SJulian Elischer * 38cc3bbd68SJulian Elischer * Author: Julian Elischer <julian@freebsd.org> 394cf49a43SJulian Elischer * 404cf49a43SJulian Elischer * $FreeBSD$ 414cf49a43SJulian Elischer * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $ 424cf49a43SJulian Elischer */ 434cf49a43SJulian Elischer 444cf49a43SJulian Elischer #ifndef _NETGRAPH_NG_MESSAGE_H_ 45e20480bfSRuslan Ermilov #define _NETGRAPH_NG_MESSAGE_H_ 464cf49a43SJulian Elischer 474cf49a43SJulian Elischer /* ASCII string size limits */ 48387ebc6dSHartmut Brandt #define NG_TYPESIZ 32 /* max type name len (including null) */ 49387ebc6dSHartmut Brandt #define NG_HOOKSIZ 32 /* max hook name len (including null) */ 50387ebc6dSHartmut Brandt #define NG_NODESIZ 32 /* max node name len (including null) */ 51387ebc6dSHartmut Brandt #define NG_PATHSIZ 512 /* max path len (including null) */ 52387ebc6dSHartmut Brandt #define NG_CMDSTRSIZ 32 /* max command string (including null) */ 53387ebc6dSHartmut Brandt 54387ebc6dSHartmut Brandt #ifndef BURN_BRIDGES 55387ebc6dSHartmut Brandt /* don't use these - they will go away */ 56387ebc6dSHartmut Brandt #define NG_TYPELEN (NG_TYPESIZ - 1) 57387ebc6dSHartmut Brandt #define NG_HOOKLEN (NG_HOOKSIZ - 1) 58387ebc6dSHartmut Brandt #define NG_NODELEN (NG_NODESIZ - 1) 59387ebc6dSHartmut Brandt #define NG_PATHLEN (NG_PATHSIZ - 1) 60387ebc6dSHartmut Brandt #define NG_CMDSTRLEN (NG_CMDSTRSIZ - 1) 61387ebc6dSHartmut Brandt #endif 62387ebc6dSHartmut Brandt 634cf49a43SJulian Elischer #define NG_TEXTRESPONSE 1024 /* allow this length for a text response */ 644cf49a43SJulian Elischer 654cf49a43SJulian Elischer /* A netgraph message */ 664cf49a43SJulian Elischer struct ng_mesg { 674cf49a43SJulian Elischer struct ng_msghdr { 68589f6ed8SJulian Elischer u_char version; /* == NGM_VERSION */ 694feaf224SGleb Smirnoff u_char spare; /* pad to 4 bytes */ 704feaf224SGleb Smirnoff u_int16_t spare2; 714feaf224SGleb Smirnoff u_int32_t arglen; /* length of data */ 72f036d408SJulian Elischer u_int32_t cmd; /* command identifier */ 734cf49a43SJulian Elischer u_int32_t flags; /* message status */ 744cf49a43SJulian Elischer u_int32_t token; /* match with reply */ 754cf49a43SJulian Elischer u_int32_t typecookie; /* node's type cookie */ 7687e2c66aSHartmut Brandt u_char cmdstr[NG_CMDSTRSIZ]; /* cmd string + \0 */ 774cf49a43SJulian Elischer } header; 780eecad8dSHartmut Brandt char data[]; /* placeholder for actual data */ 794cf49a43SJulian Elischer }; 80f8307e12SArchie Cobbs 812df050adSGleb Smirnoff /* This command is guaranteed to not alter data (or'd into the command). */ 82069154d5SJulian Elischer #define NGM_READONLY 0x10000000 832df050adSGleb Smirnoff /* This command is guaranteed to have a reply (or'd into the command). */ 842df050adSGleb Smirnoff #define NGM_HASREPLY 0x20000000 85589f6ed8SJulian Elischer 86f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 87f8307e12SArchie Cobbs #define NG_GENERIC_NG_MESG_INFO(dtype) { \ 8857b57be3SArchie Cobbs { "version", &ng_parse_uint8_type }, \ 8957b57be3SArchie Cobbs { "spare", &ng_parse_uint8_type }, \ 904feaf224SGleb Smirnoff { "spare2", &ng_parse_uint16_type }, \ 914feaf224SGleb Smirnoff { "arglen", &ng_parse_uint32_type }, \ 92f036d408SJulian Elischer { "cmd", &ng_parse_uint32_type }, \ 9357b57be3SArchie Cobbs { "flags", &ng_parse_hint32_type }, \ 9457b57be3SArchie Cobbs { "token", &ng_parse_uint32_type }, \ 9557b57be3SArchie Cobbs { "typecookie", &ng_parse_uint32_type }, \ 96f8307e12SArchie Cobbs { "cmdstr", &ng_parse_cmdbuf_type }, \ 97f8307e12SArchie Cobbs { "data", (dtype) }, \ 98f0184ff8SArchie Cobbs { NULL } \ 99f8307e12SArchie Cobbs } 100f8307e12SArchie Cobbs 101589f6ed8SJulian Elischer /* 102589f6ed8SJulian Elischer * Netgraph message header compatibility field 103589f6ed8SJulian Elischer * Interfaces within the kernel are defined by a different 1044feaf224SGleb Smirnoff * value (see NG_ABI_VERSION in netgraph.h) 105589f6ed8SJulian Elischer */ 1064feaf224SGleb Smirnoff #define NG_VERSION 8 107f8307e12SArchie Cobbs 108f8307e12SArchie Cobbs /* Flags field flags */ 109069154d5SJulian Elischer #define NGF_ORIG 0x00000000 /* the msg is the original request */ 110069154d5SJulian Elischer #define NGF_RESP 0x00000001 /* the message is a response */ 1111acb27c6SJulian Elischer 112f8307e12SArchie Cobbs /* Type of a unique node ID */ 113f8307e12SArchie Cobbs #define ng_ID_t unsigned int 114f8307e12SArchie Cobbs 1154cf49a43SJulian Elischer /* 1164cf49a43SJulian Elischer * Here we describe the "generic" messages that all nodes inherently 1174cf49a43SJulian Elischer * understand. With the exception of NGM_TEXT_STATUS, these are handled 1184cf49a43SJulian Elischer * automatically by the base netgraph code. 1194cf49a43SJulian Elischer */ 1204cf49a43SJulian Elischer 1214cf49a43SJulian Elischer /* Generic message type cookie */ 1222df050adSGleb Smirnoff #define NGM_GENERIC_COOKIE 1137070366 1234cf49a43SJulian Elischer 1242df050adSGleb Smirnoff /* Generic messages defined for this type cookie. */ 1252df050adSGleb Smirnoff enum { 1262df050adSGleb Smirnoff NGM_SHUTDOWN = 1, /* Shut down node. */ 1272df050adSGleb Smirnoff NGM_MKPEER = 2, /* Create and attach a peer node. */ 1282df050adSGleb Smirnoff NGM_CONNECT = 3, /* Connect two nodes. */ 1292df050adSGleb Smirnoff NGM_NAME = 4, /* Give a node a name. */ 1302df050adSGleb Smirnoff NGM_RMHOOK = 5, /* Break a connection between two nodes. */ 1312df050adSGleb Smirnoff 1322df050adSGleb Smirnoff /* Get nodeinfo for target. */ 1332df050adSGleb Smirnoff NGM_NODEINFO = (6|NGM_READONLY|NGM_HASREPLY), 1342df050adSGleb Smirnoff /* Get list of hooks on node. */ 1352df050adSGleb Smirnoff NGM_LISTHOOKS = (7|NGM_READONLY|NGM_HASREPLY), 1362df050adSGleb Smirnoff /* List globally named nodes. */ 1372df050adSGleb Smirnoff NGM_LISTNAMES = (8|NGM_READONLY|NGM_HASREPLY), 1382df050adSGleb Smirnoff /* List all nodes. */ 1392df050adSGleb Smirnoff NGM_LISTNODES = (9|NGM_READONLY|NGM_HASREPLY), 1402df050adSGleb Smirnoff /* List installed node types. */ 1412df050adSGleb Smirnoff NGM_LISTTYPES = (10|NGM_READONLY|NGM_HASREPLY), 1422df050adSGleb Smirnoff /* (optional) Get text status. */ 1432df050adSGleb Smirnoff NGM_TEXT_STATUS = (11|NGM_READONLY|NGM_HASREPLY), 1442df050adSGleb Smirnoff /* Convert struct ng_mesg to ASCII. */ 1452df050adSGleb Smirnoff NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY), 1462df050adSGleb Smirnoff /* Convert ASCII to struct ng_mesg. */ 1472df050adSGleb Smirnoff NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY), 1482df050adSGleb Smirnoff /* (optional) Get/set text config. */ 1492df050adSGleb Smirnoff NGM_TEXT_CONFIG = 14, 1502df050adSGleb Smirnoff }; 1514cf49a43SJulian Elischer 152859a4d16SJulian Elischer /* 153859a4d16SJulian Elischer * Flow control and intra node control messages. 154859a4d16SJulian Elischer * These are routed between nodes to allow flow control and to allow 155859a4d16SJulian Elischer * events to be passed around the graph. 156859a4d16SJulian Elischer * There will be some form of default handling for these but I 157859a4d16SJulian Elischer * do not yet know what it is.. 158859a4d16SJulian Elischer */ 159859a4d16SJulian Elischer 160859a4d16SJulian Elischer /* Generic message type cookie */ 161859a4d16SJulian Elischer #define NGM_FLOW_COOKIE 851672669 /* temp for debugging */ 162859a4d16SJulian Elischer 163859a4d16SJulian Elischer /* Upstream messages */ 164859a4d16SJulian Elischer #define NGM_LINK_IS_UP 32 /* e.g. carrier found - no data */ 165859a4d16SJulian Elischer #define NGM_LINK_IS_DOWN 33 /* carrier lost, includes queue state */ 166859a4d16SJulian Elischer #define NGM_HIGH_WATER_PASSED 34 /* includes queue state */ 167859a4d16SJulian Elischer #define NGM_LOW_WATER_PASSED 35 /* includes queue state */ 168859a4d16SJulian Elischer #define NGM_SYNC_QUEUE_STATE 36 /* sync response from sending packet */ 169859a4d16SJulian Elischer 170859a4d16SJulian Elischer /* Downstream messages */ 171859a4d16SJulian Elischer #define NGM_DROP_LINK 41 /* drop DTR, etc. - stay in the graph */ 172b57a7965SJulian Elischer #define NGM_RAISE_LINK 42 /* if you previously dropped it */ 173859a4d16SJulian Elischer #define NGM_FLUSH_QUEUE 43 /* no data */ 174069154d5SJulian Elischer #define NGM_GET_BANDWIDTH (44|NGM_READONLY) /* either real or measured */ 175859a4d16SJulian Elischer #define NGM_SET_XMIT_Q_LIMITS 45 /* includes queue state */ 176069154d5SJulian Elischer #define NGM_GET_XMIT_Q_LIMITS (46|NGM_READONLY) /* returns queue state */ 177069154d5SJulian Elischer #define NGM_MICROMANAGE 47 /* We want sync. queue state 178069154d5SJulian Elischer reply for each packet sent */ 179859a4d16SJulian Elischer #define NGM_SET_FLOW_MANAGER 48 /* send flow control here */ 180f8307e12SArchie Cobbs /* Structure used for NGM_MKPEER */ 1814cf49a43SJulian Elischer struct ngm_mkpeer { 18287e2c66aSHartmut Brandt char type[NG_TYPESIZ]; /* peer type */ 18387e2c66aSHartmut Brandt char ourhook[NG_HOOKSIZ]; /* hook name */ 18487e2c66aSHartmut Brandt char peerhook[NG_HOOKSIZ]; /* peer hook name */ 1854cf49a43SJulian Elischer }; 1864cf49a43SJulian Elischer 187f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 188f8307e12SArchie Cobbs #define NG_GENERIC_MKPEER_INFO() { \ 189f8307e12SArchie Cobbs { "type", &ng_parse_typebuf_type }, \ 190f8307e12SArchie Cobbs { "ourhook", &ng_parse_hookbuf_type }, \ 191f8307e12SArchie Cobbs { "peerhook", &ng_parse_hookbuf_type }, \ 192f0184ff8SArchie Cobbs { NULL } \ 193f8307e12SArchie Cobbs } 194f8307e12SArchie Cobbs 195f8307e12SArchie Cobbs /* Structure used for NGM_CONNECT */ 1964cf49a43SJulian Elischer struct ngm_connect { 19787e2c66aSHartmut Brandt char path[NG_PATHSIZ]; /* peer path */ 19887e2c66aSHartmut Brandt char ourhook[NG_HOOKSIZ]; /* hook name */ 19987e2c66aSHartmut Brandt char peerhook[NG_HOOKSIZ]; /* peer hook name */ 2004cf49a43SJulian Elischer }; 2014cf49a43SJulian Elischer 202f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 203f8307e12SArchie Cobbs #define NG_GENERIC_CONNECT_INFO() { \ 204f8307e12SArchie Cobbs { "path", &ng_parse_pathbuf_type }, \ 205f8307e12SArchie Cobbs { "ourhook", &ng_parse_hookbuf_type }, \ 206f8307e12SArchie Cobbs { "peerhook", &ng_parse_hookbuf_type }, \ 207f0184ff8SArchie Cobbs { NULL } \ 208f8307e12SArchie Cobbs } 209f8307e12SArchie Cobbs 210f8307e12SArchie Cobbs /* Structure used for NGM_NAME */ 2114cf49a43SJulian Elischer struct ngm_name { 21287e2c66aSHartmut Brandt char name[NG_NODESIZ]; /* node name */ 2134cf49a43SJulian Elischer }; 2144cf49a43SJulian Elischer 215f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 216f8307e12SArchie Cobbs #define NG_GENERIC_NAME_INFO() { \ 217f8307e12SArchie Cobbs { "name", &ng_parse_nodebuf_type }, \ 218f0184ff8SArchie Cobbs { NULL } \ 219f8307e12SArchie Cobbs } 220f8307e12SArchie Cobbs 221f8307e12SArchie Cobbs /* Structure used for NGM_RMHOOK */ 2224cf49a43SJulian Elischer struct ngm_rmhook { 22387e2c66aSHartmut Brandt char ourhook[NG_HOOKSIZ]; /* hook name */ 2244cf49a43SJulian Elischer }; 2254cf49a43SJulian Elischer 226f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 227f8307e12SArchie Cobbs #define NG_GENERIC_RMHOOK_INFO() { \ 228f8307e12SArchie Cobbs { "hook", &ng_parse_hookbuf_type }, \ 229f0184ff8SArchie Cobbs { NULL } \ 230f8307e12SArchie Cobbs } 231f8307e12SArchie Cobbs 232f8307e12SArchie Cobbs /* Structure used for NGM_NODEINFO */ 2334cf49a43SJulian Elischer struct nodeinfo { 23487e2c66aSHartmut Brandt char name[NG_NODESIZ]; /* node name (if any) */ 23587e2c66aSHartmut Brandt char type[NG_TYPESIZ]; /* peer type */ 236dc90cad9SJulian Elischer ng_ID_t id; /* unique identifier */ 2374cf49a43SJulian Elischer u_int32_t hooks; /* number of active hooks */ 2384cf49a43SJulian Elischer }; 2394cf49a43SJulian Elischer 240f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 241f8307e12SArchie Cobbs #define NG_GENERIC_NODEINFO_INFO() { \ 242f8307e12SArchie Cobbs { "name", &ng_parse_nodebuf_type }, \ 243f8307e12SArchie Cobbs { "type", &ng_parse_typebuf_type }, \ 24457b57be3SArchie Cobbs { "id", &ng_parse_hint32_type }, \ 24557b57be3SArchie Cobbs { "hooks", &ng_parse_uint32_type }, \ 246f0184ff8SArchie Cobbs { NULL } \ 247f8307e12SArchie Cobbs } 248f8307e12SArchie Cobbs 249f8307e12SArchie Cobbs /* Structure used for NGM_LISTHOOKS */ 2504cf49a43SJulian Elischer struct linkinfo { 25187e2c66aSHartmut Brandt char ourhook[NG_HOOKSIZ]; /* hook name */ 25287e2c66aSHartmut Brandt char peerhook[NG_HOOKSIZ]; /* peer hook */ 2534cf49a43SJulian Elischer struct nodeinfo nodeinfo; 2544cf49a43SJulian Elischer }; 2554cf49a43SJulian Elischer 256f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 257f8307e12SArchie Cobbs #define NG_GENERIC_LINKINFO_INFO(nitype) { \ 258f8307e12SArchie Cobbs { "ourhook", &ng_parse_hookbuf_type }, \ 259f8307e12SArchie Cobbs { "peerhook", &ng_parse_hookbuf_type }, \ 260f8307e12SArchie Cobbs { "nodeinfo", (nitype) }, \ 261f0184ff8SArchie Cobbs { NULL } \ 262f8307e12SArchie Cobbs } 263f8307e12SArchie Cobbs 2644cf49a43SJulian Elischer struct hooklist { 2654cf49a43SJulian Elischer struct nodeinfo nodeinfo; /* node information */ 2660eecad8dSHartmut Brandt struct linkinfo link[]; /* info about each hook */ 2674cf49a43SJulian Elischer }; 2684cf49a43SJulian Elischer 269f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 270f8307e12SArchie Cobbs #define NG_GENERIC_HOOKLIST_INFO(nitype,litype) { \ 271f8307e12SArchie Cobbs { "nodeinfo", (nitype) }, \ 272f8307e12SArchie Cobbs { "linkinfo", (litype) }, \ 273f0184ff8SArchie Cobbs { NULL } \ 274f8307e12SArchie Cobbs } 275f8307e12SArchie Cobbs 276f8307e12SArchie Cobbs /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */ 2774cf49a43SJulian Elischer struct namelist { 2784cf49a43SJulian Elischer u_int32_t numnames; 2790eecad8dSHartmut Brandt struct nodeinfo nodeinfo[]; 2804cf49a43SJulian Elischer }; 2814cf49a43SJulian Elischer 282f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 283f8307e12SArchie Cobbs #define NG_GENERIC_LISTNODES_INFO(niarraytype) { \ 28457b57be3SArchie Cobbs { "numnames", &ng_parse_uint32_type }, \ 285f8307e12SArchie Cobbs { "nodeinfo", (niarraytype) }, \ 286f0184ff8SArchie Cobbs { NULL } \ 287f8307e12SArchie Cobbs } 288f8307e12SArchie Cobbs 289f8307e12SArchie Cobbs /* Structure used for NGM_LISTTYPES */ 2904cf49a43SJulian Elischer struct typeinfo { 29187e2c66aSHartmut Brandt char type_name[NG_TYPESIZ]; /* name of type */ 2924cf49a43SJulian Elischer u_int32_t numnodes; /* number alive */ 2934cf49a43SJulian Elischer }; 2944cf49a43SJulian Elischer 295f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 296f8307e12SArchie Cobbs #define NG_GENERIC_TYPEINFO_INFO() { \ 297f8307e12SArchie Cobbs { "typename", &ng_parse_typebuf_type }, \ 29857b57be3SArchie Cobbs { "numnodes", &ng_parse_uint32_type }, \ 299f0184ff8SArchie Cobbs { NULL } \ 300f8307e12SArchie Cobbs } 301f8307e12SArchie Cobbs 3024cf49a43SJulian Elischer struct typelist { 3034cf49a43SJulian Elischer u_int32_t numtypes; 3040eecad8dSHartmut Brandt struct typeinfo typeinfo[]; 3054cf49a43SJulian Elischer }; 3064cf49a43SJulian Elischer 307f8307e12SArchie Cobbs /* Keep this in sync with the above structure definition */ 308f8307e12SArchie Cobbs #define NG_GENERIC_TYPELIST_INFO(tiarraytype) { \ 30957b57be3SArchie Cobbs { "numtypes", &ng_parse_uint32_type }, \ 310f8307e12SArchie Cobbs { "typeinfo", (tiarraytype) }, \ 311f0184ff8SArchie Cobbs { NULL } \ 312f8307e12SArchie Cobbs } 313f8307e12SArchie Cobbs 314859a4d16SJulian Elischer struct ngm_bandwidth { 315859a4d16SJulian Elischer u_int64_t nominal_in; 316859a4d16SJulian Elischer u_int64_t seen_in; 317859a4d16SJulian Elischer u_int64_t nominal_out; 318859a4d16SJulian Elischer u_int64_t seen_out; 319859a4d16SJulian Elischer }; 320859a4d16SJulian Elischer 321859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */ 322859a4d16SJulian Elischer #define NG_GENERIC_BANDWIDTH_INFO() { \ 323859a4d16SJulian Elischer { "nominal_in", &ng_parse_uint64_type }, \ 324859a4d16SJulian Elischer { "seen_in", &ng_parse_uint64_type }, \ 325859a4d16SJulian Elischer { "nominal_out", &ng_parse_uint64_type }, \ 326859a4d16SJulian Elischer { "seen_out", &ng_parse_uint64_type }, \ 327f0184ff8SArchie Cobbs { NULL } \ 328859a4d16SJulian Elischer } 329859a4d16SJulian Elischer 330859a4d16SJulian Elischer /* 331859a4d16SJulian Elischer * Information about a node's 'output' queue. 332859a4d16SJulian Elischer * This is NOT the netgraph input queueing mechanism, 333859a4d16SJulian Elischer * but rather any queue the node may implement internally 334859a4d16SJulian Elischer * This has to consider ALTQ if we are to work with it. 335859a4d16SJulian Elischer * As far as I can see, ALTQ counts PACKETS, not bytes. 336859a4d16SJulian Elischer * If ALTQ has several queues and one has passed a watermark 337859a4d16SJulian Elischer * we should have the priority of that queue be real (and not -1) 338859a4d16SJulian Elischer * XXX ALTQ stuff is just an idea..... 339859a4d16SJulian Elischer */ 340859a4d16SJulian Elischer struct ngm_queue_state { 341859a4d16SJulian Elischer u_int queue_priority; /* maybe only low-pri is full. -1 = all*/ 342859a4d16SJulian Elischer u_int max_queuelen_bytes; 343859a4d16SJulian Elischer u_int max_queuelen_packets; 344859a4d16SJulian Elischer u_int low_watermark; 345859a4d16SJulian Elischer u_int high_watermark; 346859a4d16SJulian Elischer u_int current; 347859a4d16SJulian Elischer }; 348859a4d16SJulian Elischer 349859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */ 350859a4d16SJulian Elischer #define NG_GENERIC_QUEUE_INFO() { \ 351859a4d16SJulian Elischer { "max_queuelen_bytes", &ng_parse_uint_type }, \ 352859a4d16SJulian Elischer { "max_queuelen_packets", &ng_parse_uint_type }, \ 353859a4d16SJulian Elischer { "high_watermark", &ng_parse_uint_type }, \ 354859a4d16SJulian Elischer { "low_watermark", &ng_parse_uint_type }, \ 355859a4d16SJulian Elischer { "current", &ng_parse_uint_type }, \ 356f0184ff8SArchie Cobbs { NULL } \ 357859a4d16SJulian Elischer } 358859a4d16SJulian Elischer 359859a4d16SJulian Elischer /* Tell a node who to send async flow control info to. */ 360859a4d16SJulian Elischer struct flow_manager { 361859a4d16SJulian Elischer ng_ID_t id; /* unique identifier */ 362859a4d16SJulian Elischer }; 363859a4d16SJulian Elischer 364859a4d16SJulian Elischer /* Keep this in sync with the above structure definition */ 365859a4d16SJulian Elischer #define NG_GENERIC_FLOW_MANAGER_INFO() { \ 366859a4d16SJulian Elischer { "id", &ng_parse_hint32_type }, \ 367f0184ff8SArchie Cobbs { NULL } \ 368859a4d16SJulian Elischer } 369859a4d16SJulian Elischer 370859a4d16SJulian Elischer 3714cf49a43SJulian Elischer /* 3724cf49a43SJulian Elischer * For netgraph nodes that are somehow associated with file descriptors 3734cf49a43SJulian Elischer * (e.g., a device that has a /dev entry and is also a netgraph node), 3744cf49a43SJulian Elischer * we define a generic ioctl for requesting the corresponding nodeinfo 3754cf49a43SJulian Elischer * structure and for assigning a name (if there isn't one already). 3764cf49a43SJulian Elischer * 3774cf49a43SJulian Elischer * For these to you need to also #include <sys/ioccom.h>. 3784cf49a43SJulian Elischer */ 3794cf49a43SJulian Elischer 3804cf49a43SJulian Elischer #define NGIOCGINFO _IOR('N', 40, struct nodeinfo) /* get node info */ 3814cf49a43SJulian Elischer #define NGIOCSETNAME _IOW('N', 41, struct ngm_name) /* set node name */ 3824cf49a43SJulian Elischer 383664a31e4SPeter Wemm #ifdef _KERNEL 3844cf49a43SJulian Elischer /* 3854cf49a43SJulian Elischer * Allocate and initialize a netgraph message "msg" with "len" 3864cf49a43SJulian Elischer * extra bytes of argument. Sets "msg" to NULL if fails. 3874cf49a43SJulian Elischer * Does not initialize token. 3884cf49a43SJulian Elischer */ 3894cf49a43SJulian Elischer #define NG_MKMESSAGE(msg, cookie, cmdid, len, how) \ 3904cf49a43SJulian Elischer do { \ 3914cf49a43SJulian Elischer MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg) \ 392069154d5SJulian Elischer + (len), M_NETGRAPH_MSG, (how) | M_ZERO); \ 3934cf49a43SJulian Elischer if ((msg) == NULL) \ 3944cf49a43SJulian Elischer break; \ 3954cf49a43SJulian Elischer (msg)->header.version = NG_VERSION; \ 3964cf49a43SJulian Elischer (msg)->header.typecookie = (cookie); \ 3974cf49a43SJulian Elischer (msg)->header.cmd = (cmdid); \ 3984cf49a43SJulian Elischer (msg)->header.arglen = (len); \ 3994cf49a43SJulian Elischer strncpy((msg)->header.cmdstr, #cmdid, \ 4004cf49a43SJulian Elischer sizeof((msg)->header.cmdstr) - 1); \ 4014cf49a43SJulian Elischer } while (0) 4024cf49a43SJulian Elischer 4034cf49a43SJulian Elischer /* 4044cf49a43SJulian Elischer * Allocate and initialize a response "rsp" to a message "msg" 4054cf49a43SJulian Elischer * with "len" extra bytes of argument. Sets "rsp" to NULL if fails. 4064cf49a43SJulian Elischer */ 4074cf49a43SJulian Elischer #define NG_MKRESPONSE(rsp, msg, len, how) \ 4084cf49a43SJulian Elischer do { \ 4094cf49a43SJulian Elischer MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg) \ 410069154d5SJulian Elischer + (len), M_NETGRAPH_MSG, (how) | M_ZERO); \ 4114cf49a43SJulian Elischer if ((rsp) == NULL) \ 4124cf49a43SJulian Elischer break; \ 4134cf49a43SJulian Elischer (rsp)->header.version = NG_VERSION; \ 4144cf49a43SJulian Elischer (rsp)->header.arglen = (len); \ 4154cf49a43SJulian Elischer (rsp)->header.token = (msg)->header.token; \ 4164cf49a43SJulian Elischer (rsp)->header.typecookie = (msg)->header.typecookie; \ 4174cf49a43SJulian Elischer (rsp)->header.cmd = (msg)->header.cmd; \ 4184cf49a43SJulian Elischer bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr, \ 4194cf49a43SJulian Elischer sizeof((rsp)->header.cmdstr)); \ 4204cf49a43SJulian Elischer (rsp)->header.flags |= NGF_RESP; \ 4214cf49a43SJulian Elischer } while (0) 422644168eeSGleb Smirnoff 423644168eeSGleb Smirnoff /* 424644168eeSGleb Smirnoff * Make a copy of message. Sets "copy" to NULL if fails. 425644168eeSGleb Smirnoff */ 426644168eeSGleb Smirnoff #define NG_COPYMESSAGE(copy, msg, how) \ 427644168eeSGleb Smirnoff do { \ 428644168eeSGleb Smirnoff MALLOC((copy), struct ng_mesg *, sizeof(struct ng_mesg) + \ 429644168eeSGleb Smirnoff (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO); \ 430644168eeSGleb Smirnoff if ((copy) == NULL) \ 431644168eeSGleb Smirnoff break; \ 432644168eeSGleb Smirnoff (copy)->header.version = NG_VERSION; \ 433644168eeSGleb Smirnoff (copy)->header.arglen = (msg)->header.arglen; \ 434644168eeSGleb Smirnoff (copy)->header.token = (msg)->header.token; \ 435644168eeSGleb Smirnoff (copy)->header.typecookie = (msg)->header.typecookie; \ 436644168eeSGleb Smirnoff (copy)->header.cmd = (msg)->header.cmd; \ 437644168eeSGleb Smirnoff (copy)->header.flags = (msg)->header.flags; \ 438644168eeSGleb Smirnoff bcopy((msg)->header.cmdstr, (copy)->header.cmdstr, \ 439644168eeSGleb Smirnoff sizeof((copy)->header.cmdstr)); \ 440644168eeSGleb Smirnoff if ((msg)->header.arglen > 0) \ 441644168eeSGleb Smirnoff bcopy((msg)->data, (copy)->data, (msg)->header.arglen); \ 442644168eeSGleb Smirnoff } while (0) 443644168eeSGleb Smirnoff 444664a31e4SPeter Wemm #endif /* _KERNEL */ 4454cf49a43SJulian Elischer 4464cf49a43SJulian Elischer #endif /* _NETGRAPH_NG_MESSAGE_H_ */ 447