multiplexer

package
v4.2.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package multiplexer implements SSH and TLS multiplexing on the same listener

mux, _ := multiplexer.New(Config{Listener: listener}) mux.SSH() // returns listener getting SSH connections mux.TLS() // returns listener getting TLS connections

Index

Constants

View Source
const (
	// ProtoUnknown is for unknown protocol
	ProtoUnknown = iota
	// ProtoTLS is TLS protocol
	ProtoTLS
	// ProtoSSH is SSH protocol
	ProtoSSH
	// ProtoProxy is a HAProxy proxy line protocol
	ProtoProxy
	// ProtoHTTP is HTTP protocol
	ProtoHTTP
)
View Source
const (
	// TCP4 is TCP over IPv4
	TCP4 = "TCP4"
	// TCP6 is tCP over IPv6
	TCP6 = "TCP6"
	// Unknown is unsupported or unknown protocol
	UNKNOWN = "UNKNOWN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Listener is listener to multiplex connection on
	Listener net.Listener
	// Context is a context to signal stops, cancellations
	Context context.Context
	// ReadDeadline is a connection read deadline,
	// set to defaults.ReadHeadersTimeout if unspecified
	ReadDeadline time.Duration
	// Clock is a clock to override in tests, set to real time clock
	// by default
	Clock clockwork.Clock
	// EnableProxyProtocol enables proxy protocol
	EnableProxyProtocol bool
	// DisableSSH disables SSH socket
	DisableSSH bool
	// DisableTLS disables TLS socket
	DisableTLS bool
	// ID is an identifier used for debugging purposes
	ID string
}

Config is a multiplexer config

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

CheckAndSetDefaults verifies configuration and sets defaults

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is a connection wrapper that supports communicating remote address from proxy protocol and replays first several bytes read during protocol detection

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns local address of the connection

func (*Conn) Read

func (c *Conn) Read(p []byte) (int, error)

Read reads from connection

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns remote address of the connection

type Listener

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

Listener is a listener that receives connections from multiplexer based on the connection type

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept accepts connections from parent multiplexer listener

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns listener addr, the address of multiplexer listener

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener, connections to multiplexer will hang

type Mux

type Mux struct {
	sync.RWMutex
	*log.Entry
	Config
	// contains filtered or unexported fields
}

Mux supports having both SSH and TLS on the same listener socket

func New

func New(cfg Config) (*Mux, error)

New returns a new instance of multiplexer

func (*Mux) Close

func (m *Mux) Close() error

Close closes listener

func (*Mux) SSH

func (m *Mux) SSH() net.Listener

SSH returns listener that receives SSH connections

func (*Mux) Serve

func (m *Mux) Serve() error

Serve is a blocking function that serves on the listening socket and accepts requests. Every request is served in a separate goroutine

func (*Mux) TLS

func (m *Mux) TLS() net.Listener

TLS returns listener that receives TLS connections

func (*Mux) Wait

func (m *Mux) Wait()

Wait waits until listener shuts down and stops accepting new connections this is to workaround issue https://github.com/golang/go/issues/10527 in tests

type ProxyLine

type ProxyLine struct {
	Protocol    string
	Source      net.TCPAddr
	Destination net.TCPAddr
}

ProxyLine is HA Proxy protocol version 1 https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt Original implementation here: https://github.com/racker/go-proxy-protocol

func ReadProxyLine

func ReadProxyLine(reader *bufio.Reader) (*ProxyLine, error)

ReadProxyLine reads proxy line protocol from the reader

func (*ProxyLine) String

func (p *ProxyLine) String() string

String returns on-the wire string representation of the proxy line

Jump to

Keyboard shortcuts

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