Deleted Added
full compact
ng_base.c (191827) ng_base.c (193731)
1/*
2 * ng_base.c
3 */
4
5/*-
6 * Copyright (c) 1996-1999 Whistle Communications, Inc.
7 * All rights reserved.
8 *

--- 24 unchanged lines hidden (view full) ---

33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36 * OF SUCH DAMAGE.
37 *
38 * Authors: Julian Elischer <julian@freebsd.org>
39 * Archie Cobbs <archie@freebsd.org>
40 *
1/*
2 * ng_base.c
3 */
4
5/*-
6 * Copyright (c) 1996-1999 Whistle Communications, Inc.
7 * All rights reserved.
8 *

--- 24 unchanged lines hidden (view full) ---

33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
36 * OF SUCH DAMAGE.
37 *
38 * Authors: Julian Elischer <julian@freebsd.org>
39 * Archie Cobbs <archie@freebsd.org>
40 *
41 * $FreeBSD: head/sys/netgraph/ng_base.c 191827 2009-05-05 16:26:06Z zec $
41 * $FreeBSD: head/sys/netgraph/ng_base.c 193731 2009-06-08 17:15:40Z zec $
42 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $
43 */
44
45/*
46 * This file implements the base netgraph code.
47 */
48
49#include <sys/param.h>

--- 30 unchanged lines hidden (view full) ---

80struct vnet_netgraph vnet_netgraph_0;
81#endif
82#endif
83
84/* Mutex to protect topology events. */
85static struct mtx ng_topo_mtx;
86
87static vnet_attach_fn vnet_netgraph_iattach;
42 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $
43 */
44
45/*
46 * This file implements the base netgraph code.
47 */
48
49#include <sys/param.h>

--- 30 unchanged lines hidden (view full) ---

80struct vnet_netgraph vnet_netgraph_0;
81#endif
82#endif
83
84/* Mutex to protect topology events. */
85static struct mtx ng_topo_mtx;
86
87static vnet_attach_fn vnet_netgraph_iattach;
88#ifdef VIMAGE
89static vnet_detach_fn vnet_netgraph_idetach;
90#endif
88
89#ifdef NETGRAPH_DEBUG
90static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
91static struct mtx ngq_mtx; /* protects the queue item list */
92
93static SLIST_HEAD(, ng_node) ng_allnodes;
94static LIST_HEAD(, ng_node) ng_freenodes; /* in debug, we never free() them */
95static SLIST_HEAD(, ng_hook) ng_allhooks;

--- 546 unchanged lines hidden (view full) ---

642
643 /* Make a node and try attach it to the type */
644 NG_ALLOC_NODE(node);
645 if (node == NULL) {
646 TRAP_ERROR();
647 return (ENOMEM);
648 }
649 node->nd_type = type;
91
92#ifdef NETGRAPH_DEBUG
93static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
94static struct mtx ngq_mtx; /* protects the queue item list */
95
96static SLIST_HEAD(, ng_node) ng_allnodes;
97static LIST_HEAD(, ng_node) ng_freenodes; /* in debug, we never free() them */
98static SLIST_HEAD(, ng_hook) ng_allhooks;

--- 546 unchanged lines hidden (view full) ---

645
646 /* Make a node and try attach it to the type */
647 NG_ALLOC_NODE(node);
648 if (node == NULL) {
649 TRAP_ERROR();
650 return (ENOMEM);
651 }
652 node->nd_type = type;
653#ifdef VIMAGE
654 node->nd_vnet = curvnet;
655#endif
650 NG_NODE_REF(node); /* note reference */
651 type->refs++;
652
653 NG_QUEUE_LOCK_INIT(&node->nd_input_queue);
654 STAILQ_INIT(&node->nd_input_queue.queue);
655 node->nd_input_queue.q_flags = 0;
656
657 /* Initialize hook list for new node */

--- 2411 unchanged lines hidden (view full) ---

3069 }
3070 return (error);
3071}
3072
3073#ifndef VIMAGE_GLOBALS
3074static const vnet_modinfo_t vnet_netgraph_modinfo = {
3075 .vmi_id = VNET_MOD_NETGRAPH,
3076 .vmi_name = "netgraph",
656 NG_NODE_REF(node); /* note reference */
657 type->refs++;
658
659 NG_QUEUE_LOCK_INIT(&node->nd_input_queue);
660 STAILQ_INIT(&node->nd_input_queue.queue);
661 node->nd_input_queue.q_flags = 0;
662
663 /* Initialize hook list for new node */

--- 2411 unchanged lines hidden (view full) ---

3075 }
3076 return (error);
3077}
3078
3079#ifndef VIMAGE_GLOBALS
3080static const vnet_modinfo_t vnet_netgraph_modinfo = {
3081 .vmi_id = VNET_MOD_NETGRAPH,
3082 .vmi_name = "netgraph",
3077#ifdef VIMAGE
3078 .vmi_size = sizeof(struct vnet_netgraph),
3083 .vmi_size = sizeof(struct vnet_netgraph),
3084 .vmi_dependson = VNET_MOD_LOIF,
3085 .vmi_iattach = vnet_netgraph_iattach,
3086#ifdef VIMAGE
3087 .vmi_idetach = vnet_netgraph_idetach
3079#endif
3088#endif
3080 .vmi_iattach = vnet_netgraph_iattach
3081};
3082#endif
3083
3084static int
3089};
3090#endif
3091
3092static int
3085vnet_netgraph_iattach(const void *arg __unused)
3093vnet_netgraph_iattach(const void *unused __unused)
3086{
3087 INIT_VNET_NETGRAPH(curvnet);
3088
3089 V_nextID = 1;
3090
3091 return (0);
3092}
3093
3094{
3095 INIT_VNET_NETGRAPH(curvnet);
3096
3097 V_nextID = 1;
3098
3099 return (0);
3100}
3101
3102#ifdef VIMAGE
3103static int
3104vnet_netgraph_idetach(const void *unused __unused)
3105{
3106 INIT_VNET_NETGRAPH(curvnet);
3107 node_p node, last_killed = NULL;
3108
3109 while ((node = LIST_FIRST(&V_ng_nodelist)) != NULL) {
3110 if (node == last_killed) {
3111 /* This should never happen */
3112 node->nd_flags |= NGF_REALLY_DIE;
3113 printf("netgraph node %s needs NGF_REALLY_DIE\n",
3114 node->nd_name);
3115 ng_rmnode(node, NULL, NULL, 0);
3116 /* This must never happen */
3117 if (node == LIST_FIRST(&V_ng_nodelist))
3118 panic("netgraph node %s won't die",
3119 node->nd_name);
3120 }
3121 ng_rmnode(node, NULL, NULL, 0);
3122 last_killed = node;
3123 }
3124
3125 return (0);
3126}
3127#endif /* VIMAGE */
3128
3094/*
3095 * Handle loading and unloading for this code.
3096 * The only thing we need to link into is the NETISR strucure.
3097 */
3098static int
3099ngb_mod_event(module_t mod, int event, void *data)
3100{
3101 struct proc *p;

--- 206 unchanged lines hidden (view full) ---

3308 node_p node;
3309
3310 /* Get node from the worklist. */
3311 NG_WORKLIST_LOCK();
3312 while ((node = STAILQ_FIRST(&ng_worklist)) == NULL)
3313 NG_WORKLIST_SLEEP();
3314 STAILQ_REMOVE_HEAD(&ng_worklist, nd_input_queue.q_work);
3315 NG_WORKLIST_UNLOCK();
3129/*
3130 * Handle loading and unloading for this code.
3131 * The only thing we need to link into is the NETISR strucure.
3132 */
3133static int
3134ngb_mod_event(module_t mod, int event, void *data)
3135{
3136 struct proc *p;

--- 206 unchanged lines hidden (view full) ---

3343 node_p node;
3344
3345 /* Get node from the worklist. */
3346 NG_WORKLIST_LOCK();
3347 while ((node = STAILQ_FIRST(&ng_worklist)) == NULL)
3348 NG_WORKLIST_SLEEP();
3349 STAILQ_REMOVE_HEAD(&ng_worklist, nd_input_queue.q_work);
3350 NG_WORKLIST_UNLOCK();
3351 CURVNET_SET(node->nd_vnet);
3316 CTR3(KTR_NET, "%20s: node [%x] (%p) taken off worklist",
3317 __func__, node->nd_ID, node);
3318 /*
3319 * We have the node. We also take over the reference
3320 * that the list had on it.
3321 * Now process as much as you can, until it won't
3322 * let you have another item off the queue.
3323 * All this time, keep the reference

--- 13 unchanged lines hidden (view full) ---

3337 } else {
3338 NG_QUEUE_UNLOCK(&node->nd_input_queue);
3339 NGI_GET_NODE(item, node); /* zaps stored node */
3340 ng_apply_item(node, item, rw);
3341 NG_NODE_UNREF(node);
3342 }
3343 }
3344 NG_NODE_UNREF(node);
3352 CTR3(KTR_NET, "%20s: node [%x] (%p) taken off worklist",
3353 __func__, node->nd_ID, node);
3354 /*
3355 * We have the node. We also take over the reference
3356 * that the list had on it.
3357 * Now process as much as you can, until it won't
3358 * let you have another item off the queue.
3359 * All this time, keep the reference

--- 13 unchanged lines hidden (view full) ---

3373 } else {
3374 NG_QUEUE_UNLOCK(&node->nd_input_queue);
3375 NGI_GET_NODE(item, node); /* zaps stored node */
3376 ng_apply_item(node, item, rw);
3377 NG_NODE_UNREF(node);
3378 }
3379 }
3380 NG_NODE_UNREF(node);
3381 CURVNET_RESTORE();
3345 }
3346}
3347
3348/*
3349 * XXX
3350 * It's posible that a debugging NG_NODE_REF may need
3351 * to be outside the mutex zone
3352 */

--- 317 unchanged lines hidden (view full) ---

3670/*
3671 * Official timeout routines for Netgraph nodes.
3672 */
3673static void
3674ng_callout_trampoline(void *arg)
3675{
3676 item_p item = arg;
3677
3382 }
3383}
3384
3385/*
3386 * XXX
3387 * It's posible that a debugging NG_NODE_REF may need
3388 * to be outside the mutex zone
3389 */

--- 317 unchanged lines hidden (view full) ---

3707/*
3708 * Official timeout routines for Netgraph nodes.
3709 */
3710static void
3711ng_callout_trampoline(void *arg)
3712{
3713 item_p item = arg;
3714
3715 CURVNET_SET(NGI_NODE(item)->nd_vnet);
3678 ng_snd_item(item, 0);
3716 ng_snd_item(item, 0);
3717 CURVNET_RESTORE();
3679}
3680
3681
3682int
3683ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
3684 ng_item_fn *fn, void * arg1, int arg2)
3685{
3686 item_p item, oitem;

--- 94 unchanged lines hidden ---
3718}
3719
3720
3721int
3722ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
3723 ng_item_fn *fn, void * arg1, int arg2)
3724{
3725 item_p item, oitem;

--- 94 unchanged lines hidden ---