Browse code

Extend network-change command to allow reprotecting on the same network (for short connection losses)

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>

Arne Schwabe authored on 2015/09/15 18:23:37
Showing 3 changed files
... ...
@@ -3162,14 +3162,14 @@ management_show_net_callback (void *arg, const int msglevel)
3162 3162
 
3163 3163
 #ifdef TARGET_ANDROID
3164 3164
 int
3165
-management_callback_network_change (void *arg)
3165
+management_callback_network_change (void *arg, bool samenetwork)
3166 3166
 {
3167 3167
     /* Check if the client should translate the network change to a SIGUSR1 to
3168 3168
      reestablish the connection or just reprotect the socket
3169 3169
 
3170 3170
      At the moment just assume that, for all settings that use pull (not
3171 3171
      --static) and are not using peer-id reestablishing the connection is
3172
-     required
3172
+     required (unless the network is the same)
3173 3173
 
3174 3174
      The function returns -1 on invalid fd and -2 if the socket cannot be
3175 3175
      reused. On the -2 return value the man_network_change function triggers
... ...
@@ -3184,7 +3184,7 @@ management_callback_network_change (void *arg)
3184 3184
     return -1;
3185 3185
 
3186 3186
   socketfd = c->c2.link_socket->sd;
3187
-  if (!c->options.pull || c->c2.tls_multi->use_peer_id)
3187
+  if (!c->options.pull || c->c2.tls_multi->use_peer_id || samenetwork)
3188 3188
     return socketfd;
3189 3189
   else
3190 3190
     return -2;
... ...
@@ -1129,7 +1129,7 @@ man_remote (struct management *man, const char **p)
1129 1129
 
1130 1130
 #ifdef TARGET_ANDROID
1131 1131
 static void
1132
-man_network_change (struct management *man)
1132
+man_network_change (struct management *man, bool samenetwork)
1133 1133
 {
1134 1134
   /* Called to signal the OpenVPN that the network configuration has changed and
1135 1135
      the client should either float or reconnect.
... ...
@@ -1138,7 +1138,8 @@ man_network_change (struct management *man)
1138 1138
   */
1139 1139
   if (man->persist.callback.network_change)
1140 1140
     {
1141
-      int fd = (*man->persist.callback.network_change)(man->persist.callback.arg);
1141
+      int fd = (*man->persist.callback.network_change)
1142
+	(man->persist.callback.arg, samenetwork);
1142 1143
       man->connection.fdtosend = fd;
1143 1144
       msg (M_CLIENT, "PROTECTFD: fd '%d' sent to be protected", fd);
1144 1145
       if (fd == -2)
... ...
@@ -1193,7 +1194,11 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
1193 1193
 #ifdef TARGET_ANDROID
1194 1194
   else if (streq (p[0], "network-change"))
1195 1195
     {
1196
-      man_network_change(man);
1196
+      bool samenetwork = false;
1197
+      if (p[1] && streq(p[1], "samenetwork"))
1198
+	samenetwork = true;
1199
+
1200
+      man_network_change(man, samenetwork);
1197 1201
     }
1198 1202
 #endif
1199 1203
   else if (streq (p[0], "load-stats"))
... ...
@@ -174,7 +174,7 @@ struct management_callback
174 174
   bool (*proxy_cmd) (void *arg, const char **p);
175 175
   bool (*remote_cmd) (void *arg, const char **p);
176 176
 #ifdef TARGET_ANDROID
177
-  int (*network_change) (void *arg);
177
+  int (*network_change) (void *arg, bool samenetwork);
178 178
 #endif
179 179
 };
180 180