Hey Simon, Hey Erik,

we do have a setup with two netifs and we cannot determine what the customer 
will do with the device so we need to also check for "same subnet" scenarios.

I already wrote and email to this (or devel?) list about that a while ago.

We also attacked the problem by including the src IP into the ip_route() 
function and I can provide a patch, but it just doesn't feel right.

The reason this is needed is actually because LwIP uses ip_route() to find a 
netif when the local address is INADDR_ANY.

In udp_connect(), udp_sendto(), tcp_eff_send_mss(), snmp_send_trap() and 
etharp_add_static_entry().

In all those cases, ip_route() is actually not really a good function to find a 
matching netif. If we were to replace those instances with another function 
that is a bit more complicated and finds a fitting netif with more aspects 
including gateway settings and network reachability (if that's even a word...) 
then it would make the final routing a bit easier.

Also, the default_netif construct is just too simple to make all this work 
correctly.

If you need a quick solution, you can make ip_route include the src, but then 
you also have to add that parameter to tcp_eff_send_mss().

Our middle part of ip_route() looks like this at the moment:

  /* iterate through netifs */
  for (netif = netif_list; netif != NULL; netif = netif->next) {
    if (netif_is_up(netif) && netif_is_link_up(netif)) {           //only 
consider interfaces which are up and have a link
      if(ip_addr_isany(src)) {    //when the source IP is INADDR_ANY, the 
socket is not bound to an interface => find the first match (netmask or is 
broadcast)
        if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask)) || 
ip_addr_cmp(IP_ADDR_BROADCAST, dest)) {
          /* return netif on which to forward IP packet (first matching netif 
when socket is not bound) */
          return netif;
        }
      } else { // socket is bound to a specific IP so only match the right 
netif (matching IPs and either fits netmask or is broadcast)
        if(ip_addr_cmp((&netif->ip_addr), src) && (ip_addr_netcmp(dest, 
&(netif->ip_addr), &(netif->netmask)) || ip_addr_cmp(IP_ADDR_BROADCAST, dest))) 
{
          /* this socket is bound to a specific interface, so look for that */
          return netif;
        }
      }
    }
  }

This essentially makes sending on specific interfaces possible when they are 
bound to the IP. Unbound sockets just send on the best matching netif they can 
find.

For this to work, you also need to netif_set_link_up(&loop_netif) in netif.c if 
you're using a loopback netif. (I wonder if it can be considered a bug that the 
loopif never gets a link up...)

I would still not like this in the main lwIP source tree, since it just doesn't 
feel right to include the src IP here.


Cheers,
Fabian

From: [email protected] 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Freitag, 14. November 2014 21:29
To: Mailing list for lwIP users
Subject: Re: [lwip-users] Sending to a non-local network without default netif 
set

HaaCee2 wrote:
I beg to differ....

I've added a task for this to the tracker:

https://savannah.nongnu.org/task/index.php?13397


Simon
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to