1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* ng_sample.c
|
2005-01-07 01:45:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
1999-10-21 09:06:11 +00:00
|
|
|
* Copyright (c) 1996-1999 Whistle Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Subject to the following obligations and disclaimer of warranty, use and
|
|
|
|
* redistribution of this software, in source or object code forms, with or
|
|
|
|
* without modifications are expressly permitted by Whistle Communications;
|
|
|
|
* provided, however, that:
|
|
|
|
* 1. Any and all reproductions of the source or object code must include the
|
|
|
|
* copyright notice above and the following disclaimer of warranties; and
|
|
|
|
* 2. No rights are granted, in any manner or form, to use Whistle
|
|
|
|
* Communications, Inc. trademarks, including the mark "WHISTLE
|
|
|
|
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
|
|
|
* such appears in the above copyright notice or in the software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
|
|
|
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
|
|
|
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
|
|
|
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
|
|
|
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
|
|
|
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
|
|
|
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
|
|
|
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
2000-10-24 17:32:45 +00:00
|
|
|
* Author: Julian Elischer <julian@freebsd.org>
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1999-11-01 10:00:40 +00:00
|
|
|
* $Whistle: ng_sample.c,v 1.13 1999/11/01 09:24:52 julian Exp $
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
1999-12-01 19:40:37 +00:00
|
|
|
#include <sys/ctype.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
1999-12-01 19:40:37 +00:00
|
|
|
#include <netgraph/ng_parse.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <netgraph/ng_sample.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
|
|
|
|
2001-01-10 07:13:58 +00:00
|
|
|
/* If you do complicated mallocs you may want to do this */
|
|
|
|
/* and use it for your mallocs */
|
|
|
|
#ifdef NG_SEPARATE_MALLOC
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_NETGRAPH_XXX, "netgraph_xxx", "netgraph xxx node");
|
2001-01-10 07:13:58 +00:00
|
|
|
#else
|
|
|
|
#define M_NETGRAPH_XXX M_NETGRAPH
|
|
|
|
#endif
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* This section contains the netgraph method declarations for the
|
|
|
|
* sample node. These methods define the netgraph 'type'.
|
|
|
|
*/
|
|
|
|
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_constructor_t ng_xxx_constructor;
|
|
|
|
static ng_rcvmsg_t ng_xxx_rcvmsg;
|
2001-01-06 00:46:47 +00:00
|
|
|
static ng_shutdown_t ng_xxx_shutdown;
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_newhook_t ng_xxx_newhook;
|
|
|
|
static ng_connect_t ng_xxx_connect;
|
2005-02-06 19:20:16 +00:00
|
|
|
static ng_rcvdata_t ng_xxx_rcvdata;
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_disconnect_t ng_xxx_disconnect;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
1999-12-01 19:40:37 +00:00
|
|
|
/* Parse type for struct ngxxxstat */
|
2002-05-31 23:48:03 +00:00
|
|
|
static const struct ng_parse_struct_field ng_xxx_stat_type_fields[]
|
|
|
|
= NG_XXX_STATS_TYPE_INFO;
|
1999-12-01 19:40:37 +00:00
|
|
|
static const struct ng_parse_type ng_xxx_stat_type = {
|
|
|
|
&ng_parse_struct_type,
|
2002-05-31 23:48:03 +00:00
|
|
|
&ng_xxx_stat_type_fields
|
1999-12-01 19:40:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* List of commands and how to convert arguments to/from ASCII */
|
|
|
|
static const struct ng_cmdlist ng_xxx_cmdlist[] = {
|
|
|
|
{
|
|
|
|
NGM_XXX_COOKIE,
|
|
|
|
NGM_XXX_GET_STATUS,
|
|
|
|
"getstatus",
|
|
|
|
NULL,
|
|
|
|
&ng_xxx_stat_type,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_XXX_COOKIE,
|
|
|
|
NGM_XXX_SET_FLAG,
|
|
|
|
"setflag",
|
|
|
|
&ng_parse_int32_type,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/* Netgraph node type descriptor */
|
|
|
|
static struct ng_type typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_XXX_NODE_TYPE,
|
|
|
|
.constructor = ng_xxx_constructor,
|
|
|
|
.rcvmsg = ng_xxx_rcvmsg,
|
|
|
|
.shutdown = ng_xxx_shutdown,
|
|
|
|
.newhook = ng_xxx_newhook,
|
|
|
|
/* .findhook = ng_xxx_findhook, */
|
|
|
|
.connect = ng_xxx_connect,
|
|
|
|
.rcvdata = ng_xxx_rcvdata,
|
|
|
|
.disconnect = ng_xxx_disconnect,
|
|
|
|
.cmdlist = ng_xxx_cmdlist,
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
NETGRAPH_INIT(xxx, &typestruct);
|
|
|
|
|
|
|
|
/* Information we store for each hook on each node */
|
|
|
|
struct XXX_hookinfo {
|
2005-02-06 19:24:59 +00:00
|
|
|
int dlci; /* The DLCI it represents, -1 == downstream */
|
|
|
|
int channel; /* The channel representing this DLCI */
|
|
|
|
hook_p hook;
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Information we store for each node */
|
|
|
|
struct XXX {
|
|
|
|
struct XXX_hookinfo channel[XXX_NUM_DLCIS];
|
|
|
|
struct XXX_hookinfo downstream_hook;
|
|
|
|
node_p node; /* back pointer to node */
|
|
|
|
hook_p debughook;
|
|
|
|
u_int packets_in; /* packets in from downstream */
|
|
|
|
u_int packets_out; /* packets out towards downstream */
|
|
|
|
u_int32_t flags;
|
|
|
|
};
|
|
|
|
typedef struct XXX *xxx_p;
|
|
|
|
|
|
|
|
/*
|
2001-01-06 00:46:47 +00:00
|
|
|
* Allocate the private data structure. The generic node has already
|
|
|
|
* been created. Link them together. We arrive with a reference to the node
|
|
|
|
* i.e. the reference count is incremented for us already.
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
|
|
|
* If this were a device node than this work would be done in the attach()
|
|
|
|
* routine and the constructor would return EINVAL as you should not be able
|
|
|
|
* to creatednodes that depend on hardware (unless you can add the hardware :)
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-08 05:34:06 +00:00
|
|
|
ng_xxx_constructor(node_p node)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
|
|
|
xxx_p privdata;
|
2001-02-25 05:36:25 +00:00
|
|
|
int i;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/* Initialize private descriptor */
|
2011-04-18 09:12:27 +00:00
|
|
|
privdata = malloc(sizeof(*privdata), M_NETGRAPH, M_WAITOK | M_ZERO);
|
1999-10-21 09:06:11 +00:00
|
|
|
for (i = 0; i < XXX_NUM_DLCIS; i++) {
|
|
|
|
privdata->channel[i].dlci = -2;
|
|
|
|
privdata->channel[i].channel = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link structs together; this counts as our one reference to *nodep */
|
2001-02-25 05:36:25 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, privdata);
|
2001-01-08 05:34:06 +00:00
|
|
|
privdata->node = node;
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give our ok for a hook to be added...
|
|
|
|
* If we are not running this might kick a device into life.
|
|
|
|
* Possibly decode information out of the hook name.
|
|
|
|
* Add the hook's private info to the hook structure.
|
|
|
|
* (if we had some). In this example, we assume that there is a
|
|
|
|
* an array of structs, called 'channel' in the private info,
|
|
|
|
* one for each active channel. The private
|
|
|
|
* pointer of each hook points to the appropriate XXX_hookinfo struct
|
|
|
|
* so that the source of an input packet is easily identified.
|
|
|
|
* (a dlci is a frame relay channel)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_xxx_newhook(node_p node, hook_p hook, const char *name)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const xxx_p xxxp = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
const char *cp;
|
|
|
|
int dlci = 0;
|
|
|
|
int chan;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Possibly start up the device if it's not already going */
|
|
|
|
if ((xxxp->flags & SCF_RUNNING) == 0) {
|
|
|
|
ng_xxx_start_hardware(xxxp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Example of how one might use hooks with embedded numbers: All
|
|
|
|
* hooks start with 'dlci' and have a decimal trailing channel
|
|
|
|
* number up to 4 digits Use the leadin defined int he associated .h
|
|
|
|
* file. */
|
1999-11-02 23:18:01 +00:00
|
|
|
if (strncmp(name,
|
|
|
|
NG_XXX_HOOK_DLCI_LEADIN, strlen(NG_XXX_HOOK_DLCI_LEADIN)) == 0) {
|
1999-11-24 01:03:08 +00:00
|
|
|
char *eptr;
|
1999-11-02 23:18:01 +00:00
|
|
|
|
2004-12-23 18:39:13 +00:00
|
|
|
cp = name + strlen(NG_XXX_HOOK_DLCI_LEADIN);
|
1999-11-02 23:18:01 +00:00
|
|
|
if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0'))
|
1999-10-21 09:06:11 +00:00
|
|
|
return (EINVAL);
|
1999-11-02 23:18:01 +00:00
|
|
|
dlci = (int)strtoul(cp, &eptr, 10);
|
|
|
|
if (*eptr != '\0' || dlci < 0 || dlci > 1023)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/* We have a dlci, now either find it, or allocate it */
|
|
|
|
for (chan = 0; chan < XXX_NUM_DLCIS; chan++)
|
|
|
|
if (xxxp->channel[chan].dlci == dlci)
|
|
|
|
break;
|
|
|
|
if (chan == XXX_NUM_DLCIS) {
|
|
|
|
for (chan = 0; chan < XXX_NUM_DLCIS; chan++)
|
2004-12-23 22:03:32 +00:00
|
|
|
if (xxxp->channel[chan].dlci == -2)
|
|
|
|
break;
|
1999-10-21 09:06:11 +00:00
|
|
|
if (chan == XXX_NUM_DLCIS)
|
|
|
|
return (ENOBUFS);
|
2004-12-23 22:03:32 +00:00
|
|
|
xxxp->channel[chan].dlci = dlci;
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
if (xxxp->channel[chan].hook != NULL)
|
|
|
|
return (EADDRINUSE);
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_SET_PRIVATE(hook, xxxp->channel + chan);
|
1999-10-21 09:06:11 +00:00
|
|
|
xxxp->channel[chan].hook = hook;
|
|
|
|
return (0);
|
|
|
|
} else if (strcmp(name, NG_XXX_HOOK_DOWNSTREAM) == 0) {
|
|
|
|
/* Example of simple predefined hooks. */
|
|
|
|
/* do something specific to the downstream connection */
|
|
|
|
xxxp->downstream_hook.hook = hook;
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_SET_PRIVATE(hook, &xxxp->downstream_hook);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else if (strcmp(name, NG_XXX_HOOK_DEBUG) == 0) {
|
|
|
|
/* do something specific to a debug connection */
|
|
|
|
xxxp->debughook = hook;
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_SET_PRIVATE(hook, NULL);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else
|
|
|
|
return (EINVAL); /* not a hook we know about */
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a netgraph control message.
|
2016-04-29 21:25:05 +00:00
|
|
|
* We actually receive a queue item that has a pointer to the message.
|
2001-01-06 00:46:47 +00:00
|
|
|
* If we free the item, the message will be freed too, unless we remove
|
|
|
|
* it from the item using NGI_GET_MSG();
|
|
|
|
* The return address is also stored in the item, as an ng_ID_t,
|
|
|
|
* accessible as NGI_RETADDR(item);
|
1999-10-21 09:06:11 +00:00
|
|
|
* Check it is one we understand. If needed, send a response.
|
|
|
|
* We could save the address for an async action later, but don't here.
|
|
|
|
* Always free the message.
|
|
|
|
* The response should be in a malloc'd region that the caller can 'free'.
|
|
|
|
* A response is not required.
|
|
|
|
* Theoretically you could respond defferently to old message types if
|
|
|
|
* the cookie in the header didn't match what we consider to be current
|
|
|
|
* (so that old userland programs could continue to work).
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_xxx_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const xxx_p xxxp = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
struct ng_mesg *resp = NULL;
|
|
|
|
int error = 0;
|
2001-01-06 00:46:47 +00:00
|
|
|
struct ng_mesg *msg;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_GET_MSG(item, msg);
|
1999-10-21 09:06:11 +00:00
|
|
|
/* Deal with message according to cookie and command */
|
|
|
|
switch (msg->header.typecookie) {
|
2005-02-06 19:24:59 +00:00
|
|
|
case NGM_XXX_COOKIE:
|
1999-10-21 09:06:11 +00:00
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_XXX_GET_STATUS:
|
|
|
|
{
|
|
|
|
struct ngxxxstat *stats;
|
|
|
|
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
|
|
|
|
if (!resp) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stats = (struct ngxxxstat *) resp->data;
|
|
|
|
stats->packets_in = xxxp->packets_in;
|
|
|
|
stats->packets_out = xxxp->packets_out;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_XXX_SET_FLAG:
|
|
|
|
if (msg->header.arglen != sizeof(u_int32_t)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xxxp->flags = *((u_int32_t *) msg->data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL; /* unknown command */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL; /* unknown cookie type */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Take care of synchronous response, if any */
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
1999-10-21 09:06:11 +00:00
|
|
|
/* Free the message and return */
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_MSG(msg);
|
1999-10-21 09:06:11 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive data, and do something with it.
|
2001-01-06 00:46:47 +00:00
|
|
|
* Actually we receive a queue item which holds the data.
|
2004-06-26 22:24:16 +00:00
|
|
|
* If we free the item it will also free the data unless we have
|
|
|
|
* previously disassociated it using the NGI_GET_M() macro.
|
1999-10-21 09:06:11 +00:00
|
|
|
* Possibly send it out on another link after processing.
|
|
|
|
* Possibly do something different if it comes from different
|
2004-06-26 22:24:16 +00:00
|
|
|
* hooks. The caller will never free m, so if we use up this data or
|
|
|
|
* abort we must free it.
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
|
|
|
* If we want, we may decide to force this data to be queued and reprocessed
|
2000-12-12 18:52:14 +00:00
|
|
|
* at the netgraph NETISR time.
|
|
|
|
* We would do that by setting the HK_QUEUE flag on our hook. We would do that
|
2005-02-06 19:24:59 +00:00
|
|
|
* in the connect() method.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_xxx_rcvdata(hook_p hook, item_p item )
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const xxx_p xxxp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
1999-10-21 09:06:11 +00:00
|
|
|
int chan = -2;
|
|
|
|
int dlci = -2;
|
|
|
|
int error;
|
2001-01-06 00:46:47 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
NGI_GET_M(item, m);
|
2001-01-08 05:34:06 +00:00
|
|
|
if (NG_HOOK_PRIVATE(hook)) {
|
|
|
|
dlci = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->dlci;
|
|
|
|
chan = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->channel;
|
1999-10-21 09:06:11 +00:00
|
|
|
if (dlci != -1) {
|
|
|
|
/* If received on a DLCI hook process for this
|
|
|
|
* channel and pass it to the downstream module.
|
|
|
|
* Normally one would add a multiplexing header at
|
|
|
|
* the front here */
|
|
|
|
/* M_PREPEND(....) ; */
|
|
|
|
/* mtod(m, xxxxxx)->dlci = dlci; */
|
2005-02-06 19:24:59 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item,
|
2001-01-06 00:46:47 +00:00
|
|
|
xxxp->downstream_hook.hook, m);
|
1999-10-21 09:06:11 +00:00
|
|
|
xxxp->packets_out++;
|
|
|
|
} else {
|
|
|
|
/* data came from the multiplexed link */
|
|
|
|
dlci = 1; /* get dlci from header */
|
|
|
|
/* madjust(....) *//* chop off header */
|
|
|
|
for (chan = 0; chan < XXX_NUM_DLCIS; chan++)
|
|
|
|
if (xxxp->channel[chan].dlci == dlci)
|
|
|
|
break;
|
|
|
|
if (chan == XXX_NUM_DLCIS) {
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
NG_FREE_M(m);
|
1999-10-21 09:06:11 +00:00
|
|
|
return (ENETUNREACH);
|
|
|
|
}
|
|
|
|
/* If we were called at splnet, use the following:
|
2004-06-26 22:24:16 +00:00
|
|
|
* NG_SEND_DATA_ONLY(error, otherhook, m); if this
|
1999-10-21 09:06:11 +00:00
|
|
|
* node is running at some SPL other than SPLNET
|
|
|
|
* then you should use instead: error =
|
2004-06-26 22:24:16 +00:00
|
|
|
* ng_queueit(otherhook, m, NULL); m = NULL;
|
|
|
|
* This queues the data using the standard NETISR
|
|
|
|
* system and schedules the data to be picked
|
1999-10-21 09:06:11 +00:00
|
|
|
* up again once the system has moved to SPLNET and
|
2004-06-26 22:24:16 +00:00
|
|
|
* the processing of the data can continue. After
|
|
|
|
* these are run 'm' should be considered
|
1999-10-21 09:06:11 +00:00
|
|
|
* as invalid and NG_SEND_DATA actually zaps them. */
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item,
|
|
|
|
xxxp->channel[chan].hook, m);
|
1999-10-21 09:06:11 +00:00
|
|
|
xxxp->packets_in++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* It's the debug hook, throw it away.. */
|
2001-01-11 15:44:41 +00:00
|
|
|
if (hook == xxxp->downstream_hook.hook) {
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
NG_FREE_M(m);
|
2001-01-11 15:44:41 +00:00
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* If this were a device node, the data may have been received in response
|
|
|
|
* to some interrupt.
|
|
|
|
* in which case it would probably look as follows:
|
|
|
|
*/
|
|
|
|
devintr()
|
|
|
|
{
|
2000-12-12 18:52:14 +00:00
|
|
|
int error;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/* get packet from device and send on */
|
|
|
|
m = MGET(blah blah)
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2000-12-12 18:52:14 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, xxxp->upstream_hook.hook, m);
|
|
|
|
/* see note above in xxx_rcvdata() */
|
|
|
|
/* and ng_xxx_connect() */
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do local shutdown processing..
|
2001-01-06 00:46:47 +00:00
|
|
|
* All our links and the name have already been removed.
|
2016-04-29 21:25:05 +00:00
|
|
|
* If we are a persistent device, we might refuse to go away.
|
|
|
|
* In the case of a persistent node we signal the framework that we
|
2004-07-20 17:15:38 +00:00
|
|
|
* are still in business by clearing the NGF_INVALID bit. However
|
|
|
|
* If we find the NGF_REALLY_DIE bit set, this means that
|
2001-01-30 20:51:52 +00:00
|
|
|
* we REALLY need to die (e.g. hardware removed).
|
|
|
|
* This would have been set using the NG_NODE_REALLY_DIE(node)
|
|
|
|
* macro in some device dependent function (not shown here) before
|
|
|
|
* calling ng_rmnode_self().
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_xxx_shutdown(node_p node)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const xxx_p privdata = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-30 20:51:52 +00:00
|
|
|
#ifndef PERSISTANT_NODE
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
2004-07-29 08:05:02 +00:00
|
|
|
NG_NODE_UNREF(node);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(privdata, M_NETGRAPH);
|
1999-10-21 09:06:11 +00:00
|
|
|
#else
|
2004-07-20 17:15:38 +00:00
|
|
|
if (node->nd_flags & NGF_REALLY_DIE) {
|
2001-01-30 20:51:52 +00:00
|
|
|
/*
|
|
|
|
* WE came here because the widget card is being unloaded,
|
2016-04-29 21:25:05 +00:00
|
|
|
* so stop being persistent.
|
2001-01-30 20:51:52 +00:00
|
|
|
* Actually undo all the things we did on creation.
|
|
|
|
*/
|
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
|
|
|
NG_NODE_UNREF(privdata->node);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(privdata, M_NETGRAPH);
|
2005-02-06 19:24:59 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2004-07-20 17:15:38 +00:00
|
|
|
NG_NODE_REVIVE(node); /* tell ng_rmnode() we will persist */
|
1999-10-21 09:06:11 +00:00
|
|
|
#endif /* PERSISTANT_NODE */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called once we've already connected a new hook to the other node.
|
|
|
|
* It gives us a chance to balk at the last minute.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_xxx_connect(hook_p hook)
|
|
|
|
{
|
2000-12-12 18:52:14 +00:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* If we were a driver running at other than splnet then
|
|
|
|
* we should set the QUEUE bit on the edge so that we
|
|
|
|
* will deliver by queing.
|
|
|
|
*/
|
|
|
|
if /*it is the upstream hook */
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
|
2000-12-12 18:52:14 +00:00
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* If for some reason we want incoming date to be queued
|
|
|
|
* by the NETISR system and delivered later we can set the same bit on
|
|
|
|
* OUR hook. (maybe to allow unwinding of the stack)
|
|
|
|
*/
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
if (NG_HOOK_PRIVATE(hook)) {
|
2000-12-12 18:52:14 +00:00
|
|
|
int dlci;
|
2005-02-06 19:24:59 +00:00
|
|
|
/*
|
2000-12-12 18:52:14 +00:00
|
|
|
* If it's dlci 1023, requeue it so that it's handled
|
|
|
|
* at a lower priority. This is how a node decides to
|
|
|
|
* defer a data message.
|
|
|
|
*/
|
2001-01-08 05:34:06 +00:00
|
|
|
dlci = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->dlci;
|
2000-12-12 18:52:14 +00:00
|
|
|
if (dlci == 1023) {
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_FORCE_QUEUE(hook);
|
2000-12-12 18:52:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* otherwise be really amiable and just say "YUP that's OK by me! " */
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-25 05:36:25 +00:00
|
|
|
* Hook disconnection
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
|
|
|
* For this type, removal of the last link destroys the node
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_xxx_disconnect(hook_p hook)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
if (NG_HOOK_PRIVATE(hook))
|
|
|
|
((struct XXX_hookinfo *) (NG_HOOK_PRIVATE(hook)))->hook = NULL;
|
|
|
|
if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
|
|
|
|
&& (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) /* already shutting down? */
|
|
|
|
ng_rmnode_self(NG_HOOK_NODE(hook));
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|