Commit 0c924584 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: restore use of syscall

This CL restores use of syscall functions and constants that
doesn't break the build on Go 1.1 and beyond.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/92320046
parent 38dcae40
......@@ -8,6 +8,7 @@ package ipv6
import (
"os"
"syscall"
"unsafe"
)
......@@ -20,31 +21,27 @@ 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, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceiveHopLimit(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292HopLimit, boolint(v)))
}
func ipv6ReceivePacketInfo(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceivePacketInfo(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockopt2292PacketInfo, boolint(v)))
}
func ipv6PathMTU(fd int) (int, error) {
......
......@@ -8,13 +8,12 @@ package ipv6
import (
"os"
"unsafe"
"syscall"
)
func setIPv6Checksum(fd int, on bool, offset int) error {
if !on {
offset = -1
}
v := int32(offset)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, unsafe.Pointer(&v), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptChecksum, offset))
}
......@@ -6,13 +6,12 @@ package ipv6
import (
"os"
"unsafe"
"syscall"
)
func setIPv6Checksum(fd int, on bool, offset int) error {
if !on {
offset = -1
}
v := int32(offset)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolReserved, sysSockoptChecksum, unsafe.Pointer(&v), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolReserved, sysSockoptChecksum, offset))
}
......@@ -9,74 +9,67 @@ package ipv6
import (
"net"
"os"
"syscall"
"unsafe"
)
func ipv6TrafficClass(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptTrafficClass)
if err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
return v, nil
}
func setIPv6TrafficClass(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptTrafficClass, v))
}
func ipv6HopLimit(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit)
if err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
return v, nil
}
func setIPv6HopLimit(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptUnicastHopLimit, v))
}
func ipv6Checksum(fd int) (bool, int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptChecksum, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptChecksum)
if err != nil {
return false, 0, os.NewSyscallError("getsockopt", err)
}
on := true
if v == -1 {
on = false
}
return on, int(v), nil
return on, v, nil
}
func ipv6MulticastHopLimit(fd int) (int, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit)
if err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(v), nil
return v, nil
}
func setIPv6MulticastHopLimit(fd, v int) error {
vv := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastHopLimit, v))
}
func ipv6MulticastInterface(fd int) (*net.Interface, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface)
if err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
if v == 0 {
return nil, nil
}
ifi, err := net.InterfaceByIndex(int(v))
ifi, err := net.InterfaceByIndex(v)
if err != nil {
return nil, err
}
......@@ -84,25 +77,23 @@ func ipv6MulticastInterface(fd int) (*net.Interface, error) {
}
func setIPv6MulticastInterface(fd int, ifi *net.Interface) error {
var v int32
var v int
if ifi != nil {
v = int32(ifi.Index)
v = ifi.Index
}
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, unsafe.Pointer(&v), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastInterface, v))
}
func ipv6MulticastLoopback(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6MulticastLoopback(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptMulticastLoopback, boolint(v)))
}
func joinIPv6Group(fd int, ifi *net.Interface, grp net.IP) error {
......
......@@ -8,49 +8,44 @@ package ipv6
import (
"os"
"syscall"
"unsafe"
)
func ipv6ReceiveTrafficClass(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceiveTrafficClass(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveTrafficClass, boolint(v)))
}
func ipv6ReceiveHopLimit(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceiveHopLimit(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceiveHopLimit, boolint(v)))
}
func ipv6ReceivePacketInfo(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceivePacketInfo(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePacketInfo, boolint(v)))
}
func ipv6PathMTU(fd int) (int, error) {
......@@ -63,17 +58,15 @@ func ipv6PathMTU(fd int) (int, error) {
}
func ipv6ReceivePathMTU(fd int) (bool, error) {
var v int32
l := sysSockoptLen(4)
if err := getsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, unsafe.Pointer(&v), &l); err != nil {
v, err := syscall.GetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU)
if err != nil {
return false, os.NewSyscallError("getsockopt", err)
}
return v == 1, nil
}
func setIPv6ReceivePathMTU(fd int, v bool) error {
vv := int32(boolint(v))
return os.NewSyscallError("setsockopt", setsockopt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, unsafe.Pointer(&vv), 4))
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, ianaProtocolIPv6, sysSockoptReceivePathMTU, boolint(v)))
}
func ipv6ICMPFilter(fd int) (*ICMPFilter, error) {
......
......@@ -11,33 +11,22 @@ import (
"syscall"
)
// RFC 3493 options
const (
// See /usr/include/netinet6/in6.h.
sysSockoptUnicastHopLimit = 0x4
sysSockoptMulticastHopLimit = 0xa
sysSockoptMulticastInterface = 0x9
sysSockoptMulticastLoopback = 0xb
sysSockoptJoinGroup = 0xc
sysSockoptLeaveGroup = 0xd
)
// RFC 3542 options
const (
// See /usr/include/netinet6/in6.h.
sysSockoptReceiveTrafficClass = 0x39
sysSockoptTrafficClass = 0x3d
sysSockoptReceiveHopLimit = 0x25
sysSockoptHopLimit = 0x2f
sysSockoptReceivePacketInfo = 0x24
sysSockoptPacketInfo = 0x2e
sysSockoptReceivePathMTU = 0x2b
sysSockoptPathMTU = 0x2c
sysSockoptNextHop = 0x30
sysSockoptChecksum = 0x1a
sysSockoptReceiveTrafficClass = syscall.IPV6_RECVTCLASS
sysSockoptTrafficClass = syscall.IPV6_TCLASS
sysSockoptReceiveHopLimit = syscall.IPV6_RECVHOPLIMIT
sysSockoptHopLimit = syscall.IPV6_HOPLIMIT
sysSockoptReceivePacketInfo = syscall.IPV6_RECVPKTINFO
sysSockoptPacketInfo = syscall.IPV6_PKTINFO
sysSockoptReceivePathMTU = syscall.IPV6_RECVPATHMTU
sysSockoptPathMTU = syscall.IPV6_PATHMTU
sysSockoptNextHop = syscall.IPV6_NEXTHOP
sysSockoptChecksum = syscall.IPV6_CHECKSUM
// See /usr/include/netinet6/in6.h.
sysSockoptICMPFilter = 0x12
sysSockoptICMPFilter = 0x12 // syscall.ICMP6_FILTER
)
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
......
......@@ -12,38 +12,27 @@ import (
// RFC 2292 options
const (
// See /usr/include/netinet6/in6.h.
sysSockopt2292HopLimit = 0x14
sysSockopt2292PacketInfo = 0x13
sysSockopt2292NextHop = 0x15
)
// RFC 3493 options
const (
// See /usr/include/netinet6/in6.h.
sysSockoptUnicastHopLimit = 0x4
sysSockoptMulticastHopLimit = 0xa
sysSockoptMulticastInterface = 0x9
sysSockoptMulticastLoopback = 0xb
sysSockoptJoinGroup = 0xc
sysSockoptLeaveGroup = 0xd
sysSockopt2292HopLimit = syscall.IPV6_2292HOPLIMIT
sysSockopt2292PacketInfo = syscall.IPV6_2292PKTINFO
sysSockopt2292NextHop = syscall.IPV6_2292NEXTHOP
)
// RFC 3542 options
const (
// See /usr/include/netinet6/in6.h.
sysSockoptReceiveTrafficClass = 0x23
sysSockoptTrafficClass = 0x24
sysSockoptReceiveHopLimit = 0x25
sysSockoptHopLimit = 0x2f
sysSockoptReceivePacketInfo = 0x3d
sysSockoptPacketInfo = 0x2e
sysSockoptReceivePathMTU = 0x2b
sysSockoptPathMTU = 0x2c
sysSockoptNextHop = 0x30
sysSockoptChecksum = 0x1a
sysSockoptReceiveTrafficClass = 0x23 // IPV6_RECVTCLASS
sysSockoptTrafficClass = 0x24 // IPV6_TCLASS
sysSockoptReceiveHopLimit = 0x25 // IPV6_RECVHOPLIMIT
sysSockoptHopLimit = 0x2f // IPV6_HOPLIMIT
sysSockoptReceivePacketInfo = 0x3d // IPV6_RECVPKTINFO
sysSockoptPacketInfo = 0x2e // IPV6_PKTINFO
sysSockoptReceivePathMTU = 0x2b // IPV6_RECVPATHMTU
sysSockoptPathMTU = 0x2c // IPV6_PATHMTU
sysSockoptNextHop = 0x30 // IPV6_NEXTHOP
sysSockoptChecksum = 0x1a // IPV6_CHECKSUM
// See /usr/include/netinet6/in6.h.
sysSockoptICMPFilter = 0x12
sysSockoptICMPFilter = 0x12 // ICMP6_FILTER
)
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
......
......@@ -9,33 +9,22 @@ import (
"syscall"
)
// RFC 3493 options
const (
// See /usr/include/linux/in6.h.
sysSockoptUnicastHopLimit = 0x10
sysSockoptMulticastHopLimit = 0x12
sysSockoptMulticastInterface = 0x11
sysSockoptMulticastLoopback = 0x13
sysSockoptJoinGroup = 0x14
sysSockoptLeaveGroup = 0x15
)
// RFC 3542 options
const (
// See /usr/include/linux/ipv6.h,in6.h.
sysSockoptReceiveTrafficClass = 0x42
sysSockoptTrafficClass = 0x43
sysSockoptReceiveHopLimit = 0x33
sysSockoptHopLimit = 0x34
sysSockoptReceivePacketInfo = 0x31
sysSockoptPacketInfo = 0x32
sysSockoptReceivePathMTU = 0x3c
sysSockoptPathMTU = 0x3d
sysSockoptNextHop = 0x9
sysSockoptChecksum = 0x7
sysSockoptReceiveTrafficClass = syscall.IPV6_RECVTCLASS
sysSockoptTrafficClass = syscall.IPV6_TCLASS
sysSockoptReceiveHopLimit = syscall.IPV6_RECVHOPLIMIT
sysSockoptHopLimit = syscall.IPV6_HOPLIMIT
sysSockoptReceivePacketInfo = syscall.IPV6_RECVPKTINFO
sysSockoptPacketInfo = syscall.IPV6_PKTINFO
sysSockoptReceivePathMTU = 0x3c // IPV6_RECVPATHMTU
sysSockoptPathMTU = 0x3d // IPV6_PATHMTU
sysSockoptNextHop = syscall.IPV6_NEXTHOP
sysSockoptChecksum = syscall.IPV6_CHECKSUM
// See /usr/include/linux/icmpv6.h.
sysSockoptICMPFilter = 0x1
sysSockoptICMPFilter = 0x1 // syscall.ICMPV6_FILTER
)
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
......
......@@ -8,6 +8,16 @@ package ipv6
import "syscall"
// RFC 3493 options
const (
sysSockoptUnicastHopLimit = syscall.IPV6_UNICAST_HOPS
sysSockoptMulticastHopLimit = syscall.IPV6_MULTICAST_HOPS
sysSockoptMulticastInterface = syscall.IPV6_MULTICAST_IF
sysSockoptMulticastLoopback = syscall.IPV6_MULTICAST_LOOP
sysSockoptJoinGroup = syscall.IPV6_JOIN_GROUP
sysSockoptLeaveGroup = syscall.IPV6_LEAVE_GROUP
)
const sysSizeofMTUInfo = 0x20
type sysMTUInfo struct {
......
......@@ -12,18 +12,18 @@ import (
// RFC 3493 options
const (
// See ws2tcpip.h.
sysSockoptUnicastHopLimit = 0x4
sysSockoptMulticastHopLimit = 0xa
sysSockoptMulticastInterface = 0x9
sysSockoptMulticastLoopback = 0xb
sysSockoptJoinGroup = 0xc
sysSockoptLeaveGroup = 0xd
sysSockoptUnicastHopLimit = syscall.IPV6_UNICAST_HOPS
sysSockoptMulticastHopLimit = syscall.IPV6_MULTICAST_HOPS
sysSockoptMulticastInterface = syscall.IPV6_MULTICAST_IF
sysSockoptMulticastLoopback = syscall.IPV6_MULTICAST_LOOP
sysSockoptJoinGroup = syscall.IPV6_JOIN_GROUP
sysSockoptLeaveGroup = syscall.IPV6_LEAVE_GROUP
)
// RFC 3542 options
const (
// See ws2tcpip.h.
sysSockoptPacketInfo = 0x13
sysSockoptPacketInfo = 0x13 // IPV6_PKTINFO
)
func setSockaddr(sa *syscall.RawSockaddrInet6, ip net.IP, ifindex int) {
......
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