Documentation
¶
Overview ¶
Package tuntap provides a portable interface to create and use TUN/TAP virtual network interfaces.
Note that while this package lets you create the interface and pass packets to/from it, it does not provide an API to configure the interface. Interface configuration is a very large topic and should be dealt with separately.
Index ¶
- Constants
- Variables
- type DevKind
- type Interface
- func (t *Interface) AddAddress(ip net.IP, subnet *net.IPNet) error
- func (t *Interface) Close() error
- func (t *Interface) GetAddrList() ([][]byte, error)
- func (t *Interface) IPv6(ctrl bool) error
- func (t *Interface) IPv6Forwarding(ctrl bool) error
- func (t *Interface) IPv6SLAAC(ctrl bool) error
- func (t *Interface) Name() string
- func (t *Interface) ReadPacket(buffer []byte) (Packet, error)
- func (t *Interface) SetMTU(mtu int) error
- func (t *Interface) Up() error
- func (t *Interface) WritePacket(pkt Packet) error
- type Packet
Constants ¶
const ( // various ethernet protocols, using the same names as linux does ETH_P_IP uint16 = 0x0800 ETH_P_IPV6 uint16 = 0x86dd )
Variables ¶
var ErrJumboPacket = errors.New("jumbo packet too large for /dev/tun")
var ErrNotIPPacket = errors.New("packet is not IPv4 or IPv6")
var ErrShortRead = errors.New("truncated /dev/tun read")
var ErrTruncatedPacket = errors.New("IP packet is truncated") // note that when ErrTruncatedPacket is returned, the truncated packet is also returned for the caller to use for inspection and/or logging, or to ignore
Functions ¶
This section is empty.
Types ¶
type DevKind ¶
type DevKind int
const ( // Receive/send layer routable 3 packets (IP, IPv6...). Notably, // you don't receive link-local multicast with this interface // type. DevTun DevKind = iota // Receive/send Ethernet II frames. You receive all packets that // would be visible on an Ethernet link, including broadcast and // multicast traffic. DevTap )
type Interface ¶
type Interface struct {
// contains filtered or unexported fields
}
func Open ¶
Open connects to the specified tun/tap interface.
If the specified device has been configured as persistent, this simply looks like a "cable connected" event to observers of the interface. Otherwise, the interface is created out of thin air.
ifPattern can be an exact interface name, e.g. "tun42", or a pattern containing one %d format specifier, e.g. "tun%d". In the latter case, the kernel will select an available interface name and create it.
Returns a TunTap object with channels to send/receive packets, or nil and an error if connecting to the interface failed.
func (*Interface) AddAddress ¶ added in v1.2.0
AddAddress adds an IP address to the tunnel interface.
func (*Interface) Close ¶
Disconnect from the tun/tap interface.
If the interface isn't configured to be persistent, it is immediately destroyed by the kernel.
func (*Interface) GetAddrList ¶ added in v1.2.0
GetAddrList returns the IP addresses (as bytes) associated with the interface.
func (*Interface) IPv6Forwarding ¶ added in v1.2.0
IPv6Forwarding enables/disables ipv6 forwarding for the interface.
func (*Interface) IPv6SLAAC ¶ added in v1.2.0
IPv6SLAAC enables/disables stateless address auto-configuration (SLAAC) for the interface.
func (*Interface) Name ¶
The name of the interface. May be different from the name given to Open(), if the latter was a pattern.
func (*Interface) ReadPacket ¶
Read a single packet from the kernel.
func (*Interface) WritePacket ¶
Send a single packet to the kernel.
type Packet ¶
type Packet struct {
// The raw bytes of the Ethernet payload (for DevTun) or the full
// Ethernet frame (for DevTap).
Body []byte
// The Ethernet type of the packet. Commonly seen values are
// 0x8000 for IPv4 and 0x86dd for IPv6.
Protocol uint16
}
func (*Packet) ICMPType ¶
returns ipproto, icmp type, icmp code, if this is an ICMP packet, or 0,_,_ if it isn't
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
print_tuntap
command
Simple use of the tuntap package that prints packets received by the interface.
|
Simple use of the tuntap package that prints packets received by the interface. |