Commit 6250b412 authored by Mikio Hara's avatar Mikio Hara

ipv6: deduplicate socket option code

Change-Id: I836cdf68901dc77bc4c086cabd9d43fd033fbf1d
Reviewed-on: https://go-review.googlesource.com/27736Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b3982904
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
package ipv6 package ipv6
type sysICMPv6Filter struct {
// TODO(mikio): implement this
}
func (f *sysICMPv6Filter) accept(typ ICMPType) { func (f *sysICMPv6Filter) accept(typ ICMPType) {
// TODO(mikio): implement this // TODO(mikio): implement this
} }
......
...@@ -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 darwin dragonfly freebsd linux netbsd openbsd // +build darwin dragonfly freebsd linux netbsd openbsd windows
package ipv6 package ipv6
......
// 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.
package ipv6
import (
"net"
"os"
"syscall"
"unsafe"
)
func setsockoptIPMreq(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
var mreq sysIPv6Mreq
copy(mreq.Multiaddr[:], grp)
if ifi != nil {
mreq.setIfindex(ifi.Index)
}
return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&mreq)), sysSizeofIPv6Mreq))
}
...@@ -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 darwin dragonfly freebsd linux netbsd openbsd // +build darwin dragonfly freebsd linux netbsd openbsd windows
package ipv6 package ipv6
......
// 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.
package ipv6
import (
"net"
"os"
"syscall"
"unsafe"
)
func getInt(s uintptr, opt *sockOpt) (int, error) {
if opt.name < 1 || opt.typ != ssoTypeInt {
return 0, errOpNoSupport
}
var i int32
l := int32(4)
if err := syscall.Getsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(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 {
if opt.name < 1 || opt.typ != ssoTypeInt {
return errOpNoSupport
}
i := int32(v)
return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
}
func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
if opt.name < 1 || opt.typ != ssoTypeInterface {
return nil, errOpNoSupport
}
var i int32
l := int32(4)
if err := syscall.Getsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(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 {
return nil, err
}
return ifi, nil
}
func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
if opt.name < 1 || opt.typ != ssoTypeInterface {
return errOpNoSupport
}
var i int32
if ifi != nil {
i = int32(ifi.Index)
}
return os.NewSyscallError("setsockopt", syscall.Setsockopt(syscall.Handle(s), int32(opt.level), int32(opt.name), (*byte)(unsafe.Pointer(&i)), 4))
}
func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
return nil, errOpNoSupport
}
func setICMPFilter(s uintptr, opt *sockOpt, f *ICMPFilter) error {
return errOpNoSupport
}
func getMTUInfo(s uintptr, opt *sockOpt) (*net.Interface, int, error) {
return nil, 0, errOpNoSupport
}
func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
if opt.name < 1 || opt.typ != ssoTypeIPMreq {
return errOpNoSupport
}
return setsockoptIPMreq(s, opt, ifi, grp)
}
func setSourceGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
// TODO(mikio): implement this
return errOpNoSupport
}
...@@ -23,7 +23,9 @@ const ( ...@@ -23,7 +23,9 @@ const (
sysSizeofSockaddrInet6 = 0x1c sysSizeofSockaddrInet6 = 0x1c
sysSizeofIPv6Mreq = 0x14 sysSizeofIPv6Mreq = 0x14
sysSizeofIPv6Mtuinfo = 0x20
sysSizeofICMPv6Filter = 0
) )
type sysSockaddrInet6 struct { type sysSockaddrInet6 struct {
...@@ -39,6 +41,15 @@ type sysIPv6Mreq struct { ...@@ -39,6 +41,15 @@ type sysIPv6Mreq struct {
Interface uint32 Interface uint32
} }
type sysIPv6Mtuinfo struct {
Addr sysSockaddrInet6
Mtu uint32
}
type sysICMPv6Filter struct {
// TODO(mikio): implement this
}
var ( var (
ctlOpts = [ctlMax]ctlOpt{} ctlOpts = [ctlMax]ctlOpt{}
......
// 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))
}
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