diff --git a/core/src/main/golang/native/config/load.go b/core/src/main/golang/native/config/load.go index 47027652..c6b3a4f3 100644 --- a/core/src/main/golang/native/config/load.go +++ b/core/src/main/golang/native/config/load.go @@ -76,8 +76,7 @@ func Load(path string) error { return err } - // Start the external controller like in hub.Parse(), but we have set its - // default override value to end with ":0" for security. + // like hub.Parse() hub.ApplyConfig(cfg) app.ApplySubtitlePattern(rawCfg.ClashForAndroid.UiSubtitlePattern) diff --git a/core/src/main/golang/native/config/process.go b/core/src/main/golang/native/config/process.go index 7ed60b8e..09a4f8d1 100644 --- a/core/src/main/golang/native/config/process.go +++ b/core/src/main/golang/native/config/process.go @@ -10,10 +10,9 @@ import ( "cfa/native/common" + "github.com/metacubex/mihomo/config" C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/log" - - "github.com/metacubex/mihomo/config" ) var processors = []processor{ @@ -23,6 +22,7 @@ var processors = []processor{ patchProfile, patchDns, patchTun, + patchListeners, patchProviders, validConfig, } @@ -88,7 +88,23 @@ func patchDns(cfg *config.RawConfig, _ string) error { func patchTun(cfg *config.RawConfig, _ string) error { cfg.Tun.Enable = false + cfg.Tun.AutoRoute = false + cfg.Tun.AutoDetectInterface = false + return nil +} +func patchListeners(cfg *config.RawConfig, _ string) error { + newListeners := make([]map[string]any, 0, len(cfg.Listeners)) + for _, mapping := range cfg.Listeners { + if proxyType, existType := mapping["type"].(string); existType { + switch proxyType { + case "tproxy", "redir", "tun": + continue // remove those listeners which is not supported + } + } + newListeners = append(newListeners, mapping) + } + cfg.Listeners = newListeners return nil } diff --git a/core/src/main/golang/native/proxy/http.go b/core/src/main/golang/native/proxy/http.go index 58ce57d7..9c5d64b6 100644 --- a/core/src/main/golang/native/proxy/http.go +++ b/core/src/main/golang/native/proxy/http.go @@ -18,7 +18,7 @@ func Start(listen string) (listenAt string, err error) { listener, err = http.NewWithAuthenticate(listen, tunnel.Tunnel, false) if err == nil { - listenAt = listener.Listener().Addr().String() + listenAt = listener.Address() } return diff --git a/core/src/main/golang/native/tun/tun.go b/core/src/main/golang/native/tun/tun.go index d686589f..ee2c2a91 100644 --- a/core/src/main/golang/native/tun/tun.go +++ b/core/src/main/golang/native/tun/tun.go @@ -52,14 +52,16 @@ func Start(fd int, stack, gateway, portal, dns string) (io.Closer, error) { } options := LC.Tun{ - Enable: true, - Device: sing_tun.InterfaceName, - Stack: tunStack, - DNSHijack: dnsHijack, - Inet4Address: prefix4, - Inet6Address: prefix6, - MTU: 9000, // private const val TUN_MTU = 9000 in TunService.kt - FileDescriptor: fd, + Enable: true, + Device: sing_tun.InterfaceName, + Stack: tunStack, + DNSHijack: dnsHijack, + AutoRoute: false, // had set route in TunService.kt + AutoDetectInterface: false, // implements by VpnService::protect + Inet4Address: prefix4, + Inet6Address: prefix6, + MTU: 9000, // private const val TUN_MTU = 9000 in TunService.kt + FileDescriptor: fd, } tunOptions, _ := json.Marshal(options)