summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2015-12-08 16:02:24 +0100
committerArne Schwabe <arne@rfc2549.org>2015-12-08 16:02:24 +0100
commit8289c4dadcc09121b446d4718787035f49000dff (patch)
treecc796980f38569af03c766a04ad043bccc591b95 /main
parent49c6501f141a2e173f92cd57c3da600da8d2ed5e (diff)
Fix long long long outstanding bug causing delay when starting VPN. Thanks @adamjweaver for tracking this downv0.6.46-productionv0.6.46
Closes #403
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java258
1 files changed, 129 insertions, 129 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
index f81c46ad..2572f509 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
@@ -39,16 +39,16 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
private LocalSocket mSocket;
private VpnProfile mProfile;
private OpenVPNService mOpenVPNService;
- private LinkedList<FileDescriptor> mFDList = new LinkedList<>();
+ private LinkedList<FileDescriptor> mFDList = new LinkedList<>();
private LocalServerSocket mServerSocket;
private boolean mWaitingForRelease = false;
private long mLastHoldRelease = 0;
- private static final Vector<OpenVpnManagementThread> active = new Vector<>();
+ private static final Vector<OpenVpnManagementThread> active = new Vector<>();
private LocalSocket mServerSocketLocal;
private pauseReason lastPauseReason = pauseReason.noNetwork;
- private PausedStateCallback mPauseCallback;
+ private PausedStateCallback mPauseCallback;
public OpenVpnManagementThread(VpnProfile profile, OpenVPNService openVpnService) {
mProfile = profile;
@@ -64,7 +64,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
mServerSocketLocal = new LocalSocket();
- while (tries > 0 && !mServerSocketLocal.isConnected()) {
+ while (tries > 0 && !mServerSocketLocal.isBound()) {
try {
mServerSocketLocal.bind(new LocalSocketAddress(socketName,
LocalSocketAddress.Namespace.FILESYSTEM));
@@ -72,7 +72,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
// wait 300 ms before retrying
try {
Thread.sleep(300);
- } catch (InterruptedException ignored) {
+ } catch (InterruptedException ignored) {
}
}
@@ -172,12 +172,12 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
//pfd.close();
NativeUtils.jniclose(fdint);
return;
- } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException | NullPointerException e) {
- VpnStatus.logException("Failed to retrieve fd from socket (" + fd + ")", e);
+ } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException | NullPointerException e) {
+ VpnStatus.logException("Failed to retrieve fd from socket (" + fd + ")", e);
}
Log.d("Openvpn", "Failed to retrieve fd from socket: " + fd);
-
+
}
private String processInput(String pendingInput) {
@@ -206,38 +206,38 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
String argument = parts[1];
- switch (cmd) {
- case "INFO":
+ switch (cmd) {
+ case "INFO":
/* Ignore greeting from management */
- return;
- case "PASSWORD":
- processPWCommand(argument);
- break;
- case "HOLD":
- handleHold();
- break;
- case "NEED-OK":
- processNeedCommand(argument);
- break;
- case "BYTECOUNT":
- processByteCount(argument);
- break;
- case "STATE":
- processState(argument);
- break;
- case "PROXY":
- processProxyCMD(argument);
- break;
- case "LOG":
- processLogMessage(argument);
- break;
- case "RSA_SIGN":
- processSignCommand(argument);
- break;
- default:
- VpnStatus.logWarning("MGMT: Got unrecognized command" + command);
- Log.i(TAG, "Got unrecognized command" + command);
- break;
+ return;
+ case "PASSWORD":
+ processPWCommand(argument);
+ break;
+ case "HOLD":
+ handleHold();
+ break;
+ case "NEED-OK":
+ processNeedCommand(argument);
+ break;
+ case "BYTECOUNT":
+ processByteCount(argument);
+ break;
+ case "STATE":
+ processState(argument);
+ break;
+ case "PROXY":
+ processProxyCMD(argument);
+ break;
+ case "LOG":
+ processLogMessage(argument);
+ break;
+ case "RSA_SIGN":
+ processSignCommand(argument);
+ break;
+ default:
+ VpnStatus.logWarning("MGMT: Got unrecognized command" + command);
+ Log.i(TAG, "Got unrecognized command" + command);
+ break;
}
} else if (command.startsWith("SUCCESS:")) {
/* Ignore this kind of message too */
@@ -269,22 +269,22 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
Log.d("OpenVPN", argument);
VpnStatus.LogLevel level;
- switch (args[1]) {
- case "I":
- level = VpnStatus.LogLevel.INFO;
- break;
- case "W":
- level = VpnStatus.LogLevel.WARNING;
- break;
- case "D":
- level = VpnStatus.LogLevel.VERBOSE;
- break;
- case "F":
- level = VpnStatus.LogLevel.ERROR;
- break;
- default:
- level = VpnStatus.LogLevel.INFO;
- break;
+ switch (args[1]) {
+ case "I":
+ level = VpnStatus.LogLevel.INFO;
+ break;
+ case "W":
+ level = VpnStatus.LogLevel.WARNING;
+ break;
+ case "D":
+ level = VpnStatus.LogLevel.VERBOSE;
+ break;
+ case "F":
+ level = VpnStatus.LogLevel.ERROR;
+ break;
+ default:
+ level = VpnStatus.LogLevel.INFO;
+ break;
}
int ovpnlevel = Integer.parseInt(args[2]) & 0x0F;
@@ -296,15 +296,15 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
VpnStatus.logMessageOpenVPN(level, ovpnlevel, msg);
}
- boolean shouldBeRunning() {
- if (mPauseCallback == null)
- return false;
- else
- return mPauseCallback.shouldBeRunning();
- }
-
+ boolean shouldBeRunning() {
+ if (mPauseCallback == null)
+ return false;
+ else
+ return mPauseCallback.shouldBeRunning();
+ }
+
private void handleHold() {
- if (shouldBeRunning()) {
+ if (shouldBeRunning()) {
releaseHoldCmd();
} else {
mWaitingForRelease = true;
@@ -331,7 +331,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
//managmentCommand("log on all\n");
}
-
+
public void releaseHold() {
if (mWaitingForRelease)
releaseHoldCmd();
@@ -394,19 +394,19 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
String status = "ok";
- switch (needed) {
- case "PROTECTFD":
- FileDescriptor fdtoprotect = mFDList.pollFirst();
- protectFileDescriptor(fdtoprotect);
- break;
- case "DNSSERVER":
- mOpenVPNService.addDNS(extra);
- break;
- case "DNSDOMAIN":
- mOpenVPNService.setDomain(extra);
- break;
- case "ROUTE": {
- String[] routeparts = extra.split(" ");
+ switch (needed) {
+ case "PROTECTFD":
+ FileDescriptor fdtoprotect = mFDList.pollFirst();
+ protectFileDescriptor(fdtoprotect);
+ break;
+ case "DNSSERVER":
+ mOpenVPNService.addDNS(extra);
+ break;
+ case "DNSDOMAIN":
+ mOpenVPNService.setDomain(extra);
+ break;
+ case "ROUTE": {
+ String[] routeparts = extra.split(" ");
/*
buf_printf (&out, "%s %s %s dev %s", network, netmask, gateway, rgi->iface);
@@ -414,45 +414,45 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
buf_printf (&out, "%s %s %s", network, netmask, gateway);
*/
- if (routeparts.length == 5) {
- if (BuildConfig.DEBUG) Assert.assertEquals("dev", routeparts[3]);
- mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], routeparts[4]);
- } else if (routeparts.length >= 3) {
- mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], null);
- } else {
- VpnStatus.logError("Unrecognized ROUTE cmd:" + Arrays.toString(routeparts) + " | " + argument);
- }
-
- break;
- }
- case "ROUTE6": {
- String[] routeparts = extra.split(" ");
- mOpenVPNService.addRoutev6(routeparts[0], routeparts[1]);
- break;
+ if (routeparts.length == 5) {
+ if (BuildConfig.DEBUG) Assert.assertEquals("dev", routeparts[3]);
+ mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], routeparts[4]);
+ } else if (routeparts.length >= 3) {
+ mOpenVPNService.addRoute(routeparts[0], routeparts[1], routeparts[2], null);
+ } else {
+ VpnStatus.logError("Unrecognized ROUTE cmd:" + Arrays.toString(routeparts) + " | " + argument);
+ }
+
+ break;
+ }
+ case "ROUTE6": {
+ String[] routeparts = extra.split(" ");
+ mOpenVPNService.addRoutev6(routeparts[0], routeparts[1]);
+ break;
}
- case "IFCONFIG":
- String[] ifconfigparts = extra.split(" ");
- int mtu = Integer.parseInt(ifconfigparts[2]);
- mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1], mtu, ifconfigparts[3]);
- break;
- case "IFCONFIG6":
- mOpenVPNService.setLocalIPv6(extra);
-
- break;
- case "PERSIST_TUN_ACTION":
- // check if tun cfg stayed the same
- status = mOpenVPNService.getTunReopenStatus();
- break;
- case "OPENTUN":
- if (sendTunFD(needed, extra))
- return;
- else
- status = "cancel";
- // This not nice or anything but setFileDescriptors accepts only FilDescriptor class :(
-
- break;
- default:
- Log.e(TAG, "Unkown needok command " + argument);
+ case "IFCONFIG":
+ String[] ifconfigparts = extra.split(" ");
+ int mtu = Integer.parseInt(ifconfigparts[2]);
+ mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1], mtu, ifconfigparts[3]);
+ break;
+ case "IFCONFIG6":
+ mOpenVPNService.setLocalIPv6(extra);
+
+ break;
+ case "PERSIST_TUN_ACTION":
+ // check if tun cfg stayed the same
+ status = mOpenVPNService.getTunReopenStatus();
+ break;
+ case "OPENTUN":
+ if (sendTunFD(needed, extra))
+ return;
+ else
+ status = "cancel";
+ // This not nice or anything but setFileDescriptors accepts only FilDescriptor class :(
+
+ break;
+ default:
+ Log.e(TAG, "Unkown needok command " + argument);
return;
}
@@ -494,9 +494,9 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
pfd.close();
return true;
- } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException |
- IOException | IllegalAccessException exp) {
- VpnStatus.logException("Could not send fd over socket", exp);
+ } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException |
+ IOException | IllegalAccessException exp) {
+ VpnStatus.logException("Could not send fd over socket", exp);
}
return false;
@@ -566,20 +566,20 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
@Override
public void networkChange(boolean samenetwork) {
- if (mWaitingForRelease)
- releaseHold();
- else if (samenetwork)
- managmentCommand("network-change samenetwork\n");
- else
- managmentCommand("network-change\n");
+ if (mWaitingForRelease)
+ releaseHold();
+ else if (samenetwork)
+ managmentCommand("network-change samenetwork\n");
+ else
+ managmentCommand("network-change\n");
}
- @Override
- public void setPauseCallback(PausedStateCallback callback) {
- mPauseCallback = callback;
- }
+ @Override
+ public void setPauseCallback(PausedStateCallback callback) {
+ mPauseCallback = callback;
+ }
- public void signalusr1() {
+ public void signalusr1() {
if (!mWaitingForRelease)
managmentCommand("signal SIGUSR1\n");
else