package libproxy
import "github.com/moby/vpnkit/go/pkg/libproxy"
Package libproxy provides a network Proxy interface and implementations for TCP and UDP.
Index ¶
- Constants
- Variables
- 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 NewLoopback() *loopback
- 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
- func (d Destination) Size() int
- func (d Destination) String() string
- func (d Destination) Write(w io.Writer) error
- type Frame
- func NewClose(ID uint32) *Frame
- func NewData(ID, payloadlen uint32) *Frame
- func NewOpen(ID uint32, d Destination) *Frame
- func NewShutdown(ID uint32) *Frame
- func NewWindow(ID uint32, seq uint64) *Frame
- func (f *Frame) Data() (*DataFrame, error)
- func (f *Frame) Open() (*OpenFrame, error)
- func (f *Frame) Payload() interface{}
- func (f *Frame) Size() int
- func (f *Frame) String() string
- func (f *Frame) Window() (*WindowFrame, error)
- func (f *Frame) Write(w io.Writer) error
- type MultiplexedConn
- type Multiplexer
- type OpenFrame
- type Proto
- type Proxy
- func NewBestEffortIPProxy(host net.Addr, container net.Addr) (Proxy, error)
- func NewIPProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)
- func NewStubProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)
- type ShutdownFrame
- type StubProxy
- func (p *StubProxy) BackendAddr() net.Addr
- func (p *StubProxy) Close()
- func (p *StubProxy) FrontendAddr() net.Addr
- func (p *StubProxy) Run()
- type TCPProxy
- func NewTCPProxy(listener net.Listener, backendAddr *net.TCPAddr) (*TCPProxy, error)
- func (proxy *TCPProxy) BackendAddr() net.Addr
- func (proxy *TCPProxy) Close()
- func (proxy *TCPProxy) FrontendAddr() net.Addr
- func (proxy *TCPProxy) Run()
- type UDPDialer
- type UDPListener
- type UDPProxy
- func NewUDPProxy(frontendAddr net.Addr, listener UDPListener, backendAddr *net.UDPAddr, dialer UDPDialer) (*UDPProxy, error)
- func (proxy *UDPProxy) BackendAddr() net.Addr
- func (proxy *UDPProxy) Close()
- func (proxy *UDPProxy) FrontendAddr() net.Addr
- func (proxy *UDPProxy) Run()
- type UnixProxy
- func NewUnixProxy(listener net.Listener, backendAddr *net.UnixAddr) (*UnixProxy, error)
- func (proxy *UnixProxy) BackendAddr() net.Addr
- func (proxy *UnixProxy) Close()
- func (proxy *UnixProxy) FrontendAddr() net.Addr
- func (proxy *UnixProxy) Run()
- 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 ¶
Functions ¶
func ExposePort ¶
ExposePort exposes a port using 9p
func Forward ¶
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 ¶
HandleUnixConnection forwards the Unix traffic to a specified backend address
func NewLoopback ¶
func NewLoopback() *loopback
NewLoopback creates a bidirectional buffered connection, intended for testing.
func ProxyStream ¶
ProxyStream data between client and backend, until both are at EOF or quit is closed.
func SetLogger ¶
SetLogger sets a new default logger
Types ¶
type CloseFrame ¶
type CloseFrame struct { }
CloseFrame requests to disconnect from a proxy backend
type Command ¶
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 ¶
Conn defines a network connection
type Connection ¶
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 ¶
func (c Connection) String() string
type DataFrame ¶
type DataFrame struct {
// contains filtered or unexported fields
}
DataFrame is the header of a frame containing user data
func (*DataFrame) Size ¶
Size returns the marshalled size of the data payload header
func (*DataFrame) Write ¶
type Destination ¶
Destination refers to a listening TCP or UDP service
func (Destination) Size ¶
func (d Destination) Size() int
Size returns the marshalled size in bytes
func (Destination) String ¶
func (d Destination) String() string
func (Destination) Write ¶
func (d Destination) Write(w io.Writer) error
type Frame ¶
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 ¶
NewClose creates a close frame
func NewData ¶
NewData creates a data header frame
func NewOpen ¶
func NewOpen(ID uint32, d Destination) *Frame
NewOpen creates an open message
func NewShutdown ¶
NewShutdown creates a shutdown frame
func NewWindow ¶
NewWindow creates a Window message
func (*Frame) Data ¶
Data returns the payload of the frame, if it has Command = Data
func (*Frame) Open ¶
Open returns the payload of the frame, if it has Command = Open
func (*Frame) Payload ¶
func (f *Frame) Payload() interface{}
Payload returns the payload of the frame.
func (*Frame) Size ¶
Size returns the marshalled size of the frame
func (*Frame) String ¶
func (*Frame) Window ¶
func (f *Frame) Window() (*WindowFrame, error)
Window returns the payload of the frame, if it has Command = Window.
func (*Frame) Write ¶
type MultiplexedConn ¶
type MultiplexedConn interface { Conn SetReadBuffer(uint) error // SetReadBuffer sets the maximum read buffer size SetWriteBuffer(uint) error // SetWriteBuffer sets the maximum write buffer size }
MultiplexedConn is a sub-connection within a single multiplexed connection.
type Multiplexer ¶
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) (MultiplexedConn, error) // Dial a remote Destination Accept() (MultiplexedConn, *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 ¶
func NewMultiplexer(label string, conn io.ReadWriteCloser, allocateBackwards bool) (Multiplexer, error)
NewMultiplexer constructs a multiplexer from a channel
type OpenFrame ¶
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 ¶
Size returns the marshalled size of the Open message
func (*OpenFrame) Write ¶
type Proto ¶
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 ¶
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.
func NewStubProxy ¶
NewStubProxy creates a new StubProxy
type ShutdownFrame ¶
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) Close ¶
func (p *StubProxy) Close()
Close does nothing.
func (*StubProxy) FrontendAddr ¶
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 ¶
NewTCPProxy creates a new TCPProxy.
func (*TCPProxy) BackendAddr ¶
BackendAddr returns the TCP proxied address.
func (*TCPProxy) Close ¶
func (proxy *TCPProxy) Close()
Close stops forwarding the traffic.
func (*TCPProxy) FrontendAddr ¶
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 ¶
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 ¶
BackendAddr returns the proxied UDP address.
func (*UDPProxy) Close ¶
func (proxy *UDPProxy) Close()
Close stops forwarding the traffic.
func (*UDPProxy) FrontendAddr ¶
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 ¶
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 ¶
NewUnixProxy creates a new UnixProxy.
func (*UnixProxy) BackendAddr ¶
BackendAddr returns the Unix proxied address.
func (*UnixProxy) Close ¶
func (proxy *UnixProxy) Close()
Close stops forwarding the traffic.
func (*UnixProxy) FrontendAddr ¶
FrontendAddr returns the Unix address on which the proxy is listening.
func (*UnixProxy) Run ¶
func (proxy *UnixProxy) Run()
Run starts forwarding the traffic using Unix.
type WindowFrame ¶
type WindowFrame struct {
// contains filtered or unexported fields
}
WindowFrame is a window advertisement message
func (*WindowFrame) Size ¶
func (win *WindowFrame) Size() int
Size returned the marshalled size of the Window payload
func (*WindowFrame) Write ¶
func (win *WindowFrame) Write(w io.Writer) error
Source Files ¶
expose_port.go forward.go frame.go handshake.go log.go loopbackconn.go multiplexed.go proxy.go stream_proxy.go stub_proxy.go tcp_proxy.go udp_encapsulation.go udp_proxy.go unix_proxy.go
- Version
- v0.6.0 (latest)
- Published
- Apr 8, 2025
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 12 hours ago –
Tools for package owners.