Deleted Added
sdiff udiff text old ( 185419 ) new ( 185895 )
full compact
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 $
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/* 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 */
170static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE];
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
186static LIST_HEAD(, ng_node) ng_name_hash[NG_NAME_HASH_SIZE];
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
351static ng_ID_t nextID = 1;
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. */
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 ---