Tundra - TUN Devices for Elixir

Probably a bit niche, but I pushed Tundra to hex.pm today. It provides a way to create and use non-persistent TUN devices on both Linux and Darwin. It has a consistent api on both platforms, similar to Erlang’s socket api, although currently only non-blocking i/o is supported.

On Darwin, the TUN device is a socket, and tundra provides only a very thin layer over the top of the socket API, once created. On Linux, TUN devices are files so, internally, a NIF is used to manage the file descriptor and its non-blocking i/o.

Due to TUN creation being a privileged operation, a server program is used to do the initial device creation and configuration. This ships in the priv directory of the application, but how this executable is started is left as an exercise for the reader. On both platforms, the NIF communicates with the server over a domain socket to create and configure the device.

7 Likes

What are TUN devices? I Know I can search Google, but will be nice to have a link in the topic for people unfamiliar with this niche, like me :slight_smile:

2 Likes

They are virtual network interfaces, implemented in the kernel but with a user mode program (your code) responsible for handling the actual packets.

For TUN devices, each packet is a complete IP packet, either v4 or v6, typically itself encapsulating some other protocol e.g. tcp, udp, icmp etc.

They’re commonly used for VPNs.

4 Likes