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) }