proxyproto listener handle conn without header

This commit is contained in:
zak 2022-09-07 01:29:25 +08:00 committed by 世界
parent 3d511f003f
commit c40cc02c33
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -22,7 +22,7 @@ func (l *Listener) Accept() (net.Conn, error) {
} }
bufReader := std_bufio.NewReader(conn) bufReader := std_bufio.NewReader(conn)
header, err := proxyproto.Read(bufReader) header, err := proxyproto.Read(bufReader)
if err != nil { if err != nil && err != proxyproto.ErrNoProxyProtocol {
return nil, err return nil, err
} }
if bufReader.Buffered() > 0 { if bufReader.Buffered() > 0 {
@ -33,8 +33,11 @@ func (l *Listener) Accept() (net.Conn, error) {
} }
conn = bufio.NewCachedConn(conn, cache) conn = bufio.NewCachedConn(conn, cache)
} }
return &bufio.AddrConn{Conn: conn, Metadata: M.Metadata{ if header != nil {
Source: M.SocksaddrFromNet(header.SourceAddr), return &bufio.AddrConn{Conn: conn, Metadata: M.Metadata{
Destination: M.SocksaddrFromNet(header.DestinationAddr), Source: M.SocksaddrFromNet(header.SourceAddr),
}}, nil Destination: M.SocksaddrFromNet(header.DestinationAddr),
}}, nil
}
return conn, nil
} }