[net][netdev]Use the interface to set the default netdev

This commit is contained in:
tyx 2022-10-29 09:15:38 +08:00 committed by guo
parent 2f9d3bfe20
commit 8aaa57e2ea
1 changed files with 13 additions and 4 deletions

View File

@ -98,7 +98,6 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
if (netdev_list == RT_NULL)
{
netdev_list = netdev;
netdev_default = netdev;
}
else
{
@ -108,6 +107,11 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_hw_interrupt_enable(level);
if (netdev_default == RT_NULL)
{
netdev_set_default(netdev_list);
}
return RT_EOK;
}
@ -151,13 +155,18 @@ int netdev_unregister(struct netdev *netdev)
}
if (netdev_default == netdev)
{
netdev_default = netdev_list;
netdev_default = RT_NULL;
}
break;
}
}
rt_hw_interrupt_enable(level);
if (netdev_default == RT_NULL)
{
netdev_set_default(netdev_list);
}
if (cur_netdev == netdev)
{
#ifdef RT_USING_SAL
@ -355,13 +364,13 @@ int netdev_family_get(struct netdev *netdev)
*/
void netdev_set_default(struct netdev *netdev)
{
if (netdev)
if (netdev && (netdev != netdev_default))
{
netdev_default = netdev;
/* execture the default network interface device in the current network stack */
if (netdev->ops->set_default)
{
/* set default network interface device in the current network stack */
netdev->ops->set_default(netdev);
}
LOG_D("Setting default network interface device name(%s) successfully.", netdev->name);