lwip-users
[Top][All Lists]
Advanced

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

RE: [lwip-users] regarding lwip, loopif and ip_route


From: Jim Buteau
Subject: RE: [lwip-users] regarding lwip, loopif and ip_route
Date: Tue, 12 Oct 2004 16:09:44 -0700

Leon,

Thanks for your response.

> > 1- Somewhere down the call stack shouldn't some routine have
> seen that the
> > dest matched the ethernet ipaddr and directed the packet at the
> loopif?  I
> > am tempted to add this capability to ip_route().  On the other
> hand I can't
> > find any precedent for this on lwip-users or anywhere I've searched.
> >
> Good point, but I do not think that packets destined for a non-loopback
> address are meant to be fed back into the loopback address range.
>
> I.e. suppose your adapter has IP address 192.168.0.1 and you are sending
> to it, I do not think the packet should enter the 127.0.0.1 loopback
> address.
>
> What we/you could do, is insert it directly into the ip_input() function
> of the adapter.

Well, I changed ip_route() to return the loopback netif if 1) there is one,
and 2)
the dest ip matches any of the netifs in the netif_list.  This works nicely
and it doesn't
change the packet's address.  It just returns (what seems to be) the best
netif to use
under these conditions.

The packet ends goes from loopif_output() to loopif_input() to
tcpip_input().  I passed tcpip_input()
into netif_add().

If you believe there's a better way to do this, let me know.  Thanks.

The ip_route() mod:

===
  struct netif    *loopif;
  bool            destCanUseLoopback;
  struct ip_addr  loopbackAddr;

  // first check if there is a loopback interface and if there is an exact
match between the dest ip_addr
  // and any interface.  If so, force the loopback.

  loopif = NULL;
  destCanUseLoopback = false;
  IP4_ADDR(&loopbackAddr, 127,0,0,1);

  for ( netif = netif_list; netif != NULL; netif = netif->next ) {
    if ( !destCanUseLoopback && ip_addr_cmp( dest, &(netif->ip_addr)) ) {
      destCanUseLoopback = true;
    }
    if ( (loopif == NULL) && ip_addr_cmp( &loopbackAddr,
&(netif->ip_addr)) ) {
      loopif = netif;
    }
    if ( (loopif != NULL) && destCanUseLoopback ) {
      return loopif;
    }
  }

  // otherwise, find a match using the mask
===

Thanks again,
Jim





reply via email to

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