[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Fri Mar 2 15:40:16 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/aa9c9bb008fc
changeset: 406:aa9c9bb008fc
user:      ray at terran.dlink.ua
date:      Fri Mar 02 17:18:27 2012 +0200
description:
Update to FreeBSD-HEAD @232391

diffstat:

 head/sys/netgraph/netgraph.h  |    8 +-
 head/sys/netgraph/ng_base.c   |  307 ++++++++++++++++++++++++++---------------
 head/sys/netgraph/ng_cisco.c  |   40 ++--
 head/sys/netgraph/ng_cisco.h  |    6 +-
 head/sys/netgraph/ng_device.c |    7 +-
 head/sys/netgraph/ng_socket.c |   28 +--
 6 files changed, 232 insertions(+), 164 deletions(-)

diffs (799 lines):

diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/netgraph.h
--- a/head/sys/netgraph/netgraph.h	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/netgraph.h	Fri Mar 02 17:18:27 2012 +0200
@@ -37,7 +37,7 @@
  *
  * Author: Julian Elischer <julian at freebsd.org>
  *
- * $FreeBSD: head/sys/netgraph/netgraph.h 227130 2011-11-06 05:20:27Z fjoe $
+ * $FreeBSD: head/sys/netgraph/netgraph.h 231831 2012-02-16 19:10:01Z glebius $
  * $Whistle: netgraph.h,v 1.29 1999/11/01 07:56:13 julian Exp $
  */
 
@@ -365,7 +365,7 @@
 	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_nodes;	/* name hash collision list */
 	LIST_ENTRY(ng_node)	  nd_idnodes;	/* ID hash collision list */
 	struct	ng_queue	  nd_input_queue; /* input queue for locking */
 	int	nd_refs;		/* # of references to this node */
@@ -1202,10 +1202,6 @@
 #define NGI_GET_META(i,m)
 #define	ng_copy_meta(meta) NULL
 
-/* Hash related definitions */
-#define	NG_ID_HASH_SIZE 128 /* most systems wont need even this many */
-#define	NG_NAME_HASH_SIZE 128 /* most systems wont need even this many */
-
 /*
  * Mark the current thread when called from the outbound path of the
  * network stack, in order to enforce queuing on ng nodes calling into
diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/ng_base.c
--- a/head/sys/netgraph/ng_base.c	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/ng_base.c	Fri Mar 02 17:18:27 2012 +0200
@@ -34,7 +34,7 @@
  * Authors: Julian Elischer <julian at freebsd.org>
  *          Archie Cobbs <archie at freebsd.org>
  *
- * $FreeBSD: head/sys/netgraph/ng_base.c 230480 2012-01-23 15:17:14Z glebius $
+ * $FreeBSD: head/sys/netgraph/ng_base.c 231997 2012-02-22 09:08:51Z glebius $
  * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $
  */
 
@@ -45,23 +45,23 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ctype.h>
-#include <sys/errno.h>
+#include <sys/hash.h>
 #include <sys/kdb.h>
 #include <sys/kernel.h>
+#include <sys/kthread.h>
 #include <sys/ktr.h>
 #include <sys/limits.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
+#include <sys/proc.h>
 #include <sys/queue.h>
+#include <sys/refcount.h>
+#include <sys/rwlock.h>
+#include <sys/smp.h>
 #include <sys/sysctl.h>
 #include <sys/syslog.h>
-#include <sys/refcount.h>
-#include <sys/proc.h>
-#include <sys/rwlock.h>
 #include <sys/unistd.h>
-#include <sys/kthread.h>
-#include <sys/smp.h>
 #include <machine/cpu.h>
 
 #include <net/netisr.h>
@@ -171,10 +171,20 @@
 #define	TYPELIST_WLOCK()	rw_wlock(&ng_typelist_lock)
 #define	TYPELIST_WUNLOCK()	rw_wunlock(&ng_typelist_lock)
 
-/* Hash related definitions */
-/* XXX Don't need to initialise them because it's a LIST */
-static VNET_DEFINE(LIST_HEAD(, ng_node), ng_ID_hash[NG_ID_HASH_SIZE]);
-#define	V_ng_ID_hash			VNET(ng_ID_hash)
+/* Hash related definitions. */
+LIST_HEAD(nodehash, ng_node);
+static VNET_DEFINE(struct nodehash *, ng_ID_hash);
+static VNET_DEFINE(u_long, ng_ID_hmask);
+static VNET_DEFINE(u_long, ng_nodes);
+static VNET_DEFINE(struct nodehash *, ng_name_hash);
+static VNET_DEFINE(u_long, ng_name_hmask);
+static VNET_DEFINE(u_long, ng_named_nodes);
+#define	V_ng_ID_hash		VNET(ng_ID_hash)
+#define	V_ng_ID_hmask		VNET(ng_ID_hmask)
+#define	V_ng_nodes		VNET(ng_nodes)
+#define	V_ng_name_hash		VNET(ng_name_hash)
+#define	V_ng_name_hmask		VNET(ng_name_hmask)
+#define	V_ng_named_nodes	VNET(ng_named_nodes)
 
 static struct rwlock	ng_idhash_lock;
 #define	IDHASH_RLOCK()		rw_rlock(&ng_idhash_lock)
@@ -183,7 +193,7 @@
 #define	IDHASH_WUNLOCK()	rw_wunlock(&ng_idhash_lock)
 
 /* Method to find a node.. used twice so do it here */
-#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE))
+#define NG_IDHASH_FN(ID) ((ID) % (V_ng_ID_hmask + 1))
 #define NG_IDHASH_FIND(ID, node)					\
 	do { 								\
 		rw_assert(&ng_idhash_lock, RA_LOCKED);			\
@@ -196,18 +206,6 @@
 		}							\
 	} while (0)
 
-static VNET_DEFINE(LIST_HEAD(, ng_node), ng_name_hash[NG_NAME_HASH_SIZE]);
-#define	V_ng_name_hash			VNET(ng_name_hash)
-
-#define NG_NAMEHASH(NAME, HASH)				\
-	do {						\
-		u_char	h = 0;				\
-		const u_char	*c;			\
-		for (c = (const u_char*)(NAME); *c; c++)\
-			h += *c;			\
-		(HASH) = h % (NG_NAME_HASH_SIZE);	\
-	} while (0)
-
 static struct rwlock	ng_namehash_lock;
 #define	NAMEHASH_RLOCK()	rw_rlock(&ng_namehash_lock)
 #define	NAMEHASH_RUNLOCK()	rw_runlock(&ng_namehash_lock)
@@ -228,8 +226,10 @@
 		    node_p node2, const char *name2);
 static int	ng_con_part2(node_p node, item_p item, hook_p hook);
 static int	ng_con_part3(node_p node, item_p item, hook_p hook);
-static int	ng_mkpeer(node_p node, const char *name,
-						const char *name2, char *type);
+static int	ng_mkpeer(node_p node, const char *name, const char *name2,
+		    char *type);
+static void	ng_name_rehash(void);
+static void	ng_ID_rehash(void);
 
 /* Imported, these used to be externally visible, some may go back. */
 void	ng_destroy_hook(hook_p hook);
@@ -240,7 +240,6 @@
 void	ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3);
 void	ng_unname(node_p node);
 
-
 /* Our own netgraph malloc type */
 MALLOC_DEFINE(M_NETGRAPH, "netgraph", "netgraph structures and ctrl messages");
 MALLOC_DEFINE(M_NETGRAPH_MSG, "netgraph_msg", "netgraph name storage");
@@ -341,7 +340,6 @@
 #define NG_ALLOC_HOOK(hook) do { (hook) = ng_alloc_hook(); } while (0)
 #define NG_ALLOC_NODE(node) do { (node) = ng_alloc_node(); } while (0)
 
-
 #define NG_FREE_HOOK(hook)						\
 	do {								\
 		mtx_lock(&ng_nodelist_mtx);				\
@@ -664,12 +662,7 @@
 	/* Initialize hook list for new node */
 	LIST_INIT(&node->nd_hooks);
 
-	/* Link us into the name hash. */
-	NAMEHASH_WLOCK();
-	LIST_INSERT_HEAD(&V_ng_name_hash[0], node, nd_nodes);
-	NAMEHASH_WUNLOCK();
-
-	/* get an ID and put us in the hash chain */
+	/* Get an ID and put us in the hash chain. */
 	IDHASH_WLOCK();
 	for (;;) { /* wrap protection, even if silly */
 		node_p node2 = NULL;
@@ -681,6 +674,9 @@
 			break;
 		}
 	}
+	V_ng_nodes++;
+	if (V_ng_nodes * 2 > V_ng_ID_hmask)
+		ng_ID_rehash();
 	LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], node,
 	    nd_idnodes);
 	IDHASH_WUNLOCK();
@@ -797,10 +793,14 @@
 
 		node->nd_type->refs--; /* XXX maybe should get types lock? */
 		NAMEHASH_WLOCK();
-		LIST_REMOVE(node, nd_nodes);
+		if (NG_NODE_HAS_NAME(node)) {
+			V_ng_named_nodes--;
+			LIST_REMOVE(node, nd_nodes);
+		}
 		NAMEHASH_WUNLOCK();
 
 		IDHASH_WLOCK();
+		V_ng_nodes--;
 		LIST_REMOVE(node, nd_idnodes);
 		IDHASH_WUNLOCK();
 
@@ -816,9 +816,10 @@
 ng_ID2noderef(ng_ID_t ID)
 {
 	node_p node;
+
 	IDHASH_RLOCK();
 	NG_IDHASH_FIND(ID, node);
-	if(node)
+	if (node)
 		NG_NODE_REF(node);
 	IDHASH_RUNLOCK();
 	return(node);
@@ -840,8 +841,9 @@
 int
 ng_name_node(node_p node, const char *name)
 {
-	int i, hash;
+	uint32_t hash;
 	node_p node2;
+	int i;
 
 	/* Check the name is valid */
 	for (i = 0; i < NG_NODESIZ; i++) {
@@ -857,20 +859,26 @@
 		return (EINVAL);
 	}
 
-	/* Check the name isn't already being used */
-	if ((node2 = ng_name2noderef(node, name)) != NULL) {
-		NG_NODE_UNREF(node2);
-		TRAP_ERROR();
-		return (EADDRINUSE);
-	}
-
-	/* copy it */
+	NAMEHASH_WLOCK();
+	if (V_ng_named_nodes * 2 > V_ng_name_hmask)
+		ng_name_rehash();
+
+	hash = hash32_str(name, HASHINIT) & V_ng_name_hmask;
+	/* Check the name isn't already being used. */
+	LIST_FOREACH(node2, &V_ng_name_hash[hash], nd_nodes)
+		if (NG_NODE_IS_VALID(node2) &&
+		    (strcmp(NG_NODE_NAME(node2), name) == 0)) {
+			NAMEHASH_WUNLOCK();
+			return (EADDRINUSE);
+		}
+
+	if (NG_NODE_HAS_NAME(node))
+		LIST_REMOVE(node, nd_nodes);
+	else
+		V_ng_named_nodes++;
+	/* Copy it. */
 	strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ);
-
 	/* Update name hash. */
-	NG_NAMEHASH(name, hash);
-	NAMEHASH_WLOCK();
-	LIST_REMOVE(node, nd_nodes);
 	LIST_INSERT_HEAD(&V_ng_name_hash[hash], node, nd_nodes);
 	NAMEHASH_WUNLOCK();
 
@@ -905,8 +913,8 @@
 		return (ng_ID2noderef(temp));
 	}
 
-	/* Find node by name */
-	NG_NAMEHASH(name, hash);
+	/* Find node by name. */
+	hash = hash32_str(name, HASHINIT) & V_ng_name_hmask;
 	NAMEHASH_RLOCK();
 	LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes)
 		if (NG_NODE_IS_VALID(node) &&
@@ -952,6 +960,68 @@
 {
 }
 
+/*
+ * Allocate a bigger name hash.
+ */
+static void
+ng_name_rehash()
+{
+	struct nodehash *new;
+	uint32_t hash;
+	u_long hmask;
+	node_p node, node2;
+	int i;
+
+	new = hashinit_flags((V_ng_name_hmask + 1) * 2, M_NETGRAPH_NODE, &hmask,
+	    HASH_NOWAIT);
+	if (new == NULL)
+		return;
+
+	for (i = 0; i <= V_ng_name_hmask; i++)
+		LIST_FOREACH_SAFE(node, &V_ng_name_hash[i], nd_nodes, node2) {
+#ifdef INVARIANTS
+			LIST_REMOVE(node, nd_nodes);
+#endif
+			hash = hash32_str(NG_NODE_NAME(node), HASHINIT) & hmask;
+			LIST_INSERT_HEAD(&new[hash], node, nd_nodes);
+		}
+
+	hashdestroy(V_ng_name_hash, M_NETGRAPH_NODE, V_ng_name_hmask);
+	V_ng_name_hash = new;
+	V_ng_name_hmask = hmask;
+}
+
+/*
+ * Allocate a bigger ID hash.
+ */
+static void
+ng_ID_rehash()
+{
+	struct nodehash *new;
+	uint32_t hash;
+	u_long hmask;
+	node_p node, node2;
+	int i;
+
+	new = hashinit_flags((V_ng_ID_hmask + 1) * 2, M_NETGRAPH_NODE, &hmask,
+	    HASH_NOWAIT);
+	if (new == NULL)
+		return;
+
+	for (i = 0; i <= V_ng_ID_hmask; i++)
+		LIST_FOREACH_SAFE(node, &V_ng_ID_hash[i], nd_idnodes, node2) {
+#ifdef INVARIANTS
+			LIST_REMOVE(node, nd_idnodes);
+#endif
+			hash = (node->nd_ID % (hmask + 1));
+			LIST_INSERT_HEAD(&new[hash], node, nd_idnodes);
+		}
+
+	hashdestroy(V_ng_ID_hash, M_NETGRAPH_NODE, V_ng_name_hmask);
+	V_ng_ID_hash = new;
+	V_ng_ID_hmask = hmask;
+}
+
 /************************************************************************
 			Hook routines
  Names are not optional. Hooks are always connected, except for a
@@ -1161,6 +1231,10 @@
 		return (EINVAL);
 	}
 	mtx_lock(&ng_topo_mtx);
+	if (NG_HOOK_NOT_VALID(hook1) || NG_HOOK_NOT_VALID(hook2)) {
+		mtx_unlock(&ng_topo_mtx);
+		return (EINVAL);
+	}
 	hook1->hk_peer->hk_peer = hook2->hk_peer;
 	hook2->hk_peer->hk_peer = hook1->hk_peer;
 
@@ -1202,7 +1276,6 @@
 		return (EEXIST);
 	}
 
-
 	/* Link in new type */
 	TYPELIST_WLOCK();
 	LIST_INSERT_HEAD(&ng_typelist, tp, types);
@@ -2574,28 +2647,55 @@
 		break;
 	    }
 
-	case NGM_LISTNAMES:
 	case NGM_LISTNODES:
 	    {
-		const int unnamed = (msg->header.cmd == NGM_LISTNODES);
 		struct namelist *nl;
 		node_p node;
-		int num = 0, i;
-
-		NAMEHASH_RLOCK();
-		/* Count number of nodes */
-		for (i = 0; i < NG_NAME_HASH_SIZE; i++) {
-			LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) {
-				if (NG_NODE_IS_VALID(node) &&
-				    (unnamed || NG_NODE_HAS_NAME(node))) {
-					num++;
-				}
+		int i;
+
+		IDHASH_RLOCK();
+		/* Get response struct. */
+		NG_MKRESPONSE(resp, msg, sizeof(*nl) +
+		    (V_ng_nodes * sizeof(struct nodeinfo)), M_NOWAIT | M_ZERO);
+		if (resp == NULL) {
+			IDHASH_RUNLOCK();
+			error = ENOMEM;
+			break;
+		}
+		nl = (struct namelist *) resp->data;
+
+		/* Cycle through the lists of nodes. */
+		nl->numnames = 0;
+		for (i = 0; i <= V_ng_ID_hmask; i++) {
+			LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) {
+				struct nodeinfo *const np =
+				    &nl->nodeinfo[nl->numnames];
+
+				if (NG_NODE_NOT_VALID(node))
+					continue;
+				if (NG_NODE_HAS_NAME(node))
+					strcpy(np->name, NG_NODE_NAME(node));
+				strcpy(np->type, node->nd_type->name);
+				np->id = ng_node2ID(node);
+				np->hooks = node->nd_numhooks;
+				KASSERT(nl->numnames < V_ng_nodes,
+				    ("%s: no space", __func__));
+				nl->numnames++;
 			}
 		}
-
-		/* Get response struct */
+		IDHASH_RUNLOCK();
+		break;
+	    }
+	case NGM_LISTNAMES:
+	    {
+		struct namelist *nl;
+		node_p node;
+		int i;
+
+		NAMEHASH_RLOCK();
+		/* Get response struct. */
 		NG_MKRESPONSE(resp, msg, sizeof(*nl) +
-		    (num * sizeof(struct nodeinfo)), M_NOWAIT);
+		    (V_ng_named_nodes * sizeof(struct nodeinfo)), M_NOWAIT);
 		if (resp == NULL) {
 			NAMEHASH_RUNLOCK();
 			error = ENOMEM;
@@ -2603,24 +2703,21 @@
 		}
 		nl = (struct namelist *) resp->data;
 
-		/* Cycle through the linked list of nodes */
+		/* Cycle through the lists of nodes. */
 		nl->numnames = 0;
-		for (i = 0; i < NG_NAME_HASH_SIZE; i++) {
+		for (i = 0; i <= V_ng_name_hmask; i++) {
 			LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) {
 				struct nodeinfo *const np =
 				    &nl->nodeinfo[nl->numnames];
 
 				if (NG_NODE_NOT_VALID(node))
 					continue;
-				if (!unnamed && (! NG_NODE_HAS_NAME(node)))
-					continue;
-				if (NG_NODE_HAS_NAME(node))
-					strcpy(np->name, NG_NODE_NAME(node));
+				strcpy(np->name, NG_NODE_NAME(node));
 				strcpy(np->type, node->nd_type->name);
 				np->id = ng_node2ID(node);
 				np->hooks = node->nd_numhooks;
-				KASSERT(nl->numnames < num, ("%s: no space",
-				    __func__));
+				KASSERT(nl->numnames < V_ng_named_nodes,
+				    ("%s: no space", __func__));
 				nl->numnames++;
 			}
 		}
@@ -3027,6 +3124,17 @@
 	return (error);
 }
 
+static void
+vnet_netgraph_init(const void *unused __unused)
+{
+
+	/* We start with small hashes, but they can grow. */
+	V_ng_ID_hash = hashinit(16, M_NETGRAPH_NODE, &V_ng_ID_hmask);
+	V_ng_name_hash = hashinit(16, M_NETGRAPH_NODE, &V_ng_name_hmask);
+}
+VNET_SYSINIT(vnet_netgraph_init, SI_SUB_NETGRAPH, SI_ORDER_FIRST,
+    vnet_netgraph_init, NULL);
+
 #ifdef VIMAGE
 static void
 vnet_netgraph_uninit(const void *unused __unused)
@@ -3036,9 +3144,9 @@
 
 	do {
 		/* Find a node to kill */
-		NAMEHASH_RLOCK();
-		for (i = 0; i < NG_NAME_HASH_SIZE; i++) {
-			LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) {
+		IDHASH_RLOCK();
+		for (i = 0; i <= V_ng_ID_hmask; i++) {
+			LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) {
 				if (node != &ng_deadnode) {
 					NG_NODE_REF(node);
 					break;
@@ -3047,7 +3155,7 @@
 			if (node != NULL)
 				break;
 		}
-		NAMEHASH_RUNLOCK();
+		IDHASH_RUNLOCK();
 
 		/* Attempt to kill it only if it is a regular node */
 		if (node != NULL) {
@@ -3065,8 +3173,11 @@
 			last_killed = node;
 		}
 	} while (node != NULL);
+
+	hashdestroy(V_ng_name_hash, M_NETGRAPH_NODE, V_ng_name_hmask);
+	hashdestroy(V_ng_ID_hash, M_NETGRAPH_NODE, V_ng_ID_hmask);
 }
-VNET_SYSUNINIT(vnet_netgraph_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+VNET_SYSUNINIT(vnet_netgraph_uninit, SI_SUB_NETGRAPH, SI_ORDER_FIRST,
     vnet_netgraph_uninit, NULL);
 #endif /* VIMAGE */
 
@@ -3132,7 +3243,7 @@
 	ngb_mod_event,
 	(NULL)
 };
-DECLARE_MODULE(netgraph, netgraph_mod, SI_SUB_NETGRAPH, SI_ORDER_MIDDLE);
+DECLARE_MODULE(netgraph, netgraph_mod, SI_SUB_NETGRAPH, SI_ORDER_FIRST);
 SYSCTL_NODE(_net, OID_AUTO, graph, CTLFLAG_RW, 0, "netgraph Family");
 SYSCTL_INT(_net_graph, OID_AUTO, abi_version, CTLFLAG_RD, 0, NG_ABI_VERSION,"");
 SYSCTL_INT(_net_graph, OID_AUTO, msg_version, CTLFLAG_RD, 0, NG_VERSION, "");
@@ -3271,7 +3382,6 @@
     0, sizeof(int), sysctl_debug_ng_dump_items, "I", "Number of allocated items");
 #endif	/* NETGRAPH_DEBUG */
 
-
 /***********************************************************************
 * Worklist routines
 **********************************************************************/
@@ -3355,7 +3465,6 @@
 	}
 }
 
-
 /***********************************************************************
 * Externally useable functions to set up a queue item ready for sending
 ***********************************************************************/
@@ -3436,8 +3545,6 @@
 	return (item);
 }
 
-
-
 #define SET_RETADDR(item, here, retaddr)				\
 	do {	/* Data or fn items don't have retaddrs */		\
 		if ((item->el_flags & NGQF_TYPE) == NGQF_MESG) {	\
@@ -3663,7 +3770,6 @@
 	CURVNET_RESTORE();
 }
 
-
 int
 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
     ng_item_fn *fn, void * arg1, int arg2)
@@ -3733,32 +3839,3 @@
 		NGI_RETADDR(item) = ng_node2ID(here);
 	}
 }
-
-#define TESTING
-#ifdef TESTING
-/* just test all the macros */
-void
-ng_macro_test(item_p item);
-void
-ng_macro_test(item_p item)
-{
-	node_p node = NULL;
-	hook_p hook = NULL;
-	struct mbuf *m;
-	struct ng_mesg *msg;
-	ng_ID_t retaddr;
-	int	error;
-
-	NGI_GET_M(item, m);
-	NGI_GET_MSG(item, msg);
-	retaddr = NGI_RETADDR(item);
-	NG_SEND_DATA(error, hook, m, NULL);
-	NG_SEND_DATA_ONLY(error, hook, m);
-	NG_FWD_NEW_DATA(error, item, hook, m);
-	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);
-	NG_FWD_MSG_HOOK(error, node, item, hook, retaddr);
-}
-#endif /* TESTING */
diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/ng_cisco.c
--- a/head/sys/netgraph/ng_cisco.c	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/ng_cisco.c	Fri Mar 02 17:18:27 2012 +0200
@@ -37,7 +37,7 @@
  *
  * Author: Julian Elischer <julian at freebsd.org>
  *
- * $FreeBSD: head/sys/netgraph/ng_cisco.c 227131 2011-11-06 05:23:42Z fjoe $
+ * $FreeBSD: head/sys/netgraph/ng_cisco.c 231543 2012-02-12 05:14:12Z fjoe $
  * $Whistle: ng_cisco.c,v 1.25 1999/11/01 09:24:51 julian Exp $
  */
 
@@ -75,33 +75,33 @@
 #define KEEPALIVE_SECS		10
 
 struct cisco_header {
-	u_char  address;
-	u_char  control;
-	u_short protocol;
-};
+	uint8_t  address;
+	uint8_t  control;
+	uint16_t protocol;
+} __packed;
 
 #define	CISCO_HEADER_LEN	sizeof (struct cisco_header)
 
 struct cisco_packet {
-	u_long  type;
-	u_long  par1;
-	u_long  par2;
-	u_short rel;
-	u_short time0;
-	u_short time1;
-};
+	uint32_t type;
+	uint32_t par1;
+	uint32_t par2;
+	uint16_t rel;
+	uint16_t time0;
+	uint16_t time1;
+} __packed;
 
 #define	CISCO_PACKET_LEN (sizeof(struct cisco_packet))
 
 struct protoent {
 	hook_p  hook;		/* the hook for this proto */
-	u_short af;		/* address family, -1 = downstream */
+	uint16_t af;		/* address family, -1 = downstream */
 };
 
 struct cisco_priv {
-	u_long  local_seq;
-	u_long  remote_seq;
-	u_long  seqRetries;	/* how many times we've been here throwing out
+	uint32_t local_seq;
+	uint32_t remote_seq;
+	uint32_t seqRetries;	/* how many times we've been here throwing out
 				 * the same sequence number without ack */
 	node_p  node;
 	struct callout handle;
@@ -271,7 +271,7 @@
 			pos = sprintf(arg,
 			  "keepalive period: %d sec; ", KEEPALIVE_SECS);
 			pos += sprintf(arg + pos,
-			  "unacknowledged keepalives: %ld", sc->seqRetries);
+			  "unacknowledged keepalives: %d", sc->seqRetries);
 			resp->header.arglen = pos + 1;
 			break;
 		    }
@@ -603,7 +603,7 @@
 	struct cisco_packet *ch;
 	struct mbuf *m;
 	struct timeval time;
-	u_long  t;
+	uint32_t t;
 	int     error = 0;
 
 	getmicrouptime(&time);
@@ -626,8 +626,8 @@
 	ch->par1 = htonl(par1);
 	ch->par2 = htonl(par2);
 	ch->rel = -1;
-	ch->time0 = htons((u_short) (t >> 16));
-	ch->time1 = htons((u_short) t);
+	ch->time0 = htons((uint16_t) (t >> 16));
+	ch->time1 = htons((uint16_t) t);
 
 	NG_SEND_DATA_ONLY(error, sc->downstream.hook, m);
 	return (error);
diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/ng_cisco.h
--- a/head/sys/netgraph/ng_cisco.h	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/ng_cisco.h	Fri Mar 02 17:18:27 2012 +0200
@@ -37,7 +37,7 @@
  *
  * Author: Archie Cobbs <archie at freebsd.org>
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/netgraph/ng_cisco.h 231543 2012-02-12 05:14:12Z fjoe $
  * $Whistle: ng_cisco.h,v 1.6 1999/01/25 01:21:48 archie Exp $
  */
 
@@ -76,8 +76,8 @@
 }
 
 struct ng_cisco_stats {
-	u_int32_t   seqRetries;		/* # unack'd retries */
-	u_int32_t   keepAlivePeriod;	/* in seconds */
+	uint32_t   seqRetries;		/* # unack'd retries */
+	uint32_t   keepAlivePeriod;	/* in seconds */
 };
 
 /* Keep this in sync with the above structure definition */
diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/ng_device.c
--- a/head/sys/netgraph/ng_device.c	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/ng_device.c	Fri Mar 02 17:18:27 2012 +0200
@@ -27,7 +27,7 @@
  * This node presents a /dev/ngd%d device that interfaces to an other
  * netgraph node.
  *
- * $FreeBSD: head/sys/netgraph/ng_device.c 220768 2011-04-18 09:12:27Z glebius $
+ * $FreeBSD: head/sys/netgraph/ng_device.c 231378 2012-02-10 12:35:57Z ed $
  *
  */
 
@@ -203,6 +203,7 @@
 	const priv_p priv = NG_NODE_PRIVATE(node);
 	struct ng_mesg *msg;
 	struct ng_mesg *resp = NULL;
+	const char *dn;
 	int error = 0;
 
 	NGI_GET_MSG(item, msg);
@@ -217,8 +218,8 @@
 			if (resp == NULL)
 				ERROUT(ENOMEM);
 
-			strlcpy((char *)resp->data, priv->ngddev->si_name,
-			    strlen(priv->ngddev->si_name) + 1);
+			dn = devtoname(priv->ngddev);
+			strlcpy((char *)resp->data, dn, strlen(dn) + 1);
 			break;
 
 		default:
diff -r e84d9f3b0cbe -r aa9c9bb008fc head/sys/netgraph/ng_socket.c
--- a/head/sys/netgraph/ng_socket.c	Fri Mar 02 17:18:08 2012 +0200
+++ b/head/sys/netgraph/ng_socket.c	Fri Mar 02 17:18:27 2012 +0200
@@ -37,7 +37,7 @@
  *
  * Author: Julian Elischer <julian at freebsd.org>
  *
- * $FreeBSD: head/sys/netgraph/ng_socket.c 230487 2012-01-23 16:43:13Z glebius $
+ * $FreeBSD: head/sys/netgraph/ng_socket.c 231823 2012-02-16 14:44:52Z glebius $
  * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $
  */
 
@@ -490,33 +490,30 @@
 	int sg_len;
 	int error = 0;
 
-	/* Why isn't sg_data a `char[1]' ? :-( */
-	sg_len = sizeof(struct sockaddr_ng) - sizeof(sg->sg_data) + 1;
-
 	pcbp = sotongpcb(so);
 	if ((pcbp == NULL) || (pcbp->sockdata == NULL))
 		/* XXXGL: can this still happen? */
 		return (EINVAL);
 
+	sg_len = sizeof(struct sockaddr_ng) + NG_NODESIZ -
+	    sizeof(sg->sg_data);
+	sg = malloc(sg_len, M_SONAME, M_WAITOK | M_ZERO);
+
 	mtx_lock(&pcbp->sockdata->mtx);
 	if (pcbp->sockdata->node != NULL) {
 		node_p node = pcbp->sockdata->node;
-		int namelen = 0;	/* silence compiler! */
 
 		if (NG_NODE_HAS_NAME(node))
-			sg_len += namelen = strlen(NG_NODE_NAME(node));
-
-		sg = malloc(sg_len, M_SONAME, M_WAITOK | M_ZERO);
-
-		if (NG_NODE_HAS_NAME(node))
-			bcopy(NG_NODE_NAME(node), sg->sg_data, namelen);
+			bcopy(NG_NODE_NAME(node), sg->sg_data,
+			    strlen(NG_NODE_NAME(node)));
+		mtx_unlock(&pcbp->sockdata->mtx);
 
 		sg->sg_len = sg_len;
 		sg->sg_family = AF_NETGRAPH;
 		*addr = (struct sockaddr *)sg;
-		mtx_unlock(&pcbp->sockdata->mtx);
 	} else {
 		mtx_unlock(&pcbp->sockdata->mtx);
+		free(sg, M_SONAME);
 		error = EINVAL;
 	}
 
@@ -850,12 +847,9 @@
 	uint32_t h;
 
 	/*
-	 * Microoptimisations for a ng_socket with no
-	 * hooks, or with a single hook, which is a
-	 * common case.
+	 * Microoptimisation for an ng_socket with
+	 * a single hook, which is a common case.
 	 */
-	if (node->nd_numhooks == 0)
-		return (NULL);
 	if (node->nd_numhooks == 1) {
 		hook_p hook;
 


More information about the Zrouter-src-freebsd mailing list