Skip to content

Commit

Permalink
gnrc_static: auto-select interface if there is only one
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Mar 16, 2023
1 parent 3f2d36d commit a473ca9
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM)) {
upstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM);
}

if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM)) {
downstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM);
}

while ((netif = gnrc_netif_iter(netif))) {
bool is_wired = gnrc_netapi_get(netif->pid, NETOPT_IS_WIRED, 0, NULL, 0) == 1;
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;
if (!upstream && is_wired) {
upstream = netif;
} else if (!downstream && !is_wired) {
downstream = netif;
}
}
}

Expand Down

0 comments on commit a473ca9

Please sign in to comment.