FreeBSD/sys/net/if_clone.c
/*
 * Provide list of interface cloners to userspace.
 */
Provide list of interface cloners to userspace.
Provide list of interface cloners to userspace .
int
if_clone_list(struct if_clonereq *ifcr)
{
	char *buf, *dst, *outbuf = NULL;
	struct if_clone *ifc;
	int buf_count, count, err = 0;
	if (ifcr->ifcr_count < 0)
		return (EINVAL);
	IF_CLONERS_LOCK();
	buf_count = (V_if_cloners_count < ifcr->ifcr_count) ?
	    V_if_cloners_count : ifcr->ifcr_count;
	IF_CLONERS_UNLOCK();
	outbuf = malloc(IFNAMSIZ*buf_count, M_CLONE, M_WAITOK | M_ZERO);
	IF_CLONERS_LOCK();
	ifcr->ifcr_total = V_if_cloners_count;
	if ((dst = ifcr->ifcr_buffer) == NULL) {
		goto done;
	}
	count = (V_if_cloners_count < buf_count) ?
	    V_if_cloners_count : buf_count;
	for (ifc = LIST_FIRST(&V_if_cloners), buf = outbuf;
	    ifc != NULL && count != 0;
	    ifc = LIST_NEXT(ifc, ifc_list), count--, buf += IFNAMSIZ) {
		strlcpy(buf, ifc->ifc_name, IFNAMSIZ);
	}
done:
	IF_CLONERS_UNLOCK();
	if (err == 0)
		err = copyout(outbuf, dst, buf_count*IFNAMSIZ);
	if (outbuf != NULL)
		free(outbuf, M_CLONE);
	return (err);
}
int if_clone_list ( struct if_clonereq * ifcr ) { char * buf , * dst , * outbuf = NULL ; struct if_clone * ifc ; int buf_count , count , err = 0 ; if ( ifcr -> ifcr_count < 0 ) return ( EINVAL ) ; IF_CLONERS_LOCK ( ) ; buf_count = ( V_if_cloners_count < ifcr -> ifcr_count ) ? V_if_cloners_count : ifcr -> ifcr_count ; IF_CLONERS_UNLOCK ( ) ; outbuf = malloc ( IFNAMSIZ * buf_count , M_CLONE , M_WAITOK | M_ZERO ) ; IF_CLONERS_LOCK ( ) ; ifcr -> ifcr_total = V_if_cloners_count ; if ( ( dst = ifcr -> ifcr_buffer ) == NULL ) { goto done ; } count = ( V_if_cloners_count < buf_count ) ? V_if_cloners_count : buf_count ; for ( ifc = LIST_FIRST ( & V_if_cloners ) , buf = outbuf ; ifc != NULL && count != 0 ; ifc = LIST_NEXT ( ifc , ifc_list ) , count -- , buf += IFNAMSIZ ) { strlcpy ( buf , ifc -> ifc_name , IFNAMSIZ ) ; } done : IF_CLONERS_UNLOCK ( ) ; if ( err == 0 ) err = copyout ( outbuf , dst , buf_count * IFNAMSIZ ) ; if ( outbuf != NULL ) free ( outbuf , M_CLONE ) ; return ( err ) ; }
Provide list of interface cloners to userspace.
Provide list of interface cloners to userspace .
/*
	 * Set our internal output buffer size.  We could end up not
	 * reporting a cloner that is added between the unlock and lock
	 * below, but that's not a major problem.  Not caping our
	 * allocation to the number of cloners actually in the system
	 * could be because that would let arbitrary users cause us to
	 * allocate arbitrary amounts of kernel memory.
	 */ /* Just asking how many there are. */