SCTP(4)
π sctp(4) β Internet Stream Control Transmission Protocol π
Kernel Interfaces Manual π
π NAME π
sctp β Internet Stream Control Transmission Protocol β¨
π SYNOPSIS π
okay bestie, hereβs the exact summoning ritual:
options SCTP
options SCTP_SUPPORT
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>
int
socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
int
socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
πΈ DESCRIPTION πΈ
The SCTP protocol provides reliable, flow-controlled, two-way transmission of data. It is a message oriented protocol and can support the SOCK_STREAM and SOCK_SEQPACKET abstractions. SCTP uses the standard Internet address format and, in addition, provides a per-host collection of βport addressesβ. Thus, each address is composed of an Internet address specifying the host and network, with a specific SCTP port on the host identifying the peer entity π
There are two models of programming in SCTP. The first uses the SOCK_STREAM abstraction. In this abstraction sockets utilizing the SCTP protocol are either βactiveβ or βpassiveβ. Active sockets initiate connections to passive sockets. By default, SCTP sockets are created active; to create a passive socket, the listen(2) system call must be used after binding the socket with the bind(2) or sctp_bindx(3) system calls. Only passive sockets may use the accept(2) call to accept incoming connections. Only active sockets may use the connect(2) call to initiate connections π«Ά
The other abstraction SOCK_SEQPACKET provides a βconnectionlessβ mode of operation in that the user may send to an address (using any of the valid send calls that carry a socket address) and an association will be setup implicitly by the underlying SCTP transport stack. This abstraction is the only one capable of sending data on the third leg of the four-way handshake. A user must still call listen(2) to allow the socket to accept connections. Calling listen(2) however does not restrict the user from still initiating implicit connections to other peers β¨
The SCTP protocol directly supports multi-homing. So when binding a socket with the βwildcardβ address INADDR_ANY, the SCTP stack will inform the peer about all of the local addresses that are deemed in scope of the peer. The peer will then possibly have multiple paths to reach the local host π¦
The SCTP transport protocol is also multi-streamed. Multi-streaming refers to the ability to send sub-ordered flows of messages. A user performs this by specifying a specific stream in one of the extended send calls such as the sctp_send(3) function call. Sending messages on different streams will allow parallel delivery of data i.e., a message loss in stream 1 will not block the delivery of messages sent in stream 2 π
The SCTP transport protocol also provides a unordered service as well. The unordered service allows a message to be sent and delivered with no regard to the ordering of any other message π
The SCTP kernel implementation may either be compiled into the kernel, or loaded dynamically as a module. To support dynamic loading of the stack, the kernel must be compiled with options SCTP_SUPPORT π
π¦ Extensions π¦
The FreeBSD implementation of SCTP also supports the following extensions:
- sctp partial reliability β this extension allows one to have message be skipped and not delivered based on some user specified parameters.
- sctp dynamic addressing β this extension allows addresses to be added and deleted dynamically from an existing association.
- sctp authentication β this extension allows the user to authenticate specific peer chunks (including data) to validate that the peer who sent the message is in fact the peer who setup the association. A shared key option is also provided for so that two stacks can pre-share keys.
- packet drop β some routers support a special satellite protocol that will report losses due to corruption. This allows retransmissions without subsequent loss in bandwidth utilization.
- stream reset β this extension allows a user on either side to reset the stream sequence numbers used by any or all streams.
π Socket Options π
SCTP supports a number of socket options which can be set with setsockopt(2) and tested with getsockopt(2) or sctp_opt_info(3):
SCTP_NODELAYβ under most circumstances, SCTP sends data when it is presented; when outstanding data has not yet been acknowledged, it gathers small amounts of output to be sent in a single packet once an acknowledgement is received. For some clients, such as window systems that send a stream of mouse events which receive no replies, this packetization may cause significant delays. The boolean optionSCTP_NODELAYdefeats this algorithm.SCTP_RTOINFOβ this option returns specific information about an associations βRetransmission Time Outβ. It can also be used to change the default values.SCTP_ASSOCINFOβ this option returns specific information about the requested association.SCTP_INITMSGβ this option allows you to get or set the default sending parameters when an association is implicitly setup. It allows you to change such things as the maximum number of streams allowed inbound and the number of streams requested of the peer.SCTP_AUTOCLOSEβ for the one-to-many model (SOCK_SEQPACKET) associations are setup implicitly. This option allows the user to specify a default number of idle seconds to allow the association be maintained. After the idle timer (where no user message have been sent or have been received from the peer) the association will be gracefully closed. The default for this value is 0, or unlimited (i.e., no automatic close).SCTP_SET_PEER_PRIMARY_ADDRβ the dynamic address extension allows a peer to also request a particular address of its be made into the primary address. This option allows the caller to make such a request to a peer. Note that if the peer does not also support the dynamic address extension, this call will fail. Note the caller must provide a valid local address that the peer has been told about during association setup or dynamically.SCTP_PRIMARY_ADDRβ this option allows the setting of the primary address that the caller wishes to send to. The caller provides the address of a peer that is to be made primary.SCTP_ADAPTATION_LAYERβ the dynamic address extension also allows a user to pass a 32 bit opaque value upon association setup. This option allows a user to set or get this value.SCTP_DISABLE_FRAGMENTSβ by default SCTP will fragment user messages into multiple pieces that will fit on the network and then later, upon reception, reassemble the pieces into a single user message. If this option is enabled instead, any send that exceeds the path maximum transfer unit (P-MTU) will fail and the message will NOT be sent.SCTP_PEER_ADDR_PARAMSβ this option will allow a user to set or get specific peer address parameters.SCTP_DEFAULT_SEND_PARAMβ when a user does not use one of the extended send calls (e.g.,sctp_sendmsg(3)) a set of default values apply to each send. These values include things like the stream number to send to as well as the per-protocol id. This option lets a caller both get and set these values. If the user changes these default values, then these new values will be used as the default whenever no information is provided by the sender (i.e., the non-extended API is used).SCTP_EVENTSβ SCTP has non-data events that it can communicate to its application. By default these are all disabled since they arrive in the data path with a special flagMSG_NOTIFICATIONset upon the received message. This option lets a caller both get what events are current being received as well as set different events that they may be interested in receiving.SCTP_I_WANT_MAPPED_V4_ADDRβ SCTP supports bothIPV4andIPV6. An association may span bothIPV4andIPV6addresses since SCTP is multi-homed. By default, when opening anIPV6socket, when data arrives on the socket from a peerβs V4 address the V4 address will be presented with an address family ofAF_INET. If this is undesirable, then this option can be enabled which will then convert all V4 addresses into mapped V6 representations.SCTP_MAXSEGβ by default SCTP chooses its message fragmentation point based upon the smallestP-MTUof the peer. This option lets the caller set it to a smaller value. Note that while the user can change this value, if theP-MTUis smaller than the value set by the user, then theP-MTUvalue will override any user setting.SCTP_DELAYED_SACKβ this option lets the user both set and get the delayed ack time (in milliseconds) and the ack frequency that SCTP is using. The default delayed ack time is 200 milliseconds and the default ack frequency is 2.SCTP_PARTIAL_DELIVERY_POINTβ SCTP at times may need to start delivery of a very large message before the entire message has arrived. By default SCTP waits until the incoming message is larger than one fourth of the receive buffer. This option allows the stacks value to be overridden with a smaller value.SCTP_FRAGMENT_INTERLEAVEβ okay so remember how SCTP sometimes starts partial delivery (we literally just talked about it above π )? In the normal case, successive reads just keep handing you the rest of that message β blocking if they need to β until the whole thing is read. Sounds chill, except it means other messages may have arrived, be totally ready for delivery, and be stuck waiting behind the message that's currently mid-partial-delivery. π If this option is enabled, then when a partial delivery message has no more data to receive, a subsequent read may return a different message that's ready for delivery. It's off by default, because you legit have to be using the extended APIs to even tell the difference between messages (via the stream and stream sequence number). iykyk.SCTP_AUTH_CHUNKβ by default, only the dynamic addressing chunks get authenticated. This lil option lets a user request that an additional chunk be authenticated too. Note that successive calls to this option work fine and keep adding more chunks that require authentication β it stacks, bestie. Also note this only affects future associations, not existing ones. β¨SCTP_AUTH_KEYβ this one lets a user specify a shared key that can later be used to authenticate a peer. π«ΆSCTP_HMAC_IDENTβ lets you get or set the list of HMAC algorithms used to authenticate peers. Heads up: the HMAC values are in priority order β the first HMAC identifier is the most preferred, and the last one is the least preferred. πSCTP_AUTH_ACTIVE_KEYβ lets you make a key active for generating authentication information. But bestie, the peer must have the same key, or the data will be discarded. no cap.SCTP_AUTH_DELETE_KEYβ lets you delete an old key. bye felicia πSCTP_USE_EXT_RECVINFOβ the sockets API document allows an extended send/receive information structure to be used. This extended structure includes additional fields related to the next message to be received (after the current receive completes) β if such information is known. By default the system will not pass this info along. This option is you requesting it. πSCTP_AUTO_ASCONFβ by default, when bound to all addresses and the system administrator has enabled automatic dynamic addresses, the SCTP stack will automatically generate address changes into add and delete requests to any peers β because this option is set to true. This option lets an endpoint disable that behavior. main character energy πSCTP_MAXBURSTβ by default SCTP implements micro-burst control so that as the congestion window opens up, no huge burst of packets can be generated. Default burst limit is four. This option lets the user change that value. π₯SCTP_CONTEXTβ lots of sctp extended calls have acontextfield. It's a 32 bit opaque value that gets returned in send failures. This option lets the caller set the default context value to use when the user doesn't provide one. πSCTP_EXPLICIT_EORβ by default, a single send is a complete message, and SCTP generates an implied record boundary. If you enable this option, then all sends are part of the same message until the user indicates an end of record with the special flagSCTP_EORpassed in thesctp_sndrcvinfoflags field. Which effectively makes every send part of the same message until the user says otherwise. β οΈ Which also means a caller must NOT change the stream number until after theSCTP_EORis passed to SCTP, or else an error will be returned. Do not test this. okay test it but don't say I didn't warn you.SCTP_STATUSβ a read-only option that returns various status info about the specified association. π¦SCTP_GET_PEER_ADDR_INFOβ this read-only option returns information about a peer address.SCTP_PEER_AUTH_CHUNKSβ read-only; returns a list of the chunks the peer requires to be authenticated.SCTP_LOCAL_AUTH_CHUNKSβ read-only; returns a list of the locally required chunks that must be authenticated.SCTP_RESET_STREAMSβ this socket option is used to cause a stream sequence number, or all stream sequence numbers, to be reset. Note that the peer SCTP endpoint must also support the stream reset extension as well. both sides or it's not happening, periodt.
π MIB Variables π
The SCTP protocol implements a whole bunch of variables in the net.inet.sctp branch of the sysctl(3) MIB. so many. like, an iconic amount. π
π¨ Congestion Control
default_cc_moduleβ the default congestion control module. Default value is0. The minimum is0, and the maximum is3. A value of0enables the default congestion control algorithm. A value of1enables the High Speed congestion control algorithm. A value of2enables the HTCP congestion control algorithm. A value of3enables the data center congestion control (DCCC) algorithm. pick your fighter πinitial_cwndβ defines the initial congestion window size in MTUs.cwnd_maxburstβ use congestion control instead of 'blind' logic to limit the maximum burst when sending. Default value is1. May be set to0or1.ecn_enableβ enable Explicit Congestion Notification (ECN). Default value is1. May be set to0or1.rttvar_steady_stepβ the number of identical bandwidth measurements DCCC takes to try to step down the congestion window. Default value is20. The minimum is0, and the maximum is65535.rttvar_eqretβ whether DCCC reduces the congestion window size when round-trip time and bandwidth remain unchanged. Default value is0. May be set to0or1.rttvar_bwβ the shift amount DCCC uses for bandwidth smoothing on round-trip-time calculation. Default value is4. The minimum is0, and the maximum is32.rttvar_rttβ the shift amount DCCC uses for round-trip-time smoothing on round-trip-time calculation. Default value is5. The minimum is0, and the maximum is32.use_dcccecnβ enable ECN when using DCCC. Default value is1. May be set to0or1. β¨
π Misc
getcredβ get theucredof a SCTP connection.assoclistβ list of active SCTP associations. πstatsβ SCTP statistics (struct sctp_stat).diag_info_codeβ diagnostic information error cause code.blackholeβ enable SCTP blackholing. Seeblackhole(4)for more details.sendall_limitβ maximum message size (in bytes) that can be transmitted withSCTP_SENDALLflags set.buffer_splittingβ enable send/receive buffer splitting.vtag_time_waitβ vtag wait time in seconds,0to disable.nat_friendly_initβ enable sending of the NAT-friendly SCTP option on INITs.enable_sack_immediatelyβ enable sending of the SACK-IMMEDIATELY bit.udp_tunneling_portβ set the SCTP/UDP tunneling port.mobility_fasthandoffβ enable SCTP fast handoff.mobility_baseβ enable SCTP base mobilitydefault_frag_interleaveβ default fragment interleave level.default_ss_moduleβ default stream scheduling module.log_levelβ Ltrace/KTR trace logging level.max_retran_chunkβ number of retransmissions of a DATA chunk before an association is aborted.min_residualβ minimum residual data chunk in second part of split.strict_data_orderβ enforce strict data ordering, abort if control inside data.abort_at_limitβ abort when one-to-one hits qlimit. πhb_max_burstβ confirmation heartbeat max burst.do_sctp_drainβ flush chunks in receive queues with TSN higher than the cumulative TSN if the system is low on mbufs.max_chained_mbufsβ default max number of small mbufs on a chain.abc_l_varβ SCTP ABC max increase per SACK (L).nat_friendlyβ SCTP NAT friendly operation.cmt_use_dacβ CMT DAC on/off flag.cmt_on_offβ CMT settings.outgoing_streamsβ default number of outgoing streams.incoming_streamsβ default number of incoming streams.add_more_on_outputβ when space-wise is it worthwhile to try to add more to a socket send buffer.path_pf_thresholdβ default potentially failed threshold.path_rtx_maxβ default maximum of retransmissions per path.assoc_rtx_maxβ default maximum number of retransmissions per association.init_rtx_maxβ default maximum number of retransmissions for INIT chunks.valid_cookie_lifeβ default cookie lifetime in seconds.init_rto_maxβ default maximum retransmission timeout during association setup in ms.rto_initialβ default initial retransmission timeout in ms.rto_minβ default minimum retransmission timeout in ms.rto_maxβ default maximum retransmission timeout in ms.secret_lifetimeβ default secret lifetime in seconds.shutdown_guard_timeβ shutdown guard timer in seconds (0means 5 times RTO.Max).pmtu_raise_timeβ default PMTU raise timer in seconds.heartbeat_intervalβ default heartbeat interval in ms. πasoc_resourceβ max number of cached resources in an association.sys_resourceβ max number of cached resources in the system.sack_freqβ default SACK frequency.delayed_sack_timeβ default delayed SACK timer in ms.chunkscaleβ tunable for scaling of number of chunks and messages.min_split_pointβ minimum size when splitting a chunk.pcbhashsizeβ tunable for PCB hash table sizes.tcbhashsizeβ tunable for TCB hash table sizes.maxchunksβ default max chunks on queue per association.fr_maxburstβ default max burst for SCTP endpoints when fast retransmitting.maxburstβ default max burst for SCTP endpoints.peer_chkohβ amount to debit peers rwnd per chunk sent.strict_sacksβ enable SCTP Strict SACK checking.pktdrop_enableβ enable SCTP PKTDROP.nrsack_enableβ enable SCTP NR-SACK.reconfig_enableβ turns on SCTP RE-CONFIG β¨ so the stream reconfiguration stuff is actually live, bestie.asconf_enableβ turns on SCTP ASCONF, no cap π«Άauth_enableβ turns on SCTP AUTH. security era πpr_enableβ turns on PR-SCTP, iconic behaviour unlocked πauto_asconfβ turns on SCTP Auto-ASCONF. it just does its own thing, main character energy fr π₯recvspaceβ the maximum incoming SCTP buffer size πΈsendspaceβ the maximum outgoing SCTP buffer size π¦
β¨ SEE ALSO β¨
like go read these next, bestie, i'm literally begging π₯Ί
accept(2)bind(2)connect(2)listen(2)sctp_bindx(3)sctp_connectx(3)sctp_opt_info(3)sctp_recvmsg(3)sctp_sendmsg(3)blackhole(4)
π BUGS π
ok so the one thing that is genuinely not slaying: the sctp kernel module cannot be unloaded. like at all. once it's in there it's staying. no take-backs, no undo, no "wait actuallyβ" π it's committed. periodt.
ngl that's the whole page! go forth and SCTP responsibly, bestie π
this iconic little number came from the Debian fam, version dated June 21, 2023 β mwah, kisses to whoever wrote it ππ§π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2006, Randall Stewart
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms