From 2e6bdc56361d6bf432d404a4162748a2e9010078 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Tue, 14 Jun 2022 23:08:07 +0800 Subject: [PATCH] feat: add param general.enable-process, it will always find process or uid, default value is false --- config/config.go | 2 +- hub/executor/executor.go | 1 + tunnel/tunnel.go | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 604e38b7..f82793d6 100644 --- a/config/config.go +++ b/config/config.go @@ -266,7 +266,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { Proxy: []map[string]any{}, ProxyGroup: []map[string]any{}, TCPConcurrent: false, - EnableProcess: true, + EnableProcess: false, Tun: RawTun{ Enable: false, Device: "", diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 9a3a7bc0..54763a3d 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -276,6 +276,7 @@ func updateSniffer(sniffer *config.Sniffer) { func updateGeneral(general *config.General, force bool) { log.SetLevel(general.LogLevel) tunnel.SetMode(general.Mode) + tunnel.SetAlwaysFindProcess(general.EnableProcess) dialer.DisableIPv6 = !general.IPv6 if !dialer.DisableIPv6 { log.Infoln("Use IPv6") diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 3cf99ead..7096811b 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -38,9 +38,9 @@ var ( mode = Rule // default timeout for UDP session - udpTimeout = 60 * time.Second - procesCache string - failTotal int + udpTimeout = 60 * time.Second + + alwaysFindProcess = false ) func SetSniffing(b bool) { @@ -122,6 +122,11 @@ func SetMode(m TunnelMode) { mode = m } +// SetAlwaysFindProcess set always find process info, may be increase many memory +func SetAlwaysFindProcess(findProcess bool) { + alwaysFindProcess = findProcess +} + // processUDP starts a loop to handle udp packet func processUDP() { queue := udpQueue @@ -381,7 +386,7 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) { resolved = true } - if !foundProcess && rule.ShouldFindProcess() { + if !foundProcess && alwaysFindProcess && rule.ShouldFindProcess() { srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16) if err == nil && P.ShouldFindProcess(metadata) { uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort))