From 905f1609b38517a9073ac266a0da7444baabc63c Mon Sep 17 00:00:00 2001 From: sg Date: Mon, 9 Mar 2015 21:35:57 +0100 Subject: [PATCH] fixed the IPv4 part of bug #43904 (ip_route() must detect linkup status) --- CHANGELOG | 3 +++ src/core/ipv4/ip4.c | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2debd2ff..697597ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -216,6 +216,9 @@ HISTORY ++ Bugfixes: + 2015-03-09: Simon Goldschmidt + * ip4.c: fixed the IPv4 part of bug #43904 (ip_route() must detect linkup status) + 2015-03-04: Simon Goldschmidt * nd6.c: fixed bug #43784 (a host should send at least one Router Solicitation) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 625fd08b..eccf0df3 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -140,21 +140,20 @@ ip_route(const ip_addr_t *dest) /* iterate through netifs */ for (netif = netif_list; netif != NULL; netif = netif->next) { - /* network mask matches? */ - if ((netif_is_up(netif)) -#if LWIP_IPV6 - /* prevent using IPv6-only interfaces */ - && (!ip_addr_isany(&(netif->ip_addr))) -#endif /* LWIP_IPV6 */ - ) { + /* is the netif up, does it have a link and a valid address? */ + if (netif_is_up(netif) && netif_is_link_up(netif) && !ip_addr_isany(&(netif->ip_addr))) { + /* network mask matches? */ if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { /* return netif on which to forward IP packet */ return netif; } } } - if ((netif_default == NULL) || !netif_is_up(netif_default) || + + if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) || ip_addr_isany(&netif_default->ip_addr)) { + /* No matching netif found an default netif is not usable. + If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */ LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest))); IP_STATS_INC(ip.rterr);