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  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  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  * ng_message.h
    3  */
    4 
    5 /*-
    6  * Copyright (c) 1996-1999 Whistle Communications, Inc.
    7  * All rights reserved.
    8  * 
    9  * Subject to the following obligations and disclaimer of warranty, use and
   10  * redistribution of this software, in source or object code forms, with or
   11  * without modifications are expressly permitted by Whistle Communications;
   12  * provided, however, that:
   13  * 1. Any and all reproductions of the source or object code must include the
   14  *    copyright notice above and the following disclaimer of warranties; and
   15  * 2. No rights are granted, in any manner or form, to use Whistle
   16  *    Communications, Inc. trademarks, including the mark "WHISTLE
   17  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
   18  *    such appears in the above copyright notice or in the software.
   19  * 
   20  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
   21  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
   22  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
   23  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
   24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
   25  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
   26  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
   27  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
   28  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
   29  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
   30  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
   31  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
   32  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
   33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   35  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
   36  * OF SUCH DAMAGE.
   37  *
   38  * Author: Julian Elischer <julian@freebsd.org>
   39  *
   40  * $FreeBSD: releng/7.4/sys/netgraph/ng_message.h 163461 2006-10-17 11:01:20Z glebius $
   41  * $Whistle: ng_message.h,v 1.12 1999/01/25 01:17:44 archie Exp $
   42  */
   43 
   44 #ifndef _NETGRAPH_NG_MESSAGE_H_
   45 #define _NETGRAPH_NG_MESSAGE_H_
   46 
   47 /* ASCII string size limits */
   48 #define NG_TYPESIZ      32      /* max type name len (including null) */
   49 #define NG_HOOKSIZ      32      /* max hook name len (including null) */
   50 #define NG_NODESIZ      32      /* max node name len (including null) */
   51 #define NG_PATHSIZ      512     /* max path len (including null) */
   52 #define NG_CMDSTRSIZ    32      /* max command string (including null) */
   53 
   54 #ifndef BURN_BRIDGES
   55 /* don't use these - they will go away */
   56 #define NG_TYPELEN      (NG_TYPESIZ - 1)
   57 #define NG_HOOKLEN      (NG_HOOKSIZ - 1)
   58 #define NG_NODELEN      (NG_NODESIZ - 1)
   59 #define NG_PATHLEN      (NG_PATHSIZ - 1)
   60 #define NG_CMDSTRLEN    (NG_CMDSTRSIZ - 1)
   61 #endif
   62 
   63 #define NG_TEXTRESPONSE 1024    /* allow this length for a text response */
   64 
   65 /* A netgraph message */
   66 struct ng_mesg {
   67         struct  ng_msghdr {
   68                 u_char          version;                /*  == NGM_VERSION */
   69                 u_char          spare;                  /* pad to 4 bytes */
   70                 u_int16_t       spare2; 
   71                 u_int32_t       arglen;                 /* length of data */
   72                 u_int32_t       cmd;                    /* command identifier */
   73                 u_int32_t       flags;                  /* message status */
   74                 u_int32_t       token;                  /* match with reply */
   75                 u_int32_t       typecookie;             /* node's type cookie */
   76                 u_char          cmdstr[NG_CMDSTRSIZ];   /* cmd string + \0 */
   77         } header;
   78         char    data[];                 /* placeholder for actual data */
   79 };
   80 
   81 /* This command is guaranteed to not alter data (or'd into the command). */
   82 #define NGM_READONLY    0x10000000
   83 /* This command is guaranteed to have a reply (or'd into the command). */
   84 #define NGM_HASREPLY    0x20000000
   85 
   86 /* Keep this in sync with the above structure definition */
   87 #define NG_GENERIC_NG_MESG_INFO(dtype)  {                       \
   88           { "version",          &ng_parse_uint8_type    },      \
   89           { "spare",            &ng_parse_uint8_type    },      \
   90           { "spare2",           &ng_parse_uint16_type   },      \
   91           { "arglen",           &ng_parse_uint32_type   },      \
   92           { "cmd",              &ng_parse_uint32_type   },      \
   93           { "flags",            &ng_parse_hint32_type   },      \
   94           { "token",            &ng_parse_uint32_type   },      \
   95           { "typecookie",       &ng_parse_uint32_type   },      \
   96           { "cmdstr",           &ng_parse_cmdbuf_type   },      \
   97           { "data",             (dtype)                 },      \
   98           { NULL }                                              \
   99 }
  100 
  101 /*
  102  * Netgraph message header compatibility field
  103  * Interfaces within the kernel are defined by a different 
  104  * value (see NG_ABI_VERSION in netgraph.h)
  105  */
  106 #define NG_VERSION      8
  107 
  108 /* Flags field flags */
  109 #define NGF_ORIG        0x00000000      /* the msg is the original request */
  110 #define NGF_RESP        0x00000001      /* the message is a response */
  111 
  112 /* Type of a unique node ID. */
  113 #define ng_ID_t uint32_t
  114 
  115 /*
  116  * Here we describe the "generic" messages that all nodes inherently
  117  * understand. With the exception of NGM_TEXT_STATUS, these are handled
  118  * automatically by the base netgraph code.
  119  */
  120 
  121 /* Generic message type cookie */
  122 #define NGM_GENERIC_COOKIE      1137070366
  123 
  124 /* Generic messages defined for this type cookie. */
  125 enum {
  126         NGM_SHUTDOWN    = 1,    /* Shut down node. */
  127         NGM_MKPEER      = 2,    /* Create and attach a peer node. */
  128         NGM_CONNECT     = 3,    /* Connect two nodes. */
  129         NGM_NAME        = 4,    /* Give a node a name. */
  130         NGM_RMHOOK      = 5,    /* Break a connection between two nodes. */
  131 
  132         /* Get nodeinfo for target. */
  133         NGM_NODEINFO    = (6|NGM_READONLY|NGM_HASREPLY),
  134         /* Get list of hooks on node. */
  135         NGM_LISTHOOKS   = (7|NGM_READONLY|NGM_HASREPLY),
  136         /* List globally named nodes. */
  137         NGM_LISTNAMES   = (8|NGM_READONLY|NGM_HASREPLY),
  138         /* List all nodes. */
  139         NGM_LISTNODES   = (9|NGM_READONLY|NGM_HASREPLY),
  140         /* List installed node types. */
  141         NGM_LISTTYPES   = (10|NGM_READONLY|NGM_HASREPLY),
  142         /* (optional) Get text status. */
  143         NGM_TEXT_STATUS = (11|NGM_READONLY|NGM_HASREPLY),
  144         /* Convert struct ng_mesg to ASCII. */
  145         NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
  146         /* Convert ASCII to struct ng_mesg. */
  147         NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
  148         /* (optional) Get/set text config. */
  149         NGM_TEXT_CONFIG = 14,
  150 };
  151 
  152 /*
  153  * Flow control and intra node control messages.
  154  * These are routed between nodes to allow flow control and to allow
  155  * events to be passed around the graph. 
  156  * There will be some form of default handling for these but I 
  157  * do not yet know what it is..
  158  */
  159 
  160 /* Generic message type cookie */
  161 #define NGM_FLOW_COOKIE 851672669 /* temp for debugging */
  162 
  163 /* Upstream messages */
  164 #define NGM_LINK_IS_UP          32      /* e.g. carrier found - no data */
  165 #define NGM_LINK_IS_DOWN        33      /* carrier lost, includes queue state */
  166 #define NGM_HIGH_WATER_PASSED   34      /* includes queue state */
  167 #define NGM_LOW_WATER_PASSED    35      /* includes queue state */
  168 #define NGM_SYNC_QUEUE_STATE    36      /* sync response from sending packet */
  169 
  170 /* Downstream messages */
  171 #define NGM_DROP_LINK           41      /* drop DTR, etc. - stay in the graph */
  172 #define NGM_RAISE_LINK          42      /* if you previously dropped it */
  173 #define NGM_FLUSH_QUEUE         43      /* no data */
  174 #define NGM_GET_BANDWIDTH       (44|NGM_READONLY)       /* either real or measured */
  175 #define NGM_SET_XMIT_Q_LIMITS   45      /* includes queue state */
  176 #define NGM_GET_XMIT_Q_LIMITS   (46|NGM_READONLY)       /* returns queue state */
  177 #define NGM_MICROMANAGE         47      /* We want sync. queue state
  178                                                 reply for each packet sent */
  179 #define NGM_SET_FLOW_MANAGER    48      /* send flow control here */ 
  180 /* Structure used for NGM_MKPEER */
  181 struct ngm_mkpeer {
  182         char    type[NG_TYPESIZ];               /* peer type */
  183         char    ourhook[NG_HOOKSIZ];            /* hook name */
  184         char    peerhook[NG_HOOKSIZ];           /* peer hook name */
  185 };
  186 
  187 /* Keep this in sync with the above structure definition */
  188 #define NG_GENERIC_MKPEER_INFO()        {                       \
  189           { "type",             &ng_parse_typebuf_type  },      \
  190           { "ourhook",          &ng_parse_hookbuf_type  },      \
  191           { "peerhook",         &ng_parse_hookbuf_type  },      \
  192           { NULL }                                              \
  193 }
  194 
  195 /* Structure used for NGM_CONNECT */
  196 struct ngm_connect {
  197         char    path[NG_PATHSIZ];               /* peer path */
  198         char    ourhook[NG_HOOKSIZ];            /* hook name */
  199         char    peerhook[NG_HOOKSIZ];           /* peer hook name */
  200 };
  201 
  202 /* Keep this in sync with the above structure definition */
  203 #define NG_GENERIC_CONNECT_INFO()       {                       \
  204           { "path",             &ng_parse_pathbuf_type  },      \
  205           { "ourhook",          &ng_parse_hookbuf_type  },      \
  206           { "peerhook",         &ng_parse_hookbuf_type  },      \
  207           { NULL }                                              \
  208 }
  209 
  210 /* Structure used for NGM_NAME */
  211 struct ngm_name {
  212         char    name[NG_NODESIZ];                       /* node name */
  213 };
  214 
  215 /* Keep this in sync with the above structure definition */
  216 #define NG_GENERIC_NAME_INFO()  {                               \
  217           { "name",             &ng_parse_nodebuf_type  },      \
  218           { NULL }                                              \
  219 }
  220 
  221 /* Structure used for NGM_RMHOOK */
  222 struct ngm_rmhook {
  223         char    ourhook[NG_HOOKSIZ];            /* hook name */
  224 };
  225 
  226 /* Keep this in sync with the above structure definition */
  227 #define NG_GENERIC_RMHOOK_INFO()        {                       \
  228           { "hook",             &ng_parse_hookbuf_type  },      \
  229           { NULL }                                              \
  230 }
  231 
  232 /* Structure used for NGM_NODEINFO */
  233 struct nodeinfo {
  234         char            name[NG_NODESIZ];       /* node name (if any) */
  235         char            type[NG_TYPESIZ];       /* peer type */
  236         ng_ID_t         id;                     /* unique identifier */
  237         u_int32_t       hooks;                  /* number of active hooks */
  238 };
  239 
  240 /* Keep this in sync with the above structure definition */
  241 #define NG_GENERIC_NODEINFO_INFO()      {                       \
  242           { "name",             &ng_parse_nodebuf_type  },      \
  243           { "type",             &ng_parse_typebuf_type  },      \
  244           { "id",               &ng_parse_hint32_type   },      \
  245           { "hooks",            &ng_parse_uint32_type   },      \
  246           { NULL }                                              \
  247 }
  248 
  249 /* Structure used for NGM_LISTHOOKS */
  250 struct linkinfo {
  251         char            ourhook[NG_HOOKSIZ];    /* hook name */
  252         char            peerhook[NG_HOOKSIZ];   /* peer hook */
  253         struct nodeinfo nodeinfo;
  254 };
  255 
  256 /* Keep this in sync with the above structure definition */
  257 #define NG_GENERIC_LINKINFO_INFO(nitype)        {               \
  258           { "ourhook",          &ng_parse_hookbuf_type  },      \
  259           { "peerhook",         &ng_parse_hookbuf_type  },      \
  260           { "nodeinfo",         (nitype)                },      \
  261           { NULL }                                              \
  262 }
  263 
  264 struct hooklist {
  265         struct nodeinfo nodeinfo;               /* node information */
  266         struct linkinfo link[];                 /* info about each hook */
  267 };
  268 
  269 /* Keep this in sync with the above structure definition */
  270 #define NG_GENERIC_HOOKLIST_INFO(nitype,litype) {               \
  271           { "nodeinfo",         (nitype)                },      \
  272           { "linkinfo",         (litype)                },      \
  273           { NULL }                                              \
  274 }
  275 
  276 /* Structure used for NGM_LISTNAMES/NGM_LISTNODES */
  277 struct namelist {
  278         u_int32_t       numnames;
  279         struct nodeinfo nodeinfo[];
  280 };
  281 
  282 /* Keep this in sync with the above structure definition */
  283 #define NG_GENERIC_LISTNODES_INFO(niarraytype)  {               \
  284           { "numnames",         &ng_parse_uint32_type   },      \
  285           { "nodeinfo",         (niarraytype)           },      \
  286           { NULL }                                              \
  287 }
  288 
  289 /* Structure used for NGM_LISTTYPES */
  290 struct typeinfo {
  291         char            type_name[NG_TYPESIZ];  /* name of type */
  292         u_int32_t       numnodes;               /* number alive */
  293 };
  294 
  295 /* Keep this in sync with the above structure definition */
  296 #define NG_GENERIC_TYPEINFO_INFO()              {               \
  297           { "typename",         &ng_parse_typebuf_type  },      \
  298           { "numnodes",         &ng_parse_uint32_type   },      \
  299           { NULL }                                              \
  300 }
  301 
  302 struct typelist {
  303         u_int32_t       numtypes;
  304         struct typeinfo typeinfo[];
  305 };
  306 
  307 /* Keep this in sync with the above structure definition */
  308 #define NG_GENERIC_TYPELIST_INFO(tiarraytype)   {               \
  309           { "numtypes",         &ng_parse_uint32_type   },      \
  310           { "typeinfo",         (tiarraytype)           },      \
  311           { NULL }                                              \
  312 }
  313 
  314 struct ngm_bandwidth {
  315         u_int64_t       nominal_in;
  316         u_int64_t       seen_in;
  317         u_int64_t       nominal_out;
  318         u_int64_t       seen_out;
  319 };
  320 
  321 /* Keep this in sync with the above structure definition */
  322 #define NG_GENERIC_BANDWIDTH_INFO()     {                       \
  323           { "nominal_in",       &ng_parse_uint64_type   },      \
  324           { "seen_in",          &ng_parse_uint64_type   },      \
  325           { "nominal_out",      &ng_parse_uint64_type   },      \
  326           { "seen_out",         &ng_parse_uint64_type   },      \
  327           { NULL }                                              \
  328 }
  329 
  330 /*
  331  * Information about a node's 'output' queue.
  332  * This is NOT the netgraph input queueing mechanism,
  333  * but rather any queue the node may implement internally
  334  * This has to consider ALTQ if we are to work with it.
  335  * As far as I can see, ALTQ counts PACKETS, not bytes.
  336  * If ALTQ has several queues and one has passed a watermark
  337  * we should have the priority of that queue be real (and not -1)
  338  * XXX ALTQ stuff is just an idea.....
  339  */
  340 struct ngm_queue_state {
  341         u_int queue_priority; /* maybe only low-pri is full. -1 = all*/
  342         u_int   max_queuelen_bytes;
  343         u_int   max_queuelen_packets;
  344         u_int   low_watermark;
  345         u_int   high_watermark;
  346         u_int   current;
  347 };
  348 
  349 /* Keep this in sync with the above structure definition */
  350 #define NG_GENERIC_QUEUE_INFO() {                               \
  351           { "max_queuelen_bytes", &ng_parse_uint_type   },      \
  352           { "max_queuelen_packets", &ng_parse_uint_type },      \
  353           { "high_watermark",   &ng_parse_uint_type     },      \
  354           { "low_watermark",    &ng_parse_uint_type     },      \
  355           { "current",          &ng_parse_uint_type     },      \
  356           { NULL }                                              \
  357 }
  358 
  359 /* Tell a node who to send async flow control info to. */
  360 struct flow_manager {
  361         ng_ID_t         id;                     /* unique identifier */
  362 };
  363 
  364 /* Keep this in sync with the above structure definition */
  365 #define NG_GENERIC_FLOW_MANAGER_INFO()  {                       \
  366           { "id",               &ng_parse_hint32_type   },      \
  367           { NULL }                                              \
  368 }
  369 
  370 
  371 /*
  372  * For netgraph nodes that are somehow associated with file descriptors
  373  * (e.g., a device that has a /dev entry and is also a netgraph node),
  374  * we define a generic ioctl for requesting the corresponding nodeinfo
  375  * structure and for assigning a name (if there isn't one already).
  376  *
  377  * For these to you need to also #include <sys/ioccom.h>.
  378  */
  379 
  380 #define NGIOCGINFO      _IOR('N', 40, struct nodeinfo)  /* get node info */
  381 #define NGIOCSETNAME    _IOW('N', 41, struct ngm_name)  /* set node name */
  382 
  383 #ifdef _KERNEL
  384 /*
  385  * Allocate and initialize a netgraph message "msg" with "len"
  386  * extra bytes of argument. Sets "msg" to NULL if fails.
  387  * Does not initialize token.
  388  */
  389 #define NG_MKMESSAGE(msg, cookie, cmdid, len, how)                      \
  390         do {                                                            \
  391           MALLOC((msg), struct ng_mesg *, sizeof(struct ng_mesg)        \
  392             + (len), M_NETGRAPH_MSG, (how) | M_ZERO);                   \
  393           if ((msg) == NULL)                                            \
  394             break;                                                      \
  395           (msg)->header.version = NG_VERSION;                           \
  396           (msg)->header.typecookie = (cookie);                          \
  397           (msg)->header.cmd = (cmdid);                                  \
  398           (msg)->header.arglen = (len);                                 \
  399           strncpy((msg)->header.cmdstr, #cmdid,                         \
  400             sizeof((msg)->header.cmdstr) - 1);                          \
  401         } while (0)
  402 
  403 /*
  404  * Allocate and initialize a response "rsp" to a message "msg"
  405  * with "len" extra bytes of argument. Sets "rsp" to NULL if fails.
  406  */
  407 #define NG_MKRESPONSE(rsp, msg, len, how)                               \
  408         do {                                                            \
  409           MALLOC((rsp), struct ng_mesg *, sizeof(struct ng_mesg)        \
  410             + (len), M_NETGRAPH_MSG, (how) | M_ZERO);                   \
  411           if ((rsp) == NULL)                                            \
  412             break;                                                      \
  413           (rsp)->header.version = NG_VERSION;                           \
  414           (rsp)->header.arglen = (len);                                 \
  415           (rsp)->header.token = (msg)->header.token;                    \
  416           (rsp)->header.typecookie = (msg)->header.typecookie;          \
  417           (rsp)->header.cmd = (msg)->header.cmd;                        \
  418           bcopy((msg)->header.cmdstr, (rsp)->header.cmdstr,             \
  419             sizeof((rsp)->header.cmdstr));                              \
  420           (rsp)->header.flags |= NGF_RESP;                              \
  421         } while (0)
  422 
  423 /*
  424  * Make a copy of message. Sets "copy" to NULL if fails.
  425  */
  426 #define NG_COPYMESSAGE(copy, msg, how)                                  \
  427         do {                                                            \
  428           MALLOC((copy), struct ng_mesg *, sizeof(struct ng_mesg) +     \
  429             (msg)->header.arglen, M_NETGRAPH_MSG, (how) | M_ZERO);      \
  430           if ((copy) == NULL)                                           \
  431             break;                                                      \
  432           (copy)->header.version = NG_VERSION;                          \
  433           (copy)->header.arglen = (msg)->header.arglen;                 \
  434           (copy)->header.token = (msg)->header.token;                   \
  435           (copy)->header.typecookie = (msg)->header.typecookie;         \
  436           (copy)->header.cmd = (msg)->header.cmd;                       \
  437           (copy)->header.flags = (msg)->header.flags;                   \
  438           bcopy((msg)->header.cmdstr, (copy)->header.cmdstr,            \
  439             sizeof((copy)->header.cmdstr));                             \
  440           if ((msg)->header.arglen > 0)                                 \
  441             bcopy((msg)->data, (copy)->data, (msg)->header.arglen);     \
  442         } while (0)
  443 
  444 #endif /* _KERNEL */
  445 
  446 #endif /* _NETGRAPH_NG_MESSAGE_H_ */

Cache object: d697df0be73fa46fd31f7c4182e90293


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