FreeBSD/sys/net/if_tap.c
/*
 * DEVFS handler
 *
 * We need to support two kind of devices - tap and vmnet
 */
DEVFS handler
We need to support two kind of devices - tap and vmnet
DEVFS handler We need to support two kind of devices - tap and vmnet
static void
tapclone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **dev)
{
	char		devname[SPECNAMELEN + 1];
	int		i, unit, append_unit;
	int		extra;
	if (*dev != NULL)
		return;
	if (!tapdclone ||
	    (!tapuopen && priv_check_cred(cred, PRIV_NET_IFCREATE, 0) != 0))
		return;
	unit = 0;
	append_unit = 0;
	extra = 0;
	if (strcmp(name, tapname) == 0) {
		unit = -1;
	} else if (strcmp(name, vmnetname) == 0) {
		unit = -1;
		extra = VMNET_DEV_MASK;
	} else if (dev_stdclone(name, NULL, tapname, &unit) != 1) {
		if (dev_stdclone(name, NULL, vmnetname, &unit) != 1) {
			return;
		} else {
			extra = VMNET_DEV_MASK;
		}
	}
	if (unit == -1)
		append_unit = 1;
	CURVNET_SET(CRED_TO_VNET(cred));
	i = clone_create(&tapclones, &tap_cdevsw, &unit, dev, extra);
	if (i) {
		if (append_unit) {
			namelen = snprintf(devname, sizeof(devname), "%s%d", name,
			    unit);
			name = devname;
		}
		*dev = make_dev_credf(MAKEDEV_REF, &tap_cdevsw, unit | extra,
		     cred, UID_ROOT, GID_WHEEL, 0600, "%s", name);
	}
	if_clone_create(name, namelen, NULL);
	CURVNET_RESTORE();
}
static void tapclone ( void * arg , struct ucred * cred , char * name , int namelen , struct cdev * * dev ) { char devname [ SPECNAMELEN + 1 ] ; int i , unit , append_unit ; int extra ; if ( * dev != NULL ) return ; if ( ! tapdclone || ( ! tapuopen && priv_check_cred ( cred , PRIV_NET_IFCREATE , 0 ) != 0 ) ) return ; unit = 0 ; append_unit = 0 ; extra = 0 ; if ( strcmp ( name , tapname ) == 0 ) { unit = -1 ; } else if ( strcmp ( name , vmnetname ) == 0 ) { unit = -1 ; extra = VMNET_DEV_MASK ; } else if ( dev_stdclone ( name , NULL , tapname , & unit ) != 1 ) { if ( dev_stdclone ( name , NULL , vmnetname , & unit ) != 1 ) { return ; } else { extra = VMNET_DEV_MASK ; } } if ( unit == -1 ) append_unit = 1 ; CURVNET_SET ( CRED_TO_VNET ( cred ) ) ; i = clone_create ( & tapclones , & tap_cdevsw , & unit , dev , extra ) ; if ( i ) { if ( append_unit ) { namelen = snprintf ( devname , sizeof ( devname ) , " " , name , unit ) ; name = devname ; } * dev = make_dev_credf ( MAKEDEV_REF , & tap_cdevsw , unit | extra , cred , UID_ROOT , GID_WHEEL , 0600 , " " , name ) ; } if_clone_create ( name , namelen , NULL ) ; CURVNET_RESTORE ( ) ; }
DEVFS handler
 We need to support two kind of devices - tap and vmnet
DEVFS handler We need to support two kind of devices - tap and vmnet
/* We're interested in only tap/vmnet devices. */ /* find any existing device, or allocate new unit number */ /*
			 * We were passed 'tun' or 'tap', with no unit specified
			 * so we'll need to append it now.
			 */