]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix build-up of duplicate IPv6 routes on reconnect.
authorGert Doering <gert@mobile.greenie.muc.de>
Fri, 30 Dec 2011 20:08:49 +0000 (21:08 +0100)
committerDavid Sommerseth <davids@redhat.com>
Wed, 4 Jan 2012 10:46:49 +0000 (11:46 +0100)
options.c: extend pre_pull_save() and pre_pull_restore() to
   save/restore options->routes_ipv6 as well
options.h: add routes_ipv6 to "struct options_pre_pull"
route.h, route.c: add clone_route_ipv6_option_list() and
   copy_route_ipv6_option_list() helper functions

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
options.c
options.h
route.c
route.h

index 736495e48102eb36305125a52240ac890cfe1815..a186276b3d208141fb6a320ee713a2192c7f2c0c 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2778,6 +2778,11 @@ pre_pull_save (struct options *o)
          o->pre_pull->routes = clone_route_option_list(o->routes, &o->gc);
          o->pre_pull->routes_defined = true;
        }
+      if (o->routes_ipv6)
+       {
+         o->pre_pull->routes_ipv6 = clone_route_ipv6_option_list(o->routes_ipv6, &o->gc);
+         o->pre_pull->routes_ipv6_defined = true;
+       }
 #ifdef ENABLE_CLIENT_NAT
       if (o->client_nat)
        {
@@ -2806,6 +2811,14 @@ pre_pull_restore (struct options *o)
       else
        o->routes = NULL;
 
+      if (pp->routes_ipv6_defined)
+       {
+         rol6_check_alloc (o);
+         copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6);
+       }
+      else
+       o->routes_ipv6 = NULL;
+
 #ifdef ENABLE_CLIENT_NAT
       if (pp->client_nat_defined)
        {
index 06c4dcbd41699112405dae222797d954b782088a..03fd197064405719dd5ca145591e260d925849b6 100644 (file)
--- a/options.h
+++ b/options.h
@@ -68,6 +68,9 @@ struct options_pre_pull
   bool routes_defined;
   struct route_option_list *routes;
 
+  bool routes_ipv6_defined;
+  struct route_ipv6_option_list *routes_ipv6;
+
 #ifdef ENABLE_CLIENT_NAT
   bool client_nat_defined;
   struct client_nat_option_list *client_nat;
diff --git a/route.c b/route.c
index be23a899fb9f98491637201b9a3f1b4c330d4b9d..1f0b096775f4980e99fa2a76fc4e7b312b621d1a 100644 (file)
--- a/route.c
+++ b/route.c
@@ -108,6 +108,15 @@ clone_route_option_list (const struct route_option_list *src, struct gc_arena *a
   return ret;
 }
 
+struct route_ipv6_option_list *
+clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a)
+{
+  const size_t rl_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
+  struct route_ipv6_option_list *ret = gc_malloc (rl_size, false, a);
+  memcpy (ret, src, rl_size);
+  return ret;
+}
+
 void
 copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src)
 {
@@ -117,6 +126,16 @@ copy_route_option_list (struct route_option_list *dest, const struct route_optio
   memcpy (dest, src, src_size);
 }
 
+void
+copy_route_ipv6_option_list (struct route_ipv6_option_list *dest,
+                            const struct route_ipv6_option_list *src)
+{
+  const size_t src_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
+  if (src->n > dest->capacity)
+    msg (M_FATAL, PACKAGE_NAME " ROUTE: (copy) number of route options in src (%d) is greater than route list capacity in dest (%d)", src->n, dest->capacity);
+  memcpy (dest, src, src_size);
+}
+
 struct route_list *
 new_route_list (const int max_routes, struct gc_arena *a)
 {
diff --git a/route.h b/route.h
index 995347889a087f6eb1128a74022c76c2805672ee..58c7ef437ba14d06b0b98acfc0924cf5daf93260 100644 (file)
--- a/route.h
+++ b/route.h
@@ -211,7 +211,10 @@ struct route_option_list *new_route_option_list (const int max_routes, struct gc
 struct route_ipv6_option_list *new_route_ipv6_option_list (const int max_routes, struct gc_arena *a);
 
 struct route_option_list *clone_route_option_list (const struct route_option_list *src, struct gc_arena *a);
+struct route_ipv6_option_list *clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a);
 void copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src);
+void copy_route_ipv6_option_list (struct route_ipv6_option_list *dest,
+                                 const struct route_ipv6_option_list *src);
 
 struct route_list *new_route_list (const int max_routes, struct gc_arena *a);
 struct route_ipv6_list *new_route_ipv6_list (const int max_routes, struct gc_arena *a);