[go] net: listen on specified multicast address

124 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Aug 18, 2021, 2:04:52 AM8/18/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
Gerrit-Change-Number: 343149
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Ian Lance Taylor (Gerrit)

unread,
Sep 13, 2021, 5:41:50 PM9/13/21
to Gerrit Bot, goph...@pubsubhelper.golang.org, Damien Neil, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Damien Neil.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 343149. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
    Gerrit-Change-Number: 343149
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Comment-Date: Mon, 13 Sep 2021 21:41:44 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Damien Neil (Gerrit)

    unread,
    Oct 6, 2021, 1:28:57 PM10/6/21
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, golang-co...@googlegroups.com

    View Change

    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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
    Gerrit-Change-Number: 343149
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Wed, 06 Oct 2021 17:28:51 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Daniel Kučera (Gerrit)

    unread,
    Oct 6, 2021, 2:44:33 PM10/6/21
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, Damien Neil, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil.

    View Change

    1 comment:

    • File src/net/sock_posix.go:

      • 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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
    Gerrit-Change-Number: 343149
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Daniel Kučera <daniel...@gmail.com>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Comment-Date: Wed, 06 Oct 2021 18:20:52 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Damien Neil <dn...@google.com>
    Gerrit-MessageType: comment

    Damien Neil (Gerrit)

    unread,
    Oct 7, 2021, 2:08:59 PM10/7/21
    to Gerrit Bot, Daniel Kučera, goph...@pubsubhelper.golang.org, Go Bot, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: Daniel Kučera.

    View Change

    1 comment:

    • File src/net/sock_posix.go:

      • 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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
    Gerrit-Change-Number: 343149
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Daniel Kučera <daniel...@gmail.com>
    Gerrit-Attention: Daniel Kučera <daniel...@gmail.com>
    Gerrit-Comment-Date: Thu, 07 Oct 2021 18:08:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Damien Neil <dn...@google.com>
    Comment-In-Reply-To: Daniel Kučera <daniel...@gmail.com>
    Gerrit-MessageType: comment

    Alexey McSakoff (Gerrit)

    unread,
    May 25, 2022, 6:45:04 PM5/25/22
    to Gerrit Bot, Daniel Kučera, goph...@pubsubhelper.golang.org, Gopher Robot, Ian Lance Taylor, Damien Neil, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil.

    View Change

    1 comment:

    • File src/net/sock_posix.go:

      • 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.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib45e6cd77b12f4dcca8ba3088c074d1f4a8db17e
    Gerrit-Change-Number: 343149
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Alexey McSakoff <mcsa...@gmail.com>
    Gerrit-CC: Daniel Kučera <daniel...@gmail.com>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Comment-Date: Wed, 25 May 2022 09:58:13 +0000
    Reply all
    Reply to author
    Forward
    0 new messages