"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/github.com/ishidawataru/sctp/sctp_linux.go" between
moby-20.10.6.tar.gz and moby-20.10.7.tar.gz

About: Moby is a framework to assemble specialized container systems (formerly project name Docker; see here to clarify the relationship between the projects).

sctp_linux.go  (moby-20.10.6):sctp_linux.go  (moby-20.10.7)
// +build linux,!386 // +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 package sctp
import ( import (
"io" "io"
"net" "net"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
"unsafe" "unsafe"
) )
skipping to change at line 43 skipping to change at line 57
optname, optname,
optval, optval,
optlen, optlen,
0) 0)
if errno != 0 { if errno != 0 {
return r0, r1, errno return r0, r1, errno
} }
return r0, r1, nil 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) { func (c *SCTPConn) SCTPWrite(b []byte, info *SndRcvInfo) (int, error) {
var cbuf []byte var cbuf []byte
if info != nil { if info != nil {
cmsgBuf := toBuf(info) cmsgBuf := toBuf(info)
hdr := &syscall.Cmsghdr{ hdr := &syscall.Cmsghdr{
Level: syscall.IPPROTO_SCTP, Level: syscall.IPPROTO_SCTP,
Type: SCTP_CMSG_SNDRCV, Type: SCTP_CMSG_SNDRCV,
} }
// bitwidth of hdr.Len is platform-specific, // bitwidth of hdr.Len is platform-specific,
skipping to change at line 117 skipping to change at line 148
Flags: SCTP_EOF, Flags: SCTP_EOF,
} }
c.SCTPWrite(nil, info) c.SCTPWrite(nil, info)
syscall.Shutdown(int(fd), syscall.SHUT_RDWR) syscall.Shutdown(int(fd), syscall.SHUT_RDWR)
return syscall.Close(int(fd)) return syscall.Close(int(fd))
} }
} }
return syscall.EBADF return syscall.EBADF
} }
func (c *SCTPConn) SetWriteBuffer(bytes int) error {
return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBU
F, bytes)
}
func (c *SCTPConn) GetWriteBuffer() (int, error) {
return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_SNDBU
F)
}
func (c *SCTPConn) SetReadBuffer(bytes int) error {
return syscall.SetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBU
F, bytes)
}
func (c *SCTPConn) GetReadBuffer() (int, error) {
return syscall.GetsockoptInt(c.fd(), syscall.SOL_SOCKET, syscall.SO_RCVBU
F)
}
// ListenSCTP - start listener on specified address/port // ListenSCTP - start listener on specified address/port
func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) { func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error) {
return ListenSCTPExt(net, laddr, InitMsg{NumOstreams: SCTP_MAX_STREAM}) return ListenSCTPExt(net, laddr, InitMsg{NumOstreams: SCTP_MAX_STREAM})
} }
// ListenSCTPExt - start listener on specified address/port with given SCTP opti ons // ListenSCTPExt - start listener on specified address/port with given SCTP opti ons
func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe ner, error) { func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListe ner, error) {
return listenSCTPExtConfig(network, laddr, options, nil)
}
// listenSCTPExtConfig - start listener on specified address/port with given SCT
P options and socket configuration
func listenSCTPExtConfig(network string, laddr *SCTPAddr, options InitMsg, contr
ol func(network, address string, c syscall.RawConn) error) (*SCTPListener, error
) {
af, ipv6only := favoriteAddrFamily(network, laddr, nil, "listen") af, ipv6only := favoriteAddrFamily(network, laddr, nil, "listen")
sock, err := syscall.Socket( sock, err := syscall.Socket(
af, af,
syscall.SOCK_STREAM, syscall.SOCK_STREAM,
syscall.IPPROTO_SCTP, syscall.IPPROTO_SCTP,
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
// close socket on error // close socket on error
defer func() { defer func() {
if err != nil { if err != nil {
syscall.Close(sock) syscall.Close(sock)
} }
}() }()
if err = setDefaultSockopts(sock, af, ipv6only); err != nil { if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
return nil, err 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) err = setInitOpts(sock, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if laddr != nil { if laddr != nil {
// If IP address and/or port was not provided so far, let's use t he unspecified IPv4 or IPv6 address // If IP address and/or port was not provided so far, let's use t he unspecified IPv4 or IPv6 address
if len(laddr.IPAddrs) == 0 { if len(laddr.IPAddrs) == 0 {
if af == syscall.AF_INET { if af == syscall.AF_INET {
laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{ IP: net.IPv4zero}) laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{ IP: net.IPv4zero})
} else if af == syscall.AF_INET6 { } else if af == syscall.AF_INET6 {
laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{ IP: net.IPv6zero}) 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 { if err != nil {
return nil, err return nil, err
} }
} }
err = syscall.Listen(sock, syscall.SOMAXCONN) err = syscall.Listen(sock, syscall.SOMAXCONN)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SCTPListener{ return &SCTPListener{
fd: sock, fd: sock,
skipping to change at line 194 skipping to change at line 252
return syscall.Close(ln.fd) return syscall.Close(ln.fd)
} }
// DialSCTP - bind socket to laddr (if given) and connect to raddr // DialSCTP - bind socket to laddr (if given) and connect to raddr
func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) { func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error) {
return DialSCTPExt(net, laddr, raddr, InitMsg{NumOstreams: SCTP_MAX_STREA M}) return DialSCTPExt(net, laddr, raddr, InitMsg{NumOstreams: SCTP_MAX_STREA M})
} }
// DialSCTPExt - same as DialSCTP but with given SCTP options // DialSCTPExt - same as DialSCTP but with given SCTP options
func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTP Conn, error) { func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTP Conn, error) {
return dialSCTPExtConfig(network, laddr, raddr, options, nil)
}
// dialSCTPExtConfig - same as DialSCTP but with given SCTP options and socket c
onfiguration
func dialSCTPExtConfig(network string, laddr, raddr *SCTPAddr, options InitMsg,
control func(network, address string, c syscall.RawConn) error) (*SCTPConn, erro
r) {
af, ipv6only := favoriteAddrFamily(network, laddr, raddr, "dial") af, ipv6only := favoriteAddrFamily(network, laddr, raddr, "dial")
sock, err := syscall.Socket( sock, err := syscall.Socket(
af, af,
syscall.SOCK_STREAM, syscall.SOCK_STREAM,
syscall.IPPROTO_SCTP, syscall.IPPROTO_SCTP,
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
// close socket on error // close socket on error
defer func() { defer func() {
if err != nil { if err != nil {
syscall.Close(sock) syscall.Close(sock)
} }
}() }()
if err = setDefaultSockopts(sock, af, ipv6only); err != nil { if err = setDefaultSockopts(sock, af, ipv6only); err != nil {
return nil, err 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) err = setInitOpts(sock, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if laddr != nil { if laddr != nil {
// If IP address and/or port was not provided so far, let's use t he unspecified IPv4 or IPv6 address // If IP address and/or port was not provided so far, let's use t he unspecified IPv4 or IPv6 address
if len(laddr.IPAddrs) == 0 { if len(laddr.IPAddrs) == 0 {
if af == syscall.AF_INET { if af == syscall.AF_INET {
laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{ IP: net.IPv4zero}) laddr.IPAddrs = append(laddr.IPAddrs, net.IPAddr{ IP: net.IPv4zero})
} else if af == syscall.AF_INET6 { } else if af == syscall.AF_INET6 {
 End of changes. 8 change blocks. 
1 lines changed or deleted 80 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)