libproxy

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package libproxy provides a network Proxy interface and implementations for TCP and UDP.

Index

Constants

View Source
const (
	// UDPConnTrackTimeout is the timeout used for UDP connection tracking
	UDPConnTrackTimeout = 90 * time.Second
	// UDPBufSize is the buffer size for the UDP proxy
	UDPBufSize = 65507
)

Variables

This section is empty.

Functions

func ExposePort added in v0.2.0

func ExposePort(host net.Addr, container net.Addr) (*os.File, error)

ExposePort exposes a port using 9p

func Forward added in v0.3.0

func Forward(conn Conn, destination Destination, quit <-chan struct{})

Forward a connection to a given destination.

func HandleTCPConnection

func HandleTCPConnection(client Conn, backendAddr *net.TCPAddr, quit <-chan struct{}) error

HandleTCPConnection forwards the TCP traffic to a specified backend address

func HandleUnixConnection added in v0.3.0

func HandleUnixConnection(client Conn, backendAddr *net.UnixAddr, quit <-chan struct{}) error

HandleUnixConnection forwards the Unix traffic to a specified backend address

func ProxyStream added in v0.4.0

func ProxyStream(client, backend Conn, quit <-chan struct{}) error

ProxyStream data between client and backend, until both are at EOF or quit is closed.

func SetLogger added in v0.4.0

func SetLogger(l *logrus.Logger)

SetLogger sets a new default logger

Types

type CloseFrame added in v0.3.0

type CloseFrame struct {
}

CloseFrame requests to disconnect from a proxy backend

type Command added in v0.3.0

type Command int8

Command is the action requested by a message.

const (
	// Open requests to open a connection to a backend service.
	Open Command = iota + 1
	// Close requests and then acknowledges the close of a sub-connection
	Close
	// Shutdown indicates that no more data will be written in this direction
	Shutdown
	// Data is a payload of a connection/sub-connection
	Data
	// Window is permission to send and consume buffer space
	Window
)

type Conn

type Conn interface {
	net.Conn
	CloseWrite() error
}

Conn defines a network connection

type Connection added in v0.3.0

type Connection int8

Connection indicates whether the connection will use multiplexing or not.

const (
	// Dedicated means this connection will not use multiplexing
	Dedicated Connection = iota + 1
	// Multiplexed means this connection will contain labelled sub-connections mixed together
	Multiplexed
)

func (Connection) String added in v0.3.0

func (c Connection) String() string

type DataFrame added in v0.3.0

type DataFrame struct {
	// contains filtered or unexported fields
}

DataFrame is the header of a frame containing user data

func (*DataFrame) Size added in v0.3.0

func (d *DataFrame) Size() int

Size returns the marshalled size of the data payload header

func (*DataFrame) Write added in v0.3.0

func (d *DataFrame) Write(w io.Writer) error

type Destination added in v0.3.0

type Destination struct {
	Proto Proto
	IP    net.IP
	Port  uint16
	Path  string
}

Destination refers to a listening TCP or UDP service

func (Destination) Size added in v0.3.0

func (d Destination) Size() int

Size returns the marshalled size in bytes

func (Destination) String added in v0.3.0

func (d Destination) String() string

func (Destination) Write added in v0.3.0

func (d Destination) Write(w io.Writer) error

type Frame added in v0.3.0

type Frame struct {
	Command Command // Command is the action erquested
	ID      uint32  // Id of the sub-connection, managed by the client
	// contains filtered or unexported fields
}

Frame is the low-level message sent to the multiplexer

func NewClose added in v0.3.0

func NewClose(ID uint32) *Frame

NewClose creates a close frame

func NewData added in v0.3.0

func NewData(ID, payloadlen uint32) *Frame

NewData creates a data header frame

func NewOpen added in v0.3.0

func NewOpen(ID uint32, d Destination) *Frame

NewOpen creates an open message

func NewShutdown added in v0.3.0

func NewShutdown(ID uint32) *Frame

NewShutdown creates a shutdown frame

func NewWindow added in v0.3.0

func NewWindow(ID uint32, seq uint64) *Frame

NewWindow creates a Window message

func (*Frame) Data added in v0.3.0

func (f *Frame) Data() (*DataFrame, error)

Data returns the payload of the frame, if it has Command = Data

func (*Frame) Open added in v0.3.0

func (f *Frame) Open() (*OpenFrame, error)

Open returns the payload of the frame, if it has Command = Open

func (*Frame) Payload added in v0.3.0

func (f *Frame) Payload() interface{}

Payload returns the payload of the frame.

func (*Frame) Size added in v0.3.0

func (f *Frame) Size() int

Size returns the marshalled size of the frame

func (*Frame) String added in v0.3.0

func (f *Frame) String() string

func (*Frame) Window added in v0.3.0

func (f *Frame) Window() (*WindowFrame, error)

Window returns the payload of the frame, if it has Command = Window.

func (*Frame) Write added in v0.3.0

func (f *Frame) Write(w io.Writer) error

type Multiplexer added in v0.3.0

type Multiplexer interface {
	Run()            // Run the multiplexer (otherwise Dial, Accept will not work)
	IsRunning() bool // IsRunning is true if the multiplexer is running normally, false if it has failed

	Dial(d Destination) (Conn, error)    // Dial a remote Destination
	Accept() (Conn, *Destination, error) // Accept a connection from a remote Destination

	Close() error // Close the multiplexer

	DumpState(w io.Writer) // WriteState dumps debug state to the writer
}

Multiplexer muxes and demuxes sub-connections over a single connection

func NewMultiplexer added in v0.3.0

func NewMultiplexer(label string, conn io.ReadWriteCloser, allocateBackwards bool) (Multiplexer, error)

NewMultiplexer constructs a multiplexer from a channel

type OpenFrame added in v0.3.0

type OpenFrame struct {
	Connection  Connection // Connection describes whether the opened connection should be dedicated or multiplexed
	Destination Destination
}

OpenFrame requests to connect to a proxy backend

func (*OpenFrame) Size added in v0.3.0

func (o *OpenFrame) Size() int

Size returns the marshalled size of the Open message

func (*OpenFrame) Write added in v0.3.0

func (o *OpenFrame) Write(w io.Writer) error

type Proto added in v0.3.0

type Proto uint8

Proto is the protocol of the flow

const (
	// TCP flow
	TCP Proto = 1
	// UDP flow
	UDP Proto = 2
	// Unix domain socket flow
	Unix Proto = 3
)

type Proxy

type Proxy interface {
	// Run starts forwarding traffic back and forth between the front
	// and back-end addresses.
	Run()
	// Close stops forwarding traffic and close both ends of the Proxy.
	Close()
	// FrontendAddr returns the address on which the proxy is listening.
	FrontendAddr() net.Addr
	// BackendAddr returns the proxied address.
	BackendAddr() net.Addr
}

Proxy defines the behavior of a proxy. It forwards traffic back and forth between two endpoints : the frontend and the backend. It can be used to do software port-mapping between two addresses. e.g. forward all traffic between the frontend (host) 127.0.0.1:3000 to the backend (container) at 172.17.42.108:4000.

func NewBestEffortIPProxy added in v0.2.0

func NewBestEffortIPProxy(host net.Addr, container net.Addr) (Proxy, error)

NewBestEffortIPProxy Best-effort attempt to listen on the address in the VM. This is for backwards compatibility with software that expects to be able to listen on 0.0.0.0 and then connect from within a container to the external port. If the address doesn't exist in the VM (i.e. it exists only on the host) then this is not a hard failure.

func NewIPProxy

func NewIPProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)

NewIPProxy creates a Proxy according to the specified frontendAddr and backendAddr.

func NewStubProxy

func NewStubProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)

NewStubProxy creates a new StubProxy

type ShutdownFrame added in v0.3.0

type ShutdownFrame struct {
}

ShutdownFrame requests to close the write channel to a proxy backend

type StubProxy

type StubProxy struct {
	// contains filtered or unexported fields
}

StubProxy is a proxy that is a stub (does nothing).

func (*StubProxy) BackendAddr

func (p *StubProxy) BackendAddr() net.Addr

BackendAddr returns the backend address.

func (*StubProxy) Close

func (p *StubProxy) Close()

Close does nothing.

func (*StubProxy) FrontendAddr

func (p *StubProxy) FrontendAddr() net.Addr

FrontendAddr returns the frontend address.

func (*StubProxy) Run

func (p *StubProxy) Run()

Run does nothing.

type TCPProxy

type TCPProxy struct {
	// contains filtered or unexported fields
}

TCPProxy is a proxy for TCP connections. It implements the Proxy interface to handle TCP traffic forwarding between the frontend and backend addresses.

func NewTCPProxy

func NewTCPProxy(listener net.Listener, backendAddr *net.TCPAddr) (*TCPProxy, error)

NewTCPProxy creates a new TCPProxy.

func (*TCPProxy) BackendAddr

func (proxy *TCPProxy) BackendAddr() net.Addr

BackendAddr returns the TCP proxied address.

func (*TCPProxy) Close

func (proxy *TCPProxy) Close()

Close stops forwarding the traffic.

func (*TCPProxy) FrontendAddr

func (proxy *TCPProxy) FrontendAddr() net.Addr

FrontendAddr returns the TCP address on which the proxy is listening.

func (*TCPProxy) Run

func (proxy *TCPProxy) Run()

Run starts forwarding the traffic using TCP.

type UDPDialer added in v0.4.0

type UDPDialer interface {
	Dial(*net.UDPAddr) (net.Conn, error)
}

UDPDialer creates UDP (pseudo-)connections to an address

type UDPListener

type UDPListener interface {
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
	WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
	Close() error
	LocalAddr() net.Addr
}

UDPListener defines a listener interface to read, write and close a UDP connection

type UDPProxy

type UDPProxy struct {
	// contains filtered or unexported fields
}

UDPProxy is proxy for which handles UDP datagrams. It implements the Proxy interface to handle UDP traffic forwarding between the frontend and backend addresses.

func NewUDPProxy

func NewUDPProxy(frontendAddr net.Addr, listener UDPListener, backendAddr *net.UDPAddr, dialer UDPDialer) (*UDPProxy, error)

NewUDPProxy creates a new UDPProxy.

func (*UDPProxy) BackendAddr

func (proxy *UDPProxy) BackendAddr() net.Addr

BackendAddr returns the proxied UDP address.

func (*UDPProxy) Close

func (proxy *UDPProxy) Close()

Close stops forwarding the traffic.

func (*UDPProxy) FrontendAddr

func (proxy *UDPProxy) FrontendAddr() net.Addr

FrontendAddr returns the UDP address on which the proxy is listening.

func (*UDPProxy) Run

func (proxy *UDPProxy) Run()

Run starts forwarding the traffic using UDP.

type UnixProxy added in v0.3.0

type UnixProxy struct {
	// contains filtered or unexported fields
}

UnixProxy is a proxy for Unix connections. It implements the Proxy interface to handle Unix traffic forwarding between the frontend and backend addresses.

func NewUnixProxy added in v0.3.0

func NewUnixProxy(listener net.Listener, backendAddr *net.UnixAddr) (*UnixProxy, error)

NewUnixProxy creates a new UnixProxy.

func (*UnixProxy) BackendAddr added in v0.3.0

func (proxy *UnixProxy) BackendAddr() net.Addr

BackendAddr returns the Unix proxied address.

func (*UnixProxy) Close added in v0.3.0

func (proxy *UnixProxy) Close()

Close stops forwarding the traffic.

func (*UnixProxy) FrontendAddr added in v0.3.0

func (proxy *UnixProxy) FrontendAddr() net.Addr

FrontendAddr returns the Unix address on which the proxy is listening.

func (*UnixProxy) Run added in v0.3.0

func (proxy *UnixProxy) Run()

Run starts forwarding the traffic using Unix.

type WindowFrame added in v0.3.0

type WindowFrame struct {
	// contains filtered or unexported fields
}

WindowFrame is a window advertisement message

func (*WindowFrame) Size added in v0.3.0

func (win *WindowFrame) Size() int

Size returned the marshalled size of the Window payload

func (*WindowFrame) Write added in v0.3.0

func (win *WindowFrame) Write(w io.Writer) error

Jump to

Keyboard shortcuts

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