Skip to content

Commit 9e87217

Browse files
author
alberto lalama
authored
DNS over UDP relay (#13)
* Resolve DNS through SOCKS UDP relay * Deprecate DNS (SOCKS/TCP) resolver
1 parent 2525a26 commit 9e87217

File tree

9 files changed

+123
-403
lines changed

9 files changed

+123
-403
lines changed

android/java/build-extras.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
dependencies {
22
compile 'com.android.support:appcompat-v7:23.4.0'
3-
compile 'org.uproxy.jsocks:jsocks:1.0.1'
43
}

android/java/org/uproxy/tun2socks/DnsResolverService.java

-288
This file was deleted.

android/java/org/uproxy/tun2socks/Tun2SocksJni.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static native int runTun2Socks(
2929
String vpnIpAddress,
3030
String vpnNetMask,
3131
String socksServerAddress,
32-
String dnsServerAddress,
32+
String udpRelayAddress,
33+
String dnsResolverAddress,
3334
int transparentDNS);
3435

3536
public static native int terminateTun2Socks();

android/java/org/uproxy/tun2socks/Tunnel.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public synchronized boolean startRouting() throws Exception {
103103
}
104104

105105
// Starts tun2socks. Returns true on success.
106-
public synchronized boolean startTunneling(String socksServerAddress, String dnsServerAddress)
106+
public synchronized boolean startTunneling(String socksServerAddress)
107107
throws Exception {
108-
return routeThroughTunnel(socksServerAddress, dnsServerAddress);
108+
return routeThroughTunnel(socksServerAddress);
109109
}
110110

111111
// Stops routing traffic through the tunnel by stopping tun2socks.
@@ -126,6 +126,8 @@ public synchronized void stop() {
126126

127127
private static final String VPN_INTERFACE_NETMASK = "255.255.255.0";
128128
private static final int VPN_INTERFACE_MTU = 1500;
129+
private static final String DNS_RESOLVER_IP = "8.8.8.8";
130+
private static final int DNS_RESOLVER_PORT = 53;
129131

130132
// Note: Atomic variables used for getting/setting local proxy port, routing flag, and
131133
// tun fd, as these functions may be called via callbacks. Do not use
@@ -152,7 +154,7 @@ private boolean startVpn() throws Exception {
152154
.setMtu(VPN_INTERFACE_MTU)
153155
.addAddress(mPrivateAddress.mIpAddress, mPrivateAddress.mPrefixLength)
154156
.addRoute("0.0.0.0", 0)
155-
.addDnsServer(mPrivateAddress.mRouter)
157+
.addDnsServer(DNS_RESOLVER_IP)
156158
.addDisallowedApplication(mHostService.getContext().getPackageName())
157159
.establish();
158160
} catch (NameNotFoundException e) {
@@ -183,7 +185,7 @@ private boolean startVpn() throws Exception {
183185
return true;
184186
}
185187

186-
private boolean routeThroughTunnel(String socksServerAddress, String dnsServerAddress) {
188+
private boolean routeThroughTunnel(String socksServerAddress) {
187189
if (!mRoutingThroughTunnel.compareAndSet(false, true)) {
188190
return false;
189191
}
@@ -198,7 +200,8 @@ private boolean routeThroughTunnel(String socksServerAddress, String dnsServerAd
198200
mPrivateAddress.mRouter,
199201
VPN_INTERFACE_NETMASK,
200202
socksServerAddress,
201-
dnsServerAddress,
203+
socksServerAddress, // The UDP relay has the same address and port as the SOCKS server.
204+
String.format("%s:%d", DNS_RESOLVER_IP, DNS_RESOLVER_PORT),
202205
true /* transparent DNS */);
203206

204207
mHostService.onTunnelConnected();
@@ -243,7 +246,8 @@ private void startTun2Socks(
243246
final String vpnIpAddress,
244247
final String vpnNetMask,
245248
final String socksServerAddress,
246-
final String dnsServerAddress,
249+
final String udpRelayAddress,
250+
final String dnsResolverAddress,
247251
final boolean transparentDns) {
248252
if (mTun2SocksThread != null) {
249253
return;
@@ -259,7 +263,8 @@ public void run() {
259263
vpnIpAddress,
260264
vpnNetMask,
261265
socksServerAddress,
262-
dnsServerAddress,
266+
udpRelayAddress,
267+
dnsResolverAddress,
263268
transparentDns ? 1 : 0);
264269
}
265270
});

0 commit comments

Comments
 (0)