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 and the baudrate of the tunnel
202 The type must be the same as returned by
214 The use of this ioctl is restricted to the super-user.
216 The argument should be a pointer to an
218 where the current MTU, type, and baudrate will be stored.
220 The argument should be a pointer to an
222 its value must be either
228 OR'd into the value if multicast support is required.
229 The type of the corresponding
231 interface is set to the supplied type.
232 If the value is outside the above range, an
235 The interface must be down at the time; if it is up, an
239 The argument should be a pointer to an
241 a non-zero value turns off
245 mode, causing packets read from the tunnel device to be prepended with
246 the network destination address (see above).
248 Will set the pid owning the tunnel device to the current process's pid.
250 The argument should be a pointer to an
252 a non-zero value turns off
256 mode, where every packet is preceded with a four byte address family.
258 The argument should be a pointer to an
260 the ioctl sets the value to one if the device is in
262 mode, and zero otherwise.
264 Turn non-blocking I/O for reads off or on, according as the argument
266 value is or is not zero.
267 (Writes are always non-blocking.)
269 Turn asynchronous I/O for reads
272 when data is available to be read)
273 off or on, according as the argument
275 value is or is not zero.
277 If any packets are queued to be read, store the size of the first one
280 otherwise, store zero.
282 Set the process group to receive
284 signals, when asynchronous I/O is enabled, to the argument
288 Retrieve the process group value for
290 signals into the argument
295 The control device also supports
297 for read; selecting for write is pointless, and always succeeds, since
298 writes are always non-blocking.
300 On the last close of the data device, by default, the interface is
303 .Nm ifconfig Ar tunN Cm down ) .
304 All queued packets are thrown away.
305 If the interface is up when the data device is not open
306 output packets are always thrown away rather than letting
319 This manual page was originally obtained from