Skip to content

[component][net][update]添加优先网卡配置选项 #6592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/net/netdev/Kconfig
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ if RT_USING_NETDEV
bool "Enable default netdev automatic change features"
default y

config NETDEV_USING_PRIORITY
bool "Enable priority netdev automatic change features"
default n

config NETDEV_USING_IPV6
bool "Enable IPV6 protocol support"
default n
9 changes: 8 additions & 1 deletion components/net/netdev/include/netdev.h
Original file line number Diff line number Diff line change
@@ -140,6 +140,10 @@ struct netdev_ops

/* set default network interface device in current network stack*/
int (*set_default)(struct netdev *netdev);
#ifdef NETDEV_USING_PRIORITY
/* set priority network interface device in current network stack*/
int (*set_priority)(struct netdev *netdev);
#endif
};

/* The network interface device registered and unregistered*/
@@ -157,7 +161,10 @@ int netdev_family_get(struct netdev *netdev);

/* Set default network interface device in list */
void netdev_set_default(struct netdev *netdev);

#ifdef NETDEV_USING_PRIORITY
/* Set priority network interface device in list */
void netdev_set_priority(struct netdev *netdev);
#endif
/* Set network interface device status */
int netdev_set_up(struct netdev *netdev);
int netdev_set_down(struct netdev *netdev);
59 changes: 54 additions & 5 deletions components/net/netdev/src/netdev.c
Original file line number Diff line number Diff line change
@@ -31,7 +31,10 @@
struct netdev *netdev_list = RT_NULL;
/* The default network interface device */
struct netdev *netdev_default = RT_NULL;

#ifdef NETDEV_USING_PRIORITY
/* The priority network interface device */
struct netdev *netdev_priority = RT_NULL;
#endif
/**
* This function will register network interface device and
* add it to network interface device list.
@@ -98,7 +101,10 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
if (netdev_list == RT_NULL)
{
netdev_list = netdev;
netdev_default = netdev;
netdev_default = netdev;
#ifdef NETDEV_USING_PRIORITY
netdev_priority = netdev;
#endif
}
else
{
@@ -367,7 +373,22 @@ void netdev_set_default(struct netdev *netdev)
LOG_D("Setting default network interface device name(%s) successfully.", netdev->name);
}
}
#ifdef NETDEV_USING_PRIORITY
void netdev_set_priority(struct netdev *netdev)
{
if (netdev)
{
netdev_priority= netdev;

if (netdev->ops->set_priority)
{
/* set priority network interface device in the current network stack */
netdev->ops->set_priority(netdev);
}
LOG_D("Setting priority network interface device name(%s) successfully.", netdev->name);
}
}
#endif
/**
* This function will enable network interface device .
*
@@ -740,15 +761,42 @@ void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, con
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)
#ifdef NETDEV_USING_PRIORITY
/* When the priority netdev is linkedup, switch the default netdev to the priority netdev */
/* When the priority netdev linkdown needs to switch the default netdev */
if (netdev_priority && netdev_is_link_up(netdev_priority) == 1)
{
netdev_set_default(netdev_priority);
}
else if (netdev_priority && netdev_is_link_up(netdev_priority) == 0)
{
new_netdev = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
if (new_netdev)
{
netdev_set_default(new_netdev);
}
}
#else
/* When the default netdev is linkup should continue to use default netdev */
/* When the default netdev is linkdown should change to use others netdev */
if (netdev_default && netdev_is_link_up(netdev_default) == 1)
{
if(netdev_default)
{
netdev_set_default(netdev_default);
}
}
else if(netdev_default && netdev_is_link_up(netdev_default) == 0)
{
new_netdev = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
if (new_netdev)
{
netdev_set_default(new_netdev);
}
}

#endif

}
#endif /* NETDEV_USING_AUTO_DEFAULT */

@@ -814,12 +862,13 @@ 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 */
if (netdev->status_callback)