mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Update dependencies
This commit is contained in:
191
vendor/golang.org/x/net/ipv4/batch.go
generated
vendored
Normal file
191
vendor/golang.org/x/net/ipv4/batch.go
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
// 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 go1.9
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
// BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of
|
||||
// PacketConn are not implemented.
|
||||
|
||||
// BUG(mikio): On Windows, the ReadBatch and WriteBatch methods of
|
||||
// RawConn are not implemented.
|
||||
|
||||
// A Message represents an IO message.
|
||||
//
|
||||
// type Message struct {
|
||||
// Buffers [][]byte
|
||||
// OOB []byte
|
||||
// Addr net.Addr
|
||||
// N int
|
||||
// NN int
|
||||
// Flags int
|
||||
// }
|
||||
//
|
||||
// The Buffers fields represents a list of contiguous buffers, which
|
||||
// can be used for vectored IO, for example, putting a header and a
|
||||
// payload in each slice.
|
||||
// When writing, the Buffers field must contain at least one byte to
|
||||
// write.
|
||||
// When reading, the Buffers field will always contain a byte to read.
|
||||
//
|
||||
// The OOB field contains protocol-specific control or miscellaneous
|
||||
// ancillary data known as out-of-band data.
|
||||
// It can be nil when not required.
|
||||
//
|
||||
// The Addr field specifies a destination address when writing.
|
||||
// It can be nil when the underlying protocol of the endpoint uses
|
||||
// connection-oriented communication.
|
||||
// After a successful read, it may contain the source address on the
|
||||
// received packet.
|
||||
//
|
||||
// The N field indicates the number of bytes read or written from/to
|
||||
// Buffers.
|
||||
//
|
||||
// The NN field indicates the number of bytes read or written from/to
|
||||
// OOB.
|
||||
//
|
||||
// The Flags field contains protocol-specific information on the
|
||||
// received message.
|
||||
type Message = socket.Message
|
||||
|
||||
// ReadBatch reads a batch of messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_PEEK.
|
||||
//
|
||||
// On a successful read it returns the number of messages received, up
|
||||
// to len(ms).
|
||||
//
|
||||
// On Linux, a batch read will be optimized.
|
||||
// On other platforms, this method will read only a single message.
|
||||
//
|
||||
// Unlike the ReadFrom method, it doesn't strip the IPv4 header
|
||||
// followed by option headers from the received IPv4 datagram when the
|
||||
// underlying transport is net.IPConn. Each Buffers field of Message
|
||||
// must be large enough to accommodate an IPv4 header and option
|
||||
// headers.
|
||||
func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
n, err := c.RecvMsgs([]socket.Message(ms), flags)
|
||||
if err != nil {
|
||||
err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
default:
|
||||
n := 1
|
||||
err := c.RecvMsg(&ms[0], flags)
|
||||
if err != nil {
|
||||
n = 0
|
||||
err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
|
||||
// WriteBatch writes a batch of messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_DONTROUTE.
|
||||
//
|
||||
// It returns the number of messages written on a successful write.
|
||||
//
|
||||
// On Linux, a batch write will be optimized.
|
||||
// On other platforms, this method will write only a single message.
|
||||
func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
n, err := c.SendMsgs([]socket.Message(ms), flags)
|
||||
if err != nil {
|
||||
err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
default:
|
||||
n := 1
|
||||
err := c.SendMsg(&ms[0], flags)
|
||||
if err != nil {
|
||||
n = 0
|
||||
err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
|
||||
// ReadBatch reads a batch of messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_PEEK.
|
||||
//
|
||||
// On a successful read it returns the number of messages received, up
|
||||
// to len(ms).
|
||||
//
|
||||
// On Linux, a batch read will be optimized.
|
||||
// On other platforms, this method will read only a single message.
|
||||
func (c *packetHandler) ReadBatch(ms []Message, flags int) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
n, err := c.RecvMsgs([]socket.Message(ms), flags)
|
||||
if err != nil {
|
||||
err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
default:
|
||||
n := 1
|
||||
err := c.RecvMsg(&ms[0], flags)
|
||||
if err != nil {
|
||||
n = 0
|
||||
err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
|
||||
// WriteBatch writes a batch of messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_DONTROUTE.
|
||||
//
|
||||
// It returns the number of messages written on a successful write.
|
||||
//
|
||||
// On Linux, a batch write will be optimized.
|
||||
// On other platforms, this method will write only a single message.
|
||||
func (c *packetHandler) WriteBatch(ms []Message, flags int) (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
n, err := c.SendMsgs([]socket.Message(ms), flags)
|
||||
if err != nil {
|
||||
err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
default:
|
||||
n := 1
|
||||
err := c.SendMsg(&ms[0], flags)
|
||||
if err != nil {
|
||||
n = 0
|
||||
err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
28
vendor/golang.org/x/net/ipv4/bpfopt_linux.go
generated
vendored
28
vendor/golang.org/x/net/ipv4/bpfopt_linux.go
generated
vendored
@@ -1,28 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipv4
|
||||
|
||||
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))))
|
||||
}
|
||||
16
vendor/golang.org/x/net/ipv4/bpfopt_stub.go
generated
vendored
16
vendor/golang.org/x/net/ipv4/bpfopt_stub.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !linux
|
||||
|
||||
package ipv4
|
||||
|
||||
import "golang.org/x/net/bpf"
|
||||
|
||||
// SetBPF attaches a BPF program to the connection.
|
||||
//
|
||||
// Only supported on Linux.
|
||||
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
74
vendor/golang.org/x/net/ipv4/control.go
generated
vendored
74
vendor/golang.org/x/net/ipv4/control.go
generated
vendored
@@ -8,6 +8,9 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
type rawOpt struct {
|
||||
@@ -51,6 +54,77 @@ func (cm *ControlMessage) String() string {
|
||||
return fmt.Sprintf("ttl=%d src=%v dst=%v ifindex=%d", cm.TTL, cm.Src, cm.Dst, cm.IfIndex)
|
||||
}
|
||||
|
||||
// Marshal returns the binary encoding of cm.
|
||||
func (cm *ControlMessage) Marshal() []byte {
|
||||
if cm == nil {
|
||||
return nil
|
||||
}
|
||||
var m socket.ControlMessage
|
||||
if ctlOpts[ctlPacketInfo].name > 0 && (cm.Src.To4() != nil || cm.IfIndex > 0) {
|
||||
m = socket.NewControlMessage([]int{ctlOpts[ctlPacketInfo].length})
|
||||
}
|
||||
if len(m) > 0 {
|
||||
ctlOpts[ctlPacketInfo].marshal(m, cm)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Parse parses b as a control message and stores the result in cm.
|
||||
func (cm *ControlMessage) Parse(b []byte) error {
|
||||
ms, err := socket.ControlMessage(b).Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, m := range ms {
|
||||
lvl, typ, l, err := m.ParseHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lvl != iana.ProtocolIP {
|
||||
continue
|
||||
}
|
||||
switch typ {
|
||||
case ctlOpts[ctlTTL].name:
|
||||
ctlOpts[ctlTTL].parse(cm, m.Data(l))
|
||||
case ctlOpts[ctlDst].name:
|
||||
ctlOpts[ctlDst].parse(cm, m.Data(l))
|
||||
case ctlOpts[ctlInterface].name:
|
||||
ctlOpts[ctlInterface].parse(cm, m.Data(l))
|
||||
case ctlOpts[ctlPacketInfo].name:
|
||||
ctlOpts[ctlPacketInfo].parse(cm, m.Data(l))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewControlMessage returns a new control message.
|
||||
//
|
||||
// The returned message is large enough for options specified by cf.
|
||||
func NewControlMessage(cf ControlFlags) []byte {
|
||||
opt := rawOpt{cflags: cf}
|
||||
var l int
|
||||
if opt.isset(FlagTTL) && ctlOpts[ctlTTL].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlTTL].length)
|
||||
}
|
||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
||||
if opt.isset(FlagSrc | FlagDst | FlagInterface) {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlPacketInfo].length)
|
||||
}
|
||||
} else {
|
||||
if opt.isset(FlagDst) && ctlOpts[ctlDst].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlDst].length)
|
||||
}
|
||||
if opt.isset(FlagInterface) && ctlOpts[ctlInterface].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlInterface].length)
|
||||
}
|
||||
}
|
||||
var b []byte
|
||||
if l > 0 {
|
||||
b = make([]byte, l)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Ancillary data socket options
|
||||
const (
|
||||
ctlTTL = iota // header field
|
||||
|
||||
22
vendor/golang.org/x/net/ipv4/control_bsd.go
generated
vendored
22
vendor/golang.org/x/net/ipv4/control_bsd.go
generated
vendored
@@ -12,26 +12,26 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func marshalDst(b []byte, cm *ControlMessage) []byte {
|
||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
||||
m.Level = iana.ProtocolIP
|
||||
m.Type = sysIP_RECVDSTADDR
|
||||
m.SetLen(syscall.CmsgLen(net.IPv4len))
|
||||
return b[syscall.CmsgSpace(net.IPv4len):]
|
||||
m := socket.ControlMessage(b)
|
||||
m.MarshalHeader(iana.ProtocolIP, sysIP_RECVDSTADDR, net.IPv4len)
|
||||
return m.Next(net.IPv4len)
|
||||
}
|
||||
|
||||
func parseDst(cm *ControlMessage, b []byte) {
|
||||
cm.Dst = b[:net.IPv4len]
|
||||
if len(cm.Dst) < net.IPv4len {
|
||||
cm.Dst = make(net.IP, net.IPv4len)
|
||||
}
|
||||
copy(cm.Dst, b[:net.IPv4len])
|
||||
}
|
||||
|
||||
func marshalInterface(b []byte, cm *ControlMessage) []byte {
|
||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
||||
m.Level = iana.ProtocolIP
|
||||
m.Type = sysIP_RECVIF
|
||||
m.SetLen(syscall.CmsgLen(syscall.SizeofSockaddrDatalink))
|
||||
return b[syscall.CmsgSpace(syscall.SizeofSockaddrDatalink):]
|
||||
m := socket.ControlMessage(b)
|
||||
m.MarshalHeader(iana.ProtocolIP, sysIP_RECVIF, syscall.SizeofSockaddrDatalink)
|
||||
return m.Next(syscall.SizeofSockaddrDatalink)
|
||||
}
|
||||
|
||||
func parseInterface(cm *ControlMessage, b []byte) {
|
||||
|
||||
18
vendor/golang.org/x/net/ipv4/control_pktinfo.go
generated
vendored
18
vendor/golang.org/x/net/ipv4/control_pktinfo.go
generated
vendored
@@ -7,19 +7,18 @@
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"net"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
|
||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
||||
m.Level = iana.ProtocolIP
|
||||
m.Type = sysIP_PKTINFO
|
||||
m.SetLen(syscall.CmsgLen(sizeofInetPktinfo))
|
||||
m := socket.ControlMessage(b)
|
||||
m.MarshalHeader(iana.ProtocolIP, sysIP_PKTINFO, sizeofInetPktinfo)
|
||||
if cm != nil {
|
||||
pi := (*inetPktinfo)(unsafe.Pointer(&b[syscall.CmsgLen(0)]))
|
||||
pi := (*inetPktinfo)(unsafe.Pointer(&m.Data(sizeofInetPktinfo)[0]))
|
||||
if ip := cm.Src.To4(); ip != nil {
|
||||
copy(pi.Spec_dst[:], ip)
|
||||
}
|
||||
@@ -27,11 +26,14 @@ func marshalPacketInfo(b []byte, cm *ControlMessage) []byte {
|
||||
pi.setIfindex(cm.IfIndex)
|
||||
}
|
||||
}
|
||||
return b[syscall.CmsgSpace(sizeofInetPktinfo):]
|
||||
return m.Next(sizeofInetPktinfo)
|
||||
}
|
||||
|
||||
func parsePacketInfo(cm *ControlMessage, b []byte) {
|
||||
pi := (*inetPktinfo)(unsafe.Pointer(&b[0]))
|
||||
cm.IfIndex = int(pi.Ifindex)
|
||||
cm.Dst = pi.Addr[:]
|
||||
if len(cm.Dst) < net.IPv4len {
|
||||
cm.Dst = make(net.IP, net.IPv4len)
|
||||
}
|
||||
copy(cm.Dst, pi.Addr[:])
|
||||
}
|
||||
|
||||
18
vendor/golang.org/x/net/ipv4/control_stub.go
generated
vendored
18
vendor/golang.org/x/net/ipv4/control_stub.go
generated
vendored
@@ -2,22 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build nacl plan9
|
||||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func newControlMessage(opt *rawOpt) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
|
||||
func marshalControlMessage(cm *ControlMessage) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
101
vendor/golang.org/x/net/ipv4/control_unix.go
generated
vendored
101
vendor/golang.org/x/net/ipv4/control_unix.go
generated
vendored
@@ -7,18 +7,17 @@
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"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()
|
||||
defer opt.Unlock()
|
||||
if cf&FlagTTL != 0 && sockOpts[ssoReceiveTTL].name > 0 {
|
||||
if err := setInt(s, &sockOpts[ssoReceiveTTL], boolint(on)); err != nil {
|
||||
if so, ok := sockOpts[ssoReceiveTTL]; ok && cf&FlagTTL != 0 {
|
||||
if err := so.SetInt(c, boolint(on)); err != nil {
|
||||
return err
|
||||
}
|
||||
if on {
|
||||
@@ -27,9 +26,9 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
|
||||
opt.clear(FlagTTL)
|
||||
}
|
||||
}
|
||||
if sockOpts[ssoPacketInfo].name > 0 {
|
||||
if so, ok := sockOpts[ssoPacketInfo]; ok {
|
||||
if cf&(FlagSrc|FlagDst|FlagInterface) != 0 {
|
||||
if err := setInt(s, &sockOpts[ssoPacketInfo], boolint(on)); err != nil {
|
||||
if err := so.SetInt(c, boolint(on)); err != nil {
|
||||
return err
|
||||
}
|
||||
if on {
|
||||
@@ -39,8 +38,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if cf&FlagDst != 0 && sockOpts[ssoReceiveDst].name > 0 {
|
||||
if err := setInt(s, &sockOpts[ssoReceiveDst], boolint(on)); err != nil {
|
||||
if so, ok := sockOpts[ssoReceiveDst]; ok && cf&FlagDst != 0 {
|
||||
if err := so.SetInt(c, boolint(on)); err != nil {
|
||||
return err
|
||||
}
|
||||
if on {
|
||||
@@ -49,8 +48,8 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
|
||||
opt.clear(FlagDst)
|
||||
}
|
||||
}
|
||||
if cf&FlagInterface != 0 && sockOpts[ssoReceiveInterface].name > 0 {
|
||||
if err := setInt(s, &sockOpts[ssoReceiveInterface], boolint(on)); err != nil {
|
||||
if so, ok := sockOpts[ssoReceiveInterface]; ok && cf&FlagInterface != 0 {
|
||||
if err := so.SetInt(c, boolint(on)); err != nil {
|
||||
return err
|
||||
}
|
||||
if on {
|
||||
@@ -63,84 +62,10 @@ func setControlMessage(s uintptr, opt *rawOpt, cf ControlFlags, on bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newControlMessage(opt *rawOpt) (oob []byte) {
|
||||
opt.RLock()
|
||||
var l int
|
||||
if opt.isset(FlagTTL) && ctlOpts[ctlTTL].name > 0 {
|
||||
l += syscall.CmsgSpace(ctlOpts[ctlTTL].length)
|
||||
}
|
||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
||||
if opt.isset(FlagSrc | FlagDst | FlagInterface) {
|
||||
l += syscall.CmsgSpace(ctlOpts[ctlPacketInfo].length)
|
||||
}
|
||||
} else {
|
||||
if opt.isset(FlagDst) && ctlOpts[ctlDst].name > 0 {
|
||||
l += syscall.CmsgSpace(ctlOpts[ctlDst].length)
|
||||
}
|
||||
if opt.isset(FlagInterface) && ctlOpts[ctlInterface].name > 0 {
|
||||
l += syscall.CmsgSpace(ctlOpts[ctlInterface].length)
|
||||
}
|
||||
}
|
||||
if l > 0 {
|
||||
oob = make([]byte, l)
|
||||
}
|
||||
opt.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
||||
if len(b) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
cmsgs, err := syscall.ParseSocketControlMessage(b)
|
||||
if err != nil {
|
||||
return nil, os.NewSyscallError("parse socket control message", err)
|
||||
}
|
||||
cm := &ControlMessage{}
|
||||
for _, m := range cmsgs {
|
||||
if m.Header.Level != iana.ProtocolIP {
|
||||
continue
|
||||
}
|
||||
switch int(m.Header.Type) {
|
||||
case ctlOpts[ctlTTL].name:
|
||||
ctlOpts[ctlTTL].parse(cm, m.Data[:])
|
||||
case ctlOpts[ctlDst].name:
|
||||
ctlOpts[ctlDst].parse(cm, m.Data[:])
|
||||
case ctlOpts[ctlInterface].name:
|
||||
ctlOpts[ctlInterface].parse(cm, m.Data[:])
|
||||
case ctlOpts[ctlPacketInfo].name:
|
||||
ctlOpts[ctlPacketInfo].parse(cm, m.Data[:])
|
||||
}
|
||||
}
|
||||
return cm, nil
|
||||
}
|
||||
|
||||
func marshalControlMessage(cm *ControlMessage) (oob []byte) {
|
||||
if cm == nil {
|
||||
return nil
|
||||
}
|
||||
var l int
|
||||
pktinfo := false
|
||||
if ctlOpts[ctlPacketInfo].name > 0 && (cm.Src.To4() != nil || cm.IfIndex > 0) {
|
||||
pktinfo = true
|
||||
l += syscall.CmsgSpace(ctlOpts[ctlPacketInfo].length)
|
||||
}
|
||||
if l > 0 {
|
||||
oob = make([]byte, l)
|
||||
b := oob
|
||||
if pktinfo {
|
||||
b = ctlOpts[ctlPacketInfo].marshal(b, cm)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func marshalTTL(b []byte, cm *ControlMessage) []byte {
|
||||
m := (*syscall.Cmsghdr)(unsafe.Pointer(&b[0]))
|
||||
m.Level = iana.ProtocolIP
|
||||
m.Type = sysIP_RECVTTL
|
||||
m.SetLen(syscall.CmsgLen(1))
|
||||
return b[syscall.CmsgSpace(1):]
|
||||
m := socket.ControlMessage(b)
|
||||
m.MarshalHeader(iana.ProtocolIP, sysIP_RECVTTL, 1)
|
||||
return m.Next(1)
|
||||
}
|
||||
|
||||
func parseTTL(cm *ControlMessage, b []byte) {
|
||||
|
||||
23
vendor/golang.org/x/net/ipv4/control_windows.go
generated
vendored
23
vendor/golang.org/x/net/ipv4/control_windows.go
generated
vendored
@@ -4,24 +4,13 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
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
|
||||
return syscall.EWINDOWS
|
||||
}
|
||||
|
||||
func newControlMessage(opt *rawOpt) []byte {
|
||||
// TODO(mikio): implement this
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseControlMessage(b []byte) (*ControlMessage, error) {
|
||||
// TODO(mikio): implement this
|
||||
return nil, syscall.EWINDOWS
|
||||
}
|
||||
|
||||
func marshalControlMessage(cm *ControlMessage) []byte {
|
||||
// TODO(mikio): implement this
|
||||
return nil
|
||||
}
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/defs_linux.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/defs_linux.go
generated
vendored
@@ -93,6 +93,8 @@ const (
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPFilter = C.sizeof_struct_icmp_filter
|
||||
|
||||
sizeofSockFprog = C.sizeof_struct_sock_fprog
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage C.struct___kernel_sockaddr_storage
|
||||
|
||||
130
vendor/golang.org/x/net/ipv4/dgramopt_posix.go → vendor/golang.org/x/net/ipv4/dgramopt.go
generated
vendored
130
vendor/golang.org/x/net/ipv4/dgramopt_posix.go → vendor/golang.org/x/net/ipv4/dgramopt.go
generated
vendored
@@ -2,15 +2,13 @@
|
||||
// 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 ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/netreflect"
|
||||
"golang.org/x/net/bpf"
|
||||
)
|
||||
|
||||
// MulticastTTL returns the time-to-live field value for outgoing
|
||||
@@ -19,11 +17,11 @@ func (c *dgramOpt) MulticastTTL() (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
so, ok := sockOpts[ssoMulticastTTL]
|
||||
if !ok {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
return getInt(s, &sockOpts[ssoMulticastTTL])
|
||||
return so.GetInt(c.Conn)
|
||||
}
|
||||
|
||||
// SetMulticastTTL sets the time-to-live field value for future
|
||||
@@ -32,11 +30,11 @@ func (c *dgramOpt) SetMulticastTTL(ttl int) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoMulticastTTL]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setInt(s, &sockOpts[ssoMulticastTTL], ttl)
|
||||
return so.SetInt(c.Conn, ttl)
|
||||
}
|
||||
|
||||
// MulticastInterface returns the default interface for multicast
|
||||
@@ -45,11 +43,11 @@ func (c *dgramOpt) MulticastInterface() (*net.Interface, error) {
|
||||
if !c.ok() {
|
||||
return nil, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
so, ok := sockOpts[ssoMulticastInterface]
|
||||
if !ok {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
return getInterface(s, &sockOpts[ssoMulticastInterface])
|
||||
return so.getMulticastInterface(c.Conn)
|
||||
}
|
||||
|
||||
// SetMulticastInterface sets the default interface for future
|
||||
@@ -58,11 +56,11 @@ func (c *dgramOpt) SetMulticastInterface(ifi *net.Interface) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoMulticastInterface]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setInterface(s, &sockOpts[ssoMulticastInterface], ifi)
|
||||
return so.setMulticastInterface(c.Conn, ifi)
|
||||
}
|
||||
|
||||
// MulticastLoopback reports whether transmitted multicast packets
|
||||
@@ -71,11 +69,11 @@ func (c *dgramOpt) MulticastLoopback() (bool, error) {
|
||||
if !c.ok() {
|
||||
return false, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return false, err
|
||||
so, ok := sockOpts[ssoMulticastLoopback]
|
||||
if !ok {
|
||||
return false, errOpNoSupport
|
||||
}
|
||||
on, err := getInt(s, &sockOpts[ssoMulticastLoopback])
|
||||
on, err := so.GetInt(c.Conn)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -88,11 +86,11 @@ func (c *dgramOpt) SetMulticastLoopback(on bool) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoMulticastLoopback]
|
||||
if !ok {
|
||||
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.
|
||||
@@ -108,15 +106,15 @@ func (c *dgramOpt) JoinGroup(ifi *net.Interface, group net.Addr) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoJoinGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
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
|
||||
@@ -126,15 +124,15 @@ func (c *dgramOpt) LeaveGroup(ifi *net.Interface, group net.Addr) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoLeaveGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
return errMissingAddress
|
||||
}
|
||||
return setGroup(s, &sockOpts[ssoLeaveGroup], ifi, grp)
|
||||
return so.setGroup(c.Conn, ifi, grp)
|
||||
}
|
||||
|
||||
// JoinSourceSpecificGroup joins the source-specific group comprising
|
||||
@@ -147,9 +145,9 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoJoinSourceGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
@@ -159,7 +157,7 @@ func (c *dgramOpt) JoinSourceSpecificGroup(ifi *net.Interface, group, source net
|
||||
if src == nil {
|
||||
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
|
||||
@@ -168,9 +166,9 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoLeaveSourceGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
@@ -180,7 +178,7 @@ func (c *dgramOpt) LeaveSourceSpecificGroup(ifi *net.Interface, group, source ne
|
||||
if src == nil {
|
||||
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
|
||||
@@ -190,9 +188,9 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoBlockSourceGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
@@ -202,7 +200,7 @@ func (c *dgramOpt) ExcludeSourceSpecificGroup(ifi *net.Interface, group, source
|
||||
if src == nil {
|
||||
return errMissingAddress
|
||||
}
|
||||
return setSourceGroup(s, &sockOpts[ssoBlockSourceGroup], ifi, grp, src)
|
||||
return so.setSourceGroup(c.Conn, ifi, grp, src)
|
||||
}
|
||||
|
||||
// IncludeSourceSpecificGroup includes the excluded source-specific
|
||||
@@ -211,9 +209,9 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoUnblockSourceGroup]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
grp := netAddrToIP4(group)
|
||||
if grp == nil {
|
||||
@@ -223,7 +221,7 @@ func (c *dgramOpt) IncludeSourceSpecificGroup(ifi *net.Interface, group, source
|
||||
if src == nil {
|
||||
return errMissingAddress
|
||||
}
|
||||
return setSourceGroup(s, &sockOpts[ssoUnblockSourceGroup], ifi, grp, src)
|
||||
return so.setSourceGroup(c.Conn, ifi, grp, src)
|
||||
}
|
||||
|
||||
// ICMPFilter returns an ICMP filter.
|
||||
@@ -232,11 +230,11 @@ func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
|
||||
if !c.ok() {
|
||||
return nil, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
so, ok := sockOpts[ssoICMPFilter]
|
||||
if !ok {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
return getICMPFilter(s, &sockOpts[ssoICMPFilter])
|
||||
return so.getICMPFilter(c.Conn)
|
||||
}
|
||||
|
||||
// SetICMPFilter deploys the ICMP filter.
|
||||
@@ -245,9 +243,23 @@ func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoICMPFilter]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setICMPFilter(s, &sockOpts[ssoICMPFilter], f)
|
||||
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 so.setBPF(c.Conn, filter)
|
||||
}
|
||||
106
vendor/golang.org/x/net/ipv4/dgramopt_stub.go
generated
vendored
106
vendor/golang.org/x/net/ipv4/dgramopt_stub.go
generated
vendored
@@ -1,106 +0,0 @@
|
||||
// Copyright 2012 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 ipv4
|
||||
|
||||
import "net"
|
||||
|
||||
// MulticastTTL returns the time-to-live field value for outgoing
|
||||
// multicast packets.
|
||||
func (c *dgramOpt) MulticastTTL() (int, error) {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
|
||||
// SetMulticastTTL sets the time-to-live field value for future
|
||||
// outgoing multicast packets.
|
||||
func (c *dgramOpt) SetMulticastTTL(ttl 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
|
||||
}
|
||||
|
||||
// ICMPFilter returns an ICMP filter.
|
||||
// Currently only Linux supports this.
|
||||
func (c *dgramOpt) ICMPFilter() (*ICMPFilter, error) {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
|
||||
// SetICMPFilter deploys the ICMP filter.
|
||||
// Currently only Linux supports this.
|
||||
func (c *dgramOpt) SetICMPFilter(f *ICMPFilter) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
20
vendor/golang.org/x/net/ipv4/doc.go
generated
vendored
20
vendor/golang.org/x/net/ipv4/doc.go
generated
vendored
@@ -21,10 +21,10 @@
|
||||
//
|
||||
// The options for unicasting are available for net.TCPConn,
|
||||
// net.UDPConn and net.IPConn which are created as network connections
|
||||
// that use the IPv4 transport. When a single TCP connection carrying
|
||||
// that use the IPv4 transport. When a single TCP connection carrying
|
||||
// a data flow of multiple packets needs to indicate the flow is
|
||||
// important, ipv4.Conn is used to set the type-of-service field on
|
||||
// the IPv4 header for each packet.
|
||||
// important, Conn is used to set the type-of-service field on the
|
||||
// IPv4 header for each packet.
|
||||
//
|
||||
// ln, err := net.Listen("tcp4", "0.0.0.0:1024")
|
||||
// if err != nil {
|
||||
@@ -56,7 +56,7 @@
|
||||
//
|
||||
// The options for multicasting are available for net.UDPConn and
|
||||
// net.IPconn which are created as network connections that use the
|
||||
// IPv4 transport. A few network facilities must be prepared before
|
||||
// IPv4 transport. A few network facilities must be prepared before
|
||||
// you begin multicasting, at a minimum joining network interfaces and
|
||||
// multicast groups.
|
||||
//
|
||||
@@ -80,7 +80,7 @@
|
||||
// defer c.Close()
|
||||
//
|
||||
// Second, the application joins multicast groups, starts listening to
|
||||
// the groups on the specified network interfaces. Note that the
|
||||
// the groups on the specified network interfaces. Note that the
|
||||
// service port for transport layer protocol does not matter with this
|
||||
// operation as joining groups affects only network and link layer
|
||||
// protocols, such as IPv4 and Ethernet.
|
||||
@@ -94,10 +94,10 @@
|
||||
// }
|
||||
//
|
||||
// The application might set per packet control message transmissions
|
||||
// between the protocol stack within the kernel. When the application
|
||||
// between the protocol stack within the kernel. When the application
|
||||
// needs a destination address on an incoming packet,
|
||||
// SetControlMessage of ipv4.PacketConn is used to enable control
|
||||
// message transmissions.
|
||||
// SetControlMessage of PacketConn is used to enable control message
|
||||
// transmissions.
|
||||
//
|
||||
// if err := p.SetControlMessage(ipv4.FlagDst, true); err != nil {
|
||||
// // error handling
|
||||
@@ -145,7 +145,7 @@
|
||||
// More multicasting
|
||||
//
|
||||
// An application that uses PacketConn or RawConn may join multiple
|
||||
// multicast groups. For example, a UDP listener with port 1024 might
|
||||
// multicast groups. For example, a UDP listener with port 1024 might
|
||||
// join two different groups across over two different network
|
||||
// interfaces by using:
|
||||
//
|
||||
@@ -166,7 +166,7 @@
|
||||
// }
|
||||
//
|
||||
// It is possible for multiple UDP listeners that listen on the same
|
||||
// UDP port to join the same multicast group. The net package will
|
||||
// UDP port to join the same multicast group. The net package will
|
||||
// provide a socket that listens to a wildcard address with reusable
|
||||
// UDP port when an appropriate multicast address prefix is passed to
|
||||
// the net.ListenPacket or net.ListenUDP.
|
||||
|
||||
69
vendor/golang.org/x/net/ipv4/endpoint.go
generated
vendored
69
vendor/golang.org/x/net/ipv4/endpoint.go
generated
vendored
@@ -9,7 +9,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/internal/netreflect"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
// BUG(mikio): On Windows, the JoinSourceSpecificGroup,
|
||||
@@ -25,21 +25,22 @@ type Conn struct {
|
||||
}
|
||||
|
||||
type genericOpt struct {
|
||||
net.Conn
|
||||
*socket.Conn
|
||||
}
|
||||
|
||||
func (c *genericOpt) ok() bool { return c != nil && c.Conn != nil }
|
||||
|
||||
// NewConn returns a new Conn.
|
||||
func NewConn(c net.Conn) *Conn {
|
||||
cc, _ := socket.NewConn(c)
|
||||
return &Conn{
|
||||
genericOpt: genericOpt{Conn: c},
|
||||
genericOpt: genericOpt{Conn: cc},
|
||||
}
|
||||
}
|
||||
|
||||
// A PacketConn represents a packet network endpoint that uses the
|
||||
// IPv4 transport. It is used to control several IP-level socket
|
||||
// options including multicasting. It also provides datagram based
|
||||
// IPv4 transport. It is used to control several IP-level socket
|
||||
// options including multicasting. It also provides datagram based
|
||||
// network I/O methods specific to the IPv4 and higher layer protocols
|
||||
// such as UDP.
|
||||
type PacketConn struct {
|
||||
@@ -49,21 +50,17 @@ type PacketConn 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 sets the per packet IP-level socket options.
|
||||
func (c *PacketConn) SetControlMessage(cf ControlFlags, on bool) error {
|
||||
if !c.payloadHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return setControlMessage(s, &c.payloadHandler.rawOpt, cf, on)
|
||||
return setControlMessage(c.dgramOpt.Conn, &c.payloadHandler.rawOpt, cf, on)
|
||||
}
|
||||
|
||||
// SetDeadline sets the read and write deadlines associated with the
|
||||
@@ -104,22 +101,18 @@ func (c *PacketConn) Close() error {
|
||||
// NewPacketConn returns a new PacketConn using c as its underlying
|
||||
// transport.
|
||||
func NewPacketConn(c net.PacketConn) *PacketConn {
|
||||
cc, _ := socket.NewConn(c.(net.Conn))
|
||||
p := &PacketConn{
|
||||
genericOpt: genericOpt{Conn: c.(net.Conn)},
|
||||
dgramOpt: dgramOpt{PacketConn: c},
|
||||
payloadHandler: payloadHandler{PacketConn: c},
|
||||
}
|
||||
if _, ok := c.(*net.IPConn); ok && sockOpts[ssoStripHeader].name > 0 {
|
||||
if s, err := netreflect.PacketSocketOf(c); err == nil {
|
||||
setInt(s, &sockOpts[ssoStripHeader], boolint(true))
|
||||
}
|
||||
genericOpt: genericOpt{Conn: cc},
|
||||
dgramOpt: dgramOpt{Conn: cc},
|
||||
payloadHandler: payloadHandler{PacketConn: c, Conn: cc},
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// A RawConn represents a packet network endpoint that uses the IPv4
|
||||
// transport. It is used to control several IP-level socket options
|
||||
// including IPv4 header manipulation. It also provides datagram
|
||||
// transport. It is used to control several IP-level socket options
|
||||
// including IPv4 header manipulation. It also provides datagram
|
||||
// based network I/O methods specific to the IPv4 and higher layer
|
||||
// protocols that handle IPv4 datagram directly such as OSPF, GRE.
|
||||
type RawConn struct {
|
||||
@@ -133,11 +126,7 @@ func (c *RawConn) SetControlMessage(cf ControlFlags, on bool) error {
|
||||
if !c.packetHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c.dgramOpt.PacketConn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return setControlMessage(s, &c.packetHandler.rawOpt, cf, on)
|
||||
return setControlMessage(c.dgramOpt.Conn, &c.packetHandler.rawOpt, cf, on)
|
||||
}
|
||||
|
||||
// SetDeadline sets the read and write deadlines associated with the
|
||||
@@ -146,7 +135,7 @@ func (c *RawConn) SetDeadline(t time.Time) error {
|
||||
if !c.packetHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return c.packetHandler.c.SetDeadline(t)
|
||||
return c.packetHandler.IPConn.SetDeadline(t)
|
||||
}
|
||||
|
||||
// SetReadDeadline sets the read deadline associated with the
|
||||
@@ -155,7 +144,7 @@ func (c *RawConn) SetReadDeadline(t time.Time) error {
|
||||
if !c.packetHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return c.packetHandler.c.SetReadDeadline(t)
|
||||
return c.packetHandler.IPConn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetWriteDeadline sets the write deadline associated with the
|
||||
@@ -164,7 +153,7 @@ func (c *RawConn) SetWriteDeadline(t time.Time) error {
|
||||
if !c.packetHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return c.packetHandler.c.SetWriteDeadline(t)
|
||||
return c.packetHandler.IPConn.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
// Close closes the endpoint.
|
||||
@@ -172,22 +161,26 @@ func (c *RawConn) Close() error {
|
||||
if !c.packetHandler.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return c.packetHandler.c.Close()
|
||||
return c.packetHandler.IPConn.Close()
|
||||
}
|
||||
|
||||
// NewRawConn returns a new RawConn using c as its underlying
|
||||
// transport.
|
||||
func NewRawConn(c net.PacketConn) (*RawConn, error) {
|
||||
r := &RawConn{
|
||||
genericOpt: genericOpt{Conn: c.(net.Conn)},
|
||||
dgramOpt: dgramOpt{PacketConn: c},
|
||||
packetHandler: packetHandler{c: c.(*net.IPConn)},
|
||||
}
|
||||
s, err := netreflect.PacketSocketOf(c)
|
||||
cc, err := socket.NewConn(c.(net.Conn))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := setInt(s, &sockOpts[ssoHeaderPrepend], boolint(true)); err != nil {
|
||||
r := &RawConn{
|
||||
genericOpt: genericOpt{Conn: cc},
|
||||
dgramOpt: dgramOpt{Conn: cc},
|
||||
packetHandler: packetHandler{IPConn: c.(*net.IPConn), Conn: cc},
|
||||
}
|
||||
so, ok := sockOpts[ssoHeaderPrepend]
|
||||
if !ok {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
if err := so.SetInt(r.dgramOpt.Conn, boolint(true)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r, nil
|
||||
|
||||
@@ -2,26 +2,20 @@
|
||||
// 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 ipv4
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/netreflect"
|
||||
)
|
||||
import "syscall"
|
||||
|
||||
// TOS returns the type-of-service field value for outgoing packets.
|
||||
func (c *genericOpt) TOS() (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.SocketOf(c.Conn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
so, ok := sockOpts[ssoTOS]
|
||||
if !ok {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
return getInt(s, &sockOpts[ssoTOS])
|
||||
return so.GetInt(c.Conn)
|
||||
}
|
||||
|
||||
// SetTOS sets the type-of-service field value for future outgoing
|
||||
@@ -30,11 +24,11 @@ func (c *genericOpt) SetTOS(tos int) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.SocketOf(c.Conn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoTOS]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setInt(s, &sockOpts[ssoTOS], tos)
|
||||
return so.SetInt(c.Conn, tos)
|
||||
}
|
||||
|
||||
// TTL returns the time-to-live field value for outgoing packets.
|
||||
@@ -42,11 +36,11 @@ func (c *genericOpt) TTL() (int, error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.SocketOf(c.Conn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
so, ok := sockOpts[ssoTTL]
|
||||
if !ok {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
return getInt(s, &sockOpts[ssoTTL])
|
||||
return so.GetInt(c.Conn)
|
||||
}
|
||||
|
||||
// SetTTL sets the time-to-live field value for future outgoing
|
||||
@@ -55,9 +49,9 @@ func (c *genericOpt) SetTTL(ttl int) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
s, err := netreflect.SocketOf(c.Conn)
|
||||
if err != nil {
|
||||
return err
|
||||
so, ok := sockOpts[ssoTTL]
|
||||
if !ok {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setInt(s, &sockOpts[ssoTTL], ttl)
|
||||
return so.SetInt(c.Conn, ttl)
|
||||
}
|
||||
29
vendor/golang.org/x/net/ipv4/genericopt_stub.go
generated
vendored
29
vendor/golang.org/x/net/ipv4/genericopt_stub.go
generated
vendored
@@ -1,29 +0,0 @@
|
||||
// Copyright 2012 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 ipv4
|
||||
|
||||
// TOS returns the type-of-service field value for outgoing packets.
|
||||
func (c *genericOpt) TOS() (int, error) {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
|
||||
// SetTOS sets the type-of-service field value for future outgoing
|
||||
// packets.
|
||||
func (c *genericOpt) SetTOS(tos int) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
|
||||
// TTL returns the time-to-live field value for outgoing packets.
|
||||
func (c *genericOpt) TTL() (int, error) {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
|
||||
// SetTTL sets the time-to-live field value for future outgoing
|
||||
// packets.
|
||||
func (c *genericOpt) SetTTL(ttl int) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
70
vendor/golang.org/x/net/ipv4/header.go
generated
vendored
70
vendor/golang.org/x/net/ipv4/header.go
generated
vendored
@@ -10,6 +10,8 @@ import (
|
||||
"net"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -49,7 +51,7 @@ func (h *Header) String() string {
|
||||
return fmt.Sprintf("ver=%d hdrlen=%d tos=%#x totallen=%d id=%#x flags=%#x fragoff=%#x ttl=%d proto=%d cksum=%#x src=%v dst=%v", h.Version, h.Len, h.TOS, h.TotalLen, h.ID, h.Flags, h.FragOff, h.TTL, h.Protocol, h.Checksum, h.Src, h.Dst)
|
||||
}
|
||||
|
||||
// Marshal returns the binary encoding of the IPv4 header h.
|
||||
// Marshal returns the binary encoding of h.
|
||||
func (h *Header) Marshal() ([]byte, error) {
|
||||
if h == nil {
|
||||
return nil, syscall.EINVAL
|
||||
@@ -64,12 +66,12 @@ func (h *Header) Marshal() ([]byte, error) {
|
||||
flagsAndFragOff := (h.FragOff & 0x1fff) | int(h.Flags<<13)
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
nativeEndian.PutUint16(b[2:4], uint16(h.TotalLen))
|
||||
nativeEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
|
||||
socket.NativeEndian.PutUint16(b[2:4], uint16(h.TotalLen))
|
||||
socket.NativeEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
|
||||
case "freebsd":
|
||||
if freebsdVersion < 1100000 {
|
||||
nativeEndian.PutUint16(b[2:4], uint16(h.TotalLen))
|
||||
nativeEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
|
||||
socket.NativeEndian.PutUint16(b[2:4], uint16(h.TotalLen))
|
||||
socket.NativeEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
|
||||
} else {
|
||||
binary.BigEndian.PutUint16(b[2:4], uint16(h.TotalLen))
|
||||
binary.BigEndian.PutUint16(b[6:8], uint16(flagsAndFragOff))
|
||||
@@ -96,37 +98,35 @@ func (h *Header) Marshal() ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// ParseHeader parses b as an IPv4 header.
|
||||
func ParseHeader(b []byte) (*Header, error) {
|
||||
if len(b) < HeaderLen {
|
||||
return nil, errHeaderTooShort
|
||||
// Parse parses b as an IPv4 header and sotres the result in h.
|
||||
func (h *Header) Parse(b []byte) error {
|
||||
if h == nil || len(b) < HeaderLen {
|
||||
return errHeaderTooShort
|
||||
}
|
||||
hdrlen := int(b[0]&0x0f) << 2
|
||||
if hdrlen > len(b) {
|
||||
return nil, errBufferTooShort
|
||||
}
|
||||
h := &Header{
|
||||
Version: int(b[0] >> 4),
|
||||
Len: hdrlen,
|
||||
TOS: int(b[1]),
|
||||
ID: int(binary.BigEndian.Uint16(b[4:6])),
|
||||
TTL: int(b[8]),
|
||||
Protocol: int(b[9]),
|
||||
Checksum: int(binary.BigEndian.Uint16(b[10:12])),
|
||||
Src: net.IPv4(b[12], b[13], b[14], b[15]),
|
||||
Dst: net.IPv4(b[16], b[17], b[18], b[19]),
|
||||
return errBufferTooShort
|
||||
}
|
||||
h.Version = int(b[0] >> 4)
|
||||
h.Len = hdrlen
|
||||
h.TOS = int(b[1])
|
||||
h.ID = int(binary.BigEndian.Uint16(b[4:6]))
|
||||
h.TTL = int(b[8])
|
||||
h.Protocol = int(b[9])
|
||||
h.Checksum = int(binary.BigEndian.Uint16(b[10:12]))
|
||||
h.Src = net.IPv4(b[12], b[13], b[14], b[15])
|
||||
h.Dst = net.IPv4(b[16], b[17], b[18], b[19])
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
h.TotalLen = int(nativeEndian.Uint16(b[2:4])) + hdrlen
|
||||
h.FragOff = int(nativeEndian.Uint16(b[6:8]))
|
||||
h.TotalLen = int(socket.NativeEndian.Uint16(b[2:4])) + hdrlen
|
||||
h.FragOff = int(socket.NativeEndian.Uint16(b[6:8]))
|
||||
case "freebsd":
|
||||
if freebsdVersion < 1100000 {
|
||||
h.TotalLen = int(nativeEndian.Uint16(b[2:4]))
|
||||
h.TotalLen = int(socket.NativeEndian.Uint16(b[2:4]))
|
||||
if freebsdVersion < 1000000 {
|
||||
h.TotalLen += hdrlen
|
||||
}
|
||||
h.FragOff = int(nativeEndian.Uint16(b[6:8]))
|
||||
h.FragOff = int(socket.NativeEndian.Uint16(b[6:8]))
|
||||
} else {
|
||||
h.TotalLen = int(binary.BigEndian.Uint16(b[2:4]))
|
||||
h.FragOff = int(binary.BigEndian.Uint16(b[6:8]))
|
||||
@@ -137,9 +137,23 @@ func ParseHeader(b []byte) (*Header, error) {
|
||||
}
|
||||
h.Flags = HeaderFlags(h.FragOff&0xe000) >> 13
|
||||
h.FragOff = h.FragOff & 0x1fff
|
||||
if hdrlen-HeaderLen > 0 {
|
||||
h.Options = make([]byte, hdrlen-HeaderLen)
|
||||
copy(h.Options, b[HeaderLen:])
|
||||
optlen := hdrlen - HeaderLen
|
||||
if optlen > 0 && len(b) >= hdrlen {
|
||||
if cap(h.Options) < optlen {
|
||||
h.Options = make([]byte, optlen)
|
||||
} else {
|
||||
h.Options = h.Options[:optlen]
|
||||
}
|
||||
copy(h.Options, b[HeaderLen:hdrlen])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseHeader parses b as an IPv4 header.
|
||||
func ParseHeader(b []byte) (*Header, error) {
|
||||
h := new(Header)
|
||||
if err := h.Parse(b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
296
vendor/golang.org/x/net/ipv4/header_test.go
generated
vendored
296
vendor/golang.org/x/net/ipv4/header_test.go
generated
vendored
@@ -12,141 +12,217 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
type headerTest struct {
|
||||
wireHeaderFromKernel [HeaderLen]byte
|
||||
wireHeaderToKernel [HeaderLen]byte
|
||||
wireHeaderFromTradBSDKernel [HeaderLen]byte
|
||||
wireHeaderToTradBSDKernel [HeaderLen]byte
|
||||
wireHeaderFromFreeBSD10Kernel [HeaderLen]byte
|
||||
wireHeaderToFreeBSD10Kernel [HeaderLen]byte
|
||||
wireHeaderFromKernel []byte
|
||||
wireHeaderToKernel []byte
|
||||
wireHeaderFromTradBSDKernel []byte
|
||||
wireHeaderToTradBSDKernel []byte
|
||||
wireHeaderFromFreeBSD10Kernel []byte
|
||||
wireHeaderToFreeBSD10Kernel []byte
|
||||
*Header
|
||||
}
|
||||
|
||||
var headerLittleEndianTest = headerTest{
|
||||
var headerLittleEndianTests = []headerTest{
|
||||
// TODO(mikio): Add platform dependent wire header formats when
|
||||
// we support new platforms.
|
||||
wireHeaderFromKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
{
|
||||
wireHeaderFromKernel: []byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToKernel: []byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromTradBSDKernel: []byte{
|
||||
0x45, 0x01, 0xdb, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToTradBSDKernel: []byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromFreeBSD10Kernel: []byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToFreeBSD10Kernel: []byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
Header: &Header{
|
||||
Version: Version,
|
||||
Len: HeaderLen,
|
||||
TOS: 1,
|
||||
TotalLen: 0xbeef,
|
||||
ID: 0xcafe,
|
||||
Flags: DontFragment,
|
||||
FragOff: 1500,
|
||||
TTL: 255,
|
||||
Protocol: 1,
|
||||
Checksum: 0xdead,
|
||||
Src: net.IPv4(172, 16, 254, 254),
|
||||
Dst: net.IPv4(192, 168, 0, 1),
|
||||
},
|
||||
},
|
||||
wireHeaderToKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xbe, 0xef,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromTradBSDKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xdb, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToTradBSDKernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderFromFreeBSD10Kernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
wireHeaderToFreeBSD10Kernel: [HeaderLen]byte{
|
||||
0x45, 0x01, 0xef, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
},
|
||||
Header: &Header{
|
||||
Version: Version,
|
||||
Len: HeaderLen,
|
||||
TOS: 1,
|
||||
TotalLen: 0xbeef,
|
||||
ID: 0xcafe,
|
||||
Flags: DontFragment,
|
||||
FragOff: 1500,
|
||||
TTL: 255,
|
||||
Protocol: 1,
|
||||
Checksum: 0xdead,
|
||||
Src: net.IPv4(172, 16, 254, 254),
|
||||
Dst: net.IPv4(192, 168, 0, 1),
|
||||
|
||||
// with option headers
|
||||
{
|
||||
wireHeaderFromKernel: []byte{
|
||||
0x46, 0x01, 0xbe, 0xf3,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
wireHeaderToKernel: []byte{
|
||||
0x46, 0x01, 0xbe, 0xf3,
|
||||
0xca, 0xfe, 0x45, 0xdc,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
wireHeaderFromTradBSDKernel: []byte{
|
||||
0x46, 0x01, 0xdb, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
wireHeaderToTradBSDKernel: []byte{
|
||||
0x46, 0x01, 0xf3, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
wireHeaderFromFreeBSD10Kernel: []byte{
|
||||
0x46, 0x01, 0xf3, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
wireHeaderToFreeBSD10Kernel: []byte{
|
||||
0x46, 0x01, 0xf3, 0xbe,
|
||||
0xca, 0xfe, 0xdc, 0x45,
|
||||
0xff, 0x01, 0xde, 0xad,
|
||||
172, 16, 254, 254,
|
||||
192, 168, 0, 1,
|
||||
0xff, 0xfe, 0xfe, 0xff,
|
||||
},
|
||||
Header: &Header{
|
||||
Version: Version,
|
||||
Len: HeaderLen + 4,
|
||||
TOS: 1,
|
||||
TotalLen: 0xbef3,
|
||||
ID: 0xcafe,
|
||||
Flags: DontFragment,
|
||||
FragOff: 1500,
|
||||
TTL: 255,
|
||||
Protocol: 1,
|
||||
Checksum: 0xdead,
|
||||
Src: net.IPv4(172, 16, 254, 254),
|
||||
Dst: net.IPv4(192, 168, 0, 1),
|
||||
Options: []byte{0xff, 0xfe, 0xfe, 0xff},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestMarshalHeader(t *testing.T) {
|
||||
tt := &headerLittleEndianTest
|
||||
if nativeEndian != binary.LittleEndian {
|
||||
if socket.NativeEndian != binary.LittleEndian {
|
||||
t.Skip("no test for non-little endian machine yet")
|
||||
}
|
||||
|
||||
b, err := tt.Header.Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderToTradBSDKernel[:]
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderToTradBSDKernel[:]
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderToFreeBSD10Kernel[:]
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel[:]
|
||||
for _, tt := range headerLittleEndianTests {
|
||||
b, err := tt.Header.Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderToTradBSDKernel
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderToTradBSDKernel
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderToFreeBSD10Kernel
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel
|
||||
}
|
||||
if !bytes.Equal(b, wh) {
|
||||
t.Fatalf("got %#v; want %#v", b, wh)
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderToKernel[:]
|
||||
}
|
||||
if !bytes.Equal(b, wh) {
|
||||
t.Fatalf("got %#v; want %#v", b, wh)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHeader(t *testing.T) {
|
||||
tt := &headerLittleEndianTest
|
||||
if nativeEndian != binary.LittleEndian {
|
||||
if socket.NativeEndian != binary.LittleEndian {
|
||||
t.Skip("no test for big endian machine yet")
|
||||
}
|
||||
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderFromTradBSDKernel[:]
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderFromTradBSDKernel[:]
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderFromFreeBSD10Kernel[:]
|
||||
for _, tt := range headerLittleEndianTests {
|
||||
var wh []byte
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "dragonfly", "netbsd":
|
||||
wh = tt.wireHeaderFromTradBSDKernel
|
||||
case "freebsd":
|
||||
switch {
|
||||
case freebsdVersion < 1000000:
|
||||
wh = tt.wireHeaderFromTradBSDKernel
|
||||
case 1000000 <= freebsdVersion && freebsdVersion < 1100000:
|
||||
wh = tt.wireHeaderFromFreeBSD10Kernel
|
||||
default:
|
||||
wh = tt.wireHeaderFromKernel
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderFromKernel[:]
|
||||
wh = tt.wireHeaderFromKernel
|
||||
}
|
||||
h, err := ParseHeader(wh)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.Parse(wh); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(h, tt.Header) {
|
||||
t.Fatalf("got %#v; want %#v", h, tt.Header)
|
||||
}
|
||||
s := h.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Fatalf("should be space-separated values: %s", s)
|
||||
}
|
||||
default:
|
||||
wh = tt.wireHeaderFromKernel[:]
|
||||
}
|
||||
h, err := ParseHeader(wh)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(h, tt.Header) {
|
||||
t.Fatalf("got %#v; want %#v", h, tt.Header)
|
||||
}
|
||||
s := h.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Fatalf("should be space-separated values: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
14
vendor/golang.org/x/net/ipv4/helper.go
generated
vendored
14
vendor/golang.org/x/net/ipv4/helper.go
generated
vendored
@@ -5,10 +5,8 @@
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"net"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -23,20 +21,8 @@ var (
|
||||
|
||||
// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
|
||||
freebsdVersion uint32
|
||||
|
||||
nativeEndian binary.ByteOrder
|
||||
)
|
||||
|
||||
func init() {
|
||||
i := uint32(1)
|
||||
b := (*[4]byte)(unsafe.Pointer(&i))
|
||||
if b[0] == 1 {
|
||||
nativeEndian = binary.LittleEndian
|
||||
} else {
|
||||
nativeEndian = binary.BigEndian
|
||||
}
|
||||
}
|
||||
|
||||
func boolint(b bool) int {
|
||||
if b {
|
||||
return 1
|
||||
|
||||
53
vendor/golang.org/x/net/ipv4/packet.go
generated
vendored
53
vendor/golang.org/x/net/ipv4/packet.go
generated
vendored
@@ -7,6 +7,8 @@ package ipv4
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
// BUG(mikio): On Windows, the ReadFrom and WriteTo methods of RawConn
|
||||
@@ -14,38 +16,21 @@ import (
|
||||
|
||||
// A packetHandler represents the IPv4 datagram handler.
|
||||
type packetHandler struct {
|
||||
c *net.IPConn
|
||||
*net.IPConn
|
||||
*socket.Conn
|
||||
rawOpt
|
||||
}
|
||||
|
||||
func (c *packetHandler) ok() bool { return c != nil && c.c != nil }
|
||||
func (c *packetHandler) ok() bool { return c != nil && c.IPConn != nil && c.Conn != nil }
|
||||
|
||||
// ReadFrom reads an IPv4 datagram from the endpoint c, copying the
|
||||
// datagram into b. It returns the received datagram as the IPv4
|
||||
// datagram into b. It returns the received datagram as the IPv4
|
||||
// header h, the payload p and the control message cm.
|
||||
func (c *packetHandler) ReadFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
||||
if !c.ok() {
|
||||
return nil, nil, nil, syscall.EINVAL
|
||||
}
|
||||
oob := newControlMessage(&c.rawOpt)
|
||||
n, oobn, _, src, err := c.c.ReadMsgIP(b, oob)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
var hs []byte
|
||||
if hs, p, err = slicePacket(b[:n]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if h, err = ParseHeader(hs); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if src != nil && cm != nil {
|
||||
cm.Src = src.IP
|
||||
}
|
||||
return
|
||||
return c.readFrom(b)
|
||||
}
|
||||
|
||||
func slicePacket(b []byte) (h, p []byte, err error) {
|
||||
@@ -57,14 +42,14 @@ func slicePacket(b []byte) (h, p []byte, err error) {
|
||||
}
|
||||
|
||||
// WriteTo writes an IPv4 datagram through the endpoint c, copying the
|
||||
// datagram from the IPv4 header h and the payload p. The control
|
||||
// datagram from the IPv4 header h and the payload p. The control
|
||||
// message cm allows the datagram path and the outgoing interface to be
|
||||
// specified. Currently only Darwin and Linux support this. The cm
|
||||
// specified. Currently only Darwin and Linux support this. The cm
|
||||
// may be nil if control of the outgoing datagram is not required.
|
||||
//
|
||||
// The IPv4 header h must contain appropriate fields that include:
|
||||
//
|
||||
// Version = ipv4.Version
|
||||
// Version = <must be specified>
|
||||
// Len = <must be specified>
|
||||
// TOS = <must be specified>
|
||||
// TotalLen = <must be specified>
|
||||
@@ -80,21 +65,5 @@ func (c *packetHandler) WriteTo(h *Header, p []byte, cm *ControlMessage) error {
|
||||
if !c.ok() {
|
||||
return syscall.EINVAL
|
||||
}
|
||||
oob := marshalControlMessage(cm)
|
||||
wh, err := h.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst := &net.IPAddr{}
|
||||
if cm != nil {
|
||||
if ip := cm.Dst.To4(); ip != nil {
|
||||
dst.IP = ip
|
||||
}
|
||||
}
|
||||
if dst.IP == nil {
|
||||
dst.IP = h.Dst
|
||||
}
|
||||
wh = append(wh, p...)
|
||||
_, _, err = c.c.WriteMsgIP(wh, oob, dst)
|
||||
return err
|
||||
return c.writeTo(h, p, cm)
|
||||
}
|
||||
|
||||
56
vendor/golang.org/x/net/ipv4/packet_go1_8.go
generated
vendored
Normal file
56
vendor/golang.org/x/net/ipv4/packet_go1_8.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
|
||||
func (c *packetHandler) readFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
||||
c.rawOpt.RLock()
|
||||
oob := NewControlMessage(c.rawOpt.cflags)
|
||||
c.rawOpt.RUnlock()
|
||||
n, nn, _, src, err := c.ReadMsgIP(b, oob)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
var hs []byte
|
||||
if hs, p, err = slicePacket(b[:n]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if h, err = ParseHeader(hs); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if nn > 0 {
|
||||
cm = new(ControlMessage)
|
||||
if err := cm.Parse(oob[:nn]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
if src != nil && cm != nil {
|
||||
cm.Src = src.IP
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *packetHandler) writeTo(h *Header, p []byte, cm *ControlMessage) error {
|
||||
oob := cm.Marshal()
|
||||
wh, err := h.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst := new(net.IPAddr)
|
||||
if cm != nil {
|
||||
if ip := cm.Dst.To4(); ip != nil {
|
||||
dst.IP = ip
|
||||
}
|
||||
}
|
||||
if dst.IP == nil {
|
||||
dst.IP = h.Dst
|
||||
}
|
||||
wh = append(wh, p...)
|
||||
_, _, err = c.WriteMsgIP(wh, oob, dst)
|
||||
return err
|
||||
}
|
||||
67
vendor/golang.org/x/net/ipv4/packet_go1_9.go
generated
vendored
Normal file
67
vendor/golang.org/x/net/ipv4/packet_go1_9.go
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 go1.9
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (c *packetHandler) readFrom(b []byte) (h *Header, p []byte, cm *ControlMessage, err error) {
|
||||
c.rawOpt.RLock()
|
||||
m := socket.Message{
|
||||
Buffers: [][]byte{b},
|
||||
OOB: NewControlMessage(c.rawOpt.cflags),
|
||||
}
|
||||
c.rawOpt.RUnlock()
|
||||
if err := c.RecvMsg(&m, 0); err != nil {
|
||||
return nil, nil, nil, &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
var hs []byte
|
||||
if hs, p, err = slicePacket(b[:m.N]); err != nil {
|
||||
return nil, nil, nil, &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
if h, err = ParseHeader(hs); err != nil {
|
||||
return nil, nil, nil, &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
if m.NN > 0 {
|
||||
cm = new(ControlMessage)
|
||||
if err := cm.Parse(m.OOB[:m.NN]); err != nil {
|
||||
return nil, nil, nil, &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
}
|
||||
if src, ok := m.Addr.(*net.IPAddr); ok && cm != nil {
|
||||
cm.Src = src.IP
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *packetHandler) writeTo(h *Header, p []byte, cm *ControlMessage) error {
|
||||
m := socket.Message{
|
||||
OOB: cm.Marshal(),
|
||||
}
|
||||
wh, err := h.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Buffers = [][]byte{wh, p}
|
||||
dst := new(net.IPAddr)
|
||||
if cm != nil {
|
||||
if ip := cm.Dst.To4(); ip != nil {
|
||||
dst.IP = ip
|
||||
}
|
||||
}
|
||||
if dst.IP == nil {
|
||||
dst.IP = h.Dst
|
||||
}
|
||||
m.Addr = dst
|
||||
if err := c.SendMsg(&m, 0); err != nil {
|
||||
return &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
9
vendor/golang.org/x/net/ipv4/payload.go
generated
vendored
9
vendor/golang.org/x/net/ipv4/payload.go
generated
vendored
@@ -4,7 +4,11 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
// BUG(mikio): On Windows, the ControlMessage for ReadFrom and WriteTo
|
||||
// methods of PacketConn is not implemented.
|
||||
@@ -12,7 +16,8 @@ import "net"
|
||||
// A payloadHandler represents the IPv4 datagram payload handler.
|
||||
type payloadHandler struct {
|
||||
net.PacketConn
|
||||
*socket.Conn
|
||||
rawOpt
|
||||
}
|
||||
|
||||
func (c *payloadHandler) ok() bool { return c != nil && c.PacketConn != nil }
|
||||
func (c *payloadHandler) ok() bool { return c != nil && c.PacketConn != nil && c.Conn != nil }
|
||||
|
||||
59
vendor/golang.org/x/net/ipv4/payload_cmsg.go
generated
vendored
59
vendor/golang.org/x/net/ipv4/payload_cmsg.go
generated
vendored
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !plan9,!windows
|
||||
// +build !nacl,!plan9,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
@@ -12,70 +12,25 @@ import (
|
||||
)
|
||||
|
||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// bytes copied into b, the control message cm and the source address
|
||||
// src of the received datagram.
|
||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
||||
if !c.ok() {
|
||||
return 0, nil, nil, syscall.EINVAL
|
||||
}
|
||||
oob := newControlMessage(&c.rawOpt)
|
||||
var oobn int
|
||||
switch c := c.PacketConn.(type) {
|
||||
case *net.UDPConn:
|
||||
if n, oobn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
case *net.IPConn:
|
||||
if sockOpts[ssoStripHeader].name > 0 {
|
||||
if n, oobn, _, src, err = c.ReadMsgIP(b, oob); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
} else {
|
||||
nb := make([]byte, maxHeaderLen+len(b))
|
||||
if n, oobn, _, src, err = c.ReadMsgIP(nb, oob); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
hdrlen := int(nb[0]&0x0f) << 2
|
||||
copy(b, nb[hdrlen:])
|
||||
n -= hdrlen
|
||||
}
|
||||
default:
|
||||
return 0, nil, nil, errInvalidConnType
|
||||
}
|
||||
if cm, err = parseControlMessage(oob[:oobn]); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
if cm != nil {
|
||||
cm.Src = netAddrToIP4(src)
|
||||
}
|
||||
return
|
||||
return c.readFrom(b)
|
||||
}
|
||||
|
||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// the datagram path and the outgoing interface to be specified.
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// control of the outgoing datagram is not required.
|
||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
return 0, syscall.EINVAL
|
||||
}
|
||||
oob := marshalControlMessage(cm)
|
||||
if dst == nil {
|
||||
return 0, errMissingAddress
|
||||
}
|
||||
switch c := c.PacketConn.(type) {
|
||||
case *net.UDPConn:
|
||||
n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
|
||||
case *net.IPConn:
|
||||
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
|
||||
default:
|
||||
return 0, errInvalidConnType
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return
|
||||
return c.writeTo(b, cm, dst)
|
||||
}
|
||||
|
||||
59
vendor/golang.org/x/net/ipv4/payload_cmsg_go1_8.go
generated
vendored
Normal file
59
vendor/golang.org/x/net/ipv4/payload_cmsg_go1_8.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
// +build !nacl,!plan9,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
|
||||
func (c *payloadHandler) readFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
||||
c.rawOpt.RLock()
|
||||
oob := NewControlMessage(c.rawOpt.cflags)
|
||||
c.rawOpt.RUnlock()
|
||||
var nn int
|
||||
switch c := c.PacketConn.(type) {
|
||||
case *net.UDPConn:
|
||||
if n, nn, _, src, err = c.ReadMsgUDP(b, oob); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
case *net.IPConn:
|
||||
nb := make([]byte, maxHeaderLen+len(b))
|
||||
if n, nn, _, src, err = c.ReadMsgIP(nb, oob); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
hdrlen := int(nb[0]&0x0f) << 2
|
||||
copy(b, nb[hdrlen:])
|
||||
n -= hdrlen
|
||||
default:
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Err: errInvalidConnType}
|
||||
}
|
||||
if nn > 0 {
|
||||
cm = new(ControlMessage)
|
||||
if err = cm.Parse(oob[:nn]); err != nil {
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
}
|
||||
if cm != nil {
|
||||
cm.Src = netAddrToIP4(src)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
||||
oob := cm.Marshal()
|
||||
if dst == nil {
|
||||
return 0, &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: errMissingAddress}
|
||||
}
|
||||
switch c := c.PacketConn.(type) {
|
||||
case *net.UDPConn:
|
||||
n, _, err = c.WriteMsgUDP(b, oob, dst.(*net.UDPAddr))
|
||||
case *net.IPConn:
|
||||
n, _, err = c.WriteMsgIP(b, oob, dst.(*net.IPAddr))
|
||||
default:
|
||||
return 0, &net.OpError{Op: "write", Net: c.LocalAddr().Network(), Source: c.LocalAddr(), Err: errInvalidConnType}
|
||||
}
|
||||
return
|
||||
}
|
||||
67
vendor/golang.org/x/net/ipv4/payload_cmsg_go1_9.go
generated
vendored
Normal file
67
vendor/golang.org/x/net/ipv4/payload_cmsg_go1_9.go
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 go1.9
|
||||
// +build !nacl,!plan9,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (c *payloadHandler) readFrom(b []byte) (int, *ControlMessage, net.Addr, error) {
|
||||
c.rawOpt.RLock()
|
||||
m := socket.Message{
|
||||
OOB: NewControlMessage(c.rawOpt.cflags),
|
||||
}
|
||||
c.rawOpt.RUnlock()
|
||||
switch c.PacketConn.(type) {
|
||||
case *net.UDPConn:
|
||||
m.Buffers = [][]byte{b}
|
||||
if err := c.RecvMsg(&m, 0); err != nil {
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
case *net.IPConn:
|
||||
h := make([]byte, HeaderLen)
|
||||
m.Buffers = [][]byte{h, b}
|
||||
if err := c.RecvMsg(&m, 0); err != nil {
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
hdrlen := int(h[0]&0x0f) << 2
|
||||
if hdrlen > len(h) {
|
||||
d := hdrlen - len(h)
|
||||
copy(b, b[d:])
|
||||
m.N -= d
|
||||
} else {
|
||||
m.N -= hdrlen
|
||||
}
|
||||
default:
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: errInvalidConnType}
|
||||
}
|
||||
var cm *ControlMessage
|
||||
if m.NN > 0 {
|
||||
cm = new(ControlMessage)
|
||||
if err := cm.Parse(m.OOB[:m.NN]); err != nil {
|
||||
return 0, nil, nil, &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
cm.Src = netAddrToIP4(m.Addr)
|
||||
}
|
||||
return m.N, cm, m.Addr, nil
|
||||
}
|
||||
|
||||
func (c *payloadHandler) writeTo(b []byte, cm *ControlMessage, dst net.Addr) (int, error) {
|
||||
m := socket.Message{
|
||||
Buffers: [][]byte{b},
|
||||
OOB: cm.Marshal(),
|
||||
Addr: dst,
|
||||
}
|
||||
err := c.SendMsg(&m, 0)
|
||||
if err != nil {
|
||||
err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
|
||||
}
|
||||
return m.N, err
|
||||
}
|
||||
10
vendor/golang.org/x/net/ipv4/payload_nocmsg.go
generated
vendored
10
vendor/golang.org/x/net/ipv4/payload_nocmsg.go
generated
vendored
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build plan9 windows
|
||||
// +build nacl plan9 windows
|
||||
|
||||
package ipv4
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// ReadFrom reads a payload of the received IPv4 datagram, from the
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// endpoint c, copying the payload into b. It returns the number of
|
||||
// bytes copied into b, the control message cm and the source address
|
||||
// src of the received datagram.
|
||||
func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.Addr, err error) {
|
||||
@@ -26,10 +26,10 @@ func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.
|
||||
}
|
||||
|
||||
// WriteTo writes a payload of the IPv4 datagram, to the destination
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// address dst through the endpoint c, copying the payload from b. It
|
||||
// returns the number of bytes written. The control message cm allows
|
||||
// the datagram path and the outgoing interface to be specified.
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// Currently only Darwin and Linux support this. The cm may be nil if
|
||||
// control of the outgoing datagram is not required.
|
||||
func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n int, err error) {
|
||||
if !c.ok() {
|
||||
|
||||
248
vendor/golang.org/x/net/ipv4/readwrite_go1_8_test.go
generated
vendored
Normal file
248
vendor/golang.org/x/net/ipv4/readwrite_go1_8_test.go
generated
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !go1.9
|
||||
|
||||
package ipv4_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func BenchmarkPacketConnReadWriteUnicast(b *testing.B) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
b.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
payload := []byte("HELLO-R-U-THERE")
|
||||
iph, err := (&ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TotalLen: ipv4.HeaderLen + len(payload),
|
||||
TTL: 1,
|
||||
Protocol: iana.ProtocolReserved,
|
||||
Src: net.IPv4(192, 0, 2, 1),
|
||||
Dst: net.IPv4(192, 0, 2, 254),
|
||||
}).Marshal()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
greh := []byte{0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
datagram := append(greh, append(iph, payload...)...)
|
||||
bb := make([]byte, 128)
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
|
||||
b.Run("UDP", func(b *testing.B) {
|
||||
c, err := nettest.NewLocalPacketListener("udp4")
|
||||
if err != nil {
|
||||
b.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
dst := c.LocalAddr()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagInterface
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.Run("Net", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := c.WriteTo(payload, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("ToFrom", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteTo(payload, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("IP", func(b *testing.B) {
|
||||
switch runtime.GOOS {
|
||||
case "netbsd":
|
||||
b.Skip("need to configure gre on netbsd")
|
||||
case "openbsd":
|
||||
b.Skip("net.inet.gre.allow=0 by default on openbsd")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket(fmt.Sprintf("ip4:%d", iana.ProtocolGRE), "127.0.0.1")
|
||||
if err != nil {
|
||||
b.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
dst := c.LocalAddr()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagInterface
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.Run("Net", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := c.WriteTo(datagram, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("ToFrom", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteTo(datagram, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestPacketConnConcurrentReadWriteUnicast(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
payload := []byte("HELLO-R-U-THERE")
|
||||
iph, err := (&ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TotalLen: ipv4.HeaderLen + len(payload),
|
||||
TTL: 1,
|
||||
Protocol: iana.ProtocolReserved,
|
||||
Src: net.IPv4(192, 0, 2, 1),
|
||||
Dst: net.IPv4(192, 0, 2, 254),
|
||||
}).Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
greh := []byte{0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
datagram := append(greh, append(iph, payload...)...)
|
||||
|
||||
t.Run("UDP", func(t *testing.T) {
|
||||
c, err := nettest.NewLocalPacketListener("udp4")
|
||||
if err != nil {
|
||||
t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
t.Run("ToFrom", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, payload, c.LocalAddr())
|
||||
})
|
||||
})
|
||||
t.Run("IP", func(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "netbsd":
|
||||
t.Skip("need to configure gre on netbsd")
|
||||
case "openbsd":
|
||||
t.Skip("net.inet.gre.allow=0 by default on openbsd")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket(fmt.Sprintf("ip4:%d", iana.ProtocolGRE), "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
t.Run("ToFrom", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, datagram, c.LocalAddr())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv4.PacketConn, data []byte, dst net.Addr) {
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
cf := ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst | ipv4.FlagInterface
|
||||
|
||||
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
reader := func() {
|
||||
defer wg.Done()
|
||||
b := make([]byte, 128)
|
||||
n, cm, _, err := p.ReadFrom(b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if !bytes.Equal(b[:n], data) {
|
||||
t.Errorf("got %#v; want %#v", b[:n], data)
|
||||
return
|
||||
}
|
||||
s := cm.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Errorf("should be space-separated values: %s", s)
|
||||
return
|
||||
}
|
||||
}
|
||||
writer := func(toggle bool) {
|
||||
defer wg.Done()
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
n, err := p.WriteTo(data, &cm, dst)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n != len(data) {
|
||||
t.Errorf("got %d; want %d", n, len(data))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const N = 10
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Add(2 * N)
|
||||
for i := 0; i < 2*N; i++ {
|
||||
go writer(i%2 != 0)
|
||||
|
||||
}
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
go reader()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
388
vendor/golang.org/x/net/ipv4/readwrite_go1_9_test.go
generated
vendored
Normal file
388
vendor/golang.org/x/net/ipv4/readwrite_go1_9_test.go
generated
vendored
Normal file
@@ -0,0 +1,388 @@
|
||||
// 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 go1.9
|
||||
|
||||
package ipv4_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func BenchmarkPacketConnReadWriteUnicast(b *testing.B) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
b.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
payload := []byte("HELLO-R-U-THERE")
|
||||
iph, err := (&ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TotalLen: ipv4.HeaderLen + len(payload),
|
||||
TTL: 1,
|
||||
Protocol: iana.ProtocolReserved,
|
||||
Src: net.IPv4(192, 0, 2, 1),
|
||||
Dst: net.IPv4(192, 0, 2, 254),
|
||||
}).Marshal()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
greh := []byte{0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
datagram := append(greh, append(iph, payload...)...)
|
||||
bb := make([]byte, 128)
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
|
||||
b.Run("UDP", func(b *testing.B) {
|
||||
c, err := nettest.NewLocalPacketListener("udp4")
|
||||
if err != nil {
|
||||
b.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
dst := c.LocalAddr()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagInterface
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
wms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{payload},
|
||||
Addr: dst,
|
||||
OOB: cm.Marshal(),
|
||||
},
|
||||
}
|
||||
rms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{bb},
|
||||
OOB: ipv4.NewControlMessage(cf),
|
||||
},
|
||||
}
|
||||
b.Run("Net", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := c.WriteTo(payload, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("ToFrom", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteTo(payload, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("Batch", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteBatch(wms, 0); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, err := p.ReadBatch(rms, 0); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("IP", func(b *testing.B) {
|
||||
switch runtime.GOOS {
|
||||
case "netbsd":
|
||||
b.Skip("need to configure gre on netbsd")
|
||||
case "openbsd":
|
||||
b.Skip("net.inet.gre.allow=0 by default on openbsd")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket(fmt.Sprintf("ip4:%d", iana.ProtocolGRE), "127.0.0.1")
|
||||
if err != nil {
|
||||
b.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
dst := c.LocalAddr()
|
||||
cf := ipv4.FlagTTL | ipv4.FlagInterface
|
||||
if err := p.SetControlMessage(cf, true); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
wms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{datagram},
|
||||
Addr: dst,
|
||||
OOB: cm.Marshal(),
|
||||
},
|
||||
}
|
||||
rms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{bb},
|
||||
OOB: ipv4.NewControlMessage(cf),
|
||||
},
|
||||
}
|
||||
b.Run("Net", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := c.WriteTo(datagram, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, err := c.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("ToFrom", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteTo(datagram, &cm, dst); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, _, _, err := p.ReadFrom(bb); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("Batch", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := p.WriteBatch(wms, 0); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, err := p.ReadBatch(rms, 0); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestPacketConnConcurrentReadWriteUnicast(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "nacl", "plan9", "windows":
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
payload := []byte("HELLO-R-U-THERE")
|
||||
iph, err := (&ipv4.Header{
|
||||
Version: ipv4.Version,
|
||||
Len: ipv4.HeaderLen,
|
||||
TotalLen: ipv4.HeaderLen + len(payload),
|
||||
TTL: 1,
|
||||
Protocol: iana.ProtocolReserved,
|
||||
Src: net.IPv4(192, 0, 2, 1),
|
||||
Dst: net.IPv4(192, 0, 2, 254),
|
||||
}).Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
greh := []byte{0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
datagram := append(greh, append(iph, payload...)...)
|
||||
|
||||
t.Run("UDP", func(t *testing.T) {
|
||||
c, err := nettest.NewLocalPacketListener("udp4")
|
||||
if err != nil {
|
||||
t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
t.Run("ToFrom", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, payload, c.LocalAddr(), false)
|
||||
})
|
||||
t.Run("Batch", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, payload, c.LocalAddr(), true)
|
||||
})
|
||||
})
|
||||
t.Run("IP", func(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "netbsd":
|
||||
t.Skip("need to configure gre on netbsd")
|
||||
case "openbsd":
|
||||
t.Skip("net.inet.gre.allow=0 by default on openbsd")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket(fmt.Sprintf("ip4:%d", iana.ProtocolGRE), "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
||||
}
|
||||
defer c.Close()
|
||||
p := ipv4.NewPacketConn(c)
|
||||
t.Run("ToFrom", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, datagram, c.LocalAddr(), false)
|
||||
})
|
||||
t.Run("Batch", func(t *testing.T) {
|
||||
testPacketConnConcurrentReadWriteUnicast(t, p, datagram, c.LocalAddr(), true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv4.PacketConn, data []byte, dst net.Addr, batch bool) {
|
||||
ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
|
||||
cf := ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst | ipv4.FlagInterface
|
||||
|
||||
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
|
||||
if nettest.ProtocolNotSupported(err) {
|
||||
t.Skipf("not supported on %s", runtime.GOOS)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
reader := func() {
|
||||
defer wg.Done()
|
||||
b := make([]byte, 128)
|
||||
n, cm, _, err := p.ReadFrom(b)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if !bytes.Equal(b[:n], data) {
|
||||
t.Errorf("got %#v; want %#v", b[:n], data)
|
||||
return
|
||||
}
|
||||
s := cm.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Errorf("should be space-separated values: %s", s)
|
||||
return
|
||||
}
|
||||
}
|
||||
batchReader := func() {
|
||||
defer wg.Done()
|
||||
ms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{make([]byte, 128)},
|
||||
OOB: ipv4.NewControlMessage(cf),
|
||||
},
|
||||
}
|
||||
n, err := p.ReadBatch(ms, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n != len(ms) {
|
||||
t.Errorf("got %d; want %d", n, len(ms))
|
||||
return
|
||||
}
|
||||
var cm ipv4.ControlMessage
|
||||
if err := cm.Parse(ms[0].OOB[:ms[0].NN]); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
var b []byte
|
||||
if _, ok := dst.(*net.IPAddr); ok {
|
||||
var h ipv4.Header
|
||||
if err := h.Parse(ms[0].Buffers[0][:ms[0].N]); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
b = ms[0].Buffers[0][h.Len:ms[0].N]
|
||||
} else {
|
||||
b = ms[0].Buffers[0][:ms[0].N]
|
||||
}
|
||||
if !bytes.Equal(b, data) {
|
||||
t.Errorf("got %#v; want %#v", b, data)
|
||||
return
|
||||
}
|
||||
s := cm.String()
|
||||
if strings.Contains(s, ",") {
|
||||
t.Errorf("should be space-separated values: %s", s)
|
||||
return
|
||||
}
|
||||
}
|
||||
writer := func(toggle bool) {
|
||||
defer wg.Done()
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
n, err := p.WriteTo(data, &cm, dst)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n != len(data) {
|
||||
t.Errorf("got %d; want %d", n, len(data))
|
||||
return
|
||||
}
|
||||
}
|
||||
batchWriter := func(toggle bool) {
|
||||
defer wg.Done()
|
||||
cm := ipv4.ControlMessage{
|
||||
Src: net.IPv4(127, 0, 0, 1),
|
||||
}
|
||||
if ifi != nil {
|
||||
cm.IfIndex = ifi.Index
|
||||
}
|
||||
if err := p.SetControlMessage(cf, toggle); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
ms := []ipv4.Message{
|
||||
{
|
||||
Buffers: [][]byte{data},
|
||||
OOB: cm.Marshal(),
|
||||
Addr: dst,
|
||||
},
|
||||
}
|
||||
n, err := p.WriteBatch(ms, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if n != len(ms) {
|
||||
t.Errorf("got %d; want %d", n, len(ms))
|
||||
return
|
||||
}
|
||||
if ms[0].N != len(data) {
|
||||
t.Errorf("got %d; want %d", ms[0].N, len(data))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const N = 10
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
if batch {
|
||||
go batchReader()
|
||||
} else {
|
||||
go reader()
|
||||
}
|
||||
}
|
||||
wg.Add(2 * N)
|
||||
for i := 0; i < 2*N; i++ {
|
||||
if batch {
|
||||
go batchWriter(i%2 != 0)
|
||||
} else {
|
||||
go writer(i%2 != 0)
|
||||
}
|
||||
|
||||
}
|
||||
wg.Add(N)
|
||||
for i := 0; i < N; i++ {
|
||||
if batch {
|
||||
go batchReader()
|
||||
} else {
|
||||
go reader()
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
14
vendor/golang.org/x/net/ipv4/sockopt.go
generated
vendored
14
vendor/golang.org/x/net/ipv4/sockopt.go
generated
vendored
@@ -4,6 +4,8 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import "golang.org/x/net/internal/socket"
|
||||
|
||||
// Sticky socket options
|
||||
const (
|
||||
ssoTOS = iota // header field for unicast packet
|
||||
@@ -24,16 +26,12 @@ const (
|
||||
ssoLeaveSourceGroup // source-specific multicast
|
||||
ssoBlockSourceGroup // 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
|
||||
const (
|
||||
ssoTypeByte = iota + 1
|
||||
ssoTypeInt
|
||||
ssoTypeInterface
|
||||
ssoTypeICMPFilter
|
||||
ssoTypeIPMreq
|
||||
ssoTypeIPMreq = iota + 1
|
||||
ssoTypeIPMreqn
|
||||
ssoTypeGroupReq
|
||||
ssoTypeGroupSourceReq
|
||||
@@ -41,6 +39,6 @@ const (
|
||||
|
||||
// A sockOpt represents a binding for sticky socket option.
|
||||
type sockOpt struct {
|
||||
name int // option name, must be equal or greater than 1
|
||||
typ int // option value type, must be equal or greater than 1
|
||||
socket.Option
|
||||
typ int // hint for option value type; optional
|
||||
}
|
||||
|
||||
46
vendor/golang.org/x/net/ipv4/sockopt_asmreq_posix.go
generated
vendored
46
vendor/golang.org/x/net/ipv4/sockopt_asmreq_posix.go
generated
vendored
@@ -1,46 +0,0 @@
|
||||
// Copyright 2012 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 netbsd openbsd solaris windows
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
)
|
||||
|
||||
func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
|
||||
mreq := ipMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
|
||||
if err := setIPMreqInterface(&mreq, ifi); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreq), sizeofIPMreq))
|
||||
}
|
||||
|
||||
func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
|
||||
var b [4]byte
|
||||
l := uint32(4)
|
||||
if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), &l); err != nil {
|
||||
return nil, os.NewSyscallError("getsockopt", err)
|
||||
}
|
||||
ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ifi, nil
|
||||
}
|
||||
|
||||
func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
|
||||
ip, err := netInterfaceToIP4(ifi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var b [4]byte
|
||||
copy(b[:], ip)
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&b[0]), uint32(4)))
|
||||
}
|
||||
21
vendor/golang.org/x/net/ipv4/sockopt_asmreq_stub.go
generated
vendored
21
vendor/golang.org/x/net/ipv4/sockopt_asmreq_stub.go
generated
vendored
@@ -1,21 +0,0 @@
|
||||
// Copyright 2012 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,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
|
||||
func setsockoptIPMreq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
|
||||
func getsockoptInterface(s uintptr, name int) (*net.Interface, error) {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
|
||||
func setsockoptInterface(s uintptr, name int, ifi *net.Interface) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
115
vendor/golang.org/x/net/ipv4/sockopt_posix.go
generated
vendored
115
vendor/golang.org/x/net/ipv4/sockopt_posix.go
generated
vendored
@@ -8,115 +8,64 @@ package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func getInt(s uintptr, opt *sockOpt) (int, error) {
|
||||
if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
|
||||
return 0, errOpNoSupport
|
||||
}
|
||||
var i int32
|
||||
var b byte
|
||||
p := unsafe.Pointer(&i)
|
||||
l := uint32(4)
|
||||
if opt.typ == ssoTypeByte {
|
||||
p = unsafe.Pointer(&b)
|
||||
l = 1
|
||||
}
|
||||
if err := getsockopt(s, iana.ProtocolIP, opt.name, p, &l); err != nil {
|
||||
return 0, os.NewSyscallError("getsockopt", err)
|
||||
}
|
||||
if opt.typ == ssoTypeByte {
|
||||
return int(b), nil
|
||||
}
|
||||
return int(i), nil
|
||||
}
|
||||
|
||||
func setInt(s uintptr, opt *sockOpt, v int) error {
|
||||
if opt.name < 1 || (opt.typ != ssoTypeByte && opt.typ != ssoTypeInt) {
|
||||
return errOpNoSupport
|
||||
}
|
||||
i := int32(v)
|
||||
var b byte
|
||||
p := unsafe.Pointer(&i)
|
||||
l := uint32(4)
|
||||
if opt.typ == ssoTypeByte {
|
||||
b = byte(v)
|
||||
p = unsafe.Pointer(&b)
|
||||
l = 1
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, opt.name, p, l))
|
||||
}
|
||||
|
||||
func getInterface(s uintptr, opt *sockOpt) (*net.Interface, error) {
|
||||
if opt.name < 1 {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
switch opt.typ {
|
||||
case ssoTypeInterface:
|
||||
return getsockoptInterface(s, opt.name)
|
||||
func (so *sockOpt) getMulticastInterface(c *socket.Conn) (*net.Interface, error) {
|
||||
switch so.typ {
|
||||
case ssoTypeIPMreqn:
|
||||
return getsockoptIPMreqn(s, opt.name)
|
||||
return so.getIPMreqn(c)
|
||||
default:
|
||||
return nil, errOpNoSupport
|
||||
return so.getMulticastIf(c)
|
||||
}
|
||||
}
|
||||
|
||||
func setInterface(s uintptr, opt *sockOpt, ifi *net.Interface) error {
|
||||
if opt.name < 1 {
|
||||
return errOpNoSupport
|
||||
}
|
||||
switch opt.typ {
|
||||
case ssoTypeInterface:
|
||||
return setsockoptInterface(s, opt.name, ifi)
|
||||
func (so *sockOpt) setMulticastInterface(c *socket.Conn, ifi *net.Interface) error {
|
||||
switch so.typ {
|
||||
case ssoTypeIPMreqn:
|
||||
return setsockoptIPMreqn(s, opt.name, ifi, nil)
|
||||
return so.setIPMreqn(c, ifi, nil)
|
||||
default:
|
||||
return errOpNoSupport
|
||||
return so.setMulticastIf(c, ifi)
|
||||
}
|
||||
}
|
||||
|
||||
func getICMPFilter(s uintptr, opt *sockOpt) (*ICMPFilter, error) {
|
||||
if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
|
||||
func (so *sockOpt) getICMPFilter(c *socket.Conn) (*ICMPFilter, error) {
|
||||
b := make([]byte, so.Len)
|
||||
n, err := so.Get(c, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n != sizeofICMPFilter {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
var f ICMPFilter
|
||||
l := uint32(sizeofICMPFilter)
|
||||
if err := getsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.icmpFilter), &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 {
|
||||
if opt.name < 1 || opt.typ != ssoTypeICMPFilter {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolReserved, opt.name, unsafe.Pointer(&f.icmpFilter), sizeofICMPFilter))
|
||||
func (so *sockOpt) setICMPFilter(c *socket.Conn, f *ICMPFilter) error {
|
||||
b := (*[sizeofICMPFilter]byte)(unsafe.Pointer(f))[:sizeofICMPFilter]
|
||||
return so.Set(c, b)
|
||||
}
|
||||
|
||||
func setGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp net.IP) error {
|
||||
if opt.name < 1 {
|
||||
return errOpNoSupport
|
||||
}
|
||||
switch opt.typ {
|
||||
func (so *sockOpt) setGroup(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
switch so.typ {
|
||||
case ssoTypeIPMreq:
|
||||
return setsockoptIPMreq(s, opt.name, ifi, grp)
|
||||
return so.setIPMreq(c, ifi, grp)
|
||||
case ssoTypeIPMreqn:
|
||||
return setsockoptIPMreqn(s, opt.name, ifi, grp)
|
||||
return so.setIPMreqn(c, ifi, grp)
|
||||
case ssoTypeGroupReq:
|
||||
return setsockoptGroupReq(s, opt.name, ifi, grp)
|
||||
return so.setGroupReq(c, ifi, grp)
|
||||
default:
|
||||
return errOpNoSupport
|
||||
}
|
||||
}
|
||||
|
||||
func setSourceGroup(s uintptr, opt *sockOpt, ifi *net.Interface, grp, src net.IP) error {
|
||||
if opt.name < 1 || opt.typ != ssoTypeGroupSourceReq {
|
||||
return errOpNoSupport
|
||||
}
|
||||
return setsockoptGroupSourceReq(s, opt.name, ifi, grp, src)
|
||||
func (so *sockOpt) setSourceGroup(c *socket.Conn, ifi *net.Interface, grp, src net.IP) error {
|
||||
return so.setGroupSourceReq(c, ifi, grp, src)
|
||||
}
|
||||
|
||||
func (so *sockOpt) setBPF(c *socket.Conn, f []bpf.RawInstruction) error {
|
||||
return so.setAttachFilter(c, f)
|
||||
}
|
||||
|
||||
35
vendor/golang.org/x/net/ipv4/sockopt_stub.go
generated
vendored
35
vendor/golang.org/x/net/ipv4/sockopt_stub.go
generated
vendored
@@ -2,10 +2,41 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build nacl plan9
|
||||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
func setInt(s uintptr, opt *sockOpt, v int) error {
|
||||
import (
|
||||
"net"
|
||||
|
||||
"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) 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
|
||||
}
|
||||
|
||||
@@ -6,7 +6,43 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (so *sockOpt) setIPMreq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
mreq := ipMreq{Multiaddr: [4]byte{grp[0], grp[1], grp[2], grp[3]}}
|
||||
if err := setIPMreqInterface(&mreq, ifi); err != nil {
|
||||
return err
|
||||
}
|
||||
b := (*[sizeofIPMreq]byte)(unsafe.Pointer(&mreq))[:sizeofIPMreq]
|
||||
return so.Set(c, b)
|
||||
}
|
||||
|
||||
func (so *sockOpt) getMulticastIf(c *socket.Conn) (*net.Interface, error) {
|
||||
var b [4]byte
|
||||
if _, err := so.Get(c, b[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ifi, err := netIP4ToInterface(net.IPv4(b[0], b[1], b[2], b[3]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ifi, nil
|
||||
}
|
||||
|
||||
func (so *sockOpt) setMulticastIf(c *socket.Conn, ifi *net.Interface) error {
|
||||
ip, err := netInterfaceToIP4(ifi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var b [4]byte
|
||||
copy(b[:], ip)
|
||||
return so.Set(c, b[:])
|
||||
}
|
||||
|
||||
func setIPMreqInterface(mreq *ipMreq, ifi *net.Interface) error {
|
||||
if ifi == nil {
|
||||
25
vendor/golang.org/x/net/ipv4/sys_asmreq_stub.go
generated
vendored
Normal file
25
vendor/golang.org/x/net/ipv4/sys_asmreq_stub.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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 !darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (so *sockOpt) setIPMreq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
|
||||
func (so *sockOpt) getMulticastIf(c *socket.Conn) (*net.Interface, error) {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
|
||||
func (so *sockOpt) setMulticastIf(c *socket.Conn, ifi *net.Interface) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
@@ -8,18 +8,17 @@ package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
|
||||
var mreqn ipMreqn
|
||||
l := uint32(sizeofIPMreqn)
|
||||
if err := getsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), &l); err != nil {
|
||||
return nil, os.NewSyscallError("getsockopt", err)
|
||||
func (so *sockOpt) getIPMreqn(c *socket.Conn) (*net.Interface, error) {
|
||||
b := make([]byte, so.Len)
|
||||
if _, err := so.Get(c, b); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mreqn := (*ipMreqn)(unsafe.Pointer(&b[0]))
|
||||
if mreqn.Ifindex == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -30,7 +29,7 @@ func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
|
||||
return ifi, nil
|
||||
}
|
||||
|
||||
func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
|
||||
func (so *sockOpt) setIPMreqn(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
var mreqn ipMreqn
|
||||
if ifi != nil {
|
||||
mreqn.Ifindex = int32(ifi.Index)
|
||||
@@ -38,5 +37,6 @@ func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) erro
|
||||
if grp != nil {
|
||||
mreqn.Multiaddr = [4]byte{grp[0], grp[1], grp[2], grp[3]}
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, unsafe.Pointer(&mreqn), sizeofIPMreqn))
|
||||
b := (*[sizeofIPMreqn]byte)(unsafe.Pointer(&mreqn))[:sizeofIPMreqn]
|
||||
return so.Set(c, b)
|
||||
}
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
func getsockoptIPMreqn(s uintptr, name int) (*net.Interface, error) {
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (so *sockOpt) getIPMreqn(c *socket.Conn) (*net.Interface, error) {
|
||||
return nil, errOpNoSupport
|
||||
}
|
||||
|
||||
func setsockoptIPMreqn(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
|
||||
func (so *sockOpt) setIPMreqn(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
23
vendor/golang.org/x/net/ipv4/sys_bpf.go
generated
vendored
Normal file
23
vendor/golang.org/x/net/ipv4/sys_bpf.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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 ipv4
|
||||
|
||||
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)
|
||||
}
|
||||
16
vendor/golang.org/x/net/ipv4/sys_bpf_stub.go
generated
vendored
Normal file
16
vendor/golang.org/x/net/ipv4/sys_bpf_stub.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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 ipv4
|
||||
|
||||
import (
|
||||
"golang.org/x/net/bpf"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
func (so *sockOpt) setAttachFilter(c *socket.Conn, f []bpf.RawInstruction) error {
|
||||
return errOpNoSupport
|
||||
}
|
||||
29
vendor/golang.org/x/net/ipv4/sys_bsd.go
generated
vendored
29
vendor/golang.org/x/net/ipv4/sys_bsd.go
generated
vendored
@@ -2,13 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build dragonfly netbsd
|
||||
// +build netbsd openbsd
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -18,17 +21,17 @@ var (
|
||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 1}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 1}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoReceiveDst: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVDSTADDR, Len: 4}},
|
||||
ssoReceiveInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVIF, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_ADD_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_DROP_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
}
|
||||
)
|
||||
|
||||
79
vendor/golang.org/x/net/ipv4/sys_darwin.go
generated
vendored
79
vendor/golang.org/x/net/ipv4/sys_darwin.go
generated
vendored
@@ -6,8 +6,13 @@ package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -17,60 +22,52 @@ var (
|
||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoStripHeader: {sysIP_STRIPHDR, ssoTypeInt},
|
||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 1}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoReceiveDst: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVDSTADDR, Len: 4}},
|
||||
ssoReceiveInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVIF, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoStripHeader: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_STRIPHDR, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_ADD_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_DROP_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Seems like kern.osreldate is veiled on latest OS X. We use
|
||||
// kern.osrelease instead.
|
||||
osver, err := syscall.Sysctl("kern.osrelease")
|
||||
s, err := syscall.Sysctl("kern.osrelease")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var i int
|
||||
for i = range osver {
|
||||
if osver[i] == '.' {
|
||||
break
|
||||
}
|
||||
ss := strings.Split(s, ".")
|
||||
if len(ss) == 0 {
|
||||
return
|
||||
}
|
||||
// The IP_PKTINFO and protocol-independent multicast API were
|
||||
// introduced in OS X 10.7 (Darwin 11.0.0). But it looks like
|
||||
// those features require OS X 10.8 (Darwin 12.0.0) and above.
|
||||
// introduced in OS X 10.7 (Darwin 11). But it looks like
|
||||
// those features require OS X 10.8 (Darwin 12) or above.
|
||||
// See http://support.apple.com/kb/HT1633.
|
||||
if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '2' {
|
||||
ctlOpts[ctlPacketInfo].name = sysIP_PKTINFO
|
||||
ctlOpts[ctlPacketInfo].length = sizeofInetPktinfo
|
||||
ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
|
||||
ctlOpts[ctlPacketInfo].parse = parsePacketInfo
|
||||
sockOpts[ssoPacketInfo].name = sysIP_RECVPKTINFO
|
||||
sockOpts[ssoPacketInfo].typ = ssoTypeInt
|
||||
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
|
||||
sockOpts[ssoJoinGroup].name = sysMCAST_JOIN_GROUP
|
||||
sockOpts[ssoJoinGroup].typ = ssoTypeGroupReq
|
||||
sockOpts[ssoLeaveGroup].name = sysMCAST_LEAVE_GROUP
|
||||
sockOpts[ssoLeaveGroup].typ = ssoTypeGroupReq
|
||||
sockOpts[ssoJoinSourceGroup].name = sysMCAST_JOIN_SOURCE_GROUP
|
||||
sockOpts[ssoJoinSourceGroup].typ = ssoTypeGroupSourceReq
|
||||
sockOpts[ssoLeaveSourceGroup].name = sysMCAST_LEAVE_SOURCE_GROUP
|
||||
sockOpts[ssoLeaveSourceGroup].typ = ssoTypeGroupSourceReq
|
||||
sockOpts[ssoBlockSourceGroup].name = sysMCAST_BLOCK_SOURCE
|
||||
sockOpts[ssoBlockSourceGroup].typ = ssoTypeGroupSourceReq
|
||||
sockOpts[ssoUnblockSourceGroup].name = sysMCAST_UNBLOCK_SOURCE
|
||||
sockOpts[ssoUnblockSourceGroup].typ = ssoTypeGroupSourceReq
|
||||
if mjver, err := strconv.Atoi(ss[0]); err != nil || mjver < 12 {
|
||||
return
|
||||
}
|
||||
ctlOpts[ctlPacketInfo].name = sysIP_PKTINFO
|
||||
ctlOpts[ctlPacketInfo].length = sizeofInetPktinfo
|
||||
ctlOpts[ctlPacketInfo].marshal = marshalPacketInfo
|
||||
ctlOpts[ctlPacketInfo].parse = parsePacketInfo
|
||||
sockOpts[ssoPacketInfo] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVPKTINFO, Len: 4}}
|
||||
sockOpts[ssoMulticastInterface] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: sizeofIPMreqn}, typ: ssoTypeIPMreqn}
|
||||
sockOpts[ssoJoinGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq}
|
||||
sockOpts[ssoLeaveGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq}
|
||||
sockOpts[ssoJoinSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
|
||||
sockOpts[ssoLeaveSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
|
||||
sockOpts[ssoBlockSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
|
||||
sockOpts[ssoUnblockSourceGroup] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq}
|
||||
}
|
||||
|
||||
func (pi *inetPktinfo) setIfindex(i int) {
|
||||
|
||||
35
vendor/golang.org/x/net/ipv4/sys_dragonfly.go
generated
vendored
Normal file
35
vendor/golang.org/x/net/ipv4/sys_dragonfly.go
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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.
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
ctlOpts = [ctlMax]ctlOpt{
|
||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
||||
}
|
||||
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 1}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoReceiveDst: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVDSTADDR, Len: 4}},
|
||||
ssoReceiveInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVIF, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_ADD_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_DROP_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
}
|
||||
)
|
||||
37
vendor/golang.org/x/net/ipv4/sys_freebsd.go
generated
vendored
37
vendor/golang.org/x/net/ipv4/sys_freebsd.go
generated
vendored
@@ -10,6 +10,9 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,29 +22,29 @@ var (
|
||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 1}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoReceiveDst: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVDSTADDR, Len: 4}},
|
||||
ssoReceiveInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVIF, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
freebsdVersion, _ = syscall.SysctlUint32("kern.osreldate")
|
||||
if freebsdVersion >= 1000000 {
|
||||
sockOpts[ssoMulticastInterface].typ = ssoTypeIPMreqn
|
||||
sockOpts[ssoMulticastInterface] = &sockOpt{Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: sizeofIPMreqn}, typ: ssoTypeIPMreqn}
|
||||
}
|
||||
if runtime.GOOS == "freebsd" && runtime.GOARCH == "386" {
|
||||
archs, _ := syscall.Sysctl("kern.supported_archs")
|
||||
|
||||
36
vendor/golang.org/x/net/ipv4/sys_linux.go
generated
vendored
36
vendor/golang.org/x/net/ipv4/sys_linux.go
generated
vendored
@@ -8,6 +8,9 @@ import (
|
||||
"net"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -16,22 +19,23 @@ var (
|
||||
ctlPacketInfo: {sysIP_PKTINFO, sizeofInetPktinfo, marshalPacketInfo, parsePacketInfo},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeInt},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeIPMreqn},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoPacketInfo: {sysIP_PKTINFO, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoICMPFilter: {sysICMP_FILTER, ssoTypeICMPFilter},
|
||||
ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 4}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: sizeofIPMreqn}, typ: ssoTypeIPMreqn},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoPacketInfo: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_PKTINFO, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoICMPFilter: {Option: socket.Option{Level: iana.ProtocolReserved, Name: sysICMP_FILTER, Len: sizeofICMPFilter}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoAttachFilter: {Option: socket.Option{Level: sysSOL_SOCKET, Name: sysSO_ATTACH_FILTER, Len: sizeofSockFprog}},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
8
vendor/golang.org/x/net/ipv4/sys_linux_386.s
generated
vendored
8
vendor/golang.org/x/net/ipv4/sys_linux_386.s
generated
vendored
@@ -1,8 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
TEXT ·socketcall(SB),NOSPLIT,$0-36
|
||||
JMP syscall·socketcall(SB)
|
||||
32
vendor/golang.org/x/net/ipv4/sys_openbsd.go
generated
vendored
32
vendor/golang.org/x/net/ipv4/sys_openbsd.go
generated
vendored
@@ -1,32 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
ctlOpts = [ctlMax]ctlOpt{
|
||||
ctlTTL: {sysIP_RECVTTL, 1, marshalTTL, parseTTL},
|
||||
ctlDst: {sysIP_RECVDSTADDR, net.IPv4len, marshalDst, parseDst},
|
||||
ctlInterface: {sysIP_RECVIF, syscall.SizeofSockaddrDatalink, marshalInterface, parseInterface},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeByte},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoReceiveDst: {sysIP_RECVDSTADDR, ssoTypeInt},
|
||||
ssoReceiveInterface: {sysIP_RECVIF, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
||||
}
|
||||
)
|
||||
33
vendor/golang.org/x/net/ipv4/sys_solaris.go
generated
vendored
33
vendor/golang.org/x/net/ipv4/sys_solaris.go
generated
vendored
@@ -8,6 +8,9 @@ import (
|
||||
"net"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -16,21 +19,21 @@ var (
|
||||
ctlPacketInfo: {sysIP_PKTINFO, sizeofInetPktinfo, marshalPacketInfo, parsePacketInfo},
|
||||
}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeByte},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeByte},
|
||||
ssoReceiveTTL: {sysIP_RECVTTL, ssoTypeInt},
|
||||
ssoPacketInfo: {sysIP_RECVPKTINFO, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoJoinGroup: {sysMCAST_JOIN_GROUP, ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {sysMCAST_LEAVE_GROUP, ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {sysMCAST_JOIN_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {sysMCAST_LEAVE_SOURCE_GROUP, ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {sysMCAST_BLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {sysMCAST_UNBLOCK_SOURCE, ssoTypeGroupSourceReq},
|
||||
sockOpts = map[int]sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 1}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 1}},
|
||||
ssoReceiveTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVTTL, Len: 4}},
|
||||
ssoPacketInfo: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_RECVPKTINFO, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_GROUP, Len: sizeofGroupReq}, typ: ssoTypeGroupReq},
|
||||
ssoJoinSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_JOIN_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoLeaveSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_LEAVE_SOURCE_GROUP, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoBlockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_BLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
ssoUnblockSourceGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysMCAST_UNBLOCK_SOURCE, Len: sizeofGroupSourceReq}, typ: ssoTypeGroupSourceReq},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
8
vendor/golang.org/x/net/ipv4/sys_solaris_amd64.s
generated
vendored
8
vendor/golang.org/x/net/ipv4/sys_solaris_amd64.s
generated
vendored
@@ -1,8 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
TEXT ·sysvicall6(SB),NOSPLIT,$0-88
|
||||
JMP syscall·sysvicall6(SB)
|
||||
@@ -8,54 +8,47 @@ package ipv4
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
var freebsd32o64 bool
|
||||
|
||||
func setsockoptGroupReq(s uintptr, name int, ifi *net.Interface, grp net.IP) error {
|
||||
func (so *sockOpt) setGroupReq(c *socket.Conn, ifi *net.Interface, grp net.IP) error {
|
||||
var gr groupReq
|
||||
if ifi != nil {
|
||||
gr.Interface = uint32(ifi.Index)
|
||||
}
|
||||
gr.setGroup(grp)
|
||||
var p unsafe.Pointer
|
||||
var l uint32
|
||||
var b []byte
|
||||
if freebsd32o64 {
|
||||
var d [sizeofGroupReq + 4]byte
|
||||
s := (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))
|
||||
copy(d[:4], s[:4])
|
||||
copy(d[8:], s[4:])
|
||||
p = unsafe.Pointer(&d[0])
|
||||
l = sizeofGroupReq + 4
|
||||
b = d[:]
|
||||
} else {
|
||||
p = unsafe.Pointer(&gr)
|
||||
l = sizeofGroupReq
|
||||
b = (*[sizeofGroupReq]byte)(unsafe.Pointer(&gr))[:sizeofGroupReq]
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
|
||||
return so.Set(c, b)
|
||||
}
|
||||
|
||||
func setsockoptGroupSourceReq(s uintptr, name int, 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
|
||||
if ifi != nil {
|
||||
gsr.Interface = uint32(ifi.Index)
|
||||
}
|
||||
gsr.setSourceGroup(grp, src)
|
||||
var p unsafe.Pointer
|
||||
var l uint32
|
||||
var b []byte
|
||||
if freebsd32o64 {
|
||||
var d [sizeofGroupSourceReq + 4]byte
|
||||
s := (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))
|
||||
copy(d[:4], s[:4])
|
||||
copy(d[8:], s[4:])
|
||||
p = unsafe.Pointer(&d[0])
|
||||
l = sizeofGroupSourceReq + 4
|
||||
b = d[:]
|
||||
} else {
|
||||
p = unsafe.Pointer(&gsr)
|
||||
l = sizeofGroupSourceReq
|
||||
b = (*[sizeofGroupSourceReq]byte)(unsafe.Pointer(&gsr))[:sizeofGroupSourceReq]
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, iana.ProtocolIP, name, p, l))
|
||||
return so.Set(c, b)
|
||||
}
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
func setsockoptGroupReq(s uintptr, name int, 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
|
||||
}
|
||||
|
||||
func setsockoptGroupSourceReq(s uintptr, name int, 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
|
||||
}
|
||||
4
vendor/golang.org/x/net/ipv4/sys_stub.go
generated
vendored
4
vendor/golang.org/x/net/ipv4/sys_stub.go
generated
vendored
@@ -2,12 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build nacl plan9
|
||||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package ipv4
|
||||
|
||||
var (
|
||||
ctlOpts = [ctlMax]ctlOpt{}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{}
|
||||
sockOpts = map[int]*sockOpt{}
|
||||
)
|
||||
|
||||
23
vendor/golang.org/x/net/ipv4/sys_windows.go
generated
vendored
23
vendor/golang.org/x/net/ipv4/sys_windows.go
generated
vendored
@@ -4,6 +4,11 @@
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
const (
|
||||
// See ws2tcpip.h.
|
||||
sysIP_OPTIONS = 0x1
|
||||
@@ -45,15 +50,15 @@ type ipMreqSource struct {
|
||||
var (
|
||||
ctlOpts = [ctlMax]ctlOpt{}
|
||||
|
||||
sockOpts = [ssoMax]sockOpt{
|
||||
ssoTOS: {sysIP_TOS, ssoTypeInt},
|
||||
ssoTTL: {sysIP_TTL, ssoTypeInt},
|
||||
ssoMulticastTTL: {sysIP_MULTICAST_TTL, ssoTypeInt},
|
||||
ssoMulticastInterface: {sysIP_MULTICAST_IF, ssoTypeInterface},
|
||||
ssoMulticastLoopback: {sysIP_MULTICAST_LOOP, ssoTypeInt},
|
||||
ssoHeaderPrepend: {sysIP_HDRINCL, ssoTypeInt},
|
||||
ssoJoinGroup: {sysIP_ADD_MEMBERSHIP, ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {sysIP_DROP_MEMBERSHIP, ssoTypeIPMreq},
|
||||
sockOpts = map[int]*sockOpt{
|
||||
ssoTOS: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TOS, Len: 4}},
|
||||
ssoTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_TTL, Len: 4}},
|
||||
ssoMulticastTTL: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_TTL, Len: 4}},
|
||||
ssoMulticastInterface: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_IF, Len: 4}},
|
||||
ssoMulticastLoopback: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_MULTICAST_LOOP, Len: 4}},
|
||||
ssoHeaderPrepend: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_HDRINCL, Len: 4}},
|
||||
ssoJoinGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_ADD_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
ssoLeaveGroup: {Option: socket.Option{Level: iana.ProtocolIP, Name: sysIP_DROP_MEMBERSHIP, Len: sizeofIPMreq}, typ: ssoTypeIPMreq},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
31
vendor/golang.org/x/net/ipv4/syscall_linux_386.go
generated
vendored
31
vendor/golang.org/x/net/ipv4/syscall_linux_386.go
generated
vendored
@@ -1,31 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
sysGETSOCKOPT = 0xf
|
||||
sysSETSOCKOPT = 0xe
|
||||
)
|
||||
|
||||
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
|
||||
|
||||
func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
|
||||
if _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
|
||||
if _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
38
vendor/golang.org/x/net/ipv4/syscall_solaris.go
generated
vendored
38
vendor/golang.org/x/net/ipv4/syscall_solaris.go
generated
vendored
@@ -1,38 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipv4
|
||||
|
||||
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
|
||||
}
|
||||
26
vendor/golang.org/x/net/ipv4/syscall_unix.go
generated
vendored
26
vendor/golang.org/x/net/ipv4/syscall_unix.go
generated
vendored
@@ -1,26 +0,0 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build darwin dragonfly freebsd linux,!386 netbsd openbsd
|
||||
|
||||
package ipv4
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func getsockopt(s uintptr, level, name int, v unsafe.Pointer, l *uint32) error {
|
||||
if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setsockopt(s uintptr, level, name int, v unsafe.Pointer, l uint32) error {
|
||||
if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
|
||||
return error(errno)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
18
vendor/golang.org/x/net/ipv4/syscall_windows.go
generated
vendored
18
vendor/golang.org/x/net/ipv4/syscall_windows.go
generated
vendored
@@ -1,18 +0,0 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipv4
|
||||
|
||||
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))
|
||||
}
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_386.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_386.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x104
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x8
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_amd64.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_amd64.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_arm.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_arm.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x104
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x8
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_arm64.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_arm64.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x104
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x8
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips64.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips64.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips64le.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_mips64le.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_mipsle.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_mipsle.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x104
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x8
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x104
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x8
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc64.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc64.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc64le.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_ppc64le.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
2
vendor/golang.org/x/net/ipv4/zsys_linux_s390x.go
generated
vendored
2
vendor/golang.org/x/net/ipv4/zsys_linux_s390x.go
generated
vendored
@@ -70,6 +70,8 @@ const (
|
||||
sizeofGroupSourceReq = 0x108
|
||||
|
||||
sizeofICMPFilter = 0x4
|
||||
|
||||
sizeofSockFprog = 0x10
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage struct {
|
||||
|
||||
Reference in New Issue
Block a user