Revert "fix #322: add option general.find-process-mode, user can turn off findProcess feature in router"
This commit is contained in:
parent
de6d32a9d5
commit
95564f1ae6
@ -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
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
P "github.com/Dreamacro/clash/component/process"
|
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -53,7 +52,6 @@ type General struct {
|
|||||||
GeodataLoader string `json:"geodata-loader"`
|
GeodataLoader string `json:"geodata-loader"`
|
||||||
TCPConcurrent bool `json:"tcp-concurrent"`
|
TCPConcurrent bool `json:"tcp-concurrent"`
|
||||||
EnableProcess bool `json:"enable-process"`
|
EnableProcess bool `json:"enable-process"`
|
||||||
FindProcessMode P.FindProcessMode `json:"find-process-mode"`
|
|
||||||
Sniffing bool `json:"sniffing"`
|
Sniffing bool `json:"sniffing"`
|
||||||
EBpf EBpf `json:"-"`
|
EBpf EBpf `json:"-"`
|
||||||
}
|
}
|
||||||
@ -254,7 +252,6 @@ type RawConfig struct {
|
|||||||
GeodataLoader string `yaml:"geodata-loader"`
|
GeodataLoader string `yaml:"geodata-loader"`
|
||||||
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
||||||
EnableProcess bool `yaml:"enable-process" json:"enable-process"`
|
EnableProcess bool `yaml:"enable-process" json:"enable-process"`
|
||||||
FindProcessMode P.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"`
|
|
||||||
|
|
||||||
Sniffer RawSniffer `yaml:"sniffer"`
|
Sniffer RawSniffer `yaml:"sniffer"`
|
||||||
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`
|
ProxyProvider map[string]map[string]any `yaml:"proxy-providers"`
|
||||||
@ -332,7 +329,6 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
|||||||
ProxyGroup: []map[string]any{},
|
ProxyGroup: []map[string]any{},
|
||||||
TCPConcurrent: false,
|
TCPConcurrent: false,
|
||||||
EnableProcess: false,
|
EnableProcess: false,
|
||||||
FindProcessMode: P.FindProcessStrict,
|
|
||||||
Tun: RawTun{
|
Tun: RawTun{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Device: "",
|
Device: "",
|
||||||
@ -550,7 +546,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||||||
GeodataLoader: cfg.GeodataLoader,
|
GeodataLoader: cfg.GeodataLoader,
|
||||||
TCPConcurrent: cfg.TCPConcurrent,
|
TCPConcurrent: cfg.TCPConcurrent,
|
||||||
EnableProcess: cfg.EnableProcess,
|
EnableProcess: cfg.EnableProcess,
|
||||||
FindProcessMode: cfg.FindProcessMode,
|
|
||||||
EBpf: cfg.EBpf,
|
EBpf: cfg.EBpf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,7 @@ func updateTunnels(tunnels []LC.Tunnel) {
|
|||||||
|
|
||||||
func updateGeneral(general *config.General, force bool) {
|
func updateGeneral(general *config.General, force bool) {
|
||||||
tunnel.SetMode(general.Mode)
|
tunnel.SetMode(general.Mode)
|
||||||
tunnel.SetFindProcessMode(general.EnableProcess, general.FindProcessMode)
|
tunnel.SetAlwaysFindProcess(general.EnableProcess)
|
||||||
dialer.DisableIPv6 = !general.IPv6
|
dialer.DisableIPv6 = !general.IPv6
|
||||||
if !dialer.DisableIPv6 {
|
if !dialer.DisableIPv6 {
|
||||||
log.Infoln("Use IPv6")
|
log.Infoln("Use IPv6")
|
||||||
|
@ -43,7 +43,7 @@ var (
|
|||||||
// default timeout for UDP session
|
// default timeout for UDP session
|
||||||
udpTimeout = 60 * time.Second
|
udpTimeout = 60 * time.Second
|
||||||
|
|
||||||
findProcessMode P.FindProcessMode
|
alwaysFindProcess = false
|
||||||
|
|
||||||
fakeIPRange netip.Prefix
|
fakeIPRange netip.Prefix
|
||||||
)
|
)
|
||||||
@ -146,14 +146,9 @@ func SetMode(m TunnelMode) {
|
|||||||
mode = m
|
mode = m
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFindProcessMode replace SetAlwaysFindProcess
|
// SetAlwaysFindProcess set always find process info, may be increase many memory
|
||||||
// always find process info if legacyAlways = true or mode.Always() = true, may be increase many memory
|
func SetAlwaysFindProcess(findProcess bool) {
|
||||||
func SetFindProcessMode(legacyAlways bool, mode P.FindProcessMode) {
|
alwaysFindProcess = findProcess
|
||||||
if legacyAlways {
|
|
||||||
findProcessMode = P.FindProcessAlways
|
|
||||||
} else {
|
|
||||||
findProcessMode = mode
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// processUDP starts a loop to handle udp packet
|
// 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)
|
srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16)
|
||||||
uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort))
|
uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user