Is creating this file and having it present in a system extension enough to "activate" the PacketTunnelProvider class and call startTunnel()? What else must be done?
If I am understanding you correctly, no, at some point after the System Extension is installed,
startVPNTunnel must be called to call over into the
NEPacketTunnelProvider.
So the steps here for macOS would be:
1) Create a OSSystemExtensionRequest.activationRequest for your NEPacketTunnelProvider.
2) Use
NETunnelProviderManager.loadAllFromPreferences to load your preferences for tunnel configuration. This is where you setup specifics from the container app about your tunnel. Also, where you configure the NETunnelProviderProtocol and any onDemandRules.
3) Call
saveToPreferences on your
NETunnelProviderManager. This should prompt the Network Configuration prompt to allow.
4) Call
connection.startVPNTunnel(options: options) on
NETunnelProviderManager to try and start the tunnel from the container app side.
5) Number (4) will trigger the call into the
NEPacketTunnelProvider for
startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void)6) In
startTunnel(options...) on the provider side you then configure
NEPacketTunnelNetworkSettings with the specific IPv4 / IPv6 settings and routes you want to claim for your tunnel. Also, you can setup any specific DNS domains you wish to custom serve.
7) After
NEPacketTunnelNetworkSettings are created these settings are passed into
setTunnelNetworkSettings and then any error that is triggered here should be passed back to the container app via the completionHandler.
8) You should be off and running at this point.
The SimpleTunnel example uses an App Extension since it's targeting iOS. Am I correct in thinking that for the macOS it should be a System Extension?
Yes, for Catalina and above a Network System Extension is used.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com