From 40eb17c3c472bf088568abe7082427f1ab891399 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 18 May 2012 14:11:37 +0200 Subject: Allow only one log window at a time (closes issue #26) Make OpenvpnService honour net30 routes (closes issue #24) --- src/de/blinkt/openvpn/CIDRIP.java | 32 ++++++++++++---------- src/de/blinkt/openvpn/LaunchVPN.java | 1 + src/de/blinkt/openvpn/OpenVpnManagementThread.java | 2 +- src/de/blinkt/openvpn/OpenVpnService.java | 21 ++++++++++++-- 4 files changed, 38 insertions(+), 18 deletions(-) (limited to 'src/de') diff --git a/src/de/blinkt/openvpn/CIDRIP.java b/src/de/blinkt/openvpn/CIDRIP.java index c2f0d821..ccb3836a 100644 --- a/src/de/blinkt/openvpn/CIDRIP.java +++ b/src/de/blinkt/openvpn/CIDRIP.java @@ -5,13 +5,7 @@ class CIDRIP{ int len; public CIDRIP(String ip, String mask){ mIp=ip; - String[] ipt = mask.split("\\."); - long netmask=0; - - netmask += Long.parseLong(ipt[0])<< 24; - netmask += Integer.parseInt(ipt[1])<< 16; - netmask += Integer.parseInt(ipt[2])<< 8; - netmask += Integer.parseInt(ipt[3]); + long netmask=getInt(mask); // Add 33. bit to ensure the loop terminates netmask += 1l << 32; @@ -36,14 +30,7 @@ class CIDRIP{ } public boolean normalise(){ - long ip=0; - - String[] ipt = mIp.split("\\."); - - ip += Long.parseLong(ipt[0])<< 24; - ip += Integer.parseInt(ipt[1])<< 16; - ip += Integer.parseInt(ipt[2])<< 8; - ip += Integer.parseInt(ipt[3]); + long ip=getInt(mIp); long newip = ip & (0xffffffffl << (32 -len)); if (newip != ip){ @@ -53,4 +40,19 @@ class CIDRIP{ return false; } } + static long getInt(String ipaddr) { + String[] ipt = ipaddr.split("\\."); + long ip=0; + + ip += Long.parseLong(ipt[0])<< 24; + ip += Integer.parseInt(ipt[1])<< 16; + ip += Integer.parseInt(ipt[2])<< 8; + ip += Integer.parseInt(ipt[3]); + + return ip; + } + public long getInt() { + return getInt(mIp); + } + } \ No newline at end of file diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index b084b19d..73b1f34d 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -349,6 +349,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { void startOpenVpn() { Intent startLW = new Intent(getBaseContext(),LogWindow.class); + startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(startLW); if(!writeMiniVPN()) { diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java index b568bd60..82d6f00d 100644 --- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java +++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java @@ -239,7 +239,7 @@ public class OpenVpnManagementThread implements Runnable { } else if (needed.equals("IFCONFIG")) { String[] ifconfigparts = extra.split(" "); int mtu = Integer.parseInt(ifconfigparts[2]); - mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1],mtu); + mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1],mtu,ifconfigparts[3]); } else if (needed.equals("IFCONFIG6")) { mOpenVPNService.setLocalIPv6(extra); diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index 8f846e32..e2f7ba12 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -248,7 +248,9 @@ public class OpenVpnService extends VpnService implements Handler.Callback { // Let the configure Button show the Log Intent intent = new Intent(getBaseContext(),LogWindow.class); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent startLW = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); builder.setConfigureIntent(startLW); try { ParcelFileDescriptor pfd = builder.establish(); @@ -309,16 +311,31 @@ public class OpenVpnService extends VpnService implements Handler.Callback { } - public void setLocalIP(String local, String netmask,int mtu) { + public void setLocalIP(String local, String netmask,int mtu, String mode) { mLocalIP = new CIDRIP(local, netmask); mMtu = mtu; if(mLocalIP.len == 32 && !netmask.equals("255.255.255.255")) { - OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask))); + // get the netmask as IP + long netint = CIDRIP.getInt(netmask); + if(Math.abs(netint - mLocalIP.getInt()) ==1) { + if(mode.equals("net30")) + mLocalIP.len=30; + else + mLocalIP.len=31; + } else { + OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask,mode))); + } } } + + + + + + public void setLocalIPv6(String ipv6addr) { mLocalIPv6 = ipv6addr; } -- cgit v1.2.3