rebase "comzyh/add-water" & add dns config fallback
This commit is contained in:
7 files changed
+142
-96
No files matched your search
@@ -1,3 +1,3 @@
|
||||
import java.io.File
|
||||
|
||||
data class GolangBuildOptions(val sourceDir: File, val outputDir: File, val platform: String)
|
||||
import java.io.File
|
||||
|
||||
data class GolangBuildOptions(val sourceDir: File, val outputDir: File, val platform: String)
|
||||
Submodule core/src/main/golang/clash updated: d5d22cce0c...7767f1554c.
@@ -5,7 +5,7 @@ go 1.13
|
||||
require (
|
||||
github.com/Dreamacro/clash v0.0.0 // local
|
||||
github.com/google/go-cmp v0.3.1 // indirect
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe
|
||||
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
|
||||
)
|
||||
|
||||
replace github.com/Dreamacro/clash v0.0.0 => ./clash
|
||||
@@ -30,6 +30,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
|
||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/miekg/dns v1.1.9 h1:OIdC9wT96RzuZMf2PfKRhFgsStHUUBZLM/lo1LqiM9E=
|
||||
github.com/miekg/dns v1.1.9/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
|
||||
@@ -57,12 +59,16 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1 h1:anGSYQpPhQwXlwsu5wmfq0nWkCNaMEMUwAv13Y92hd8=
|
||||
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191011234655-491137f69257 h1:ry8e2D+cwaV6hk7lb3aRTjjZo24shrbK0e11QEOkTIg=
|
||||
golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk=
|
||||
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
||||
@@ -74,6 +80,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
|
||||
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
|
||||
@@ -86,3 +94,5 @@ gopkg.in/eapache/channels.v1 v1.1.0 h1:5bGAyKKvyCTWjSj7mhefG6Lc68VyN4MH1v8/7Ooee
|
||||
gopkg.in/eapache/channels.v1 v1.1.0/go.mod h1:BHIBujSvu9yMTrTYbTCjDD43gUhtmaOtTWDe7sTv1js=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -1,82 +1,123 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
adapters "github.com/Dreamacro/clash/adapters/outbound"
|
||||
"github.com/Dreamacro/clash/component/auth"
|
||||
trie "github.com/Dreamacro/clash/component/domain-trie"
|
||||
"github.com/Dreamacro/clash/config"
|
||||
"github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/dns"
|
||||
"github.com/Dreamacro/clash/hub/executor"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"github.com/Dreamacro/clash/tunnel"
|
||||
|
||||
"github.com/kr328/cfa/tun"
|
||||
)
|
||||
|
||||
// LoadDefault - load default configure
|
||||
func LoadDefault() {
|
||||
defaultC := &config.Config{
|
||||
General: &config.General{
|
||||
Port: 0,
|
||||
SocksPort: 0,
|
||||
RedirPort: 0,
|
||||
Authentication: []string{},
|
||||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
Mode: tunnel.Direct,
|
||||
LogLevel: log.SILENT,
|
||||
ExternalController: "",
|
||||
ExternalUI: "",
|
||||
Secret: "",
|
||||
},
|
||||
DNS: &config.DNS{
|
||||
Enable: false,
|
||||
IPv6: false,
|
||||
NameServer: []dns.NameServer{},
|
||||
Fallback: []dns.NameServer{},
|
||||
FallbackFilter: config.FallbackFilter{
|
||||
GeoIP: false,
|
||||
IPCIDR: []*net.IPNet{},
|
||||
},
|
||||
Listen: "",
|
||||
EnhancedMode: dns.NORMAL,
|
||||
FakeIPRange: nil,
|
||||
},
|
||||
Experimental: &config.Experimental{
|
||||
IgnoreResolveFail: false,
|
||||
},
|
||||
Hosts: trie.New(),
|
||||
Rules: []constant.Rule{},
|
||||
Users: []auth.AuthUser{},
|
||||
Proxies: map[string]constant.Proxy{},
|
||||
}
|
||||
|
||||
reject := adapters.NewProxy(adapters.NewReject())
|
||||
direct := adapters.NewProxy(adapters.NewDirect())
|
||||
global, _ := adapters.NewSelector("GLOBAL", []constant.Proxy{direct})
|
||||
|
||||
defaultC.Proxies["DIRECT"] = direct
|
||||
defaultC.Proxies["REJECT"] = reject
|
||||
defaultC.Proxies["GLOBAL"] = adapters.NewProxy(global)
|
||||
|
||||
tun.ResetDnsRedirect()
|
||||
|
||||
executor.ApplyConfig(defaultC, true)
|
||||
}
|
||||
|
||||
// LoadFromFile - load file
|
||||
func LoadFromFile(path string) error {
|
||||
cfg, err := executor.ParseWithPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
executor.ApplyConfig(cfg, true)
|
||||
|
||||
tun.ResetDnsRedirect()
|
||||
|
||||
return nil
|
||||
}
|
||||
package profile
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
adapters "github.com/Dreamacro/clash/adapters/outbound"
|
||||
"github.com/Dreamacro/clash/component/auth"
|
||||
trie "github.com/Dreamacro/clash/component/domain-trie"
|
||||
"github.com/Dreamacro/clash/config"
|
||||
"github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/dns"
|
||||
"github.com/Dreamacro/clash/hub/executor"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"github.com/Dreamacro/clash/tunnel"
|
||||
|
||||
"github.com/kr328/cfa/tun"
|
||||
)
|
||||
|
||||
var defaultDNSResolver = dns.New(dns.Config{
|
||||
Main: []dns.NameServer{
|
||||
dns.NameServer{Net: "tcp", Addr: "1.1.1.1"},
|
||||
dns.NameServer{Net: "tcp", Addr: "8.8.8.8"},
|
||||
dns.NameServer{Net: "tcp", Addr: "208.67.222.222"},
|
||||
dns.NameServer{Net: "", Addr: "119.29.29.29"},
|
||||
dns.NameServer{Net: "", Addr: "223.5.5.5"},
|
||||
dns.NameServer{Net: "", Addr: "114.114.114.114"},
|
||||
},
|
||||
Fallback: make([]dns.NameServer, 0),
|
||||
IPv6: true,
|
||||
EnhancedMode: dns.MAPPING,
|
||||
Pool: nil,
|
||||
FallbackFilter: dns.FallbackFilter{
|
||||
GeoIP: false,
|
||||
IPCIDR: make([]*net.IPNet, 0),
|
||||
},
|
||||
})
|
||||
|
||||
// LoadDefault - load default configure
|
||||
func LoadDefault() {
|
||||
defaultC := &config.Config{
|
||||
General: &config.General{
|
||||
Port: 0,
|
||||
SocksPort: 0,
|
||||
RedirPort: 0,
|
||||
Authentication: []string{},
|
||||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
Mode: tunnel.Direct,
|
||||
LogLevel: log.SILENT,
|
||||
ExternalController: "",
|
||||
ExternalUI: "",
|
||||
Secret: "",
|
||||
},
|
||||
DNS: &config.DNS{
|
||||
Enable: false,
|
||||
IPv6: false,
|
||||
NameServer: []dns.NameServer{},
|
||||
Fallback: []dns.NameServer{},
|
||||
FallbackFilter: config.FallbackFilter{
|
||||
GeoIP: false,
|
||||
IPCIDR: []*net.IPNet{},
|
||||
},
|
||||
Listen: "",
|
||||
EnhancedMode: dns.NORMAL,
|
||||
FakeIPRange: nil,
|
||||
},
|
||||
Experimental: &config.Experimental{
|
||||
IgnoreResolveFail: false,
|
||||
},
|
||||
Hosts: trie.New(),
|
||||
Rules: []constant.Rule{},
|
||||
Users: []auth.AuthUser{},
|
||||
Proxies: map[string]constant.Proxy{},
|
||||
}
|
||||
|
||||
reject := adapters.NewProxy(adapters.NewReject())
|
||||
direct := adapters.NewProxy(adapters.NewDirect())
|
||||
global, _ := adapters.NewSelector("GLOBAL", []constant.Proxy{direct})
|
||||
|
||||
defaultC.Proxies["DIRECT"] = direct
|
||||
defaultC.Proxies["REJECT"] = reject
|
||||
defaultC.Proxies["GLOBAL"] = adapters.NewProxy(global)
|
||||
|
||||
tun.ResetDnsRedirect()
|
||||
|
||||
executor.ApplyConfig(defaultC, true)
|
||||
}
|
||||
|
||||
// LoadFromFile - load file
|
||||
func LoadFromFile(path string) error {
|
||||
cfg, err := executor.ParseWithPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
executor.ApplyConfig(cfg, true)
|
||||
|
||||
if dns.DefaultResolver == nil && cfg.DNS.Enable {
|
||||
c := cfg.DNS
|
||||
|
||||
r := dns.New(dns.Config{
|
||||
Main: c.NameServer,
|
||||
Fallback: c.Fallback,
|
||||
IPv6: c.IPv6,
|
||||
EnhancedMode: c.EnhancedMode,
|
||||
Pool: c.FakeIPRange,
|
||||
FallbackFilter: dns.FallbackFilter{
|
||||
GeoIP: c.FallbackFilter.GeoIP,
|
||||
IPCIDR: c.FallbackFilter.IPCIDR,
|
||||
},
|
||||
})
|
||||
|
||||
dns.DefaultResolver = r
|
||||
}
|
||||
|
||||
if dns.DefaultResolver == nil {
|
||||
dns.DefaultResolver = defaultDNSResolver
|
||||
}
|
||||
|
||||
tun.ResetDnsRedirect()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -12,7 +12,7 @@ type handler struct {
|
||||
tunAdapter *T.TunAdapter
|
||||
}
|
||||
|
||||
const dnsRedirectAddr = "0.0.0.0"
|
||||
const dnsServerAddress = "172.19.0.2:53"
|
||||
|
||||
var (
|
||||
instance *handler
|
||||
@@ -51,10 +51,5 @@ func ResetDnsRedirect() {
|
||||
return
|
||||
}
|
||||
|
||||
resolver := dns.DefaultResolver
|
||||
if resolver != nil {
|
||||
(*instance.tunAdapter).CreateDNSServer(resolver, dnsRedirectAddr+":53")
|
||||
} else {
|
||||
(*instance.tunAdapter).DestroyDNSSerrvice()
|
||||
}
|
||||
(*instance.tunAdapter).ReCreateDNSServer(dns.DefaultResolver, dnsServerAddress)
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class TunService : VpnService(), IClashEventObserver {
|
||||
companion object {
|
||||
// from https://github.com/shadowsocks/shadowsocks-android/blob/master/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
|
||||
private const val VPN_MTU = 1500
|
||||
private const val PRIVATE_DEFAULT_DNS = "119.29.29.29" // sync with tun/tun.go/dnsRedirectAddr
|
||||
private const val PRIVATE_VLAN_DNS = "172.19.0.2" // sync with tun/tun.go/dnsServerAddress
|
||||
private const val PRIVATE_VLAN4_CLIENT = "172.19.0.1"
|
||||
private const val PRIVATE_VLAN6_CLIENT = "fdfe:dcba:9876::1"
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class TunService : VpnService(), IClashEventObserver {
|
||||
|
||||
fileDescriptor = Builder()
|
||||
.addAddress()
|
||||
.addDnsServer(PRIVATE_DEFAULT_DNS)
|
||||
.addDnsServer(PRIVATE_VLAN_DNS)
|
||||
.addBypassApplications()
|
||||
.addBypassPrivateRoute()
|
||||
.setMtu(VPN_MTU)
|
||||
|
||||
Reference in new issue
Block a user