summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2001-01-08 05:34:06 +0000
committerjulian <julian@FreeBSD.org>2001-01-08 05:34:06 +0000
commitff86256bf7f74eac72c4bd8a23d667579c672873 (patch)
treecf83301911bb4085e13cb3bf982901253e5919e5 /sys/netgraph
parent6b827cac3b001e32ed3dd87c8875590ebebda375 (diff)
downloadFreeBSD-src-ff86256bf7f74eac72c4bd8a23d667579c672873.zip
FreeBSD-src-ff86256bf7f74eac72c4bd8a23d667579c672873.tar.gz
Part 2 of the netgraph rewrite.
This is mostly cosmetic changes, (though I caught a bug or two while makeing them) Reviewed by: archie@freebsd.org
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/netgraph.h735
-rw-r--r--sys/netgraph/ng_UI.c34
-rw-r--r--sys/netgraph/ng_async.c35
-rw-r--r--sys/netgraph/ng_base.c732
-rw-r--r--sys/netgraph/ng_bpf.c31
-rw-r--r--sys/netgraph/ng_bridge.c47
-rw-r--r--sys/netgraph/ng_cisco.c37
-rw-r--r--sys/netgraph/ng_echo.c9
-rw-r--r--sys/netgraph/ng_ether.c47
-rw-r--r--sys/netgraph/ng_frame_relay.c35
-rw-r--r--sys/netgraph/ng_hole.c5
-rw-r--r--sys/netgraph/ng_iface.c16
-rw-r--r--sys/netgraph/ng_ksocket.c29
-rw-r--r--sys/netgraph/ng_lmi.c39
-rw-r--r--sys/netgraph/ng_mppc.c31
-rw-r--r--sys/netgraph/ng_one2many.c32
-rw-r--r--sys/netgraph/ng_ppp.c102
-rw-r--r--sys/netgraph/ng_pppoe.c125
-rw-r--r--sys/netgraph/ng_pptpgre.c61
-rw-r--r--sys/netgraph/ng_rfc1490.c23
-rw-r--r--sys/netgraph/ng_sample.c55
-rw-r--r--sys/netgraph/ng_socket.c97
-rw-r--r--sys/netgraph/ng_tee.c43
-rw-r--r--sys/netgraph/ng_tty.c37
-rw-r--r--sys/netgraph/ng_vjc.c25
25 files changed, 1548 insertions, 914 deletions
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 323aacc..b3c6afc 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -1,4 +1,3 @@
-
/*
* netgraph.h
*
@@ -43,64 +42,266 @@
#ifndef _NETGRAPH_NETGRAPH_H_
#define _NETGRAPH_NETGRAPH_H_ 1
-#include <sys/queue.h>
-#include <sys/malloc.h>
-#include <sys/module.h>
-
#ifndef _KERNEL
#error "This file should not be included in user level programs"
#endif
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
#include <sys/mutex.h>
-/* The structure for queueing across ISR switches */
-struct ng_item ; /* forward reference */
-typedef struct ng_item *item_p;
-struct ng_queue {
- u_long q_flags;
- struct mtx q_mtx;
- item_p queue;
- item_p *last;
- struct ng_node *q_node; /* find the front of the node.. */
-};
+#define NETGRAPH_DEBUG
/*
+ * 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 5
+#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;
+
+/***********************************************************************
+ ***************** Hook Structure and Methods **************************
+ ***********************************************************************
+ *
* Structure of a hook
*/
struct ng_hook {
- char name[NG_HOOKLEN+1];/* what this node knows this link as */
- void *private; /* node dependant ID for this hook */
- int flags; /* info about this hook/link */
- int refs; /* dont actually free this till 0 */
- struct ng_hook *peer; /* the other end of this link */
- struct ng_node *node; /* The node this hook is attached to */
- LIST_ENTRY(ng_hook) hooks; /* linked list of all hooks on node */
+ char hk_name[NG_HOOKLEN+1]; /* what this node knows this link as */
+ void *hk_private; /* node dependant ID for this hook */
+ int hk_flags; /* info about this hook/link */
+ int hk_refs; /* dont actually free this till 0 */
+ 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 */
+#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 */ /*----------------------------------------------*/
};
-typedef struct ng_hook *hook_p;
-
/* Flags for a hook */
#define HK_INVALID 0x0001 /* don't trust it! */
#define HK_QUEUE 0x0002 /* queue for later delivery */
#define HK_FORCE_WRITER 0x0004 /* Incoming data queued as a writer */
/*
+ * 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 */
+#define _NG_HOOK_REF(hook) atomic_add_int(&(hook)->hk_refs, 1)
+#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)
+#define _NG_HOOK_PRIVATE(hook) ((hook)->hk_private)
+#define _NG_HOOK_NOT_VALID(hook) ((hook)->hk_flags & HK_INVALID)
+#define _NG_HOOK_IS_VALID(hook) (!(hook)->hk_flags & HK_INVALID)
+#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)
+
+/* 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,
+ void * 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 void __inline
+_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_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);
+}
+
+
+#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_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_)
+
+#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)
+#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)
+
+#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
+
+/***********************************************************************
+ ***************** Node Structure and Methods **************************
+ ***********************************************************************
* Structure of a node
+ * including the eembedded queue structure.
+ *
+ * The structure for queueing Netgraph request items
+ * embedded in the node structure
*/
+struct ng_queue {
+ u_long q_flags;
+ struct mtx q_mtx;
+ item_p queue;
+ item_p *last;
+ struct ng_node *q_node; /* find the front of the node.. */
+};
+
struct ng_node {
- char name[NG_NODELEN+1]; /* optional globally unique name */
- struct ng_type *type; /* the installed 'type' */
- int flags; /* see below for bit definitions */
- int refs; /* number of references to this node */
- int numhooks; /* number of hooks */
- void *private; /* node type dependant node ID */
- ng_ID_t ID; /* Unique per node */
- LIST_HEAD(hooks, ng_hook) hooks; /* linked list of node hooks */
- LIST_ENTRY(ng_node) nodes; /* linked list of all nodes */
- LIST_ENTRY(ng_node) idnodes; /* ID hash collision list */
- TAILQ_ENTRY(ng_node) work; /* nodes with work to do */
- struct ng_queue input_queue; /* input queue for locking */
+ char nd_name[NG_NODELEN+1]; /* optional globally unique name */
+ struct ng_type *nd_type; /* the installed 'type' */
+ int nd_flags; /* see below for bit definitions */
+ int nd_refs; /* # of references to this node */
+ 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 */
+ LIST_ENTRY(ng_node) nd_nodes; /* linked list of all nodes */
+ LIST_ENTRY(ng_node) nd_idnodes; /* ID hash collision list */
+ TAILQ_ENTRY(ng_node) nd_work; /* nodes with work to do */
+ struct ng_queue nd_input_queue; /* input queue for locking */
+#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 */ /*----------------------------------------------*/
};
-typedef struct ng_node *node_p;
/* Flags for a node */
#define NG_INVALID 0x00000001 /* free when refs go to 0 */
@@ -113,6 +314,193 @@ typedef struct ng_node *node_p;
#define NGF_TYPE4 0x80000000 /* reserved for type specific storage */
/*
+ * Public methods for nodes.
+ * If you can't do it with these you probably shouldn't be doing it.
+ */
+void ng_unref_node(node_p node); /* don't move this */
+#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)
+#define _NG_NODE_REF(node) atomic_add_int(&(node)->nd_refs, 1)
+#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)
+#define _NG_NODE_IS_VALID(node) (!((node)->nd_flags & NG_INVALID))
+#define _NG_NODE_NOT_VALID(node) ((node)->nd_flags & NG_INVALID)
+#define _NG_NODE_NUMHOOKS(node) ((node)->nd_numhooks + 0) /* rvalue */
+#define _NG_NODE_FORCE_WRITER(node) \
+ do{ node->nd_flags |= NG_FORCE_WRITER; }while (0)
+/*
+ * 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 { \
+ hook_p hook; \
+ LIST_FOREACH(hook, &((node)->nd_hooks), hk_hooks) { \
+ if ((fn)(hook, arg) == 0) { \
+ (rethook) = hook; \
+ break; \
+ } \
+ } \
+ } while (0)
+
+#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
+void dumpnode(node_p node, char *file, int line);
+static void __inline _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 void _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 void __inline
+_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 void
+_ng_node_unref(node_p node, char *file, int line)
+{
+ _chknode(node, file, line);
+ _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 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_NUMHOOKS(node) _ng_node_numhooks(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_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)
+#define NG_NODE_NUMHOOKS(node) _NG_NODE_NUMHOOKS(node)
+#define NG_NODE_FOREACH_HOOK(node, fn, arg, rethook) \
+ _NG_NODE_FOREACH_HOOK(node, fn, arg, rethook)
+#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
+
+/***********************************************************************
+ ***************** Meta Data Structures and Methods ********************
+ ***********************************************************************
+ *
* The structure that holds meta_data about a data packet (e.g. priority)
* Nodes might add or subtract options as needed if there is room.
* They might reallocate the struct to make more room if they need to.
@@ -145,64 +533,11 @@ typedef struct ng_meta *meta_p;
#define NGMF_TEST 0x01 /* discard at the last moment before sending */
#define NGMF_TRACE 0x02 /* trace when handing this data to a node */
-/* node method definitions */
-typedef int ng_constructor_t(node_p node);
-typedef int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook);
-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_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);
-/*
- * 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).
+/***********************************************************************
+ ************* Node Queue and Item Structures and Methods **************
+ ***********************************************************************
+ *
*/
-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 */
- 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 */
-};
-
struct ng_item {
u_long el_flags;
item_p el_next;
@@ -218,12 +553,11 @@ struct ng_item {
ng_ID_t msg_retaddr;
} msg;
} body;
-#define ITEM_DEBUG
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
char *lastfile;
int lastline;
TAILQ_ENTRY(ng_item) all; /* all existing items */
-#endif /* ITEM_DEBUG */
+#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
};
#define NGQF_D_M 0x01 /* MASK of data/message */
#define NGQF_DATA 0x01 /* the queue element is data */
@@ -234,23 +568,6 @@ struct ng_item {
#define NGQF_FREE 0x04
/*
- * 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 ITEM_DEBUG version so we cannot mix debug and non debug
- * modules.
- */
-#define _NG_ABI_VERSION 5
-#ifdef ITEM_DEBUG
-#define NG_ABI_VERSION (_NG_ABI_VERSION + 0x10000)
-#else /* ITEM_DEBUG */
-#define NG_ABI_VERSION _NG_ABI_VERSION
-#endif /* ITEM_DEBUG */
-
-/**********************************************************************
-* Queue item macros. Peek and extract values.
-**********************************************************************/
-/*
* 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).
@@ -265,13 +582,15 @@ struct ng_item {
#define _NGI_MSG(i) ((i)->body.msg.msg_msg)
#define _NGI_RETADDR(i) ((i)->body.msg.msg_retaddr)
-#ifdef ITEM_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 meta_p * _ngi_meta(item_p item, char *file, int line) ;
-static __inline struct ng_mesg ** _ngi_msg(item_p item, char *file, int line) ;
-static __inline ng_ID_t * _ngi_retaddr(item_p item, char *file, int line) ;
+#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 meta_p * _ngi_meta(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 void
_ngi_check(item_p item, char *file, int line)
@@ -312,13 +631,13 @@ _ngi_retaddr(item_p item, char *file, int line)
return (&_NGI_RETADDR(item));
}
-#define NGI_M(i) (*_ngi_m(i, __FILE__, __LINE__))
+#define NGI_M(i) (*_ngi_m(i, _NN_))
-#define NGI_META(i) (*_ngi_meta(i, __FILE__, __LINE__))
+#define NGI_META(i) (*_ngi_meta(i, _NN_))
-#define NGI_MSG(i) (*_ngi_msg(i, __FILE__, __LINE__))
+#define NGI_MSG(i) (*_ngi_msg(i, _NN_))
-#define NGI_RETADDR(i) (*_ngi_retaddr(i, __FILE__, __LINE__))
+#define NGI_RETADDR(i) (*_ngi_retaddr(i, _NN_))
#define NGI_GET_M(i,m) \
do { \
@@ -340,7 +659,7 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NG_FREE_ITEM(item) \
do { \
- _ngi_check(item, __FILE__, __LINE__); \
+ _ngi_check(item, _NN_); \
ng_free_item((item)); \
} while (0)
@@ -350,8 +669,7 @@ _ngi_retaddr(item_p item, char *file, int line)
(item)->lastfile = __FILE__; \
} while (0)
-#else /* ITEM_DEBUG */
-
+#else /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
#define NGI_M(i) _NGI_M(i)
#define NGI_META(i) _NGI_META(i)
@@ -363,14 +681,14 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NGI_GET_MSG(i,m) do {m = NGI_MSG(i); NGI_MSG(i) = NULL; } while (0)
#define NG_FREE_ITEM(item) ng_free_item((item))
-#define SAVE_LINE(item)
+#define SAVE_LINE(item) do {} while (0)
-#endif /* ITEM_DEBUG */
+#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
/**********************************************************************
* Data macros. Send, manipulate and free.
**********************************************************************/
-/* Send data packet including a possible sync response pointer */
+/* Send previously unpackeged data and metadata. */
#define NG_SEND_DATA(error, hook, m, meta) \
do { \
item_p item; \
@@ -387,6 +705,7 @@ _ngi_retaddr(item_p item, char *file, int line)
(meta) = NULL; \
} while (0)
+/* Send a previously unpackaged mbuf when we have no metadata to send */
#define NG_SEND_DATA_ONLY(error, hook, m) \
do { \
item_p item; \
@@ -405,7 +724,10 @@ _ngi_retaddr(item_p item, char *file, int line)
/*
* Forward a data packet with no new meta-data.
* old metadata is passed along without change.
- * Mbuf pointer is updated to new value.
+ * 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
*/
#define NG_FWD_NEW_DATA(error, item, hook, m) \
do { \
@@ -422,7 +744,7 @@ _ngi_retaddr(item_p item, char *file, int line)
/*
* Assuming the data is already ok, just set the new address and send
*/
-#define NG_FWD_DATA(error, item, hook) \
+#define NG_FWD_ITEM_HOOK(error, item, hook) \
do { \
if (!((error) = ng_address_hook(NULL, (item), \
(hook), NULL))) { \
@@ -462,12 +784,7 @@ _ngi_retaddr(item_p item, char *file, int line)
(m) = NULL; \
} \
} while (0)
-/* Free any data packet and/or meta-data */
-#define NG_FREE_DATAX(m, meta) \
- do { \
- NG_FREE_M((m)); \
- NG_FREE_META((meta)); \
- } while (0)
+
/*****************************************
* Message macros
*****************************************/
@@ -475,13 +792,15 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NG_SEND_MSG_HOOK(error, here, msg, hook, retaddr) \
do { \
item_p item; \
- if ((item = ng_package_msg(msg)) \
- && (ng_address_hook((here), (item), \
- (hook), (retaddr)) == 0)) { \
+ if ((item = ng_package_msg(msg)) == NULL) { \
+ (msg) = NULL; \
+ (error) = ENOMEM; \
+ break; \
+ } \
+ if (((error) = ng_address_hook((here), (item), \
+ (hook), (retaddr))) == 0) { \
SAVE_LINE(item); \
(error) = ng_snd_item((item), 0); \
- } else { \
- (error) = EINVAL; \
} \
(msg) = NULL; \
} while (0)
@@ -489,13 +808,15 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NG_SEND_MSG_PATH(error, here, msg, path, retaddr) \
do { \
item_p item; \
- if ((item = ng_package_msg(msg)) \
- && (ng_address_path((here), (item), \
- (path), (retaddr)) == 0)) { \
+ if ((item = ng_package_msg(msg)) == NULL) { \
+ (msg) = NULL; \
+ (error) = ENOMEM; \
+ break; \
+ } \
+ if (((error) = ng_address_path((here), (item), \
+ (path), (retaddr))) == 0) { \
SAVE_LINE(item); \
(error) = ng_snd_item((item), 0); \
- } else { \
- (error) = EINVAL; \
} \
(msg) = NULL; \
} while (0)
@@ -503,13 +824,15 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NG_SEND_MSG_ID(error, here, msg, ID, retaddr) \
do { \
item_p item; \
- if ((item = ng_package_msg(msg)) \
- && (ng_address_ID((here), (item), \
- (ID), (retaddr)) == 0)) { \
+ if ((item = ng_package_msg(msg)) == NULL) { \
+ (msg) = NULL; \
+ (error) = ENOMEM; \
+ break; \
+ } \
+ if (((error) = ng_address_ID((here), (item), \
+ (ID), (retaddr))) == 0) { \
SAVE_LINE(item); \
(error) = ng_snd_item((item), 0); \
- } else { \
- (error) = EINVAL; \
} \
(msg) = NULL; \
} while (0)
@@ -517,13 +840,15 @@ _ngi_retaddr(item_p item, char *file, int line)
#define NG_QUEUE_MSG(error, here, msg, path, retaddr) \
do { \
item_p item; \
- if ((item = ng_package_msg(msg)) \
- && (ng_address_path((here), (item), \
- (path), (retaddr)) == 0)) { \
+ if ((item = ng_package_msg(msg)) == NULL) { \
+ (msg) = NULL; \
+ (error) = ENOMEM; \
+ break; \
+ } \
+ if (((error) = ng_address_path((here), (item), \
+ (path), (retaddr))) == 0) { \
SAVE_LINE(item); \
- (error) = ng_snd_item((item), 0); \
- } else { \
- (error) = EINVAL; \
+ (error) = ng_snd_item((item), 1); \
} \
(msg) = NULL; \
} while (0)
@@ -535,12 +860,10 @@ _ngi_retaddr(item_p item, char *file, int line)
*/
#define NG_FWD_MSG_HOOK(error, here, item, hook, retaddr) \
do { \
- if ((ng_address_hook((here), (item), \
+ if (((error) = ng_address_hook((here), (item), \
(hook), (retaddr))) == 0) { \
SAVE_LINE(item); \
(error) = ng_snd_item((item), 0); \
- } else { \
- (error) = EINVAL; \
} \
(item) = NULL; \
} while (0)
@@ -569,6 +892,72 @@ _ngi_retaddr(item_p item, char *file, int line)
} while (0)
+/***********************************************************************
+ ******** Structures Definitions and Macros for defining a node *******
+ ***********************************************************************
+ *
+ * Here we define the structures needed to actually define a new node
+ * type.
+ */
+
+/* node method definitions */
+typedef int ng_constructor_t(node_p node);
+typedef int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook);
+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_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);
+/*
+ * 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 */
+ 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 */
+};
+
/*
* Use the NETGRAPH_INIT() macro to link a node type into the
* netgraph system. This works for types compiled into the kernel
@@ -601,17 +990,17 @@ MALLOC_DECLARE(M_NETGRAPH_META);
-/* Methods that should go away (or become private)*/
-/* Methods that should exist */
+/*
+ * Methods that the nodes can use.
+ * Many of these methods should usually NOT be used directly but via
+ * Macros above.
+ */
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);
-int ng_address_path(node_p here, item_p item,
- char *address, ng_ID_t retaddr);
+int ng_address_path(node_p here, item_p item, char *address, ng_ID_t raddr);
meta_p ng_copy_meta(meta_p meta);
hook_p ng_findhook(node_p node, const char *name);
-void ng_free_item(item_p item);
int ng_make_node_common(struct ng_type *typep, node_p *nodep);
-int ng_mod_event(module_t mod, int what, void *arg);
int ng_name_node(node_p node, const char *name);
int ng_newtype(struct ng_type *tp);
ng_ID_t ng_node2ID(node_p node);
@@ -621,8 +1010,12 @@ 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);
int ng_rmnode_self(node_p here);
int ng_snd_item(item_p item, int queue);
-void ng_unname(node_p node);
-void ng_unref(node_p node);
+
+/*
+ * prototypes the user should DEFINITLY not use directly
+ */
+void ng_free_item(item_p item); /* Use NG_FREE_ITEM instead */
+int ng_mod_event(module_t mod, int what, void *arg);
#endif /* _NETGRAPH_NETGRAPH_H_ */
diff --git a/sys/netgraph/ng_UI.c b/sys/netgraph/ng_UI.c
index faf4f55..fdf03bd 100644
--- a/sys/netgraph/ng_UI.c
+++ b/sys/netgraph/ng_UI.c
@@ -101,7 +101,7 @@ NETGRAPH_INIT(UI, &typestruct);
*/
static int
-ng_UI_constructor(node_p nodep)
+ng_UI_constructor(node_p node)
{
priv_p priv;
@@ -110,7 +110,7 @@ ng_UI_constructor(node_p nodep)
if (priv == NULL) {
return (ENOMEM);
}
- nodep->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
return (0);
}
@@ -120,7 +120,7 @@ ng_UI_constructor(node_p nodep)
static int
ng_UI_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
if (!strcmp(name, NG_UI_HOOK_DOWNSTREAM)) {
if (priv->downlink)
@@ -142,27 +142,25 @@ static int
ng_UI_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
int error;
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *msg;
msg = NGI_MSG(item); /* only peeking */
if ((msg->header.typecookie == NGM_FLOW_COOKIE) && lasthook) {
if (lasthook == priv->downlink) {
if (priv->uplink) {
- NG_FWD_MSG_HOOK(error, node, item,
- priv->uplink, 0);
+ NG_FWD_ITEM_HOOK(error, item, priv->uplink);
return (error);
}
} else {
if (priv->downlink) {
- NG_FWD_MSG_HOOK(error, node, item,
- priv->downlink, 0);
+ NG_FWD_ITEM_HOOK(error, item, priv->downlink);
return (error);
}
}
}
- NG_FREE_MSG(msg);
+ NG_FREE_ITEM(item);
return (EINVAL);
}
@@ -175,8 +173,8 @@ ng_UI_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_UI_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m;
int error = 0;
@@ -217,12 +215,12 @@ done:
static int
ng_UI_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Take down netgraph node */
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -232,7 +230,7 @@ ng_UI_shutdown(node_p node)
static int
ng_UI_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
if (hook == priv->downlink)
priv->downlink = NULL;
@@ -244,9 +242,9 @@ ng_UI_disconnect(hook_p hook)
* If we are not already shutting down,
* and we have no more hooks, then DO shut down.
*/
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0)) {
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
}
return (0);
}
diff --git a/sys/netgraph/ng_async.c b/sys/netgraph/ng_async.c
index 8f9e118..426ddd8 100644
--- a/sys/netgraph/ng_async.c
+++ b/sys/netgraph/ng_async.c
@@ -197,7 +197,7 @@ fail:
FREE(sc, M_NETGRAPH);
return (ENOMEM);
}
- node->private = sc;
+ NG_NODE_SET_PRIVATE(node, sc);
sc->node = node;
return (0);
}
@@ -208,7 +208,7 @@ fail:
static int
nga_newhook(node_p node, hook_p hook, const char *name)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
hook_p *hookp;
if (!strcmp(name, NG_ASYNC_HOOK_ASYNC)) {
@@ -217,7 +217,7 @@ nga_newhook(node_p node, hook_p hook, const char *name)
* at a time can be allowed to travel in this direction.
* Force Writer semantics.
*/
- hook->flags |= HK_FORCE_WRITER;
+ NG_HOOK_FORCE_WRITER(hook);
hookp = &sc->async;
} else if (!strcmp(name, NG_ASYNC_HOOK_SYNC)) {
/*
@@ -228,8 +228,7 @@ nga_newhook(node_p node, hook_p hook, const char *name)
* we might as well set it for the whole node
* bit I haven;t done that (yet).
*/
- hook->flags |= HK_FORCE_WRITER;
- hookp = &sc->async;
+ NG_HOOK_FORCE_WRITER(hook);
hookp = &sc->sync;
} else {
return (EINVAL);
@@ -246,10 +245,7 @@ nga_newhook(node_p node, hook_p hook, const char *name)
static int
nga_rcvdata(hook_p hook, item_p item)
{
- const sc_p sc = hook->node->private;
-#ifdef ITEM_DEBUG
- meta_p meta = NGI_META(item);
-#endif
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
if (hook == sc->sync)
return (nga_rcv_sync(sc, item));
@@ -264,12 +260,11 @@ nga_rcvdata(hook_p hook, item_p item)
static int
nga_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const sc_p sc = (sc_p) node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
-
NGI_GET_MSG(item, msg);
switch (msg->header.typecookie) {
case NGM_ASYNC_COOKIE:
@@ -347,14 +342,14 @@ done:
static int
nga_shutdown(node_p node)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
FREE(sc->abuf, M_NETGRAPH);
FREE(sc->sbuf, M_NETGRAPH);
bzero(sc, sizeof(*sc));
FREE(sc, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -364,7 +359,7 @@ nga_shutdown(node_p node)
static int
nga_disconnect(hook_p hook)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
hook_p *hookp;
if (hook == sc->async)
@@ -378,9 +373,9 @@ nga_disconnect(hook_p hook)
*hookp = NULL;
bzero(&sc->stats, sizeof(sc->stats));
sc->lasttime = 0;
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
@@ -422,7 +417,7 @@ nga_rcv_sync(const sc_p sc, item_p item)
/* Check for bypass mode */
if (!sc->cfg.enabled) {
- NG_FWD_DATA(error, item, sc->async );
+ NG_FWD_ITEM_HOOK(error, item, sc->async );
return (error);
}
NGI_GET_M(item, m);
@@ -510,7 +505,7 @@ nga_rcv_async(const sc_p sc, item_p item)
struct mbuf *m;
if (!sc->cfg.enabled) {
- NG_FWD_DATA(error, item, sc->sync);
+ NG_FWD_ITEM_HOOK(error, item, sc->sync);
return (error);
}
NGI_GET_M(item, m);
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index 0cbd63d..975f8fb 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -65,11 +65,23 @@
MODULE_VERSION(netgraph, 1);
-/* List of all nodes */
+/* List of all active nodes */
static LIST_HEAD(, ng_node) ng_nodelist;
static struct mtx ng_nodelist_mtx;
-/* NETISR queue */
+#ifdef NETGRAPH_DEBUG
+
+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 */
+
/* List nodes with unallocated work */
static TAILQ_HEAD(, ng_node) ng_worklist = TAILQ_HEAD_INITIALIZER(ng_worklist);
static struct mtx ng_worklist_mtx;
@@ -102,7 +114,7 @@ static void ng_flush_input_queue(struct ng_queue * ngq);
static void ng_setisr(node_p node);
static node_p ng_ID2noderef(ng_ID_t ID);
-/* imported */
+/* imported , these used to be externally visible, some may go back */
int ng_bypass(hook_p hook1, hook_p hook2);
void ng_cutlinks(node_p node);
int ng_con_nodes(node_p node, const char *name, node_p node2,
@@ -116,6 +128,7 @@ int ng_make_node(const char *type, node_p *nodepp);
int ng_mkpeer(node_p node, const char *name, const char *name2, char *type);
int ng_path_parse(char *addr, char **node, char **path, char **hook);
void ng_rmnode(node_p node);
+void ng_unname(node_p node);
/* Our own netgraph malloc type */
@@ -127,9 +140,105 @@ MALLOC_DEFINE(M_NETGRAPH_META, "netgraph_meta", "netgraph name storage");
MALLOC_DEFINE(M_NETGRAPH_MSG, "netgraph_msg", "netgraph name storage");
/* Should not be visible outside this file */
+
+#define _NG_ALLOC_HOOK(hook) \
+ MALLOC(hook, hook_p, sizeof(*hook), M_NETGRAPH_HOOK, M_NOWAIT | M_ZERO)
+#define _NG_ALLOC_NODE(node) \
+ MALLOC(node, node_p, sizeof(*node), M_NETGRAPH_NODE, M_NOWAIT | M_ZERO)
+
+#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_enter(&ng_nodelist_mtx, MTX_DEF);
+ 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_exit(&ng_nodelist_mtx, MTX_DEF);
+ hook->hk_magic = HK_MAGIC;
+ } else {
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF);
+ _NG_ALLOC_HOOK(hook);
+ if (hook) {
+ hook->hk_magic = HK_MAGIC;
+ mtx_enter(&ng_nodelist_mtx, MTX_DEF);
+ SLIST_INSERT_HEAD(&ng_allhooks, hook, hk_all);
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF);
+ }
+ }
+ return (hook);
+}
+
+static __inline node_p
+ng_alloc_node(void)
+{
+ node_p node;
+ SLIST_ENTRY(ng_node) temp;
+ mtx_enter(&ng_nodelist_mtx, MTX_DEF);
+ 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_exit(&ng_nodelist_mtx, MTX_DEF);
+ node->nd_magic = ND_MAGIC;
+ } else {
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF);
+ _NG_ALLOC_NODE(node);
+ if (node) {
+ node->nd_magic = ND_MAGIC;
+ mtx_enter(&ng_nodelist_mtx, MTX_DEF);
+ SLIST_INSERT_HEAD(&ng_allnodes, node, nd_all);
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF);
+ }
+ }
+ 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_enter(&ng_nodelist_mtx, MTX_DEF); \
+ LIST_INSERT_HEAD(&ng_freehooks, hook, hk_hooks); \
+ hook->hk_magic = 0; \
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF); \
+ } while (0)
+
+#define NG_FREE_NODE(node) \
+ do { \
+ mtx_enter(&ng_nodelist_mtx, MTX_DEF); \
+ LIST_INSERT_HEAD(&ng_freenodes, node, nd_nodes); \
+ node->nd_magic = 0; \
+ mtx_exit(&ng_nodelist_mtx, MTX_DEF); \
+ } 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 { FREE((hook), M_NETGRAPH_HOOK); } while (0)
#define NG_FREE_NODE(node) do { FREE((node), M_NETGRAPH_NODE); } while (0)
-#define NG_FREE_NAME(name) do { FREE((name), M_NETGRAPH_NAME); } while (0)
+
+#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
+
/* Warning: Generally use NG_FREE_ITEM() instead */
#define NG_FREE_ITEM_REAL(item) do { FREE((item), M_NETGRAPH_ITEM); } while (0)
@@ -384,7 +493,7 @@ ng_make_node(const char *typename, node_p *nodepp)
if (type->constructor != NULL) {
if ((error = ng_make_node_common(type, nodepp)) == 0) {
if ((error = ((*type->constructor)(*nodepp)) != 0)) {
- ng_unref(*nodepp);
+ NG_NODE_UNREF(*nodepp);
}
}
} else {
@@ -395,6 +504,7 @@ ng_make_node(const char *typename, node_p *nodepp)
* call ng_make_node_common() directly to get the
* netgraph part initialised.
*/
+ TRAP_ERROR
error = EINVAL;
}
return (error);
@@ -417,44 +527,48 @@ ng_make_node_common(struct ng_type *type, node_p *nodepp)
}
/* Make a node and try attach it to the type */
- MALLOC(node, node_p, sizeof(*node), M_NETGRAPH_NODE, M_NOWAIT | M_ZERO);
+ NG_ALLOC_NODE(node);
if (node == NULL) {
TRAP_ERROR;
return (ENOMEM);
}
- node->type = type;
- node->refs++; /* note reference */
+ node->nd_type = type;
+ NG_NODE_REF(node); /* note reference */
type->refs++;
- mtx_init(&node->input_queue.q_mtx, "netgraph node mutex", 0);
- node->input_queue.queue = NULL;
- node->input_queue.last = &node->input_queue.queue;
- node->input_queue.q_flags = 0;
- node->input_queue.q_node = node;
+ mtx_init(&node->nd_input_queue.q_mtx, "netgraph node mutex", 0);
+ node->nd_input_queue.queue = NULL;
+ node->nd_input_queue.last = &node->nd_input_queue.queue;
+ node->nd_input_queue.q_flags = 0;
+ node->nd_input_queue.q_node = node;
/* Initialize hook list for new node */
- LIST_INIT(&node->hooks);
+ LIST_INIT(&node->nd_hooks);
/* Link us into the node linked list */
mtx_enter(&ng_nodelist_mtx, MTX_DEF);
- LIST_INSERT_HEAD(&ng_nodelist, node, nodes);
+ LIST_INSERT_HEAD(&ng_nodelist, node, nd_nodes);
mtx_exit(&ng_nodelist_mtx, MTX_DEF);
/* get an ID and put us in the hash chain */
mtx_enter(&ng_idhash_mtx, MTX_DEF);
- do { /* wrap protection, even if silly */
+ for (;;) { /* wrap protection, even if silly */
node_p node2 = NULL;
- node->ID = nextID++; /* 137 per second for 1 year before wrap */
- if ((node->ID == 0) || (node2 = ng_ID2noderef(node->ID))) {
+ node->nd_ID = nextID++; /* 137/second for 1 year before wrap */
+ /* Is there a problem with the new number? */
+ if ((node->nd_ID == 0)
+ || (node2 = ng_ID2noderef(node->nd_ID))) {
if (node2) {
- ng_unref(node2);
+ NG_NODE_UNREF(node2);
node2 = NULL;
}
- continue; /* try again */
+ } else {
+ break;
}
- } while (0);
- LIST_INSERT_HEAD(&ng_ID_hash[node->ID % ID_HASH_SIZE], node, idnodes);
+ }
+ LIST_INSERT_HEAD(&ng_ID_hash[node->nd_ID % ID_HASH_SIZE],
+ node, nd_idnodes);
mtx_exit(&ng_idhash_mtx, MTX_DEF);
/* Done */
@@ -477,41 +591,69 @@ void
ng_rmnode(node_p node)
{
/* Check if it's already shutting down */
- if ((node->flags & NG_CLOSING) != 0)
+ if ((node->nd_flags & NG_CLOSING) != 0)
return;
/* Add an extra reference so it doesn't go away during this */
- node->refs++;
+ NG_NODE_REF(node);
- /* Mark it invalid so any newcomers know not to try use it */
- node->flags |= NG_INVALID|NG_CLOSING;
+ /*
+ * Mark it invalid so any newcomers know not to try use it
+ * Also add our own mark so we can't recurse
+ * note that NG_INVALID does not do this as it's also set during
+ * creation
+ */
+ node->nd_flags |= NG_INVALID|NG_CLOSING;
- ng_unname(node);
ng_cutlinks(node);
+
/*
* Drain the input queue forceably.
+ * it has no hooks so what's it going to do, bleed on someone?
+ * Theoretically we came here from a queue entry that was added
+ * Just before the queue was closed, so it should be empty anyway.
*/
- ng_flush_input_queue(&node->input_queue);
+ ng_flush_input_queue(&node->nd_input_queue);
/*
* Take us off the work queue if we are there.
+ * We definatly have no work to be done.
*/
ng_worklist_remove(node);
-
/* Ask the type if it has anything to do in this case */
- if (node->type && node->type->shutdown) {
- (*node->type->shutdown)(node);
+ if (node->nd_type && node->nd_type->shutdown) {
+ (*node->nd_type->shutdown)(node);
} else { /* do the default thing */
- ng_unref(node); /* XXX hmmmmm check this */
+ NG_NODE_UNREF(node);
+ }
+ if (NG_NODE_IS_VALID(node)) {
+ /*
+ * Well, blow me down if the node code hasn't declared
+ * that it doesn't want to die.
+ * Presumably it is a persistant node.
+ * XXX we need a way to tell the node
+ * "No, really.. the hardware's going away.. REALLY die"
+ * We need a way
+ */
+ return;
}
- /* Remove extra reference, possibly the last */
- ng_unref(node);
+ ng_unname(node); /* basically a NOP these days */
+
+ /*
+ * Remove extra reference, possibly the last
+ * Possible other holders of references may include
+ * timeout callouts, but theoretically the node's supposed to
+ * have cancelled them. Possibly hardware dependencies may
+ * force a driver to 'linger' with a reference.
+ */
+ NG_NODE_UNREF(node);
}
/*
* Called by the destructor to remove any STANDARD external references
+ * May one day have it's own message to call it..
*/
void
ng_cutlinks(node_p node)
@@ -519,17 +661,17 @@ ng_cutlinks(node_p node)
hook_p hook;
/* Make sure that this is set to stop infinite loops */
- node->flags |= NG_INVALID;
+ node->nd_flags |= NG_INVALID;
/*
* Drain the input queue forceably.
* We also do this in ng_rmnode
* to make sure we get all code paths.
*/
- ng_flush_input_queue(&node->input_queue);
+ ng_flush_input_queue(&node->nd_input_queue);
/* Notify all remaining connected nodes to disconnect */
- while ((hook = LIST_FIRST(&node->hooks)) != NULL)
+ while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL)
ng_destroy_hook(hook);
}
@@ -537,26 +679,26 @@ ng_cutlinks(node_p node)
* Remove a reference to the node, possibly the last
*/
void
-ng_unref(node_p node)
+ng_unref_node(node_p node)
{
- int s;
+ int v;
+ do {
+ v = node->nd_refs;
+ } while (! atomic_cmpset_int(&node->nd_refs, v, v - 1));
- s = splhigh();
-/* XXX not atomic.. fix */
- if (--node->refs <= 0) {
+ if (v == 1) { /* we were the last */
mtx_enter(&ng_nodelist_mtx, MTX_DEF);
- node->type->refs--; /* XXX maybe should get types lock? */
- LIST_REMOVE(node, nodes);
+ node->nd_type->refs--; /* XXX maybe should get types lock? */
+ LIST_REMOVE(node, nd_nodes);
mtx_exit(&ng_nodelist_mtx, MTX_DEF);
mtx_enter(&ng_idhash_mtx, MTX_DEF);
- LIST_REMOVE(node, idnodes);
+ LIST_REMOVE(node, nd_idnodes);
mtx_exit(&ng_idhash_mtx, MTX_DEF);
NG_FREE_NODE(node);
}
- splx(s);
}
/************************************************************************
@@ -565,22 +707,22 @@ ng_unref(node_p node)
static node_p
ng_ID2noderef(ng_ID_t ID)
{
- node_p np;
+ node_p node;
mtx_enter(&ng_idhash_mtx, MTX_DEF);
- LIST_FOREACH(np, &ng_ID_hash[ID % ID_HASH_SIZE], idnodes) {
- if (np->ID == ID)
+ LIST_FOREACH(node, &ng_ID_hash[ID % ID_HASH_SIZE], nd_idnodes) {
+ if (node->nd_ID == ID)
break;
}
- if(np)
- np->refs++;
+ if(node)
+ NG_NODE_REF(node);
mtx_exit(&ng_idhash_mtx, MTX_DEF);
- return(np);
+ return(node);
}
ng_ID_t
ng_node2ID(node_p node)
{
- return (node?node->ID:0);
+ return (node?node->nd_ID:0);
}
/************************************************************************
@@ -612,13 +754,13 @@ ng_name_node(node_p node, const char *name)
/* Check the name isn't already being used */
if ((node2 = ng_name2noderef(node, name)) != NULL) {
- ng_unref(node2);
+ NG_NODE_UNREF(node2);
TRAP_ERROR;
return (EADDRINUSE);
}
/* copy it */
- strcpy(node->name, name);
+ strncpy(NG_NODE_NAME(node), name, NG_NODELEN);
return (0);
}
@@ -630,7 +772,7 @@ ng_name_node(node_p node, const char *name)
*
* Returns the node if found, else NULL.
* Eventually should add something faster than a sequential search.
- * Note it holds a reference on the node so you an be sure it's still there.
+ * Note it aquires a reference on the node so you can be sure it's still there.
*/
node_p
ng_name2noderef(node_p here, const char *name)
@@ -640,7 +782,7 @@ ng_name2noderef(node_p here, const char *name)
/* "." means "this node" */
if (strcmp(name, ".") == 0) {
- here->refs++;
+ NG_NODE_REF(here);
return(here);
}
@@ -651,12 +793,13 @@ ng_name2noderef(node_p here, const char *name)
/* Find node by name */
mtx_enter(&ng_nodelist_mtx, MTX_DEF);
- LIST_FOREACH(node, &ng_nodelist, nodes) {
- if (node->name[0] != '\0' && strcmp(node->name, name) == 0)
+ LIST_FOREACH(node, &ng_nodelist, nd_nodes) {
+ if (NG_NODE_HAS_NAME(node)
+ && (strcmp(NG_NODE_NAME(node), name) == 0))
break;
}
if (node)
- node->refs++;
+ NG_NODE_REF(node);
mtx_exit(&ng_nodelist_mtx, MTX_DEF);
return (node);
}
@@ -691,7 +834,7 @@ ng_decodeidname(const char *name)
void
ng_unname(node_p node)
{
- bzero(node->name, NG_NODELEN);
+ bzero(NG_NODE_NAME(node), NG_NODELEN);
}
/************************************************************************
@@ -703,21 +846,21 @@ ng_unname(node_p node)
/*
* Remove a hook reference
*/
-static void
+void
ng_unref_hook(hook_p hook)
{
- int s;
+ int v;
+ do {
+ v = hook->hk_refs;
+ } while (! atomic_cmpset_int(&hook->hk_refs, v, v - 1));
- s = splhigh();
-/* XXX not atomic.. fix */
- if (--hook->refs == 0) {
- if (hook->node) {
- ng_unref(hook->node);
- hook->node = NULL;
+ if (v == 1) { /* we were the last */
+ if (NG_HOOK_NODE(hook)) {
+ NG_NODE_UNREF((NG_HOOK_NODE(hook)));
+ hook->hk_node = NULL;
}
NG_FREE_HOOK(hook);
}
- splx(s);
}
/*
@@ -740,20 +883,20 @@ ng_add_hook(node_p node, const char *name, hook_p *hookp)
}
/* Allocate the hook and link it up */
- MALLOC(hook, hook_p, sizeof(*hook), M_NETGRAPH_HOOK, M_NOWAIT | M_ZERO);
+ NG_ALLOC_HOOK(hook);
if (hook == NULL) {
TRAP_ERROR;
return (ENOMEM);
}
- hook->refs = 1;
- hook->flags = HK_INVALID;
- hook->node = node;
- node->refs++; /* each hook counts as a reference */
+ hook->hk_refs = 1;
+ hook->hk_flags = HK_INVALID;
+ hook->hk_node = node;
+ NG_NODE_REF(node); /* each hook counts as a reference */
/* Check if the node type code has something to say about it */
- if (node->type->newhook != NULL)
- if ((error = (*node->type->newhook)(node, hook, name)) != 0) {
- ng_unref_hook(hook); /* this frees the hook */
+ if (node->nd_type->newhook != NULL)
+ if ((error = (*node->nd_type->newhook)(node, hook, name)) != 0) {
+ NG_HOOK_UNREF(hook); /* this frees the hook */
return (error);
}
@@ -762,11 +905,11 @@ ng_add_hook(node_p node, const char *name, hook_p *hookp)
* We'll ask again later when we actually connect the hooks.
* The reference we have is for this linkage.
*/
- LIST_INSERT_HEAD(&node->hooks, hook, hooks);
- node->numhooks++;
+ LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks);
+ node->nd_numhooks++;
/* Set hook name */
- strcpy(hook->name, name);
+ strncpy(NG_HOOK_NAME(hook), name, NG_HOOKLEN);
if (hookp)
*hookp = hook;
return (error);
@@ -780,24 +923,24 @@ ng_connect(hook_p hook1, hook_p hook2)
{
int error;
- hook1->peer = hook2;
- hook2->peer = hook1;
+ hook1->hk_peer = hook2;
+ hook2->hk_peer = hook1;
/* Give each node the opportunity to veto the impending connection */
- if (hook1->node->type->connect) {
- if ((error = (*hook1->node->type->connect) (hook1))) {
+ if (hook1->hk_node->nd_type->connect) {
+ if ((error = (*hook1->hk_node->nd_type->connect) (hook1))) {
ng_destroy_hook(hook1); /* also zaps hook2 */
return (error);
}
}
- if (hook2->node->type->connect) {
- if ((error = (*hook2->node->type->connect) (hook2))) {
+ if (hook2->hk_node->nd_type->connect) {
+ if ((error = (*hook2->hk_node->nd_type->connect) (hook2))) {
ng_destroy_hook(hook2); /* also zaps hook1 */
return (error);
}
}
- hook1->flags &= ~HK_INVALID;
- hook2->flags &= ~HK_INVALID;
+ hook1->hk_flags &= ~HK_INVALID;
+ hook2->hk_flags &= ~HK_INVALID;
return (0);
}
@@ -812,10 +955,10 @@ ng_findhook(node_p node, const char *name)
{
hook_p hook;
- if (node->type->findhook != NULL)
- return (*node->type->findhook)(node, name);
- LIST_FOREACH(hook, &node->hooks, hooks) {
- if (strcmp(hook->name, name) == 0)
+ if (node->nd_type->findhook != NULL)
+ return (*node->nd_type->findhook)(node, name);
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
+ if (strcmp(NG_HOOK_NAME(hook), name) == 0)
return (hook);
}
return (NULL);
@@ -831,13 +974,13 @@ ng_findhook(node_p node, const char *name)
void
ng_destroy_hook(hook_p hook)
{
- hook_p peer = hook->peer;
+ hook_p peer = NG_HOOK_PEER(hook);
- hook->flags |= HK_INVALID; /* as soon as possible */
+ hook->hk_flags |= HK_INVALID; /* as soon as possible */
if (peer) {
- peer->flags |= HK_INVALID; /* as soon as possible */
- hook->peer = NULL;
- peer->peer = NULL;
+ peer->hk_flags |= HK_INVALID; /* as soon as possible */
+ hook->hk_peer = NULL;
+ peer->hk_peer = NULL;
ng_disconnect_hook(peer);
}
ng_disconnect_hook(hook);
@@ -853,22 +996,22 @@ ng_destroy_hook(hook_p hook)
static void
ng_disconnect_hook(hook_p hook)
{
- node_p node = hook->node;
+ node_p node = NG_HOOK_NODE(hook);
/*
* Remove the hook from the node's list to avoid possible recursion
* in case the disconnection results in node shutdown.
*/
- LIST_REMOVE(hook, hooks);
- node->numhooks--;
- if (node->type->disconnect) {
+ LIST_REMOVE(hook, hk_hooks);
+ node->nd_numhooks--;
+ if (node->nd_type->disconnect) {
/*
* The type handler may elect to destroy the peer so don't
* trust its existance after this point.
*/
- (*node->type->disconnect) (hook);
+ (*node->nd_type->disconnect) (hook);
}
- ng_unref_hook(hook);
+ NG_HOOK_UNREF(hook);
}
/*
@@ -878,14 +1021,16 @@ ng_disconnect_hook(hook_p hook)
int
ng_bypass(hook_p hook1, hook_p hook2)
{
- if (hook1->node != hook2->node)
+ if (hook1->hk_node != hook2->hk_node) {
+ TRAP_ERROR
return (EINVAL);
- hook1->peer->peer = hook2->peer;
- hook2->peer->peer = hook1->peer;
+ }
+ hook1->hk_peer->hk_peer = hook2->hk_peer;
+ hook2->hk_peer->hk_peer = hook1->hk_peer;
/* XXX If we ever cache methods on hooks update them as well */
- hook1->peer = NULL;
- hook2->peer = NULL;
+ hook1->hk_peer = NULL;
+ hook2->hk_peer = NULL;
ng_destroy_hook(hook1);
ng_destroy_hook(hook2);
return (0);
@@ -1037,11 +1182,11 @@ ng_rmnode_self(node_p here)
* to hold a reference actually to stop it from all
* going up in smoke.
*/
-/* ng_flush_input_queue(&here->input_queue); will mask problem */
+/* ng_flush_input_queue(&here->nd_input_queue); will mask problem */
item = ng_package_msg_self(here, NULL, msg);
if (item == NULL) { /* it would have freed the msg except static */
/* try again after flushing our queue */
- ng_flush_input_queue(&here->input_queue);
+ ng_flush_input_queue(&here->nd_input_queue);
item = ng_package_msg_self(here, NULL, msg);
if (item == NULL) {
printf("failed to free node 0x%x\n", ng_node2ID(here));
@@ -1146,8 +1291,10 @@ ng_path2noderef(node_p here, const char *address,
hook_p hook = NULL;
/* Initialize */
- if (destp == NULL)
+ if (destp == NULL) {
+ TRAP_ERROR
return EINVAL;
+ }
*destp = NULL;
/* Make a writable copy of address for ng_path_parse() */
@@ -1173,7 +1320,7 @@ ng_path2noderef(node_p here, const char *address,
if (nodename) {
node = ng_name2noderef(here, nodename);
if (node == NULL) {
- TRAP_ERROR;
+ TRAP_ERROR
return (ENOENT);
}
} else {
@@ -1182,7 +1329,7 @@ ng_path2noderef(node_p here, const char *address,
return (EINVAL);
}
node = here;
- node->refs++;
+ NG_NODE_REF(node);
}
/*
@@ -1222,11 +1369,20 @@ ng_path2noderef(node_p here, const char *address,
/* Can't get there from here... */
if (hook == NULL
- || hook->peer == NULL
- || (hook->flags & HK_INVALID) != 0
- || (hook->peer->flags & HK_INVALID) != 0) {
+ || NG_HOOK_PEER(hook) == NULL
+ || NG_HOOK_NOT_VALID(hook)
+ || NG_HOOK_NOT_VALID(NG_HOOK_PEER(hook))) {
TRAP_ERROR;
- ng_unref(node);
+ NG_NODE_UNREF(node);
+#if 0
+ printf("hooknotvalid %s %s %d %d %d %d ",
+ path,
+ segment,
+ hook == NULL,
+ NG_HOOK_PEER(hook) == NULL,
+ NG_HOOK_NOT_VALID(hook),
+ NG_HOOK_NOT_VALID(NG_HOOK_PEER(hook)));
+#endif
return (ENOENT);
}
@@ -1238,11 +1394,11 @@ ng_path2noderef(node_p here, const char *address,
* instead of the direct hook in this crawl?
*/
oldnode = node;
- if ((node = hook->peer->node))
- node->refs++; /* XXX RACE */
- ng_unref(oldnode); /* XXX another race */
- if (node->flags & NG_INVALID) {
- ng_unref(node); /* XXX more races */
+ if ((node = NG_PEER_NODE(hook)))
+ NG_NODE_REF(node); /* XXX RACE */
+ NG_NODE_UNREF(oldnode); /* XXX another race */
+ if (NG_NODE_NOT_VALID(node)) {
+ NG_NODE_UNREF(node); /* XXX more races */
node = NULL;
}
}
@@ -1256,7 +1412,7 @@ ng_path2noderef(node_p here, const char *address,
/* Done */
*destp = node;
if (lasthook != NULL)
- *lasthook = (hook ? hook->peer : NULL);
+ *lasthook = (hook ? NG_HOOK_PEER(hook) : NULL);
return (0);
}
@@ -1684,17 +1840,19 @@ ng_snd_item(item_p item, int queue)
int rw;
int error = 0, ierror;
item_p oitem;
- struct ng_queue * ngq = &dest->input_queue;
+ struct ng_queue * ngq = &dest->nd_input_queue;
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
if (item == NULL) {
+ TRAP_ERROR;
return (EINVAL); /* failed to get queue element */
}
if (dest == NULL) {
NG_FREE_ITEM(item);
+ TRAP_ERROR;
return (EINVAL); /* No address */
}
if ((item->el_flags & NGQF_D_M) == NGQF_DATA) {
@@ -1705,21 +1863,21 @@ ng_snd_item(item_p item, int queue)
* the node is derivable from the hook.
* References are held on both by the item.
*/
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
CHECK_DATA_MBUF(NGI_M(item));
if (hook == NULL) {
NG_FREE_ITEM(item);
+ TRAP_ERROR;
return(EINVAL);
}
- if (((hook->flags & HK_INVALID) != 0)
- || ((hook->node->flags & NG_INVALID) != 0)) {
- TRAP_ERROR;
+ if ((NG_HOOK_NOT_VALID(hook))
+ || (NG_NODE_NOT_VALID(NG_HOOK_NODE(hook)))) {
NG_FREE_ITEM(item);
return (ENOTCONN);
}
- if ((hook->flags & HK_QUEUE)) {
+ if ((hook->hk_flags & HK_QUEUE)) {
queue = 1;
}
/* By default data is a reader in the locking scheme */
@@ -1733,7 +1891,7 @@ ng_snd_item(item_p item, int queue)
* References are held by the item on the node and
* the hook if it is present.
*/
- if (hook && (hook->flags & HK_QUEUE)) {
+ if (hook && (hook->hk_flags & HK_QUEUE)) {
queue = 1;
}
/* Data messages count as writers unles explicitly exempted */
@@ -1751,14 +1909,14 @@ ng_snd_item(item_p item, int queue)
* These are over-rides.
*/
if ((ngq->q_flags & SINGLE_THREAD_ONLY)
- || (dest->flags & NG_FORCE_WRITER)
- || (hook && (hook->flags & HK_FORCE_WRITER))) {
+ || (dest->nd_flags & NG_FORCE_WRITER)
+ || (hook && (hook->hk_flags & HK_FORCE_WRITER))) {
rw = NGQRW_W;
item->el_flags &= ~NGQF_TYPE;
}
if (queue) {
/* Put it on the queue for that node*/
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
mtx_enter(&(ngq->q_mtx), MTX_SPIN);
@@ -1802,7 +1960,7 @@ ng_snd_item(item_p item, int queue)
return (0);
}
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
ierror = ng_apply_item(dest, item); /* drops r/w lock when done */
@@ -1824,7 +1982,7 @@ ng_snd_item(item_p item, int queue)
for (;;) {
/* quick hack to save all that mutex stuff */
if ((ngq->q_flags & (WRITE_PENDING | READ_PENDING)) == 0) {
- if (dest->flags & NG_WORKQ)
+ if (dest->nd_flags & NG_WORKQ)
ng_worklist_remove(dest);
return (0);
}
@@ -1841,11 +1999,11 @@ ng_snd_item(item_p item, int queue)
* then we certainly don't need to be
* on the worklist.
*/
- if (dest->flags & NG_WORKQ)
+ if (dest->nd_flags & NG_WORKQ)
ng_worklist_remove(dest);
return (0);
}
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
@@ -1880,12 +2038,12 @@ ng_apply_item(node_p node, item_p item)
ng_rcvdata_t *rcvdata;
hook = item->el_hook;
- item->el_hook = NULL; /* so NG_FREE_ITEM doesn't ng_unref_hook() */
+ item->el_hook = NULL; /* so NG_FREE_ITEM doesn't NG_HOOK_UNREF() */
/* We already have the node.. assume responsibility */
/* And the reference */
/* node = item->el_dest; */
item->el_dest = NULL; /* same as for the hook above */
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
@@ -1896,9 +2054,9 @@ ng_apply_item(node_p node, item_p item)
*/
if ((hook == NULL)
- || ((hook->flags & HK_INVALID) != 0)
- || ((hook->node->flags & NG_INVALID) != 0)
- || ((rcvdata = hook->node->type->rcvdata) == NULL)) {
+ || NG_HOOK_NOT_VALID(hook)
+ || NG_NODE_NOT_VALID(NG_HOOK_NODE(hook))
+ || ((rcvdata = NG_HOOK_NODE(hook)->nd_type->rcvdata) == NULL)) {
error = EIO;
NG_FREE_ITEM(item);
} else {
@@ -1909,13 +2067,13 @@ ng_apply_item(node_p node, item_p item)
if (hook) {
item->el_hook = NULL;
- if ((hook->flags & HK_INVALID) != 0) {
+ if (NG_HOOK_NOT_VALID(hook)) {
/*
* If the hook has been zapped then we can't use it.
* Immediatly drop its reference.
* The message may not need it.
*/
- ng_unref_hook(hook);
+ NG_HOOK_UNREF(hook);
hook = NULL;
}
}
@@ -1923,7 +2081,8 @@ ng_apply_item(node_p node, item_p item)
* Similarly, if the node is a zombie there is
* nothing we can do with it, drop everything.
*/
- if (node->flags & NG_INVALID) {
+ if (NG_NODE_NOT_VALID(node)) {
+ TRAP_ERROR;
error = EINVAL;
NG_FREE_ITEM(item);
} else {
@@ -1945,8 +2104,8 @@ ng_apply_item(node_p node, item_p item)
&& ((msg->header.flags & NGF_RESP) == 0)) {
error = ng_generic_msg(node, item, hook);
} else {
- if ((node)->type->rcvmsg != NULL) {
- error = (*(node)->type->rcvmsg)((node),
+ if ((node)->nd_type->rcvmsg != NULL) {
+ error = (*(node)->nd_type->rcvmsg)((node),
(item), (hook));
} else {
TRAP_ERROR;
@@ -1964,15 +2123,15 @@ ng_apply_item(node_p node, item_p item)
* finished doing everything, drop those references.
*/
if (hook) {
- ng_unref_hook(hook);
+ NG_HOOK_UNREF(hook);
}
if (was_reader) {
- ng_leave_read(&node->input_queue);
+ ng_leave_read(&node->nd_input_queue);
} else {
- ng_leave_write(&node->input_queue);
+ ng_leave_write(&node->nd_input_queue);
}
- ng_unref(node);
+ NG_NODE_UNREF(node);
return (error);
}
@@ -1988,6 +2147,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
NGI_GET_MSG(item, msg);
if (msg->header.typecookie != NGM_GENERIC_COOKIE) {
+ TRAP_ERROR
error = EINVAL;
goto out;
}
@@ -2000,6 +2160,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
struct ngm_mkpeer *const mkp = (struct ngm_mkpeer *) msg->data;
if (msg->header.arglen != sizeof(*mkp)) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2016,6 +2177,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
node_p node2;
if (msg->header.arglen != sizeof(*con)) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2027,7 +2189,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
if (error)
break;
error = ng_con_nodes(here, con->ourhook, node2, con->peerhook);
- ng_unref(node2);
+ NG_NODE_UNREF(node2);
break;
}
case NGM_NAME:
@@ -2035,6 +2197,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
struct ngm_name *const nam = (struct ngm_name *) msg->data;
if (msg->header.arglen != sizeof(*nam)) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2048,6 +2211,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
hook_p hook;
if (msg->header.arglen != sizeof(*rmh)) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2068,16 +2232,16 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
/* Fill in node info */
ni = (struct nodeinfo *) resp->data;
- if (here->name != NULL)
- strncpy(ni->name, here->name, NG_NODELEN);
- strncpy(ni->type, here->type->name, NG_TYPELEN);
+ if (NG_NODE_HAS_NAME(here))
+ strncpy(ni->name, NG_NODE_NAME(here), NG_NODELEN);
+ strncpy(ni->type, here->nd_type->name, NG_TYPELEN);
ni->id = ng_node2ID(here);
- ni->hooks = here->numhooks;
+ ni->hooks = here->nd_numhooks;
break;
}
case NGM_LISTHOOKS:
{
- const int nhooks = here->numhooks;
+ const int nhooks = here->nd_numhooks;
struct hooklist *hl;
struct nodeinfo *ni;
hook_p hook;
@@ -2093,14 +2257,14 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
ni = &hl->nodeinfo;
/* Fill in node info */
- if (here->name)
- strncpy(ni->name, here->name, NG_NODELEN);
- strncpy(ni->type, here->type->name, NG_TYPELEN);
+ if (NG_NODE_HAS_NAME(here))
+ strncpy(ni->name, NG_NODE_NAME(here), NG_NODELEN);
+ strncpy(ni->type, here->nd_type->name, NG_TYPELEN);
ni->id = ng_node2ID(here);
/* Cycle through the linked list of hooks */
ni->hooks = 0;
- LIST_FOREACH(hook, &here->hooks, hooks) {
+ LIST_FOREACH(hook, &here->nd_hooks, hk_hooks) {
struct linkinfo *const link = &hl->link[ni->hooks];
if (ni->hooks >= nhooks) {
@@ -2108,17 +2272,18 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
__FUNCTION__, "hooks");
break;
}
- if ((hook->flags & HK_INVALID) != 0)
+ if (NG_HOOK_NOT_VALID(hook))
continue;
- strncpy(link->ourhook, hook->name, NG_HOOKLEN);
- strncpy(link->peerhook, hook->peer->name, NG_HOOKLEN);
- if (hook->peer->node->name[0] != '\0')
+ strncpy(link->ourhook, NG_HOOK_NAME(hook), NG_HOOKLEN);
+ strncpy(link->peerhook,
+ NG_PEER_HOOK_NAME(hook), NG_HOOKLEN);
+ if (NG_PEER_NODE_NAME(hook)[0] != '\0')
strncpy(link->nodeinfo.name,
- hook->peer->node->name, NG_NODELEN);
+ NG_PEER_NODE_NAME(hook), NG_NODELEN);
strncpy(link->nodeinfo.type,
- hook->peer->node->type->name, NG_TYPELEN);
- link->nodeinfo.id = ng_node2ID(hook->peer->node);
- link->nodeinfo.hooks = hook->peer->node->numhooks;
+ NG_PEER_NODE(hook)->nd_type->name, NG_TYPELEN);
+ link->nodeinfo.id = ng_node2ID(NG_PEER_NODE(hook));
+ link->nodeinfo.hooks = NG_PEER_NODE(hook)->nd_numhooks;
ni->hooks++;
}
break;
@@ -2134,8 +2299,8 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
mtx_enter(&ng_nodelist_mtx, MTX_DEF);
/* Count number of nodes */
- LIST_FOREACH(node, &ng_nodelist, nodes) {
- if (unnamed || node->name[0] != '\0')
+ LIST_FOREACH(node, &ng_nodelist, nd_nodes) {
+ if (unnamed || NG_NODE_HAS_NAME(node))
num++;
}
mtx_exit(&ng_nodelist_mtx, MTX_DEF);
@@ -2152,7 +2317,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
/* Cycle through the linked list of nodes */
nl->numnames = 0;
mtx_enter(&ng_nodelist_mtx, MTX_DEF);
- LIST_FOREACH(node, &ng_nodelist, nodes) {
+ LIST_FOREACH(node, &ng_nodelist, nd_nodes) {
struct nodeinfo *const np = &nl->nodeinfo[nl->numnames];
if (nl->numnames >= num) {
@@ -2160,15 +2325,15 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
__FUNCTION__, "nodes");
break;
}
- if ((node->flags & NG_INVALID) != 0)
+ if (NG_NODE_NOT_VALID(node))
continue;
- if (!unnamed && node->name[0] == '\0')
+ if (!unnamed && (! NG_NODE_HAS_NAME(node)))
continue;
- if (node->name[0] != '\0')
- strncpy(np->name, node->name, NG_NODELEN);
- strncpy(np->type, node->type->name, NG_TYPELEN);
+ if (NG_NODE_HAS_NAME(node))
+ strncpy(np->name, NG_NODE_NAME(node), NG_NODELEN);
+ strncpy(np->type, node->nd_type->name, NG_TYPELEN);
np->id = ng_node2ID(node);
- np->hooks = node->numhooks;
+ np->hooks = node->nd_numhooks;
nl->numnames++;
}
mtx_exit(&ng_nodelist_mtx, MTX_DEF);
@@ -2227,6 +2392,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
if (msg->header.arglen < sizeof(struct ng_mesg)
|| msg->header.arglen - sizeof(struct ng_mesg)
< binary->header.arglen) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2243,7 +2409,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
bcopy(binary, ascii, sizeof(*binary));
/* Find command by matching typecookie and command number */
- for (c = here->type->cmdlist;
+ for (c = here->nd_type->cmdlist;
c != NULL && c->name != NULL; c++) {
if (binary->header.typecookie == c->cookie
&& binary->header.cmd == c->cmd)
@@ -2301,6 +2467,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
|| ascii->header.arglen < 1
|| msg->header.arglen
< sizeof(*ascii) + ascii->header.arglen) {
+ TRAP_ERROR
error = EINVAL;
break;
}
@@ -2318,7 +2485,7 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
bcopy(ascii, binary, sizeof(*ascii));
/* Find command by matching ASCII command string */
- for (c = here->type->cmdlist;
+ for (c = here->nd_type->cmdlist;
c != NULL && c->name != NULL; c++) {
if (strcmp(ascii->header.cmdstr, c->name) == 0)
break;
@@ -2366,9 +2533,9 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook)
* This means we must assume that the item/msg is already freed
* when control passes back to us.
*/
- if (here->type->rcvmsg != NULL) {
+ if (here->nd_type->rcvmsg != NULL) {
NGI_MSG(item) = msg; /* put it back as we found it */
- return((*here->type->rcvmsg)(here, item, lasthook));
+ return((*here->nd_type->rcvmsg)(here, item, lasthook));
}
/* Fall through if rcvmsg not supported */
default:
@@ -2521,7 +2688,7 @@ static int maxalloc = 128; /* limit the damage of a leak */
static const int ngqfreemax = 64;/* cache at most this many */
static const int ngqfreelow = 4; /* try malloc if free < this */
static volatile int ngqfreesize; /* number of cached entries */
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
static TAILQ_HEAD(, ng_item) ng_itemlist = TAILQ_HEAD_INITIALIZER(ng_itemlist);
#endif
/*
@@ -2558,10 +2725,10 @@ ng_getqblk(void)
sizeof(*item), M_NETGRAPH_ITEM,
(M_NOWAIT | M_ZERO));
if (item) {
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
TAILQ_INSERT_TAIL(&ng_itemlist,
item, all);
-#endif /* ITEM_DEBUG */
+#endif /* NETGRAPH_DEBUG */
atomic_add_int(&allocated, 1);
break;
}
@@ -2626,11 +2793,11 @@ ng_free_item(item_p item)
}
/* If we still have a node or hook referenced... */
if (item->el_dest) {
- ng_unref(item->el_dest);
+ NG_NODE_UNREF(item->el_dest);
item->el_dest = NULL;
}
if (item->el_hook) {
- ng_unref_hook(item->el_hook);
+ NG_HOOK_UNREF(item->el_hook);
item->el_hook = NULL;
}
item->el_flags |= NGQF_FREE;
@@ -2649,15 +2816,41 @@ ng_free_item(item_p item)
atomic_add_int(&ngqfreesize, 1);
} else {
/* This is the only place that should use this Macro */
-#ifdef ITEM_DEBUG
+#ifdef NETGRAPH_DEBUG
TAILQ_REMOVE(&ng_itemlist, item, all);
-#endif /* ITEM_DEBUG */
+#endif /* NETGRAPH_DEBUG */
NG_FREE_ITEM_REAL(item);
atomic_subtract_int(&allocated, 1);
}
}
-#ifdef ITEM_DEBUG
+#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_node2ID(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)
{
@@ -2673,48 +2866,70 @@ dumpitem(item_p item, char *file, int line)
printf(" - [data]\n");
}
}
- printf(" problem discovered at file %s, line %d\n", file, line);
- if (item->el_dest)
- printf("node %X ([%x])\n",
- item->el_dest, ng_node2ID(item->el_dest));
+ if (line) {
+ printf(" problem discovered at file %s, line %d\n", file, line);
+ if (item->el_dest) {
+ printf("node %p ([%x])\n",
+ item->el_dest, ng_node2ID(item->el_dest));
+ }
+ }
+}
+
+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;
+ SLIST_FOREACH(node, &ng_allnodes, nd_all) {
+ printf("[%d] ", i++);
+ dumpnode(node, NULL, 0);
+ }
+}
+
+static void
+ng_dumphooks(void)
+{
+ hook_p hook;
+ int i = 1;
+ SLIST_FOREACH(hook, &ng_allhooks, hk_all) {
+ printf("[%d] ", i++);
+ dumphook(hook, NULL, 0);
+ }
}
static int
sysctl_debug_ng_dump_items(SYSCTL_HANDLER_ARGS)
{
+ static int count;
int error;
int val;
- item_p item;
int i;
val = allocated;
i = 1;
error = sysctl_handle_int(oidp, &val, sizeof(int), req);
- TAILQ_FOREACH(item, &ng_itemlist, all) {
- if (item->el_flags & NGQF_FREE) {
- printf("[%d] free item, freed at %s, line %d\n",
- i++, item->lastfile, item->lastline);
- } else {
- printf("[%d] ACTIVE item, last used at %s, line %d",
- i++, item->lastfile, item->lastline);
- if ((item->el_flags & NGQF_D_M) == NGQF_MESG) {
- printf(" - retaddr[%d]:\n", _NGI_RETADDR(item));
- } else {
- printf(" - [data]\n");
- }
- }
- if (item->el_dest) {
- printf("node %X ([%x])",
- item->el_dest, ng_node2ID(item->el_dest));
- printf("<%X>\n",item->el_dest->input_queue.q_flags);
- }
+ if(count++ & 1) { /* for some reason sysctl calls it twice */
+ ng_dumpitems();
+ ng_dumpnodes();
+ ng_dumphooks();
}
return error;
}
SYSCTL_PROC(_debug, OID_AUTO, ng_dump_items, CTLTYPE_INT | CTLFLAG_RD,
0, 0, sysctl_debug_ng_dump_items, "I", "Number of allocated items");
-#endif /* ITEM_DEBUG */
+#endif /* NETGRAPH_DEBUG */
/***********************************************************************
@@ -2739,7 +2954,7 @@ ngintr(void)
mtx_exit(&ng_worklist_mtx, MTX_SPIN);
break;
}
- TAILQ_REMOVE(&ng_worklist, node, work);
+ TAILQ_REMOVE(&ng_worklist, node, nd_work);
mtx_exit(&ng_worklist_mtx, MTX_SPIN);
/*
* We have the node. We also take over the reference
@@ -2751,8 +2966,8 @@ ngintr(void)
* Let the reference go at the last minute.
*/
for (;;) {
- mtx_enter(&node->input_queue.q_mtx, MTX_SPIN);
- item = ng_dequeue(&node->input_queue);
+ mtx_enter(&node->nd_input_queue.q_mtx, MTX_SPIN);
+ item = ng_dequeue(&node->nd_input_queue);
if (item == NULL) {
/*
* Say we are on the queue as long as
@@ -2760,13 +2975,13 @@ ngintr(void)
* it probably wouldn't come here while we
* are processing anyhow.
*/
- node->flags &= ~NG_WORKQ;
- mtx_exit(&node->input_queue.q_mtx, MTX_SPIN);
- ng_unref(node);
+ node->nd_flags &= ~NG_WORKQ;
+ mtx_exit(&node->nd_input_queue.q_mtx, MTX_SPIN);
+ NG_NODE_UNREF(node);
break; /* go look for another node */
} else {
- mtx_exit(&node->input_queue.q_mtx, MTX_SPIN);
-#ifdef ITEM_DEBUG
+ mtx_exit(&node->nd_input_queue.q_mtx, MTX_SPIN);
+#ifdef NETGRAPH_DEBUG
_ngi_check(item, __FILE__, __LINE__);
#endif
ng_apply_item(node, item);
@@ -2779,11 +2994,11 @@ static void
ng_worklist_remove(node_p node)
{
mtx_enter(&ng_worklist_mtx, MTX_SPIN);
- if (node->flags & NG_WORKQ) {
- TAILQ_REMOVE(&ng_worklist, node, work);
- ng_unref(node);
+ if (node->nd_flags & NG_WORKQ) {
+ TAILQ_REMOVE(&ng_worklist, node, nd_work);
+ NG_NODE_UNREF(node);
}
- node->flags &= ~NG_WORKQ;
+ node->nd_flags &= ~NG_WORKQ;
mtx_exit(&ng_worklist_mtx, MTX_SPIN);
}
@@ -2791,14 +3006,14 @@ static void
ng_setisr(node_p node)
{
mtx_enter(&ng_worklist_mtx, MTX_SPIN);
- if ((node->flags & NG_WORKQ) == 0) {
+ if ((node->nd_flags & NG_WORKQ) == 0) {
/*
* If we are not already on the work queue,
* then put us on.
*/
- node->flags |= NG_WORKQ;
- TAILQ_INSERT_TAIL(&ng_worklist, node, work);
- node->refs++;
+ node->nd_flags |= NG_WORKQ;
+ TAILQ_INSERT_TAIL(&ng_worklist, node, nd_work);
+ NG_NODE_REF(node);
}
mtx_exit(&ng_worklist_mtx, MTX_SPIN);
schednetisr(NETISR_NETGRAPH);
@@ -2809,24 +3024,24 @@ ng_setisr(node_p node)
* Externally useable functions to set up a queue item ready for sending
***********************************************************************/
-#ifdef ITEM_DEBUG
-#define DEBUG_CHECKS \
+#ifdef NETGRAPH_DEBUG
+#define ITEM_DEBUG_CHECKS \
do { \
if (item->el_dest ) { \
printf("item already has node"); \
Debugger("has node"); \
- ng_unref(item->el_dest); \
+ NG_NODE_UNREF(item->el_dest); \
item->el_dest = NULL; \
} \
if (item->el_hook ) { \
printf("item already has hook"); \
Debugger("has hook"); \
- ng_unref_hook(item->el_hook); \
+ NG_HOOK_UNREF(item->el_hook); \
item->el_hook = NULL; \
} \
} while (0)
#else
-#define DEBUG_CHECKS
+#define ITEM_DEBUG_CHECKS
#endif
/*
@@ -2852,7 +3067,7 @@ ng_package_data(struct mbuf *m, meta_p meta)
NG_FREE_META(meta);
return (NULL);
}
- DEBUG_CHECKS;
+ ITEM_DEBUG_CHECKS;
item->el_flags = NGQF_DATA;
item->el_next = NULL;
NGI_M(item) = m;
@@ -2878,7 +3093,7 @@ ng_package_msg(struct ng_mesg *msg)
}
return (NULL);
}
- DEBUG_CHECKS;
+ ITEM_DEBUG_CHECKS;
item->el_flags = NGQF_MESG;
item->el_next = NULL;
/*
@@ -2913,27 +3128,30 @@ ng_package_msg(struct ng_mesg *msg)
int
ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr)
{
- DEBUG_CHECKS;
+ ITEM_DEBUG_CHECKS;
/*
* Quick sanity check..
+ * Since a hook holds a reference on it's node, once we know
+ * that the peer is still connected (even if invalid,) we know
+ * that the peer node is present, though maybe invalid.
*/
if ((hook == NULL)
- || ((hook->flags & HK_INVALID) != 0)
- || (hook->peer == NULL)
- || ((hook->peer->flags & HK_INVALID) != 0)
- || ((hook->peer->node->flags & NG_INVALID) != 0)) {
+ || NG_HOOK_NOT_VALID(hook)
+ || (NG_HOOK_PEER(hook) == NULL)
+ || NG_HOOK_NOT_VALID(NG_HOOK_PEER(hook))
+ || NG_NODE_NOT_VALID(NG_PEER_NODE(hook))) {
NG_FREE_ITEM(item);
+ TRAP_ERROR
return (EINVAL);
}
/*
* Transfer our interest to the other (peer) end.
- * note sleazy use of 'hook'.
*/
- item->el_hook = hook->peer;
- item->el_hook->refs++; /* don't let it go away while on the queue */
- item->el_dest = hook->peer->node; /* sleaze */
- item->el_dest->refs++; /* XXX dangerous, not atomic */
+ item->el_hook = NG_HOOK_PEER(hook);
+ NG_HOOK_REF(item->el_hook); /* Don't let it go while on the queue */
+ item->el_dest = NG_PEER_NODE(hook);
+ NG_NODE_REF(item->el_dest); /* Nor this */
SET_RETADDR;
return (0);
}
@@ -2945,7 +3163,7 @@ ng_address_path(node_p here, item_p item, char *address, ng_ID_t retaddr)
hook_p hook = NULL;
int error;
- DEBUG_CHECKS;
+ 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.
@@ -2953,11 +3171,11 @@ ng_address_path(node_p here, item_p item, char *address, ng_ID_t retaddr)
error = ng_path2noderef(here, address, &dest, &hook);
if (error) {
NG_FREE_ITEM(item);
- return (EINVAL);
+ return (error);
}
item->el_dest = dest;
if (( item->el_hook = hook))
- hook->refs++; /* don't let it go away while on the queue */
+ NG_HOOK_REF(hook); /* don't let it go while on the queue */
SET_RETADDR;
return (0);
}
@@ -2967,13 +3185,14 @@ ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr)
{
node_p dest;
- DEBUG_CHECKS;
+ ITEM_DEBUG_CHECKS;
/*
* Find the target node.
*/
dest = ng_ID2noderef(ID); /* GETS REFERENCE! */
if (dest == NULL) {
NG_FREE_ITEM(item);
+ TRAP_ERROR
return(EINVAL);
}
/* Fill out the contents */
@@ -2981,7 +3200,6 @@ ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr)
item->el_next = NULL;
item->el_dest = dest;
item->el_hook = NULL;
- /* NGI_RETADDR(item) = ng_node2ID(here); not sure why its here XXX */
SET_RETADDR;
return (0);
}
@@ -3012,10 +3230,10 @@ ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg)
item->el_flags = NGQF_MESG;
item->el_next = NULL;
item->el_dest = here;
- here->refs++; /* XXX not atomic, + May have other races */
+ NG_NODE_REF(here);
item->el_hook = hook;
if (hook)
- hook->refs++;
+ NG_HOOK_REF(hook);
NGI_MSG(item) = msg;
NGI_RETADDR(item) = ng_node2ID(here);
return (item);
@@ -3061,7 +3279,7 @@ ng_macro_test(item_p item)
NG_SEND_DATA(error, hook, m, meta);
NG_SEND_DATA_ONLY(error, hook, m);
NG_FWD_NEW_DATA(error, item, hook, m);
- NG_FWD_DATA(error, item, hook);
+ NG_FWD_ITEM_HOOK(error, item, hook);
NG_SEND_MSG_HOOK(error, node, msg, hook, retaddr);
NG_SEND_MSG_ID(error, node, msg, retaddr, retaddr);
NG_SEND_MSG_PATH(error, node, msg, ".:", retaddr);
diff --git a/sys/netgraph/ng_bpf.c b/sys/netgraph/ng_bpf.c
index 33b8384..00d5d35 100644
--- a/sys/netgraph/ng_bpf.c
+++ b/sys/netgraph/ng_bpf.c
@@ -219,7 +219,7 @@ static const struct ng_bpf_hookprog ng_bpf_default_prog = {
static int
ng_bpf_constructor(node_p node)
{
- node->private = NULL;
+ NG_NODE_SET_PRIVATE(node, NULL);
return (0);
}
@@ -237,13 +237,13 @@ ng_bpf_newhook(node_p node, hook_p hook, const char *name)
if (hip == NULL)
return (ENOMEM);
hip->hook = hook;
- hook->private = hip;
+ NG_HOOK_SET_PRIVATE(hook, hip);
hip->node = node;
/* Attach the default BPF program */
if ((error = ng_bpf_setprog(hook, &ng_bpf_default_prog)) != 0) {
FREE(hip, M_NETGRAPH);
- hook->private = NULL;
+ NG_HOOK_SET_PRIVATE(hook, NULL);
return (error);
}
@@ -304,7 +304,7 @@ ng_bpf_rcvmsg(node_p node, item_p item, hook_p lasthook)
ERROUT(ENOENT);
/* Build response */
- hp = ((hinfo_p)hook->private)->prog;
+ hp = ((hinfo_p)NG_HOOK_PRIVATE(hook))->prog;
NG_MKRESPONSE(resp, msg,
NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len), M_NOWAIT);
if (resp == NULL)
@@ -329,7 +329,7 @@ ng_bpf_rcvmsg(node_p node, item_p item, hook_p lasthook)
/* Find hook */
if ((hook = ng_findhook(node, msg->data)) == NULL)
ERROUT(ENOENT);
- stats = &((hinfo_p)hook->private)->stats;
+ stats = &((hinfo_p)NG_HOOK_PRIVATE(hook))->stats;
/* Build response (if desired) */
if (msg->header.cmd != NGM_BPF_CLR_STATS) {
@@ -371,7 +371,7 @@ done:
static int
ng_bpf_rcvdata(hook_p hook, item_p item)
{
- const hinfo_p hip = hook->private;
+ const hinfo_p hip = NG_HOOK_PRIVATE(hook);
int totlen;
int needfree = 0, error = 0;
u_char *data, buf[256];
@@ -431,10 +431,10 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
}
/* Deliver frame out destination hook */
- dhip = (hinfo_p)dest->private;
+ dhip = NG_HOOK_PRIVATE(dest);
dhip->stats.xmitOctets += totlen;
dhip->stats.xmitFrames++;
- NG_FWD_DATA(error, item, dest);
+ NG_FWD_ITEM_HOOK(error, item, dest);
return (error);
}
@@ -444,8 +444,7 @@ ng_bpf_rcvdata(hook_p hook, item_p item)
static int
ng_bpf_shutdown(node_p node)
{
- node->flags |= NG_INVALID;
- ng_unref(node);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -455,16 +454,16 @@ ng_bpf_shutdown(node_p node)
static int
ng_bpf_disconnect(hook_p hook)
{
- const hinfo_p hip = hook->private;
+ const hinfo_p hip = NG_HOOK_PRIVATE(hook);
KASSERT(hip != NULL, ("%s: null info", __FUNCTION__));
FREE(hip->prog, M_NETGRAPH);
bzero(hip, sizeof(*hip));
FREE(hip, M_NETGRAPH);
- hook->private = NULL; /* for good measure */
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags && NG_INVALID) == 0)) {
- ng_rmnode_self(hook->node);
+ NG_HOOK_SET_PRIVATE(hook, NULL); /* for good measure */
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
}
return (0);
}
@@ -479,7 +478,7 @@ ng_bpf_disconnect(hook_p hook)
static int
ng_bpf_setprog(hook_p hook, const struct ng_bpf_hookprog *hp0)
{
- const hinfo_p hip = hook->private;
+ const hinfo_p hip = NG_HOOK_PRIVATE(hook);
struct ng_bpf_hookprog *hp;
int size;
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c
index 9539757..9698842 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -324,12 +324,12 @@ ng_bridge_constructor(node_p node)
* When it's fixed the process SHOULD NOT SLEEP, spinlocks please!
* (and atomic ops )
*/
- node->flags |= NG_FORCE_WRITER;
- node->private = priv;
+ NG_NODE_FORCE_WRITER(node);
+ NG_NODE_SET_PRIVATE(node, priv);
priv->node = node;
/* Start timer by faking a timeout event */
- node->refs++; /* XXX ???? because of the timeout?*/
+ NG_NODE_REF(node); /* because the timeout will drop a reference */
ng_bridge_timeout(node);
return (0);
}
@@ -340,7 +340,7 @@ ng_bridge_constructor(node_p node)
static int
ng_bridge_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Check for a link hook */
if (strncmp(name, NG_BRIDGE_HOOK_LINK_PREFIX,
@@ -362,7 +362,7 @@ ng_bridge_newhook(node_p node, hook_p hook, const char *name)
if (priv->links[linkNum] == NULL)
return (ENOMEM);
priv->links[linkNum]->hook = hook;
- LINK_NUM(hook) = linkNum;
+ NG_HOOK_SET_PRIVATE(hook, (void *)linkNum);
priv->numLinks++;
return (0);
}
@@ -377,7 +377,7 @@ ng_bridge_newhook(node_p node, hook_p hook, const char *name)
static int
ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -512,8 +512,8 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_bridge_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_bridge_host *host;
struct ng_bridge_link *link;
struct ether_header *eh;
@@ -525,7 +525,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
NGI_GET_M(item, m);
/* Get link number */
- linkNum = LINK_NUM(hook);
+ linkNum = (int)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum >= 0 && linkNum < NG_BRIDGE_MAX_LINKS,
("%s: linkNum=%u", __FUNCTION__, linkNum));
link = priv->links[linkNum];
@@ -600,7 +600,7 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
log(LOG_WARNING, "ng_bridge: %s:"
" loopback detected on %s%s\n",
ng_bridge_nodename(node),
- hook->name, suffix);
+ NG_HOOK_NAME(hook), suffix);
}
/* Mark link as linka non grata */
@@ -758,15 +758,15 @@ ng_bridge_rcvdata(hook_p hook, item_p item)
static int
ng_bridge_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
KASSERT(priv->numLinks == 0 && priv->numHosts == 0,
("%s: numLinks=%d numHosts=%d",
__FUNCTION__, priv->numLinks, priv->numHosts));
FREE(priv->tab, M_NETGRAPH);
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -776,11 +776,11 @@ ng_bridge_shutdown(node_p node)
static int
ng_bridge_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int linkNum;
/* Get link number */
- linkNum = LINK_NUM(hook);
+ linkNum = (int)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum >= 0 && linkNum < NG_BRIDGE_MAX_LINKS,
("%s: linkNum=%u", __FUNCTION__, linkNum));
@@ -794,9 +794,10 @@ ng_bridge_disconnect(hook_p hook)
priv->numLinks--;
/* If no more hooks, go away */
- if ((hook->node->numhooks == 0)
- && (( hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
+ }
return (0);
}
@@ -965,15 +966,15 @@ static void
ng_bridge_timeout(void *arg)
{
const node_p node = arg;
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int s, bucket;
int counter = 0;
int linkNum;
/* Avoid race condition with ng_bridge_shutdown() */
s = splnet();
- if ((node->flags & NG_INVALID) != 0 || priv == NULL) {
- ng_unref(node);
+ if ((NG_NODE_NOT_VALID(node)) || priv == NULL) {
+ NG_NODE_UNREF(node);
splx(s);
return;
}
@@ -1045,8 +1046,8 @@ ng_bridge_nodename(node_p node)
{
static char name[NG_NODELEN+1];
- if (node->name != NULL)
- snprintf(name, sizeof(name), "%s", node->name);
+ if (NG_NODE_NAME(node) != NULL)
+ snprintf(name, sizeof(name), "%s", NG_NODE_NAME(node));
else
snprintf(name, sizeof(name), "[%x]", ng_node2ID(node));
return name;
diff --git a/sys/netgraph/ng_cisco.c b/sys/netgraph/ng_cisco.c
index a926156..8bd78ba 100644
--- a/sys/netgraph/ng_cisco.c
+++ b/sys/netgraph/ng_cisco.c
@@ -199,7 +199,7 @@ cisco_constructor(node_p node)
return (ENOMEM);
callout_handle_init(&sc->handle);
- node->private = sc;
+ NG_NODE_SET_PRIVATE(node, sc);
sc->node = node;
/* Initialise the varous protocol hook holders */
@@ -217,25 +217,25 @@ cisco_constructor(node_p node)
static int
cisco_newhook(node_p node, hook_p hook, const char *name)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
if (strcmp(name, NG_CISCO_HOOK_DOWNSTREAM) == 0) {
sc->downstream.hook = hook;
- hook->private = &sc->downstream;
+ NG_HOOK_SET_PRIVATE(hook, &sc->downstream);
/* Start keepalives */
sc->handle = timeout(cisco_keepalive, sc, hz * KEEPALIVE_SECS);
} else if (strcmp(name, NG_CISCO_HOOK_INET) == 0) {
sc->inet.hook = hook;
- hook->private = &sc->inet;
+ NG_HOOK_SET_PRIVATE(hook, &sc->inet);
} else if (strcmp(name, NG_CISCO_HOOK_APPLETALK) == 0) {
sc->atalk.hook = hook;
- hook->private = &sc->atalk;
+ NG_HOOK_SET_PRIVATE(hook, &sc->atalk);
} else if (strcmp(name, NG_CISCO_HOOK_IPX) == 0) {
sc->ipx.hook = hook;
- hook->private = &sc->ipx;
+ NG_HOOK_SET_PRIVATE(hook, &sc->ipx);
} else if (strcmp(name, NG_CISCO_HOOK_DEBUG) == 0) {
- hook->private = NULL; /* unimplemented */
+ NG_HOOK_SET_PRIVATE(hook, NULL); /* unimplemented */
} else
return (EINVAL);
return 0;
@@ -248,7 +248,7 @@ static int
cisco_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
struct ng_mesg *msg;
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
@@ -344,13 +344,13 @@ cisco_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
cisco_rcvdata(hook_p hook, item_p item)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
struct protoent *pep;
struct cisco_header *h;
int error = 0;
struct mbuf *m;
- if ((pep = hook->private) == NULL)
+ if ((pep = NG_HOOK_PRIVATE(hook)) == NULL)
goto out;
/* If it came from our downlink, deal with it separately */
@@ -402,11 +402,10 @@ out:
static int
cisco_shutdown(node_p node)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
- node->flags |= NG_INVALID;
- node->private = NULL;
- ng_unref(sc->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(sc->node);
FREE(sc, M_NETGRAPH);
return (0);
}
@@ -419,11 +418,11 @@ cisco_shutdown(node_p node)
static int
cisco_disconnect(hook_p hook)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
struct protoent *pep;
/* Check it's not the debug hook */
- if ((pep = hook->private)) {
+ if ((pep = NG_HOOK_PRIVATE(hook))) {
pep->hook = NULL;
if (pep->af == 0xffff) {
/* If it is the downstream hook, stop the timers */
@@ -432,9 +431,9 @@ cisco_disconnect(hook_p hook)
}
/* If no more hooks, remove the node */
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_echo.c b/sys/netgraph/ng_echo.c
index 337df72..68a165d 100644
--- a/sys/netgraph/ng_echo.c
+++ b/sys/netgraph/ng_echo.c
@@ -47,6 +47,7 @@
*/
#include <sys/param.h>
+#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
@@ -106,7 +107,7 @@ nge_rcvdata(hook_p hook, item_p item)
{
int error = 0;
- NG_FWD_DATA(error, item, hook);
+ NG_FWD_ITEM_HOOK(error, item, hook);
return (0);
}
@@ -116,9 +117,9 @@ nge_rcvdata(hook_p hook, item_p item)
static int
nge_disconnect(hook_p hook)
{
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0)) {
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
}
return (0);
}
diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index 1433ada..15410b8 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -210,7 +210,7 @@ ng_ether_input(struct ifnet *ifp,
struct mbuf **mp, struct ether_header *eh)
{
const node_p node = IFP2NG(ifp);
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* If "lower" hook not connected, let packet continue */
if (priv->lower == NULL || priv->lowerOrphan)
@@ -229,7 +229,7 @@ ng_ether_input_orphan(struct ifnet *ifp,
struct mbuf *m, struct ether_header *eh)
{
const node_p node = IFP2NG(ifp);
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* If "orphan" hook not connected, let packet continue */
if (priv->lower == NULL || !priv->lowerOrphan) {
@@ -251,7 +251,7 @@ ng_ether_input_orphan(struct ifnet *ifp,
static void
ng_ether_input2(node_p node, struct mbuf **mp, struct ether_header *eh)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int error;
/* Glue Ethernet header back on */
@@ -271,7 +271,7 @@ static int
ng_ether_output(struct ifnet *ifp, struct mbuf **mp)
{
const node_p node = IFP2NG(ifp);
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int error = 0;
/* If "upper" hook not connected, let packet continue */
@@ -308,10 +308,10 @@ ng_ether_attach(struct ifnet *ifp)
if (priv == NULL) {
log(LOG_ERR, "%s: can't %s for %s\n",
__FUNCTION__, "allocate memory", name);
- ng_unref(node);
+ NG_NODE_UNREF(node);
return;
}
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
priv->ifp = ifp;
IFP2NG(ifp) = node;
priv->autoSrcAddr = 1;
@@ -336,13 +336,12 @@ ng_ether_detach(struct ifnet *ifp)
if (node == NULL) /* no node (why not?), ignore */
return;
ng_rmnode_self(node); /* break all links to other nodes */
- node->flags |= NG_INVALID;
IFP2NG(ifp) = NULL; /* detach node from interface */
- priv = node->private; /* free node private info */
+ priv = NG_NODE_PRIVATE(node); /* free node private info */
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node); /* free node itself */
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node); /* free node itself */
}
/*
@@ -441,7 +440,7 @@ ng_ether_constructor(node_p node)
static int
ng_ether_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
u_char orphan = priv->lowerOrphan;
hook_p *hookptr;
@@ -479,7 +478,7 @@ ng_ether_newhook(node_p node, hook_p hook, const char *name)
static int
ng_ether_connect(hook_p hook)
{
- hook->peer->flags |= HK_QUEUE;
+ NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
return (0);
}
@@ -489,7 +488,7 @@ ng_ether_connect(hook_p hook)
static int
ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -593,8 +592,8 @@ ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_ether_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m;
meta_p meta;
@@ -614,7 +613,7 @@ ng_ether_rcvdata(hook_p hook, item_p item)
static int
ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Make sure header is fully pulled up */
if (m->m_pkthdr.len < sizeof(struct ether_header)) {
@@ -646,7 +645,7 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta)
static int
ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ether_header *eh;
/* Check length and pull off header */
@@ -681,13 +680,13 @@ static int
ng_ether_shutdown(node_p node)
{
char name[IFNAMSIZ + 1];
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
if (priv->promisc) { /* disable promiscuous mode */
(void)ifpromisc(priv->ifp, 0);
priv->promisc = 0;
}
- ng_unref(node);
+ NG_NODE_UNREF(node);
snprintf(name, sizeof(name), "%s%d", priv->ifp->if_name, priv->ifp->if_unit);
if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) {
log(LOG_ERR, "%s: can't %s for %s\n",
@@ -696,7 +695,7 @@ ng_ether_shutdown(node_p node)
}
/* Allocate private data */
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
IFP2NG(priv->ifp) = node;
priv->autoSrcAddr = 1; /* reset auto-src-addr flag */
@@ -714,7 +713,7 @@ ng_ether_shutdown(node_p node)
static int
ng_ether_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
if (hook == priv->upper)
priv->upper = NULL;
@@ -723,9 +722,9 @@ ng_ether_disconnect(hook_p hook)
priv->lowerOrphan = 0;
} else
panic("%s: weird hook", __FUNCTION__);
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node); /* reset node */
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */
return (0);
}
diff --git a/sys/netgraph/ng_frame_relay.c b/sys/netgraph/ng_frame_relay.c
index 9887284..b82831e 100644
--- a/sys/netgraph/ng_frame_relay.c
+++ b/sys/netgraph/ng_frame_relay.c
@@ -222,7 +222,7 @@ ngfrm_constructor(node_p node)
sc->addrlen = 2; /* default */
/* Link the node and our private info */
- node->private = sc;
+ NG_NODE_SET_PRIVATE(node, sc);
sc->node = node;
return (0);
}
@@ -237,7 +237,7 @@ ngfrm_constructor(node_p node)
static int
ngfrm_newhook(node_p node, hook_p hook, const char *name)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
const char *cp;
char *eptr;
int dlci = 0;
@@ -245,7 +245,7 @@ ngfrm_newhook(node_p node, hook_p hook, const char *name)
/* Check if it's our friend the control hook */
if (strcmp(name, NG_FRAMERELAY_HOOK_DEBUG) == 0) {
- hook->private = NULL; /* paranoid */
+ NG_HOOK_SET_PRIVATE(hook, NULL); /* paranoid */
return (0);
}
@@ -266,7 +266,7 @@ ngfrm_newhook(node_p node, hook_p hook, const char *name)
return (EADDRINUSE);
/* OK add it */
- hook->private = &sc->downstream;
+ NG_HOOK_SET_PRIVATE(hook, &sc->downstream);
sc->downstream.hook = hook;
sc->downstream.dlci = -1;
sc->downstream.flags |= CHAN_ACTIVE;
@@ -303,7 +303,7 @@ ngfrm_newhook(node_p node, hook_p hook, const char *name)
* Put our hooks into it (pun not intended)
*/
sc->channel[ctxnum].flags |= CHAN_ACTIVE;
- hook->private = sc->channel + ctxnum;
+ NG_HOOK_SET_PRIVATE(hook, sc->channel + ctxnum);
sc->channel[ctxnum].hook = hook;
sc->datahooks++;
return (0);
@@ -332,7 +332,7 @@ ngfrm_addrlen(char *hdr)
static int
ngfrm_rcvdata(hook_p hook, item_p item)
{
- struct ctxinfo *const ctxp = hook->private;
+ struct ctxinfo *const ctxp = NG_HOOK_PRIVATE(hook);
int error = 0;
int dlci;
sc_p sc;
@@ -349,11 +349,11 @@ ngfrm_rcvdata(hook_p hook, item_p item)
/* If coming from downstream, decode it to a channel */
dlci = ctxp->dlci;
if (dlci == -1)
- return (ngfrm_decode(hook->node, item));
+ return (ngfrm_decode(NG_HOOK_NODE(hook), item));
NGI_GET_M(item, m);
/* Derive the softc we will need */
- sc = hook->node->private;
+ sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
/* If there is no live channel, throw it away */
if ((sc->downstream.hook == NULL)
@@ -419,7 +419,7 @@ bad:
static int
ngfrm_decode(node_p node, item_p item)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
char *data;
int alen;
u_int dlci = 0;
@@ -482,12 +482,11 @@ out:
static int
ngfrm_shutdown(node_p node)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
- node->flags |= NG_INVALID;
- node->private = NULL;
+ NG_NODE_SET_PRIVATE(node, NULL);
FREE(sc, M_NETGRAPH);
- ng_unref(node);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -500,8 +499,8 @@ ngfrm_shutdown(node_p node)
static int
ngfrm_disconnect(hook_p hook)
{
- const sc_p sc = hook->node->private;
- struct ctxinfo *const cp = hook->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
+ struct ctxinfo *const cp = NG_HOOK_PRIVATE(hook);
int dlci;
/* If it's a regular dlci hook, then free resources etc.. */
@@ -513,8 +512,8 @@ ngfrm_disconnect(hook_p hook)
cp->flags = 0;
sc->datahooks--;
}
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_hole.c b/sys/netgraph/ng_hole.c
index 92fa603..8b4df29 100644
--- a/sys/netgraph/ng_hole.c
+++ b/sys/netgraph/ng_hole.c
@@ -45,6 +45,7 @@
*/
#include <sys/param.h>
+#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
@@ -98,7 +99,7 @@ ngh_rcvdata(hook_p hook, item_p item)
static int
ngh_disconnect(hook_p hook)
{
- if (hook->node->numhooks == 0)
- ng_rmnode_self(hook->node);
+ if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index 42aa1ba..820ec88 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -550,7 +550,7 @@ ng_iface_constructor(node_p node)
}
/* Link together node and private info */
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
priv->node = node;
/* Initialize interface structure */
@@ -594,7 +594,7 @@ ng_iface_newhook(node_p node, hook_p hook, const char *name)
if (iffam == NULL)
return (EPFNOSUPPORT);
- hookptr = get_hook_from_iffam((priv_p) node->private, iffam);
+ hookptr = get_hook_from_iffam(NG_NODE_PRIVATE(node), iffam);
if (*hookptr != NULL)
return (EISCONN);
*hookptr = hook;
@@ -607,7 +607,7 @@ ng_iface_newhook(node_p node, hook_p hook, const char *name)
static int
ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ifnet *const ifp = priv->ifp;
struct ng_mesg *resp = NULL;
int error = 0;
@@ -709,7 +709,7 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_iface_rcvdata(hook_p hook, item_p item)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
const iffam_p iffam = get_iffam_from_hook(priv, hook);
struct ifnet *const ifp = priv->ifp;
struct mbuf *m;
@@ -746,15 +746,15 @@ ng_iface_rcvdata(hook_p hook, item_p item)
static int
ng_iface_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
bpfdetach(priv->ifp);
if_detach(priv->ifp);
priv->ifp = NULL;
ng_iface_free_unit(priv->unit);
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -765,7 +765,7 @@ ng_iface_shutdown(node_p node)
static int
ng_iface_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
const iffam_p iffam = get_iffam_from_hook(priv, hook);
if (iffam == NULL)
diff --git a/sys/netgraph/ng_ksocket.c b/sys/netgraph/ng_ksocket.c
index 5162da5..fec2336 100644
--- a/sys/netgraph/ng_ksocket.c
+++ b/sys/netgraph/ng_ksocket.c
@@ -493,7 +493,7 @@ ng_ksocket_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Done */
return (0);
@@ -511,7 +511,7 @@ static int
ng_ksocket_newhook(node_p node, hook_p hook, const char *name0)
{
struct proc *p = curproc ? curproc : &proc0; /* XXX broken */
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
char *s1, *s2, name[NG_HOOKLEN+1];
int family, type, protocol, error;
@@ -560,7 +560,7 @@ static int
ng_ksocket_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
struct proc *p = curproc ? curproc : &proc0; /* XXX broken */
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct socket *const so = priv->so;
struct ng_mesg *resp = NULL;
int error = 0;
@@ -774,8 +774,8 @@ static int
ng_ksocket_rcvdata(hook_p hook, item_p item)
{
struct proc *p = curproc ? curproc : &proc0; /* XXX broken */
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct socket *const so = priv->so;
int error;
struct mbuf *m;
@@ -792,7 +792,7 @@ ng_ksocket_rcvdata(hook_p hook, item_p item)
static int
ng_ksocket_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Close our socket (if any) */
if (priv->so != NULL) {
@@ -804,11 +804,10 @@ ng_ksocket_shutdown(node_p node)
}
/* Take down netgraph node */
- node->flags |= NG_INVALID;
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node); /* let the node escape */
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node); /* let the node escape */
return (0);
}
@@ -818,10 +817,10 @@ ng_ksocket_shutdown(node_p node)
static int
ng_ksocket_disconnect(hook_p hook)
{
- KASSERT(hook->node->numhooks == 0,
- ("%s: numhooks=%d?", __FUNCTION__, hook->node->numhooks));
- if ((hook->node->flags & NG_INVALID) == 0)
- ng_rmnode_self(hook->node);
+ KASSERT(NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0,
+ ("%s: numhooks=%d?", __FUNCTION__, NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook))));
+ if (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
@@ -836,7 +835,7 @@ static void
ng_ksocket_incoming(struct socket *so, void *arg, int waitflag)
{
const node_p node = arg;
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m;
struct uio auio;
int s, flags, error;
@@ -844,7 +843,7 @@ ng_ksocket_incoming(struct socket *so, void *arg, int waitflag)
s = splnet();
/* Sanity check */
- if ((node->flags & NG_INVALID) != 0) {
+ if (NG_NODE_NOT_VALID(node)) {
splx(s);
return;
}
diff --git a/sys/netgraph/ng_lmi.c b/sys/netgraph/ng_lmi.c
index c088680..7a8ea4a 100644
--- a/sys/netgraph/ng_lmi.c
+++ b/sys/netgraph/ng_lmi.c
@@ -192,7 +192,7 @@ nglmi_constructor(node_p node)
if (sc == NULL)
return (ENOMEM);
callout_handle_init(&sc->handle);
- node->private = sc;
+ NG_NODE_SET_PRIVATE(node, sc);
sc->protoname = NAME_NONE;
sc->node = node;
sc->liv_per_full = NG_LMI_SEQ_PER_FULL; /* make this dynamic */
@@ -207,10 +207,10 @@ nglmi_constructor(node_p node)
static int
nglmi_newhook(node_p node, hook_p hook, const char *name)
{
- sc_p sc = node->private;
+ sc_p sc = NG_NODE_PRIVATE(node);
if (strcmp(name, NG_LMI_HOOK_DEBUG) == 0) {
- hook->private = NULL;
+ NG_HOOK_SET_PRIVATE(hook, NULL);
return (0);
}
if (sc->flags & SCF_CONNECTED) {
@@ -219,21 +219,21 @@ nglmi_newhook(node_p node, hook_p hook, const char *name)
}
if (strcmp(name, NG_LMI_HOOK_ANNEXA) == 0) {
sc->lmi_annexA = hook;
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
sc->protoID = 8;
SETLMITYPE(sc, SCF_ANNEX_A);
sc->protoname = NAME_ANNEXA;
nglmi_startup_fixed(sc, hook);
} else if (strcmp(name, NG_LMI_HOOK_ANNEXD) == 0) {
sc->lmi_annexD = hook;
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
sc->protoID = 8;
SETLMITYPE(sc, SCF_ANNEX_D);
sc->protoname = NAME_ANNEXD;
nglmi_startup_fixed(sc, hook);
} else if (strcmp(name, NG_LMI_HOOK_GROUPOF4) == 0) {
sc->lmi_group4 = hook;
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
sc->protoID = 9;
SETLMITYPE(sc, SCF_GROUP4);
sc->protoname = NAME_GROUP4;
@@ -242,14 +242,14 @@ nglmi_newhook(node_p node, hook_p hook, const char *name)
/* Note this, and if B is already installed, we're complete */
sc->lmi_channel0 = hook;
sc->protoname = NAME_NONE;
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
if (sc->lmi_channel1023)
nglmi_startup_auto(sc);
} else if (strcmp(name, NG_LMI_HOOK_AUTO1023) == 0) {
/* Note this, and if A is already installed, we're complete */
sc->lmi_channel1023 = hook;
sc->protoname = NAME_NONE;
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
if (sc->lmi_channel0)
nglmi_startup_auto(sc);
} else
@@ -445,7 +445,7 @@ ngauto_state_machine(sc_p sc)
static int
nglmi_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- sc_p sc = node->private;
+ sc_p sc = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -557,7 +557,7 @@ nglmi_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
nglmi_rcvdata(hook_p hook, item_p item)
{
- sc_p sc = hook->node->private;
+ sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
u_char *data;
unsigned short dlci;
u_short packetlen;
@@ -567,7 +567,7 @@ nglmi_rcvdata(hook_p hook, item_p item)
NGI_GET_M(item, m);
NG_FREE_ITEM(item);
- if (hook->private == NULL) {
+ if (NG_HOOK_PRIVATE(hook) == NULL) {
goto drop;
}
packetlen = m->m_hdr.mh_len;
@@ -742,7 +742,7 @@ drop:
static int
nglmi_checkdata(hook_p hook, struct mbuf *m)
{
- sc_p sc = hook->node->private;
+ sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
u_char *data;
u_short packetlen;
unsigned short dlci;
@@ -1055,11 +1055,10 @@ reject:
static int
nglmi_shutdown(node_p node)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
- node->flags |= NG_INVALID;
- node->private = NULL;
- ng_unref(sc->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(sc->node);
FREE(sc, M_NETGRAPH);
return (0);
}
@@ -1071,10 +1070,10 @@ nglmi_shutdown(node_p node)
static int
nglmi_disconnect(hook_p hook)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
/* OK to remove debug hook(s) */
- if (hook->private == NULL)
+ if (NG_HOOK_PRIVATE(hook) == NULL)
return (0);
/* Stop timer if it's currently active */
@@ -1082,8 +1081,8 @@ nglmi_disconnect(hook_p hook)
untimeout(LMI_ticker, sc, sc->handle);
/* Self-destruct */
- if ((hook->node->flags & NG_INVALID) == 0)
- ng_rmnode_self(hook->node);
+ if (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_mppc.c b/sys/netgraph/ng_mppc.c
index 93cdc8c..0192251 100644
--- a/sys/netgraph/ng_mppc.c
+++ b/sys/netgraph/ng_mppc.c
@@ -180,7 +180,7 @@ ng_mppc_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Done */
return (0);
@@ -192,7 +192,7 @@ ng_mppc_constructor(node_p node)
static int
ng_mppc_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
hook_p *hookPtr;
/* Check hook name */
@@ -218,7 +218,7 @@ ng_mppc_newhook(node_p node, hook_p hook, const char *name)
static int
ng_mppc_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -328,8 +328,8 @@ done:
static int
ng_mppc_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *out;
int error;
struct mbuf *m;
@@ -390,10 +390,9 @@ ng_mppc_rcvdata(hook_p hook, item_p item)
static int
ng_mppc_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Take down netgraph node */
- node->flags |= NG_INVALID;
#ifdef NETGRAPH_MPPC_COMPRESSION
if (priv->xmit.history != NULL)
FREE(priv->xmit.history, M_NETGRAPH);
@@ -402,8 +401,8 @@ ng_mppc_shutdown(node_p node)
#endif
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node); /* let the node escape */
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node); /* let the node escape */
return (0);
}
@@ -413,8 +412,8 @@ ng_mppc_shutdown(node_p node)
static int
ng_mppc_disconnect(hook_p hook)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Zero out hook pointer */
if (hook == priv->xmit.hook)
@@ -423,8 +422,8 @@ ng_mppc_disconnect(hook_p hook)
priv->recv.hook = NULL;
/* Go away if no longer connected */
- if ((node->numhooks == 0)
- && ((node->flags & NG_INVALID) == 0))
+ if ((NG_NODE_NUMHOOKS(node) == 0)
+ && NG_NODE_IS_VALID(node))
ng_rmnode_self(node);
return (0);
}
@@ -440,7 +439,7 @@ ng_mppc_disconnect(hook_p hook)
static int
ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mppc_dir *const d = &priv->xmit;
u_char *inbuf, *outbuf;
int outlen, inlen;
@@ -556,7 +555,7 @@ ng_mppc_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
static int
ng_mppc_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mppc_dir *const d = &priv->recv;
u_int16_t header, cc, numLost;
u_char *buf;
@@ -719,7 +718,7 @@ failed:
static void
ng_mppc_reset_req(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mppc_dir *const d = &priv->xmit;
#ifdef NETGRAPH_MPPC_COMPRESSION
diff --git a/sys/netgraph/ng_one2many.c b/sys/netgraph/ng_one2many.c
index bf800a8..89d1927 100644
--- a/sys/netgraph/ng_one2many.c
+++ b/sys/netgraph/ng_one2many.c
@@ -196,7 +196,7 @@ ng_one2many_constructor(node_p node)
priv->conf.xmitAlg = NG_ONE2MANY_XMIT_ROUNDROBIN;
priv->conf.failAlg = NG_ONE2MANY_FAIL_MANUAL;
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Done */
return (0);
@@ -208,7 +208,7 @@ ng_one2many_constructor(node_p node)
static int
ng_one2many_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_one2many_link *link;
int linkNum;
u_long i;
@@ -238,7 +238,7 @@ ng_one2many_newhook(node_p node, hook_p hook, const char *name)
return (EISCONN);
/* Setup private info for this link */
- LINK_NUM(hook) = linkNum;
+ NG_HOOK_SET_PRIVATE(hook, (void *)linkNum);
link->hook = hook;
bzero(&link->stats, sizeof(link->stats));
if (linkNum != NG_ONE2MANY_ONE_LINKNUM) {
@@ -256,7 +256,7 @@ ng_one2many_newhook(node_p node, hook_p hook, const char *name)
static int
ng_one2many_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -375,8 +375,8 @@ ng_one2many_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_one2many_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_one2many_link *src;
struct ng_one2many_link *dst;
int error = 0;
@@ -385,7 +385,7 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
m = NGI_M(item); /* just peaking, mbuf still owned by item */
/* Get link number */
- linkNum = LINK_NUM(hook);
+ linkNum = (int)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum == NG_ONE2MANY_ONE_LINKNUM
|| (linkNum >= 0 && linkNum < NG_ONE2MANY_MAX_LINKS),
("%s: linkNum=%d", __FUNCTION__, linkNum));
@@ -415,7 +415,7 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
dst->stats.xmitOctets += m->m_pkthdr.len;
/* Deliver packet */
- NG_FWD_DATA(error, item, dst->hook);
+ NG_FWD_ITEM_HOOK(error, item, dst->hook);
return (error);
}
@@ -425,13 +425,13 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
static int
ng_one2many_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
KASSERT(priv->numActiveMany == 0,
("%s: numActiveMany=%d", __FUNCTION__, priv->numActiveMany));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -441,11 +441,11 @@ ng_one2many_shutdown(node_p node)
static int
ng_one2many_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int linkNum;
/* Get link number */
- linkNum = LINK_NUM(hook);
+ linkNum = (int)NG_HOOK_PRIVATE(hook);
KASSERT(linkNum == NG_ONE2MANY_ONE_LINKNUM
|| (linkNum >= 0 && linkNum < NG_ONE2MANY_MAX_LINKS),
("%s: linkNum=%d", __FUNCTION__, linkNum));
@@ -460,9 +460,9 @@ ng_one2many_disconnect(hook_p hook)
}
/* If no hooks left, go away */
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_ppp.c b/sys/netgraph/ng_ppp.c
index 2587207..fdf84df 100644
--- a/sys/netgraph/ng_ppp.c
+++ b/sys/netgraph/ng_ppp.c
@@ -170,8 +170,10 @@ static const char *const ng_ppp_hook_names[] = {
/* We store index numbers in the hook private pointer. The HOOK_INDEX()
for a hook is either the index (above) for normal hooks, or the ones
- complement of the link number for link hooks. */
+ complement of the link number for link hooks.
+XXX Not any more.. (what a hack)
#define HOOK_INDEX(hook) (*((int16_t *) &(hook)->private))
+*/
/* Per-link private information */
struct ng_ppp_link {
@@ -384,7 +386,7 @@ ng_ppp_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Initialize state */
TAILQ_INIT(&priv->frags);
@@ -402,7 +404,7 @@ ng_ppp_constructor(node_p node)
static int
ng_ppp_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int linkNum = -1;
hook_p *hookPtr = NULL;
int hookIndex = -1;
@@ -446,7 +448,7 @@ ng_ppp_newhook(node_p node, hook_p hook, const char *name)
/* OK */
*hookPtr = hook;
- HOOK_INDEX(hook) = hookIndex;
+ NG_HOOK_SET_PRIVATE(hook, (void *)hookIndex);
ng_ppp_update(node, 0);
return (0);
}
@@ -457,7 +459,7 @@ ng_ppp_newhook(node_p node, hook_p hook, const char *name)
static int
ng_ppp_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -553,11 +555,16 @@ ng_ppp_rcvmsg(node_p node, item_p item, hook_p lasthook)
/*
* Forward it to the vjc node. leave the
* old return address alone.
+ * If we have no hook, let NG_RESPOND_MSG
+ * clean up any remaining resources.
+ * Because we have no resp, the item will be freed
+ * along with anything it references. Don't
+ * let msg be freed twice.
*/
NGI_MSG(item) = msg; /* put it back in the item */
- if (priv->links[HOOK_INDEX_VJC_IP].hook) {
- NG_FWD_MSG_HOOK(error, NULL, item,
- priv->links[HOOK_INDEX_VJC_IP].hook, NULL);
+ msg = NULL;
+ if ((lasthook = priv->links[HOOK_INDEX_VJC_IP].hook)) {
+ NG_FWD_ITEM_HOOK(error, item, lasthook);
}
return (error);
}
@@ -577,9 +584,9 @@ done:
static int
ng_ppp_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
- const int index = HOOK_INDEX(hook);
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
+ const int index = (int)NG_HOOK_PRIVATE(hook);
u_int16_t linkNum = NG_PPP_BUNDLE_LINKNUM;
hook_p outHook = NULL;
int proto = 0, error;
@@ -780,13 +787,7 @@ ng_ppp_rcvdata(hook_p hook, item_p item)
}
/* Send packet out hook */
- NG_FWD_DATA(error, item, outHook);
-#if 0
- /* help archie... what's going on? */
- /* Looks like you were acrually USING the stub functions
- (now gone again) */
- return ng_ppp_rcvdata(outHook, item);
-#endif
+ NG_FWD_ITEM_HOOK(error, item, outHook);
return (error);
}
@@ -796,18 +797,17 @@ ng_ppp_rcvdata(hook_p hook, item_p item)
static int
ng_ppp_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Stop fragment queue timer */
ng_ppp_stop_frag_timer(node);
/* Take down netgraph node */
- node->flags |= NG_INVALID;
ng_ppp_frag_reset(node);
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node); /* let the node escape */
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node); /* let the node escape */
return (0);
}
@@ -817,9 +817,9 @@ ng_ppp_shutdown(node_p node)
static int
ng_ppp_disconnect(hook_p hook)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
- const int index = HOOK_INDEX(hook);
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
+ const int index = (int)NG_HOOK_PRIVATE(hook);
/* Zero out hook pointer */
if (index < 0)
@@ -828,10 +828,10 @@ ng_ppp_disconnect(hook_p hook)
priv->hooks[index] = NULL;
/* Update derived info (or go away if no hooks left) */
- if (node->numhooks > 0) {
+ if (NG_NODE_NUMHOOKS(node) > 0) {
ng_ppp_update(node, 0);
} else {
- if ((node->flags & NG_INVALID) == 0) {
+ if (NG_NODE_IS_VALID(node)) {
ng_rmnode_self(node);
}
}
@@ -849,7 +849,7 @@ ng_ppp_disconnect(hook_p hook)
static int
ng_ppp_input(node_p node, int bypass, int linkNum, item_p item)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
hook_p outHook = NULL;
int proto, error;
struct mbuf *m;
@@ -947,7 +947,7 @@ static int
ng_ppp_output(node_p node, int bypass,
int proto, int linkNum, item_p item)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_link *link;
int len, error;
struct mbuf *m;
@@ -1070,7 +1070,7 @@ ng_ppp_output(node_p node, int bypass,
static int
ng_ppp_mp_input(node_p node, int linkNum, item_p item)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_link *const link = &priv->links[linkNum];
struct ng_ppp_frag frag0, *frag = &frag0;
struct ng_ppp_frag *qent;
@@ -1190,7 +1190,7 @@ ng_ppp_mp_input(node_p node, int linkNum, item_p item)
static int
ng_ppp_check_packet(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_frag *qent, *qnext;
/* Check for empty queue */
@@ -1223,7 +1223,7 @@ ng_ppp_check_packet(node_p node)
static void
ng_ppp_get_packet(node_p node, struct mbuf **mp, meta_p *metap)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_frag *qent, *qnext;
struct mbuf *m = NULL, *tail;
@@ -1261,7 +1261,7 @@ ng_ppp_get_packet(node_p node, struct mbuf **mp, meta_p *metap)
static int
ng_ppp_frag_trim(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_frag *qent, *qnext = NULL;
int removed = 0;
@@ -1311,7 +1311,7 @@ ng_ppp_frag_trim(node_p node)
static int
ng_ppp_frag_process(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct mbuf *m;
meta_p meta;
item_p item;
@@ -1389,7 +1389,7 @@ ng_ppp_frag_process(node_p node)
static void
ng_ppp_frag_checkstale(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_frag *qent, *beg, *end;
struct timeval now, age;
struct mbuf *m;
@@ -1474,12 +1474,12 @@ static void
ng_ppp_frag_timeout(void *arg)
{
const node_p node = arg;
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int s = splnet();
/* Handle the race where shutdown happens just before splnet() above */
- if ((node->flags & NG_INVALID) != 0) {
- ng_unref(node);
+ if (NG_NODE_NOT_VALID(node)) {
+ NG_NODE_UNREF(node);
splx(s);
return;
}
@@ -1487,8 +1487,8 @@ ng_ppp_frag_timeout(void *arg)
/* Reset timer state after timeout */
KASSERT(priv->timerActive, ("%s: !timerActive", __FUNCTION__));
priv->timerActive = 0;
- KASSERT(node->refs > 1, ("%s: refs=%d", __FUNCTION__, node->refs));
- ng_unref(node);
+ KASSERT(node->nd_refs > 1, ("%s: nd_refs=%d", __FUNCTION__, node->nd_refs));
+ NG_NODE_UNREF(node);
/* Start timer again */
ng_ppp_start_frag_timer(node);
@@ -1505,7 +1505,7 @@ ng_ppp_frag_timeout(void *arg)
static int
ng_ppp_mp_output(node_p node, struct mbuf *m, meta_p meta)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int distrib[NG_PPP_MAX_LINKS];
int firstFragment;
int activeLinkNum;
@@ -1720,7 +1720,7 @@ deliver:
static void
ng_ppp_mp_strategy(node_p node, int len, int *distrib)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int latency[NG_PPP_MAX_LINKS];
int sortByLatency[NG_PPP_MAX_LINKS];
int activeLinkNum;
@@ -1906,7 +1906,7 @@ ng_ppp_prepend(struct mbuf *m, const void *buf, int len)
static void
ng_ppp_update(node_p node, int newConf)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int i;
/* Update active status for VJ Compression */
@@ -1983,7 +1983,7 @@ ng_ppp_update(node_p node, int newConf)
static int
ng_ppp_config_valid(node_p node, const struct ng_ppp_node_conf *newConf)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int i, newNumLinksActive;
/* Check per-link config and count how many links would be active */
@@ -2029,7 +2029,7 @@ ng_ppp_config_valid(node_p node, const struct ng_ppp_node_conf *newConf)
static void
ng_ppp_frag_reset(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_ppp_frag *qent, *qnext;
for (qent = TAILQ_FIRST(&priv->frags); qent; qent = qnext) {
@@ -2048,13 +2048,13 @@ ng_ppp_frag_reset(node_p node)
static void
ng_ppp_start_frag_timer(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
if (!priv->timerActive) {
priv->fragTimer = timeout(ng_ppp_frag_timeout,
node, MP_FRAGTIMER_INTERVAL);
priv->timerActive = 1;
- node->refs++;
+ NG_NODE_REF(node);
}
}
@@ -2064,14 +2064,14 @@ ng_ppp_start_frag_timer(node_p node)
static void
ng_ppp_stop_frag_timer(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
if (priv->timerActive) {
untimeout(ng_ppp_frag_timeout, node, priv->fragTimer);
priv->timerActive = 0;
- KASSERT(node->refs > 1,
- ("%s: refs=%d", __FUNCTION__, node->refs));
- ng_unref(node);
+ KASSERT(node->nd_refs > 1,
+ ("%s: nd_refs=%d", __FUNCTION__, node->nd_refs));
+ NG_NODE_UNREF(node);
}
}
diff --git a/sys/netgraph/ng_pppoe.c b/sys/netgraph/ng_pppoe.c
index 4b90f9f..8d20f49 100644
--- a/sys/netgraph/ng_pppoe.c
+++ b/sys/netgraph/ng_pppoe.c
@@ -263,7 +263,7 @@ get_new_sid(node_p node)
sessp sp;
hook_p hook;
u_int16_t val;
- priv_p privp = node->private;
+ priv_p privp = NG_NODE_PRIVATE(node);
AAA
restart:
@@ -278,12 +278,12 @@ restart:
}
/* Check it isn't already in use */
- LIST_FOREACH(hook, &node->hooks, hooks) {
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
/* don't check special hooks */
- if ((hook->private == &privp->debug_hook)
- || (hook->private == &privp->ethernet_hook))
+ if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
+ || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
continue;
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
if (sp->Session_ID == val)
goto restart;
}
@@ -423,17 +423,17 @@ pppoe_match_svc(node_p node, char *svc_name, int svc_len)
{
sessp sp = NULL;
negp neg = NULL;
- priv_p privp = node->private;
+ priv_p privp = NG_NODE_PRIVATE(node);
hook_p hook;
AAA
- LIST_FOREACH(hook, &node->hooks, hooks) {
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
/* skip any hook that is debug or ethernet */
- if ((hook->private == &privp->debug_hook)
- || (hook->private == &privp->ethernet_hook))
+ if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
+ || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
continue;
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
/* Skip any sessions which are not in LISTEN mode. */
if ( sp->state != PPPOE_LISTENING)
@@ -471,20 +471,20 @@ pppoe_findsession(node_p node, struct pppoe_full_hdr *wh)
{
sessp sp = NULL;
hook_p hook = NULL;
- priv_p privp = node->private;
+ priv_p privp = NG_NODE_PRIVATE(node);
u_int16_t session = ntohs(wh->ph.sid);
/*
* find matching peer/session combination.
*/
AAA
- LIST_FOREACH(hook, &node->hooks, hooks) {
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
/* don't check special hooks */
- if ((hook->private == &privp->debug_hook)
- || (hook->private == &privp->ethernet_hook)) {
+ if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
+ || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) {
continue;
}
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
if ( ( (sp->state == PPPOE_CONNECTED)
|| (sp->state == PPPOE_NEWCONNECTED) )
&& (sp->Session_ID == session)
@@ -501,18 +501,18 @@ static hook_p
pppoe_finduniq(node_p node, struct pppoe_tag *tag)
{
hook_p hook = NULL;
- priv_p privp = node->private;
+ priv_p privp = NG_NODE_PRIVATE(node);
union uniq uniq;
AAA
bcopy(tag->tag_data, uniq.bytes, sizeof(void *));
/* cycle through all known hooks */
- LIST_FOREACH(hook, &node->hooks, hooks) {
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
/* don't check special hooks */
- if ((hook->private == &privp->debug_hook)
- || (hook->private == &privp->ethernet_hook))
+ if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
+ || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
continue;
- if (uniq.pointer == hook->private)
+ if (uniq.pointer == NG_HOOK_PRIVATE(hook))
break;
}
return (hook);
@@ -544,7 +544,7 @@ AAA
return (ENOMEM);
/* Link structs together; this counts as our one reference to *nodep */
- node->private = privdata;
+ NG_NODE_SET_PRIVATE(node, privdata);
privdata->node = node;
return (0);
}
@@ -561,16 +561,16 @@ AAA
static int
ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p privp = node->private;
+ const priv_p privp = NG_NODE_PRIVATE(node);
sessp sp;
AAA
if (strcmp(name, NG_PPPOE_HOOK_ETHERNET) == 0) {
privp->ethernet_hook = hook;
- hook->private = &privp->ethernet_hook;
+ NG_HOOK_SET_PRIVATE(hook, &privp->ethernet_hook);
} else if (strcmp(name, NG_PPPOE_HOOK_DEBUG) == 0) {
privp->debug_hook = hook;
- hook->private = &privp->debug_hook;
+ NG_HOOK_SET_PRIVATE(hook, &privp->debug_hook);
} else {
/*
* Any other unique name is OK.
@@ -582,7 +582,7 @@ AAA
return (ENOMEM);
}
- hook->private = sp;
+ NG_HOOK_SET_PRIVATE(hook, sp);
sp->hook = hook;
}
return(0);
@@ -597,7 +597,7 @@ AAA
static int
ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- priv_p privp = node->private;
+ priv_p privp = NG_NODE_PRIVATE(node);
struct ngpppoe_init_data *ourmsg = NULL;
struct ng_mesg *resp = NULL;
int error = 0;
@@ -638,19 +638,19 @@ AAA
ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
/* cycle through all known hooks */
- LIST_FOREACH(hook, &node->hooks, hooks) {
- if (hook->name
- && strcmp(hook->name, ourmsg->hook) == 0)
+ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
+ if (NG_HOOK_NAME(hook)
+ && strcmp(NG_HOOK_NAME(hook), ourmsg->hook) == 0)
break;
}
if (hook == NULL) {
LEAVE(ENOENT);
}
- if ((hook->private == &privp->debug_hook)
- || (hook->private == &privp->ethernet_hook)) {
+ if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
+ || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) {
LEAVE(EINVAL);
}
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
/*
* PPPOE_SERVICE advertisments are set up
@@ -848,9 +848,9 @@ AAA
static int
ng_pppoe_rcvdata(hook_p hook, item_p item)
{
- node_p node = hook->node;
- const priv_p privp = node->private;
- sessp sp = hook->private;
+ node_p node = NG_HOOK_NODE(hook);
+ const priv_p privp = NG_NODE_PRIVATE(node);
+ sessp sp = NG_HOOK_PRIVATE(hook);
struct pppoe_full_hdr *wh;
struct pppoe_hdr *ph;
int error = 0;
@@ -868,14 +868,14 @@ ng_pppoe_rcvdata(hook_p hook, item_p item)
AAA
NGI_GET_M(item, m);
- if (hook->private == &privp->debug_hook) {
+ if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
/*
* Data from the debug hook gets sent without modification
* straight to the ethernet.
*/
- NG_FWD_DATA( error, item, privp->ethernet_hook);
+ NG_FWD_ITEM_HOOK( error, item, privp->ethernet_hook);
privp->packets_out++;
- } else if (hook->private == &privp->ethernet_hook) {
+ } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
/*
* Incoming data.
* Dig out various fields from the packet.
@@ -952,7 +952,7 @@ AAA
printf("no service tag\n");
LEAVE(ENETUNREACH);
}
- sendhook = pppoe_match_svc(hook->node,
+ sendhook = pppoe_match_svc(NG_HOOK_NODE(hook),
tag->tag_data, ntohs(tag->tag_len));
if (sendhook) {
NG_FWD_NEW_DATA(error, item,
@@ -987,7 +987,7 @@ AAA
* Check the session is in the right state.
* It needs to be in PPPOE_SINIT.
*/
- sp = sendhook->private;
+ sp = NG_HOOK_PRIVATE(sendhook);
if (sp->state != PPPOE_SINIT) {
printf("session in wrong state\n");
LEAVE(ENETUNREACH);
@@ -1044,7 +1044,7 @@ AAA
* then this is a retry by the client.
* so be nice, and resend.
*/
- sp = sendhook->private;
+ sp = NG_HOOK_PRIVATE(sendhook);
if (sp->state == PPPOE_NEWCONNECTED) {
/*
* Whoa! drop back to resend that
@@ -1119,7 +1119,7 @@ AAA
* Check the session is in the right state.
* It needs to be in PPPOE_SREQ.
*/
- sp = sendhook->private;
+ sp = NG_HOOK_PRIVATE(sendhook);
if (sp->state != PPPOE_SREQ) {
LEAVE(ENETUNREACH);
}
@@ -1176,7 +1176,7 @@ AAA
LEAVE (ENETUNREACH);
break;
}
- sp = sendhook->private;
+ sp = NG_HOOK_PRIVATE(sendhook);
m_adj(m, sizeof(*wh));
if (m->m_pkthdr.len < length) {
/* Packet too short, dump it */
@@ -1220,7 +1220,7 @@ AAA
* So we can decide how to handle it.
* Check the hook's state.
*/
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
switch (sp->state) {
case PPPOE_NEWCONNECTED:
case PPPOE_CONNECTED: {
@@ -1349,12 +1349,11 @@ quit:
static int
ng_pppoe_shutdown(node_p node)
{
- const priv_p privdata = node->private;
+ const priv_p privdata = NG_NODE_PRIVATE(node);
AAA
- node->flags |= NG_INVALID;
- node->private = NULL;
- ng_unref(privdata->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(privdata->node);
FREE(privdata, M_NETGRAPH);
return (0);
}
@@ -1379,21 +1378,21 @@ ng_pppoe_connect(hook_p hook)
static int
ng_pppoe_disconnect(hook_p hook)
{
- node_p node = hook->node;
- priv_p privp = node->private;
+ node_p node = NG_HOOK_NODE(hook);
+ priv_p privp = NG_NODE_PRIVATE(node);
sessp sp;
int hooks;
AAA
- hooks = node->numhooks; /* this one already not counted */
- if (hook->private == &privp->debug_hook) {
+ hooks = NG_NODE_NUMHOOKS(node); /* this one already not counted */
+ if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
privp->debug_hook = NULL;
- } else if (hook->private == &privp->ethernet_hook) {
+ } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
privp->ethernet_hook = NULL;
- if ((node->flags & NG_INVALID) == 0)
+ if (NG_NODE_IS_VALID(node))
ng_rmnode_self(node);
} else {
- sp = hook->private;
+ sp = NG_HOOK_PRIVATE(hook);
if (sp->state != PPPOE_SNONE ) {
pppoe_send_event(sp, NGM_PPPOE_CLOSE);
}
@@ -1452,14 +1451,14 @@ AAA
FREE(sp->neg, M_NETGRAPH);
}
FREE(sp, M_NETGRAPH);
- hook->private = NULL;
+ NG_HOOK_SET_PRIVATE(hook, NULL);
/* work out how many session hooks there are */
/* Node goes away on last session hook removal */
if (privp->ethernet_hook) hooks -= 1;
if (privp->debug_hook) hooks -= 1;
}
- if ((node->numhooks == 0)
- && ((node->flags & NG_INVALID) == 0))
+ if ((NG_NODE_NUMHOOKS(node) == 0)
+ && (NG_NODE_IS_VALID(node)))
ng_rmnode_self(node);
return (0);
}
@@ -1472,11 +1471,11 @@ pppoe_ticker(void *arg)
{
int s = splnet();
hook_p hook = arg;
- sessp sp = hook->private;
+ sessp sp = NG_HOOK_PRIVATE(hook);
negp neg = sp->neg;
int error = 0;
struct mbuf *m0 = NULL;
- priv_p privp = hook->node->private;
+ priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
AAA
switch(sp->state) {
@@ -1521,7 +1520,7 @@ sendpacket(sessp sp)
struct mbuf *m0 = NULL;
hook_p hook = sp->hook;
negp neg = sp->neg;
- priv_p privp = hook->node->private;
+ priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
AAA
switch(sp->state) {
@@ -1628,7 +1627,7 @@ AAA
if (msg == NULL)
return (ENOMEM);
sts = (struct ngpppoe_sts *)msg->data;
- strncpy(sts->hook, sp->hook->name, NG_HOOKLEN + 1);
- NG_SEND_MSG_ID(error, sp->hook->node, msg, sp->creator, NULL);
+ strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKLEN + 1);
+ NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, NULL);
return (error);
}
diff --git a/sys/netgraph/ng_pptpgre.c b/sys/netgraph/ng_pptpgre.c
index c126d9d..a165a3a 100644
--- a/sys/netgraph/ng_pptpgre.c
+++ b/sys/netgraph/ng_pptpgre.c
@@ -279,7 +279,7 @@ ng_pptpgre_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Initialize state */
callout_handle_init(&priv->ackp.sackTimer);
@@ -295,7 +295,7 @@ ng_pptpgre_constructor(node_p node)
static int
ng_pptpgre_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
hook_p *hookPtr;
/* Check hook name */
@@ -321,7 +321,7 @@ ng_pptpgre_newhook(node_p node, hook_p hook, const char *name)
static int
ng_pptpgre_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -385,8 +385,8 @@ done:
static int
ng_pptpgre_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* If not configured, reject */
if (!priv->conf.enabled) {
@@ -408,17 +408,16 @@ ng_pptpgre_rcvdata(hook_p hook, item_p item)
static int
ng_pptpgre_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Reset node */
ng_pptpgre_reset(node);
/* Take down netgraph node */
- node->flags |= NG_INVALID;
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -428,8 +427,8 @@ ng_pptpgre_shutdown(node_p node)
static int
ng_pptpgre_disconnect(hook_p hook)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Zero out hook pointer */
if (hook == priv->upper)
@@ -440,8 +439,8 @@ ng_pptpgre_disconnect(hook_p hook)
panic("%s: unknown hook", __FUNCTION__);
/* Go away if no longer connected to anything */
- if ((node->numhooks == 0)
- && ((node->flags & NG_INVALID) == 0))
+ if ((NG_NODE_NUMHOOKS(node) == 0)
+ && (NG_NODE_IS_VALID(node)))
ng_rmnode_self(node);
return (0);
}
@@ -456,7 +455,7 @@ ng_pptpgre_disconnect(hook_p hook)
static int
ng_pptpgre_xmit(node_p node, item_p item)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
u_char buf[sizeof(struct greheader) + 2 * sizeof(u_int32_t)];
struct greheader *const gre = (struct greheader *)buf;
@@ -561,7 +560,7 @@ ng_pptpgre_xmit(node_p node, item_p item)
static int
ng_pptpgre_recv(node_p node, item_p item)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
int iphlen, grelen, extralen;
struct greheader *gre;
struct ip *ip;
@@ -739,7 +738,7 @@ badAck:
static void
ng_pptpgre_start_recv_ack_timer(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
int remain, ticks;
@@ -761,7 +760,7 @@ ng_pptpgre_start_recv_ack_timer(node_p node)
return; /* XXX potential hang here */
}
*a->rackTimerPtr = node; /* insures the correct timeout event */
- node->refs++;
+ NG_NODE_REF(node);
/* Be conservative: timeout() can return up to 1 tick early */
ticks = (((remain * hz) + PPTP_TIME_SCALE - 1) / PPTP_TIME_SCALE) + 1;
@@ -779,18 +778,18 @@ ng_pptpgre_recv_ack_timeout(void *arg)
{
int s = splnet();
const node_p node = *((node_p *)arg);
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
/* This complicated stuff is needed to avoid race conditions */
FREE(arg, M_NETGRAPH);
- KASSERT(node->refs > 0, ("%s: no refs", __FUNCTION__));
- if ((node->flags & NG_INVALID) != 0) { /* shutdown race condition */
- ng_unref(node);
+ KASSERT(node->nd_refs > 0, ("%s: no nd_refs", __FUNCTION__));
+ if (NG_NODE_NOT_VALID(node)) { /* shutdown race condition */
+ NG_NODE_UNREF(node);
splx(s);
return;
}
- ng_unref(node);
+ NG_NODE_UNREF(node);
if (arg != a->rackTimerPtr) { /* timer stopped race condition */
splx(s);
return;
@@ -827,7 +826,7 @@ ng_pptpgre_recv_ack_timeout(void *arg)
static void
ng_pptpgre_start_send_ack_timer(node_p node, int ackTimeout)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
int ticks;
@@ -839,7 +838,7 @@ ng_pptpgre_start_send_ack_timer(node_p node, int ackTimeout)
return; /* XXX potential hang here */
}
*a->sackTimerPtr = node;
- node->refs++;
+ NG_NODE_REF(node);
/* Be conservative: timeout() can return up to 1 tick early */
ticks = (((ackTimeout * hz) + PPTP_TIME_SCALE - 1) / PPTP_TIME_SCALE);
@@ -858,18 +857,18 @@ ng_pptpgre_send_ack_timeout(void *arg)
{
int s = splnet();
const node_p node = *((node_p *)arg);
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
/* This complicated stuff is needed to avoid race conditions */
FREE(arg, M_NETGRAPH);
- KASSERT(node->refs > 0, ("%s: no refs", __FUNCTION__));
- if ((node->flags & NG_INVALID) != 0) { /* shutdown race condition */
- ng_unref(node);
+ KASSERT(node->nd_refs > 0, ("%s: no nd_refs", __FUNCTION__));
+ if (NG_NODE_NOT_VALID(node)) { /* shutdown race condition */
+ NG_NODE_UNREF(node);
splx(s);
return;
}
- ng_unref(node);
+ NG_NODE_UNREF(node);
if (a->sackTimerPtr != arg) { /* timer stopped race condition */
splx(s);
return;
@@ -891,7 +890,7 @@ ng_pptpgre_send_ack_timeout(void *arg)
static void
ng_pptpgre_reset(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_pptpgre_ackp *const a = &priv->ackp;
/* Reset adaptive timeout state */
@@ -930,7 +929,7 @@ ng_pptpgre_reset(node_p node)
static pptptime_t
ng_pptpgre_time(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct timeval tv;
pptptime_t t;
diff --git a/sys/netgraph/ng_rfc1490.c b/sys/netgraph/ng_rfc1490.c
index 52ee66c..b18e297 100644
--- a/sys/netgraph/ng_rfc1490.c
+++ b/sys/netgraph/ng_rfc1490.c
@@ -128,7 +128,7 @@ ng_rfc1490_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Done */
return (0);
@@ -140,7 +140,7 @@ ng_rfc1490_constructor(node_p node)
static int
ng_rfc1490_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
if (!strcmp(name, NG_RFC1490_HOOK_DOWNSTREAM)) {
if (priv->downlink)
@@ -208,8 +208,8 @@ ng_rfc1490_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_rfc1490_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
int error = 0;
struct mbuf *m;
@@ -306,13 +306,12 @@ done:
static int
ng_rfc1490_shutdown(node_p node)
{
- const priv_p priv = node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Take down netgraph node */
- node->flags |= NG_INVALID;
bzero(priv, sizeof(*priv));
- node->private = NULL;
- ng_unref(node); /* let the node escape */
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node); /* let the node escape */
return (0);
}
@@ -322,11 +321,11 @@ ng_rfc1490_shutdown(node_p node)
static int
ng_rfc1490_disconnect(hook_p hook)
{
- const priv_p priv = hook->node->private;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
else if (hook == priv->downlink)
priv->downlink = NULL;
else if (hook == priv->inet)
diff --git a/sys/netgraph/ng_sample.c b/sys/netgraph/ng_sample.c
index 76558f3..90ed838 100644
--- a/sys/netgraph/ng_sample.c
+++ b/sys/netgraph/ng_sample.c
@@ -140,7 +140,7 @@ typedef struct XXX *xxx_p;
* to creatednodes that depend on hardware (unless you can add the hardware :)
*/
static int
-ng_xxx_constructor(node_p nodep)
+ng_xxx_constructor(node_p node)
{
xxx_p privdata;
int i, error;
@@ -156,8 +156,8 @@ ng_xxx_constructor(node_p nodep)
}
/* Link structs together; this counts as our one reference to *nodep */
- (*nodep)->private = privdata;
- privdata->node = *nodep;
+ NG_NODE_PRIVATE(node) = privdata;
+ privdata->node = node;
return (0);
}
@@ -176,7 +176,7 @@ ng_xxx_constructor(node_p nodep)
static int
ng_xxx_newhook(node_p node, hook_p hook, const char *name)
{
- const xxx_p xxxp = node->private;
+ const xxx_p xxxp = NG_NODE_PRIVATE(node);
const char *cp;
int dlci = 0;
int chan;
@@ -216,18 +216,18 @@ ng_xxx_newhook(node_p node, hook_p hook, const char *name)
}
if (xxxp->channel[chan].hook != NULL)
return (EADDRINUSE);
- hook->private = xxxp->channel + chan;
+ NG_HOOK_SET_PRIVATE(hook, xxxp->channel + chan);
xxxp->channel[chan].hook = hook;
return (0);
} else if (strcmp(name, NG_XXX_HOOK_DOWNSTREAM) == 0) {
/* Example of simple predefined hooks. */
/* do something specific to the downstream connection */
xxxp->downstream_hook.hook = hook;
- hook->private = &xxxp->downstream_hook;
+ NG_HOOK_SET_PRIVATE(hook, &xxxp->downstream_hook);
} else if (strcmp(name, NG_XXX_HOOK_DEBUG) == 0) {
/* do something specific to a debug connection */
xxxp->debughook = hook;
- hook->private = NULL;
+ NG_HOOK_SET_PRIVATE(hook, NULL);
} else
return (EINVAL); /* not a hook we know about */
return(0);
@@ -252,7 +252,7 @@ ng_xxx_newhook(node_p node, hook_p hook, const char *name)
static int
ng_xxx_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const xxx_p xxxp = node->private;
+ const xxx_p xxxp = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -318,7 +318,7 @@ ng_xxx_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ng_xxx_rcvdata(hook_p hook, item_p item )
{
- const xxx_p xxxp = hook->node->private;
+ const xxx_p xxxp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int chan = -2;
int dlci = -2;
int error;
@@ -327,9 +327,9 @@ ng_xxx_rcvdata(hook_p hook, item_p item )
NGI_GET_M(item, m);
- if (hook->private) {
- dlci = ((struct XXX_hookinfo *) hook->private)->dlci;
- chan = ((struct XXX_hookinfo *) hook->private)->channel;
+ if (NG_HOOK_PRIVATE(hook)) {
+ dlci = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->dlci;
+ chan = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->channel;
if (dlci != -1) {
/* If received on a DLCI hook process for this
* channel and pass it to the downstream module.
@@ -406,12 +406,11 @@ devintr()
static int
ng_xxx_shutdown(node_p node)
{
- const xxx_p privdata = node->private;
+ const xxx_p privdata = NG_NODE_PRIVATE(node);
int error;
- node->flags |= NG_INVALID;
- node->private = NULL;
- ng_unref(privdata->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(privdata->node);
#ifndef PERSISTANT_NODE
FREE(privdata, M_NETGRAPH);
#else
@@ -426,7 +425,7 @@ ng_xxx_shutdown(node_p node)
}
if ( ng_name_node(node, "name")) { /* whatever name is needed */
printf("something informative");
- ng_unref(node); /* drop it again */
+ NG_NODE_UNREF(node); /* drop it again */
return (0);
}
privdata->packets_in = 0; /* reset stats */
@@ -438,8 +437,8 @@ ng_xxx_shutdown(node_p node)
/* Link structs together; this counts as our one reference to node */
privdata->node = node;
- node->private = privdata;
- node->flags &= ~NG_INVALID; /* reset invalid flag */
+ NG_NODE_SET_PRIVATE(node, privdata);
+ node->nd_flags &= ~NG_INVALID; /* reset invalid flag */
#endif /* PERSISTANT_NODE */
return (0);
}
@@ -458,7 +457,7 @@ ng_xxx_connect(hook_p hook)
* will deliver by queing.
*/
if /*it is the upstream hook */
- hook->peer->flags |= HK_QUEUE;
+ NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
#endif
#if 0
/*
@@ -467,16 +466,16 @@ ng_xxx_connect(hook_p hook)
* OUR hook. (maybe to allow unwinding of the stack)
*/
- if (hook->private) {
+ if (NG_HOOK_PRIVATE(hook)) {
int dlci;
/*
* If it's dlci 1023, requeue it so that it's handled
* at a lower priority. This is how a node decides to
* defer a data message.
*/
- dlci = ((struct XXX_hookinfo *) hook->private)->dlci;
+ dlci = ((struct XXX_hookinfo *) NG_HOOK_PRIVATE(hook))->dlci;
if (dlci == 1023) {
- hook->flags |= HK_QUEUE;
+ NG_HOOK_FORCE_QUEUE(hook);
}
#endif
/* otherwise be really amiable and just say "YUP that's OK by me! " */
@@ -491,11 +490,11 @@ ng_xxx_connect(hook_p hook)
static int
ng_xxx_disconnect(hook_p hook)
{
- if (hook->private)
- ((struct XXX_hookinfo *) (hook->private))->hook = NULL;
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0)) /* already shutting down? */
- ng_rmnode_self(hook->node);
+ if (NG_HOOK_PRIVATE(hook))
+ ((struct XXX_hookinfo *) (NG_HOOK_PRIVATE(hook)))->hook = NULL;
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) /* already shutting down? */
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index 953793c..16b07df 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -4,7 +4,7 @@
*
* 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;
@@ -15,7 +15,7 @@
* 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,
@@ -235,9 +235,38 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
}
m_copydata(m, 0, len, (char *)msg);
+#ifdef TRACE_MESSAGES
+ do {
+ item_p item;
+ if ((item = ng_package_msg(msg)) == NULL) {
+ (msg) = NULL;
+ (error) = ENOMEM;
+printf("err=%d\n",error);
+ break;
+ }
+ if (((error) = ng_address_path((pcbp->sockdata->node), (item),
+ (path), (NULL))) == 0) {
+printf("[%x]:<---------[socket]: c=<%d>cmd=%x(%s) f=%x #%d (%s)\n",
+item->el_dest->nd_ID,
+msg->header.typecookie,
+msg->header.cmd,
+msg->header.cmdstr,
+msg->header.flags,
+msg->header.token,
+item->el_dest->nd_type->name);
+ SAVE_LINE(item);
+ (error) = ng_snd_item((item), 0);
+ }
+else {
+printf("errx=%d\n",error);
+}
+ (msg) = NULL;
+ } while (0);
+
+#else
/* The callee will free the msg when done. The path is our business. */
NG_SEND_MSG_PATH(error, pcbp->sockdata->node, msg, path, NULL);
-
+#endif
release:
if (path != NULL)
FREE(path, M_NETGRAPH);
@@ -261,8 +290,9 @@ ngc_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
static int
ngc_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
{
+printf(" program tried to connect control socket to remote node\n ");
/*
- * At this time refuse to do this.. it used to
+ * At this time refuse to do this.. it used to
* do something but it was undocumented and not used.
*/
return (EINVAL);
@@ -318,7 +348,7 @@ ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
if ((sap == NULL)
|| ((len = sap->sg_len) <= 2)
|| (*sap->sg_data == '\0')) {
- if (pcbp->sockdata->node->numhooks != 1) {
+ if (NG_NODE_NUMHOOKS(pcbp->sockdata->node) != 1) {
error = EDESTADDRREQ;
goto release;
}
@@ -326,7 +356,7 @@ ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
* if exactly one hook exists, just use it.
* Special case to allow write(2) to work on an ng_socket.
*/
- hook = LIST_FIRST(&pcbp->sockdata->node->hooks);
+ hook = LIST_FIRST(&pcbp->sockdata->node->nd_hooks);
} else {
if (len > NG_HOOKLEN) {
error = EINVAL;
@@ -341,8 +371,8 @@ ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
hookname[len] = '\0';
/* Find the correct hook from 'hookname' */
- LIST_FOREACH(hook, &pcbp->sockdata->node->hooks, hooks) {
- if (strcmp(hookname, hook->name) == 0)
+ LIST_FOREACH(hook, &pcbp->sockdata->node->nd_hooks, hk_hooks) {
+ if (strcmp(hookname, NG_HOOK_NAME(hook)) == 0)
break;
}
if (hook == NULL)
@@ -391,14 +421,13 @@ ng_setsockaddr(struct socket *so, struct sockaddr **addr)
}
namelen = 0; /* silence compiler ! */
-
- if (pcbp->sockdata->node->name != NULL)
- sg_len += namelen = strlen(pcbp->sockdata->node->name);
+ if ( NG_NODE_HAS_NAME(pcbp->sockdata->node))
+ sg_len += namelen = strlen(NG_NODE_NAME(pcbp->sockdata->node));
MALLOC(sg, struct sockaddr_ng *, sg_len, M_SONAME, M_WAITOK | M_ZERO);
- if (pcbp->sockdata->node->name != NULL)
- bcopy(pcbp->sockdata->node->name, sg->sg_data, namelen);
+ if (NG_NODE_HAS_NAME(pcbp->sockdata->node))
+ bcopy(NG_NODE_NAME(pcbp->sockdata->node), sg->sg_data, namelen);
splx(s);
sg->sg_len = sg_len;
@@ -440,7 +469,7 @@ ng_attach_cntl(struct socket *so)
ng_detach_common(pcbp, NG_CONTROL);
return (error);
}
- privdata->node->private = privdata;
+ NG_NODE_SET_PRIVATE(privdata->node, privdata);
/* Link the pcb and the node private data */
privdata->ctlsock = pcbp;
@@ -612,16 +641,16 @@ ng_connect_data(struct sockaddr *nam, struct ngpcb *pcbp)
return (error); /* item is freed on failure */
/*
- * Extract node from item and free item. Remember we now have
+ * Extract node from item and free item. Remember we now have
* a reference on the node. The item holds it for us.
* when we free the item we release the reference.
*/
farnode = item->el_dest; /* shortcut */
- if (strcmp(farnode->type->name, NG_SOCKET_NODE_TYPE) != 0) {
+ if (strcmp(farnode->nd_type->name, NG_SOCKET_NODE_TYPE) != 0) {
NG_FREE_ITEM(item); /* drop the reference to the node */
return (EINVAL);
}
- sockdata = farnode->private;
+ sockdata = NG_NODE_PRIVATE(farnode);
if (sockdata->datasock != NULL) {
NG_FREE_ITEM(item); /* drop the reference to the node */
return (EADDRINUSE);
@@ -712,7 +741,7 @@ ngs_constructor(node_p nodep)
static int
ngs_newhook(node_p node, hook_p hook, const char *name)
{
- hook->private = node->private;
+ NG_HOOK_SET_PRIVATE(hook, NG_NODE_PRIVATE(node));
return (0);
}
@@ -723,7 +752,7 @@ ngs_newhook(node_p node, hook_p hook, const char *name)
static int
ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- struct ngsock *const sockdata = node->private;
+ struct ngsock *const sockdata = NG_NODE_PRIVATE(node);
struct ngpcb *const pcbp = sockdata->ctlsock;
struct sockaddr_ng *addr;
int addrlen;
@@ -741,6 +770,16 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
TRAP_ERROR;
return (EINVAL);
}
+#ifdef TRACE_MESSAGES
+printf("[%x]:---------->[socket]: c=<%d>cmd=%x(%s) f=%x #%d\n",
+retaddr,
+msg->header.typecookie,
+msg->header.cmd,
+msg->header.cmdstr,
+msg->header.flags,
+msg->header.token);
+
+#endif
if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
switch (msg->header.cmd) {
@@ -783,7 +822,7 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook)
static int
ngs_rcvdata(hook_p hook, item_p item)
{
- struct ngsock *const sockdata = hook->node->private;
+ struct ngsock *const sockdata = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
struct ngpcb *const pcbp = sockdata->datasock;
struct socket *so;
struct sockaddr_ng *addr;
@@ -801,11 +840,11 @@ ngs_rcvdata(hook_p hook, item_p item)
so = pcbp->ng_socket;
/* Get the return address into a sockaddr. */
- addrlen = strlen(hook->name); /* <= NG_HOOKLEN */
+ addrlen = strlen(NG_HOOK_NAME(hook)); /* <= NG_HOOKLEN */
addr = (struct sockaddr_ng *) addrbuf;
addr->sg_len = addrlen + 3;
addr->sg_family = AF_NETGRAPH;
- bcopy(hook->name, addr->sg_data, addrlen);
+ bcopy(NG_HOOK_NAME(hook), addr->sg_data, addrlen);
addr->sg_data[addrlen] = '\0';
/* Try to tell the socket which hook it came in on */
@@ -827,12 +866,12 @@ ngs_rcvdata(hook_p hook, item_p item)
static int
ngs_disconnect(hook_p hook)
{
- struct ngsock *const sockdata = hook->node->private;
+ struct ngsock *const sockdata = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
if ((sockdata->flags & NGS_FLAG_NOLINGER )
- && (hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0)) {
- ng_rmnode_self(hook->node);
+ && (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
}
return (0);
}
@@ -845,7 +884,7 @@ ngs_disconnect(hook_p hook)
static int
ngs_shutdown(node_p node)
{
- struct ngsock *const sockdata = node->private;
+ struct ngsock *const sockdata = NG_NODE_PRIVATE(node);
struct ngpcb *const dpcbp = sockdata->datasock;
struct ngpcb *const pcbp = sockdata->ctlsock;
@@ -861,8 +900,8 @@ ngs_shutdown(node_p node)
sockdata->ctlsock = NULL;
sockdata->refs--;
}
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
FREE(sockdata, M_NETGRAPH);
return (0);
}
diff --git a/sys/netgraph/ng_tee.c b/sys/netgraph/ng_tee.c
index 02ae393..7482efc 100644
--- a/sys/netgraph/ng_tee.c
+++ b/sys/netgraph/ng_tee.c
@@ -155,7 +155,7 @@ ngt_constructor(node_p node)
if (privdata == NULL)
return (ENOMEM);
- node->private = privdata;
+ NG_NODE_SET_PRIVATE(node, privdata);
privdata->node = node;
return (0);
}
@@ -166,24 +166,24 @@ ngt_constructor(node_p node)
static int
ngt_newhook(node_p node, hook_p hook, const char *name)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
if (strcmp(name, NG_TEE_HOOK_RIGHT) == 0) {
sc->right.hook = hook;
bzero(&sc->right.stats, sizeof(sc->right.stats));
- hook->private = &sc->right;
+ NG_HOOK_SET_PRIVATE(hook, &sc->right);
} else if (strcmp(name, NG_TEE_HOOK_LEFT) == 0) {
sc->left.hook = hook;
bzero(&sc->left.stats, sizeof(sc->left.stats));
- hook->private = &sc->left;
+ NG_HOOK_SET_PRIVATE(hook, &sc->left);
} else if (strcmp(name, NG_TEE_HOOK_RIGHT2LEFT) == 0) {
sc->right2left.hook = hook;
bzero(&sc->right2left.stats, sizeof(sc->right2left.stats));
- hook->private = &sc->right2left;
+ NG_HOOK_SET_PRIVATE(hook, &sc->right2left);
} else if (strcmp(name, NG_TEE_HOOK_LEFT2RIGHT) == 0) {
sc->left2right.hook = hook;
bzero(&sc->left2right.stats, sizeof(sc->left2right.stats));
- hook->private = &sc->left2right;
+ NG_HOOK_SET_PRIVATE(hook, &sc->left2right);
} else
return (EINVAL);
return (0);
@@ -195,7 +195,7 @@ ngt_newhook(node_p node, hook_p hook, const char *name)
static int
ngt_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -249,15 +249,15 @@ ngt_rcvmsg(node_p node, item_p item, hook_p lasthook)
if (lasthook == sc->left.hook) {
if (sc->right.hook) {
NGI_MSG(item) = msg;
- NG_FWD_MSG_HOOK(error, node, item,
- sc->right.hook, 0);
+ NG_FWD_ITEM_HOOK(error, item,
+ sc->right.hook);
return (error);
}
} else {
if (sc->left.hook) {
NGI_MSG(item) = msg;
- NG_FWD_MSG_HOOK(error, node, item,
- sc->left.hook, 0);
+ NG_FWD_ITEM_HOOK(error, item,
+ sc->left.hook);
return (error);
}
}
@@ -286,8 +286,8 @@ done:
static int
ngt_rcvdata(hook_p hook, item_p item)
{
- const sc_p sc = hook->node->private;
- struct hookinfo *const hinfo = (struct hookinfo *) hook->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
+ struct hookinfo *const hinfo = NG_HOOK_PRIVATE(hook);
struct hookinfo *dest;
struct hookinfo *dup;
int error = 0;
@@ -350,7 +350,7 @@ ngt_rcvdata(hook_p hook, item_p item)
dest->stats.outOctets += m->m_pkthdr.len;
dest->stats.outFrames++;
if (dest->hook)
- NG_FWD_DATA(error, item, dest->hook);
+ NG_FWD_ITEM_HOOK(error, item, dest->hook);
else
NG_FREE_ITEM(item);
return (0);
@@ -370,15 +370,14 @@ ngt_rcvdata(hook_p hook, item_p item)
static int
ngt_shutdown(node_p node)
{
- const sc_p privdata = node->private;
+ const sc_p privdata = NG_NODE_PRIVATE(node);
- node->flags |= NG_INVALID;
#if 0 /* can never happen as cutlinks is already called */
if (privdata->left.hook && privdata->right.hook)
ng_bypass(privdata->left.hook, privdata->right.hook);
#endif
- node->private = NULL;
- ng_unref(privdata->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(privdata->node);
FREE(privdata, M_NETGRAPH);
return (0);
}
@@ -389,13 +388,13 @@ ngt_shutdown(node_p node)
static int
ngt_disconnect(hook_p hook)
{
- struct hookinfo *const hinfo = (struct hookinfo *) hook->private;
+ struct hookinfo *const hinfo = NG_HOOK_PRIVATE(hook);
KASSERT(hinfo != NULL, ("%s: null info", __FUNCTION__));
hinfo->hook = NULL;
- if ((hook->node->numhooks == 0)
- && ((hook->node->flags & NG_INVALID) == 0))
- ng_rmnode_self(hook->node);
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
+ ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}
diff --git a/sys/netgraph/ng_tty.c b/sys/netgraph/ng_tty.c
index 2f95e85..f6e4e25 100644
--- a/sys/netgraph/ng_tty.c
+++ b/sys/netgraph/ng_tty.c
@@ -233,13 +233,13 @@ ngt_open(dev_t dev, struct tty *tp)
if ((error = ng_name_node(sc->node, name))) {
log(LOG_ERR, "%s: node name exists?\n", name);
ngt_nodeop_ok = 1;
- ng_unref(sc->node);
+ NG_NODE_UNREF(sc->node);
ngt_nodeop_ok = 0;
goto done;
}
/* Set back pointers */
- sc->node->private = sc;
+ NG_NODE_SET_PRIVATE(sc->node, sc);
tp->t_sc = (caddr_t) sc;
/*
@@ -322,11 +322,11 @@ ngt_tioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
const node_p node = sc->node;
bzero(ni, sizeof(*ni));
- if (node->name)
- strncpy(ni->name, node->name, sizeof(ni->name) - 1);
- strncpy(ni->type, node->type->name, sizeof(ni->type) - 1);
- ni->id = (u_int32_t) node;
- ni->hooks = node->numhooks;
+ if (NG_NODE_HAS_NAME(node))
+ strncpy(ni->name, NG_NODE_NAME(node), sizeof(ni->name) - 1);
+ strncpy(ni->type, node->nd_type->name, sizeof(ni->type) - 1);
+ ni->id = (u_int32_t) ng_node2ID(node);
+ ni->hooks = NG_NODE_NUMHOOKS(node);
break;
}
default:
@@ -359,14 +359,14 @@ ngt_input(int c, struct tty *tp)
/* Check for error conditions */
if ((tp->t_state & TS_CONNECTED) == 0) {
if (sc->flags & FLG_DEBUG)
- log(LOG_DEBUG, "%s: no carrier\n", node->name);
+ log(LOG_DEBUG, "%s: no carrier\n", NG_NODE_NAME(node));
ERROUT(0);
}
if (c & TTY_ERRORMASK) {
/* framing error or overrun on this char */
if (sc->flags & FLG_DEBUG)
log(LOG_DEBUG, "%s: line error %x\n",
- node->name, c & TTY_ERRORMASK);
+ NG_NODE_NAME(node), c & TTY_ERRORMASK);
ERROUT(0);
}
c &= TTY_CHARMASK;
@@ -377,7 +377,7 @@ ngt_input(int c, struct tty *tp)
if (!m) {
if (sc->flags & FLG_DEBUG)
log(LOG_ERR,
- "%s: can't get mbuf\n", node->name);
+ "%s: can't get mbuf\n", NG_NODE_NAME(node));
ERROUT(ENOBUFS);
}
m->m_len = m->m_pkthdr.len = 0;
@@ -504,7 +504,7 @@ ngt_constructor(node_p node)
static int
ngt_newhook(node_p node, hook_p hook, const char *name)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
int s, error = 0;
if (strcmp(name, NG_TTY_HOOK))
@@ -525,7 +525,8 @@ done:
static int
ngt_connect(hook_p hook)
{
- hook->peer->flags |= HK_QUEUE|HK_FORCE_WRITER;
+ /*NG_HOOK_FORCE_WRITER(hook);
+ NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));*/
return (0);
}
@@ -535,7 +536,7 @@ ngt_connect(hook_p hook)
static int
ngt_disconnect(hook_p hook)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int s;
s = spltty();
@@ -555,12 +556,12 @@ ngt_disconnect(hook_p hook)
static int
ngt_shutdown(node_p node)
{
- const sc_p sc = node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
if (!ngt_nodeop_ok)
return (EOPNOTSUPP);
- node->private = NULL;
- ng_unref(sc->node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(sc->node);
m_freem(sc->qhead);
m_freem(sc->m);
bzero(sc, sizeof(*sc));
@@ -575,7 +576,7 @@ ngt_shutdown(node_p node)
static int
ngt_rcvdata(hook_p hook, item_p item)
{
- const sc_p sc = hook->node->private;
+ const sc_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
int s, error = 0;
struct mbuf *m;
@@ -608,7 +609,7 @@ done:
static int
ngt_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const sc_p sc = (sc_p) node->private;
+ const sc_p sc = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
diff --git a/sys/netgraph/ng_vjc.c b/sys/netgraph/ng_vjc.c
index a9c9515..5a2e2da 100644
--- a/sys/netgraph/ng_vjc.c
+++ b/sys/netgraph/ng_vjc.c
@@ -254,7 +254,7 @@ ng_vjc_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- node->private = priv;
+ NG_NODE_SET_PRIVATE(node, priv);
/* Done */
return (0);
@@ -266,7 +266,7 @@ ng_vjc_constructor(node_p node)
static int
ng_vjc_newhook(node_p node, hook_p hook, const char *name)
{
- const priv_p priv = (priv_p) node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
hook_p *hookp;
/* Get hook */
@@ -296,7 +296,7 @@ ng_vjc_newhook(node_p node, hook_p hook, const char *name)
static int
ng_vjc_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
- const priv_p priv = (priv_p) node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
@@ -403,8 +403,8 @@ done:
static int
ng_vjc_rcvdata(hook_p hook, item_p item)
{
- const node_p node = hook->node;
- const priv_p priv = (priv_p) node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
int error = 0;
struct mbuf *m;
@@ -549,13 +549,12 @@ ng_vjc_rcvdata(hook_p hook, item_p item)
static int
ng_vjc_shutdown(node_p node)
{
- const priv_p priv = (priv_p) node->private;
+ const priv_p priv = NG_NODE_PRIVATE(node);
- node->flags |= NG_INVALID;
bzero(priv, sizeof(*priv));
FREE(priv, M_NETGRAPH);
- node->private = NULL;
- ng_unref(node);
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
return (0);
}
@@ -565,8 +564,8 @@ ng_vjc_shutdown(node_p node)
static int
ng_vjc_disconnect(hook_p hook)
{
- const node_p node = hook->node;
- const priv_p priv = node->private;
+ const node_p node = NG_HOOK_NODE(hook);
+ const priv_p priv = NG_NODE_PRIVATE(node);
/* Zero out hook pointer */
if (hook == priv->ip)
@@ -581,8 +580,8 @@ ng_vjc_disconnect(hook_p hook)
panic("%s: unknown hook", __FUNCTION__);
/* Go away if no hooks left */
- if ((node->numhooks == 0)
- && ((node->flags & NG_INVALID) == 0))
+ if ((NG_NODE_NUMHOOKS(node) == 0)
+ && (NG_NODE_IS_VALID(node)))
ng_rmnode_self(node);
return (0);
}
OpenPOWER on IntegriCloud