Deleted Added
full compact
ng_base.c (185419) ng_base.c (185895)
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 185419 2008-11-28 23:30:51Z zec $
41 * $FreeBSD: head/sys/netgraph/ng_base.c 185895 2008-12-10 23:12:39Z 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>

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

67#include <net/netisr.h>
68
69#include <netgraph/ng_message.h>
70#include <netgraph/netgraph.h>
71#include <netgraph/ng_parse.h>
72
73MODULE_VERSION(netgraph, NG_ABI_VERSION);
74
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>

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

67#include <net/netisr.h>
68
69#include <netgraph/ng_message.h>
70#include <netgraph/netgraph.h>
71#include <netgraph/ng_parse.h>
72
73MODULE_VERSION(netgraph, NG_ABI_VERSION);
74
75#ifndef VIMAGE
76#ifndef VIMAGE_GLOBALS
77struct vnet_netgraph vnet_netgraph_0;
78#endif
79#endif
80
75/* Mutex to protect topology events. */
76static struct mtx ng_topo_mtx;
77
78#ifdef NETGRAPH_DEBUG
79static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
80static struct mtx ngq_mtx; /* protects the queue item list */
81
82static SLIST_HEAD(, ng_node) ng_allnodes;

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

162static struct mtx ng_worklist_mtx; /* MUST LOCK NODE FIRST */
163
164/* List of installed types */
165static LIST_HEAD(, ng_type) ng_typelist;
166static struct mtx ng_typelist_mtx;
167
168/* Hash related definitions */
169/* XXX Don't need to initialise them because it's a LIST */
81/* Mutex to protect topology events. */
82static struct mtx ng_topo_mtx;
83
84#ifdef NETGRAPH_DEBUG
85static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
86static struct mtx ngq_mtx; /* protects the queue item list */
87
88static SLIST_HEAD(, ng_node) ng_allnodes;

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

168static struct mtx ng_worklist_mtx; /* MUST LOCK NODE FIRST */
169
170/* List of installed types */
171static LIST_HEAD(, ng_type) ng_typelist;
172static struct mtx ng_typelist_mtx;
173
174/* Hash related definitions */
175/* XXX Don't need to initialise them because it's a LIST */
176#ifdef VIMAGE_GLOBALS
170static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE];
177static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE];
178#endif
171static struct mtx ng_idhash_mtx;
172/* Method to find a node.. used twice so do it here */
173#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE))
174#define NG_IDHASH_FIND(ID, node) \
175 do { \
176 mtx_assert(&ng_idhash_mtx, MA_OWNED); \
177 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \
178 nd_idnodes) { \
179 if (NG_NODE_IS_VALID(node) \
180 && (NG_NODE_ID(node) == ID)) { \
181 break; \
182 } \
183 } \
184 } while (0)
185
179static struct mtx ng_idhash_mtx;
180/* Method to find a node.. used twice so do it here */
181#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE))
182#define NG_IDHASH_FIND(ID, node) \
183 do { \
184 mtx_assert(&ng_idhash_mtx, MA_OWNED); \
185 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \
186 nd_idnodes) { \
187 if (NG_NODE_IS_VALID(node) \
188 && (NG_NODE_ID(node) == ID)) { \
189 break; \
190 } \
191 } \
192 } while (0)
193
194#ifdef VIMAGE_GLOBALS
186static LIST_HEAD(, ng_node) ng_name_hash[NG_NAME_HASH_SIZE];
195static LIST_HEAD(, ng_node) ng_name_hash[NG_NAME_HASH_SIZE];
196#endif
187static struct mtx ng_namehash_mtx;
188#define NG_NAMEHASH(NAME, HASH) \
189 do { \
190 u_char h = 0; \
191 const u_char *c; \
192 for (c = (const u_char*)(NAME); *c; c++)\
193 h += *c; \
194 (HASH) = h % (NG_NAME_HASH_SIZE); \

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

343
344#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
345
346/* Set this to kdb_enter("X") to catch all errors as they occur */
347#ifndef TRAP_ERROR
348#define TRAP_ERROR()
349#endif
350
197static struct mtx ng_namehash_mtx;
198#define NG_NAMEHASH(NAME, HASH) \
199 do { \
200 u_char h = 0; \
201 const u_char *c; \
202 for (c = (const u_char*)(NAME); *c; c++)\
203 h += *c; \
204 (HASH) = h % (NG_NAME_HASH_SIZE); \

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

353
354#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
355
356/* Set this to kdb_enter("X") to catch all errors as they occur */
357#ifndef TRAP_ERROR
358#define TRAP_ERROR()
359#endif
360
351static ng_ID_t nextID = 1;
361#ifdef VIMAGE_GLOBALS
362static ng_ID_t nextID;
363#endif
352
353#ifdef INVARIANTS
354#define CHECK_DATA_MBUF(m) do { \
355 struct mbuf *n; \
356 int total; \
357 \
358 M_ASSERTPKTHDR(m); \
359 for (total = 0, n = (m); n != NULL; n = n->m_next) { \

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

3058static int
3059ngb_mod_event(module_t mod, int event, void *data)
3060{
3061 int error = 0;
3062
3063 switch (event) {
3064 case MOD_LOAD:
3065 /* Initialize everything. */
364
365#ifdef INVARIANTS
366#define CHECK_DATA_MBUF(m) do { \
367 struct mbuf *n; \
368 int total; \
369 \
370 M_ASSERTPKTHDR(m); \
371 for (total = 0, n = (m); n != NULL; n = n->m_next) { \

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

3070static int
3071ngb_mod_event(module_t mod, int event, void *data)
3072{
3073 int error = 0;
3074
3075 switch (event) {
3076 case MOD_LOAD:
3077 /* Initialize everything. */
3078 V_nextID = 1;
3066 NG_WORKLIST_LOCK_INIT();
3067 mtx_init(&ng_typelist_mtx, "netgraph types mutex", NULL,
3068 MTX_DEF);
3069 mtx_init(&ng_idhash_mtx, "netgraph idhash mutex", NULL,
3070 MTX_DEF);
3071 mtx_init(&ng_namehash_mtx, "netgraph namehash mutex", NULL,
3072 MTX_DEF);
3073 mtx_init(&ng_topo_mtx, "netgraph topology mutex", NULL,

--- 654 unchanged lines hidden ---
3079 NG_WORKLIST_LOCK_INIT();
3080 mtx_init(&ng_typelist_mtx, "netgraph types mutex", NULL,
3081 MTX_DEF);
3082 mtx_init(&ng_idhash_mtx, "netgraph idhash mutex", NULL,
3083 MTX_DEF);
3084 mtx_init(&ng_namehash_mtx, "netgraph namehash mutex", NULL,
3085 MTX_DEF);
3086 mtx_init(&ng_topo_mtx, "netgraph topology mutex", NULL,

--- 654 unchanged lines hidden ---