From 2b2ea50cb1b6e26a3d26eeca001529249afa1845 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Fri, 28 Jul 2017 16:36:57 -0500 Subject: [PATCH] ip4: fix swapped src/dst params with ip4_route_src This fixes a couple of occurrences where the src and dst parameters to ip4_route_src() were swapped. This was most likely due to confusion between ip_route(src, dst) and ip4_route_src(dst, src) This was found in a system where LWIP_IPV4_SRC_ROUTING is 0 The UDP case was an application socket bound to INADDR_ANY with IP_MULTICAST_IF set. Transmits would result in calling ip4_route(dst) where dst was pcb->local_addr (which was INADDR_ANY) instead of pcb->mcast_ip4. This resulted in a routing failure The ICMP issue was found through code analysis only --- src/core/ipv4/icmp.c | 2 +- src/core/udp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index c866663b..dbf7349c 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -380,7 +380,7 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code) { ip4_addr_t iphdr_dst; ip4_addr_copy(iphdr_dst, iphdr->dest); - netif = ip4_route_src(&iphdr_src, &iphdr_dst); + netif = ip4_route_src(&iphdr_dst, &iphdr_src); } #else netif = ip4_route(&iphdr_src); diff --git a/src/core/udp.c b/src/core/udp.c index f7ac596c..553f6fb6 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -539,7 +539,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, fails, we try regular routing as though no override was set. */ if (!ip4_addr_isany_val(pcb->mcast_ip4) && !ip4_addr_cmp(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) { - netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4); + netif = ip4_route_src(&pcb->mcast_ip4, ip_2_ip4(&pcb->local_ip)); } } #endif /* LWIP_IPV4 */