From f8a9c272f3e6de10a6a5763ae48664d64ad4f21f Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 22 Apr 2022 13:30:04 +0800 Subject: [PATCH] feat: dnsHijack support "any" chore: adjust process debug display logic --- config/config.go | 2 +- go.sum | 6 ++++-- tunnel/tunnel.go | 16 +++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 4bd00c91..168d37a0 100644 --- a/config/config.go +++ b/config/config.go @@ -896,7 +896,7 @@ func parseTun(rawTun RawTun, general *General) (*Tun, error) { if _, after, ok := strings.Cut(d, "://"); ok { d = after } - + d = strings.Replace(d, "any", "0.0.0.0", 1) addrPort, err := netip.ParseAddrPort(d) if err != nil { return nil, fmt.Errorf("parse dns-hijack url error: %w", err) diff --git a/go.sum b/go.sum index e159f21a..8ac11ca2 100644 --- a/go.sum +++ b/go.sum @@ -224,6 +224,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd h1:zVFyTKZN/Q7mNRWSs1GOYnHM9NiFSJ54YVRsD0rNWT4= +golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -255,8 +257,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2 h1:6mzvA99KwZxbOrxww4EvWVQUnN1+xEu9tafK5ZxkYeA= -golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 0cfc823a..e720dff9 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -37,9 +37,9 @@ var ( mode = Rule // default timeout for UDP session - udpTimeout = 60 * time.Second - - snifferDispatcher *sniffer.SnifferDispatcher + udpTimeout = 60 * time.Second + procesCache string + failTotal int ) func init() { @@ -171,11 +171,17 @@ func preHandleMetadata(metadata *C.Metadata) error { if err == nil && P.ShouldFindProcess(metadata) { path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, srcPort) if err != nil { - log.Debugln("[Process] find process %s: %v", metadata.String(), err) + if failTotal < 20 { + log.Debugln("[Process] find process %s: %v", metadata.String(), err) + failTotal++ + } } else { - log.Debugln("[Process] %s from process %s", metadata.String(), path) metadata.Process = filepath.Base(path) metadata.ProcessPath = path + if procesCache == metadata.Process { + log.Debugln("[Process] %s from process %s", metadata.String(), path) + } + procesCache = metadata.Process } } return nil