Refine #1217
This commit is contained in:
@@ -315,13 +315,6 @@ trait BaseService extends Service {
|
||||
file
|
||||
}
|
||||
|
||||
private final def buildRemoteDns(remoteDns: String): String = {
|
||||
val addr = InetAddress.getByName(remoteDns)
|
||||
if (addr.isInstanceOf[Inet6Address])
|
||||
return "[" + remoteDns + "]"
|
||||
remoteDns
|
||||
}
|
||||
|
||||
protected final def buildOvertureConfig(file: String): String = {
|
||||
val config = new JSONObject()
|
||||
.put("BindAddress", ":" + (profile.localPort + 53))
|
||||
@@ -333,7 +326,10 @@ trait BaseService extends Service {
|
||||
def makeDns(name: String, address: String, edns: Boolean = true) = {
|
||||
val dns = new JSONObject()
|
||||
.put("Name", name)
|
||||
.put("Address", address + ":53")
|
||||
.put("Address", (Utils.parseNumericAddress(address) match {
|
||||
case _: Inet6Address => '[' + address + ']'
|
||||
case _ => address
|
||||
}) + ":53")
|
||||
.put("Timeout", 6)
|
||||
.put("EDNSClientSubnet", new JSONObject().put("Policy", "disable"))
|
||||
if (edns) dns
|
||||
@@ -342,29 +338,23 @@ trait BaseService extends Service {
|
||||
else dns.put("Protocol", "udp")
|
||||
dns
|
||||
}
|
||||
val remoteDns = new JSONArray(profile.remoteDns.split(",").zipWithIndex.map {
|
||||
case (dns, i) => makeDns("UserDef-" + i, dns.trim)
|
||||
})
|
||||
profile.route match {
|
||||
case Acl.BYPASS_CHN | Acl.BYPASS_LAN_CHN | Acl.GFWLIST | Acl.CUSTOM_RULES => config
|
||||
.put("PrimaryDNS", new JSONArray(Array(
|
||||
makeDns("Primary-1", "119.29.29.29", edns = false),
|
||||
makeDns("Primary-2", "114.114.114.114", edns = false)
|
||||
)))
|
||||
.put("AlternativeDNS", new JSONArray(
|
||||
for (remoteDns <- profile.remoteDns.split(","))
|
||||
yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim)
|
||||
)))
|
||||
.put("AlternativeDNS", remoteDns)
|
||||
.put("IPNetworkFile", "china_ip_list.txt")
|
||||
.put("DomainFile", "gfwlist.txt")
|
||||
case Acl.CHINALIST => config
|
||||
.put("PrimaryDNS", new JSONArray().put(makeDns("Primary", "119.29.29.29")))
|
||||
.put("AlternativeDNS", new JSONArray(
|
||||
for (remoteDns <- profile.remoteDns.split(","))
|
||||
yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim)
|
||||
)))
|
||||
.put("AlternativeDNS", remoteDns)
|
||||
case _ => config
|
||||
.put("PrimaryDNS", new JSONArray(
|
||||
for (remoteDns <- profile.remoteDns.split(","))
|
||||
yield makeDns(remoteDns.trim, buildRemoteDns(remoteDns.trim)
|
||||
)))
|
||||
.put("PrimaryDNS", new JSONArray(remoteDns))
|
||||
// no need to setup AlternativeDNS in Acl.ALL/BYPASS_LAN mode
|
||||
.put("OnlyPrimaryDNS", true)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class ShadowsocksNatService extends BaseService {
|
||||
"-t", "10",
|
||||
"-b", "127.0.0.1",
|
||||
"-l", (profile.localPort + 63).toString,
|
||||
"-L", profile.remoteDns.split(",")(0).trim + ":53",
|
||||
"-L", profile.remoteDns.split(",").head.trim + ":53",
|
||||
"-c", buildShadowsocksConfig("ss-tunnel-nat.conf"))
|
||||
|
||||
if (profile.udpdns) cmd.append("-u")
|
||||
|
||||
@@ -22,8 +22,6 @@ package com.github.shadowsocks
|
||||
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import java.net.InetAddress
|
||||
import java.net.Inet6Address
|
||||
|
||||
import android.content._
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
@@ -223,13 +221,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
val subnet = Subnet.fromString(cidr)
|
||||
builder.addRoute(subnet.address.getHostAddress, subnet.prefixSize)
|
||||
})
|
||||
profile.remoteDns.split(",").foreach(remoteDns => {
|
||||
val addr = InetAddress.getByName(remoteDns.trim)
|
||||
if (addr.isInstanceOf[Inet6Address])
|
||||
builder.addRoute(addr, 128)
|
||||
else if (addr.isInstanceOf[InetAddress])
|
||||
builder.addRoute(addr, 32)
|
||||
})
|
||||
profile.remoteDns.split(",").map(dns => Utils.parseNumericAddress(dns.trim)).foreach(dns =>
|
||||
builder.addRoute(dns, dns.getAddress.length << 3))
|
||||
}
|
||||
|
||||
conn = builder.establish()
|
||||
|
||||
Reference in New Issue
Block a user