How to call PacketTunnelProvider?

I have added the extension through Target > Packet Tunnel and got a PacketTunnelProvider generated.

I tried to call PacketTunnelProvider in my code but it will return:


Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_PacketTunnelProvider", referenced from:
      objc-class-ref in VPNConnection.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)



Should I call the classes in the extension directly? Or should I inherit from it and do my customization?


If there will be more document on it, it will be perfect.


Thank you!

I tried to call PacketTunnelProvider in my code …

I presume your PacketTunnelProvider is a subclass of NEPacketTunnelProvider. In that case, you don’t call that class directly. Rather, it is the principal class of your packet tunnel provider extension.

Remember that a VPN app has two targets:

  • The app itself, which is run by the user like any other app. It uses NETunnelProviderManager to configure and control the VPN.

  • The packet tunnel provider extension, which is invoked by the system when it wants to do VPN stuff. That extension has a principal class, your subclass of NEPacketTunnelProvider, that implements the custom logic associated with your VPN.

So your app does not call your NEPacketTunnelProvider subclass directly. Rather, your app configures the VPN using NETunnelProviderManager and then the system does the work to start your extension and call your NEPacketTunnelProvider subclass within the context of that extension. This can happen as the result of direct action on your app’s part (for example, if you call

-startTunnelWithOptions:
on the NETunnelProviderSession associated with your NETunnelProviderManager) but it can also happen behind the scenes (for example, if your VPN supports VPN On Demand).

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Yes. I did try NETunnelProviderManager before.

I code like this:



            NETunnelProviderManager *manager = [[NETunnelProviderManager alloc]init];
         
            [manager setProtocolConfiguration:tunnelProtocol];
            [manager setOnDemandEnabled:YES];
            [manager setEnabled:YES];
         
            [manager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) {
                if (error!=nil)
                    NSLog(@"load From error: %@", error);
                else {
                    NSLog(@"load success");
                    [manager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable error) {
                        if (error!=nil)
                            NSLog(@"save To error: %@", error);
                        else {
                         
                            NEVPNConnection *conn =  [manager connection];
                 
                            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
                            ...
                 
                            NSError *connError;
                            [conn startVPNTunnelWithOptions:dict andReturnError:&connError]
                         
                            if (connError!=nil)
                                NSLog(@"Connection error:%@", connError);
                         
                            vpnConn = conn;
                        }
                    }];
                 
                }
            }];



And I put some NSLogs in the PacketTunnelProvider.
However, when I run startVPNTunnelWithOptions, I don't think it really gets into PacketTunnelProvider as no log is found.


Is there any other things I need to set in plist or entitlement?


Thank you very much!

Is there any other things I need to set in plist or entitlement?

There are lots of packaging things that you need to get right for your extension to be recognised. I recommend that you build the SimpleTunnel sample (with just the tunnel parts) and then compare the packaging of your app and extension against the packaging that it uses.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Fiona,

I do face the same issue, When i call startVPNTunnel(), it does not hit Packet Tunnel extension which i have added to target. I tried to attach extension process using "Attach by Process" provided by Xcode but I dont find packet tunnel process running. I am sure whether my packet tunnel has started running.


Some help on this issue will be greatful.


Thanks

The most common cause of startup problems like this is broken entitlements. A while back I wrote up a document that explains how to debug these problems; I’ve just posted it in a separate article.

You should also read Technote 2415 Entitlements Troubleshooting, which covers this in more depth (albeit with less of a Network Extension framework focus).

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

"I do face the same issue, When i call startVPNTunnel(), it does not hit Packet Tunnel extension which i have added to target...."


Me too. Do u fix this?


Thanks

Me too. Do u fix this?


Thanks

How to call PacketTunnelProvider?
 
 
Q