Browse code

Added --route-metric option to set a default route metric for --route (Roy Marples).

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@1011 e7ae566f-a301-0410-adde-c780ea21d3b5

james authored on 2006/04/14 05:40:39
Showing 7 changed files
... ...
@@ -7,9 +7,14 @@ $Id$
7 7
 
8 8
 * Fixed Windows server bug in time backtrack handling code which
9 9
   could cause TLS negotiation failures on legitimate clients.
10
+	
10 11
 * Rewrote gettimeofday function for Windows to be
11 12
   simpler and more efficient.
13
+	
12 14
 * Merged PKCS#11 extensions to easy-rsa/2.0  (Alon Bar-Lev).
15
+
16
+* Added --route-metric option to set a default route metric
17
+  for --route (Roy Marples).
13 18
 	
14 19
 2006.04.12 -- Version 2.1-beta13
15 20
 
... ...
@@ -634,15 +634,19 @@ do_init_route_list (const struct options *options,
634 634
 {
635 635
   const char *gw = NULL;
636 636
   int dev = dev_type_enum (options->dev, options->dev_type);
637
+  int metric = 0;
637 638
 
638 639
   if (dev == DEV_TYPE_TUN && (options->topology == TOP_NET30 || options->topology == TOP_P2P))
639 640
     gw = options->ifconfig_remote_netmask;
640 641
   if (options->route_default_gateway)
641 642
     gw = options->route_default_gateway;
643
+  if (options->route_default_metric)
644
+    metric = options->route_default_metric;
642 645
 
643 646
   if (!init_route_list (route_list,
644 647
 			options->routes,
645 648
 			gw,
649
+			metric,
646 650
 			link_socket_current_remote (link_socket_info),
647 651
 			es))
648 652
     {
... ...
@@ -240,6 +240,7 @@ openvpn \- secure IP tunnel daemon.
240 240
 [\ \fB\-\-route\-delay\fR\ \fI[n]\ [w]\fR\ ]
241 241
 [\ \fB\-\-route\-gateway\fR\ \fIgw\fR\ ]
242 242
 [\ \fB\-\-route\-method\fR\ \fIm\fR\ ]
243
+[\ \fB\-\-route\-metric\fR\ \fIm\fR\ ]
243 244
 [\ \fB\-\-route\-noexec\fR\ ]
244 245
 [\ \fB\-\-route\-nopull\fR\ ]
245 246
 [\ \fB\-\-route\-up\fR\ \fIcmd\fR\ ]
... ...
@@ -1037,6 +1038,11 @@ when
1037 1037
 .B --dev tun
1038 1038
 is specified.
1039 1039
 
1040
+.B metric
1041
+default -- taken from
1042
+.B --route-metric
1043
+otherwise 0.
1044
+
1040 1045
 The default can be specified by leaving an option blank or setting
1041 1046
 it to "default".
1042 1047
 
... ...
@@ -1073,6 +1079,12 @@ Specify a default gateway
1073 1073
 .B gw
1074 1074
 for use with
1075 1075
 .B --route.
1076
+.TP
1077
+.B --route-metric m
1078
+Specify a default metric
1079
+.B m
1080
+for use with
1081
+.B --route.
1076 1082
 .\"*********************************************************
1077 1083
 .TP
1078 1084
 .B --route-delay [n] [w]
... ...
@@ -166,6 +166,7 @@ static const char usage_message[] =
166 166
   "                  gateway default: taken from --route-gateway or --ifconfig\n"
167 167
   "                  Specify default by leaving blank or setting to \"nil\".\n"
168 168
   "--route-gateway gw : Specify a default gateway for use with --route.\n"
169
+  "--route-metric m : Specify a default metric for use with --route.\n"
169 170
   "--route-delay n [w] : Delay n seconds after connection initiation before\n"
170 171
   "                  adding routes (may be 0).  If not specified, routes will\n"
171 172
   "                  be added immediately after tun/tap open.  On Windows, wait\n"
... ...
@@ -1175,6 +1176,7 @@ show_settings (const struct options *o)
1175 1175
 
1176 1176
   SHOW_STR (route_script);
1177 1177
   SHOW_STR (route_default_gateway);
1178
+  SHOW_INT (route_default_metric);
1178 1179
   SHOW_BOOL (route_noexec);
1179 1180
   SHOW_INT (route_delay);
1180 1181
   SHOW_INT (route_delay_window);
... ...
@@ -3938,6 +3940,11 @@ add_option (struct options *options,
3938 3938
       VERIFY_PERMISSION (OPT_P_ROUTE_EXTRAS);
3939 3939
       options->route_default_gateway = p[1];      
3940 3940
     }
3941
+  else if (streq (p[0], "route-metric") && p[1])
3942
+    {
3943
+      VERIFY_PERMISSION (OPT_P_ROUTE);
3944
+      options->route_default_metric = positive_atoi (p[1]);
3945
+    }
3941 3946
   else if (streq (p[0], "route-delay"))
3942 3947
     {
3943 3948
       VERIFY_PERMISSION (OPT_P_ROUTE_EXTRAS);
... ...
@@ -243,6 +243,7 @@ struct options
243 243
   /* route management */
244 244
   const char *route_script;
245 245
   const char *route_default_gateway;
246
+  int route_default_metric;
246 247
   bool route_noexec;
247 248
   int route_delay;
248 249
   int route_delay_window;
... ...
@@ -276,10 +276,10 @@ init_route (struct route *r,
276 276
 	}
277 277
       r->metric_defined = true;
278 278
     }
279
-  else
279
+  else if (spec->default_metric_defined)
280 280
     {
281
-      r->metric = 0;
282
-      r->metric_defined = false;
281
+      r->metric = spec->default_metric;
282
+      r->metric_defined = true;
283 283
     }
284 284
 
285 285
   r->defined = true;
... ...
@@ -322,6 +322,7 @@ bool
322 322
 init_route_list (struct route_list *rl,
323 323
 		 const struct route_option_list *opt,
324 324
 		 const char *remote_endpoint,
325
+		 int default_metric,
325 326
 		 in_addr_t remote_host,
326 327
 		 struct env_set *es)
327 328
 {
... ...
@@ -338,6 +339,12 @@ init_route_list (struct route_list *rl,
338 338
       rl->spec.remote_host_defined = true;
339 339
     }
340 340
 
341
+  if (default_metric)
342
+    {
343
+      rl->spec.default_metric = default_metric;
344
+      rl->spec.default_metric_defined = true;
345
+    }
346
+
341 347
   rl->spec.net_gateway_defined = get_default_gateway (&rl->spec.net_gateway);
342 348
   if (rl->spec.net_gateway_defined)
343 349
     {
... ...
@@ -65,6 +65,8 @@ struct route_special_addr
65 65
   in_addr_t remote_host;
66 66
   bool remote_host_defined;
67 67
   struct route_bypass bypass;
68
+  int default_metric;
69
+  bool default_metric_defined;
68 70
 };
69 71
 
70 72
 struct route_option {
... ...
@@ -132,6 +134,7 @@ void clear_route_list (struct route_list *rl);
132 132
 bool init_route_list (struct route_list *rl,
133 133
 		      const struct route_option_list *opt,
134 134
 		      const char *remote_endpoint,
135
+		      int default_metric,
135 136
 		      in_addr_t remote_host,
136 137
 		      struct env_set *es);
137 138