@@ -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