Documentation
¶
Index ¶
- Constants
- Variables
- func CalcCRC32cChecksum(raw []byte) []byte
- func ChecksumCRC32c(h *Header) bool
- type AddressFamily
- type Command
- type Conn
- func (c *Conn) Err() error
- func (c *Conn) GetVpceID() string
- func (c *Conn) GetVpceIDWithType(typ PP2Type, subType PP2Type) string
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) LogrusFields() logrus.Fields
- func (c *Conn) RawHeader() []byte
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) TLVs() TLVs
- func (c *Conn) ZapFields() []zap.Field
- type Header
- type Listener
- type Option
- type PP2Type
- type PostReadHeader
- type TLV
- type TLVs
- type TransportProtocol
- type Version
Constants ¶
const ( Version1 Version = 0x1 // Version 1 Version2 Version = 0x2 // Version 2 CMD_LOCAL Command = 0x0 // Local CMD_PROXY Command = 0x1 // Proxy AF_UNSPEC AddressFamily = 0x0 // Unspec AF_INET AddressFamily = 0x1 // IPv4 AF_INET6 AddressFamily = 0x2 // IPv6 AF_UNIX AddressFamily = 0x3 // Unix SOCK_UNSPEC TransportProtocol = 0x0 // Unspec SOCK_STREAM TransportProtocol = 0x1 // TCP SOCK_DGRAM TransportProtocol = 0x2 // UDP Unknown string = "Unknown" // Unknown value )
Variables ¶
var ( ErrUnknownVersion = errors.New("formater unknown version") ErrUnknownAddrFamily = errors.New("formater unknown address family") ErrUnknownTranProtocol = errors.New("formater unknown transport protocol") ErrInvalidAddress = errors.New("formater invalid source or destination address") ErrExceedPayloadLength = errors.New("payload's length exceeds uint16 (65535) when TLV will be wrote") )
var ( ErrTlvLenTooShort = errors.New("TLV's length is too short") ErrTlvValTooShort = errors.New("TLV's values are too short") )
var ( ErrMustEndWithCRLF = errors.New("pp1 header must end with '\\r\\n'") ErrHeaderTooLong = errors.New("pp1 header too long") ErrNotFoundAddressFamily = errors.New("pp1 header not found address family") ErrInvalidAddressFamily = errors.New("pp1 invalid address family") ErrNotFoundAddressOrPort = errors.New("pp1 header not found address or port") )
var ( ErrUnknownVersionAndCommand = errors.New("pp2 unknown version and command") ErrUnknownAddrFamilyAndTranProtocol = errors.New("pp2 unknown address family and transport protocol") ErrPayloadLengthTooShort = errors.New("pp2 payload length is too short") ErrPayloadBytesTooShort = errors.New("pp2 payload of bytes are too short") )
var (
ErrNoProxyProtocol = errors.New("proxy protocol prefix not present")
)
var ErrValidateCRC32cChecksum = errors.New("pp2 failed to validate CRC-32c checksum")
Functions ¶
func CalcCRC32cChecksum ¶ added in v1.0.1
CalcCRC32cChecksum calculate a CRC32c checksum value of the whole PROXY header.
func ChecksumCRC32c ¶
ChecksumCRC32c CRC-32c checksum with header. just do it when the header is valid and contains a CRC-32c checksum.
Types ¶
type AddressFamily ¶
type AddressFamily byte // IPv4, IPv6 or Unix
func (AddressFamily) String ¶
func (af AddressFamily) String() string
type Conn ¶
Conn wrap net.Conn, want to read and parse Proxy Protocol header, and so on.
func (*Conn) GetVpceID ¶ added in v1.0.2
GetVpceID find VPC endpoint ID in the PROXY header's TLVs. an unregistered PP2Type will be choosen, and the first byte discarded.
func (*Conn) GetVpceIDWithType ¶ added in v1.0.2
GetVpceIDWithType gets VPC endpoint ID with PP2Type from PROXY header. the subtype of 0 returns all values, otherwise the first byte is discarded.
func (*Conn) LogrusFields ¶
LogrusFields header fields for logrus
func (*Conn) RemoteAddr ¶
RemoteAddr implement net.Conn, in order to read Proxy Protocol header
func (*Conn) SetDeadline ¶
SetDeadline implement net.Conn, in order to catch deadline
func (*Conn) SetReadDeadline ¶
SetReadDeadline implement net.Conn, in order to catch deadline
type Header ¶
type Header struct { Version Version Command Command AddressFamily AddressFamily TransportProtocol TransportProtocol SrcAddr net.Addr // source address DstAddr net.Addr // destination address Raw []byte // raw proxy protocol header TLVs TLVs // all of TLV groups }
func (*Header) FormatWithChecksum ¶ added in v1.0.1
FormatWithChecksum formater header to bytes, and append checksum with CRC-32c.
func (*Header) LogrusFields ¶
type Option ¶
type Option func(*Conn)
func WithCRC32cChecksum ¶
WithCRC32cChecksum validate CRC-32c checksum. pp2 (proxy protocol version 2) will validate it.
func WithDisableProxyProto ¶
WithDisableProxyProto header is not read
func WithPostReadHeader ¶
func WithPostReadHeader(fn PostReadHeader) Option
WithPostReadHeader want to do after reading header, such as logging
func WithReadHeaderTimeout ¶
WithReadHeaderTimeout read header with timeout
type PP2Type ¶
type PP2Type byte
PP2Type type of proxy protocol version 2
const ( PP2_TYPE_ALPN PP2Type = 0x01 PP2_TYPE_AUTHORITY PP2Type = 0x02 PP2_TYPE_CRC32C PP2Type = 0x03 PP2_TYPE_NOOP PP2Type = 0x04 PP2_TYPE_UNIQUE_ID PP2Type = 0x05 PP2_TYPE_SSL PP2Type = 0x20 PP2_SUBTYPE_SSL_VERSION PP2Type = 0x21 PP2_SUBTYPE_SSL_CN PP2Type = 0x22 PP2_SUBTYPE_SSL_CIPHER PP2Type = 0x23 PP2_SUBTYPE_SSL_SIG_ALG PP2Type = 0x24 PP2_SUBTYPE_SSL_KEY_ALG PP2Type = 0x25 PP2_TYPE_NETNS PP2Type = 0x30 )
The following types have already been registered for the <type> field:
type PostReadHeader ¶
PostReadHeader will be called after reading Proxy Protocol header.
type TLV ¶
TLV a Type-Length-Value group
func NewNoOpTLV ¶ added in v1.0.1
NewNoOpTLV create a PP2_TYPE_NOOP TLV group.
func (TLV) IsRegistered ¶
IsRegistered true if type have already been registered
type TransportProtocol ¶
type TransportProtocol byte // TCP or UDP
func (TransportProtocol) String ¶
func (tp TransportProtocol) String() string