Hello,
I'm creating a small app to log all the domains the iPhone uses.
I use NEPacketTunnelProvider, creating a virtual interface and redirecting all DNS traffic there, which means I don't have to manage TCP flows, just extract DNS queries from IP packets, and managing UDP sessions, which is much easier than managing TCP flows.
I also use NEOnDemandRuleConnect so my VPN is always connected.
My app works fine and I can see how all the domains are logged properly and the user can see them. I also inject back the actual DNS responses and the network works properly (you can browse website and use apps)
This is the problem I have: Sometimes, whem going to WiFi to cellular, from cellular to WiFi or airplain mode to Wifi/3G, I see how the VPN starts again (probably because NEOnDemandRuleConnect, which is what I want) but then I see that the network does not work. No websites are loaded. If I check the system console (filtering by process name, otherwise it is impossible to see anything), I see something I don't see when everything works fine:
error 21:19:25.226644 +0100 Domain Checker Extension __nw_socket_service_writes_block_invoke sendmsg(fd 5, 40 bytes): [51] Network is unreachable
error 21:19:25.227015 +0100 Domain Checker Extension nw_endpoint_flow_prepare_output_frames Failing the write requests: [51] Network is unreachable
So, maybe I'm missing something but I cannot see it.
The documentation is not very clear about how to implement fault tolerant VPNs/tunnels, although I saw this document that perhaps says something that could be used for that:
https://developer.apple.com/documentation/networkextension/neprovider/1406740-defaultpath
Should I create a KVO observer in order to start the tunnel again when the interface changes?
Perhaps when "defaultPath" changes, I should reconnect, but, the problem is that my extension is not connected to anything.
When going to airplane mode, 3G, WifI... I see how "defaultPath" changes, so perhaps that's what I'm missing.
Do you have any idea about what I should do? Or what could I try to solve this?
Thank you very much for your suggestions.