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

Cache object: 348af2f22fbc8419bafff6c89d81927a


[ 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.