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_split.c

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  * Copyright (c) 1999-2000, Vitaly V Belekhov
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice unmodified, this list of conditions, and the following
   11  *    disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  * $FreeBSD: releng/5.2/sys/netgraph/ng_split.c 87599 2001-12-10 08:09:49Z obrien $
   29  *
   30  */
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/errno.h>
   35 #include <sys/kernel.h>
   36 #include <sys/malloc.h>
   37 #include <sys/mbuf.h>
   38 #include <sys/errno.h>
   39 #include <sys/sockio.h>
   40 #include <sys/socket.h>
   41 #include <sys/syslog.h>
   42 
   43 #include <netgraph/ng_message.h>
   44 #include <netgraph/netgraph.h>
   45 #include <netgraph/ng_split.h>
   46 
   47 /* Netgraph methods */
   48 static ng_constructor_t ng_split_constructor;
   49 static ng_shutdown_t ng_split_shutdown;
   50 static ng_newhook_t ng_split_newhook;
   51 static ng_rcvdata_t ng_split_rcvdata;
   52 static ng_disconnect_t ng_split_disconnect;
   53 
   54 /* Node type descriptor */
   55 static struct ng_type typestruct = {
   56         NG_ABI_VERSION,
   57         NG_SPLIT_NODE_TYPE,
   58         NULL,
   59         ng_split_constructor,
   60         NULL,
   61         ng_split_shutdown,
   62         ng_split_newhook,
   63         NULL,
   64         NULL,
   65         ng_split_rcvdata,
   66         ng_split_disconnect,
   67         NULL
   68 };
   69 NETGRAPH_INIT(ng_split, &typestruct);
   70 
   71 /* Node private data */
   72 struct ng_split_private {
   73         hook_p out;
   74         hook_p in;
   75         hook_p mixed;
   76         node_p  node;                   /* Our netgraph node */
   77 };
   78 typedef struct ng_split_private *priv_p;
   79 
   80 /************************************************************************
   81                         NETGRAPH NODE STUFF
   82  ************************************************************************/
   83 
   84 /*
   85  * Constructor for a node
   86  */
   87 static int
   88 ng_split_constructor(node_p node)
   89 {
   90         priv_p          priv;
   91 
   92         /* Allocate node */
   93         MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_ZERO | M_NOWAIT);
   94         if (priv == NULL)
   95                 return (ENOMEM);
   96         bzero(priv, sizeof(*priv));
   97 
   98         /* Link together node and private info */
   99         NG_NODE_SET_PRIVATE(node, priv);
  100         priv->node = node;
  101 
  102         /* Done */
  103         return (0);
  104 }
  105 
  106 /*
  107  * Give our ok for a hook to be added
  108  */
  109 static int
  110 ng_split_newhook(node_p node, hook_p hook, const char *name)
  111 {
  112         priv_p          priv = NG_NODE_PRIVATE(node);
  113         hook_p          *localhook;
  114 
  115         if (strcmp(name, NG_SPLIT_HOOK_MIXED) == 0) {
  116                 localhook = &priv->mixed;
  117         } else if (strcmp(name, NG_SPLIT_HOOK_IN) == 0) {
  118                 localhook = &priv->in;
  119         } else if (strcmp(name, NG_SPLIT_HOOK_OUT) == 0) {
  120                 localhook = &priv->out;
  121         } else {
  122                 return (EPFNOSUPPORT);
  123         }
  124 
  125         if (*localhook != NULL)
  126                 return (EISCONN);
  127         *localhook = hook;
  128         NG_HOOK_SET_PRIVATE(hook, localhook);
  129 
  130         return (0);
  131 }
  132 
  133 /*
  134  * Recive data from a hook.
  135  */
  136 static int
  137 ng_split_rcvdata(hook_p hook, item_p item)
  138 {
  139         const priv_p    priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
  140         int             error = 0;
  141 
  142         if (hook == priv->out) {
  143                 printf("ng_split: got packet from out hook!\n");
  144                 NG_FREE_ITEM(item);
  145                 error = EINVAL;
  146         } else if ((hook == priv->in) && (priv->mixed != NULL)) {
  147                 NG_FWD_ITEM_HOOK(error, item, priv->mixed);
  148         } else if ((hook == priv->mixed) && (priv->out != NULL)) {
  149                 NG_FWD_ITEM_HOOK(error, item, priv->out);
  150         }
  151 
  152         return (error);
  153 }
  154 
  155 static int
  156 ng_split_shutdown(node_p node)
  157 {
  158         const priv_p    priv = NG_NODE_PRIVATE(node);
  159 
  160         NG_NODE_SET_PRIVATE(node, NULL);
  161         NG_NODE_UNREF(node);
  162         FREE(priv, M_NETGRAPH);
  163 
  164         return (0);
  165 }
  166 
  167 /*
  168  * Hook disconnection
  169  */
  170 static int
  171 ng_split_disconnect(hook_p hook)
  172 {
  173         hook_p          *localhook = NG_HOOK_PRIVATE(hook);
  174         
  175         KASSERT(localhook != NULL, ("%s: null info", __func__));
  176         *localhook = NULL;
  177         if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
  178             && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
  179                 ng_rmnode_self(NG_HOOK_NODE(hook));
  180         }
  181 
  182         return (0);
  183 }

Cache object: faf58366943a58c877cd20998ac95930


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