From 58d5c65f1e9217b93f2e887b63e235af538f82cc 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/5] 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 46fbdc92..ba101eb1 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -4274,6 +4274,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 c831f8a6..14ebcc89 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -171,6 +171,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 3c9028f7..56980fc6 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
@@ -505,6 +505,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.32.0

