]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Allow routes to be set before opening tun, similar to ifconfig before opening tun
authorArne Schwabe <arne@rfc2549.org>
Sun, 28 Apr 2013 14:32:39 +0000 (16:32 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 1 May 2013 09:42:56 +0000 (11:42 +0200)
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1367159559-22947-1-git-send-email-arne@rfc2549.org>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7564

Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/init.c
src/openvpn/tun.h

index 979ba231e09fb609df8062b5fc368d268a314489..e7c16e0b2a3ba3562a591119ea33e1373e7953cb 100644 (file)
@@ -1429,6 +1429,13 @@ do_open_tun (struct context *c)
          do_ifconfig (c->c1.tuntap, guess, TUN_MTU_SIZE (&c->c2.frame), c->c2.es);
        }
 
+      /* possibly add routes */
+      if (route_order() == ROUTE_BEFORE_TUN) {
+        /* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */
+        do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list,
+                  c->c1.tuntap, c->plugins, c->c2.es);
+      }
+
       /* open the tun device */
       open_tun (c->options.dev, c->options.dev_type, c->options.dev_node,
                c->c1.tuntap);
@@ -1460,7 +1467,7 @@ do_open_tun (struct context *c)
                   c->c2.es);
 
       /* possibly add routes */
-      if (!c->options.route_delay_defined)
+      if ((route_order() == ROUTE_AFTER_TUN) && (!c->options.route_delay_defined))
        do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list,
                  c->c1.tuntap, c->plugins, c->c2.es);
 
@@ -1668,7 +1675,7 @@ do_up (struct context *c, bool pulled_options, unsigned int option_types_found)
 #endif
 
          /* if --route-delay was specified, start timer */
-         if (c->options.route_delay_defined)
+         if ((route_order() == ROUTE_AFTER_TUN) && c->options.route_delay_defined)
            {
              event_timeout_init (&c->c2.route_wakeup, c->options.route_delay, now);
              event_timeout_init (&c->c2.route_wakeup_expire, c->options.route_delay + c->options.route_delay_window, now);
index c3fc62e1a79312dfeae9a365b523466b60fe09e6..63e4b5c833c66417e26936255453f13e2afe89db 100644 (file)
@@ -297,6 +297,17 @@ ifconfig_order(void)
 #endif
 }
 
+#define ROUTE_BEFORE_TUN 0
+#define ROUTE_AFTER_TUN 1
+#define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN
+
+static inline int
+route_order(void)
+{
+    return ROUTE_ORDER_DEFAULT;
+}
+
+
 #ifdef WIN32
 
 #define TUN_PASS_BUFFER