0

Say, there are 2 services (A and B) bound to listen onto the same UDP port. service A employs SO_REUSEPORT socket option and service B doesn't.

Is there a way to make both services to work together on the same ip/port?

Specifically, would it matter an order of starting the services (A then B, or B then A) so that both work correctly?
Or both services must configure their sockets with SO_REUSEPORT to be able to work correctly?

Dmitry
  • 1,275
  • 1
  • 5
  • 14
  • What is the original problem you need to solve? Why can't you have one single process listening on the specific address/port pair, and then dispatch to other processes or threads? – Some programmer dude Jun 16 '23 at 21:07
  • @Someprogrammerdude, because these 2 services (A and B) are beyond my control - they are indeppendent programs and I cannot front-end those with a demultiplexing serivce. – Dmitry Jun 16 '23 at 21:09
  • Can you configure the programs to listen on different ports? Then a simple proxy should be possible: For the true clients it acts as a single server, and for the two actual servers it acts as a single client. All it does is forward the packages to the two actual servers. – Some programmer dude Jun 16 '23 at 21:20
  • Or if the two programs can be run on separate systems (virtualization, containers, etc. will work well for that) then it doesn't matter if you can't change their configuration. – Some programmer dude Jun 16 '23 at 21:22
  • Anyway, `SO_REUSEPORT` have some limitations and restrictions that make it hard to impossible to use general applications with it. Not to mention that you will then have no control over which application will get what package. – Some programmer dude Jun 16 '23 at 21:24
  • @Someprogrammerdude, unfortunately the answer is "no" to all suggestions. 1) it's a well known public network port, it cannot be changed. If even it was possible, it wouldn't be possible to make all the clients to change using a new port (it's beyond my control). 2) all the options for virtualizations/containerization are not applicable in this specific environment. I just need to understand whether this specific scenario is possible to make work or not. – Dmitry Jun 16 '23 at 22:10
  • Then I don't see any way forward with your problem. You need to go back to your original problem and find another solution. Perhaps if you ask about that directly instead (making your question less of an [XY problem](https://en.wikipedia.org/wiki/XY_problem)) we might be able to help you with that instead? – Some programmer dude Jun 17 '23 at 06:15
  • "_there are 2 services (A and B) bound to listen onto the same UDP port._" You cannot do that. UDP will reject a second request to use an already in-use port number. See [this answer](https://networkengineering.stackexchange.com/a/28966/8499) about that. – Ron Maupin Jun 18 '23 at 14:36
  • thanks @RonMaupin, however, here's a quote from `man 7 socket`: "_SO_REUSEPORT (since Linux 3.9) "Permits multiple AF_INET or AF_INET6 sockets to be bound to an identical socket address...."_ – Dmitry Jun 18 '23 at 19:23
  • That is for multiple threads of the same service, not separate services. – Ron Maupin Jun 18 '23 at 19:33
  • @RonMaupin. A) the sockets are simply higher level abstraction unaware (so sockets they agnostics whether they being used by the same process/different threads or by different processes. B) in the very same manual you'll read that it talks about the same socket usage (using `SO_REUSEPORT` by different processes). – Dmitry Jun 18 '23 at 20:36
  • There are restrictions to prevent port hijacking by a rogue process. Read [this](https://lwn.net/Articles/542629/) and especially the last paragraph, "_The SO_REUSEPORT option is non-standard..._" – Ron Maupin Jun 18 '23 at 21:18

0 Answers0