summaryrefslogtreecommitdiffstats
path: root/Documentation/networking/ethertap.txt
blob: 27202efbaf1f64c10a9fe2ece1f1e418ce517efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Documentation on setup and use of EtherTap.

Contact Jay Schulist <Jay.Schulist@spacs.k12.wi.us> if you
have questions or need futher assistance.

Introduction
============

Ethertap provides packet reception and transmission for user
space programs. It can be viewed as a simple Ethernet device,
which instead of receiving packets from a network wire, it receives
them from user space.

Ethertap can be used for anything from AppleTalk to IPX to even 
building bridging tunnels. It also has many other general purpose
uses.

Ethertap also can do ARP for you, although this is not enabled by
default.

SetUp
=====

First you will have to enable Ethertap in the kernel configuration.
Then you will need to create any number of ethertap device files,
/dev/tap0->/dev/tap15. This is done by the following command.

mknod /dev/tap* c 36 16  ( 17 18 19 20 for tap1,2,3,4...)

** Replace * with the proper tap device number you need. **

Now with your kernel that has ethertap enabled, you will need
to ifconfig /dev/tap* 192.168.1.1 (replace 192.168.1.1 with the
proper IP number for your situation.)

If you want your Ethertap device to ARP for you would ifconfig
the interface like this: ifconfig tap* 192.168.1.1 arp

Remember that you need to have a corresponding /dev/tap* file
for each tap* device you need to ifconfig.

Now Ethertap should be ready to use.

Diagram of how Ethertap works. (Courtesy of Alan Cox)
====================================================

This is for a tunnel, but you should be able to
get the general idea.

        1.2.3.4 will be the router to the outside world
        1.2.3.5 our box
        2.0.0.1 our box (appletalk side)
        2.0.0.* a pile of macintoys


[1.2.3.4]-------------1.2.3.5[Our Box]2.0.0.1---------> macs

The routing on our box would be

                ifconfig eth0 1.2.3.5 netmask 255.255.255.0 up
                route add default gw 1.2.3.4
                ifconfig tap0   2.0.0.1 netmask 255.255.255.0 up arp
                (route add 2.0.0.0 netmask 255.255.255.0)

C code for a Simple program using an EtherTap device
====================================================

This code is just excerpts from a real program, so some parts are missing
but the important stuff is below.

void main (void)
{
	int TapDevice, eth_pkt_len = 0;
	unsigned char full_pkt_len[MAX_PKT_LEN];

	TapDevice = open("/dev/tap0", O_RDWR);
        if(TapDevice < 0)
        {
                perror("Error opening device");
                exit(1);
        }

	write(TapDevice, full_packet, eth_pkt_len);

	close(TapDevice);

	return;
}