@@ -103,9 +103,9 @@ public synchronized boolean startRouting() throws Exception {
103
103
}
104
104
105
105
// Starts tun2socks. Returns true on success.
106
- public synchronized boolean startTunneling (String socksServerAddress , String dnsServerAddress )
106
+ public synchronized boolean startTunneling (String socksServerAddress )
107
107
throws Exception {
108
- return routeThroughTunnel (socksServerAddress , dnsServerAddress );
108
+ return routeThroughTunnel (socksServerAddress );
109
109
}
110
110
111
111
// Stops routing traffic through the tunnel by stopping tun2socks.
@@ -126,6 +126,8 @@ public synchronized void stop() {
126
126
127
127
private static final String VPN_INTERFACE_NETMASK = "255.255.255.0" ;
128
128
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 ;
129
131
130
132
// Note: Atomic variables used for getting/setting local proxy port, routing flag, and
131
133
// tun fd, as these functions may be called via callbacks. Do not use
@@ -152,7 +154,7 @@ private boolean startVpn() throws Exception {
152
154
.setMtu (VPN_INTERFACE_MTU )
153
155
.addAddress (mPrivateAddress .mIpAddress , mPrivateAddress .mPrefixLength )
154
156
.addRoute ("0.0.0.0" , 0 )
155
- .addDnsServer (mPrivateAddress . mRouter )
157
+ .addDnsServer (DNS_RESOLVER_IP )
156
158
.addDisallowedApplication (mHostService .getContext ().getPackageName ())
157
159
.establish ();
158
160
} catch (NameNotFoundException e ) {
@@ -183,7 +185,7 @@ private boolean startVpn() throws Exception {
183
185
return true ;
184
186
}
185
187
186
- private boolean routeThroughTunnel (String socksServerAddress , String dnsServerAddress ) {
188
+ private boolean routeThroughTunnel (String socksServerAddress ) {
187
189
if (!mRoutingThroughTunnel .compareAndSet (false , true )) {
188
190
return false ;
189
191
}
@@ -198,7 +200,8 @@ private boolean routeThroughTunnel(String socksServerAddress, String dnsServerAd
198
200
mPrivateAddress .mRouter ,
199
201
VPN_INTERFACE_NETMASK ,
200
202
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 ),
202
205
true /* transparent DNS */ );
203
206
204
207
mHostService .onTunnelConnected ();
@@ -243,7 +246,8 @@ private void startTun2Socks(
243
246
final String vpnIpAddress ,
244
247
final String vpnNetMask ,
245
248
final String socksServerAddress ,
246
- final String dnsServerAddress ,
249
+ final String udpRelayAddress ,
250
+ final String dnsResolverAddress ,
247
251
final boolean transparentDns ) {
248
252
if (mTun2SocksThread != null ) {
249
253
return ;
@@ -259,7 +263,8 @@ public void run() {
259
263
vpnIpAddress ,
260
264
vpnNetMask ,
261
265
socksServerAddress ,
262
- dnsServerAddress ,
266
+ udpRelayAddress ,
267
+ dnsResolverAddress ,
263
268
transparentDns ? 1 : 0 );
264
269
}
265
270
});
0 commit comments