xref: /freebsd/sys/netgraph/netgraph.h (revision c68159a6d8eede11766cf13896d0f7670dbd51aa)
1 
2 /*
3  * netgraph.h
4  *
5  * Copyright (c) 1996-1999 Whistle Communications, Inc.
6  * All rights reserved.
7  *
8  * Subject to the following obligations and disclaimer of warranty, use and
9  * redistribution of this software, in source or object code forms, with or
10  * without modifications are expressly permitted by Whistle Communications;
11  * provided, however, that:
12  * 1. Any and all reproductions of the source or object code must include the
13  *    copyright notice above and the following disclaimer of warranties; and
14  * 2. No rights are granted, in any manner or form, to use Whistle
15  *    Communications, Inc. trademarks, including the mark "WHISTLE
16  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17  *    such appears in the above copyright notice or in the software.
18  *
19  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35  * OF SUCH DAMAGE.
36  *
37  * Author: Julian Elischer <julian@freebsd.org>
38  *
39  * $FreeBSD$
40  * $Whistle: netgraph.h,v 1.29 1999/11/01 07:56:13 julian Exp $
41  */
42 
43 #ifndef _NETGRAPH_NETGRAPH_H_
44 #define _NETGRAPH_NETGRAPH_H_ 1
45 
46 #include <sys/queue.h>
47 #include <sys/malloc.h>
48 #include <sys/module.h>
49 
50 #ifndef _KERNEL
51 #error "This file should not be included in user level programs"
52 #endif
53 
54 #include <sys/mutex.h>
55 
56 /* The structure for queueing across ISR switches */
57 struct ng_item ; /* forward reference */
58 typedef	struct ng_item *item_p;
59 struct ng_queue {
60 	u_long          q_flags;
61 	struct mtx      q_mtx;
62 	item_p queue;
63 	item_p *last;
64 	struct ng_node *q_node;		/* find the front of the node.. */
65 };
66 
67 /*
68  * Structure of a hook
69  */
70 struct ng_hook {
71 	char   name[NG_HOOKLEN+1];/* what this node knows this link as */
72 	void   *private;	/* node dependant ID for this hook */
73 	int	flags;		/* info about this hook/link */
74 	int	refs;		/* dont actually free this till 0 */
75 	struct	ng_hook *peer;	/* the other end of this link */
76 	struct	ng_node *node;	/* The node this hook is attached to */
77 	LIST_ENTRY(ng_hook) hooks;	/* linked list of all hooks on node */
78 };
79 typedef struct ng_hook *hook_p;
80 
81 /* Flags for a hook */
82 #define HK_INVALID		0x0001	/* don't trust it! */
83 #define HK_QUEUE		0x0002	/* queue for later delivery */
84 #define HK_FORCE_WRITER		0x0004	/* Incoming data queued as a writer */
85 
86 /*
87  * Structure of a node
88  */
89 struct ng_node {
90 	char   name[NG_NODELEN+1]; /* optional globally unique name */
91 	struct	ng_type *type;	/* the installed 'type' */
92 	int	flags;		/* see below for bit definitions */
93 	int	refs;		/* number of references to this node */
94 	int	numhooks;	/* number of hooks */
95 	void   *private;	/* node type dependant node ID */
96 	ng_ID_t		ID;	/* Unique per node */
97 	LIST_HEAD(hooks, ng_hook) hooks;	/* linked list of node hooks */
98 	LIST_ENTRY(ng_node)	  nodes;	/* linked list of all nodes */
99 	LIST_ENTRY(ng_node)	  idnodes;	/* ID hash collision list */
100 	TAILQ_ENTRY(ng_node)	  work;		/* nodes with work to do */
101 	struct	ng_queue	  input_queue;	/* input queue for locking */
102 };
103 typedef struct ng_node *node_p;
104 
105 /* Flags for a node */
106 #define NG_INVALID	0x00000001	/* free when refs go to 0 */
107 #define NG_WORKQ	0x00000002	/* node is on the work queue */
108 #define NG_FORCE_WRITER	0x00000004	/* Never multithread this node */
109 #define NG_CLOSING	0x00000008	/* ng_rmnode() at work */
110 #define NGF_TYPE1	0x10000000	/* reserved for type specific storage */
111 #define NGF_TYPE2	0x20000000	/* reserved for type specific storage */
112 #define NGF_TYPE3	0x40000000	/* reserved for type specific storage */
113 #define NGF_TYPE4	0x80000000	/* reserved for type specific storage */
114 
115 /*
116  * The structure that holds meta_data about a data packet (e.g. priority)
117  * Nodes might add or subtract options as needed if there is room.
118  * They might reallocate the struct to make more room if they need to.
119  * Meta-data is still experimental.
120  */
121 struct meta_field_header {
122 	u_long	cookie;		/* cookie for the field. Skip fields you don't
123 				 * know about (same cookie as in messgaes) */
124 	u_short type;		/* field ID */
125 	u_short len;		/* total len of this field including extra
126 				 * data */
127 	char	data[0];	/* data starts here */
128 };
129 
130 /* To zero out an option 'in place' set it's cookie to this */
131 #define NGM_INVALID_COOKIE	865455152
132 
133 /* This part of the metadata is always present if the pointer is non NULL */
134 struct ng_meta {
135 	char	priority;	/* -ve is less priority,  0 is default */
136 	char	discardability; /* higher is less valuable.. discard first */
137 	u_short allocated_len;	/* amount malloc'd */
138 	u_short used_len;	/* sum of all fields, options etc. */
139 	u_short flags;		/* see below.. generic flags */
140 	struct meta_field_header options[0];	/* add as (if) needed */
141 };
142 typedef struct ng_meta *meta_p;
143 
144 /* Flags for meta-data */
145 #define NGMF_TEST	0x01	/* discard at the last moment before sending */
146 #define NGMF_TRACE	0x02	/* trace when handing this data to a node */
147 
148 /* node method definitions */
149 typedef	int	ng_constructor_t(node_p node);
150 typedef	int	ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook);
151 typedef	int	ng_shutdown_t(node_p node);
152 typedef	int	ng_newhook_t(node_p node, hook_p hook, const char *name);
153 typedef	hook_p	ng_findhook_t(node_p node, const char *name);
154 typedef	int	ng_connect_t(hook_p hook);
155 typedef	int	ng_rcvdata_t(hook_p hook, item_p item);
156 typedef	int	ng_disconnect_t(hook_p hook);
157 typedef	int	ng_rcvitem (node_p node, hook_p hook, item_p item);
158 /*
159  * Command list -- each node type specifies the command that it knows
160  * how to convert between ASCII and binary using an array of these.
161  * The last element in the array must be a terminator with cookie=0.
162  */
163 
164 struct ng_cmdlist {
165 	u_int32_t			cookie;		/* command typecookie */
166 	int				cmd;		/* command number */
167 	const char			*name;		/* command name */
168 	const struct ng_parse_type	*mesgType;	/* args if !NGF_RESP */
169 	const struct ng_parse_type	*respType;	/* args if NGF_RESP */
170 };
171 
172 /*
173  * Structure of a node type
174  * If data is sent to the "rcvdata()" entrypoint then the system
175  * may decide to defer it until later by queing it with the normal netgraph
176  * input queuing system.  This is decidde by the HK_QUEUE flag being set in
177  * the flags word of the peer (receiving) hook. The dequeuing mechanism will
178  * ensure it is not requeued again.
179  * Note the input queueing system is to allow modules
180  * to 'release the stack' or to pass data across spl layers.
181  * The data will be redelivered as soon as the NETISR code runs
182  * which may be almost immediatly.  A node may also do it's own queueing
183  * for other reasons (e.g. device output queuing).
184  */
185 struct ng_type {
186 
187 	u_int32_t	version; 	/* must equal NG_API_VERSION */
188 	const char	*name;		/* Unique type name */
189 	modeventhand_t	mod_event;	/* Module event handler (optional) */
190 	ng_constructor_t *constructor;	/* Node constructor */
191 	ng_rcvmsg_t	*rcvmsg;	/* control messages come here */
192 	ng_shutdown_t	*shutdown;	/* reset, and free resources */
193 	ng_newhook_t	*newhook;	/* first notification of new hook */
194 	ng_findhook_t	*findhook;	/* only if you have lots of hooks */
195 	ng_connect_t	*connect;	/* final notification of new hook */
196 	ng_rcvdata_t	*rcvdata;	/* data comes here */
197 	ng_disconnect_t	*disconnect;	/* notify on disconnect */
198 
199 	const struct	ng_cmdlist *cmdlist;	/* commands we can convert */
200 
201 	/* R/W data private to the base netgraph code DON'T TOUCH! */
202 	LIST_ENTRY(ng_type) types;		/* linked list of all types */
203 	int		    refs;		/* number of instances */
204 };
205 
206 struct ng_item {
207 	u_long	el_flags;
208 	item_p	el_next;
209 	node_p	el_dest; /* The node it will be applied against (or NULL) */
210 	hook_p	el_hook; /* Entering hook. Optional in Control messages */
211 	union {
212 		struct {
213 			struct mbuf	*da_m;
214 			meta_p		da_meta;
215 		} data;
216 		struct {
217 			struct ng_mesg	*msg_msg;
218 			ng_ID_t		msg_retaddr;
219 		} msg;
220 	} body;
221 #define ITEM_DEBUG
222 #ifdef	ITEM_DEBUG
223 	char *lastfile;
224 	int  lastline;
225 	TAILQ_ENTRY(ng_item)	  all;		/* all existing items */
226 #endif	/* ITEM_DEBUG */
227 };
228 #define NGQF_D_M	0x01		/* MASK of data/message */
229 #define NGQF_DATA	0x01		/* the queue element is data */
230 #define NGQF_MESG	0x00		/* the queue element is a message */
231 #define NGQF_TYPE	0x02		/*  MASK for queue entry type */
232 #define NGQF_READER	0x02		/* queued as a reader */
233 #define NGQF_WRITER	0x00		/* queued as a writer */
234 #define NGQF_FREE	0x04
235 
236 /*
237  * This defines the in-kernel binary interface version.
238  * It is possible to change this but leave the external message
239  * API the same. Each type also has it's own cookies for versioning as well.
240  * Change it for ITEM_DEBUG version so we cannot mix debug and non debug
241  * modules.
242  */
243 #define _NG_ABI_VERSION 5
244 #ifdef	ITEM_DEBUG
245 #define NG_ABI_VERSION	(_NG_ABI_VERSION + 0x10000)
246 #else	/* ITEM_DEBUG */
247 #define NG_ABI_VERSION	_NG_ABI_VERSION
248 #endif	/* ITEM_DEBUG */
249 
250 /**********************************************************************
251 * Queue item macros.  Peek and extract values.
252 **********************************************************************/
253 /*
254  * Get the mbuf (etc) out of an item.
255  * Sets the value in the item to NULL in case we need to call NG_FREE_ITEM()
256  * with it, (to avoid freeing the things twice).
257  * If you don't want to zero out the item then realise that the
258  * item still owns it.
259  * Retaddr is different. There are no references on that. It's just a number.
260  * The debug versions must be either all used everywhere or not at all.
261  */
262 
263 #define _NGI_M(i) ((i)->body.data.da_m)
264 #define _NGI_META(i) ((i)->body.data.da_meta)
265 #define _NGI_MSG(i) ((i)->body.msg.msg_msg)
266 #define _NGI_RETADDR(i) ((i)->body.msg.msg_retaddr)
267 
268 #ifdef ITEM_DEBUG
269 void	dumpitem(item_p item, char *file, int line);
270 static __inline void _ngi_check(item_p item, char *file, int line) ;
271 static __inline struct mbuf ** _ngi_m(item_p item, char *file, int line) ;
272 static __inline meta_p * _ngi_meta(item_p item, char *file, int line) ;
273 static __inline struct ng_mesg ** _ngi_msg(item_p item, char *file, int line) ;
274 static __inline ng_ID_t * _ngi_retaddr(item_p item, char *file, int line) ;
275 
276 static __inline void
277 _ngi_check(item_p item, char *file, int line)
278 {
279 	if (item->el_flags & NGQF_FREE) {
280 		dumpitem(item, file, line);
281 		panic ("free item!");
282 	}
283 	(item)->lastline = line;
284 	(item)->lastfile = file;
285 }
286 
287 static __inline struct mbuf **
288 _ngi_m(item_p item, char *file, int line)
289 {
290 	_ngi_check(item, file, line);
291 	return (&_NGI_M(item));
292 }
293 
294 static __inline meta_p *
295 _ngi_meta(item_p item, char *file, int line)
296 {
297 	_ngi_check(item, file, line);
298 	return (&_NGI_META(item));
299 }
300 
301 static __inline struct ng_mesg **
302 _ngi_msg(item_p item, char *file, int line)
303 {
304 	_ngi_check(item, file, line);
305 	return (&_NGI_MSG(item));
306 }
307 
308 static __inline ng_ID_t *
309 _ngi_retaddr(item_p item, char *file, int line)
310 {
311 	_ngi_check(item, file, line);
312 	return (&_NGI_RETADDR(item));
313 }
314 
315 #define NGI_M(i) (*_ngi_m(i, __FILE__, __LINE__))
316 
317 #define NGI_META(i) (*_ngi_meta(i, __FILE__, __LINE__))
318 
319 #define NGI_MSG(i) (*_ngi_msg(i, __FILE__, __LINE__))
320 
321 #define NGI_RETADDR(i) (*_ngi_retaddr(i, __FILE__, __LINE__))
322 
323 #define NGI_GET_M(i,m)							\
324 	do {								\
325 		m = NGI_M(i);						\
326 		_NGI_M(i) = NULL;					\
327 	} while (0)
328 
329 #define NGI_GET_META(i,m)						\
330 	do {								\
331 		m = NGI_META(i);					\
332 		_NGI_META(i) = NULL;					\
333 	} while (0)
334 
335 #define NGI_GET_MSG(i,m)						\
336 	do {								\
337 		m = NGI_MSG(i);						\
338 		_NGI_MSG(i) = NULL;					\
339 	} while (0)
340 
341 #define NG_FREE_ITEM(item)						\
342 	do {								\
343 		_ngi_check(item, __FILE__, __LINE__);			\
344 		ng_free_item((item));					\
345 	} while (0)
346 
347 #define	SAVE_LINE(item)							\
348 	do {								\
349 		(item)->lastline = __LINE__;				\
350 		(item)->lastfile = __FILE__;				\
351 	} while (0)
352 
353 #else	/* ITEM_DEBUG */
354 
355 
356 #define NGI_M(i)	_NGI_M(i)
357 #define NGI_META(i)	_NGI_META(i)
358 #define NGI_MSG(i)	_NGI_MSG(i)
359 #define NGI_RETADDR(i)	_NGI_RETADDR(i)
360 
361 #define NGI_GET_M(i,m)       do {m = NGI_M(i); NGI_M(i) = NULL;      } while (0)
362 #define NGI_GET_META(i,m)    do {m = NGI_META(i); NGI_META(i) = NULL;} while (0)
363 #define NGI_GET_MSG(i,m)     do {m = NGI_MSG(i); NGI_MSG(i) = NULL;  } while (0)
364 
365 #define	NG_FREE_ITEM(item)	ng_free_item((item))
366 #define	SAVE_LINE(item)
367 
368 #endif	/* ITEM_DEBUG */
369 
370 /**********************************************************************
371 * Data macros.  Send, manipulate and free.
372 **********************************************************************/
373 /* Send data packet including a possible sync response pointer */
374 #define NG_SEND_DATA(error, hook, m, meta)				\
375 	do {								\
376 		item_p item;						\
377 		if ((item = ng_package_data((m), (meta)))) {		\
378 			if (!((error) = ng_address_hook(NULL, item,	\
379 							hook, NULL))) {	\
380 				SAVE_LINE(item);			\
381 				(error) = ng_snd_item((item), 0);	\
382 			}						\
383 		} else {						\
384 			(error) = ENOMEM;				\
385 		}							\
386 		(m) = NULL;						\
387 		(meta) = NULL;						\
388 	} while (0)
389 
390 #define NG_SEND_DATA_ONLY(error, hook, m)				\
391 	do {								\
392 		item_p item;						\
393 		if ((item = ng_package_data((m), NULL))) {		\
394 			if (!((error) = ng_address_hook(NULL, item,	\
395 							hook, NULL))) {	\
396 				SAVE_LINE(item);			\
397 				(error) = ng_snd_item((item), 0);	\
398 			}						\
399 		} else {						\
400 			(error) = ENOMEM;				\
401 		}							\
402 		(m) = NULL;						\
403 	} while (0)
404 
405 /*
406  * Forward a data packet with no new meta-data.
407  * old metadata is passed along without change.
408  * Mbuf pointer is updated to new value.
409  */
410 #define NG_FWD_NEW_DATA(error, item, hook, m)				\
411 	do {								\
412 		NGI_M(item) = m;					\
413 		if (!((error) = ng_address_hook(NULL, (item),		\
414 						(hook), NULL))) {	\
415 			SAVE_LINE(item);				\
416 			(error) = ng_snd_item((item), 0);		\
417 		}							\
418 		(item) = NULL;						\
419 		(m) = NULL;						\
420 	} while (0)
421 
422 /*
423  * Assuming the data is already ok, just set the new address and send
424  */
425 #define NG_FWD_DATA(error, item, hook)					\
426 	do {								\
427 		if (!((error) = ng_address_hook(NULL, (item),		\
428 						(hook), NULL))) {	\
429 			SAVE_LINE(item);				\
430 			(error) = ng_snd_item((item), 0);		\
431 		} else {						\
432 			(error) = ENXIO;				\
433 		}							\
434 		(item) = NULL;						\
435 	} while (0)
436 
437 
438 /* Note that messages can be static (e.g. in ng_rmnode_self()) */
439 /* XXX flag should not be user visible  */
440 #define NG_FREE_MSG(msg)						\
441 	do {								\
442 		if ((msg)) {						\
443 			if ((msg->header.flags & NGF_STATIC) == 0) {	\
444 				FREE((msg), M_NETGRAPH_MSG);		\
445 			}						\
446 			(msg) = NULL;					\
447 		}	 						\
448 	} while (0)
449 
450 #define NG_FREE_META(meta)						\
451 	do {								\
452 		if ((meta)) {						\
453 			FREE((meta), M_NETGRAPH_META);			\
454 			(meta) = NULL;					\
455 		}	 						\
456 	} while (0)
457 
458 #define NG_FREE_M(m)							\
459 	do {								\
460 		if ((m)) {						\
461 			m_freem((m));					\
462 			(m) = NULL;					\
463 		}							\
464 	} while (0)
465 /* Free any data packet and/or meta-data */
466 #define NG_FREE_DATAX(m, meta)						\
467 	do {								\
468 		NG_FREE_M((m));						\
469 		NG_FREE_META((meta));					\
470 	} while (0)
471 /*****************************************
472 * Message macros
473 *****************************************/
474 
475 #define NG_SEND_MSG_HOOK(error, here, msg, hook, retaddr)		\
476 	do {								\
477 		item_p item;						\
478 		if ((item = ng_package_msg(msg))			\
479 		&& (ng_address_hook((here), (item),			\
480 					(hook), (retaddr)) == 0)) {	\
481 			SAVE_LINE(item);				\
482 			(error) = ng_snd_item((item), 0);		\
483 		} else {						\
484 			(error) = EINVAL;				\
485 		}							\
486 		(msg) = NULL;						\
487 	} while (0)
488 
489 #define NG_SEND_MSG_PATH(error, here, msg, path, retaddr)		\
490 	do {								\
491 		item_p item;						\
492 		if ((item = ng_package_msg(msg))			\
493 		&& (ng_address_path((here), (item),			\
494 					(path), (retaddr)) == 0)) {	\
495 			SAVE_LINE(item);				\
496 			(error) = ng_snd_item((item), 0);		\
497 		} else {						\
498 			(error) = EINVAL;				\
499 		}							\
500 		(msg) = NULL;						\
501 	} while (0)
502 
503 #define NG_SEND_MSG_ID(error, here, msg, ID, retaddr)			\
504 	do {								\
505 		item_p item;						\
506 		if ((item = ng_package_msg(msg))			\
507 		&& (ng_address_ID((here), (item),			\
508 					(ID), (retaddr)) == 0)) {	\
509 			SAVE_LINE(item);				\
510 			(error) = ng_snd_item((item), 0);		\
511 		} else {						\
512 			(error) = EINVAL;				\
513 		}							\
514 		(msg) = NULL;						\
515 	} while (0)
516 
517 #define NG_QUEUE_MSG(error, here, msg, path, retaddr)			\
518 	do {								\
519 		item_p item;						\
520 		if ((item = ng_package_msg(msg))			\
521 		&& (ng_address_path((here), (item),			\
522 					(path), (retaddr)) == 0)) {	\
523 			SAVE_LINE(item);				\
524 			(error) = ng_snd_item((item), 0);		\
525 		} else {						\
526 			(error) = EINVAL;				\
527 		}							\
528 		(msg) = NULL;						\
529 	} while (0)
530 
531 /*
532  * Redirect the message to the next hop using the given hook.
533  * ng_retarget_msg() frees the item if there is an error
534  * and returns an error code.  It returns 0 on success.
535  */
536 #define NG_FWD_MSG_HOOK(error, here, item, hook, retaddr)		\
537 	do {								\
538 		if ((ng_address_hook((here), (item),			\
539 					(hook), (retaddr))) == 0) {	\
540 			SAVE_LINE(item);				\
541 			(error) = ng_snd_item((item), 0);		\
542 		} else {						\
543 			(error) = EINVAL;				\
544 		}							\
545 		(item) = NULL;						\
546 	} while (0)
547 
548 /*
549  * Send a queue item back to it's originator with a response message.
550  * Assume original message was removed and freed separatly.
551  */
552 #define NG_RESPOND_MSG(error, here, item, resp)				\
553 	do {								\
554 		if (resp) {						\
555 			ng_ID_t dest = NGI_RETADDR(item);		\
556 			NGI_RETADDR(item) = NULL;			\
557 			NGI_MSG(item) = resp;				\
558 			if ((ng_address_ID((here), (item),		\
559 					dest, NULL )) == 0) {		\
560 				SAVE_LINE(item);			\
561 				(error) = ng_snd_item((item), 1);	\
562 			} else {					\
563 				(error) = EINVAL;			\
564 			}						\
565 		} else {						\
566 			NG_FREE_ITEM(item);				\
567 		}							\
568 		(item) = NULL;						\
569 	} while (0)
570 
571 
572 /*
573  * Use the NETGRAPH_INIT() macro to link a node type into the
574  * netgraph system. This works for types compiled into the kernel
575  * as well as KLD modules. The first argument should be the type
576  * name (eg, echo) and the second a pointer to the type struct.
577  *
578  * If a different link time is desired, e.g., a device driver that
579  * needs to install its netgraph type before probing, use the
580  * NETGRAPH_INIT_ORDERED() macro instead. Deivce drivers probably
581  * want to use SI_SUB_DRIVERS instead of SI_SUB_PSEUDO.
582  */
583 
584 #define NETGRAPH_INIT_ORDERED(typename, typestructp, sub, order)	\
585 static moduledata_t ng_##typename##_mod = {				\
586 	"ng_" #typename,						\
587 	ng_mod_event,							\
588 	(typestructp)							\
589 };									\
590 DECLARE_MODULE(ng_##typename, ng_##typename##_mod, sub, order);		\
591 MODULE_DEPEND(ng_##typename, netgraph, 1, 1, 1)
592 
593 #define NETGRAPH_INIT(tn, tp)						\
594 	NETGRAPH_INIT_ORDERED(tn, tp, SI_SUB_PSEUDO, SI_ORDER_ANY)
595 
596 /* Special malloc() type for netgraph structs and ctrl messages */
597 /* Only these two types should be visible to nodes */
598 MALLOC_DECLARE(M_NETGRAPH);
599 MALLOC_DECLARE(M_NETGRAPH_MSG);
600 MALLOC_DECLARE(M_NETGRAPH_META);
601 
602 
603 
604 /* Methods that should go away (or become private)*/
605 /* Methods that should exist */
606 int	ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr);
607 int	ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr);
608 int	ng_address_path(node_p here, item_p item,
609 	char *address, ng_ID_t retaddr);
610 meta_p	ng_copy_meta(meta_p meta);
611 hook_p	ng_findhook(node_p node, const char *name);
612 void	ng_free_item(item_p item);
613 int	ng_make_node_common(struct ng_type *typep, node_p *nodep);
614 int	ng_mod_event(module_t mod, int what, void *arg);
615 int	ng_name_node(node_p node, const char *name);
616 int	ng_newtype(struct ng_type *tp);
617 ng_ID_t ng_node2ID(node_p node);
618 item_p	ng_package_data(struct mbuf *m, meta_p meta);
619 item_p	ng_package_msg(struct ng_mesg *msg);
620 item_p	ng_package_msg_self(node_p here, hook_p hook, struct ng_mesg *msg);
621 void	ng_replace_retaddr(node_p here, item_p item, ng_ID_t retaddr);
622 int	ng_rmnode_self(node_p here);
623 int	ng_snd_item(item_p item, int queue);
624 void	ng_unname(node_p node);
625 void	ng_unref(node_p node);
626 
627 #endif /* _NETGRAPH_NETGRAPH_H_ */
628 
629