shaf81
asked on
Adding route entry fails with different gateways
I am using Windows IP helper functions to add an entry to the routing table which directs all requests to the 82.x.x.x through a VPN connection which has an interface IP 192.168.x.x. The VPN connection is started through a call to RasDial().
When I use my local network's router IP 10.0.0.1as the gateway, which is also the default gateway, the CreateIpForwardEntry() successfully adds the new route to the route table. But I want to make the gateway for that connection same as the 192.168.x.x, but when I try that, the CreateIpForwardEntry() fails with error ERROR_INVALID_PARAMETER.
I tried with different metrics for the connection, but none of them work. Here's the code segment I am using.
MIB_IPFORWARDROW routeEntry; // route entry data
memset(&routeEntry, 0, sizeof(MIB_IPFORWARDROW));
routeEntry.dwForwardDest=i net_addr(" 82.x.x.x") ;
routeEntry.dwForwardMask=i net_addr(" 255.255.25 5.255");
routeEntry.dwForwardAge=0;
CString s;
DWORD dwIndex=0,dwMask=0, dwVPNIP;;
in_addr in;
dwVPNIP=GetVPNIP(&dwIndex) ;
in.s_addr=dwVPNIP;
routeEntry.dwForwardNextHo p=dwVPNIP; //inet_add r("10.0.0. 1");
routeEntry.dwForwardIfInde x = dwIndex;
routeEntry.dwForwardMetric 1 = 20; // hard coded ************
// some default values
routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;
routeEntry.dwForwardMetric 2 = 1;
routeEntry.dwForwardMetric 3 = 1;
routeEntry.dwForwardMetric 4 = 1;
DWORD dwStatus;
if ((dwStatus=CreateIpForward Entry(&rou teEntry))! = NO_ERROR)
{
if(dwStatus==ERROR_INVALID _PARAMETER )
MessageBox("Invalid param");
s.Format("Adding entry failed Status %d",dwStatus);
MessageBox(s);
}
What might have cause this problem?
Thanks.
Shaf81
When I use my local network's router IP 10.0.0.1as the gateway, which is also the default gateway, the CreateIpForwardEntry() successfully adds the new route to the route table. But I want to make the gateway for that connection same as the 192.168.x.x, but when I try that, the CreateIpForwardEntry() fails with error ERROR_INVALID_PARAMETER.
I tried with different metrics for the connection, but none of them work. Here's the code segment I am using.
MIB_IPFORWARDROW routeEntry; // route entry data
memset(&routeEntry, 0, sizeof(MIB_IPFORWARDROW));
routeEntry.dwForwardDest=i
routeEntry.dwForwardMask=i
routeEntry.dwForwardAge=0;
CString s;
DWORD dwIndex=0,dwMask=0, dwVPNIP;;
in_addr in;
dwVPNIP=GetVPNIP(&dwIndex)
in.s_addr=dwVPNIP;
routeEntry.dwForwardNextHo
routeEntry.dwForwardIfInde
routeEntry.dwForwardMetric
// some default values
routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;
routeEntry.dwForwardMetric
routeEntry.dwForwardMetric
routeEntry.dwForwardMetric
DWORD dwStatus;
if ((dwStatus=CreateIpForward
{
if(dwStatus==ERROR_INVALID
MessageBox("Invalid param");
s.Format("Adding entry failed Status %d",dwStatus);
MessageBox(s);
}
What might have cause this problem?
Thanks.
Shaf81
The error usually means that one of the members of the MIB_IPFORWARDROW structure is invalid. You can try to use route.exe and execute "route add" command to add the entry. Thus, you can test whether the parameters are
correct or not.
-MAHESH
correct or not.
-MAHESH
ASKER
I've used routeEntry.dwForwardProto= MIB_IPPROT O_NETMGMT initially, but it failed ,too. "route add" successfully adds the route. Confused?!
changin values of dwForwardMetric2 ,dwForwardMetric3 ,dwForwardMetric4
to ' -1' ?
-MAHESH
to ' -1' ?
-MAHESH
ASKER
Sorry Mahesh, I tried initially with those values set to -1 but failed and then only tried with 1 which also fails.
ASKER
Any experts out there who can help me?
On the command prompt, when I use:
Route ADD 82.x.x.x MASK 255.255.255.255 192.168.x.x IF 0x4003 - it works
Also this too works:
Route ADD 82.x.x.x MASK 255.255.255.255 10.0.0.1 IF 0x4003
But with CreateIpForwardEntry() only gateway 10.0.0.1 work, and not the VPN gateway. What am I doing wrong?
Please help.
On the command prompt, when I use:
Route ADD 82.x.x.x MASK 255.255.255.255 192.168.x.x IF 0x4003 - it works
Also this too works:
Route ADD 82.x.x.x MASK 255.255.255.255 10.0.0.1 IF 0x4003
But with CreateIpForwardEntry() only gateway 10.0.0.1 work, and not the VPN gateway. What am I doing wrong?
Please help.
ASKER
Thanks experts,
I've resolved the problem myself !!!!!! routeEntry,ForwardType must be set to 4 (The next hop is not the final destination (remote route)) to make this happen. When I memset(), this value becomes 0 which falls to none of the allowed values in the documentation.
I've resolved the problem myself !!!!!! routeEntry,ForwardType must be set to 4 (The next hop is not the final destination (remote route)) to make this happen. When I memset(), this value becomes 0 which falls to none of the allowed values in the documentation.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is that correct ? it should not be MIB_IPPROTO_NETMGMT ?? ie. 3 ??
-MAHESH