Gerrit Bot has uploaded this change for review.
net: listen on specified multicast address
Fixes #34728
This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.
**Please ensure you adhere to every item in this list.**
More info can be found at https://github.com/golang/go/wiki/CommitMessage
+ The PR title is formatted as follows: `net/http: frob the quux before blarfing`
+ The package name goes before the colon
+ The part after the colon uses the verb tense + phrase that completes the blank in,
"This change modifies Go to ___________"
+ Lowercase verb after the colon
+ No trailing period
+ Keep the title as short as possible. ideally under 76 characters or shorter
+ No Markdown
+ The first PR comment (this one) is wrapped at 76 characters, unless it's
really needed (ASCII art, table, or long link)
+ If there is a corresponding issue, add either `Fixes #1234` or `Updates #1234`
(the latter if this is not a complete fix) to this comment
+ If referring to a repo other than `golang/go` you can use the
`owner/repo#issue_number` syntax: `Fixes golang/tools#1234`
+ We do not use Signed-off-by lines in Go. Please don't add them.
Our Gerrit server & GitHub bots enforce CLA compliance instead.
+ Delete these instructions once you have read and applied them
Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
GitHub-Last-Rev: 0226690a9b95ddafc72225f9c74cded1d72f12f5
GitHub-Pull-Request: golang/go#47772
---
M src/net/sock_posix.go
1 file changed, 0 insertions(+), 15 deletions(-)
diff --git a/src/net/sock_posix.go b/src/net/sock_posix.go
index 9b1e788..64645c4 100644
--- a/src/net/sock_posix.go
+++ b/src/net/sock_posix.go
@@ -208,25 +208,10 @@
func (fd *netFD) listenDatagram(laddr sockaddr, ctrlFn func(string, string, syscall.RawConn) error) error {
switch addr := laddr.(type) {
case *UDPAddr:
- // We provide a socket that listens to a wildcard
- // address with reusable UDP port when the given laddr
- // is an appropriate UDP multicast address prefix.
- // This makes it possible for a single UDP listener to
- // join multiple different group addresses, for
- // multiple UDP listeners that listen on the same UDP
- // port to join the same group address.
if addr.IP != nil && addr.IP.IsMulticast() {
if err := setDefaultMulticastSockopts(fd.pfd.Sysfd); err != nil {
return err
}
- addr := *addr
- switch fd.family {
- case syscall.AF_INET:
- addr.IP = IPv4zero
- case syscall.AF_INET6:
- addr.IP = IPv6unspecified
- }
- laddr = &addr
}
}
var err error
To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
Patch set 1:Run-TryBot +1
1 comment:
File src/net/sock_posix.go:
Patch Set #1, Line 229: laddr = &addr
Doesn't this break net.ListenMulticastUDP, which expects the conversion of laddr from the group address to the wildcard addr to happen here?
To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
1 comment:
File src/net/sock_posix.go:
Patch Set #1, Line 229: laddr = &addr
Doesn't this break net. […]
That is the point, when listening on multicast addr, one usually want's to listen on that particular address to receive only packes destined for that address, not for all addresses (in case of IPv4zero). When listening on 0.0.0.0, one may receive packets destined for different multicast addresses or even local addresses.
For comparison, look what nc does:
nc -lu 239.1.2.3 1234
results in:
$ netstat -anp | grep /nc
udp 0 0 239.1.2.3:1234 0.0.0.0:* 828871/nc
Vs go:
code:
l, err := net.ListenPacket("udp", "239.1.2.3:1234")
results in:
udp 0 0 0.0.0.0:1234 0.0.0.0:* 676/gomcastrelay
To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Daniel Kučera.
1 comment:
File src/net/sock_posix.go:
Patch Set #1, Line 229: laddr = &addr
But the ListenMulticastUDP documentation says:
ListenMulticastUDP listens on all available IP addresses of the local system including the group, multicast IP address.
Perhaps it shouldn't do that, but it seems like it does what the documentation says. If it does change, the documentation needs to be updated. And since that would be an API change, this would also need an approved proposal.
Or perhaps I'm missing something.
To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Damien Neil.
1 comment:
File src/net/sock_posix.go:
Patch Set #1, Line 229: laddr = &addr
But the ListenMulticastUDP documentation says: […]
net.ListenMulticastUDP must NOT bind to 0.0.0.0, it must bind to multicast group address. When binding to 0.0.0.0 you will receive all multicast traffic to that port for which you and other processes on the host added a group membership.
UNIX® Network Programming Volume 1, Third Edition: The Sockets Networking API by W.R Stevens. 21.10. Sending and Receiving:
[...] We want the receiving socket to bind the multicast group and port, say 239.255.1.2 port 8888. (Recall that we could just bind the wildcard IP address and port 8888, but binding the multicast address prevents the socket from receiving any other datagrams that might arrive destined for port 8888.)
To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.