diff options
84 files changed, 843 insertions, 696 deletions
diff --git a/Documentation/networking/tuntap.txt b/Documentation/networking/tuntap.txt index c0aab985bad9..949d5dcdd9a3 100644 --- a/Documentation/networking/tuntap.txt +++ b/Documentation/networking/tuntap.txt | |||
| @@ -105,6 +105,83 @@ Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com> | |||
| 105 | Proto [2 bytes] | 105 | Proto [2 bytes] |
| 106 | Raw protocol(IP, IPv6, etc) frame. | 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. | ||
