Link to home
Start Free TrialLog in
Avatar of shaf81
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=inet_addr("82.x.x.x");
      routeEntry.dwForwardMask=inet_addr("255.255.255.255");
      routeEntry.dwForwardAge=0;

     

      CString s;
      DWORD dwIndex=0,dwMask=0, dwVPNIP;;
      in_addr in;
      dwVPNIP=GetVPNIP(&dwIndex);
      in.s_addr=dwVPNIP;
      routeEntry.dwForwardNextHop=dwVPNIP;//inet_addr("10.0.0.1");
     
      routeEntry.dwForwardIfIndex = dwIndex;
     
   
    routeEntry.dwForwardMetric1 = 20;      //      hard coded ************

    // some default values
    routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;
    routeEntry.dwForwardMetric2 = 1;
    routeEntry.dwForwardMetric3 = 1;
    routeEntry.dwForwardMetric4 = 1;
      DWORD dwStatus;

      if ((dwStatus=CreateIpForwardEntry(&routeEntry))!= 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
Avatar of mahesh1402
mahesh1402
Flag of India image

>> routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;

Is that correct ? it should not be MIB_IPPROTO_NETMGMT  ?? ie. 3 ??

-MAHESH
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


Avatar of shaf81
shaf81

ASKER

I've used routeEntry.dwForwardProto=MIB_IPPROTO_NETMGMT initially, but it failed ,too. "route add" successfully adds the route. Confused?!
changin values of dwForwardMetric2 ,dwForwardMetric3 ,dwForwardMetric4
to ' -1' ?

-MAHESH
Avatar of shaf81

ASKER

Sorry Mahesh, I tried initially with those values set to -1 but failed and then only tried with 1 which also fails.
Avatar of shaf81

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.
Avatar of shaf81

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.
ASKER CERTIFIED SOLUTION
Avatar of Vee_Mod
Vee_Mod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial