Browse code

Modified get_default_gateway code for Windows to return the route with the smallest metric if multiple 0.0.0.0/0.0.0.0 entries are present.

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

james authored on 2005/10/20 16:42:01
Showing 1 changed files
... ...
@@ -1102,9 +1102,11 @@ test_routes (const struct route_list *rl, const struct tuntap *tt)
1102 1102
 static const MIB_IPFORWARDROW *
1103 1103
 get_default_gateway_row (const MIB_IPFORWARDTABLE *routes)
1104 1104
 {
1105
-  DWORD lowest_index = ~0;
1105
+  struct gc_arena gc = gc_new ();
1106
+  DWORD lowest_metric = ~0;
1106 1107
   const MIB_IPFORWARDROW *ret = NULL;
1107 1108
   int i;
1109
+  int best = -1;
1108 1110
 
1109 1111
   if (routes)
1110 1112
     {
... ...
@@ -1114,22 +1116,27 @@ get_default_gateway_row (const MIB_IPFORWARDTABLE *routes)
1114 1114
 	  const in_addr_t net = ntohl (row->dwForwardDest);
1115 1115
 	  const in_addr_t mask = ntohl (row->dwForwardMask);
1116 1116
 	  const DWORD index = row->dwForwardIfIndex;
1117
+	  const DWORD metric = row->dwForwardMetric1;
1117 1118
 
1118
-#if 0
1119
-	  msg (M_INFO, "route[%d] %s %s %s",
1120
-	       i,
1121
-	       print_in_addr_t ((in_addr_t) net, 0, &gc),
1122
-	       print_in_addr_t ((in_addr_t) mask, 0, &gc),
1123
-	       print_in_addr_t ((in_addr_t) gw, 0, &gc));
1124
-#endif
1119
+	  dmsg (D_ROUTE_DEBUG, "GDGR: route[%d] %s/%s i=%d m=%d",
1120
+		i,
1121
+		print_in_addr_t ((in_addr_t) net, 0, &gc),
1122
+		print_in_addr_t ((in_addr_t) mask, 0, &gc),
1123
+		(int)index,
1124
+		(int)metric);
1125 1125
 
1126
-	  if (!net && !mask && index < lowest_index)
1126
+	  if (!net && !mask && metric < lowest_metric)
1127 1127
 	    {
1128 1128
 	      ret = row;
1129
-	      lowest_index = index;
1129
+	      lowest_metric = metric;
1130
+	      best = i;
1130 1131
 	    }
1131 1132
 	}
1132 1133
     }
1134
+
1135
+  dmsg (D_ROUTE_DEBUG, "GDGR: best=%d lm=%u", best, (unsigned int)lowest_metric);
1136
+
1137
+  gc_free (&gc);
1133 1138
   return ret;
1134 1139
 }
1135 1140