FreeBSD/sys/netinet/in_mcast.c
/*
 * Look up a source filter entry for a multicast group.
 *
 * inm is the group descriptor to work with.
 * haddr is the host-byte-order IPv4 address to look up.
 * noalloc may be non-zero to suppress allocation of sources.
 * *pims will be set to the address of the retrieved or allocated source.
 *
 * SMPng: NOTE: may be called with locks held.
 * Return 0 if successful, otherwise return a non-zero error code.
 */
Look up a source filter entry for a multicast group.
inm is the group descriptor to work with.
haddr is the host-byte-order IPv4 address to look up.
noalloc may be non-zero to suppress allocation of sources.
*pims will be set to the address of the retrieved or allocated source.

may be called with locks held.
Return 0 if successful, otherwise return a non-zero error code.
Look up a source filter entry for a multicast group . inm is the group descriptor to work with . haddr is the host - byte - order IPv4 address to look up . noalloc may be non - zero to suppress allocation of sources . * pims will be set to the address of the retrieved or allocated source . may be called with locks held . Return 0 if successful otherwise return a non - zero error code .
static int
inm_get_source(struct in_multi *inm, const in_addr_t haddr,
    const int noalloc, struct ip_msource **pims)
{
	struct ip_msource	 find;
	struct ip_msource	*ims, *nims;
#ifdef KTR
	struct in_addr ia;
#endif
	find.ims_haddr = haddr;
	ims = RB_FIND(ip_msource_tree, &inm->inm_srcs, &find);
	if (ims == NULL && !noalloc) {
		if (inm->inm_nsrc == in_mcast_maxgrpsrc)
			return (ENOSPC);
		nims = malloc(sizeof(struct ip_msource), M_IPMSOURCE,
		    M_NOWAIT | M_ZERO);
		if (nims == NULL)
			return (ENOMEM);
		nims->ims_haddr = haddr;
		RB_INSERT(ip_msource_tree, &inm->inm_srcs, nims);
		++inm->inm_nsrc;
		ims = nims;
#ifdef KTR
		ia.s_addr = htonl(haddr);
		CTR3(KTR_IGMPV3, "%s: allocated %s as %p", __func__,
		    inet_ntoa(ia), ims);
#endif
	}
	*pims = ims;
	return (0);
}
static int inm_get_source ( struct in_multi * inm , const in_addr_t haddr , const int noalloc , struct ip_msource * * pims ) { struct ip_msource find ; struct ip_msource * ims , * nims ; #ifdef KTR struct in_addr ia ; #endif find . ims_haddr = haddr ; ims = RB_FIND ( ip_msource_tree , & inm -> inm_srcs , & find ) ; if ( ims == NULL && ! noalloc ) { if ( inm -> inm_nsrc == in_mcast_maxgrpsrc ) return ( ENOSPC ) ; nims = malloc ( sizeof ( struct ip_msource ) , M_IPMSOURCE , M_NOWAIT | M_ZERO ) ; if ( nims == NULL ) return ( ENOMEM ) ; nims -> ims_haddr = haddr ; RB_INSERT ( ip_msource_tree , & inm -> inm_srcs , nims ) ; ++ inm -> inm_nsrc ; ims = nims ; #ifdef KTR ia . s_addr = htonl ( haddr ) ; CTR3 ( KTR_IGMPV3 , " " , __func__ , inet_ntoa ( ia ) , ims ) ; #endif } * pims = ims ; return ( 0 ) ; }
Look up a source filter entry for a multicast group.
Look up a source filter entry for a multicast group .