FreeBSD/sys/netgraph/ng_ksocket.c
/*
 * You should not "just call" a netgraph node function from an external
 * asynchronous event. This is because in doing so you are ignoring the
 * locking on the netgraph nodes. Instead call your function via ng_send_fn().
 * This will call the function you chose, but will first do all the
 * locking rigmarole. Your function MAY only be called at some distant future
 * time (several millisecs away) so don't give it any arguments
 * that may be revoked soon (e.g. on your stack).
 *
 * To decouple stack, we use queue version of ng_send_fn().
 */
You should not "just call" a netgraph node function from an external
asynchronous event. This is because in doing so you are ignoring the
locking on the netgraph nodes. Instead call your function via ng_send_fn().
This will call the function you chose, but will first do all the
locking rigmarole. Your function MAY only be called at some distant future
time (several millisecs away) so don't give it any arguments
that may be revoked soon .

To decouple stack, we use queue version of ng_send_fn().
You should not " just call " a netgraph node function from an external asynchronous event . This is because in doing so you are ignoring the locking on the netgraph nodes . Instead call your function via ng_send_fn () . This will call the function you chose but will first do all the locking rigmarole . Your function MAY only be called at some distant future time ( several millisecs away ) so don ' t give it any arguments that may be revoked soon . To decouple stack we use queue version of ng_send_fn () .
static int
ng_ksocket_incoming(struct socket *so, void *arg, int waitflag)
{
	const node_p node = arg;
	const priv_p priv = NG_NODE_PRIVATE(node);
	int wait = ((waitflag & M_WAITOK) ? NG_WAITOK : 0) | NG_QUEUE;
	if (atomic_cmpset_int(&priv->fn_sent, 0, 1) &&
	    ng_send_fn1(node, NULL, &ng_ksocket_incoming2, so, 0, wait)) {
		atomic_store_rel_int(&priv->fn_sent, 0);
	}
	return (SU_OK);
}
static int ng_ksocket_incoming ( struct socket * so , void * arg , int waitflag ) { const node_p node = arg ; const priv_p priv = NG_NODE_PRIVATE ( node ) ; int wait = ( ( waitflag & M_WAITOK ) ? NG_WAITOK : 0 ) | NG_QUEUE ; if ( atomic_cmpset_int ( & priv -> fn_sent , 0 , 1 ) && ng_send_fn1 ( node , NULL , & ng_ksocket_incoming2 , so , 0 , wait ) ) { atomic_store_rel_int ( & priv -> fn_sent , 0 ) ; } return ( SU_OK ) ; }
You should not "just call" a netgraph node function from an external
 asynchronous event.
You should not " just call " a netgraph node function from an external asynchronous event .
/*
	 * Even if node is not locked, as soon as we are called, we assume
	 * it exist and it's private area is valid. With some care we can
	 * access it. Mark node that incoming event for it was sent to
	 * avoid unneded queue trashing.
	 */