Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: docs: document multiqueue tuntap API

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jason Wang and committed by
David S. Miller
f422d2a0 70e21fe4

+77
+77
Documentation/networking/tuntap.txt
··· 105 105 Proto [2 bytes] 106 106 Raw protocol(IP, IPv6, etc) frame. 107 107 108 + 3.3 Multiqueue tuntap interface: 109 + 110 + From version 3.8, Linux supports multiqueue tuntap which can uses multiple 111 + file descriptors (queues) to parallelize packets sending or receiving. The 112 + device allocation is the same as before, and if user wants to create multiple 113 + queues, TUNSETIFF with the same device name must be called many times with 114 + IFF_MULTI_QUEUE flag. 115 + 116 + char *dev should be the name of the device, queues is the number of queues to 117 + be created, fds is used to store and return the file descriptors (queues) 118 + created to the caller. Each file descriptor were served as the interface of a 119 + queue which could be accessed by userspace. 120 + 121 + #include <linux/if.h> 122 + #include <linux/if_tun.h> 123 + 124 + int tun_alloc_mq(char *dev, int queues, int *fds) 125 + { 126 + struct ifreq ifr; 127 + int fd, err, i; 128 + 129 + if (!dev) 130 + return -1; 131 + 132 + memset(&ifr, 0, sizeof(ifr)); 133 + /* Flags: IFF_TUN - TUN device (no Ethernet headers) 134 + * IFF_TAP - TAP device 135 + * 136 + * IFF_NO_PI - Do not provide packet information 137 + * IFF_MULTI_QUEUE - Create a queue of multiqueue device 138 + */ 139 + ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_MULTI_QUEUE; 140 + strcpy(ifr.ifr_name, dev); 141 + 142 + for (i = 0; i < queues; i++) { 143 + if ((fd = open("/dev/net/tun", O_RDWR)) < 0) 144 + goto err; 145 + err = ioctl(fd, TUNSETIFF, (void *)&ifr); 146 + if (err) { 147 + close(fd); 148 + goto err; 149 + } 150 + fds[i] = fd; 151 + } 152 + 153 + return 0; 154 + err: 155 + for (--i; i >= 0; i--) 156 + close(fds[i]); 157 + return err; 158 + } 159 + 160 + A new ioctl(TUNSETQUEUE) were introduced to enable or disable a queue. When 161 + calling it with IFF_DETACH_QUEUE flag, the queue were disabled. And when 162 + calling it with IFF_ATTACH_QUEUE flag, the queue were enabled. The queue were 163 + enabled by default after it was created through TUNSETIFF. 164 + 165 + fd is the file descriptor (queue) that we want to enable or disable, when 166 + enable is true we enable it, otherwise we disable it 167 + 168 + #include <linux/if.h> 169 + #include <linux/if_tun.h> 170 + 171 + int tun_set_queue(int fd, int enable) 172 + { 173 + struct ifreq ifr; 174 + 175 + memset(&ifr, 0, sizeof(ifr)); 176 + 177 + if (enable) 178 + ifr.ifr_flags = IFF_ATTACH_QUEUE; 179 + else 180 + ifr.ifr_flags = IFF_DETACH_QUEUE; 181 + 182 + return ioctl(fd, TUNSETQUEUE, (void *)&ifr); 183 + } 184 + 108 185 Universal TUN/TAP device driver Frequently Asked Question. 109 186 110 187 1. What platforms are supported by TUN/TAP driver ?