1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* netgraph.h
|
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: netgraph.h,v 1.29 1999/11/01 07:56:13 julian Exp $
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETGRAPH_NETGRAPH_H_
|
2003-11-11 12:30:37 +00:00
|
|
|
#define _NETGRAPH_NETGRAPH_H_
|
1999-10-21 09:06:11 +00:00
|
|
|
|
1999-12-29 04:46:21 +00:00
|
|
|
#ifndef _KERNEL
|
1999-10-21 09:06:11 +00:00
|
|
|
#error "This file should not be included in user level programs"
|
|
|
|
#endif
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
#include <sys/queue.h>
|
2001-03-28 09:17:56 +00:00
|
|
|
#include <sys/lock.h>
|
2001-01-08 05:34:06 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
2001-01-06 00:46:47 +00:00
|
|
|
#include <sys/mutex.h>
|
2011-07-04 07:03:44 +00:00
|
|
|
#include <sys/refcount.h>
|
2005-05-16 08:25:55 +00:00
|
|
|
|
2008-06-24 18:49:49 +00:00
|
|
|
#ifdef HAVE_KERNEL_OPTION_HEADERS
|
2005-05-16 08:25:55 +00:00
|
|
|
#include "opt_netgraph.h"
|
2011-10-27 09:43:25 +00:00
|
|
|
#include "opt_kdb.h"
|
2008-06-24 18:49:49 +00:00
|
|
|
#endif
|
2005-05-16 08:25:55 +00:00
|
|
|
|
2001-01-10 07:13:58 +00:00
|
|
|
/* debugging options */
|
|
|
|
#define NG_SEPARATE_MALLOC /* make modules use their own malloc types */
|
2001-01-06 00:46:47 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2001-01-08 05:34:06 +00:00
|
|
|
* This defines the in-kernel binary interface version.
|
|
|
|
* It is possible to change this but leave the external message
|
|
|
|
* API the same. Each type also has it's own cookies for versioning as well.
|
|
|
|
* Change it for NETGRAPH_DEBUG version so we cannot mix debug and non debug
|
|
|
|
* modules.
|
|
|
|
*/
|
2008-04-15 21:15:32 +00:00
|
|
|
#define _NG_ABI_VERSION 12
|
2001-01-08 05:34:06 +00:00
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
#define NG_ABI_VERSION (_NG_ABI_VERSION + 0x10000)
|
|
|
|
#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
#define NG_ABI_VERSION _NG_ABI_VERSION
|
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward references for the basic structures so we can
|
|
|
|
* define the typedefs and use them in the structures themselves.
|
|
|
|
*/
|
|
|
|
struct ng_hook ;
|
|
|
|
struct ng_node ;
|
|
|
|
struct ng_item ;
|
|
|
|
typedef struct ng_item *item_p;
|
|
|
|
typedef struct ng_node *node_p;
|
|
|
|
typedef struct ng_hook *hook_p;
|
|
|
|
|
2001-01-31 20:46:00 +00:00
|
|
|
/* node method definitions */
|
|
|
|
typedef int ng_constructor_t(node_p node);
|
2004-05-29 07:21:46 +00:00
|
|
|
typedef int ng_close_t(node_p node);
|
2001-01-31 20:46:00 +00:00
|
|
|
typedef int ng_shutdown_t(node_p node);
|
|
|
|
typedef int ng_newhook_t(node_p node, hook_p hook, const char *name);
|
|
|
|
typedef hook_p ng_findhook_t(node_p node, const char *name);
|
|
|
|
typedef int ng_connect_t(hook_p hook);
|
|
|
|
typedef int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook);
|
|
|
|
typedef int ng_rcvdata_t(hook_p hook, item_p item);
|
|
|
|
typedef int ng_disconnect_t(hook_p hook);
|
|
|
|
typedef int ng_rcvitem (node_p node, hook_p hook, item_p item);
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
/***********************************************************************
|
|
|
|
***************** Hook Structure and Methods **************************
|
|
|
|
***********************************************************************
|
|
|
|
*
|
1999-10-21 09:06:11 +00:00
|
|
|
* Structure of a hook
|
|
|
|
*/
|
|
|
|
struct ng_hook {
|
2004-01-26 12:24:07 +00:00
|
|
|
char hk_name[NG_HOOKSIZ]; /* what this node knows this link as */
|
2001-01-08 05:34:06 +00:00
|
|
|
void *hk_private; /* node dependant ID for this hook */
|
|
|
|
int hk_flags; /* info about this hook/link */
|
2005-07-21 12:31:42 +00:00
|
|
|
int hk_type; /* tbd: hook data link type */
|
2001-01-08 05:34:06 +00:00
|
|
|
struct ng_hook *hk_peer; /* the other end of this link */
|
|
|
|
struct ng_node *hk_node; /* The node this hook is attached to */
|
|
|
|
LIST_ENTRY(ng_hook) hk_hooks; /* linked list of all hooks on node */
|
2001-01-31 20:46:00 +00:00
|
|
|
ng_rcvmsg_t *hk_rcvmsg; /* control messages come here */
|
|
|
|
ng_rcvdata_t *hk_rcvdata; /* data comes here */
|
2008-04-15 21:15:32 +00:00
|
|
|
int hk_refs; /* dont actually free this till 0 */
|
2001-01-08 05:34:06 +00:00
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
#define HK_MAGIC 0x78573011
|
|
|
|
int hk_magic;
|
|
|
|
char *lastfile;
|
|
|
|
int lastline;
|
|
|
|
SLIST_ENTRY(ng_hook) hk_all; /* all existing items */
|
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
/* Flags for a hook */
|
|
|
|
#define HK_INVALID 0x0001 /* don't trust it! */
|
2000-12-12 18:52:14 +00:00
|
|
|
#define HK_QUEUE 0x0002 /* queue for later delivery */
|
2001-01-06 00:46:47 +00:00
|
|
|
#define HK_FORCE_WRITER 0x0004 /* Incoming data queued as a writer */
|
2001-01-11 19:27:54 +00:00
|
|
|
#define HK_DEAD 0x0008 /* This is the dead hook.. don't free */
|
2008-01-31 08:51:48 +00:00
|
|
|
#define HK_HI_STACK 0x0010 /* Hook has hi stack usage */
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
#define HK_TO_INBOUND 0x0020 /* Hook on ntw. stack inbound path. */
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/*
|
2001-01-08 05:34:06 +00:00
|
|
|
* Public Methods for hook
|
|
|
|
* If you can't do it with these you probably shouldn;t be doing it.
|
|
|
|
*/
|
|
|
|
void ng_unref_hook(hook_p hook); /* don't move this */
|
2011-07-04 07:03:44 +00:00
|
|
|
#define _NG_HOOK_REF(hook) refcount_acquire(&(hook)->hk_refs)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_HOOK_NAME(hook) ((hook)->hk_name)
|
|
|
|
#define _NG_HOOK_UNREF(hook) ng_unref_hook(hook)
|
|
|
|
#define _NG_HOOK_SET_PRIVATE(hook, val) do {(hook)->hk_private = val;} while (0)
|
2001-01-31 20:46:00 +00:00
|
|
|
#define _NG_HOOK_SET_RCVMSG(hook, val) do {(hook)->hk_rcvmsg = val;} while (0)
|
|
|
|
#define _NG_HOOK_SET_RCVDATA(hook, val) do {(hook)->hk_rcvdata = val;} while (0)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_HOOK_PRIVATE(hook) ((hook)->hk_private)
|
|
|
|
#define _NG_HOOK_NOT_VALID(hook) ((hook)->hk_flags & HK_INVALID)
|
2001-03-03 05:50:47 +00:00
|
|
|
#define _NG_HOOK_IS_VALID(hook) (!((hook)->hk_flags & HK_INVALID))
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_HOOK_NODE(hook) ((hook)->hk_node) /* only rvalue! */
|
|
|
|
#define _NG_HOOK_PEER(hook) ((hook)->hk_peer) /* only rvalue! */
|
|
|
|
#define _NG_HOOK_FORCE_WRITER(hook) \
|
|
|
|
do { hook->hk_flags |= HK_FORCE_WRITER; } while (0)
|
|
|
|
#define _NG_HOOK_FORCE_QUEUE(hook) do { hook->hk_flags |= HK_QUEUE; } while (0)
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
#define _NG_HOOK_SET_TO_INBOUND(hook) \
|
|
|
|
do { hook->hk_flags |= HK_TO_INBOUND; } while (0)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define _NG_HOOK_HI_STACK(hook) do { hook->hk_flags |= HK_HI_STACK; } while (0)
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
/* Some shortcuts */
|
|
|
|
#define NG_PEER_NODE(hook) NG_HOOK_NODE(NG_HOOK_PEER(hook))
|
|
|
|
#define NG_PEER_HOOK_NAME(hook) NG_HOOK_NAME(NG_HOOK_PEER(hook))
|
|
|
|
#define NG_PEER_NODE_NAME(hook) NG_NODE_NAME(NG_PEER_NODE(hook))
|
|
|
|
|
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
#define _NN_ __FILE__,__LINE__
|
|
|
|
void dumphook (hook_p hook, char *file, int line);
|
|
|
|
static __inline void _chkhook(hook_p hook, char *file, int line);
|
|
|
|
static __inline void _ng_hook_ref(hook_p hook, char * file, int line);
|
|
|
|
static __inline char * _ng_hook_name(hook_p hook, char * file, int line);
|
|
|
|
static __inline void _ng_hook_unref(hook_p hook, char * file, int line);
|
|
|
|
static __inline void _ng_hook_set_private(hook_p hook,
|
2001-01-31 20:46:00 +00:00
|
|
|
void * val, char * file, int line);
|
|
|
|
static __inline void _ng_hook_set_rcvmsg(hook_p hook,
|
|
|
|
ng_rcvmsg_t *val, char * file, int line);
|
|
|
|
static __inline void _ng_hook_set_rcvdata(hook_p hook,
|
|
|
|
ng_rcvdata_t *val, char * file, int line);
|
2001-01-08 05:34:06 +00:00
|
|
|
static __inline void * _ng_hook_private(hook_p hook, char * file, int line);
|
|
|
|
static __inline int _ng_hook_not_valid(hook_p hook, char * file, int line);
|
|
|
|
static __inline int _ng_hook_is_valid(hook_p hook, char * file, int line);
|
|
|
|
static __inline node_p _ng_hook_node(hook_p hook, char * file, int line);
|
|
|
|
static __inline hook_p _ng_hook_peer(hook_p hook, char * file, int line);
|
|
|
|
static __inline void _ng_hook_force_writer(hook_p hook, char * file,
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
int line);
|
|
|
|
static __inline void _ng_hook_force_queue(hook_p hook, char * file,
|
|
|
|
int line);
|
|
|
|
static __inline void _ng_hook_set_to_inbound(hook_p hook, char * file,
|
|
|
|
int line);
|
2001-01-08 05:34:06 +00:00
|
|
|
|
2005-08-08 20:08:44 +00:00
|
|
|
static __inline void
|
2001-01-08 05:34:06 +00:00
|
|
|
_chkhook(hook_p hook, char *file, int line)
|
|
|
|
{
|
|
|
|
if (hook->hk_magic != HK_MAGIC) {
|
2011-10-27 09:43:25 +00:00
|
|
|
printf("Accessing freed ");
|
2001-01-08 05:34:06 +00:00
|
|
|
dumphook(hook, file, line);
|
|
|
|
}
|
|
|
|
hook->lastline = line;
|
|
|
|
hook->lastfile = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_ref(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_REF(hook);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline char *
|
|
|
|
_ng_hook_name(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_NAME(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_unref(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_UNREF(hook);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_set_private(hook_p hook, void *val, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_SET_PRIVATE(hook, val);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
2001-01-31 20:46:00 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_hook_set_rcvmsg(hook_p hook, ng_rcvmsg_t *val, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_SET_RCVMSG(hook, val);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-31 20:46:00 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_set_rcvdata(hook_p hook, ng_rcvdata_t *val, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_SET_RCVDATA(hook, val);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-31 20:46:00 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
static __inline void *
|
|
|
|
_ng_hook_private(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_PRIVATE(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline int
|
|
|
|
_ng_hook_not_valid(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_NOT_VALID(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline int
|
|
|
|
_ng_hook_is_valid(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_IS_VALID(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline node_p
|
|
|
|
_ng_hook_node(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_NODE(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline hook_p
|
|
|
|
_ng_hook_peer(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
return (_NG_HOOK_PEER(hook));
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_force_writer(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_FORCE_WRITER(hook);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_hook_force_queue(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_FORCE_QUEUE(hook);
|
2005-11-15 10:54:20 +00:00
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_hook_set_to_inbound(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_SET_TO_INBOUND(hook);
|
|
|
|
}
|
|
|
|
|
2008-01-31 08:51:48 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_hook_hi_stack(hook_p hook, char * file, int line)
|
|
|
|
{
|
|
|
|
_chkhook(hook, file, line);
|
|
|
|
_NG_HOOK_HI_STACK(hook);
|
|
|
|
}
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
#define NG_HOOK_REF(hook) _ng_hook_ref(hook, _NN_)
|
|
|
|
#define NG_HOOK_NAME(hook) _ng_hook_name(hook, _NN_)
|
|
|
|
#define NG_HOOK_UNREF(hook) _ng_hook_unref(hook, _NN_)
|
|
|
|
#define NG_HOOK_SET_PRIVATE(hook, val) _ng_hook_set_private(hook, val, _NN_)
|
2001-01-31 20:46:00 +00:00
|
|
|
#define NG_HOOK_SET_RCVMSG(hook, val) _ng_hook_set_rcvmsg(hook, val, _NN_)
|
|
|
|
#define NG_HOOK_SET_RCVDATA(hook, val) _ng_hook_set_rcvdata(hook, val, _NN_)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_HOOK_PRIVATE(hook) _ng_hook_private(hook, _NN_)
|
|
|
|
#define NG_HOOK_NOT_VALID(hook) _ng_hook_not_valid(hook, _NN_)
|
|
|
|
#define NG_HOOK_IS_VALID(hook) _ng_hook_is_valid(hook, _NN_)
|
|
|
|
#define NG_HOOK_NODE(hook) _ng_hook_node(hook, _NN_)
|
|
|
|
#define NG_HOOK_PEER(hook) _ng_hook_peer(hook, _NN_)
|
|
|
|
#define NG_HOOK_FORCE_WRITER(hook) _ng_hook_force_writer(hook, _NN_)
|
|
|
|
#define NG_HOOK_FORCE_QUEUE(hook) _ng_hook_force_queue(hook, _NN_)
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
#define NG_HOOK_SET_TO_INBOUND(hook) _ng_hook_set_to_inbound(hook, _NN_)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define NG_HOOK_HI_STACK(hook) _ng_hook_hi_stack(hook, _NN_)
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
|
|
|
|
#define NG_HOOK_REF(hook) _NG_HOOK_REF(hook)
|
|
|
|
#define NG_HOOK_NAME(hook) _NG_HOOK_NAME(hook)
|
|
|
|
#define NG_HOOK_UNREF(hook) _NG_HOOK_UNREF(hook)
|
|
|
|
#define NG_HOOK_SET_PRIVATE(hook, val) _NG_HOOK_SET_PRIVATE(hook, val)
|
2001-01-31 20:46:00 +00:00
|
|
|
#define NG_HOOK_SET_RCVMSG(hook, val) _NG_HOOK_SET_RCVMSG(hook, val)
|
|
|
|
#define NG_HOOK_SET_RCVDATA(hook, val) _NG_HOOK_SET_RCVDATA(hook, val)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_HOOK_PRIVATE(hook) _NG_HOOK_PRIVATE(hook)
|
|
|
|
#define NG_HOOK_NOT_VALID(hook) _NG_HOOK_NOT_VALID(hook)
|
|
|
|
#define NG_HOOK_IS_VALID(hook) _NG_HOOK_IS_VALID(hook)
|
|
|
|
#define NG_HOOK_NODE(hook) _NG_HOOK_NODE(hook)
|
|
|
|
#define NG_HOOK_PEER(hook) _NG_HOOK_PEER(hook)
|
|
|
|
#define NG_HOOK_FORCE_WRITER(hook) _NG_HOOK_FORCE_WRITER(hook)
|
|
|
|
#define NG_HOOK_FORCE_QUEUE(hook) _NG_HOOK_FORCE_QUEUE(hook)
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
#define NG_HOOK_SET_TO_INBOUND(hook) _NG_HOOK_SET_TO_INBOUND(hook)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define NG_HOOK_HI_STACK(hook) _NG_HOOK_HI_STACK(hook)
|
2001-01-08 05:34:06 +00:00
|
|
|
|
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
***************** Node Structure and Methods **************************
|
|
|
|
***********************************************************************
|
1999-10-21 09:06:11 +00:00
|
|
|
* Structure of a node
|
2001-01-08 05:34:06 +00:00
|
|
|
* including the eembedded queue structure.
|
|
|
|
*
|
2005-11-15 10:54:20 +00:00
|
|
|
* The structure for queueing Netgraph request items
|
2001-01-08 05:34:06 +00:00
|
|
|
* embedded in the node structure
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2001-01-08 05:34:06 +00:00
|
|
|
struct ng_queue {
|
2008-04-15 21:15:32 +00:00
|
|
|
u_int q_flags; /* Current r/w/q lock flags */
|
|
|
|
u_int q_flags2; /* Other queue flags */
|
2005-11-15 10:54:20 +00:00
|
|
|
struct mtx q_mtx;
|
2008-04-15 21:15:32 +00:00
|
|
|
STAILQ_ENTRY(ng_node) q_work; /* nodes with work to do */
|
|
|
|
STAILQ_HEAD(, ng_item) queue; /* actually items queue */
|
2001-01-08 05:34:06 +00:00
|
|
|
};
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
struct ng_node {
|
2004-01-26 12:24:07 +00:00
|
|
|
char nd_name[NG_NODESIZ]; /* optional globally unique name */
|
2001-01-08 05:34:06 +00:00
|
|
|
struct ng_type *nd_type; /* the installed 'type' */
|
|
|
|
int nd_flags; /* see below for bit definitions */
|
|
|
|
int nd_numhooks; /* number of hooks */
|
|
|
|
void *nd_private; /* node type dependant node ID */
|
|
|
|
ng_ID_t nd_ID; /* Unique per node */
|
|
|
|
LIST_HEAD(hooks, ng_hook) nd_hooks; /* linked list of node hooks */
|
Refactor the name hash and the ID hash, that are used to address nodes:
- Make hash sizes growable, to satisfy users running large mpd
installations, having thousands of nodes.
- NG_NAMEHASH() proved to give a very bad distribution in real life
name sets, while generic hash32_str(name, HASHINIT) proved to give
an even one, so you the latter for name hash.
- Do not store unnamed nodes in slot 0 of name hash, no reason for that.
- Use the ID hash in cases when we need to run through all nodes: the
NGM_LISTNODES command and in the vnet_netgraph_uninit().
- Implement NGM_LISTNODES and NGM_LISTNAMES as separate code, the former
iterates through the ID hash, and the latter through the name hash.
- Keep count of all nodes and of named nodes, so that we don't need
to count nodes in NGM_LISTNODES and NGM_LISTNAMES. The counters are
also used to estimate whether we need to grow hashes.
- Close a race between two threads running ng_name_node() assigning same
name to different nodes.
2012-02-16 19:10:01 +00:00
|
|
|
LIST_ENTRY(ng_node) nd_nodes; /* name hash collision list */
|
2001-01-08 05:34:06 +00:00
|
|
|
LIST_ENTRY(ng_node) nd_idnodes; /* ID hash collision list */
|
|
|
|
struct ng_queue nd_input_queue; /* input queue for locking */
|
2008-04-15 21:15:32 +00:00
|
|
|
int nd_refs; /* # of references to this node */
|
Change the curvnet variable from a global const struct vnet *,
previously always pointing to the default vnet context, to a
dynamically changing thread-local one. The currvnet context
should be set on entry to networking code via CURVNET_SET() macros,
and reverted to previous state via CURVNET_RESTORE(). Recursions
on curvnet are permitted, though strongly discuouraged.
This change should have no functional impact on nooptions VIMAGE
kernel builds, where CURVNET_* macros expand to whitespace.
The curthread->td_vnet (aka curvnet) variable's purpose is to be an
indicator of the vnet context in which the current network-related
operation takes place, in case we cannot deduce the current vnet
context from any other source, such as by looking at mbuf's
m->m_pkthdr.rcvif->if_vnet, sockets's so->so_vnet etc. Moreover, so
far curvnet has turned out to be an invaluable consistency checking
aid: it helps to catch cases when sockets, ifnets or any other
vnet-aware structures may have leaked from one vnet to another.
The exact placement of the CURVNET_SET() / CURVNET_RESTORE() macros
was a result of an empirical iterative process, whith an aim to
reduce recursions on CURVNET_SET() to a minimum, while still reducing
the scope of CURVNET_SET() to networking only operations - the
alternative would be calling CURVNET_SET() on each system call entry.
In general, curvnet has to be set in three typicall cases: when
processing socket-related requests from userspace or from within the
kernel; when processing inbound traffic flowing from device drivers
to upper layers of the networking stack, and when executing
timer-driven networking functions.
This change also introduces a DDB subcommand to show the list of all
vnet instances.
Approved by: julian (mentor)
2009-05-05 10:56:12 +00:00
|
|
|
struct vnet *nd_vnet; /* network stack instance */
|
2001-01-08 05:34:06 +00:00
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
#define ND_MAGIC 0x59264837
|
|
|
|
int nd_magic;
|
|
|
|
char *lastfile;
|
|
|
|
int lastline;
|
|
|
|
SLIST_ENTRY(ng_node) nd_all; /* all existing nodes */
|
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Flags for a node */
|
2004-07-20 17:15:38 +00:00
|
|
|
#define NGF_INVALID 0x00000001 /* free when refs go to 0 */
|
|
|
|
#define NG_INVALID NGF_INVALID /* compat for old code */
|
|
|
|
#define NGF_FORCE_WRITER 0x00000004 /* Never multithread this node */
|
|
|
|
#define NG_FORCE_WRITER NGF_FORCE_WRITER /* compat for old code */
|
|
|
|
#define NGF_CLOSING 0x00000008 /* ng_rmnode() at work */
|
|
|
|
#define NG_CLOSING NGF_CLOSING /* compat for old code */
|
|
|
|
#define NGF_REALLY_DIE 0x00000010 /* "persistent" node is unloading */
|
|
|
|
#define NG_REALLY_DIE NGF_REALLY_DIE /* compat for old code */
|
2008-01-31 08:51:48 +00:00
|
|
|
#define NGF_HI_STACK 0x00000020 /* node has hi stack usage */
|
1999-10-21 09:06:11 +00:00
|
|
|
#define NGF_TYPE1 0x10000000 /* reserved for type specific storage */
|
|
|
|
#define NGF_TYPE2 0x20000000 /* reserved for type specific storage */
|
|
|
|
#define NGF_TYPE3 0x40000000 /* reserved for type specific storage */
|
|
|
|
#define NGF_TYPE4 0x80000000 /* reserved for type specific storage */
|
|
|
|
|
|
|
|
/*
|
2001-01-08 05:34:06 +00:00
|
|
|
* Public methods for nodes.
|
|
|
|
* If you can't do it with these you probably shouldn't be doing it.
|
|
|
|
*/
|
2011-07-04 07:03:44 +00:00
|
|
|
void ng_unref_node(node_p node); /* don't move this */
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_NODE_NAME(node) ((node)->nd_name + 0)
|
|
|
|
#define _NG_NODE_HAS_NAME(node) ((node)->nd_name[0] + 0)
|
|
|
|
#define _NG_NODE_ID(node) ((node)->nd_ID + 0)
|
2011-07-04 07:03:44 +00:00
|
|
|
#define _NG_NODE_REF(node) refcount_acquire(&(node)->nd_refs)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_NODE_UNREF(node) ng_unref_node(node)
|
|
|
|
#define _NG_NODE_SET_PRIVATE(node, val) do {(node)->nd_private = val;} while (0)
|
|
|
|
#define _NG_NODE_PRIVATE(node) ((node)->nd_private)
|
2004-07-20 17:15:38 +00:00
|
|
|
#define _NG_NODE_IS_VALID(node) (!((node)->nd_flags & NGF_INVALID))
|
|
|
|
#define _NG_NODE_NOT_VALID(node) ((node)->nd_flags & NGF_INVALID)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define _NG_NODE_NUMHOOKS(node) ((node)->nd_numhooks + 0) /* rvalue */
|
|
|
|
#define _NG_NODE_FORCE_WRITER(node) \
|
2004-07-20 17:15:38 +00:00
|
|
|
do{ node->nd_flags |= NGF_FORCE_WRITER; }while (0)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define _NG_NODE_HI_STACK(node) \
|
|
|
|
do{ node->nd_flags |= NGF_HI_STACK; }while (0)
|
2001-01-30 20:51:52 +00:00
|
|
|
#define _NG_NODE_REALLY_DIE(node) \
|
2004-07-20 17:15:38 +00:00
|
|
|
do{ node->nd_flags |= (NGF_REALLY_DIE|NGF_INVALID); }while (0)
|
|
|
|
#define _NG_NODE_REVIVE(node) \
|
|
|
|
do { node->nd_flags &= ~NGF_INVALID; } while (0)
|
2001-01-08 05:34:06 +00:00
|
|
|
/*
|
|
|
|
* The hook iterator.
|
|
|
|
* This macro will call a function of type ng_fn_eachhook for each
|
|
|
|
* hook attached to the node. If the function returns 0, then the
|
|
|
|
* iterator will stop and return a pointer to the hook that returned 0.
|
|
|
|
*/
|
|
|
|
typedef int ng_fn_eachhook(hook_p hook, void* arg);
|
|
|
|
#define _NG_NODE_FOREACH_HOOK(node, fn, arg, rethook) \
|
|
|
|
do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
hook_p _hook; \
|
|
|
|
(rethook) = NULL; \
|
|
|
|
LIST_FOREACH(_hook, &((node)->nd_hooks), hk_hooks) { \
|
|
|
|
if ((fn)(_hook, arg) == 0) { \
|
|
|
|
(rethook) = _hook; \
|
2001-01-08 05:34:06 +00:00
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
void dumpnode(node_p node, char *file, int line);
|
2005-08-08 20:08:44 +00:00
|
|
|
static __inline void _chknode(node_p node, char *file, int line);
|
2001-01-08 05:34:06 +00:00
|
|
|
static __inline char * _ng_node_name(node_p node, char *file, int line);
|
|
|
|
static __inline int _ng_node_has_name(node_p node, char *file, int line);
|
|
|
|
static __inline ng_ID_t _ng_node_id(node_p node, char *file, int line);
|
|
|
|
static __inline void _ng_node_ref(node_p node, char *file, int line);
|
2011-07-04 20:50:09 +00:00
|
|
|
static __inline void _ng_node_unref(node_p node, char *file, int line);
|
2001-01-08 05:34:06 +00:00
|
|
|
static __inline void _ng_node_set_private(node_p node, void * val,
|
|
|
|
char *file, int line);
|
|
|
|
static __inline void * _ng_node_private(node_p node, char *file, int line);
|
|
|
|
static __inline int _ng_node_is_valid(node_p node, char *file, int line);
|
|
|
|
static __inline int _ng_node_not_valid(node_p node, char *file, int line);
|
|
|
|
static __inline int _ng_node_numhooks(node_p node, char *file, int line);
|
|
|
|
static __inline void _ng_node_force_writer(node_p node, char *file, int line);
|
|
|
|
static __inline hook_p _ng_node_foreach_hook(node_p node,
|
|
|
|
ng_fn_eachhook *fn, void *arg, char *file, int line);
|
2004-07-20 17:15:38 +00:00
|
|
|
static __inline void _ng_node_revive(node_p node, char *file, int line);
|
2001-01-08 05:34:06 +00:00
|
|
|
|
2005-11-15 10:54:20 +00:00
|
|
|
static __inline void
|
2001-01-08 05:34:06 +00:00
|
|
|
_chknode(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
if (node->nd_magic != ND_MAGIC) {
|
2011-10-27 09:43:25 +00:00
|
|
|
printf("Accessing freed ");
|
2001-01-08 05:34:06 +00:00
|
|
|
dumpnode(node, file, line);
|
|
|
|
}
|
|
|
|
node->lastline = line;
|
|
|
|
node->lastfile = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline char *
|
|
|
|
_ng_node_name(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_NAME(node));
|
|
|
|
}
|
|
|
|
|
2005-11-15 10:54:20 +00:00
|
|
|
static __inline int
|
2001-01-08 05:34:06 +00:00
|
|
|
_ng_node_has_name(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_HAS_NAME(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline ng_ID_t
|
|
|
|
_ng_node_id(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_ID(node));
|
|
|
|
}
|
|
|
|
|
2005-11-15 10:54:20 +00:00
|
|
|
static __inline void
|
2001-01-08 05:34:06 +00:00
|
|
|
_ng_node_ref(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
2006-01-12 21:03:09 +00:00
|
|
|
_NG_NODE_REF(node);
|
2001-01-08 05:34:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 13:55:55 +00:00
|
|
|
static __inline void
|
2001-01-08 05:34:06 +00:00
|
|
|
_ng_node_unref(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
2011-07-04 13:55:55 +00:00
|
|
|
_NG_NODE_UNREF(node);
|
2001-01-08 05:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_node_set_private(node_p node, void * val, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_SET_PRIVATE(node, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void *
|
|
|
|
_ng_node_private(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return (_NG_NODE_PRIVATE(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
_ng_node_is_valid(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_IS_VALID(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
_ng_node_not_valid(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_NOT_VALID(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
_ng_node_numhooks(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
return(_NG_NODE_NUMHOOKS(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
_ng_node_force_writer(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_FORCE_WRITER(node);
|
|
|
|
}
|
|
|
|
|
2008-01-31 08:51:48 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_node_hi_stack(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_HI_STACK(node);
|
|
|
|
}
|
|
|
|
|
2001-01-30 20:51:52 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_node_really_die(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_REALLY_DIE(node);
|
|
|
|
}
|
|
|
|
|
2004-07-20 17:15:38 +00:00
|
|
|
static __inline void
|
|
|
|
_ng_node_revive(node_p node, char *file, int line)
|
|
|
|
{
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_REVIVE(node);
|
|
|
|
}
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
static __inline hook_p
|
|
|
|
_ng_node_foreach_hook(node_p node, ng_fn_eachhook *fn, void *arg,
|
|
|
|
char *file, int line)
|
|
|
|
{
|
|
|
|
hook_p hook;
|
|
|
|
_chknode(node, file, line);
|
|
|
|
_NG_NODE_FOREACH_HOOK(node, fn, arg, hook);
|
|
|
|
return (hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NG_NODE_NAME(node) _ng_node_name(node, _NN_)
|
|
|
|
#define NG_NODE_HAS_NAME(node) _ng_node_has_name(node, _NN_)
|
2001-01-11 04:13:46 +00:00
|
|
|
#define NG_NODE_ID(node) _ng_node_id(node, _NN_)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_NODE_REF(node) _ng_node_ref(node, _NN_)
|
|
|
|
#define NG_NODE_UNREF(node) _ng_node_unref(node, _NN_)
|
|
|
|
#define NG_NODE_SET_PRIVATE(node, val) _ng_node_set_private(node, val, _NN_)
|
|
|
|
#define NG_NODE_PRIVATE(node) _ng_node_private(node, _NN_)
|
|
|
|
#define NG_NODE_IS_VALID(node) _ng_node_is_valid(node, _NN_)
|
|
|
|
#define NG_NODE_NOT_VALID(node) _ng_node_not_valid(node, _NN_)
|
|
|
|
#define NG_NODE_FORCE_WRITER(node) _ng_node_force_writer(node, _NN_)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define NG_NODE_HI_STACK(node) _ng_node_hi_stack(node, _NN_)
|
2001-01-30 20:51:52 +00:00
|
|
|
#define NG_NODE_REALLY_DIE(node) _ng_node_really_die(node, _NN_)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_NODE_NUMHOOKS(node) _ng_node_numhooks(node, _NN_)
|
2004-07-20 17:15:38 +00:00
|
|
|
#define NG_NODE_REVIVE(node) _ng_node_revive(node, _NN_)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_NODE_FOREACH_HOOK(node, fn, arg, rethook) \
|
|
|
|
do { \
|
|
|
|
rethook = _ng_node_foreach_hook(node, fn, (void *)arg, _NN_); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
|
|
|
|
#define NG_NODE_NAME(node) _NG_NODE_NAME(node)
|
|
|
|
#define NG_NODE_HAS_NAME(node) _NG_NODE_HAS_NAME(node)
|
|
|
|
#define NG_NODE_ID(node) _NG_NODE_ID(node)
|
|
|
|
#define NG_NODE_REF(node) _NG_NODE_REF(node)
|
|
|
|
#define NG_NODE_UNREF(node) _NG_NODE_UNREF(node)
|
|
|
|
#define NG_NODE_SET_PRIVATE(node, val) _NG_NODE_SET_PRIVATE(node, val)
|
|
|
|
#define NG_NODE_PRIVATE(node) _NG_NODE_PRIVATE(node)
|
|
|
|
#define NG_NODE_IS_VALID(node) _NG_NODE_IS_VALID(node)
|
|
|
|
#define NG_NODE_NOT_VALID(node) _NG_NODE_NOT_VALID(node)
|
|
|
|
#define NG_NODE_FORCE_WRITER(node) _NG_NODE_FORCE_WRITER(node)
|
2008-01-31 08:51:48 +00:00
|
|
|
#define NG_NODE_HI_STACK(node) _NG_NODE_HI_STACK(node)
|
2001-01-30 20:51:52 +00:00
|
|
|
#define NG_NODE_REALLY_DIE(node) _NG_NODE_REALLY_DIE(node)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_NODE_NUMHOOKS(node) _NG_NODE_NUMHOOKS(node)
|
2004-07-20 17:15:38 +00:00
|
|
|
#define NG_NODE_REVIVE(node) _NG_NODE_REVIVE(node)
|
2001-01-08 05:34:06 +00:00
|
|
|
#define NG_NODE_FOREACH_HOOK(node, fn, arg, rethook) \
|
|
|
|
_NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)
|
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
************* Node Queue and Item Structures and Methods **************
|
|
|
|
***********************************************************************
|
|
|
|
*
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2001-01-30 20:51:52 +00:00
|
|
|
typedef void ng_item_fn(node_p node, hook_p hook, void *arg1, int arg2);
|
2007-10-19 15:04:17 +00:00
|
|
|
typedef int ng_item_fn2(node_p node, struct ng_item *item, hook_p hook);
|
2005-07-05 17:35:20 +00:00
|
|
|
typedef void ng_apply_t(void *context, int error);
|
2007-10-19 15:04:17 +00:00
|
|
|
struct ng_apply_info {
|
|
|
|
ng_apply_t *apply;
|
|
|
|
void *context;
|
|
|
|
int refs;
|
2008-03-11 21:58:48 +00:00
|
|
|
int error;
|
2007-10-19 15:04:17 +00:00
|
|
|
};
|
2001-01-06 00:46:47 +00:00
|
|
|
struct ng_item {
|
|
|
|
u_long el_flags;
|
2008-04-15 21:15:32 +00:00
|
|
|
STAILQ_ENTRY(ng_item) el_next;
|
2001-01-06 00:46:47 +00:00
|
|
|
node_p el_dest; /* The node it will be applied against (or NULL) */
|
|
|
|
hook_p el_hook; /* Entering hook. Optional in Control messages */
|
|
|
|
union {
|
2004-06-30 22:51:29 +00:00
|
|
|
struct mbuf *da_m;
|
2001-01-06 00:46:47 +00:00
|
|
|
struct {
|
|
|
|
struct ng_mesg *msg_msg;
|
|
|
|
ng_ID_t msg_retaddr;
|
|
|
|
} msg;
|
2001-01-14 23:25:54 +00:00
|
|
|
struct {
|
2007-10-19 15:04:17 +00:00
|
|
|
union {
|
|
|
|
ng_item_fn *fn_fn;
|
|
|
|
ng_item_fn2 *fn_fn2;
|
|
|
|
} fn_fn;
|
2001-01-14 23:25:54 +00:00
|
|
|
void *fn_arg1;
|
|
|
|
int fn_arg2;
|
|
|
|
} fn;
|
2001-01-06 00:46:47 +00:00
|
|
|
} body;
|
2005-07-05 17:35:20 +00:00
|
|
|
/*
|
|
|
|
* Optional callback called when item is being applied,
|
|
|
|
* and its context.
|
|
|
|
*/
|
2007-10-19 15:04:17 +00:00
|
|
|
struct ng_apply_info *apply;
|
2008-04-15 21:15:32 +00:00
|
|
|
u_int depth;
|
2001-01-08 05:34:06 +00:00
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
2001-01-06 00:46:47 +00:00
|
|
|
char *lastfile;
|
|
|
|
int lastline;
|
|
|
|
TAILQ_ENTRY(ng_item) all; /* all existing items */
|
2001-01-08 05:34:06 +00:00
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
2001-01-06 00:46:47 +00:00
|
|
|
};
|
2001-01-14 23:25:54 +00:00
|
|
|
|
|
|
|
#define NGQF_TYPE 0x03 /* MASK of content definition */
|
2001-01-06 00:46:47 +00:00
|
|
|
#define NGQF_MESG 0x00 /* the queue element is a message */
|
2001-01-14 23:25:54 +00:00
|
|
|
#define NGQF_DATA 0x01 /* the queue element is data */
|
|
|
|
#define NGQF_FN 0x02 /* the queue element is a function */
|
2007-10-19 15:04:17 +00:00
|
|
|
#define NGQF_FN2 0x03 /* the queue element is a new function */
|
2001-01-14 23:25:54 +00:00
|
|
|
|
2005-11-02 14:27:24 +00:00
|
|
|
#define NGQF_RW 0x04 /* MASK for wanted queue mode */
|
|
|
|
#define NGQF_READER 0x04 /* wants to be a reader */
|
|
|
|
#define NGQF_WRITER 0x00 /* wants to be a writer */
|
|
|
|
|
|
|
|
#define NGQF_QMODE 0x08 /* MASK for how it was queued */
|
|
|
|
#define NGQF_QREADER 0x08 /* was queued as a reader */
|
|
|
|
#define NGQF_QWRITER 0x00 /* was queued as a writer */
|
2001-01-14 23:25:54 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
/*
|
|
|
|
* Get the mbuf (etc) out of an item.
|
|
|
|
* Sets the value in the item to NULL in case we need to call NG_FREE_ITEM()
|
|
|
|
* with it, (to avoid freeing the things twice).
|
|
|
|
* If you don't want to zero out the item then realise that the
|
|
|
|
* item still owns it.
|
|
|
|
* Retaddr is different. There are no references on that. It's just a number.
|
|
|
|
* The debug versions must be either all used everywhere or not at all.
|
|
|
|
*/
|
|
|
|
|
2004-06-30 22:51:29 +00:00
|
|
|
#define _NGI_M(i) ((i)->body.da_m)
|
2001-01-06 00:46:47 +00:00
|
|
|
#define _NGI_MSG(i) ((i)->body.msg.msg_msg)
|
|
|
|
#define _NGI_RETADDR(i) ((i)->body.msg.msg_retaddr)
|
2007-10-19 15:04:17 +00:00
|
|
|
#define _NGI_FN(i) ((i)->body.fn.fn_fn.fn_fn)
|
|
|
|
#define _NGI_FN2(i) ((i)->body.fn.fn_fn.fn_fn2)
|
2001-01-14 23:25:54 +00:00
|
|
|
#define _NGI_ARG1(i) ((i)->body.fn.fn_arg1)
|
|
|
|
#define _NGI_ARG2(i) ((i)->body.fn.fn_arg2)
|
2001-01-30 20:51:52 +00:00
|
|
|
#define _NGI_NODE(i) ((i)->el_dest)
|
|
|
|
#define _NGI_HOOK(i) ((i)->el_hook)
|
|
|
|
#define _NGI_SET_HOOK(i,h) do { _NGI_HOOK(i) = h; h = NULL;} while (0)
|
|
|
|
#define _NGI_CLR_HOOK(i) do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
hook_p _hook = _NGI_HOOK(i); \
|
|
|
|
if (_hook) { \
|
|
|
|
_NG_HOOK_UNREF(_hook); \
|
2001-01-30 20:51:52 +00:00
|
|
|
_NGI_HOOK(i) = NULL; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define _NGI_SET_NODE(i,n) do { _NGI_NODE(i) = n; n = NULL;} while (0)
|
|
|
|
#define _NGI_CLR_NODE(i) do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
node_p _node = _NGI_NODE(i); \
|
|
|
|
if (_node) { \
|
|
|
|
_NG_NODE_UNREF(_node); \
|
2001-01-30 20:51:52 +00:00
|
|
|
_NGI_NODE(i) = NULL; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2001-01-06 00:46:47 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
|
|
|
void dumpitem(item_p item, char *file, int line);
|
|
|
|
static __inline void _ngi_check(item_p item, char *file, int line) ;
|
|
|
|
static __inline struct mbuf ** _ngi_m(item_p item, char *file, int line) ;
|
2001-01-30 20:51:52 +00:00
|
|
|
static __inline ng_ID_t * _ngi_retaddr(item_p item, char *file, int line);
|
|
|
|
static __inline struct ng_mesg ** _ngi_msg(item_p item, char *file, int line) ;
|
|
|
|
static __inline ng_item_fn ** _ngi_fn(item_p item, char *file, int line) ;
|
2007-10-19 15:04:17 +00:00
|
|
|
static __inline ng_item_fn2 ** _ngi_fn2(item_p item, char *file, int line) ;
|
2001-01-30 20:51:52 +00:00
|
|
|
static __inline void ** _ngi_arg1(item_p item, char *file, int line) ;
|
|
|
|
static __inline int * _ngi_arg2(item_p item, char *file, int line) ;
|
|
|
|
static __inline node_p _ngi_node(item_p item, char *file, int line);
|
|
|
|
static __inline hook_p _ngi_hook(item_p item, char *file, int line);
|
2001-01-06 00:46:47 +00:00
|
|
|
|
|
|
|
static __inline void
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_check(item_p item, char *file, int line)
|
2001-01-06 00:46:47 +00:00
|
|
|
{
|
|
|
|
(item)->lastline = line;
|
|
|
|
(item)->lastfile = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline struct mbuf **
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_m(item_p item, char *file, int line)
|
2001-01-06 00:46:47 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_M(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline struct ng_mesg **
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_msg(item_p item, char *file, int line)
|
2001-01-06 00:46:47 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_MSG(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline ng_ID_t *
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_retaddr(item_p item, char *file, int line)
|
2001-01-06 00:46:47 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_RETADDR(item));
|
|
|
|
}
|
|
|
|
|
2001-01-14 23:25:54 +00:00
|
|
|
static __inline ng_item_fn **
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_fn(item_p item, char *file, int line)
|
2001-01-14 23:25:54 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_FN(item));
|
|
|
|
}
|
2001-01-06 00:46:47 +00:00
|
|
|
|
2007-10-19 15:04:17 +00:00
|
|
|
static __inline ng_item_fn2 **
|
|
|
|
_ngi_fn2(item_p item, char *file, int line)
|
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_FN2(item));
|
|
|
|
}
|
|
|
|
|
2001-01-14 23:25:54 +00:00
|
|
|
static __inline void **
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_arg1(item_p item, char *file, int line)
|
2001-01-14 23:25:54 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_ARG1(item));
|
|
|
|
}
|
2001-01-06 00:46:47 +00:00
|
|
|
|
2001-01-14 23:25:54 +00:00
|
|
|
static __inline int *
|
2005-11-15 10:54:20 +00:00
|
|
|
_ngi_arg2(item_p item, char *file, int line)
|
2001-01-14 23:25:54 +00:00
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (&_NGI_ARG2(item));
|
|
|
|
}
|
2001-01-06 00:46:47 +00:00
|
|
|
|
2001-01-30 20:51:52 +00:00
|
|
|
static __inline node_p
|
|
|
|
_ngi_node(item_p item, char *file, int line)
|
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (_NGI_NODE(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline hook_p
|
|
|
|
_ngi_hook(item_p item, char *file, int line)
|
|
|
|
{
|
|
|
|
_ngi_check(item, file, line);
|
|
|
|
return (_NGI_HOOK(item));
|
|
|
|
}
|
|
|
|
|
2001-01-14 23:25:54 +00:00
|
|
|
#define NGI_M(i) (*_ngi_m(i, _NN_))
|
|
|
|
#define NGI_MSG(i) (*_ngi_msg(i, _NN_))
|
|
|
|
#define NGI_RETADDR(i) (*_ngi_retaddr(i, _NN_))
|
|
|
|
#define NGI_FN(i) (*_ngi_fn(i, _NN_))
|
2007-10-19 15:04:17 +00:00
|
|
|
#define NGI_FN2(i) (*_ngi_fn2(i, _NN_))
|
2001-01-14 23:25:54 +00:00
|
|
|
#define NGI_ARG1(i) (*_ngi_arg1(i, _NN_))
|
|
|
|
#define NGI_ARG2(i) (*_ngi_arg2(i, _NN_))
|
2001-01-30 20:51:52 +00:00
|
|
|
#define NGI_HOOK(i) _ngi_hook(i, _NN_)
|
|
|
|
#define NGI_NODE(i) _ngi_node(i, _NN_)
|
|
|
|
#define NGI_SET_HOOK(i,h) \
|
|
|
|
do { _ngi_check(i, _NN_); _NGI_SET_HOOK(i, h); } while (0)
|
|
|
|
#define NGI_CLR_HOOK(i) \
|
|
|
|
do { _ngi_check(i, _NN_); _NGI_CLR_HOOK(i); } while (0)
|
|
|
|
#define NGI_SET_NODE(i,n) \
|
|
|
|
do { _ngi_check(i, _NN_); _NGI_SET_NODE(i, n); } while (0)
|
|
|
|
#define NGI_CLR_NODE(i) \
|
|
|
|
do { _ngi_check(i, _NN_); _NGI_CLR_NODE(i); } while (0)
|
2001-01-06 00:46:47 +00:00
|
|
|
|
|
|
|
#define NG_FREE_ITEM(item) \
|
|
|
|
do { \
|
2001-01-08 05:34:06 +00:00
|
|
|
_ngi_check(item, _NN_); \
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_free_item((item)); \
|
|
|
|
} while (0)
|
2000-12-18 20:03:32 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
#define SAVE_LINE(item) \
|
1999-10-21 09:06:11 +00:00
|
|
|
do { \
|
2001-01-06 00:46:47 +00:00
|
|
|
(item)->lastline = __LINE__; \
|
|
|
|
(item)->lastfile = __FILE__; \
|
|
|
|
} while (0)
|
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
2001-01-06 00:46:47 +00:00
|
|
|
|
|
|
|
#define NGI_M(i) _NGI_M(i)
|
|
|
|
#define NGI_MSG(i) _NGI_MSG(i)
|
|
|
|
#define NGI_RETADDR(i) _NGI_RETADDR(i)
|
2001-01-14 23:25:54 +00:00
|
|
|
#define NGI_FN(i) _NGI_FN(i)
|
2007-10-19 15:04:17 +00:00
|
|
|
#define NGI_FN2(i) _NGI_FN2(i)
|
2001-01-14 23:25:54 +00:00
|
|
|
#define NGI_ARG1(i) _NGI_ARG1(i)
|
|
|
|
#define NGI_ARG2(i) _NGI_ARG2(i)
|
2001-01-30 20:51:52 +00:00
|
|
|
#define NGI_NODE(i) _NGI_NODE(i)
|
|
|
|
#define NGI_HOOK(i) _NGI_HOOK(i)
|
|
|
|
#define NGI_SET_HOOK(i,h) _NGI_SET_HOOK(i,h)
|
|
|
|
#define NGI_CLR_HOOK(i) _NGI_CLR_HOOK(i)
|
|
|
|
#define NGI_SET_NODE(i,n) _NGI_SET_NODE(i,n)
|
|
|
|
#define NGI_CLR_NODE(i) _NGI_CLR_NODE(i)
|
2001-01-06 00:46:47 +00:00
|
|
|
|
|
|
|
#define NG_FREE_ITEM(item) ng_free_item((item))
|
2001-01-08 05:34:06 +00:00
|
|
|
#define SAVE_LINE(item) do {} while (0)
|
2001-01-06 00:46:47 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
|
2001-01-30 20:51:52 +00:00
|
|
|
|
|
|
|
#define NGI_GET_M(i,m) \
|
|
|
|
do { \
|
|
|
|
(m) = NGI_M(i); \
|
|
|
|
_NGI_M(i) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NGI_GET_MSG(i,m) \
|
|
|
|
do { \
|
|
|
|
(m) = NGI_MSG(i); \
|
|
|
|
_NGI_MSG(i) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NGI_GET_NODE(i,n) /* YOU NOW HAVE THE REFERENCE */ \
|
|
|
|
do { \
|
|
|
|
(n) = NGI_NODE(i); \
|
|
|
|
_NGI_NODE(i) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NGI_GET_HOOK(i,h) \
|
|
|
|
do { \
|
|
|
|
(h) = NGI_HOOK(i); \
|
|
|
|
_NGI_HOOK(i) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
2005-11-02 14:27:24 +00:00
|
|
|
#define NGI_SET_WRITER(i) ((i)->el_flags &= ~NGQF_QMODE)
|
|
|
|
#define NGI_SET_READER(i) ((i)->el_flags |= NGQF_QREADER)
|
|
|
|
|
|
|
|
#define NGI_QUEUED_READER(i) ((i)->el_flags & NGQF_QREADER)
|
|
|
|
#define NGI_QUEUED_WRITER(i) (((i)->el_flags & NGQF_QMODE) == NGQF_QWRITER)
|
2001-01-06 00:46:47 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Data macros. Send, manipulate and free.
|
|
|
|
**********************************************************************/
|
2001-03-03 05:52:49 +00:00
|
|
|
/*
|
|
|
|
* Assuming the data is already ok, just set the new address and send
|
|
|
|
*/
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_FWD_ITEM_HOOK_FLAGS(error, item, hook, flags) \
|
1999-10-21 09:06:11 +00:00
|
|
|
do { \
|
2001-03-03 05:52:49 +00:00
|
|
|
(error) = \
|
2006-01-12 22:44:04 +00:00
|
|
|
ng_address_hook(NULL, (item), (hook), NG_NOFLAGS); \
|
2001-03-03 05:52:49 +00:00
|
|
|
if (error == 0) { \
|
|
|
|
SAVE_LINE(item); \
|
2006-01-12 22:44:04 +00:00
|
|
|
(error) = ng_snd_item((item), (flags)); \
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
2001-03-03 05:52:49 +00:00
|
|
|
(item) = NULL; \
|
1999-10-21 09:06:11 +00:00
|
|
|
} while (0)
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_FWD_ITEM_HOOK(error, item, hook) \
|
|
|
|
NG_FWD_ITEM_HOOK_FLAGS(error, item, hook, NG_NOFLAGS)
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
/*
|
2004-06-30 22:51:29 +00:00
|
|
|
* Forward a data packet. Mbuf pointer is updated to new value. We
|
|
|
|
* presume you dealt with the old one when you update it to the new one
|
|
|
|
* (or it maybe the old one). We got a packet and possibly had to modify
|
|
|
|
* the mbuf. You should probably use NGI_GET_M() if you are going to use
|
|
|
|
* this too.
|
2001-01-06 00:46:47 +00:00
|
|
|
*/
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_FWD_NEW_DATA_FLAGS(error, item, hook, m, flags) \
|
2000-12-12 18:52:14 +00:00
|
|
|
do { \
|
2001-03-03 05:52:49 +00:00
|
|
|
NGI_M(item) = (m); \
|
|
|
|
(m) = NULL; \
|
2006-01-12 22:44:04 +00:00
|
|
|
NG_FWD_ITEM_HOOK_FLAGS(error, item, hook, flags); \
|
2001-03-03 05:52:49 +00:00
|
|
|
} while (0)
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_FWD_NEW_DATA(error, item, hook, m) \
|
|
|
|
NG_FWD_NEW_DATA_FLAGS(error, item, hook, m, NG_NOFLAGS)
|
2001-03-03 05:52:49 +00:00
|
|
|
|
2004-06-30 22:51:29 +00:00
|
|
|
/* Send a previously unpackaged mbuf. XXX: This should be called
|
|
|
|
* NG_SEND_DATA in future, but this name is kept for compatibility
|
|
|
|
* reasons.
|
|
|
|
*/
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_SEND_DATA_FLAGS(error, hook, m, flags) \
|
2001-03-03 05:52:49 +00:00
|
|
|
do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
item_p _item; \
|
2006-01-12 22:44:04 +00:00
|
|
|
if ((_item = ng_package_data((m), flags))) { \
|
|
|
|
NG_FWD_ITEM_HOOK_FLAGS(error, _item, hook, flags);\
|
2001-03-03 05:52:49 +00:00
|
|
|
} else { \
|
|
|
|
(error) = ENOMEM; \
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
2000-12-12 18:52:14 +00:00
|
|
|
(m) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
2006-01-12 22:44:04 +00:00
|
|
|
#define NG_SEND_DATA_ONLY(error, hook, m) \
|
|
|
|
NG_SEND_DATA_FLAGS(error, hook, m, NG_NOFLAGS)
|
|
|
|
/* NG_SEND_DATA() compat for meta-data times */
|
|
|
|
#define NG_SEND_DATA(error, hook, m, x) \
|
|
|
|
NG_SEND_DATA_FLAGS(error, hook, m, NG_NOFLAGS)
|
2000-04-28 17:09:00 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
#define NG_FREE_MSG(msg) \
|
|
|
|
do { \
|
|
|
|
if ((msg)) { \
|
2008-10-23 15:53:51 +00:00
|
|
|
free((msg), M_NETGRAPH_MSG); \
|
2001-01-06 00:46:47 +00:00
|
|
|
(msg) = NULL; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NG_FREE_M(m) \
|
1999-10-21 09:06:11 +00:00
|
|
|
do { \
|
|
|
|
if ((m)) { \
|
|
|
|
m_freem((m)); \
|
2001-01-06 00:46:47 +00:00
|
|
|
(m) = NULL; \
|
1999-10-21 09:06:11 +00:00
|
|
|
} \
|
2001-01-06 00:46:47 +00:00
|
|
|
} while (0)
|
2001-01-08 05:34:06 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
/*****************************************
|
|
|
|
* Message macros
|
|
|
|
*****************************************/
|
|
|
|
|
|
|
|
#define NG_SEND_MSG_HOOK(error, here, msg, hook, retaddr) \
|
|
|
|
do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
item_p _item; \
|
2005-05-16 17:07:03 +00:00
|
|
|
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
|
2001-01-08 05:34:06 +00:00
|
|
|
(msg) = NULL; \
|
|
|
|
(error) = ENOMEM; \
|
|
|
|
break; \
|
|
|
|
} \
|
2002-08-20 18:57:11 +00:00
|
|
|
if (((error) = ng_address_hook((here), (_item), \
|
2001-01-08 05:34:06 +00:00
|
|
|
(hook), (retaddr))) == 0) { \
|
2002-08-20 18:57:11 +00:00
|
|
|
SAVE_LINE(_item); \
|
|
|
|
(error) = ng_snd_item((_item), 0); \
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
|
|
|
(msg) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NG_SEND_MSG_PATH(error, here, msg, path, retaddr) \
|
|
|
|
do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
item_p _item; \
|
2005-05-16 17:07:03 +00:00
|
|
|
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
|
2001-01-08 05:34:06 +00:00
|
|
|
(msg) = NULL; \
|
|
|
|
(error) = ENOMEM; \
|
|
|
|
break; \
|
|
|
|
} \
|
2002-08-20 18:57:11 +00:00
|
|
|
if (((error) = ng_address_path((here), (_item), \
|
2001-01-08 05:34:06 +00:00
|
|
|
(path), (retaddr))) == 0) { \
|
2002-08-20 18:57:11 +00:00
|
|
|
SAVE_LINE(_item); \
|
|
|
|
(error) = ng_snd_item((_item), 0); \
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
|
|
|
(msg) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define NG_SEND_MSG_ID(error, here, msg, ID, retaddr) \
|
|
|
|
do { \
|
2002-08-20 18:57:11 +00:00
|
|
|
item_p _item; \
|
2005-05-16 17:07:03 +00:00
|
|
|
if ((_item = ng_package_msg(msg, NG_NOFLAGS)) == NULL) {\
|
2001-01-08 05:34:06 +00:00
|
|
|
(msg) = NULL; \
|
|
|
|
(error) = ENOMEM; \
|
|
|
|
break; \
|
|
|
|
} \
|
2002-08-20 18:57:11 +00:00
|
|
|
if (((error) = ng_address_ID((here), (_item), \
|
2001-01-08 05:34:06 +00:00
|
|
|
(ID), (retaddr))) == 0) { \
|
2002-08-20 18:57:11 +00:00
|
|
|
SAVE_LINE(_item); \
|
|
|
|
(error) = ng_snd_item((_item), 0); \
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
|
|
|
(msg) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redirect the message to the next hop using the given hook.
|
|
|
|
* ng_retarget_msg() frees the item if there is an error
|
|
|
|
* and returns an error code. It returns 0 on success.
|
|
|
|
*/
|
|
|
|
#define NG_FWD_MSG_HOOK(error, here, item, hook, retaddr) \
|
|
|
|
do { \
|
2001-01-08 05:34:06 +00:00
|
|
|
if (((error) = ng_address_hook((here), (item), \
|
2001-01-06 00:46:47 +00:00
|
|
|
(hook), (retaddr))) == 0) { \
|
|
|
|
SAVE_LINE(item); \
|
|
|
|
(error) = ng_snd_item((item), 0); \
|
|
|
|
} \
|
|
|
|
(item) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a queue item back to it's originator with a response message.
|
|
|
|
* Assume original message was removed and freed separatly.
|
|
|
|
*/
|
|
|
|
#define NG_RESPOND_MSG(error, here, item, resp) \
|
|
|
|
do { \
|
|
|
|
if (resp) { \
|
2002-08-20 18:57:11 +00:00
|
|
|
ng_ID_t _dest = NGI_RETADDR(item); \
|
2002-08-22 00:30:03 +00:00
|
|
|
NGI_RETADDR(item) = 0; \
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_MSG(item) = resp; \
|
2006-10-17 10:59:39 +00:00
|
|
|
if ((error = ng_address_ID((here), (item), \
|
2002-08-22 00:30:03 +00:00
|
|
|
_dest, 0)) == 0) { \
|
2001-01-06 00:46:47 +00:00
|
|
|
SAVE_LINE(item); \
|
2005-05-16 19:52:42 +00:00
|
|
|
(error) = ng_snd_item((item), NG_QUEUE);\
|
2001-01-06 00:46:47 +00:00
|
|
|
} \
|
2006-10-17 10:59:39 +00:00
|
|
|
} else \
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_ITEM(item); \
|
|
|
|
(item) = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
/***********************************************************************
|
|
|
|
******** Structures Definitions and Macros for defining a node *******
|
|
|
|
***********************************************************************
|
2005-11-15 10:54:20 +00:00
|
|
|
*
|
2001-01-08 05:34:06 +00:00
|
|
|
* Here we define the structures needed to actually define a new node
|
|
|
|
* type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command list -- each node type specifies the command that it knows
|
|
|
|
* how to convert between ASCII and binary using an array of these.
|
|
|
|
* The last element in the array must be a terminator with cookie=0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ng_cmdlist {
|
|
|
|
u_int32_t cookie; /* command typecookie */
|
|
|
|
int cmd; /* command number */
|
|
|
|
const char *name; /* command name */
|
|
|
|
const struct ng_parse_type *mesgType; /* args if !NGF_RESP */
|
|
|
|
const struct ng_parse_type *respType; /* args if NGF_RESP */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure of a node type
|
|
|
|
* If data is sent to the "rcvdata()" entrypoint then the system
|
|
|
|
* may decide to defer it until later by queing it with the normal netgraph
|
|
|
|
* input queuing system. This is decidde by the HK_QUEUE flag being set in
|
|
|
|
* the flags word of the peer (receiving) hook. The dequeuing mechanism will
|
|
|
|
* ensure it is not requeued again.
|
|
|
|
* Note the input queueing system is to allow modules
|
|
|
|
* to 'release the stack' or to pass data across spl layers.
|
|
|
|
* The data will be redelivered as soon as the NETISR code runs
|
|
|
|
* which may be almost immediatly. A node may also do it's own queueing
|
|
|
|
* for other reasons (e.g. device output queuing).
|
|
|
|
*/
|
|
|
|
struct ng_type {
|
|
|
|
|
|
|
|
u_int32_t version; /* must equal NG_API_VERSION */
|
|
|
|
const char *name; /* Unique type name */
|
|
|
|
modeventhand_t mod_event; /* Module event handler (optional) */
|
|
|
|
ng_constructor_t *constructor; /* Node constructor */
|
|
|
|
ng_rcvmsg_t *rcvmsg; /* control messages come here */
|
2004-05-29 07:21:46 +00:00
|
|
|
ng_close_t *close; /* warn about forthcoming shutdown */
|
2001-01-08 05:34:06 +00:00
|
|
|
ng_shutdown_t *shutdown; /* reset, and free resources */
|
|
|
|
ng_newhook_t *newhook; /* first notification of new hook */
|
|
|
|
ng_findhook_t *findhook; /* only if you have lots of hooks */
|
|
|
|
ng_connect_t *connect; /* final notification of new hook */
|
|
|
|
ng_rcvdata_t *rcvdata; /* data comes here */
|
|
|
|
ng_disconnect_t *disconnect; /* notify on disconnect */
|
|
|
|
|
|
|
|
const struct ng_cmdlist *cmdlist; /* commands we can convert */
|
|
|
|
|
|
|
|
/* R/W data private to the base netgraph code DON'T TOUCH! */
|
|
|
|
LIST_ENTRY(ng_type) types; /* linked list of all types */
|
|
|
|
int refs; /* number of instances */
|
|
|
|
};
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Use the NETGRAPH_INIT() macro to link a node type into the
|
|
|
|
* netgraph system. This works for types compiled into the kernel
|
|
|
|
* as well as KLD modules. The first argument should be the type
|
|
|
|
* name (eg, echo) and the second a pointer to the type struct.
|
|
|
|
*
|
|
|
|
* If a different link time is desired, e.g., a device driver that
|
|
|
|
* needs to install its netgraph type before probing, use the
|
2005-08-02 20:06:48 +00:00
|
|
|
* NETGRAPH_INIT_ORDERED() macro instead. Device drivers probably
|
|
|
|
* want to use SI_SUB_DRIVERS/SI_ORDER_FIRST.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NETGRAPH_INIT_ORDERED(typename, typestructp, sub, order) \
|
|
|
|
static moduledata_t ng_##typename##_mod = { \
|
|
|
|
"ng_" #typename, \
|
|
|
|
ng_mod_event, \
|
|
|
|
(typestructp) \
|
|
|
|
}; \
|
2000-04-29 13:36:07 +00:00
|
|
|
DECLARE_MODULE(ng_##typename, ng_##typename##_mod, sub, order); \
|
2001-02-05 18:57:11 +00:00
|
|
|
MODULE_DEPEND(ng_##typename, netgraph, NG_ABI_VERSION, \
|
|
|
|
NG_ABI_VERSION, \
|
|
|
|
NG_ABI_VERSION)
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
#define NETGRAPH_INIT(tn, tp) \
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
NETGRAPH_INIT_ORDERED(tn, tp, SI_SUB_PSEUDO, SI_ORDER_MIDDLE)
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/* Special malloc() type for netgraph structs and ctrl messages */
|
2005-11-15 10:54:20 +00:00
|
|
|
/* Only these two types should be visible to nodes */
|
1999-10-21 09:06:11 +00:00
|
|
|
MALLOC_DECLARE(M_NETGRAPH);
|
2001-01-06 00:46:47 +00:00
|
|
|
MALLOC_DECLARE(M_NETGRAPH_MSG);
|
|
|
|
|
2001-02-23 16:34:22 +00:00
|
|
|
/* declare the base of the netgraph sysclt hierarchy */
|
|
|
|
/* but only if this file cares about sysctls */
|
|
|
|
#ifdef SYSCTL_DECL
|
|
|
|
SYSCTL_DECL(_net_graph);
|
|
|
|
#endif
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
/*
|
|
|
|
* Methods that the nodes can use.
|
2005-11-15 10:54:20 +00:00
|
|
|
* Many of these methods should usually NOT be used directly but via
|
2001-01-08 05:34:06 +00:00
|
|
|
* Macros above.
|
|
|
|
*/
|
2001-01-06 00:46:47 +00:00
|
|
|
int ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr);
|
|
|
|
int ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr);
|
2011-11-06 05:20:27 +00:00
|
|
|
int ng_address_path(node_p here, item_p item, const char *address, ng_ID_t raddr);
|
2004-05-29 07:21:46 +00:00
|
|
|
int ng_bypass(hook_p hook1, hook_p hook2);
|
1999-12-03 21:17:30 +00:00
|
|
|
hook_p ng_findhook(node_p node, const char *name);
|
2004-07-27 20:30:56 +00:00
|
|
|
struct ng_type *ng_findtype(const char *type);
|
1999-10-21 09:06:11 +00:00
|
|
|
int ng_make_node_common(struct ng_type *typep, node_p *nodep);
|
|
|
|
int ng_name_node(node_p node, const char *name);
|
2009-04-26 07:14:50 +00:00
|
|
|
node_p ng_name2noderef(node_p node, const char *name);
|
1999-10-21 09:06:11 +00:00
|
|
|
int ng_newtype(struct ng_type *tp);
|
1999-11-01 00:31:14 +00:00
|
|
|
ng_ID_t ng_node2ID(node_p node);
|
2005-05-16 17:07:03 +00:00
|
|
|
item_p ng_package_data(struct mbuf *m, int flags);
|
|
|
|
item_p ng_package_msg(struct ng_mesg *msg, int flags);
|
2001-01-06 00:46:47 +00:00
|
|
|
item_p ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg);
|
|
|
|
void ng_replace_retaddr(node_p here, item_p item, ng_ID_t retaddr);
|
2001-01-11 19:27:54 +00:00
|
|
|
int ng_rmhook_self(hook_p hook); /* if a node wants to kill a hook */
|
|
|
|
int ng_rmnode_self(node_p here); /* if a node wants to suicide */
|
2001-07-23 21:14:57 +00:00
|
|
|
int ng_rmtype(struct ng_type *tp);
|
2001-01-06 00:46:47 +00:00
|
|
|
int ng_snd_item(item_p item, int queue);
|
2007-11-14 11:25:58 +00:00
|
|
|
int ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void *arg1,
|
|
|
|
int arg2);
|
|
|
|
int ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void *arg1,
|
|
|
|
int arg2, int flags);
|
|
|
|
int ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn,
|
2005-05-16 17:07:03 +00:00
|
|
|
void *arg1, int arg2, int flags);
|
2004-12-01 11:56:32 +00:00
|
|
|
int ng_uncallout(struct callout *c, node_p node);
|
|
|
|
int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
|
2002-03-05 20:26:20 +00:00
|
|
|
ng_item_fn *fn, void * arg1, int arg2);
|
2007-07-28 07:31:30 +00:00
|
|
|
#define ng_callout_init(c) callout_init(c, CALLOUT_MPSAFE)
|
2001-01-08 05:34:06 +00:00
|
|
|
|
2005-05-16 17:07:03 +00:00
|
|
|
/* Flags for netgraph functions. */
|
|
|
|
#define NG_NOFLAGS 0x00000000 /* no special options */
|
|
|
|
#define NG_QUEUE 0x00000001 /* enqueue item, don't dispatch */
|
|
|
|
#define NG_WAITOK 0x00000002 /* use M_WAITOK, etc. */
|
2007-11-14 11:25:58 +00:00
|
|
|
/* XXXGL: NG_PROGRESS unused since ng_base.c rev. 1.136. Should be deleted? */
|
2005-07-05 17:35:20 +00:00
|
|
|
#define NG_PROGRESS 0x00000004 /* return EINPROGRESS if queued */
|
2007-11-14 11:25:58 +00:00
|
|
|
#define NG_REUSE_ITEM 0x00000008 /* supplied item should be reused */
|
2005-05-16 17:07:03 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
/*
|
2004-06-25 19:22:05 +00:00
|
|
|
* prototypes the user should DEFINITELY not use directly
|
2001-01-08 05:34:06 +00:00
|
|
|
*/
|
|
|
|
void ng_free_item(item_p item); /* Use NG_FREE_ITEM instead */
|
|
|
|
int ng_mod_event(module_t mod, int what, void *arg);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2004-06-25 19:22:05 +00:00
|
|
|
/*
|
|
|
|
* Tag definitions and constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NG_TAG_PRIO 1
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2004-06-25 19:22:05 +00:00
|
|
|
struct ng_tag_prio {
|
|
|
|
struct m_tag tag;
|
|
|
|
char priority;
|
|
|
|
char discardability;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NG_PRIO_CUTOFF 32
|
|
|
|
#define NG_PRIO_LINKSTATE 64
|
|
|
|
|
2004-06-30 22:51:29 +00:00
|
|
|
/* Macros and declarations to keep compatibility with metadata, which
|
|
|
|
* is obsoleted now. To be deleted.
|
|
|
|
*/
|
|
|
|
typedef void *meta_p;
|
|
|
|
#define _NGI_META(i) NULL
|
|
|
|
#define NGI_META(i) NULL
|
|
|
|
#define NG_FREE_META(meta)
|
|
|
|
#define NGI_GET_META(i,m)
|
|
|
|
#define ng_copy_meta(meta) NULL
|
|
|
|
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
/*
|
|
|
|
* Mark the current thread when called from the outbound path of the
|
|
|
|
* network stack, in order to enforce queuing on ng nodes calling into
|
|
|
|
* the inbound network stack path.
|
|
|
|
*/
|
|
|
|
#define NG_OUTBOUND_THREAD_REF() \
|
|
|
|
curthread->td_ng_outbound++
|
|
|
|
#define NG_OUTBOUND_THREAD_UNREF() \
|
|
|
|
do { \
|
|
|
|
curthread->td_ng_outbound--; \
|
|
|
|
KASSERT(curthread->td_ng_outbound >= 0, \
|
|
|
|
("%s: negative td_ng_outbound", __func__)); \
|
|
|
|
} while (0)
|
|
|
|
|
2004-06-25 19:22:05 +00:00
|
|
|
#endif /* _NETGRAPH_NETGRAPH_H_ */
|