Commit b7c3c7d2 authored by Max Lv's avatar Max Lv

enable NAT mode again

parent 897b222a
......@@ -334,14 +334,12 @@ class Shadowsocks
Console.runCommand(ab.toArray)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
ab.clear()
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.conf")
ab.append(Utils.getIptables + " -t nat -F OUTPUT")
ab.clear()
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`")
ab.append("rm /data/data/com.github.shadowsocks/redsocks.conf")
ab.append(Utils.getIptables + " -t nat -F OUTPUT")
Console.runRootCommand(ab.toArray)
}
Console.runRootCommand(ab.toArray)
}
private def getVersionName: String = {
......@@ -497,7 +495,7 @@ class Shadowsocks
// Bind to the service
spawn {
val isRoot = Build.VERSION.SDK_INT != Build.VERSION_CODES.LOLLIPOP && Console.isRoot
val isRoot = Console.isRoot
handler.post(new Runnable {
override def run() {
status.edit.putBoolean(Key.isRoot, isRoot).commit()
......@@ -767,7 +765,7 @@ class Shadowsocks
if (pref != null) {
if (Seq(Key.isGlobalProxy, Key.proxyedApps)
.contains(name)) {
pref.setEnabled(enabled && (!isVpnEnabled || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP))
pref.setEnabled(enabled && !isVpnEnabled)
} else {
pref.setEnabled(enabled)
}
......@@ -875,8 +873,7 @@ class Shadowsocks
def isVpnEnabled: Boolean = {
if (vpnEnabled < 0) {
vpnEnabled = if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP
|| !status.getBoolean(Key.isRoot, false)) {
vpnEnabled = if (!status.getBoolean(Key.isRoot, false)) {
1
} else {
0
......
......@@ -63,7 +63,6 @@ class ShadowsocksNatService extends Service with BaseService {
val TAG = "ShadowsocksNatService"
val CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN"
val CMD_IPTABLES_REDIRECT_ADD_SOCKS = " -t nat -A OUTPUT -p tcp " + "-j REDIRECT --to 8123"
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
......@@ -75,7 +74,6 @@ class ShadowsocksNatService extends Service with BaseService {
var receiver: BroadcastReceiver = null
var notificationManager: NotificationManager = null
var config: Config = null
var hasRedirectSupport = false
var apps: Array[ProxiedApp] = null
val myUid = Process.myUid()
......@@ -293,22 +291,10 @@ class ShadowsocksNatService extends Service with BaseService {
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))
if (hasRedirectSupport) {
init_sb
.append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to "
+ DNS_PORT)
} else {
init_sb
.append(Utils.getIptables
+ " -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:"
+ DNS_PORT)
}
init_sb.append(Utils.getIptables
+ " -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:" + DNS_PORT)
if (config.isGlobalProxy || config.isBypassApps) {
http_sb.append(if (hasRedirectSupport) {
Utils.getIptables + CMD_IPTABLES_REDIRECT_ADD_SOCKS
} else {
Utils.getIptables + CMD_IPTABLES_DNAT_ADD_SOCKS
})
http_sb.append(Utils.getIptables + CMD_IPTABLES_DNAT_ADD_SOCKS)
}
if (!config.isGlobalProxy) {
if (apps == null || apps.length <= 0) {
......@@ -322,11 +308,7 @@ class ShadowsocksNatService extends Service with BaseService {
}
for (uid <- uidSet) {
if (!config.isBypassApps) {
http_sb.append((if (hasRedirectSupport) {
Utils.getIptables + CMD_IPTABLES_REDIRECT_ADD_SOCKS
} else {
Utils.getIptables + CMD_IPTABLES_DNAT_ADD_SOCKS
}).replace("-t nat", "-t nat -m owner --uid-owner " + uid))
http_sb.append((Utils.getIptables + CMD_IPTABLES_DNAT_ADD_SOCKS).replace("-t nat", "-t nat -m owner --uid-owner " + uid))
} else {
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " + uid))
}
......@@ -430,8 +412,6 @@ class ShadowsocksNatService extends Service with BaseService {
resolved = true
}
hasRedirectSupport = Utils.getHasRedirectSupport
if (resolved && handleConnection) {
notifyForegroundAlert(getString(R.string.forward_success),
getString(R.string.service_running).format(config.profileName))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment