core

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LWIP_ERR_OK int = iota
	LWIP_ERR_ABRT
)
View Source
const BufSize = 2 * 1024

Variables

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

Functions

func FreeBytes

func FreeBytes(b []byte)

func FreeConnKeyArg added in v1.8.1

func FreeConnKeyArg(p unsafe.Pointer)

func GetConnKeyVal added in v1.8.1

func GetConnKeyVal(p unsafe.Pointer) uint32

func GetSyncMapLen added in v1.8.1

func GetSyncMapLen(m sync.Map) int

func IPAddrATON added in v1.8.1

func IPAddrATON(cp string, addr *C.struct_ip_addr)

func IPAddrNTOA added in v1.8.1

func IPAddrNTOA(ipaddr C.struct_ip_addr) string

ipaddr_ntoa() is using a global static buffer to return result, reentrants are not allowed, caller is required to lock lwipMutex.

func Input added in v1.8.1

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

func NewBytes

func NewBytes(size int) []byte

func NewConnKeyArg added in v1.8.1

func NewConnKeyArg() unsafe.Pointer

We need such a key-value mechanism because when passing a Go pointer to C, the Go pointer will only be valid during the call. If we pass a Go pointer to tcp_arg(), this pointer will not be usable in subsequent callbacks (e.g.: tcp_recv(), tcp_err()).

Instead we need to pass a C pointer to tcp_arg(), we manually allocate the memory in C and return its pointer to Go code. After the connection end, the memory should be freed manually.

See also: https://github.com/golang/go/issues/12416

func NewLWIPError

func NewLWIPError(code int) error

func Output added in v1.8.1

func Output(p *C.struct_pbuf) C.err_t

func ParseTCPAddr

func ParseTCPAddr(addr string, port uint16) net.Addr

func ParseUDPAddr

func ParseUDPAddr(addr string, port uint16) net.Addr

func RegisterOutputFn

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

func RegisterTCPConnectionHandler added in v1.8.1

func RegisterTCPConnectionHandler(h ConnectionHandler)

func RegisterUDPConnectionHandler added in v1.8.1

func RegisterUDPConnectionHandler(h ConnectionHandler)

func SetBufferPool

func SetBufferPool(p *sync.Pool)

func SetConnKeyVal added in v1.8.1

func SetConnKeyVal(p unsafe.Pointer, val uint32)

func SetTCPAcceptCallback added in v1.8.1

func SetTCPAcceptCallback(pcb *C.struct_tcp_pcb)

func SetTCPErrCallback added in v1.8.1

func SetTCPErrCallback(pcb *C.struct_tcp_pcb)

func SetTCPPollCallback added in v1.8.1

func SetTCPPollCallback(pcb *C.struct_tcp_pcb, interval C.u8_t)

func SetTCPRecvCallback added in v1.8.1

func SetTCPRecvCallback(pcb *C.struct_tcp_pcb)

func SetTCPSentCallback added in v1.8.1

func SetTCPSentCallback(pcb *C.struct_tcp_pcb)

func SetUDPRecvCallback added in v1.8.1

func SetUDPRecvCallback(pcb *C.struct_udp_pcb, recvArg unsafe.Pointer)

func TCPAcceptFn added in v1.8.1

func TCPAcceptFn(arg unsafe.Pointer, newpcb *C.struct_tcp_pcb, err C.err_t) C.err_t

func TCPErrFn added in v1.8.1

func TCPErrFn(arg unsafe.Pointer, err C.err_t)

func TCPPollFn added in v1.8.1

func TCPPollFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb) C.err_t

func TCPRecvFn added in v1.8.1

func TCPRecvFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb, p *C.struct_pbuf, err C.err_t) C.err_t

func TCPSentFn added in v1.8.1

func TCPSentFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb, len C.u16_t) C.err_t

func UDPRecvFn added in v1.8.1

func UDPRecvFn(arg unsafe.Pointer, pcb *C.struct_udp_pcb, p *C.struct_pbuf, addr *C.ip_addr_t, port C.u16_t, destAddr *C.ip_addr_t, destPort C.u16_t)

Types

type Connection added in v1.8.1

type Connection interface {
	// RemoteAddr returns the destination network address.
	RemoteAddr() net.Addr

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

	// Receive receives data from TUN.
	Receive(data []byte) error

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

	// Sent will be called when sent data has been acknowledged by clients (TCP only).
	Sent(len uint16) error

	// Close closes the connection (TCP only).
	Close() error

	// Abort aborts the connection to client by sending a RST segment (TCP only).
	Abort()

	// Err will be called when a fatal error has occurred on the connection (TCP only).
	Err(err error)

	// LocalDidClose will be called when local client has close the connection (TCP only).
	LocalDidClose() error

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

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

func NewTCPConnection added in v1.8.1

func NewTCPConnection(pcb *C.struct_tcp_pcb, handler ConnectionHandler) (Connection, error)

func NewUDPConnection added in v1.8.1

func NewUDPConnection(pcb *C.struct_udp_pcb, handler ConnectionHandler, localIP, remoteIP C.ip_addr_t, localPort, remotePort C.u16_t) (Connection, error)

type ConnectionHandler added in v1.8.1

type ConnectionHandler interface {
	// Connect connects the proxy server.
	Connect(conn Connection, target net.Addr) error

	// DidReceive will be called when data arrives from TUN.
	DidReceive(conn Connection, data []byte) error

	// DidSend will be called when sent data has been acknowledged by local clients.
	DidSend(conn Connection, len uint16)

	// DidClose will be called when the connection has been closed.
	DidClose(conn Connection)

	// LocalDidClose will be called when local client has close the connection.
	LocalDidClose(conn Connection)
}

ConnectionHandler handles connections comming from TUN.

type LWIPStack

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

func NewLWIPStack

func NewLWIPStack() LWIPStack

Jump to

Keyboard shortcuts

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