mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
All the dropped platforms either don't support raw sockets or the tests pass sucessfully (e.g. ipv4.TestPacketConnReadWriteMulticastICMP on solaris), so the tests can rely on being skipped due to !nettest.SupportsRawSocket(). Also check for errNotImplemented to cover cases where functionality is not available on windows. Change-Id: Ic9107a7ca16e9d9faed4991e1148b493c646ea7d Reviewed-on: https://go-review.googlesource.com/c/net/+/489155 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
97 lines
2.0 KiB
Go
97 lines
2.0 KiB
Go
// 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 (
|
|
"errors"
|
|
"net"
|
|
"reflect"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"golang.org/x/net/ipv6"
|
|
"golang.org/x/net/nettest"
|
|
)
|
|
|
|
var icmpStringTests = []struct {
|
|
in ipv6.ICMPType
|
|
out string
|
|
}{
|
|
{ipv6.ICMPTypeDestinationUnreachable, "destination unreachable"},
|
|
|
|
{256, "<nil>"},
|
|
}
|
|
|
|
func TestICMPString(t *testing.T) {
|
|
for _, tt := range icmpStringTests {
|
|
s := tt.in.String()
|
|
if s != tt.out {
|
|
t.Errorf("got %s; want %s", s, tt.out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestICMPFilter(t *testing.T) {
|
|
switch runtime.GOOS {
|
|
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
|
|
t.Skipf("not supported on %s", runtime.GOOS)
|
|
}
|
|
|
|
var f ipv6.ICMPFilter
|
|
for _, toggle := range []bool{false, true} {
|
|
f.SetAll(toggle)
|
|
for _, typ := range []ipv6.ICMPType{
|
|
ipv6.ICMPTypeDestinationUnreachable,
|
|
ipv6.ICMPTypeEchoReply,
|
|
ipv6.ICMPTypeNeighborSolicitation,
|
|
ipv6.ICMPTypeDuplicateAddressConfirmation,
|
|
} {
|
|
f.Accept(typ)
|
|
if f.WillBlock(typ) {
|
|
t.Errorf("ipv6.ICMPFilter.Set(%v, false) failed", typ)
|
|
}
|
|
f.Block(typ)
|
|
if !f.WillBlock(typ) {
|
|
t.Errorf("ipv6.ICMPFilter.Set(%v, true) failed", typ)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSetICMPFilter(t *testing.T) {
|
|
if !nettest.SupportsIPv6() {
|
|
t.Skip("ipv6 is not supported")
|
|
}
|
|
if !nettest.SupportsRawSocket() {
|
|
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
|
|
}
|
|
|
|
c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
|
|
p := ipv6.NewPacketConn(c)
|
|
|
|
var f ipv6.ICMPFilter
|
|
f.SetAll(true)
|
|
f.Accept(ipv6.ICMPTypeEchoRequest)
|
|
f.Accept(ipv6.ICMPTypeEchoReply)
|
|
if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) {
|
|
t.Skipf("setting ICMP filter not supported: %v", err)
|
|
} else if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
kf, err := p.ICMPFilter()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(kf, &f) {
|
|
t.Fatalf("got %#v; want %#v", kf, f)
|
|
}
|
|
}
|