Changing the VPN Configuration

When we install a VPN configuration on the device, we set some configuration parameters like OnDemandRules, serverAddress, providerBundleIdentifier etc. in the protocol configuration of the VPNManager and then save that in the Network Extension Preferences.

If we want to change those parameters later, like change the serverAddress, how can we do that?

Can these parameters be changed in the PacketTunnelProvider class?

If we want to change those parameters later, like change the serverAddress, how can we do that? Can these parameters be changed in the PacketTunnelProvider class?

If I understand you correctly, you can update these network configuration settings from the container app and then reconnect the tunnel. For example:

let manager = NETunnelProviderManager()
...
let proto = NETunnelProviderProtocol()
// Depending on the protocol, may be an IP address, host name, or URL
proto.serverAddress = "xx.xx.xx.xx"
proto.providerBundleIdentifier = "com.example.mytunnelApp.PacketTunnel"
manager.protocolConfiguration = proto
manager.isEnabled = true
manager.localizedDescription = "Testbed iOS Packet Tunnel"
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

Hey Matt, Thanks a lot for your reply.

Couple of follow up questions here -

  1. I understand that this line of code gives us the VPNManager which is currently associated with our application. Is this correct?
let manager = NETunnelProviderManager()
  1. After making changes in the configuration values, we have to save this to Network Extension preferences like this?
manager.saveToPreferences(completionHandler: completionHandler)
  1. And then we reconnect the tunnel something like this -
NETunnelProviderSession *session = (NETunnelProviderSession *)manager.connection;
NSError *error = nil;
NSDictionary *options = @{/* tunnel key/value args */};
[session startTunnelWithOptions:options andReturnError:&error];

I understand that this line of code gives us the VPNManager which is currently associated with our application. Is this correct? let manager = NETunnelProviderManager()

This will create a new NETunnelProviderManager to build a new network configuration for your provider. To get the existing tunnel manager call:

NETunnelProviderManager.loadAllFromPreferences { managers, error in
	// Examine the managers passed in here and get the one associated with your app/provider.
}

Regarding:

After making changes in the configuration values, we have to save this to Network Extension preferences like this? manager.saveToPreferences(completionHandler: completionHandler)

Yes.

Regarding:

And then we reconnect the tunnel something like this - NETunnelProviderSession *session = (NETunnelProviderSession *)manager.connection; NSError *error = nil; NSDictionary options = @{/ tunnel key/value args */}; [session startTunnelWithOptions:options andReturnError:&error];

Yes.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Changing the VPN Configuration
 
 
Q