net: if: add default selection of first up interface

Add the default selection of the first interface which is up.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
This commit is contained in:
Benedikt Schmidt 2022-03-08 11:43:59 +01:00 committed by Anas Nashif
commit ccd7ae2445
3 changed files with 25 additions and 0 deletions

View file

@ -581,6 +581,9 @@ struct net_if *net_if_get_default(void)
#if defined(CONFIG_NET_DEFAULT_IF_PPP)
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP));
#endif
#if defined(CONFIG_NET_DEFAULT_IF_UP)
iface = net_if_get_first_up();
#endif
return iface ? iface : _net_if_list_start;
}
@ -601,6 +604,17 @@ struct net_if *net_if_get_first_by_type(const struct net_l2 *l2)
return NULL;
}
struct net_if *net_if_get_first_up(void)
{
STRUCT_SECTION_FOREACH(net_if, iface) {
if (net_if_flag_is_set(iface, NET_IF_UP)) {
return iface;
}
}
return NULL;
}
static enum net_l2_flags l2_flags_get(struct net_if *iface)
{
enum net_l2_flags flags = 0;