• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1315
  • Last Modified:

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
0
shaf81
Asked:
shaf81
  • 4
  • 3
1 Solution
 
mahesh1402Commented:
>> routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;

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

-MAHESH
0
 
mahesh1402Commented:
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


0
 
shaf81Author Commented:
I've used routeEntry.dwForwardProto=MIB_IPPROTO_NETMGMT initially, but it failed ,too. "route add" successfully adds the route. Confused?!
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
mahesh1402Commented:
changin values of dwForwardMetric2 ,dwForwardMetric3 ,dwForwardMetric4
to ' -1' ?

-MAHESH
0
 
shaf81Author Commented:
Sorry Mahesh, I tried initially with those values set to -1 but failed and then only tried with 1 which also fails.
0
 
shaf81Author Commented:
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.
0
 
shaf81Author Commented:
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.
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now