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 (if
47 is built into your kernel, the network interfaces cannot be removed).
52 permits opens on the special control device
54 When this device is opened,
56 will return a handle for the lowest unused
61 Control devices (once successfully opened) persist until
63 is unloaded in the same way that network interfaces persist (see above).
65 Each interface supports the usual network-interface
71 and thus can be used with
73 like any other interface.
74 At boot time, they are
76 interfaces, but this can be changed; see the description of the control
78 When the system chooses to transmit a packet on the
79 network interface, the packet can be read from the control device
83 writing a packet to the control device generates an input
84 packet on the network interface, as if the (non-existent)
85 hardware had just received it.
88 .Pq Pa /dev/tun Ns Ar N
90 (it cannot be opened if it is already open).
93 call will return an error
95 if the interface is not
97 (which means that the control device is open and the interface's
98 address has been set).
100 Once the interface is ready,
102 will return a packet if one is available; if not, it will either block
103 until one is or return
105 depending on whether non-blocking I/O has been enabled.
106 If the packet is longer than is allowed for in the buffer passed to
108 the extra data will be silently dropped.
112 ioctl has been set, packets read from the control device will be prepended
113 with the destination address as presented to the network interface output
116 The destination address is in
119 The actual length of the prepended address is in the member
123 ioctl has been set, packets will be prepended with a four byte address
124 family in network byte order.
128 are mutually exclusive.
129 In any case, the packet data follows immediately.
133 call passes a packet in to be
135 on the pseudo-interface.
138 ioctl has been set, the address family must be prepended, otherwise the
139 packet is assumed to be of type
143 call supplies exactly one packet; the packet length is taken from the
144 amount of data provided to
146 (minus any supplied address family).
147 Writes will not block; if the packet cannot be accepted for a
149 (e.g., no buffer space available),
150 it is silently dropped; if the reason is not transient
151 (e.g., packet too large),
152 an error is returned.
159 .Bl -tag -width ".Dv TUNSIFMODE"
161 The argument should be a pointer to an
163 this sets the internal debugging variable to that value.
164 What, if anything, this variable controls is not documented here; see
167 The argument should be a pointer to an
169 this stores the internal debugging variable's value into it.
171 The argument should be a pointer to an
173 and allows setting the MTU, the type, and the baudrate of the tunnel
180 The use of this ioctl is restricted to the super-user.
182 The argument should be a pointer to an
184 where the current MTU, type, and baudrate will be stored.
186 The argument should be a pointer to an
188 its value must be either
194 OR'd into the value if multicast support is required.
195 The type of the corresponding
197 interface is set to the supplied type.
198 If the value is outside the above range, an
201 The interface must be down at the time; if it is up, an
205 The argument should be a pointer to an
207 a non-zero value turns off
211 mode, causing packets read from the tunnel device to be prepended with
212 the network destination address (see above).
214 Will set the pid owning the tunnel device to the current process's pid.
216 The argument should be a pointer to an
218 a non-zero value turns off
222 mode, where every packet is preceded with a four byte address family.
224 The argument should be a pointer to an
226 the ioctl sets the value to one if the device is in
228 mode, and zero otherwise.
230 Turn non-blocking I/O for reads off or on, according as the argument
232 value is or is not zero.
233 (Writes are always non-blocking.)
235 Turn asynchronous I/O for reads
238 when data is available to be read)
239 off or on, according as the argument
241 value is or is not zero.
243 If any packets are queued to be read, store the size of the first one
246 otherwise, store zero.
248 Set the process group to receive
250 signals, when asynchronous I/O is enabled, to the argument
254 Retrieve the process group value for
256 signals into the argument
261 The control device also supports
263 for read; selecting for write is pointless, and always succeeds, since
264 writes are always non-blocking.
266 On the last close of the data device, by default, the interface is
269 .Nm ifconfig Ar tunN Cm down ) .
270 All queued packets are thrown away.
271 If the interface is up when the data device is not open
272 output packets are always thrown away rather than letting
285 This manual page was originally obtained from