vendor: github.com/ishidawataru/sctp f2269e66cdee387bd321445d5d300893449805be

full diff: 6e2cb13661...f2269e66cd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-05-19 14:11:08 +02:00
parent fb5ea7c4e0
commit 719504b810
7 changed files with 169 additions and 2 deletions

View file

@ -43,7 +43,7 @@ golang.org/x/net ab34263943818b32f575efc978a3
golang.org/x/sys ed371f2e16b4b305ee99df548828de367527b76b
golang.org/x/sync cd5d95a43a6e21273425c7ae415d3df9ea832eeb
github.com/pkg/errors 614d223910a179a466c1767a985424175c39b465 # v0.9.1
github.com/ishidawataru/sctp 6e2cb1366111dcf547c13531e3a263a067715847
github.com/ishidawataru/sctp f2269e66cdee387bd321445d5d300893449805be
go.opencensus.io 9c377598961b706d1542bd2d84d538b5094d596e # v0.22.0
gotest.tools/v3 bb0d8a963040ea5048dcef1a14d8f8b58a33d4b3 # v3.0.2

View file

@ -0,0 +1,3 @@
This source code includes following third party code
- ipsock_linux.go : licensed by the Go authors, see GO_LICENSE file for the license which applies to the code

View file

@ -0,0 +1,3 @@
module github.com/ishidawataru/sctp
go 1.12

View file

@ -1,3 +1,7 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the GO_LICENSE file.
package sctp
import (

View file

@ -1,3 +1,18 @@
// Copyright 2019 Wataru Ishida. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sctp
import (
@ -678,3 +693,37 @@ func (c *SCTPSndRcvInfoWrappedConn) SetReadDeadline(t time.Time) error {
func (c *SCTPSndRcvInfoWrappedConn) SetWriteDeadline(t time.Time) error {
return c.conn.SetWriteDeadline(t)
}
func (c *SCTPSndRcvInfoWrappedConn) SetWriteBuffer(bytes int) error {
return c.conn.SetWriteBuffer(bytes)
}
func (c *SCTPSndRcvInfoWrappedConn) GetWriteBuffer() (int, error) {
return c.conn.GetWriteBuffer()
}
func (c *SCTPSndRcvInfoWrappedConn) SetReadBuffer(bytes int) error {
return c.conn.SetReadBuffer(bytes)
}
func (c *SCTPSndRcvInfoWrappedConn) GetReadBuffer() (int, error) {
return c.conn.GetReadBuffer()
}
// SocketConfig contains options for the SCTP socket.
type SocketConfig struct {
// If Control is not nil it is called after the socket is created but before
// it is bound or connected.
Control func(network, address string, c syscall.RawConn) error
// InitMsg is the options to send in the initial SCTP message
InitMsg InitMsg
}
func (cfg *SocketConfig) Listen(net string, laddr *SCTPAddr) (*SCTPListener, error) {
return listenSCTPExtConfig(net, laddr, cfg.InitMsg, cfg.Control)
}
func (cfg *SocketConfig) Dial(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
return dialSCTPExtConfig(net, laddr, raddr, cfg.InitMsg, cfg.Control)
}

View file

@ -1,4 +1,18 @@
// +build linux,!386
// Copyright 2019 Wataru Ishida. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sctp
@ -40,6 +54,23 @@ func getsockopt(fd int, optname, optval, optlen uintptr) (uintptr, uintptr, erro
return r0, r1, nil
}
type rawConn struct {
sockfd int
}
func (r rawConn) Control(f func(fd uintptr)) error {
f(uintptr(r.sockfd))
return nil
}
func (r rawConn) Read(f func(fd uintptr) (done bool)) error {
panic("not implemented")
}
func (r rawConn) Write(f func(fd uintptr) (done bool)) error {
panic("not implemented")
}
func (c *SCTPConn) SCTPWrite(b []byte, info *SndRcvInfo) (int, error) {
var cbuf []byte
if info != nil {
@ -114,6 +145,22 @@ func (c *SCTPConn) Close() error {
return syscall.EBADF
}
func (c *SCTPConn) SetWriteBuffer(bytes int) error {
return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBUF, bytes)
}
func (c *SCTPConn) GetWriteBuffer() (int, error) {
return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
}
func (c *SCTPConn) SetReadBuffer(bytes int) error {
return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bytes)
}
func (c *SCTPConn) GetReadBuffer() (int, error) {
return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
}
// ListenSCTP - start listener on specified address/port
func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
return ListenSCTPExt(net, laddr, InitMsg{NumOstreams: SCTP_MAX_STREAM})
@ -121,6 +168,11 @@ func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
// ListenSCTPExt - start listener on specified address/port with given SCTP options
func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListener, error) {
return listenSCTPExtConfig(network, laddr, options, nil)
}
// listenSCTPExtConfig - start listener on specified address/port with given SCTP options and socket configuration
func listenSCTPExtConfig(network string, laddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPListener, error) {
af, ipv6only := favoriteAddrFamily(network, laddr, nil, "listen")
sock, err := syscall.Socket(
af,
@ -140,6 +192,12 @@ func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe
if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
return nil, err
}
if control != nil {
rc := rawConn{sockfd: sock}
if err = control(network, laddr.String(), rc); err != nil {
return nil, err
}
}
err = setInitOpts(sock, options)
if err != nil {
return nil, err
@ -154,7 +212,7 @@ func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe
laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{IP: net.IPv6zero})
}
}
err := SCTPBind(sock, laddr, SCTP_BINDX_ADD_ADDR)
err = SCTPBind(sock, laddr, SCTP_BINDX_ADD_ADDR)
if err != nil {
return nil, err
}
@ -191,6 +249,11 @@ func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
// DialSCTPExt - same as DialSCTP but with given SCTP options
func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error) {
return dialSCTPExtConfig(network, laddr, raddr, options, nil)
}
// dialSCTPExtConfig - same as DialSCTP but with given SCTP options and socket configuration
func dialSCTPExtConfig(network string, laddr, raddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPConn, error) {
af, ipv6only := favoriteAddrFamily(network, laddr, raddr, "dial")
sock, err := syscall.Socket(
af,
@ -210,6 +273,12 @@ func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTP
if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
return nil, err
}
if control != nil {
rc := rawConn{sockfd: sock}
if err = control(network, laddr.String(), rc); err != nil {
return nil, err
}
}
err = setInitOpts(sock, options)
if err != nil {
return nil, err

View file

@ -1,4 +1,18 @@
// +build !linux linux,386
// Copyright 2019 Wataru Ishida. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sctp
@ -6,6 +20,7 @@ import (
"errors"
"net"
"runtime"
"syscall"
)
var ErrUnsupported = errors.New("SCTP is unsupported on " + runtime.GOOS + "/" + runtime.GOARCH)
@ -30,6 +45,22 @@ func (c *SCTPConn) Close() error {
return ErrUnsupported
}
func (c *SCTPConn) SetWriteBuffer(bytes int) error {
return ErrUnsupported
}
func (c *SCTPConn) GetWriteBuffer() (int, error) {
return 0, ErrUnsupported
}
func (c *SCTPConn) SetReadBuffer(bytes int) error {
return ErrUnsupported
}
func (c *SCTPConn) GetReadBuffer() (int, error) {
return 0, ErrUnsupported
}
func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
return nil, ErrUnsupported
}
@ -38,6 +69,10 @@ func ListenSCTPExt(net string, laddr *SCTPAddr, options InitMsg) (*SCTPListener,
return nil, ErrUnsupported
}
func listenSCTPExtConfig(network string, laddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPListener, error) {
return nil, ErrUnsupported
}
func (ln *SCTPListener) Accept() (net.Conn, error) {
return nil, ErrUnsupported
}
@ -57,3 +92,7 @@ func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error) {
return nil, ErrUnsupported
}
func dialSCTPExtConfig(network string, laddr, raddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPConn, error) {
return nil, ErrUnsupported
}