From a8ff5059ee83fb83b835032c484ee446bd421432 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 14 Dec 2014 23:41:15 +0100 Subject: fix net30, p2p detection logic (again...), fix NPE when no ifconfig was set/pushed --HG-- extra : rebase_source : 5828a3a9c60f49f9715971ff08d6bc89a638e98b --- .../main/java/de/blinkt/openvpn/core/OpenVPNService.java | 14 +++++++++----- 1 file 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); -- cgit v1.2.3