Is there any way on MacOS, I mean at all, to generically handle packet routing in user space?
That depends on your specific requirements. You wrote:
pass [connections] through a transparent proxy globally or on a per-app basis
This last point makes per-app VPN the most obvious contender. Whether this is a contender depends on your security model. Per-app VPN was designed for an enterprise environment, where the connection won’t work without the VPN (it’s otherwise blocked by the enterprise firewall). However, it sounds like you’re actually trying to create a security product — like a personal firewall or a data egress checker — where the connection will work without your product but you don’t want it to. In that case per-app VPN is a non-starter, and your best option — albeit not a good option — is an NKE.
Creating a new NKE today is, as you’ve noted, likely to be a compatibility problem sometime down the line. From a technical perspective your best option would be to:
Minimise the code within the kernel itself
Isolate the bulk of your user space code from the specific mechanism used to catch the connections, making it easier to adapt to future changes
IMPORTANT Deploying an NKE requires a KEXT-enabled Developer ID. If you go down this path, I recommend that you apply for the early. Before applying, file an enhancement request describing what you’d like to do and why an NKE is your only option right now. I’d appreciate you posting that bug number here so that I can add it to my records.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"