feat: add param general.enable-process, it will always find process or uid, default value is false

This commit is contained in:
Skyxim 2022-06-14 23:08:07 +08:00
parent be298cfa16
commit 2e6bdc5636
3 changed files with 11 additions and 5 deletions

View file

@ -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: "",

View file

@ -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")

View file

@ -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))