Browse code

vendor: github.com/ishidawataru/sctp f2269e66cdee387bd321445d5d300893449805be

full diff: https://github.com/ishidawataru/sctp/compare/6e2cb1366111dcf547c13531e3a263a067715847...f2269e66cdee387bd321445d5d300893449805be

- support SO_SNDBUF/SO_RCVBUF handling
- Support Go Modules
- license clarificaton
- ci: drop 1.6, 1.7, 1.8 support
- Add support for SocketConfig
- support goarch mips64le architecture.
- fix possible socket leak when bind fails

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 22b9e2a7e53645a3090ef305658f22264c380368)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2021/05/25 18:36:11
Showing 7 changed files
... ...
@@ -72,7 +72,7 @@ github.com/coreos/go-semver                         8ab6407b697782a06568d4b7f1db
72 72
 github.com/ugorji/go                                b4c50a2b199d93b13dc15e78929cfb23bfdf21ab # v1.1.1
73 73
 github.com/hashicorp/consul                         9a9cc9341bb487651a0399e3fc5e1e8a42e62dd9 # v0.5.2
74 74
 github.com/miekg/dns                                6c0c4e6581f8e173cc562c8b3363ab984e4ae071 # v1.1.27
75
-github.com/ishidawataru/sctp                        6e2cb1366111dcf547c13531e3a263a067715847
75
+github.com/ishidawataru/sctp                        f2269e66cdee387bd321445d5d300893449805be
76 76
 go.etcd.io/bbolt                                    232d8fc87f50244f9c808f4745759e08a304c029 # v1.3.5
77 77
 
78 78
 # get graph and distribution packages
79 79
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+This source code includes following third party code
1
+
2
+- ipsock_linux.go : licensed by the Go authors, see GO_LICENSE file for the license which applies to the code
0 3
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+module github.com/ishidawataru/sctp
1
+
2
+go 1.12
... ...
@@ -1,3 +1,7 @@
1
+// Copyright 2009 The Go Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the GO_LICENSE file.
4
+
1 5
 package sctp
2 6
 
3 7
 import (
... ...
@@ -1,3 +1,18 @@
1
+// Copyright 2019 Wataru Ishida. All rights reserved.
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License");
4
+// you may not use this file except in compliance with the License.
5
+// You may obtain a copy of the License at
6
+//
7
+//    http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS,
11
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
+// implied.
13
+// See the License for the specific language governing permissions and
14
+// limitations under the License.
15
+
1 16
 package sctp
2 17
 
3 18
 import (
... ...
@@ -678,3 +693,37 @@ func (c *SCTPSndRcvInfoWrappedConn) SetReadDeadline(t time.Time) error {
678 678
 func (c *SCTPSndRcvInfoWrappedConn) SetWriteDeadline(t time.Time) error {
679 679
 	return c.conn.SetWriteDeadline(t)
680 680
 }
681
+
682
+func (c *SCTPSndRcvInfoWrappedConn) SetWriteBuffer(bytes int) error {
683
+	return c.conn.SetWriteBuffer(bytes)
684
+}
685
+
686
+func (c *SCTPSndRcvInfoWrappedConn) GetWriteBuffer() (int, error) {
687
+	return c.conn.GetWriteBuffer()
688
+}
689
+
690
+func (c *SCTPSndRcvInfoWrappedConn) SetReadBuffer(bytes int) error {
691
+	return c.conn.SetReadBuffer(bytes)
692
+}
693
+
694
+func (c *SCTPSndRcvInfoWrappedConn) GetReadBuffer() (int, error) {
695
+	return c.conn.GetReadBuffer()
696
+}
697
+
698
+// SocketConfig contains options for the SCTP socket.
699
+type SocketConfig struct {
700
+	// If Control is not nil it is called after the socket is created but before
701
+	// it is bound or connected.
702
+	Control func(network, address string, c syscall.RawConn) error
703
+
704
+	// InitMsg is the options to send in the initial SCTP message
705
+	InitMsg InitMsg
706
+}
707
+
708
+func (cfg *SocketConfig) Listen(net string, laddr *SCTPAddr) (*SCTPListener, error) {
709
+	return listenSCTPExtConfig(net, laddr, cfg.InitMsg, cfg.Control)
710
+}
711
+
712
+func (cfg *SocketConfig) Dial(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
713
+	return dialSCTPExtConfig(net, laddr, raddr, cfg.InitMsg, cfg.Control)
714
+}
... ...
@@ -1,4 +1,18 @@
1 1
 // +build linux,!386
2
+// Copyright 2019 Wataru Ishida. All rights reserved.
3
+//
4
+// Licensed under the Apache License, Version 2.0 (the "License");
5
+// you may not use this file except in compliance with the License.
6
+// You may obtain a copy of the License at
7
+//
8
+//    http://www.apache.org/licenses/LICENSE-2.0
9
+//
10
+// Unless required by applicable law or agreed to in writing, software
11
+// distributed under the License is distributed on an "AS IS" BASIS,
12
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+// implied.
14
+// See the License for the specific language governing permissions and
15
+// limitations under the License.
2 16
 
3 17
 package sctp
4 18
 
... ...
@@ -40,6 +54,23 @@ func getsockopt(fd int, optname, optval, optlen uintptr) (uintptr, uintptr, erro
40 40
 	return r0, r1, nil
41 41
 }
42 42
 
43
+type rawConn struct {
44
+	sockfd int
45
+}
46
+
47
+func (r rawConn) Control(f func(fd uintptr)) error {
48
+	f(uintptr(r.sockfd))
49
+	return nil
50
+}
51
+
52
+func (r rawConn) Read(f func(fd uintptr) (done bool)) error {
53
+	panic("not implemented")
54
+}
55
+
56
+func (r rawConn) Write(f func(fd uintptr) (done bool)) error {
57
+	panic("not implemented")
58
+}
59
+
43 60
 func (c *SCTPConn) SCTPWrite(b []byte, info *SndRcvInfo) (int, error) {
44 61
 	var cbuf []byte
45 62
 	if info != nil {
... ...
@@ -114,6 +145,22 @@ func (c *SCTPConn) Close() error {
114 114
 	return syscall.EBADF
115 115
 }
116 116
 
117
+func (c *SCTPConn) SetWriteBuffer(bytes int) error {
118
+	return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBUF, bytes)
119
+}
120
+
121
+func (c *SCTPConn) GetWriteBuffer() (int, error) {
122
+	return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
123
+}
124
+
125
+func (c *SCTPConn) SetReadBuffer(bytes int) error {
126
+	return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bytes)
127
+}
128
+
129
+func (c *SCTPConn) GetReadBuffer() (int, error) {
130
+	return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
131
+}
132
+
117 133
 // ListenSCTP - start listener on specified address/port
118 134
 func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
119 135
 	return ListenSCTPExt(net, laddr, InitMsg{NumOstreams: SCTP_MAX_STREAM})
... ...
@@ -121,6 +168,11 @@ func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
121 121
 
122 122
 // ListenSCTPExt - start listener on specified address/port with given SCTP options
123 123
 func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListener, error) {
124
+	return listenSCTPExtConfig(network, laddr, options, nil)
125
+}
126
+
127
+// listenSCTPExtConfig - start listener on specified address/port with given SCTP options and socket configuration
128
+func listenSCTPExtConfig(network string, laddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPListener, error) {
124 129
 	af, ipv6only := favoriteAddrFamily(network, laddr, nil, "listen")
125 130
 	sock, err := syscall.Socket(
126 131
 		af,
... ...
@@ -140,6 +192,12 @@ func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe
140 140
 	if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
141 141
 		return nil, err
142 142
 	}
143
+	if control != nil {
144
+		rc := rawConn{sockfd: sock}
145
+		if err = control(network, laddr.String(), rc); err != nil {
146
+			return nil, err
147
+		}
148
+	}
143 149
 	err = setInitOpts(sock, options)
144 150
 	if err != nil {
145 151
 		return nil, err
... ...
@@ -154,7 +212,7 @@ func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe
154 154
 				laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{IP: net.IPv6zero})
155 155
 			}
156 156
 		}
157
-		err := SCTPBind(sock, laddr, SCTP_BINDX_ADD_ADDR)
157
+		err = SCTPBind(sock, laddr, SCTP_BINDX_ADD_ADDR)
158 158
 		if err != nil {
159 159
 			return nil, err
160 160
 		}
... ...
@@ -191,6 +249,11 @@ func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
191 191
 
192 192
 // DialSCTPExt - same as DialSCTP but with given SCTP options
193 193
 func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error) {
194
+	return dialSCTPExtConfig(network, laddr, raddr, options, nil)
195
+}
196
+
197
+// dialSCTPExtConfig - same as DialSCTP but with given SCTP options and socket configuration
198
+func dialSCTPExtConfig(network string, laddr, raddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPConn, error) {
194 199
 	af, ipv6only := favoriteAddrFamily(network, laddr, raddr, "dial")
195 200
 	sock, err := syscall.Socket(
196 201
 		af,
... ...
@@ -210,6 +273,12 @@ func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTP
210 210
 	if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
211 211
 		return nil, err
212 212
 	}
213
+	if control != nil {
214
+		rc := rawConn{sockfd: sock}
215
+		if err = control(network, laddr.String(), rc); err != nil {
216
+			return nil, err
217
+		}
218
+	}
213 219
 	err = setInitOpts(sock, options)
214 220
 	if err != nil {
215 221
 		return nil, err
... ...
@@ -1,4 +1,18 @@
1 1
 // +build !linux linux,386
2
+// Copyright 2019 Wataru Ishida. All rights reserved.
3
+//
4
+// Licensed under the Apache License, Version 2.0 (the "License");
5
+// you may not use this file except in compliance with the License.
6
+// You may obtain a copy of the License at
7
+//
8
+//    http://www.apache.org/licenses/LICENSE-2.0
9
+//
10
+// Unless required by applicable law or agreed to in writing, software
11
+// distributed under the License is distributed on an "AS IS" BASIS,
12
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+// implied.
14
+// See the License for the specific language governing permissions and
15
+// limitations under the License.
2 16
 
3 17
 package sctp
4 18
 
... ...
@@ -6,6 +20,7 @@ import (
6 6
 	"errors"
7 7
 	"net"
8 8
 	"runtime"
9
+	"syscall"
9 10
 )
10 11
 
11 12
 var ErrUnsupported = errors.New("SCTP is unsupported on " + runtime.GOOS + "/" + runtime.GOARCH)
... ...
@@ -30,6 +45,22 @@ func (c *SCTPConn) Close() error {
30 30
 	return ErrUnsupported
31 31
 }
32 32
 
33
+func (c *SCTPConn) SetWriteBuffer(bytes int) error {
34
+	return ErrUnsupported
35
+}
36
+
37
+func (c *SCTPConn) GetWriteBuffer() (int, error) {
38
+	return 0, ErrUnsupported
39
+}
40
+
41
+func (c *SCTPConn) SetReadBuffer(bytes int) error {
42
+	return ErrUnsupported
43
+}
44
+
45
+func (c *SCTPConn) GetReadBuffer() (int, error) {
46
+	return 0, ErrUnsupported
47
+}
48
+
33 49
 func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
34 50
 	return nil, ErrUnsupported
35 51
 }
... ...
@@ -38,6 +69,10 @@ func ListenSCTPExt(net string, laddr *SCTPAddr, options InitMsg) (*SCTPListener,
38 38
 	return nil, ErrUnsupported
39 39
 }
40 40
 
41
+func listenSCTPExtConfig(network string, laddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPListener, error) {
42
+	return nil, ErrUnsupported
43
+}
44
+
41 45
 func (ln *SCTPListener) Accept() (net.Conn, error) {
42 46
 	return nil, ErrUnsupported
43 47
 }
... ...
@@ -57,3 +92,7 @@ func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
57 57
 func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error) {
58 58
 	return nil, ErrUnsupported
59 59
 }
60
+
61
+func dialSCTPExtConfig(network string, laddr, raddr *SCTPAddr, options InitMsg, control func(network, address string, c syscall.RawConn) error) (*SCTPConn, error) {
62
+	return nil, ErrUnsupported
63
+}