FreeBSD/sys/netgraph/ng_ksocket.c
/*
 * Receive incoming data on our hook.  Send it out the socket.
 */
Receive incoming data on our hook.  Send it out the socket.
Receive incoming data on our hook . Send it out the socket .
static int
ng_ksocket_rcvdata(hook_p hook, item_p item)
{
	struct thread *td = curthread;	
	const node_p node = NG_HOOK_NODE(hook);
	const priv_p priv = NG_NODE_PRIVATE(node);
	struct socket *const so = priv->so;
	struct sockaddr *sa = NULL;
	int error;
	struct mbuf *m;
#ifdef ALIGNED_POINTER
	struct mbuf *n;
#endif 
	struct sa_tag *stag;
	NGI_GET_M(item, m);
	NG_FREE_ITEM(item);
#ifdef ALIGNED_POINTER
	if (!ALIGNED_POINTER(mtod(m, caddr_t), uint32_t)) {
		n = m_defrag(m, M_NOWAIT);
		if (n == NULL) {
			m_freem(m);
			return (ENOBUFS);
		}
		m = n;
	}
#endif 
	if (((stag = (struct sa_tag *)m_tag_locate(m, NGM_KSOCKET_COOKIE,
	    NG_KSOCKET_TAG_SOCKADDR, NULL)) != NULL) &&
	    (stag->id == NG_NODE_ID(node) || stag->id == 0))
		sa = &stag->sa;
	m->m_flags &= ~(M_BCAST|M_MCAST);
	error = sosend(so, sa, 0, m, 0, 0, td);
	return (error);
}
static int ng_ksocket_rcvdata ( hook_p hook , item_p item ) { struct thread * td = curthread ; const node_p node = NG_HOOK_NODE ( hook ) ; const priv_p priv = NG_NODE_PRIVATE ( node ) ; struct socket * const so = priv -> so ; struct sockaddr * sa = NULL ; int error ; struct mbuf * m ; #ifdef ALIGNED_POINTER struct mbuf * n ; #endif struct sa_tag * stag ; NGI_GET_M ( item , m ) ; NG_FREE_ITEM ( item ) ; #ifdef ALIGNED_POINTER if ( ! ALIGNED_POINTER ( mtod ( m , caddr_t ) , uint32_t ) ) { n = m_defrag ( m , M_NOWAIT ) ; if ( n == NULL ) { m_freem ( m ) ; return ( ENOBUFS ) ; } m = n ; } #endif if ( ( ( stag = ( struct sa_tag * ) m_tag_locate ( m , NGM_KSOCKET_COOKIE , NG_KSOCKET_TAG_SOCKADDR , NULL ) ) != NULL ) && ( stag -> id == NG_NODE_ID ( node ) || stag -> id == 0 ) ) sa = & stag -> sa ; m -> m_flags &= ~ ( M_BCAST | M_MCAST ) ; error = sosend ( so , sa , 0 , m , 0 , 0 , td ) ; return ( error ) ; }
Receive incoming data on our hook.
Receive incoming data on our hook .
/* XXX broken */ /* ALIGNED_POINTER */ /* Extract data */ /* ALIGNED_POINTER */ /*
	 * Look if socket address is stored in packet tags.
	 * If sockaddr is ours, or provided by a third party (zero id),
	 * then we accept it.
	 */ /* Reset specific mbuf flags to prevent addressing problems. */ /* Send packet */