Get udp recipent IP for incoming packet #54483
Labels
dgram
Issues and PRs related to the dgram subsystem / UDP.
feature request
Issues that request new features to be added to Node.js.
What is the problem this feature will solve?
It's impossible to serve a UDP based server with nodejs on multiple IP server.
A lot of cloud service provider or ISPs allowing us to purchase additional IP on it.
Assume I have a server with multiple IP on it.
In this case, I'm demo with
172.22.10.100
and172.22.10.101
The
172.22.10.100
is marked as primary, and172.22.10.101
is marked as secondary by kernel.This is a simple udp server, it replys "pong" message to every client.
If the client connect to
172.22.10.100.55567
, it replies with src ip172.22.10.100.55567
But if the client connect to
172.22.10.101.55567
, the server still reply with src ip172.22.10.100.55567
which make it unuseable on IP 172.22.10.101This bug happens is because linux selects source address with following rules:
bind
orwrite
)3-1. If
pref-src
is set on the route, use it3-2. if the route points a NIC, select an IP from it
3-3. If multiple IP on the NIC, use the ip marked as primary.
TCP socket get covered by system at rule 2 but udp is not.
If the selection hits rule 3, it's basically guess. Because it lost the information of which IP is the client connect to.
Different from TCP session, system won't track udp session for user, we have to handle it by our self.
We have to
bind
specfic source IP on udp each session otherwise system just select the primary IP from NIC based on default table. So that it brokes at system have multiple route table or secondary IP on the NIC.What is the feature you are proposing to solve the problem?
In order to reply message with correct
source address
, we have to get the information of destnation IP at incoming packet.Unfortunately we can't do it in nodejs right now so that there is no way to implement workable udp server with nodejs on multiple IP server.
There are similar issue, but all get closed and locked. And all these are talking something about broadcast address.
nodejs/node-v0.x-archive#8788
nodejs/node-v0.x-archive#6589
But in my use case, it irrelevant to broadcast address or overlapping subnets etc.
It's just a try to create a regular udp server application on a multiple IP server.
So I want nodejs developers reconsider this feature.
The another issue is get destnation IP for incoming packet is platform specific.
We have to write a lot of code to hendle it.
In linux (include Android) based platform, we have to use
IP_PKTINFO
In BSD based platform (include MacOS and iOS), we need
IP_RECVDSTADDR
In Windows platform, we need
WSAIoctl
andWSARecvMsg
For these 3 platform, it covers 99% of our scenarios.
But this is a generial purpose requirement.
It would be nice if we can make a abstraction for this feature at nodejs, instead of implement it with platform specific code with C binding.
What alternatives have you considered?
Uses native C api to retrive the destnation IP at incoming packet, then we can reply reply with correct
source address
.Which make the code more complex, unreadable and unportable.
The text was updated successfully, but these errors were encountered: