refine pdnsd settings
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -67,7 +67,6 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
val CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN"
|
||||
val CMD_IPTABLES_DNAT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " +
|
||||
"-j DNAT --to-destination 127.0.0.1:8123"
|
||||
val DNS_PORT = 8153
|
||||
|
||||
private val mStartForegroundSignature = Array[Class[_]](classOf[Int], classOf[Notification])
|
||||
private val mStopForegroundSignature = Array[Class[_]](classOf[Boolean])
|
||||
@@ -222,11 +221,12 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
p.println(conf)
|
||||
})
|
||||
val cmd = new ArrayBuffer[String]
|
||||
cmd += (Path.BASE + "ss-tunnel" , "-u"
|
||||
, "-b" , "127.0.0.1"
|
||||
, "-L" , "8.8.8.8:53"
|
||||
, "-c" , Path.BASE + "ss-tunnel-nat.conf"
|
||||
, "-f" , Path.BASE + "ss-tunnel-nat.pid")
|
||||
cmd += (Path.BASE + "ss-tunnel"
|
||||
, "-u"
|
||||
, "-b" , "127.0.0.1"
|
||||
, "-L" , "8.8.8.8:53"
|
||||
, "-c" , Path.BASE + "ss-tunnel-nat.conf"
|
||||
, "-f" , Path.BASE + "ss-tunnel-nat.pid")
|
||||
|
||||
cmd += ("-l" , "8153")
|
||||
|
||||
@@ -243,6 +243,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
})
|
||||
val cmdBuf = new ArrayBuffer[String]
|
||||
cmdBuf += (Path.BASE + "ss-tunnel"
|
||||
, "-u"
|
||||
, "-b" , "127.0.0.1"
|
||||
, "-l" , "8163"
|
||||
, "-L" , "8.8.8.8:53"
|
||||
@@ -255,8 +256,16 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
}
|
||||
|
||||
def startDnsDaemon() {
|
||||
val conf = ConfigUtils
|
||||
.PDNSD_BYPASS.formatLocal(Locale.ENGLISH, "127.0.0.1", 8153, Path.BASE + "pdnsd-nat.pid", getString(R.string.exclude), 8163)
|
||||
|
||||
val conf = if (config.route == Route.BYPASS_CHN) {
|
||||
val reject = ConfigUtils.getRejectList(getContext, application)
|
||||
ConfigUtils.PDNSD_DIRECT.formatLocal(Locale.ENGLISH, "127.0.0.1", 8153,
|
||||
Path.BASE + "pdnsd-nat.pid", reject, reject, 8163)
|
||||
} else {
|
||||
ConfigUtils.PDNSD_LOCAL.formatLocal(Locale.ENGLISH, "127.0.0.1", 8153,
|
||||
Path.BASE + "pdnsd-nat.pid", 8163)
|
||||
}
|
||||
|
||||
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd-nat.conf"))(p => {
|
||||
p.println(conf)
|
||||
})
|
||||
@@ -407,14 +416,14 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
val cmd_bypass = Utils.getIptables + CMD_IPTABLES_RETURN
|
||||
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("-p tcp -d 0.0.0.0", "-d " + config.proxy))
|
||||
}
|
||||
init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1"))
|
||||
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " + myUid))
|
||||
init_sb.append(cmd_bypass.replace("-p tcp -d 0.0.0.0", "-d 127.0.0.1"))
|
||||
init_sb.append(cmd_bypass.replace("-p tcp -d 0.0.0.0", "-m owner --uid-owner " + myUid))
|
||||
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport 53"))
|
||||
|
||||
init_sb.append(Utils.getIptables
|
||||
+ " -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:" + DNS_PORT)
|
||||
+ " -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:" + 8153)
|
||||
|
||||
if (config.isGlobalProxy || config.isBypassApps) {
|
||||
http_sb.append(Utils.getIptables + CMD_IPTABLES_DNAT_ADD_SOCKS)
|
||||
|
||||
@@ -138,6 +138,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
})
|
||||
val cmd = new ArrayBuffer[String]
|
||||
cmd +=(Path.BASE + "ss-tunnel"
|
||||
, "-u"
|
||||
, "-b", "127.0.0.1"
|
||||
, "-l", "8163"
|
||||
, "-L", "8.8.8.8:53"
|
||||
@@ -150,10 +151,13 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
def startDnsDaemon() {
|
||||
val conf = {
|
||||
if (Utils.isLollipopOrAbove) {
|
||||
ConfigUtils.PDNSD_BYPASS.formatLocal(Locale.ENGLISH, "0.0.0.0", 8153, Path.BASE + "pdnsd-vpn.pid", getString(R.string.exclude), 8163)
|
||||
if (Utils.isLollipopOrAbove && config.route == Route.BYPASS_CHN) {
|
||||
val reject = ConfigUtils.getRejectList(getContext, application)
|
||||
ConfigUtils.PDNSD_DIRECT.formatLocal(Locale.ENGLISH, "0.0.0.0", 8153,
|
||||
Path.BASE + "pdnsd-vpn.pid", reject, reject, 8163)
|
||||
} else {
|
||||
ConfigUtils.PDNSD_LOCAL.formatLocal(Locale.ENGLISH, "0.0.0.0", 8163)
|
||||
ConfigUtils.PDNSD_LOCAL.formatLocal(Locale.ENGLISH, "0.0.0.0", 8153,
|
||||
Path.BASE + "pdnsd-vpn.pid", 8163)
|
||||
}
|
||||
}
|
||||
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd-vpn.conf"))(p => {
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import android.content.{SharedPreferences, Context}
|
||||
import com.github.shadowsocks.ShadowsocksApplication
|
||||
import com.github.shadowsocks.{R, ShadowsocksApplication}
|
||||
import com.google.android.gms.tagmanager.Container
|
||||
import com.github.kevinsawicki.http.HttpRequest
|
||||
import com.github.shadowsocks.aidl.Config
|
||||
@@ -61,36 +61,6 @@ object ConfigUtils {
|
||||
" port = %d;" +
|
||||
" type = socks5;" +
|
||||
"}"
|
||||
val PDNSD =
|
||||
"""
|
||||
|global {
|
||||
| perm_cache = 2048;
|
||||
| cache_dir = "/data/data/com.github.shadowsocks";
|
||||
| server_ip = %s;
|
||||
| server_port = 8153;
|
||||
| query_method = tcp_only;
|
||||
| run_ipv4 = on;
|
||||
| min_ttl = 15m;
|
||||
| max_ttl = 1w;
|
||||
| timeout = 10;
|
||||
| daemon = on;
|
||||
| pid_file = "/data/data/com.github.shadowsocks/pdnsd.pid";
|
||||
|}
|
||||
|
|
||||
|server {
|
||||
| label = "google-servers";
|
||||
| ip = 8.8.8.8, 8.8.4.4;
|
||||
| timeout = 5;
|
||||
|}
|
||||
|
|
||||
|rr {
|
||||
| name=localhost;
|
||||
| reverse=on;
|
||||
| a=127.0.0.1;
|
||||
| owner=localhost;
|
||||
| soa=localhost,root.localhost,42,86400,900,86400,86400;
|
||||
|}
|
||||
""".stripMargin
|
||||
|
||||
val PDNSD_LOCAL =
|
||||
"""
|
||||
@@ -98,14 +68,14 @@ object ConfigUtils {
|
||||
| perm_cache = 2048;
|
||||
| cache_dir = "/data/data/com.github.shadowsocks";
|
||||
| server_ip = %s;
|
||||
| server_port = 8153;
|
||||
| server_port = %d;
|
||||
| query_method = tcp_only;
|
||||
| run_ipv4 = on;
|
||||
| min_ttl = 15m;
|
||||
| max_ttl = 1w;
|
||||
| timeout = 10;
|
||||
| daemon = on;
|
||||
| pid_file = "/data/data/com.github.shadowsocks/pdnsd.pid";
|
||||
| pid_file = %s;
|
||||
|}
|
||||
|
|
||||
|server {
|
||||
@@ -166,6 +136,63 @@ object ConfigUtils {
|
||||
|}
|
||||
""".stripMargin
|
||||
|
||||
val PDNSD_DIRECT =
|
||||
"""
|
||||
|global {
|
||||
| perm_cache = 2048;
|
||||
| cache_dir = "/data/data/com.github.shadowsocks";
|
||||
| server_ip = %s;
|
||||
| server_port = %d;
|
||||
| query_method = udp_tcp;
|
||||
| run_ipv4 = on;
|
||||
| min_ttl = 15m;
|
||||
| max_ttl = 1w;
|
||||
| timeout = 10;
|
||||
| daemon = on;
|
||||
| pid_file = "%s";
|
||||
|}
|
||||
|
|
||||
|server {
|
||||
| label = "china-servers";
|
||||
| ip = 223.5.5.5, 114.114.114.114;
|
||||
| timeout = 2;
|
||||
| reject = %s;
|
||||
| reject_policy = fail;
|
||||
| reject_recursively = on;
|
||||
| uptest = query;
|
||||
| query_test_name = ".";
|
||||
| interval = ontimeout;
|
||||
|}
|
||||
|
|
||||
|server {
|
||||
| label= "secure";
|
||||
| port = 443;
|
||||
| ip = 208.67.220.220,113.20.8.17,77.66.84.233,176.56.237.171;
|
||||
| timeout = 3;
|
||||
| reject = %s;
|
||||
| reject_policy = fail;
|
||||
| reject_recursively = on;
|
||||
| uptest = query;
|
||||
| query_test_name = ".";
|
||||
| interval = ontimeout;
|
||||
|}
|
||||
|
|
||||
|server {
|
||||
| label = "local-server";
|
||||
| ip = 127.0.0.1;
|
||||
| port = %d;
|
||||
| timeout = 3;
|
||||
|}
|
||||
|
|
||||
|rr {
|
||||
| name=localhost;
|
||||
| reverse=on;
|
||||
| a=127.0.0.1;
|
||||
| owner=localhost;
|
||||
| soa=localhost,root.localhost,42,86400,900,86400,86400;
|
||||
|}
|
||||
""".stripMargin
|
||||
|
||||
def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
|
||||
val p = new java.io.PrintWriter(f)
|
||||
try {
|
||||
@@ -180,6 +207,17 @@ object ConfigUtils {
|
||||
if (holder != null) holder.refresh()
|
||||
}
|
||||
|
||||
def getRejectList(context: Context, app: ShadowsocksApplication): String = {
|
||||
val default = context.getString(R.string.reject)
|
||||
try {
|
||||
val container = app.containerHolder.getContainer
|
||||
val update = container.getString("reject")
|
||||
if (update == null || update.isEmpty) default else update
|
||||
} catch {
|
||||
case ex: Exception => default
|
||||
}
|
||||
}
|
||||
|
||||
def getPublicConfig(context: Context, container: Container, config: Config): Config = {
|
||||
val url = container.getString("proxy_url")
|
||||
val sig = Utils.getSignature(context)
|
||||
|
||||
Reference in New Issue
Block a user