From 94a4350003492d140d6e2c8b9c979703fce81939 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 28 Feb 2007 03:49:33 +0000 Subject: Worked around an incompatibility in the Windows Vista 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 | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/route.c b/route.c index 354a10c..36d41cd 100644 --- 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); } } -- cgit v1.2.3