Browse code

Fix build-up of duplicate IPv6 routes on reconnect.

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>

Gert Doering authored on 2011/12/31 05:08:49
Showing 4 changed files
... ...
@@ -2778,6 +2778,11 @@ pre_pull_save (struct options *o)
2778 2778
 	  o->pre_pull->routes = clone_route_option_list(o->routes, &o->gc);
2779 2779
 	  o->pre_pull->routes_defined = true;
2780 2780
 	}
2781
+      if (o->routes_ipv6)
2782
+	{
2783
+	  o->pre_pull->routes_ipv6 = clone_route_ipv6_option_list(o->routes_ipv6, &o->gc);
2784
+	  o->pre_pull->routes_ipv6_defined = true;
2785
+	}
2781 2786
 #ifdef ENABLE_CLIENT_NAT
2782 2787
       if (o->client_nat)
2783 2788
 	{
... ...
@@ -2806,6 +2811,14 @@ pre_pull_restore (struct options *o)
2806 2806
       else
2807 2807
 	o->routes = NULL;
2808 2808
 
2809
+      if (pp->routes_ipv6_defined)
2810
+	{
2811
+	  rol6_check_alloc (o);
2812
+	  copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6);
2813
+	}
2814
+      else
2815
+	o->routes_ipv6 = NULL;
2816
+
2809 2817
 #ifdef ENABLE_CLIENT_NAT
2810 2818
       if (pp->client_nat_defined)
2811 2819
 	{
... ...
@@ -68,6 +68,9 @@ struct options_pre_pull
68 68
   bool routes_defined;
69 69
   struct route_option_list *routes;
70 70
 
71
+  bool routes_ipv6_defined;
72
+  struct route_ipv6_option_list *routes_ipv6;
73
+
71 74
 #ifdef ENABLE_CLIENT_NAT
72 75
   bool client_nat_defined;
73 76
   struct client_nat_option_list *client_nat;
... ...
@@ -108,6 +108,15 @@ clone_route_option_list (const struct route_option_list *src, struct gc_arena *a
108 108
   return ret;
109 109
 }
110 110
 
111
+struct route_ipv6_option_list *
112
+clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a)
113
+{
114
+  const size_t rl_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
115
+  struct route_ipv6_option_list *ret = gc_malloc (rl_size, false, a);
116
+  memcpy (ret, src, rl_size);
117
+  return ret;
118
+}
119
+
111 120
 void
112 121
 copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src)
113 122
 {
... ...
@@ -117,6 +126,16 @@ copy_route_option_list (struct route_option_list *dest, const struct route_optio
117 117
   memcpy (dest, src, src_size);
118 118
 }
119 119
 
120
+void
121
+copy_route_ipv6_option_list (struct route_ipv6_option_list *dest,
122
+			     const struct route_ipv6_option_list *src)
123
+{
124
+  const size_t src_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
125
+  if (src->n > dest->capacity)
126
+    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);
127
+  memcpy (dest, src, src_size);
128
+}
129
+
120 130
 struct route_list *
121 131
 new_route_list (const int max_routes, struct gc_arena *a)
122 132
 {
... ...
@@ -211,7 +211,10 @@ struct route_option_list *new_route_option_list (const int max_routes, struct gc
211 211
 struct route_ipv6_option_list *new_route_ipv6_option_list (const int max_routes, struct gc_arena *a);
212 212
 
213 213
 struct route_option_list *clone_route_option_list (const struct route_option_list *src, struct gc_arena *a);
214
+struct route_ipv6_option_list *clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a);
214 215
 void copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src);
216
+void copy_route_ipv6_option_list (struct route_ipv6_option_list *dest,
217
+				  const struct route_ipv6_option_list *src);
215 218
 
216 219
 struct route_list *new_route_list (const int max_routes, struct gc_arena *a);
217 220
 struct route_ipv6_list *new_route_ipv6_list (const int max_routes, struct gc_arena *a);