1 .\" $NetBSD: tun.4,v 1.1 1996/06/25 22:17:37 pk Exp $
10 .Nd tunnel software network interface
16 interface is a software loopback mechanism that can be loosely
17 described as the network interface analog of the
21 does for network interfaces what the
23 driver does for terminals.
29 driver, provides two interfaces: an interface like the usual facility
31 (a network interface in the case of
35 and a character-special device
39 The network interfaces are named
42 etc., one for each control device that has been opened.
43 These network interfaces persist until the
45 module is unloaded, or until removed with the
50 devices are created using interface cloning.
51 This is done using the
52 .Dq ifconfig tun Ns Sy N No create
54 This is the preferred method of creating
57 The same method allows removal of interfaces.
59 .Dq ifconfig tun Ns Sy N No destroy
65 .Va net.link.tun.devfs_cloning
69 permits opens on the special control device
71 When this device is opened,
73 will return a handle for the lowest unused
80 Disabling the legacy devfs cloning functionality may break existing
81 applications which use
87 It therefore defaults to being enabled until further notice.
90 Control devices (once successfully opened) persist until
92 is unloaded in the same way that network interfaces persist (see above).
94 Each interface supports the usual network-interface
98 and thus can be used with
100 like any other interface.
101 At boot time, they are
103 interfaces, but this can be changed; see the description of the control
105 When the system chooses to transmit a packet on the
106 network interface, the packet can be read from the control device
110 writing a packet to the control device generates an input
111 packet on the network interface, as if the (non-existent)
112 hardware had just received it.
115 .Pq Pa /dev/tun Ns Ar N
117 (it cannot be opened if it is already open).
120 call will return an error
122 if the interface is not
124 (which means that the control device is open and the interface's
125 address has been set).
127 Once the interface is ready,
129 will return a packet if one is available; if not, it will either block
130 until one is or return
132 depending on whether non-blocking I/O has been enabled.
133 If the packet is longer than is allowed for in the buffer passed to
135 the extra data will be silently dropped.
139 ioctl has been set, packets read from the control device will be prepended
140 with the destination address as presented to the network interface output
143 The destination address is in
146 The actual length of the prepended address is in the member
150 ioctl has been set, packets will be prepended with a four byte address
151 family in network byte order.
155 are mutually exclusive.
156 In any case, the packet data follows immediately.
160 call passes a packet in to be
162 on the pseudo-interface.
165 ioctl has been set, the address family must be prepended, otherwise the
166 packet is assumed to be of type
170 call supplies exactly one packet; the packet length is taken from the
171 amount of data provided to
173 (minus any supplied address family).
174 Writes will not block; if the packet cannot be accepted for a
176 (e.g., no buffer space available),
177 it is silently dropped; if the reason is not transient
178 (e.g., packet too large),
179 an error is returned.
186 .Bl -tag -width ".Dv TUNSIFMODE"
188 The argument should be a pointer to an
190 this sets the internal debugging variable to that value.
191 What, if anything, this variable controls is not documented here; see
194 The argument should be a pointer to an
196 this stores the internal debugging variable's value into it.
198 The argument should be a pointer to an
200 and allows setting the MTU, the type, and the baudrate of the tunnel
207 The use of this ioctl is restricted to the super-user.
209 The argument should be a pointer to an
211 where the current MTU, type, and baudrate will be stored.
213 The argument should be a pointer to an
215 its value must be either
221 OR'd into the value if multicast support is required.
222 The type of the corresponding
224 interface is set to the supplied type.
225 If the value is outside the above range, an
228 The interface must be down at the time; if it is up, an
232 The argument should be a pointer to an
234 a non-zero value turns off
238 mode, causing packets read from the tunnel device to be prepended with
239 the network destination address (see above).
241 Will set the pid owning the tunnel device to the current process's pid.
243 The argument should be a pointer to an
245 a non-zero value turns off
249 mode, where every packet is preceded with a four byte address family.
251 The argument should be a pointer to an
253 the ioctl sets the value to one if the device is in
255 mode, and zero otherwise.
257 Turn non-blocking I/O for reads off or on, according as the argument
259 value is or is not zero.
260 (Writes are always non-blocking.)
262 Turn asynchronous I/O for reads
265 when data is available to be read)
266 off or on, according as the argument
268 value is or is not zero.
270 If any packets are queued to be read, store the size of the first one
273 otherwise, store zero.
275 Set the process group to receive
277 signals, when asynchronous I/O is enabled, to the argument
281 Retrieve the process group value for
283 signals into the argument
288 The control device also supports
290 for read; selecting for write is pointless, and always succeeds, since
291 writes are always non-blocking.
293 On the last close of the data device, by default, the interface is
296 .Nm ifconfig Ar tunN Cm down ) .
297 All queued packets are thrown away.
298 If the interface is up when the data device is not open
299 output packets are always thrown away rather than letting
312 This manual page was originally obtained from