diff --git a/component/process/find_process_mode.go b/component/process/find_process_mode.go deleted file mode 100644 index 06618cef..00000000 --- a/component/process/find_process_mode.go +++ /dev/null @@ -1,57 +0,0 @@ -package process - -import ( - "encoding/json" - "errors" - "strings" -) - -const ( - FindProcessAlways = "always" - FindProcessStrict = "strict" - FindProcessOff = "off" -) - -var ( - validModes = map[string]struct{}{ - FindProcessAlways: {}, - FindProcessOff: {}, - FindProcessStrict: {}, - } -) - -type FindProcessMode string - -func (m FindProcessMode) Always() bool { - return m == FindProcessAlways -} - -func (m FindProcessMode) Off() bool { - return m == FindProcessOff -} - -func (m *FindProcessMode) UnmarshalYAML(unmarshal func(any) error) error { - var tp string - if err := unmarshal(&tp); err != nil { - return err - } - return m.Set(tp) -} - -func (m *FindProcessMode) UnmarshalJSON(data []byte) error { - var tp string - if err := json.Unmarshal(data, &tp); err != nil { - return err - } - return m.Set(tp) -} - -func (m *FindProcessMode) Set(value string) error { - mode := strings.ToLower(value) - _, exist := validModes[mode] - if !exist { - return errors.New("invalid find process mode") - } - *m = FindProcessMode(mode) - return nil -} diff --git a/config/config.go b/config/config.go index e2250e8a..da05877f 100644 --- a/config/config.go +++ b/config/config.go @@ -4,7 +4,6 @@ import ( "container/list" "errors" "fmt" - P "github.com/Dreamacro/clash/component/process" "net" "net/netip" "net/url" @@ -43,19 +42,18 @@ import ( type General struct { Inbound Controller - Mode T.TunnelMode `json:"mode"` - UnifiedDelay bool - LogLevel log.LogLevel `json:"log-level"` - IPv6 bool `json:"ipv6"` - Interface string `json:"interface-name"` - RoutingMark int `json:"-"` - GeodataMode bool `json:"geodata-mode"` - GeodataLoader string `json:"geodata-loader"` - TCPConcurrent bool `json:"tcp-concurrent"` - EnableProcess bool `json:"enable-process"` - FindProcessMode P.FindProcessMode `json:"find-process-mode"` - Sniffing bool `json:"sniffing"` - EBpf EBpf `json:"-"` + Mode T.TunnelMode `json:"mode"` + UnifiedDelay bool + LogLevel log.LogLevel `json:"log-level"` + IPv6 bool `json:"ipv6"` + Interface string `json:"interface-name"` + RoutingMark int `json:"-"` + GeodataMode bool `json:"geodata-mode"` + GeodataLoader string `json:"geodata-loader"` + TCPConcurrent bool `json:"tcp-concurrent"` + EnableProcess bool `json:"enable-process"` + Sniffing bool `json:"sniffing"` + EBpf EBpf `json:"-"` } // Inbound config @@ -228,33 +226,32 @@ type RawTuicServer struct { } type RawConfig struct { - Port int `yaml:"port"` - SocksPort int `yaml:"socks-port"` - RedirPort int `yaml:"redir-port"` - TProxyPort int `yaml:"tproxy-port"` - MixedPort int `yaml:"mixed-port"` - ShadowSocksConfig string `yaml:"ss-config"` - VmessConfig string `yaml:"vmess-config"` - InboundTfo bool `yaml:"inbound-tfo"` - Authentication []string `yaml:"authentication"` - AllowLan bool `yaml:"allow-lan"` - BindAddress string `yaml:"bind-address"` - Mode T.TunnelMode `yaml:"mode"` - UnifiedDelay bool `yaml:"unified-delay"` - LogLevel log.LogLevel `yaml:"log-level"` - IPv6 bool `yaml:"ipv6"` - ExternalController string `yaml:"external-controller"` - ExternalControllerTLS string `yaml:"external-controller-tls"` - ExternalUI string `yaml:"external-ui"` - Secret string `yaml:"secret"` - Interface string `yaml:"interface-name"` - RoutingMark int `yaml:"routing-mark"` - Tunnels []LC.Tunnel `yaml:"tunnels"` - GeodataMode bool `yaml:"geodata-mode"` - GeodataLoader string `yaml:"geodata-loader"` - TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"` - EnableProcess bool `yaml:"enable-process" json:"enable-process"` - FindProcessMode P.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"` + Port int `yaml:"port"` + SocksPort int `yaml:"socks-port"` + RedirPort int `yaml:"redir-port"` + TProxyPort int `yaml:"tproxy-port"` + MixedPort int `yaml:"mixed-port"` + ShadowSocksConfig string `yaml:"ss-config"` + VmessConfig string `yaml:"vmess-config"` + InboundTfo bool `yaml:"inbound-tfo"` + Authentication []string `yaml:"authentication"` + AllowLan bool `yaml:"allow-lan"` + BindAddress string `yaml:"bind-address"` + Mode T.TunnelMode `yaml:"mode"` + UnifiedDelay bool `yaml:"unified-delay"` + LogLevel log.LogLevel `yaml:"log-level"` + IPv6 bool `yaml:"ipv6"` + ExternalController string `yaml:"external-controller"` + ExternalControllerTLS string `yaml:"external-controller-tls"` + ExternalUI string `yaml:"external-ui"` + Secret string `yaml:"secret"` + Interface string `yaml:"interface-name"` + RoutingMark int `yaml:"routing-mark"` + Tunnels []LC.Tunnel `yaml:"tunnels"` + GeodataMode bool `yaml:"geodata-mode"` + GeodataLoader string `yaml:"geodata-loader"` + TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"` + EnableProcess bool `yaml:"enable-process" json:"enable-process"` Sniffer RawSniffer `yaml:"sniffer"` ProxyProvider map[string]map[string]any `yaml:"proxy-providers"` @@ -317,22 +314,21 @@ func Parse(buf []byte) (*Config, error) { func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { // config with default value rawCfg := &RawConfig{ - AllowLan: false, - BindAddress: "*", - IPv6: true, - Mode: T.Rule, - GeodataMode: C.GeodataMode, - GeodataLoader: "memconservative", - UnifiedDelay: false, - Authentication: []string{}, - LogLevel: log.INFO, - Hosts: map[string]string{}, - Rule: []string{}, - Proxy: []map[string]any{}, - ProxyGroup: []map[string]any{}, - TCPConcurrent: false, - EnableProcess: false, - FindProcessMode: P.FindProcessStrict, + AllowLan: false, + BindAddress: "*", + IPv6: true, + Mode: T.Rule, + GeodataMode: C.GeodataMode, + GeodataLoader: "memconservative", + UnifiedDelay: false, + Authentication: []string{}, + LogLevel: log.INFO, + Hosts: map[string]string{}, + Rule: []string{}, + Proxy: []map[string]any{}, + ProxyGroup: []map[string]any{}, + TCPConcurrent: false, + EnableProcess: false, Tun: RawTun{ Enable: false, Device: "", @@ -540,18 +536,17 @@ func parseGeneral(cfg *RawConfig) (*General, error) { Secret: cfg.Secret, ExternalControllerTLS: cfg.ExternalControllerTLS, }, - UnifiedDelay: cfg.UnifiedDelay, - Mode: cfg.Mode, - LogLevel: cfg.LogLevel, - IPv6: cfg.IPv6, - Interface: cfg.Interface, - RoutingMark: cfg.RoutingMark, - GeodataMode: cfg.GeodataMode, - GeodataLoader: cfg.GeodataLoader, - TCPConcurrent: cfg.TCPConcurrent, - EnableProcess: cfg.EnableProcess, - FindProcessMode: cfg.FindProcessMode, - EBpf: cfg.EBpf, + UnifiedDelay: cfg.UnifiedDelay, + Mode: cfg.Mode, + LogLevel: cfg.LogLevel, + IPv6: cfg.IPv6, + Interface: cfg.Interface, + RoutingMark: cfg.RoutingMark, + GeodataMode: cfg.GeodataMode, + GeodataLoader: cfg.GeodataLoader, + TCPConcurrent: cfg.TCPConcurrent, + EnableProcess: cfg.EnableProcess, + EBpf: cfg.EBpf, }, nil } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 55786864..eb4436fb 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -309,7 +309,7 @@ func updateTunnels(tunnels []LC.Tunnel) { func updateGeneral(general *config.General, force bool) { tunnel.SetMode(general.Mode) - tunnel.SetFindProcessMode(general.EnableProcess, general.FindProcessMode) + 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 c5534062..8f0ef8f6 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -43,7 +43,7 @@ var ( // default timeout for UDP session udpTimeout = 60 * time.Second - findProcessMode P.FindProcessMode + alwaysFindProcess = false fakeIPRange netip.Prefix ) @@ -146,14 +146,9 @@ func SetMode(m TunnelMode) { mode = m } -// SetFindProcessMode replace SetAlwaysFindProcess -// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory -func SetFindProcessMode(legacyAlways bool, mode P.FindProcessMode) { - if legacyAlways { - findProcessMode = P.FindProcessAlways - } else { - findProcessMode = mode - } +// 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 @@ -468,7 +463,7 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) { }() } - if !findProcessMode.Off() && !processFound && (findProcessMode.Always() || rule.ShouldFindProcess()) { + if !processFound && (alwaysFindProcess || rule.ShouldFindProcess()) { srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16) uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort)) if err != nil {