1sctp(7P)                           Protocols                          sctp(7P)
2
3
4

NAME

6       sctp, SCTP - Stream Control Transmission Protocol
7

SYNOPSIS

9       #include <sys/socket.h>
10       #include <netinet/in.h>
11
12       s = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
13
14
15       s = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
16
17
18       s = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP);
19
20
21       s = socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP);
22
23

DESCRIPTION

25       SCTP  is a transport protocol layered above the Internet Protocol (IP),
26       or the Internet Protocol Version 6 (IPv6). SCTP  provides  a  reliable,
27       session  oriented, flow-controlled, two-way transmission of data. It is
28       a message- oriented protocol and supports framing  of  individual  mes‐
29       sages  boundaries. An SCTP association is created between two endpoints
30       for data transfer which is maintained during the lifetime of the trans‐
31       fer.  An  SCTP association is setup between two endpoints using a four-
32       way handshake mechanism with the use of a cookie to guard against  some
33       types of denial of service (DoS) attacks. These endpoints may be repre‐
34       sented by multiple IP addresses.
35
36
37       An SCTP message includes a common SCTP header followed by one  or  more
38       chunks.  Included in the common header is a 32-bit field which contains
39       the checksum (computed using CRC-32c polynomial)  of  the  entire  SCTP
40       packet.
41
42
43       SCTP  transfers  data  payloads  in  the form of DATA chunks. Each DATA
44       chunk contains a Transmission Sequence Number (TSN), which governs  the
45       transmission  of  messages  and detection of loss. DATA chunk exchanges
46       follow the Transmission Control Protocol's (TCP) Selective  ACK  (SACK)
47       mechanism. The receiver acknowledges data by sending SACK chunks, which
48       not only indicate the cumulative TSN range received, but also non-cumu‐
49       lative TSNs received, implying gaps in the received TSN sequence. SACKs
50       are sent using the delayed acknowledgment method similar to  TCP,  that
51       is, one SCTP per every other received packet with an upper bound on the
52       delay (when there are gaps detected the frequency is increased  to  one
53       every  received  packet).  Flow and congestion control follow TCP algo‐
54       rithms: Slow  Start,  Congestion  Avoidance,  Fast  Recovery  and  Fast
55       retransmit. But unlike TCP, SCTP does not support half-close connection
56       and "urgent" data.
57
58
59       SCTP is designed to support a number of functions that are critical for
60       telephony  signalling transport, including multi-streaming. SCTP allows
61       data to be partitioned into multiple streams that have the property  of
62       independent  sequenced  delivery so that message loss in any one stream
63       only affects delivery within that stream. In many applications (partic‐
64       ularly telephony signalling), it is only necessary to maintain sequenc‐
65       ing of messages that affect some resource. Other messages may be deliv‐
66       ered  without  having  to  maintain  overall sequence integrity. A DATA
67       chunk on an SCTP association contains  the  Stream  Id/Stream  Sequence
68       Number pair, in addition to the TSN, which is used for sequenced deliv‐
69       ery within a stream.
70
71
72       SCTP uses IP's host level addressing and adds its own per-host  collec‐
73       tion  of port addresses. The endpoints of an SCTP association are iden‐
74       tified by the combination of IP address(es) and an SCTP port number. By
75       providing  the  ability  for an endpoint to have multiple IP addresses,
76       SCTP supports  multi-homing,  which  makes  an  SCTP  association  more
77       resilient  in the presence of network failures (assuming the network is
78       constructed to provided redundancy). For a  multi-homed  SCTP  associa‐
79       tion, a single address is used as the primary address, which is used as
80       the destination address for normal DATA chunk transfers.  Retransmitted
81       DATA  chunks are sent over alternate address(es) to increase the proba‐
82       bility of reaching the  remote endpoint. Continued failure to send DATA
83       chunks  over  the  primary  address  results  in selecting an alternate
84       address as  the primary address. Additionally, SCTP monitors the acces‐
85       sibility  of  all  alternate addresses by sending periodic "heartbeats"
86       chunks. An SCTP association supports  multi-homing  by  exchanging  the
87       available  list  of  addresses during association setup (as part of its
88       four-way handshake mechanism). An SCTP endpoint is  associated  with  a
89       local  address using the bind(3SOCKET) call. Subsequently, the endpoint
90       can be associated with additional addresses using  sctp_bindx(3SOCKET).
91       By  using  a  special  value  of  INADDR_ANY with IP or the unspecified
92       address (all zeros) with IPv6 in the bind() or sctp_bindx()  calls,  an
93       endpoint can be bound to all available IP or IPv6 addresses on the sys‐
94       tem.
95
96
97       SCTP uses a three-way mechanism to allow graceful shutdown, where  each
98       endpoint  has  confirmation  of  the DATA chunks received by the remote
99       endpoint prior to completion of the shutdown. An Abort is provided  for
100       error cases when an immediate shutdown is needed.
101
102
103       Applications   can   access  SCTP  using  the  socket  interface  as  a
104       SOCK_STREAM (one-to-one style) or  SOCK_SEQPACKET  (one-to-many  style)
105       socket type.
106
107
108       One-to-one style socket interface supports similar semantics as sockets
109       for connection oriented protocols, such as TCP. Thus, a passive  socket
110       is  created  by  calling the listen(3SOCKET) function after binding the
111       socket using  bind().  Associations  to  this  passive  socket  can  be
112       received  using  accept(3SOCKET)  function. Active sockets use the con‐
113       nect(3SOCKET) function after binding  to initiate an association. If an
114       active  socket  is  not  explicitly  bound, an implicit binding is per‐
115       formed. If an application wants to exchange data during the association
116       setup    phase,    it    should    not    call   connect(),   but   use
117       sendto(3SOCKET)/sendmsg(3SOCKET) to implicitly initiate an association.
118       Once an association has been established, read(2) and write(2) can used
119       to exchange data. Additionally, send(3SOCKET), recv(3SOCKET), sendto(),
120       recvfrom(3SOCKET), sendmsg(), and recvmsg(3SOCKET) can be used.
121
122
123       One-to-many  socket interface supports similar semantics as sockets for
124       connection less protocols, such as UDP (however, unlike  UDP,  it  does
125       not  support  broadcast or multicast communications).  A passive socket
126       is created using the listen() function after binding the  socket  using
127       bind().  An accept() call is not needed to receive associations to this
128       passive socket (in fact, an  accept()  on  a  one-to-many  socket  will
129       fail). Associations are accepted automatically and notifications of new
130       associations are delivered  in  recvmsg()  provided  notifications  are
131       enabled.  Active  sockets after binding (implicitly or explicitly) need
132       not call connect() to establish an association,  implicit  associations
133       can  be created using sendmsg()/recvmsg() or sendto()/recvfrom() calls.
134       Such implicit associations cannot be created using  send()  and  recv()
135       calls.  On  an  SCTP socket (one-to-one or one-to-many), an association
136       may be established using sendmsg(). However, if an association  already
137       exists  for the destination address specified in the msg_name member of
138       the msg parameter, sendmsg() must include the association id in msg_iov
139       member  of  the  msg  parameter (using sctp_sndrcvinfo structure) for a
140       one-to-many SCTP  socket.  If  the  association  id  is  not  provided,
141       sendmsg() fails with EADDRINUSE. On a one-to-one socket the destination
142       information in the msg parameter is ignored for an established associa‐
143       tion.
144
145
146       A  one-to-one style association can be created from a one-to-many asso‐
147       ciation by branching  it  off  using  the  sctp_peeloff(3SOCKET)  call;
148       send()  and recv() can be used on such peeled off associations. Calling
149       close(2) on a one-to-many socket will gracefully shutdown all the asso‐
150       ciations represented by that one-to-many socket.
151
152
153       The  sctp_sendmsg(3SOCKET)  and  sctp_recvmsg(3SOCKET) functions can be
154       used to access advanced features provided by SCTP.
155
156
157       SCTP provides the following socket options which are set using setsock‐
158       opt(3SOCKET)  and  read  using getsockopt(3SOCKET). The option level is
159       the protocol number for SCTP, available from getprotobyname(3SOCKET).
160
161       SCTP_NODELAY
162
163           Turn on/off any Nagle-like algorithm (similar to TCP_NODELAY).
164
165
166       SO_RCVBUF
167
168           Set the receive buffer.
169
170
171       SO_SNDBUF
172
173           Set the send buffer.
174
175
176       SCTP_AUTOCLOSE
177
178           For one-to-many style socket, automatically close  any  association
179           that has been idle for more than the specified number of seconds. A
180           value of '0' indicates that no associations should be closed  auto‐
181           matically.
182
183
184       SCTP_EVENTS
185
186           Specify  various notifications and ancillary data the user wants to
187           receive.
188
189
190       SCTP_STATUS
191
192           Retrieve current status information about an SCTP association.
193
194
195       SCTP_GET_ASSOC_STATS
196
197           Gather and reset per endpoint association statistics.
198
199
200
201       Example Usage:
202
203         #include <netinet/sctp.h>
204
205         struct sctp_assoc_stats stat;
206         int rc;
207
208         int32_t len = sizeof (stat);
209
210         /*
211          * Per endpoint stats use the socket descriptor for sctp association.
212          */
213
214         /* Gather per endpoint association statistics */
215         rc = getsockopt(sd, IPPROTO_SCTP, SCTP_GET_ASSOC_STATS, &stat, &len);
216
217
218
219       Extract from the modified header file:
220
221         sctp.h
222
223          /*
224           * SCTP socket option used to read per endpoint association statistics.
225           */
226           #define SCTP_GET_ASSOC_STATS          24
227
228          /*
229           * A socket user request reads local per endpoint association stats.
230           * All stats are counts except sas_maxrto, which is the max value
231           * since the last user request for stats on this endpoint.
232           */
233           typedef struct sctp_assoc_stats {
234               uint64_t  sas_rtxchunks;   /* Retransmitted Chunks */
235               uint64_t  sas_gapcnt;      /* Gap Acknowledgements Received */
236               uint64_t  sas_maxrto;      /* Maximum Observed RTO this period */
237               uint64_t  sas_outseqtsns;  /* TSN received > next expected */
238               uint64_t  sas_osacks;      /* SACKs sent */
239               uint64_t  sas_isacks;      /* SACKs received */
240               uint64_t  sas_octrlchunks; /* Control chunks sent - no dups */
241               uint64_t  sas_ictrlchunks; /* Control chunks received - no dups */
242               uint64_t  sas_oodchunks;   /* Ordered data chunks sent */
243               uint64_t  sas_iodchunks;   /* Ordered data chunks received */
244               uint64_t  sas_ouodchunks;  /* Unordered data chunks sent */
245               uint64_t  sas_iuodchunks;  /* Unordered data chunks received */
246               uint64_t  sas_idupchunks;  /* Dups received (ordered+unordered) */
247         } sctp_assoc_stats_t;
248
249

MULTIHOMING

251       The ability of SCTP to use multiple addresses  in  an  association  can
252       create  issues  with  some  network  utilities.  This requires a system
253       administrator to be careful in setting up the system.
254
255
256       For example, the tcpd allows an administrator to use a simple  form  of
257       address/hostname  access  control.  While  tcpd can work with SCTP, the
258       access control part can have some problems. The tcpd access control  is
259       only  based  on one of the addresses at association setup time. Once as
260       association is allowed, no more checking is performed. This means  that
261       during  the  life  time of the association, SCTP packets from different
262       addresses of the peer host can be received in the system. This may  not
263       be  what the system administrator wants as some of the peer's addresses
264       are supposed to be blocked.
265
266
267       Another example is the use of IP Filter, which provides  several  func‐
268       tions  such  as  IP  packet filtering (ipf(1M)) and NAT ipnat(1M)). For
269       packet filtering, one issue is that a filter policy can  block  packets
270       from  some  of  the  addresses of an association while allowing packets
271       from other addresses to go through. This can degrade SCTP's performance
272       when  failure occurs. There is a more serious issue with IP address re‐
273       write by NAT. At association setup time,  SCTP  endpoints  exchange  IP
274       addresses. But IP Filter is not aware of this. So when NAT is done on a
275       packet, it may change the address to an unacceptable one. Thus the SCTP
276       association  setup may succeed but packets cannot go through afterwards
277       when a different IP address is used for the association.
278

SEE ALSO

280       ipf(1M), ipnat(1M), ndd(1M),  ioctl(2),  close(2),  read(2),  write(2),
281       accept(3SOCKET),     bind(3SOCKET),    connect(3SOCKET),    getprotoby‐
282       name(3SOCKET),  getsockopt(3SOCKET),  libsctp(3LIB),   listen(3SOCKET),
283       recv(3SOCKET),           recvfrom(3SOCKET),           recvmsg(3SOCKET),
284       sctp_bindx(3SOCKET), sctp_getladdrs(3SOCKET),  sctp_getpaddrs(3SOCKET),
285       sctp_freepaddrs(3SOCKET),                       sctp_opt_info(3SOCKET),
286       sctp_peeloff(3SOCKET),  sctp_recvmsg(3SOCKET),   sctp_sendmsg(3SOCKET),
287       send(3SOCKET),   sendmsg(3SOCKET),   sendto(3SOCKET),  socket(3SOCKET),
288       ipfilter(5), tcp(7P), udp(7P), inet(7P), inet6(7P), ip(7P), ip6(7P)
289
290
291       R. Stewart, Q. Xie, K. Morneault, C. Sharp, H. Schwarzbauer, T. Taylor,
292       I.  Rytina,  M.  Kalla,  L.  Zang,  V. Paxson, RFC 2960, Stream Control
293       Transmission Protocol, October 2000
294
295
296       L. Ong, J. Yoakum, RFC 3286, An Introduction to Stream  Control  Trans‐
297       mission Protocol (SCTP), May 2002
298
299
300       J.  Stone,  R.  Stewart, D. Otis, RFC 3309, Stream Control Transmission
301       Protocol (SCTP) Checksum Change, September 2002.
302

DIAGNOSTICS

304       A socket operation may fail if:
305
306       EPROTONOSUPPORT    The  socket  type  is  other  than  SOCK_STREAM  and
307                          SOCK_SEQPACKET.
308
309
310       ETIMEDOUT          An association was dropped due to excessive retrans‐
311                          missions.
312
313
314       ECONNREFUSED       The remote peer refused establishing an association.
315
316
317       EADDRINUSE         A bind() operation was attempted on a socket with  a
318                          network  address/port  pair  that  has  already been
319                          bound to another socket.
320
321
322       EINVAL             A bind() operation was attempted on a socket with an
323                          invalid network address.
324
325
326       EPERM              A  bind() operation was attempted on a socket with a
327                          "reserved" port number and the effective user ID  of
328                          the process was not the privileged user.
329
330
331
332
333SunOS 5.11                        30 Jul 2009                         sctp(7P)
Impressum