lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Confusion about udp_sendto_if()


From: Jeffle Xu
Subject: [lwip-users] Confusion about udp_sendto_if()
Date: Sun, 1 Oct 2017 08:01:22 +0800

Hello everyone, I’m a student learning about implementations of lwIP recently, and I have some confusion about function udp_sendto_if(). The source code version is 2.0.0.

Before calling udp_sendto_if(), the stack will call ip_route(), which will find an egress netif based on source/destination ip address. In the assumption that we use IPv4 only and LWIP_HOOK_IP4_ROUTE_SRC not defined, ip_route() is degraded to ip4_route(), which finds the appropriate egress netif only based on destination address.

Besides, if we have 2 network interfaces on one host, which are netif1 with address 192.168.19.17 / netmask 255.255.255.0, and netif2 with address 192.168.19.18 / netmask 255.255.255.0, and now a udp pcb, which is bound to 192.168.19.18, wants to send a packet to 192.168.19.20. The ip_route() would searches the registered netif list linearly and if netif1 is prior to netif2, then netif1 would be selected as the egress netif, which would violates the following snippet from udp_sendto_if().

```c
/* check if UDP PCB local IP address is correct
* this could be an old address if netif->ip_addr has changed */
if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) {
/* local_ip doesn't match, drop the packet */
return ERR_VAL;
}
```

I think it is valid to send the packet with source address 192.168.19.18 using netif1. However it will fail in
udp_sendto_if().

I’m confused about the logic and would appreciate it if someone could tell me that I’ve missed something.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]