Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - ethernet loopback with multiple/different IP addresses on the same device/board: (10 Items)
   
ethernet loopback with multiple/different IP addresses on the same device/board  
I have a board that uses the MPC8347 cpu. This board has three separate
IP addresses on it; en0, en1, en2. 
I am using en0 connected to my pc network for downloading files etc.  

I am trying to create a functional loopback test for en1 and en2 where I
connect them via a cross-over cable.  
I wrote two quick applications using UDP sockets to sendto and recvfrom
a command line address... 
When I run them, everything appears to work fine (send: packet =
"123456", recv: packet = "123456").  

The problem comes when I disconnect the loopback. The same messages
appear.  It appears QNX knows the  two IP addresses are on the same
machine and bypasses the external connection. I read up all about route
and ifconfig but must be missing something. Is this a limitation within
QNX, or do I have to configure something differently?

I am running io-net and it is setup with dhcp.clients. Also I ifconfig
each en# at boot up
RE: ethernet loopback with multiple/different IP addresses on the same device/board  
I would just run two instances of io-net on en1
and en2 to avoid any confusion.

Probably too simple, though  :)

--
aboyd
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
> The problem comes when I disconnect the loopback. The same messages
> appear.  It appears QNX knows the  two IP addresses are on the same
> machine and bypasses the external connection. I read up all about route
> and ifconfig but must be missing something. Is this a limitation within
> QNX, or do I have to configure something differently?
>    

You're seeing expected behavior of any networking stack. Even in host 
mode stacks, the packets sent to any locally assigned address will get 
handled locally.

What you may want to do is run two separate networking stacks, like 
Andrew suggested. Alternatively, I believe you can use socket options to 
bind to an interface (SO_BINDTODEVICE) and bypass routing (SO_DONTROUTE) 
when sending to force the packet out a particular interface. Or, yet 
another alternative, you may also be able to set up some clever pf rules.

/P
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
I attempted to try a few of your suggestions... and I am awaiting a response from the SW guys on starting a 2nd instance
 of io-net for the specific devices... But I'm not getting SO_BINDTODEVICE or SO_DONTROUTE to work. Here is some of the 
code:

/*
   struct addrinfo iface, *s_addrinfo_snd;
   const char * iname3 = "en3";

   memset(&iface, 0, sizeof iface);
   iface.ai_family = AF_UNSPEC; 
   iface.ai_socktype = SOCK_DGRAM;
   iface.ai_flags = AI_PASSIVE; 

   if(getaddrinfo("128.0.0.3", MYPORT, &iface, &s_addrinfo_snd) != 0)
      printf("failed getaddrinfo: \n");

   if(snd_sock_hndl = socket(s_addrinfo_snd->ai_family, 
                                             s_addrinfo_snd->ai_socktype, 
                                             s_addrinfo_snd->ai_protocol)  == -1)
         printf("failed to create sending socket\n");

   if(setsockopt(snd_sock_hndl, SOL_SOCKET, SO_BINDTODEVICE, 
                         iname3, sizeof(iname3)) == -1)
      printf("setsockopt: can't bind to send device\n");
*/

BTW; if i do create a second instance of io-net... will the new iname3 become:
     "/dev/io-net2/en3"
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
On 18/02/10 03:46 PM, mike gerlach wrote:
> But I'm not getting SO_BINDTODEVICE or SO_DONTROUTE to work.
What is it that isn't working?
> Here is some of the code:
>    
I didn't see SO_DONTROUTE in your code, only SO_BINDTODEVICE, could that 
be your problem?

> BTW; if i do create a second instance of io-net... will the new iname3 become:
>       "/dev/io-net2/en3"
>    
No, you should be able to use SOCK env var to direct the your socket 
library calls to use the second stack instance. Please see the wiki.

/P
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
sorry, i only posted a few lines of code. Both setsockopt return -1
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
Ok, and what's errno?
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
OK. I changed my process around since I had no luck with the direct loopback method... I probably should re-start this 
post under SW discussion... but here it goes anyway since you know the history.

Instead of doing a direct loopback, I run each interface (en1, en2, en3) into a hub. The hub goes into a test PC.

option 1: *** prefer this method so I can communicate to each device directly
- have 3 seperate IP addresses on the test PC named 128.1.0.100, 128.2.0.100, and 128.3.0.100 
- configure the devices as
   ifconfig en1 128.1.0.1
   ifconfig en2 128.2.0.1
   ifconfig en3 128.3.0.1

option 2:
- have 1 address on the test PC named 128.1.0.100
- configure the devices as
   ifconfig en1 128.1.0.1
   ifconfig en2 128.1.0.2
   ifconfig en3 128.1.0.3
and setsockopt SO_BINDTODEVICE within my test program to ensure each device is actually sending the data.

Either way, I have an echo server running on the test pc configured to a specific port. My test program creates the 
socket, connects to the echo server, sends some data, and reads/verifies the incomming data is valid (from the correct 
device). 

Everything works with one problem that I believe has to do with the route table, but I don't know how to set it up

Here is the problem:
After setting the ifconfig commands I can not ping to 128.X.0.100. When I do, it just sits there. ***As it sits there***
, if I ping from windows to the specific device, both start to work (i.e. ping works to/from). If I ping from windows to
 all the devices all will work and my test program will work. So it seems something is not updating the routing tables 
and the ping forces the system to learn it.  Since this is a test program, I don't want the test PC (echo server) to 
start the process, I want it to just sit there and echo back once the devices start the test.  Is this something with 
the routing?

attached is the route tables before/after. Please ignore en0 and lo0 for now. Eventually en0 will also be hooked up to 
the hub and echo server.
Attachment: Text FBCPU_routing.txt 2.37 KB
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
OK. I changed my process around since I had no luck with the direct 
loopback method... I probably should re-start this post under SW 
discussion... but here it goes anyway since you know the history.

Instead of doing a direct loopback, I run each interface (en1, en2, en3) 
into a hub. The hub goes into a test PC.

option 1: *** prefer this method so I can communicate to each device directly
- have 3 seperate IP addresses on the test PC named 128.1.0.100, 128.2.0.100, and 128.3.0.100 
- configure the devices as
   ifconfig en1 128.1.0.1
   ifconfig en2 128.2.0.1
   ifconfig en3 128.3.0.1

option 2:
- have 1 address on the test PC named 128.1.0.100
- configure the devices as
   ifconfig en1 128.1.0.1
   ifconfig en2 128.1.0.2
   ifconfig en3 128.1.0.3
and setsockopt SO_BINDTODEVICE within my test program to 
ensure each device is actually sending the data.

Either way, I have an echo server running on the test pc configured 
to a specific port. My test program creates the socket, connects to 
the echo server, sends some data, and reads/verifies the incomming 
data is valid (from the correct device). 

Everything works with one problem that I believe has to do with the 
route table, but I don't know how to set it up

Here is the problem:
After setting the ifconfig commands I can not ping to 128.X.0.100. 
When I do, it just sits there. ***As it sits there***, if I ping from windows 
to the specific device, both start to work (i.e. ping works to/from). If I 
ping from windows to all the devices all will work and my test program 
will work. So it seems something is not updating the routing tables and 
the ping forces the system to learn it.  Since this is a test program, I 
don't want the test PC (echo server) to start the process, I want it to 
just sit there and echo back once the devices start the test.  Is this 
something with the routing?

attached is the route tables before/after. Please ignore en0 and lo0 for 
now. Eventually en0 will also be hooked up to the hub and echo server.
Attachment: Text FBCPU_routing.txt 2.37 KB
Re: ethernet loopback with multiple/different IP addresses on the same device/board  
Hi

Looks like some issue with ARP resolution.

You can try putting sniffer/wireshark on each interface of test PC and see if your device sends ARP request when you 
ping. You can run your experiment and capture the entire thing on wireshark.

Analysis of that might be able to help you.

VG