2000-07-20 17:01:10 +00:00
|
|
|
.\" $FreeBSD$
|
|
|
|
.\" Based on PR#2411
|
|
|
|
.\"
|
2008-09-08 22:44:51 +00:00
|
|
|
.Dd September 8, 2008
|
2000-07-20 17:01:10 +00:00
|
|
|
.Dt TAP 4
|
2010-04-14 19:08:06 +00:00
|
|
|
.Os
|
2000-07-20 17:01:10 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm tap
|
|
|
|
.Nd Ethernet tunnel software network interface
|
|
|
|
.Sh SYNOPSIS
|
2001-05-01 09:15:30 +00:00
|
|
|
.Cd device tap
|
2000-07-20 17:01:10 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm
|
2000-07-20 17:01:10 +00:00
|
|
|
interface is a software loopback mechanism that can be loosely
|
|
|
|
described as the network interface analog of the
|
|
|
|
.Xr pty 4 ,
|
|
|
|
that is,
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm
|
2000-07-20 17:01:10 +00:00
|
|
|
does for network interfaces what the
|
|
|
|
.Nm pty
|
|
|
|
driver does for terminals.
|
|
|
|
.Pp
|
|
|
|
The
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm
|
2000-07-20 17:01:10 +00:00
|
|
|
driver, like the
|
|
|
|
.Nm pty
|
|
|
|
driver, provides two interfaces: an interface like the usual facility
|
|
|
|
it is simulating
|
2000-12-29 09:18:45 +00:00
|
|
|
(an Ethernet network interface in the case of
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm ,
|
2000-07-20 17:01:10 +00:00
|
|
|
or a terminal for
|
2000-12-29 09:18:45 +00:00
|
|
|
.Nm pty ) ,
|
2000-07-20 17:01:10 +00:00
|
|
|
and a character-special device
|
|
|
|
.Dq control
|
|
|
|
interface.
|
|
|
|
.Pp
|
|
|
|
The network interfaces are named
|
2001-09-05 01:06:21 +00:00
|
|
|
.Dq Li tap0 ,
|
|
|
|
.Dq Li tap1 ,
|
|
|
|
etc., one for each control device that has been opened.
|
|
|
|
These Ethernet network interfaces persist until
|
|
|
|
.Pa if_tap.ko
|
2007-02-04 16:32:46 +00:00
|
|
|
module is unloaded, or until removed with "ifconfig destroy" (see below).
|
|
|
|
.Pp
|
|
|
|
.Nm
|
|
|
|
devices are created using interface cloning.
|
|
|
|
This is done using the
|
|
|
|
.Dq ifconfig tap Ns Sy N No create
|
|
|
|
command.
|
|
|
|
This is the preferred method of creating
|
2001-09-05 01:06:21 +00:00
|
|
|
.Nm
|
2007-02-04 16:32:46 +00:00
|
|
|
devices.
|
|
|
|
The same method allows removal of interfaces.
|
|
|
|
For this, use the
|
|
|
|
.Dq ifconfig tap Ns Sy N No destroy
|
|
|
|
command.
|
2001-09-05 01:06:21 +00:00
|
|
|
.Pp
|
2007-02-04 16:32:46 +00:00
|
|
|
If the
|
|
|
|
.Xr sysctl 8
|
|
|
|
variable
|
|
|
|
.Va net.link.tap.devfs_cloning
|
|
|
|
is non-zero, the
|
2001-09-05 01:06:21 +00:00
|
|
|
.Nm
|
2003-03-25 14:49:02 +00:00
|
|
|
interface
|
2001-09-05 01:06:21 +00:00
|
|
|
permits opens on the special control device
|
|
|
|
.Pa /dev/tap .
|
|
|
|
When this device is opened,
|
|
|
|
.Nm
|
|
|
|
will return a handle for the lowest unused
|
|
|
|
.Nm
|
|
|
|
device (use
|
|
|
|
.Xr devname 3
|
|
|
|
to determine which).
|
2007-02-04 16:32:46 +00:00
|
|
|
.Pp
|
|
|
|
.Bf Em
|
|
|
|
Disabling the legacy devfs cloning functionality may break existing
|
|
|
|
applications which use
|
|
|
|
.Nm ,
|
|
|
|
such as
|
|
|
|
.Tn VMware
|
|
|
|
and
|
|
|
|
.Xr ssh 1 .
|
|
|
|
It therefore defaults to being enabled until further notice.
|
|
|
|
.Ef
|
|
|
|
.Pp
|
2001-09-05 01:06:21 +00:00
|
|
|
Control devices (once successfully opened) persist until
|
|
|
|
.Pa if_tap.ko
|
2007-02-04 16:32:46 +00:00
|
|
|
is unloaded or the interface is destroyed.
|
2001-09-05 01:06:21 +00:00
|
|
|
.Pp
|
|
|
|
Each interface supports the usual Ethernet network interface
|
2000-07-20 17:01:10 +00:00
|
|
|
.Xr ioctl 2 Ns s ,
|
|
|
|
such as
|
|
|
|
.Dv SIOCSIFADDR
|
|
|
|
and
|
|
|
|
.Dv SIOCSIFNETMASK ,
|
|
|
|
and thus can be used with
|
|
|
|
.Xr ifconfig 8
|
2001-09-11 10:08:29 +00:00
|
|
|
like any other Ethernet interface.
|
|
|
|
When the system chooses to transmit
|
2001-05-01 09:15:30 +00:00
|
|
|
an Ethernet frame on the network interface, the frame can be read from
|
2000-07-20 17:01:10 +00:00
|
|
|
the control device
|
2001-02-01 16:38:02 +00:00
|
|
|
(it appears as
|
2000-07-20 17:01:10 +00:00
|
|
|
.Dq input
|
2001-02-01 16:38:02 +00:00
|
|
|
there);
|
2000-07-20 17:01:10 +00:00
|
|
|
writing an Ethernet frame to the control device generates an input frame on
|
|
|
|
the network interface, as if the
|
2001-08-07 15:48:51 +00:00
|
|
|
(non-existent)
|
2000-07-20 17:01:10 +00:00
|
|
|
hardware had just received it.
|
|
|
|
.Pp
|
|
|
|
The Ethernet tunnel device, normally
|
|
|
|
.Pa /dev/tap Ns Sy N ,
|
|
|
|
is exclusive-open
|
2001-02-01 16:38:02 +00:00
|
|
|
(it cannot be opened if it is already open)
|
2005-04-13 00:30:19 +00:00
|
|
|
and is restricted to the super-user, unless the
|
|
|
|
.Xr sysctl 8
|
|
|
|
variable
|
|
|
|
.Va net.link.tap.user_open
|
|
|
|
is non-zero.
|
2007-03-19 18:27:00 +00:00
|
|
|
If the
|
|
|
|
.Xr sysctl 8
|
|
|
|
variable
|
|
|
|
.Va net.link.tap.up_on_open
|
|
|
|
is non-zero, the tunnel device will be marked
|
|
|
|
.Dq up
|
|
|
|
when the control device is opened.
|
2000-07-20 17:01:10 +00:00
|
|
|
A
|
|
|
|
.Fn read
|
|
|
|
call will return an error
|
|
|
|
.Pq Er EHOSTDOWN
|
|
|
|
if the interface is not
|
|
|
|
.Dq ready .
|
|
|
|
Once the interface is ready,
|
|
|
|
.Fn read
|
2001-05-01 09:15:30 +00:00
|
|
|
will return an Ethernet frame if one is available; if not, it will
|
2000-07-20 17:01:10 +00:00
|
|
|
either block until one is or return
|
|
|
|
.Er EWOULDBLOCK ,
|
2001-09-11 10:08:29 +00:00
|
|
|
depending on whether non-blocking I/O has been enabled.
|
|
|
|
If the frame
|
2000-07-20 17:01:10 +00:00
|
|
|
is longer than is allowed for in the buffer passed to
|
|
|
|
.Fn read ,
|
|
|
|
the extra data will be silently dropped.
|
|
|
|
.Pp
|
|
|
|
A
|
|
|
|
.Xr write 2
|
|
|
|
call passes an Ethernet frame in to be
|
|
|
|
.Dq received
|
2001-09-11 10:08:29 +00:00
|
|
|
on the pseudo-interface.
|
|
|
|
Each
|
2000-07-20 17:01:10 +00:00
|
|
|
.Fn write
|
|
|
|
call supplies exactly one frame; the frame length is taken from the
|
|
|
|
amount of data provided to
|
|
|
|
.Fn write .
|
|
|
|
Writes will not block; if the frame cannot be accepted
|
|
|
|
for a transient reason
|
2001-08-07 15:48:51 +00:00
|
|
|
(e.g., no buffer space available),
|
2000-07-20 17:01:10 +00:00
|
|
|
it is silently dropped; if the reason is not transient
|
2001-08-07 15:48:51 +00:00
|
|
|
(e.g., frame too large),
|
2000-07-20 17:01:10 +00:00
|
|
|
an error is returned.
|
|
|
|
The following
|
|
|
|
.Xr ioctl 2
|
|
|
|
calls are supported
|
2001-08-07 15:48:51 +00:00
|
|
|
(defined in
|
2003-09-08 19:57:22 +00:00
|
|
|
.In net/if_tap.h ) :
|
2000-07-20 17:01:10 +00:00
|
|
|
.Bl -tag -width VMIO_SIOCSETMACADDR
|
2008-09-08 22:44:51 +00:00
|
|
|
.It Dv TAPSIFINFO
|
|
|
|
Set network interface information (line speed, MTU and type).
|
|
|
|
The argument should be a pointer to a
|
|
|
|
.Va struct tapinfo .
|
|
|
|
.It Dv TAPGIFINFO
|
|
|
|
Retrieve network interface information (line speed, MTU and type).
|
|
|
|
The argument should be a pointer to a
|
|
|
|
.Va struct tapinfo .
|
2000-07-20 17:01:10 +00:00
|
|
|
.It Dv TAPSDEBUG
|
|
|
|
The argument should be a pointer to an
|
|
|
|
.Va int ;
|
2001-09-11 10:08:29 +00:00
|
|
|
this sets the internal debugging variable to that value.
|
|
|
|
What, if
|
2000-07-20 17:01:10 +00:00
|
|
|
anything, this variable controls is not documented here; see the source
|
|
|
|
code.
|
|
|
|
.It Dv TAPGDEBUG
|
|
|
|
The argument should be a pointer to an
|
|
|
|
.Va int ;
|
|
|
|
this stores the internal debugging variable's value into it.
|
2008-09-08 22:44:51 +00:00
|
|
|
.It Dv TAPGIFNAME
|
|
|
|
Retrieve network interface name.
|
|
|
|
The argument should be a pointer to a
|
|
|
|
.Va struct ifreq .
|
|
|
|
The interface name will be returned in the
|
|
|
|
.Va ifr_name
|
|
|
|
field.
|
2000-07-20 17:01:10 +00:00
|
|
|
.It Dv FIONBIO
|
|
|
|
Turn non-blocking I/O for reads off or on, according as the argument
|
|
|
|
.Va int Ns 's
|
2005-02-13 22:25:33 +00:00
|
|
|
value is or is not zero
|
2001-08-07 15:48:51 +00:00
|
|
|
(Writes are always nonblocking).
|
2000-07-20 17:01:10 +00:00
|
|
|
.It Dv FIOASYNC
|
|
|
|
Turn asynchronous I/O for reads
|
2001-02-01 16:38:02 +00:00
|
|
|
(i.e., generation of
|
2000-07-20 17:01:10 +00:00
|
|
|
.Dv SIGIO
|
2001-02-01 16:38:02 +00:00
|
|
|
when data is available to be read)
|
2000-07-20 17:01:10 +00:00
|
|
|
off or on, according as the argument
|
|
|
|
.Va int Ns 's
|
2005-02-13 22:25:33 +00:00
|
|
|
value is or is not zero.
|
2000-07-20 17:01:10 +00:00
|
|
|
.It Dv FIONREAD
|
|
|
|
If any frames are queued to be read, store the size of the first one into the argument
|
|
|
|
.Va int ;
|
|
|
|
otherwise, store zero.
|
|
|
|
.It Dv TIOCSPGRP
|
|
|
|
Set the process group to receive
|
|
|
|
.Dv SIGIO
|
|
|
|
signals, when asynchronous I/O is enabled, to the argument
|
|
|
|
.Va int
|
|
|
|
value.
|
|
|
|
.It Dv TIOCGPGRP
|
|
|
|
Retrieve the process group value for
|
|
|
|
.Dv SIGIO
|
|
|
|
signals into the argument
|
|
|
|
.Va int
|
|
|
|
value.
|
2000-08-02 17:27:39 +00:00
|
|
|
.It Dv SIOCGIFADDR
|
2000-07-20 17:01:10 +00:00
|
|
|
Retrieve the Media Access Control
|
2001-05-01 09:15:30 +00:00
|
|
|
.Pq Dv MAC
|
2000-08-02 17:27:39 +00:00
|
|
|
address of the
|
|
|
|
.Dq remote
|
2001-09-11 10:08:29 +00:00
|
|
|
side.
|
|
|
|
This command is used by the VMware port and expected to be executed on
|
2000-08-02 17:27:39 +00:00
|
|
|
descriptor, associated with control device
|
2001-02-01 16:38:02 +00:00
|
|
|
(usually
|
2001-05-01 09:15:30 +00:00
|
|
|
.Pa /dev/vmnet Ns Sy N
|
2000-08-02 17:27:39 +00:00
|
|
|
or
|
2001-02-01 16:38:02 +00:00
|
|
|
.Pa /dev/tap Ns Sy N ) .
|
2000-07-20 17:01:10 +00:00
|
|
|
The
|
|
|
|
.Va buffer ,
|
2000-08-02 17:27:39 +00:00
|
|
|
which is passed as the argument, is expected to have enough space to store
|
|
|
|
the
|
|
|
|
.Dv MAC
|
2001-09-11 10:08:29 +00:00
|
|
|
address.
|
|
|
|
At the open time both
|
2000-08-02 17:27:39 +00:00
|
|
|
.Dq local
|
|
|
|
and
|
|
|
|
.Dq remote
|
|
|
|
.Dv MAC
|
|
|
|
addresses are the same, so this command could be used to retrieve the
|
|
|
|
.Dq local
|
|
|
|
.Dv MAC
|
2000-07-20 17:01:10 +00:00
|
|
|
address.
|
2000-08-02 17:27:39 +00:00
|
|
|
.It Dv SIOCSIFADDR
|
2000-07-20 17:01:10 +00:00
|
|
|
Set the Media Access Control
|
2000-08-02 17:27:39 +00:00
|
|
|
.Pq Dv MAC
|
|
|
|
address of the
|
|
|
|
.Dq remote
|
2001-09-11 10:08:29 +00:00
|
|
|
side.
|
|
|
|
This command is used by VMware port and expected to be executed on
|
2000-08-02 17:27:39 +00:00
|
|
|
a descriptor, associated with control device
|
2001-08-07 15:48:51 +00:00
|
|
|
(usually
|
|
|
|
.Pa /dev/vmnet Ns Sy N ) .
|
2000-07-20 17:01:10 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The control device also supports
|
|
|
|
.Xr select 2
|
|
|
|
for read; selecting for write is pointless, and always succeeds, since
|
|
|
|
writes are always non-blocking.
|
|
|
|
.Pp
|
2000-08-02 17:27:39 +00:00
|
|
|
On the last close of the data device, the interface is
|
2000-07-20 17:01:10 +00:00
|
|
|
brought down
|
2001-05-01 09:15:30 +00:00
|
|
|
(as if with
|
2001-02-01 16:38:02 +00:00
|
|
|
.Dq ifconfig tap Ns Sy N No down )
|
2002-11-29 11:39:20 +00:00
|
|
|
unless the device is a
|
|
|
|
.Em VMnet
|
2002-04-12 22:06:16 +00:00
|
|
|
device.
|
2001-09-11 10:08:29 +00:00
|
|
|
All queued frames are thrown away.
|
|
|
|
If the interface is up when the data
|
2001-05-01 09:15:30 +00:00
|
|
|
device is not open, output frames are thrown away rather than
|
2000-07-20 17:01:10 +00:00
|
|
|
letting them pile up.
|
|
|
|
.Pp
|
2001-05-01 09:15:30 +00:00
|
|
|
The
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm
|
2002-04-12 22:06:16 +00:00
|
|
|
device can also be used with the VMware port as a replacement
|
2002-11-29 11:39:20 +00:00
|
|
|
for the old
|
|
|
|
.Em VMnet
|
2002-04-12 22:06:16 +00:00
|
|
|
device driver.
|
2001-09-11 10:08:29 +00:00
|
|
|
The driver uses the minor number
|
2000-08-02 17:27:39 +00:00
|
|
|
to select between
|
2000-11-20 18:41:33 +00:00
|
|
|
.Nm
|
2000-07-20 17:01:10 +00:00
|
|
|
and
|
|
|
|
.Nm vmnet
|
2001-09-11 10:08:29 +00:00
|
|
|
devices.
|
2002-11-29 11:39:20 +00:00
|
|
|
.Em VMnet
|
2002-04-12 22:06:16 +00:00
|
|
|
minor numbers begin at
|
2001-09-05 01:06:21 +00:00
|
|
|
.Va 0x800000
|
2000-07-20 17:01:10 +00:00
|
|
|
+
|
2002-04-12 22:06:16 +00:00
|
|
|
.Va N ;
|
|
|
|
where
|
2001-05-01 09:15:30 +00:00
|
|
|
.Va N
|
2002-11-29 11:39:20 +00:00
|
|
|
is a
|
|
|
|
.Em VMnet
|
2002-04-12 22:06:16 +00:00
|
|
|
unit number.
|
|
|
|
In this case the control device is expected to be
|
2000-07-20 17:01:10 +00:00
|
|
|
.Pa /dev/vmnet Ns Sy N ,
|
2002-04-12 22:06:16 +00:00
|
|
|
and the network interface will be
|
2000-07-20 17:01:10 +00:00
|
|
|
.Sy vmnet Ns Ar N .
|
2002-11-29 11:39:20 +00:00
|
|
|
Additionally,
|
|
|
|
.Em VMnet
|
|
|
|
devices do not
|
|
|
|
.Xr ifconfig 8
|
2002-04-12 22:06:16 +00:00
|
|
|
themselves down when the
|
2001-09-11 10:08:29 +00:00
|
|
|
control device is closed.
|
|
|
|
Everything else is the same.
|
2000-07-20 17:01:10 +00:00
|
|
|
.Pp
|
2002-11-29 11:39:20 +00:00
|
|
|
In addition to the above mentioned
|
2000-07-20 17:01:10 +00:00
|
|
|
.Xr ioctl 2
|
2002-04-12 22:06:16 +00:00
|
|
|
calls, there is an additional one for the VMware port.
|
2000-07-20 17:01:10 +00:00
|
|
|
.Bl -tag -width VMIO_SIOCSETMACADDR
|
2000-08-02 17:27:39 +00:00
|
|
|
.It Dv VMIO_SIOCSIFFLAGS
|
2001-05-01 09:15:30 +00:00
|
|
|
VMware
|
2000-07-20 17:01:10 +00:00
|
|
|
.Dv SIOCSIFFLAGS .
|
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr inet 4 ,
|
|
|
|
.Xr intro 4
|