github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/ipv6/sockopt_test.go (about) 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. 4 5 package ipv6_test 6 7 import ( 8 "fmt" 9 "net" 10 "runtime" 11 "testing" 12 13 "github.com/hxx258456/ccgo/net/internal/iana" 14 "github.com/hxx258456/ccgo/net/ipv6" 15 "github.com/hxx258456/ccgo/net/nettest" 16 ) 17 18 func TestConnInitiatorPathMTU(t *testing.T) { 19 switch runtime.GOOS { 20 case "fuchsia", "hurd", "js", "nacl", "plan9", "windows", "zos": 21 t.Skipf("not supported on %s", runtime.GOOS) 22 } 23 if !nettest.SupportsIPv6() { 24 t.Skip("ipv6 is not supported") 25 } 26 27 ln, err := net.Listen("tcp6", "[::1]:0") 28 if err != nil { 29 t.Fatal(err) 30 } 31 defer ln.Close() 32 33 done := make(chan bool) 34 go acceptor(t, ln, done) 35 36 c, err := net.Dial("tcp6", ln.Addr().String()) 37 if err != nil { 38 t.Fatal(err) 39 } 40 defer c.Close() 41 42 if pmtu, err := ipv6.NewConn(c).PathMTU(); err != nil { 43 t.Fatal(err) 44 } else { 45 t.Logf("path mtu for %v: %v", c.RemoteAddr(), pmtu) 46 } 47 48 <-done 49 } 50 51 func TestConnResponderPathMTU(t *testing.T) { 52 switch runtime.GOOS { 53 case "fuchsia", "hurd", "js", "nacl", "plan9", "windows", "zos": 54 t.Skipf("not supported on %s", runtime.GOOS) 55 } 56 if !nettest.SupportsIPv6() { 57 t.Skip("ipv6 is not supported") 58 } 59 60 ln, err := net.Listen("tcp6", "[::1]:0") 61 if err != nil { 62 t.Fatal(err) 63 } 64 defer ln.Close() 65 66 done := make(chan bool) 67 go connector(t, "tcp6", ln.Addr().String(), done) 68 69 c, err := ln.Accept() 70 if err != nil { 71 t.Fatal(err) 72 } 73 defer c.Close() 74 75 if pmtu, err := ipv6.NewConn(c).PathMTU(); err != nil { 76 t.Fatal(err) 77 } else { 78 t.Logf("path mtu for %v: %v", c.RemoteAddr(), pmtu) 79 } 80 81 <-done 82 } 83 84 func TestPacketConnChecksum(t *testing.T) { 85 switch runtime.GOOS { 86 case "fuchsia", "hurd", "js", "nacl", "plan9", "windows": 87 t.Skipf("not supported on %s", runtime.GOOS) 88 } 89 if !nettest.SupportsIPv6() { 90 t.Skip("ipv6 is not supported") 91 } 92 if !nettest.SupportsRawSocket() { 93 t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) 94 } 95 96 c, err := net.ListenPacket(fmt.Sprintf("ip6:%d", iana.ProtocolOSPFIGP), "::") // OSPF for IPv6 97 if err != nil { 98 t.Fatal(err) 99 } 100 defer c.Close() 101 102 p := ipv6.NewPacketConn(c) 103 offset := 12 // see RFC 5340 104 105 for _, toggle := range []bool{false, true} { 106 if err := p.SetChecksum(toggle, offset); err != nil { 107 if toggle { 108 t.Fatalf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err) 109 } else { 110 // Some platforms never allow to disable the kernel 111 // checksum processing. 112 t.Logf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err) 113 } 114 } 115 if on, offset, err := p.Checksum(); err != nil { 116 t.Fatal(err) 117 } else { 118 t.Logf("kernel checksum processing enabled=%v, offset=%v", on, offset) 119 } 120 } 121 }