Skip to content

Commit

Permalink
default interface selected when gateway is valid (#54)
Browse files Browse the repository at this point in the history
* default_route: only if not already set to elsewhere
* interface set as default when gw is valid
* +deregister default interface
  • Loading branch information
d-a-v authored Jan 3, 2022
1 parent 27f9894 commit 450bb63
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions glue-lwip/lwip-git.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,21 @@ void esp2glue_netif_set_default (int netif_idx)
static void netif_sta_status_callback (struct netif* netif)
{
// address can be set or reset/any (=0)
// netif is netif_sta

uprint(DBG "netif status callback:\n");
new_display_netif(netif);

// tell ESP that link is updated
glue2esp_ifupdown(netif->num, ip_2_ip4(&netif->ip_addr)->addr, ip_2_ip4(&netif->netmask)->addr, ip_2_ip4(&netif->gw)->addr);

if ( netif->flags & NETIF_FLAG_UP
&& netif == netif_sta)
if (netif->flags & NETIF_FLAG_UP)
{
// this is our default route
netif_set_default(netif);

if ((netif_default == NULL) && !ip_addr_isany(&netif->gw)) {
// STA interface can be our default route if there is currently none and if there is a valid gw address
netif_set_default(netif);
}

// If we have a valid address of any type restart SNTP
bool valid_address = ip_2_ip4(&netif->ip_addr)->addr;

Expand All @@ -340,6 +342,11 @@ static void netif_sta_status_callback (struct netif* netif)
sntp_init();
}
}
else
{
if (netif_default == netif)
netif_set_default(NULL);
}
}

static void netif_init_common (struct netif* netif)
Expand Down

0 comments on commit 450bb63

Please sign in to comment.