1 .\" $NetBSD: tun.4,v 1.22 2008/04/30 13:10:54 martin Exp $
3 .\" Copyright (c) 1996-2006 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd tunnel software network interface
41 interface is a software loopback mechanism that can be loosely
42 described as the network interface analog of the
46 does for network interfaces what the
48 driver does for terminals.
54 driver, provides two interfaces: an interface like the usual facility
57 a network interface in the case of
62 and a character-special device
68 device, the administrator must first create the interface.
69 This can be done by using the
78 .Pa /dev/tun Ns Sy N ,
79 will also create a network interface with the same unit number of
80 that device if it doesn't exist yet.
82 The network interfaces should be named
86 Each interface supports the usual network-interface
92 and thus can be used with
94 like any other interface.
95 At boot time, they are
97 interfaces, but this can be changed; see the description of the control
99 When the system chooses to transmit a packet on the
100 network interface, the packet can be read from the control device
105 writing a packet to the control device generates an input
106 packet on the network interface, as if the
108 hardware had just received it.
110 The tunnel device, normally
111 .Pa /dev/tun Ns Sy N ,
114 it cannot be opened if it is already open
116 and is restricted to the super-user
117 .Pq regardless of file system permissions .
120 call will return an error
122 if the interface is not
124 (which means that the interface
125 address has not been set).
126 Once the interface is ready,
128 will return a packet if one is available; if not, it will either block
129 until one is or return
131 depending on whether non-blocking I/O has been enabled.
133 is longer than is allowed for in the buffer passed to
135 the extra data will be silently dropped.
137 Packets can be optionally prepended with the destination address as presented
138 to the network interface output routine
139 .Pq Sq Li tunoutput .
140 The destination address is in
141 .Sq Li struct sockaddr
143 The actual length of the prepended address is in the member
145 The packet data follows immediately.
148 call passes a packet in to be
150 on the pseudo-interface.
153 call supplies exactly one packet; the packet length is taken from the
154 amount of data provided to
156 Writes will not block; if the packet cannot be accepted for a
158 .Pq e.g., no buffer space available ,
159 it is silently dropped; if the reason is not transient
160 .Pq e.g., packet too large ,
161 an error is returned.
165 .Pq see Dv TUNSLMODE No below ,
166 the actual packet data must be preceded by a
167 .Sq Li struct sockaddr .
168 The driver currently only inspects the
174 .Pq defined in Aq Pa net/if_tun.h :
175 .Bl -tag -width TUNSIFMODE
177 The argument should be a pointer to an
179 this sets the internal debugging variable to that value.
180 What, if anything, this variable controls is not documented here;
183 The argument should be a pointer to an
185 this stores the internal debugging variable's value into it.
187 The argument should be a pointer to an
189 its value must be either
195 may be or'ed into the value).
196 The type of the corresponding
198 interface is set to the supplied type.
199 If the value is anything else, an
202 The interface must be down at the time; if it is up, an
206 The argument should be a pointer to an
208 a non-zero value turns off
212 mode, causing packets read from the tunnel device to be prepended with
213 network destination address.
215 The argument should be a pointer to an
217 the ioctl sets the value to one if the device is in
219 mode, and zero otherwise.
221 The argument should be a pointer to an
223 a non-zero value turns off
227 mode, where every packet is preceded with a four byte address family.
229 Turn non-blocking I/O for reads off or on, according as the argument
231 value is or isn't zero
232 .Pq Writes are always nonblocking .
234 Turn asynchronous I/O for reads
238 when data is available to be read
239 .Pc off or on, according as the argument
241 value is or isn't 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 .Dq ifconfig tun Ns Sy n No down
271 All queued packets are thrown away.
272 If the interface is up when the data device is not open
273 output packets are always thrown away rather than letting
280 IPv6 support comes mostly from
286 .Aq rpaulo@NetBSD.org .