Documentation
¶
Overview ¶
Package vnet implements TCP/IP connectivity through a VirtIO (version 1.2) network device.
The TCP/IP stack is implemented using gVisor pure Go implementation.
This package is only meant to be used with `GOOS=tamago` as supported by the TamaGo framework for bare metal Go, see https://github.com/usbarmory/tamago.
Index ¶
- Constants
- Variables
- type Config
- type Header
- type Interface
- func (iface *Interface) DialContextTCP4(ctx context.Context, address string) (net.Conn, error)
- func (iface *Interface) DialTCP4(address string) (net.Conn, error)
- func (iface *Interface) DialUDP4(lAddr, rAddr string) (net.Conn, error)
- func (iface *Interface) EnableICMP() error
- func (iface *Interface) Init(nic *Net, ip string, netmask string, gateway string) (err error)
- func (iface *Interface) ListenerTCP4(port uint16) (net.Listener, error)
- func (iface *Interface) Socket(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c interface{}, err error)
- type NIC
- type Net
Constants ¶
const ( DeviceID = 0x01 ConfigSize = 12 )
Device parameters
const ( // receiveq1 ReceiveQueue = 0 // transmitq1 TransmitQueue = 1 )
virtual queue pairs
const ( STATUS_DOWN = 0 STATUS_UP = 1 SPEED_MIN = 0x00000000 SPEED_MAX = 0x7fffffff DUPLEX_HALF = 0x00 DUPLEX_FULL = 0x01 HASH_TYPE_IPV4 = 1 << 0 HASH_TYPE_TCPV4 = 1 << 1 HASH_TYPE_UDPV4 = 1 << 2 HASH_TYPE_IPV6 = 1 << 3 HASH_TYPE_TCPV6 = 1 << 4 HASH_TYPE_UDPV6 = 1 << 5 HASH_TYPE_IP_EX = 1 << 6 HASH_TYPE_TCP_EX = 1 << 7 HASH_TYPE_UDP_EX = 1 << 8 )
Configuration constants
const ( FeatureChecksum = (1 << 0) FeatureMTU = (1 << 3) FeatureMAC = (1 << 5) FeatureStatus = (1 << 16) FeatureSpeedDuplex = (1 << 63) DriverFeatures = FeatureChecksum | FeatureMTU | FeatureMAC | FeatureStatus | FeatureSpeedDuplex )
Supported Features
const (
NeedsChecksum = 0
)
Header flags
Variables ¶
var ( // MTU represents the Maximum Transmission Unit MTU = 1518 // NICID represents the default gVisor NIC identifier NICID = tcpip.NICID(1) // DefaultStackOptions represents the default gVisor Stack configuration DefaultStackOptions = stack.Options{ NetworkProtocols: []stack.NetworkProtocolFactory{ ipv4.NewProtocol, arp.NewProtocol}, TransportProtocols: []stack.TransportProtocolFactory{ tcp.NewProtocol, icmp.NewProtocol4, udp.NewProtocol}, } )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // MAC represents the interface physical address. MAC [6]byte // Status represents the driver status. Status uint16 // MaxVirtualQueuePairs is the Maximum number of tx/rx queues. MaxVirtualQueuePairs uint16 // MTU represents the Ethernet Maximum Transmission Unit. MTU uint16 }
Config represents a VirtIO network device configuration
type Header ¶
type Header struct { Flags uint8 GSOType uint8 HdrLen uint16 GSOSize uint16 CSumStart uint16 CSumOffset uint16 NumBuffers uint16 // not used in legacy drivers }
Header represents a VirtIO network device header (virtio_net_hdr)
type Interface ¶
Interface represents an Ethernet interface instance.
func (*Interface) DialContextTCP4 ¶
DialContextTCP4 connects to an IPv4 TCP address with support for timeout supplied by ctx.
func (*Interface) DialUDP4 ¶
DialUDP4 creates a UDP connection to the ip:port specified by rAddr, optionally setting the local ip:port to lAddr.
func (*Interface) EnableICMP ¶
EnableICMP adds an ICMP endpoint to the interface, it is useful to enable ping requests.
func (*Interface) Init ¶
Init initializes a VirtIO Network interface associating it to a gVisor link, a default NICID and TCP/IP gVisor Stack are set if not previously assigned.
func (*Interface) ListenerTCP4 ¶
ListenerTCP4 returns a net.Listener capable of accepting IPv4 TCP connections for the argument port.
type NIC ¶
type NIC struct { // Link is a gVisor channel endpoint Link *channel.Endpoint // Device is the physical interface associated to the virtual one. Device *Net // contains filtered or unexported fields }
NIC represents an virtual Ethernet instance.
func (*NIC) Init ¶
Init initializes a virtual Ethernet instance bound to a physical Ethernet device.
type Net ¶
type Net struct { sync.Mutex // Controller index Index int // VirtIO Transport instance Transport virtio.VirtIO // Interrupt ID IRQ int // Incoming packet handler RxHandler func([]byte) // HeaderLength allows to override the VirtIO network device header // length as some implementations, such as QEMU, omit certain fields. HeaderLength int // Maximum Transmission Unit MTU uint16 // contains filtered or unexported fields }
Net represents a VirtIO network device instance.
func (*Net) Rx ¶
Rx receives a single network frame, excluding the checksum, from the MAC controller ring buffer.