Commit 77ebfc57 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: make use of internal/{iana,icmp,nettest} packages

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/168210043
parent 7db411a1
// go run gentest.go
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
package ipv6_test
// Differentiated Services Field Codepoints (DSCP), Updated: 2013-06-25
const (
DiffServCS0 = 0x0 // CS0
DiffServCS1 = 0x20 // CS1
DiffServCS2 = 0x40 // CS2
DiffServCS3 = 0x60 // CS3
DiffServCS4 = 0x80 // CS4
DiffServCS5 = 0xa0 // CS5
DiffServCS6 = 0xc0 // CS6
DiffServCS7 = 0xe0 // CS7
DiffServAF11 = 0x28 // AF11
DiffServAF12 = 0x30 // AF12
DiffServAF13 = 0x38 // AF13
DiffServAF21 = 0x48 // AF21
DiffServAF22 = 0x50 // AF22
DiffServAF23 = 0x58 // AF23
DiffServAF31 = 0x68 // AF31
DiffServAF32 = 0x70 // AF32
DiffServAF33 = 0x78 // AF33
DiffServAF41 = 0x88 // AF41
DiffServAF42 = 0x90 // AF42
DiffServAF43 = 0x98 // AF43
DiffServEFPHB = 0xb8 // EF PHB
DiffServVOICEADMIT = 0xb0 // VOICE-ADMIT
)
// IPv4 TOS Byte and IPv6 Traffic Class Octet, Updated: 2001-09-06
const (
NotECNTransport = 0x0 // Not-ECT (Not ECN-Capable Transport)
ECNTransport1 = 0x1 // ECT(1) (ECN-Capable Transport(1))
ECNTransport0 = 0x2 // ECT(0) (ECN-Capable Transport(0))
CongestionExperienced = 0x3 // CE (Congestion Experienced)
)
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
package ipv6_test package ipv6_test
import ( import (
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"reflect" "reflect"
"runtime" "runtime"
"sync" "sync"
"testing" "testing"
"code.google.com/p/go.net/ipv6"
) )
var icmpStringTests = []struct { var icmpStringTests = []struct {
......
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ipv6_test
import (
"code.google.com/p/go.net/ipv6"
"errors"
"net"
)
const (
ipv6PseudoHeaderLen = 2*net.IPv6len + 8
ianaProtocolIPv6ICMP = 58
)
func ipv6PseudoHeader(src, dst net.IP, nextHeader int) []byte {
b := make([]byte, ipv6PseudoHeaderLen)
copy(b[:net.IPv6len], src)
copy(b[net.IPv6len:], dst)
b[len(b)-1] = byte(nextHeader)
return b
}
// icmpMessage represents an ICMP message.
type icmpMessage struct {
Type ipv6.ICMPType // type
Code int // code
Checksum int // checksum
Body icmpMessageBody // body
}
// icmpMessageBody represents an ICMP message body.
type icmpMessageBody interface {
Len() int
Marshal() ([]byte, error)
}
// Marshal returns the binary enconding of the ICMP echo request or
// reply message m.
func (m *icmpMessage) Marshal(psh []byte) ([]byte, error) {
b := []byte{byte(m.Type), byte(m.Code), 0, 0}
if psh != nil {
b = append(psh, b...)
}
if m.Body != nil && m.Body.Len() != 0 {
mb, err := m.Body.Marshal()
if err != nil {
return nil, err
}
b = append(b, mb...)
}
if psh == nil {
return b, nil
}
off, l := 2*net.IPv6len, len(b)-len(psh)
b[off], b[off+1], b[off+2], b[off+3] = byte(l>>24), byte(l>>16), byte(l>>8), byte(l)
csumcv := len(b) - 1 // checksum coverage
s := uint32(0)
for i := 0; i < csumcv; i += 2 {
s += uint32(b[i+1])<<8 | uint32(b[i])
}
if csumcv&1 == 0 {
s += uint32(b[csumcv])
}
s = s>>16 + s&0xffff
s = s + s>>16
// Place checksum back in header; using ^= avoids the
// assumption the checksum bytes are zero.
b[len(psh)+2] ^= byte(^s)
b[len(psh)+3] ^= byte(^s >> 8)
return b[len(psh):], nil
}
// parseICMPMessage parses b as an ICMP message.
func parseICMPMessage(b []byte) (*icmpMessage, error) {
msglen := len(b)
if msglen < 4 {
return nil, errors.New("message too short")
}
m := &icmpMessage{Type: ipv6.ICMPType(b[0]), Code: int(b[1]), Checksum: int(b[2])<<8 | int(b[3])}
if msglen > 4 {
var err error
switch m.Type {
case ipv6.ICMPTypeEchoRequest, ipv6.ICMPTypeEchoReply:
m.Body, err = parseICMPEcho(b[4:])
if err != nil {
return nil, err
}
}
}
return m, nil
}
// imcpEcho represenets an ICMP echo request or reply message body.
type icmpEcho struct {
ID int // identifier
Seq int // sequence number
Data []byte // data
}
func (p *icmpEcho) Len() int {
if p == nil {
return 0
}
return 4 + len(p.Data)
}
// Marshal returns the binary enconding of the ICMP echo request or
// reply message body p.
func (p *icmpEcho) Marshal() ([]byte, error) {
b := make([]byte, 4+len(p.Data))
b[0], b[1] = byte(p.ID>>8), byte(p.ID)
b[2], b[3] = byte(p.Seq>>8), byte(p.Seq)
copy(b[4:], p.Data)
return b, nil
}
// parseICMPEcho parses b as an ICMP echo request or reply message
// body.
func parseICMPEcho(b []byte) (*icmpEcho, error) {
bodylen := len(b)
p := &icmpEcho{ID: int(b[0])<<8 | int(b[1]), Seq: int(b[2])<<8 | int(b[3])}
if bodylen > 4 {
p.Data = make([]byte, bodylen-4)
copy(p.Data, b[4:])
}
return p, nil
}
...@@ -9,62 +9,6 @@ import ( ...@@ -9,62 +9,6 @@ import (
"testing" "testing"
) )
func isLinkLocalUnicast(ip net.IP) bool {
return ip.To4() == nil && ip.To16() != nil && ip.IsLinkLocalUnicast()
}
func loopbackInterface() *net.Interface {
ift, err := net.Interfaces()
if err != nil {
return nil
}
for _, ifi := range ift {
if ifi.Flags&net.FlagLoopback == 0 || ifi.Flags&net.FlagUp == 0 {
continue
}
ifat, err := ifi.Addrs()
if err != nil {
continue
}
for _, ifa := range ifat {
switch ifa := ifa.(type) {
case *net.IPAddr:
if isLinkLocalUnicast(ifa.IP) {
return &ifi
}
case *net.IPNet:
if isLinkLocalUnicast(ifa.IP) {
return &ifi
}
}
}
}
return nil
}
func isMulticastAvailable(ifi *net.Interface) (net.IP, bool) {
if ifi == nil || ifi.Flags&net.FlagUp == 0 || ifi.Flags&net.FlagMulticast == 0 {
return nil, false
}
ifat, err := ifi.Addrs()
if err != nil {
return nil, false
}
for _, ifa := range ifat {
switch ifa := ifa.(type) {
case *net.IPAddr:
if isLinkLocalUnicast(ifa.IP) {
return ifa.IP, true
}
case *net.IPNet:
if isLinkLocalUnicast(ifa.IP) {
return ifa.IP, true
}
}
}
return nil, false
}
func connector(t *testing.T, network, addr string, done chan<- bool) { func connector(t *testing.T, network, addr string, done chan<- bool) {
defer func() { done <- true }() defer func() { done <- true }()
......
...@@ -6,12 +6,16 @@ package ipv6_test ...@@ -6,12 +6,16 @@ package ipv6_test
import ( import (
"bytes" "bytes"
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"time" "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) { func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
...@@ -25,7 +29,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) { ...@@ -25,7 +29,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
if !supportsIPv6 { if !supportsIPv6 {
t.Skip("ipv6 is not supported") t.Skip("ipv6 is not supported")
} }
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil { if ifi == nil {
t.Skipf("not available on %q", runtime.GOOS) t.Skipf("not available on %q", runtime.GOOS)
} }
...@@ -64,7 +68,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) { ...@@ -64,7 +68,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
} }
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
Src: net.IPv6loopback, Src: net.IPv6loopback,
IfIndex: ifi.Index, IfIndex: ifi.Index,
} }
...@@ -106,7 +110,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -106,7 +110,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
if os.Getuid() != 0 { if os.Getuid() != 0 {
t.Skip("must be root") t.Skip("must be root")
} }
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil { if ifi == nil {
t.Skipf("not available on %q", runtime.GOOS) t.Skipf("not available on %q", runtime.GOOS)
} }
...@@ -122,7 +126,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -122,7 +126,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
t.Fatalf("net.ResolveIPAddr failed: %v", err) 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) p := ipv6.NewPacketConn(c)
defer p.Close() defer p.Close()
if err := p.JoinGroup(ifi, dst); err != nil { if err := p.JoinGroup(ifi, dst); err != nil {
...@@ -142,7 +146,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -142,7 +146,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
} }
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
Src: net.IPv6loopback, Src: net.IPv6loopback,
IfIndex: ifi.Index, IfIndex: ifi.Index,
} }
...@@ -168,15 +172,15 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -168,15 +172,15 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
// kernel checksum processing. // kernel checksum processing.
p.SetChecksum(false, -1) p.SetChecksum(false, -1)
} }
wb, err := (&icmpMessage{ wb, err := (&icmp.Message{
Type: ipv6.ICMPTypeEchoRequest, Code: 0, Type: ipv6.ICMPTypeEchoRequest, Code: 0,
Body: &icmpEcho{ Body: &icmp.Echo{
ID: os.Getpid() & 0xffff, Seq: i + 1, ID: os.Getpid() & 0xffff, Seq: i + 1,
Data: []byte("HELLO-R-U-THERE"), Data: []byte("HELLO-R-U-THERE"),
}, },
}).Marshal(psh) }).Marshal(psh)
if err != nil { 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 { if err := p.SetControlMessage(cf, toggle); err != nil {
t.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err)
...@@ -195,8 +199,8 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -195,8 +199,8 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
t.Fatalf("ipv6.PacketConn.ReadFrom failed: %v", err) t.Fatalf("ipv6.PacketConn.ReadFrom failed: %v", err)
} else { } else {
t.Logf("rcvd cmsg: %v", cm) t.Logf("rcvd cmsg: %v", cm)
if m, err := parseICMPMessage(rb[:n]); err != nil { if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
t.Fatalf("parseICMPMessage failed: %v", err) t.Fatalf("icmp.ParseMessage failed: %v", err)
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 { } 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) t.Fatalf("got type=%v, code=%v; expected type=%v, code=%v", m.Type, m.Code, ipv6.ICMPTypeEchoReply, 0)
} }
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
package ipv6_test package ipv6_test
import ( import (
"code.google.com/p/go.net/ipv6"
"fmt" "fmt"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"code.google.com/p/go.net/internal/nettest"
"code.google.com/p/go.net/ipv6"
) )
var udpMultipleGroupListenerTests = []net.Addr{ var udpMultipleGroupListenerTests = []net.Addr{
...@@ -43,7 +45,7 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) { ...@@ -43,7 +45,7 @@ func TestUDPSinglePacketConnWithMultipleGroupListeners(t *testing.T) {
t.Fatalf("net.Interfaces failed: %v", err) t.Fatalf("net.Interfaces failed: %v", err)
} }
for i, ifi := range ift { for i, ifi := range ift {
if _, ok := isMulticastAvailable(&ifi); !ok { if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
continue continue
} }
if err := p.JoinGroup(&ifi, gaddr); err != nil { if err := p.JoinGroup(&ifi, gaddr); err != nil {
...@@ -91,7 +93,7 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) { ...@@ -91,7 +93,7 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
t.Fatalf("net.Interfaces failed: %v", err) t.Fatalf("net.Interfaces failed: %v", err)
} }
for i, ifi := range ift { for i, ifi := range ift {
if _, ok := isMulticastAvailable(&ifi); !ok { if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
continue continue
} }
for _, p := range ps { for _, p := range ps {
...@@ -132,7 +134,7 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -132,7 +134,7 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
t.Fatalf("net.Interfaces failed: %v", err) t.Fatalf("net.Interfaces failed: %v", err)
} }
for i, ifi := range ift { for i, ifi := range ift {
ip, ok := isMulticastAvailable(&ifi) ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
if !ok { if !ok {
continue continue
} }
...@@ -181,7 +183,7 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -181,7 +183,7 @@ func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
t.Fatalf("net.Interfaces failed: %v", err) t.Fatalf("net.Interfaces failed: %v", err)
} }
for i, ifi := range ift { for i, ifi := range ift {
if _, ok := isMulticastAvailable(&ifi); !ok { if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
continue continue
} }
if err := p.JoinGroup(&ifi, &gaddr); err != nil { if err := p.JoinGroup(&ifi, &gaddr); err != nil {
...@@ -220,7 +222,7 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -220,7 +222,7 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
t.Fatalf("net.Interfaces failed: %v", err) t.Fatalf("net.Interfaces failed: %v", err)
} }
for i, ifi := range ift { for i, ifi := range ift {
ip, ok := isMulticastAvailable(&ifi) ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
if !ok { if !ok {
continue continue
} }
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
package ipv6_test package ipv6_test
import ( import (
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"code.google.com/p/go.net/internal/nettest"
"code.google.com/p/go.net/ipv6"
) )
var packetConnMulticastSocketOptionTests = []struct { var packetConnMulticastSocketOptionTests = []struct {
...@@ -28,7 +30,7 @@ func TestPacketConnMulticastSocketOptions(t *testing.T) { ...@@ -28,7 +30,7 @@ func TestPacketConnMulticastSocketOptions(t *testing.T) {
if !supportsIPv6 { if !supportsIPv6 {
t.Skip("ipv6 is not supported") t.Skip("ipv6 is not supported")
} }
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
if ifi == nil { if ifi == nil {
t.Skipf("not available on %q", runtime.GOOS) t.Skipf("not available on %q", runtime.GOOS)
} }
......
...@@ -6,11 +6,14 @@ package ipv6_test ...@@ -6,11 +6,14 @@ package ipv6_test
import ( import (
"bytes" "bytes"
"code.google.com/p/go.net/ipv6"
"net" "net"
"runtime" "runtime"
"sync" "sync"
"testing" "testing"
"code.google.com/p/go.net/internal/iana"
"code.google.com/p/go.net/internal/nettest"
"code.google.com/p/go.net/ipv6"
) )
func benchmarkUDPListener() (net.PacketConn, net.Addr, error) { func benchmarkUDPListener() (net.PacketConn, net.Addr, error) {
...@@ -61,7 +64,7 @@ func BenchmarkReadWriteIPv6UDP(b *testing.B) { ...@@ -61,7 +64,7 @@ func BenchmarkReadWriteIPv6UDP(b *testing.B) {
if err := p.SetControlMessage(cf, true); err != nil { if err := p.SetControlMessage(cf, true); err != nil {
b.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err) b.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err)
} }
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128) wb, rb := []byte("HELLO-R-U-THERE"), make([]byte, 128)
b.ResetTimer() b.ResetTimer()
...@@ -72,7 +75,7 @@ func BenchmarkReadWriteIPv6UDP(b *testing.B) { ...@@ -72,7 +75,7 @@ func BenchmarkReadWriteIPv6UDP(b *testing.B) {
func benchmarkReadWriteIPv6UDP(b *testing.B, p *ipv6.PacketConn, wb, rb []byte, dst net.Addr, ifi *net.Interface) { func benchmarkReadWriteIPv6UDP(b *testing.B, p *ipv6.PacketConn, wb, rb []byte, dst net.Addr, ifi *net.Interface) {
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
HopLimit: 1, HopLimit: 1,
} }
if ifi != nil { if ifi != nil {
...@@ -110,7 +113,7 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) { ...@@ -110,7 +113,7 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) {
t.Fatalf("net.ResolveUDPAddr failed: %v", err) t.Fatalf("net.ResolveUDPAddr failed: %v", err)
} }
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
wb := []byte("HELLO-R-U-THERE") wb := []byte("HELLO-R-U-THERE")
...@@ -131,7 +134,7 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) { ...@@ -131,7 +134,7 @@ func TestPacketConnConcurrentReadWriteUnicastUDP(t *testing.T) {
writer := func(toggle bool) { writer := func(toggle bool) {
defer wg.Done() defer wg.Done()
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
Src: net.IPv6loopback, Src: net.IPv6loopback,
} }
if ifi != nil { if ifi != nil {
......
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
package ipv6_test package ipv6_test
import ( import (
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"code.google.com/p/go.net/ipv6"
) )
var supportsIPv6 bool var supportsIPv6 bool
......
...@@ -6,12 +6,16 @@ package ipv6_test ...@@ -6,12 +6,16 @@ package ipv6_test
import ( import (
"bytes" "bytes"
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"time" "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 TestPacketConnReadWriteUnicastUDP(t *testing.T) { func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
...@@ -37,11 +41,11 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { ...@@ -37,11 +41,11 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
} }
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
Src: net.IPv6loopback, Src: net.IPv6loopback,
} }
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
if ifi != nil { if ifi != nil {
cm.IfIndex = ifi.Index cm.IfIndex = ifi.Index
} }
...@@ -99,13 +103,13 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -99,13 +103,13 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
t.Fatalf("net.ResolveIPAddr failed: %v", err) 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)
cm := ipv6.ControlMessage{ cm := ipv6.ControlMessage{
TrafficClass: DiffServAF11 | CongestionExperienced, TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
Src: net.IPv6loopback, Src: net.IPv6loopback,
} }
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
ifi := loopbackInterface() ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
if ifi != nil { if ifi != nil {
cm.IfIndex = ifi.Index cm.IfIndex = ifi.Index
} }
...@@ -130,15 +134,15 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -130,15 +134,15 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
// kernel checksum processing. // kernel checksum processing.
p.SetChecksum(false, -1) p.SetChecksum(false, -1)
} }
wb, err := (&icmpMessage{ wb, err := (&icmp.Message{
Type: ipv6.ICMPTypeEchoRequest, Code: 0, Type: ipv6.ICMPTypeEchoRequest, Code: 0,
Body: &icmpEcho{ Body: &icmp.Echo{
ID: os.Getpid() & 0xffff, Seq: i + 1, ID: os.Getpid() & 0xffff, Seq: i + 1,
Data: []byte("HELLO-R-U-THERE"), Data: []byte("HELLO-R-U-THERE"),
}, },
}).Marshal(psh) }).Marshal(psh)
if err != nil { 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 { if err := p.SetControlMessage(cf, toggle); err != nil {
t.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv6.PacketConn.SetControlMessage failed: %v", err)
...@@ -160,8 +164,8 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -160,8 +164,8 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
t.Fatalf("ipv6.PacketConn.ReadFrom failed: %v", err) t.Fatalf("ipv6.PacketConn.ReadFrom failed: %v", err)
} else { } else {
t.Logf("rcvd cmsg: %v", cm) t.Logf("rcvd cmsg: %v", cm)
if m, err := parseICMPMessage(rb[:n]); err != nil { if m, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]); err != nil {
t.Fatalf("parseICMPMessage failed: %v", err) t.Fatalf("icmp.ParseMessage failed: %v", err)
} else if m.Type != ipv6.ICMPTypeEchoReply || m.Code != 0 { } 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) t.Fatalf("got type=%v, code=%v; expected type=%v, code=%v", m.Type, m.Code, ipv6.ICMPTypeEchoReply, 0)
} }
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
package ipv6_test package ipv6_test
import ( import (
"code.google.com/p/go.net/ipv6"
"net" "net"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"code.google.com/p/go.net/internal/iana"
"code.google.com/p/go.net/ipv6"
) )
func TestConnUnicastSocketOptions(t *testing.T) { func TestConnUnicastSocketOptions(t *testing.T) {
...@@ -79,7 +81,7 @@ type testIPv6UnicastConn interface { ...@@ -79,7 +81,7 @@ type testIPv6UnicastConn interface {
} }
func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) { func testUnicastSocketOptions(t *testing.T, c testIPv6UnicastConn) {
tclass := DiffServCS0 | NotECNTransport tclass := iana.DiffServCS0 | iana.NotECNTransport
if err := c.SetTrafficClass(tclass); err != nil { if err := c.SetTrafficClass(tclass); err != nil {
t.Fatalf("ipv6.Conn.SetTrafficClass failed: %v", err) t.Fatalf("ipv6.Conn.SetTrafficClass failed: %v", 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