ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
482 stars 215 forks source link

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

Closed javierdemartin closed 5 years ago

javierdemartin commented 5 years ago

Currently working on a Network Extension that lets me stablish a connection using a .ovpn file using a 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

javierdemartin commented 5 years ago

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.

Yangjiajiaa commented 3 years ago

hi @javierdemartin i have the same problem func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (Error?) -> Void) { setTunnelNetworkSettings(networkSettings) { (error) in completionHandler(error == nil ? self.packetFlow as? Error : nil) } } is my code right?