Documentation ¶
Overview ¶
Package libproxy provides a network Proxy interface and implementations for TCP and UDP.
Index ¶
- Constants
- func ExposePort(host net.Addr, container net.Addr) (*os.File, error)
- func Forward(conn Conn, destination Destination, quit <-chan struct{})
- func HandleTCPConnection(client Conn, backendAddr *net.TCPAddr, quit <-chan struct{}) error
- func HandleUnixConnection(client Conn, backendAddr *net.UnixAddr, quit <-chan struct{}) error
- func ProxyStream(client, backend Conn, quit <-chan struct{}) error
- func SetLogger(l *logrus.Logger)
- type CloseFrame
- type Command
- type Conn
- type Connection
- type DataFrame
- type Destination
- type Frame
- type Multiplexer
- type OpenFrame
- type Proto
- type Proxy
- type ShutdownFrame
- type StubProxy
- type TCPProxy
- type UDPDialer
- type UDPListener
- type UDPProxy
- type UnixProxy
- type WindowFrame
Constants ¶
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
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 ¶
HandleTCPConnection forwards the TCP traffic to a specified backend address
func HandleUnixConnection ¶ added in v0.3.0
HandleUnixConnection forwards the Unix traffic to a specified backend address
func ProxyStream ¶ added in v0.4.0
ProxyStream data between client and backend, until both are at EOF or quit is closed.
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 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
type Destination ¶ added in v0.3.0
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
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 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
NewShutdown creates a shutdown frame
func (*Frame) Data ¶ added in v0.3.0
Data returns the payload of the frame, if it has Command = Data
func (*Frame) Open ¶ added in v0.3.0
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) Window ¶ added in v0.3.0
func (f *Frame) Window() (*WindowFrame, error)
Window returns the payload of the frame, if it has Command = Window.
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
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
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 ¶
NewIPProxy creates a Proxy according to the specified frontendAddr and backendAddr.
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 ¶
BackendAddr returns the backend address.
func (*StubProxy) FrontendAddr ¶
FrontendAddr returns the frontend address.
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 ¶
NewTCPProxy creates a new TCPProxy.
func (*TCPProxy) BackendAddr ¶
BackendAddr returns the TCP proxied address.
func (*TCPProxy) FrontendAddr ¶
FrontendAddr returns the TCP address on which the proxy is listening.
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 ¶
BackendAddr returns the proxied UDP address.
func (*UDPProxy) FrontendAddr ¶
FrontendAddr returns the UDP address on which the proxy is listening.
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
NewUnixProxy creates a new UnixProxy.
func (*UnixProxy) BackendAddr ¶ added in v0.3.0
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
FrontendAddr returns the Unix address on which the proxy is listening.
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