Some of the approaches to this problem that I have thought about, but aren't perfect include:
Enumerate the open TCP connections using sysctl() (similar to how netstat does it) and then force-close them using pfctlinput(PRC_UNREACH_PORT, &addr). This seems like it should work, but it doesn't do anything to address UDP flows that ought to be closed.
Restarting the NETransparentProxyProvider seems like it should cause the kernel's flow director to restart, but I can't really find any documentation on how this works and whether it would trigger the existing flows to be closed. It would also be nice if the transparent proxy provider could restart itself in this case.
There is an undocumented syscall: pid_shutdown_sockets() that we could use to force-close sockets for an entire process. But this seems mostly used for suspend/resume operations. And it's probably a bad idea to try and use undocumented APIs.
There is an undocumented method fetchFlowStatesWithCompletionHandler() that I had hoped would return a list of flows that we could close, but this does not seem to return the flows where we returned NO from handleNewFlow().
Topic:
App & System Services
SubTopic:
Networking
Tags: