lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] [lwip] Testing tun/tap interfaces


From: Adam Dunkels
Subject: [lwip-users] [lwip] Testing tun/tap interfaces
Date: Wed, 08 Jan 2003 21:46:54 -0000

Hi all!

Because of the recent discussion, I thought I'd describe how I went about for 
testing the tun and tap interfaces under BSD and Linux.

** The tun interface:

The tun interface is a virtual point-to-point network interface, which works 
as any normal network interface in the BSD/Linux kernels with the exception 
that packets are not written to a hardware device, but are written to a file 
that can be read by a user process. For the tun device, this file is called 
/dev/tunX, where X is a number (usually) between 0 and 3 (this means that 
multiple tun interfaces can be used simultaneously).

In order to use a tun interface, a process must be reading the tunX file. 
This can simply be done with "cat /dev/tun0", but since IP packets contain 
all kinds of bytes, this will mess up the xterm output. I prefer to run 
"hexdump /dev/tun0" instead. This must be done as root. The hexdump will 
hang, waiting for data to arrive on the tun interface. 

Now, the tun interface must be configured with an IP address. I believe this 
is the step that differs on BSDs and Linux. On FreeBSD, the following command 
will set the IP address of the tun interface to 192.168.0.1, and the IP 
address of the other end of the virtual point-to-point link (i.e., the IP 
address of the "hexdump" process) to 192.168.0.2:

# ifconfig tun0 192.168.0.1 192.168.0.2

I am not sure if Linux works the same, but if not, it might be worthwhile to 
try those two commands:

# ifconfig tun0 inet 192.168.0.1
# ifconfig tun0 dstaddr 192.168.0.2

Or perhaps a combination of the three commands above.

Now, check the configuration of the tun0 interface with "ifconfig tun0". If 
everying is working correctly, it should now be possible to ping the 
"hexdump" process:

> ping 192.168.0.2

The result should be that the ping packet is displayed in hexadecimal in the 
xterm window running the "hexdump" process! (I found this to be very cool 
first time I saw it :-)

** The tap interface:

The tap interface is similar to the tun interface, but instead of providing a 
virtual point-to-point link, it provides a virtual Ethernet link. I haven't 
tried it, but it might be possible to attach many processes to the tap 
interface and run it as a normal Ethernet.

It should be possible to repeat the above steps but replace "tun" with "tap". 
The only place where it differs is when the IP address is configured. Since 
the tap interface is like an Ethernet, only the IP address of the BSD/Linux 
kernel side needs to be configured. One of the below commands should work:

# ifconfig tap0 192.168.0.2

# ifconfig tap0 inet 192.168.0.2

This time, the "ping 192.168.0.2" doesn't make the ping packet show up in the 
hexdump window. Instead, it is the ARP request for the IP address 192.168.0.2 
that is seen.

Hope this information helps. If someone gets this to work under Linux, I 
modify the tapif.c and tunif.c files so that they will work under Linux too.

/adam
-- 
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]




reply via email to

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