summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-03-13 13:37:57 +0100
committerArne Schwabe <arne@rfc2549.org>2014-03-13 13:37:57 +0100
commitd2692a74e86d44cc70e276184f1c67a84bfe17ae (patch)
treea446a705d60a7097f93b3a3e3e06e11ca53d4796
parent9c3b8cae419af4888580fe89b4c5d3789d4369ad (diff)
Allow interface roaming. Currently only tested with static/udp configuration
-rw-r--r--main/openvpn/config-version.h4
-rw-r--r--main/openvpn/src/openvpn/init.c17
-rw-r--r--main/openvpn/src/openvpn/manage.c17
-rw-r--r--main/openvpn/src/openvpn/manage.h3
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java12
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java4
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java15
7 files changed, 65 insertions, 7 deletions
diff --git a/main/openvpn/config-version.h b/main/openvpn/config-version.h
index 3b3c7918..4dcbb0ae 100644
--- a/main/openvpn/config-version.h
+++ b/main/openvpn/config-version.h
@@ -1,2 +1,2 @@
-#define CONFIGURE_GIT_REVISION "icsopenvpn_70-078981e61dfdf105"
-#define CONFIGURE_GIT_FLAGS ""
+#define CONFIGURE_GIT_REVISION "icsopenvpn_610-eab94f1a54e461a1"
+#define CONFIGURE_GIT_FLAGS "+"
diff --git a/main/openvpn/src/openvpn/init.c b/main/openvpn/src/openvpn/init.c
index c39646de..a866b7d6 100644
--- a/main/openvpn/src/openvpn/init.c
+++ b/main/openvpn/src/openvpn/init.c
@@ -3209,6 +3209,20 @@ management_show_net_callback (void *arg, const int msglevel)
#endif
}
+#ifdef TARGET_ANDROID
+int
+managmenet_callback_network_change (void *arg)
+{
+ struct context *c = (struct context *) arg;
+ if (!c->c2.link_socket)
+ return -1;
+ if (c->c2.link_socket->sd == SOCKET_UNDEFINED)
+ return -1;
+
+ return c->c2.link_socket->sd;
+}
+#endif
+
#endif
void
@@ -3224,6 +3238,9 @@ init_management_callback_p2p (struct context *c)
cb.show_net = management_show_net_callback;
cb.proxy_cmd = management_callback_proxy_cmd;
cb.remote_cmd = management_callback_remote_cmd;
+#ifdef TARGET_ANDROID
+ cb.network_change = managmenet_callback_network_change;
+#endif
management_set_callback (management, &cb);
}
#endif
diff --git a/main/openvpn/src/openvpn/manage.c b/main/openvpn/src/openvpn/manage.c
index 561c252b..855ed042 100644
--- a/main/openvpn/src/openvpn/manage.c
+++ b/main/openvpn/src/openvpn/manage.c
@@ -1105,6 +1105,19 @@ man_remote (struct management *man, const char **p)
}
}
+#ifdef TARGET_ANDROID
+static void
+man_network_change (struct management *man)
+{
+ if (man->persist.callback.network_change)
+ {
+ int fd = (*man->persist.callback.network_change)(man->persist.callback.arg);
+ man->connection.fdtosend = fd;
+ msg (M_CLIENT, "PROTECTFD: fd '%d' sent to be protected", fd);
+ }
+}
+#endif
+
static void
man_dispatch_command (struct management *man, struct status_output *so, const char **p, const int nparms)
{
@@ -1148,6 +1161,10 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
if (man_need (man, p, 1, 0))
man_signal (man, p[1]);
}
+ else if (streq (p[0], "network-change"))
+ {
+ man_network_change(man);
+ }
else if (streq (p[0], "load-stats"))
{
man_load_stats (man);
diff --git a/main/openvpn/src/openvpn/manage.h b/main/openvpn/src/openvpn/manage.h
index 1c8dda69..c48875c7 100644
--- a/main/openvpn/src/openvpn/manage.h
+++ b/main/openvpn/src/openvpn/manage.h
@@ -173,6 +173,9 @@ struct management_callback
#endif
bool (*proxy_cmd) (void *arg, const char **p);
bool (*remote_cmd) (void *arg, const char **p);
+#ifdef TARGET_ANDROID
+ int (*network_change) (void *arg);
+#endif
};
/*
diff --git a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
index 68b30bce..41e8ff0a 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/DeviceStateReceiver.java
@@ -172,15 +172,19 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL
int newnet = networkInfo.getType();
network = connectState.SHOULDBECONNECTED;
- if (sendusr1 && lastNetwork != newnet) {
+ if (lastNetwork != newnet) {
if (screen == connectState.PENDINGDISCONNECT)
screen = connectState.DISCONNECTED;
if (shouldBeConnected()) {
- if (lastNetwork == -1) {
- mManagement.resume();
+ if (sendusr1) {
+ if (lastNetwork == -1) {
+ mManagement.resume();
+ } else {
+ mManagement.reconnect();
+ }
} else {
- mManagement.reconnect();
+ mManagement.networkChange();
}
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
index ce8d38c2..a5a3e9f4 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
@@ -17,4 +17,8 @@ public interface OpenVPNManagement {
boolean stopVPN();
+ /*
+ * Rebind the interface
+ */
+ void networkChange();
}
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 1937ffc0..6ef41e1b 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVpnManagementThread.java
@@ -158,7 +158,10 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
// You can even get more evil by parsing toString() and extract the int from that :)
- mOpenVPNService.protect(fdint);
+ boolean result = mOpenVPNService.protect(fdint);
+ if (!result)
+ VpnStatus.logWarning("Could not protect VPN socket");
+
//ParcelFileDescriptor pfd = ParcelFileDescriptor.fromFd(fdint);
//pfd.close();
@@ -232,6 +235,10 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
} else if (command.startsWith("SUCCESS:")) {
/* Ignore this kind of message too */
return;
+ } else if (command.startsWith("PROTECTFD: ")) {
+ FileDescriptor fdtoprotect = mFDList.pollFirst();
+ if (fdtoprotect!=null)
+ protectFileDescriptor(fdtoprotect);
} else {
Log.i(TAG, "Got unrecognized line from managment" + command);
VpnStatus.logWarning("MGMT: Got unrecognized line from management:" + command);
@@ -535,6 +542,12 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement {
return sendCMD;
}
+ @Override
+ public void networkChange() {
+ if(!mWaitingForRelease)
+ managmentCommand("network-change\n");
+ }
+
public void signalusr1() {
mReleaseHold=false;