lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] 2 Interfaces


From: Dipswitch
Subject: Re: [lwip-users] 2 Interfaces
Date: Tue, 05 Mar 2013 15:43:03 +0100
User-agent: Roundcube Webmail/0.8.5

On 2013-03-05 15:07, Fabian Cenedese wrote:
That's what I already tried. However if I netif_set_up the second
interface then the communication over the first interface doesn't
work anymore. I found out that the interfaces must have IP
addresses differing inside the network mask. That may be
obvious to you but I thought that's what the default is for. If
no interfaces match or more than one then use the default
instead of just the first found. Because I'd like to have both
interfaces in the same subnet even with differing IP addresses.

If there's no rule/standard on what to do in this case then I'd
change core/ipv4/ip.c like this (could use some more error
handling):

struct netif *
ip_route(ip_addr_t *dest)
{
  struct netif *netif;
  u8_t matches=0;
  struct netif *firstmatch=NULL;

#ifdef LWIP_HOOK_IP4_ROUTE
  netif = LWIP_HOOK_IP4_ROUTE(dest);
  if (netif != NULL) {
    return netif;
  }
#endif

  /* iterate through netifs */
  for (netif = netif_list; netif != NULL; netif = netif->next) {
    /* network mask matches? */
    if (netif_is_up(netif)) {
if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
        /* return netif on which to forward IP packet */
/*        return netif;*/
        matches=matches+1;
        if (firstmatch==NULL) {
          firstmatch=netif;
        }
      }
    }
  }

/* only return netif if there's exactly one match, otherwise return default */
  if (matches==1) {
    return firstmatch;
  }

  if ((netif_default == NULL) || (!netif_is_up(netif_default))) {
    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);
    snmp_inc_ipoutnoroutes();
    return NULL;
  }
  /* no matching netif found, use default netif */
  return netif_default;
}


Thanks

bye  Fabi


Hello Fabi,

That is not the only thing to change, you might want to take a look at the changes we made for multiple interfaces in the same network at https://github.com/EngineeringSpirit/FreeLwIP-Nios-II/tree/master/lwip/FreeRTOS

I have changed the sources in core/ip4.c/h and core/udp.c as far as I can remember. And to catch UDP broadcasts via both interfaces, we create two sockets both listening specifically on the IP address of the interface. (So not INADDR_ANY but the IP from the interface)

Unfortunately you would probably need to make your own diff, I moved to files around a bit so I could include them in the IDE where it's build for...

Hope it helps!

Kind regards,
Nick



reply via email to

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