Documentation
¶
Overview ¶
Package sctp is a binding for the Linux kernel's SCTP stack.
It does not implement SCTP. Chunk handling, association setup, retransmission, congestion control, path management and checksums all belong to the kernel; what is here is the socket API around them — net.Conn and net.Listener implementations, the socket options of RFC 6458 and its extensions, ancillary data, and the notifications the kernel delivers on the data stream.
Platforms ¶
The socket-backed implementation is selected by Go's linux build tag, which also applies to Android and includes Linux/386. On other targets with a real syscall package the package still compiles, and entry points that need an SCTP socket return ErrUnsupported, which wraps errors.ErrUnsupported.
Two qualifications: plan9, js/wasm and wasip1/wasm do not compile, their syscall packages having no RawSockaddrInet4; and ResolveSCTPAddr never touches the kernel, so it works normally everywhere rather than reporting ErrUnsupported.
Reading ¶
SCTP is message-oriented, so a read returns either a whole message or part of one and SCTPRead cannot say which: a message larger than the buffer is split, and the remainder arrives looking like a fresh message. Use ReadMsg, which reassembles, or SCTPReadFlags and test the flags for MSG_EOR.
SCTPReadFlags also reports MSG_NOTIFICATION when no NotificationHandler is installed; pass those bytes to ParseNotification. A configured handler consumes notifications before the read returns. Read and ReadMsg always skip notifications. SCTPReadMsg is the raw one-recvmsg escape hatch and applies no notification or framing policy.
Writing ¶
Write follows net.Conn semantics: it waits for the complete SCTP message to be accepted, or until a deadline, Close, or another error ends the operation. SCTPWrite and SCTPWriteInfo retain their message-oriented non-blocking behaviour without a write deadline and may return EAGAIN when the send buffer is full; setting a write deadline makes them wait through the runtime poller.
Options announced in the INIT ¶
Several options are only meaningful before the association exists, because they are announced in the INIT chunk: SetInitMsg, SetAdaptationLayer, and the capability negotiations SetPrSupported, SetReconfigSupported, SetAsconfSupported, SetAuthSupported and SetEcnSupported. Setting one on an established association is accepted and does nothing. Several also depend on a net.sctp.* sysctl; each says so.
Index ¶
- Constants
- Variables
- func ErrorCauseString(cause uint32) string
- func SCTPBind(fd int, addr *SCTPAddr, flags int) error
- func SCTPConnect(fd int, addr *SCTPAddr) (int, error)
- type AdaptationIndication
- type AddStreamsReq
- type AssocChange
- type AssocInfo
- type AssocReset
- type AssocStats
- type AssocValue
- type AuthInfo
- type AuthKeyEvent
- type AuthKeyID
- type DefaultPrInfo
- type DelayedSACKConfig
- type Event
- type EventSubscribe
- type GetAddrsOld
- type InitMsg
- type Notification
- type NotificationHandler
- type NotificationHeader
- type NotificationSubscription
- type NxtInfo
- type OptionalInt
- type OptionalUint32
- type PartialDelivery
- type PeerAddrChange
- type PeerAddrParams
- type PeerAddrThlds
- type PeerAddrThldsV2
- type PeerAddrinfo
- type PeerState
- type PrInfo
- type PrStatus
- type PreAssociationConfig
- type PreconfiguredSocket
- func (cfg *PreconfiguredSocket) Dial(network string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
- func (cfg *PreconfiguredSocket) DialContext(ctx context.Context, network string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
- func (cfg *PreconfiguredSocket) Listen(network string, laddr *SCTPAddr) (*SCTPListener, error)
- func (cfg *PreconfiguredSocket) ListenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
- func (cfg *PreconfiguredSocket) OpenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
- type ProbeInterval
- type RcvInfo
- type RemoteError
- type RtoInfo
- type SCTPAddr
- type SCTPAssocID
- type SCTPConn
- func DialSCTP(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
- func DialSCTPContext(ctx context.Context, network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error)
- func DialSCTPExt(network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error)
- func NewSCTPConn(fd int, handler NotificationHandler) *SCTPConn
- func (c *SCTPConn) Abort() error
- func (c *SCTPConn) AddStreams(inStreams, outStreams uint16) error
- func (c *SCTPConn) AsconfSupported() (bool, error)
- func (c *SCTPConn) AuthActiveKey() (uint16, error)
- func (c *SCTPConn) AuthSupported() (bool, error)
- func (c *SCTPConn) AutoAsconf() (bool, error)
- func (c *SCTPConn) BindAdd(addr *SCTPAddr) error
- func (c *SCTPConn) BindRemove(addr *SCTPAddr) error
- func (c *SCTPConn) Close() error
- func (c *SCTPConn) CloseWithTimeout(timeout time.Duration) error
- func (c *SCTPConn) DeactivateAuthKey(keyNumber uint16) error
- func (c *SCTPConn) DeleteAuthKey(keyNumber uint16) error
- func (c *SCTPConn) DisableFragments() (bool, error)
- func (c *SCTPConn) EcnSupported() (bool, error)
- func (c *SCTPConn) EnableStreamReset() (uint32, error)
- func (c *SCTPConn) EventSubscribed(eventType SCTPNotificationType) (bool, error)
- func (c *SCTPConn) ExposePotentiallyFailed() (uint32, error)
- func (c *SCTPConn) GetAdaptationLayer() (uint32, error)
- func (c *SCTPConn) GetAssocInfo() (*AssocInfo, error)
- func (c *SCTPConn) GetAssocStats() (*AssocStats, error)
- func (c *SCTPConn) GetContext() (uint32, error)
- func (c *SCTPConn) GetDefaultPrInfo() (*DefaultPrInfo, error)
- func (c *SCTPConn) GetDefaultSentParam() (*SndRcvInfo, error)
- func (c *SCTPConn) GetDefaultSndInfo() (*SndInfo, error)
- func (c *SCTPConn) GetFragmentInterleave() (int, error)
- func (c *SCTPConn) GetInitMsg() (*InitMsg, error)
- func (c *SCTPConn) GetMaxBurst() (int, error)
- func (c *SCTPConn) GetMaxSegSize() (int, error)
- func (c *SCTPConn) GetNoDelay() (int, error)
- func (c *SCTPConn) GetPartialDeliveryPoint() (int, error)
- func (c *SCTPConn) GetPeerAddrInfo(info *PeerAddrinfo) error
- func (c *SCTPConn) GetPeerAddrParams(p *PeerAddrParams) error
- func (c *SCTPConn) GetPeerAddrThlds() (*PeerAddrThlds, error)
- func (c *SCTPConn) GetPeerAddrThldsV2() (*PeerAddrThldsV2, error)
- func (c *SCTPConn) GetPrAssocStatus(policy uint16) (*PrStatus, error)
- func (c *SCTPConn) GetPrStreamStatus(sid uint16, policy uint16) (*PrStatus, error)
- func (c *SCTPConn) GetProbeInterval(p *ProbeInterval) error
- func (c *SCTPConn) GetReadBuffer() (int, error)
- func (c *SCTPConn) GetRemoteUDPEncapsPort(e *UDPEncaps) error
- func (c *SCTPConn) GetReusePort() (bool, error)
- func (c *SCTPConn) GetRtoInfo() (*RtoInfo, error)
- func (c *SCTPConn) GetSackTimer() (*SackTimer, error)
- func (c *SCTPConn) GetStatus() (*Status, error)
- func (c *SCTPConn) GetStreamSchedulerValue(streamID uint16) (uint16, error)
- func (c *SCTPConn) GetWriteBuffer() (int, error)
- func (c *SCTPConn) Getsockopt(optname, optval, optlen uintptr) (uintptr, uintptr, error)
- func (c *SCTPConn) HmacIdent() ([]uint16, error)
- func (c *SCTPConn) InterleavingSupported() (bool, error)
- func (c *SCTPConn) LocalAddr() net.Addr
- func (c *SCTPConn) LocalAuthChunks() ([]uint8, error)
- func (c *SCTPConn) MappedV4Addr() (bool, error)
- func (c *SCTPConn) PeelOff(id int) (*SCTPConn, error)
- func (c *SCTPConn) PeerAuthChunks() ([]uint8, error)
- func (c *SCTPConn) PrSupported() (bool, error)
- func (c *SCTPConn) Read(b []byte) (int, error)
- func (c *SCTPConn) ReadMsg(max int) ([]byte, *SndRcvInfo, error)
- func (c *SCTPConn) ReconfigSupported() (bool, error)
- func (c *SCTPConn) RemoteAddr() net.Addr
- func (c *SCTPConn) ResetAssoc() error
- func (c *SCTPConn) ResetStreams(direction uint16, streams ...uint16) error
- func (c *SCTPConn) SCTPGetPrimaryPeerAddr() (*SCTPAddr, error)
- func (c *SCTPConn) SCTPLocalAddr(id int) (*SCTPAddr, error)
- func (c *SCTPConn) SCTPRead(b []byte) (int, *SndRcvInfo, error)
- func (c *SCTPConn) SCTPReadFlags(b []byte) (int, *SndRcvInfo, int, error)
- func (c *SCTPConn) SCTPReadMsg(b, oob []byte) (n, oobn, flags int, err error)
- func (c *SCTPConn) SCTPReadNextInfo(b []byte) (int, *SndRcvInfo, *NxtInfo, int, error)
- func (c *SCTPConn) SCTPRemoteAddr(id int) (*SCTPAddr, error)
- func (c *SCTPConn) SCTPWrite(b []byte, info *SndRcvInfo) (int, error)
- func (c *SCTPConn) SCTPWriteInfo(b []byte, info *SndInfo, pr *PrInfo, auth *AuthInfo) (int, error)
- func (c *SCTPConn) SetAdaptationLayer(ind uint32) error
- func (c *SCTPConn) SetAsconfSupported(on bool) error
- func (c *SCTPConn) SetAssocInfo(info *AssocInfo) error
- func (c *SCTPConn) SetAuthActiveKey(keyNumber uint16) error
- func (c *SCTPConn) SetAuthChunk(chunkType uint8) error
- func (c *SCTPConn) SetAuthKey(keyNumber uint16, key []byte) error
- func (c *SCTPConn) SetAuthSupported(on bool) error
- func (c *SCTPConn) SetAutoAsconf(on bool) error
- func (c *SCTPConn) SetContext(context uint32) error
- func (c *SCTPConn) SetDeadline(t time.Time) error
- func (c *SCTPConn) SetDefaultPrInfo(info *DefaultPrInfo) error
- func (c *SCTPConn) SetDefaultSentParam(info *SndRcvInfo) error
- func (c *SCTPConn) SetDefaultSndInfo(info *SndInfo) error
- func (c *SCTPConn) SetDisableFragments(on bool) error
- func (c *SCTPConn) SetEcnSupported(on bool) error
- func (c *SCTPConn) SetEnableStreamReset(mask uint32) error
- func (c *SCTPConn) SetExposePotentiallyFailed(level uint32) error
- func (c *SCTPConn) SetFragmentInterleave(level int) error
- func (c *SCTPConn) SetHmacIdent(idents ...uint16) error
- func (c *SCTPConn) SetInitMsg(numOstreams, maxInstreams, maxAttempts, maxInitTimeout int) error
- func (c *SCTPConn) SetInterleavingSupported(on bool) error
- func (c *SCTPConn) SetMappedV4Addr(on bool) error
- func (c *SCTPConn) SetMaxBurst(burst int) error
- func (c *SCTPConn) SetMaxSegSize(size int) error
- func (c *SCTPConn) SetNoDelay(optval int) error
- func (c *SCTPConn) SetPartialDeliveryPoint(bytes int) error
- func (c *SCTPConn) SetPeerAddrParams(p *PeerAddrParams) error
- func (c *SCTPConn) SetPeerAddrThlds(th *PeerAddrThlds) error
- func (c *SCTPConn) SetPeerAddrThldsV2(th *PeerAddrThldsV2) error
- func (c *SCTPConn) SetPeerPrimaryAddr(addr *SCTPAddr) error
- func (c *SCTPConn) SetPrSupported(on bool) error
- func (c *SCTPConn) SetPrimaryPeerAddr(addr *SCTPAddr) error
- func (c *SCTPConn) SetProbeInterval(p *ProbeInterval) error
- func (c *SCTPConn) SetReadBuffer(bytes int) error
- func (c *SCTPConn) SetReadDeadline(t time.Time) error
- func (c *SCTPConn) SetReconfigSupported(on bool) error
- func (c *SCTPConn) SetRecvNxtInfo(on bool) error
- func (c *SCTPConn) SetRecvRcvInfo(on bool) error
- func (c *SCTPConn) SetRemoteUDPEncapsPort(e *UDPEncaps) error
- func (c *SCTPConn) SetReusePort(on bool) error
- func (c *SCTPConn) SetRtoInfo(info *RtoInfo) error
- func (c *SCTPConn) SetSackTimer(timer *SackTimer) error
- func (c *SCTPConn) SetStreamScheduler(sched uint32) error
- func (c *SCTPConn) SetStreamSchedulerValue(streamID, value uint16) error
- func (c *SCTPConn) SetWriteBuffer(bytes int) error
- func (c *SCTPConn) SetWriteDeadline(t time.Time) error
- func (c *SCTPConn) Setsockopt(optname, optval, optlen uintptr) (uintptr, uintptr, error)
- func (c *SCTPConn) StreamScheduler() (uint32, error)
- func (c *SCTPConn) SubscribeEvent(eventType SCTPNotificationType, on bool) error
- func (c *SCTPConn) SubscribeEvents(flags int) error
- func (c *SCTPConn) SubscribedEvents() (int, error)
- func (c *SCTPConn) SyscallConn() (syscall.RawConn, error)
- func (c *SCTPConn) Write(b []byte) (int, error)
- type SCTPEndpoint
- func (ep *SCTPEndpoint) Abort() error
- func (ep *SCTPEndpoint) AbortAssociation(id SCTPAssocID, cause []byte) error
- func (ep *SCTPEndpoint) Addr() net.Addr
- func (ep *SCTPEndpoint) AssociationCount() (uint32, error)
- func (ep *SCTPEndpoint) AssociationIDs() ([]SCTPAssocID, error)
- func (ep *SCTPEndpoint) BindAdd(addr *SCTPAddr) error
- func (ep *SCTPEndpoint) BindRemove(addr *SCTPAddr) error
- func (ep *SCTPEndpoint) Close() error
- func (ep *SCTPEndpoint) CloseAssociation(id SCTPAssocID) error
- func (ep *SCTPEndpoint) Connect(raddr *SCTPAddr) (SCTPAssocID, error)
- func (ep *SCTPEndpoint) GetAutoClose() (uint32, error)
- func (ep *SCTPEndpoint) LocalAddrs(id SCTPAssocID) (*SCTPAddr, error)
- func (ep *SCTPEndpoint) Network() string
- func (ep *SCTPEndpoint) PeelOff(id SCTPAssocID) (*SCTPConn, error)
- func (ep *SCTPEndpoint) PeerAddrs(id SCTPAssocID) (*SCTPAddr, error)
- func (ep *SCTPEndpoint) Receive(b []byte) (n int, info *RcvInfo, flags int, err error)
- func (ep *SCTPEndpoint) Send(b []byte, info *SndInfo, pr *PrInfo, auth *AuthInfo) (int, error)
- func (ep *SCTPEndpoint) SetAutoClose(seconds uint32) error
- func (ep *SCTPEndpoint) SetDeadline(t time.Time) error
- func (ep *SCTPEndpoint) SetReadDeadline(t time.Time) error
- func (ep *SCTPEndpoint) SetWriteDeadline(t time.Time) error
- func (ep *SCTPEndpoint) SyscallConn() (syscall.RawConn, error)
- type SCTPListener
- func (ln *SCTPListener) Accept() (net.Conn, error)
- func (ln *SCTPListener) AcceptSCTP() (*SCTPConn, error)
- func (ln *SCTPListener) Addr() net.Addr
- func (ln *SCTPListener) BindAdd(addr *SCTPAddr) error
- func (ln *SCTPListener) BindRemove(addr *SCTPAddr) error
- func (ln *SCTPListener) Close() error
- func (ln *SCTPListener) SetDeadline(t time.Time) error
- func (ln *SCTPListener) SyscallConn() (syscall.RawConn, error)
- type SCTPNotificationType
- type SCTPSndRcvInfoWrappedConn
- func (c *SCTPSndRcvInfoWrappedConn) Close() error
- func (c *SCTPSndRcvInfoWrappedConn) GetReadBuffer() (int, error)
- func (c *SCTPSndRcvInfoWrappedConn) GetWriteBuffer() (int, error)
- func (c *SCTPSndRcvInfoWrappedConn) LocalAddr() net.Addr
- func (c *SCTPSndRcvInfoWrappedConn) Read(b []byte) (int, error)
- func (c *SCTPSndRcvInfoWrappedConn) RemoteAddr() net.Addr
- func (c *SCTPSndRcvInfoWrappedConn) SetDeadline(t time.Time) error
- func (c *SCTPSndRcvInfoWrappedConn) SetReadBuffer(bytes int) error
- func (c *SCTPSndRcvInfoWrappedConn) SetReadDeadline(t time.Time) error
- func (c *SCTPSndRcvInfoWrappedConn) SetWriteBuffer(bytes int) error
- func (c *SCTPSndRcvInfoWrappedConn) SetWriteDeadline(t time.Time) error
- func (c *SCTPSndRcvInfoWrappedConn) Write(b []byte) (int, error)
- type SCTPState
- type SackTimer
- type SendFailed
- type SendFailedEvent
- type SenderDry
- type Shutdown
- type SndInfo
- type SndRcvInfo
- type SocketConfig
- func (cfg *SocketConfig) Dial(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
- func (cfg *SocketConfig) DialContext(ctx context.Context, net string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
- func (cfg *SocketConfig) Listen(net string, laddr *SCTPAddr) (*SCTPListener, error)
- func (cfg *SocketConfig) ListenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
- func (cfg *SocketConfig) OpenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
- func (cfg *SocketConfig) WithPreAssociation(pre PreAssociationConfig) *PreconfiguredSocket
- type SocketOptionState
- type Status
- type StatusState
- type StreamChange
- type StreamReset
- type UDPEncaps
Constants ¶
const ( SOL_SCTP = 132 SCTP_BINDX_ADD_ADDR = 0x01 SCTP_BINDX_REM_ADDR = 0x02 MSG_NOTIFICATION = 0x8000 // MSG_EOR is set in the flags returned by SCTPReadFlags when the buffer // received the end of a message. Its absence means the message was // truncated to the buffer and the remainder follows on later reads. MSG_EOR = 0x80 )
const ( SCTP_RTOINFO = iota SCTP_ASSOCINFO SCTP_INITMSG SCTP_NODELAY SCTP_AUTOCLOSE SCTP_SET_PEER_PRIMARY_ADDR SCTP_PRIMARY_ADDR SCTP_ADAPTATION_LAYER SCTP_DISABLE_FRAGMENTS SCTP_PEER_ADDR_PARAMS // SCTP_DEFAULT_SEND_PARAM is option 10. Both the kernel's uapi header and // RFC 6458 §8.1.13 spell it SEND; this package shipped it as SENT, so the // name below is the correct one and SCTP_DEFAULT_SENT_PARAM is kept as an // alias rather than renamed out from under callers. SCTP_DEFAULT_SEND_PARAM SCTP_EVENTS SCTP_I_WANT_MAPPED_V4_ADDR SCTP_MAXSEG SCTP_STATUS SCTP_GET_PEER_ADDR_INFO SCTP_DELAYED_ACK_TIME SCTP_DELAYED_ACK = SCTP_DELAYED_ACK_TIME SCTP_DELAYED_SACK = SCTP_DELAYED_ACK_TIME // SCTP_DEFAULT_SENT_PARAM is the original misspelling of // SCTP_DEFAULT_SEND_PARAM. Deprecated: use SCTP_DEFAULT_SEND_PARAM. SCTP_DEFAULT_SENT_PARAM = SCTP_DEFAULT_SEND_PARAM SCTP_SOCKOPT_BINDX_ADD = 100 SCTP_SOCKOPT_BINDX_REM = 101 SCTP_SOCKOPT_PEELOFF = 102 // SCTP_SOCKOPT_PEELOFF_FLAGS is SCTP_SOCKOPT_PEELOFF with a flags word // appended, so the peeled descriptor can be asked for close-on-exec. SCTP_SOCKOPT_PEELOFF_FLAGS = 122 SCTP_GET_PEER_ADDRS = 108 SCTP_GET_LOCAL_ADDRS = 109 SCTP_SOCKOPT_CONNECTX = 110 SCTP_SOCKOPT_CONNECTX3 = 111 // SCTP_EVENT is the per-event subscription option RFC 6458 §6.2.2 // introduced to replace SCTP_EVENTS. Its value is not part of the // contiguous block above, so it is spelled out. SCTP_EVENT = 127 // SCTP_RECVRCVINFO makes the kernel return SCTP_RCVINFO as ancillary data // on recvmsg (RFC 6458 §8.1.29). It is the non-deprecated counterpart of // the SCTP_SNDRCV data SubscribeEvents(SCTP_EVENT_DATA_IO) asks for. SCTP_RECVRCVINFO = 32 // SCTP_RECVNXTINFO makes the kernel return SCTP_NXTINFO, describing the // message *after* the one being read (RFC 6458 §8.1.30). SCTP_RECVNXTINFO = 33 // SCTP_FRAGMENT_INTERLEAVE controls whether a partial delivery on one // stream blocks messages on the others (RFC 6458 §8.1.20). SCTP_FRAGMENT_INTERLEAVE = 18 // SCTP_PARTIAL_DELIVERY_POINT is the message size at which the partial // delivery API is invoked (RFC 6458 §8.1.21). SCTP_PARTIAL_DELIVERY_POINT = 19 // SCTP_MAX_BURST bounds how many packets may be emitted back to back // (RFC 6458 §8.1.24). The kernel default is 4. SCTP_MAX_BURST = 20 // SCTP_CONTEXT is the default context reported with messages received from // the peer (RFC 6458 §8.1.25). SCTP_CONTEXT = 17 // SCTP_REUSE_PORT allows several one-to-one endpoints to bind the same port // (RFC 6458 §8.1.27). Linux rejects it on SCTPEndpoint's one-to-many // socket style. SCTP_REUSE_PORT = 36 // SCTP_DEFAULT_SNDINFO carries struct sctp_sndinfo and is the replacement // RFC 6458 §8.1.31 gives for SCTP_DEFAULT_SEND_PARAM, which §8.1.13 marks // deprecated along with the struct sctp_sndrcvinfo it takes. SCTP_DEFAULT_SNDINFO = 34 // SCTP_AUTO_ASCONF makes the kernel announce local address changes to the // peer with ASCONF chunks (RFC 6458 §8.1.23). SCTP_AUTO_ASCONF = 30 // SCTP_GET_ASSOC_NUMBER returns the current association count on a // one-to-many socket (RFC 6458 §8.2.5). SCTP_GET_ASSOC_NUMBER = 28 // SCTP_GET_ASSOC_ID_LIST returns its current association identifiers // (RFC 6458 §8.2.6). SCTP_GET_ASSOC_ID_LIST = 29 // SCTP_PEER_ADDR_THLDS carries struct sctp_paddrthlds and sets the // per-path failure and Potentially Failed thresholds (RFC 7829 §7.2). SCTP_PEER_ADDR_THLDS = 31 // SCTP_PEER_ADDR_THLDS_V2 is the same option with a third threshold added: // the consecutive-error threshold which must be exceeded before the primary // path is switched (RFC 7829 §5). The option number is Linux's // back-compatibility device — // the threshold itself is RFC 7829 §7.2's spt_pathcpthld, the third member // of struct sctp_paddrthlds. See PeerAddrThldsV2.PathCpThld. SCTP_PEER_ADDR_THLDS_V2 = 37 // SCTP_GET_ASSOC_STATS reads struct sctp_assoc_stats, the per-association // counters. Linux-specific; it has no RFC 6458 equivalent. SCTP_GET_ASSOC_STATS = 112 // SCTP_PR_SUPPORTED negotiates PR-SCTP, the partial reliability extension // (RFC 7496 §4.5). SCTP_PR_SUPPORTED = 113 // SCTP_DEFAULT_PRINFO carries struct sctp_default_prinfo, the default // partial reliability policy and its lifetime (RFC 6458 §8.1.32). SCTP_DEFAULT_PRINFO = 114 // SCTP_PR_STREAM_STATUS reads struct sctp_prstatus, the count of messages // abandoned on one stream under the partial reliability policy // (RFC 7496 §4.3). SCTP_PR_STREAM_STATUS = 116 // SCTP_PR_ASSOC_STATUS reads the same struct sctp_prstatus totalled across // every stream of the association (RFC 7496 §4.4). SCTP_PR_ASSOC_STATUS = 115 // SCTP_RECONFIG_SUPPORTED negotiates the stream reconfiguration extension // for this socket. Linux-specific: RFC 6525 defines the extension and the // four socket options in its §6.3, but nothing that negotiates support, // and the name appears nowhere in it. SCTP_RECONFIG_SUPPORTED = 117 // SCTP_ENABLE_STREAM_RESET selects which reconfiguration requests are // permitted (RFC 6525 §6.3). SCTP_ENABLE_STREAM_RESET = 118 // SCTP_ADD_STREAMS asks the peer to widen the association's stream count // (RFC 6525 §6.3.4). SCTP_ADD_STREAMS = 121 // SCTP_RESET_STREAMS restarts the sequence numbering of some or all // streams (RFC 6525 §6.3.2). SCTP_RESET_STREAMS = 119 // SCTP_RESET_ASSOC restarts the whole association's sequence numbering // (RFC 6525 §6.3.3). SCTP_RESET_ASSOC = 120 // SCTP_HMAC_IDENT carries struct sctp_hmacalgo, the ordered list of HMAC // algorithms this endpoint offers (RFC 6458 §8.1.17). SCTP_HMAC_IDENT = 22 // SCTP_AUTH_ACTIVE_KEY carries struct sctp_authkeyid and selects the key // used for outbound AUTH chunks (RFC 6458 §8.1.18). SCTP_AUTH_ACTIVE_KEY = 24 // SCTP_AUTH_CHUNK adds one chunk type to the CHUNKS list advertised by // future associations (RFC 6458 §8.3.2 and RFC 4895 §6.1). Set only. SCTP_AUTH_CHUNK = 21 // SCTP_AUTH_KEY installs a shared key, carrying struct sctp_authkey with // the key bytes appended (RFC 6458 §8.3.3). Set only. SCTP_AUTH_KEY = 23 // SCTP_AUTH_DELETE_KEY removes a shared key (RFC 6458 §8.3.5). Set only. SCTP_AUTH_DELETE_KEY = 25 // SCTP_AUTH_DEACTIVATE_KEY stops a shared key being used for new packets // while leaving it able to verify what is already in flight // (RFC 6458 §8.3.4). Set only. SCTP_AUTH_DEACTIVATE_KEY = 35 // SCTP_PEER_AUTH_CHUNKS reads the chunk types the peer requires to be // authenticated (RFC 6458 §8.2.3). Read only. SCTP_PEER_AUTH_CHUNKS = 26 // SCTP_LOCAL_AUTH_CHUNKS reads the chunk types this endpoint requires to // be authenticated (RFC 6458 §8.2.4). Read only. SCTP_LOCAL_AUTH_CHUNKS = 27 // SCTP_STREAM_SCHEDULER selects the order outbound streams are served in // (RFC 8260 §4). SCTP_STREAM_SCHEDULER = 123 // SCTP_STREAM_SCHEDULER_VALUE sets a per-stream parameter for the // scheduler in force, which for SCTP_SS_PRIO is the stream's priority. SCTP_STREAM_SCHEDULER_VALUE = 124 // SCTP_INTERLEAVING_SUPPORTED negotiates user message interleaving, the // I-DATA chunk of RFC 8260. The kernel refuses it with EPERM unless // net.sctp.intl_enable is on and SetFragmentInterleave has been given a // non-zero level. SCTP_INTERLEAVING_SUPPORTED = 125 // SCTP_ASCONF_SUPPORTED negotiates dynamic address reconfiguration // (RFC 5061). See SetAsconfSupported: this is what makes SetAutoAsconf do // anything at all. SCTP_ASCONF_SUPPORTED = 128 // SCTP_AUTH_SUPPORTED negotiates AUTH (RFC 4895) for this socket, without // net.sctp.auth_enable. SCTP_AUTH_SUPPORTED = 129 // SCTP_ECN_SUPPORTED is a Linux-specific experimental capability toggle. // RFC 9260 §1.7 removed the former SCTP ECN specification, so this option // is not evidence of support for a current standards-track SCTP extension. SCTP_ECN_SUPPORTED = 130 // SCTP_EXPOSE_POTENTIALLY_FAILED_STATE controls whether the PF state of // RFC 7829 is visible; see SetExposePotentiallyFailed. SCTP_EXPOSE_POTENTIALLY_FAILED_STATE = 131 // SCTP_EXPOSE_PF_STATE is the kernel's shorter spelling of the same option. SCTP_EXPOSE_PF_STATE = SCTP_EXPOSE_POTENTIALLY_FAILED_STATE // SCTP_REMOTE_UDP_ENCAPS_PORT sets the peer's UDP encapsulation port // (RFC 6951, updated by RFC 8899). SCTP_REMOTE_UDP_ENCAPS_PORT = 132 // SCTP_PLPMTUD_PROBE_INTERVAL is Linux's socket control for the // packetization-layer path MTU discovery probe interval. RFC 8899 defines // the DPLPMTUD procedure, not this option or its numeric ABI. SCTP_PLPMTUD_PROBE_INTERVAL = 133 )
const ( // SCTPSchedFCFS sends messages in the order they were handed over, // regardless of stream (RFC 8260 §3.1). It is the default. SCTPSchedFCFS = 0 // SCTPSchedPrio serves streams by the priority set with // SetStreamSchedulerValue, lowest number first (RFC 8260 §3.4). SCTPSchedPrio = 1 // SCTPSchedRR serves streams round-robin, one message at a time // (RFC 8260 §3.2). SCTPSchedRR = 2 // SCTPSchedFC distributes capacity fairly between streams, accounting for // message length rather than message count (RFC 8260 §3.5). It takes no // per-stream value. SCTPSchedFC = 3 // SCTPSchedWFQ is weighted fair queueing: capacity is shared in proportion // to the per-stream weight set with SetStreamSchedulerValue, so a stream // weighted n times another gets n times the capacity (RFC 8260 §3.6). SCTPSchedWFQ = 4 )
Stream schedulers for SetStreamScheduler, from the kernel's enum sctp_sched_type. RFC 8260 §3 defines six schedulers; Linux implements five of them, all of the ones below.
Measured on 6.12: 0 to 4 are accepted and read back unchanged, 5 and above are refused with EINVAL. RFC 8260 §3.3's round-robin-per-packet (SCTP_SS_RR_PKT) is the one with no Linux implementation and so no constant here.
SetStreamScheduler does not police the value, so a caller may pass a number the running kernel does not know; it will fail at the setsockopt with EINVAL rather than silently doing something else.
const ( // SCTPPFStateUnset leaves the decision to net.sctp.pf_expose, whose own // default is this same value — measured, and the sysctl's floor is 0. This // is the state of a socket nobody has asked. // // It is not the same as SCTPPFStateDisabled: at this level GetPeerAddrInfo // does report SCTP_PF for a potentially-failed path. Only the notification // is withheld. SCTPPFStateUnset = 0 // SCTPPFStateDisabled suppresses the PF state, and does so by refusing the // question rather than by answering it differently: GetPeerAddrInfo on a // path that is in the PF state returns EACCES. The SCTP_UNKNOWN to // SCTP_ACTIVE fixup in the kernel happens after that check and rewrites only // SCTP_UNKNOWN, so a PF path is never reported as active. // // That makes this the level least likely to do what a caller wants: polling // path health under it starts failing at exactly the moment a path degrades, // and GetPeerAddrInfo is the only way to see a secondary path at all. // GetStatus is not gated, so the primary path's state stays readable. SCTPPFStateDisabled = 1 // SCTPPFStateEnabled reports the PF state through both // SCTP_PEER_ADDR_CHANGE and GetPeerAddrInfo. This is what a caller wants // if they are asking at all. SCTPPFStateEnabled = 2 )
PF state exposure levels for SetExposePotentiallyFailed (RFC 7829), from the kernel's SCTP_PF_EXPOSE_* enum in include/net/sctp/constants.h.
The values are not a boolean with an extra mode: zero means "no answer given", and the two explicit answers are 1 for off and 2 for on. Reading them as off/on/locked, which is the shape most of these options have, puts "exposed" on the value that disables it — a round-trip test still passes, because the number written is the number read back.
const ( SPP_HB_ENABLE = 1 << 0 SPP_HB_DISABLE = 1 << 1 SPP_HB_DEMAND = 1 << 2 // send one heartbeat now SPP_PMTUD_ENABLE = 1 << 3 SPP_PMTUD_DISABLE = 1 << 4 SPP_SACKDELAY_ENABLE = 1 << 5 SPP_SACKDELAY_DISABLE = 1 << 6 SPP_HB_TIME_IS_ZERO = 1 << 7 // heartbeat immediately after each RTO SPP_IPV6_FLOWLABEL = 1 << 8 SPP_DSCP = 1 << 9 )
Flags for PeerAddrParams.Flags, from Linux's spp_flags. RFC 6458 §8.1.12 defines the heartbeat (including SPP_HB_TIME_IS_ZERO), PMTUD, IPv6 flow-label, and DSCP controls. Linux adds only the SACK-delay controls; those two bits and the PeerAddrParams.SackDelay field are kernel extensions.
The ENABLE/DISABLE pairs are how the option distinguishes "set this" from "leave it alone": with neither bit set the corresponding value field is ignored, which is why SetPeerAddrParams cannot be used to clear a setting by passing zero.
const ( SCTPPrPolicyNone = 0x0000 SCTPPrPolicyTTL = 0x0010 SCTPPrPolicyRtx = 0x0020 SCTPPrPolicyPrio = 0x0030 )
Partial reliability policies for SetDefaultPrInfo (RFC 7496 §4.2). The value accompanying each policy is interpreted differently, which is why they are not interchangeable:
- SCTPPrPolicyNone ignores the value; the message is sent reliably.
- SCTPPrPolicyTTL treats it as a lifetime in milliseconds.
- SCTPPrPolicyRtx treats it as a retransmission count.
- SCTPPrPolicyPrio treats it as a priority, where a larger number is discarded sooner when the send buffer is under pressure.
Unlike the fragment interleave levels, the kernel does police these: a policy outside this set is rejected with EINVAL, which was measured.
const ( // SCTPEnableResetStreamReq permits resetting the sequence numbers of // individual streams. SCTPEnableResetStreamReq = 0x01 // SCTPEnableResetAssocReq permits resetting the whole association's // sequence numbers. SCTPEnableResetAssocReq = 0x02 // SCTPEnableChangeAssocReq permits adding streams to a live association. SCTPEnableChangeAssocReq = 0x04 )
Stream reconfiguration request types for SetEnableStreamReset (RFC 6525 §6.3). These are a bitmask; a socket may permit any combination.
const ( SCTPAuthHmacIDSHA1 = 1 SCTPAuthHmacIDSHA256 = 3 )
HMAC algorithm identifiers for SetHmacIdent (RFC 4895 §3.3 Table 2 and the IANA registry it establishes). SHA-1 is mandatory to implement; SHA-256 is optional. Note that 2 is not assigned — the registry skips it — so these are not contiguous.
const ( // SCTPFragmentInterleaveNone blocks every other message while a partial // delivery is in progress. This is the kernel default. SCTPFragmentInterleaveNone = 0 // SCTPFragmentInterleaveOther allows messages from other associations to be // delivered during a partial delivery, but not from other streams of this // one. SCTPFragmentInterleaveOther = 1 // SCTPFragmentInterleaveStreams additionally allows messages from other // streams of the same association. // // Current Linux keeps fragment interleave as a flag rather than a level, so // it stores this request as SCTPFragmentInterleaveOther. SetFragmentInterleave // detects that mismatch and returns an error wrapping errors.ErrUnsupported; // true RFC 6458 level 2 is unavailable on those kernels. RFC 8260 I-DATA // negotiation is a separate capability and does not turn readback level 1 // into level 2. SCTPFragmentInterleaveStreams = 2 )
Fragmented interleave levels for SetFragmentInterleave (RFC 6458 §8.1.20).
Linux does not store a level. It keeps a single flag, so anything non-zero becomes 1: setting 2 and setting 3 both read back as 1, which was measured. That means an out-of-range value is not rejected and not honoured either, and nothing tells the caller. SetFragmentInterleave rejects anything outside this set so the mistake fails at the call.
const ( SCTP_EVENT_DATA_IO = 1 << iota SCTP_EVENT_ASSOCIATION SCTP_EVENT_ADDRESS SCTP_EVENT_SEND_FAILURE SCTP_EVENT_PEER_ERROR SCTP_EVENT_SHUTDOWN SCTP_EVENT_PARTIAL_DELIVERY SCTP_EVENT_ADAPTATION_LAYER SCTP_EVENT_AUTHENTICATION SCTP_EVENT_SENDER_DRY SCTP_EVENT_ALL = SCTP_EVENT_DATA_IO | SCTP_EVENT_ASSOCIATION | SCTP_EVENT_ADDRESS | SCTP_EVENT_SEND_FAILURE | SCTP_EVENT_PEER_ERROR | SCTP_EVENT_SHUTDOWN | SCTP_EVENT_PARTIAL_DELIVERY | SCTP_EVENT_ADAPTATION_LAYER | SCTP_EVENT_AUTHENTICATION | SCTP_EVENT_SENDER_DRY )
const ( SCTP_SN_TYPE_BASE = SCTPNotificationType(iota + (1 << 15)) SCTP_ASSOC_CHANGE SCTP_PEER_ADDR_CHANGE SCTP_SEND_FAILED SCTP_REMOTE_ERROR SCTP_SHUTDOWN_EVENT SCTP_PARTIAL_DELIVERY_EVENT SCTP_ADAPTATION_INDICATION SCTP_AUTHENTICATION_INDICATION SCTP_SENDER_DRY_EVENT SCTP_STREAM_RESET_EVENT SCTP_ASSOC_RESET_EVENT SCTP_STREAM_CHANGE_EVENT SCTP_SEND_FAILED_EVENT )
const ( SCTP_CMSG_INIT = iota SCTP_CMSG_SNDRCV SCTP_CMSG_SNDINFO SCTP_CMSG_RCVINFO SCTP_CMSG_NXTINFO // SCTP_CMSG_PRINFO carries struct sctp_prinfo on a send, setting the // partial reliability policy for that one message (RFC 6458 §5.3.7). SCTP_CMSG_PRINFO // SCTP_CMSG_AUTHINFO carries struct sctp_authinfo, naming the shared key // to authenticate that one message with (RFC 6458 §5.3.8). SCTP_CMSG_AUTHINFO // SCTP_CMSG_DSTADDRV4 and SCTP_CMSG_DSTADDRV6 add a destination address to // a send on an unconnected one-to-many socket (RFC 6458 §5.3.9, §5.3.10). // SCTPEndpoint routes sends by an established association id and therefore // does not emit either destination-address item; they remain defined for // controlled raw-descriptor users. SCTP_CMSG_DSTADDRV4 SCTP_CMSG_DSTADDRV6 )
Ancillary data types, enum sctp_cmsg_type. The values are positional in the C enum, so the order here is the contract — SCTP_CMSG_PRINFO must stay 5.
const ( // SCTPStreamResetIncoming resets the streams the peer sends on. SCTPStreamResetIncoming = 0x01 // SCTPStreamResetOutgoing resets the streams this endpoint sends on. SCTPStreamResetOutgoing = 0x02 )
Direction flags for ResetStreams (RFC 6525 §6.3.2). At least one is required: a request with neither is rejected with EINVAL, which was measured.
const ( // SCTP_UNORDERED sends the message without sequencing. SCTP_UNORDERED = 1 << 0 // SCTP_ADDR_OVER overrides the primary destination, using the address in // SndRcvInfo. It applies to one-to-many sockets. SCTP_ADDR_OVER = 1 << 1 // SCTP_ABORT tears the association down with an ABORT instead of sending. SCTP_ABORT = 1 << 2 // SCTP_SACK_IMMEDIATELY asks the peer to acknowledge without waiting for // its delayed-ack timer. SCTP_SACK_IMMEDIATELY = 1 << 3 // SCTP_SENDALL sends the message on every association of a one-to-many // socket. SCTP_SENDALL = 1 << 6 // SCTP_PR_SCTP_ALL is not a send flag, despite living in this word. It has // no effect on any send path — the kernel's only two uses of it are in // sctp_getsockopt_pr_streamstatus and sctp_getsockopt_pr_assocstatus, where // it asks for the counters aggregated over every PR policy rather than one // (RFC 7496 §4.3 and §4.4). Setting it in SndInfo.Flags or SndRcvInfo.Flags does // nothing. It is declared here because it occupies a bit in the same field; // pass it to GetPrStreamStatus or GetPrAssocStatus, not to a send. SCTP_PR_SCTP_ALL = 1 << 7 // SCTP_NOTIFICATION is the last member of the kernel's enum, and like // SCTP_PR_SCTP_ALL it is not a send flag. It is MSG_NOTIFICATION, and the // enum lists it because the field is wide enough to hold it, not because // anything sets it there. // // Nothing does, on either path. Measured: with sctp_data_io_event on, a // data message arrives carrying an SCTP_SNDRCV cmsg whose sinfo_flags is 0, // and a notification arrives with no SCTP_SNDRCV cmsg at all — only // MSG_NOTIFICATION in the recvmsg flags. So a caller cannot learn from // SndRcvInfo.Flags that a message is a notification; test the flags word // SCTPReadFlags returns instead. SCTP_NOTIFICATION = 0x8000 // SCTP_EOF starts a graceful shutdown once the message is delivered. It is // MSG_FIN, not a bit of its own. SCTP_EOF = 0x200 )
Per-message send flags, for SndRcvInfo.Flags and SndInfo.Flags. These are the kernel's enum sctp_sinfo_flags (RFC 6458 §5.3.2).
The sequence is not contiguous, which is what makes it worth writing out rather than generating with iota. Bits 4 and 5 belong to SCTP_PR_SCTP_MASK — the partial reliability policy travels in the same word — and SCTP_EOF is not an SCTP-specific bit at all but MSG_FIN, which is 0x200.
SCTP_EOF used to be the fifth iota here, so 1<<4, which is exactly SCTP_PR_SCTP_TTL. A caller asking for a graceful shutdown on their last message instead selected a partial reliability policy, and got neither the shutdown nor an error.
const ( // SCTP_FUTURE_ASSOC affects only associations created after the call. SCTP_FUTURE_ASSOC = 0 // SCTP_CURRENT_ASSOC affects only associations that already exist; future // ones keep the previous default. SCTP_CURRENT_ASSOC = 1 // SCTP_ALL_ASSOC affects both. SCTP_ALL_ASSOC = 2 )
Special association identifiers for the AssocID field of the option structs in this package (RFC 6458 §7.2).
They exist for one-to-many sockets, where one descriptor carries many associations and an option has to say which ones it means. SCTPEndpoint uses that socket style and its typed per-association methods reject scope selectors where the RFC requires one real id. On the one-to-one sockets from Dial and Accept, the kernel ignores the field altogether — measured: reading SCTP_MAX_BURST with each of the three returns the same value and no error. RFC 6458 §7.2 says getsockopt and sctp_opt_info calls using CURRENT or ALL must fail with EINVAL; that requirement applies to the one-to-many scoping facility, not to Linux's one-to-one behavior.
They are declared because zero is not self-describing. An option struct left zeroed is already asking for SCTP_FUTURE_ASSOC, and a reader of this package should not have to know that 0 is a name. RFC 6458 Held Erratum 6114 concerns the symbolic spelling in the separate sctp_getladdrs example in §9.5; it is not a normative change to these §7.2 selectors.
const ( SCTP_COMM_UP = SCTPState(iota) SCTP_COMM_LOST SCTP_RESTART SCTP_SHUTDOWN_COMP SCTP_CANT_STR_ASSOC )
const ( SCTP_ERROR_NO_ERROR = 0x00 SCTP_ERROR_INV_STRM = 0x01 // Invalid Stream Identifier SCTP_ERROR_MISS_PARAM = 0x02 // Missing Mandatory Parameter SCTP_ERROR_STALE_COOKIE = 0x03 // Stale Cookie SCTP_ERROR_NO_RESOURCE = 0x04 // Out of Resource SCTP_ERROR_DNS_FAILED = 0x05 // Unresolvable Address SCTP_ERROR_UNKNOWN_CHUNK = 0x06 // Unrecognized Chunk Type SCTP_ERROR_INV_PARAM = 0x07 // Invalid Mandatory Parameter SCTP_ERROR_UNKNOWN_PARAM = 0x08 // Unrecognized Parameters SCTP_ERROR_NO_DATA = 0x09 // No User Data SCTP_ERROR_COOKIE_IN_SHUTDOWN = 0x0a // Cookie Received While Shutting Down SCTP_ERROR_RESTART = 0x0b // Restart with New Addresses SCTP_ERROR_USER_ABORT = 0x0c // User Initiated Abort SCTP_ERROR_PROTO_VIOLATION = 0x0d // Protocol Violation SCTP_ERROR_NEW_ENCAP_PORT = 0x0e // Restart with New Encapsulation Port SCTP_ERROR_DEL_LAST_IP = 0xa0 // Delete Last Remaining Address (RFC 5061) SCTP_ERROR_RSRC_LOW = 0xa1 // Operation Refused Due to Resources SCTP_ERROR_DEL_SRC_IP = 0xa2 // Delete Source IP Address (RFC 5061) SCTP_ERROR_ASCONF_ACK = 0xa3 // Association Aborted due to ASCONF-ACK SCTP_ERROR_REQ_REFUSED = 0xa4 // Request Refused - No Authorization SCTP_ERROR_UNSUP_HMAC = 0x105 // Unsupported HMAC Identifier (RFC 4895) )
Error cause codes, RFC 9260 section 3.3.10, as carried by AssocChange.Error, RemoteError.Error and SendFailed.Error.
These are the values the peer puts in an ERROR or ABORT chunk, so they answer "why did this association fail" — the question those three notifications exist to answer.
Codes 1 to 13 are all in the base specification and IANA attributes every one of them to RFC 9260; an earlier version of this comment placed 11 to 13 in the Implementation Guide instead, which was where they were first written but not where they live now. Code 14 is the odd one: IANA lists 14-159 as Unassigned, and Linux defines SCTP_ERROR_NEW_ENCAP_PORT there from the UDP encapsulation work. So a peer that is not Linux may mean something else by it.
They are deliberately untyped, so that comparing them against Error works whether the field is a uint16 or a uint32.
const ( SCTP_ADDR_AVAILABLE = iota SCTP_ADDR_UNREACHABLE SCTP_ADDR_REMOVED SCTP_ADDR_ADDED SCTP_ADDR_MADE_PRIM SCTP_ADDR_CONFIRMED // SCTP_ADDR_POTENTIALLY_FAILED is RFC 7829's early warning: the path has // missed enough retransmissions to be suspect but not enough to be // unreachable. The kernel suppresses it unless SetExposePotentiallyFailed // is on, which is why it is easy to conclude the state does not exist. SCTP_ADDR_POTENTIALLY_FAILED )
Peer address change states, from the kernel's enum sctp_spc_state. These are distinct from PeerState, which GetStatus reports.
const ( SCTP_STREAM_RESET_INCOMING_SSN = 0x0001 SCTP_STREAM_RESET_OUTGOING_SSN = 0x0002 SCTP_STREAM_RESET_DENIED = 0x0004 SCTP_STREAM_RESET_FAILED = 0x0008 SCTP_ASSOC_RESET_DENIED = 0x0004 SCTP_ASSOC_RESET_FAILED = 0x0008 SCTP_STREAM_CHANGE_DENIED = 0x0004 SCTP_STREAM_CHANGE_FAILED = 0x0008 )
Flags reported by StreamReset, AssocReset and StreamChange.
DENIED means the peer refused the request; FAILED means it could not be carried out. Either way the request did not take effect, which is the whole reason these events matter: ResetStreams and AddStreams return as soon as the request is away, so success there means "sent", not "done".
const ( SCTP_AUTH_NEW_KEY = iota // a new shared key is usable // SCTP_AUTH_FREE_KEY says this endpoint has released a key: it is emitted // when the local refcount drops, from sctp_auth_deact_key_id and from the // destructor of the last locally queued chunk that referenced the key. It // says nothing about the peer, which may still have packets in flight // signed with it — so waiting for this before DeleteAuthKey does not make // the deletion safe. RFC 6458 §6.1.8 words it the same way: the SCTP // implementation will no longer use the key. SCTP_AUTH_FREE_KEY SCTP_AUTH_NO_AUTH // the peer does not support AUTH )
Indications reported by AuthKeyEvent.
const ( SCTP_DATA_UNSENT = iota // never put on the wire SCTP_DATA_SENT // transmitted, but not acknowledged )
Flags reported by SendFailed and SendFailedEvent, saying how far the undelivered message got.
const NotificationMaxSize = 1024
NotificationMaxSize is a read buffer size that holds any fixed-size notification this package parses.
It is not a bound on every notification. SCTP_SEND_FAILED, SCTP_SEND_FAILED_EVENT and SCTP_REMOTE_ERROR carry a variable tail — the undelivered message, or the peer's ERROR chunk — so their size follows the data rather than the struct. Measured on 6.12, by queueing to a peer that never reads and then aborting:
message notifications payload each 65485 65516 + 33 65484 + 1 204800 65516 + 65516 + 65516 + 8380 65484 x3 + 8348
So the tail is capped at 65484 bytes and the event around it is 32 bytes larger for SCTP_SEND_FAILED_EVENT, 48 for the legacy SCTP_SEND_FAILED. An undelivered message longer than that arrives as several notifications whose payloads sum to exactly the message, and a single one is already 64 times this constant. A message over roughly a megabyte is refused at the send with EMSGSIZE instead.
Those several notifications are each complete, with MSG_EOR set — that is the kernel dividing one message across events, and is not the same thing as the truncation ErrShortNotification reports. Truncation is what an undersized read buffer produces, and it is distinguished by MSG_EOR being clear.
const NotificationReassemblyLimit = 1 << 20
NotificationReassemblyLimit bounds memory retained by the package while it assembles notifications for a NotificationHandler. It also bounds the total completed notifications ReadMsg queues while it finishes an interleaved application record.
This is a package policy, not an SCTP wire limit. It is deliberately much larger than the largest event observed from Linux (65,516 bytes), including variable-length send-failure events. Callers that need to accept larger implementation-specific records can use SCTPReadMsg or SCTPReadFlags and apply their own bounded reassembly policy.
const SCTP_AUTHENTICATION_EVENT = SCTP_AUTHENTICATION_INDICATION
SCTP_AUTHENTICATION_EVENT is the spelling RFC 6458 §6.1.8 and the kernel's enum sctp_sn_type use. SCTP_AUTHENTICATION_INDICATION is the name Linux gives the same value through its compatibility #define, and is what this package has always called it.
const SCTP_DATA_IO_EVENT = SCTP_SN_TYPE_BASE
SCTP_DATA_IO_EVENT is the modern SCTP_EVENT type that enables per-message receive metadata. Linux calls the same numeric value SCTP_SN_TYPE_BASE in its enum; the alias gives callers the RFC 6458 §§6.2.2 and 8.1.20 spelling.
const (
SCTP_MAX_STREAM = 0xffff
)
const SCTP_POTENTIALLY_FAILED = SCTP_PF
SCTP_POTENTIALLY_FAILED is the spelling RFC 7829 uses for SCTP_PF.
Variables ¶
var ErrAssociationListTooLarge = errors.New("sctp: association id list exceeds safety limit")
ErrAssociationListTooLarge reports that an endpoint has more associations than AssociationIDs can enumerate within its fixed allocation safety limit. SyscallConn remains available to applications that deliberately manage a larger caller-owned buffer.
var ErrControlTruncated = errors.New("sctp: control message data truncated")
ErrControlTruncated reports that the kernel could not fit all ancillary data for a received message in the supplied control buffer. The payload may still have been received, but its stream, PPID, association, or next-message metadata is incomplete and must not be silently treated as authoritative.
var ErrInvalidAssociationList = errors.New("sctp: invalid association id list")
ErrInvalidAssociationList reports a malformed SCTP_GET_ASSOC_ID_LIST result. Association ids are security-sensitive routing metadata, so a truncated, inconsistent, reserved, or duplicate id list is never returned partially.
var ErrInvalidReceiveInfo = errors.New("sctp: invalid SCTP_RCVINFO association id")
ErrInvalidReceiveInfo reports SCTP_RCVINFO whose association id is a scope selector or otherwise cannot identify one routable association. Returning application bytes with such metadata could make a one-to-many endpoint reply to the wrong peer, so Receive fails closed and returns no RcvInfo.
var ErrMessageInterrupted = errors.New("sctp: message interrupted before end of record")
ErrMessageInterrupted reports that ReadMsg consumed the beginning of an SCTP user message but could not reach MSG_EOR. The returned bytes are only a prefix. The connection is aborted before ReadMsg returns so a queued tail can never be mistaken for a new message on a later call.
var ErrMissingReceiveInfo = errors.New("sctp: SCTP_RCVINFO missing from endpoint receive")
ErrMissingReceiveInfo reports application data received without the SCTP_RCVINFO ancillary item that identifies its association.
SCTPEndpoint enables SCTP_RECVRCVINFO before it can create or accept an association, so this error means the per-association routing contract was lost. Returning the bytes with a nil association would make it possible to answer the wrong peer and is therefore never treated as a successful read.
var ErrMsgTooLong = errors.New("sctp: message exceeds maximum length")
ErrMsgTooLong is returned by ReadMsg when a message exceeds the caller's limit. The bytes read up to the limit are returned with it; ReadMsg drains the rest of that message before returning so the next read starts at the next message boundary.
var ErrNotificationTooLong = errors.New("sctp: notification exceeds reassembly limit")
ErrNotificationTooLong is returned when automatic notification buffering or reassembly reaches NotificationReassemblyLimit. The current notification and any application record already in progress are drained before the error is returned, so the following read begins on a record boundary.
var ErrShortNotification = errors.New("sctp: notification truncated")
ErrShortNotification is returned by ParseNotification when the buffer holds fewer bytes than the notification declares itself to be, or when the declared length is too small to be an event at all.
A notification read into an undersized buffer arrives split, and what follows is not dropped. Measured by reading a 20 byte SCTP_ASSOC_CHANGE with an 8 byte buffer:
read 1: n=8 notification=1 eor=0 0180 0000 14000000 read 2: n=8 notification=1 eor=0 00000000 0a000a00 read 3: n=4 notification=1 eor=1 68030100
Every one is flagged MSG_NOTIFICATION, with MSG_EOR set only on the last. So the continuation fragments look like fresh notifications to anything that only tests the flag — and a fragment whose first two bytes happen to match a known type would otherwise decode into an event assembled from the middle of another one.
When consuming notifications through a raw API, read with a buffer of at least NotificationMaxSize and treat a fragment without MSG_EOR as incomplete rather than as an event. NotificationHandler users receive a reassembled event and do not need to size their application read buffer for it.
var ErrUnsupported = fmt.Errorf("sctp: socket operation unsupported: %w", errors.ErrUnsupported)
ErrUnsupported is returned by socket-backed entry points on a platform without SCTP.
It is declared on every platform so portable callers can use either the package-specific or standard-library check without a build constraint:
errors.Is(err, sctp.ErrUnsupported) errors.Is(err, errors.ErrUnsupported)
Functions ¶
func ErrorCauseString ¶
ErrorCauseString names an RFC 9260 section 3.3.10 error cause.
func SCTPConnect ¶
SCTPConnect establishes an association with addr on the socket fd.
EISCONN is reported as success because the requested association is already established. EALREADY is preserved: it means the association exists but its handshake is still in progress. net/sctp/socket.c has, in __sctp_connect and again in sctp_connect_add_peer:
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
if (asoc)
return asoc->state >= SCTP_STATE_ESTABLISHED ? -EISCONN
: -EALREADY;
Treating EALREADY as success is unsafe even on a descriptor without O_NONBLOCK: a second goroutine can reach this branch while the first remains blocked in the original connect. The early return skips sctp_wait_for_connect, so the socket is not yet usable. DialSCTP handles this internal state by waiting for SCTP_STATUS; the exported raw-descriptor operation returns EALREADY so its caller retains control of that policy.
Two CONNECTX3 calls against an unreachable address on one non-blocking socket can give EINPROGRESS then EALREADY repeatably.
AssocID is not filled in on either early-return path, so 0 is returned with a nil error for EISCONN or with EALREADY; callers needing the id read it back from the socket after establishment.
Types ¶
type AdaptationIndication ¶
type AdaptationIndication struct {
AdaptationInd uint32
AssocID SCTPAssocID
// contains filtered or unexported fields
}
AdaptationIndication is SCTP_ADAPTATION_INDICATION (RFC 6458 6.1.6), carrying the peer's adaptation layer indication.
func (*AdaptationIndication) Flags ¶
func (n *AdaptationIndication) Flags() uint16
func (*AdaptationIndication) Length ¶
func (n *AdaptationIndication) Length() uint32
func (*AdaptationIndication) Type ¶
func (n *AdaptationIndication) Type() SCTPNotificationType
type AddStreamsReq ¶
type AddStreamsReq struct {
AssocID SCTPAssocID
// InStreams is how many inbound streams to add.
InStreams uint16
// OutStreams is how many outbound streams to add.
OutStreams uint16
}
AddStreamsReq mirrors struct sctp_add_streams (RFC 6525 §6.3.4), the request to widen an association's stream count. The AddStreams method wraps it; this type is exported so the layout can be pinned by the layout test.
type AssocChange ¶
type AssocChange struct {
State SCTPState
// Error is an RFC 9260 section 3.3.10 error cause, in host byte order —
// see ErrorCauseString. It is meaningful when State is SCTP_COMM_LOST or
// SCTP_CANT_STR_ASSOC and zero otherwise.
Error uint16
OutboundStreams uint16
InboundStreams uint16
AssocID SCTPAssocID
// Info carries any additional data the kernel appended, most usefully the
// ABORT chunk when State is SCTP_COMM_LOST.
//
// Its extent comes from the length in the event's own header, not from the
// buffer the event was read into, so passing a read buffer rather than
// b[:n] to ParseNotification does not append whatever the previous read
// left behind.
Info []byte
// contains filtered or unexported fields
}
AssocChange is SCTP_ASSOC_CHANGE (RFC 6458 6.1.1), reporting that an association has come up, come down, restarted, or failed to start. State says which.
func (*AssocChange) Flags ¶
func (n *AssocChange) Flags() uint16
func (*AssocChange) Length ¶
func (n *AssocChange) Length() uint32
func (*AssocChange) Type ¶
func (n *AssocChange) Type() SCTPNotificationType
type AssocInfo ¶
type AssocInfo struct {
AssocID SCTPAssocID
// AsocMaxRxt is the maximum retransmission attempts for the association.
AsocMaxRxt uint16
// NumberPeerDestinations is how many destination addresses the peer has.
NumberPeerDestinations uint16
// PeerRwnd is the peer's last reported receive window, minus outstanding
// data. It stops shrinking and stays put when a peer stops acknowledging,
// which makes it a useful companion signal to Status.Unackdata.
PeerRwnd uint32
// LocalRwnd is the last receive window reported to the peer.
LocalRwnd uint32
// CookieLife is the association's cookie lifetime, in milliseconds.
CookieLife uint32
}
AssocInfo mirrors struct sctp_assocparams (RFC 6458 8.1.2, SCTP_ASSOCINFO).
AsocMaxRxt is the field that matters for detecting an unreachable peer: it is Association.Max.Retrans, RFC 9260 section 8.1 — section 8.2 is the path counter, not the association one. Once that many consecutive retransmissions to a peer go unacknowledged, the association is torn down and the socket becomes readable with an error. Lowering it, and lowering RtoInfo.Max, is what turns a silent peer into a prompt, reportable failure.
type AssocReset ¶
type AssocReset struct {
AssocID SCTPAssocID
LocalTSN uint32
RemoteTSN uint32
// contains filtered or unexported fields
}
AssocReset is SCTP_ASSOC_RESET_EVENT (RFC 6525 §6.1.2), reporting the outcome of an association reset and the TSNs the two sides restarted from.
func (*AssocReset) Flags ¶
func (n *AssocReset) Flags() uint16
func (*AssocReset) Length ¶
func (n *AssocReset) Length() uint32
func (*AssocReset) Type ¶
func (n *AssocReset) Type() SCTPNotificationType
type AssocStats ¶
type AssocStats struct {
AssocID SCTPAssocID
// ObsRtoIPAddr is the path on which MaxRto was observed.
//
// This one is worth reading carefully. struct sctp_assoc_stats is 256 bytes
// on every architecture and its counters begin at 136 on every
// architecture, but the sockaddr_storage in front of them does not: it sits
// at offset 8 on a 64-bit kernel and at offset 4 on a 32-bit one, with the
// slack absorbed by padding before the counters. So the size check every
// getsockopt performs cannot see the difference, and neither can a test
// that only looks at the numbers — which is why this is unmarshalled from
// an offset rather than being read straight off a mirrored struct.
ObsRtoIPAddr [128]byte
// MaxRto is the largest retransmission timeout observed since the last
// read. Reading resets it.
MaxRto uint64
// ISacks and OSacks count SACK chunks received and sent.
ISacks, OSacks uint64
// OPackets and IPackets count packets sent and received.
OPackets, IPackets uint64
// RtxChunks counts retransmitted data chunks.
RtxChunks uint64
// OutOfSeqTsns counts chunks arriving beyond the next expected TSN.
OutOfSeqTsns uint64
// IDupChunks counts duplicate chunks received.
IDupChunks uint64
// GapCnt counts gap acknowledgement blocks received.
GapCnt uint64
// OUodChunks and IUodChunks count unordered data chunks sent and received.
OUodChunks, IUodChunks uint64
// OOdChunks and IOdChunks count ordered data chunks sent and received.
OOdChunks, IOdChunks uint64
// OCtrlChunks and ICtrlChunks count control chunks sent and received.
OCtrlChunks, ICtrlChunks uint64
}
AssocStats mirrors struct sctp_assoc_stats, the per-association counters Linux exposes through SCTP_GET_ASSOC_STATS. This has no RFC 6458 counterpart — the field set is the kernel's own.
type AssocValue ¶
type AssocValue struct {
AssocID SCTPAssocID
AssocVal uint32
}
AssocValue mirrors struct sctp_assoc_value, the association-id-and-value pair several socket options take.
AssocID is ignored on the one-to-one style sockets this package creates.
type AuthInfo ¶
type AuthInfo struct {
KeyNumber uint16
}
AuthInfo mirrors struct sctp_authinfo (RFC 6458 §5.3.8), naming the shared key to authenticate one message with, carried as SCTP_CMSG_AUTHINFO.
type AuthKeyEvent ¶
type AuthKeyEvent struct {
KeyNumber uint16
AltKeyNumber uint16
// Indication is SCTP_AUTH_NEW_KEY, SCTP_AUTH_FREE_KEY or SCTP_AUTH_NO_AUTH.
Indication uint32
AssocID SCTPAssocID
// contains filtered or unexported fields
}
AuthKeyEvent is SCTP_AUTHENTICATION_EVENT (RFC 6458 §6.1.8), reporting a change in the AUTH shared keys in force.
It is what makes key rollover observable, but every indication it carries is about this endpoint. SCTP_AUTH_FREE_KEY in particular says the local stack has released a key, not that the peer has stopped using it — see the constant — so it is not the signal to wait for before DeleteAuthKey.
func (*AuthKeyEvent) Flags ¶
func (n *AuthKeyEvent) Flags() uint16
func (*AuthKeyEvent) Length ¶
func (n *AuthKeyEvent) Length() uint32
func (*AuthKeyEvent) Type ¶
func (n *AuthKeyEvent) Type() SCTPNotificationType
type AuthKeyID ¶
type AuthKeyID struct {
AssocID SCTPAssocID
KeyNumber uint16
// contains filtered or unexported fields
}
AuthKeyID mirrors struct sctp_authkeyid (RFC 6458 §8.1.18), naming one of the endpoint's shared keys.
type DefaultPrInfo ¶
type DefaultPrInfo struct {
AssocID SCTPAssocID
// Value is a lifetime, a retransmission count or a priority depending on
// Policy. See the SCTPPrPolicy constants.
Value uint32
// Policy is one of the SCTPPrPolicy constants.
Policy uint16
// contains filtered or unexported fields
}
DefaultPrInfo represents struct sctp_default_prinfo, the default partial reliability policy for messages that do not carry their own.
Its field order follows the Linux UAPI: association id, value, then policy. RFC 6458 §8.1.32 specifies policy, value, then association id instead. The socket-backed methods must use the Linux order; this is an explicit ABI divergence rather than a byte-for-byte mirror of the RFC structure.
type DelayedSACKConfig ¶
DelayedSACKConfig configures the delayed acknowledgement policy for future associations (RFC 6458 §8.1.19 and RFC 9260 §6.2). A zero field leaves that field unchanged. Delay is milliseconds; values above 500 are rejected before a descriptor is opened because RFC 9260 says an implementation MUST NOT allow a larger SACK.Delay.
RFC 9260 also says an acknowledgement SHOULD be generated within 200 ms and for at least every second packet. Delay values from 201 through 500 and Frequency values above 2 are accepted because those are recommendations, not prohibitions; using a non-nil config makes that deliberate departure explicit.
type Event ¶
type Event struct {
// AssocID is ignored on the one-to-one style sockets this package creates.
AssocID SCTPAssocID
// Type is a notification type, e.g. SCTP_ASSOC_CHANGE.
Type uint16
// On is 1 to subscribe and 0 to unsubscribe.
On uint8
// contains filtered or unexported fields
}
Event mirrors struct sctp_event (RFC 6458 §6.2.2), which subscribes to or unsubscribes from one notification type at a time.
Both this struct and the kernel's are 8 bytes: three fields totalling 7, rounded up for the alignment of the leading 4 byte association id. The trailing field below is that padding written out. Go would insert it either way — removing it does not change the size, which was checked — so it is here to make the layout the kernel expects visible at the declaration rather than implied by alignment rules. TestEventStructMatchesKernel asserts the size and every offset.
type EventSubscribe ¶
type EventSubscribe struct {
DataIO uint8
Association uint8
Address uint8
SendFailure uint8
PeerError uint8
Shutdown uint8
PartialDelivery uint8
AdaptationLayer uint8
Authentication uint8
SenderDry uint8
}
EventSubscribe mirrors struct sctp_event_subscribe, the bulk subscription used by SCTP_EVENTS.
The fields are the ten RFC 6458 §6.2.1 events. Linux appends four of its own (stream reset, association reset, stream change, and a second send-failure event), so the kernel's struct is 14 bytes against this one's 10. That is safe in both directions and was measured rather than assumed: setsockopt with a 10 byte option length is accepted and applied, and getsockopt with one writes only the first 10 bytes and leaves the rest of the caller's buffer untouched. The cost is that those four Linux-only events cannot be reached through this struct.
RFC 6458 §6.2.2 deprecates SCTP_EVENTS for precisely this reason — the struct has to grow as events are added — and replaces it with SCTP_EVENT, which names one event per call. See SubscribeEvent.
type GetAddrsOld ¶
type Notification ¶
type Notification interface {
// A typed nil notification is permitted; each accessor returns its zero
// value rather than panicking.
// Type reports which notification this is.
Type() SCTPNotificationType
// Flags are the notification's type-specific flags.
Flags() uint16
// Length is the length the kernel declared for the notification. It may
// exceed the bytes actually received if the read buffer was too small.
Length() uint32
}
Notification is an event delivered on the data stream when a message is read with MSG_NOTIFICATION set in its flags, as described in RFC 6458 section 6.
Notifications are only delivered for events the socket is subscribed to; see SubscribeEvents.
func ParseNotification ¶
func ParseNotification(b []byte) (Notification, error)
ParseNotification decodes a notification from bytes read with MSG_NOTIFICATION set in the flags, as returned by SCTPReadFlags or handed to a NotificationHandler.
It returns ErrShortNotification if b is too short for the notification it declares itself to be, rather than reading past the end of the buffer: a notification read through a raw API into an undersized buffer arrives as an incomplete fragment, and the length in its header describes the whole event, not the bytes present. NotificationHandler receives reassembled events.
An unrecognised notification type returns a nil Notification and a nil error, since new event types may be added by the kernel.
type NotificationHandler ¶
NotificationHandler receives one complete SCTP notification consumed by a connection. Notification records are reassembled before the callback even when the application read buffer is smaller than the event. NotificationReassemblyLimit bounds automatic reassembly; an oversized event is drained and reported as ErrNotificationTooLong. Raw receive APIs remain available to applications that need a different bounded policy. If the poller itself fails after consuming a notification prefix but before MSG_EOR, the connection is aborted: leaving it open would let a later read misidentify the unread tail as a new event.
The handler may be invoked concurrently when the same handler is installed on several accepted connections or when several goroutines read one connection. It may call methods on that connection, including another read; callbacks never run while the package holds the descriptor's runtime-poller read lock. The byte slice is valid only until the callback returns. A handler that retains a notification must copy it.
type NotificationHeader ¶
type NotificationSubscription ¶
type NotificationSubscription struct {
Type SCTPNotificationType
State SocketOptionState
}
NotificationSubscription configures one modern SCTP_EVENT subscription from RFC 6458 §6.2.2 for future associations. State must be SocketOptionEnable or SocketOptionDisable; omit an entry instead of using SocketOptionDefault.
Linux does not expose RFC 6458 §6.1.10's SCTP_NOTIFICATIONS_STOPPED_EVENT. This type accepts only notification values represented by this package and never guesses the missing kernel value.
type NxtInfo ¶
type NxtInfo struct {
// SID is the stream the next message arrives on.
SID uint16
// Flags carries SCTP_UNORDERED and, if the next message is a notification,
// MSG_NOTIFICATION.
Flags uint16
// PPID is the payload protocol identifier, converted to host order as
// SCTPRead does for SndRcvInfo.PPID.
PPID uint32
// Length is the size of the whole next message in bytes.
Length uint32
AssocID SCTPAssocID
}
NxtInfo mirrors struct sctp_nxtinfo (RFC 6458 §5.3.6), describing the message queued behind the one just read.
Length is the point of it: a caller can size the next buffer exactly instead of guessing, which on a message-oriented protocol is the difference between one read and a reassembly loop. It arrives only when SetRecvNxtInfo is on and only when there is a next message — an empty queue means no ancillary data, which SCTPReadNextInfo reports as a nil NxtInfo rather than an error.
type OptionalInt ¶
OptionalInt distinguishes an explicit zero from an unset int option. Value must be zero when Set is false; each field using this type documents its own accepted range.
type OptionalUint32 ¶
OptionalUint32 distinguishes an explicit zero from an unset uint32 option. Value must be zero when Set is false; rejecting an otherwise ignored value catches incomplete configurations before a descriptor is opened.
type PartialDelivery ¶
type PartialDelivery struct {
Indication uint32
StreamID uint32
SeqNum uint32
AssocID SCTPAssocID
// contains filtered or unexported fields
}
PartialDelivery is SCTP_PARTIAL_DELIVERY_EVENT (RFC 6458 6.1.7), reporting that a partially delivered message was aborted.
func (*PartialDelivery) Flags ¶
func (n *PartialDelivery) Flags() uint16
func (*PartialDelivery) Length ¶
func (n *PartialDelivery) Length() uint32
func (*PartialDelivery) Type ¶
func (n *PartialDelivery) Type() SCTPNotificationType
type PeerAddrChange ¶
type PeerAddrChange struct {
// Addr is the raw sockaddr_storage of the affected peer address.
Addr [128]byte
State uint32
Error uint32
AssocID SCTPAssocID
// contains filtered or unexported fields
}
PeerAddrChange is SCTP_PEER_ADDR_CHANGE (RFC 6458 6.1.2), reporting that one of the peer's addresses has changed reachability. This is the notification that reports a path going unreachable before the association as a whole fails.
func (*PeerAddrChange) Flags ¶
func (n *PeerAddrChange) Flags() uint16
func (*PeerAddrChange) Length ¶
func (n *PeerAddrChange) Length() uint32
func (*PeerAddrChange) Type ¶
func (n *PeerAddrChange) Type() SCTPNotificationType
type PeerAddrParams ¶
type PeerAddrParams struct {
AssocID SCTPAssocID
// Address selects the path. Leaving it zeroed addresses the association as
// a whole, which is what a one-to-one socket normally wants; to name one
// path, copy in the bytes SCTPAddr.ToRawSockAddrBuf produces.
Address [128]byte
// HBInterval is the heartbeat period in milliseconds. Needs SPP_HB_ENABLE.
HBInterval uint32
// PathMaxRxt is the retransmission count after which this path is
// considered inactive.
PathMaxRxt uint16
// PathMTU overrides path MTU discovery. Needs SPP_PMTUD_DISABLE.
PathMTU uint32
// SackDelay is the delayed acknowledgement timer in milliseconds. Needs
// SPP_SACKDELAY_ENABLE.
SackDelay uint32
Flags uint32
// IPv6FlowLabel needs SPP_IPV6_FLOWLABEL.
IPv6FlowLabel uint32
// DSCP needs SPP_DSCP.
DSCP uint8
}
PeerAddrParams represents Linux's struct sctp_paddrparams, the per-path timers. It is a superset of RFC 6458 §8.1.12: Linux inserts spp_sackdelay and adds the SPP_SACKDELAY_ENABLE and SPP_SACKDELAY_DISABLE flag bits.
Flags decides which of the other fields are read: each value has an ENABLE/DISABLE pair in the SPP_ constants, and a value with neither bit set is ignored. So this cannot be used to clear a setting by passing zero, and a caller who wants to change one thing should read the current parameters, modify them, and write them back.
HBInterval is the one that usually matters. On an idle association nothing but the heartbeat detects that a path has gone silent, and its default of 30 seconds was unreachable from this package before.
Address selects the path. Leaving it zeroed addresses the association as a whole, which is what a one-to-one socket normally wants; to name one path, copy a raw sockaddr in — GetPeerAddrs returns them decoded, and SCTPAddr.ToRawSockAddrBuf encodes one back.
This is the one struct in the package that cannot simply mirror the kernel's field by field. sctp_paddrparams is declared packed and aligned(4), and the 128-byte address leaves spp_pathmtu at offset 138 — a uint32 on a two-byte boundary, which Go will not lay out at any cost. So the exported form is an ordinary Go struct and the packed form is built on the way in and out. TestPeerAddrParamsLayoutMatchesKernel pins every offset.
type PeerAddrThlds ¶
type PeerAddrThlds struct {
AssocID SCTPAssocID
// Address selects the path. A zeroed address applies to the association as
// a whole, which is the useful form on the single-homed sockets this
// package usually creates.
Address [128]byte
// PathMaxRxt is the threshold after which a path is declared inactive: RFC
// 7829 §7.2 acts when the path error counter exceeds this value.
PathMaxRxt uint16
// PathPfThld is the threshold after which a path enters the Potentially
// Failed state. RFC 7829 §7.2 acts when the path error counter exceeds this
// value. A value greater than or equal to PathMaxRxt is permitted, but the
// path then becomes inactive before it can enter PF.
PathPfThld uint16
}
PeerAddrThlds mirrors Linux's legacy two-field struct sctp_paddrthlds. It carries the per-path failure and Potentially Failed thresholds, but omits the primary-path switchover threshold that RFC 7829 §7.2 includes in its three-field struct sctp_paddrthlds. Use PeerAddrThldsV2 for the complete RFC field set on Linux.
type PeerAddrThldsV2 ¶
type PeerAddrThldsV2 struct {
AssocID SCTPAssocID
// Address selects the path; a zeroed address applies to the association.
Address [128]byte
// PathMaxRxt is exceeded before the path is declared inactive (RFC 7829
// §7.2).
PathMaxRxt uint16
// PathPfThld is exceeded before the path enters the Potentially Failed
// state (RFC 7829 §7.2).
PathPfThld uint16
// PathCpThld is the consecutive-error threshold on the primary path. Once
// the error counter exceeds it, the stack makes the current active path
// primary instead — RFC 7829 §§5 and 7.2 Primary Path Switchover. The kernel
// calls it ps_retrans and exposes its default as net.sctp.ps_retrans.
//
// It is not a probing control. The kernel reads this value in exactly one
// place, where it calls sctp_assoc_set_primary; nothing consults it when
// deciding whether to keep heartbeating a path. The default of 0xffff
// therefore means switchover is disabled, not that probing is unbounded —
// the kernel's own comment on the default reads "Disable of Primary Path
// Switchover by default".
//
// Both RFC 7829 §5 and Linux test error_count > ps_retrans, so a value of 3
// permits three consecutive errors and switches when the counter becomes 4.
PathCpThld uint16
}
PeerAddrThldsV2 mirrors Linux's struct sctp_paddrthlds_v2. Linux introduced the V2 option number for ABI compatibility, but its three fields are the complete struct sctp_paddrthlds specified by RFC 7829 §7.2; the older Linux option exposes only the first two.
type PeerAddrinfo ¶
type PeerAddrinfo struct {
AssocID SCTPAssocID
// Address holds the peer address as a raw sockaddr. Use
// (*SCTPConn).SCTPGetPrimaryPeerAddr to obtain it decoded: the decoder
// this package uses is unexported, and decoding the bytes by hand means
// reproducing the per-entry family and bounds handling it does.
Address [128]byte
State PeerState
CWND uint32
SRTT uint32
RTO uint32
MTU uint32
}
PeerAddrinfo Parameters defined in RFC 6458 8.2.2 - Peer Address Information (SCTP_GET_PEER_ADDR_INFO)
type PeerState ¶
type PeerState int32
const ( // SCTP_INACTIVE means the path has failed: it has exceeded // Path.Max.Retrans without a response. See RFC 9260 section 8.2. SCTP_INACTIVE PeerState = iota // SCTP_PF ("potentially failed") is an intermediate state from RFC 7829: // some retransmissions have failed but the path is not yet declared // inactive. SCTP_PF // SCTP_ACTIVE means the path is reachable and in use. SCTP_ACTIVE // SCTP_UNCONFIRMED means the path has not yet been validated by a // heartbeat exchange. SCTP_UNCONFIRMED // SCTP_UNKNOWN is reported when the transport state is not known. SCTP_UNKNOWN PeerState = 0xffff )
Per-path states, from enum sctp_spinfo_state in the kernel's uapi linux/sctp.h. The order is load-bearing: callers compare PeerAddrinfo.State against these to decide whether a path is still usable, so the values must match what the kernel reports rather than read in a natural-looking order.
type PrInfo ¶
type PrInfo struct {
// Policy is one of the SCTPPrPolicy constants.
Policy uint16
// Value is a lifetime, retransmission count or priority, per Policy.
Value uint32
// contains filtered or unexported fields
}
PrInfo mirrors struct sctp_prinfo (RFC 6458 §5.3.7), the per-message partial reliability policy carried as SCTP_CMSG_PRINFO ancillary data.
Note the padding: the C struct is a __u16 followed by a __u32, so the value sits at offset 4 and the struct is 8 bytes rather than 6.
type PrStatus ¶
type PrStatus struct {
AssocID SCTPAssocID
// SID selects the stream to report on. Set it before the call.
SID uint16
// Policy selects which policy's counters to report. Set it before the
// call.
Policy uint16
// AbandonedUnsent counts messages discarded before any part was sent.
AbandonedUnsent uint64
// AbandonedSent counts messages discarded after at least one fragment had
// gone out.
AbandonedSent uint64
}
PrStatus mirrors struct sctp_prstatus used by RFC 7496 §4.3 for one-stream counters and §4.4 for association-wide counters.
type PreAssociationConfig ¶
type PreAssociationConfig struct {
// PartialReliability negotiates PR-SCTP (RFC 7496 §4.5).
PartialReliability SocketOptionState
// StreamReconfiguration controls Linux's negotiation switch for RFC 6525.
// RFC 6525 §6.3 defines StreamResetMask, but does not define this Linux
// support switch.
StreamReconfiguration SocketOptionState
// DynamicAddressReconfiguration negotiates ASCONF (RFC 5061). Enabling it
// requires Authentication to be explicitly enabled because RFC 5061
// §§4.1.1 and 4.1.2 require ASCONF and ASCONF-ACK to be authenticated.
DynamicAddressReconfiguration SocketOptionState
// Authentication negotiates SCTP-AUTH (RFC 4895).
Authentication SocketOptionState
// MessageInterleaving negotiates I-DATA user-message interleaving
// (RFC 8260). Linux also requires a non-zero fragment-interleave level.
MessageInterleaving SocketOptionState
// ExperimentalECN controls Linux's SCTP_ECN_SUPPORTED option. RFC 9260
// §1.7 removed the earlier SCTP ECN specification, so enabling this is an
// explicitly experimental kernel choice, not standards compliance.
ExperimentalECN SocketOptionState
// ReusePort is SCTP_REUSE_PORT (RFC 6458 §8.1.27). RFC 6458 limits it to
// one-to-one sockets, so any non-default value is rejected for SCTPEndpoint.
ReusePort SocketOptionState
// MappedV4Address is SCTP_I_WANT_MAPPED_V4_ADDR (RFC 6458 §8.1.15).
MappedV4Address SocketOptionState
// DisableFragments is SCTP_DISABLE_FRAGMENTS (RFC 6458 §8.1.11).
DisableFragments SocketOptionState
// ReceiveRcvInfo enables SCTP_RCVINFO (RFC 6458 §§5.3.5 and 8.1.29).
// SCTPEndpoint requires it and rejects an explicit disable.
ReceiveRcvInfo SocketOptionState
// ReceiveNxtInfo enables SCTP_NXTINFO (RFC 6458 §§5.3.6 and 8.1.30).
ReceiveNxtInfo SocketOptionState
// AdaptationLayer announces an adaptation indication in INIT
// (RFC 6458 §8.1.10). Zero is a valid explicit indication.
AdaptationLayer OptionalUint32
// FragmentInterleave is the level from RFC 6458 §8.1.20. Values 0, 1,
// and 2 are accepted by portable validation. Current Linux stores this as a
// boolean, so applying level 2 returns an error wrapping
// errors.ErrUnsupported instead of silently degrading to level 1. When it
// is unset, one-to-one sockets preserve the kernel default, while one-to-many
// SCTPEndpoint sockets apply level 1 as that section's SHOULD default.
// Explicit level 0, 1, or 2 always wins portable validation.
FragmentInterleave OptionalInt
// StreamResetMask selects the RFC 6525 §6.3 requests this endpoint permits.
// It is a combination of the SCTPEnableReset constants; zero explicitly
// permits none.
StreamResetMask OptionalUint32
// RTOInfo applies retransmission timeout parameters to SCTP_FUTURE_ASSOC
// before connect, bind, or listen (RFC 6458 §8.1.1, SCTP_RTOINFO). Nil
// leaves the kernel defaults unchanged. Non-zero fields set milliseconds;
// zero fields leave those values unchanged. AssocID must be
// SCTP_FUTURE_ASSOC.
RTOInfo *RtoInfo
// DelayedSACK applies Delay and Frequency to SCTP_FUTURE_ASSOC. Nil leaves
// the kernel defaults unchanged. The pointed-to value is snapshotted before
// SocketConfig opens a descriptor or invokes Control.
DelayedSACK *DelayedSACKConfig
// HMACIdentifiers is the preference-ordered HMAC-ALGO list sent in INIT
// (RFC 4895 §§3.3 and 6.1). Nil leaves the kernel list unchanged. A
// non-nil list must include mandatory SHA-1, contain only assigned package
// identifiers, and requires Authentication to be explicitly enabled.
HMACIdentifiers []uint16
// AuthenticatedChunks is the additive CHUNKS list sent in INIT
// (RFC 4895 §§3.2 and 6.1). Nil adds nothing. A non-nil list must be
// non-empty and unique, cannot contain INIT, INIT-ACK, SHUTDOWN-COMPLETE,
// or AUTH, and requires Authentication to be explicitly enabled.
AuthenticatedChunks []uint8
// Notifications configures future-association subscriptions with the
// non-deprecated SCTP_EVENT option (RFC 6458 §6.2.2). Duplicate types are
// rejected. SCTPEndpoint requires SCTP_ASSOC_CHANGE and rejects disabling
// it as a package invariant, following RFC 6458 §3.1.3's recommendation to
// ensure the event is enabled when association ids are used.
Notifications []NotificationSubscription
}
PreAssociationConfig is the typed socket configuration applied after SocketConfig.Control and InitMsg, but before bind, connect, or listen. It is snapshotted and validated before a descriptor is opened. Typed settings take precedence over overlapping writes made by Control.
The zero value is safe. Boolean settings use an explicit three-state value, while numeric settings use OptionalUint32 or OptionalInt so an intentional zero is distinguishable from the default.
Authentication key bytes and active-key selection deliberately remain in Control. RFC 4895 §6.1 permits endpoint-pair keys to be established by an external mechanism, and retaining secret material in a reusable SocketConfig would extend its lifetime unnecessarily. The non-secret INIT state is exposed by Authentication, HMACIdentifiers, and AuthenticatedChunks.
type PreconfiguredSocket ¶
type PreconfiguredSocket struct {
// contains filtered or unexported fields
}
PreconfiguredSocket is an immutable SocketConfig snapshot with typed options that must be applied after Control and InitMsg but before bind, connect, or listen. Construct one with SocketConfig.WithPreAssociation.
Keeping this as a wrapper preserves SocketConfig's original three-field shape so existing unkeyed literals remain source-compatible.
func (*PreconfiguredSocket) Dial ¶
func (cfg *PreconfiguredSocket) Dial(network string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
Dial is SocketConfig.Dial with the snapshotted pre-association plan.
func (*PreconfiguredSocket) DialContext ¶
func (cfg *PreconfiguredSocket) DialContext( ctx context.Context, network string, laddr, raddr *SCTPAddr, ) (*SCTPConn, error)
DialContext is SocketConfig.DialContext with the snapshotted pre-association plan.
func (*PreconfiguredSocket) Listen ¶
func (cfg *PreconfiguredSocket) Listen(network string, laddr *SCTPAddr) (*SCTPListener, error)
Listen is SocketConfig.Listen with the snapshotted pre-association plan.
func (*PreconfiguredSocket) ListenEndpoint ¶
func (cfg *PreconfiguredSocket) ListenEndpoint( network string, laddr *SCTPAddr, ) (*SCTPEndpoint, error)
ListenEndpoint is SocketConfig.ListenEndpoint with the snapshotted pre-association plan.
func (*PreconfiguredSocket) OpenEndpoint ¶
func (cfg *PreconfiguredSocket) OpenEndpoint( network string, laddr *SCTPAddr, ) (*SCTPEndpoint, error)
OpenEndpoint is SocketConfig.OpenEndpoint with the snapshotted pre-association plan.
type ProbeInterval ¶
type ProbeInterval struct {
AssocID SCTPAssocID
// Address selects the path; a zeroed address applies to the association.
Address [128]byte
// Interval is the probe period in milliseconds. Zero turns PLPMTUD off.
Interval uint32
}
ProbeInterval mirrors Linux's struct sctp_probeinterval, the kernel UAPI for controlling the packetization-layer path MTU discovery probe period. RFC 8899 defines the DPLPMTUD protocol procedure, but it does not define this struct or socket option.
PLPMTUD is how a path finds its MTU without relying on ICMP, which is widely filtered. Zero disables it, which is the default.
type RcvInfo ¶
type RcvInfo struct {
// SID is the stream the message arrived on.
SID uint16
// SSN is the stream sequence number.
SSN uint16
// Flags carries SCTP_UNORDERED and friends.
Flags uint16
// PPID is the payload protocol identifier in host byte order when returned
// by SCTPEndpoint.Receive. RFC 6458 §5.3.5 labels the ancillary field network
// byte order and says the SCTP stack leaves it untouched; the receive path
// converts it at the kernel boundary, matching SndInfo and SndRcvInfo.
PPID uint32
// TSN is the transmission sequence number.
TSN uint32
// CumTSN is the cumulative TSN acknowledged.
CumTSN uint32
// Context is the value set with SetContext.
Context uint32
// AssocID identifies the association; ignored on one-to-one sockets.
AssocID SCTPAssocID
// contains filtered or unexported fields
}
RcvInfo mirrors struct sctp_rcvinfo (RFC 6458 §5.3.5), the per-message receive information the kernel attaches as SCTP_RCVINFO ancillary data once SetRecvRcvInfo is enabled.
It is the non-deprecated half of what SndRcvInfo carries: RFC 6458 §5.3.2 titles SCTP_SNDRCV "DEPRECATED" and splits it into SCTP_SNDINFO for sending and this for receiving. The field order is not the same as SndRcvInfo's — TSN and CumTSN come before Context here and after it there — so the two are not interchangeable as raw memory.
TestStructLayoutsMatchKernel pins the layout. Callers normally do not need this type: SCTPRead converts whichever form the kernel sent into SndRcvInfo.
type RemoteError ¶
type RemoteError struct {
Error uint16
AssocID SCTPAssocID
// Data is the body of the peer's ERROR chunk.
Data []byte
// contains filtered or unexported fields
}
RemoteError is SCTP_REMOTE_ERROR (RFC 6458 6.1.3), delivering an ERROR chunk the peer sent.
func (*RemoteError) Flags ¶
func (n *RemoteError) Flags() uint16
func (*RemoteError) Length ¶
func (n *RemoteError) Length() uint32
func (*RemoteError) Type ¶
func (n *RemoteError) Type() SCTPNotificationType
type RtoInfo ¶
type RtoInfo struct {
AssocID SCTPAssocID
// Initial is the RTO used before any round trip has been measured.
Initial uint32
// Max caps the exponential backoff. Combined with AssocInfo.AsocMaxRxt it
// bounds how long a send can sit unacknowledged before the association is
// declared failed: the retransmission intervals double up to Max, so a
// large Max means a peer that vanishes is noticed only after minutes.
Max uint32
// Min floors the RTO.
Min uint32
}
RtoInfo mirrors struct sctp_rtoinfo (RFC 6458 §8.1.1, SCTP_RTOINFO). It governs the retransmission timer, and with it how quickly the stack gives up on an unresponsive peer.
All durations are milliseconds. A zero field means "leave unchanged" on a set, which is how the kernel reads it.
type SCTPAddr ¶
func ResolveSCTPAddr ¶
func (*SCTPAddr) MarshalSockaddr ¶
MarshalSockaddr validates and encodes the packed sockaddr array used by Linux SCTP connectx and bindx operations.
func (*SCTPAddr) ToRawSockAddrBuf ¶
ToRawSockAddrBuf encodes this address for compatibility with older callers. It returns nil for an invalid address; new code should call MarshalSockaddr when it needs the validation error.
type SCTPAssocID ¶
type SCTPAssocID int32
type SCTPConn ¶
type SCTPConn struct {
// contains filtered or unexported fields
}
func DialSCTPContext ¶
func DialSCTPContext(ctx context.Context, network string, laddr, raddr *SCTPAddr, options InitMsg) (*SCTPConn, error)
DialSCTPContext is DialSCTPExt with a context. A nil context is rejected with an error wrapping syscall.EINVAL.
The attempt is abandoned as soon as ctx is done: the association is aborted and the socket released before this returns, so nothing further goes on the wire and no descriptor is left behind. A caller expresses a bounded attempt with context.WithTimeout and retries on its own schedule.
DialSCTP, DialSCTPExt and SocketConfig.Dial are unchanged and still block for as long as the kernel's own retransmission budget.
func DialSCTPExt ¶
DialSCTPExt - same as DialSCTP but with given SCTP options
func NewSCTPConn ¶
func NewSCTPConn(fd int, handler NotificationHandler) *SCTPConn
NewSCTPConn takes ownership of fd immediately, including when descriptor initialization fails. The caller must not close fd or use it after this call. The returned connection records initialization failures and reports them from subsequent operations because this compatibility signature cannot return an error directly.
func (*SCTPConn) Abort ¶
Abort terminates the SCTP association immediately by sending an ABORT chunk. Unlike Close(), this does not perform a graceful shutdown handshake. Use this when you need immediate resource release without waiting for the peer to acknowledge the shutdown (e.g., when the peer is unreachable).
func (*SCTPConn) AddStreams ¶
AddStreams asks the peer to widen the association, adding inStreams inbound and outStreams outbound streams (RFC 6525 §6.3.4).
This needs the reconfiguration extension negotiated — SetReconfigSupported on both ends before connecting — and SCTPEnableChangeAssocReq present in the mask SetEnableStreamReset installed. Without both the kernel refuses with ENOPROTOOPT, which is easy to misread as the option not existing.
The request goes to the peer, so success here means it was sent and accepted, not that the streams are usable yet. GetStatus reports the counts once the peer has answered.
func (*SCTPConn) AsconfSupported ¶
AsconfSupported reports the negotiated outcome for ASCONF.
func (*SCTPConn) AuthActiveKey ¶
AuthActiveKey reports which shared key currently signs outbound AUTH chunks.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) AuthSupported ¶
AuthSupported reports the negotiated outcome for AUTH.
func (*SCTPConn) AutoAsconf ¶
AutoAsconf reports whether ASCONF announcement is enabled.
func (*SCTPConn) BindAdd ¶
BindAdd atomically adds addr to this endpoint's local address set (sctp_bindx with SCTP_BINDX_ADD_ADDR, RFC 6458 §9.1).
A zero port is replaced with the endpoint's bound port. A non-zero port must equal that port. The caller's SCTPAddr is never modified, and LocalAddr is refreshed from the kernel after a successful operation.
On an established association this local socket operation may also start the optional RFC 5061 dynamic-address procedure. That capability must have been negotiated before the INIT; see SetAsconfSupported and SetAuthSupported. Success from BindAdd records the kernel's acceptance of the local bindx call, not receipt of the peer's ASCONF-ACK: RFC 5061 §5.3 rule F1 says the address is not fully added to the association until that acknowledgement arrives.
RFC 6458 Erratum 4921 proposes different IPv4/IPv6 wording for §9.1, but is Held for Document Update, not Verified. This method therefore preserves the socket family's kernel behavior rather than treating that erratum as a new normative rule.
func (*SCTPConn) BindRemove ¶
BindRemove atomically removes addr from this endpoint's local address set (sctp_bindx with SCTP_BINDX_REM_ADDR, RFC 6458 §9.1).
Port handling, input ownership, cache refresh, RFC 5061 negotiation, and the status of RFC 6458 Erratum 4921 are the same as for BindAdd. RFC 6458 §9.1 forbids removing every local address. For an established association, RFC 5061 §5.3 rules F4 and F5 additionally govern when a removed address stops being valid and prohibit deleting the association's last address.
func (*SCTPConn) Close ¶
Close closes the SCTP connection gracefully with a timeout fallback.
It initiates a graceful shutdown by sending a SHUTDOWN chunk to the peer and waits up to 3 seconds for the peer to acknowledge (SHUTDOWN-ACK). If the peer responds, the connection closes gracefully and resources are released immediately. If the peer does not respond within the timeout (e.g., network failure or unreachable peer), an ABORT chunk is sent to forcefully terminate the association and release resources.
This ensures that Close always returns promptly and releases resources, avoiding the EADDRINUSE "Address already in use" error that can occur when the kernel still occupies the resource.
For immediate termination without waiting, use Abort() instead.
func (*SCTPConn) CloseWithTimeout ¶
CloseWithTimeout is Close with a caller-chosen grace period.
A zero or negative timeout skips the wait entirely and terminates the association immediately, which is equivalent to Abort.
func (*SCTPConn) DeactivateAuthKey ¶
DeactivateAuthKey stops a shared key being used for new packets while leaving it able to verify packets already in flight (RFC 6458 §8.3.4).
This is the safe half of key rollover: deactivate, let the peer's in-flight packets drain, then delete.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) DeleteAuthKey ¶
DeleteAuthKey removes a shared key (RFC 6458 §8.3.5).
The active key cannot be deleted — the kernel reports EINVAL — so select another with SetAuthActiveKey first, or deactivate this one. A key still needed to verify packets in flight should be deactivated rather than deleted.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) DisableFragments ¶
DisableFragments reports whether message fragmentation is disabled.
func (*SCTPConn) EcnSupported ¶
EcnSupported reports Linux's SCTP_ECN_SUPPORTED value; see SetEcnSupported.
func (*SCTPConn) EnableStreamReset ¶
EnableStreamReset reports which stream reconfiguration requests are permitted.
func (*SCTPConn) EventSubscribed ¶
func (c *SCTPConn) EventSubscribed(eventType SCTPNotificationType) (bool, error)
EventSubscribed reports whether a single notification type is subscribed.
It is the getsockopt direction of SCTP_EVENT: the type to query goes in, and the kernel fills in whether it is on.
func (*SCTPConn) ExposePotentiallyFailed ¶
ExposePotentiallyFailed reports the current PF exposure level.
func (*SCTPConn) GetAdaptationLayer ¶
GetAdaptationLayer reports the adaptation layer indication this endpoint announces.
func (*SCTPConn) GetAssocInfo ¶
GetAssocInfo reports association parameters, including the peer's last advertised receive window.
func (*SCTPConn) GetAssocStats ¶
func (c *SCTPConn) GetAssocStats() (*AssocStats, error)
GetAssocStats reads the per-association counters (SCTP_GET_ASSOC_STATS).
This is a Linux extension with no RFC 6458 equivalent. It needs an established association; on a socket without one the kernel returns EINVAL.
Reading resets AssocStats.MaxRto, so the value is the maximum observed since the previous call rather than since the association began.
func (*SCTPConn) GetContext ¶
GetContext reports the current default context.
func (*SCTPConn) GetDefaultPrInfo ¶
func (c *SCTPConn) GetDefaultPrInfo() (*DefaultPrInfo, error)
GetDefaultPrInfo reports the current default partial reliability policy.
func (*SCTPConn) GetDefaultSentParam ¶
func (c *SCTPConn) GetDefaultSentParam() (*SndRcvInfo, error)
GetDefaultSentParam returns PPID in host byte order. Prefer GetDefaultSndInfo for new code (RFC 6458 §8.1.13).
func (*SCTPConn) GetDefaultSndInfo ¶
GetDefaultSndInfo reports the current default send parameters.
func (*SCTPConn) GetFragmentInterleave ¶
GetFragmentInterleave reports the current fragmented interleave level.
func (*SCTPConn) GetInitMsg ¶
GetInitMsg reads the association initialisation parameters (SCTP_INITMSG).
SetInitMsg has always been available; this is the direction that was missing, which meant a caller could not check what the kernel actually recorded — the zero fields of an InitMsg mean "leave the default", so what was set and what is in force are different things.
func (*SCTPConn) GetMaxBurst ¶
GetMaxBurst reports the current maximum burst.
func (*SCTPConn) GetMaxSegSize ¶
GetMaxSegSize reports the association's current maximum fragment size.
func (*SCTPConn) GetNoDelay ¶
func (*SCTPConn) GetPartialDeliveryPoint ¶
GetPartialDeliveryPoint reports the current partial delivery point in bytes.
func (*SCTPConn) GetPeerAddrInfo ¶
func (c *SCTPConn) GetPeerAddrInfo(info *PeerAddrinfo) error
GetPeerAddrInfo reads one peer address's state (SCTP_GET_PEER_ADDR_INFO, RFC 6458 §8.2.2).
This is the only way to see a secondary path. GetStatus reports the primary only, so on the multi-homed associations this package exists to support, nothing else says whether the other paths are active, what their round-trip time is, or what congestion window they have.
Set Address on the value passed in to name the path; the rest is filled in.
It returns EACCES for a path that is in the PF state when the association's PF exposure level is SCTPPFStateDisabled — the kernel refuses the question rather than answering it. That is the one combination where this call starts failing precisely when a path degrades; see SCTPPFStateDisabled.
func (*SCTPConn) GetPeerAddrParams ¶
func (c *SCTPConn) GetPeerAddrParams(p *PeerAddrParams) error
GetPeerAddrParams reads the per-path parameters (SCTP_PEER_ADDR_PARAMS).
Zero the Address of the value passed in to ask about the association rather than one path.
func (*SCTPConn) GetPeerAddrThlds ¶
func (c *SCTPConn) GetPeerAddrThlds() (*PeerAddrThlds, error)
GetPeerAddrThlds reports the current per-path retransmission thresholds.
func (*SCTPConn) GetPeerAddrThldsV2 ¶
func (c *SCTPConn) GetPeerAddrThldsV2() (*PeerAddrThldsV2, error)
GetPeerAddrThldsV2 reports the per-path thresholds including the switchover threshold.
func (*SCTPConn) GetPrAssocStatus ¶
GetPrAssocStatus reports how many messages were abandoned across the whole association under the given partial reliability policy (RFC 7496 §4.4).
This is the association-wide total; GetPrStreamStatus reports one stream. Both need an established association.
The returned PrStatus.SID is not meaningful here — the option ignores it.
func (*SCTPConn) GetPrStreamStatus ¶
GetPrStreamStatus reports how many messages were abandoned on one stream under the given partial reliability policy (RFC 7496 §4.3).
It needs an established association; on a socket without one the kernel returns EINVAL.
func (*SCTPConn) GetProbeInterval ¶
func (c *SCTPConn) GetProbeInterval(p *ProbeInterval) error
GetProbeInterval reads the PLPMTUD probe interval.
func (*SCTPConn) GetReadBuffer ¶
func (*SCTPConn) GetRemoteUDPEncapsPort ¶
GetRemoteUDPEncapsPort reads the peer's UDP encapsulation port. Set Address on the value passed in to name a path.
func (*SCTPConn) GetReusePort ¶
GetReusePort reports whether port reuse is enabled.
func (*SCTPConn) GetRtoInfo ¶
GetRtoInfo reports the association's retransmission timer parameters.
func (*SCTPConn) GetSackTimer ¶
func (*SCTPConn) GetStreamSchedulerValue ¶
GetStreamSchedulerValue reads the scheduler parameter for one stream.
func (*SCTPConn) GetWriteBuffer ¶
func (*SCTPConn) Getsockopt ¶
func (*SCTPConn) HmacIdent ¶
HmacIdent reports the HMAC algorithms this endpoint offers, in preference order (RFC 6458 §8.1.17).
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) InterleavingSupported ¶
InterleavingSupported reports the negotiated outcome for message interleaving.
func (*SCTPConn) LocalAuthChunks ¶
LocalAuthChunks reports the chunk types this endpoint requires the peer to authenticate (RFC 6458 §8.2.4).
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) MappedV4Addr ¶
MappedV4Addr reports whether IPv4-mapped addresses are in use.
func (*SCTPConn) PeelOff ¶
PeelOff detaches association id onto its own socket (RFC 6458 §9.2).
This only works on a one-to-many (SOCK_SEQPACKET) socket, which is what peeling off is for: it turns one association out of many into a socket of its own. SCTPEndpoint.PeelOff is the package-owned typed path. Calling this method on a connection returned by Dial or Accept still returns EINVAL from the kernel — sctp_do_peeloff rejects their one-to-one style. NewSCTPConn remains the lower-level escape for a caller-owned one-to-many descriptor.
A peeled socket looks one-to-one from userspace but is not one internally: sctp_do_peeloff builds it with sctp_clone_sock(..., SCTP_SOCKET_UDP_HIGH_BANDWIDTH). That matters at teardown, because sctp_shutdown opens with "if (!sctp_style(sk, TCP)) return" and so does nothing on this style. Close asks through the send path as well, which is the route that works here; see shutdownViaEOF.
Without that second route Close was measurably wrong on these connections, with a capture on both sides:
ordinary conn peeled, before peeled, now Close returned in 21.7us 3.005s 260us SHUTDOWN on wire 1 0 1 ABORT on wire 0 1 0
It ran the whole grace period out, because SCTP_STATUS kept reporting SCTP_ESTABLISHED and nothing told it the handshake had finished, and then fell back to the abort. So a caller asking for a graceful close got the opposite of one, three seconds later.
func (*SCTPConn) PeerAuthChunks ¶
PeerAuthChunks reports the chunk types the peer requires this endpoint to authenticate (RFC 6458 §8.2.3).
It needs an established association: without one the kernel returns EINVAL, since there is no peer to have told us anything. See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) PrSupported ¶
PrSupported reports whether partial reliability is available on this association.
It reports the negotiated outcome, not what SetPrSupported requested. With net.sctp.prsctp_enable at its default of 1 that outcome is true regardless of the socket option, so a true result here does not imply anyone asked for it. Compare ReconfigSupported, whose sysctl defaults to 0 and which therefore does track the option.
func (*SCTPConn) ReadMsg ¶
func (c *SCTPConn) ReadMsg(max int) ([]byte, *SndRcvInfo, error)
ReadMsg reads one whole message, reassembling it across as many recvmsg calls as the kernel needs to deliver it. Once the first application-data fragment arrives, one runtime-poller read lock covers the complete record so another concurrent reader cannot steal a fragment. Notifications preceding that record are delivered outside the poller's lock.
At most max bytes are retained. If the message is larger, ReadMsg drains its remainder before returning ErrMsgTooLong; this preserves the record boundary and guarantees the next read cannot mistake the rejected tail for a new message. Notifications are likewise header-validated and bounded by NotificationReassemblyLimit before being consumed or passed to a handler. The returned SndRcvInfo is from the first application-data fragment.
func (*SCTPConn) ReconfigSupported ¶
ReconfigSupported reports whether stream reconfiguration is available.
The value is negotiated, and the getter changes meaning once an association exists — which is easy to misread as the setter having failed:
- Before connecting it echoes what SetReconfigSupported wrote.
- After connecting it reports whether *both* ends enabled it. Setting it on only one end reads back false there, and a set issued after connect never changes the answer even though it returns success.
That was measured across all three combinations rather than inferred. So a false result on a live association means the peer did not offer the extension, not that the local call was rejected.
func (*SCTPConn) RemoteAddr ¶
func (*SCTPConn) ResetAssoc ¶
ResetAssoc restarts the association's sequence numbering as a whole (RFC 6525 §6.3.3).
This needs the reconfiguration extension negotiated and SCTPEnableResetAssocReq in the SetEnableStreamReset mask.
func (*SCTPConn) ResetStreams ¶
ResetStreams restarts the sequence numbering of the named streams, or of every stream when streams is empty (RFC 6525 §6.3.2).
direction is a combination of SCTPStreamResetIncoming and SCTPStreamResetOutgoing; at least one is required, since the kernel rejects a request with neither.
Like AddStreams this needs the reconfiguration extension negotiated — SetReconfigSupported on both ends before connecting — plus SCTPEnableResetStreamReq in the SetEnableStreamReset mask. Without them the kernel answers ENOPROTOOPT, which reads like the option not existing.
The option length has to cover the stream list, not just the fixed header: naming one stream while passing the bare struct length is rejected with EINVAL. That is handled here, and is the reason this takes a slice rather than exposing the raw struct.
func (*SCTPConn) SCTPGetPrimaryPeerAddr ¶
func (*SCTPConn) SCTPRead ¶
func (c *SCTPConn) SCTPRead(b []byte) (int, *SndRcvInfo, error)
SCTPRead reads one message, or as much of one message as fits in b.
If the message is larger than b, the remainder is not discarded: it is returned by subsequent reads, which makes a truncated message indistinguishable from a complete one here. Callers of framed protocols should use SCTPReadFlags and test the returned flags for MSG_EOR, or use ReadMsg to have the reassembly done for them.
func (*SCTPConn) SCTPReadFlags ¶
SCTPReadFlags is SCTPRead, additionally returning the flags recvmsg reported for the message.
The kernel sets MSG_EOR when b received the end of a message and clears it when more of that message remains, so flags&MSG_EOR == 0 means the message was truncated and the remainder will arrive on subsequent reads. Without checking it, an oversized message is silently split and the remainder is delivered as what looks like a fresh message.
func (*SCTPConn) SCTPReadMsg ¶
SCTPReadMsg performs one recvmsg and returns the payload, ancillary-data length, and message flags without interpreting or discarding any of them. It is the escape hatch for extensions whose control messages this package does not yet decode. In particular, callers must test MSG_CTRUNC before trusting oob; use syscall.ParseSocketControlMessage to walk complete data.
Notifications are returned with MSG_NOTIFICATION, and an application record that does not fit in b is returned without MSG_EOR. Unlike Read and ReadMsg, this method deliberately applies no notification or framing policy.
func (*SCTPConn) SCTPReadNextInfo ¶
SCTPReadNextInfo is SCTPReadFlags, additionally returning what the kernel said about the message queued behind this one.
nxt is nil when SetRecvNxtInfo has not been enabled or when nothing else is queued; neither is an error. Its Length is the whole size of the next message, so a caller can size the next buffer exactly rather than reading into a guess and reassembling.
func (*SCTPConn) SCTPWriteInfo ¶
SCTPWriteInfo sends one message using the non-deprecated ancillary data types, optionally attaching a partial reliability policy and an authentication key.
This is the send-side counterpart to the SCTP_RCVINFO support on the read path. RFC 6458 §5.3.2 titles the struct sctp_sndrcvinfo that SCTPWrite sends "DEPRECATED" and splits it into SCTP_SNDINFO for sending and SCTP_RCVINFO for receiving; this emits SCTP_SNDINFO.
SCTPWrite is unchanged and still emits SCTP_SNDRCV, because switching it would change the bytes on every existing caller's socket. The kernel accepts either, and in fact accepts both in one sendmsg without complaint, so the two can be mixed freely on the same association — that was measured.
Any of the three may be nil:
- info nil sends with the socket defaults from SetDefaultSndInfo.
- pr adds SCTP_CMSG_PRINFO, overriding the default policy from SetDefaultPrInfo for this message only. It needs PR-SCTP negotiated; see SetPrSupported.
- auth adds SCTP_CMSG_AUTHINFO, naming the shared key to authenticate this message with. It needs net.sctp.auth_enable; see SetAuthActiveKey.
SndInfo.PPID follows the package-wide host-order convention. RFC 6458 §5.3.4 labels the ancillary field network byte order and says the SCTP stack leaves it untouched, so the copy emitted below is converted without mutating the caller's structure.
func (*SCTPConn) SetAdaptationLayer ¶
SetAdaptationLayer announces an adaptation layer indication to the peer (SCTP_ADAPTATION_LAYER, RFC 6458 §8.1.10).
The value is opaque to SCTP and is carried in the INIT, so it must be set before the association is established to reach the peer. The other direction has always been available: the peer's indication arrives as an AdaptationIndication notification.
func (*SCTPConn) SetAsconfSupported ¶
SetAsconfSupported negotiates dynamic address reconfiguration, RFC 5061, for this socket.
This is what makes SetAutoAsconf mean anything. net.sctp.addip_enable defaults to 0, and with it off the endpoint never negotiates ASCONF, so SetAutoAsconf succeeds and then adding a local address mid-association puts nothing on the wire — measured as zero ASCONF chunks, against two ASCONF and two ASCONF-ACK once this is on.
It must be set before the socket is bound: the capability goes in the INIT. The kernel also requires AUTH for ASCONF, so SetAuthSupported belongs with it.
func (*SCTPConn) SetAssocInfo ¶
SetAssocInfo sets association parameters (SCTP_ASSOCINFO). Fields left zero are unchanged.
Setting AsocMaxRxt bounds how many unacknowledged retransmissions the stack tolerates before declaring the association failed, which is what converts a peer that has silently gone away into an error the application can see.
func (*SCTPConn) SetAuthActiveKey ¶
SetAuthActiveKey selects which shared key signs outbound AUTH chunks (RFC 6458 §8.1.18).
The whole SCTP_AUTH_* family needs AUTH negotiated on the socket, and on a stock kernel it is not. With it off every one of these calls fails with EACCES — not EOPNOTSUPP, which is what makes it look like a permissions problem rather than a disabled feature. That was measured.
There are two ways to turn it on, and the per-socket one is usually what a caller wants: SetAuthSupported before binding, which needs no privilege. The other is the net.sctp.auth_enable sysctl, which is system-wide and root-only; this comment used to name it as the only option, which is why the rest of this family still points here.
func (*SCTPConn) SetAuthChunk ¶
SetAuthChunk adds one chunk type to the CHUNKS list this endpoint will send in future INIT and INIT ACK chunks (RFC 6458 §8.3.2 and RFC 4895 §6.1).
The option is additive and set-only: each call adds a type, and there is no way to remove one or to read the set back other than LocalAuthChunks.
RFC 6458 §8.3.2 specifies that changes affect only future associations. A call on a connected Linux socket therefore succeeds but does not retrofit the current association; that is the specified timing, not a missing kernel validation. RFC 4895 §6.1 separately defines how the CHUNKS list is advertised and how shared keys are established.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) SetAuthKey ¶
SetAuthKey installs a shared key for authenticating chunks (RFC 6458 §8.3.3).
keyNumber names the key for SetAuthActiveKey, DeleteAuthKey and DeactivateAuthKey. Key 0 is the null key every association starts with; overwriting it is permitted.
The key may not be empty: the kernel rejects a zero-length key with EINVAL rather than treating it as a deletion. The upper bound is what the length field can express — sca_keylength is a __u16, and sctp_setsockopt_auth_key clamps optlen to USHRT_MAX + sizeof(*authkey) for that reason — which is the same 65535 the guard below applies. An earlier version of this comment claimed 8192; no such bound exists. The kernel also validates the length against the option size, so a mismatch cannot make it read past the buffer.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) SetAuthSupported ¶
SetAuthSupported negotiates AUTH, RFC 4895, for this socket.
The AUTH accessors on this type are documented as needing net.sctp.auth_enable, which is a system-wide sysctl only root can set. That is the older half of the story: this option turns AUTH on for one socket with the sysctl still at its default of 0, which was measured rather than assumed.
Set it before binding — the capability is announced in the INIT.
func (*SCTPConn) SetAutoAsconf ¶
SetAutoAsconf enables or disables announcing local address changes to the peer with ASCONF chunks (RFC 6458 §8.1.23).
Enabling it needs a socket bound to the wildcard address, not merely a bound socket. The kernel's gate is
if (!sctp_is_ep_boundall(sk) && *val) return -EINVAL;
so a socket bound to a specific address is refused exactly like an unbound one — measured as bound 127.0.0.1 set(1) → EINVAL, bound 0.0.0.0 set(1) → OK. Disabling it is always allowed, since the gate only guards a non-zero value.
That rules out the obvious place to call it. A listener bound to named addresses, which is the ordinary multi-homing case, cannot enable this at all; it has to be a wildcard bind. Contrast SetReusePort, which must be set before bind.
func (*SCTPConn) SetContext ¶
SetContext sets the context value reported with messages received from the peer (RFC 6458 §8.1.25).
Per the RFC this affects received messages only; it does not change the context saved with outbound messages, which SCTPWrite carries per message in SndRcvInfo.Context.
func (*SCTPConn) SetDeadline ¶
SetDeadline sets both the read and write deadlines.
A zero time.Time clears the deadline, as with net.Conn.
func (*SCTPConn) SetDefaultPrInfo ¶
func (c *SCTPConn) SetDefaultPrInfo(info *DefaultPrInfo) error
SetDefaultPrInfo sets the partial reliability policy applied to messages sent without their own (SCTP_DEFAULT_PRINFO, RFC 6458 §8.1.32).
The meaning of Value depends on Policy; see the SCTPPrPolicy constants. A policy outside that set is rejected by the kernel with EINVAL.
This is accepted on a socket where PrSupported reports false — the policy is recorded and simply never takes effect, because abandoning a message requires the FORWARD-TSN the extension negotiates. Enable SetPrSupported before connecting if the policy is meant to do anything.
func (*SCTPConn) SetDefaultSentParam ¶
func (c *SCTPConn) SetDefaultSentParam(info *SndRcvInfo) error
SetDefaultSentParam sets the deprecated sctp_sndrcvinfo defaults from RFC 6458 §8.1.13. PPID is accepted in host byte order, like SCTPWrite. RFC 6458 §5.3.2 labels the ABI field network byte order while requiring the SCTP stack to leave it untouched, so the package converts a copy without modifying info. Prefer SetDefaultSndInfo for new code.
func (*SCTPConn) SetDefaultSndInfo ¶
SetDefaultSndInfo sets the send parameters applied to messages written without their own (RFC 6458 §8.1.31).
This is the replacement for SetDefaultSentParam: RFC 6458 §8.1.13 deprecates SCTP_DEFAULT_SEND_PARAM along with the struct sctp_sndrcvinfo it carries. Prefer this for new code; the two write the same underlying defaults.
PPID uses the same host-order convention as SCTPWrite and SCTPWriteInfo. RFC 6458 §5.3.4 labels the ABI field network byte order while requiring the SCTP stack to leave it untouched, so the package converts a copy at the socket boundary without modifying info.
The kernel rejects a short option, so this is one of the places where the Go struct size has to be right; TestStructLayoutsMatchKernel pins it.
func (*SCTPConn) SetDisableFragments ¶
SetDisableFragments controls whether a message larger than the path MTU is fragmented (SCTP_DISABLE_FRAGMENTS, RFC 6458 §8.1.11).
With fragmentation off, a message that does not fit is refused with EMSGSIZE rather than split. That is what a caller wants when the peer is a device that cannot reassemble, and it turns a silent behaviour change into an error they can see.
func (*SCTPConn) SetEcnSupported ¶
SetEcnSupported toggles Linux's experimental SCTP ECN capability.
RFC 9260 §1.7 removed the former SCTP ECN specification. This Linux UAPI option is therefore not a claim of compliance with a current SCTP ECN RFC and should be used only when both endpoints' kernel behavior is independently qualified.
func (*SCTPConn) SetEnableStreamReset ¶
SetEnableStreamReset selects which stream reconfiguration requests this endpoint permits (RFC 6525 §6.3). mask is a combination of the SCTPEnableReset constants; zero permits none.
This governs what the endpoint will accept and initiate, and is independent of SetReconfigSupported, which decides whether the extension is negotiated at all. Both are needed for reconfiguration to work.
func (*SCTPConn) SetExposePotentiallyFailed ¶
SetExposePotentiallyFailed controls whether the PF state of RFC 7829 is reported (SCTP_EXPOSE_POTENTIALLY_FAILED_STATE).
PF is the early warning that a path has missed retransmissions but has not yet been declared unreachable, and it is the reason RFC 7829 exists: without it a caller learns about a dead path only when the retransmission budget runs out, which on the defaults is minutes. The kernel hides it unless asked, following net.sctp.pf_expose, so a caller who correctly subscribes to SCTP_PEER_ADDR_CHANGE and never sees SCTP_ADDR_POTENTIALLY_FAILED concludes the state does not exist.
level is one of the SCTPPFState constants; SCTPPFStateEnabled is the one that turns reporting on. Unlike most of the options here it may be changed on a live association, and it can be changed back: sctp_setsockopt_pf_expose rejects only a value above SCTPPFStateEnabled, with EINVAL, and has no locked state. An earlier version of this comment said otherwise; that was not measured, and the kernel has no such path.
Only SCTPPFStateEnabled delivers SCTP_ADDR_POTENTIALLY_FAILED: the kernel suppresses the notification at both other levels. The levels differ in what GetPeerAddrInfo does, not in what it reports —
SCTPPFStateUnset GetPeerAddrInfo reports SCTP_PF, no notification SCTPPFStateDisabled GetPeerAddrInfo returns EACCES, no notification SCTPPFStateEnabled GetPeerAddrInfo reports SCTP_PF, notification delivered
func (*SCTPConn) SetFragmentInterleave ¶
SetFragmentInterleave controls whether a partial delivery on one stream blocks delivery of messages on the others (RFC 6458 §8.1.20).
level must be one of SCTPFragmentInterleaveNone, ...Other or ...Streams. Linux keeps a flag rather than a level, so it stores any non-zero request as 1. The range check rejects undefined values before the syscall, and the immediate readback rejects level 2 with an error wrapping errors.ErrUnsupported instead of reporting false success.
The default is SCTPFragmentInterleaveNone, which blocks every other message while a partial delivery is in progress. ...Other is the highest level that reads back. True level 2 is unavailable on current Linux. Negotiating the I-DATA chunk with SetInterleavingSupported is a separate RFC 8260 capability; it requires a non-zero fragment setting but does not make this option level 2.
func (*SCTPConn) SetHmacIdent ¶
SetHmacIdent sets the HMAC algorithms this endpoint offers, most preferred first (RFC 6458 §8.1.17).
The kernel validates the identifiers and reports EOPNOTSUPP for one it does not implement — identifier 2 is unassigned in the IANA registry and is refused, which was measured. Use the SCTPAuthHmacID constants.
See SetAuthActiveKey about net.sctp.auth_enable.
func (*SCTPConn) SetInitMsg ¶
SetInitMsg sets the association initialisation parameters (SCTP_INITMSG).
Every field is a uint16 in the kernel. The arguments are ints, so a value outside that range used to be truncated silently: 65536 streams became 0, which the kernel reads as "leave the default", and a caller asking for more streams than SCTP can carry got the default instead of an error. Read them back with GetInitMsg.
func (*SCTPConn) SetInterleavingSupported ¶
SetInterleavingSupported negotiates user message interleaving, the I-DATA chunk of RFC 8260.
Set it before binding, like the other capability negotiations here: the kernel stores it on the endpoint and reads it when the INIT is built, so on a connection returned by Dial or Accept this succeeds and changes nothing, and InterleavingSupported then reports false — which reads like a broken getter rather than a call that came too late. Use SocketConfig.Control to reach the descriptor beforehand.
It is also refused with EPERM unless net.sctp.intl_enable is on and SetFragmentInterleave has been given a non-zero level, because interleaving without that would deliver fragments of different messages to a caller not expecting them.
func (*SCTPConn) SetMappedV4Addr ¶
SetMappedV4Addr controls whether IPv4 addresses are reported to the caller in IPv4-mapped IPv6 form on an AF_INET6 socket (SCTP_I_WANT_MAPPED_V4_ADDR, RFC 6458 §8.1.15).
func (*SCTPConn) SetMaxBurst ¶
SetMaxBurst bounds how many packets the association may emit back to back (RFC 6458 §8.1.24).
Zero disables burst mitigation. The kernel default is 4, which was read back rather than taken from the specification.
func (*SCTPConn) SetMaxSegSize ¶
SetMaxSegSize sets the maximum fragment size the association will use (SCTP_MAXSEG, RFC 6458 8.1.16). Messages larger than this are fragmented across multiple DATA chunks rather than being sent as one.
A value of zero restores the default, which is derived from the path MTU. The kernel clamps the request to what the path can carry, so read it back with GetMaxSegSize if the effective value matters.
func (*SCTPConn) SetNoDelay ¶
func (*SCTPConn) SetPartialDeliveryPoint ¶
SetPartialDeliveryPoint sets the message size, in bytes, at which the kernel starts delivering a message piecewise to free receive window for the peer (RFC 6458 §8.1.21).
A lower value makes partial delivery happen more often. RFC 6458 notes the call fails if the value exceeds the socket receive buffer, so a caller raising this should raise SO_RCVBUF first.
func (*SCTPConn) SetPeerAddrParams ¶
func (c *SCTPConn) SetPeerAddrParams(p *PeerAddrParams) error
SetPeerAddrParams writes the per-path parameters (SCTP_PEER_ADDR_PARAMS).
Set the matching SPP_ flag for each field that should take effect; see PeerAddrParams.
func (*SCTPConn) SetPeerAddrThlds ¶
func (c *SCTPConn) SetPeerAddrThlds(th *PeerAddrThlds) error
SetPeerAddrThlds sets the per-path retransmission thresholds that drive failure detection (RFC 7829 §7.2).
A zeroed Address applies the thresholds to every path of the association, which is the form to use on the single-homed sockets this package usually creates.
func (*SCTPConn) SetPeerAddrThldsV2 ¶
func (c *SCTPConn) SetPeerAddrThldsV2(th *PeerAddrThldsV2) error
SetPeerAddrThldsV2 sets the per-path thresholds including the primary path switchover threshold that SetPeerAddrThlds cannot reach.
This is a Linux extension of the RFC 7829 option in the sense that the option number is Linux's back-compatibility device; the third threshold itself is RFC 7829 §7.2's spt_pathcpthld. See PeerAddrThldsV2.PathCpThld for what it does — it moves the primary path, and does not govern probing.
func (*SCTPConn) SetPeerPrimaryAddr ¶
SetPeerPrimaryAddr asks the peer to make addr its primary destination (SCTP_SET_PEER_PRIMARY_ADDR, RFC 6458 §8.3.1).
This is the other direction from SetPrimaryPeerAddr: that one chooses where this endpoint sends, while this one asks the peer to change where it sends. The request travels as an ASCONF parameter, so it needs RFC 5061 negotiated — see SetAsconfSupported, without which the kernel refuses with EPERM because net.sctp.addip_enable defaults to 0. addr must be one of this endpoint's own bound addresses.
As with SetPrimaryPeerAddr, addr must name exactly one address; anything else returns EINVAL rather than being narrowed to the first silently.
func (*SCTPConn) SetPrSupported ¶
SetPrSupported enables or disables the PR-SCTP partial reliability extension (RFC 7496 §4.5).
Set it before connecting: the extension is negotiated in the INIT handshake, so a later call cannot add it to a live association.
On a stock kernel this option changes nothing, because net.sctp.prsctp_enable defaults to 1 and the extension is therefore offered whether or not it is set here. PrSupported consequently reports true on an association where neither end touched the option — measured across all four enable combinations. The call is still worth making for a caller that cannot assume the sysctl, and setting it to false is the only way to opt an individual socket out.
Despite RFC 7496 describing this as an on/off value, Linux carries it in a struct sctp_assoc_value and rejects a plain int with EINVAL — measured, not inferred from the header, which declares no struct for it.
func (*SCTPConn) SetPrimaryPeerAddr ¶
SetPrimaryPeerAddr makes addr the primary path for this association (SCTP_PRIMARY_ADDR, RFC 6458 §8.1.9).
The primary is where data goes when every path is usable; the others carry retransmissions and take over on failure. Choosing it is the point of multi-homing, and until now only the getter existed, so an application could see which path was primary but not say which one should be. addr must be one the peer announced — GetPeerAddrs lists them — and the kernel rejects anything else with EINVAL.
addr must name exactly one address, and this returns EINVAL otherwise. The option carries a single sockaddr, so a multi-address SCTPAddr used to be accepted and silently applied to whichever address marshalled first: measured on a two-homed association, passing the peer's full address returned nil and moved the primary to a path the caller had not asked for. That shape is easy to reach by accident, since RemoteAddr and SCTPRemoteAddr both return one *SCTPAddr carrying every address the peer has.
func (*SCTPConn) SetProbeInterval ¶
func (c *SCTPConn) SetProbeInterval(p *ProbeInterval) error
SetProbeInterval sets the PLPMTUD probe interval (SCTP_PLPMTUD_PROBE_INTERVAL).
func (*SCTPConn) SetReadBuffer ¶
func (*SCTPConn) SetReadDeadline ¶
SetReadDeadline sets the absolute time after which reads fail.
A read that exceeds the deadline returns an error satisfying errors.Is(err, os.ErrDeadlineExceeded). The deadline applies to each read as a whole: ReadMsg, which may need several recvmsg calls to reassemble a message, is bounded by the deadline overall rather than per call.
The deadline applies to pending and future reads and can be moved or cleared while another goroutine is blocked in Read.
func (*SCTPConn) SetReconfigSupported ¶
SetReconfigSupported enables or disables the stream reconfiguration extension of RFC 6525 for this socket.
The option is Linux's own. RFC 6525 defines the extension and its four socket options in §6.3, but nothing that negotiates whether the extension is offered at all — SCTP_RECONFIG_SUPPORTED appears nowhere in it.
Set it before connecting. It is carried in a struct sctp_assoc_value rather than a plain int, as SetPrSupported is.
func (*SCTPConn) SetRecvNxtInfo ¶
SetRecvNxtInfo enables or disables delivery of SCTP_NXTINFO, which describes the message following the one being read (RFC 6458 §8.1.30).
Read the result with SCTPReadNextInfo. SCTPRead and SCTPReadFlags ignore the ancillary data this enables, so enabling it and then reading with those discards it — which is what this package did in both directions until SCTPReadNextInfo existed.
func (*SCTPConn) SetRecvRcvInfo ¶
SetRecvRcvInfo enables or disables delivery of SCTP_RCVINFO as ancillary data on each received message (RFC 6458 §8.1.29).
This is the non-deprecated counterpart of the SCTP_SNDRCV data that SubscribeEvents(SCTP_EVENT_DATA_IO) asks for: RFC 6458 §5.3.2 marks SCTP_SNDRCV deprecated and directs callers to SCTP_SNDINFO and SCTP_RCVINFO. SCTPRead accepts either form and normalizes both to SndRcvInfo. SCTPReadMsg exposes the raw SCTP_RCVINFO control message to callers that need the modern ABI without normalization.
func (*SCTPConn) SetRemoteUDPEncapsPort ¶
SetRemoteUDPEncapsPort sets the UDP port SCTP is encapsulated in for a peer address (SCTP_REMOTE_UDP_ENCAPS_PORT).
func (*SCTPConn) SetReusePort ¶
SetReusePort enables or disables binding several endpoints to one port (RFC 6458 §8.1.27).
RFC 6458 restricts this to one-to-one style sockets, which is the only style this package creates, and says it has to be set before bind.
Linux enforces that strictly: on a socket that is already bound or connected the call fails with EFAULT rather than being ignored, which was measured. A connection returned by DialSCTP or AcceptSCTP is therefore always too late — the option is only useful on a descriptor obtained before bind, for example inside the Control hook of a SocketConfig.
func (*SCTPConn) SetRtoInfo ¶
SetRtoInfo sets the association's retransmission timer parameters (SCTP_RTOINFO). Fields left zero are unchanged.
Reducing Max is half of making an unreachable peer detectable promptly; see SetAssocInfo for the other half.
func (*SCTPConn) SetSackTimer ¶
SetSackTimer configures delayed acknowledgements (RFC 6458 §8.1.19 and RFC 9260 §6.2). Zero fields leave the corresponding value unchanged.
RFC 9260 requires implementations to reject SACK.Delay above 500 ms. It recommends, but does not require, a delay no greater than 200 ms and an acknowledgement for at least every second packet, so larger frequencies and delays through 500 remain available for applications that deliberately need them.
func (*SCTPConn) SetStreamScheduler ¶
SetStreamScheduler selects the order outbound streams are served in (SCTP_STREAM_SCHEDULER, RFC 8260 §4).
sched is one of the SCTPSched constants. The default, SCTPSchedFCFS, ignores streams entirely and sends in the order messages were handed over, so a caller who separates traffic by stream and expects that to affect scheduling gets nothing until this is set.
func (*SCTPConn) SetStreamSchedulerValue ¶
SetStreamSchedulerValue sets a per-stream parameter for the scheduler in force (SCTP_STREAM_SCHEDULER_VALUE).
Two schedulers use it. Under SCTPSchedPrio it is the stream's priority, lowest served first; under SCTPSchedWFQ it is the stream's weight, and a stream weighted n times another gets n times the capacity.
Under SCTPSchedFCFS, SCTPSchedRR and SCTPSchedFC the call still succeeds and the value is discarded — measured: written as 7, it reads back as 0. So a caller who sets a priority without also selecting a scheduler that has one gets no error and no effect, which is why this says which schedulers those are rather than "the others ignore it".
func (*SCTPConn) SetWriteBuffer ¶
func (*SCTPConn) SetWriteDeadline ¶
SetWriteDeadline sets the absolute time after which writes fail, including a write that is already waiting for send-buffer space.
func (*SCTPConn) Setsockopt ¶
func (*SCTPConn) StreamScheduler ¶
StreamScheduler reports the scheduler in force.
func (*SCTPConn) SubscribeEvent ¶
func (c *SCTPConn) SubscribeEvent(eventType SCTPNotificationType, on bool) error
SubscribeEvent subscribes to a single notification type, or unsubscribes from it when on is false.
This is the SCTP_EVENT option from RFC 6458 §6.2.2, which exists because SCTP_EVENTS — what SubscribeEvents uses — is deprecated: its struct has to grow every time an event is added, so a binary built against an older definition silently cannot reach the newer events. Naming one event per call has no such limit.
eventType is a notification type such as SCTP_ASSOC_CHANGE. The kernel validates it and reports EINVAL for a type it does not know.
The two options do not read the same state once an association exists, which was measured rather than assumed. On a socket with no association, an event set here reads back as set in the struct SubscribeEvents sends. On a connected socket it does not: AssocID 0 acts on that association, while SCTP_EVENTS reads the endpoint defaults, so the subscription shows as on through EventSubscribed and off through SCTP_EVENTS. Do not mix the two on a connected socket and expect either to report what the other set. Set whichever you use before connecting if you need one consistent view.
func (*SCTPConn) SubscribeEvents ¶
func (*SCTPConn) SubscribedEvents ¶
type SCTPEndpoint ¶
type SCTPEndpoint struct {
// contains filtered or unexported fields
}
SCTPEndpoint is a Linux SCTP one-to-many style socket (RFC 6458 §3.1). One package-owned SOCK_SEQPACKET descriptor carries any number of associations, each identified by the SCTPAssocID in its send and receive metadata.
SCTPEndpoint deliberately does not implement net.Conn or net.Listener. It has message boundaries rather than stream reads, no single remote address, and associations arrive through Receive rather than Accept. Send requires a kernel-assigned association id and Receive returns RFC 6458 §5.3.5 RcvInfo; this prevents a zero-valued default from silently selecting the wrong peer.
Methods may be called concurrently. All Receive calls consume the same endpoint queue, so applications that reassemble a message across calls must use one receiving goroutine or dispatch complete fragments before allowing another reader. Readiness and write deadlines are endpoint-wide, not association-specific (RFC 6458 §3.2); use PeelOff before an association with independent backpressure or readiness requirements carries high-volume traffic.
The package owns the descriptor from construction until Close or Abort. PeelOff returns a second package-owned descriptor and transfers that association completely away from this endpoint as required by RFC 6458 §§3.1 and 9.2. Closing the endpoint does not close a peeled association.
func ListenSCTPEndpoint ¶
func ListenSCTPEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
ListenSCTPEndpoint creates a listening one-to-many endpoint.
RFC 6458 §3.1.3 specifies that associations are accepted automatically: there is no Accept call. Receive reports SCTP_ASSOC_CHANGE notifications and per-message association metadata. The endpoint can also initiate outbound associations with Connect.
func OpenSCTPEndpoint ¶
func OpenSCTPEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
OpenSCTPEndpoint creates an active-only one-to-many endpoint.
It is not put into the listening state, so peers cannot create inbound associations. Call Connect one or more times to initiate associations. The descriptor is owned by the returned endpoint; callers never need to wrap a borrowed descriptor with NewSCTPConn.
func (*SCTPEndpoint) Abort ¶
func (ep *SCTPEndpoint) Abort() error
Abort immediately terminates every association still owned by the endpoint and releases its descriptor. Peeled associations are independent.
func (*SCTPEndpoint) AbortAssociation ¶
func (ep *SCTPEndpoint) AbortAssociation(id SCTPAssocID, cause []byte) error
AbortAssociation terminates one association immediately and optionally carries cause as the user-specified ABORT data from RFC 6458 §3.1.5. Every other association and the endpoint descriptor remain open.
func (*SCTPEndpoint) Addr ¶
func (ep *SCTPEndpoint) Addr() net.Addr
Addr returns a copy of the endpoint's bound local address set.
func (*SCTPEndpoint) AssociationCount ¶
func (ep *SCTPEndpoint) AssociationCount() (uint32, error)
AssociationCount returns a snapshot of the associations currently attached to the endpoint (RFC 6458 §8.2.5). The count may change immediately after this call returns and must not be used as an authority for later routing.
func (*SCTPEndpoint) AssociationIDs ¶
func (ep *SCTPEndpoint) AssociationIDs() ([]SCTPAssocID, error)
AssociationIDs returns a validated snapshot of the association identifiers currently attached to the endpoint (RFC 6458 §8.2.6).
The list can become stale immediately after return. This method grows a small package-owned buffer to a fixed limit rather than allocating from the SCTP_GET_ASSOC_NUMBER snapshot; a hostile or inconsistent kernel count can therefore never cause an unbounded allocation.
func (*SCTPEndpoint) BindAdd ¶
func (ep *SCTPEndpoint) BindAdd(addr *SCTPAddr) error
BindAdd atomically adds addr to the endpoint's local address set (RFC 6458 §9.1). The endpoint cache is refreshed from the kernel after a successful operation. See SCTPConn.BindAdd for port handling and the RFC 5061 ASCONF negotiation caveat on established associations.
func (*SCTPEndpoint) BindRemove ¶
func (ep *SCTPEndpoint) BindRemove(addr *SCTPAddr) error
BindRemove atomically removes addr from the endpoint's local address set (RFC 6458 §9.1). It rejects removal of the last local address. See SCTPConn.BindRemove for port handling and established-association semantics.
func (*SCTPEndpoint) Close ¶
func (ep *SCTPEndpoint) Close() error
Close gracefully shuts down every association still owned by the endpoint and releases its descriptor (RFC 6458 §3.1.5). It waits up to three seconds for the handshakes and then aborts any associations whose peers did not respond. Peeled associations are independent and remain open.
func (*SCTPEndpoint) CloseAssociation ¶
func (ep *SCTPEndpoint) CloseAssociation(id SCTPAssocID) error
CloseAssociation gracefully shuts down one association while leaving every other association and the endpoint descriptor open (RFC 6458 §3.1.5). Completion is reported by SCTP_ASSOC_CHANGE with SCTP_SHUTDOWN_COMP.
func (*SCTPEndpoint) Connect ¶
func (ep *SCTPEndpoint) Connect(raddr *SCTPAddr) (SCTPAssocID, error)
Connect initiates one association and returns its endpoint-local id.
The endpoint descriptor is non-blocking. A nil error therefore means the association was either established immediately or was successfully started; completion is reported by the automatically enabled SCTP_ASSOC_CHANGE event as SCTP_COMM_UP or SCTP_CANT_STR_ASSOC (RFC 6458 §3.2 and Verified Erratum 6112). Connect never translates EALREADY or EISCONN into success, because in those cases Linux does not return an association id and reporting id 0 would alias SCTP_FUTURE_ASSOC.
Multiple calls may create associations with different peers on the same endpoint. The returned id is valid only on this endpoint; the peer assigns a different local id to the same association.
func (*SCTPEndpoint) GetAutoClose ¶
func (ep *SCTPEndpoint) GetAutoClose() (uint32, error)
GetAutoClose returns the endpoint's SCTP_AUTOCLOSE idle timeout in seconds (RFC 6458 §8.1.8). Zero means automatic close is disabled.
func (*SCTPEndpoint) LocalAddrs ¶
func (ep *SCTPEndpoint) LocalAddrs(id SCTPAssocID) (*SCTPAddr, error)
LocalAddrs returns a package-owned copy of association id's local address set (RFC 6458 §9.5). Scope selectors are rejected: this method always describes one live association rather than endpoint defaults.
func (*SCTPEndpoint) Network ¶
func (ep *SCTPEndpoint) Network() string
Network returns the canonical network used to create the endpoint: "sctp", "sctp4", or "sctp6". It returns the empty string for a nil endpoint.
func (*SCTPEndpoint) PeelOff ¶
func (ep *SCTPEndpoint) PeelOff(id SCTPAssocID) (*SCTPConn, error)
PeelOff transfers one association to a new package-owned SCTPConn (RFC 6458 §9.2). The id must identify a real association on this endpoint; scope selectors are rejected. After success every operation for that association, including queued data and close, belongs to the returned connection.
func (*SCTPEndpoint) PeerAddrs ¶
func (ep *SCTPEndpoint) PeerAddrs(id SCTPAssocID) (*SCTPAddr, error)
PeerAddrs returns a package-owned copy of association id's peer address set (RFC 6458 §9.3). Scope selectors are rejected.
func (*SCTPEndpoint) Receive ¶
Receive performs one recvmsg on the shared endpoint queue.
Application data is returned with RFC 6458 §5.3.5 RcvInfo, including the endpoint-local AssocID, stream and host-order PPID. flags contains MSG_EOR; its absence means b held only a fragment and later Receive calls continue the same message. Receive never silently discards that distinction.
With no NotificationHandler, notifications are returned as bytes with MSG_NOTIFICATION and nil RcvInfo. With a handler, they are delivered to it as one complete record even when b is smaller than the notification, and Receive continues to the next application message. The callback runs outside the descriptor's poller lock and may re-enter endpoint operations; its byte slice is valid only for the duration of the call.
func (*SCTPEndpoint) Send ¶
Send transmits one complete message to info.AssocID using the modern SCTP_SNDINFO ancillary item (RFC 6458 §5.3.4).
info is required and its AssocID must be a kernel-assigned id returned by Connect, Receive, or SCTP_ASSOC_CHANGE. The reserved FUTURE, CURRENT, and ALL selectors are rejected so a zero-valued SndInfo cannot silently route data. PPID is in host byte order at this API boundary. pr and auth have the same per-message meaning as SCTPConn.SCTPWriteInfo.
Without a write deadline Send is non-blocking and can return EAGAIN. With a deadline it waits through endpoint-wide readiness; RFC 6458 §3.2 warns that writable readiness may belong to another association. Peel off an association that needs independent readiness or sustained backpressure.
func (*SCTPEndpoint) SetAutoClose ¶
func (ep *SCTPEndpoint) SetAutoClose(seconds uint32) error
SetAutoClose sets the number of idle seconds after which the kernel gracefully closes an association on this one-to-many endpoint (RFC 6458 §8.1.8). Zero disables automatic close. Linux may clamp values to the current net.sctp.max_autoclose limit; call GetAutoClose to read it back. After an automatic close, Linux may reuse that association id. Applications must retire ids when SCTPEndpoint's automatically enabled SCTP_ASSOC_CHANGE notification reports termination rather than treating a previously observed id as a durable peer identity.
func (*SCTPEndpoint) SetDeadline ¶
func (ep *SCTPEndpoint) SetDeadline(t time.Time) error
SetDeadline sets both endpoint-wide receive and send deadlines.
func (*SCTPEndpoint) SetReadDeadline ¶
func (ep *SCTPEndpoint) SetReadDeadline(t time.Time) error
SetReadDeadline sets the deadline for pending and future Receive calls.
func (*SCTPEndpoint) SetWriteDeadline ¶
func (ep *SCTPEndpoint) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the deadline used by Send.
func (*SCTPEndpoint) SyscallConn ¶
func (ep *SCTPEndpoint) SyscallConn() (syscall.RawConn, error)
SyscallConn returns controlled access to the endpoint descriptor.
The descriptor remains package-owned and is valid only for the duration of each RawConn callback. A callback must not close it, wrap it in os.File or net.Conn, or retain the numeric value after returning. This is the same ownership and lifetime contract as net.Conn.SyscallConn.
type SCTPListener ¶
type SCTPListener struct {
// contains filtered or unexported fields
}
func FileListener ¶
func FileListener(file *os.File) (*SCTPListener, error)
FileListener takes a file, dup's the underlying file descriptor, and returns a SCTPListener created from the dup'd fd.
func ListenSCTP ¶
func ListenSCTP(net string, laddr *SCTPAddr) (*SCTPListener, error)
ListenSCTP - start listener on specified address/port
func ListenSCTPExt ¶
func ListenSCTPExt(network string, laddr *SCTPAddr, options InitMsg) (*SCTPListener, error)
ListenSCTPExt - start listener on specified address/port with given SCTP options
func (*SCTPListener) Accept ¶
func (ln *SCTPListener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*SCTPListener) AcceptSCTP ¶
func (ln *SCTPListener) AcceptSCTP() (*SCTPConn, error)
AcceptSCTP waits for and returns the next SCTP connection to the listener.
func (*SCTPListener) Addr ¶
func (ln *SCTPListener) Addr() net.Addr
func (*SCTPListener) BindAdd ¶
func (ln *SCTPListener) BindAdd(addr *SCTPAddr) error
BindAdd atomically adds addr to the listener's local address set (sctp_bindx with SCTP_BINDX_ADD_ADDR, RFC 6458 §9.1). Associations accepted after it succeeds inherit the enlarged set.
A zero port is replaced with the listener's bound port. A non-zero port must equal that port. The caller's SCTPAddr is never modified, and Addr is refreshed from the kernel after success. This changes the listening endpoint itself; RFC 5061 applies only if established associations are also updated. RFC 6458 Erratum 4921 remains Held for Document Update, so address-family acceptance follows the socket and kernel rather than treating it as a normative correction.
func (*SCTPListener) BindRemove ¶
func (ln *SCTPListener) BindRemove(addr *SCTPAddr) error
BindRemove atomically removes addr from the listener's local address set (sctp_bindx with SCTP_BINDX_REM_ADDR, RFC 6458 §9.1). Associations accepted after it succeeds no longer inherit those addresses. The port, ownership, cache, RFC 5061, and Held Erratum 4921 rules are the same as for BindAdd. Removing every address is forbidden and is rejected with EINVAL.
func (*SCTPListener) Close ¶
func (ln *SCTPListener) Close() error
Close releases the listening socket.
The descriptor is swapped out atomically, so concurrent or repeated calls report EBADF rather than closing the number a second time. That matters because the kernel reuses descriptor numbers: without it, a second Close could release a socket that had since been opened elsewhere in the process.
func (*SCTPListener) SetDeadline ¶
func (ln *SCTPListener) SetDeadline(t time.Time) error
SetDeadline sets the absolute time after which Accept fails.
An Accept that exceeds the deadline returns an error satisfying errors.Is(err, os.ErrDeadlineExceeded). A zero time.Time clears it, as with net.Conn. This mirrors net.TCPListener.SetDeadline, which net.Listener itself does not require.
The deadline applies to pending and future Accept calls and can be moved or cleared while another goroutine is blocked in Accept.
func (*SCTPListener) SyscallConn ¶
func (ln *SCTPListener) SyscallConn() (syscall.RawConn, error)
type SCTPNotificationType ¶
type SCTPNotificationType int
type SCTPSndRcvInfoWrappedConn ¶
type SCTPSndRcvInfoWrappedConn struct {
// contains filtered or unexported fields
}
func NewSCTPSndRcvInfoWrappedConn ¶
func NewSCTPSndRcvInfoWrappedConn(conn *SCTPConn) *SCTPSndRcvInfoWrappedConn
NewSCTPSndRcvInfoWrappedConn wraps conn so that Read and Write carry a SndRcvInfo header inline, ahead of the payload.
The inline header is a process-local Go representation in native byte order; PPID follows this package's public host-order convention. It is not a wire encoding and must not be persisted or exchanged between unlike architectures.
The whole type depends on SCTP_EVENT_DATA_IO being subscribed, since that is what makes the kernel return the ancillary data the header is built from. The subscription used to be attempted and its error discarded, which fails quietly in the worst way: every Read then finds no ancillary data and writes a zeroed header, so the caller reads a well-formed SndRcvInfo reporting stream 0 and PPID 0 for every message regardless of which stream it arrived on.
This signature cannot return an error without breaking callers, so the failure is kept and returned from the first Read or Write instead.
func (*SCTPSndRcvInfoWrappedConn) Close ¶
func (c *SCTPSndRcvInfoWrappedConn) Close() error
func (*SCTPSndRcvInfoWrappedConn) GetReadBuffer ¶
func (c *SCTPSndRcvInfoWrappedConn) GetReadBuffer() (int, error)
func (*SCTPSndRcvInfoWrappedConn) GetWriteBuffer ¶
func (c *SCTPSndRcvInfoWrappedConn) GetWriteBuffer() (int, error)
func (*SCTPSndRcvInfoWrappedConn) LocalAddr ¶
func (c *SCTPSndRcvInfoWrappedConn) LocalAddr() net.Addr
func (*SCTPSndRcvInfoWrappedConn) Read ¶
func (c *SCTPSndRcvInfoWrappedConn) Read(b []byte) (int, error)
func (*SCTPSndRcvInfoWrappedConn) RemoteAddr ¶
func (c *SCTPSndRcvInfoWrappedConn) RemoteAddr() net.Addr
func (*SCTPSndRcvInfoWrappedConn) SetDeadline ¶
func (c *SCTPSndRcvInfoWrappedConn) SetDeadline(t time.Time) error
func (*SCTPSndRcvInfoWrappedConn) SetReadBuffer ¶
func (c *SCTPSndRcvInfoWrappedConn) SetReadBuffer(bytes int) error
func (*SCTPSndRcvInfoWrappedConn) SetReadDeadline ¶
func (c *SCTPSndRcvInfoWrappedConn) SetReadDeadline(t time.Time) error
func (*SCTPSndRcvInfoWrappedConn) SetWriteBuffer ¶
func (c *SCTPSndRcvInfoWrappedConn) SetWriteBuffer(bytes int) error
func (*SCTPSndRcvInfoWrappedConn) SetWriteDeadline ¶
func (c *SCTPSndRcvInfoWrappedConn) SetWriteDeadline(t time.Time) error
type SackTimer ¶
type SackTimer struct {
// AssocID is ignored on the one-to-one style sockets this package creates.
AssocID SCTPAssocID
// SackDelay is the delayed acknowledgement timer in milliseconds. Zero
// leaves the current value in place.
SackDelay uint32
// SackFrequency is the number of packets that must arrive before an
// acknowledgement is sent without waiting for SackDelay. Zero leaves the
// current value in place; 1 disables delayed acknowledgement entirely.
SackFrequency uint32
}
SackTimer mirrors struct sctp_sack_info (RFC 6458 §8.1.19), the delayed acknowledgement timer and the number of packets that force an acknowledgement without waiting for it.
A zero field means "leave this one alone", not "set it to zero". RFC 6458 §8.1.19 says so and Linux agrees, which makes this struct unlike most of the package: the two fields cannot be set independently to a known state, because there is no way to spell "no delay". Measured on 6.12, from a default of 200/2:
set 137/5 -> 137/5 both taken set 0/9 -> 137/9 SackDelay ignored, previous value kept set 211/0 -> 211/9 SackFrequency ignored, previous value kept set 0/0 -> 211/9 accepted, and a complete no-op
SackFrequency == 1 disables the delayed acknowledgement algorithm. That case does not follow the rule above: setting 0/1 leaves SackDelay reading back as 0 rather than unchanged, because disabling the algorithm clears the timer.
SackDelay is policed. RFC 9260 §6.2 wants at most 500 ms; the kernel rejects a value it considers out of range with EINVAL — 100000 was refused — so an absurd delay fails at the call rather than being silently clamped.
type SendFailed ¶
type SendFailed struct {
Error uint32
// Info is the send parameters the failed message carried.
//
// Info.PPID is converted to host byte order, matching SCTPRead and the send
// APIs. RFC 6458 §5.3.2 defines only the network-order kernel ABI.
Info SndRcvInfo
AssocID SCTPAssocID
// Data is the message that was not delivered.
Data []byte
// contains filtered or unexported fields
}
SendFailed is SCTP_SEND_FAILED (RFC 6458 6.1.4), reporting a message that could not be delivered. The undelivered message is returned in Data.
func (*SendFailed) Flags ¶
func (n *SendFailed) Flags() uint16
func (*SendFailed) Length ¶
func (n *SendFailed) Length() uint32
func (*SendFailed) Type ¶
func (n *SendFailed) Type() SCTPNotificationType
type SendFailedEvent ¶
type SendFailedEvent struct {
// Error is an RFC 9260 section 3.3.10 error cause; see ErrorCauseString.
Error uint32
// Info is the send parameters the failed message carried. Info.PPID is
// converted to host byte order, matching every other public PPID value.
Info SndInfo
AssocID SCTPAssocID
// Data is the message that was not delivered.
Data []byte
// contains filtered or unexported fields
}
SendFailedEvent is SCTP_SEND_FAILED_EVENT (RFC 6458 §6.1.11), the replacement for SCTP_SEND_FAILED.
It carries SndInfo where the older event carries the deprecated SndRcvInfo, and it is the one RFC 6458 §6.1.4 tells new code to subscribe to. Both describe the same failure, so a socket subscribed to both sees it twice.
func (*SendFailedEvent) Flags ¶
func (n *SendFailedEvent) Flags() uint16
func (*SendFailedEvent) Length ¶
func (n *SendFailedEvent) Length() uint32
func (*SendFailedEvent) Type ¶
func (n *SendFailedEvent) Type() SCTPNotificationType
type SenderDry ¶
type SenderDry struct {
AssocID SCTPAssocID
// contains filtered or unexported fields
}
SenderDry is SCTP_SENDER_DRY_EVENT (RFC 6458 6.1.9), reporting that the stack has no more user data to send and none outstanding. It is the authoritative signal that everything written has been acknowledged.
func (*SenderDry) Type ¶
func (n *SenderDry) Type() SCTPNotificationType
type Shutdown ¶
type Shutdown struct {
AssocID SCTPAssocID
// contains filtered or unexported fields
}
Shutdown is SCTP_SHUTDOWN_EVENT (RFC 6458 6.1.5), reporting that the peer has shut the association down and will accept no further data.
func (*Shutdown) Type ¶
func (n *Shutdown) Type() SCTPNotificationType
type SndInfo ¶
type SndInfo struct {
// SID is the stream to send on.
SID uint16
// Flags carries SCTP_UNORDERED and friends.
Flags uint16
// PPID is expressed in host byte order. RFC 6458 §5.3.4 labels the
// ancillary field network byte order and says the SCTP stack does not modify
// it; this package converts at the kernel boundary and back in notifications.
PPID uint32
// Context is returned with a send failure notification, letting a caller
// identify which message failed.
Context uint32
AssocID int32
}
SndInfo mirrors struct sctp_sndinfo (RFC 6458 §5.3.4). It is the non-deprecated replacement for the send-side half of SndRcvInfo, and is what SCTP_DEFAULT_SNDINFO carries.
Five fields where SndRcvInfo has ten: the deprecated struct doubled as the receive-side descriptor, and those fields have moved to RcvInfo.
type SndRcvInfo ¶
type SndRcvInfo struct {
Stream uint16
SSN uint16
Flags uint16
// PPID is expressed in host byte order. RFC 6458 §5.3.2 labels the ancillary
// field network byte order and says the SCTP stack performs no byte-order
// modification. This package applies htonl/ntohl at the kernel boundary so
// every public PPID uses one host-order convention.
PPID uint32
Context uint32
TTL uint32
TSN uint32
CumTSN uint32
AssocID int32
// contains filtered or unexported fields
}
type SocketConfig ¶
type SocketConfig struct {
// If Control is not nil it is called after the socket is created but before
// it is bound or connected. Dial and DialContext pass the remote address;
// Listen passes the local address. The RawConn is Control-only at this stage:
// Read and Write return EINVAL. The callback must not retain the numeric file
// descriptor after it returns.
Control func(network, address string, c syscall.RawConn) error
// NotificationHandler consumes notifications before SCTPReadFlags or ReadMsg
// returns. Leave it nil to receive notification bytes and MSG_NOTIFICATION
// through SCTPReadFlags, or use SCTPReadMsg for an always-raw receive.
NotificationHandler NotificationHandler
// InitMsg configures the association parameters announced in INIT.
InitMsg InitMsg
}
SocketConfig contains options for the SCTP socket.
func (*SocketConfig) Dial ¶
func (cfg *SocketConfig) Dial(net string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
func (*SocketConfig) DialContext ¶
func (cfg *SocketConfig) DialContext(ctx context.Context, net string, laddr, raddr *SCTPAddr) (*SCTPConn, error)
DialContext is Dial with a context; see DialSCTPContext for what the context bounds and why Dial cannot offer it. A nil context is rejected with an error wrapping syscall.EINVAL.
func (*SocketConfig) Listen ¶
func (cfg *SocketConfig) Listen(net string, laddr *SCTPAddr) (*SCTPListener, error)
func (*SocketConfig) ListenEndpoint ¶
func (cfg *SocketConfig) ListenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
ListenEndpoint is ListenSCTPEndpoint with this SocketConfig applied before bind and listen. Association-change notifications and SCTP_RCVINFO are enabled after Control returns because they are mandatory to this API's routing contract and cannot be disabled by configuration.
func (*SocketConfig) OpenEndpoint ¶
func (cfg *SocketConfig) OpenEndpoint(network string, laddr *SCTPAddr) (*SCTPEndpoint, error)
OpenEndpoint is OpenSCTPEndpoint with this SocketConfig applied before bind. Control receives a borrowed, Control-only descriptor exactly as it does for Dial and Listen; it must not retain or transfer ownership of that descriptor.
func (*SocketConfig) WithPreAssociation ¶
func (cfg *SocketConfig) WithPreAssociation(pre PreAssociationConfig) *PreconfiguredSocket
WithPreAssociation snapshots cfg and pre for a later Listen, Dial, DialContext, OpenEndpoint, or ListenEndpoint call. A nil cfg snapshots the zero SocketConfig. Slice and pointer fields are copied, so later caller mutation cannot race with socket construction or change the applied plan.
type SocketOptionState ¶
type SocketOptionState uint8
SocketOptionState controls an optional boolean socket setting without making the zero value mean "disabled". SocketOptionDefault leaves the setting alone, so a zero-valued PreAssociationConfig preserves the kernel default.
const ( // SocketOptionDefault leaves the socket option unchanged. SocketOptionDefault SocketOptionState = iota // SocketOptionEnable writes an enabled value to the socket option. SocketOptionEnable // SocketOptionDisable writes a disabled value to the socket option. SocketOptionDisable )
func (SocketOptionState) String ¶
func (state SocketOptionState) String() string
String returns the configuration name used in validation errors.
type Status ¶
type Status struct {
AssocID SCTPAssocID
State StatusState
RWND uint32
Unackdata uint16
Penddata uint16
Instreams uint16
Ostreams uint16
FragmentationPoint uint32
PrimaryPeerAddr PeerAddrinfo
}
Status Parameters defined in RFC 6458 8.2.1 - Association Status (SCTP_STATUS)
type StatusState ¶
type StatusState int32
const ( SCTP_EMPTY StatusState = iota SCTP_CLOSED SCTP_COOKIE_WAIT SCTP_COOKIE_ECHOED SCTP_ESTABLISHED SCTP_SHUTDOWN_PENDING SCTP_SHUTDOWN_SENT SCTP_SHUTDOWN_RECEIVED SCTP_SHUTDOWN_ACK_SENT )
Association states, from enum sctp_sstat_state in the kernel's uapi linux/sctp.h, as reported by GetStatus.
The enum begins at SCTP_EMPTY rather than SCTP_CLOSED, and has no SCTP_BOUND or SCTP_LISTEN members. Numbering from SCTP_CLOSED = 0 shifts every state by one, so an established association compares equal to SCTP_COOKIE_ECHOED.
type StreamChange ¶
type StreamChange struct {
AssocID SCTPAssocID
// InboundStreams is the number of inbound streams the request added. It is
// 0 on the requesting side, since granting inbound streams is the peer's
// half of the exchange.
InboundStreams uint16
// OutboundStreams is the number of outbound streams the request added, and
// zero if none were. It is not the width of the association: use GetStatus
// for that.
OutboundStreams uint16
// contains filtered or unexported fields
}
StreamChange is SCTP_STREAM_CHANGE_EVENT (RFC 6525 §6.1.3), reporting the outcome of an AddStreams request.
The counts are the streams the request added, not the totals the association ended up with. RFC 6525 §6.1.3 says the opposite — strchange_outstrms is "the number of streams that the endpoint is allowed to use outbound" — but Linux passes the request's own stream count into the event and never the new width. Measured on 6.12: from an association with 5 outbound streams, AddStreams(0, 3) produced OutboundStreams == 3, while SCTP_STATUS reported 8 and a send on stream 7 was accepted.
So this event answers "did it work", and GetStatus answers "how wide is the association now". Check Flags before believing either: on a denied request — forced by clearing SCTPEnableChangeAssocReq on the peer — the counts are reported unchanged, with only SCTP_STREAM_CHANGE_DENIED to say the streams were never granted.
func (*StreamChange) Flags ¶
func (n *StreamChange) Flags() uint16
func (*StreamChange) Length ¶
func (n *StreamChange) Length() uint32
func (*StreamChange) Type ¶
func (n *StreamChange) Type() SCTPNotificationType
type StreamReset ¶
type StreamReset struct {
AssocID SCTPAssocID
// Streams are the stream identifiers the event covers. Empty means all of
// them, which is how the kernel reports a request made with no list.
//
// The list ends where the event's declared length ends, not where the read
// buffer does. That distinction decides the meaning rather than a detail of
// it: bounding by the buffer invents one identifier per two spare bytes, so
// an event covering every stream arrives naming a handful of specific ones.
Streams []uint16
// contains filtered or unexported fields
}
StreamReset is SCTP_STREAM_RESET_EVENT (RFC 6525 §6.1.1), reporting the outcome of a stream reset — this side's or the peer's.
This is the answer to ResetStreams, which only reports that the request was sent. Check Flags for SCTP_STREAM_RESET_DENIED and SCTP_STREAM_RESET_FAILED.
func (*StreamReset) Flags ¶
func (n *StreamReset) Flags() uint16
func (*StreamReset) Length ¶
func (n *StreamReset) Length() uint32
func (*StreamReset) Type ¶
func (n *StreamReset) Type() SCTPNotificationType
type UDPEncaps ¶
type UDPEncaps struct {
AssocID SCTPAssocID
// Address selects the peer address. RFC 6951 §6.1 specifies that a
// wildcard applies only to future paths. Linux deliberately extends that
// request in sctp_setsockopt_encap_port by updating every current transport
// as well as the association default, so a zero value affects current and
// future paths on this package's socket-backed implementation.
Address [128]byte
// Port is the peer's UDP port in host byte order at the Go API boundary.
// RFC 6951 §6.1 requires sue_port in network byte order; marshal and
// unmarshal perform that conversion. Zero disables encapsulation.
Port uint16
}
UDPEncaps mirrors struct sctp_udpencaps (RFC 6951 §6.1), naming the UDP port to encapsulate SCTP in when talking to one peer address.
This is what lets an association traverse a middlebox that drops IP protocol 132 outright, which is most consumer NAT. It needs net.sctp.udp_port set for the local side to receive; this option is the remote half.