From 102387077f1a7382b49e7362ae60cd6c9ca9e6b3 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 5 Nov 2014 15:52:57 +0800 Subject: [PATCH] refine DNS resolver on Lollipop --- jni/shadowsocks | 2 +- .../shadowsocks/ShadowsocksVpnService.scala | 18 +++++++++++------- .../github/shadowsocks/utils/ConfigUtils.scala | 7 ++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/jni/shadowsocks b/jni/shadowsocks index 271d55942c..1008cf1f5b 160000 --- a/jni/shadowsocks +++ b/jni/shadowsocks @@ -1 +1 @@ -Subproject commit 271d55942c943c3813638a19a7194ca062ba6fe3 +Subproject commit 1008cf1f5bb0004c64a86b103c157ec98c177cd6 diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index b1e277e44e..f3c738c7c5 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -75,7 +75,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication] - def isACLEnabled: Boolean = { + def isLollipopOrAbove: Boolean = { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { true } else { @@ -90,7 +90,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { def startShadowsocksDaemon() { - if (isACLEnabled && config.isGFWList) { + if (isLollipopOrAbove && config.isGFWList) { val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list_full) ConfigUtils.printToFile(new File(Path.BASE + "chn.acl"))(p => { chn_list.foreach(item => p.println(item)) @@ -107,7 +107,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { , "-m" , config.encMethod , "-f" , Path.BASE + "ss-local.pid") - if (config.isGFWList && isACLEnabled) { + if (config.isGFWList && isLollipopOrAbove) { cmd += "--acl" cmd += (Path.BASE + "chn.acl") } @@ -133,7 +133,11 @@ class ShadowsocksVpnService extends VpnService with BaseService { def startDnsDaemon() { val conf = { - ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163) + if (isLollipopOrAbove) { + ConfigUtils.PDNSD_BYPASS.format("0.0.0.0", getString(R.string.exclude), 8163) + } else { + ConfigUtils.PDNSD_LOCAL.format("0.0.0.0", 8163) + } } ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { p.println(conf) @@ -164,7 +168,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { .addAddress(PRIVATE_VLAN.format("1"), 24) .addDnsServer("8.8.8.8") - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) { + if (isLollipopOrAbove) { if (!config.isGlobalProxy) { val apps = AppManager.getProxiedApps(this, config.proxiedAppString) val pkgSet: mutable.HashSet[String] = new mutable.HashSet[String] @@ -191,7 +195,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { if (InetAddressUtils.isIPv6Address(config.proxy)) { builder.addRoute("0.0.0.0", 0) - } else if (!isACLEnabled && config.isGFWList) { + } else if (!isLollipopOrAbove && config.isGFWList) { val gfwList = { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { getResources.getStringArray(R.array.simple_list) @@ -207,7 +211,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { } }) } else { - if (isACLEnabled) { + if (isLollipopOrAbove) { builder.addRoute("0.0.0.0", 0) } else { for (i <- 1 to 223) { diff --git a/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala b/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala index 6a49d0154a..9dc9f70615 100644 --- a/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala +++ b/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala @@ -142,7 +142,7 @@ object ConfigUtils { | |server { | label = "china-servers"; - | ip = 114.114.114.114, 114.114.115.115; + | ip = 114.114.114.114, 223.5.5.5; | uptest = none; | preset = on; | include = %s; @@ -151,8 +151,9 @@ object ConfigUtils { |} | |server { - | label = "google-servers"; - | ip = 8.8.8.8, 8.8.4.4; + | label = "local-server"; + | ip = 127.0.0.1; + | port = %d; | timeout = 5; |} |