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
38 A client program transfers IP (by default) packets to or from the
44 interface provides similar functionality at the Ethernet layer:
45 a client will transfer Ethernet frames to or from a
50 The network interfaces are named
53 etc., one for each control device that has been opened.
54 These network interfaces persist until the
56 module is unloaded, or until removed with the
61 devices are created using interface cloning.
62 This is done using the
63 .Dq ifconfig tun Ns Sy N No create
65 This is the preferred method of creating
68 The same method allows removal of interfaces.
70 .Dq ifconfig tun Ns Sy N No destroy
76 .Va net.link.tun.devfs_cloning
80 permits opens on the special control device
82 When this device is opened,
84 will return a handle for the lowest unused
91 Disabling the legacy devfs cloning functionality may break existing
92 applications which use
98 It therefore defaults to being enabled until further notice.
101 Control devices (once successfully opened) persist until
103 is unloaded in the same way that network interfaces persist (see above).
105 Each interface supports the usual network-interface
109 and thus can be used with
111 like any other interface.
112 At boot time, they are
114 interfaces, but this can be changed; see the description of the control
116 When the system chooses to transmit a packet on the
117 network interface, the packet can be read from the control device
121 writing a packet to the control device generates an input
122 packet on the network interface, as if the (non-existent)
123 hardware had just received it.
126 .Pq Pa /dev/tun Ns Ar N
128 (it cannot be opened if it is already open).
131 call will return an error
133 if the interface is not
135 (which means that the control device is open and the interface's
136 address has been set).
138 Once the interface is ready,
140 will return a packet if one is available; if not, it will either block
141 until one is or return
143 depending on whether non-blocking I/O has been enabled.
144 If the packet is longer than is allowed for in the buffer passed to
146 the extra data will be silently dropped.
150 ioctl has been set, packets read from the control device will be prepended
151 with the destination address as presented to the network interface output
154 The destination address is in
157 The actual length of the prepended address is in the member
161 ioctl has been set, packets will be prepended with a four byte address
162 family in network byte order.
166 are mutually exclusive.
167 In any case, the packet data follows immediately.
171 call passes a packet in to be
173 on the pseudo-interface.
176 ioctl has been set, the address family must be prepended, otherwise the
177 packet is assumed to be of type
181 call supplies exactly one packet; the packet length is taken from the
182 amount of data provided to
184 (minus any supplied address family).
185 Writes will not block; if the packet cannot be accepted for a
187 (e.g., no buffer space available),
188 it is silently dropped; if the reason is not transient
189 (e.g., packet too large),
190 an error is returned.
197 .Bl -tag -width ".Dv TUNSIFMODE"
199 The argument should be a pointer to an
201 this sets the internal debugging variable to that value.
202 What, if anything, this variable controls is not documented here; see
205 The argument should be a pointer to an
207 this stores the internal debugging variable's value into it.
209 The argument should be a pointer to an
211 and allows setting the MTU, the type, and the baudrate of the tunnel
218 The use of this ioctl is restricted to the super-user.
220 The argument should be a pointer to an
222 where the current MTU, type, and baudrate will be stored.
224 The argument should be a pointer to an
226 its value must be either
232 OR'd into the value if multicast support is required.
233 The type of the corresponding
235 interface is set to the supplied type.
236 If the value is outside the above range, an
239 The interface must be down at the time; if it is up, an
243 The argument should be a pointer to an
245 a non-zero value turns off
249 mode, causing packets read from the tunnel device to be prepended with
250 the network destination address (see above).
252 Will set the pid owning the tunnel device to the current process's pid.
254 The argument should be a pointer to an
256 a non-zero value turns off
260 mode, where every packet is preceded with a four byte address family.
262 The argument should be a pointer to an
264 the ioctl sets the value to one if the device is in
266 mode, and zero otherwise.
268 Turn non-blocking I/O for reads off or on, according as the argument
270 value is or is not zero.
271 (Writes are always non-blocking.)
273 Turn asynchronous I/O for reads
276 when data is available to be read)
277 off or on, according as the argument
279 value is or is not zero.
281 If any packets are queued to be read, store the size of the first one
284 otherwise, store zero.
286 Set the process group to receive
288 signals, when asynchronous I/O is enabled, to the argument
292 Retrieve the process group value for
294 signals into the argument
299 The control device also supports
301 for read; selecting for write is pointless, and always succeeds, since
302 writes are always non-blocking.
304 On the last close of the data device, by default, the interface is
307 .Nm ifconfig Ar tunN Cm down ) .
308 All queued packets are thrown away.
309 If the interface is up when the data device is not open
310 output packets are always thrown away rather than letting
324 This manual page was originally obtained from