-
Notifications
You must be signed in to change notification settings - Fork 18k
net: ListenMulticastUDP doesn't limit data to packets from the declared group port on Linux #73484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, I've had a deeper look into the socket setup from the golang executable using strace. When the socket is being setup it is not bound to the actual group address. Instead it is being bound to 0.0.0.0 . This causes all packets received on a interface destined to the provided port to be delivered to the program userspace. This doesn't only create some unexpected data to be received in user program, but also performance impact as unneeded data is being copied from kernel space to userspace (though I'm no expert here). I guess a modification is required in net/sock_posix.go netFD.dial to correctly bind to the group address. Though I might have made a wrong turn following the function calls. The fourth line in the strace output is the line of interest. main() { strace output from where the socket setup startssocket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 3 |
As per the code, it intentionally binds to 0.0.0.0 instead of the original address. Lines 184 to 203 in f9ce1dd
|
I wonder if such a policy decision should be made so deep/close to the kernel. I would think it would be rather simple to enforce such a policy in some higher level function where one could actually make a conscious decision if they want a wildcard socket or not. |
I'm definitely not the expert here, and I don't understand the comment in the code. It was introduced in 0ae8078. It seems to me the that the standard library should not be binding to 0.0.0.0 like this. Clearly This would also fix the current surprising behavior where |
I've looked at the commit message, From that message I assume that fuctionallity was pushed down the stack which should have been solved at a higher level. namely the ipv4 package in this case. |
@mrinny do you have an example of how an application could be relying on the current behavior? |
I off course don't have knowledge about all usecases. Though I think maybe in a discovery system where one could receive announces from multiples groups and consolidate them in a single socket. I've been using multicast just as multimedia transport. which has other contraints that using it as a messaging transport I would imagine. |
just some small feedback. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes, also tested on 1.24.2 linux/amd64
tested on
debian trixie - kernel 6.12.22-amd64
ubuntu 24.04 - kernel 6.8.0-51-generic
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
join a multicast group using net.ListenMulticastUDP.
example / repoduction scenario
A sender process sends multicast packets every second on group A (239.0.10.10).
A proxy process listens for multicast packets on group A if a packet is received it sends a packet with different content on group B (239.0.10.11)
A receiver process listens for multicast packets on group B
mc_sender process: https://gist.github.com/mrinny/3c948eb86fc9cfa151cdf4b089980cbc
mc_proxy process: https://gist.github.com/mrinny/bbe1884dea72a4d08ad4101301f9b258
mc_receiver process: https://gist.github.com/mrinny/2e38dede9d32ebea222b28176537b55f
What did you expect to see?
reading from the connection should only return data send to multicast group which was decared as the remote address (group address and port).
the proxy process prints out "hello world" every second
the receiver process prints out "hello proxy" every second
What did you see instead?
Data from any linux kernel joined group is being returned by calling ReadFromUDP.
The proxy process prints out "hello world" followed by lots of "hello proxy"
the proxy process prints out "hello proxy"
Further Information
On OSX the behavior seems to be as expected.
The example reproduction uses three go programs to demonstrate the issue. Though it can also be observed with other programs.
For example:
The moment the linux ip stack joins the multicast group. I start seeing the proxy process printout the binary video data. While the poxy process never actually joined the group being used for the rtp multicast.
Instead of the call ListenMulticastUDP I've also tried the net.ListenPacket => ipv4.PacketConn => JoinGroup approach. Though this gives the same result.
The text was updated successfully, but these errors were encountered: