From 827be3cea3dc7ca0073befb0da4fda8d28aea68d Mon Sep 17 00:00:00 2001 From: sbruens Date: Mon, 5 Aug 2024 12:27:16 -0400 Subject: [PATCH] Check if the command is UNKNOWN (v1) or LOCAL (v2). --- service/listeners.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/service/listeners.go b/service/listeners.go index e1bc763f..4037771e 100644 --- a/service/listeners.go +++ b/service/listeners.go @@ -24,7 +24,7 @@ import ( "sync/atomic" "github.com/Jigsaw-Code/outline-sdk/transport" - proxyproto "github.com/pires/go-proxyproto" + "github.com/pires/go-proxyproto" ) // The implementations of listeners for different network types are not @@ -138,15 +138,18 @@ func (l *ProxyStreamListener) AcceptStream() (ClientStreamConn, error) { return nil, err } r := bufio.NewReader(conn) - h, err := proxyproto.Read(r) + header, err := proxyproto.Read(r) if errors.Is(err, proxyproto.ErrNoProxyProtocol) { logger.Warningf("Received connection from %v without proxy header.", conn.RemoteAddr()) return conn, nil } - if err != nil { + if header == nil || err != nil { return nil, fmt.Errorf("error parsing proxy header: %v", err) } - return &clientStreamConn{StreamConn: conn, clientAddr: h.SourceAddr}, nil + if header.Command.IsLocal() { + return conn, nil + } + return &clientStreamConn{StreamConn: conn, clientAddr: header.SourceAddr}, nil } type virtualPacketConn struct {