Commit bd58382b authored by Mikio Hara's avatar Mikio Hara

ipv6: plumb in the standard library of Go 1.9 by using internal/socket package

This change uses the internal/socket package to ensure that the ipv6
package works with all supported versions of the Go standard library.

Fixes golang/go#19051.

Change-Id: I74911a8c5bba79e082a10d64e621ed415be1c033
Reviewed-on: https://go-review.googlesource.com/37042Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent c4fa6e0d
// 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 (
"os"
"unsafe"
"golang.org/x/net/bpf"
"golang.org/x/net/internal/netreflect"
)
// SetBPF attaches a BPF program to the connection.
//
// Only supported on Linux.
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
s, err := netreflect.PacketSocketOf(c.PacketConn)
if err != nil {
return err
}
prog := sockFProg{
Len: uint16(len(filter)),
Filter: (*sockFilter)(unsafe.Pointer(&filter[0])),
}
return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
}
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build nacl plan9 // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
package ipv6 package ipv6
func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { import "golang.org/x/net/internal/socket"
func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
return errOpNoSupport return errOpNoSupport
} }
......
...@@ -11,13 +11,14 @@ import ( ...@@ -11,13 +11,14 @@ import (
"syscall" "syscall"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
opt.Lock() opt.Lock()
defer opt.Unlock() defer opt.Unlock()
if cf&FlagTrafficClass != 0 && sockOpts[ssoReceiveTrafficClass].name > 0 { if so, ok := sockOpts[ssoReceiveTrafficClass]; ok && cf&FlagTrafficClass != 0 {
if err := setInt(s, &sockOpts[ssoReceiveTrafficClass], boolint(on)); err != nil { if err := so.SetInt(c, boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -26,8 +27,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -26,8 +27,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
opt.clear(FlagTrafficClass) opt.clear(FlagTrafficClass)
} }
} }
if cf&FlagHopLimit != 0 && sockOpts[ssoReceiveHopLimit].name > 0 { if so, ok := sockOpts[ssoReceiveHopLimit]; ok && cf&FlagHopLimit != 0 {
if err := setInt(s, &sockOpts[ssoReceiveHopLimit], boolint(on)); err != nil { if err := so.SetInt(c, boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -36,8 +37,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -36,8 +37,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
opt.clear(FlagHopLimit) opt.clear(FlagHopLimit)
} }
} }
if cf&flagPacketInfo != 0 && sockOpts[ssoReceivePacketInfo].name > 0 { if so, ok := sockOpts[ssoReceivePacketInfo]; ok && cf&flagPacketInfo != 0 {
if err := setInt(s, &sockOpts[ssoReceivePacketInfo], boolint(on)); err != nil { if err := so.SetInt(c, boolint(on)); err != nil {
return err return err
} }
if on { if on {
...@@ -46,8 +47,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { ...@@ -46,8 +47,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
opt.clear(cf & flagPacketInfo) opt.clear(cf & flagPacketInfo)
} }
} }
if cf&FlagPathMTU != 0 && sockOpts[ssoReceivePathMTU].name > 0 { if so, ok := sockOpts[ssoReceivePathMTU]; ok && cf&FlagPathMTU != 0 {
if err := setInt(s, &sockOpts[ssoReceivePathMTU], boolint(on)); err != nil { if err := so.SetInt(c, boolint(on)); err != nil {
return err return err
} }
if on { if on {
......
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
package ipv6 package ipv6
import "syscall" import (
"syscall"
func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error { "golang.org/x/net/internal/socket"
)
func setControlMessage(c *socket.Conn, opt *rawOpt, cf ControlFlags, on bool) error {
// TODO(mikio): implement this // TODO(mikio): implement this
return syscall.EWINDOWS return syscall.EWINDOWS
} }
......
...@@ -120,6 +120,8 @@ const ( ...@@ -120,6 +120,8 @@ const (
sizeofGroupSourceReq = C.sizeof_struct_group_source_req sizeofGroupSourceReq = C.sizeof_struct_group_source_req
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
sizeofSockFprog = C.sizeof_struct_sock_fprog
) )
type kernelSockaddrStorage C.struct___kernel_sockaddr_storage type kernelSockaddrStorage C.struct___kernel_sockaddr_storage
......
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
package ipv6 package ipv6
import ( import (
"net" "net"
"syscall" "syscall"
"golang.org/x/net/internal/netreflect" "golang.org/x/net/bpf"
) )
// MulticastHopLimit returns the hop limit field value for outgoing // MulticastHopLimit returns the hop limit field value for outgoing
...@@ -19,11 +17,11 @@ func (c *dgramOpt) MulticastHopLimit() (int, error) { ...@@ -19,11 +17,11 @@ func (c *dgramOpt) MulticastHopLimit() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastHopLimit]
if err != nil { if !ok {
return 0, err return 0, errOpNoSupport
} }
return getInt(s, &sockOpts[ssoMulticastHopLimit]) return so.GetInt(c.Conn)
} }
// SetMulticastHopLimit sets the hop limit field value for future // SetMulticastHopLimit sets the hop limit field value for future
...@@ -32,11 +30,11 @@ func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error { ...@@ -32,11 +30,11 @@ func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastHopLimit]
if err != nil { if !ok {
return err return errOpNoSupport
} }
return setInt(s, &sockOpts[ssoMulticastHopLimit], hoplim) return so.SetInt(c.Conn, hoplim)
} }
// MulticastInterface returns the default interface for multicast // MulticastInterface returns the default interface for multicast
...@@ -45,11 +43,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) { ...@@ -45,11 +43,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
if !c.ok() { if !c.ok() {
return nil, syscall.EINVAL return nil, syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastInterface]
if err != nil { if !ok {
return nil, err return nil, errOpNoSupport
} }
return getInterface(s, &sockOpts[ssoMulticastInterface]) return so.getMulticastInterface(c.Conn)
} }
// SetMulticastInterface sets the default interface for future // SetMulticastInterface sets the default interface for future
...@@ -58,11 +56,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error { ...@@ -58,11 +56,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastInterface]
if err != nil { if !ok {
return err return errOpNoSupport
} }
return setInterface(s, &sockOpts[ssoMulticastInterface], ifi) return so.setMulticastInterface(c.Conn, ifi)
} }
// MulticastLoopback reports whether transmitted multicast packets // MulticastLoopback reports whether transmitted multicast packets
...@@ -71,11 +69,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) { ...@@ -71,11 +69,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) {
if !c.ok() { if !c.ok() {
return false, syscall.EINVAL return false, syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastLoopback]
if err != nil { if !ok {
return false, err return false, errOpNoSupport
} }
on, err := getInt(s, &sockOpts[ssoMulticastLoopback]) on, err := so.GetInt(c.Conn)
if err != nil { if err != nil {
return false, err return false, err
} }
...@@ -88,11 +86,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error { ...@@ -88,11 +86,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoMulticastLoopback]
if err != nil { if !ok {
return err return errOpNoSupport
} }
return setInt(s, &sockOpts[ssoMulticastLoopback], boolint(on)) return so.SetInt(c.Conn, boolint(on))
} }
// JoinGroup joins the group address group on the interface ifi. // JoinGroup joins the group address group on the interface ifi.
...@@ -108,15 +106,15 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error { ...@@ -108,15 +106,15 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoJoinGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
return errMissingAddress return errMissingAddress
} }
return setGroup(s, &sockOpts[ssoJoinGroup], ifi, grp) return so.setGroup(c.Conn, ifi, grp)
} }
// LeaveGroup leaves the group address group on the interface ifi // LeaveGroup leaves the group address group on the interface ifi
...@@ -126,15 +124,15 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error { ...@@ -126,15 +124,15 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoLeaveGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
return errMissingAddress return errMissingAddress
} }
return setGroup(s, &sockOpts[ssoLeaveGroup], ifi, grp) return so.setGroup(c.Conn, ifi, grp)
} }
// JoinSourceSpecificGroup joins the source-specific group comprising // JoinSourceSpecificGroup joins the source-specific group comprising
...@@ -147,9 +145,9 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net ...@@ -147,9 +145,9 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoJoinSourceGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
...@@ -159,7 +157,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net ...@@ -159,7 +157,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(s, &sockOpts[ssoJoinSourceGroup], ifi, grp, src) return so.setSourceGroup(c.Conn, ifi, grp, src)
} }
// LeaveSourceSpecificGroup leaves the source-specific group on the // LeaveSourceSpecificGroup leaves the source-specific group on the
...@@ -168,9 +166,9 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne ...@@ -168,9 +166,9 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoLeaveSourceGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
...@@ -180,7 +178,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne ...@@ -180,7 +178,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(s, &sockOpts[ssoLeaveSourceGroup], ifi, grp, src) return so.setSourceGroup(c.Conn, ifi, grp, src)
} }
// ExcludeSourceSpecificGroup excludes the source-specific group from // ExcludeSourceSpecificGroup excludes the source-specific group from
...@@ -190,9 +188,9 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -190,9 +188,9 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoBlockSourceGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
...@@ -202,7 +200,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -202,7 +200,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(s, &sockOpts[ssoBlockSourceGroup], ifi, grp, src) return so.setSourceGroup(c.Conn, ifi, grp, src)
} }
// IncludeSourceSpecificGroup includes the excluded source-specific // IncludeSourceSpecificGroup includes the excluded source-specific
...@@ -211,9 +209,9 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -211,9 +209,9 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoUnblockSourceGroup]
if err != nil { if !ok {
return err return errOpNoSupport
} }
grp := netAddrToIP16(group) grp := netAddrToIP16(group)
if grp == nil { if grp == nil {
...@@ -223,7 +221,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source ...@@ -223,7 +221,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
if src == nil { if src == nil {
return errMissingAddress return errMissingAddress
} }
return setSourceGroup(s, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src) return so.setSourceGroup(c.Conn, ifi, grp, src)
} }
// Checksum reports whether the kernel will compute, store or verify a // Checksum reports whether the kernel will compute, store or verify a
...@@ -234,11 +232,11 @@ func (c *dgramOpt) Checksum() (on bool, offset int, err error) { ...@@ -234,11 +232,11 @@ func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
if !c.ok() { if !c.ok() {
return false, 0, syscall.EINVAL return false, 0, syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoChecksum]
if err != nil { if !ok {
return false, 0, err return false, 0, errOpNoSupport
} }
offset, err = getInt(s, &sockOpts[ssoChecksum]) offset, err = so.GetInt(c.Conn)
if err != nil { if err != nil {
return false, 0, err return false, 0, err
} }
...@@ -255,14 +253,14 @@ func (c *dgramOpt) SetChecksum(on bool, offset int) error { ...@@ -255,14 +253,14 @@ func (c *dgramOpt) SetChecksum(on bool, offset int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoChecksum]
if err != nil { if !ok {
return err return errOpNoSupport
} }
if !on { if !on {
offset = -1 offset = -1
} }
return setInt(s, &sockOpts[ssoChecksum], offset) return so.SetInt(c.Conn, offset)
} }
// ICMPFilter returns an ICMP filter. // ICMPFilter returns an ICMP filter.
...@@ -270,11 +268,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) { ...@@ -270,11 +268,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
if !c.ok() { if !c.ok() {
return nil, syscall.EINVAL return nil, syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoICMPFilter]
if err != nil { if !ok {
return nil, err return nil, errOpNoSupport
} }
return getICMPFilter(s, &sockOpts[ssoICMPFilter]) return so.getICMPFilter(c.Conn)
} }
// SetICMPFilter deploys the ICMP filter. // SetICMPFilter deploys the ICMP filter.
...@@ -282,9 +280,23 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error { ...@@ -282,9 +280,23 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.PacketConn) so, ok := sockOpts[ssoICMPFilter]
if err != nil { if !ok {
return err return errOpNoSupport
}
return so.setICMPFilter(c.Conn, f)
}
// SetBPF attaches a BPF program to the connection.
//
// Only supported on Linux.
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
if !c.ok() {
return syscall.EINVAL
}
so, ok := sockOpts[ssoAttachFilter]
if !ok {
return errOpNoSupport
} }
return setICMPFilter(s, &sockOpts[ssoICMPFilter], f) return so.setBPF(c.Conn, filter)
} }
// Copyright 2013 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 nacl plan9
package ipv6
import "net"
// MulticastHopLimit returns the hop limit field value for outgoing
// multicast packets.
func (c *dgramOpt) MulticastHopLimit() (int, error) {
return 0, errOpNoSupport
}
// SetMulticastHopLimit sets the hop limit field value for future
// outgoing multicast packets.
func (c *dgramOpt) SetMulticastHopLimit(hoplim int) error {
return errOpNoSupport
}
// MulticastInterface returns the default interface for multicast
// packet transmissions.
func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
return nil, errOpNoSupport
}
// SetMulticastInterface sets the default interface for future
// multicast packet transmissions.
func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
return errOpNoSupport
}
// MulticastLoopback reports whether transmitted multicast packets
// should be copied and send back to the originator.
func (c *dgramOpt) MulticastLoopback() (bool, error) {
return false, errOpNoSupport
}
// SetMulticastLoopback sets whether transmitted multicast packets
// should be copied and send back to the originator.
func (c *dgramOpt) SetMulticastLoopback(on bool) error {
return errOpNoSupport
}
// JoinGroup joins the group address group on the interface ifi.
// By default all sources that can cast data to group are accepted.
// It's possible to mute and unmute data transmission from a specific
// source by using ExcludeSourceSpecificGroup and
// IncludeSourceSpecificGroup.
// JoinGroup uses the system assigned multicast interface when ifi is
// nil, although this is not recommended because the assignment
// depends on platforms and sometimes it might require routing
// configuration.
func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
return errOpNoSupport
}
// LeaveGroup leaves the group address group on the interface ifi
// regardless of whether the group is any-source group or
// source-specific group.
func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
return errOpNoSupport
}
// JoinSourceSpecificGroup joins the source-specific group comprising
// group and source on the interface ifi.
// JoinSourceSpecificGroup uses the system assigned multicast
// interface when ifi is nil, although this is not recommended because
// the assignment depends on platforms and sometimes it might require
// routing configuration.
func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
return errOpNoSupport
}
// LeaveSourceSpecificGroup leaves the source-specific group on the
// interface ifi.
func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
return errOpNoSupport
}
// ExcludeSourceSpecificGroup excludes the source-specific group from
// the already joined any-source groups by JoinGroup on the interface
// ifi.
func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
return errOpNoSupport
}
// IncludeSourceSpecificGroup includes the excluded source-specific
// group by ExcludeSourceSpecificGroup again on the interface ifi.
func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source net.Addr) error {
return errOpNoSupport
}
// Checksum reports whether the kernel will compute, store or verify a
// checksum for both incoming and outgoing packets. If on is true, it
// returns an offset in bytes into the data of where the checksum
// field is located.
func (c *dgramOpt) Checksum() (on bool, offset int, err error) {
return false, 0, errOpNoSupport
}
// SetChecksum enables the kernel checksum processing. If on is ture,
// the offset should be an offset in bytes into the data of where the
// checksum field is located.
func (c *dgramOpt) SetChecksum(on bool, offset int) error {
return errOpNoSupport
}
// ICMPFilter returns an ICMP filter.
func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
return nil, errOpNoSupport
}
// SetICMPFilter deploys the ICMP filter.
func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
return errOpNoSupport
}
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"syscall" "syscall"
"time" "time"
"golang.org/x/net/internal/netreflect" "golang.org/x/net/internal/socket"
) )
// BUG(mikio): On Windows, the JoinSourceSpecificGroup, // BUG(mikio): On Windows, the JoinSourceSpecificGroup,
...@@ -25,7 +25,7 @@ type Conn struct { ...@@ -25,7 +25,7 @@ type Conn struct {
} }
type genericOpt struct { type genericOpt struct {
net.Conn *socket.Conn
} }
func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil } func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil }
...@@ -33,14 +33,14 @@ func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil } ...@@ -33,14 +33,14 @@ func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil }
// PathMTU returns a path MTU value for the destination associated // PathMTU returns a path MTU value for the destination associated
// with the endpoint. // with the endpoint.
func (c *Conn) PathMTU() (int, error) { func (c *Conn) PathMTU() (int, error) {
if !c.genericOpt.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
s, err := netreflect.SocketOf(c.genericOpt.Conn) so, ok := sockOpts[ssoPathMTU]
if err != nil { if !ok {
return 0, err return 0, errOpNoSupport
} }
_, mtu, err := getMTUInfo(s, &sockOpts[ssoPathMTU]) _, mtu, err := so.getMTUInfo(c.Conn)
if err != nil { if err != nil {
return 0, err return 0, err
} }
...@@ -49,8 +49,9 @@ func (c *Conn) PathMTU() (int, error) { ...@@ -49,8 +49,9 @@ func (c *Conn) PathMTU() (int, error) {
// NewConn returns a new Conn. // NewConn returns a new Conn.
func NewConn(c net.Conn) *Conn { func NewConn(c net.Conn) *Conn {
cc, _ := socket.NewConn(c)
return &Conn{ return &Conn{
genericOpt: genericOpt{Conn: c}, genericOpt: genericOpt{Conn: cc},
} }
} }
...@@ -66,10 +67,10 @@ type PacketConn struct { ...@@ -66,10 +67,10 @@ type PacketConn struct {
} }
type dgramOpt struct { type dgramOpt struct {
net.PacketConn *socket.Conn
} }
func (c *dgramOpt) ok() bool { return c != nil && c.PacketConn != nil } func (c *dgramOpt) ok() bool { return c != nil && c.Conn != nil }
// SetControlMessage allows to receive the per packet basis IP-level // SetControlMessage allows to receive the per packet basis IP-level
// socket options. // socket options.
...@@ -77,11 +78,7 @@ func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error { ...@@ -77,11 +78,7 @@ func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
if !c.payloadHandler.ok() { if !c.payloadHandler.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn) return setControlMessage(c.dgramOpt.Conn, &c.payloadHandler.rawOpt, cf, on)
if err != nil {
return err
}
return setControlMessage(s, &c.payloadHandler.rawOpt, cf, on)
} }
// SetDeadline sets the read and write deadlines associated with the // SetDeadline sets the read and write deadlines associated with the
...@@ -122,9 +119,10 @@ func (c *PacketConn) Close() error { ...@@ -122,9 +119,10 @@ func (c *PacketConn) Close() error {
// NewPacketConn returns a new PacketConn using c as its underlying // NewPacketConn returns a new PacketConn using c as its underlying
// transport. // transport.
func NewPacketConn(c net.PacketConn) *PacketConn { func NewPacketConn(c net.PacketConn) *PacketConn {
cc, _ := socket.NewConn(c.(net.Conn))
return &PacketConn{ return &PacketConn{
genericOpt: genericOpt{Conn: c.(net.Conn)}, genericOpt: genericOpt{Conn: cc},
dgramOpt: dgramOpt{PacketConn: c}, dgramOpt: dgramOpt{Conn: cc},
payloadHandler: payloadHandler{PacketConn: c}, payloadHandler: payloadHandler{PacketConn: c},
} }
} }
...@@ -2,15 +2,9 @@ ...@@ -2,15 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
package ipv6 package ipv6
import ( import "syscall"
"syscall"
"golang.org/x/net/internal/netreflect"
)
// TrafficClass returns the traffic class field value for outgoing // TrafficClass returns the traffic class field value for outgoing
// packets. // packets.
...@@ -18,11 +12,11 @@ func (c *genericOpt) TrafficClass() (int, error) { ...@@ -18,11 +12,11 @@ func (c *genericOpt) TrafficClass() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
s, err := netreflect.SocketOf(c.Conn) so, ok := sockOpts[ssoTrafficClass]
if err != nil { if !ok {
return 0, err return 0, errOpNoSupport
} }
return getInt(s, &sockOpts[ssoTrafficClass]) return so.GetInt(c.Conn)
} }
// SetTrafficClass sets the traffic class field value for future // SetTrafficClass sets the traffic class field value for future
...@@ -31,11 +25,11 @@ func (c *genericOpt) SetTrafficClass(tclass int) error { ...@@ -31,11 +25,11 @@ func (c *genericOpt) SetTrafficClass(tclass int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.SocketOf(c.Conn) so, ok := sockOpts[ssoTrafficClass]
if err != nil { if !ok {
return err return errOpNoSupport
} }
return setInt(s, &sockOpts[ssoTrafficClass], tclass) return so.SetInt(c.Conn, tclass)
} }
// HopLimit returns the hop limit field value for outgoing packets. // HopLimit returns the hop limit field value for outgoing packets.
...@@ -43,11 +37,11 @@ func (c *genericOpt) HopLimit() (int, error) { ...@@ -43,11 +37,11 @@ func (c *genericOpt) HopLimit() (int, error) {
if !c.ok() { if !c.ok() {
return 0, syscall.EINVAL return 0, syscall.EINVAL
} }
s, err := netreflect.SocketOf(c.Conn) so, ok := sockOpts[ssoHopLimit]
if err != nil { if !ok {
return 0, err return 0, errOpNoSupport
} }
return getInt(s, &sockOpts[ssoHopLimit]) return so.GetInt(c.Conn)
} }
// SetHopLimit sets the hop limit field value for future outgoing // SetHopLimit sets the hop limit field value for future outgoing
...@@ -56,9 +50,9 @@ func (c *genericOpt) SetHopLimit(hoplim int) error { ...@@ -56,9 +50,9 @@ func (c *genericOpt) SetHopLimit(hoplim int) error {
if !c.ok() { if !c.ok() {
return syscall.EINVAL return syscall.EINVAL
} }
s, err := netreflect.SocketOf(c.Conn) so, ok := sockOpts[ssoHopLimit]
if err != nil { if !ok {
return err return errOpNoSupport
} }
return setInt(s, &sockOpts[ssoHopLimit], hoplim) return so.SetInt(c.Conn, hoplim)
} }
// Copyright 2013 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 nacl plan9
package ipv6
// TrafficClass returns the traffic class field value for outgoing
// packets.
func (c *genericOpt) TrafficClass() (int, error) {
return 0, errOpNoSupport
}
// SetTrafficClass sets the traffic class field value for future
// outgoing packets.
func (c *genericOpt) SetTrafficClass(tclass int) error {
return errOpNoSupport
}
// HopLimit returns the hop limit field value for outgoing packets.
func (c *genericOpt) HopLimit() (int, error) {
return 0, errOpNoSupport
}
// SetHopLimit sets the hop limit field value for future outgoing
// packets.
func (c *genericOpt) SetHopLimit(hoplim int) error {
return errOpNoSupport
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build nacl plan9 // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
package ipv6 package ipv6
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package ipv6 package ipv6
import "golang.org/x/net/internal/socket"
// Sticky socket options // Sticky socket options
const ( const (
ssoTrafficClass = iota // header field for unicast packet, RFC 3542 ssoTrafficClass = iota // header field for unicast packet, RFC 3542
...@@ -24,23 +26,18 @@ const ( ...@@ -24,23 +26,18 @@ const (
ssoLeaveSourceGroup // source-specific multicast ssoLeaveSourceGroup // source-specific multicast
ssoBlockSourceGroup // any-source or source-specific multicast ssoBlockSourceGroup // any-source or source-specific multicast
ssoUnblockSourceGroup // any-source or source-specific multicast ssoUnblockSourceGroup // any-source or source-specific multicast
ssoMax ssoAttachFilter // attach BPF for filtering inbound traffic
) )
// Sticky socket option value types // Sticky socket option value types
const ( const (
ssoTypeInt = iota + 1 ssoTypeIPMreq = iota + 1
ssoTypeInterface
ssoTypeICMPFilter
ssoTypeMTUInfo
ssoTypeIPMreq
ssoTypeGroupReq ssoTypeGroupReq
ssoTypeGroupSourceReq ssoTypeGroupSourceReq
) )
// A sockOpt represents a binding for sticky socket option. // A sockOpt represents a binding for sticky socket option.
type sockOpt struct { type sockOpt struct {
level int // option level socket.Option
name int // option name, must be equal or greater than 1 typ int // hint for option value type; optional
typ int // option value type, must be equal or greater than 1
} }
...@@ -8,88 +8,55 @@ package ipv6 ...@@ -8,88 +8,55 @@ package ipv6
import ( import (
"net" "net"
"os"
"unsafe" "unsafe"
)
func getInt(s uintptr, opt *sockOpt) (int, error) {
if opt.name < 1 || opt.typ != ssoTypeInt {
return 0, errOpNoSupport
}
var i int32
l := uint32(4)
if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return 0, os.NewSyscallError("getsockopt", err)
}
return int(i), nil
}
func setInt(s uintptr, opt *sockOpt, v int) error { "golang.org/x/net/bpf"
if opt.name < 1 || opt.typ != ssoTypeInt { "golang.org/x/net/internal/socket"
return errOpNoSupport )
}
i := int32(v)
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4))
}
func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) { func (so *sockOpt) getMulticastInterface(c *socket.Conn) (*net.Interface, error) {
if opt.name < 1 || opt.typ != ssoTypeInterface { n, err := so.GetInt(c)
return nil, errOpNoSupport
}
var i int32
l := uint32(4)
if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
}
if i == 0 {
return nil, nil
}
ifi, err := net.InterfaceByIndex(int(i))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return ifi, nil return net.InterfaceByIndex(n)
} }
func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error { func (so *sockOpt) setMulticastInterface(c *socket.Conn, ifi *net.Interface) error {
if opt.name < 1 || opt.typ != ssoTypeInterface { var n int
return errOpNoSupport
}
var i int32
if ifi != nil { if ifi != nil {
i = int32(ifi.Index) n = ifi.Index
} }
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&i), 4)) return so.SetInt(c, n)
} }
func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) { func (so *sockOpt) getICMPFilter(c *socket.Conn) (*ICMPFilter, error) {
if opt.name < 1 || opt.typ != ssoTypeICMPFilter { b := make([]byte, so.Len)
return nil, errOpNoSupport n, err := so.Get(c, b)
if err != nil {
return nil, err
} }
var f ICMPFilter if n != sizeofICMPv6Filter {
l := uint32(sizeofICMPv6Filter) return nil, errOpNoSupport
if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.icmpv6Filter), &l); err != nil {
return nil, os.NewSyscallError("getsockopt", err)
} }
return &f, nil return (*ICMPFilter)(unsafe.Pointer(&b[0])), nil
} }
func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error { func (so *sockOpt) setICMPFilter(c *socket.Conn, f *ICMPFilter) error {
if opt.name < 1 || opt.typ != ssoTypeICMPFilter { b := (*[sizeofICMPv6Filter]byte)(unsafe.Pointer(f))[:sizeofICMPv6Filter]
return errOpNoSupport return so.Set(c, b)
}
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&f.icmpv6Filter), sizeofICMPv6Filter))
} }
func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) { func (so *sockOpt) getMTUInfo(c *socket.Conn) (*net.Interface, int, error) {
if opt.name < 1 || opt.typ != ssoTypeMTUInfo { b := make([]byte, so.Len)
return nil, 0, errOpNoSupport n, err := so.Get(c, b)
if err != nil {
return nil, 0, err
} }
var mi ipv6Mtuinfo if n != sizeofIPv6Mtuinfo {
l := uint32(sizeofIPv6Mtuinfo) return nil, 0, errOpNoSupport
if err := getsockopt(s, opt.level, opt.name, unsafe.Pointer(&mi), &l); err != nil {
return nil, 0, os.NewSyscallError("getsockopt", err)
} }
mi := (*ipv6Mtuinfo)(unsafe.Pointer(&b[0]))
if mi.Addr.Scope_id == 0 { if mi.Addr.Scope_id == 0 {
return nil, int(mi.Mtu), nil return nil, int(mi.Mtu), nil
} }
...@@ -100,23 +67,21 @@ func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) { ...@@ -100,23 +67,21 @@ func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
return ifi, int(mi.Mtu), nil return ifi, int(mi.Mtu), nil
} }
func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func (so *sockOpt) setGroup(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
if opt.name < 1 { switch so.typ {
return errOpNoSupport
}
switch opt.typ {
case ssoTypeIPMreq: case ssoTypeIPMreq:
return setsockoptIPMreq(s, opt, ifi, grp) return so.setIPMreq(c, ifi, grp)
case ssoTypeGroupReq: case ssoTypeGroupReq:
return setsockoptGroupReq(s, opt, ifi, grp) return so.setGroupReq(c, ifi, grp)
default: default:
return errOpNoSupport return errOpNoSupport
} }
} }
func setSourceGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error { func (so *sockOpt) setSourceGroup(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
if opt.name < 1 || opt.typ != ssoTypeGroupSourceReq { return so.setGroupSourceReq(c, ifi, grp, src)
return errOpNoSupport }
}
return setsockoptGroupSourceReq(s, opt, ifi, grp, src) func (so *sockOpt) setBPF(c *socket.Conn, f []bpf.RawInstruction) error {
return so.setAttachFilter(c, f)
} }
...@@ -2,12 +2,45 @@ ...@@ -2,12 +2,45 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build nacl plan9 // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
package ipv6 package ipv6
import "net" import (
"net"
func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) { "golang.org/x/net/bpf"
"golang.org/x/net/internal/socket"
)
func (so *sockOpt) getMulticastInterface(c *socket.Conn) (*net.Interface, error) {
return nil, errOpNoSupport
}
func (so *sockOpt) setMulticastInterface(c *socket.Conn, ifi *net.Interface) error {
return errOpNoSupport
}
func (so *sockOpt) getICMPFilter(c *socket.Conn) (*ICMPFilter, error) {
return nil, errOpNoSupport
}
func (so *sockOpt) setICMPFilter(c *socket.Conn, f *ICMPFilter) error {
return errOpNoSupport
}
func (so *sockOpt) getMTUInfo(c *socket.Conn) (*net.Interface, int, error) {
return nil, 0, errOpNoSupport return nil, 0, errOpNoSupport
} }
func (so *sockOpt) setGroup(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
return errOpNoSupport
}
func (so *sockOpt) setSourceGroup(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
return errOpNoSupport
}
func (so *sockOpt) setBPF(c *socket.Conn, f []bpf.RawInstruction) error {
return errOpNoSupport
}
...@@ -8,15 +8,17 @@ package ipv6 ...@@ -8,15 +8,17 @@ package ipv6
import ( import (
"net" "net"
"os"
"unsafe" "unsafe"
"golang.org/x/net/internal/socket"
) )
func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func (so *sockOpt) setIPMreq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
var mreq ipv6Mreq var mreq ipv6Mreq
copy(mreq.Multiaddr[:], grp) copy(mreq.Multiaddr[:], grp)
if ifi != nil { if ifi != nil {
mreq.setIfindex(ifi.Index) mreq.setIfindex(ifi.Index)
} }
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, unsafe.Pointer(&mreq), sizeofIPv6Mreq)) b := (*[sizeofIPv6Mreq]byte)(unsafe.Pointer(&mreq))[:sizeofIPv6Mreq]
return so.Set(c, b)
} }
// Copyright 2013 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,!netbsd,!openbsd,!solaris,!windows
package ipv6
import (
"net"
"golang.org/x/net/internal/socket"
)
func (so *sockOpt) setIPMreq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
return errOpNoSupport
}
// Copyright 2017 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 linux
package ipv6
import (
"unsafe"
"golang.org/x/net/bpf"
"golang.org/x/net/internal/socket"
)
func (so *sockOpt) setAttachFilter(c *socket.Conn, f []bpf.RawInstruction) error {
prog := sockFProg{
Len: uint16(len(f)),
Filter: (*sockFilter)(unsafe.Pointer(&f[0])),
}
b := (*[sizeofSockFprog]byte)(unsafe.Pointer(&prog))[:sizeofSockFprog]
return so.Set(c, b)
}
// Copyright 2016 The Go Authors. All rights reserved. // Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
package ipv6 package ipv6
import "golang.org/x/net/bpf" import (
"golang.org/x/net/bpf"
"golang.org/x/net/internal/socket"
)
// SetBPF attaches a BPF program to the connection. func (so *sockOpt) setAttachFilter(c *socket.Conn, f []bpf.RawInstruction) error {
//
// Only supported on Linux.
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
return errOpNoSupport return errOpNoSupport
} }
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"syscall" "syscall"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
var ( var (
...@@ -22,21 +23,21 @@ var ( ...@@ -22,21 +23,21 @@ var (
ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU}, ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
} }
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]*sockOpt{
ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt}, ssoTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_TCLASS, Len: 4}},
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt}, ssoReceiveTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVTCLASS, Len: 4}},
ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt}, ssoReceiveHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVHOPLIMIT, Len: 4}},
ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt}, ssoReceivePacketInfo: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPKTINFO, Len: 4}},
ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt}, ssoReceivePathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPATHMTU, Len: 4}},
ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo}, ssoPathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}},
ssoChecksum: {iana.ProtocolIPv6, sysIPV6_CHECKSUM, ssoTypeInt}, ssoChecksum: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_CHECKSUM, Len: 4}},
ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMP6_FILTER, ssoTypeICMPFilter}, ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: sysICMP6_FILTER, Len: sizeofICMPv6Filter}},
ssoJoinGroup: {iana.ProtocolIPv6, sysIPV6_JOIN_GROUP, ssoTypeIPMreq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_JOIN_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysIPV6_LEAVE_GROUP, ssoTypeIPMreq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_LEAVE_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
} }
) )
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"unsafe" "unsafe"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
var ( var (
...@@ -20,17 +21,17 @@ var ( ...@@ -20,17 +21,17 @@ var (
ctlPacketInfo: {sysIPV6_2292PKTINFO, sizeofInet6Pktinfo, marshal2292PacketInfo, parsePacketInfo}, ctlPacketInfo: {sysIPV6_2292PKTINFO, sizeofInet6Pktinfo, marshal2292PacketInfo, parsePacketInfo},
} }
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]*sockOpt{
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_2292HOPLIMIT, ssoTypeInt}, ssoReceiveHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_2292HOPLIMIT, Len: 4}},
ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_2292PKTINFO, ssoTypeInt}, ssoReceivePacketInfo: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_2292PKTINFO, Len: 4}},
ssoChecksum: {iana.ProtocolIPv6, sysIPV6_CHECKSUM, ssoTypeInt}, ssoChecksum: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_CHECKSUM, Len: 4}},
ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMP6_FILTER, ssoTypeICMPFilter}, ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: sysICMP6_FILTER, Len: sizeofICMPv6Filter}},
ssoJoinGroup: {iana.ProtocolIPv6, sysIPV6_JOIN_GROUP, ssoTypeIPMreq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_JOIN_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysIPV6_LEAVE_GROUP, ssoTypeIPMreq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_LEAVE_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
} }
) )
...@@ -57,18 +58,18 @@ func init() { ...@@ -57,18 +58,18 @@ func init() {
ctlOpts[ctlPacketInfo] = ctlOpt{sysIPV6_PKTINFO, sizeofInet6Pktinfo, marshalPacketInfo, parsePacketInfo} ctlOpts[ctlPacketInfo] = ctlOpt{sysIPV6_PKTINFO, sizeofInet6Pktinfo, marshalPacketInfo, parsePacketInfo}
ctlOpts[ctlNextHop] = ctlOpt{sysIPV6_NEXTHOP, sizeofSockaddrInet6, marshalNextHop, parseNextHop} ctlOpts[ctlNextHop] = ctlOpt{sysIPV6_NEXTHOP, sizeofSockaddrInet6, marshalNextHop, parseNextHop}
ctlOpts[ctlPathMTU] = ctlOpt{sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU} ctlOpts[ctlPathMTU] = ctlOpt{sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU}
sockOpts[ssoTrafficClass] = sockOpt{iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt} sockOpts[ssoTrafficClass] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_TCLASS, Len: 4}}
sockOpts[ssoReceiveTrafficClass] = sockOpt{iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt} sockOpts[ssoReceiveTrafficClass] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVTCLASS, Len: 4}}
sockOpts[ssoReceiveHopLimit] = sockOpt{iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt} sockOpts[ssoReceiveHopLimit] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVHOPLIMIT, Len: 4}}
sockOpts[ssoReceivePacketInfo] = sockOpt{iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt} sockOpts[ssoReceivePacketInfo] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPKTINFO, Len: 4}}
sockOpts[ssoReceivePathMTU] = sockOpt{iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt} sockOpts[ssoReceivePathMTU] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPATHMTU, Len: 4}}
sockOpts[ssoPathMTU] = sockOpt{iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo} sockOpts[ssoPathMTU] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}}
sockOpts[ssoJoinGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq} sockOpts[ssoJoinGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq}
sockOpts[ssoLeaveGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq} sockOpts[ssoLeaveGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq}
sockOpts[ssoJoinSourceGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq} sockOpts[ssoJoinSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
sockOpts[ssoLeaveSourceGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq} sockOpts[ssoLeaveSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
sockOpts[ssoBlockSourceGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq} sockOpts[ssoBlockSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
sockOpts[ssoUnblockSourceGroup] = sockOpt{iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq} sockOpts[ssoUnblockSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
} }
func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) { func (sa *sockaddrInet6) setSockaddr(ip net.IP, i int) {
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"unsafe" "unsafe"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
var ( var (
...@@ -23,25 +24,25 @@ var ( ...@@ -23,25 +24,25 @@ var (
ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU}, ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
} }
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]sockOpt{
ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt}, ssoTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_TCLASS, Len: 4}},
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt}, ssoReceiveTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVTCLASS, Len: 4}},
ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt}, ssoReceiveHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVHOPLIMIT, Len: 4}},
ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt}, ssoReceivePacketInfo: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPKTINFO, Len: 4}},
ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt}, ssoReceivePathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPATHMTU, Len: 4}},
ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo}, ssoPathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}},
ssoChecksum: {iana.ProtocolIPv6, sysIPV6_CHECKSUM, ssoTypeInt}, ssoChecksum: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_CHECKSUM, Len: 4}},
ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMP6_FILTER, ssoTypeICMPFilter}, ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: sysICMP6_FILTER, Len: sizeofICMPv6Filter}},
ssoJoinGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoJoinSourceGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoLeaveSourceGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoBlockSourceGroup: {iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoUnblockSourceGroup: {iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
} }
) )
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"unsafe" "unsafe"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
var ( var (
...@@ -20,25 +21,26 @@ var ( ...@@ -20,25 +21,26 @@ var (
ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU}, ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
} }
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]*sockOpt{
ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt}, ssoTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_TCLASS, Len: 4}},
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt}, ssoReceiveTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVTCLASS, Len: 4}},
ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt}, ssoReceiveHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVHOPLIMIT, Len: 4}},
ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt}, ssoReceivePacketInfo: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPKTINFO, Len: 4}},
ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt}, ssoReceivePathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPATHMTU, Len: 4}},
ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo}, ssoPathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}},
ssoChecksum: {iana.ProtocolReserved, sysIPV6_CHECKSUM, ssoTypeInt}, ssoChecksum: {Option: socket.Option{Level: iana.ProtocolReserved, Name: sysIPV6_CHECKSUM, Len: 4}},
ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMPV6_FILTER, ssoTypeICMPFilter}, ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: sysICMPV6_FILTER, Len: sizeofICMPv6Filter}},
ssoJoinGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoJoinSourceGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoLeaveSourceGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoBlockSourceGroup: {iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoUnblockSourceGroup: {iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoAttachFilter: {Option: socket.Option{Level: sysSOL_SOCKET, Name: sysSO_ATTACH_FILTER, Len: sizeofSockFprog}},
} }
) )
......
// 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.
#include "textflag.h"
TEXT ·socketcall(SB),NOSPLIT,$0-36
JMP syscall·socketcall(SB)
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"unsafe" "unsafe"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
var ( var (
...@@ -21,25 +22,25 @@ var ( ...@@ -21,25 +22,25 @@ var (
ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU}, ctlPathMTU: {sysIPV6_PATHMTU, sizeofIPv6Mtuinfo, marshalPathMTU, parsePathMTU},
} }
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]*sockOpt{
ssoTrafficClass: {iana.ProtocolIPv6, sysIPV6_TCLASS, ssoTypeInt}, ssoTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_TCLASS, Len: 4}},
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoReceiveTrafficClass: {iana.ProtocolIPv6, sysIPV6_RECVTCLASS, ssoTypeInt}, ssoReceiveTrafficClass: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVTCLASS, Len: 4}},
ssoReceiveHopLimit: {iana.ProtocolIPv6, sysIPV6_RECVHOPLIMIT, ssoTypeInt}, ssoReceiveHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVHOPLIMIT, Len: 4}},
ssoReceivePacketInfo: {iana.ProtocolIPv6, sysIPV6_RECVPKTINFO, ssoTypeInt}, ssoReceivePacketInfo: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPKTINFO, Len: 4}},
ssoReceivePathMTU: {iana.ProtocolIPv6, sysIPV6_RECVPATHMTU, ssoTypeInt}, ssoReceivePathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_RECVPATHMTU, Len: 4}},
ssoPathMTU: {iana.ProtocolIPv6, sysIPV6_PATHMTU, ssoTypeMTUInfo}, ssoPathMTU: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_PATHMTU, Len: sizeofIPv6Mtuinfo}},
ssoChecksum: {iana.ProtocolIPv6, sysIPV6_CHECKSUM, ssoTypeInt}, ssoChecksum: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_CHECKSUM, Len: 4}},
ssoICMPFilter: {iana.ProtocolIPv6ICMP, sysICMP6_FILTER, ssoTypeICMPFilter}, ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolIPv6ICMP, Name: sysICMP6_FILTER, Len: sizeofICMPv6Filter}},
ssoJoinGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_GROUP, ssoTypeGroupReq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_GROUP, ssoTypeGroupReq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
ssoJoinSourceGroup: {iana.ProtocolIPv6, sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoLeaveSourceGroup: {iana.ProtocolIPv6, sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq}, ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoBlockSourceGroup: {iana.ProtocolIPv6, sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
ssoUnblockSourceGroup: {iana.ProtocolIPv6, sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq}, ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
} }
) )
......
// 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.
#include "textflag.h"
TEXT ·sysvicall6(SB),NOSPLIT,$0-88
JMP syscall·sysvicall6(SB)
...@@ -8,52 +8,47 @@ package ipv6 ...@@ -8,52 +8,47 @@ package ipv6
import ( import (
"net" "net"
"os"
"unsafe" "unsafe"
"golang.org/x/net/internal/socket"
) )
var freebsd32o64 bool var freebsd32o64 bool
func setsockoptGroupReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error { func (so *sockOpt) setGroupReq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
var gr groupReq var gr groupReq
if ifi != nil { if ifi != nil {
gr.Interface = uint32(ifi.Index) gr.Interface = uint32(ifi.Index)
} }
gr.setGroup(grp) gr.setGroup(grp)
var p unsafe.Pointer var b []byte
var l uint32
if freebsd32o64 { if freebsd32o64 {
var d [sizeofGroupReq + 4]byte var d [sizeofGroupReq + 4]byte
s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr)) s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))
copy(d[:4], s[:4]) copy(d[:4], s[:4])
copy(d[8:], s[4:]) copy(d[8:], s[4:])
p = unsafe.Pointer(&d[0]) b = d[:]
l = sizeofGroupReq + 4
} else { } else {
p = unsafe.Pointer(&gr) b = (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))[:sizeofGroupReq]
l = sizeofGroupReq
} }
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l)) return so.Set(c, b)
} }
func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error { func (so *sockOpt) setGroupSourceReq(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
var gsr groupSourceReq var gsr groupSourceReq
if ifi != nil { if ifi != nil {
gsr.Interface = uint32(ifi.Index) gsr.Interface = uint32(ifi.Index)
} }
gsr.setSourceGroup(grp, src) gsr.setSourceGroup(grp, src)
var p unsafe.Pointer var b []byte
var l uint32
if freebsd32o64 { if freebsd32o64 {
var d [sizeofGroupSourceReq + 4]byte var d [sizeofGroupSourceReq + 4]byte
s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr)) s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
copy(d[:4], s[:4]) copy(d[:4], s[:4])
copy(d[8:], s[4:]) copy(d[8:], s[4:])
p = unsafe.Pointer(&d[0]) b = d[:]
l = sizeofGroupSourceReq + 4
} else { } else {
p = unsafe.Pointer(&gsr) b = (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))[:sizeofGroupSourceReq]
l = sizeofGroupSourceReq
} }
return os.NewSyscallError("setsockopt", setsockopt(s, opt.level, opt.name, p, l)) return so.Set(c, b)
} }
...@@ -6,12 +6,16 @@ ...@@ -6,12 +6,16 @@
package ipv6 package ipv6
import "net" import (
"net"
func setsockoptGroupReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error { "golang.org/x/net/internal/socket"
)
func (so *sockOpt) setGroupReq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
return errOpNoSupport return errOpNoSupport
} }
func setsockoptGroupSourceReq(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error { func (so *sockOpt) setGroupSourceReq(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
return errOpNoSupport return errOpNoSupport
} }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build nacl plan9 // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
package ipv6 package ipv6
var ( var (
ctlOpts = [ctlMax]ctlOpt{} ctlOpts = [ctlMax]ctlOpt{}
sockOpts = [ssoMax]sockOpt{} sockOpts = map[int]*sockOpt{}
) )
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"syscall" "syscall"
"golang.org/x/net/internal/iana" "golang.org/x/net/internal/iana"
"golang.org/x/net/internal/socket"
) )
const ( const (
...@@ -53,13 +54,13 @@ type icmpv6Filter struct { ...@@ -53,13 +54,13 @@ type icmpv6Filter struct {
var ( var (
ctlOpts = [ctlMax]ctlOpt{} ctlOpts = [ctlMax]ctlOpt{}
sockOpts = [ssoMax]sockOpt{ sockOpts = map[int]*sockOpt{
ssoHopLimit: {iana.ProtocolIPv6, sysIPV6_UNICAST_HOPS, ssoTypeInt}, ssoHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_UNICAST_HOPS, Len: 4}},
ssoMulticastInterface: {iana.ProtocolIPv6, sysIPV6_MULTICAST_IF, ssoTypeInterface}, ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_IF, Len: 4}},
ssoMulticastHopLimit: {iana.ProtocolIPv6, sysIPV6_MULTICAST_HOPS, ssoTypeInt}, ssoMulticastHopLimit: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_HOPS, Len: 4}},
ssoMulticastLoopback: {iana.ProtocolIPv6, sysIPV6_MULTICAST_LOOP, ssoTypeInt}, ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_MULTICAST_LOOP, Len: 4}},
ssoJoinGroup: {iana.ProtocolIPv6, sysIPV6_JOIN_GROUP, ssoTypeIPMreq}, ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_JOIN_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
ssoLeaveGroup: {iana.ProtocolIPv6, sysIPV6_LEAVE_GROUP, ssoTypeIPMreq}, ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIPv6, Name: sysIPV6_LEAVE_GROUP, Len: sizeofIPv6Mreq}, typ: ssoTypeIPMreq},
} }
) )
......
// Copyright 2009 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"
)
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
}
// 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"
)
//go:cgo_import_dynamic libc___xnet_getsockopt __xnet_getsockopt "libsocket.so"
//go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
//go:linkname procGetsockopt libc___xnet_getsockopt
//go:linkname procSetsockopt libc_setsockopt
var (
procGetsockopt uintptr
procSetsockopt uintptr
)
func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (uintptr, uintptr, syscall.Errno)
func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procGetsockopt)), 5, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0)
if errno != 0 {
return error(errno)
}
return nil
}
func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
if _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procSetsockopt)), 5, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
return error(errno)
}
return nil
}
// Copyright 2013 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 ipv6
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
}
// 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))
}
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x104 sizeofGroupSourceReq = 0x104
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x8
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x104 sizeofGroupSourceReq = 0x104
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x8
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x104 sizeofGroupSourceReq = 0x104
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x8
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x104 sizeofGroupSourceReq = 0x104
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x8
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x104 sizeofGroupSourceReq = 0x104
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x8
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
...@@ -98,6 +98,8 @@ const ( ...@@ -98,6 +98,8 @@ const (
sizeofGroupSourceReq = 0x108 sizeofGroupSourceReq = 0x108
sizeofICMPv6Filter = 0x20 sizeofICMPv6Filter = 0x20
sizeofSockFprog = 0x10
) )
type kernelSockaddrStorage struct { type kernelSockaddrStorage struct {
......
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