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: Implement PacketConn.JoinSourceSpecificGroup() and PacketConn.LeaveSourceSpecificGroup for Windows #40317

Open
Misty418 opened this issue Jul 20, 2020 · 4 comments

Comments

@Misty418
Copy link

@Misty418 Misty418 commented Jul 20, 2020

What version of Go are you using (go version)?

go1.12.6 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build729998322=/tmp/go-build -gno-record-gcc-switches

What did you do?

Following this documentation https://godoc.org/golang.org/x/net/ipv4 we wanted to join a multicast group and receive packets from a specified source on Windows :

func (m *MCastSource) joinMulticastSourceGroup() error {
	var err error

	m.iface, err = net.InterfaceByName(m.ifaceName)
	if err != nil {
		return err
	}

	// Listens on any interfaces
	m.netPacketConn, err = net.ListenPacket("udp4", "0.0.0.0:5050")
	if err != nil {
		return err
	}
	m.ipv4PacketConn = ipv4.NewPacketConn(m.netPacketConn)

	groupIP := net.ParseIP(m.groupIp)
	sourceIP := net.ParseIP(m.sourceIp)
	m.ssmgroup = &net.UDPAddr{IP: net.IPv4(groupIP[12], groupIP[13], groupIP[14], groupIP[15])}
	m.ssmsource = &net.UDPAddr{IP: net.IPv4(sourceIP[12], sourceIP[13], sourceIP[14], sourceIP[15])}

	// Join source-specific multicast group
	if err := m.ipv4PacketConn.JoinSourceSpecificGroup(m.iface, m.ssmgroup, m.ssmsource); err != nil {
		return err
	}

	return nil
}

What did you expect to see?

We expected to join a multicast group with a specified source.

What did you see instead?

An error message explaining that PacketConn.JoinSourceSpecificGroup() from /net/ipv4 is not implemented on Windows.

What's next?

A pull request will quickly follow this issue. This PR aims to add the support of JoinSourceSpecificGroup() and LeaveSourceSpecificGroup() to Windows OSes.
We plan on doing so by adding the IP_ADD_SOURCE_MEMBERSHIP and the IP_DROP_SOURCE_MEMBERSHIP options to the list of sockopts supported on Windows.
https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options

We do know that there's a more recent API (https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-group_source_req) that we could use to implement these two methods on Windows but we chose to use the IPProto socket options for the following reasons:

  • these socket options are part of the same group of options that is currently used by the net/ipv4 package to implement the JoinGroup() and LeaveGroup() methods on Windows (IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP). We find it more consistent to use the same API for both joining/leaving groups and source specific groups.
  • these socket options are available on a wider range of OSes (it was first added on Windows XP)
@Misty418 Misty418 changed the title net/ipv4 : Implement PacketConn.JoinSourceSpecificGroup() and PacketConn.LeaveSourceSpecificGroup for Windows x/net: Implement PacketConn.JoinSourceSpecificGroup() and PacketConn.LeaveSourceSpecificGroup for Windows Jul 21, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 21, 2020
@toothrot
Copy link
Contributor

@toothrot toothrot commented Jul 21, 2020

@networkimprov
Copy link

@networkimprov networkimprov commented Jul 22, 2020

@julienmathevet
Copy link

@julienmathevet julienmathevet commented Nov 4, 2020

Any news about this bug and PR golang/net#79 ?

@networkimprov
Copy link

@networkimprov networkimprov commented Nov 4, 2020

cc @mattn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants