Skip to content
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

x/net/ipv4: PacketConn.MulticastInterface is implemented incorrectly on Linux #41854

Open
tamird opened this issue Oct 7, 2020 · 4 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tamird
Copy link
Contributor

tamird commented Oct 7, 2020

Per the man page:

       IP_MULTICAST_IF (since Linux 1.2)
              Set the local device for a multicast socket.  The argument for
              setsockopt(2) is an ip_mreqn or (since Linux 3.5) ip_mreq
              structure similar to IP_ADD_MEMBERSHIP, or an in_addr struc‐
              ture.  (The kernel determines which structure is being passed
              based on the size passed in optlen.)  For getsockopt(2), the
              argument is an in_addr structure.

However, the implementation uses the wrong type for retrieval:

https://github.com/golang/net/blob/a7d1128ccaa05167332a625f69773af1a0c6b39c/ipv4/dgramopt.go#L41

https://github.com/golang/net/blob/a7d1128ccaa05167332a625f69773af1a0c6b39c/ipv4/sys_linux.go#L27

https://github.com/golang/net/blob/a7d1128ccaa05167332a625f69773af1a0c6b39c/ipv4/sockopt_posix.go#L17

Oddly, the default case in getMulticastInterface would do the right thing.

This looks to have been broken in golang/net@353547e

@gopherbot gopherbot added this to the Unreleased milestone Oct 7, 2020
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/260680 mentions this issue: ipv4: Correctly MulticastInterface on Linux

@networkimprov
Copy link

cc @odeke-em

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 9, 2020
@dmitshur
Copy link
Contributor

CC @mikioh, @ianlancetaylor per owners.

@randomizedcoder
Copy link

A related observation, is that Linux has "ip_mreq_source":

           struct ip_mreq_source {
               struct in_addr imr_multiaddr;  /* IP multicast group
                                                 address */
               struct in_addr imr_interface;  /* IP address of local
                                                 interface */
               struct in_addr imr_sourceaddr; /* IP address of
                                                 multicast source */
           };

https://man7.org/linux/man-pages/man7/ip.7.html
https://github.com/torvalds/linux/blob/9b6de136b5f0158c60844f85286a593cb70fb364/include/uapi/linux/in.h#L189

Go doesn't seem to have the equivalent of ip_mreq_source
https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/syscall/ztypes_linux_amd64.go;l=216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants