diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index a51cfda..33d900b 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -125,7 +125,7 @@ len = dev->rx_urb_size; - ret = usb_bulk_msg(dev->udev, dev->in, rx_buf, len, &alen, 1000); + ret = usb_bulk_msg(dev->udev, dev->in, rx_buf, len, &alen, 1); if (ret) return ret; diff --git a/include/net.h b/include/net.h index 13e335a..8f857c8 100644 --- a/include/net.h +++ b/include/net.h @@ -51,6 +51,7 @@ struct phy_device *phydev; struct device_d dev; + char *devname; struct device_d *parent; char *nodepath; @@ -65,6 +66,11 @@ #define dev_to_edev(d) container_of(d, struct eth_device, dev) +static inline const char *eth_name(struct eth_device *edev) +{ + return edev->devname; +} + int eth_register(struct eth_device* dev); /* Register network device */ void eth_unregister(struct eth_device* dev); /* Unregister network device */ int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr); @@ -466,4 +472,8 @@ int ifup(const char *name, unsigned flags); int ifup_all(unsigned flags); +extern struct list_head netdev_list; + +#define for_each_netdev(netdev) list_for_each_entry(netdev, &netdev_list, list) + #endif /* __NET_H__ */ diff --git a/net/eth.c b/net/eth.c index fb3f22f..6f8e78d 100644 --- a/net/eth.c +++ b/net/eth.c @@ -31,7 +31,7 @@ static struct eth_device *eth_current; static uint64_t last_link_check; -static LIST_HEAD(netdev_list); +LIST_HEAD(netdev_list); struct eth_ethaddr { struct list_head list; @@ -104,7 +104,7 @@ eth_drop_ethaddr(ethid); - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (edev->dev.id == ethid) { register_preset_mac_address(edev, ethaddr); return; @@ -121,7 +121,7 @@ { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (!edev->parent) continue; if (!edev->parent->device_node) @@ -163,8 +163,8 @@ { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { - if (!strcmp(ethname, dev_name(&edev->dev))) + for_each_netdev(edev) { + if (!strcmp(ethname, eth_name(edev))) return edev; } return NULL; @@ -174,17 +174,15 @@ int eth_complete(struct string_list *sl, char *instr) { struct eth_device *edev; - const char *devname; int len; len = strlen(instr); - list_for_each_entry(edev, &netdev_list, list) { - devname = dev_name(&edev->dev); - if (strncmp(instr, devname, len)) + for_each_netdev(edev) { + if (strncmp(instr, eth_name(edev), len)) continue; - string_list_add_asprintf(sl, "%s ", devname); + string_list_add_asprintf(sl, "%s ", eth_name(edev)); } return COMPLETE_CONTINUE; } @@ -228,7 +226,7 @@ if (edev->active) return 0; - ret = edev->open(eth_current); + ret = edev->open(edev); if (ret) return ret; @@ -273,7 +271,7 @@ { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (edev->active) __eth_rx(edev); } @@ -337,7 +335,7 @@ eth_of_fixup_node(root, addr->node ? addr->node->full_name : NULL, addr->ethid, addr->ethaddr); - list_for_each_entry(edev, &netdev_list, list) + for_each_netdev(edev) eth_of_fixup_node(root, edev->nodepath, edev->dev.id, edev->ethaddr); return 0; @@ -378,6 +376,8 @@ if (ret) return ret; + edev->devname = xstrdup(dev_name(&edev->dev)); + dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev); dev_add_param_ip(dev, "serverip", NULL, NULL, &edev->serverip, edev); dev_add_param_ip(dev, "gateway", NULL, NULL, &edev->gateway, edev); @@ -424,6 +424,8 @@ if (IS_ENABLED(CONFIG_OFDEVICE)) free(edev->nodepath); + free(edev->devname); + unregister_device(&edev->dev); list_del(&edev->list); } diff --git a/net/net.c b/net/net.c index e5bd9bb..df1d677 100644 --- a/net/net.c +++ b/net/net.c @@ -379,11 +379,10 @@ return net_ip_send(con, sizeof(struct icmphdr) + len); } -static int net_answer_arp(unsigned char *pkt, int len) +static int net_answer_arp(struct eth_device *edev, unsigned char *pkt, int len) { struct arprequest *arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE); struct ethernet *et = (struct ethernet *)pkt; - struct eth_device *edev = eth_get_current(); unsigned char *packet; int ret; @@ -453,7 +452,7 @@ switch (ntohs(arp->ar_op)) { case ARPOP_REQUEST: - return net_answer_arp(pkt, len); + return net_answer_arp(edev, pkt, len); case ARPOP_REPLY: arp_handler(arp); return 1;