summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-18 14:11:37 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-18 14:11:37 +0200
commit40eb17c3c472bf088568abe7082427f1ab891399 (patch)
treef1433083ca238930bf3b8167d6c38a7a3cacb2ec /src/de/blinkt/openvpn
parentf743921f5812cd7f6c6b681382d60508ed02a4a9 (diff)
Allow only one log window at a time (closes issue #26)
Make OpenvpnService honour net30 routes (closes issue #24)
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/CIDRIP.java32
-rw-r--r--src/de/blinkt/openvpn/LaunchVPN.java1
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java2
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java21
4 files changed, 38 insertions, 18 deletions
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;
}