Documentation ¶
Index ¶
- Constants
- Variables
- func FreeBytes(b []byte)
- func FreeConnKeyArg(p unsafe.Pointer)
- func GetConnKeyVal(p unsafe.Pointer) uint32
- func GetSyncMapLen(m sync.Map) int
- func IPAddrATON(cp string, addr *C.struct_ip_addr)
- func IPAddrNTOA(ipaddr C.struct_ip_addr) string
- func Input(pkt []byte) (int, error)
- func NewBytes(size int) []byte
- func NewConnKeyArg() unsafe.Pointer
- func NewLWIPError(code int) error
- func Output(p *C.struct_pbuf) C.err_t
- func ParseTCPAddr(addr string, port uint16) net.Addr
- func ParseUDPAddr(addr string, port uint16) net.Addr
- func RegisterOutputFn(fn func([]byte) (int, error))
- func RegisterTCPConnectionHandler(h ConnectionHandler)
- func RegisterUDPConnectionHandler(h ConnectionHandler)
- func SetBufferPool(p *sync.Pool)
- func SetConnKeyVal(p unsafe.Pointer, val uint32)
- func SetTCPAcceptCallback(pcb *C.struct_tcp_pcb)
- func SetTCPErrCallback(pcb *C.struct_tcp_pcb)
- func SetTCPPollCallback(pcb *C.struct_tcp_pcb, interval C.u8_t)
- func SetTCPRecvCallback(pcb *C.struct_tcp_pcb)
- func SetTCPSentCallback(pcb *C.struct_tcp_pcb)
- func SetUDPRecvCallback(pcb *C.struct_udp_pcb, recvArg unsafe.Pointer)
- func TCPAcceptFn(arg unsafe.Pointer, newpcb *C.struct_tcp_pcb, err C.err_t) C.err_t
- func TCPErrFn(arg unsafe.Pointer, err C.err_t)
- func TCPPollFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb) C.err_t
- func TCPRecvFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb, p *C.struct_pbuf, err C.err_t) C.err_t
- func TCPSentFn(arg unsafe.Pointer, tpcb *C.struct_tcp_pcb, len C.u16_t) C.err_t
- func UDPRecvFn(arg unsafe.Pointer, pcb *C.struct_udp_pcb, p *C.struct_pbuf, addr *C.ip_addr_t, ...)
- type Connection
- type ConnectionHandler
- type LWIPStack
Constants ¶
const ( LWIP_ERR_OK int = iota LWIP_ERR_ABRT )
const BufSize = 2 * 1024
const CHECK_TIMEOUTS_INTERVAL = 250 // in millisecond
const TCP_POLL_INTERVAL = 2 * (float32(1000) / CHECK_TIMEOUTS_INTERVAL) // poll every 2 seconds
Variables ¶
var OutputFn func([]byte) (int, error)
Functions ¶
func FreeConnKeyArg ¶
func GetConnKeyVal ¶
func GetSyncMapLen ¶
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 NewConnKeyArg ¶
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.
func NewLWIPError ¶
func RegisterOutputFn ¶
func RegisterTCPConnectionHandler ¶
func RegisterTCPConnectionHandler(h ConnectionHandler)
func RegisterUDPConnectionHandler ¶
func RegisterUDPConnectionHandler(h ConnectionHandler)
func SetBufferPool ¶
func SetConnKeyVal ¶
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 ¶
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) (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.