* 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.
*/
#define _NG_ABI_VERSION 12
-#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
ng_rcvmsg_t *hk_rcvmsg; /* control messages come here */
ng_rcvdata_t *hk_rcvdata; /* data comes here */
int hk_refs; /* dont actually free this till 0 */
-#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 */ /*----------------------------------------------*/
};
/* Flags for a hook */
#define HK_INVALID 0x0001 /* don't trust it! */
#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,
- 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);
-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,
- int line);
-static __inline void _ng_hook_force_queue(hook_p hook, char * file, int line);
-
-static __inline void
-_chkhook(hook_p hook, char *file, int line)
-{
- if (hook->hk_magic != HK_MAGIC) {
- printf("Accessing freed hook ");
- 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);
-}
-
-static __inline char *
-_ng_hook_name(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_NAME(hook));
-}
-
-static __inline void
-_ng_hook_unref(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- _NG_HOOK_UNREF(hook);
-}
-
-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);
-}
-
-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);
-}
-
-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);
-}
-
-static __inline void *
-_ng_hook_private(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_PRIVATE(hook));
-}
-
-static __inline int
-_ng_hook_not_valid(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_NOT_VALID(hook));
-}
-
-static __inline int
-_ng_hook_is_valid(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_IS_VALID(hook));
-}
-
-static __inline node_p
-_ng_hook_node(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_NODE(hook));
-}
-
-static __inline hook_p
-_ng_hook_peer(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- return (_NG_HOOK_PEER(hook));
-}
-
-static __inline void
-_ng_hook_force_writer(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- _NG_HOOK_FORCE_WRITER(hook);
-}
-
-static __inline void
-_ng_hook_force_queue(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- _NG_HOOK_FORCE_QUEUE(hook);
-}
-
-static __inline void
-_ng_hook_hi_stack(hook_p hook, char * file, int line)
-{
- _chkhook(hook, file, line);
- _NG_HOOK_HI_STACK(hook);
-}
-
-
-#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_)
-#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_)
-#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_)
-#define NG_HOOK_HI_STACK(hook) _ng_hook_hi_stack(hook, _NN_)
-
-#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_FORCE_QUEUE(hook) _NG_HOOK_FORCE_QUEUE(hook)
#define NG_HOOK_HI_STACK(hook) _NG_HOOK_HI_STACK(hook)
-#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
-
/***********************************************************************
***************** Node Structure and Methods **************************
***********************************************************************
LIST_ENTRY(ng_node) nd_idnodes; /* ID hash collision list */
struct ng_queue nd_input_queue; /* input queue for locking */
int nd_refs; /* # of references to this node */
-#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 */ /*----------------------------------------------*/
};
/* Flags for a node */
} \
} while (0)
-#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
-void dumpnode(node_p node, char *file, int line);
-static __inline void _chknode(node_p node, char *file, int line);
-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);
-static __inline int _ng_node_unref(node_p node, char *file, int line);
-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);
-static __inline void _ng_node_revive(node_p node, char *file, int line);
-
-static __inline void
-_chknode(node_p node, char *file, int line)
-{
- if (node->nd_magic != ND_MAGIC) {
- printf("Accessing freed node ");
- 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));
-}
-
-static __inline int
-_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));
-}
-
-static __inline void
-_ng_node_ref(node_p node, char *file, int line)
-{
- _chknode(node, file, line);
- _NG_NODE_REF(node);
-}
-
-static __inline int
-_ng_node_unref(node_p node, char *file, int line)
-{
- _chknode(node, file, line);
- return (_NG_NODE_UNREF(node));
-}
-
-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);
-}
-
-static __inline void
-_ng_node_hi_stack(node_p node, char *file, int line)
-{
- _chknode(node, file, line);
- _NG_NODE_HI_STACK(node);
-}
-
-static __inline void
-_ng_node_really_die(node_p node, char *file, int line)
-{
- _chknode(node, file, line);
- _NG_NODE_REALLY_DIE(node);
-}
-
-static __inline void
-_ng_node_revive(node_p node, char *file, int line)
-{
- _chknode(node, file, line);
- _NG_NODE_REVIVE(node);
-}
-
-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_)
-#define NG_NODE_ID(node) _ng_node_id(node, _NN_)
-#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_)
-#define NG_NODE_HI_STACK(node) _ng_node_hi_stack(node, _NN_)
-#define NG_NODE_REALLY_DIE(node) _ng_node_really_die(node, _NN_)
-#define NG_NODE_NUMHOOKS(node) _ng_node_numhooks(node, _NN_)
-#define NG_NODE_REVIVE(node) _ng_node_revive(node, _NN_)
-#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_REVIVE(node) _NG_NODE_REVIVE(node)
#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 **************
*/
struct ng_apply_info *apply;
u_int depth;
-#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
- char *lastfile;
- int lastline;
- TAILQ_ENTRY(ng_item) all; /* all existing items */
-#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
};
#define NGQF_TYPE 0x03 /* MASK of content definition */
} \
} while (0)
-#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) ;
-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) ;
-static __inline ng_item_fn2 ** _ngi_fn2(item_p item, char *file, int line) ;
-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);
-
-static __inline void
-_ngi_check(item_p item, char *file, int line)
-{
- (item)->lastline = line;
- (item)->lastfile = file;
-}
-
-static __inline struct mbuf **
-_ngi_m(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_M(item));
-}
-
-static __inline struct ng_mesg **
-_ngi_msg(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_MSG(item));
-}
-
-static __inline ng_ID_t *
-_ngi_retaddr(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_RETADDR(item));
-}
-
-static __inline ng_item_fn **
-_ngi_fn(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_FN(item));
-}
-
-static __inline ng_item_fn2 **
-_ngi_fn2(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_FN2(item));
-}
-
-static __inline void **
-_ngi_arg1(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_ARG1(item));
-}
-
-static __inline int *
-_ngi_arg2(item_p item, char *file, int line)
-{
- _ngi_check(item, file, line);
- return (&_NGI_ARG2(item));
-}
-
-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));
-}
-
-#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_))
-#define NGI_FN2(i) (*_ngi_fn2(i, _NN_))
-#define NGI_ARG1(i) (*_ngi_arg1(i, _NN_))
-#define NGI_ARG2(i) (*_ngi_arg2(i, _NN_))
-#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)
-
-#define NG_FREE_ITEM(item) \
- do { \
- _ngi_check(item, _NN_); \
- ng_free_item((item)); \
- } while (0)
-
-#define SAVE_LINE(item) \
- do { \
- (item)->lastline = __LINE__; \
- (item)->lastfile = __FILE__; \
- } while (0)
-
-#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
-
#define NGI_M(i) _NGI_M(i)
#define NGI_MSG(i) _NGI_MSG(i)
#define NGI_RETADDR(i) _NGI_RETADDR(i)
#define NG_FREE_ITEM(item) ng_free_item((item))
#define SAVE_LINE(item) do {} while (0)
-#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
-
#define NGI_GET_M(i,m) \
do { \
(m) = NGI_M(i); \
/* Mutex to protect topology events. */
static struct mtx ng_topo_mtx;
-#ifdef NETGRAPH_DEBUG
-static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
-static struct mtx ngq_mtx; /* protects the queue item list */
-
-static SLIST_HEAD(, ng_node) ng_allnodes;
-static LIST_HEAD(, ng_node) ng_freenodes; /* in debug, we never free() them */
-static SLIST_HEAD(, ng_hook) ng_allhooks;
-static LIST_HEAD(, ng_hook) ng_freehooks; /* in debug, we never free() them */
-
-static void ng_dumpitems(void);
-static void ng_dumpnodes(void);
-static void ng_dumphooks(void);
-
-#endif /* NETGRAPH_DEBUG */
/*
* DEAD versions of the structures.
* In order to avoid races, it is sometimes neccesary to point
STAILQ_HEAD_INITIALIZER(ng_deadnode.nd_input_queue.queue),
},
1, /* refs */
-#ifdef NETGRAPH_DEBUG
- ND_MAGIC,
- __FILE__,
- __LINE__,
- {NULL}
-#endif /* NETGRAPH_DEBUG */
};
struct ng_hook ng_deadhook = {
NULL, /* override rcvmsg() */
NULL, /* override rcvdata() */
1, /* refs always >= 1 */
-#ifdef NETGRAPH_DEBUG
- HK_MAGIC,
- __FILE__,
- __LINE__,
- {NULL}
-#endif /* NETGRAPH_DEBUG */
};
/*
#define NG_WORKLIST_UNLOCK() \
mtx_unlock(&ng_worklist_mtx)
-#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
-/*
- * In debug mode:
- * In an attempt to help track reference count screwups
- * we do not free objects back to the malloc system, but keep them
- * in a local cache where we can examine them and keep information safely
- * after they have been freed.
- * We use this scheme for nodes and hooks, and to some extent for items.
- */
-static __inline hook_p
-ng_alloc_hook(void)
-{
- hook_p hook;
- SLIST_ENTRY(ng_hook) temp;
- mtx_lock(&ng_nodelist_mtx);
- hook = LIST_FIRST(&ng_freehooks);
- if (hook) {
- LIST_REMOVE(hook, hk_hooks);
- bcopy(&hook->hk_all, &temp, sizeof(temp));
- bzero(hook, sizeof(struct ng_hook));
- bcopy(&temp, &hook->hk_all, sizeof(temp));
- mtx_unlock(&ng_nodelist_mtx);
- hook->hk_magic = HK_MAGIC;
- } else {
- mtx_unlock(&ng_nodelist_mtx);
- _NG_ALLOC_HOOK(hook);
- if (hook) {
- hook->hk_magic = HK_MAGIC;
- mtx_lock(&ng_nodelist_mtx);
- SLIST_INSERT_HEAD(&ng_allhooks, hook, hk_all);
- mtx_unlock(&ng_nodelist_mtx);
- }
- }
- return (hook);
-}
-
-static __inline node_p
-ng_alloc_node(void)
-{
- node_p node;
- SLIST_ENTRY(ng_node) temp;
- mtx_lock(&ng_nodelist_mtx);
- node = LIST_FIRST(&ng_freenodes);
- if (node) {
- LIST_REMOVE(node, nd_nodes);
- bcopy(&node->nd_all, &temp, sizeof(temp));
- bzero(node, sizeof(struct ng_node));
- bcopy(&temp, &node->nd_all, sizeof(temp));
- mtx_unlock(&ng_nodelist_mtx);
- node->nd_magic = ND_MAGIC;
- } else {
- mtx_unlock(&ng_nodelist_mtx);
- _NG_ALLOC_NODE(node);
- if (node) {
- node->nd_magic = ND_MAGIC;
- mtx_lock(&ng_nodelist_mtx);
- SLIST_INSERT_HEAD(&ng_allnodes, node, nd_all);
- mtx_unlock(&ng_nodelist_mtx);
- }
- }
- return (node);
-}
-
-#define NG_ALLOC_HOOK(hook) do { (hook) = ng_alloc_hook(); } while (0)
-#define NG_ALLOC_NODE(node) do { (node) = ng_alloc_node(); } while (0)
-
-
-#define NG_FREE_HOOK(hook) \
- do { \
- mtx_lock(&ng_nodelist_mtx); \
- LIST_INSERT_HEAD(&ng_freehooks, hook, hk_hooks); \
- hook->hk_magic = 0; \
- mtx_unlock(&ng_nodelist_mtx); \
- } while (0)
-
-#define NG_FREE_NODE(node) \
- do { \
- mtx_lock(&ng_nodelist_mtx); \
- LIST_INSERT_HEAD(&ng_freenodes, node, nd_nodes); \
- node->nd_magic = 0; \
- mtx_unlock(&ng_nodelist_mtx); \
- } while (0)
-
-#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
-
#define NG_ALLOC_HOOK(hook) _NG_ALLOC_HOOK(hook)
#define NG_ALLOC_NODE(node) _NG_ALLOC_NODE(node)
#define NG_FREE_HOOK(hook) do { kfree((hook), M_NETGRAPH_HOOK); } while (0)
#define NG_FREE_NODE(node) do { kfree((node), M_NETGRAPH_NODE); } while (0)
-#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
-
/* Set this to kdb_enter("X") to catch all errors as they occur */
#ifndef TRAP_ERROR
#define TRAP_ERROR()
/* We are sending item, so it must be present! */
KASSERT(item != NULL, ("ng_snd_item: item is NULL"));
-#ifdef NETGRAPH_DEBUG
- _ngi_check(item, __FILE__, __LINE__);
-#endif
-
/* Item was sent once more, postpone apply() call. */
if (item->apply)
refcount_acquire(&item->apply->refs);
KASSERT(item != NULL, ("ng_apply_item: item is NULL"));
NGI_GET_HOOK(item, hook); /* clears stored hook */
-#ifdef NETGRAPH_DEBUG
- _ngi_check(item, __FILE__, __LINE__);
-#endif
apply = item->apply;
depth = item->depth;
SYSCTL_INT(_net_graph, OID_AUTO, maxdata, CTLFLAG_RDTUN, &maxdata,
0, "Maximum number of data queue items to allocate");
-#ifdef NETGRAPH_DEBUG
-static TAILQ_HEAD(, ng_item) ng_itemlist = TAILQ_HEAD_INITIALIZER(ng_itemlist);
-static int allocated; /* number of items malloc'd */
-#endif
-
/*
* Get a queue entry.
* This is usually called when a packet first enters netgraph.
if (item) {
item->el_flags = type;
-#ifdef NETGRAPH_DEBUG
- mtx_lock(&ngq_mtx);
- TAILQ_INSERT_TAIL(&ng_itemlist, item, all);
- allocated++;
- mtx_unlock(&ngq_mtx);
-#endif
}
return (item);
_NGI_CLR_NODE(item);
_NGI_CLR_HOOK(item);
-#ifdef NETGRAPH_DEBUG
- mtx_lock(&ngq_mtx);
- TAILQ_REMOVE(&ng_itemlist, item, all);
- allocated--;
- mtx_unlock(&ngq_mtx);
-#endif
uma_zfree(((item->el_flags & NGQF_TYPE) == NGQF_DATA)?
ng_qdzone:ng_qzone, item);
}
mtx_init(&ng_idhash_mtx);
mtx_init(&ng_namehash_mtx);
mtx_init(&ng_topo_mtx);
-#ifdef NETGRAPH_DEBUG
- mtx_init(&ng_nodelist_mtx);
- mtx_init(&ngq_mtx);
-#endif
ng_qzone = uma_zcreate("NetGraph items", sizeof(struct ng_item),
NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0);
uma_zone_set_max(ng_qzone, maxalloc);
SYSCTL_INT(_net_graph, OID_AUTO, abi_version, CTLFLAG_RD, 0, NG_ABI_VERSION,"");
SYSCTL_INT(_net_graph, OID_AUTO, msg_version, CTLFLAG_RD, 0, NG_VERSION, "");
-#ifdef NETGRAPH_DEBUG
-void
-dumphook (hook_p hook, char *file, int line)
-{
- printf("hook: name %s, %d refs, Last touched:\n",
- _NG_HOOK_NAME(hook), hook->hk_refs);
- printf(" Last active @ %s, line %d\n",
- hook->lastfile, hook->lastline);
- if (line) {
- printf(" problem discovered at file %s, line %d\n", file, line);
- }
-}
-
-void
-dumpnode(node_p node, char *file, int line)
-{
- printf("node: ID [%x]: type '%s', %d hooks, flags 0x%x, %d refs, %s:\n",
- _NG_NODE_ID(node), node->nd_type->name,
- node->nd_numhooks, node->nd_flags,
- node->nd_refs, node->nd_name);
- printf(" Last active @ %s, line %d\n",
- node->lastfile, node->lastline);
- if (line) {
- printf(" problem discovered at file %s, line %d\n", file, line);
- }
-}
-
-void
-dumpitem(item_p item, char *file, int line)
-{
- printf(" ACTIVE item, last used at %s, line %d",
- item->lastfile, item->lastline);
- switch(item->el_flags & NGQF_TYPE) {
- case NGQF_DATA:
- printf(" - [data]\n");
- break;
- case NGQF_MESG:
- printf(" - retaddr[%d]:\n", _NGI_RETADDR(item));
- break;
- case NGQF_FN:
- printf(" - fn@%p (%p, %p, %p, %d (%x))\n",
- _NGI_FN(item),
- _NGI_NODE(item),
- _NGI_HOOK(item),
- item->body.fn.fn_arg1,
- item->body.fn.fn_arg2,
- item->body.fn.fn_arg2);
- break;
- case NGQF_FN2:
- printf(" - fn2@%p (%p, %p, %p, %d (%x))\n",
- _NGI_FN2(item),
- _NGI_NODE(item),
- _NGI_HOOK(item),
- item->body.fn.fn_arg1,
- item->body.fn.fn_arg2,
- item->body.fn.fn_arg2);
- break;
- }
- if (line) {
- printf(" problem discovered at file %s, line %d\n", file, line);
- if (_NGI_NODE(item)) {
- printf("node %p ([%x])\n",
- _NGI_NODE(item), ng_node2ID(_NGI_NODE(item)));
- }
- }
-}
-
-static void
-ng_dumpitems(void)
-{
- item_p item;
- int i = 1;
- TAILQ_FOREACH(item, &ng_itemlist, all) {
- printf("[%d] ", i++);
- dumpitem(item, NULL, 0);
- }
-}
-
-static void
-ng_dumpnodes(void)
-{
- node_p node;
- int i = 1;
- mtx_lock(&ng_nodelist_mtx);
- SLIST_FOREACH(node, &ng_allnodes, nd_all) {
- printf("[%d] ", i++);
- dumpnode(node, NULL, 0);
- }
- mtx_unlock(&ng_nodelist_mtx);
-}
-
-static void
-ng_dumphooks(void)
-{
- hook_p hook;
- int i = 1;
- mtx_lock(&ng_nodelist_mtx);
- SLIST_FOREACH(hook, &ng_allhooks, hk_all) {
- printf("[%d] ", i++);
- dumphook(hook, NULL, 0);
- }
- mtx_unlock(&ng_nodelist_mtx);
-}
-
-static int
-sysctl_debug_ng_dump_items(SYSCTL_HANDLER_ARGS)
-{
- int error;
- int val;
- int i;
-
- val = allocated;
- i = 1;
- error = sysctl_handle_int(oidp, &val, 0, req);
- if (error != 0 || req->newptr == NULL)
- return (error);
- if (val == 42) {
- ng_dumpitems();
- ng_dumpnodes();
- ng_dumphooks();
- }
- return (0);
-}
-
-SYSCTL_PROC(_debug, OID_AUTO, ng_dump_items, CTLTYPE_INT | CTLFLAG_RW,
- 0, sizeof(int), sysctl_debug_ng_dump_items, "I", "Number of allocated items");
-#endif /* NETGRAPH_DEBUG */
-
-
/***********************************************************************
* Worklist routines
**********************************************************************/
* Externally useable functions to set up a queue item ready for sending
***********************************************************************/
-#ifdef NETGRAPH_DEBUG
-#define ITEM_DEBUG_CHECKS \
- do { \
- if (NGI_NODE(item) ) { \
- printf("item already has node"); \
- kdb_enter(KDB_WHY_NETGRAPH, "has node"); \
- NGI_CLR_NODE(item); \
- } \
- if (NGI_HOOK(item) ) { \
- printf("item already has hook"); \
- kdb_enter(KDB_WHY_NETGRAPH, "has hook"); \
- NGI_CLR_HOOK(item); \
- } \
- } while (0)
-#else
-#define ITEM_DEBUG_CHECKS
-#endif
-
/*
* Put mbuf into the item.
* Hook and node references will be removed when the item is dequeued.
NG_FREE_M(m);
return (NULL);
}
- ITEM_DEBUG_CHECKS;
item->el_flags |= NGQF_READER;
NGI_M(item) = m;
return (item);
NG_FREE_MSG(msg);
return (NULL);
}
- ITEM_DEBUG_CHECKS;
/* Messages items count as writers unless explicitly exempted. */
if (msg->header.cmd & NGM_READONLY)
item->el_flags |= NGQF_READER;
{
hook_p peer;
node_p peernode;
- ITEM_DEBUG_CHECKS;
/*
* Quick sanity check..
* Since a hook holds a reference on it's node, once we know
hook_p hook = NULL;
int error;
- ITEM_DEBUG_CHECKS;
/*
* Note that ng_path2noderef increments the reference count
* on the node for us if it finds one. So we don't have to.
{
node_p dest;
- ITEM_DEBUG_CHECKS;
/*
* Find the target node.
*/