FreeBSD/sys/netgraph/ng_ksocket.c
/*
 * Give our OK for a hook to be added. The hook name is of the
 * form "<family>/<type>/<proto>" where the three components may
 * be decimal numbers or else aliases from the above lists.
 *
 * Connecting a hook amounts to opening the socket.  Disconnecting
 * the hook closes the socket and destroys the node as well.
 */
Give our OK for a hook to be added. The hook name is of the
form "//" where the three components may
be decimal numbers or else aliases from the above lists.

Connecting a hook amounts to opening the socket.  Disconnecting
the hook closes the socket and destroys the node as well.
Give our OK for a hook to be added . The hook name is of the form " // " where the three components may be decimal numbers or else aliases from the above lists . Connecting a hook amounts to opening the socket . Disconnecting the hook closes the socket and destroys the node as well .
static int
ng_ksocket_newhook(node_p node, hook_p hook, const char *name0)
{
	struct thread *td = curthread;	
	const priv_p priv = NG_NODE_PRIVATE(node);
	char *s1, *s2, name[NG_HOOKSIZ];
	int family, type, protocol, error;
	if (priv->hook != NULL)
		return (EISCONN);
	if (priv->flags & KSF_CLONED) {
		if (priv->flags & KSF_EMBRYONIC) {
			LIST_REMOVE(priv, siblings);
			priv->flags &= ~KSF_EMBRYONIC;
		}
	} else {
		snprintf(name, sizeof(name), "%s", name0);
		s1 = name;
		if ((s2 = strchr(s1, '/')) == NULL)
			return (EINVAL);
		*s2++ = '\0';
		family = ng_ksocket_parse(ng_ksocket_families, s1, 0);
		if (family == -1)
			return (EINVAL);
		s1 = s2;
		if ((s2 = strchr(s1, '/')) == NULL)
			return (EINVAL);
		*s2++ = '\0';
		type = ng_ksocket_parse(ng_ksocket_types, s1, 0);
		if (type == -1)
			return (EINVAL);
		s1 = s2;
		protocol = ng_ksocket_parse(ng_ksocket_protos, s1, family);
		if (protocol == -1)
			return (EINVAL);
		error = socreate(family, &priv->so, type, protocol,
		   td->td_ucred, td);
		if (error != 0)
			return (error);
	}
	priv->hook = hook;
	NG_HOOK_FORCE_QUEUE(hook);
	return(0);
}
static int ng_ksocket_newhook ( node_p node , hook_p hook , const char * name0 ) { struct thread * td = curthread ; const priv_p priv = NG_NODE_PRIVATE ( node ) ; char * s1 , * s2 , name [ NG_HOOKSIZ ] ; int family , type , protocol , error ; if ( priv -> hook != NULL ) return ( EISCONN ) ; if ( priv -> flags & KSF_CLONED ) { if ( priv -> flags & KSF_EMBRYONIC ) { LIST_REMOVE ( priv , siblings ) ; priv -> flags &= ~ KSF_EMBRYONIC ; } } else { snprintf ( name , sizeof ( name ) , " " , name0 ) ; s1 = name ; if ( ( s2 = strchr ( s1 , ' ' ) ) == NULL ) return ( EINVAL ) ; * s2 ++ = ' \0 ' ; family = ng_ksocket_parse ( ng_ksocket_families , s1 , 0 ) ; if ( family == -1 ) return ( EINVAL ) ; s1 = s2 ; if ( ( s2 = strchr ( s1 , ' ' ) ) == NULL ) return ( EINVAL ) ; * s2 ++ = ' \0 ' ; type = ng_ksocket_parse ( ng_ksocket_types , s1 , 0 ) ; if ( type == -1 ) return ( EINVAL ) ; s1 = s2 ; protocol = ng_ksocket_parse ( ng_ksocket_protos , s1 , family ) ; if ( protocol == -1 ) return ( EINVAL ) ; error = socreate ( family , & priv -> so , type , protocol , td -> td_ucred , td ) ; if ( error != 0 ) return ( error ) ; } priv -> hook = hook ; NG_HOOK_FORCE_QUEUE ( hook ) ; return ( 0 ) ; }
Give our OK for a hook to be added.
Give our OK for a hook to be added .
/* XXX broken */ /* Check if we're already connected */ /* Remove ourselves from our parent's embryo list */ /* Extract family, type, and protocol from hook name */ /* Create the socket */ /* XXX call soreserve() ? */ /* OK */ /*
	 * In case of misconfigured routing a packet may reenter
	 * ksocket node recursively. Decouple stack to avoid possible
	 * panics about sleeping with locks held.
	 */