core

package
v1.16.7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LWIP_ERR_OK int = iota
	LWIP_ERR_ABRT
	LWIP_ERR_CONN
	LWIP_ERR_CLSD
)
View Source
const BufSize = 2 * 1024
View Source
const CHECK_TIMEOUTS_INTERVAL = 250 // in millisecond
View Source
const TCP_POLL_INTERVAL = 8 // poll every 4 seconds

Variables

View Source
var OutputFn func([]byte) (int, error)

Functions

func FreeBytes

func FreeBytes(b []byte)

func Input

func Input(pkt []byte) (int, error)

func NewBytes

func NewBytes(size int) []byte

func NewLWIPError

func NewLWIPError(code int) error

func ParseTCPAddr

func ParseTCPAddr(addr string, port uint16) *net.TCPAddr

func ParseUDPAddr

func ParseUDPAddr(addr string, port uint16) *net.UDPAddr

func RegisterOutputFn

func RegisterOutputFn(fn func([]byte) (int, error))

func RegisterTCPConnHandler added in v1.12.0

func RegisterTCPConnHandler(h TCPConnHandler)

func RegisterUDPConnHandler added in v1.12.0

func RegisterUDPConnHandler(h UDPConnHandler)

func SetBufferPool

func SetBufferPool(p *sync.Pool)

Types

type LWIPStack

type LWIPStack interface {
	Write([]byte) (int, error)
	Close() error
	RestartTimeouts()
}

func NewLWIPStack

func NewLWIPStack() LWIPStack

NewLWIPStack listens for any incoming connections/packets and registers corresponding accept/recv callback functions.

type TCPConn added in v1.12.0

type TCPConn interface {
	// Sent will be called when sent data has been acknowledged by peer.
	Sent(len uint16) error

	// Receive will be called when data arrives from TUN.
	Receive(data []byte) error

	// Err will be called when a fatal error has occurred on the connection.
	// The corresponding pcb is already freed when this callback is called
	Err(err error)

	// LocalClosed will be called when lwIP receives a FIN segment on a
	// connection.
	LocalClosed() error

	// Poll will be periodically called by TCP timers.
	Poll() error

	// RemoteAddr returns the destination network address.
	RemoteAddr() net.Addr

	// LocalAddr returns the local client network address.
	LocalAddr() net.Addr

	// Read reads data comming from TUN, note that it reads from an
	// underlying pipe that the writer writes in the lwip thread,
	// write op blocks until previous written data is consumed, one
	// should read out all data as soon as possible.
	Read(data []byte) (int, error)

	// Write writes data to TUN.
	Write(data []byte) (int, error)

	// Close closes the connection.
	Close() error

	// CloseWrite closes the writing side by sending a FIN
	// segment to local peer. That means we can write no further
	// data to TUN.
	CloseWrite() error

	// CloseRead closes the reading side. That means we can no longer
	// read more from TUN.
	CloseRead() error

	// Abort aborts the connection by sending a RST segment.
	Abort()

	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

TCPConn abstracts a TCP connection comming from TUN. This connection should be handled by a registered TCP proxy handler. It's important to note that callback members are called from lwIP, they are already in the lwIP thread when they are called, that is, they are holding the lwipMutex.

type TCPConnHandler added in v1.12.0

type TCPConnHandler interface {
	// Handle handles the conn for target.
	Handle(conn net.Conn, target *net.TCPAddr) error
}

TCPConnHandler handles TCP connections comming from TUN.

type UDPConn added in v1.12.0

type UDPConn interface {
	// LocalAddr returns the local client network address.
	LocalAddr() *net.UDPAddr

	// ReceiveTo will be called when data arrives from TUN, and the received
	// data should be sent to addr.
	ReceiveTo(data []byte, addr *net.UDPAddr) error

	// WriteFrom writes data to TUN, addr will be set as source address of
	// UDP packets that output to TUN.
	WriteFrom(data []byte, addr *net.UDPAddr) (int, error)

	// Close closes the connection.
	Close() error
}

TCPConn abstracts a UDP connection comming from TUN. This connection should be handled by a registered UDP proxy handler.

type UDPConnHandler added in v1.12.0

type UDPConnHandler interface {
	// Connect connects the proxy server. Note that target can be nil.
	Connect(conn UDPConn, target *net.UDPAddr) error

	// ReceiveTo will be called when data arrives from TUN.
	ReceiveTo(conn UDPConn, data []byte, addr *net.UDPAddr) error
}

UDPConnHandler handles UDP connections comming from TUN.

Jump to

Keyboard shortcuts

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