summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-12-14 23:41:15 +0100
committerArne Schwabe <arne@rfc2549.org>2014-12-14 23:41:15 +0100
commita8ff5059ee83fb83b835032c484ee446bd421432 (patch)
tree8a2ab3e75c3e65d2ff6d348187a2363615a83782
parent370f94cd97e6869be267a69d1ab4943a3418f27c (diff)
fix net30, p2p detection logic (again...), fix NPE when no ifconfig was set/pushed
--HG-- extra : rebase_source : 5828a3a9c60f49f9715971ff08d6bc89a638e98b
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 0569a4f4..d8cf49b2 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -498,7 +498,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
VpnStatus.logInfo(R.string.last_openvpn_tun_config);
- addLocalNetworksToRoutes();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && mProfile.mAllowLocalLAN)
{
allowAllAFFamilies(builder);
@@ -510,6 +509,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
if (mLocalIP != null) {
+ addLocalNetworksToRoutes();
try {
builder.addAddress(mLocalIP.mIp, mLocalIP.len);
} catch (IllegalArgumentException iae) {
@@ -641,6 +641,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
private void addLocalNetworksToRoutes() {
+
// Add local network interfaces
String[] localRoutes = NativeUtils.getIfconfig();
@@ -781,12 +782,15 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
// get the netmask as IP
int masklen;
- if ("net30".equals(mode))
+ long mask;
+ if ("net30".equals(mode)) {
masklen = 30;
- else
+ mask = 0xfffffffc;
+ } else {
masklen = 31;
+ mask = 0xfffffffe;
+ }
- int mask = ~(1 << (32 - (mLocalIP.len + 1)));
// Netmask is Ip address +/-1, assume net30/p2p with small net
if ((netMaskAsInt & mask) == (mLocalIP.getInt() & mask)) {
mLocalIP.len = masklen;
@@ -802,7 +806,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
/* Workaround for Lollipop, it does not route traffic to the VPNs own network mask */
- if (netMaskAsInt < 31 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
+ if (mLocalIP.len <= 31 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
addRoute(mLocalIP);