Browse code

Use pseudo gw as default gw on Android as a workaround for not being able to read /proc/net/route

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1442309019-7586-5-git-send-email-arne@rfc2549.org>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10111

Signed-off-by: Gert Doering <gert@greenie.muc.de>

Arne Schwabe authored on 2015/09/15 18:23:35
Showing 1 changed files
... ...
@@ -2509,6 +2509,7 @@ get_default_gateway (struct route_gateway_info *rgi)
2509 2509
 
2510 2510
   CLEAR(*rgi);
2511 2511
 
2512
+#ifndef TARGET_ANDROID
2512 2513
   /* get default gateway IP addr */
2513 2514
   {
2514 2515
     FILE *fp = fopen ("/proc/net/route", "r");
... ...
@@ -2565,6 +2566,19 @@ get_default_gateway (struct route_gateway_info *rgi)
2565 2565
 	  }
2566 2566
       }
2567 2567
   }
2568
+#else
2569
+  /* Android, set some pseudo GW, addr is in host byte order,
2570
+   * Determining the default GW on Android 5.0+ is non trivial
2571
+   * and serves almost no purpose since OpenVPN only uses the
2572
+   * default GW address to add routes for networks that should
2573
+   * NOT be routed over the VPN. Using a well known address
2574
+   * (127.'d'.'g'.'w') for the default GW make detecting
2575
+   * these routes easier from the controlling app.
2576
+   */
2577
+  rgi->gateway.addr = 127 << 24 | 'd' << 16 | 'g' << 8 | 'w';
2578
+  rgi->flags |= RGI_ADDR_DEFINED;
2579
+  strcpy(best_name, "android-gw");
2580
+#endif
2568 2581
 
2569 2582
   /* scan adapter list */
2570 2583
   if (rgi->flags & RGI_ADDR_DEFINED)