Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
9217aee2
Commit
9217aee2
authored
Jun 05, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnsgw works now
parent
c361dacf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
36 deletions
+72
-36
src/main/assets/arm/tun2socks
src/main/assets/arm/tun2socks
+0
-0
src/main/assets/x86/tun2socks
src/main/assets/x86/tun2socks
+0
-0
src/main/jni/Android.mk
src/main/jni/Android.mk
+3
-1
src/main/jni/badvpn/base/BLog.c
src/main/jni/badvpn/base/BLog.c
+14
-0
src/main/jni/badvpn/base/BLog.h
src/main/jni/badvpn/base/BLog.h
+0
-8
src/main/jni/badvpn/tun2socks/tun2socks.c
src/main/jni/badvpn/tun2socks/tun2socks.c
+53
-15
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
+2
-12
No files found.
src/main/assets/arm/tun2socks
View file @
9217aee2
No preview for this file type
src/main/assets/x86/tun2socks
View file @
9217aee2
No preview for this file type
src/main/jni/Android.mk
View file @
9217aee2
...
...
@@ -184,7 +184,7 @@ LOCAL_CFLAGS := -std=gnu99
LOCAL_CFLAGS
+=
-DBADVPN_THREADWORK_USE_PTHREAD
-DBADVPN_LINUX
-DBADVPN_BREACTOR_BADVPN
-D_GNU_SOURCE
LOCAL_CFLAGS
+=
-DBADVPN_USE_SELFPIPE
-DBADVPN_USE_EPOLL
LOCAL_CFLAGS
+=
-DBADVPN_LITTLE_ENDIAN
-DBADVPN_THREAD_SAFE
LOCAL_CFLAGS
+=
-DANDROID
LOCAL_CFLAGS
+=
-D
NDEBUG
-D
ANDROID
LOCAL_C_INCLUDES
:=
\
$(LOCAL_PATH)
/badvpn/lwip/src/include/ipv4
\
...
...
@@ -255,6 +255,8 @@ TUN2SOCKS_SOURCES := \
LOCAL_MODULE
:=
tun2socks
LOCAL_LDLIBS
:=
-ldl
-llog
LOCAL_SRC_FILES
:=
$(
addprefix
badvpn/,
$(TUN2SOCKS_SOURCES)
)
include
$(BUILD_EXECUTABLE)
...
...
src/main/jni/badvpn/base/BLog.c
View file @
9217aee2
...
...
@@ -32,6 +32,10 @@
#include "BLog.h"
#ifdef ANDROID
#include <android/log.h>
#endif
#ifndef BADVPN_PLUGIN
struct
_BLog_channel
blog_channel_list
[]
=
{
...
...
@@ -51,12 +55,22 @@ static char *level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBU
static
void
stdout_log
(
int
channel
,
int
level
,
const
char
*
msg
)
{
#ifndef ANDROID
fprintf
(
stdout
,
"%s(%s): %s
\n
"
,
level_names
[
level
],
blog_global
.
channels
[
channel
].
name
,
msg
);
#else
__android_log_print
(
ANDROID_LOG_DEBUG
,
"tun2socks"
,
"%s(%s): %s
\n
"
,
level_names
[
level
],
blog_global
.
channels
[
channel
].
name
,
msg
);
#endif
}
static
void
stderr_log
(
int
channel
,
int
level
,
const
char
*
msg
)
{
#ifndef ANDROID
fprintf
(
stderr
,
"%s(%s): %s
\n
"
,
level_names
[
level
],
blog_global
.
channels
[
channel
].
name
,
msg
);
#else
__android_log_print
(
ANDROID_LOG_ERROR
,
"tun2socks"
,
"%s(%s): %s
\n
"
,
level_names
[
level
],
blog_global
.
channels
[
channel
].
name
,
msg
);
#endif
}
static
void
stdout_stderr_free
(
void
)
...
...
src/main/jni/badvpn/base/BLog.h
View file @
9217aee2
...
...
@@ -40,14 +40,6 @@
#include <misc/debug.h>
#include <base/BMutex.h>
#ifdef ANDROID
#include <android/log.h>
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "tun2socks", __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "tun2socks", __VA_ARGS__))
#endif
// auto-generated channel numbers and number of channels
#include <generated/blog_channels_defines.h>
...
...
src/main/jni/badvpn/tun2socks/tun2socks.c
View file @
9217aee2
...
...
@@ -965,7 +965,7 @@ int process_arguments (void)
}
#ifdef ANDROID
// resolve dnsgw
ip
addr
// resolve dnsgw addr
if
(
options
.
dnsgw
)
{
if
(
!
BAddr_Parse2
(
&
dnsgw
,
options
.
dnsgw
,
NULL
,
0
,
0
))
{
BLog
(
BLOG_ERROR
,
"dnsgw addr: BAddr_Parse2 failed"
);
...
...
@@ -1179,9 +1179,12 @@ int process_device_dns_packet (uint8_t *data, int data_len)
goto
fail
;
}
BAddr
local_addr
;
BAddr
remote_addr
;
int
is_dns
;
static
BAddr
local_addr
;
static
BAddr
remote_addr
;
static
int
init
=
0
;
int
to_dns
;
int
from_dns
;
int
packet_length
=
0
;
uint8_t
ip_version
=
0
;
...
...
@@ -1215,28 +1218,63 @@ int process_device_dns_packet (uint8_t *data, int data_len)
if
(
checksum_in_packet
!=
checksum_computed
)
{
goto
fail
;
}
BLog
(
BLOG_INFO
,
"UDP: from device %d bytes"
,
data_len
);
// to port 53 is considered a DNS packet
is_dns
=
udp_header
.
dest_port
==
hton16
(
53
);
to_dns
=
udp_header
.
dest_port
==
hton16
(
53
);
// from port 8153 is considered a DNS packet
from_dns
=
udp_header
.
source_port
==
dnsgw
.
ipv4
.
port
;
// if not DNS packet, just bypass it.
if
(
!
is
_dns
)
{
if
(
!
to_dns
&&
!
from
_dns
)
{
goto
fail
;
}
// build IP header
ipv4_header
.
destination_address
=
dnsgw
.
ipv4
.
ip
;
// modify DNS packet
if
(
to_dns
)
{
BLog
(
BLOG_INFO
,
"UDP: to DNS %d bytes"
,
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
);
}
// build IP header
ipv4_header
.
destination_address
=
dnsgw
.
ipv4
.
ip
;
ipv4_header
.
source_address
=
netif_ipaddr
.
ipv4
;
// build UDP header
udp_header
.
dest_port
=
dnsgw
.
ipv4
.
port
;
}
else
if
(
from_dns
)
{
// if not initialized
if
(
!
init
)
{
goto
fail
;
}
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
;
// build UDP header
udp_header
.
source_port
=
remote_addr
.
ipv4
.
port
;
}
// update IPv4 header's checksum
ipv4_header
.
checksum
=
hton16
(
0
);
ipv4_header
.
checksum
=
ipv4_checksum
(
&
ipv4_header
,
NULL
,
0
);
// build UDP header
udp_header
.
dest_port
=
dnsgw
.
ipv4
.
port
;
// update UDP header's checksum
udp_header
.
checksum
=
hton16
(
0
);
udp_header
.
checksum
=
udp_checksum
(
&
udp_header
,
data
,
data_len
,
ipv4_header
.
source_address
,
ipv4_header
.
destination_address
);
// write packet
memcpy
(
device_write_buf
,
&
ipv4_header
,
sizeof
(
ipv4_header
));
memcpy
(
device_write_buf
+
sizeof
(
ipv4_header
),
&
udp_header
,
sizeof
(
udp_header
));
...
...
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
View file @
9217aee2
...
...
@@ -75,7 +75,6 @@ class ShadowVpnService extends VpnService {
val
PRIVATE_VLAN_172
=
"172.30.254.%d"
var
conn
:
ParcelFileDescriptor
=
null
var
udpgw
:
String
=
null
var
notificationManager
:
NotificationManager
=
null
var
receiver
:
BroadcastReceiver
=
null
var
apps
:
Array
[
ProxiedApp
]
=
null
...
...
@@ -203,14 +202,6 @@ class ShadowVpnService extends VpnService {
resolved
=
true
}
// Resolve UDP gateway
if
(
resolved
)
{
Utils
.
resolve
(
"u.maxcdn.info"
,
enableIPv6
=
false
)
match
{
case
Some
(
host
)
=>
udpgw
=
host
case
None
=>
resolved
=
false
}
}
if
(
resolved
&&
handleConnection
)
{
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_SUCCESS
,
300
)
}
else
{
...
...
@@ -259,7 +250,6 @@ class ShadowVpnService extends VpnService {
.
setMtu
(
VPN_MTU
)
.
addAddress
(
localAddress
.
format
(
1
),
24
)
.
addDnsServer
(
"8.8.8.8"
)
.
addDnsServer
(
"8.8.4.4"
)
if
(
InetAddressUtils
.
isIPv6Address
(
config
.
proxy
))
{
builder
.
addRoute
(
"0.0.0.0"
,
0
)
...
...
@@ -312,13 +302,13 @@ class ShadowVpnService extends VpnService {
val
cmd
=
(
BASE
+
"tun2socks --netif-ipaddr %s "
// + "--udpgw-remote-server-addr %s:7300 "
+
"--dnsgw
127.0.0.1
:8153 "
+
"--dnsgw
%s
:8153 "
+
"--netif-netmask 255.255.255.0 "
+
"--socks-server-addr 127.0.0.1:%d "
+
"--tunfd %d "
+
"--tunmtu %d "
+
"--pid %stun2socks.pid"
)
.
format
(
localAddress
.
format
(
2
),
config
.
localPort
,
fd
,
VPN_MTU
,
BASE
)
.
format
(
localAddress
.
format
(
2
),
localAddress
.
format
(
1
),
config
.
localPort
,
fd
,
VPN_MTU
,
BASE
)
Log
.
d
(
TAG
,
cmd
)
System
.
exec
(
cmd
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment