?
Solved

Adding route entry fails with different gateways

Posted on 2007-07-30
9
Medium Priority
?
1,280 Views
Last Modified: 2013-11-20
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
Comment
Question by:shaf81
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19591386
>> routeEntry.dwForwardProto =MIB_IPPROTO_LOCAL;// MIB_IPPROTO_LOCAL;

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

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 19591401
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
 
LVL 3

Author Comment

by:shaf81
ID: 19591494
I've used routeEntry.dwForwardProto=MIB_IPPROTO_NETMGMT initially, but it failed ,too. "route add" successfully adds the route. Confused?!
0
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

 
LVL 22

Expert Comment

by:mahesh1402
ID: 19592390
changin values of dwForwardMetric2 ,dwForwardMetric3 ,dwForwardMetric4
to ' -1' ?

-MAHESH
0
 
LVL 3

Author Comment

by:shaf81
ID: 19592472
Sorry Mahesh, I tried initially with those values set to -1 but failed and then only tried with 1 which also fails.
0
 
LVL 3

Author Comment

by:shaf81
ID: 19598979
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
 
LVL 3

Author Comment

by:shaf81
ID: 19599129
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
 
LVL 1

Accepted Solution

by:
Vee_Mod earned 0 total points
ID: 19677738
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question