lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Multiple network adapters


From: Adam Fullerton
Subject: Re: [lwip-users] Multiple network adapters
Date: Mon, 11 Apr 2011 09:14:04 +0100



On Fri, Apr 1, 2011 at 1:58 PM, Kieran Mansley <address@hidden> wrote:
On Wed, 2011-03-30 at 21:42 +0100, Adam Fullerton wrote:
>
> Unless the network interfaces are on different subnets lwIP sends the
> data
> to the last interface added with "netif_add". The function ip_route
> always
> returns a pointer to the first  interface (last on the list) that
> matches
> the desintation IP address & mask.
>
> Should it not send it to the network interface that the destination IP
> address is attached to? This is either a bug in lwIP or I don't know
> what I
> am doing! Can anyone help?

If they're on the same subnet that suggests packets can reach the
correct destination by using either interface and so lwIP is free to use
whichever it likes.  Could you give an example of how the interfaces are
configured (IP addresses and netmasks) and the address you're trying to
send to to illustrate the problem?

Kieran
 

The application is for IEE1588 clock synchronisation, see the attached for sample connection. Since the ports are connected to different parts of the network it is important that the message is routed to the correct port. I have implemented a workaround where the IP addresses received by the driver are cached. If there is a matching address in an adapter cache then a pointer to the appropriate adapter is returned to the ip_route function:

 

/**

 * Finds the appropriate network interface for a given IP address. It

 * searches the list of network interfaces linearly. A match is found

 * if the masked IP address of the network interface equals the masked

 * IP address given to the function.

 *

 * @param dest the destination IP address for which to find the route

 * @return the netif on which to send to reach dest

 */

struct netif *

ip_route(struct ip_addr *dest)

{

  struct netif *netif;

  /* ++ REE/EDC */

  /* Multiple network interfaces on the same subnet get the wrong

     interface, this quick hack avoids this problem */

  netif = ipGetNetIf(dest);

  if (netif)

  {

      return netif;

  }

  /* -- REE/EDC */

  /* 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;

      }

    }

  }

  if ((netif_default == NULL) || (!netif_is_up(netif_default))) {

    LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to 0x%"X32_F"\n", dest->addr));

    IP_STATS_INC(ip.rterr);

    snmp_inc_ipoutnoroutes();

    return NULL;

  }

  /* no matching netif found, use default netif */

  return netif_default;

}

 

Does anyone know how this should be done properly?

 

Cheers,

 

Adam.

Attachment: lwip_IEE1588.PNG
Description: PNG image


reply via email to

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