sys/net/if_clone.c
void
if_clone_attach(struct if_clone *ifc)
{
	int bytoff, bitoff;
	int err;
	int len, maxclone;
	int unit;

	KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit,
	    ("%s: %s requested more units then allowed (%d > %d)",
	    __func__, ifc->ifc_name, ifc->ifc_minifs,
	    ifc->ifc_maxunit + 1));
	/*
	 * Compute bitmap size and allocate it.
	 */
	maxclone = ifc->ifc_maxunit + 1;
	len = maxclone >> 3;
	if ((len << 3) < maxclone)
		len++;
	ifc->ifc_units = kmalloc(len, M_CLONE, M_WAITOK | M_ZERO);
	ifc->ifc_bmlen = len;

	LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
	if_cloners_count++;

	for (unit = 0; unit < ifc->ifc_minifs; unit++) {
		err = (*ifc->ifc_create)(ifc, unit, NULL);
		KASSERT(err == 0,
		    ("%s: failed to create required interface %s%d",
		    __func__, ifc->ifc_name, unit));

		/* Allocate the unit in the bitmap. */
		bytoff = unit >> 3;
		bitoff = unit - (bytoff << 3);
		ifc->ifc_units[bytoff] |= (1 << bitoff);
	}
}
/*
 * Register a network interface cloner.
 */
Register a network interface cloner.
Register a network interface cloner .
void
if_clone_attach(struct if_clone *ifc)
{
	int bytoff, bitoff;
	int err;
	int len, maxclone;
	int unit;
	KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit,
	    ("%s: %s requested more units then allowed (%d > %d)",
	    __func__, ifc->ifc_name, ifc->ifc_minifs,
	    ifc->ifc_maxunit + 1));
	maxclone = ifc->ifc_maxunit + 1;
	len = maxclone >> 3;
	if ((len << 3) < maxclone)
		len++;
	ifc->ifc_units = kmalloc(len, M_CLONE, M_WAITOK | M_ZERO);
	ifc->ifc_bmlen = len;
	LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
	if_cloners_count++;
	for (unit = 0; unit < ifc->ifc_minifs; unit++) {
		err = (*ifc->ifc_create)(ifc, unit, NULL);
		KASSERT(err == 0,
		    ("%s: failed to create required interface %s%d",
		    __func__, ifc->ifc_name, unit));
		bytoff = unit >> 3;
		bitoff = unit - (bytoff << 3);
		ifc->ifc_units[bytoff] |= (1 << bitoff);
	}
}
void if_clone_attach ( struct if_clone * ifc ) { int bytoff , bitoff ; int err ; int len , maxclone ; int unit ; KASSERT ( ifc -> ifc_minifs - 1 <= ifc -> ifc_maxunit , ( " " , __func__ , ifc -> ifc_name , ifc -> ifc_minifs , ifc -> ifc_maxunit + 1 ) ) ; maxclone = ifc -> ifc_maxunit + 1 ; len = maxclone >> 3 ; if ( ( len << 3 ) < maxclone ) len ++ ; ifc -> ifc_units = kmalloc ( len , M_CLONE , M_WAITOK | M_ZERO ) ; ifc -> ifc_bmlen = len ; LIST_INSERT_HEAD ( & if_cloners , ifc , ifc_list ) ; if_cloners_count ++ ; for ( unit = 0 ; unit < ifc -> ifc_minifs ; unit ++ ) { err = ( * ifc -> ifc_create ) ( ifc , unit , NULL ) ; KASSERT ( err == 0 , ( " " , __func__ , ifc -> ifc_name , unit ) ) ; bytoff = unit >> 3 ; bitoff = unit - ( bytoff << 3 ) ; ifc -> ifc_units [ bytoff ] |= ( 1 << bitoff ) ; } }
Register a network interface cloner.
Register a network interface cloner .
/*
	 * Compute bitmap size and allocate it.
	 */ /* Allocate the unit in the bitmap. */