enet

package module
v0.0.0-...-ba7b130 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: BSD-3-Clause Imports: 20 Imported by: 1

README

i.MX Ethernet driver

This Go package implements TCP/IP connectivity through Ethernet (ENET) on NXP i.MX SoCs, to be used with GOOS=tamago GOARCH=arm as supported by the TamaGo framework for bare metal Go on ARM SoCs.

The package supports TCP/IP networking through gVisor (go branch) tcpip stack pure Go implementation.

The interface TCP/IP stack can be attached to the Go runtime by setting net.SocketFunc to the interface Socket function:

iface, _ := imxenet.Init(usbarmory.ENET2, "10.0.0.1", "255.255.255.0", "1a:55:89:a2:69:41", "10.0.0.2", 1)
net.SocketFunc = iface.Socket

See tamago-example for a full integration example.

Authors

Andrea Barisani
andrea.barisani@withsecure.com | andrea@inversepath.com

Andrej Rosano
andrej.rosano@withsecure.com | andrej@inversepath.com

Documentation

The package API documentation can be found on pkg.go.dev.

For more information about TamaGo see its repository and project wiki.

License

tamago | https://github.com/usbarmory/imx-enet
Copyright (c) WithSecure Corporation

These source files are distributed under the BSD-style license found in the LICENSE file.

Documentation

Overview

Package enet implements TCP/IP connectivity through Ethernet (ENET) controllers on i.MX6 SoCs.

The TCP/IP stack is implemented using gVisor pure Go implementation.

This package is only meant to be used with `GOOS=tamago GOARCH=arm` as supported by the TamaGo framework for bare metal Go, see https://github.com/usbarmory/tamago.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MTU represents the Ethernet Maximum Transmission Unit.
	MTU uint32 = enet.MTU

	// 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 Interface

type Interface struct {
	NICID tcpip.NICID
	NIC   *NIC

	Stack *stack.Stack
	Link  *channel.Endpoint
}

Interface represents an Ethernet interface instance.

func (*Interface) DialContextTCP4

func (iface *Interface) DialContextTCP4(ctx context.Context, address string) (net.Conn, error)

DialContextTCP4 connects to an IPv4 TCP address with support for timeout supplied by ctx.

func (*Interface) DialTCP4

func (iface *Interface) DialTCP4(address string) (net.Conn, error)

DialTCP4 connects to an IPv4 TCP address.

func (*Interface) DialUDP4

func (iface *Interface) DialUDP4(lAddr, rAddr string) (net.Conn, error)

DialUDP4 creates a UDP connection to the ip:port specified by rAddr, optionally setting the local ip:port to lAddr.

func (*Interface) EnableICMP

func (iface *Interface) EnableICMP() error

EnableICMP adds an ICMP endpoint to the interface, it is useful to enable ping requests.

func (*Interface) Init

func (iface *Interface) Init(nic *enet.ENET, ip string, netmask string, mac string, gateway string) (err error)

Init initializes an ENET Ethernet interface associating it to a gVisor link, a default NICID and TCP/IP gVisor Stack are set if not previously assigned.

func (*Interface) ListenerTCP4

func (iface *Interface) ListenerTCP4(port uint16) (net.Listener, error)

ListenerTCP4 returns a net.Listener capable of accepting IPv4 TCP connections for the argument port.

func (*Interface) Socket

func (iface *Interface) Socket(ctx context.Context, network string, family, sotype int, laddr, raddr net.Addr) (c interface{}, err error)

Socket can be used as net.SocketFunc under GOOS=tamago to allow its use internal use within the Go runtime.

type NIC

type NIC struct {
	// MAC address
	MAC net.HardwareAddr

	// Link is a gVisor channel endpoint
	Link *channel.Endpoint

	// Device is the physical interface associated to the virtual one.
	Device *enet.ENET
}

NIC represents an virtual Ethernet instance.

func (*NIC) Init

func (eth *NIC) Init() (err error)

Init initializes a virtual Ethernet instance bound to a physical Ethernet device.

func (*NIC) Rx

func (eth *NIC) Rx(buf []byte)

Rx receives a single Ethernet frame from the virtual Ethernet instance.

func (*NIC) Tx

func (eth *NIC) Tx() (buf []byte)

Tx transmits a single Ethernet frame to the virtual Ethernet instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL