From 4bf784fd9f0c51f1d9cfd207ceb2b7d79debb88a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Fri, 7 Mar 2014 15:10:44 +0800 Subject: [PATCH] fix a bypass issue --- .../github/shadowsocks/ShadowsocksNatService.scala | 4 ++-- .../github/shadowsocks/ShadowsocksVpnService.scala | 4 ++-- .../com/github/shadowsocks/utils/ConfigUtils.scala | 2 +- .../scala/com/github/shadowsocks/utils/Utils.scala | 11 ++++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala index d1b3ec39..71846264 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala @@ -118,7 +118,7 @@ class ShadowsocksNatService extends Service with BaseService { Path.BASE + "ss-local.pid") .format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod) } else { - val conf = ConfigUtils.PDNSD.format("127.0.0.1", getString(R.string.exclude), System.getDNS1); + val conf = ConfigUtils.PDNSD.format("127.0.0.1", getString(R.string.exclude), Utils.getDNS); ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { p.println(conf) }) @@ -310,8 +310,8 @@ class ShadowsocksNatService extends Service with BaseService { // Bypass DNS servers init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1")) + init_sb.append(cmd_bypass.replace("0.0.0.0", Utils.getDNS)) init_sb.append(cmd_bypass.replace("0.0.0.0", "114.114.114.114")) - init_sb.append(cmd_bypass.replace("0.0.0.0", "114.114.115.115")) if (hasRedirectSupport) { init_sb diff --git a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index 210ad839..edd5c1ed 100644 --- a/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -91,7 +91,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { Path.BASE + "ss-tunnel.pid") .format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod) } else { - val conf = ConfigUtils.PDNSD.format("0.0.0.0", getString(R.string.exclude), System.getDNS1) + val conf = ConfigUtils.PDNSD.format("0.0.0.0", getString(R.string.exclude), Utils.getDNS) ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { p.println(conf) }) @@ -115,7 +115,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { def isByass(util: SubnetUtils): Boolean = { val info = util.getInfo - info.isInRange(config.proxy) || info.isInRange("114.114.114.114") || info.isInRange("114.114.115.115") + info.isInRange(config.proxy) || info.isInRange("114.114.114.114") || info.isInRange(Utils.getDNS) } def startVpn() { diff --git a/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala b/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala index ae7dc5aa..e89a43c8 100644 --- a/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala +++ b/src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala @@ -86,7 +86,7 @@ object ConfigUtils { | |server { | label = "china-servers"; - | ip = %s, 114.114.114.114, 114.114.115.115; + | ip = %s, 114.114.114.114; | timeout = 5; |} | diff --git a/src/main/scala/com/github/shadowsocks/utils/Utils.scala b/src/main/scala/com/github/shadowsocks/utils/Utils.scala index ab37428d..985fabc2 100644 --- a/src/main/scala/com/github/shadowsocks/utils/Utils.scala +++ b/src/main/scala/com/github/shadowsocks/utils/Utils.scala @@ -53,7 +53,7 @@ import android.os.Build import android.provider.Settings import scala.Some import java.security.MessageDigest -import com.github.shadowsocks.{BuildConfig} +import com.github.shadowsocks.{BuildConfig, System} object Utils { @@ -80,6 +80,15 @@ object Utils { var data_path: String = null var rootTries = 0 + def getDNS(): String = { + val dns1 = System.getDNS1 + if (dns1 != null && !dns1.isEmpty && InetAddressUtils.isIPv4Address(dns1)) { + dns1 + } else { + "114.114.114.114" + } + } + def getSignature(context: Context): String = { val info = context .getPackageManager