From a473ca9ed521db88d9f2686e271f9323a32b5c6f Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 16 Mar 2023 11:20:23 +0100 Subject: [PATCH] gnrc_static: auto-select interface if there is only one --- .../ipv6/static_addr/gnrc_ipv6_static_addr.c | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c b/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c index 49ce13f96b..71c9b1b738 100644 --- a/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c +++ b/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c @@ -113,25 +113,34 @@ static void _config_downstream(gnrc_netif_t *downstream) void auto_init_gnrc_ipv6_static_addr(void) { - gnrc_netif_t *netif = NULL; gnrc_netif_t *upstream = NULL; gnrc_netif_t *downstream = NULL; - if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM)) { - upstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM); - } + if (gnrc_netif_highlander() || gnrc_netif_numof() == 1) { + upstream = gnrc_netif_iter(NULL); - if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM)) { - downstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM); - } + if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM)) { + assert(upstream->pid == CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM); + } + } else { - while ((netif = gnrc_netif_iter(netif))) { - bool is_wired = gnrc_netapi_get(netif->pid, NETOPT_IS_WIRED, 0, NULL, 0) == 1; + if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM)) { + upstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM); + } - if (!upstream && is_wired) { - upstream = netif; - } else if (!downstream && !is_wired) { - downstream = netif; + if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM)) { + downstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM); + } + + gnrc_netif_t *netif = NULL; + while ((netif = gnrc_netif_iter(netif))) { + bool is_wired = gnrc_netapi_get(netif->pid, NETOPT_IS_WIRED, 0, NULL, 0) == 1; + + if (!upstream && is_wired) { + upstream = netif; + } else if (!downstream && !is_wired) { + downstream = netif; + } } }