[network-manager-openvpn/th/bgo556134_up_restart: 3/4] helper: pass device type to helper script as command line argument



commit 5620cad979e7945e093ca0e9f2e49c7afe37d8b4
Author: Thomas Haller <thaller redhat com>
Date:   Tue Mar 18 15:40:41 2014 +0100

    helper: pass device type to helper script as command line argument
    
    The device name can be changed, so we should not use it do detect
    the device type. Instead pass it to the helper script as argument.
    
    Signed-off-by: Thomas Haller <thaller redhat com>

 src/nm-openvpn-service-openvpn-helper.c |   10 +++++++---
 src/nm-openvpn-service.c                |    8 +++++---
 2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/src/nm-openvpn-service-openvpn-helper.c b/src/nm-openvpn-service-openvpn-helper.c
index c3ff6b8..da0d715 100644
--- a/src/nm-openvpn-service-openvpn-helper.c
+++ b/src/nm-openvpn-service-openvpn-helper.c
@@ -535,7 +535,7 @@ main (int argc, char *argv[])
        GValue *nbns_list = NULL;
        GPtrArray *dns_domains = NULL;
        struct in_addr temp_addr;
-       gboolean tapdev = FALSE;
+       int tapdev = -1;
        char **iter;
        int shift = 0;
 
@@ -551,6 +551,10 @@ main (int argc, char *argv[])
                        }
                        if (!strcmp (argv[i], "--helper-debug"))
                                helper_debug = TRUE;
+                       else if (!strcmp (argv[i], "tun"))
+                               tapdev = 0;
+                       else if (!strcmp (argv[i], "tap"))
+                               tapdev = 1;
                        else
                                break;
                }
@@ -625,8 +629,8 @@ main (int argc, char *argv[])
        else
                helper_failed (connection, "Tunnel Device");
 
-       if (strncmp (tmp, "tap", 3) == 0)
-               tapdev = TRUE;
+       if (tapdev == -1)
+               tapdev = strncmp (tmp, "tap", 3) == 0;
 
        /* IPv4 address */
        tmp = getenv ("ifconfig_local");
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index fc3fd84..4e77243 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -866,6 +866,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        GPtrArray *args;
        GSource *openvpn_watch;
        GPid pid;
+       const char *dev_type;
        char *stmp;
 
        /* Find openvpn */
@@ -958,9 +959,10 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        add_openvpn_arg (args, "--dev");
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV);
        if (tmp && !strcmp (tmp, "yes"))
-               add_openvpn_arg (args, "tap");
+               dev_type = "tap";
        else
-               add_openvpn_arg (args, "tun");
+               dev_type = "tun";
+       add_openvpn_arg (args, dev_type);
 
        /* Protocol, either tcp or udp */
        add_openvpn_arg (args, "--proto");
@@ -1111,7 +1113,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 
        /* Up script, called when connection has been established or has been restarted */
        add_openvpn_arg (args, "--up");
-       stmp = g_strdup_printf ("%s%s --", NM_OPENVPN_HELPER_PATH, debug ? " --helper-debug" : "");
+       stmp = g_strdup_printf ("%s%s %s --", NM_OPENVPN_HELPER_PATH, debug ? " --helper-debug" : "", 
dev_type);
        add_openvpn_arg (args, stmp);
        g_free (stmp);
        add_openvpn_arg (args, "--up-restart");


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