From a03fb1a1c7887c2824735665a8bcb34fc63dcd4d Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Fri, 3 Jan 2020 19:52:37 +0100
Subject: [PATCH 3/4] add new state when remote server is chosen

---
 src/openvpn/init.c   | 11 +++++++++++
 src/openvpn/manage.c |  3 +++
 src/openvpn/manage.h |  1 +
 3 files changed, 15 insertions(+)

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 00606ebd..b37f5fa5 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -4131,6 +4131,17 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f
         do_event_set_init(c, false);
     }
 
+#ifdef ENABLE_MANAGEMENT
+    if (management)
+         management_set_state(management,
+                             OPENVPN_STATE_WILL_CONNECT,
+                             c->options.ce.remote,
+                             NULL,
+                             NULL,
+                             NULL,
+                             NULL);
+#endif
+
     /* initialize HTTP or SOCKS proxy object at scope level 2 */
     init_proxy(c);
 
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 61d61ef2..805b0538 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -168,6 +168,9 @@ man_state_name(const int state)
         case OPENVPN_STATE_TCP_CONNECT:
             return "TCP_CONNECT";
 
+        case OPENVPN_STATE_WILL_CONNECT:
+            return "WILL_CONNECT";
+
         default:
             return "?";
     }
diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h
index f286754b..3231e26b 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
@@ -504,6 +504,7 @@ management_enable_def_auth(const struct management *man)
 #define OPENVPN_STATE_GET_CONFIG    9  /* Downloading configuration from server */
 #define OPENVPN_STATE_RESOLVE       10 /* DNS lookup */
 #define OPENVPN_STATE_TCP_CONNECT   11 /* Connecting to TCP server */
+#define OPENVPN_STATE_WILL_CONNECT   12 /* call after choosing remote */
 
 #define OPENVPN_STATE_CLIENT_BASE   7  /* Base index of client-only states */
 
-- 
2.17.1

