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



commit fe79e83d3125fa7fd505e0c3f853673ade867cb3
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                |   10 +++++-----
 2 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/src/nm-openvpn-service-openvpn-helper.c b/src/nm-openvpn-service-openvpn-helper.c
index 1094d80..edf44e7 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;
 
@@ -550,6 +550,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;
        }
@@ -619,8 +623,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..f2f013c 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;
+       gboolean dev_type_is_tap;
        char *stmp;
 
        /* Find openvpn */
@@ -957,10 +958,8 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        /* Device, either tun or tap */
        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");
-       else
-               add_openvpn_arg (args, "tun");
+       dev_type_is_tap = !g_strcmp0 (tmp, "yes");
+       add_openvpn_arg (args, dev_type_is_tap ? "tap" : "tun");
 
        /* Protocol, either tcp or udp */
        add_openvpn_arg (args, "--proto");
@@ -1111,7 +1110,8 @@ 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_is_tap ? "--tap" : "--tun");
        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]