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
39 The network interfaces are named
42 etc, as many as were made by
44 Each one supports the usual network-interface
50 and thus can be used with
52 like any other interface.
53 At boot time, they are
55 interfaces, but this can be changed; see the description of the control
57 When the system chooses to transmit a packet on the
58 network interface, the packet can be read from the control device
62 writing a packet to the control device generates an input
63 packet on the network interface, as if the (non\-existent)
64 hardware had just received it.
66 The tunnel device, normally
67 .Pa /dev/tun Ns Ar N ,
69 (it cannot be opened if it is already open)
70 and is restricted to the super-user.
73 call will return an error
75 if the interface is not
77 (which means that the control device is open and the interface's
78 address has been set).
80 Once the interface is ready,
82 will return a packet if one is available; if not, it will either block
83 until one is or return
85 depending on whether non-blocking I/O has been enabled.
86 If the packet is longer than is allowed for in the buffer passed to
88 the extra data will be silently dropped.
90 Packets can be optionally prepended with the destination address as presented
91 to the network interface output routine,
93 The destination address is in
96 The actual length of the prepended address is in the member
98 The packet data follows immediately.
102 call passes a packet in to be
104 on the pseudo-interface.
107 call supplies exactly one packet; the packet length is taken from the
108 amount of data provided to
110 Writes will not block; if the packet cannot be accepted for a
112 (e.g., no buffer space available),
113 it is silently dropped; if the reason is not transient
114 (e.g., packet too large),
115 an error is returned.
122 the actual packet data must be preceded by a
123 .Vt struct sockaddr .
124 The driver currently only inspects the
132 .Aq Pa net/if_tun.h ) :
133 .Bl -tag -width ".Dv TUNSIFMODE"
135 The argument should be a pointer to an
137 this sets the internal debugging variable to that value.
138 What, if anything, this variable controls is not documented here; see
141 The argument should be a pointer to an
143 this stores the internal debugging variable's value into it.
145 The argument should be a pointer to an
147 and allows setting the MTU, the type, and the baudrate of the tunnel
152 .Aq Pa net/if_tun.h .
154 The argument should be a pointer to an
156 where the current MTU, type, and baudrate will be stored.
158 The argument should be a pointer to an
160 its value must be either
164 The type of the corresponding
166 interface is set to the supplied type.
167 If the value is anything else, an
170 The interface must be down at the time; if it is up, an
174 The argument should be a pointer to an
176 a non-zero value turns on
178 mode, causing packets read from the tunnel device to be prepended with
179 network destination address.
181 Will set the pid owning the tunnel device to the current process's pid.
183 The argument should be a pointer to an
185 a non-zero value turns off
189 mode, where every packet is preceded with a four byte address family.
191 The argument should be a pointer to an
193 this stores one if the device is in
195 mode, and zero otherwise in it.
197 Turn non-blocking I/O for reads off or on, according as the argument
199 value is or isn't zero.
200 (Writes are always non-blocking.)
202 Turn asynchronous I/O for reads
205 when data is available to be read)
206 off or on, according as the argument
208 value is or isn't zero.
210 If any packets are queued to be read, store the size of the first one
213 otherwise, store zero.
215 Set the process group to receive
217 signals, when asynchronous I/O is enabled, to the argument
221 Retrieve the process group value for
223 signals into the argument
228 The control device also supports
230 for read; selecting for write is pointless, and always succeeds, since
231 writes are always non-blocking.
233 On the last close of the data device, by default, the interface is
236 .Nm ifconfig Ar tunN Cm down ) .
237 All queued packets are thrown away.
238 If the interface is up when the data device is not open
239 output packets are always thrown away rather than letting
245 This manual page was originally obtained from