swiftvpnnetworkextension

iOS Network Extension error creating TUN/TAP interface SIOCGIFMTU failed: device not configured


Currently working on a Network Extension that lets me stablish a connection using a VPN using a .ovpn file, by using OpenVPNAdapter library. I have saved correcly my configuration to the System settings and when running the extension to perform debug my extension status changes from disconnected, stays in connecting for a while and then disconnects. Further inspecting the console logs for the device anf filtering by the network extension I get three main error messages.

Log message from provider: TUN Error: cannot acquire tun interface socket

SIOCGIFMTU failed: Device not configured

NEVirtualInterfaceAdjustReadBufferSize: interface_get_mtu failed (6), defaulting to max mtu

I don't know where to head now as I am debugging the network extension using the Console from the device.


Solution

  • Okay I managed to solve this on my own. I created a Packet Tunnel Network Extension and in my PacketTunnelProvider class came the problems. It did not crash so setting up the debugger in that class was not worth it. I ran my target and started my app and set several NSLogs in the functions so I could see in the device's console what was happening. My problem was that I tried to set a nil value in a dictionary for a key thus terminating the extension. That crash message can easily be seen in the console.

    The problem was when extending PacketTunnelProvider with OpenVPNAdapterDelegate in the function to configure the tunnel

    func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
        networkSettings?.dnsSettings?.matchDomains = [""];
    }
    

    Previously I had networkSettings.dnsSettings?.matchDomains = [""]; so networkSettings was unwrapped and it was nil making it crash the extension and the tunnel not being able to get connected.