gnet

package module
v0.0.0-...-93d9ffe Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: BSD-3-Clause Imports: 21 Imported by: 0

README

Bare metal Go TCP/IP connectivity

This Go package implements TCP/IP connectivity through a generic network interface to be used with GOOS=tamago as supported by the TamaGo framework for bare metal Go.

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:

// TamaGo UEFI Simple Network interface
nic, _ := &x64.UEFI.Boot.GetNetwork{}

// gnet interface
iface := gnet.Interface{}

// initialize IP, MAC, Gateway
_ = iface.Init(nic, "10.0.0.1/24", "", "10.0.0.2")

// Go runtime hook
net.SocketFunc = iface.Socket

See go-boot for a full integration example with the UEFI Simple Network Protocol.

Authors

Andrea Barisani
[email protected]

Andrej Rosano
[email protected]

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/go-net
Copyright (c) The go-net authors. All Rights Reserved.

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

Documentation

Overview

Package gnet implements TCP/IP connectivity through a generic NetworkDevice interface.

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

This section is empty.

Variables

View Source
var (
	// MTU represents the Ethernet Maximum Transmission Unit.
	MTU uint32 = 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 Interface

type Interface struct {
	NICID tcpip.NICID
	NIC   *NIC

	Stack *stack.Stack
	Link  *channel.Endpoint
}

Interface represents an Ethernet interface instance.

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 NetworkDevice, addr string, mac string, gateway string) (err error)

Init initializes a NetworkDevice associating it to a gVisor link, a default NICID and TCP/IP gVisor Stack are set if not previously assigned, a random MAC address is set if its argument is empty.

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 NetworkDevice
}

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) Start

func (eth *NIC) Start()

Start begins processing of incoming packets, the function receives packets through [NetworkDevice.Receive] and handles them through NIC.Rx, it should never return.

func (*NIC) Tx

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

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

type NetworkDevice

type NetworkDevice interface {
	// Receive receives a single Ethernet frame from a network adapter.
	Receive(buf []byte) (n int, err error)
	// Transmit transmits a single Ethernet frame to a network adapter.
	Transmit(buf []byte) (err error)
}

NetworkDevice represents a generic network device interface capable of receiving and transmitting raw Ethernet frames.

Jump to

Keyboard shortcuts

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