]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Provide 'dev_type' environment variable to plug-ins and script hooks
authorDavid Sommerseth <dazo@users.sourceforge.net>
Mon, 29 Nov 2010 22:57:44 +0000 (23:57 +0100)
committerDavid Sommerseth <davids@redhat.com>
Fri, 25 Mar 2011 08:38:48 +0000 (09:38 +0100)
Normally OpenVPN is configured with --dev {tun,tap}, but it is also possible
to use --dev myvpn instead.  In these situations, OpenVPN will request
--dev-type as well to be able to set up a tun or tap device properly.

The 'dev' environment variable will contain the value provided by --dev.  In
those cases where the plug-in/script need to behave differently when using a tun
device versus using a tap device, there are no possibilities for it to know what
kind of device --dev myvpn would be.

This patch adds a 'dev_type' environment variable which contains a string of the
device type, either automatically discovered based on the --dev name, or set using
the --dev-type option.

Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Acked-by: James Yonan <james@openvpn.net>
init.c
misc.c
misc.h

diff --git a/init.c b/init.c
index a7c4b2be69690ca6731de88f3e51c21a92a0d627..61e04fa79493cab7167c932fa24133d86b195ce1 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1303,6 +1303,7 @@ do_open_tun (struct context *c)
                   c->plugins,
                   OPENVPN_PLUGIN_UP,
                   c->c1.tuntap->actual_name,
+                  dev_type_string (c->options.dev, c->options.dev_type),
                   TUN_MTU_SIZE (&c->c2.frame),
                   EXPANDED_SIZE (&c->c2.frame),
                   print_in_addr_t (c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
@@ -1338,6 +1339,7 @@ do_open_tun (struct context *c)
                     c->plugins,
                     OPENVPN_PLUGIN_UP,
                     c->c1.tuntap->actual_name,
+                    dev_type_string (c->options.dev, c->options.dev_type),
                     TUN_MTU_SIZE (&c->c2.frame),
                     EXPANDED_SIZE (&c->c2.frame),
                     print_in_addr_t (c->c1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
@@ -1401,6 +1403,7 @@ do_close_tun (struct context *c, bool force)
                       c->plugins,
                       OPENVPN_PLUGIN_DOWN,
                       tuntap_actual,
+                      NULL,
                       TUN_MTU_SIZE (&c->c2.frame),
                       EXPANDED_SIZE (&c->c2.frame),
                       print_in_addr_t (local, IA_EMPTY_IF_UNDEF, &gc),
@@ -1423,6 +1426,7 @@ do_close_tun (struct context *c, bool force)
                         c->plugins,
                         OPENVPN_PLUGIN_DOWN,
                         tuntap_actual,
+                        NULL,
                         TUN_MTU_SIZE (&c->c2.frame),
                         EXPANDED_SIZE (&c->c2.frame),
                         print_in_addr_t (local, IA_EMPTY_IF_UNDEF, &gc),
diff --git a/misc.c b/misc.c
index 9e70744c1c19e67d7385331abd43c8b2c8a8c4ab..dbf8807d14b553d56bea2e78a937559ad488b2fe 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -174,6 +174,7 @@ run_up_down (const char *command,
             const struct plugin_list *plugins,
             int plugin_type,
             const char *arg,
+            const char *dev_type,
             int tun_mtu,
             int link_mtu,
             const char *ifconfig_local,
@@ -191,6 +192,8 @@ run_up_down (const char *command,
   setenv_int (es, "tun_mtu", tun_mtu);
   setenv_int (es, "link_mtu", link_mtu);
   setenv_str (es, "dev", arg);
+  if (dev_type)
+    setenv_str (es, "dev_type", dev_type);
 
   if (!ifconfig_local)
     ifconfig_local = "";
diff --git a/misc.h b/misc.h
index 3f22ca0b1957d065c5229447b8d7582f8f2eb343..dbd206a024aae356122f0ee5d3f08b2436b61dc9 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -93,6 +93,7 @@ void run_up_down (const char *command,
                  const struct plugin_list *plugins,
                  int plugin_type,
                  const char *arg,
+                 const char *dev_type,
                  int tun_mtu,
                  int link_mtu,
                  const char *ifconfig_local,