Documentation ¶
Overview ¶
Package proxyprotocol implements network reader shims for terminating proxy protocol connections.
Index ¶
- Variables
- func CreateListener(addr string, opts ...CreateListenerOption) (net.Listener, error)
- type Conn
- func (p *Conn) Close() error
- func (p *Conn) LocalAddr() net.Addr
- func (p *Conn) Read(b []byte) (int, error)
- func (p *Conn) RemoteAddr() net.Addr
- func (p *Conn) SetDeadline(t time.Time) error
- func (p *Conn) SetReadDeadline(t time.Time) error
- func (p *Conn) SetWriteDeadline(t time.Time) error
- func (p *Conn) Write(b []byte) (int, error)
- type CreateListenerOption
- type CreateListenerOptions
- type Listener
- type SourceChecker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidUpstream is a common error. ErrInvalidUpstream ex.Class = "upstream connection address not trusted for PROXY information" )
Functions ¶
func CreateListener ¶ added in v1.20201204.1
func CreateListener(addr string, opts ...CreateListenerOption) (net.Listener, error)
CreateListener creates a new proxy protocol listener.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is used to wrap and underlying connection which may be speaking the Proxy Protocol. If it is, the RemoteAddr() will return the address of the client instead of the proxy address.
func NewConn ¶
NewConn is used to wrap a net.Conn that may be speaking the proxy protocol into a proxyproto.Conn
func (*Conn) Read ¶
Read is check for the proxy protocol header when doing the initial scan. If there is an error parsing the header, it is returned and the socket is closed.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the address of the client if the proxy protocol is being used, otherwise just returns the address of the socket peer. If there is an error parsing the header, the address of the client is not returned, and the socket is closed. Once implication of this is that the call could block if the client is slow. Using a Deadline is recommended if this is called before Read()
func (*Conn) SetReadDeadline ¶
SetReadDeadline reads a field.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets a field.
type CreateListenerOption ¶ added in v1.20201204.1
type CreateListenerOption func(*CreateListenerOptions) error
CreateListenerOption is a mutator for the options used when creating a listener.
func OptKeepAlive ¶ added in v1.20201204.1
func OptKeepAlive(keepAlive bool) CreateListenerOption
OptKeepAlive sets if we should keep TCP connections alive or not.
func OptKeepAlivePeriod ¶ added in v1.20201204.1
func OptKeepAlivePeriod(keepAlivePeriod time.Duration) CreateListenerOption
OptKeepAlivePeriod sets the duration we should keep connections alive for.
func OptTLSConfig ¶ added in v1.20201204.1
func OptTLSConfig(tlsConfig *tls.Config) CreateListenerOption
OptTLSConfig sets the listener tls config.
func OptUseProxyProtocol ¶ added in v1.20201204.1
func OptUseProxyProtocol(useProxyProtocol bool) CreateListenerOption
OptUseProxyProtocol sets if we should decode proxy protocol or not.
type CreateListenerOptions ¶ added in v1.20201204.1
type CreateListenerOptions struct { TLSConfig *tls.Config UseProxyProtocol bool KeepAlive bool KeepAlivePeriod time.Duration }
CreateListenerOptions are the options for creating listeners.
type Listener ¶
type Listener struct { Listener net.Listener ProxyHeaderTimeout time.Duration SourceCheck SourceChecker }
Listener is used to wrap an underlying listener, whose connections may be using the HAProxy Proxy Protocol (version 1). If the connection is using the protocol, the RemoteAddr() will return the correct client address.
Optionally define ProxyHeaderTimeout to set a maximum time to receive the Proxy Protocol Header. Zero means no timeout.
type SourceChecker ¶
SourceChecker can be used to decide whether to trust the PROXY info or pass the original connection address through. If set, the connecting address is passed in as an argument. If the function returns an error due to the source being disallowed, it should return ErrInvalidUpstream.
Behavior is as follows: * If error is not nil, the call to Accept() will fail. If the reason for triggering this failure is due to a disallowed source, it should return ErrInvalidUpstream. * If bool is true, the PROXY-set address is used. * If bool is false, the connection's remote address is used, rather than the address claimed in the PROXY info.