Merge pull request #2650 from Lawlieta/develop
[net][netdev] Add default netdev automatic change features configuration
This commit is contained in:
commit
4a2242b94d
|
@ -73,6 +73,9 @@ config RT_USING_NETDEV
|
|||
bool "Enable netstat features"
|
||||
default y
|
||||
|
||||
config NETDEV_USING_AUTO_DEFAULT
|
||||
bool "Enable default netdev automatic change features"
|
||||
default y
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -269,7 +269,7 @@ struct netdev *netdev_get_by_family(int family)
|
|||
{
|
||||
netdev = rt_slist_entry(node, struct netdev, list);
|
||||
pf = (struct sal_proto_family *) netdev->sal_user_data;
|
||||
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev) && netdev_is_link_up(netdev))
|
||||
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
return netdev;
|
||||
|
@ -671,6 +671,23 @@ void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, con
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef NETDEV_USING_AUTO_DEFAULT
|
||||
/* Change to the first link_up network interface device automatically */
|
||||
static void netdev_auto_change_default(struct netdev *netdev)
|
||||
{
|
||||
struct netdev *new_netdev = RT_NULL;
|
||||
|
||||
if (rt_memcmp(netdev, netdev_default, sizeof(struct netdev)) == 0)
|
||||
{
|
||||
new_netdev = netdev_get_first_link_up();
|
||||
if (new_netdev)
|
||||
{
|
||||
netdev_set_default(new_netdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* NETDEV_USING_AUTO_DEFAULT */
|
||||
|
||||
/**
|
||||
* This function will set network interface device status.
|
||||
* @NOTE it can only be called in the network interface device driver.
|
||||
|
@ -689,6 +706,11 @@ void netdev_low_level_set_status(struct netdev *netdev, rt_bool_t is_up)
|
|||
else
|
||||
{
|
||||
netdev->flags &= ~NETDEV_FLAG_UP;
|
||||
|
||||
#ifdef NETDEV_USING_AUTO_DEFAULT
|
||||
/* change to the first link_up network interface device automatically */
|
||||
netdev_auto_change_default(netdev);
|
||||
#endif /* NETDEV_USING_AUTO_DEFAULT */
|
||||
}
|
||||
|
||||
/* execute network interface device status change callback function */
|
||||
|
@ -728,6 +750,11 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
|
|||
|
||||
/* set network interface device flags to internet down */
|
||||
netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
|
||||
|
||||
#ifdef NETDEV_USING_AUTO_DEFAULT
|
||||
/* change to the first link_up network interface device automatically */
|
||||
netdev_auto_change_default(netdev);
|
||||
#endif /* NETDEV_USING_AUTO_DEFAULT */
|
||||
}
|
||||
|
||||
/* execute link status change callback function */
|
||||
|
|
|
@ -387,14 +387,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
|
|||
sock->type = type;
|
||||
sock->protocol = protocol;
|
||||
|
||||
/* get socket operations from network interface device */
|
||||
if (netdv_def == RT_NULL)
|
||||
{
|
||||
LOG_E("not find default network interface device for socket create.");
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (netdev_is_up(netdv_def) && netdev_is_link_up(netdv_def))
|
||||
if (netdv_def && netdev_is_up(netdv_def))
|
||||
{
|
||||
/* check default network interface device protocol family */
|
||||
pf = (struct sal_proto_family *) netdv_def->sal_user_data;
|
||||
|
|
Loading…
Reference in New Issue