Commit b7c3c7d2 authored by Max Lv's avatar Max Lv

enable NAT mode again

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