The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netgraph/ng_message.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 43890c7cf69d7fff51aae6db8848c7b4


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.