1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 "golang.org/x/net/internal/nettest"
14 "golang.org/x/net/ipv6"
17 var icmpStringTests = []struct {
21 {ipv6.ICMPTypeDestinationUnreachable, "destination unreachable"},
26 func TestICMPString(t *testing.T) {
27 for _, tt := range icmpStringTests {
30 t.Errorf("got %s; want %s", s, tt.out)
35 func TestICMPFilter(t *testing.T) {
37 case "nacl", "plan9", "windows":
38 t.Skipf("not supported on %s", runtime.GOOS)
42 for _, toggle := range []bool{false, true} {
44 for _, typ := range []ipv6.ICMPType{
45 ipv6.ICMPTypeDestinationUnreachable,
46 ipv6.ICMPTypeEchoReply,
47 ipv6.ICMPTypeNeighborSolicitation,
48 ipv6.ICMPTypeDuplicateAddressConfirmation,
52 t.Errorf("ipv6.ICMPFilter.Set(%v, false) failed", typ)
55 if !f.WillBlock(typ) {
56 t.Errorf("ipv6.ICMPFilter.Set(%v, true) failed", typ)
62 func TestSetICMPFilter(t *testing.T) {
64 case "nacl", "plan9", "windows":
65 t.Skipf("not supported on %s", runtime.GOOS)
68 t.Skip("ipv6 is not supported")
70 if m, ok := nettest.SupportsRawIPSocket(); !ok {
74 c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
80 p := ipv6.NewPacketConn(c)
84 f.Accept(ipv6.ICMPTypeEchoRequest)
85 f.Accept(ipv6.ICMPTypeEchoReply)
86 if err := p.SetICMPFilter(&f); err != nil {
89 kf, err := p.ICMPFilter()
93 if !reflect.DeepEqual(kf, &f) {
94 t.Fatalf("got %#v; want %#v", kf, f)