git » go-net » commit d06f1c2

ipv4/ipv6: common {get,set}sockopt to internal/netsyscall

author Alberto Bertogli
2016-09-16 20:18:42 UTC
committer Alberto Bertogli
2016-09-16 20:42:07 UTC
parent 71a035914f99bb58fe82eac0f1289f10963d876c

ipv4/ipv6: common {get,set}sockopt to internal/netsyscall

The low-level "unsafe" variants of the getsockopt/setockopt syscalls
are duplicated between ipv4 and ipv6.  It's likely these will be
needed in an upcoming "unix" package as well.

So to avoid copying them a third time, his commit moves them to a new
internal/netsyscall/, and updates ipv4 and ipv6 to make use of it.

{ipv6 => internal/netsyscall}/syscall_linux_386.go +3 -3
{ipv6 => internal/netsyscall}/syscall_unix.go +3 -3
{ipv4 => internal/netsyscall}/syscall_windows.go +3 -3
{ipv4 => internal/netsyscall}/thunk_linux_386.s +0 -0
ipv4/bpfopt_linux.go +2 -1
ipv4/sockopt_asmreq_posix.go +4 -3
ipv4/sockopt_asmreqn_unix.go +3 -2
ipv4/sockopt_posix.go +5 -4
ipv4/sockopt_ssmreq_unix.go +3 -2
ipv4/syscall_linux_386.go +0 -31
ipv4/syscall_unix.go +0 -26
ipv6/bpfopt_linux.go +2 -1
ipv6/sockopt_asmreq_posix.go +3 -1
ipv6/sockopt_posix.go +9 -7
ipv6/sockopt_ssmreq_unix.go +4 -2
ipv6/syscall_windows.go +0 -18
ipv6/thunk_linux_386.s +0 -8

diff --git a/ipv6/syscall_linux_386.go b/internal/netsyscall/syscall_linux_386.go
similarity index 82%
rename from ipv6/syscall_linux_386.go
rename to internal/netsyscall/syscall_linux_386.go
index 5184dbe..ea5da1a 100644
--- a/ipv6/syscall_linux_386.go
+++ b/internal/netsyscall/syscall_linux_386.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package ipv6
+package netsyscall
 
 import (
 	"syscall"
@@ -16,14 +16,14 @@ const (
 
 func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
 
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
+func Getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
 	if _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil
 }
 
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
+func Setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
 	if _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
 		return error(errno)
 	}
diff --git a/ipv6/syscall_unix.go b/internal/netsyscall/syscall_unix.go
similarity index 81%
rename from ipv6/syscall_unix.go
rename to internal/netsyscall/syscall_unix.go
index 52eb9bd..5f10d75 100644
--- a/ipv6/syscall_unix.go
+++ b/internal/netsyscall/syscall_unix.go
@@ -4,21 +4,21 @@
 
 // +build darwin dragonfly freebsd linux,!386 netbsd openbsd
 
-package ipv6
+package netsyscall
 
 import (
 	"syscall"
 	"unsafe"
 )
 
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
+func Getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
 	if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
 		return error(errno)
 	}
 	return nil
 }
 
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
+func Setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
 	if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
 		return error(errno)
 	}
diff --git a/ipv4/syscall_windows.go b/internal/netsyscall/syscall_windows.go
similarity index 75%
rename from ipv4/syscall_windows.go
rename to internal/netsyscall/syscall_windows.go
index 0f42d22..ef86835 100644
--- a/ipv4/syscall_windows.go
+++ b/internal/netsyscall/syscall_windows.go
@@ -2,17 +2,17 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package ipv4
+package netsyscall
 
 import (
 	"syscall"
 	"unsafe"
 )
 
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
+func Getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
 	return syscall.Getsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), (*int32)(unsafe.Pointer(l)))
 }
 
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
+func Setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
 	return syscall.Setsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), int32(l))
 }
diff --git a/ipv4/thunk_linux_386.s b/internal/netsyscall/thunk_linux_386.s
similarity index 100%
rename from ipv4/thunk_linux_386.s
rename to internal/netsyscall/thunk_linux_386.s
diff --git a/ipv4/bpfopt_linux.go b/ipv4/bpfopt_linux.go
index e9bbda9..10aebeb 100644
--- a/ipv4/bpfopt_linux.go
+++ b/ipv4/bpfopt_linux.go
@@ -10,6 +10,7 @@ import (
 
 	"golang.org/x/net/bpf"
 	"golang.org/x/net/internal/netreflect"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 // SetBPF attaches a BPF program to the connection.
@@ -24,5 +25,5 @@ func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
 		Len:    uint16(len(filter)),
 		Filter: (*sysSockFilter)(unsafe.Pointer(&filter[0])),
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
 }
diff --git a/ipv4/sockopt_asmreq_posix.go b/ipv4/sockopt_asmreq_posix.go
index ef9b139..8f7a9f9 100644
--- a/ipv4/sockopt_asmreq_posix.go
+++ b/ipv4/sockopt_asmreq_posix.go
@@ -12,6 +12,7 @@ import (
 	"unsafe"
 
 	"golang.org/x/net/internal/iana"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
@@ -19,13 +20,13 @@ func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error
 	if err := setIPMreqInterface(&mreq, ifi); err != nil {
 		return err
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sysSizeofIPMreq))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sysSizeofIPMreq))
 }
 
 func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
 	var b [4]byte
 	l := uint32(4)
-	if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
@@ -42,5 +43,5 @@ func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
 	}
 	var b [4]byte
 	copy(b[:], ip)
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
 }
diff --git a/ipv4/sockopt_asmreqn_unix.go b/ipv4/sockopt_asmreqn_unix.go
index 9d4069f..6c180a6 100644
--- a/ipv4/sockopt_asmreqn_unix.go
+++ b/ipv4/sockopt_asmreqn_unix.go
@@ -12,12 +12,13 @@ import (
 	"unsafe"
 
 	"golang.org/x/net/internal/iana"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
 	var mreqn sysIPMreqn
 	l := uint32(sysSizeofIPMreqn)
-	if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	if mreqn.Ifindex == 0 {
@@ -38,5 +39,5 @@ func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) erro
 	if grp != nil {
 		mreqn.Multiaddr = [4]byte{grp[0], grp[1], grp[2], grp[3]}
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sysSizeofIPMreqn))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sysSizeofIPMreqn))
 }
diff --git a/ipv4/sockopt_posix.go b/ipv4/sockopt_posix.go
index 0b7d6b6..a5b65b1 100644
--- a/ipv4/sockopt_posix.go
+++ b/ipv4/sockopt_posix.go
@@ -12,6 +12,7 @@ import (
 	"unsafe"
 
 	"golang.org/x/net/internal/iana"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 func getInt(s uintptr, opt *sockOpt) (int, error) {
@@ -26,7 +27,7 @@ func getInt(s uintptr, opt *sockOpt) (int, error) {
 		p = unsafe.Pointer(&b)
 		l = 1
 	}
-	if err := getsockopt(s, iana.ProtocolIP, opt.name, p, &l); err != nil {
+	if err := netsyscall.Getsockopt(s, iana.ProtocolIP, opt.name, p, &l); err != nil {
 		return 0, os.NewSyscallError("getsockopt", err)
 	}
 	if opt.typ == ssoTypeByte {
@@ -48,7 +49,7 @@ func setInt(s uintptr, opt *sockOpt, v int) error {
 		p = unsafe.Pointer(&b)
 		l = 1
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, opt.name, p, l))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, opt.name, p, l))
 }
 
 func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
@@ -85,7 +86,7 @@ func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
 	}
 	var f ICMPFilter
 	l := uint32(sysSizeofICMPFilter)
-	if err := getsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	return &f, nil
@@ -95,7 +96,7 @@ func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
 	if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
 		return errOpNoSupport
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
 }
 
 func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
diff --git a/ipv4/sockopt_ssmreq_unix.go b/ipv4/sockopt_ssmreq_unix.go
index 588e9b9..04bc8f1 100644
--- a/ipv4/sockopt_ssmreq_unix.go
+++ b/ipv4/sockopt_ssmreq_unix.go
@@ -12,6 +12,7 @@ import (
 	"unsafe"
 
 	"golang.org/x/net/internal/iana"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 var freebsd32o64 bool
@@ -35,7 +36,7 @@ func setsockoptGroupReq(s uintptr, name int, ifi *net.Interface, grp net.IP) err
 		p = unsafe.Pointer(&gr)
 		l = sysSizeofGroupReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, name, p, l))
 }
 
 func setsockoptGroupSourceReq(s uintptr, name int, ifi *net.Interface, grp, src net.IP) error {
@@ -57,5 +58,5 @@ func setsockoptGroupSourceReq(s uintptr, name int, ifi *net.Interface, grp, src
 		p = unsafe.Pointer(&gsr)
 		l = sysSizeofGroupSourceReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, iana.ProtocolIP, name, p, l))
 }
diff --git a/ipv4/syscall_linux_386.go b/ipv4/syscall_linux_386.go
deleted file mode 100644
index 84f60bf..0000000
--- a/ipv4/syscall_linux_386.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 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 ipv4
-
-import (
-	"syscall"
-	"unsafe"
-)
-
-const (
-	sysGETSOCKOPT = 0xf
-	sysSETSOCKOPT = 0xe
-)
-
-func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
-
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
-	if _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
-		return error(errno)
-	}
-	return nil
-}
-
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
-	if _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
-		return error(errno)
-	}
-	return nil
-}
diff --git a/ipv4/syscall_unix.go b/ipv4/syscall_unix.go
deleted file mode 100644
index d952763..0000000
--- a/ipv4/syscall_unix.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 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.
-
-// +build darwin dragonfly freebsd linux,!386 netbsd openbsd
-
-package ipv4
-
-import (
-	"syscall"
-	"unsafe"
-)
-
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
-	if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
-		return error(errno)
-	}
-	return nil
-}
-
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
-	if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
-		return error(errno)
-	}
-	return nil
-}
diff --git a/ipv6/bpfopt_linux.go b/ipv6/bpfopt_linux.go
index 328427c..bb0795e 100644
--- a/ipv6/bpfopt_linux.go
+++ b/ipv6/bpfopt_linux.go
@@ -10,6 +10,7 @@ import (
 
 	"golang.org/x/net/bpf"
 	"golang.org/x/net/internal/netreflect"
+	"golang.org/x/net/internal/netsyscall"
 )
 
 // SetBPF attaches a BPF program to the connection.
@@ -24,5 +25,5 @@ func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
 		Len:    uint16(len(filter)),
 		Filter: (*sysSockFilter)(unsafe.Pointer(&filter[0])),
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
 }
diff --git a/ipv6/sockopt_asmreq_posix.go b/ipv6/sockopt_asmreq_posix.go
index 092e398..148e61f 100644
--- a/ipv6/sockopt_asmreq_posix.go
+++ b/ipv6/sockopt_asmreq_posix.go
@@ -10,6 +10,8 @@ import (
 	"net"
 	"os"
 	"unsafe"
+
+	"golang.org/x/net/internal/netsyscall"
 )
 
 func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
@@ -18,5 +20,5 @@ func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) e
 	if ifi != nil {
 		mreq.setIfindex(ifi.Index)
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&mreq), sysSizeofIPv6Mreq))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, unsafe.Pointer(&mreq), sysSizeofIPv6Mreq))
 }
diff --git a/ipv6/sockopt_posix.go b/ipv6/sockopt_posix.go
index 651aa93..5966e5d 100644
--- a/ipv6/sockopt_posix.go
+++ b/ipv6/sockopt_posix.go
@@ -10,6 +10,8 @@ import (
 	"net"
 	"os"
 	"unsafe"
+
+	"golang.org/x/net/internal/netsyscall"
 )
 
 func getInt(s uintptr, opt *sockOpt) (int, error) {
@@ -18,7 +20,7 @@ func getInt(s uintptr, opt *sockOpt) (int, error) {
 	}
 	var i int32
 	l := uint32(4)
-	if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
 		return 0, os.NewSyscallError("getsockopt", err)
 	}
 	return int(i), nil
@@ -29,7 +31,7 @@ func setInt(s uintptr, opt *sockOpt, v int) error {
 		return errOpNoSupport
 	}
 	i := int32(v)
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
 }
 
 func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
@@ -38,7 +40,7 @@ func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
 	}
 	var i int32
 	l := uint32(4)
-	if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	if i == 0 {
@@ -59,7 +61,7 @@ func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
 	if ifi != nil {
 		i = int32(ifi.Index)
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
 }
 
 func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
@@ -68,7 +70,7 @@ func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
 	}
 	var f ICMPFilter
 	l := uint32(sysSizeofICMPv6Filter)
-	if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), &l); err != nil {
 		return nil, os.NewSyscallError("getsockopt", err)
 	}
 	return &f, nil
@@ -78,7 +80,7 @@ func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
 	if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
 		return errOpNoSupport
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), sysSizeofICMPv6Filter))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.sysICMPv6Filter), sysSizeofICMPv6Filter))
 }
 
 func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
@@ -87,7 +89,7 @@ func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
 	}
 	var mi sysIPv6Mtuinfo
 	l := uint32(sysSizeofIPv6Mtuinfo)
-	if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
+	if err := netsyscall.Getsockopt(s, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
 		return nil, 0, os.NewSyscallError("getsockopt", err)
 	}
 	if mi.Addr.Scope_id == 0 {
diff --git a/ipv6/sockopt_ssmreq_unix.go b/ipv6/sockopt_ssmreq_unix.go
index 88f118c..d1265ca 100644
--- a/ipv6/sockopt_ssmreq_unix.go
+++ b/ipv6/sockopt_ssmreq_unix.go
@@ -10,6 +10,8 @@ import (
 	"net"
 	"os"
 	"unsafe"
+
+	"golang.org/x/net/internal/netsyscall"
 )
 
 var freebsd32o64 bool
@@ -33,7 +35,7 @@ func setsockoptGroupReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP)
 		p = unsafe.Pointer(&gr)
 		l = sysSizeofGroupReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, p, l))
 }
 
 func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
@@ -55,5 +57,5 @@ func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp,
 		p = unsafe.Pointer(&gsr)
 		l = sysSizeofGroupSourceReq
 	}
-	return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l))
+	return os.NewSyscallError("setsockopt", netsyscall.Setsockopt(s, opt.level, opt.name, p, l))
 }
diff --git a/ipv6/syscall_windows.go b/ipv6/syscall_windows.go
deleted file mode 100644
index c1f649d..0000000
--- a/ipv6/syscall_windows.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2016 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
-
-import (
-	"syscall"
-	"unsafe"
-)
-
-func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
-	return syscall.Getsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), (*int32)(unsafe.Pointer(l)))
-}
-
-func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
-	return syscall.Setsockopt(syscall.Handle(s), int32(level), int32(name), (*byte)(v), int32(l))
-}
diff --git a/ipv6/thunk_linux_386.s b/ipv6/thunk_linux_386.s
deleted file mode 100644
index daa78bc..0000000
--- a/ipv6/thunk_linux_386.s
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright 2014 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.
-
-// +build go1.2
-
-TEXT	·socketcall(SB),4,$0-36
-	JMP	syscall·socketcall(SB)