FreeBSD/sys/kern/uipc_domain.c
/*
 * The caller must make sure the protocol and its functions correctly shut down
 * all sockets and release all locks and memory references.
 */
The caller must make sure the protocol and its functions correctly shut down
all sockets and release all locks and memory references.
The caller must make sure the protocol and its functions correctly shut down all sockets and release all locks and memory references .
int
pf_proto_unregister(int family, int protocol, int type)
{
	struct domain *dp;
	struct protosw *pr, *dpr;
	if (family == 0)
		return (EPFNOSUPPORT);
	if (protocol == 0)
		return (EPROTONOSUPPORT);
	if (type == 0)
		return (EPROTOTYPE);
	dp = pffinddomain(family);
	if (dp == NULL)
		return (EPFNOSUPPORT);
	dpr = NULL;
	mtx_lock(&dom_mtx);
	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
		if ((pr->pr_type == type) && (pr->pr_protocol == protocol)) {
			if (dpr != NULL) {
				mtx_unlock(&dom_mtx);
				return (EMLINK);   
			} else
				dpr = pr;
		}
	}
	if (dpr == NULL) {
		mtx_unlock(&dom_mtx);
		return (EPROTONOSUPPORT);
	}
	dpr->pr_type = 0;
	dpr->pr_domain = dp;
	dpr->pr_protocol = PROTO_SPACER;
	dpr->pr_flags = 0;
	dpr->pr_input = NULL;
	dpr->pr_output = NULL;
	dpr->pr_ctlinput = NULL;
	dpr->pr_ctloutput = NULL;
	dpr->pr_init = NULL;
	dpr->pr_fasttimo = NULL;
	dpr->pr_slowtimo = NULL;
	dpr->pr_drain = NULL;
	dpr->pr_usrreqs = &nousrreqs;
	mtx_unlock(&dom_mtx);
	return (0);
}
int pf_proto_unregister ( int family , int protocol , int type ) { struct domain * dp ; struct protosw * pr , * dpr ; if ( family == 0 ) return ( EPFNOSUPPORT ) ; if ( protocol == 0 ) return ( EPROTONOSUPPORT ) ; if ( type == 0 ) return ( EPROTOTYPE ) ; dp = pffinddomain ( family ) ; if ( dp == NULL ) return ( EPFNOSUPPORT ) ; dpr = NULL ; mtx_lock ( & dom_mtx ) ; for ( pr = dp -> dom_protosw ; pr < dp -> dom_protoswNPROTOSW ; pr ++ ) { if ( ( pr -> pr_type == type ) && ( pr -> pr_protocol == protocol ) ) { if ( dpr != NULL ) { mtx_unlock ( & dom_mtx ) ; return ( EMLINK ) ; } else dpr = pr ; } } if ( dpr == NULL ) { mtx_unlock ( & dom_mtx ) ; return ( EPROTONOSUPPORT ) ; } dpr -> pr_type = 0 ; dpr -> pr_domain = dp ; dpr -> pr_protocol = PROTO_SPACER ; dpr -> pr_flags = 0 ; dpr -> pr_input = NULL ; dpr -> pr_output = NULL ; dpr -> pr_ctlinput = NULL ; dpr -> pr_ctloutput = NULL ; dpr -> pr_init = NULL ; dpr -> pr_fasttimo = NULL ; dpr -> pr_slowtimo = NULL ; dpr -> pr_drain = NULL ; dpr -> pr_usrreqs = & nousrreqs ; mtx_unlock ( & dom_mtx ) ; return ( 0 ) ; }
The caller must make sure the protocol and its functions correctly shut down
 all sockets and release all locks and memory references.
The caller must make sure the protocol and its functions correctly shut down all sockets and release all locks and memory references .
/* Sanity checks. */ /* Try to find the specified domain based on the family type. */ /* Lock out everyone else while we are manipulating the protosw. */ /* The protocol must exist and only once. */ /* Should not happen! */ /* Protocol does not exist. */ /* De-orbit the protocol and make the slot available again. */ /* Job is done, not more protection required. */