Skip to content

Commit 0055e00

Browse files
rveerama1jukkar
authored andcommitted
net: if: Provide a Kconfig to select default network interface
Default network interface is the first interface if there are multiple interfaces exist. But this creates an issue when different parts of the network subsystem wants to choose particular default interface. At-least with this Kconfig option user can select default network interface. Signed-off-by: Ravi kumar Veeramally <[email protected]>
1 parent c6524ab commit 0055e00

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

subsys/net/ip/Kconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,39 @@ config NET_BUF_USER_DATA_SIZE
349349
Example: For Bluetooth, the user_data shall be at least 4 bytes as
350350
that is used for identifying the type of data they are carrying.
351351

352+
choice
353+
prompt "Default Network Interface"
354+
default NET_DEFAULT_IF_FIRST
355+
help
356+
If system has multiple interfaces enabled, then user shall be able
357+
to choose default interface. Otherwise first interface will be the
358+
default interface.
359+
360+
config NET_DEFAULT_IF_FIRST
361+
bool "First available interface"
362+
363+
config NET_DEFAULT_IF_ETHERNET
364+
bool "Ethernet"
365+
depends on NET_L2_ETHERNET
366+
367+
config NET_DEFAULT_IF_BLUETOOTH
368+
bool "Bluetooth"
369+
depends on NET_L2_BT
370+
371+
config NET_DEFAULT_IF_IEEE802154
372+
bool "IEEE 802.15.4"
373+
depends on NET_L2_IEEE802154
374+
375+
config NET_DEFAULT_IF_OFFLOAD
376+
bool "Offloaded interface"
377+
depends on NET_L2_OFFLOAD
378+
379+
config NET_DEFAULT_IF_DUMMY
380+
bool "Dummy testing interface"
381+
depends on NET_L2_DUMMY
382+
383+
endchoice
384+
352385
source "subsys/net/ip/Kconfig.stack"
353386

354387
source "subsys/net/ip/l2/Kconfig"

subsys/net/ip/net_if.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,29 @@ struct net_if *net_if_lookup_by_dev(struct device *dev)
367367

368368
struct net_if *net_if_get_default(void)
369369
{
370+
struct net_if *iface = NULL;
371+
370372
if (__net_if_start == __net_if_end) {
371373
return NULL;
372374
}
373375

374-
return __net_if_start;
376+
#if defined(CONFIG_NET_DEFAULT_IF_ETHERNET)
377+
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
378+
#endif
379+
#if defined(CONFIG_NET_DEFAULT_IF_IEEE802154)
380+
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(IEEE802154));
381+
#endif
382+
#if defined(CONFIG_NET_DEFAULT_IF_BLUETOOTH)
383+
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(BLUETOOTH));
384+
#endif
385+
#if defined(CONFIG_NET_DEFAULT_IF_DUMMY)
386+
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
387+
#endif
388+
#if defined(CONFIG_NET_DEFAULT_IF_OFFLOAD)
389+
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(OFFLOAD_IP));
390+
#endif
391+
392+
return iface ? iface : __net_if_start;
375393
}
376394

377395
struct net_if *net_if_get_first_by_type(const struct net_l2 *l2)

0 commit comments

Comments
 (0)