Commit d587440b authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: use unsafe.Pointer instead of uintptr

Fixes golang/go#7173.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/90820044
parent 9704df96
......@@ -22,7 +22,7 @@ func setIPv6ReceiveTrafficClass(fd int, v bool) error {
func ipv6ReceiveHopLimit(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -30,13 +30,13 @@ func ipv6ReceiveHopLimit(fd int) (bool, error) {
func setIPv6ReceiveHopLimit(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, unsafe.Pointer(&vv), 4))
}
func ipv6ReceivePacketInfo(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -44,7 +44,7 @@ func ipv6ReceivePacketInfo(fd int) (bool, error) {
func setIPv6ReceivePacketInfo(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, unsafe.Pointer(&vv), 4))
}
func ipv6PathMTU(fd int) (int, error) {
......@@ -62,12 +62,12 @@ func setIPv6ReceivePathMTU(fd int, v bool) error {
func ipv6ICMPFilter(fd int) (*ICMPFilter, error) {
var v ICMPFilter
l := sysSockoptLen(sysSizeofICMPFilter)
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, uintptr(unsafe.Pointer(&v.sysICMPFilter)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&v.sysICMPFilter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
return &v, nil
}
func setIPv6ICMPFilter(fd int, f *ICMPFilter) error {
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, uintptr(unsafe.Pointer(&f.sysICMPFilter)), sysSizeofICMPFilter))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
}
......@@ -16,5 +16,5 @@ func setIPv6Checksum(fd int, on bool, offset int) error {
offset = -1
}
v := int32(offset)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, uintptr(unsafe.Pointer(&v)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, unsafe.Pointer(&v), 4))
}
......@@ -14,5 +14,5 @@ func setIPv6Checksum(fd int, on bool, offset int) error {
offset = -1
}
v := int32(offset)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolReserved, sysSockoptChecksum, uintptr(unsafe.Pointer(&v)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolReserved, sysSockoptChecksum, unsafe.Pointer(&v), 4))
}
......@@ -15,7 +15,7 @@ import (
func ipv6TrafficClass(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, unsafe.Pointer(&v), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
......@@ -23,13 +23,13 @@ func ipv6TrafficClass(fd int) (int, error) {
func setIPv6TrafficClass(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, unsafe.Pointer(&vv), 4))
}
func ipv6HopLimit(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, unsafe.Pointer(&v), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
......@@ -37,13 +37,13 @@ func ipv6HopLimit(fd int) (int, error) {
func setIPv6HopLimit(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, unsafe.Pointer(&vv), 4))
}
func ipv6Checksum(fd int) (bool, int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, unsafe.Pointer(&v), &l); err != nil {
return false, 0, os.NewSyscallError("getsockopt", err)
}
on := true
......@@ -56,7 +56,7 @@ func ipv6Checksum(fd int) (bool, int, error) {
func ipv6MulticastHopLimit(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, unsafe.Pointer(&v), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
......@@ -64,13 +64,13 @@ func ipv6MulticastHopLimit(fd int) (int, error) {
func setIPv6MulticastHopLimit(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, unsafe.Pointer(&vv), 4))
}
func ipv6MulticastInterface(fd int) (*net.Interface, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, unsafe.Pointer(&v), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
if v == 0 {
......@@ -88,13 +88,13 @@ func setIPv6MulticastInterface(fd int, ifi *net.Interface) error {
if ifi != nil {
v = int32(ifi.Index)
}
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, uintptr(unsafe.Pointer(&v)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, unsafe.Pointer(&v), 4))
}
func ipv6MulticastLoopback(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -102,7 +102,7 @@ func ipv6MulticastLoopback(fd int) (bool, error) {
func setIPv6MulticastLoopback(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, unsafe.Pointer(&vv), 4))
}
func joinIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
......@@ -111,7 +111,7 @@ func joinIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
if ifi != nil {
mreq.IfIndex = uint32(ifi.Index)
}
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptJoinGroup, uintptr(unsafe.Pointer(&mreq)), sysSizeofMulticastReq))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptJoinGroup, unsafe.Pointer(&mreq), sysSizeofMulticastReq))
}
func leaveIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
......@@ -120,5 +120,5 @@ func leaveIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
if ifi != nil {
mreq.IfIndex = uint32(ifi.Index)
}
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptLeaveGroup, uintptr(unsafe.Pointer(&mreq)), sysSizeofMulticastReq))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptLeaveGroup, unsafe.Pointer(&mreq), sysSizeofMulticastReq))
}
......@@ -14,7 +14,7 @@ import (
func ipv6ReceiveTrafficClass(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -22,13 +22,13 @@ func ipv6ReceiveTrafficClass(fd int) (bool, error) {
func setIPv6ReceiveTrafficClass(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, unsafe.Pointer(&vv), 4))
}
func ipv6ReceiveHopLimit(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -36,13 +36,13 @@ func ipv6ReceiveHopLimit(fd int) (bool, error) {
func setIPv6ReceiveHopLimit(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, unsafe.Pointer(&vv), 4))
}
func ipv6ReceivePacketInfo(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -50,13 +50,13 @@ func ipv6ReceivePacketInfo(fd int) (bool, error) {
func setIPv6ReceivePacketInfo(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, unsafe.Pointer(&vv), 4))
}
func ipv6PathMTU(fd int) (int, error) {
var v sysMTUInfo
l := sysSockoptLen(sysSizeofMTUInfo)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptPathMTU, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptPathMTU, unsafe.Pointer(&v), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v.MTU), nil
......@@ -65,7 +65,7 @@ func ipv6PathMTU(fd int) (int, error) {
func ipv6ReceivePathMTU(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, uintptr(unsafe.Pointer(&v)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, unsafe.Pointer(&v), &l); err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
......@@ -73,18 +73,18 @@ func ipv6ReceivePathMTU(fd int) (bool, error) {
func setIPv6ReceivePathMTU(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, uintptr(unsafe.Pointer(&vv)), 4))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, unsafe.Pointer(&vv), 4))
}
func ipv6ICMPFilter(fd int) (*ICMPFilter, error) {
var v ICMPFilter
l := sysSockoptLen(sysSizeofICMPFilter)
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, uintptr(unsafe.Pointer(&v.sysICMPFilter)), &l); err != nil {
if err := getsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&v.sysICMPFilter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
return &v, nil
}
func setIPv6ICMPFilter(fd int, f *ICMPFilter) error {
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, uintptr(unsafe.Pointer(&f.sysICMPFilter)), sysSizeofICMPFilter))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6ICMP, sysSockoptICMPFilter, unsafe.Pointer(&f.sysICMPFilter), sysSizeofICMPFilter))
}
......@@ -27,15 +27,15 @@ const (
var socketcall func(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
func getsockopt(fd int, level int, name int, v uintptr, l *sysSockoptLen) error {
func getsockopt(fd int, level int, name int, v unsafe.Pointer, l *sysSockoptLen) error {
if _, errno := socketcall(_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd int, level int, name int, v uintptr, l uintptr) error {
if _, errno := socketcall(_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), v, l, 0); errno != 0 {
func setsockopt(fd int, level int, name int, v unsafe.Pointer, l uintptr) error {
if _, errno := socketcall(_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
return nil
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.2
// +build go1.2 go1.3
package ipv6
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.1,!go1.2
// +build go1.1,!go1.2,!go1.3
package ipv6
......
......@@ -11,14 +11,14 @@ import (
"unsafe"
)
func getsockopt(fd int, level, name int, v uintptr, l *sysSockoptLen) error {
func getsockopt(fd int, level, name int, v unsafe.Pointer, l *sysSockoptLen) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(fd int, level int, name int, v uintptr, l uintptr) error {
func setsockopt(fd int, level int, name int, v unsafe.Pointer, l uintptr) error {
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment