I am trying to find the available methods to capture selective IP traffic to tunnel it using an UDP tunneling.
I went through the online resources and found that we can achieve this using PacketTunnelProvider where we will configure the tunnel then define inbound and outbound reader and writer functions.
One another method I found where we open a utun socket, assign source and destination tunnel address of the tunnel endpoints and then start doing read write operations on the utun interface, where our application will be able to read any traffic coming to that interface. (also we need to configure appropriate routes for the utun interface to redirect traffic).
I wanted to understand the difference between the two methods, and in which scenario both should be used?
how the manual route of creating utun interface and doing read/write can limit any functionalities. it is easy to maintain the code avoiding the sandboxing and app groups and managing the inbound and outbound connections.
Essentially we have created a supported API path for working with VPNs and virtual interfaces on our platforms, and that is the Network Extension frameworks. That means that if something breaks or goes wrong, you have a supported route to file bugs or contact DTS about this path. Going the route of building a virtual interface by hand and writing code around this is not the supported route. So if something goes wrong or changes in the OS, then you will need to find a way to deal with deal these changes on your own.
Furthermore, I would argue that taking advantage of security features like the Sandbox, that comes out of the box with Network Extensions, is something that you would want to adopt in your project. For example, one of the main goals for a Sandbox is to help protect files and resources that belong to a specific project on disk. If these files are not Sandboxed then that means anyone can arbitrarily edit them an that is not great.