I have some iptables port-forwards and I want to make SURE that no other process on the system uses those ports. I can bind() a socket myself, so other processes get EADDRINUSE, but if my process dies those sockets become available for use again and I can lose the race.
For example:
- I set a port-forward on port 8000 to some other destination
- other process tries to bind() to 8000
- other process should fail
In the other order:
- other process binds() to 8000
- I try to set a port-forward on port 8000
- I fail
I'm looking for some clever trick to make the kernel treat a port as if I have it open, even without a living PID. Something like NS FDs (https://lwn.net/Articles/407495/).
I know it's a stretch, but I am grasping, trying to avoid a process-based solution.