core

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 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
View Source
const CHECK_TIMEOUTS_INTERVAL = 250 // in millisecond
View Source
const TCP_POLL_INTERVAL = 2 * (float32(1000) / CHECK_TIMEOUTS_INTERVAL) // poll every 2 seconds

Variables

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

Functions

func FreeBytes

func FreeBytes(b []byte)

func FreeConnKeyArg

func FreeConnKeyArg(p unsafe.Pointer)

func GetConnKeyVal

func GetConnKeyVal(p unsafe.Pointer) uint32

func GetSyncMapLen

func GetSyncMapLen(m sync.Map) int

func IPAddrATON

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

func IPAddrNTOA

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

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

func NewBytes

func NewBytes(size int) []byte

func NewConnKeyArg

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

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

func RegisterTCPConnectionHandler(h ConnectionHandler)

func RegisterUDPConnectionHandler

func RegisterUDPConnectionHandler(h ConnectionHandler)

func SetBufferPool

func SetBufferPool(p *sync.Pool)

func SetConnKeyVal

func SetConnKeyVal(p unsafe.Pointer, val uint32)

func SetTCPAcceptCallback

func SetTCPAcceptCallback(pcb *C.struct_tcp_pcb)

func SetTCPErrCallback

func SetTCPErrCallback(pcb *C.struct_tcp_pcb)

func SetTCPPollCallback

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

func SetTCPRecvCallback

func SetTCPRecvCallback(pcb *C.struct_tcp_pcb)

func SetTCPSentCallback

func SetTCPSentCallback(pcb *C.struct_tcp_pcb)

func SetUDPRecvCallback

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

func TCPAcceptFn

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

func TCPErrFn

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

func TCPPollFn

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

func TCPRecvFn

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

func TCPSentFn

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

func UDPRecvFn

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

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

func NewTCPConnection(pcb *C.struct_tcp_pcb, handler ConnectionHandler, connKey uint32, connKeyArg unsafe.Pointer) (Connection, error)

func NewUDPConnection

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

type ConnectionHandler

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
	RestartTimeouts()
}

func NewLWIPStack

func NewLWIPStack() LWIPStack

Jump to

Keyboard shortcuts

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