diff --git a/include/net.h b/include/net.h index 81118d2..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); diff --git a/net/eth.c b/net/eth.c index 499f4b0..6f8e78d 100644 --- a/net/eth.c +++ b/net/eth.c @@ -164,7 +164,7 @@ struct eth_device *edev; for_each_netdev(edev) { - if (!strcmp(ethname, dev_name(&edev->dev))) + 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); for_each_netdev(edev) { - devname = dev_name(&edev->dev); - if (strncmp(instr, devname, len)) + 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; } @@ -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); }