- int err = 0;
- domid_t domid = create->domid;
- unsigned int handle = create->netif_handle;
- struct net_device *dev;
- netif_t **pnetif, *netif;
- char name[IFNAMSIZ] = {};
-
- snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
- dev = alloc_netdev(sizeof(netif_t), name, ether_setup);
- if ( dev == NULL )
- {
- DPRINTK("Could not create netif: out of memory\n");
- create->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
- return;
- }
-
- netif = netdev_priv(dev);
- memset(netif, 0, sizeof(*netif));
- netif->domid = domid;
- netif->handle = handle;
- netif->status = DISCONNECTED;
- atomic_set(&netif->refcnt, 0);
- netif->dev = dev;
-
- netif->credit_bytes = netif->remaining_credit = ~0UL;
- netif->credit_usec = 0UL;
- init_timer(&netif->credit_timeout);
-
- pnetif = &netif_hash[NETIF_HASH(domid, handle)];
- while ( *pnetif != NULL )
- {
- if ( ((*pnetif)->domid == domid) && ((*pnetif)->handle == handle) )
- {
- DPRINTK("Could not create netif: already exists\n");
- create->status = NETIF_BE_STATUS_INTERFACE_EXISTS;
- free_netdev(dev);
- return;
- }
- pnetif = &(*pnetif)->hash_next;
- }
-
- dev->hard_start_xmit = netif_be_start_xmit;
- dev->get_stats = netif_be_get_stats;
- dev->open = net_open;
- dev->stop = net_close;
-
- /* Disable queuing. */
- dev->tx_queue_len = 0;
-
- if ( (create->be_mac[0] == 0) && (create->be_mac[1] == 0) &&
- (create->be_mac[2] == 0) && (create->be_mac[3] == 0) &&
- (create->be_mac[4] == 0) && (create->be_mac[5] == 0) )
- {
- /*
- * Initialise a dummy MAC address. We choose the numerically largest
- * non-broadcast address to prevent the address getting stolen by an
- * Ethernet bridge for STP purposes. (FE:FF:FF:FF:FF:FF)
- */
- memset(dev->dev_addr, 0xFF, ETH_ALEN);
- dev->dev_addr[0] &= ~0x01;
- }
- else
- {
- memcpy(dev->dev_addr, create->be_mac, ETH_ALEN);
- }
-
- memcpy(netif->fe_dev_addr, create->mac, ETH_ALEN);
-
- rtnl_lock();
- err = register_netdevice(dev);
- rtnl_unlock();
-
- if ( err != 0 )
- {
- DPRINTK("Could not register new net device %s: err=%d\n",
- dev->name, err);
- create->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
- free_netdev(dev);
- return;
- }
-
- netif->hash_next = *pnetif;
- *pnetif = netif;
-
- DPRINTK("Successfully created netif\n");
- create->status = NETIF_BE_STATUS_OKAY;