Linux Route/Loopback Problem - 2 STAs on same machine

David C Wang dave at davidwang.com
Thu Dec 19 17:51:40 EST 2002


Kristian,

> If you have the iproute2 utilities, run "ip route show table local".
> Those routes are visited first, so your host routes are never
> reached.

Thanks for the suggestion on iproute2.  I've already tried modifying
the "local" table directly to do the redirection, but packets were
still looping back.

  dave:/home/dave# ip route change table local local 192.168.0.10 \
		  dev wlan1 proto kernel scope host src 192.168.0.11
  dave:/home/dave# ip route change table local local 192.168.0.11 \
		  dev wlan0 proto kernel scope host src 192.168.0.10

> You can delete the routes in the local table that tell your machine
> how to get to its own addresses, and then it will use the host
> routes you specify.

I did try your suggestion on removing the routes from "local".  The
REALLY GOOD news is that the Kernel IP routing cache is finally
reflecting the intended interface destinations.  Also, doing a
wireless dump of the radio, the packets are indeed hitting the radio
medium.

  dave:/home/dave# route -nC|grep -v 10.
  Kernel IP routing cache
  Source       Destination     Gateway         Flags Metric Ref Use
Iface
  192.168.0.11 192.168.0.10    192.168.0.10    i     0      0     2
wlan1
  192.168.0.10 192.168.0.11    192.168.0.11          0      0     1
wlan0
  192.168.0.11 192.168.0.10    192.168.0.10          0      0     1
wlan1
  192.168.0.10 192.168.0.11    192.168.0.11    i     0      0     2
wlan0

The bad news is that when I attempt to ping STA to STA, I'm not
receiving the replies over any medium, neither loopback nor radio.

The strange thing here is that the "Gateway" field in the Kernel
routing *cache* (above) is set to a value, even though I did not
define it in the Kernel routing *table* (below).  I'm wondering if
this is causing the problem of me not receiving ping replies.

  dave:/home/dave# route add -host 192.168.0.11 dev wlan0
  dave:/home/dave# route add -host 192.168.0.10 dev wlan1
  dave:/home/dave# route -n
  Kernel IP routing table
  Destination  Gateway      Genmask         Flags Metric Ref  Use Iface
  192.168.0.10 0.0.0.0      255.255.255.255 UH    0      0      0 wlan1
  192.168.0.11 0.0.0.0      255.255.255.255 UH    0      0      0 wlan0
  10.1.1.0     0.0.0.0      255.255.255.0   U     0      0      0 eth0
  0.0.0.0      10.1.1.254   0.0.0.0         UG    0      0      0 eth0

> The packets will reach the AP and then be sent back to your other
> interface.  Since you delete the local routes though, when the other
> interface receives the packets, they will be dropped because it
> won't know how to route to itself.

I believe that what you say is correct here.  If I set up a direct
route to the AP and then ping it, then over radio I see a request go
from my wlan0 to the ap (+ control ack), and then a reply go from the
ap to my wlan0 (+ control ack).  The ping reply, however, is never
received by the ping program.

  dave:/home/dave# route add -host 192.168.0.1 dev wlan0
  dave:/home/dave# ping -c 1 192.168.0.1

There must be some way to make the return trip work.  This problem is
90% solved.  Do anyone have any other suggestions?

thanks,
-dave
dave at davidwang dot c*m

------------------------------------------------------------------
# Excerpt from 1st message
I am also aware of the "local" routing table accessible through the old
linux-2.2 "iproute2" interface.

  dave:/home/dave# ip route show table local|grep 192
  broadcast 192.168.0.255 dev wlan0  proto kernel  scope link  src
192.168.0.10 
  broadcast 192.168.0.255 dev wlan1  proto kernel  scope link  src
192.168.0.11 
  local 192.168.0.11 dev wlan1  proto kernel  scope host  src
192.168.0.11 
  local 192.168.0.10 dev wlan0  proto kernel  scope host  src
192.168.0.10 
  broadcast 192.168.0.0 dev wlan0  proto kernel  scope link  src
192.168.0.10 
  broadcast 192.168.0.0 dev wlan1  proto kernel  scope link  src
192.168.0.11 

So I try to swap the sources also in this table for each device

  dave:/home/dave# ip route change table local local 192.168.0.10 dev
wlan1 \
		  proto kernel scope host src 192.168.0.11
  dave:/home/dave# ip route change table local local 192.168.0.11 dev
wlan0 \
		  proto kernel scope host src 192.168.0.10

And this is what i get.

  dave:/home/dave# ip route show table local|grep 192
  broadcast 192.168.0.255 dev wlan0  proto kernel  scope link  src
192.168.0.10 
  broadcast 192.168.0.255 dev wlan1  proto kernel  scope link  src
192.168.0.11 
  local 192.168.0.11 dev wlan0  proto kernel  scope host  src
192.168.0.10 
  local 192.168.0.10 dev wlan1  proto kernel  scope host  src
192.168.0.11 
  broadcast 192.168.0.0 dev wlan0  proto kernel  scope link  src
192.168.0.10 
  broadcast 192.168.0.0 dev wlan1  proto kernel  scope link  src
192.168.0.11 

Again, when i try to ping it goes through the loopback device.  The
routing cache verifies this again.

It seems that linux is ignoring the routing table for local network
devices, and forcing the route through the loopback device.  Is there
any way to get around this?

-----Original Message-----
From: Kristian Hoffmann [mailto:khoff at pc-intouch.com] 
Sent: Thursday, December 19, 2002 1:50 PM
To: David C Wang
Cc: hostap at shmoo.com
Subject: Re: Linux Route/Loopback Problem - 2 STAs on same machine

If you have the iproute2 utilities, run "ip route show table local".
Those routes are visited first, so your host routes are never reached.

You can delete the routes in the local table that tell your machine how
to
get to its own addresses, and then it will use the host routes you
specify.  The packets will reach the AP and then be sent back to your
other interface.  Since you delete the local routes though, when the
other
interface receives the packets, they will be dropped because it won't
know
how to route to itself.

In other words, this is just a bad idea.  Get another machine to test
with. :-)

-Kristian

On Thu, 19 Dec 2002, David C Wang wrote:

> Hi,
>
> I've been unable to resolve this problem for a while.  Hopefully
> someone can help me out.  I've already posted this question to
> comp.os.linux.networking with no luck.  I'll probably also post
> to linux-wlan.
>
> I have 2 wireless interfaces on the *same machine* wlan0 and wlan1
> (linux-wlan), and am trying to test an ap (hostap) by having both
> interfaces wlan0 and wlan1 speak to each other via the ap.  Both
> interfaces associate just fine, but i'm having trouble setting up the
> linux routes so that the stas can ping each other.  I'm hoping that
> someone on this list has tried this before.
>
> It seems that linux is ignoring the routing table for local network
> devices, and forcing the route through the loopback device.  Is there
> any way to get around this?
>
> Here's a description of the problem.  On the same computer, I have
> interfaces wlan0 (192.168.0.10) and wlan1 (192.168.0.11).  I want to
> ping from wlan0 to wlan1, and make the packet physically hit the
> radio, instead of going through the loopback netdevice.
>
> I enable ip_forwarding
>   echo "1" > /proc/sys/net/ipv4/ip_forward
> I clear the kernel routing cache
>   echo "1" > /proc/sys/net/ipv4/route/flush
>
> Then, I modify my routing tables to say that packets going to
> 192.168.0.10 (wlan0) should exit through the wlan1 netdevice, and vice
> versa:
>
>   dave:/home/dave# route add -host 192.168.0.11 dev wlan0
>   dave:/home/dave# route add -host 192.168.0.10 dev wlan1
>   dave:/home/dave# route -n
>   Kernel IP routing table
>   Destination  Gateway      Genmask         Flags Metric Ref  Use
Iface
>   192.168.0.10 0.0.0.0      255.255.255.255 UH    0      0      0
wlan1
>   192.168.0.11 0.0.0.0      255.255.255.255 UH    0      0      0
wlan0
>   10.1.1.0     0.0.0.0      255.255.255.0   U     0      0      0 eth0
>   0.0.0.0      10.1.1.254   0.0.0.0         UG    0      0      0 eth0
>
> Then I ping 192.168.0.10, which should get routed through the second
> netdevice wlan1, but the packet still goes through the loopback
> netdevice, instead of directly out the physical device.
>
>   dave:/home/dave#  ping -c 1 192.168.0.10
>   PING 192.168.0.10 (192.168.0.10): 56 data bytes
>   64 bytes from 192.168.0.10: icmp_seq=0 ttl=64 time=0.0 ms
>   --- 192.168.0.10 ping statistics ---
>   1 packets transmitted, 1 packets received, 0% packet loss
>   round-trip min/avg/max = 0.0/0.0/0.0 ms
>
> To verify, I check the Kernel Routing Cache, which indeed shows that
> pings to 192.68.0.10 will go through the loopback device.
>
>   dave:/home/dave# route -nC|grep -v 10
>   Kernel IP routing cache
>   Source        Destination   Gateway       Flags Metric Ref  Use
Iface
>   192.168.0.11  192.168.0.11  192.168.0.11  l     0      0      0 lo
>   192.168.0.11  192.168.0.11  192.168.0.11  l     0      0      0 lo
>   192.168.0.10  192.168.0.10  192.168.0.10  l     0      0      1 lo
>   192.168.0.10  192.168.0.10  192.168.0.10  l     0      0      1 lo
>
> I try again by modifying the routing tables to include a gateway for
> each device.  But I get the same result, and the same output from the
> kernel routing cache.
>
>   da:/home/dave# route add -host 192.168.0.11 gw 192.168.0.10 dev
wlan0
>   da:/home/dave# route add -host 192.168.0.10 gw 192.168.0.11 dev
wlan1
>   dave:/home/dave# route -n
>   Kernel IP routing table
>   Destination  Gateway      Genmask         Flags Metric Ref Use Iface
>   192.168.0.10 192.168.0.11 255.255.255.255 UGH   0      0     0 wlan1
>   192.168.0.11 192.168.0.10 255.255.255.255 UGH   0      0     0 wlan0
>   10.1.1.0     0.0.0.0      255.255.255.0   U     0      0     0 eth0
>   0.0.0.0      10.1.1.254   0.0.0.0         UG    0      0     0 eth0
>
> I am also aware of the "local" routing table accessible through the
> old linux-2.2 "iproute2" interface.
>
>   dave:/home/dave# ip route show table local|grep 192
>   broadcast 192.168.0.255 dev wlan0  proto kernel  scope link  src
> 192.168.0.10
>   broadcast 192.168.0.255 dev wlan1  proto kernel  scope link  src
> 192.168.0.11
>   local 192.168.0.11 dev wlan1  proto kernel  scope host  src
> 192.168.0.11
>   local 192.168.0.10 dev wlan0  proto kernel  scope host  src
> 192.168.0.10
>   broadcast 192.168.0.0 dev wlan0  proto kernel  scope link  src
> 192.168.0.10
>   broadcast 192.168.0.0 dev wlan1  proto kernel  scope link  src
> 192.168.0.11
>
> So I try to swap the sources also in this table for each device
>
>   dave:/home/dave# ip route change table local local 192.168.0.10 dev
> wlan1 \
> 		  proto kernel scope host src 192.168.0.11
>   dave:/home/dave# ip route change table local local 192.168.0.11 dev
> wlan0 \
> 		  proto kernel scope host src 192.168.0.10
>
> And this is what i get.
>
>   dave:/home/dave# ip route show table local|grep 192
>   broadcast 192.168.0.255 dev wlan0  proto kernel  scope link  src
> 192.168.0.10
>   broadcast 192.168.0.255 dev wlan1  proto kernel  scope link  src
> 192.168.0.11
>   local 192.168.0.11 dev wlan0  proto kernel  scope host  src
> 192.168.0.10
>   local 192.168.0.10 dev wlan1  proto kernel  scope host  src
> 192.168.0.11
>   broadcast 192.168.0.0 dev wlan0  proto kernel  scope link  src
> 192.168.0.10
>   broadcast 192.168.0.0 dev wlan1  proto kernel  scope link  src
> 192.168.0.11
>
> Again, when i try to ping it goes through the loopback device.  The
> routing cache verifies this again.
>
> It seems that linux is ignoring the routing table for local network
> devices, and forcing the route through the loopback device.  Is there
> any way to get around this?
>
> thanks,
> -dave
> dave at davidwang dot c*m
>
>
>
>
>
> _______________________________________________
> HostAP mailing list
> HostAP at shmoo.com
> http://lists.shmoo.com/mailman/listinfo/hostap
>




More information about the HostAP mailing list