FreeBSD/sys/netinet6/in6_mcast.c
/*
 * Return a pointer to an in6_msource owned by an in6_mfilter,
 * given its source address.
 * Lazy-allocate if needed. If this is a new entry its filter state is
 * undefined at t0.
 *
 * imf is the filter set being modified.
 * addr is the source address.
 *
 * SMPng: May be called with locks held; malloc must not block.
 */
Return a pointer to an in6_msource owned by an in6_mfilter,
given its source address.
Lazy-allocate if needed. If this is a new entry its filter state is
undefined at t0.

imf is the filter set being modified.
addr is the source address.

May be called with locks held; malloc must not block.
Return a pointer to an in6_msource owned by an in6_mfilter given its source address . Lazy - allocate if needed . If this is a new entry its filter state is undefined at t0 . imf is the filter set being modified . addr is the source address . May be called with locks held ; malloc must not block .
static int
im6f_get_source(struct in6_mfilter *imf, const struct sockaddr_in6 *psin,
    struct in6_msource **plims)
{
	struct ip6_msource	 find;
	struct ip6_msource	*ims, *nims;
	struct in6_msource	*lims;
	int			 error;
	error = 0;
	ims = NULL;
	lims = NULL;
	find.im6s_addr = psin->sin6_addr;
	ims = RB_FIND(ip6_msource_tree, &imf->im6f_sources, &find);
	lims = (struct in6_msource *)ims;
	if (lims == NULL) {
		if (imf->im6f_nsrc == in6_mcast_maxsocksrc)
			return (ENOSPC);
		nims = malloc(sizeof(struct in6_msource), M_IN6MFILTER,
		    M_NOWAIT | M_ZERO);
		if (nims == NULL)
			return (ENOMEM);
		lims = (struct in6_msource *)nims;
		lims->im6s_addr = find.im6s_addr;
		lims->im6sl_st[0] = MCAST_UNDEFINED;
		RB_INSERT(ip6_msource_tree, &imf->im6f_sources, nims);
		++imf->im6f_nsrc;
	}
	*plims = lims;
	return (error);
}
static int im6f_get_source ( struct in6_mfilter * imf , const struct sockaddr_in6 * psin , struct in6_msource * * plims ) { struct ip6_msource find ; struct ip6_msource * ims , * nims ; struct in6_msource * lims ; int error ; error = 0 ; ims = NULL ; lims = NULL ; find . im6s_addr = psin -> sin6_addr ; ims = RB_FIND ( ip6_msource_tree , & imf -> im6f_sources , & find ) ; lims = ( struct in6_msource * ) ims ; if ( lims == NULL ) { if ( imf -> im6f_nsrc == in6_mcast_maxsocksrc ) return ( ENOSPC ) ; nims = malloc ( sizeof ( struct in6_msource ) , M_IN6MFILTER , M_NOWAIT | M_ZERO ) ; if ( nims == NULL ) return ( ENOMEM ) ; lims = ( struct in6_msource * ) nims ; lims -> im6s_addr = find . im6s_addr ; lims -> im6sl_st [ 0 ] = MCAST_UNDEFINED ; RB_INSERT ( ip6_msource_tree , & imf -> im6f_sources , nims ) ; ++ imf -> im6f_nsrc ; } * plims = lims ; return ( error ) ; }
Return a pointer to an in6_msource owned by an in6_mfilter,
 given its source address.
Return a pointer to an in6_msource owned by an in6_mfilter given its source address .