|
|
@@ -6,12 +6,16 @@ package ipv6_test
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
- "code.google.com/p/go.net/ipv6"
|
|
|
"net"
|
|
|
"os"
|
|
|
"runtime"
|
|
|
"testing"
|
|
|
"time"
|
|
|
+
|
|
|
+ "code.google.com/p/go.net/internal/iana"
|
|
|
+ "code.google.com/p/go.net/internal/icmp"
|
|
|
+ "code.google.com/p/go.net/internal/nettest"
|
|
|
+ "code.google.com/p/go.net/ipv6"
|
|
|
)
|
|
|
|
|
|
func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
|
|
|
@@ -25,7 +29,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
|
|
|
if !supportsIPv6 {
|
|
|
t.Skip("ipv6 is not supported")
|
|
|
}
|
|
|
- ifi := loopbackInterface()
|
|
|
+ ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
|
|
if ifi == nil {
|
|
|
t.Skipf("not available on %q", runtime.GOOS)
|
|
|
}
|
|
|
@@ -64,7 +68,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
cm := ipv6.ControlMessage{
|
|
|
- TrafficClass: DiffServAF11 | CongestionExperienced,
|
|
|
+ TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
|
|
Src: net.IPv6loopback,
|
|
|
IfIndex: ifi.Index,
|
|
|
}
|
|
|
@@ -106,7 +110,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
|
|
if os.Getuid() != 0 {
|
|
|
t.Skip("must be root")
|
|
|
}
|
|
|
- ifi := loopbackInterface()
|
|
|
+ ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
|
|
|
if ifi == nil {
|
|
|
t.Skipf("not available on %q", runtime.GOOS)
|
|
|
}
|
|
|
@@ -122,7 +126,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
|
|
t.Fatalf("net.ResolveIPAddr failed: %v", err)
|
|
|
}
|
|
|
|
|
|
- pshicmp := ipv6PseudoHeader(c.LocalAddr().(*net.IPAddr).IP, dst.IP, ianaProtocolIPv6ICMP)
|
|
|
+ pshicmp := icmp.IPv6PseudoHeader(c.LocalAddr().(*net.IPAddr).IP, dst.IP)
|
|
|
p := ipv6.NewPacketConn(c)
|
|
|
defer p.Close()
|
|
|
if err := p.JoinGroup(ifi, dst); err != nil {
|
|
|
@@ -142,7 +146,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
cm := ipv6.ControlMessage{
|
|
|
- TrafficClass: DiffServAF11 | CongestionExperienced,
|
|
|
+ TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
|
|
|
Src: net.IPv6loopback,
|
|
|
IfIndex: ifi.Index,
|
|
|
}
|
|
|
@@ -168,15 +172,15 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
|
|
// kernel checksum processing.
|
|
|
p.SetChecksum(false, -1)
|
|
|
}
|
|
|
- wb, err := (&icmpMessage{
|
|
|
+ wb, err := (&icmp.Message{
|
|
|
Type: ipv6.ICMPTypeEchoRequest, Code: 0,
|
|
|
- Body: &icmpEcho{
|
|
|
+ Body: &icmp.Echo{
|
|
|
ID: os.Getpid() & 0xffff, Seq: i + 1,
|
|
|
Data: []byte("HELLO-R-U-THERE"),
|
|
|
},
|
|
|
}).Marshal(psh)
|
|
|
if err != nil {
|
|
|
- t.Fatalf("icmpMessage.Marshal failed: %v", err)
|
|
|
+ t.Fatalf("icmp.Message.Marshal failed: %v", err)
|
|
|
}
|
|
|
if err := p.SetControlMessage(cf, toggle); err != nil {
|
|
|
t.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err)
|
|
|
@@ -195,8 +199,8 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
|
|
|
t.Fatalf("ipv6.PacketConn.ReadFrom failed: %v", err)
|
|
|
} else {
|
|
|
t.Logf("rcvd cmsg: %v", cm)
|
|
|
- if m, err := parseICMPMessage(rb[:n]); err != nil {
|
|
|
- t.Fatalf("parseICMPMessage failed: %v", err)
|
|
|
+ if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
|
|
|
+ t.Fatalf("icmp.ParseMessage failed: %v", err)
|
|
|
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 {
|
|
|
t.Fatalf("got type=%v, code=%v; expected type=%v, code=%v", m.Type, m.Code, ipv6.ICMPTypeEchoReply, 0)
|
|
|
}
|