How to create tap network interfaces


#1

I want to create a tap interface to test networking and if I run sudo ip tuntap add tap3 mode tap I get an error:

ubuntu@box316:/dev$ sudo ip tuntap add tap3 mode tap
open: No such file or directory

I then run it with strace Isee that the ‘tun’ character device isn’t available:

ubuntu@box316:/dev$ sudo strace ip tuntap add tap3 mode tap
execve("/sbin/ip", ["ip", "tuntap", "add", "tap3", "mode", "tap"], [/* 14 vars */]) = 0
brk(0)                                  = 0x1baf000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f09c8768000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=74438, ...}) = 0
mmap(NULL, 74438, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f09c8755000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14664, ...}) = 0
mmap(NULL, 2109744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f09c8344000
mprotect(0x7f09c8347000, 2093056, PROT_NONE) = 0
mmap(0x7f09c8546000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f09c8546000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\37\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1840928, ...}) = 0
mmap(NULL, 3949248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f09c7f7f000
mprotect(0x7f09c813a000, 2093056, PROT_NONE) = 0
mmap(0x7f09c8339000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7f09c8339000
mmap(0x7f09c833f000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f09c833f000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f09c8754000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f09c8752000
arch_prctl(ARCH_SET_FS, 0x7f09c8752740) = 0
mprotect(0x7f09c8339000, 16384, PROT_READ) = 0
mprotect(0x7f09c8546000, 4096, PROT_READ) = 0
mprotect(0x646000, 4096, PROT_READ)     = 0
mprotect(0x7f09c876a000, 4096, PROT_READ) = 0
munmap(0x7f09c8755000, 74438)           = 0
socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0) = 3
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=22033, groups=00000000}, [12]) = 0
open("/dev/net/tun", O_RDWR)            = -1 ENOENT (No such file or directory)
dup(2)                                  = 4
fcntl(4, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
brk(0)                                  = 0x1baf000
brk(0x1bd0000)                          = 0x1bd0000
fstat(4, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 7), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f09c8767000
lseek(4, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
write(4, "open: No such file or directory\n", 32open: No such file or directory
) = 32
close(4)                                = 0
munmap(0x7f09c8767000, 4096)            = 0
exit_group(1)                           = ?
+++ exited with 1 +++

We see the error is that /dev/net/tun is cannot be opened:

open("/dev/net/tun", O_RDWR)            = -1 ENOENT (No such file or directory)

And sure enough there is no /dev/net/tun character device:

ubuntu@box175:~$ ls -al /dev/net
total 0
drwxr-xr-x 2 root root  40 Jun  9 20:22 .
drwxr-xr-x 6 root root 500 Jun  9 20:22 ..

Anyone have ideas on what I’m doing wrong or have other suggestions on a work around?


#2

Based on this blog post I would say it it likely not possible.


#3

That’s very sad. I’m creating a runtime for bare metal systems and use qemu for testing and using tap seems to be the correct solution for communicating to outside entities from emulated NICs in qemu. Maybe someone has another solution?


#4