]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Worked around an incompatibility in the Windows Vista
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Wed, 28 Feb 2007 03:49:33 +0000 (03:49 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Wed, 28 Feb 2007 03:49:33 +0000 (03:49 +0000)
version of CreateIpForwardEntry as described in
http://www.nynaeve.net/?p=59
This issue would cause route additions using the
IP Helper API to fail on Vista.

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

route.c

diff --git a/route.c b/route.c
index 354a10cbb7450bba485f2d0ff99ebe76f0c90131..36d41cd424c74b16fd0e8bcd17b7e882d8ba082c 100644 (file)
--- a/route.c
+++ b/route.c
@@ -1279,16 +1279,34 @@ add_route_ipapi (const struct route *r, const struct tuntap *tt)
        ret = true;
       else
        {
-         /* failed, try a different forward type (--redirect-gateway over RRAS seems to need this) */
-         fr.dwForwardType = 3;  /* the next hop is the final dest */
+         /* failed, try increasing the metric to work around Vista issue */
+         const unsigned int forward_metric_limit = 2048; /* iteratively retry higher metrics up to this limit */
 
-         status = CreateIpForwardEntry (&fr);
+         for ( ; fr.dwForwardMetric1 <= forward_metric_limit; ++fr.dwForwardMetric1)
+           {
+             /* try a different forward type=3 ("the next hop is the final dest") in addition to 4.
+                --redirect-gateway over RRAS seems to need this. */
+             for (fr.dwForwardType = 4; fr.dwForwardType >= 3; --fr.dwForwardType)
+               {
+                 status = CreateIpForwardEntry (&fr);
+                 if (status == NO_ERROR)
+                   {
+                     msg (D_ROUTE, "ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=%u and dwForwardType=%u",
+                          (unsigned int)fr.dwForwardMetric1,
+                          (unsigned int)fr.dwForwardType);
+                     ret = true;
+                     goto doublebreak;
+                   }
+                 else if (status != ERROR_BAD_ARGUMENTS)
+                   goto doublebreak;
+               }
+           }
 
-         if (status == NO_ERROR)
-           ret = true;
-         else
-           msg (M_WARN, "ROUTE: route addition failed using CreateIpForwardEntry: %s [if_index=%u]",
+       doublebreak:
+         if (status != NO_ERROR)
+           msg (M_WARN, "ROUTE: route addition failed using CreateIpForwardEntry: %s [status=%u if_index=%u]",
                 strerror_win32 (status, &gc),
+                (unsigned int)status,
                 (unsigned int)if_index);
        }
     }