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 215701 2010-11-22 19:32:54Z dim $
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>
--- 116 unchanged lines hidden (view full) ---
166static struct mtx ng_worklist_mtx; /* MUST LOCK NODE FIRST */
167
168/* List of installed types */
169static LIST_HEAD(, ng_type) ng_typelist;
170static struct mtx ng_typelist_mtx;
171
172/* Hash related definitions */
173/* XXX Don't need to initialise them because it's a LIST */
174static VNET_DEFINE(LIST_HEAD(, ng_node), ng_ID_hash[NG_ID_HASH_SIZE]);
175#define V_ng_ID_hash VNET(ng_ID_hash)
176
177static struct mtx ng_idhash_mtx;
178/* Method to find a node.. used twice so do it here */
179#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE))
180#define NG_IDHASH_FIND(ID, node) \
181 do { \
182 mtx_assert(&ng_idhash_mtx, MA_OWNED); \
183 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \
184 nd_idnodes) { \
185 if (NG_NODE_IS_VALID(node) \
186 && (NG_NODE_ID(node) == ID)) { \
187 break; \
188 } \
189 } \
190 } while (0)
191
192static VNET_DEFINE(LIST_HEAD(, ng_node), ng_name_hash[NG_NAME_HASH_SIZE]);
193#define V_ng_name_hash VNET(ng_name_hash)
194
195static struct mtx ng_namehash_mtx;
196#define NG_NAMEHASH(NAME, HASH) \
197 do { \
198 u_char h = 0; \
199 const u_char *c; \
200 for (c = (const u_char*)(NAME); *c; c++)\
--- 153 unchanged lines hidden (view full) ---
354
355#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
356
357/* Set this to kdb_enter("X") to catch all errors as they occur */
358#ifndef TRAP_ERROR
359#define TRAP_ERROR()
360#endif
361
362static VNET_DEFINE(ng_ID_t, nextID) = 1;
363#define V_nextID VNET(nextID)
364
365#ifdef INVARIANTS
366#define CHECK_DATA_MBUF(m) do { \
367 struct mbuf *n; \
368 int total; \
369 \
370 M_ASSERTPKTHDR(m); \
--- 3424 unchanged lines hidden ---
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 215701 2010-11-22 19:32:54Z dim $
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>
--- 116 unchanged lines hidden (view full) ---
166static struct mtx ng_worklist_mtx; /* MUST LOCK NODE FIRST */
167
168/* List of installed types */
169static LIST_HEAD(, ng_type) ng_typelist;
170static struct mtx ng_typelist_mtx;
171
172/* Hash related definitions */
173/* XXX Don't need to initialise them because it's a LIST */
174static VNET_DEFINE(LIST_HEAD(, ng_node), ng_ID_hash[NG_ID_HASH_SIZE]);
175#define V_ng_ID_hash VNET(ng_ID_hash)
176
177static struct mtx ng_idhash_mtx;
178/* Method to find a node.. used twice so do it here */
179#define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE))
180#define NG_IDHASH_FIND(ID, node) \
181 do { \
182 mtx_assert(&ng_idhash_mtx, MA_OWNED); \
183 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \
184 nd_idnodes) { \
185 if (NG_NODE_IS_VALID(node) \
186 && (NG_NODE_ID(node) == ID)) { \
187 break; \
188 } \
189 } \
190 } while (0)
191
192static VNET_DEFINE(LIST_HEAD(, ng_node), ng_name_hash[NG_NAME_HASH_SIZE]);
193#define V_ng_name_hash VNET(ng_name_hash)
194
195static struct mtx ng_namehash_mtx;
196#define NG_NAMEHASH(NAME, HASH) \
197 do { \
198 u_char h = 0; \
199 const u_char *c; \
200 for (c = (const u_char*)(NAME); *c; c++)\
--- 153 unchanged lines hidden (view full) ---
354
355#endif /* NETGRAPH_DEBUG */ /*----------------------------------------------*/
356
357/* Set this to kdb_enter("X") to catch all errors as they occur */
358#ifndef TRAP_ERROR
359#define TRAP_ERROR()
360#endif
361
362static VNET_DEFINE(ng_ID_t, nextID) = 1;
363#define V_nextID VNET(nextID)
364
365#ifdef INVARIANTS
366#define CHECK_DATA_MBUF(m) do { \
367 struct mbuf *n; \
368 int total; \
369 \
370 M_ASSERTPKTHDR(m); \
--- 3424 unchanged lines hidden ---