Compare commits

..
5 Commits
Author SHA1 Message Date
Max Lv 08d5d56e46 fix #158 and #155 2014-11-21 16:20:15 +08:00
Max Lv e22b145023 fix #158 2014-11-21 14:51:16 +08:00
Max Lv a10889bb5b fix a bug 2014-11-21 12:15:59 +08:00
Max Lv 800e85dc0d fix #146 2014-11-20 15:37:37 +08:00
Max Lv e778a313ba bump version 2014-11-20 09:22:12 +08:00
8 changed files with 98 additions and 24 deletions
+2 -4
View File
@@ -1,14 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks"
android:versionCode="81"
android:versionName="2.4.1">
android:versionCode="84"
android:versionName="2.4.4">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-feature
android:name="android.hardware.touchscreen"
+76 -9
View File
@@ -70,6 +70,61 @@
#include <generated/blog_channel_tun2socks.h>
#ifdef ANDROID
#include <structure/BAVL.h>
BAVL connections_tree;
typedef struct {
BAddr local_addr;
BAddr remote_addr;
uint16_t port;
int count;
BAVLNode connections_tree_node;
} Connection;
static int conaddr_comparator (void *unused, uint16_t *v1, uint16_t *v2)
{
if (*v1 == *v2) return 0;
else if (*v1 > *v2) return 1;
else return -1;
}
static Connection * find_connection (uint16_t port)
{
BAVLNode *tree_node = BAVL_LookupExact(&connections_tree, &port);
if (!tree_node) {
return NULL;
}
return UPPER_OBJECT(tree_node, Connection, connections_tree_node);
}
static void remove_connection (Connection *con)
{
con->count -= 1;
if (con->count <= 0)
{
BAVL_Remove(&connections_tree, &con->connections_tree_node);
free(con);
}
}
static void insert_connection (BAddr local_addr, BAddr remote_addr, uint16_t port)
{
Connection * con = find_connection(port);
if (con != NULL)
con->count += 1;
else
{
Connection * tmp = (Connection *)malloc(sizeof(Connection));
tmp->local_addr = local_addr;
tmp->remote_addr = remote_addr;
tmp->port = port;
tmp->count = 1;
BAVL_Insert(&connections_tree, &tmp->connections_tree_node, NULL);
}
}
#endif
#define LOGGER_STDOUT 1
#define LOGGER_SYSLOG 2
@@ -1199,8 +1254,6 @@ int process_device_dns_packet (uint8_t *data, int data_len)
goto fail;
}
static BAddr local_addr;
static BAddr remote_addr;
static int init = 0;
int to_dns;
@@ -1257,9 +1310,13 @@ int process_device_dns_packet (uint8_t *data, int data_len)
// construct addresses
if (!init) {
init = 1;
BAddr_InitIPv4(&local_addr, ipv4_header.source_address, udp_header.source_port);
BAddr_InitIPv4(&remote_addr, ipv4_header.destination_address, udp_header.dest_port);
BAVL_Init(&connections_tree, OFFSET_DIFF(Connection, port, connections_tree_node), (BAVL_comparator)conaddr_comparator, NULL);
}
BAddr local_addr;
BAddr remote_addr;
BAddr_InitIPv4(&local_addr, ipv4_header.source_address, udp_header.source_port);
BAddr_InitIPv4(&remote_addr, ipv4_header.destination_address, udp_header.dest_port);
insert_connection(local_addr, remote_addr, udp_header.source_port);
// build IP header
ipv4_header.destination_address = dnsgw.ipv4.ip;
@@ -1277,13 +1334,23 @@ int process_device_dns_packet (uint8_t *data, int data_len)
BLog(BLOG_INFO, "UDP: from DNS %d bytes", data_len);
// build IP header
ipv4_header.source_address = remote_addr.ipv4.ip;
ipv4_header.destination_address = local_addr.ipv4.ip;
Connection * con = find_connection(udp_header.dest_port);
if (con != NULL)
{
// build IP header
ipv4_header.source_address = con->remote_addr.ipv4.ip;
ipv4_header.destination_address = con->local_addr.ipv4.ip;
// build UDP header
udp_header.source_port = remote_addr.ipv4.port;
// build UDP header
udp_header.source_port = con->remote_addr.ipv4.port;
remove_connection(con);
}
else
{
goto fail;
}
}
// update IPv4 header's checksum
+1 -1
View File
@@ -15,7 +15,7 @@ LOCAL_CFLAGS += -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_SCTP \
# LOCAL_CFLAGS += -DOPENSSL_NO_DEPRECATED
# Extra
LOCAL_CFLAGS += -DOPENSSL_NO_HW -DOPENSSL_NO_ASM -DOPENSSL_NO_ENGINE -DZLIB
LOCAL_CFLAGS += -DOPENSSL_NO_HW -DOPENSSL_NO_ENGINE -DZLIB
# Debug
# LOCAL_CFLAGS += -DCIPHER_DEBUG
@@ -100,8 +100,8 @@ static int rc4_hmac_md5_init_key(EVP_CIPHER_CTX *ctx,
return 1;
}
// Disable asm for Android x86_64
#if !defined(OPENSSL_NO_ASM) && ( \
defined(__x86_64) || defined(__x86_64__) || \
defined(_M_AMD64) || defined(_M_X64) || \
defined(__INTEL__) ) && \
!(defined(__APPLE__) && defined(__MACH__))
+6 -1
View File
@@ -6,13 +6,18 @@
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- Enable exception reports -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="com.google.android.gms.analytics.samples.mobileplayground.ScreenviewFragment">
Shadowsocks ScreenView
</screenName>
<screenName name="com.google.android.gms.analytics.samples.mobileplayground.EcommerceFragment">
Shadowsocks EcommerceView
</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-37082941-1</string>
</resources>
</resources>
@@ -128,11 +128,6 @@ object Shadowsocks {
// Helper functions
def updateListPreference(pref: Preference, value: String) {
pref.asInstanceOf[ListPreference].setValue(value)
val entry = pref.asInstanceOf[ListPreference].getEntry
if (entry != null)
pref.setSummary(entry)
else
pref.setSummary(value)
}
def updatePasswordEditTextPreference(pref: Preference, value: String) {
@@ -329,10 +324,12 @@ class Shadowsocks
private def crash_recovery() {
val ab = new ArrayBuffer[String]
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-local.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-tunnel.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.pid")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.conf")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.cache")
@@ -340,9 +337,16 @@ class Shadowsocks
if (!Utils.isLollipopOrAbove) {
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("rm /data/data/com.github.shadowsocks/redsocks.pid")
ab.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.pid")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.conf")
ab.append("rm /data/data/com.github.shadowsocks/pdnsd.cache")
ab.append(Utils.getIptables + " -t nat -F OUTPUT")
Console.runRootCommand(ab.toArray)
@@ -56,7 +56,7 @@ class SummaryListPreference(context: Context, attrs: AttributeSet)
}
override def setSummary(summary: CharSequence) {
if (summary.toString.isEmpty) {
if (summary == null || summary.toString.isEmpty) {
super.setSummary("")
} else {
super.setSummary(summary)