Commit f34fe9e0 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: add missing per interface multicast listener test

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/15550043
parent 998fc9ed
...@@ -59,7 +59,7 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
} }
} }
func TestUDPMultipleConnWithMultipleGroupListeners(t *testing.T) { func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
switch runtime.GOOS { switch runtime.GOOS {
case "plan9", "windows": case "plan9", "windows":
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
...@@ -120,7 +120,7 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -120,7 +120,7 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
t.Skip("ipv6 is not supported") t.Skip("ipv6 is not supported")
} }
gaddr := &net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727 gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
type ml struct { type ml struct {
c *ipv6.PacketConn c *ipv6.PacketConn
ifi *net.Interface ifi *net.Interface
...@@ -142,13 +142,13 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -142,13 +142,13 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
} }
defer c.Close() defer c.Close()
p := ipv6.NewPacketConn(c) p := ipv6.NewPacketConn(c)
if err := p.JoinGroup(&ifi, gaddr); err != nil { if err := p.JoinGroup(&ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.JoinGroup on %v failed: %v", ifi, err) t.Fatalf("ipv6.PacketConn.JoinGroup on %v failed: %v", ifi, err)
} }
mlt = append(mlt, &ml{p, &ift[i]}) mlt = append(mlt, &ml{p, &ift[i]})
} }
for _, m := range mlt { for _, m := range mlt {
if err := m.c.LeaveGroup(m.ifi, gaddr); err != nil { if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.LeaveGroup on %v failed: %v", m.ifi, err) t.Fatalf("ipv6.PacketConn.LeaveGroup on %v failed: %v", m.ifi, err)
} }
} }
...@@ -166,14 +166,14 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -166,14 +166,14 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
t.Skip("must be root") t.Skip("must be root")
} }
c, err := net.ListenPacket("ip6:ipv6-icmp", "::") c, err := net.ListenPacket("ip6:ipv6-icmp", "::") // wildcard address
if err != nil { if err != nil {
t.Fatalf("net.ListenPacket failed: %v", err) t.Fatalf("net.ListenPacket failed: %v", err)
} }
defer c.Close() defer c.Close()
p := ipv6.NewPacketConn(c) p := ipv6.NewPacketConn(c)
gaddr := &net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727 gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
var mift []*net.Interface var mift []*net.Interface
ift, err := net.Interfaces() ift, err := net.Interfaces()
...@@ -184,14 +184,60 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -184,14 +184,60 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
if _, ok := isMulticastAvailable(&ifi); !ok { if _, ok := isMulticastAvailable(&ifi); !ok {
continue continue
} }
if err := p.JoinGroup(&ifi, gaddr); err != nil { if err := p.JoinGroup(&ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.JoinGroup on %v failed: %v", ifi, err) t.Fatalf("ipv6.PacketConn.JoinGroup on %v failed: %v", ifi, err)
} }
mift = append(mift, &ift[i]) mift = append(mift, &ift[i])
} }
for _, ifi := range mift { for _, ifi := range mift {
if err := p.LeaveGroup(ifi, gaddr); err != nil { if err := p.LeaveGroup(ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.LeaveGroup on %v failed: %v", ifi, err) t.Fatalf("ipv6.PacketConn.LeaveGroup on %v failed: %v", ifi, err)
} }
} }
} }
func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
switch runtime.GOOS {
case "darwin", "plan9", "windows":
t.Skipf("not supported on %q", runtime.GOOS)
}
if !supportsIPv6 {
t.Skip("ipv6 is not supported")
}
if os.Getuid() != 0 {
t.Skip("must be root")
}
gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
type ml struct {
c *ipv6.PacketConn
ifi *net.Interface
}
var mlt []*ml
ift, err := net.Interfaces()
if err != nil {
t.Fatalf("net.Interfaces failed: %v", err)
}
for i, ifi := range ift {
ip, ok := isMulticastAvailable(&ifi)
if !ok {
continue
}
c, err := net.ListenPacket("ip6:ipv6-icmp", fmt.Sprintf("%s%%%s", ip.String(), ifi.Name)) // unicast address
if err != nil {
t.Fatalf("net.ListenPacket failed: %v", err)
}
defer c.Close()
p := ipv6.NewPacketConn(c)
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.JoinGroup on %v failed: %v", ifi, err)
}
mlt = append(mlt, &ml{p, &ift[i]})
}
for _, m := range mlt {
if err := m.c.LeaveGroup(m.ifi, &gaddr); err != nil {
t.Fatalf("ipv6.PacketConn.LeaveGroup on %v failed: %v", m.ifi, err)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment