lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] 2 Interfaces


From: Fabian Cenedese
Subject: Re: [lwip-users] 2 Interfaces
Date: Tue, 05 Mar 2013 15:07:55 +0100

At 15:30 05.03.2013 +0700, you wrote:
>> Assuming that both interfaces have different IP/MAC and
>> don't need to handle the same ports, would it then be
>> possible to handle both devices with the same instance
>> of lwip? I mean there's netif_add, can't I call this twice
>> for every interface and set just one as the default? What
>> conditions need to be fulfilled to make this work?
>
>Yes, you can. Also you can listen TCP connections or receive
>UDP datagrams on specified port within single socket or netconn
>(binded with IP_ADDR_ANY) from all interfaces. You just need
>two network drivers initialized with netif_add() and netif_up() each,
>then set one of them default. Details on how implement drivers
>depend on your hardware. lwip provides driver functions with
>netif* instance handle allowing driver(-s) distinguish interface
>used.

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




reply via email to

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