ethertap.txt
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:7k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. NOTE: Ethertap is now an obsolete facility, and is scheduled
  2.       to be removed in the 2.5.x kernel series.  Those writing
  3.       applications using ethertap should convert their code to
  4.       use the TUN/TAP driver instead, see 'tuntap.txt' in this
  5.       directory for more details.  -DaveM
  6. Ethertap programming mini-HOWTO
  7. -------------------------------
  8. The ethertap driver was written by Jay Schulist <jschlst@samba.org>,
  9. you should contact him for further information. This document was written by
  10. bert hubert <bert.hubert@netherlabs.nl>. Updates are welcome.
  11. What ethertap can do for you
  12. ----------------------------
  13. Ethertap allows you to easily run your own network stack from userspace.
  14. Tunnels can benefit greatly from this. You can also use it to do network
  15. experiments. The alternative would be to use a raw socket to send data and
  16. use libpcap to receive it. Using ethertap saves you this multiplicity and
  17. also does ARP for you if you want.
  18. The more technical blurb:
  19. Ethertap provides packet reception and transmission for user space programs.
  20. It can be viewed as a simple Ethernet device, which instead of receiving
  21. packets from a network wire, it receives them from user space.
  22. Ethertap can be used for anything from AppleTalk to IPX to even building
  23. bridging tunnels. It also has many other general purpose uses.
  24. Configuring your kernel
  25. -----------------------
  26. Firstly, you need this in Networking Options:
  27. #
  28. # Code maturity level options
  29. #
  30. CONFIG_EXPERIMENTAL=y
  31. Then you need Netlink support:
  32. CONFIG_NETLINK=y
  33. This allows the kernel to exchange data with userspace applications. There
  34. are two ways of doing this, the new way works with netlink sockets and I
  35. have no experience with that yet. ANK uses it in his excellent iproute2
  36. package, see for example rtmon.c. iproute2 can be found on
  37. ftp://ftp.inr.ac.ru/ip-routing/iproute2*
  38. The new way is described, partly in netlink(7), available on 
  39. http://www.europe.redhat.com/documentation/man-pages/man7/netlink.7.php3
  40. There is also a Netlink-HOWTO, available on http://snafu.freedom.org/linux2.2/docs/netlink-HOWTO.html
  41. Sadly I know of no code using ethertap with this new interface.
  42. The older way works by opening character special files with major node 36.
  43. Enable this with:
  44. CONFIG_NETLINK_DEV=m
  45. Please be advised that this support is going to be dropped somewhere in the
  46. future!
  47. Then finally in the Network Devices section, 
  48. CONFIG_ETHERTAP=m
  49. You can include it directly in the kernel if you want, of course, no need
  50. for modules.
  51. Setting it all up
  52. -----------------
  53. First we need to create the /dev/tap0 device node:
  54. # mknod /dev/tap0 c 36 16
  55. # mknod /dev/tap1 c 36 17
  56. (etc)
  57. Include the relevant modules (ethertap.o, netlink_dev.o, perhaps netlink.o),
  58. and bring up your tap0 device:
  59. # ifconfig tap0 10.0.0.123 up
  60. Now your device is up and running, you can ping it as well. This is what
  61. confused me to no end, because nothing is connected to our ethertap as yet,
  62. how is it that we can ping it?
  63. It turns out that the ethertap is just like a regular network interface -
  64. even when it's down you can ping it. We need to route stuff to it:
  65. # route add -host 10.0.0.124 gw 10.0.0.123
  66. Now we can read /dev/tap0 and when we ping 10.0.0.124 from our
  67. localhost, output should appear on the screen.
  68. # cat /dev/tap0
  69. :遃U:9````````````````````````