[network-manager-openvpn/dcbw/openvpn-restart: 5/5] core: track openvpn state to detect reconnections



commit 13d3c1426345005f4dd905ff9f0c45ca84ccae9b
Author: Dan Williams <dcbw redhat com>
Date:   Fri Oct 17 16:23:58 2014 -0500

    core: track openvpn state to detect reconnections
    
    Unfortunately openvpn doesn't allow us to suppress pushed
    'ping-exit' options, in which case the exit action will
    override our default 'ping-restart' and openvpn will just
    exit instead of restarting as we really want.
    
    But, if the server is correctly configured, this commit
    will cause the plugin to re-enter the ACTIVATING state,
    allow a reconnect, and update NetworkManager with the new
    IP configuration, all while leaving the tunnel up.

 src/nm-openvpn-service.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 9345850..2c5f180 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -79,6 +79,7 @@ typedef struct {
        char *pending_auth;
        GIOChannel *socket_channel;
        guint socket_channel_eventid;
+       gboolean did_connect;
 } NMOpenvpnPluginIOData;
 
 typedef struct {
@@ -511,6 +512,35 @@ handle_management_socket (NMVPNPlugin *plugin,
        if (debug)
                g_message ("VPN request '%s'", str);
 
+       if (g_str_has_prefix (str, ">STATE:")) {
+               const char *state;
+               char *end;
+
+               /* Management state messages look like this:
+                * >STATE:1413563064,CONNECTED,SUCCESS,10.3.112.70,1.2.3.4
+                */
+               state = strchr (str, ',');
+               if (state) {
+                       state++;
+                       end = strchr (state, ',');
+                       if (end)
+                               *end = '\0';
+
+                       if (debug)
+                               g_message ("VPN state now '%s'", state);
+
+                       if (strcmp (state, "CONNECTED") == 0)
+                               priv->io_data->did_connect = TRUE;
+                       else if (strcmp (state, "RECONNECTING") == 0) {
+                               if (priv->io_data->did_connect)
+                                       nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
+                       }
+               }
+
+               g_free (auth);
+               goto out;
+       }
+
        auth = get_detail (str, ">PASSWORD:Need '");
        if (auth) {
                if (priv->io_data->pending_auth)
@@ -626,12 +656,19 @@ nm_openvpn_connect_timer_cb (gpointer data)
                nm_vpn_plugin_failure (NM_VPN_PLUGIN (plugin), NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
                nm_vpn_plugin_set_state (NM_VPN_PLUGIN (plugin), NM_VPN_SERVICE_STATE_STOPPED);
        } else {
+#define STATE_ON "state on\n"
+
                io_data->socket_channel = g_io_channel_unix_new (fd);
                g_io_channel_set_encoding (io_data->socket_channel, NULL, NULL);
                io_data->socket_channel_eventid = g_io_add_watch (io_data->socket_channel,
                                                                  G_IO_IN,
                                                                  nm_openvpn_socket_data_cb,
                                                                  plugin);
+
+               /* Turn on state buffer logging */
+               /* Will always write everything in blocking channels (on success) */
+               g_io_channel_write_chars (io_data->socket_channel, STATE_ON, strlen (STATE_ON), NULL, NULL);
+               g_io_channel_flush (io_data->socket_channel, NULL);
        }
 
 out:
@@ -1195,6 +1232,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        add_openvpn_arg (args, "root");
        add_openvpn_arg (args, "--management-client-group");
        add_openvpn_arg (args, "root");
+       add_openvpn_arg (args, "--ping-timer-rem");
 
        /* Query on the management socket for user/pass */
        add_openvpn_arg (args, "--management-query-passwords");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]