On Fri, Apr 1, 2011 at 1:58 PM, Kieran Mansley <[email protected]> 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>>

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

Reply via email to