From fecd1bde835e1f65def998397f85908526bbb76b Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 1 Oct 2015 21:17:59 +0200 Subject: [PATCH] ip4_route: fixed checking twice for a valid default_netif, fixed checking loopback traffic before checking for a valid default netif --- src/core/ipv4/ip4.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index c6e88f5e..17944b49 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -185,17 +185,6 @@ ip4_route(const ip4_addr_t *dest) } } - if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) || - ip4_addr_isany_val(*netif_ip4_addr(netif_default))) { - /* No matching netif found and 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); - MIB2_STATS_INC(mib2.ipoutnoroutes); - return NULL; - } - #if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF /* loopif is disabled, looopback traffic is passed through any netif */ if (ip4_addr_isloopback(dest)) { @@ -213,10 +202,17 @@ ip4_route(const ip4_addr_t *dest) } #endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */ - /* no matching netif found, use default netif */ - if (!netif_is_up(netif_default) || !netif_is_link_up(netif_default)) { + if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) || + ip4_addr_isany_val(*netif_ip4_addr(netif_default))) { + /* No matching netif found and 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); + MIB2_STATS_INC(mib2.ipoutnoroutes); return NULL; } + return netif_default; }