avoid self loop route in android in tun

This commit is contained in:
Hiddify
2024-08-06 14:36:17 -04:00
parent ebfea88cff
commit cfb37888d4
3 changed files with 30 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ import (
"net"
"net/netip"
"net/url"
"runtime"
"strings"
"time"
@@ -472,6 +473,30 @@ func setRoutingOptions(options *option.Options, opt *ConfigOptions) {
routeRules := []option.Rule{}
rulesets := []option.RuleSet{}
if opt.EnableTun && runtime.GOOS == "android" {
routeRules = append(
routeRules,
option.Rule{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
Inbound: []string{InboundTUNTag},
PackageName: []string{"app.hiddify.com"},
Outbound: OutboundBypassTag,
},
},
)
// routeRules = append(
// routeRules,
// option.Rule{
// Type: C.RuleTypeDefault,
// DefaultOptions: option.DefaultRule{
// ProcessName: []string{"Hiddify", "Hiddify.exe", "HiddifyCli", "HiddifyCli.exe"},
// Outbound: OutboundBypassTag,
// },
// },
// )
}
routeRules = append(routeRules, option.Rule{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
@@ -487,28 +512,7 @@ func setRoutingOptions(options *option.Options, opt *ConfigOptions) {
Outbound: OutboundDNSTag,
},
})
if opt.EnableTun {
routeRules = append(
routeRules,
option.Rule{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
ProcessName: []string{"Hiddify", "Hiddify.exe", "HiddifyCli", "HiddifyCli.exe"},
Outbound: OutboundBypassTag,
},
},
)
routeRules = append(
routeRules,
option.Rule{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
PackageName: []string{"app.hiddify.com"},
Outbound: OutboundBypassTag,
},
},
)
}
// {
// Type: C.RuleTypeDefault,
// DefaultOptions: option.DefaultRule{

2
go.mod
View File

@@ -20,6 +20,8 @@ require (
gopkg.in/yaml.v3 v3.0.1
)
require github.com/akavel/rsrc v0.10.2 // indirect
require (
berty.tech/go-libtor v1.0.385 // indirect
github.com/ajg/form v1.5.1 // indirect

2
go.sum
View File

@@ -14,6 +14,8 @@ github.com/OmarTariq612/goech v0.0.0-20240405204721-8e2e1dafd3a0 h1:Wo41lDOevRJS
github.com/OmarTariq612/goech v0.0.0-20240405204721-8e2e1dafd3a0/go.mod h1:FVGavL/QEBQDcBpr3fAojoK17xX5k9bicBphrOpP7uM=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=