What is the use of tun.ko?

Posted on March 3, 2012 @ 2:02 am

The tun.ko file is a device driver(module) that provides packet reception and transmission for user space programs.

The Android OS just like Linux allows you to dynamically load and unload components of the operating system as you need them. These components or modules are lumps of code that can be dynamically linked into the kernel at any point after the system has booted. They can be unlinked from the kernel and removed when they are no longer needed. Mostly these modules are device drivers, pseudo-device drivers such as network drivers, or file-systems. In the case of tun.ko it is a virtual network kernel device. The equivalent of tun.ko in Linux is TUN/TAP or the TAP-Win32 driver in Windows.

You can either load and unload modules explicitly using the insmod and rmmod commands or the kernel itself can demand that the kernel daemon (kerneld) loads and unloads the modules as they are needed.

Tun.ko or the tun driver can be viewed as a simple Point-to-Point or Ethernet device, which instead of receiving packets from a physical media, receives them from user space program and instead of sending packets via physical media writes them to the user space program that attaches itself to the device. A user-space program may also pass packets into the tun device. In this case the tun device delivers (or "injects") these packets to the operating system network stack thus emulating their reception from an external source.

When a vpn application opens /dev/tun, the driver creates and registers corresponding net device tunX or tapX. After a program closed above devices, driver will automatically delete tunXX or tapXX device and all routes corresponding to it. Let's say that you configured tun0 as your default gateway, then whenever kernel sends any IP packet to tun0, it is passed to the application (DroidVPN for example). Application encrypts, compresses and sends it to the other side over TCP,UDP or ICMP. Application on other side decompress and decrypts them and write packet to the TUN device, kernel handles the packet like it came from real physical device.

In simple terms, the tun driver acts like the messenger of your internet traffic. It captures all your internet traffic and passes it to DroidVPN for processing, DroidVPN will then encapsulate those IP frames and pass it to our servers.

Related articles:
Where can I download this tun.ko?

×