From a55acea38feacf7069b6f333345ca11c7b020ef5 Mon Sep 17 00:00:00 2001 From: dingjun Date: Thu, 17 Sep 2020 14:25:58 +0800 Subject: [PATCH] add debug log and ignore ip sni --- main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.go b/main.go index 3cb4f14..563e63e 100644 --- a/main.go +++ b/main.go @@ -157,11 +157,23 @@ func serve(ctx context.Context, c net.Conn) { forward(ctx, c, buf[:n], getDefaultDST()) return } + + // sni is ip address, ignore it, prevent dead loop + ip := net.ParseIP(servername) + if ip != nil { + glog.Debugf("sni %s, send to default", ip.String()) + forward(ctx, c, buf[:n], getDefaultDST()) + return + } + dst := getDST(c, servername) if dst == "" { dst = getDefaultDST() glog.Debugf("use default dst %s for sni %s", dst, servername) } + + glog.Debugf("from %s, sni %s, forward to %s", c.RemoteAddr(), servername, dst) + forward(ctx, c, buf[:n], dst) }