SCTP(4)

๐Ÿ’– SCTP(4) ๐Ÿ’–

okay so bestie, this is the SCTP(4) page from the Kernel Interfaces Manual, and it's literally all about the Internet Stream Control Transmission Protocol. It's giving reliable, message-oriented, multi-homed, multi-streamed networking realness, and we're gonna vibe through every single detail. No cap. ๐Ÿ’…

โœจ NAME โœจ

sctp โ€” Internet Stream Control Transmission Protocol

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

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. iconic. ๐ŸŽ€

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 way that works is so main character energy. ๐Ÿ’œ

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. paths on paths on paths ๐Ÿ›ฃ๏ธ

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. fr fr, stream 2 stays unbothered. โœจ

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. it's giving chaos, but make it intentional. ๐Ÿ’€

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. iykyk. ๐ŸŒˆ

๐ŸŽ€ 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 option SCTP_NODELAY defeats this algorithm. no more tiny-packet lag, bestie. ๐Ÿ’…
  • 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). so it just chills forever unless you say otherwise. ๐Ÿ“
  • 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. so dramatic, but also important. ๐Ÿ˜ญ
  • 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 flag MSG_NOTIFICATION set 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 both IPV4 and IPV6. An association may span both IPV4 and IPV6 addresses since SCTP is multi-homed. By default, when opening an IPV6 socket, when data arrives on the socket from a peer's V4 address the V4 address will be presented with an address family of AF_INET. If this is undesirable, then this option can be enabled which will then convert all V4 addresses into mapped V6 representations. mapping the vibe, as one does. ๐Ÿงš
  • SCTP_MAXSEG โ€” By default SCTP chooses its message fragmentation point based upon the smallest P-MTU of the peer. This option lets the caller set it to a smaller value. Note that while the user can change this value, if the P-MTU is smaller than the value set by the user, then the P-MTU value will override any user setting. peer says no, basically. โญ
  • SCTP_DELAYED_ACK_TIME โ€” This option lets the user both set and get the delayed ack time (in milliseconds) that SCTP is using. The default is 200 milliseconds.
  • 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. big message, small patience, customizable. ๐Ÿ‘‘
  • SCTP_FRAGMENT_INTERLEAVE โ€” okay so bestie, you know how SCTP sometimes kicks off partial delivery (it's literally the thing we were just talking about ๐Ÿ’…)? Normally, the reads that follow keep handing you the rest of that same message, blocking if they have to, until the whole message is read. Which sounds fine until you realise that other messages may have totally arrived and be ready to go, just sitting there stuck behind the message being partially delivered ๐Ÿ˜ญ. Turn this option on and it changes: when a partial delivery message has no more data to be received, a later read can return a different message that's ready for delivery. By default this is off, because you the user have to be using the extended API's to even tell the difference between messages (via the stream and stream sequence number). So like, don't rawdog it with the basic API, fr fr ๐Ÿซถ
  • SCTP_AUTH_CHUNK โ€” by default, only the dynamic addressing chunks get authenticated. This option lets you request that an additional chunk be authenticated too โœจ. Heads up: successive calls to this option work and keep adding more chunks that require authentication โ€” it stacks ๐ŸŽ€. And it only effects future associations, not existing ones. Past associations said no thanks ๐Ÿ’€
  • SCTP_AUTH_KEY โ€” lets you specify a shared key that can later be used to authenticate a peer ๐Ÿ”‘
  • SCTP_HMAC_IDENT โ€” get or set the list of HMAC algorithms used to authenticate peers ๐Ÿงš. The HMAC values are in priority order, where the first HMAC identifier is the most preferred and the last is the least preferred. First place wins, periodt ๐Ÿ‘‘
  • SCTP_AUTH_ACTIVE_KEY โ€” makes a key active for the generation of authentication information. Big caveat: the peer must have the same key or else the data will be discarded ๐Ÿ’€. Matching keys or nothing, bestie.
  • SCTP_AUTH_DELETE_KEY โ€” lets you delete an old key ๐Ÿ—‘๏ธ
  • SCTP_USE_EXT_RECVINFO โ€” the sockets api document allows an extended send/receive information structure, and that extended structure includes additional fields related to the next message to be received (after the current receive completes) โ€” but only if such information is known ๐Ÿ‘€. By default the system will not pass this information. This option is how you ask for it, bestie, you just have to say the word ๐Ÿซถ
  • SCTP_AUTO_ASCONF โ€” by default, when bound to all address and the system administrator has enables automatic dynamic addresses, the SCTP stack will automatically generate address changes into add and delete requests to any peers by setting this option to true. This option lets an endpoint disable that behavior. Main character energy: opting out of the group chat ๐Ÿšช
  • SCTP_MAXBURST โ€” by default SCTP implements micro-burst control so that as the congestion window opens up, no large burst of packets can be generated ๐ŸŒŠ. The default burst limit is four. This option lets you change that value. Four is the vibe until you decide otherwise ๐Ÿ’…
  • SCTP_CONTEXT โ€” many sctp extended calls have a context field. That context field is a 32 bit opaque value that will be returned in send failures ๐Ÿ“ฎ. This option lets the caller set the default context value to use when none is provided by the user.
  • SCTP_EXPLICIT_EOR โ€” by default, a single send is a complete message, and SCTP generates an implied record boundary. If this option is enabled, then all sends are part of the same message until the user indicates an end of record with the special flag SCTP_EOR passed in the sctp_sndrcvinfo flags field ๐ŸŽ€. This effectively makes all sends part of the same message until the user specifies differently. Which means: a caller must NOT change the stream number until after the SCTP_EOR is passed to SCTP, else an error will be returned ๐Ÿ˜ญ. Do not test this, I'm begging.
  • SCTP_STATUS โ€” a read-only option that returns various status information about the specified association ๐Ÿ‘‘
  • SCTP_GET_PEER_ADDR_INFO โ€” this read-only option returns information about a peer address ๐Ÿ“
  • SCTP_PEER_AUTH_CHUNKS โ€” this read-only option returns a list of the chunks the peer requires to be authenticated ๐Ÿ“‹
  • SCTP_LOCAL_AUTH_CHUNKS โ€” this read-only option returns a list of the locally required chunks that must be authenticated ๐Ÿ“‹
  • SCTP_RESET_STREAMS โ€” 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 โ€” it takes two, bestie ๐Ÿค

๐ŸŒˆ MIB Variables ๐ŸŒˆ

The SCTP protocol implements a number of variables in the net.inet.sctp branch of the sysctl(3) MIB. It's giving control panel ๐ŸŽ›๏ธโœจ

๐Ÿ’– Congestion Control ๐Ÿ’–

  • default_cc_module โ€” default congestion control module. Default value is 0. The minimum is 0, and the maximum is 3. A value of 0 enables the default congestion control algorithm. A value of 1 enables the High Speed congestion control algorithm. A value of 2 enables the HTCP congestion control algorithm. A value of 3 enables the data center congestion control (DCCC) algorithm ๐Ÿšฆ
  • initial_cwnd โ€” defines the initial congestion window size in MTUs ๐Ÿ“
  • cwnd_maxburst โ€” use congestion control instead of 'blind' logic to limit maximum burst when sending. Default value is 1. May be set to 0 or 1.
  • ecn_enable โ€” enable Explicit Congestion Notification (ECN). Default value is 1. May be set to 0 or 1.
  • rttvar_steady_step โ€” number of identical bandwidth measurements DCCC takes to try step down the congestion window. Default value is 20. The minimum is 0, and the maximum is 65535.
  • rttvar_eqret โ€” whether DCCC reduces the congestion window size when round-trip time and bandwidth remain unchanged. Default value is 0. May be set to 0 or 1.
  • rttvar_bw โ€” shift amount DCCC uses for bandwidth smoothing on round-trip-time calculation. Default value is 4. The minimum is 0, and the maximum is 32.
  • rttvar_rtt โ€” shift amount DCCC uses for round-trip-time smoothing on round-trip-time calculation. Default value is 5. The minimum is 0, and the maximum is 32.
  • use_dcccecn โ€” enable ECN when using DCCC. Default value is 1. May be set to 0 or 1.

๐ŸŒธ Misc ๐ŸŒธ

  • getcred โ€” get the ucred of 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. See blackhole(4) for more details ๐Ÿ•ณ๏ธ
  • sendall_limit โ€” maximum message size (in bytes) that can be transmitted with SCTP_SENDALL flags set ๐Ÿ“ฆ
  • buffer_splitting โ€” enable send/receive buffer splitting โœ‚๏ธ
  • vtag_time_wait โ€” vtag wait time in seconds, 0 to 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 mobility ๐Ÿšถโ€โ™€๏ธ
  • default_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 (0 means 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 ๐Ÿ’… bestie this is the one that lets you shuffle streams and addresses around mid-connection, and it's off until you say so.
  • asconf_enable โ€” turns on SCTP ASCONF. yes it's a real acronym, yes it's giving very serious protocol energy ๐ŸŽ€
  • auth_enable โ€” turns on SCTP AUTH. security girlies rise ๐Ÿซถ
  • pr_enable โ€” turns on PR-SCTP (that's Partial Reliability, and no, "partial reliability" is not a metaphor for your ex) โœจ
  • auto_asconf โ€” turns on SCTP Auto-ASCONF. it does the ASCONF thing for you automatically, lowkey the laziest and best option here ๐ŸŒธ
  • recvspace โ€” the maximum incoming SCTP buffer size. how much love (data) you're willing to receive at once ๐Ÿ’–
  • sendspace โ€” the maximum outgoing SCTP buffer size. how much you're willing to put out into the world ๐Ÿ‘‘

๐ŸŒˆ SEE ALSO

okay so if you wanna go deeper (and you do, you're a scholar), go read these icons:

periodt. that's the whole reading list ๐Ÿ“š


๐Ÿ’€ BUGS

the sctp kernel module cannot be unloaded.

not "shouldn't", not "usually won't" โ€” cannot. once it's in, it's in. it's giving main character who never leaves the party ๐Ÿ˜ญ you can't rmmod your way out of this one, so load it with intention. no cap.


and that's the whole page, bestie!! this one shipped from Debian on July 9, 2020 and it's filed under SCTP(4) โ€” go forth and slay your sockets ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from