static void virtio_net_disconnect(struct virtio_device *dev) { struct virtio_net_dev *ndev = dev->emu_data; vmm_netport_unregister(ndev->port); vmm_netport_free(ndev->port); vmm_free(ndev); }
static void __exit lwip_netstack_exit(void) { vmm_netport_unregister(lns.port); vmm_netport_free(lns.port); }
static int __init lwip_netstack_init(void) { int rc; struct vmm_netswitch *nsw; struct vmm_devtree_node *node; const char *str; u8 ip[] = {169, 254, 1, 1}; u8 mask[] = {255, 255, 255, 0}; ip_addr_t __ip, __nm, __gw; /* Clear lwIP state */ memset(&lns, 0, sizeof(lns)); /* Get netstack device tree node if available */ node = vmm_devtree_getnode(VMM_DEVTREE_PATH_SEPARATOR_STRING VMM_DEVTREE_VMMINFO_NODE_NAME VMM_DEVTREE_PATH_SEPARATOR_STRING VMM_DEVTREE_VMMNET_NODE_NAME VMM_DEVTREE_PATH_SEPARATOR_STRING VMM_DEVTREE_NETSTACK_NODE_NAME); /* Retrive preferred IP address */ if (vmm_devtree_read_string(node, "ipaddr", &str) == VMM_OK) { /* Read ip address from netstack node */ str2ipaddr(ip, str); } /* Retrive preferred IP address */ if (vmm_devtree_read_string(node, "netmask", &str) == VMM_OK) { /* Read network mask from netstack node */ str2ipaddr(mask, str); } /* Retrive preferred netswitch */ if (vmm_devtree_read_string(node, "netswitch", &str) == VMM_OK) { /* Find netswitch with given name */ nsw = vmm_netswitch_find(str); } else { /* Get default netswitch */ nsw = vmm_netswitch_default(); } if (!nsw) { vmm_panic("%s: No netswitch found\n", __func__); } /* Release netstack device tree node */ vmm_devtree_dref_node(node); /* Allocate a netport */ lns.port = vmm_netport_alloc("lwip-netport", VMM_NETPORT_DEF_QUEUE_SIZE); if (!lns.port) { vmm_printf("%s: vmm_netport_alloc() failed\n", __func__); rc = VMM_ENOMEM; goto fail; } /* Setup a netport */ lns.port->mtu = 1500; lns.port->link_changed = lwip_set_link; lns.port->can_receive = lwip_can_receive; lns.port->switch2port_xfer = lwip_switch2port_xfer; lns.port->priv = &lns; /* Register a netport */ rc = vmm_netport_register(lns.port); if (rc) { goto fail1; } /* Initialize lwIP + TCP/IP APIs */ tcpip_init(NULL, NULL); /* Add netif */ IP4_ADDR(&__ip, ip[0],ip[1],ip[2],ip[3]); IP4_ADDR(&__nm, mask[0],mask[1],mask[2],mask[3]); IP4_ADDR(&__gw, ip[0],ip[1],ip[2],ip[3]); netif_add(&lns.nif, &__ip, &__nm, &__gw, &lns, lwip_netstack_netif_init, ethernet_input); /* Set default netif */ netif_set_default(&lns.nif); /* Attach netport with netswitch * Note: This will cause netport link_change() */ rc = vmm_netswitch_port_add(nsw, lns.port); if (rc) { goto fail2; } #if !defined(PING_USE_SOCKETS) /* Initalize RAW PCB for ping */ ping_raw_init(); #endif return VMM_OK; fail2: vmm_netport_unregister(lns.port); fail1: vmm_netport_free(lns.port); fail: return rc; }