[lwip-users] Communication between different subnets

195 views
Skip to first unread message

hellish

unread,
Sep 14, 2010, 5:04:20 AM9/14/10
to lwip-...@nongnu.org

Hi!
Recently I ported lwip 1.3.2 to my board running FreeRTOS and is now
doing some experiment within my school LAN.
Both my board and my PC are connected to school LAN via an 8-port switch
in my room. Their network interfaces are configured by DHCP. My board is
able to communicate with my PC(and any other PCs on the same subnet). But my
board can't connect to devices that reside on another subnet(for example,
the school FTP server) , while my PC can download files from that FTP just
fine.
I checked lwip's source code and it says:
* For unicast addresses, the packet is submitted to etharp_query(). In
* case the IP address is outside the local network, the IP address of
* the gateway is used.
So lwip modified destination IP address of the packets(sent from my
board) to that of the gateway? This confused me. Why change the destination
IP address? According to my network textbook, it is the destination MAC
address that should be changed to that of the gateway.

Could someone provide guidance as to how to communicate with devices on
another subnet using lwip? Thanks in advance.

Attached below is a snapshot of the network status:
My computer: /IP/ 172.20.123.144 /subnet mask/ 255.255.254.0 /default
gateway/ 172.20.122.1
My board running lwip: /IP/ 172.20.122.224 /subnet mask/ 255.255.254.0
/default gateway/ 172.20.122.1
school FTP server: IP 172.20.106.31

--
View this message in context: http://old.nabble.com/Communication-between-different-subnets-tp29706546p29706546.html
Sent from the lwip-users mailing list archive at Nabble.com.


_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users

Kieran Mansley

unread,
Sep 14, 2010, 5:22:53 AM9/14/10
to Mailing list for lwIP users
On Tue, 2010-09-14 at 02:04 -0700, hellish wrote:
> * For unicast addresses, the packet is submitted to etharp_query().
> In
> * case the IP address is outside the local network, the IP address of
> * the gateway is used.
> So lwip modified destination IP address of the packets(sent from my
> board) to that of the gateway? This confused me. Why change the
> destination
> IP address? According to my network textbook, it is the destination
> MAC
> address that should be changed to that of the gateway.

Yes, your textbook is right. But to find the MAC address of the gateway
we have to use the IP address of the gateway in the lookup. The packet
itself will still be sent with the IP address of the FTP server.

It should just work if you've configured the netif with the gateway
address properly.

Can you get a packet capture to show what's going wrong. You've said it
doesn't work but we need more information about what goes wrong to debug
this problem.

Kieran

Kieran Mansley

unread,
Sep 14, 2010, 5:41:14 AM9/14/10
to Mailing list for lwIP users
On Tue, 2010-09-14 at 10:27 +0100, Bandu wrote:
> You computer Default Gateway address is wrong.

> >>My computer: /IP/ 172.20.123.144 /subnet mask/
> 255.255.254.0 /default
> gateway/ 172.20.122.1
> should be 172.20.123.x
> right?

Why? Looks OK to me. Perhaps you didn't spot his netmask setting?

Kieran

hellish

unread,
Sep 14, 2010, 8:32:52 AM9/14/10
to lwip-...@nongnu.org

Thanks for clearing up the IP destination confusion! Sure, I'll use wireshark
to capture some packets tomorrow.
Then again, I remember doing this yesterday and wireshark didn't see any
packet (from my board to FTP server), hmm....

--
View this message in context: http://old.nabble.com/Communication-between-different-subnets-tp29706546p29708089.html


Sent from the lwip-users mailing list archive at Nabble.com.

Kieran Mansley

unread,
Sep 14, 2010, 8:37:54 AM9/14/10
to Mailing list for lwIP users
On Tue, 2010-09-14 at 05:32 -0700, hellish wrote:
> Thanks for clearing up the IP destination confusion! Sure, I'll use wireshark
> to capture some packets tomorrow.
> Then again, I remember doing this yesterday and wireshark didn't see any
> packet (from my board to FTP server), hmm....

Where were you running wireshark? If on your PC you wouldn't expect it
to see packets as they're not going to or from it. If you can configure
your switch to do port mirroring you might be able to get them that way.
Alternatively get the packet capture by running it on something
mid-stream (e.g. the gateway). That probably isn't an option on your
live school network, so you might need to set up a little network of
your own to reproduce it.

If the traffic level is very low and you can get the console output from
your board you might have luck just using the debug statements in lwIP
to dump details of the packets sent and received. This is potentially
easy to try, though much less useful than a full packet capture.

hellish

unread,
Sep 15, 2010, 3:04:56 AM9/15/10
to lwip-...@nongnu.org

Thanks for your reply!
After some serious debugging today I found that the real problem lies in my
FTP-related code. I thought something was wrong with lwip because of the
somewhat misleading comment in the lwip source code and the fact that
wireshark running on my PC didn't capture any packets.

Lesson learned:
1. When sending packets to non-local subnets, during the lookup stage lwip
changes the destination IP to that of the gateway in order to find gateway's
MAC address. The destination IP of the packet itself remains unchanged.

2. Wireshark can't capture packets that are neither sent or received by the
host.

Thanks again for your detailed suggestions, Kieran!

--
View this message in context: http://old.nabble.com/Communication-between-different-subnets-tp29706546p29715772.html


Sent from the lwip-users mailing list archive at Nabble.com.

Reply all
Reply to author
Forward
0 new messages