Update dependencies

This commit is contained in:
Zlatko Čalušić
2017-06-25 12:06:41 +02:00
parent 0c22253d41
commit 4873fd9ffe
47 changed files with 11212 additions and 9462 deletions

View File

@@ -129,14 +129,14 @@ func (cm *ControlMessage) Parse(b []byte) error {
if lvl != iana.ProtocolIPv6 {
continue
}
switch typ {
case ctlOpts[ctlTrafficClass].name:
switch {
case typ == ctlOpts[ctlTrafficClass].name && l >= ctlOpts[ctlTrafficClass].length:
ctlOpts[ctlTrafficClass].parse(cm, m.Data(l))
case ctlOpts[ctlHopLimit].name:
case typ == ctlOpts[ctlHopLimit].name && l >= ctlOpts[ctlHopLimit].length:
ctlOpts[ctlHopLimit].parse(cm, m.Data(l))
case ctlOpts[ctlPacketInfo].name:
case typ == ctlOpts[ctlPacketInfo].name && l >= ctlOpts[ctlPacketInfo].length:
ctlOpts[ctlPacketInfo].parse(cm, m.Data(l))
case ctlOpts[ctlPathMTU].name:
case typ == ctlOpts[ctlPathMTU].name && l >= ctlOpts[ctlPathMTU].length:
ctlOpts[ctlPathMTU].parse(cm, m.Data(l))
}
}

View File

@@ -17,7 +17,7 @@ func marshal2292HopLimit(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, 4)
if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
}
return m.Next(4)
}

View File

@@ -18,26 +18,26 @@ func marshalTrafficClass(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_TCLASS, 4)
if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass))
socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.TrafficClass))
}
return m.Next(4)
}
func parseTrafficClass(cm *ControlMessage, b []byte) {
cm.TrafficClass = int(nativeEndian.Uint32(b[:4]))
cm.TrafficClass = int(socket.NativeEndian.Uint32(b[:4]))
}
func marshalHopLimit(b []byte, cm *ControlMessage) []byte {
m := socket.ControlMessage(b)
m.MarshalHeader(iana.ProtocolIPv6, sysIPV6_HOPLIMIT, 4)
if cm != nil {
nativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
socket.NativeEndian.PutUint32(m.Data(4), uint32(cm.HopLimit))
}
return m.Next(4)
}
func parseHopLimit(cm *ControlMessage, b []byte) {
cm.HopLimit = int(nativeEndian.Uint32(b[:4]))
cm.HopLimit = int(socket.NativeEndian.Uint32(b[:4]))
}
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {

21
vendor/golang.org/x/net/ipv6/control_test.go generated vendored Normal file
View File

@@ -0,0 +1,21 @@
// Copyright 2017 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 (
"testing"
"golang.org/x/net/ipv6"
)
func TestControlMessageParseWithFuzz(t *testing.T) {
var cm ipv6.ControlMessage
for _, fuzz := range []string{
"\f\x00\x00\x00)\x00\x00\x00.\x00\x00\x00",
"\f\x00\x00\x00)\x00\x00\x00,\x00\x00\x00",
} {
cm.Parse([]byte(fuzz))
}
}

View File

@@ -5,10 +5,8 @@
package ipv6
import (
"encoding/binary"
"errors"
"net"
"unsafe"
)
var (
@@ -17,20 +15,8 @@ var (
errInvalidConnType = errors.New("invalid conn type")
errOpNoSupport = errors.New("operation not supported")
errNoSuchInterface = errors.New("no such interface")
nativeEndian binary.ByteOrder
)
func init() {
i := uint32(1)
b := (*[4]byte)(unsafe.Pointer(&i))
if b[0] == 1 {
nativeEndian = binary.LittleEndian
} else {
nativeEndian = binary.BigEndian
}
}
func boolint(b bool) int {
if b {
return 1
@@ -51,3 +37,21 @@ func netAddrToIP16(a net.Addr) net.IP {
}
return nil
}
func opAddr(a net.Addr) net.Addr {
switch a.(type) {
case *net.TCPAddr:
if a == nil {
return nil
}
case *net.UDPAddr:
if a == nil {
return nil
}
case *net.IPAddr:
if a == nil {
return nil
}
}
return a
}

View File

@@ -5,7 +5,6 @@
package ipv6_test
import (
"fmt"
"net"
"runtime"
"testing"
@@ -70,13 +69,16 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
}
for _, gaddr := range udpMultipleGroupListenerTests {
c1, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port
c1, err := net.ListenPacket("udp6", "[ff02::]:0") // wildcard address with reusable port
if err != nil {
t.Fatal(err)
}
defer c1.Close()
c2, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port
_, port, err := net.SplitHostPort(c1.LocalAddr().String())
if err != nil {
t.Fatal(err)
}
c2, err := net.ListenPacket("udp6", net.JoinHostPort("ff02::", port)) // wildcard address with reusable port
if err != nil {
t.Fatal(err)
}
@@ -132,16 +134,29 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
if err != nil {
t.Fatal(err)
}
port := "0"
for i, ifi := range ift {
ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
if !ok {
continue
}
c, err := net.ListenPacket("udp6", fmt.Sprintf("[%s%%%s]:1024", ip.String(), ifi.Name)) // unicast address with non-reusable port
c, err := net.ListenPacket("udp6", net.JoinHostPort(ip.String()+"%"+ifi.Name, port)) // unicast address with non-reusable port
if err != nil {
t.Fatal(err)
// The listen may fail when the serivce is
// already in use, but it's fine because the
// purpose of this is not to test the
// bookkeeping of IP control block inside the
// kernel.
t.Log(err)
continue
}
defer c.Close()
if port == "0" {
_, port, err = net.SplitHostPort(c.LocalAddr().String())
if err != nil {
t.Fatal(err)
}
}
p := ipv6.NewPacketConn(c)
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
t.Fatal(err)
@@ -227,7 +242,7 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
if !ok {
continue
}
c, err := net.ListenPacket("ip6:ipv6-icmp", fmt.Sprintf("%s%%%s", ip.String(), ifi.Name)) // unicast address
c, err := net.ListenPacket("ip6:ipv6-icmp", ip.String()+"%"+ifi.Name) // unicast address
if err != nil {
t.Fatal(err)
}

View File

@@ -49,7 +49,7 @@ func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (n
case *net.IPConn:
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
default:
return 0, &net.OpError{Op: "write", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Err: errInvalidConnType}
return 0, &net.OpError{Op: "write", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Addr: opAddr(dst), Err: errInvalidConnType}
}
return
}

View File

@@ -51,7 +51,7 @@ func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (in
}
err := c.SendMsg(&m, 0)
if err != nil {
err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Addr: opAddr(dst), Err: err}
}
return m.N, err
}