bypass dns queries for popular sites in china

This commit is contained in:
Max Lv
2014-03-07 13:07:44 +08:00
parent 5052b74893
commit 1beb175957
4 changed files with 32 additions and 11 deletions
File diff suppressed because one or more lines are too long
@@ -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")
val conf = ConfigUtils.PDNSD.format("127.0.0.1", getString(R.string.exclude));
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf)
})
@@ -302,10 +302,17 @@ class ShadowsocksNatService extends Service with BaseService {
val http_sb = new ArrayBuffer[String]
init_sb.append(Utils.getIptables + " -t nat -F OUTPUT")
val cmd_bypass = Utils.getIptables + CMD_IPTABLES_RETURN
// Bypass proxy servers
if (!InetAddressUtils.isIPv6Address(config.proxy.toUpperCase)) {
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-d " + config.proxy))
init_sb.append(cmd_bypass.replace("0.0.0.0", config.proxy))
}
// 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", "114.114.114.114"))
init_sb.append(cmd_bypass.replace("0.0.0.0", "114.114.115.115"))
if (hasRedirectSupport) {
init_sb
.append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to "
@@ -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")
val conf = ConfigUtils.PDNSD.format("0.0.0.0", getString(R.string.exclude))
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf)
})
@@ -113,9 +113,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
version
}
def startVpn() {
def isByass(info: SubnetUtils.SubnetInfo): Boolean = {
info.isInRange(config.proxy) || info.isInRange("114.114.114.114")
|| info.isInRange("114.114.115.115")
}
val proxy_address = config.proxy
def startVpn() {
val builder = new Builder()
builder
@@ -136,7 +139,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
gfwList.foreach(cidr => {
val net = new SubnetUtils(cidr).getInfo
if (!net.isInRange(proxy_address)) {
if (!isByass(net)) {
val addr = cidr.split('/')
builder.addRoute(addr(0), addr(1).toInt)
}
@@ -148,7 +151,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val cidr = addr + "/8"
val net = new SubnetUtils(cidr).getInfo
if (!net.isInRange(proxy_address)) {
if (!isByass(net)) {
if (!InetAddress.getByName(addr).isSiteLocalAddress) {
builder.addRoute(addr, 8)
}
@@ -157,7 +160,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val subAddr = i.toString + "." + j.toString + ".0.0"
val subCidr = subAddr + "/16"
val subNet = new SubnetUtils(subCidr).getInfo
if (!subNet.isInRange(proxy_address)) {
if (!isByass(subNet)) {
if (!InetAddress.getByName(subAddr).isSiteLocalAddress) {
builder.addRoute(subAddr, 16)
}
@@ -78,8 +78,15 @@ object ConfigUtils {
|}
|
|server {
| label = "root-servers";
| ip = 8.8.8.8, 8.8.4.4, 208.67.222.222, 208.67.220.220;
| label = "google-servers";
| ip = 8.8.8.8, 8.8.4.4;
| exclude = %s;
| timeout = 5;
|}
|
|server {
| label = "china-servers";
| ip = 114.114.114.114, 114.114.115.115;
| timeout = 5;
|}
|
@@ -156,4 +163,4 @@ object ConfigUtils {
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, isUdpDns, profileName, proxy,
sitekey, encMethod, proxiedAppString, remotePort, localPort)
}
}
}