Skip to content

Commit

Permalink
avoid self loop route in android in tun
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Aug 6, 2024
1 parent ebfea88 commit cfb3788
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
48 changes: 26 additions & 22 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"net/netip"
"net/url"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit cfb3788

Please sign in to comment.