IpPrioritizeRemote option in Dialer entry

Feb 4, 2010 at 9:45 AM

Is there a way to change this option from 1 to 0 from within the code. I can obviously change it manually but i would like to set this option on the fly.

Cheers
Chris

Coordinator
Feb 4, 2010 at 1:36 PM

Sorry, but you'll need to elaborate on what it is you're wanting to do. I haven't got a clue what IpPrioritizeRemote option is, or where it's at.

Feb 4, 2010 at 5:38 PM

Basically the code creates an phonebook entry for the VPN connection. This creates a file in your connections folder that contains the settings for the connection. by default the option IpPrioritizeRemote is set to 1 this means all ip traffic will be routed down the vpn connection. if you change this option to 0 then only traffic destend for the network on the VPN is routed down the VPN. Any other traffic is routed as normal. I am after a way to set this option with the code. you can set things like the IP address DNS server etc but i cant find an option for IpPrioritizeRemote.

Cheers
Chris

 

Coordinator
Feb 4, 2010 at 6:29 PM

Where are you getting the term IpPrioritizeRemote from? It sounds like you might be talking about the remote default gateway and split-tunneling a VPN connection.

Feb 4, 2010 at 7:18 PM

Basically the code creates a phonebook entry. in doing so it creates a file (C:\ProgramData\Microsoft\Network\Connections\pbk) with the connection details in. the IpPrioritizeRemote setting is in that file. If this setting is set to 1 all IP traffic is forced down VPN if set to 0 it is not.

My question is Can you set this setting within the code. ?? I dont want to split the VPN just add the connection to the PC as an additional interface.

 

Thanks
Chris

[VPN Connection]
Encoding=1
PBVersion=1
Type=2
AutoLogon=0
UseRasCredentials=1
LowDateTime=1309645168
HighDateTime=30057942
DialParamsUID=256578750
Guid=A772540DF9B9BE4687B4320C3A90F2CF
VpnStrategy=0
ExcludedProtocols=8
LcpExtensions=1
DataEncryption=256
SwCompression=0
NegotiateMultilinkAlways=0
SkipDoubleDialDialog=0
DialMode=0
OverridePref=15
RedialAttempts=3
RedialSeconds=60
IdleDisconnectSeconds=0
RedialOnLinkFailure=0
CallbackMode=0
CustomDialDll=
CustomDialFunc=
CustomRasDialDll=
ForceSecureCompartment=0
DisableIKENameEkuCheck=0
AuthenticateServer=0
ShareMsFilePrint=1
BindMsNetClient=1
SharedPhoneNumbers=0
GlobalDeviceSettings=0
PrerequisiteEntry=
PrerequisitePbk=
PreferredPort=VPN3-0
PreferredDevice=WAN Miniport (PPTP)
PreferredBps=0
PreferredHwFlow=0
PreferredProtocol=0
PreferredCompression=0
PreferredSpeaker=0
PreferredMdmProtocol=0
PreviewUserPw=1
PreviewDomain=1
PreviewPhoneNumber=0
ShowDialingProgress=1
ShowMonitorIconInTaskBar=1
CustomAuthKey=0
AuthRestrictions=544
IpPrioritizeRemote=1
IpInterfaceMetric=0
IpHeaderCompression=0
IpAddress=0.0.0.0
IpDnsAddress=0.0.0.0
IpDns2Address=0.0.0.0
IpWinsAddress=0.0.0.0
IpWins2Address=0.0.0.0
IpAssign=1
IpNameAssign=1
IpDnsFlags=0
IpNBTFlags=1
TcpWindowSize=0
UseFlags=2
IpSecFlags=0
IpDnsSuffix=
Ipv6Assign=1
Ipv6Address=::
Ipv6PrefixLength=0
Ipv6PrioritizeRemote=1
Ipv6InterfaceMetric=0
Ipv6NameAssign=1
Ipv6DnsAddress=::
Ipv6Dns2Address=::
Ipv6Prefix=0000000000000000
Ipv6InterfaceId=0000000000000000
DisableClassBasedDefaultRoute=0
DisableMobility=0
NetworkOutageTime=0
ProvisionType=0
PreSharedKey=

NETCOMPONENTS=
ms_msclient=1
ms_server=1

MEDIA=rastapi
Port=VPN3-0
Device=WAN Miniport (PPTP)

DEVICE=vpn
PhoneNumber=127.0.0.1
AreaCode=
CountryCode=0
CountryID=0
UseDialingRules=0
Comment=
FriendlyName=
LastSelectedPhone=0
PromoteAlternates=0
TryNextAlternateOnFail=1

 

Coordinator
Feb 4, 2010 at 8:10 PM

That's what a split-tunnel connection is. Any network traffic that's destined for the VPN network goes down the VPN tunnel, and all other traffic goes to the internet connection. This library doesn't modify the .pbk files directly, it uses Win32 interop to call the native APIs Microsoft has exposed by the Remote Access Service.

Anyway, you can set this behavior by modifying the RasEntry options property and removing the RemoteDefaultGateway flag.

RasPhoneBook pbk = new RasPhoneBook();
pbk.Open(); // You'll need to open whichever phonebook you want here.

// How to when creating a new entry:
RasEntry entry = RasEntry.CreateVpnEntry(....);
entry.Options = entry.Options & ~RasEntryOptions.RemoteDefaultGateway;
pbk.Entries.Add(entry);

// How to when modifying an existing entry:
RasEntry entry = pbk.Entries["Your Entry Name"];
if (entry != null)
{
    entry.Options = entry.Options & ~RasEntryOptions.RemoteDefaultGateway;
}

entry.Update();

The remote default gateway is always enabled when creating new entries using the 1.1 SDK, in 1.2 (under development) the RasEntry.CreateVpnEntry static method allows it to be turned off.

If you have any other questions feel free to ask.

Feb 4, 2010 at 8:40 PM

Thats perfect.

Thanks
Chris

Coordinator
Feb 4, 2010 at 9:41 PM

Not a problem, good luck with your project!

 

Feb 4, 2010 at 11:23 PM

Hi Chris, if you succeeded in removing the "default gateway" like you wanted to do, I would also like to use the code if you won't mind sharing it?

For my use, I think the code that Jeff gave would do the job exactly like I would want it :)
My application is written solely to route traffic, with the use of DotRas to dial PPTP VPN & PPPoE connections. I'm overriding the default gateway by getting the IP address of the dialed interface and then creating new route table entries: 0.0.0.0 subnet mask 128.0.0.0 & 128.0.0.0 subnet mask 128.0.0.0, which would override all the other "default gateways" that are simply using 0.0.0.0 subnet mask 0.0.0.0
You're more than welcome to use my code ( http://code.google.com/p/traffic-splitter/ ), but I guess that won't be necessary if Jeff's code would suffice.

Regards
Chris