Default route metric
PATCH 1/1 Default route metric
Hi
Using route metrics is a great way to get around default route issues whilst preserving the original routes. Attached are patches to 2.0 and 2.1_beta12 that allow a default metric to be applied to all routes.
IMO, this is a better option than redirecting the local route.
Thanks
Signature · 2 lines
Roy Marples <[email protected]...> Gentoo Linux Developer
init.c +4 -0
@@ -552,15 +552,19 @@ {const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type); +int metric =0 ;if (dev ==DEV_TYPE_TUN ) gw = options->ifconfig_remote_netmask;if (options->route_default_gateway) gw = options->route_default_gateway; +if (options->route_default_metric) + metric = options->route_default_metric;if (!init_route_list (route_list, options->routes, gw, + metric,link_socket_current_remote (link_socket_info), es)) {
openvpn.8 +12 -0
@@ -223,6 +223,7 @@ [\ \fB\-\-route\-delay\fR\ \fI[n]\ [w]\fR\ ] [\ \fB\-\-route\-gateway\fR\ \fIgw\fR\ ] [\ \fB\-\-route\-method\fR\ \fIm\fR\ ] +[\ \fB\-\-route\-metric\fR\ \fIm\fR\ ] [\ \fB\-\-route\-noexec\fR\ ] [\ \fB\-\-route\-up\fR\ \fIcmd\fR\ ] [\ \fB\-\-route\fR\ \fInetwork\ [netmask]\ [gateway]\ [metric]\fR\ ]
@@ -918,6 +919,11 @@ .B --dev tun is specified. +.B metric +default -- taken from +.B --route-metric +otherwise 0. + The default can be specified by leaving an option blank or setting it to "default".
@@ -954,6 +960,12 @@ .B gw for use with .B --route. +.TP +.B --route-metric m +Specify a default metric +.B m +for use with +.B --route. .\"********************************************************* .TP .B --route-delay [n] [w]
options.c +8 -0
@@ -147,6 +147,7 @@" gateway default: taken from --route-gateway or --ifconfig\n" " Specify default by leaving blank or setting to \"nil\".\n" "--route-gateway gw : 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" " adding routes (may be 0). If not specified, routes will\n" " be added immediately after tun/tap open. On Windows, wait\n"
@@ -1062,6 +1063,7 @@SHOW_STR (route_script);SHOW_STR (route_default_gateway); +SHOW_INT (route_default_metric);SHOW_BOOL (route_noexec);SHOW_INT (route_delay);SHOW_INT (route_delay_window);
@@ -3505,6 +3507,12 @@VERIFY_PERMISSION (OPT_P_ROUTE ); options->route_default_gateway = p[1 ]; } +else if (streq (p[0 ],"route-metric" ) && p[1 ]) + { + ++i; +VERIFY_PERMISSION (OPT_P_ROUTE ); + options->route_default_metric =positive_atoi (p[1 ]); + }else if (streq (p[0 ],"route-delay" )) {VERIFY_PERMISSION (OPT_P_ROUTE );
options.h +1 -0
@@ -234,6 +234,7 @@/* route management */ const char *route_script;const char *route_default_gateway; +int route_default_metric;bool route_noexec;int route_delay;int route_delay_window;
route.c +10 -3
@@ -238,10 +238,10 @@ } r->metric_defined = true; } -else +else if (spec->default_metric_defined) { - r->metric =0 ; - r->metric_defined = false; + r->metric = spec->default_metric; + r->metric_defined = true; } r->defined = true;
@@ -284,6 +284,7 @@ init_route_list (struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, + int default_metric, in_addr_t remote_host, struct env_set *es) {
@@ -298,6 +299,12 @@ rl->spec.remote_host_defined = true; } +if (default_metric) + { + rl->spec.default_metric = default_metric; + rl->spec.default_metric_defined = true; + } + rl->spec.net_gateway_defined =get_default_gateway (&rl->spec.net_gateway);if (rl->spec.net_gateway_defined) {
route.h +3 -0
@@ -56,6 +56,8 @@bool net_gateway_defined;in_addr_t remote_host;bool remote_host_defined; +int default_metric; +bool default_metric_defined; };struct route_option {
@@ -119,6 +121,7 @@bool init_route_list (struct route_list *rl,const struct route_option_list *opt,const char *remote_endpoint, +int default_metric,in_addr_t remote_host,struct env_set *es);
init.c +4 -0
@@ -629,15 +629,19 @@ {const char *gw =NULL ;int dev =dev_type_enum (options->dev, options->dev_type); +int metric =0 ;if (dev ==DEV_TYPE_TUN && (options->topology ==TOP_NET30 || options->topology ==TOP_P2P )) gw = options->ifconfig_remote_netmask;if (options->route_default_gateway) gw = options->route_default_gateway; +if (options->route_default_metric) + metric = options->route_default_metric;if (!init_route_list (route_list, options->routes, gw, + metric,link_socket_current_remote (link_socket_info), es)) {
openvpn.8 +12 -0
@@ -240,6 +240,7 @@ [\ \fB\-\-route\-delay\fR\ \fI[n]\ [w]\fR\ ] [\ \fB\-\-route\-gateway\fR\ \fIgw\fR\ ] [\ \fB\-\-route\-method\fR\ \fIm\fR\ ] +[\ \fB\-\-route\-metric\fR\ \fIm\fR\ ] [\ \fB\-\-route\-noexec\fR\ ] [\ \fB\-\-route\-nopull\fR\ ] [\ \fB\-\-route\-up\fR\ \fIcmd\fR\ ]
@@ -1037,6 +1038,11 @@ .B --dev tun is specified. +.B metric +default -- taken from +.B --route-metric +otherwise 0. + The default can be specified by leaving an option blank or setting it to "default".
@@ -1073,6 +1079,12 @@ .B gw for use with .B --route. +.TP +.B --route-metric m +Specify a default metric +.B m +for use with +.B --route. .\"********************************************************* .TP .B --route-delay [n] [w]
Only in openvpn-2.1_beta12: openvpn.8.orig
options.c +7 -0
@@ -166,6 +166,7 @@" gateway default: taken from --route-gateway or --ifconfig\n" " Specify default by leaving blank or setting to \"nil\".\n" "--route-gateway gw : 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" " adding routes (may be 0). If not specified, routes will\n" " be added immediately after tun/tap open. On Windows, wait\n"
@@ -1175,6 +1176,7 @@SHOW_STR (route_script);SHOW_STR (route_default_gateway); +SHOW_INT (route_default_metric);SHOW_BOOL (route_noexec);SHOW_INT (route_delay);SHOW_INT (route_delay_window);
@@ -3938,6 +3940,11 @@VERIFY_PERMISSION (OPT_P_ROUTE_EXTRAS ); options->route_default_gateway = p[1 ]; } +else if (streq (p[0 ],"route-metric" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_ROUTE ); + options->route_default_metric =positive_atoi (p[1 ]); + }else if (streq (p[0 ],"route-delay" )) {VERIFY_PERMISSION (OPT_P_ROUTE_EXTRAS );
options.h +1 -0
@@ -243,6 +243,7 @@/* route management */ const char *route_script;const char *route_default_gateway; +int route_default_metric;bool route_noexec;int route_delay;int route_delay_window;
route.c +10 -3
@@ -276,10 +276,10 @@ } r->metric_defined = true; } -else +else if (spec->default_metric_defined) { - r->metric =0 ; - r->metric_defined = false; + r->metric = spec->default_metric; + r->metric_defined = true; } r->defined = true;
@@ -322,6 +322,7 @@ init_route_list (struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, + int default_metric, in_addr_t remote_host, struct env_set *es) {
@@ -338,6 +339,12 @@ rl->spec.remote_host_defined = true; } +if (default_metric) + { + rl->spec.default_metric = default_metric; + rl->spec.default_metric_defined = true; + } + rl->spec.net_gateway_defined =get_default_gateway (&rl->spec.net_gateway);if (rl->spec.net_gateway_defined) {
route.h +3 -0
@@ -65,6 +65,8 @@in_addr_t remote_host;bool remote_host_defined;struct route_bypass bypass; +int default_metric; +bool default_metric_defined; };struct route_option {
@@ -132,6 +134,7 @@bool init_route_list (struct route_list *rl,const struct route_option_list *opt,const char *remote_endpoint, +int default_metric,in_addr_t remote_host,struct env_set *es);
Quoted 6 lines · Roy Marples
Hi
Using route metrics is a great way to get around default route issues whilst preserving the original routes. Attached are patches to 2.0 and 2.1_beta12 that allow a default metric to be applied to all routes.
IMO, this is a better option than redirecting the local route.
Roy,
Thanks for the patches -- I will be merging this one and the link layer patch in 2.1.
The route interface association patch is good, but I think it needs to be off unless explicitly enabled (see previous email).
James