FreeBSD/sys/dev/netmap/netmap_freebsd.c
/*
 * Implementation of a netmap-capable virtual interface that
 * registered to the system.
 * It is based on if_tap.c and ip_fw_log.c in FreeBSD 9.
 *
 * Note: Linux sets refcount to 0 on allocation of net_device,
 * then increments it on registration to the system.
 * FreeBSD sets refcount to 1 on if_alloc(), and does not
 * increment this refcount on if_attach().
 */
Implementation of a netmap-capable virtual interface that
registered to the system.
It is based on if_tap.c and ip_fw_log.c in FreeBSD 9.

Linux sets refcount to 0 on allocation of net_device,
then increments it on registration to the system.
FreeBSD sets refcount to 1 on if_alloc(), and does not
increment this refcount on if_attach().
Implementation of a netmap - capable virtual interface that registered to the system . It is based on if_tap . c and ip_fw_log . c in FreeBSD 9 . Linux sets refcount to 0 on allocation of net_device then increments it on registration to the system . FreeBSD sets refcount to 1 on if_alloc () and does not increment this refcount on if_attach () .
int
nm_vi_persist(const char *name, struct ifnet **ret)
{
	struct ifnet *ifp;
	u_short macaddr_hi;
	uint32_t macaddr_mid;
	u_char eaddr[6];
	int unit = nm_vi_get_index(); 
	if (unit < 0)
		return EBUSY;
	macaddr_hi = htons(0x00be); 
	macaddr_mid = (uint32_t) ticks;
	bcopy(&macaddr_hi, eaddr, sizeof(short));
	bcopy(&macaddr_mid, &eaddr[2], sizeof(uint32_t));
	eaddr[5] = (uint8_t)unit;
	ifp = if_alloc(IFT_ETHER);
	if (ifp == NULL) {
		D("if_alloc failed");
		return ENOMEM;
	}
	if_initname(ifp, name, IF_DUNIT_NONE);
	ifp->if_mtu = 65536;
	ifp->if_flags = IFF_UP | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_init = (void *)nm_vi_dummy;
	ifp->if_ioctl = nm_vi_dummy;
	ifp->if_start = nm_vi_start;
	ifp->if_mtu = ETHERMTU;
	IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
	ifp->if_capabilities |= IFCAP_LINKSTATE;
	ifp->if_capenable |= IFCAP_LINKSTATE;
	ether_ifattach(ifp, eaddr);
	*ret = ifp;
	return 0;
}
int nm_vi_persist ( const char * name , struct ifnet * * ret ) { struct ifnet * ifp ; u_short macaddr_hi ; uint32_t macaddr_mid ; u_char eaddr [ 6 ] ; int unit = nm_vi_get_index ( ) ; if ( unit < 0 ) return EBUSY ; macaddr_hi = htons ( 0x00be ) ; macaddr_mid = ( uint32_t ) ticks ; bcopy ( & macaddr_hi , eaddr , sizeof ( short ) ) ; bcopy ( & macaddr_mid , & eaddr [ 2 ] , sizeof ( uint32_t ) ) ; eaddr [ 5 ] = ( uint8_t ) unit ; ifp = if_alloc ( IFT_ETHER ) ; if ( ifp == NULL ) { D ( " " ) ; return ENOMEM ; } if_initname ( ifp , name , IF_DUNIT_NONE ) ; ifp -> if_mtu = 65536 ; ifp -> if_flags = IFF_UP | IFF_SIMPLEX | IFF_MULTICAST ; ifp -> if_init = ( void * ) nm_vi_dummy ; ifp -> if_ioctl = nm_vi_dummy ; ifp -> if_start = nm_vi_start ; ifp -> if_mtu = ETHERMTU ; IFQ_SET_MAXLEN ( & ifp -> if_snd , ifqmaxlen ) ; ifp -> if_capabilities |= IFCAP_LINKSTATE ; ifp -> if_capenable |= IFCAP_LINKSTATE ; ether_ifattach ( ifp , eaddr ) ; * ret = ifp ; return 0 ; }
Implementation of a netmap-capable virtual interface that
 registered to the system.
Implementation of a netmap - capable virtual interface that registered to the system .
/* just to decide MAC address */ /*
	 * We use the same MAC address generation method with tap
	 * except for the highest octet is 00:be instead of 00:bd
	 */ /* XXX tap + 1 */