]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Extend network-change command to allow reprotecting on the same network (for short...
authorArne Schwabe <arne@rfc2549.org>
Tue, 15 Sep 2015 09:23:37 +0000 (11:23 +0200)
committerGert Doering <gert@greenie.muc.de>
Tue, 15 Sep 2015 11:19:48 +0000 (13:19 +0200)
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1442309019-7586-7-git-send-email-arne@rfc2549.org>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10106

Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/init.c
src/openvpn/manage.c
src/openvpn/manage.h

index b6cfecee1fdeab4630b7528689b1f1e4c67904cb..48542c9c394cd9b7565517453140ac9d4c8ccfbb 100644 (file)
@@ -3162,14 +3162,14 @@ management_show_net_callback (void *arg, const int msglevel)
 
 #ifdef TARGET_ANDROID
 int
-management_callback_network_change (void *arg)
+management_callback_network_change (void *arg, bool samenetwork)
 {
     /* Check if the client should translate the network change to a SIGUSR1 to
      reestablish the connection or just reprotect the socket
 
      At the moment just assume that, for all settings that use pull (not
      --static) and are not using peer-id reestablishing the connection is
-     required
+     required (unless the network is the same)
 
      The function returns -1 on invalid fd and -2 if the socket cannot be
      reused. On the -2 return value the man_network_change function triggers
@@ -3184,7 +3184,7 @@ management_callback_network_change (void *arg)
     return -1;
 
   socketfd = c->c2.link_socket->sd;
-  if (!c->options.pull || c->c2.tls_multi->use_peer_id)
+  if (!c->options.pull || c->c2.tls_multi->use_peer_id || samenetwork)
     return socketfd;
   else
     return -2;
index af4aa44f20739fe8935149376d35a5ca4ee8a28e..d02dac9c6acfdf5794538b460ae65eab283aeaa6 100644 (file)
@@ -1129,7 +1129,7 @@ man_remote (struct management *man, const char **p)
 
 #ifdef TARGET_ANDROID
 static void
-man_network_change (struct management *man)
+man_network_change (struct management *man, bool samenetwork)
 {
   /* Called to signal the OpenVPN that the network configuration has changed and
      the client should either float or reconnect.
@@ -1138,7 +1138,8 @@ man_network_change (struct management *man)
   */
   if (man->persist.callback.network_change)
     {
-      int fd = (*man->persist.callback.network_change)(man->persist.callback.arg);
+      int fd = (*man->persist.callback.network_change)
+       (man->persist.callback.arg, samenetwork);
       man->connection.fdtosend = fd;
       msg (M_CLIENT, "PROTECTFD: fd '%d' sent to be protected", fd);
       if (fd == -2)
@@ -1193,7 +1194,11 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
 #ifdef TARGET_ANDROID
   else if (streq (p[0], "network-change"))
     {
-      man_network_change(man);
+      bool samenetwork = false;
+      if (p[1] && streq(p[1], "samenetwork"))
+       samenetwork = true;
+
+      man_network_change(man, samenetwork);
     }
 #endif
   else if (streq (p[0], "load-stats"))
index 73183777a77da5a8a1b42c6fab18a22f141bcde8..a97e8a2345867b87b22208d59cdc6099545a9405 100644 (file)
@@ -174,7 +174,7 @@ struct management_callback
   bool (*proxy_cmd) (void *arg, const char **p);
   bool (*remote_cmd) (void *arg, const char **p);
 #ifdef TARGET_ANDROID
-  int (*network_change) (void *arg);
+  int (*network_change) (void *arg, bool samenetwork);
 #endif
 };