ethertap.txt
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:7k
- NOTE: Ethertap is now an obsolete facility, and is scheduled
- to be removed in the 2.5.x kernel series. Those writing
- applications using ethertap should convert their code to
- use the TUN/TAP driver instead, see 'tuntap.txt' in this
- directory for more details. -DaveM
- Ethertap programming mini-HOWTO
- -------------------------------
- The ethertap driver was written by Jay Schulist <jschlst@samba.org>,
- you should contact him for further information. This document was written by
- bert hubert <bert.hubert@netherlabs.nl>. Updates are welcome.
- What ethertap can do for you
- ----------------------------
- Ethertap allows you to easily run your own network stack from userspace.
- Tunnels can benefit greatly from this. You can also use it to do network
- experiments. The alternative would be to use a raw socket to send data and
- use libpcap to receive it. Using ethertap saves you this multiplicity and
- also does ARP for you if you want.
- The more technical blurb:
- 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.
- Configuring your kernel
- -----------------------
- Firstly, you need this in Networking Options:
- #
- # Code maturity level options
- #
- CONFIG_EXPERIMENTAL=y
- Then you need Netlink support:
- CONFIG_NETLINK=y
- This allows the kernel to exchange data with userspace applications. There
- are two ways of doing this, the new way works with netlink sockets and I
- have no experience with that yet. ANK uses it in his excellent iproute2
- package, see for example rtmon.c. iproute2 can be found on
- ftp://ftp.inr.ac.ru/ip-routing/iproute2*
- The new way is described, partly in netlink(7), available on
- http://www.europe.redhat.com/documentation/man-pages/man7/netlink.7.php3
- There is also a Netlink-HOWTO, available on http://snafu.freedom.org/linux2.2/docs/netlink-HOWTO.html
- Sadly I know of no code using ethertap with this new interface.
- The older way works by opening character special files with major node 36.
- Enable this with:
- CONFIG_NETLINK_DEV=m
- Please be advised that this support is going to be dropped somewhere in the
- future!
- Then finally in the Network Devices section,
- CONFIG_ETHERTAP=m
- You can include it directly in the kernel if you want, of course, no need
- for modules.
- Setting it all up
- -----------------
- First we need to create the /dev/tap0 device node:
- # mknod /dev/tap0 c 36 16
- # mknod /dev/tap1 c 36 17
- (etc)
- Include the relevant modules (ethertap.o, netlink_dev.o, perhaps netlink.o),
- and bring up your tap0 device:
- # ifconfig tap0 10.0.0.123 up
- Now your device is up and running, you can ping it as well. This is what
- confused me to no end, because nothing is connected to our ethertap as yet,
- how is it that we can ping it?
- It turns out that the ethertap is just like a regular network interface -
- even when it's down you can ping it. We need to route stuff to it:
- # route add -host 10.0.0.124 gw 10.0.0.123
- Now we can read /dev/tap0 and when we ping 10.0.0.124 from our
- localhost, output should appear on the screen.
- # cat /dev/tap0
- :遃U:9````````````````````````