Skip to content

Commit a197f8f

Browse files
committed
patch more unsupported config
1 parent 8f1c235 commit a197f8f

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

core/src/main/golang/native/config/load.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ func Load(path string) error {
7676
return err
7777
}
7878

79-
// Start the external controller like in hub.Parse(), but we have set its
80-
// default override value to end with ":0" for security.
79+
// like hub.Parse()
8180
hub.ApplyConfig(cfg)
8281

8382
app.ApplySubtitlePattern(rawCfg.ClashForAndroid.UiSubtitlePattern)

core/src/main/golang/native/config/process.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010

1111
"cfa/native/common"
1212

13+
"github.com/metacubex/mihomo/config"
1314
C "github.com/metacubex/mihomo/constant"
1415
"github.com/metacubex/mihomo/log"
15-
16-
"github.com/metacubex/mihomo/config"
1716
)
1817

1918
var processors = []processor{
@@ -23,6 +22,7 @@ var processors = []processor{
2322
patchProfile,
2423
patchDns,
2524
patchTun,
25+
patchListeners,
2626
patchProviders,
2727
validConfig,
2828
}
@@ -88,7 +88,23 @@ func patchDns(cfg *config.RawConfig, _ string) error {
8888

8989
func patchTun(cfg *config.RawConfig, _ string) error {
9090
cfg.Tun.Enable = false
91+
cfg.Tun.AutoRoute = false
92+
cfg.Tun.AutoDetectInterface = false
93+
return nil
94+
}
9195

96+
func patchListeners(cfg *config.RawConfig, _ string) error {
97+
newListeners := make([]map[string]any, 0, len(cfg.Listeners))
98+
for _, mapping := range cfg.Listeners {
99+
if proxyType, existType := mapping["type"].(string); existType {
100+
switch proxyType {
101+
case "tproxy", "redir", "tun":
102+
continue // remove those listeners which is not supported
103+
}
104+
}
105+
newListeners = append(newListeners, mapping)
106+
}
107+
cfg.Listeners = newListeners
92108
return nil
93109
}
94110

core/src/main/golang/native/proxy/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Start(listen string) (listenAt string, err error) {
1818

1919
listener, err = http.NewWithAuthenticate(listen, tunnel.Tunnel, false)
2020
if err == nil {
21-
listenAt = listener.Listener().Addr().String()
21+
listenAt = listener.Address()
2222
}
2323

2424
return

core/src/main/golang/native/tun/tun.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ func Start(fd int, stack, gateway, portal, dns string) (io.Closer, error) {
5252
}
5353

5454
options := LC.Tun{
55-
Enable: true,
56-
Device: sing_tun.InterfaceName,
57-
Stack: tunStack,
58-
DNSHijack: dnsHijack,
59-
Inet4Address: prefix4,
60-
Inet6Address: prefix6,
61-
MTU: 9000, // private const val TUN_MTU = 9000 in TunService.kt
62-
FileDescriptor: fd,
55+
Enable: true,
56+
Device: sing_tun.InterfaceName,
57+
Stack: tunStack,
58+
DNSHijack: dnsHijack,
59+
AutoRoute: false, // had set route in TunService.kt
60+
AutoDetectInterface: false, // implements by VpnService::protect
61+
Inet4Address: prefix4,
62+
Inet6Address: prefix6,
63+
MTU: 9000, // private const val TUN_MTU = 9000 in TunService.kt
64+
FileDescriptor: fd,
6365
}
6466

6567
tunOptions, _ := json.Marshal(options)

0 commit comments

Comments
 (0)