Author: glebius
Date: Sat Apr 14 10:08:07 2012
New Revision: 234276
URL: http://svn.freebsd.org/changeset/base/234276

Log:
  Merge 231760,231761,231764,231765,231766,231823,231830 from head:
  
    231760,231766:
        style(9): sort includes
    231761:
        In ng_bypass() add more protection against potential race
        with ng_rmnode() and its followers.
    231764:
        Remove testing stuff, reducing kernel memory footprint by 1 Kb.
    231765:
        Trim double empty lines.
    231823:
        In ng_getsockaddr() allocate memory prior to obtaining lock.
    231830:
        Specify correct loading order for core of netgraph(4).

Modified:
  stable/9/sys/netgraph/ng_base.c
  stable/9/sys/netgraph/ng_socket.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/netgraph/ng_base.c
==============================================================================
--- stable/9/sys/netgraph/ng_base.c     Sat Apr 14 09:48:52 2012        
(r234275)
+++ stable/9/sys/netgraph/ng_base.c     Sat Apr 14 10:08:07 2012        
(r234276)
@@ -45,23 +45,22 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ctype.h>
-#include <sys/errno.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/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 <sys/sysctl.h>
+#include <sys/syslog.h>
+#include <sys/unistd.h>
 #include <machine/cpu.h>
 
 #include <net/netisr.h>
@@ -240,7 +239,6 @@ int ng_path_parse(char *addr, char **nod
 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_HOOK, "netgraph_hook", "netgraph hook structures");
@@ -338,7 +336,6 @@ ng_alloc_node(void)
 #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);                             \
@@ -1158,6 +1155,10 @@ ng_bypass(hook_p hook1, hook_p hook2)
                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;
 
@@ -1199,7 +1200,6 @@ ng_newtype(struct ng_type *tp)
                return (EEXIST);
        }
 
-
        /* Link in new type */
        TYPELIST_WLOCK();
        LIST_INSERT_HEAD(&ng_typelist, tp, types);
@@ -3063,7 +3063,7 @@ vnet_netgraph_uninit(const void *unused 
                }
        } while (node != NULL);
 }
-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 */
 
@@ -3129,7 +3129,7 @@ static moduledata_t netgraph_mod = {
        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, "");
@@ -3268,7 +3268,6 @@ SYSCTL_PROC(_debug, OID_AUTO, ng_dump_it
     0, sizeof(int), sysctl_debug_ng_dump_items, "I", "Number of allocated 
items");
 #endif /* NETGRAPH_DEBUG */
 
-
 /***********************************************************************
 * Worklist routines
 **********************************************************************/
@@ -3352,7 +3351,6 @@ ng_worklist_add(node_p node)
        }
 }
 
-
 /***********************************************************************
 * Externally useable functions to set up a queue item ready for sending
 ***********************************************************************/
@@ -3433,8 +3431,6 @@ ng_package_msg(struct ng_mesg *msg, int 
        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) {        \
@@ -3660,7 +3656,6 @@ ng_callout_trampoline(void *arg)
        CURVNET_RESTORE();
 }
 
-
 int
 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
     ng_item_fn *fn, void * arg1, int arg2)
@@ -3730,32 +3725,3 @@ ng_replace_retaddr(node_p here, item_p i
                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 */

Modified: stable/9/sys/netgraph/ng_socket.c
==============================================================================
--- stable/9/sys/netgraph/ng_socket.c   Sat Apr 14 09:48:52 2012        
(r234275)
+++ stable/9/sys/netgraph/ng_socket.c   Sat Apr 14 10:08:07 2012        
(r234276)
@@ -469,33 +469,30 @@ ng_getsockaddr(struct socket *so, struct
        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;
        }
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "[email protected]"

Reply via email to