lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] tun/tap devices


From: Felipe Massia Pereira
Subject: [lwip-users] Re: [lwip] tun/tap devices
Date: Wed, 08 Jan 2003 23:47:31 -0000

lwIP opens the /dev/net/tun special file and data written to this file
descriptor is sent over the network as an Ethernet frame. The tap0
interface is registered in the kernel at the moment /dev/net/tun is open,
and its address is configured with ifconfig by lwIP as 192.168.0.1. It
will stay like this until the /dev/net/tun is closed (when progarm quits).
So if you type "ifconfig" after running the demo program you will see tap0
in the list, but not when the program is not running anymore. Also, you
should try typing "route" to see that a route was created.

Now, 192.168.0.1 is the tap0 address wich is the gateway between kernel
and lwIP. lwIP uses the /dev/net/tun and kernel uses tap0. It's like the
two endpoints of a pipe.

When you do "ping 192.168.0.1" you are not pinging lwIP, but the kernel
will answer. It's like to ping the loopback device or your own IP address.

The address of lwIP is 192.168.0.2. When you do "ping 192.168.0.2" the
ping program sends an IP packet to the kernel destined to the 192.168.0.2
address. Kernel then will use the routing table to determine which
interface should be this packet sent to. It will see that packets to the
192.168.0 network should be sent through interface tap0. Just like a
normal Ethernet interface. Kernel does not know yet the MAC address of
192.168.0.2, so it will send an ARP REQUEST, to the 192.168.0.255
broadcast address. This request will get caught by lwIP that will reply
with an ARP REPLY (since someone is asking for its address). After that,
kernel now knows the MAC address of lwIP and can now send through tap0 the
IP packet (the "ping") inside an Ethernet frame. This frame will have the
destination address equal to the MAC address answered by lwIP.

The only difference between tap0 and eth0 is that frames sent through eth0
will be received by a real adapter while frames sent through tap0 will be
received by a process (in our case, lwIP).

In fact, when I say kernel I refer to the Linux TCP/IP stack. But it's in
the kernel anyway :)

Try this:
. Open 3 xterms
. in the 1st, execute simhost
. 2nd, execute "tcpdump -i tap0"
. 3rd, type "ping -c 1 192.168.0.2"

Other references:
./src/arch/unix/netif/tapif.c
./proj/unix/main.c
http://vtun.sourceforge.net/tun (home of tun/tap driver, has some FAQs)

[]s good luck,
Felipe

On Mon, 23 Sep 2002, ERIC MAHLAKO wrote:

> Can anyone tells me how the LWip uses the tun/tap
> devices.
> 
> Eric
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
> [This message was sent through the lwip discussion list.]
> 

[This message was sent through the lwip discussion list.]




reply via email to

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