l2

package module
v0.0.0-...-34d6001 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 35 Imported by: 0

README

l2

Layer-2 bridging over TCP / UDP / ICMP

Documentation

Index

Constants

View Source
const (
	BridgeICMP = "ICMP"
	BridgeTCP  = "TCP"
	BridgeUDP  = "UDP"
)
View Source
const (
	EvTCP = iota + 1
	EvTCPReady
	EvTCPConnAdded
	EvTCPConnDeleted
	EvTCPReadInboundError
	EvTCPConnGotAddr
	EvTCPConnGotIP
	EvTCPInboundSent
	EvTCPListening
	EvTCPListenFailed
	EvTCPListened
	EvTCPAccepted
	EvTCPDialing
	EvTCPDialed
	EvTCPDialFailed
	EvTCPRefreshed
	EvTCPWriteError
	EvTCPNotSent
	EvTCPListenerClosed
	EvTCPClosed
	EvTCPSlow

	EvUDP
	EvUDPReady
	EvUDPRemoteAdded
	EvUDPLocalAdded
	EvUDPConnReadError
	EvUDPReadInboundError
	EvUDPLocalClosed
	EvUDPRemoteClosed
	EvUDPRemoteGotAddr
	EvUDPRemoteGotIP
	EvUDPInboundSent
	EvUDPWriteError
	EvUDPNotSent
	EvUDPClosed

	EvICMP
	EvICMPReady
	EvICMPClosed
	EvICMPNotSent
	EvICMPInboundSent
	EvICMPReadInboundError
	EvICMPWriteError

	EvNetwork
	EvNetworkClosing
	EvNetworkOutboundSent
	EvNetworkInboundReceived
	EvNetworkInboundDuplicated
	EvNetworkInboundWritten
)

Variables

View Source
var (
	EthernetBroadcast = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
	IPv4zero          = net.IPv4(0, 0, 0, 0)
)

Functions

This section is empty.

Types

type AllNodes

type AllNodes []*Node

type Close

type Close func()

type CloseWaitGroup

type CloseWaitGroup struct {
	*sync.WaitGroup
}

type Closing

type Closing chan struct{}

type CryptoKey

type CryptoKey []byte

type CryptoKeyInt

type CryptoKeyInt uint64

type GetReachableIP

type GetReachableIP func(node *Node) net.IP

type GetTime

type GetTime func() time.Time

type HardwareAddr

type HardwareAddr = net.HardwareAddr

type Hostname

type Hostname string

type ICMPInbound

type ICMPInbound struct {
	Addr    *net.IPAddr
	ID      uint16
	Inbound *Inbound
}

type ICMPRemote

type ICMPRemote struct {
	ID  uint16
	IP  net.IP
	IPs []net.IP
}

type Inbound

type Inbound struct {
	WireData
	DestAddr    *net.HardwareAddr
	BridgeIndex uint8
}

type InitNodes

type InitNodes []*Node

type Interface

type Interface interface {
	io.ReadWriteCloser
	Name() string
}

type MTU

type MTU int

type Network

type Network struct {
	RootScope Scope
}

func NewNetwork

func NewNetwork(parent Scope, defSets ...[]any) *Network

func (Network) AllNodes

func (Network) AllNodes(
	localNode *Node,
	initNodes InitNodes,
) AllNodes

func (Network) Close

func (n Network) Close(
	trigger Trigger,
) (
	closing Closing,
	wg CloseWaitGroup,
	_close Close,
)

func (Network) CryptoKey

func (Network) CryptoKey() CryptoKey

func (Network) CryptoKeyInt

func (Network) CryptoKeyInt(
	key CryptoKey,
) CryptoKeyInt

func (Network) Events

func (Network) Events() (
	on On,
	trigger Trigger,
)

func (Network) GetReachableIP

func (Network) GetReachableIP(
	sysAddrs SystemInterfaceAddrs,
) GetReachableIP

func (Network) GetTime

func (Network) GetTime() GetTime

func (Network) HardwareAddr

func (Network) HardwareAddr(
	iface Interface,
) HardwareAddr

func (Network) Hostname

func (Network) Hostname() Hostname

func (Network) IPNet

func (Network) IPNet() net.IPNet

func (Network) InitNodes

func (Network) InitNodes() InitNodes

func (Network) Interface

func (Network) Interface(
	localNode *Node,
	ipnet net.IPNet,
	mtu MTU,
) Interface

func (Network) LocalNode

func (Network) LocalNode(
	selectNode SelectNode,
	ipnet net.IPNet,
	initNodes InitNodes,
) *Node

func (Network) MTU

func (Network) MTU() MTU

func (Network) NewSendQueue

func (Network) NewSendQueue(
	writeOutbound WriteOutbound,
	mtu MTU,
) NewSendQueue

func (Network) OnFrameFunc

func (Network) OnFrameFunc() OnFrameFunc

func (Network) PreferFormatFunc

func (Network) PreferFormatFunc() PreferFormatFunc

func (Network) ReadInbound

func (Network) ReadInbound(
	key CryptoKey,
	keyInt CryptoKeyInt,
) ReadInbound

func (Network) SelectNode

func (Network) SelectNode() SelectNode

func (Network) Spawn

func (Network) Spawn(
	wg CloseWaitGroup,
) Spawn

func (*Network) Start

func (n *Network) Start(
	localNode *Node,
	startTCP StartTCP,
	startUDP StartUDP,
	startICMP StartICMP,
	spawn Spawn,
	on On,
	closing Closing,
	mtu MTU,
	preferFormatFunc PreferFormatFunc,
	iface Interface,
	ipnet net.IPNet,
	onFrameFunc OnFrameFunc,
	cryptoKey CryptoKey,
	cryptoKeyInt CryptoKeyInt,
	trigger Trigger,
	hwAddr HardwareAddr,
) Start

func (*Network) StartICMP

func (n *Network) StartICMP(
	spawn Spawn,
	closing Closing,
	trigger Trigger,
	sysAddrs SystemInterfaceAddrs,
	localNode *Node,
	mtu MTU,
	readInbound ReadInbound,
	newSendQueue NewSendQueue,
	allNodes AllNodes,
	getReachableIP GetReachableIP,
) StartICMP

func (*Network) StartTCP

func (n *Network) StartTCP(
	closing Closing,
	spawn Spawn,
	getTime GetTime,
	trigger Trigger,
	sysAddrs SystemInterfaceAddrs,
	readInbound ReadInbound,
	localNode *Node,
	newSendQueue NewSendQueue,
	key CryptoKey,
	allNodes AllNodes,
	getReachableIP GetReachableIP,
) StartTCP

func (*Network) StartUDP

func (n *Network) StartUDP(
	spawn Spawn,
	closing Closing,
	getTime GetTime,
	trigger Trigger,
	sysAddrs SystemInterfaceAddrs,
	localNode *Node,
	mtu MTU,
	readInbound ReadInbound,
	key CryptoKey,
	newSendQueue NewSendQueue,
	allNodes AllNodes,
	getReachableIP GetReachableIP,
) StartUDP

func (Network) SystemInterfaceAddrs

func (Network) SystemInterfaceAddrs() SystemInterfaceAddrs

func (Network) WriteOutbound

func (Network) WriteOutbound(
	key CryptoKey,
	keyInt CryptoKeyInt,
) WriteOutbound

type NewSendQueue

type NewSendQueue func(
	sendFunc queueSendFunc,
) *sendQueue

type Node

type Node struct {
	LanIP       net.IP
	WanHost     string // reachable from anywhere
	PrivateIP   net.IP // reachable from local lan
	BridgeNames []string
	ID          int // to allow multiple nodes in single host
	// contains filtered or unexported fields
}

func (*Node) HasBridge

func (n *Node) HasBridge(name string) bool

func (*Node) Init

func (n *Node) Init()

type On

type On func(ev any, fn any)

type OnFrameFunc

type OnFrameFunc func([]byte)

type Outbound

type Outbound struct {
	WireData
	DestIP       *net.IP
	DestAddr     *net.HardwareAddr
	PreferFormat WireFormat
	// contains filtered or unexported fields
}

type PreferFormatFunc

type PreferFormatFunc func(
	*layers.Ethernet,
	*layers.ARP,
	*layers.IPv4,
	*layers.TCP,
	*layers.UDP,
	*[]gopacket.LayerType,
) WireFormat

type ReadInbound

type ReadInbound func(r io.Reader) (inbound *Inbound, err error)

type Scope

type Scope = dscope.Scope

type SelectNode

type SelectNode func() *Node

type Spawn

type Spawn func(fn func())

type Start

type Start func() (err error)

type StartICMP

type StartICMP func(
	bridgeIndex int,
	inboundChan chan *Inbound,
	outboundChan chan *Outbound,
	ready chan struct{},
	inboundSenderGroup *sync.WaitGroup,
)

type StartTCP

type StartTCP func(
	bridgeIndex int,
	inboundChan chan *Inbound,
	outboundChan chan *Outbound,
	ready chan struct{},
	inboundSenderGroup *sync.WaitGroup,
)

type StartUDP

type StartUDP func(
	bridgeIndex int,
	inboundChan chan *Inbound,
	outboundChan chan *Outbound,
	ready chan struct{},
	inboundSenderGroup *sync.WaitGroup,
)

type SystemInterfaceAddrs

type SystemInterfaceAddrs []net.Addr

type TCPConn

type TCPConn struct {
	sync.RWMutex
	*net.TCPConn

	IPs   []net.IP
	Addrs []net.HardwareAddr
	T0    time.Time
	// contains filtered or unexported fields
}

type TCPListener

type TCPListener struct {
	Listener  net.Listener
	StartedAt time.Time
}

type Trigger

type Trigger func(scope Scope, evs ...any)

type UDPInbound

type UDPInbound struct {
	RemoteAddr *net.UDPAddr
	Inbound    *Inbound
	LocalPort  int
}

type UDPLocal

type UDPLocal struct {
	Conn      *net.UDPConn
	Port      int
	StartedAt time.Time
}

type UDPRemote

type UDPRemote struct {
	UDPAddr    *net.UDPAddr
	UDPAddrStr string
	AddedAt    time.Time
	IPs        []net.IP
	Addrs      []net.HardwareAddr
}

type WireData

type WireData struct {
	Eth    []byte
	Serial uint64
}

type WireFormat

type WireFormat byte
const (
	FormatChacha20Poly1305 WireFormat = iota
	FormatAESGCM
	FormatChacha20Poly1305Partial

	AESGCMNonceSize = 12
)

type WriteOutbound

type WriteOutbound func(w io.Writer, outbound *Outbound) (err error)

Jump to

Keyboard shortcuts

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