From e7581f0a9e8c51a5553de6acfb06bc52a2516ed3 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Wed, 4 Sep 2024 22:44:05 +0800 Subject: [PATCH] add sniffing.fallback option for red handler --- go.sum | 6 ------ handler/redirect/tcp/handler.go | 4 ++++ handler/redirect/tcp/metadata.go | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.sum b/go.sum index 0bd8cc51..90f1d7a2 100644 --- a/go.sum +++ b/go.sum @@ -53,18 +53,12 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= -github.com/go-gost/core v0.1.1 h1:8joR9KJYBvpurNu3i0zqN9orQthVzOjhtT4STumwNF0= -github.com/go-gost/core v0.1.1/go.mod h1:WGI43jOka7FAsSAwi/fSMaqxdR+E339ycb4NBGlFr6A= github.com/go-gost/core v0.1.2 h1:uWGLXEcfqkLYwvpGutXN2eIGXLOUGQX7L1QTe3NUDeA= github.com/go-gost/core v0.1.2/go.mod h1:WGI43jOka7FAsSAwi/fSMaqxdR+E339ycb4NBGlFr6A= github.com/go-gost/gosocks4 v0.0.1 h1:+k1sec8HlELuQV7rWftIkmy8UijzUt2I6t+iMPlGB2s= github.com/go-gost/gosocks4 v0.0.1/go.mod h1:3B6L47HbU/qugDg4JnoFPHgJXE43Inz8Bah1QaN9qCc= github.com/go-gost/gosocks5 v0.4.2 h1:IianxHTkACPqCwiOAT3MHoMdSUl+SEPSRu1ikawC1Pc= github.com/go-gost/gosocks5 v0.4.2/go.mod h1:1G6I7HP7VFVxveGkoK8mnprnJqSqJjdcASKsdUn4Pp4= -github.com/go-gost/plugin v0.0.0-20240103125338-9c84e29cb81a h1:ME7P1Brcg4C640DSPqlvQr7JuvvQfJ8QpmS3yCFlK3A= -github.com/go-gost/plugin v0.0.0-20240103125338-9c84e29cb81a/go.mod h1:qXr2Zm9Ex2ATqnWuNUzVZqySPMnuIihvblYZt4MlZLw= -github.com/go-gost/plugin v0.1.0 h1:3C4pm+jyEy8EpGN2DzVUM4eS75T/GVxCq2fU4RuiFJs= -github.com/go-gost/plugin v0.1.0/go.mod h1:oN23l+yGDCIP9G3KnDl/I/0zVGOobZUDCB2Z5yYYXts= github.com/go-gost/plugin v0.1.1 h1:LNoc/Rqwb3ceGhhxwhpjf1SeeYBGe80MJ9E4lpM3qak= github.com/go-gost/plugin v0.1.1/go.mod h1:oN23l+yGDCIP9G3KnDl/I/0zVGOobZUDCB2Z5yYYXts= github.com/go-gost/relay v0.5.0 h1:JG1tgy/KWiVXS0ukuVXvbM0kbYuJTWxYpJ5JwzsCf/c= diff --git a/handler/redirect/tcp/handler.go b/handler/redirect/tcp/handler.go index bd17b643..e8e548b5 100644 --- a/handler/redirect/tcp/handler.go +++ b/handler/redirect/tcp/handler.go @@ -241,6 +241,10 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad cc, err = h.options.Router.Dial(ctx, "tcp", host) if err != nil { log.Error(err) + + if !h.md.sniffingFallback { + return err + } } } diff --git a/handler/redirect/tcp/metadata.go b/handler/redirect/tcp/metadata.go index 8206eb1b..cc9d995b 100644 --- a/handler/redirect/tcp/metadata.go +++ b/handler/redirect/tcp/metadata.go @@ -11,11 +11,13 @@ type metadata struct { tproxy bool sniffing bool sniffingTimeout time.Duration + sniffingFallback bool } func (h *redirectHandler) parseMetadata(md mdata.Metadata) (err error) { h.md.tproxy = mdutil.GetBool(md, "tproxy") h.md.sniffing = mdutil.GetBool(md, "sniffing") h.md.sniffingTimeout = mdutil.GetDuration(md, "sniffing.timeout") + h.md.sniffingFallback = mdutil.GetBool(md, "sniffing.fallback") return }