1 .\" $NetBSD: tun.4,v 1.1 1996/06/25 22:17:37 pk Exp $
2 .\" $FreeBSD: src/share/man/man4/tun.4,v 1.9.2.4 2001/08/17 13:08:39 ru 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
62 devices are created using interface cloning.
63 This is done using the
64 .Dq ifconfig tun Ns Sy N No create
66 This is the preferred method of creating
69 The same method allows removal of interfaces by using the
70 .Dq ifconfig tun Ns Sy N No destroy
75 interface permits opens on the special control device
77 When this device is opened,
79 will return a handle for the lowest unused
85 Control devices (once successfully opened) persist until the
87 module is unloaded or the interface is destroyed.
89 Each interface supports the usual network-interface
91 and thus can be used with
93 like any other interface.
94 At boot time, they are
96 interfaces, but this can be changed; see the description of the control
98 When the system chooses to transmit a packet on the
99 network interface, the packet can be read from the control device
103 writing a packet to the control device generates an input
104 packet on the network interface, as if the (non-existent)
105 hardware had just received it.
108 .Pq Pa /dev/tun Ns Ar N
110 (it cannot be opened if it is already open).
113 call will return an error
115 if the interface is not
117 (which means that the control device is open and the interface's
118 address has been set).
120 Once the interface is ready,
122 will return a packet if one is available; if not, it will either block
123 until one is or return
125 depending on whether non-blocking I/O has been enabled.
126 If the packet is longer than is allowed for in the buffer passed to
128 the extra data will be silently dropped.
132 ioctl has been set (i.e.,
134 mode), packets read from the control device will be prepended
135 with the destination address as presented to the network interface output
137 The destination address is in
140 The actual length of the prepended address is in the member
144 ioctl has been set (i.e.,
146 mode), packets will be prepended with a 4-byte address
147 family in network byte order.
151 are mutually exclusive.
152 In any case, the packet data follows immediately.
156 call passes a packet in to be
158 on the pseudo-interface.
161 call supplies exactly one packet; the packet length is taken from the
162 amount of data provided to
164 (minus any supplied address family).
165 Writes will not block; if the packet cannot be accepted for a
167 (e.g., no buffer space available),
168 it is silently dropped; if the reason is not transient
169 (e.g., packet too large),
170 an error is returned.
174 ioctl has been set (i.e.,
176 mode), the actual packet data must be preceded by a
177 .Vt struct sockaddr .
178 The driver currently only inspects the
183 ioctl has been set (i.e.,
185 mode), the address family must be prepended, otherwise the
186 packet is assumed to be of type
193 .In net/tun/if_tun.h ) :
194 .Bl -tag -width ".Dv TUNSIFMODE"
196 The argument should be a pointer to an
198 this sets the internal debugging variable to that value.
199 What, if anything, this variable controls is not documented here; see
202 The argument should be a pointer to an
204 this stores the internal debugging variable's value into it.
206 The argument should be a pointer to an
208 and allows setting the MTU and the baudrate of the tunnel device.
209 The type must be the same as returned by
218 .In net/tun/if_tun.h .
220 The argument should be a pointer to an
222 where the current MTU, type, and baudrate will be stored.
224 Retrieve the name of the network interface that is associated with the
226 The argument should be a pointer to a
228 The interface name will be returned in the
232 The argument should be a pointer to an
234 its value must be either
240 OR'd into the value if multicast support is required.
241 The type of the corresponding
243 interface is set to the supplied type.
244 If the value is anything else, an
247 The interface must be down at the time; if it is up, an
251 The argument should be a pointer to an
253 a non-zero value turns off
257 mode, causing packets read from the tunnel device to be prepended with
258 the network destination address (see above).
260 Will set the PID owning the tunnel device to the current process's PID.
262 The argument should be a pointer to an
264 a non-zero value turns off
268 mode, where every packet is preceded with a 4-byte address family.
270 The argument should be a pointer to an
272 the ioctl sets the value to one if the device is in
274 mode, and zero otherwise.
276 Turn asynchronous I/O for reads
279 when data is available to be read)
280 off or on, according as the argument
282 value is or is not zero.
284 If any packets are queued to be read, store the size of the first one
287 otherwise, store zero.
289 Set the process group to receive
291 signals, when asynchronous I/O is enabled, to the argument
295 Retrieve the process group value for
297 signals into the argument
302 The control device also supports
304 for read; selecting for write is pointless, and always succeeds, since
305 writes are always non-blocking.
307 On the last close of the data device, by default, the interface is
310 .Nm ifconfig Ar tunN Cm down ) .
311 All queued packets are thrown away.
312 If the interface is up when the data device is not open
313 output packets are always thrown away rather than letting