grow route lists dynamically
PATCH 1/1 grow route lists dynamically
This removes the need for the --max-routes option. Instead of allocating a fixed size array for the route(-option)s they are managed in linked lists instead.
--- src/openvpn/init.c | 4 +- src/openvpn/options.c | 33 ++----- src/openvpn/options.h | 3 +- src/openvpn/push.c | 2 +- src/openvpn/route.c | 227 ++++++++++++++++++++----------------------------- src/openvpn/route.h | 38 ++++----- 6 files changed, 123 insertions(+), 184 deletions(-)
src/openvpn/init.c +2 -2
@@ -1167,9 +1167,9 @@ static void do_alloc_route_list (struct context *c) {if (!c->c1.route_list) - c->c1.route_list =new_route_list (c->options.max_routes, &c->gc); + ALLOC_OBJ_CLEAR_GC (c->c1.route_list, struct route_list, &c->gc);if (c->options.routes_ipv6 && !c->c1.route_ipv6_list) - c->c1.route_ipv6_list =new_route_ipv6_list (c->options.max_routes, &c->gc); + ALLOC_OBJ_CLEAR_GC (c->c1.route_ipv6_list, struct route_ipv6_list, &c->gc); }
src/openvpn/options.c +8 -25
@@ -218,8 +218,6 @@ static const char usage_message[] =" Add IPv6 route to routing table after connection\n" " is established. Multiple routes can be specified.\n" " gateway default: taken from 'remote' in --ifconfig-ipv6\n" -"--max-routes n : Specify the maximum number of routes that may be defined\n" -" or pulled from a server.\n" "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n" "--route-metric m : Specify a default metric for use with --route.\n" "--route-delay n [w] : Delay n seconds after connection initiation before\n"
@@ -796,7 +794,6 @@ init_options (struct options *o, const bool init_gc) o->ce.mtu_discover_type =-1 ; o->ce.mssfix =MSSFIX_DEFAULT ; o->route_delay_window =30 ; - o->max_routes =MAX_ROUTES_DEFAULT ; o->resolve_retry_seconds =RESOLV_RETRY_INFINITE ; o->proto_force =-1 ;#ifdef ENABLE_OCC
@@ -1340,14 +1337,14 @@ void rol_check_alloc (struct options *options) {if (!options->routes) - options->routes =new_route_option_list (options->max_routes, &options->gc); + options->routes =new_route_option_list (&options->gc); }void rol6_check_alloc (struct options *options) {if (!options->routes_ipv6) - options->routes_ipv6 =new_route_ipv6_option_list (options->max_routes, &options->gc); + options->routes_ipv6 =new_route_ipv6_option_list (&options->gc); }#ifdef ENABLE_CLIENT_NAT
@@ -1550,7 +1547,6 @@ show_settings (const struct options *o)SHOW_BOOL (route_delay_defined);SHOW_BOOL (route_nopull);SHOW_BOOL (route_gateway_via_dhcp); -SHOW_INT (max_routes);SHOW_BOOL (allow_pull_fqdn);if (o->routes)print_route_options (o->routes,D_SHOW_PARMS );
@@ -2829,7 +2825,7 @@ pre_pull_save (struct options *o) }void -pre_pull_restore (struct options *o) +pre_pull_restore (struct options *o,struct gc_arena *gc) {const struct options_pre_pull *pp = o->pre_pull;if (pp)
@@ -2841,7 +2837,7 @@ pre_pull_restore (struct options *o)if (pp->routes_defined) {rol_check_alloc (o); -copy_route_option_list (o->routes, pp->routes); +copy_route_option_list (o->routes, pp->routes, gc); }else o->routes =NULL ;
@@ -2849,7 +2845,7 @@ pre_pull_restore (struct options *o)if (pp->routes_ipv6_defined) {rol6_check_alloc (o); -copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6); +copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6, gc); }else o->routes_ipv6 =NULL ;
@@ -5227,23 +5223,10 @@ add_option (struct options *options, }add_route_ipv6_to_option_list (options->routes_ipv6, p[1 ], p[2 ], p[3 ]); } -else if (streq (p[0 ],"max-routes" ) && p[1 ]) +else if (streq (p[0 ],"max-routes" )) { -int max_routes; - -VERIFY_PERMISSION (OPT_P_GENERAL ); - max_routes =atoi (p[1 ]); -if (max_routes <0 || max_routes >100000000 ) - { -msg (msglevel,"--max-routes parameter is out of range" ); - goto err; - } -if (options->routes || options->routes_ipv6) - { -msg (msglevel,"--max-routes must to be specifed before any route/route-ipv6/redirect-gateway option" ); - goto err; - } - options->max_routes = max_routes; +msg (msglevel,"--max-routes option ignored. The number of routes is unlimited as of version 2.4. " +"This option will be removed in a future version, please remove it from your configuration." ); }else if (streq (p[0 ],"route-gateway" ) && p[1 ]) {
src/openvpn/options.h +1 -2
@@ -343,7 +343,6 @@ struct optionsint route_delay;int route_delay_window;bool route_delay_defined; -int max_routes;struct route_option_list *routes;struct route_ipv6_option_list *routes_ipv6;/* IPv6 */ bool route_nopull;
@@ -715,7 +714,7 @@ void options_warning (char *actual, const char *expected);void options_postprocess (struct options *options);void pre_pull_save (struct options *o); -void pre_pull_restore (struct options *o); +void pre_pull_restore (struct options *o,struct gc_arena *gc); bool apply_push_options (struct options *options, struct buffer *buf,
src/openvpn/push.c +1 -1
@@ -456,7 +456,7 @@ process_incoming_push_msg (struct context *c, }if (!c->c2.did_pre_pull_restore) { -pre_pull_restore (&c->options); +pre_pull_restore (&c->options, &c->c2.gc); c->c2.did_pre_pull_restore = true; } if (apply_push_options (&c->options,
src/openvpn/route.c +94 -133
415 lines not on this page · raw message
src/openvpn/route.h +17 -21
@@ -33,8 +33,6 @@#include "tun.h" #include "misc.h" -#define MAX_ROUTES_DEFAULT 100 -#ifdef WIN32 /* * Windows route methods
@@ -74,6 +72,7 @@ struct route_special_addr };struct route_option { +struct route_option *next;const char *network;const char *netmask;const char *gateway;
@@ -92,12 +91,12 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ -int capacity; -int n; -struct route_option routes[EMPTY_ARRAY_SIZE ]; +struct route_option *routes; +struct gc_arena *gc; };struct route_ipv6_option { +struct route_ipv6_option *next;const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */
@@ -105,15 +104,15 @@ struct route_ipv6_option {struct route_ipv6_option_list {unsigned int flags; -int capacity; -int n; -struct route_ipv6_option routes_ipv6[EMPTY_ARRAY_SIZE ]; +struct route_ipv6_option *routes_ipv6; +struct gc_arena *gc; };struct route_ipv4 {# define RT_DEFINED (1<<0)# define RT_ADDED (1<<1)# define RT_METRIC_DEFINED (1<<2) +struct route *next;unsigned int flags;const struct route_option *option;in_addr_t network;
@@ -123,6 +122,7 @@ struct route_ipv4 { };struct route_ipv6 { +struct route_ipv6 *next;bool defined;struct in6_addr network;unsigned int netbits;
@@ -140,9 +140,8 @@ struct route_ipv6_list {bool remote_endpoint_defined;bool did_redirect_default_gateway;/* TODO (?) */ bool did_local;/* TODO (?) */ -int capacity; -int n; -struct route_ipv6 routes_ipv6[EMPTY_ARRAY_SIZE ]; +struct route_ipv6 *routes_ipv6; +struct gc_arena gc; };
@@ -188,9 +187,8 @@ struct route_list {struct route_special_addr spec;struct route_gateway_info rgi;unsigned int flags;/* RG_x flags */ -int capacity; -int n; -struct route_ipv4 routes[EMPTY_ARRAY_SIZE ]; +struct route_ipv4 *routes; +struct gc_arena gc; };#if P2MP
@@ -208,17 +206,15 @@ struct iroute_ipv6 { };#endif -struct route_option_list *new_route_option_list (const int max_routes,struct gc_arena *a); -struct route_ipv6_option_list *new_route_ipv6_option_list (const int max_routes,struct gc_arena *a); +struct route_option_list *new_route_option_list (struct gc_arena *a); +struct route_ipv6_option_list *new_route_ipv6_option_list (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_option_list (struct route_option_list *dest,const struct route_option_list *src,struct gc_arena *a);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); +const struct route_ipv6_option_list *src, +struct gc_arena *a);void add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es);void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es);
Signature · 1 line
1.7.9.5
Am 29.01.14 14:03, schrieb Heiko Hund:
Quoted 5 lines
This removes the need for the --max-routes option. Instead of allocating a fixed size array for the route(-option)s they are managed in linked lists instead.
ACK but with two changes
- adding a comment to the copy method that this does a shallow copy with two lists with the same tail
- struct route* next should be struct route_ipv4 *next in the route_ipv4 struct.
Arne
Hi Arne
Quoted 6 lines · On Monday 17 February 2014 19:49:49 Arne Schwabe wrote:
ACK but with two changes
- adding a comment to the copy method that this does a shallow copy with two lists with the same tail
- struct route* next should be structroute_ipv4*next in theroute_ipv4struct.
Thanks for the review. I will post an updated patch.
Heiko
PATCH v2 1/1 grow route lists dynamically
In reply to Heiko HundThis removes the need for the --max-routes option. Instead of allocating a fixed size array for the route(-option)s they are managed in linked lists instead.
--- src/openvpn/init.c | 4 +- src/openvpn/options.c | 33 ++----- src/openvpn/options.h | 3 +- src/openvpn/push.c | 2 +- src/openvpn/route.c | 234 ++++++++++++++++++++++---------------------------- src/openvpn/route.h | 38 ++++---- 6 files changed, 130 insertions(+), 184 deletions(-)
src/openvpn/init.c +2 -2
@@ -1167,9 +1167,9 @@ static void do_alloc_route_list (struct context *c) {if (!c->c1.route_list) - c->c1.route_list =new_route_list (c->options.max_routes, &c->gc); + ALLOC_OBJ_CLEAR_GC (c->c1.route_list, struct route_list, &c->gc);if (c->options.routes_ipv6 && !c->c1.route_ipv6_list) - c->c1.route_ipv6_list =new_route_ipv6_list (c->options.max_routes, &c->gc); + ALLOC_OBJ_CLEAR_GC (c->c1.route_ipv6_list, struct route_ipv6_list, &c->gc); }
src/openvpn/options.c +8 -25
@@ -218,8 +218,6 @@ static const char usage_message[] =" Add IPv6 route to routing table after connection\n" " is established. Multiple routes can be specified.\n" " gateway default: taken from 'remote' in --ifconfig-ipv6\n" -"--max-routes n : Specify the maximum number of routes that may be defined\n" -" or pulled from a server.\n" "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n" "--route-metric m : Specify a default metric for use with --route.\n" "--route-delay n [w] : Delay n seconds after connection initiation before\n"
@@ -796,7 +794,6 @@ init_options (struct options *o, const bool init_gc) o->ce.mtu_discover_type =-1 ; o->ce.mssfix =MSSFIX_DEFAULT ; o->route_delay_window =30 ; - o->max_routes =MAX_ROUTES_DEFAULT ; o->resolve_retry_seconds =RESOLV_RETRY_INFINITE ; o->proto_force =-1 ;#ifdef ENABLE_OCC
@@ -1340,14 +1337,14 @@ void rol_check_alloc (struct options *options) {if (!options->routes) - options->routes =new_route_option_list (options->max_routes, &options->gc); + options->routes =new_route_option_list (&options->gc); }void rol6_check_alloc (struct options *options) {if (!options->routes_ipv6) - options->routes_ipv6 =new_route_ipv6_option_list (options->max_routes, &options->gc); + options->routes_ipv6 =new_route_ipv6_option_list (&options->gc); }#ifdef ENABLE_CLIENT_NAT
@@ -1550,7 +1547,6 @@ show_settings (const struct options *o)SHOW_BOOL (route_delay_defined);SHOW_BOOL (route_nopull);SHOW_BOOL (route_gateway_via_dhcp); -SHOW_INT (max_routes);SHOW_BOOL (allow_pull_fqdn);if (o->routes)print_route_options (o->routes,D_SHOW_PARMS );
@@ -2829,7 +2825,7 @@ pre_pull_save (struct options *o) }void -pre_pull_restore (struct options *o) +pre_pull_restore (struct options *o,struct gc_arena *gc) {const struct options_pre_pull *pp = o->pre_pull;if (pp)
@@ -2841,7 +2837,7 @@ pre_pull_restore (struct options *o)if (pp->routes_defined) {rol_check_alloc (o); -copy_route_option_list (o->routes, pp->routes); +copy_route_option_list (o->routes, pp->routes, gc); }else o->routes =NULL ;
@@ -2849,7 +2845,7 @@ pre_pull_restore (struct options *o)if (pp->routes_ipv6_defined) {rol6_check_alloc (o); -copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6); +copy_route_ipv6_option_list (o->routes_ipv6, pp->routes_ipv6, gc); }else o->routes_ipv6 =NULL ;
@@ -5227,23 +5223,10 @@ add_option (struct options *options, }add_route_ipv6_to_option_list (options->routes_ipv6, p[1 ], p[2 ], p[3 ]); } -else if (streq (p[0 ],"max-routes" ) && p[1 ]) +else if (streq (p[0 ],"max-routes" )) { -int max_routes; - -VERIFY_PERMISSION (OPT_P_GENERAL ); - max_routes =atoi (p[1 ]); -if (max_routes <0 || max_routes >100000000 ) - { -msg (msglevel,"--max-routes parameter is out of range" ); - goto err; - } -if (options->routes || options->routes_ipv6) - { -msg (msglevel,"--max-routes must to be specifed before any route/route-ipv6/redirect-gateway option" ); - goto err; - } - options->max_routes = max_routes; +msg (msglevel,"--max-routes option ignored. The number of routes is unlimited as of version 2.4. " +"This option will be removed in a future version, please remove it from your configuration." ); }else if (streq (p[0 ],"route-gateway" ) && p[1 ]) {
src/openvpn/options.h +1 -2
@@ -343,7 +343,6 @@ struct optionsint route_delay;int route_delay_window;bool route_delay_defined; -int max_routes;struct route_option_list *routes;struct route_ipv6_option_list *routes_ipv6;/* IPv6 */ bool route_nopull;
@@ -715,7 +714,7 @@ void options_warning (char *actual, const char *expected);void options_postprocess (struct options *options);void pre_pull_save (struct options *o); -void pre_pull_restore (struct options *o); +void pre_pull_restore (struct options *o,struct gc_arena *gc); bool apply_push_options (struct options *options, struct buffer *buf,
src/openvpn/push.c +1 -1
@@ -456,7 +456,7 @@ process_incoming_push_msg (struct context *c, }if (!c->c2.did_pre_pull_restore) { -pre_pull_restore (&c->options); +pre_pull_restore (&c->options, &c->c2.gc); c->c2.did_pre_pull_restore = true; } if (apply_push_options (&c->options,
src/openvpn/route.c +101 -133
422 lines not on this page · raw message
src/openvpn/route.h +17 -21
@@ -33,8 +33,6 @@#include "tun.h" #include "misc.h" -#define MAX_ROUTES_DEFAULT 100 -#ifdef WIN32 /* * Windows route methods
@@ -74,6 +72,7 @@ struct route_special_addr };struct route_option { +struct route_option *next;const char *network;const char *netmask;const char *gateway;
@@ -92,12 +91,12 @@ struct route_option {struct route_option_list {unsigned int flags;/* RG_x flags */ -int capacity; -int n; -struct route_option routes[EMPTY_ARRAY_SIZE ]; +struct route_option *routes; +struct gc_arena *gc; };struct route_ipv6_option { +struct route_ipv6_option *next;const char *prefix;/* e.g. "2001:db8:1::/64" */ const char *gateway;/* e.g. "2001:db8:0::2" */ const char *metric;/* e.g. "5" */
@@ -105,15 +104,15 @@ struct route_ipv6_option {struct route_ipv6_option_list {unsigned int flags; -int capacity; -int n; -struct route_ipv6_option routes_ipv6[EMPTY_ARRAY_SIZE ]; +struct route_ipv6_option *routes_ipv6; +struct gc_arena *gc; };struct route_ipv4 {# define RT_DEFINED (1<<0)# define RT_ADDED (1<<1)# define RT_METRIC_DEFINED (1<<2) +struct route_ipv4 *next;unsigned int flags;const struct route_option *option;in_addr_t network;
@@ -123,6 +122,7 @@ struct route_ipv4 { };struct route_ipv6 { +struct route_ipv6 *next;bool defined;struct in6_addr network;unsigned int netbits;
@@ -140,9 +140,8 @@ struct route_ipv6_list {bool remote_endpoint_defined;bool did_redirect_default_gateway;/* TODO (?) */ bool did_local;/* TODO (?) */ -int capacity; -int n; -struct route_ipv6 routes_ipv6[EMPTY_ARRAY_SIZE ]; +struct route_ipv6 *routes_ipv6; +struct gc_arena gc; };
@@ -188,9 +187,8 @@ struct route_list {struct route_special_addr spec;struct route_gateway_info rgi;unsigned int flags;/* RG_x flags */ -int capacity; -int n; -struct route_ipv4 routes[EMPTY_ARRAY_SIZE ]; +struct route_ipv4 *routes; +struct gc_arena gc; };#if P2MP
@@ -208,17 +206,15 @@ struct iroute_ipv6 { };#endif -struct route_option_list *new_route_option_list (const int max_routes,struct gc_arena *a); -struct route_ipv6_option_list *new_route_ipv6_option_list (const int max_routes,struct gc_arena *a); +struct route_option_list *new_route_option_list (struct gc_arena *a); +struct route_ipv6_option_list *new_route_ipv6_option_list (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_option_list (struct route_option_list *dest,const struct route_option_list *src,struct gc_arena *a);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); +const struct route_ipv6_option_list *src, +struct gc_arena *a);void add_route_ipv6 (struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es);void delete_route_ipv6 (const struct route_ipv6 *r,const struct tuntap *tt,unsigned int flags,const struct env_set *es);
Signature · 1 line
1.8.2.3
Am 18.02.14 18:59, schrieb Heiko Hund:
Quoted 4 lines
This removes the need for the --max-routes option. Instead of allocating a fixed size array for the route(-option)s they are managed in linked lists instead.
ACK.
Arne
Another ACK from me. Get rid of one option and a "historic" limitation (and actually save memory on typical setups with less than 100 routes...), plus simplify the code in a few places. *like* :-)
Patch has been applied to the master branch.
commit d0085293e709c8a722356cfa68ad74c962aef9a2 (master)
Author: Heiko Hund Date: Tue Feb 18 18:59:55 2014 +0100
grow route lists dynamically
Signed-off-by: Heiko Hund <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8295
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 1/1 fix route struct name
In reply to Heiko HundThis slipped in with commit d0085293.
--- src/openvpn/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/route.c +1 -1
@@ -2117,7 +2117,7 @@ test_routes (const struct route_list *rl, const struct tuntap *tt)if (rl) { -struct route *r; +struct route_ipv4 *r;for (r = rl->routes, len =0 ; r; r = r->next, ++len)test_route_helper (&ret, &count, &good, &ambig, adapters, r->gateway);
Signature · 1 line
1.7.9.5
[Openvpn-devel] [PATCH applied] Re: fix route struct name
ACK, thanks.
Inside #ifdef WIN32, which is why we didn't catch it on unix before (we really need a windows buildslave...).
Your patch has been applied to the master branch.
commit 60b40a58c4caaeb5c5aa8d402020414d3ba05050 (master)
Author: Heiko Hund Date: Tue Apr 1 12:06:43 2014 +0200
fix route struct name
Signed-off-by: Heiko Hund <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8421
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering