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

docs: networking: convert tuntap.txt to ReST

- add SPDX header;
- use copyright symbol;
- adjust titles and chapters, adding proper markups;
- mark code blocks and literals as such;
- adjust identation, whitespaces and blank lines where needed;
- add to networking/index.rst.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Mauro Carvalho Chehab and committed by
David S. Miller
973d55e5 ef891284

+119 -86
+1
Documentation/networking/index.rst
··· 111 111 team 112 112 timestamping 113 113 tproxy 114 + tuntap 114 115 115 116 .. only:: subproject and html 116 117
+116 -84
Documentation/networking/tuntap.txt Documentation/networking/tuntap.rst
··· 1 - Universal TUN/TAP device driver. 2 - Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com> 1 + .. SPDX-License-Identifier: GPL-2.0 2 + .. include:: <isonum.txt> 3 3 4 - Linux, Solaris drivers 5 - Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com> 4 + =============================== 5 + Universal TUN/TAP device driver 6 + =============================== 6 7 7 - FreeBSD TAP driver 8 - Copyright (c) 1999-2000 Maksim Yevmenkin <m_evmenkin@yahoo.com> 8 + Copyright |copy| 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com> 9 + 10 + Linux, Solaris drivers 11 + Copyright |copy| 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com> 12 + 13 + FreeBSD TAP driver 14 + Copyright |copy| 1999-2000 Maksim Yevmenkin <m_evmenkin@yahoo.com> 9 15 10 16 Revision of this document 2002 by Florian Thiel <florian.thiel@gmx.net> 11 17 12 18 1. Description 13 - TUN/TAP provides packet reception and transmission for user space programs. 19 + ============== 20 + 21 + TUN/TAP provides packet reception and transmission for user space programs. 14 22 It can be seen as a simple Point-to-Point or Ethernet device, which, 15 - instead of receiving packets from physical media, receives them from 16 - user space program and instead of sending packets via physical media 17 - writes them to the user space program. 23 + instead of receiving packets from physical media, receives them from 24 + user space program and instead of sending packets via physical media 25 + writes them to the user space program. 18 26 19 27 In order to use the driver a program has to open /dev/net/tun and issue a 20 28 corresponding ioctl() to register a network device with the kernel. A network ··· 41 33 br_sigio.c - bridge based on async io and SIGIO signal. 42 34 However, the best example is VTun http://vtun.sourceforge.net :)) 43 35 44 - 2. Configuration 45 - Create device node: 36 + 2. Configuration 37 + ================ 38 + 39 + Create device node:: 40 + 46 41 mkdir /dev/net (if it doesn't exist already) 47 42 mknod /dev/net/tun c 10 200 48 - 49 - Set permissions: 43 + 44 + Set permissions:: 45 + 50 46 e.g. chmod 0666 /dev/net/tun 51 - There's no harm in allowing the device to be accessible by non-root users, 52 - since CAP_NET_ADMIN is required for creating network devices or for 53 - connecting to network devices which aren't owned by the user in question. 54 - If you want to create persistent devices and give ownership of them to 55 - unprivileged users, then you need the /dev/net/tun device to be usable by 56 - those users. 47 + 48 + There's no harm in allowing the device to be accessible by non-root users, 49 + since CAP_NET_ADMIN is required for creating network devices or for 50 + connecting to network devices which aren't owned by the user in question. 51 + If you want to create persistent devices and give ownership of them to 52 + unprivileged users, then you need the /dev/net/tun device to be usable by 53 + those users. 57 54 58 55 Driver module autoloading 59 56 60 57 Make sure that "Kernel module loader" - module auto-loading 61 58 support is enabled in your kernel. The kernel should load it on 62 59 first access. 63 - 64 - Manual loading 65 - insert the module by hand: 66 - modprobe tun 60 + 61 + Manual loading 62 + 63 + insert the module by hand:: 64 + 65 + modprobe tun 67 66 68 67 If you do it the latter way, you have to load the module every time you 69 68 need it, if you do it the other way it will be automatically loaded when 70 69 /dev/net/tun is being opened. 71 70 72 - 3. Program interface 73 - 3.1 Network device allocation: 71 + 3. Program interface 72 + ==================== 74 73 75 - char *dev should be the name of the device with a format string (e.g. 76 - "tun%d"), but (as far as I can see) this can be any valid network device name. 77 - Note that the character pointer becomes overwritten with the real device name 78 - (e.g. "tun0") 74 + 3.1 Network device allocation 75 + ----------------------------- 76 + 77 + ``char *dev`` should be the name of the device with a format string (e.g. 78 + "tun%d"), but (as far as I can see) this can be any valid network device name. 79 + Note that the character pointer becomes overwritten with the real device name 80 + (e.g. "tun0"):: 79 81 80 82 #include <linux/if.h> 81 83 #include <linux/if_tun.h> ··· 96 78 int fd, err; 97 79 98 80 if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) 99 - return tun_alloc_old(dev); 81 + return tun_alloc_old(dev); 100 82 101 83 memset(&ifr, 0, sizeof(ifr)); 102 84 103 - /* Flags: IFF_TUN - TUN device (no Ethernet headers) 104 - * IFF_TAP - TAP device 85 + /* Flags: IFF_TUN - TUN device (no Ethernet headers) 86 + * IFF_TAP - TAP device 105 87 * 106 - * IFF_NO_PI - Do not provide packet information 107 - */ 108 - ifr.ifr_flags = IFF_TUN; 88 + * IFF_NO_PI - Do not provide packet information 89 + */ 90 + ifr.ifr_flags = IFF_TUN; 109 91 if( *dev ) 110 - strncpy(ifr.ifr_name, dev, IFNAMSIZ); 92 + strncpy(ifr.ifr_name, dev, IFNAMSIZ); 111 93 112 94 if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){ 113 - close(fd); 114 - return err; 95 + close(fd); 96 + return err; 115 97 } 116 98 strcpy(dev, ifr.ifr_name); 117 99 return fd; 118 - } 119 - 120 - 3.2 Frame format: 121 - If flag IFF_NO_PI is not set each frame format is: 100 + } 101 + 102 + 3.2 Frame format 103 + ---------------- 104 + 105 + If flag IFF_NO_PI is not set each frame format is:: 106 + 122 107 Flags [2 bytes] 123 108 Proto [2 bytes] 124 109 Raw protocol(IP, IPv6, etc) frame. 125 110 126 - 3.3 Multiqueue tuntap interface: 111 + 3.3 Multiqueue tuntap interface 112 + ------------------------------- 127 113 128 - From version 3.8, Linux supports multiqueue tuntap which can uses multiple 129 - file descriptors (queues) to parallelize packets sending or receiving. The 130 - device allocation is the same as before, and if user wants to create multiple 131 - queues, TUNSETIFF with the same device name must be called many times with 132 - IFF_MULTI_QUEUE flag. 114 + From version 3.8, Linux supports multiqueue tuntap which can uses multiple 115 + file descriptors (queues) to parallelize packets sending or receiving. The 116 + device allocation is the same as before, and if user wants to create multiple 117 + queues, TUNSETIFF with the same device name must be called many times with 118 + IFF_MULTI_QUEUE flag. 133 119 134 - char *dev should be the name of the device, queues is the number of queues to 135 - be created, fds is used to store and return the file descriptors (queues) 136 - created to the caller. Each file descriptor were served as the interface of a 137 - queue which could be accessed by userspace. 120 + ``char *dev`` should be the name of the device, queues is the number of queues 121 + to be created, fds is used to store and return the file descriptors (queues) 122 + created to the caller. Each file descriptor were served as the interface of a 123 + queue which could be accessed by userspace. 124 + 125 + :: 138 126 139 127 #include <linux/if.h> 140 128 #include <linux/if_tun.h> ··· 151 127 int fd, err, i; 152 128 153 129 if (!dev) 154 - return -1; 130 + return -1; 155 131 156 132 memset(&ifr, 0, sizeof(ifr)); 157 133 /* Flags: IFF_TUN - TUN device (no Ethernet headers) ··· 164 140 strcpy(ifr.ifr_name, dev); 165 141 166 142 for (i = 0; i < queues; i++) { 167 - if ((fd = open("/dev/net/tun", O_RDWR)) < 0) 168 - goto err; 169 - err = ioctl(fd, TUNSETIFF, (void *)&ifr); 170 - if (err) { 171 - close(fd); 172 - goto err; 173 - } 174 - fds[i] = fd; 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; 175 151 } 176 152 177 153 return 0; 178 154 err: 179 155 for (--i; i >= 0; i--) 180 - close(fds[i]); 156 + close(fds[i]); 181 157 return err; 182 158 } 183 159 184 - A new ioctl(TUNSETQUEUE) were introduced to enable or disable a queue. When 185 - calling it with IFF_DETACH_QUEUE flag, the queue were disabled. And when 186 - calling it with IFF_ATTACH_QUEUE flag, the queue were enabled. The queue were 187 - enabled by default after it was created through TUNSETIFF. 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. 188 164 189 - fd is the file descriptor (queue) that we want to enable or disable, when 190 - enable is true we enable it, otherwise we disable it 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:: 191 167 192 168 #include <linux/if.h> 193 169 #include <linux/if_tun.h> ··· 199 175 memset(&ifr, 0, sizeof(ifr)); 200 176 201 177 if (enable) 202 - ifr.ifr_flags = IFF_ATTACH_QUEUE; 178 + ifr.ifr_flags = IFF_ATTACH_QUEUE; 203 179 else 204 - ifr.ifr_flags = IFF_DETACH_QUEUE; 180 + ifr.ifr_flags = IFF_DETACH_QUEUE; 205 181 206 182 return ioctl(fd, TUNSETQUEUE, (void *)&ifr); 207 183 } 208 184 209 - Universal TUN/TAP device driver Frequently Asked Question. 210 - 185 + Universal TUN/TAP device driver Frequently Asked Question 186 + ========================================================= 187 + 211 188 1. What platforms are supported by TUN/TAP driver ? 189 + 212 190 Currently driver has been written for 3 Unices: 213 - Linux kernels 2.2.x, 2.4.x 214 - FreeBSD 3.x, 4.x, 5.x 215 - Solaris 2.6, 7.0, 8.0 191 + 192 + - Linux kernels 2.2.x, 2.4.x 193 + - FreeBSD 3.x, 4.x, 5.x 194 + - Solaris 2.6, 7.0, 8.0 216 195 217 196 2. What is TUN/TAP driver used for? 218 - As mentioned above, main purpose of TUN/TAP driver is tunneling. 197 + 198 + As mentioned above, main purpose of TUN/TAP driver is tunneling. 219 199 It is used by VTun (http://vtun.sourceforge.net). 220 200 221 201 Another interesting application using TUN/TAP is pipsecd 222 202 (http://perso.enst.fr/~beyssac/pipsec/), a userspace IPSec 223 203 implementation that can use complete kernel routing (unlike FreeS/WAN). 224 204 225 - 3. How does Virtual network device actually work ? 205 + 3. How does Virtual network device actually work ? 206 + 226 207 Virtual network device can be viewed as a simple Point-to-Point or 227 - Ethernet device, which instead of receiving packets from a physical 228 - media, receives them from user space program and instead of sending 229 - packets via physical media sends them to the user space program. 208 + Ethernet device, which instead of receiving packets from a physical 209 + media, receives them from user space program and instead of sending 210 + packets via physical media sends them to the user space program. 230 211 231 212 Let's say that you configured IPv6 on the tap0, then whenever 232 213 the kernel sends an IPv6 packet to tap0, it is passed to the application 233 - (VTun for example). The application encrypts, compresses and sends it to 214 + (VTun for example). The application encrypts, compresses and sends it to 234 215 the other side over TCP or UDP. The application on the other side decompresses 235 - and decrypts the data received and writes the packet to the TAP device, 216 + and decrypts the data received and writes the packet to the TAP device, 236 217 the kernel handles the packet like it came from real physical device. 237 218 238 219 4. What is the difference between TUN driver and TAP driver? 220 + 239 221 TUN works with IP frames. TAP works with Ethernet frames. 240 222 241 223 This means that you have to read/write IP packets when you are using tun and 242 224 ethernet frames when using tap. 243 225 244 226 5. What is the difference between BPF and TUN/TAP driver? 227 + 245 228 BPF is an advanced packet filter. It can be attached to existing 246 229 network interface. It does not provide a virtual network interface. 247 230 A TUN/TAP driver does provide a virtual network interface and it is possible 248 231 to attach BPF to this interface. 249 232 250 233 6. Does TAP driver support kernel Ethernet bridging? 251 - Yes. Linux and FreeBSD drivers support Ethernet bridging. 234 + 235 + Yes. Linux and FreeBSD drivers support Ethernet bridging.
+1 -1
MAINTAINERS
··· 17161 17161 M: Maxim Krasnyansky <maxk@qti.qualcomm.com> 17162 17162 S: Maintained 17163 17163 W: http://vtun.sourceforge.net/tun 17164 - F: Documentation/networking/tuntap.txt 17164 + F: Documentation/networking/tuntap.rst 17165 17165 F: arch/um/os-Linux/drivers/ 17166 17166 17167 17167 TURBOCHANNEL SUBSYSTEM
+1 -1
drivers/net/Kconfig
··· 355 355 devices, driver will automatically delete tunXX or tapXX device and 356 356 all routes corresponding to it. 357 357 358 - Please read <file:Documentation/networking/tuntap.txt> for more 358 + Please read <file:Documentation/networking/tuntap.rst> for more 359 359 information. 360 360 361 361 To compile this driver as a module, choose M here: the module