netstack

package module
v0.0.0-...-6119cc6 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BufConfig = []int{128, 256, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}

BufConfig defines the shape of the vectorised view used to read packets from the NIC.

View Source
var (
	Dump = false
)

Functions

func DefTcpServer

func DefTcpServer(nt *NetstackTun, handler TUNHandler) (tcpip.Endpoint, waiter.Queue, error)
func NewReaderWriterLink(tunw io.WriteCloser, tunr io.Reader, opts *Options) tcpip.LinkEndpointID

New creates a new fd-based endpoint.

Makes fd non-blocking, but does not take ownership of fd, which must remain open for the lifetime of the returned endpoint.

Types

type NetstackTun

type NetstackTun struct {
	// The IP stack serving the tun. It intercepts all TCP connections.
	IPStack *stack.Stack

	DefUDP tcpip.Endpoint
	DefTCP tcpip.Endpoint

	// If set, will be used to handle accepted TCP connections and UDP packets.
	// Else the Listener interface is used.
	Handler    TUNHandler
	UDPHandler UDPHandler
	// contains filtered or unexported fields
}

Intercept using a TUN and google netstack to parse TCP/UDP into streams. The connections are redirected to a capture.ProxyHandler

func NewTunCapture

func NewTunCapture(ep *tcpip.LinkEndpointID, handler TUNHandler, udpNat UDPHandler, snif bool) *NetstackTun

NewTunCapture creates an in-process tcp stack, backed by an tun-like network interface. All TCP streams initiated on the tun or localhost will be captured.

func (*NetstackTun) DefTcp6Server

func (nt *NetstackTun) DefTcp6Server() (tcpip.Endpoint, waiter.Queue, error)

func (*NetstackTun) WriteTo

func (nt *NetstackTun) WriteTo(data []byte, dst *net.UDPAddr, src *net.UDPAddr) (int, error)

type Options

type Options struct {
	MTU             uint32
	EthernetHeader  bool
	ChecksumOffload bool
	ClosedFunc      func(*tcpip.Error)
	Address         tcpip.LinkAddress
}

Options specify the details about the fd-based endpoint to be created.

type TUNHandler

type TUNHandler interface {
	HandleTUN(conn net.Conn, target *net.TCPAddr) error
}

Interface implemented by TUNHandler. Important: for android the system makes sure tun is the default route, but packets from the VPN app are excluded.

On Linux we need a similar setup. This still requires iptables to mark packets from istio-proxy, and use 2 routing tables.

type UDPHandler

type UDPHandler interface {
	HandleUdp(dstAddr net.IP, dstPort uint16,
		localAddr net.IP, localPort uint16,
		data []byte)
}

Interface implemented by TUNHandler.

type UdpLocalReader

type UdpLocalReader interface {
	ReadLocal(addr *tcpip.DoubleAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error)
}

type UdpWriter

type UdpWriter interface {
	WriteTo(data []byte, dstAddr *net.UDPAddr, srcAddr *net.UDPAddr) (int, error)
}

UdpWriter is the interface implemented by the TunTransport, to send packets back to the virtual interface

func NewTUNFD

func NewTUNFD(fd io.ReadWriteCloser, handler TUNHandler, udpNat UDPHandler) UdpWriter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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