blob: 115a7fd9e70119048f8f387db73ad861b3732ef9 [file] [log] [blame]
Austin Schuh8d0a2852019-12-28 22:54:28 -08001
2
3
4
5
6
7Internet Engineering Task Force (IETF) R. Stewart
8Request for Comments: 6458 Adara Networks
9Category: Informational M. Tuexen
10ISSN: 2070-1721 Muenster Univ. of Appl. Sciences
11 K. Poon
12 Oracle Corporation
13 P. Lei
14 Cisco Systems, Inc.
15 V. Yasevich
16 HP
17 December 2011
18
19
20 Sockets API Extensions
21 for the Stream Control Transmission Protocol (SCTP)
22
23Abstract
24
25 This document describes a mapping of the Stream Control Transmission
26 Protocol (SCTP) into a sockets API. The benefits of this mapping
27 include compatibility for TCP applications, access to new SCTP
28 features, and a consolidated error and event notification scheme.
29
30Status of This Memo
31
32 This document is not an Internet Standards Track specification; it is
33 published for informational purposes.
34
35 This document is a product of the Internet Engineering Task Force
36 (IETF). It represents the consensus of the IETF community. It has
37 received public review and has been approved for publication by the
38 Internet Engineering Steering Group (IESG). Not all documents
39 approved by the IESG are a candidate for any level of Internet
40 Standard; see Section 2 of RFC 5741.
41
42 Information about the current status of this document, any errata,
43 and how to provide feedback on it may be obtained at
44 http://www.rfc-editor.org/info/rfc6458.
45
46
47
48
49
50
51
52
53
54
55
56
57
58Stewart, et al. Informational [Page 1]
59
60RFC 6458 SCTP Sockets API December 2011
61
62
63Copyright Notice
64
65 Copyright (c) 2011 IETF Trust and the persons identified as the
66 document authors. All rights reserved.
67
68 This document is subject to BCP 78 and the IETF Trust's Legal
69 Provisions Relating to IETF Documents
70 (http://trustee.ietf.org/license-info) in effect on the date of
71 publication of this document. Please review these documents
72 carefully, as they describe your rights and restrictions with respect
73 to this document. Code Components extracted from this document must
74 include Simplified BSD License text as described in Section 4.e of
75 the Trust Legal Provisions and are provided without warranty as
76 described in the Simplified BSD License.
77
78 This document may contain material from IETF Documents or IETF
79 Contributions published or made publicly available before November
80 10, 2008. The person(s) controlling the copyright in some of this
81 material may not have granted the IETF Trust the right to allow
82 modifications of such material outside the IETF Standards Process.
83 Without obtaining an adequate license from the person(s) controlling
84 the copyright in such materials, this document may not be modified
85 outside the IETF Standards Process, and derivative works of it may
86 not be created outside the IETF Standards Process, except to format
87 it for publication as an RFC or to translate it into languages other
88 than English.
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114Stewart, et al. Informational [Page 2]
115
116RFC 6458 SCTP Sockets API December 2011
117
118
119Table of Contents
120
121 1. Introduction ....................................................6
122 2. Data Types ......................................................8
123 3. One-to-Many Style Interface .....................................8
124 3.1. Basic Operation ............................................8
125 3.1.1. socket() ............................................9
126 3.1.2. bind() .............................................10
127 3.1.3. listen() ...........................................11
128 3.1.4. sendmsg() and recvmsg() ............................12
129 3.1.5. close() ............................................14
130 3.1.6. connect() ..........................................14
131 3.2. Non-Blocking Mode .........................................15
132 3.3. Special Considerations ....................................16
133 4. One-to-One Style Interface .....................................18
134 4.1. Basic Operation ...........................................18
135 4.1.1. socket() ...........................................19
136 4.1.2. bind() .............................................19
137 4.1.3. listen() ...........................................21
138 4.1.4. accept() ...........................................21
139 4.1.5. connect() ..........................................22
140 4.1.6. close() ............................................23
141 4.1.7. shutdown() .........................................23
142 4.1.8. sendmsg() and recvmsg() ............................24
143 4.1.9. getpeername() ......................................24
144 5. Data Structures ................................................25
145 5.1. The msghdr and cmsghdr Structures .........................25
146 5.2. Ancillary Data Considerations and Semantics ...............26
147 5.2.1. Multiple Items and Ordering ........................27
148 5.2.2. Accessing and Manipulating Ancillary Data ..........27
149 5.2.3. Control Message Buffer Sizing ......................28
150 5.3. SCTP msg_control Structures ...............................28
151 5.3.1. SCTP Initiation Structure (SCTP_INIT) ..............29
152 5.3.2. SCTP Header Information Structure
153 (SCTP_SNDRCV) - DEPRECATED .........................30
154 5.3.3. Extended SCTP Header Information Structure
155 (SCTP_EXTRCV) - DEPRECATED .........................33
156 5.3.4. SCTP Send Information Structure (SCTP_SNDINFO) .....35
157 5.3.5. SCTP Receive Information Structure (SCTP_RCVINFO) ..37
158 5.3.6. SCTP Next Receive Information Structure
159 (SCTP_NXTINFO) .....................................38
160 5.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO) ...39
161 5.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO) ....40
162 5.3.9. SCTP Destination IPv4 Address Structure
163 (SCTP_DSTADDRV4) ...................................41
164 5.3.10. SCTP Destination IPv6 Address Structure
165 (SCTP_DSTADDRV6) ..................................41
166
167
168
169
170Stewart, et al. Informational [Page 3]
171
172RFC 6458 SCTP Sockets API December 2011
173
174
175 6. SCTP Events and Notifications ..................................41
176 6.1. SCTP Notification Structure ...............................42
177 6.1.1. SCTP_ASSOC_CHANGE ..................................43
178 6.1.2. SCTP_PEER_ADDR_CHANGE ..............................45
179 6.1.3. SCTP_REMOTE_ERROR ..................................46
180 6.1.4. SCTP_SEND_FAILED - DEPRECATED ......................47
181 6.1.5. SCTP_SHUTDOWN_EVENT ................................48
182 6.1.6. SCTP_ADAPTATION_INDICATION .........................49
183 6.1.7. SCTP_PARTIAL_DELIVERY_EVENT ........................49
184 6.1.8. SCTP_AUTHENTICATION_EVENT ..........................50
185 6.1.9. SCTP_SENDER_DRY_EVENT ..............................51
186 6.1.10. SCTP_NOTIFICATIONS_STOPPED_EVENT ..................52
187 6.1.11. SCTP_SEND_FAILED_EVENT ............................52
188 6.2. Notification Interest Options .............................54
189 6.2.1. SCTP_EVENTS Option - DEPRECATED ....................54
190 6.2.2. SCTP_EVENT Option ..................................56
191 7. Common Operations for Both Styles ..............................57
192 7.1. send(), recv(), sendto(), and recvfrom() ..................57
193 7.2. setsockopt() and getsockopt() .............................59
194 7.3. read() and write() ........................................60
195 7.4. getsockname() .............................................60
196 7.5. Implicit Association Setup ................................61
197 8. Socket Options .................................................61
198 8.1. Read/Write Options ........................................63
199 8.1.1. Retransmission Timeout Parameters (SCTP_RTOINFO) ...63
200 8.1.2. Association Parameters (SCTP_ASSOCINFO) ............64
201 8.1.3. Initialization Parameters (SCTP_INITMSG) ...........66
202 8.1.4. SO_LINGER ..........................................66
203 8.1.5. SCTP_NODELAY .......................................66
204 8.1.6. SO_RCVBUF ..........................................67
205 8.1.7. SO_SNDBUF ..........................................67
206 8.1.8. Automatic Close of Associations (SCTP_AUTOCLOSE) ...67
207 8.1.9. Set Primary Address (SCTP_PRIMARY_ADDR) ............68
208 8.1.10. Set Adaptation Layer Indicator
209 (SCTP_ADAPTATION_LAYER) ...........................68
210 8.1.11. Enable/Disable Message Fragmentation
211 (SCTP_DISABLE_FRAGMENTS) ..........................68
212 8.1.12. Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) ...69
213 8.1.13. Set Default Send Parameters
214 (SCTP_DEFAULT_SEND_PARAM) - DEPRECATED ............71
215 8.1.14. Set Notification and Ancillary Events
216 (SCTP_EVENTS) - DEPRECATED ........................72
217 8.1.15. Set/Clear IPv4 Mapped Addresses
218 (SCTP_I_WANT_MAPPED_V4_ADDR) ......................72
219 8.1.16. Get or Set the Maximum Fragmentation Size
220 (SCTP_MAXSEG) .....................................72
221 8.1.17. Get or Set the List of Supported HMAC
222 Identifiers (SCTP_HMAC_IDENT) .....................73
223
224
225
226Stewart, et al. Informational [Page 4]
227
228RFC 6458 SCTP Sockets API December 2011
229
230
231 8.1.18. Get or Set the Active Shared Key
232 (SCTP_AUTH_ACTIVE_KEY) ............................74
233 8.1.19. Get or Set Delayed SACK Timer
234 (SCTP_DELAYED_SACK) ...............................74
235 8.1.20. Get or Set Fragmented Interleave
236 (SCTP_FRAGMENT_INTERLEAVE) ........................75
237 8.1.21. Set or Get the SCTP Partial Delivery Point
238 (SCTP_PARTIAL_DELIVERY_POINT) .....................77
239 8.1.22. Set or Get the Use of Extended Receive Info
240 (SCTP_USE_EXT_RCVINFO) - DEPRECATED ...............77
241 8.1.23. Set or Get the Auto ASCONF Flag
242 (SCTP_AUTO_ASCONF) ................................77
243 8.1.24. Set or Get the Maximum Burst (SCTP_MAX_BURST) .....78
244 8.1.25. Set or Get the Default Context (SCTP_CONTEXT) .....78
245 8.1.26. Enable or Disable Explicit EOR Marking
246 (SCTP_EXPLICIT_EOR) ...............................79
247 8.1.27. Enable SCTP Port Reusage (SCTP_REUSE_PORT) ........79
248 8.1.28. Set Notification Event (SCTP_EVENT) ...............79
249 8.1.29. Enable or Disable the Delivery of SCTP_RCVINFO
250 as Ancillary Data (SCTP_RECVRCVINFO) ..............79
251 8.1.30. Enable or Disable the Delivery of SCTP_NXTINFO
252 as Ancillary Data (SCTP_RECVNXTINFO) ..............80
253 8.1.31. Set Default Send Parameters
254 (SCTP_DEFAULT_SNDINFO) ............................80
255 8.1.32. Set Default PR-SCTP Parameters
256 (SCTP_DEFAULT_PRINFO) .............................80
257 8.2. Read-Only Options .........................................81
258 8.2.1. Association Status (SCTP_STATUS) ...................81
259 8.2.2. Peer Address Information
260 (SCTP_GET_PEER_ADDR_INFO) ..........................82
261 8.2.3. Get the List of Chunks the Peer Requires to
262 Be Authenticated (SCTP_PEER_AUTH_CHUNKS) ...........84
263 8.2.4. Get the List of Chunks the Local Endpoint Requires
264 to Be Authenticated (SCTP_LOCAL_AUTH_CHUNKS) .......84
265 8.2.5. Get the Current Number of Associations
266 (SCTP_GET_ASSOC_NUMBER) ............................85
267 8.2.6. Get the Current Identifiers of Associations
268 (SCTP_GET_ASSOC_ID_LIST) ...........................85
269 8.3. Write-Only Options ........................................85
270 8.3.1. Set Peer Primary Address
271 (SCTP_SET_PEER_PRIMARY_ADDR) .......................86
272 8.3.2. Add a Chunk That Must Be Authenticated
273 (SCTP_AUTH_CHUNK) ..................................86
274 8.3.3. Set a Shared Key (SCTP_AUTH_KEY) ...................86
275 8.3.4. Deactivate a Shared Key
276 (SCTP_AUTH_DEACTIVATE_KEY) .........................87
277 8.3.5. Delete a Shared Key (SCTP_AUTH_DELETE_KEY) .........88
278
279
280
281
282Stewart, et al. Informational [Page 5]
283
284RFC 6458 SCTP Sockets API December 2011
285
286
287 9. New Functions ..................................................88
288 9.1. sctp_bindx() ..............................................88
289 9.2. sctp_peeloff() ............................................90
290 9.3. sctp_getpaddrs() ..........................................91
291 9.4. sctp_freepaddrs() .........................................92
292 9.5. sctp_getladdrs() ..........................................92
293 9.6. sctp_freeladdrs() .........................................93
294 9.7. sctp_sendmsg() - DEPRECATED ...............................93
295 9.8. sctp_recvmsg() - DEPRECATED ...............................94
296 9.9. sctp_connectx() ...........................................95
297 9.10. sctp_send() - DEPRECATED .................................96
298 9.11. sctp_sendx() - DEPRECATED ................................97
299 9.12. sctp_sendv() .............................................98
300 9.13. sctp_recvv() ............................................101
301 10. Security Considerations ......................................103
302 11. Acknowledgments ..............................................103
303 12. References ...................................................104
304 12.1. Normative References ....................................104
305 12.2. Informative References ..................................104
306 Appendix A. Example Using One-to-One Style Sockets ...............106
307 Appendix B. Example Using One-to-Many Style Sockets ..............109
308
3091. Introduction
310
311 The sockets API has provided a standard mapping of the Internet
312 Protocol suite to many operating systems. Both TCP [RFC0793] and UDP
313 [RFC0768] have benefited from this standard representation and access
314 method across many diverse platforms. SCTP is a new protocol that
315 provides many of the characteristics of TCP but also incorporates
316 semantics more akin to UDP. This document defines a method to map
317 the existing sockets API for use with SCTP, providing both a base for
318 access to new features and compatibility so that most existing TCP
319 applications can be migrated to SCTP with few (if any) changes.
320
321 There are three basic design objectives:
322
323 1. Maintain consistency with existing sockets APIs: We define a
324 sockets mapping for SCTP that is consistent with other sockets
325 API protocol mappings (for instance UDP, TCP, IPv4, and IPv6).
326
327 2. Support a one-to-many style interface: This set of semantics is
328 similar to that defined for connectionless protocols, such as
329 UDP. A one-to-many style SCTP socket should be able to control
330 multiple SCTP associations. This is similar to a UDP socket,
331 which can communicate with many peer endpoints. Each of these
332 associations is assigned an association identifier so that an
333
334
335
336
337
338Stewart, et al. Informational [Page 6]
339
340RFC 6458 SCTP Sockets API December 2011
341
342
343 application can use the ID to differentiate them. Note that SCTP
344 is connection-oriented in nature, and it does not support
345 broadcast or multicast communications, as UDP does.
346
347 3. Support a one-to-one style interface: This interface supports a
348 similar semantics as sockets for connection-oriented protocols,
349 such as TCP. A one-to-one style SCTP socket should only control
350 one SCTP association. One purpose of defining this interface is
351 to allow existing applications built on other connection-oriented
352 protocols to be ported to use SCTP with very little effort.
353 Developers familiar with these semantics can easily adapt to
354 SCTP. Another purpose is to make sure that existing mechanisms
355 in most operating systems that support sockets, such as select(),
356 should continue to work with this style of socket. Extensions
357 are added to this mapping to provide mechanisms to exploit new
358 features of SCTP.
359
360 Goals 2 and 3 are not compatible, so this document defines two modes
361 of mapping, namely the one-to-many style mapping and the one-to-one
362 style mapping. These two modes share some common data structures and
363 operations, but will require the use of two different application
364 programming styles. Note that all new SCTP features can be used with
365 both styles of socket. The decision on which one to use depends
366 mainly on the nature of the applications.
367
368 A mechanism is defined to extract an SCTP association from a one-to-
369 many style socket into a one-to-one style socket.
370
371 Some of the SCTP mechanisms cannot be adequately mapped to an
372 existing socket interface. In some cases, it is more desirable to
373 have a new interface instead of using existing socket calls.
374 Section 9 of this document describes these new interfaces.
375
376 Please note that some elements of the SCTP sockets API are declared
377 as deprecated. During the evolution of this document, elements of
378 the API were introduced, implemented, and later on replaced by other
379 elements. These replaced elements are declared as deprecated, since
380 they are still available in some implementations and the replacement
381 functions are not. This applies especially to older versions of
382 operating systems supporting SCTP. New SCTP socket implementations
383 must implement at least the non-deprecated elements. Implementations
384 intending interoperability with older versions of the API should also
385 include the deprecated functions.
386
387
388
389
390
391
392
393
394Stewart, et al. Informational [Page 7]
395
396RFC 6458 SCTP Sockets API December 2011
397
398
3992. Data Types
400
401 Whenever possible, Portable Operating System Interface (POSIX) data
402 types defined in [IEEE-1003.1-2008] are used: uintN_t means an
403 unsigned integer of exactly N bits (e.g., uint16_t). This document
404 also assumes the argument data types from POSIX when possible (e.g.,
405 the final argument to setsockopt() is a socklen_t value). Whenever
406 buffer sizes are specified, the POSIX size_t data type is used.
407
4083. One-to-Many Style Interface
409
410 In the one-to-many style interface, there is a one-to-many
411 relationship between sockets and associations.
412
4133.1. Basic Operation
414
415 A typical server in this style uses the following socket calls in
416 sequence to prepare an endpoint for servicing requests:
417
418 o socket()
419
420 o bind()
421
422 o listen()
423
424 o recvmsg()
425
426 o sendmsg()
427
428 o close()
429
430 A typical client uses the following calls in sequence to set up an
431 association with a server to request services:
432
433 o socket()
434
435 o sendmsg()
436
437 o recvmsg()
438
439 o close()
440
441 In this style, by default, all of the associations connected to the
442 endpoint are represented with a single socket. Each association is
443 assigned an association identifier (the type is sctp_assoc_t) so that
444 an application can use it to differentiate among them. In some
445 implementations, the peer endpoints' addresses can also be used for
446 this purpose. But this is not required for performance reasons. If
447
448
449
450Stewart, et al. Informational [Page 8]
451
452RFC 6458 SCTP Sockets API December 2011
453
454
455 an implementation does not support using addresses to differentiate
456 between different associations, the sendto() call can only be used to
457 set up an association implicitly. It cannot be used to send data to
458 an established association, as the association identifier cannot be
459 specified.
460
461 Once an association identifier is assigned to an SCTP association,
462 that identifier will not be reused until the application explicitly
463 terminates the use of the association. The resources belonging to
464 that association will not be freed until that happens. This is
465 similar to the close() operation on a normal socket. The only
466 exception is when the SCTP_AUTOCLOSE option (Section 8.1.8) is set.
467 In this case, after the association is terminated gracefully and
468 automatically, the association identifier assigned to it can be
469 reused. All applications using this option should be aware of this
470 to avoid the possible problem of sending data to an incorrect peer
471 endpoint.
472
473 If the server or client wishes to branch an existing association off
474 to a separate socket, it is required to call sctp_peeloff() and to
475 specify the association identifier. The sctp_peeloff() call will
476 return a new one-to-one style socket that can then be used with
477 recv() and send() functions for message passing. See Section 9.2 for
478 more on branched-off associations.
479
480 Once an association is branched off to a separate socket, it becomes
481 completely separated from the original socket. All subsequent
482 control and data operations to that association must be done through
483 the new socket. For example, the close() operation on the original
484 socket will not terminate any associations that have been branched
485 off to a different socket.
486
487 One-to-many style socket calls are discussed in more detail in the
488 following subsections.
489
4903.1.1. socket()
491
492 Applications use socket() to create a socket descriptor to represent
493 an SCTP endpoint.
494
495 The function prototype is
496
497 int socket(int domain,
498 int type,
499 int protocol);
500
501 and one uses PF_INET or PF_INET6 as the domain, SOCK_SEQPACKET as the
502 type, and IPPROTO_SCTP as the protocol.
503
504
505
506Stewart, et al. Informational [Page 9]
507
508RFC 6458 SCTP Sockets API December 2011
509
510
511 Here, SOCK_SEQPACKET indicates the creation of a one-to-many style
512 socket.
513
514 The function returns a socket descriptor, or -1 in case of an error.
515
516 Using the PF_INET domain indicates the creation of an endpoint that
517 can use only IPv4 addresses, while PF_INET6 creates an endpoint that
518 can use both IPv6 and IPv4 addresses.
519
5203.1.2. bind()
521
522 Applications use bind() to specify with which local address and port
523 the SCTP endpoint should associate itself.
524
525 An SCTP endpoint can be associated with multiple addresses. To do
526 this, sctp_bindx() is introduced in Section 9.1 to help applications
527 do the job of associating multiple addresses. But note that an
528 endpoint can only be associated with one local port.
529
530 These addresses associated with a socket are the eligible transport
531 addresses for the endpoint to send and receive data. The endpoint
532 will also present these addresses to its peers during the association
533 initialization process; see [RFC4960].
534
535 After calling bind(), if the endpoint wishes to accept new
536 associations on the socket, it must call listen() (see
537 Section 3.1.3).
538
539 The function prototype of bind() is
540
541 int bind(int sd,
542 struct sockaddr *addr,
543 socklen_t addrlen);
544
545 and the arguments are
546
547 sd: The socket descriptor returned by socket().
548
549 addr: The address structure (struct sockaddr_in for an IPv4 address
550 or struct sockaddr_in6 for an IPv6 address; see [RFC3493]).
551
552 addrlen: The size of the address structure.
553
554 bind() returns 0 on success and -1 in case of an error.
555
556 If sd is an IPv4 socket, the address passed must be an IPv4 address.
557 If the sd is an IPv6 socket, the address passed can either be an IPv4
558 or an IPv6 address.
559
560
561
562Stewart, et al. Informational [Page 10]
563
564RFC 6458 SCTP Sockets API December 2011
565
566
567 Applications cannot call bind() multiple times to associate multiple
568 addresses to an endpoint. After the first call to bind(), all
569 subsequent calls will return an error.
570
571 If the IP address part of addr is specified as a wildcard (INADDR_ANY
572 for an IPv4 address, or as IN6ADDR_ANY_INIT or in6addr_any for an
573 IPv6 address), the operating system will associate the endpoint with
574 an optimal address set of the available interfaces. If the IPv4
575 sin_port or IPv6 sin6_port is set to 0, the operating system will
576 choose an ephemeral port for the endpoint.
577
578 If bind() is not called prior to a sendmsg() call that initiates a
579 new association, the system picks an ephemeral port and will choose
580 an address set equivalent to binding with a wildcard address. One of
581 those addresses will be the primary address for the association.
582 This automatically enables the multi-homing capability of SCTP.
583
584 The completion of this bind() process does not allow the SCTP
585 endpoint to accept inbound SCTP association requests. Until a
586 listen() system call, described below, is performed on the socket,
587 the SCTP endpoint will promptly reject an inbound SCTP INIT request
588 with an SCTP ABORT.
589
5903.1.3. listen()
591
592 By default, a one-to-many style socket does not accept new
593 association requests. An application uses listen() to mark a socket
594 as being able to accept new associations.
595
596 The function prototype is
597
598 int listen(int sd,
599 int backlog);
600
601 and the arguments are
602
603 sd: The socket descriptor of the endpoint.
604
605 backlog: If backlog is non-zero, enable listening, else disable
606 listening.
607
608 listen() returns 0 on success and -1 in case of an error.
609
610 Note that one-to-many style socket consumers do not need to call
611 accept() to retrieve new associations. Calling accept() on a one-to-
612 many style socket should return EOPNOTSUPP. Rather, new associations
613 are accepted automatically, and notifications of the new associations
614 are delivered via recvmsg() with the SCTP_ASSOC_CHANGE event (if
615
616
617
618Stewart, et al. Informational [Page 11]
619
620RFC 6458 SCTP Sockets API December 2011
621
622
623 these notifications are enabled). Clients will typically not call
624 listen(), so that they can be assured that only actively initiated
625 associations are possible on the socket. Server or peer-to-peer
626 sockets, on the other hand, will always accept new associations, so a
627 well-written application using server one-to-many style sockets must
628 be prepared to handle new associations from unwanted peers.
629
630 Also note that the SCTP_ASSOC_CHANGE event provides the association
631 identifier for a new association, so if applications wish to use the
632 association identifier as a parameter to other socket calls, they
633 should ensure that the SCTP_ASSOC_CHANGE event is enabled.
634
6353.1.4. sendmsg() and recvmsg()
636
637 An application uses the sendmsg() and recvmsg() calls to transmit
638 data to and receive data from its peer.
639
640 The function prototypes are
641
642 ssize_t sendmsg(int sd,
643 const struct msghdr *message,
644 int flags);
645
646 and
647
648 ssize_t recvmsg(int sd,
649 struct msghdr *message,
650 int flags);
651
652 using the following arguments:
653
654 sd: The socket descriptor of the endpoint.
655
656 message: Pointer to the msghdr structure that contains a single user
657 message and possibly some ancillary data. See Section 5 for a
658 complete description of the data structures.
659
660 flags: No new flags are defined for SCTP at this level. See
661 Section 5 for SCTP-specific flags used in the msghdr structure.
662
663 sendmsg() returns the number of bytes accepted by the kernel or -1 in
664 case of an error. recvmsg() returns the number of bytes received or
665 -1 in case of an error.
666
667
668
669
670
671
672
673
674Stewart, et al. Informational [Page 12]
675
676RFC 6458 SCTP Sockets API December 2011
677
678
679 As described in Section 5, different types of ancillary data can be
680 sent and received along with user data. When sending, the ancillary
681 data is used to specify the sent behavior, such as the SCTP stream
682 number to use. When receiving, the ancillary data is used to
683 describe the received data, such as the SCTP stream sequence number
684 of the message.
685
686 When sending user data with sendmsg(), the msg_name field in the
687 msghdr structure will be filled with one of the transport addresses
688 of the intended receiver. If there is no existing association
689 between the sender and the intended receiver, the sender's SCTP stack
690 will set up a new association and then send the user data (see
691 Section 7.5 for more on implicit association setup). If sendmsg() is
692 called with no data and there is no existing association, a new one
693 will be established. The SCTP_INIT type ancillary data can be used
694 to change some of the parameters used to set up a new association.
695 If sendmsg() is called with NULL data, and there is no existing
696 association but the SCTP_ABORT or SCTP_EOF flags are set as described
697 in Section 5.3.4, then -1 is returned and errno is set to EINVAL.
698 Sending a message using sendmsg() is atomic unless explicit end of
699 record (EOR) marking is enabled on the socket specified by sd (see
700 Section 8.1.26).
701
702 If a peer sends a SHUTDOWN, an SCTP_SHUTDOWN_EVENT notification will
703 be delivered if that notification has been enabled, and no more data
704 can be sent to that association. Any attempt to send more data will
705 cause sendmsg() to return with an ESHUTDOWN error. Note that the
706 socket is still open for reading at this point, so it is possible to
707 retrieve notifications.
708
709 When receiving a user message with recvmsg(), the msg_name field in
710 the msghdr structure will be populated with the source transport
711 address of the user data. The caller of recvmsg() can use this
712 address information to determine to which association the received
713 user message belongs. Note that if SCTP_ASSOC_CHANGE events are
714 disabled, applications must use the peer transport address provided
715 in the msg_name field by recvmsg() to perform correlation to an
716 association, since they will not have the association identifier.
717
718 If all data in a single message has been delivered, MSG_EOR will be
719 set in the msg_flags field of the msghdr structure (see Section 5.1).
720
721 If the application does not provide enough buffer space to completely
722 receive a data message, MSG_EOR will not be set in msg_flags.
723 Successive reads will consume more of the same message until the
724 entire message has been delivered, and MSG_EOR will be set.
725
726
727
728
729
730Stewart, et al. Informational [Page 13]
731
732RFC 6458 SCTP Sockets API December 2011
733
734
735 If the SCTP stack is running low on buffers, it may partially deliver
736 a message. In this case, MSG_EOR will not be set, and more calls to
737 recvmsg() will be necessary to completely consume the message. Only
738 one message at a time can be partially delivered in any stream. The
739 socket option SCTP_FRAGMENT_INTERLEAVE controls various aspects of
740 what interlacing of messages occurs for both the one-to-one and the
741 one-to-many style sockets. Please consult Section 8.1.20 for further
742 details on message delivery options.
743
7443.1.5. close()
745
746 Applications use close() to perform graceful shutdown (as described
747 in Section 10.1 of [RFC4960]) on all of the associations currently
748 represented by a one-to-many style socket.
749
750 The function prototype is
751
752 int close(int sd);
753
754 and the argument is
755
756 sd: The socket descriptor of the associations to be closed.
757
758 0 is returned on success and -1 in case of an error.
759
760 To gracefully shut down a specific association represented by the
761 one-to-many style socket, an application should use the sendmsg()
762 call and include the SCTP_EOF flag. A user may optionally terminate
763 an association non-gracefully by using sendmsg() with the SCTP_ABORT
764 flag set and possibly passing a user-specified abort code in the data
765 field. Both flags SCTP_EOF and SCTP_ABORT are passed with ancillary
766 data (see Section 5.3.4) in the sendmsg() call.
767
768 If sd in the close() call is a branched-off socket representing only
769 one association, the shutdown is performed on that association only.
770
7713.1.6. connect()
772
773 An application may use the connect() call in the one-to-many style to
774 initiate an association without sending data.
775
776 The function prototype is
777
778 int connect(int sd,
779 const struct sockaddr *nam,
780 socklen_t len);
781
782
783
784
785
786Stewart, et al. Informational [Page 14]
787
788RFC 6458 SCTP Sockets API December 2011
789
790
791 and the arguments are
792
793 sd: The socket descriptor to which a new association is added.
794
795 nam: The address structure (struct sockaddr_in for an IPv4 address
796 or struct sockaddr_in6 for an IPv6 address; see [RFC3493]).
797
798 len: The size of the address.
799
800 0 is returned on success and -1 in case of an error.
801
802 Multiple connect() calls can be made on the same socket to create
803 multiple associations. This is different from the semantics of
804 connect() on a UDP socket.
805
806 Note that SCTP allows data exchange, similar to T/TCP [RFC1644] (made
807 Historic by [RFC6247]), during the association setup phase. If an
808 application wants to do this, it cannot use the connect() call.
809 Instead, it should use sendto() or sendmsg() to initiate an
810 association. If it uses sendto() and it wants to change the
811 initialization behavior, it needs to use the SCTP_INITMSG socket
812 option before calling sendto(). Or it can use sendmsg() with
813 SCTP_INIT type ancillary data to initiate an association without
814 calling setsockopt(). Note that the implicit setup is supported for
815 the one-to-many style sockets.
816
817 SCTP does not support half close semantics. This means that unlike
818 T/TCP, MSG_EOF should not be set in the flags parameter when calling
819 sendto() or sendmsg() when the call is used to initiate a connection.
820 MSG_EOF is not an acceptable flag with an SCTP socket.
821
8223.2. Non-Blocking Mode
823
824 Some SCTP applications may wish to avoid being blocked when calling a
825 socket interface function.
826
827 Once a bind() call and/or subsequent sctp_bindx() calls are complete
828 on a one-to-many style socket, an application may set the
829 non-blocking option via a fcntl() (such as O_NONBLOCK). After
830 setting the socket to non-blocking mode, the sendmsg() function
831 returns immediately. The success or failure of sending the data
832 message (with possible SCTP_INITMSG ancillary data) will be signaled
833 by the SCTP_ASSOC_CHANGE event with SCTP_COMM_UP or
834 SCTP_CANT_START_ASSOC. If user data could not be sent (due to an
835 SCTP_CANT_START_ASSOC), the sender will also receive an
836 SCTP_SEND_FAILED_EVENT event. Events can be received by the user
837 calling recvmsg(). A server (having called listen()) is also
838
839
840
841
842Stewart, et al. Informational [Page 15]
843
844RFC 6458 SCTP Sockets API December 2011
845
846
847 notified of an association-up event via the reception of an
848 SCTP_ASSOC_CHANGE with SCTP_COMM_UP via the calling of recvmsg() and
849 possibly the reception of the first data message.
850
851 To shut down the association gracefully, the user must call sendmsg()
852 with no data and with the SCTP_EOF flag set as described in
853 Section 5.3.4. The function returns immediately, and completion of
854 the graceful shutdown is indicated by an SCTP_ASSOC_CHANGE
855 notification of type SCTP_SHUTDOWN_COMP (see Section 6.1.1). Note
856 that this can also be done using the sctp_sendv() call described in
857 Section 9.12.
858
859 It is recommended that an application use caution when using select()
860 (or poll()) for writing on a one-to-many style socket, because the
861 interpretation of select() on write is implementation specific.
862 Generally, a positive return on a select() on write would only
863 indicate that one of the associations represented by the one-to-many
864 style socket is writable. An application that writes after the
865 select() returns may still block, since the association that was
866 writable is not the destination association of the write call.
867 Likewise, select() (or poll()) for reading from a one-to-many style
868 socket will only return an indication that one of the associations
869 represented by the socket has data to be read.
870
871 An application that wishes to know that a particular association is
872 ready for reading or writing should either use the one-to-one style
873 or use the sctp_peeloff() function (see Section 9.2) to separate the
874 association of interest from the one-to-many style socket.
875
876 Note that some implementations may have an extended select call, such
877 as epoll or kqueue, that may escape this limitation and allow a
878 select on a specific association of a one-to-many style socket, but
879 this is an implementation-specific detail that a portable application
880 cannot depend on.
881
8823.3. Special Considerations
883
884 The fact that a one-to-many style socket can provide access to many
885 SCTP associations through a single socket descriptor has important
886 implications for both application programmers and system programmers
887 implementing this API. A key issue is how buffer space inside the
888 sockets layer is managed. Because this implementation detail
889 directly affects how application programmers must write their code to
890 ensure correct operation and portability, this section provides some
891 guidance to both implementers and application programmers.
892
893
894
895
896
897
898Stewart, et al. Informational [Page 16]
899
900RFC 6458 SCTP Sockets API December 2011
901
902
903 An important feature that SCTP shares with TCP is flow control.
904 Specifically, a sender may not send data faster than the receiver can
905 consume it.
906
907 For TCP, flow control is typically provided for in the sockets API as
908 follows. If the reader stops reading, the sender queues messages in
909 the socket layer until the send socket buffer is completely filled.
910 This results in a "stalled connection". Further attempts to write to
911 the socket will block or return the error EAGAIN or EWOULDBLOCK for a
912 non-blocking socket. At some point, either the connection is closed,
913 or the receiver begins to read, again freeing space in the output
914 queue.
915
916 For one-to-one style SCTP sockets (this includes sockets descriptors
917 that were separated from a one-to-many style socket with
918 sctp_peeloff()), the behavior is identical. For one-to-many style
919 SCTP sockets, there are multiple associations for a single socket,
920 which makes the situation more complicated. If the implementation
921 uses a single buffer space allocation shared by all associations, a
922 single stalled association can prevent the further sending of data on
923 all associations active on a particular one-to-many style socket.
924
925 For a blocking socket, it should be clear that a single stalled
926 association can block the entire socket. For this reason,
927 application programmers may want to use non-blocking one-to-many
928 style sockets. The application should at least be able to send
929 messages to the non-stalled associations.
930
931 But a non-blocking socket is not sufficient if the API implementer
932 has chosen a single shared buffer allocation for the socket. A
933 single stalled association would eventually cause the shared
934 allocation to fill, and it would become impossible to send even to
935 non-stalled associations.
936
937 The API implementer can solve this problem by providing each
938 association with its own allocation of outbound buffer space. Each
939 association should conceptually have as much buffer space as it would
940 have if it had its own socket. As a bonus, this simplifies the
941 implementation of sctp_peeloff().
942
943 To ensure that a given stalled association will not prevent other
944 non-stalled associations from being writable, application programmers
945 should either
946
947 o demand that the underlying implementation dedicates independent
948 buffer space reservation to each association (as suggested
949 above), or
950
951
952
953
954Stewart, et al. Informational [Page 17]
955
956RFC 6458 SCTP Sockets API December 2011
957
958
959 o verify that their application-layer protocol does not permit large
960 amounts of unread data at the receiver (this is true of some
961 request-response protocols, for example), or
962
963 o use one-to-one style sockets for association, which may
964 potentially stall (either from the beginning, or by using
965 sctp_peeloff() before sending large amounts of data that may cause
966 a stalled condition).
967
9684. One-to-One Style Interface
969
970 The goal of this style is to follow as closely as possible the
971 current practice of using the sockets interface for a connection-
972 oriented protocol such as TCP. This style enables existing
973 applications using connection-oriented protocols to be ported to SCTP
974 with very little effort.
975
976 One-to-one style sockets can be connected (explicitly or implicitly)
977 at most once, similar to TCP sockets.
978
979 Note that some new SCTP features and some new SCTP socket options can
980 only be utilized through the use of sendmsg() and recvmsg() calls;
981 see Section 4.1.8.
982
9834.1. Basic Operation
984
985 A typical one-to-one style server uses the following system call
986 sequence to prepare an SCTP endpoint for servicing requests:
987
988 o socket()
989
990 o bind()
991
992 o listen()
993
994 o accept()
995
996 The accept() call blocks until a new association is set up. It
997 returns with a new socket descriptor. The server then uses the new
998 socket descriptor to communicate with the client, using recv() and
999 send() calls to get requests and send back responses.
1000
1001 Then it calls
1002
1003 o close()
1004
1005 to terminate the association.
1006
1007
1008
1009
1010Stewart, et al. Informational [Page 18]
1011
1012RFC 6458 SCTP Sockets API December 2011
1013
1014
1015 A typical client uses the following system call sequence to set up an
1016 association with a server to request services:
1017
1018 o socket()
1019
1020 o connect()
1021
1022 After returning from the connect() call, the client uses send()/
1023 sendmsg() and recv()/recvmsg() calls to send out requests and receive
1024 responses from the server.
1025
1026 The client calls
1027
1028 o close()
1029
1030 to terminate this association when done.
1031
10324.1.1. socket()
1033
1034 Applications call socket() to create a socket descriptor to represent
1035 an SCTP endpoint.
1036
1037 The function prototype is
1038
1039 int socket(int domain,
1040 int type,
1041 int protocol);
1042
1043 and one uses PF_INET or PF_INET6 as the domain, SOCK_STREAM as the
1044 type, and IPPROTO_SCTP as the protocol.
1045
1046 Here, SOCK_STREAM indicates the creation of a one-to-one style
1047 socket.
1048
1049 Using the PF_INET domain indicates the creation of an endpoint that
1050 can use only IPv4 addresses, while PF_INET6 creates an endpoint that
1051 can use both IPv6 and IPv4 addresses.
1052
10534.1.2. bind()
1054
1055 Applications use bind() to specify with which local address and port
1056 the SCTP endpoint should associate itself.
1057
1058 An SCTP endpoint can be associated with multiple addresses. To do
1059 this, sctp_bindx() is introduced in Section 9.1 to help applications
1060 do the job of associating multiple addresses. But note that an
1061 endpoint can only be associated with one local port.
1062
1063
1064
1065
1066Stewart, et al. Informational [Page 19]
1067
1068RFC 6458 SCTP Sockets API December 2011
1069
1070
1071 These addresses associated with a socket are the eligible transport
1072 addresses for the endpoint to send and receive data. The endpoint
1073 will also present these addresses to its peers during the association
1074 initialization process; see [RFC4960].
1075
1076 The function prototype of bind() is
1077
1078 int bind(int sd,
1079 struct sockaddr *addr,
1080 socklen_t addrlen);
1081
1082 and the arguments are
1083
1084 sd: The socket descriptor returned by socket().
1085
1086 addr: The address structure (struct sockaddr_in for an IPv4 address
1087 or struct sockaddr_in6 for an IPv6 address; see [RFC3493]).
1088
1089 addrlen: The size of the address structure.
1090
1091 If sd is an IPv4 socket, the address passed must be an IPv4 address.
1092 If sd is an IPv6 socket, the address passed can either be an IPv4 or
1093 an IPv6 address.
1094
1095 Applications cannot call bind() multiple times to associate multiple
1096 addresses to the endpoint. After the first call to bind(), all
1097 subsequent calls will return an error.
1098
1099 If the IP address part of addr is specified as a wildcard (INADDR_ANY
1100 for an IPv4 address, or as IN6ADDR_ANY_INIT or in6addr_any for an
1101 IPv6 address), the operating system will associate the endpoint with
1102 an optimal address set of the available interfaces. If the IPv4
1103 sin_port or IPv6 sin6_port is set to 0, the operating system will
1104 choose an ephemeral port for the endpoint.
1105
1106 If bind() is not called prior to the connect() call, the system picks
1107 an ephemeral port and will choose an address set equivalent to
1108 binding with a wildcard address. One of these addresses will be the
1109 primary address for the association. This automatically enables the
1110 multi-homing capability of SCTP.
1111
1112 The completion of this bind() process does not allow the SCTP
1113 endpoint to accept inbound SCTP association requests. Until a
1114 listen() system call, described below, is performed on the socket,
1115 the SCTP endpoint will promptly reject an inbound SCTP INIT request
1116 with an SCTP ABORT.
1117
1118
1119
1120
1121
1122Stewart, et al. Informational [Page 20]
1123
1124RFC 6458 SCTP Sockets API December 2011
1125
1126
11274.1.3. listen()
1128
1129 Applications use listen() to allow the SCTP endpoint to accept
1130 inbound associations.
1131
1132 The function prototype is
1133
1134 int listen(int sd,
1135 int backlog);
1136
1137 and the arguments are
1138
1139 sd: The socket descriptor of the SCTP endpoint.
1140
1141 backlog: Specifies the max number of outstanding associations
1142 allowed in the socket's accept queue. These are the associations
1143 that have finished the four-way initiation handshake (see
1144 Section 5 of [RFC4960]) and are in the ESTABLISHED state. Note
1145 that a backlog of '0' indicates that the caller no longer wishes
1146 to receive new associations.
1147
1148 listen() returns 0 on success and -1 in case of an error.
1149
11504.1.4. accept()
1151
1152 Applications use the accept() call to remove an established SCTP
1153 association from the accept queue of the endpoint. A new socket
1154 descriptor will be returned from accept() to represent the newly
1155 formed association.
1156
1157 The function prototype is
1158
1159 int accept(int sd,
1160 struct sockaddr *addr,
1161 socklen_t *addrlen);
1162
1163 and the arguments are
1164
1165 sd: The listening socket descriptor.
1166
1167 addr: On return, addr (struct sockaddr_in for an IPv4 address or
1168 struct sockaddr_in6 for an IPv6 address; see [RFC3493]) will
1169 contain the primary address of the peer endpoint.
1170
1171 addrlen: On return, addrlen will contain the size of addr.
1172
1173 The function returns the socket descriptor for the newly formed
1174 association on success and -1 in case of an error.
1175
1176
1177
1178Stewart, et al. Informational [Page 21]
1179
1180RFC 6458 SCTP Sockets API December 2011
1181
1182
11834.1.5. connect()
1184
1185 Applications use connect() to initiate an association to a peer.
1186
1187 The function prototype is
1188
1189 int connect(int sd,
1190 const struct sockaddr *addr,
1191 socklen_t addrlen);
1192
1193 and the arguments are
1194
1195 sd: The socket descriptor of the endpoint.
1196
1197 addr: The peer's (struct sockaddr_in for an IPv4 address or struct
1198 sockaddr_in6 for an IPv6 address; see [RFC3493]) address.
1199
1200 addrlen: The size of the address.
1201
1202 connect() returns 0 on success and -1 on error.
1203
1204 This operation corresponds to the ASSOCIATE primitive described in
1205 Section 10.1 of [RFC4960].
1206
1207 The number of outbound streams the new association has is stack
1208 dependent. Before connecting, applications can use the SCTP_INITMSG
1209 option described in Section 8.1.3 to change the number of outbound
1210 streams.
1211
1212 If bind() is not called prior to the connect() call, the system picks
1213 an ephemeral port and will choose an address set equivalent to
1214 binding with INADDR_ANY and IN6ADDR_ANY_INIT for IPv4 and IPv6
1215 sockets, respectively. One of the addresses will be the primary
1216 address for the association. This automatically enables the
1217 multi-homing capability of SCTP.
1218
1219 Note that SCTP allows data exchange, similar to T/TCP [RFC1644] (made
1220 Historic by [RFC6247]), during the association setup phase. If an
1221 application wants to do this, it cannot use the connect() call.
1222 Instead, it should use sendto() or sendmsg() to initiate an
1223 association. If it uses sendto() and it wants to change the
1224 initialization behavior, it needs to use the SCTP_INITMSG socket
1225 option before calling sendto(). Or it can use sendmsg() with
1226 SCTP_INIT type ancillary data to initiate an association without
1227 calling setsockopt(). Note that the implicit setup is supported for
1228 the one-to-one style sockets.
1229
1230
1231
1232
1233
1234Stewart, et al. Informational [Page 22]
1235
1236RFC 6458 SCTP Sockets API December 2011
1237
1238
1239 SCTP does not support half close semantics. This means that unlike
1240 T/TCP, MSG_EOF should not be set in the flags parameter when calling
1241 sendto() or sendmsg() when the call is used to initiate a connection.
1242 MSG_EOF is not an acceptable flag with an SCTP socket.
1243
12444.1.6. close()
1245
1246 Applications use close() to gracefully close down an association.
1247
1248 The function prototype is
1249
1250 int close(int sd);
1251
1252 and the argument is
1253
1254 sd: The socket descriptor of the association to be closed.
1255
1256 close() returns 0 on success and -1 in case of an error.
1257
1258 After an application calls close() on a socket descriptor, no further
1259 socket operations will succeed on that descriptor.
1260
12614.1.7. shutdown()
1262
1263 SCTP differs from TCP in that it does not have half close semantics.
1264 Hence, the shutdown() call for SCTP is an approximation of the TCP
1265 shutdown() call, and solves some different problems. Full TCP
1266 compatibility is not provided, so developers porting TCP applications
1267 to SCTP may need to recode sections that use shutdown(). (Note that
1268 it is possible to achieve the same results as half close in SCTP
1269 using SCTP streams.)
1270
1271 The function prototype is
1272
1273 int shutdown(int sd,
1274 int how);
1275
1276 and the arguments are
1277
1278 sd: The socket descriptor of the association to be closed.
1279
1280 how: Specifies the type of shutdown. The values are as follows:
1281
1282 SHUT_RD: Disables further receive operations. No SCTP protocol
1283 action is taken.
1284
1285 SHUT_WR: Disables further send operations, and initiates the SCTP
1286 shutdown sequence.
1287
1288
1289
1290Stewart, et al. Informational [Page 23]
1291
1292RFC 6458 SCTP Sockets API December 2011
1293
1294
1295 SHUT_RDWR: Disables further send and receive operations, and
1296 initiates the SCTP shutdown sequence.
1297
1298 shutdown() returns 0 on success and -1 in case of an error.
1299
1300 The major difference between SCTP and TCP shutdown() is that SCTP
1301 SHUT_WR initiates immediate and full protocol shutdown, whereas TCP
1302 SHUT_WR causes TCP to go into the half close state. SHUT_RD behaves
1303 the same for SCTP as for TCP. The purpose of SCTP SHUT_WR is to
1304 close the SCTP association while still leaving the socket descriptor
1305 open. This allows the caller to receive back any data that SCTP is
1306 unable to deliver (see Section 6.1.4 for more information) and
1307 receive event notifications.
1308
1309 To perform the ABORT operation described in Section 10.1 of
1310 [RFC4960], an application can use the socket option SO_LINGER.
1311 SO_LINGER is described in Section 8.1.4.
1312
13134.1.8. sendmsg() and recvmsg()
1314
1315 With a one-to-one style socket, the application can also use
1316 sendmsg() and recvmsg() to transmit data to and receive data from its
1317 peer. The semantics is similar to those used in the one-to-many
1318 style (see Section 3.1.4), with the following differences:
1319
1320 1. When sending, the msg_name field in the msghdr is not used to
1321 specify the intended receiver; rather, it is used to indicate a
1322 preferred peer address if the sender wishes to discourage the
1323 stack from sending the message to the primary address of the
1324 receiver. If the socket is connected and the transport address
1325 given is not part of the current association, the data will not
1326 be sent, and an SCTP_SEND_FAILED_EVENT event will be delivered to
1327 the application if send failure events are enabled.
1328
1329 2. Using sendmsg() on a non-connected one-to-one style socket for
1330 implicit connection setup may or may not work, depending on the
1331 SCTP implementation.
1332
13334.1.9. getpeername()
1334
1335 Applications use getpeername() to retrieve the primary socket address
1336 of the peer. This call is for TCP compatibility and is not
1337 multi-homed. It may not work with one-to-many style sockets,
1338 depending on the implementation. See Section 9.3 for a multi-homed
1339 style version of the call.
1340
1341
1342
1343
1344
1345
1346Stewart, et al. Informational [Page 24]
1347
1348RFC 6458 SCTP Sockets API December 2011
1349
1350
1351 The function prototype is
1352
1353 int getpeername(int sd,
1354 struct sockaddr *address,
1355 socklen_t *len);
1356
1357 and the arguments are
1358
1359 sd: The socket descriptor to be queried.
1360
1361 address: On return, the peer primary address is stored in this
1362 buffer. If the socket is an IPv4 socket, the address will be
1363 IPv4. If the socket is an IPv6 socket, the address will be either
1364 an IPv6 or IPv4 address.
1365
1366 len: The caller should set the length of address here. On return,
1367 this is set to the length of the returned address.
1368
1369 getpeername() returns 0 on success and -1 in case of an error.
1370
1371 If the actual length of the address is greater than the length of the
1372 supplied sockaddr structure, the stored address will be truncated.
1373
13745. Data Structures
1375
1376 This section discusses important data structures that are specific to
1377 SCTP and are used with sendmsg() and recvmsg() calls to control SCTP
1378 endpoint operations and to access ancillary information and
1379 notifications.
1380
13815.1. The msghdr and cmsghdr Structures
1382
1383 The msghdr structure used in the sendmsg() and recvmsg() calls, as
1384 well as the ancillary data carried in the structure, is the key for
1385 the application to set and get various control information from the
1386 SCTP endpoint.
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402Stewart, et al. Informational [Page 25]
1403
1404RFC 6458 SCTP Sockets API December 2011
1405
1406
1407 The msghdr and the related cmsghdr structures are defined and
1408 discussed in detail in [RFC3542]. They are defined as
1409
1410 struct msghdr {
1411 void *msg_name; /* ptr to socket address structure */
1412 socklen_t msg_namelen; /* size of socket address structure */
1413 struct iovec *msg_iov; /* scatter/gather array */
1414 int msg_iovlen; /* # elements in msg_iov */
1415 void *msg_control; /* ancillary data */
1416 socklen_t msg_controllen; /* ancillary data buffer length */
1417 int msg_flags; /* flags on received message */
1418 };
1419
1420 struct cmsghdr {
1421 socklen_t cmsg_len; /* # bytes, including this header */
1422 int cmsg_level; /* originating protocol */
1423 int cmsg_type; /* protocol-specific type */
1424 /* followed by unsigned char cmsg_data[]; */
1425 };
1426
1427 In the msghdr structure, the usage of msg_name has been discussed in
1428 previous sections (see Sections 3.1.4 and 4.1.8).
1429
1430 The scatter/gather buffers, or I/O vectors (pointed to by the msg_iov
1431 field) are treated by SCTP as a single user message for both
1432 sendmsg() and recvmsg().
1433
1434 The SCTP stack uses the ancillary data (msg_control field) to
1435 communicate the attributes, such as SCTP_RCVINFO, of the message
1436 stored in msg_iov to the socket endpoint. The different ancillary
1437 data types are described in Section 5.3.
1438
1439 The msg_flags are not used when sending a message with sendmsg().
1440
1441 If a notification has arrived, recvmsg() will return the notification
1442 in the msg_iov field and set the MSG_NOTIFICATION flag in msg_flags.
1443 If the MSG_NOTIFICATION flag is not set, recvmsg() will return data.
1444 See Section 6 for more information about notifications.
1445
1446 If all portions of a data frame or notification have been read,
1447 recvmsg() will return with MSG_EOR set in msg_flags.
1448
14495.2. Ancillary Data Considerations and Semantics
1450
1451 Programming with ancillary socket data (msg_control) contains some
1452 subtleties and pitfalls, which are discussed below.
1453
1454
1455
1456
1457
1458Stewart, et al. Informational [Page 26]
1459
1460RFC 6458 SCTP Sockets API December 2011
1461
1462
14635.2.1. Multiple Items and Ordering
1464
1465 Multiple ancillary data items may be included in any call to
1466 sendmsg() or recvmsg(); these may include multiple SCTP items,
1467 non-SCTP items (such as IP-level items), or both.
1468
1469 The ordering of ancillary data items (either by SCTP or another
1470 protocol) is not significant and is implementation dependent, so
1471 applications must not depend on any ordering.
1472
1473 SCTP_SNDRCV/SCTP_SNDINFO/SCTP_RCVINFO type ancillary data always
1474 corresponds to the data in the msghdr's msg_iov member. There can be
1475 only one such type of ancillary data for each sendmsg() or recvmsg()
1476 call.
1477
14785.2.2. Accessing and Manipulating Ancillary Data
1479
1480 Applications can infer the presence of data or ancillary data by
1481 examining the msg_iovlen and msg_controllen msghdr members,
1482 respectively.
1483
1484 Implementations may have different padding requirements for ancillary
1485 data, so portable applications should make use of the macros
1486 CMSG_FIRSTHDR, CMSG_NXTHDR, CMSG_DATA, CMSG_SPACE, and CMSG_LEN. See
1487 [RFC3542] and the SCTP implementation's documentation for more
1488 information. The following is an example, from [RFC3542],
1489 demonstrating the use of these macros to access ancillary data:
1490
1491 struct msghdr msg;
1492 struct cmsghdr *cmsgptr;
1493
1494 /* fill in msg */
1495
1496 /* call recvmsg() */
1497
1498 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
1499 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
1500 if (cmsgptr->cmsg_len == 0) {
1501 /* Error handling */
1502 break;
1503 }
1504 if (cmsgptr->cmsg_level == ... && cmsgptr->cmsg_type == ... ) {
1505 u_char *ptr;
1506
1507 ptr = CMSG_DATA(cmsgptr);
1508 /* process data pointed to by ptr */
1509 }
1510 }
1511
1512
1513
1514Stewart, et al. Informational [Page 27]
1515
1516RFC 6458 SCTP Sockets API December 2011
1517
1518
15195.2.3. Control Message Buffer Sizing
1520
1521 The information conveyed via SCTP_SNDRCV/SCTP_SNDINFO/SCTP_RCVINFO
1522 ancillary data will often be fundamental to the correct and sane
1523 operation of the sockets application. This is particularly true for
1524 one-to-many style sockets, but also for one-to-one style sockets.
1525 For example, if an application needs to send and receive data on
1526 different SCTP streams, SCTP_SNDRCV/SCTP_SNDINFO/SCTP_RCVINFO
1527 ancillary data is indispensable.
1528
1529 Given that some ancillary data is critical, and that multiple
1530 ancillary data items may appear in any order, applications should be
1531 carefully written to always provide a large enough buffer to contain
1532 all possible ancillary data that can be presented by recvmsg(). If
1533 the buffer is too small, and crucial data is truncated, it may pose a
1534 fatal error condition.
1535
1536 Thus, it is essential that applications be able to deterministically
1537 calculate the maximum required buffer size to pass to recvmsg(). One
1538 constraint imposed on this specification that makes this possible is
1539 that all ancillary data definitions are of a fixed length. One way
1540 to calculate the maximum required buffer size might be to take the
1541 sum of the sizes of all enabled ancillary data item structures, as
1542 calculated by CMSG_SPACE. For example, if we enabled
1543 SCTP_SNDRCV_INFO and IPV6_RECVPKTINFO [RFC3542], we would calculate
1544 and allocate the buffer size as follows:
1545
1546 size_t total;
1547 void *buf;
1548
1549 total = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)) +
1550 CMSG_SPACE(sizeof(struct in6_pktinfo));
1551
1552 buf = malloc(total);
1553
1554 We could then use this buffer (buf) for msg_control on each call to
1555 recvmsg() and be assured that we would not lose any ancillary data to
1556 truncation.
1557
15585.3. SCTP msg_control Structures
1559
1560 A key element of all SCTP-specific socket extensions is the use of
1561 ancillary data to specify and access SCTP-specific data via the
1562 msghdr structure's msg_control member used in sendmsg() and
1563 recvmsg(). Fine-grained control over initialization and sending
1564 parameters are handled with ancillary data.
1565
1566
1567
1568
1569
1570Stewart, et al. Informational [Page 28]
1571
1572RFC 6458 SCTP Sockets API December 2011
1573
1574
1575 Each ancillary data item is preceded by a struct cmsghdr (see
1576 Section 5.1), which defines the function and purpose of the data
1577 contained in the cmsg_data[] member.
1578
1579 By default, on either style of socket, SCTP will pass no ancillary
1580 data. Specific ancillary data items can be enabled with socket
1581 options defined for SCTP; see Section 6.2.
1582
1583 Note that all ancillary types are of fixed length; see Section 5.2
1584 for further discussion on this. These data structures use struct
1585 sockaddr_storage (defined in [RFC3493]) as a portable, fixed-length
1586 address format.
1587
1588 Other protocols may also provide ancillary data to the socket layer
1589 consumer. These ancillary data items from other protocols may
1590 intermingle with SCTP data. For example, the IPv6 sockets API
1591 definitions ([RFC3542] and [RFC3493]) define a number of ancillary
1592 data items. If a sockets API consumer enables delivery of both SCTP
1593 and IPv6 ancillary data, they both may appear in the same msg_control
1594 buffer in any order. An application may thus need to handle other
1595 types of ancillary data besides those passed by SCTP.
1596
1597 The sockets application must provide a buffer large enough to
1598 accommodate all ancillary data provided via recvmsg(). If the buffer
1599 is not large enough, the ancillary data will be truncated and the
1600 msghdr's msg_flags will include MSG_CTRUNC.
1601
16025.3.1. SCTP Initiation Structure (SCTP_INIT)
1603
1604 This cmsghdr structure provides information for initializing new SCTP
1605 associations with sendmsg(). The SCTP_INITMSG socket option uses
1606 this same data structure. This structure is not used for recvmsg().
1607
1608 +--------------+-----------+---------------------+
1609 | cmsg_level | cmsg_type | cmsg_data[] |
1610 +--------------+-----------+---------------------+
1611 | IPPROTO_SCTP | SCTP_INIT | struct sctp_initmsg |
1612 +--------------+-----------+---------------------+
1613
1614 The sctp_initmsg structure is defined below:
1615
1616 struct sctp_initmsg {
1617 uint16_t sinit_num_ostreams;
1618 uint16_t sinit_max_instreams;
1619 uint16_t sinit_max_attempts;
1620 uint16_t sinit_max_init_timeo;
1621 };
1622
1623
1624
1625
1626Stewart, et al. Informational [Page 29]
1627
1628RFC 6458 SCTP Sockets API December 2011
1629
1630
1631 sinit_num_ostreams: This is an integer representing the number of
1632 streams to which the application wishes to be able to send. This
1633 number is confirmed in the SCTP_COMM_UP notification and must be
1634 verified, since it is a negotiated number with the remote
1635 endpoint. The default value of 0 indicates the use of the
1636 endpoint's default value.
1637
1638 sinit_max_instreams: This value represents the maximum number of
1639 inbound streams the application is prepared to support. This
1640 value is bounded by the actual implementation. In other words,
1641 the user may be able to support more streams than the operating
1642 system. In such a case, the operating-system limit overrides the
1643 value requested by the user. The default value of 0 indicates the
1644 use of the endpoint's default value.
1645
1646 sinit_max_attempts: This integer specifies how many attempts the
1647 SCTP endpoint should make at resending the INIT. This value
1648 overrides the system SCTP 'Max.Init.Retransmits' value. The
1649 default value of 0 indicates the use of the endpoint's default
1650 value. This is normally set to the system's default
1651 'Max.Init.Retransmit' value.
1652
1653 sinit_max_init_timeo: This value represents the largest timeout or
1654 retransmission timeout (RTO) value (in milliseconds) to use in
1655 attempting an INIT. Normally, the 'RTO.Max' is used to limit the
1656 doubling of the RTO upon timeout. For the INIT message, this
1657 value may override 'RTO.Max'. This value must not influence
1658 'RTO.Max' during data transmission and is only used to bound the
1659 initial setup time. A default value of 0 indicates the use of the
1660 endpoint's default value. This is normally set to the system's
1661 'RTO.Max' value (60 seconds).
1662
16635.3.2. SCTP Header Information Structure (SCTP_SNDRCV) - DEPRECATED
1664
1665 This cmsghdr structure specifies SCTP options for sendmsg() and
1666 describes SCTP header information about a received message through
1667 recvmsg(). This structure mixes the send and receive path.
1668 SCTP_SNDINFO (described in Section 5.3.4) and SCTP_RCVINFO (described
1669 in Section 5.3.5) split this information. These structures should be
1670 used, when possible, since SCTP_SNDRCV is deprecated.
1671
1672 +--------------+-------------+------------------------+
1673 | cmsg_level | cmsg_type | cmsg_data[] |
1674 +--------------+-------------+------------------------+
1675 | IPPROTO_SCTP | SCTP_SNDRCV | struct sctp_sndrcvinfo |
1676 +--------------+-------------+------------------------+
1677
1678
1679
1680
1681
1682Stewart, et al. Informational [Page 30]
1683
1684RFC 6458 SCTP Sockets API December 2011
1685
1686
1687 The sctp_sndrcvinfo structure is defined below:
1688
1689 struct sctp_sndrcvinfo {
1690 uint16_t sinfo_stream;
1691 uint16_t sinfo_ssn;
1692 uint16_t sinfo_flags;
1693 uint32_t sinfo_ppid;
1694 uint32_t sinfo_context;
1695 uint32_t sinfo_timetolive;
1696 uint32_t sinfo_tsn;
1697 uint32_t sinfo_cumtsn;
1698 sctp_assoc_t sinfo_assoc_id;
1699 };
1700
1701 sinfo_stream: For recvmsg(), the SCTP stack places the message's
1702 stream number in this value. For sendmsg(), this value holds the
1703 stream number to which the application wishes to send this
1704 message. If a sender specifies an invalid stream number, an error
1705 indication is returned and the call fails.
1706
1707 sinfo_ssn: For recvmsg(), this value contains the stream sequence
1708 number that the remote endpoint placed in the DATA chunk. For
1709 fragmented messages, this is the same number for all deliveries of
1710 the message (if more than one recvmsg() is needed to read the
1711 message). The sendmsg() call will ignore this parameter.
1712
1713 sinfo_flags: This field may contain any of the following flags and
1714 is composed of a bitwise OR of these values.
1715
1716 recvmsg() flags:
1717
1718 SCTP_UNORDERED: This flag is present when the message was sent
1719 unordered.
1720
1721 sendmsg() flags:
1722
1723 SCTP_UNORDERED: This flag requests the unordered delivery of
1724 the message. If this flag is clear, the datagram is
1725 considered an ordered send.
1726
1727 SCTP_ADDR_OVER: This flag, for a one-to-many style socket,
1728 requests that the SCTP stack override the primary
1729 destination address with the address found with the sendto/
1730 sendmsg call.
1731
1732
1733
1734
1735
1736
1737
1738Stewart, et al. Informational [Page 31]
1739
1740RFC 6458 SCTP Sockets API December 2011
1741
1742
1743 SCTP_ABORT: Setting this flag causes the specified association
1744 to abort by sending an ABORT message to the peer. The ABORT
1745 chunk will contain an error cause of 'User Initiated Abort'
1746 with cause code 12. The cause-specific information of this
1747 error cause is provided in msg_iov.
1748
1749 SCTP_EOF: Setting this flag invokes the SCTP graceful shutdown
1750 procedure on the specified association. Graceful shutdown
1751 assures that all data queued by both endpoints is
1752 successfully transmitted before closing the association.
1753
1754 SCTP_SENDALL: This flag, if set, will cause a one-to-many
1755 style socket to send the message to all associations that
1756 are currently established on this socket. For the one-to-
1757 one style socket, this flag has no effect.
1758
1759 sinfo_ppid: This value in sendmsg() is an unsigned integer that is
1760 passed to the remote end in each user message. In recvmsg(), this
1761 value is the same information that was passed by the upper layer
1762 in the peer application. Please note that the SCTP stack performs
1763 no byte order modification of this field. For example, if the
1764 DATA chunk has to contain a given value in network byte order, the
1765 SCTP user has to perform the htonl() computation.
1766
1767 sinfo_context: This value is an opaque 32-bit context datum that is
1768 used in the sendmsg() function. This value is passed back to the
1769 upper layer if an error occurs on the send of a message and is
1770 retrieved with each undelivered message.
1771
1772 sinfo_timetolive: For the sending side, this field contains the
1773 message's time to live, in milliseconds. The sending side will
1774 expire the message within the specified time period if the message
1775 has not been sent to the peer within this time period. This value
1776 will override any default value set using any socket option. Also
1777 note that the value of 0 is special in that it indicates no
1778 timeout should occur on this message.
1779
1780 sinfo_tsn: For the receiving side, this field holds a Transmission
1781 Sequence Number (TSN) that was assigned to one of the SCTP DATA
1782 chunks. For the sending side, it is ignored.
1783
1784 sinfo_cumtsn: This field will hold the current cumulative TSN as
1785 known by the underlying SCTP layer. Note that this field is
1786 ignored when sending.
1787
1788
1789
1790
1791
1792
1793
1794Stewart, et al. Informational [Page 32]
1795
1796RFC 6458 SCTP Sockets API December 2011
1797
1798
1799 sinfo_assoc_id: The association handle field, sinfo_assoc_id, holds
1800 the identifier for the association announced in the SCTP_COMM_UP
1801 notification. All notifications for a given association have the
1802 same identifier. This field is ignored for one-to-one style
1803 sockets.
1804
1805 An sctp_sndrcvinfo item always corresponds to the data in msg_iov.
1806
18075.3.3. Extended SCTP Header Information Structure (SCTP_EXTRCV) -
1808 DEPRECATED
1809
1810 This cmsghdr structure specifies SCTP options for SCTP header
1811 information about a received message via recvmsg(). Note that this
1812 structure is an extended version of SCTP_SNDRCV (see Section 5.3.2)
1813 and will only be received if the user has set the socket option
1814 SCTP_USE_EXT_RCVINFO (see Section 8.1.22) to true in addition to any
1815 event subscription needed to receive ancillary data. Note that data
1816 in the next message is not valid unless the current message is
1817 completely read, i.e., unless the MSG_EOR is set; in other words, if
1818 the application has more data to read from the current message, then
1819 no next-message information will be available.
1820
1821 SCTP_NXTINFO (described in Section 5.3.6) should be used when
1822 possible, since SCTP_EXTRCV is considered deprecated.
1823
1824 +--------------+-------------+------------------------+
1825 | cmsg_level | cmsg_type | cmsg_data[] |
1826 +--------------+-------------+------------------------+
1827 | IPPROTO_SCTP | SCTP_EXTRCV | struct sctp_extrcvinfo |
1828 +--------------+-------------+------------------------+
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850Stewart, et al. Informational [Page 33]
1851
1852RFC 6458 SCTP Sockets API December 2011
1853
1854
1855 The sctp_extrcvinfo structure is defined below:
1856
1857 struct sctp_extrcvinfo {
1858 uint16_t sinfo_stream;
1859 uint16_t sinfo_ssn;
1860 uint16_t sinfo_flags;
1861 uint32_t sinfo_ppid;
1862 uint32_t sinfo_context;
1863 uint32_t sinfo_pr_value;
1864 uint32_t sinfo_tsn;
1865 uint32_t sinfo_cumtsn;
1866 uint16_t serinfo_next_flags;
1867 uint16_t serinfo_next_stream;
1868 uint32_t serinfo_next_aid;
1869 uint32_t serinfo_next_length;
1870 uint32_t serinfo_next_ppid;
1871 sctp_assoc_t sinfo_assoc_id;
1872 };
1873
1874 sinfo_*: Please see Section 5.3.2 for details for these fields.
1875
1876 serinfo_next_flags: This bitmask will hold one or more of the
1877 following values:
1878
1879 SCTP_NEXT_MSG_AVAIL: This bit, when set to 1, indicates that
1880 next-message information is available; i.e., next_stream,
1881 next_aid, next_length, and next_ppid fields all have valid
1882 values. If this bit is set to 0, then these fields are not
1883 valid and should be ignored.
1884
1885 SCTP_NEXT_MSG_ISCOMPLETE: This bit, when set, indicates that the
1886 next message is completely in the receive buffer. The
1887 next_length field thus contains the entire message size. If
1888 this flag is set to 0, then the next_length field only contains
1889 part of the message size, since the message is still being
1890 received (it is being partially delivered).
1891
1892 SCTP_NEXT_MSG_IS_UNORDERED: This bit, when set, indicates that
1893 the next message to be received was sent by the peer as
1894 unordered. If this bit is not set (i.e., the bit is 0) the
1895 next message to be read is an ordered message in the stream
1896 specified.
1897
1898 SCTP_NEXT_MSG_IS_NOTIFICATION: This bit, when set, indicates that
1899 the next message to be received is not a message from the peer,
1900 but instead is a MSG_NOTIFICATION from the local SCTP stack.
1901
1902
1903
1904
1905
1906Stewart, et al. Informational [Page 34]
1907
1908RFC 6458 SCTP Sockets API December 2011
1909
1910
1911 serinfo_next_stream: This value, when valid (see
1912 serinfo_next_flags), contains the next stream number that will be
1913 received on a subsequent call to one of the receive message
1914 functions.
1915
1916 serinfo_next_aid: This value, when valid (see serinfo_next_flags),
1917 contains the next association identifier that will be received on
1918 a subsequent call to one of the receive message functions.
1919
1920 serinfo_next_length: This value, when valid (see
1921 serinfo_next_flags), contains the length of the next message that
1922 will be received on a subsequent call to one of the receive
1923 message functions. Note that this length may be a partial length,
1924 depending on the settings of next_flags.
1925
1926 serinfo_next_ppid: This value, when valid (see serinfo_next_flags),
1927 contains the ppid of the next message that will be received on a
1928 subsequent call to one of the receive message functions.
1929
19305.3.4. SCTP Send Information Structure (SCTP_SNDINFO)
1931
1932 This cmsghdr structure specifies SCTP options for sendmsg().
1933
1934 +--------------+--------------+---------------------+
1935 | cmsg_level | cmsg_type | cmsg_data[] |
1936 +--------------+--------------+---------------------+
1937 | IPPROTO_SCTP | SCTP_SNDINFO | struct sctp_sndinfo |
1938 +--------------+--------------+---------------------+
1939
1940 The sctp_sndinfo structure is defined below:
1941
1942 struct sctp_sndinfo {
1943 uint16_t snd_sid;
1944 uint16_t snd_flags;
1945 uint32_t snd_ppid;
1946 uint32_t snd_context;
1947 sctp_assoc_t snd_assoc_id;
1948 };
1949
1950 snd_sid: This value holds the stream number to which the application
1951 wishes to send this message. If a sender specifies an invalid
1952 stream number, an error indication is returned and the call fails.
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962Stewart, et al. Informational [Page 35]
1963
1964RFC 6458 SCTP Sockets API December 2011
1965
1966
1967 snd_flags: This field may contain any of the following flags and is
1968 composed of a bitwise OR of these values.
1969
1970 SCTP_UNORDERED: This flag requests the unordered delivery of the
1971 message. If this flag is clear, the datagram is considered an
1972 ordered send.
1973
1974 SCTP_ADDR_OVER: This flag, for a one-to-many style socket,
1975 requests that the SCTP stack override the primary destination
1976 address with the address found with the sendto()/sendmsg call.
1977
1978 SCTP_ABORT: Setting this flag causes the specified association to
1979 abort by sending an ABORT message to the peer. The ABORT chunk
1980 will contain an error cause of 'User Initiated Abort' with
1981 cause code 12. The cause-specific information of this error
1982 cause is provided in msg_iov.
1983
1984 SCTP_EOF: Setting this flag invokes the SCTP graceful shutdown
1985 procedures on the specified association. Graceful shutdown
1986 assures that all data queued by both endpoints is successfully
1987 transmitted before closing the association.
1988
1989 SCTP_SENDALL: This flag, if set, will cause a one-to-many style
1990 socket to send the message to all associations that are
1991 currently established on this socket. For the one-to-one style
1992 socket, this flag has no effect.
1993
1994 snd_ppid: This value in sendmsg() is an unsigned integer that is
1995 passed to the remote end in each user message. Please note that
1996 the SCTP stack performs no byte order modification of this field.
1997 For example, if the DATA chunk has to contain a given value in
1998 network byte order, the SCTP user has to perform the htonl()
1999 computation.
2000
2001 snd_context: This value is an opaque 32-bit context datum that is
2002 used in the sendmsg() function. This value is passed back to the
2003 upper layer if an error occurs on the send of a message and is
2004 retrieved with each undelivered message.
2005
2006 snd_assoc_id: The association handle field, sinfo_assoc_id, holds
2007 the identifier for the association announced in the SCTP_COMM_UP
2008 notification. All notifications for a given association have the
2009 same identifier. This field is ignored for one-to-one style
2010 sockets.
2011
2012 An sctp_sndinfo item always corresponds to the data in msg_iov.
2013
2014
2015
2016
2017
2018Stewart, et al. Informational [Page 36]
2019
2020RFC 6458 SCTP Sockets API December 2011
2021
2022
20235.3.5. SCTP Receive Information Structure (SCTP_RCVINFO)
2024
2025 This cmsghdr structure describes SCTP receive information about a
2026 received message through recvmsg().
2027
2028 To enable the delivery of this information, an application must use
2029 the SCTP_RECVRCVINFO socket option (see Section 8.1.29).
2030
2031 +--------------+--------------+---------------------+
2032 | cmsg_level | cmsg_type | cmsg_data[] |
2033 +--------------+--------------+---------------------+
2034 | IPPROTO_SCTP | SCTP_RCVINFO | struct sctp_rcvinfo |
2035 +--------------+--------------+---------------------+
2036
2037 The sctp_rcvinfo structure is defined below:
2038
2039 struct sctp_rcvinfo {
2040 uint16_t rcv_sid;
2041 uint16_t rcv_ssn;
2042 uint16_t rcv_flags;
2043 uint32_t rcv_ppid;
2044 uint32_t rcv_tsn;
2045 uint32_t rcv_cumtsn;
2046 uint32_t rcv_context;
2047 sctp_assoc_t rcv_assoc_id;
2048 };
2049
2050 rcv_sid: The SCTP stack places the message's stream number in this
2051 value.
2052
2053 rcv_ssn: This value contains the stream sequence number that the
2054 remote endpoint placed in the DATA chunk. For fragmented
2055 messages, this is the same number for all deliveries of the
2056 message (if more than one recvmsg() is needed to read the
2057 message).
2058
2059 rcv_flags: This field may contain any of the following flags and is
2060 composed of a bitwise OR of these values.
2061
2062 SCTP_UNORDERED: This flag is present when the message was sent
2063 unordered.
2064
2065 rcv_ppid: This value is the same information that was passed by the
2066 upper layer in the peer application. Please note that the SCTP
2067 stack performs no byte order modification of this field. For
2068 example, if the DATA chunk has to contain a given value in network
2069 byte order, the SCTP user has to perform the ntohl() computation.
2070
2071
2072
2073
2074Stewart, et al. Informational [Page 37]
2075
2076RFC 6458 SCTP Sockets API December 2011
2077
2078
2079 rcv_tsn: This field holds a TSN that was assigned to one of the SCTP
2080 DATA chunks.
2081
2082 rcv_cumtsn: This field will hold the current cumulative TSN as known
2083 by the underlying SCTP layer.
2084
2085 rcv_context: This value is an opaque 32-bit context datum that was
2086 set by the user with the SCTP_CONTEXT socket option. This value
2087 is passed back to the upper layer if an error occurs on the send
2088 of a message and is retrieved with each undelivered message.
2089
2090 rcv_assoc_id: The association handle field, sinfo_assoc_id, holds
2091 the identifier for the association announced in the SCTP_COMM_UP
2092 notification. All notifications for a given association have the
2093 same identifier. This field is ignored for one-to-one style
2094 sockets.
2095
2096 An sctp_rcvinfo item always corresponds to the data in msg_iov.
2097
20985.3.6. SCTP Next Receive Information Structure (SCTP_NXTINFO)
2099
2100 This cmsghdr structure describes SCTP receive information of the next
2101 message that will be delivered through recvmsg() if this information
2102 is already available when delivering the current message.
2103
2104 To enable the delivery of this information, an application must use
2105 the SCTP_RECVNXTINFO socket option (see Section 8.1.30).
2106
2107 +--------------+--------------+---------------------+
2108 | cmsg_level | cmsg_type | cmsg_data[] |
2109 +--------------+--------------+---------------------+
2110 | IPPROTO_SCTP | SCTP_NXTINFO | struct sctp_nxtinfo |
2111 +--------------+--------------+---------------------+
2112
2113 The sctp_nxtinfo structure is defined below:
2114
2115 struct sctp_nxtinfo {
2116 uint16_t nxt_sid;
2117 uint16_t nxt_flags;
2118 uint32_t nxt_ppid;
2119 uint32_t nxt_length;
2120 sctp_assoc_t nxt_assoc_id;
2121 };
2122
2123
2124
2125
2126
2127
2128
2129
2130Stewart, et al. Informational [Page 38]
2131
2132RFC 6458 SCTP Sockets API December 2011
2133
2134
2135 nxt_sid: The SCTP stack places the next message's stream number in
2136 this value.
2137
2138 nxt_flags: This field may contain any of the following flags and is
2139 composed of a bitwise OR of these values.
2140
2141 SCTP_UNORDERED: This flag is present when the next message was
2142 sent unordered.
2143
2144 SCTP_COMPLETE: This flag indicates that the entire message has
2145 been received and is in the socket buffer. Note that this has
2146 special implications with respect to the nxt_length field; see
2147 the description for nxt_length below.
2148
2149 SCTP_NOTIFICATION: This flag is present when the next message is
2150 not a user message but instead is a notification.
2151
2152 nxt_ppid: This value is the same information that was passed by the
2153 upper layer in the peer application for the next message. Please
2154 note that the SCTP stack performs no byte order modification of
2155 this field. For example, if the DATA chunk has to contain a given
2156 value in network byte order, the SCTP user has to perform the
2157 ntohl() computation.
2158
2159 nxt_length: This value is the length of the message currently within
2160 the socket buffer. This might NOT be the entire length of the
2161 message, since a partial delivery may be in progress. Only if the
2162 flag SCTP_COMPLETE is set in the nxt_flags field does this field
2163 represent the size of the entire next message.
2164
2165 nxt_assoc_id: The association handle field of the next message,
2166 nxt_assoc_id, holds the identifier for the association announced
2167 in the SCTP_COMM_UP notification. All notifications for a given
2168 association have the same identifier. This field is ignored for
2169 one-to-one style sockets.
2170
21715.3.7. SCTP PR-SCTP Information Structure (SCTP_PRINFO)
2172
2173 This cmsghdr structure specifies SCTP options for sendmsg().
2174
2175 +--------------+-------------+--------------------+
2176 | cmsg_level | cmsg_type | cmsg_data[] |
2177 +--------------+-------------+--------------------+
2178 | IPPROTO_SCTP | SCTP_PRINFO | struct sctp_prinfo |
2179 +--------------+-------------+--------------------+
2180
2181
2182
2183
2184
2185
2186Stewart, et al. Informational [Page 39]
2187
2188RFC 6458 SCTP Sockets API December 2011
2189
2190
2191 The sctp_prinfo structure is defined below:
2192
2193 struct sctp_prinfo {
2194 uint16_t pr_policy;
2195 uint32_t pr_value;
2196 };
2197
2198 pr_policy: This specifies which Partially Reliable SCTP (PR-SCTP)
2199 policy is used. Using SCTP_PR_SCTP_NONE results in a reliable
2200 transmission. When SCTP_PR_SCTP_TTL is used, the PR-SCTP policy
2201 "timed reliability" defined in [RFC3758] is used. In this case,
2202 the lifetime is provided in pr_value.
2203
2204 pr_value: The meaning of this field depends on the PR-SCTP policy
2205 specified by the pr_policy field. It is ignored when
2206 SCTP_PR_SCTP_NONE is specified. In the case of SCTP_PR_SCTP_TTL,
2207 the lifetime in milliseconds is specified.
2208
2209 An sctp_prinfo item always corresponds to the data in msg_iov.
2210
22115.3.8. SCTP AUTH Information Structure (SCTP_AUTHINFO)
2212
2213 This cmsghdr structure specifies SCTP options for sendmsg().
2214
2215 +--------------+---------------+----------------------+
2216 | cmsg_level | cmsg_type | cmsg_data[] |
2217 +--------------+---------------+----------------------+
2218 | IPPROTO_SCTP | SCTP_AUTHINFO | struct sctp_authinfo |
2219 +--------------+---------------+----------------------+
2220
2221 The sctp_authinfo structure is defined below:
2222
2223 struct sctp_authinfo {
2224 uint16_t auth_keynumber;
2225 };
2226
2227 auth_keynumber: This specifies the shared key identifier used for
2228 sending the user message.
2229
2230 An sctp_authinfo item always corresponds to the data in msg_iov.
2231 Please note that the SCTP implementation must not bundle user
2232 messages that need to be authenticated using different shared key
2233 identifiers.
2234
2235
2236
2237
2238
2239
2240
2241
2242Stewart, et al. Informational [Page 40]
2243
2244RFC 6458 SCTP Sockets API December 2011
2245
2246
22475.3.9. SCTP Destination IPv4 Address Structure (SCTP_DSTADDRV4)
2248
2249 This cmsghdr structure specifies SCTP options for sendmsg().
2250
2251 +--------------+----------------+----------------+
2252 | cmsg_level | cmsg_type | cmsg_data[] |
2253 +--------------+----------------+----------------+
2254 | IPPROTO_SCTP | SCTP_DSTADDRV4 | struct in_addr |
2255 +--------------+----------------+----------------+
2256
2257 This ancillary data can be used to provide more than one destination
2258 address to sendmsg(). It can be used to implement sctp_sendv() using
2259 sendmsg().
2260
22615.3.10. SCTP Destination IPv6 Address Structure (SCTP_DSTADDRV6)
2262
2263 This cmsghdr structure specifies SCTP options for sendmsg().
2264
2265 +--------------+----------------+-----------------+
2266 | cmsg_level | cmsg_type | cmsg_data[] |
2267 +--------------+----------------+-----------------+
2268 | IPPROTO_SCTP | SCTP_DSTADDRV6 | struct in6_addr |
2269 +--------------+----------------+-----------------+
2270
2271 This ancillary data can be used to provide more than one destination
2272 address to sendmsg(). It can be used to implement sctp_sendv() using
2273 sendmsg().
2274
22756. SCTP Events and Notifications
2276
2277 An SCTP application may need to understand and process events and
2278 errors that happen on the SCTP stack. These events include network
2279 status changes, association startups, remote operational errors, and
2280 undeliverable messages. All of these can be essential for the
2281 application.
2282
2283 When an SCTP application layer does a recvmsg(), the message read is
2284 normally a data message from a peer endpoint. If the application
2285 wishes to have the SCTP stack deliver notifications of non-data
2286 events, it sets the appropriate socket option for the notifications
2287 it wants. See Section 6.2 for these socket options. When a
2288 notification arrives, recvmsg() returns the notification in the
2289 application-supplied data buffer via msg_iov, and sets
2290 MSG_NOTIFICATION in msg_flags.
2291
2292 This section details the notification structures. Every notification
2293 structure carries some common fields that provide general
2294 information.
2295
2296
2297
2298Stewart, et al. Informational [Page 41]
2299
2300RFC 6458 SCTP Sockets API December 2011
2301
2302
2303 A recvmsg() call will return only one notification at a time. Just
2304 as when reading normal data, it may return part of a notification if
2305 the msg_iov buffer is not large enough. If a single read is not
2306 sufficient, msg_flags will have MSG_EOR clear. The user must finish
2307 reading the notification before subsequent data can arrive.
2308
23096.1. SCTP Notification Structure
2310
2311 The notification structure is defined as the union of all
2312 notification types.
2313
2314 union sctp_notification {
2315 struct sctp_tlv {
2316 uint16_t sn_type; /* Notification type. */
2317 uint16_t sn_flags;
2318 uint32_t sn_length;
2319 } sn_header;
2320 struct sctp_assoc_change sn_assoc_change;
2321 struct sctp_paddr_change sn_paddr_change;
2322 struct sctp_remote_error sn_remote_error;
2323 struct sctp_send_failed sn_send_failed;
2324 struct sctp_shutdown_event sn_shutdown_event;
2325 struct sctp_adaptation_event sn_adaptation_event;
2326 struct sctp_pdapi_event sn_pdapi_event;
2327 struct sctp_authkey_event sn_auth_event;
2328 struct sctp_sender_dry_event sn_sender_dry_event;
2329 struct sctp_send_failed_event sn_send_failed_event;
2330 };
2331
2332 sn_type: The following list describes the SCTP notification and
2333 event types for the field sn_type.
2334
2335 SCTP_ASSOC_CHANGE: This tag indicates that an association has
2336 either been opened or closed. Refer to Section 6.1.1 for
2337 details.
2338
2339 SCTP_PEER_ADDR_CHANGE: This tag indicates that an address that is
2340 part of an existing association has experienced a change of
2341 state (e.g., a failure or return to service of the reachability
2342 of an endpoint via a specific transport address). Please see
2343 Section 6.1.2 for data structure details.
2344
2345 SCTP_REMOTE_ERROR: The attached error message is an Operation
2346 Error message received from the remote peer. It includes the
2347 complete TLV sent by the remote endpoint. See Section 6.1.3
2348 for the detailed format.
2349
2350
2351
2352
2353
2354Stewart, et al. Informational [Page 42]
2355
2356RFC 6458 SCTP Sockets API December 2011
2357
2358
2359 SCTP_SEND_FAILED_EVENT: The attached datagram could not be sent
2360 to the remote endpoint. This structure includes the original
2361 SCTP_SNDINFO that was used in sending this message; i.e., this
2362 structure uses the sctp_sndinfo per Section 6.1.11.
2363
2364 SCTP_SHUTDOWN_EVENT: The peer has sent a SHUTDOWN. No further
2365 data should be sent on this socket.
2366
2367 SCTP_ADAPTATION_INDICATION: This notification holds the peer's
2368 indicated adaptation layer. Please see Section 6.1.6.
2369
2370 SCTP_PARTIAL_DELIVERY_EVENT: This notification is used to tell a
2371 receiver that the partial delivery has been aborted. This may
2372 indicate that the association is about to be aborted. Please
2373 see Section 6.1.7.
2374
2375 SCTP_AUTHENTICATION_EVENT: This notification is used to tell a
2376 receiver that either an error occurred on authentication, or a
2377 new key was made active. See Section 6.1.8.
2378
2379 SCTP_SENDER_DRY_EVENT: This notification is used to inform the
2380 application that the sender has no more user data queued for
2381 transmission or retransmission. See Section 6.1.9.
2382
2383 sn_flags: These are notification-specific flags.
2384
2385 sn_length: This is the length of the whole sctp_notification
2386 structure, including the sn_type, sn_flags, and sn_length fields.
2387
23886.1.1. SCTP_ASSOC_CHANGE
2389
2390 Communication notifications inform the application that an SCTP
2391 association has either begun or ended. The identifier for a new
2392 association is provided by this notification. The notification
2393 information has the following format:
2394
2395 struct sctp_assoc_change {
2396 uint16_t sac_type;
2397 uint16_t sac_flags;
2398 uint32_t sac_length;
2399 uint16_t sac_state;
2400 uint16_t sac_error;
2401 uint16_t sac_outbound_streams;
2402 uint16_t sac_inbound_streams;
2403 sctp_assoc_t sac_assoc_id;
2404 uint8_t sac_info[];
2405 };
2406
2407
2408
2409
2410Stewart, et al. Informational [Page 43]
2411
2412RFC 6458 SCTP Sockets API December 2011
2413
2414
2415 sac_type: This field should be set to SCTP_ASSOC_CHANGE.
2416
2417 sac_flags: This field is currently unused.
2418
2419 sac_length: This field is the total length of the notification data,
2420 including the notification header.
2421
2422 sac_state: This field holds one of a number of values that
2423 communicate the event that happened to the association. These
2424 values include
2425
2426 SCTP_COMM_UP: A new association is now ready, and data may be
2427 exchanged with this peer. When an association has been
2428 established successfully, this notification should be the
2429 first one.
2430
2431 SCTP_COMM_LOST: The association has failed. The association is
2432 now in the closed state. If SEND_FAILED notifications are
2433 turned on, an SCTP_COMM_LOST is accompanied by a series of
2434 SCTP_SEND_FAILED_EVENT events, one for each outstanding
2435 message.
2436
2437 SCTP_RESTART: SCTP has detected that the peer has restarted.
2438
2439 SCTP_SHUTDOWN_COMP: The association has gracefully closed.
2440
2441 SCTP_CANT_STR_ASSOC: The association setup failed. If
2442 non-blocking mode is set and data was sent (on a one-to-many
2443 style socket), an SCTP_CANT_STR_ASSOC is accompanied by a
2444 series of SCTP_SEND_FAILED_EVENT events, one for each
2445 outstanding message.
2446
2447 sac_error: If the state was reached due to an error condition (e.g.,
2448 SCTP_COMM_LOST), any relevant error information is available in
2449 this field. This corresponds to the protocol error codes defined
2450 in [RFC4960].
2451
2452 sac_outbound_streams and sac_inbound_streams: The maximum number of
2453 streams allowed in each direction is available in
2454 sac_outbound_streams and sac_inbound streams.
2455
2456 sac_assoc_id: The sac_assoc_id field holds the identifier for the
2457 association. All notifications for a given association have the
2458 same association identifier. For a one-to-one style socket, this
2459 field is ignored.
2460
2461
2462
2463
2464
2465
2466Stewart, et al. Informational [Page 44]
2467
2468RFC 6458 SCTP Sockets API December 2011
2469
2470
2471 sac_info: If sac_state is SCTP_COMM_LOST and an ABORT chunk was
2472 received for this association, sac_info[] contains the complete
2473 ABORT chunk as defined in Section 3.3.7 of the SCTP specification
2474 [RFC4960]. If sac_state is SCTP_COMM_UP or SCTP_RESTART, sac_info
2475 may contain an array of uint8_t describing the features that the
2476 current association supports. Features may include
2477
2478 SCTP_ASSOC_SUPPORTS_PR: Both endpoints support the protocol
2479 extension described in [RFC3758].
2480
2481 SCTP_ASSOC_SUPPORTS_AUTH: Both endpoints support the protocol
2482 extension described in [RFC4895].
2483
2484 SCTP_ASSOC_SUPPORTS_ASCONF: Both endpoints support the protocol
2485 extension described in [RFC5061].
2486
2487 SCTP_ASSOC_SUPPORTS_MULTIBUF: For a one-to-many style socket, the
2488 local endpoints use separate send and/or receive buffers for
2489 each SCTP association.
2490
24916.1.2. SCTP_PEER_ADDR_CHANGE
2492
2493 When a destination address of a multi-homed peer encounters a state
2494 change, a peer address change event is sent. The notification has
2495 the following format:
2496
2497 struct sctp_paddr_change {
2498 uint16_t spc_type;
2499 uint16_t spc_flags;
2500 uint32_t spc_length;
2501 struct sockaddr_storage spc_aaddr;
2502 uint32_t spc_state;
2503 uint32_t spc_error;
2504 sctp_assoc_t spc_assoc_id;
2505 }
2506
2507 spc_type: This field should be set to SCTP_PEER_ADDR_CHANGE.
2508
2509 spc_flags: This field is currently unused.
2510
2511 spc_length: This field is the total length of the notification data,
2512 including the notification header.
2513
2514 spc_aaddr: The affected address field holds the remote peer's
2515 address that is encountering the change of state.
2516
2517
2518
2519
2520
2521
2522Stewart, et al. Informational [Page 45]
2523
2524RFC 6458 SCTP Sockets API December 2011
2525
2526
2527 spc_state: This field holds one of a number of values that
2528 communicate the event that happened to the address. They include
2529
2530 SCTP_ADDR_AVAILABLE: This address is now reachable. This
2531 notification is provided whenever an address becomes reachable.
2532
2533 SCTP_ADDR_UNREACHABLE: The address specified can no longer be
2534 reached. Any data sent to this address is rerouted to an
2535 alternate until this address becomes reachable. This
2536 notification is provided whenever an address becomes
2537 unreachable.
2538
2539 SCTP_ADDR_REMOVED: The address is no longer part of the
2540 association.
2541
2542 SCTP_ADDR_ADDED: The address is now part of the association.
2543
2544 SCTP_ADDR_MADE_PRIM: This address has now been made the primary
2545 destination address. This notification is provided whenever an
2546 address is made primary.
2547
2548 spc_error: If the state was reached due to any error condition
2549 (e.g., SCTP_ADDR_UNREACHABLE), any relevant error information is
2550 available in this field.
2551
2552 spc_assoc_id: The spc_assoc_id field holds the identifier for the
2553 association. All notifications for a given association have the
2554 same association identifier. For a one-to-one style socket, this
2555 field is ignored.
2556
25576.1.3. SCTP_REMOTE_ERROR
2558
2559 A remote peer may send an Operation Error message to its peer. This
2560 message indicates a variety of error conditions on an association.
2561 The entire ERROR chunk as it appears on the wire is included in an
2562 SCTP_REMOTE_ERROR event. Please refer to the SCTP specification
2563 [RFC4960] and any extensions for a list of possible error formats.
2564 An SCTP error notification has the following format:
2565
2566 struct sctp_remote_error {
2567 uint16_t sre_type;
2568 uint16_t sre_flags;
2569 uint32_t sre_length;
2570 uint16_t sre_error;
2571 sctp_assoc_t sre_assoc_id;
2572 uint8_t sre_data[];
2573 };
2574
2575
2576
2577
2578Stewart, et al. Informational [Page 46]
2579
2580RFC 6458 SCTP Sockets API December 2011
2581
2582
2583 sre_type: This field should be set to SCTP_REMOTE_ERROR.
2584
2585 sre_flags: This field is currently unused.
2586
2587 sre_length: This field is the total length of the notification data,
2588 including the notification header and the contents of sre_data.
2589
2590 sre_error: This value represents one of the Operation Error causes
2591 defined in the SCTP specification [RFC4960], in network byte
2592 order.
2593
2594 sre_assoc_id: The sre_assoc_id field holds the identifier for the
2595 association. All notifications for a given association have the
2596 same association identifier. For a one-to-one style socket, this
2597 field is ignored.
2598
2599 sre_data: This contains the ERROR chunk as defined in Section 3.3.10
2600 of the SCTP specification [RFC4960].
2601
26026.1.4. SCTP_SEND_FAILED - DEPRECATED
2603
2604 Please note that this notification is deprecated. Use
2605 SCTP_SEND_FAILED_EVENT instead.
2606
2607 If SCTP cannot deliver a message, it can return back the message as a
2608 notification if the SCTP_SEND_FAILED event is enabled. The
2609 notification has the following format:
2610
2611 struct sctp_send_failed {
2612 uint16_t ssf_type;
2613 uint16_t ssf_flags;
2614 uint32_t ssf_length;
2615 uint32_t ssf_error;
2616 struct sctp_sndrcvinfo ssf_info;
2617 sctp_assoc_t ssf_assoc_id;
2618 uint8_t ssf_data[];
2619 };
2620
2621 ssf_type: This field should be set to SCTP_SEND_FAILED.
2622
2623 ssf_flags: The flag value will take one of the following values:
2624
2625 SCTP_DATA_UNSENT: This value indicates that the data was never
2626 put on the wire.
2627
2628 SCTP_DATA_SENT: This value indicates that the data was put on the
2629 wire. Note that this does not necessarily mean that the data
2630 was (or was not) successfully delivered.
2631
2632
2633
2634Stewart, et al. Informational [Page 47]
2635
2636RFC 6458 SCTP Sockets API December 2011
2637
2638
2639 ssf_length: This field is the total length of the notification data,
2640 including the notification header and the payload in ssf_data.
2641
2642 ssf_error: This value represents the reason why the send failed, and
2643 if set, will be an SCTP protocol error code as defined in
2644 Section 3.3.10 of [RFC4960].
2645
2646 ssf_info: This field includes the ancillary data (struct
2647 sctp_sndrcvinfo) used to send the undelivered message. Regardless
2648 of whether ancillary data is used or not, the ssf_info.sinfo_flags
2649 field indicates whether the complete message or only part of the
2650 message is returned in ssf_data. If only part of the message is
2651 returned, it means that the part that is not present has been sent
2652 successfully to the peer.
2653
2654 If the complete message cannot be sent, the SCTP_DATA_NOT_FRAG
2655 flag is set in ssf_info.sinfo_flags. If the first part of the
2656 message is sent successfully, SCTP_DATA_LAST_FRAG is set. This
2657 means that the tail end of the message is returned in ssf_data.
2658
2659 ssf_assoc_id: The ssf_assoc_id field, ssf_assoc_id, holds the
2660 identifier for the association. All notifications for a given
2661 association have the same association identifier. For a one-to-
2662 one style socket, this field is ignored.
2663
2664 ssf_data: The undelivered message or part of the undelivered message
2665 will be present in the ssf_data field. Note that the
2666 ssf_info.sinfo_flags field as noted above should be used to
2667 determine whether a complete message or just a piece of the
2668 message is present. Note that only user data is present in this
2669 field; any chunk headers or SCTP common headers must be removed by
2670 the SCTP stack.
2671
26726.1.5. SCTP_SHUTDOWN_EVENT
2673
2674 When a peer sends a SHUTDOWN, SCTP delivers this notification to
2675 inform the application that it should cease sending data.
2676
2677 struct sctp_shutdown_event {
2678 uint16_t sse_type;
2679 uint16_t sse_flags;
2680 uint32_t sse_length;
2681 sctp_assoc_t sse_assoc_id;
2682 };
2683
2684 sse_type: This field should be set to SCTP_SHUTDOWN_EVENT.
2685
2686 sse_flags: This field is currently unused.
2687
2688
2689
2690Stewart, et al. Informational [Page 48]
2691
2692RFC 6458 SCTP Sockets API December 2011
2693
2694
2695 sse_length: This field is the total length of the notification data,
2696 including the notification header. It will generally be
2697 sizeof(struct sctp_shutdown_event).
2698
2699 sse_assoc_id: The sse_assoc_id field holds the identifier for the
2700 association. All notifications for a given association have the
2701 same association identifier. For a one-to-one style socket, this
2702 field is ignored.
2703
27046.1.6. SCTP_ADAPTATION_INDICATION
2705
2706 When a peer sends an Adaptation Layer Indication parameter as
2707 described in [RFC5061], SCTP delivers this notification to inform the
2708 application about the peer's adaptation layer indication.
2709
2710 struct sctp_adaptation_event {
2711 uint16_t sai_type;
2712 uint16_t sai_flags;
2713 uint32_t sai_length;
2714 uint32_t sai_adaptation_ind;
2715 sctp_assoc_t sai_assoc_id;
2716 };
2717
2718 sai_type: This field should be set to SCTP_ADAPTATION_INDICATION.
2719
2720 sai_flags: This field is currently unused.
2721
2722 sai_length: This field is the total length of the notification data,
2723 including the notification header. It will generally be
2724 sizeof(struct sctp_adaptation_event).
2725
2726 sai_adaptation_ind: This field holds the bit array sent by the peer
2727 in the Adaptation Layer Indication parameter.
2728
2729 sai_assoc_id: The sai_assoc_id field holds the identifier for the
2730 association. All notifications for a given association have the
2731 same association identifier. For a one-to-one style socket, this
2732 field is ignored.
2733
27346.1.7. SCTP_PARTIAL_DELIVERY_EVENT
2735
2736 When a receiver is engaged in a partial delivery of a message, this
2737 notification will be used to indicate various events.
2738
2739 struct sctp_pdapi_event {
2740 uint16_t pdapi_type;
2741 uint16_t pdapi_flags;
2742 uint32_t pdapi_length;
2743
2744
2745
2746Stewart, et al. Informational [Page 49]
2747
2748RFC 6458 SCTP Sockets API December 2011
2749
2750
2751 uint32_t pdapi_indication;
2752 uint32_t pdapi_stream;
2753 uint32_t pdapi_seq;
2754 sctp_assoc_t pdapi_assoc_id;
2755 };
2756
2757 pdapi_type: This field should be set to SCTP_PARTIAL_DELIVERY_EVENT.
2758
2759 pdapi_flags: This field is currently unused.
2760
2761 pdapi_length: This field is the total length of the notification
2762 data, including the notification header. It will generally be
2763 sizeof(struct sctp_pdapi_event).
2764
2765 pdapi_indication: This field holds the indication being sent to the
2766 application. Currently, there is only one defined value:
2767
2768 SCTP_PARTIAL_DELIVERY_ABORTED: This indicates that the partial
2769 delivery of a user message has been aborted. This happens, for
2770 example, if an association is aborted while a partial delivery
2771 is going on or the user message gets abandoned using PR-SCTP
2772 while the partial delivery of this message is going on.
2773
2774 pdapi_stream: This field holds the stream on which the partial
2775 delivery event happened.
2776
2777 pdapi_seq: This field holds the stream sequence number that was
2778 being partially delivered.
2779
2780 pdapi_assoc_id: The pdapi_assoc_id field holds the identifier for
2781 the association. All notifications for a given association have
2782 the same association identifier. For a one-to-one style socket,
2783 this field is ignored.
2784
27856.1.8. SCTP_AUTHENTICATION_EVENT
2786
2787 [RFC4895] defines an extension to authenticate SCTP messages. The
2788 following notification is used to report different events relating to
2789 the use of this extension.
2790
2791 struct sctp_authkey_event {
2792 uint16_t auth_type;
2793 uint16_t auth_flags;
2794 uint32_t auth_length;
2795 uint16_t auth_keynumber;
2796 uint32_t auth_indication;
2797 sctp_assoc_t auth_assoc_id;
2798 };
2799
2800
2801
2802Stewart, et al. Informational [Page 50]
2803
2804RFC 6458 SCTP Sockets API December 2011
2805
2806
2807 auth_type: This field should be set to SCTP_AUTHENTICATION_EVENT.
2808
2809 auth_flags: This field is currently unused.
2810
2811 auth_length: This field is the total length of the notification
2812 data, including the notification header. It will generally be
2813 sizeof(struct sctp_authkey_event).
2814
2815 auth_keynumber: This field holds the key number for the affected key
2816 indicated in the event (depends on auth_indication).
2817
2818 auth_indication: This field holds the error or indication being
2819 reported. The following values are currently defined:
2820
2821 SCTP_AUTH_NEW_KEY: This report indicates that a new key has been
2822 made active (used for the first time by the peer) and is now
2823 the active key. The auth_keynumber field holds the user-
2824 specified key number.
2825
2826 SCTP_AUTH_NO_AUTH: This report indicates that the peer does not
2827 support SCTP authentication as defined in [RFC4895].
2828
2829 SCTP_AUTH_FREE_KEY: This report indicates that the SCTP
2830 implementation will no longer use the key identifier specified
2831 in auth_keynumber.
2832
2833 auth_assoc_id: The auth_assoc_id field holds the identifier for the
2834 association. All notifications for a given association have the
2835 same association identifier. For a one-to-one style socket, this
2836 field is ignored.
2837
28386.1.9. SCTP_SENDER_DRY_EVENT
2839
2840 When the SCTP stack has no more user data to send or retransmit, this
2841 notification is given to the user. Also, at the time when a user app
2842 subscribes to this event, if there is no data to be sent or
2843 retransmit, the stack will immediately send up this notification.
2844
2845 struct sctp_sender_dry_event {
2846 uint16_t sender_dry_type;
2847 uint16_t sender_dry_flags;
2848 uint32_t sender_dry_length;
2849 sctp_assoc_t sender_dry_assoc_id;
2850 };
2851
2852 sender_dry_type: This field should be set to SCTP_SENDER_DRY_EVENT.
2853
2854 sender_dry_flags: This field is currently unused.
2855
2856
2857
2858Stewart, et al. Informational [Page 51]
2859
2860RFC 6458 SCTP Sockets API December 2011
2861
2862
2863 sender_dry_length: This field is the total length of the
2864 notification data, including the notification header. It will
2865 generally be sizeof(struct sctp_sender_dry_event).
2866
2867 sender_dry_assoc_id: The sender_dry_assoc_id field holds the
2868 identifier for the association. All notifications for a given
2869 association have the same association identifier. For a one-to-
2870 one style socket, this field is ignored.
2871
28726.1.10. SCTP_NOTIFICATIONS_STOPPED_EVENT
2873
2874 SCTP notifications, when subscribed to, are reliable. They are
2875 always delivered as long as there is space in the socket receive
2876 buffer. However, if an implementation experiences a notification
2877 storm, it may run out of socket buffer space. When this occurs, it
2878 may wish to disable notifications. If the implementation chooses to
2879 do this, it will append a final notification
2880 SCTP_NOTIFICATIONS_STOPPED_EVENT. This notification is a union
2881 sctp_notification, where only the sctp_tlv structure (see the union
2882 above) is used. It only contains this type in the sn_type field, the
2883 sn_length field set to the size of an sctp_tlv structure, and the
2884 sn_flags set to 0. If an application receives this notification, it
2885 will need to re-subscribe to any notifications of interest to it,
2886 except for the sctp_data_io_event (note that SCTP_EVENTS is
2887 deprecated).
2888
2889 An endpoint is automatically subscribed to this event as soon as it
2890 is subscribed to any event other than data io events.
2891
28926.1.11. SCTP_SEND_FAILED_EVENT
2893
2894 If SCTP cannot deliver a message, it can return back the message as a
2895 notification if the SCTP_SEND_FAILED_EVENT event is enabled. The
2896 notification has the following format:
2897
2898 struct sctp_send_failed_event {
2899 uint16_t ssfe_type;
2900 uint16_t ssfe_flags;
2901 uint32_t ssfe_length;
2902 uint32_t ssfe_error;
2903 struct sctp_sndinfo ssfe_info;
2904 sctp_assoc_t ssfe_assoc_id;
2905 uint8_t ssfe_data[];
2906 };
2907
2908
2909
2910
2911
2912
2913
2914Stewart, et al. Informational [Page 52]
2915
2916RFC 6458 SCTP Sockets API December 2011
2917
2918
2919 ssfe_type: This field should be set to SCTP_SEND_FAILED_EVENT.
2920
2921 ssfe_flags: The flag value will take one of the following values:
2922
2923 SCTP_DATA_UNSENT: This value indicates that the data was never
2924 put on the wire.
2925
2926 SCTP_DATA_SENT: This value indicates that the data was put on the
2927 wire. Note that this does not necessarily mean that the data
2928 was (or was not) successfully delivered.
2929
2930 ssfe_length: This field is the total length of the notification
2931 data, including the notification header and the payload in
2932 ssf_data.
2933
2934 ssfe_error: This value represents the reason why the send failed,
2935 and if set, will be an SCTP protocol error code as defined in
2936 Section 3.3.10 of [RFC4960].
2937
2938 ssfe_info: This field includes the ancillary data (struct
2939 sctp_sndinfo) used to send the undelivered message. Regardless of
2940 whether ancillary data is used or not, the ssfe_info.sinfo_flags
2941 field indicates whether the complete message or only part of the
2942 message is returned in ssf_data. If only part of the message is
2943 returned, it means that the part that is not present has been sent
2944 successfully to the peer.
2945
2946 If the complete message cannot be sent, the SCTP_DATA_NOT_FRAG
2947 flag is set in ssfe_info.sinfo_flags. If the first part of the
2948 message is sent successfully, SCTP_DATA_LAST_FRAG is set. This
2949 means that the tail end of the message is returned in ssf_data.
2950
2951 ssfe_assoc_id: The ssfe_assoc_id field, ssf_assoc_id, holds the
2952 identifier for the association. All notifications for a given
2953 association have the same association identifier. For a one-to-
2954 one style socket, this field is ignored.
2955
2956 ssfe_data: The undelivered message or part of the undelivered
2957 message will be present in the ssf_data field. Note that the
2958 ssf_info.sinfo_flags field as noted above should be used to
2959 determine whether a complete message or just a piece of the
2960 message is present. Note that only user data is present in this
2961 field; any chunk headers or SCTP common headers must be removed by
2962 the SCTP stack.
2963
2964
2965
2966
2967
2968
2969
2970Stewart, et al. Informational [Page 53]
2971
2972RFC 6458 SCTP Sockets API December 2011
2973
2974
29756.2. Notification Interest Options
2976
29776.2.1. SCTP_EVENTS Option - DEPRECATED
2978
2979 Please note that this option is deprecated. Use the SCTP_EVENT
2980 option described in Section 6.2.2 instead.
2981
2982 To receive SCTP event notifications, an application registers its
2983 interest by setting the SCTP_EVENTS socket option. The application
2984 then uses recvmsg() to retrieve notifications. A notification is
2985 stored in the data part (msg_iov) of the msghdr structure. The
2986 socket option uses the following structure:
2987
2988 struct sctp_event_subscribe {
2989 uint8_t sctp_data_io_event;
2990 uint8_t sctp_association_event;
2991 uint8_t sctp_address_event;
2992 uint8_t sctp_send_failure_event;
2993 uint8_t sctp_peer_error_event;
2994 uint8_t sctp_shutdown_event;
2995 uint8_t sctp_partial_delivery_event;
2996 uint8_t sctp_adaptation_layer_event;
2997 uint8_t sctp_authentication_event;
2998 uint8_t sctp_sender_dry_event;
2999 };
3000
3001 sctp_data_io_event: Setting this flag to 1 will cause the reception
3002 of SCTP_SNDRCV information on a per-message basis. The
3003 application will need to use the recvmsg() interface so that it
3004 can receive the event information contained in the msg_control
3005 field. Setting the flag to 0 will disable the reception of the
3006 message control information. Note that this flag is not really a
3007 notification and is stored in the ancillary data (msg_control),
3008 not in the data part (msg_iov).
3009
3010 sctp_association_event: Setting this flag to 1 will enable the
3011 reception of association event notifications. Setting the flag to
3012 0 will disable association event notifications.
3013
3014 sctp_address_event: Setting this flag to 1 will enable the reception
3015 of address event notifications. Setting the flag to 0 will
3016 disable address event notifications.
3017
3018 sctp_send_failure_event: Setting this flag to 1 will enable the
3019 reception of send failure event notifications. Setting the flag
3020 to 0 will disable send failure event notifications.
3021
3022
3023
3024
3025
3026Stewart, et al. Informational [Page 54]
3027
3028RFC 6458 SCTP Sockets API December 2011
3029
3030
3031 sctp_peer_error_event: Setting this flag to 1 will enable the
3032 reception of peer error event notifications. Setting the flag to
3033 0 will disable peer error event notifications.
3034
3035 sctp_shutdown_event: Setting this flag to 1 will enable the
3036 reception of shutdown event notifications. Setting the flag to 0
3037 will disable shutdown event notifications.
3038
3039 sctp_partial_delivery_event: Setting this flag to 1 will enable the
3040 reception of partial delivery event notifications. Setting the
3041 flag to 0 will disable partial delivery event notifications.
3042
3043 sctp_adaptation_layer_event: Setting this flag to 1 will enable the
3044 reception of adaptation layer event notifications. Setting the
3045 flag to 0 will disable adaptation layer event notifications.
3046
3047 sctp_authentication_event: Setting this flag to 1 will enable the
3048 reception of authentication layer event notifications. Setting
3049 the flag to 0 will disable authentication layer event
3050 notifications.
3051
3052 sctp_sender_dry_event: Setting this flag to 1 will enable the
3053 reception of sender dry event notifications. Setting the flag to
3054 0 will disable sender dry event notifications.
3055
3056 An example where an application would like to receive data_io_events
3057 and association_events but no others would be as follows:
3058
3059 {
3060 struct sctp_event_subscribe events;
3061
3062 memset(&events, 0, sizeof(events));
3063
3064 events.sctp_data_io_event = 1;
3065 events.sctp_association_event = 1;
3066
3067 setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events, sizeof(events));
3068 }
3069
3070 Note that for one-to-many style SCTP sockets, the caller of recvmsg()
3071 receives ancillary data and notifications for all associations bound
3072 to the file descriptor. For one-to-one style SCTP sockets, the
3073 caller receives ancillary data and notifications only for the single
3074 association bound to the file descriptor.
3075
3076 By default, both the one-to-one style and the one-to-many style
3077 socket do not subscribe to any notification.
3078
3079
3080
3081
3082Stewart, et al. Informational [Page 55]
3083
3084RFC 6458 SCTP Sockets API December 2011
3085
3086
30876.2.2. SCTP_EVENT Option
3088
3089 The SCTP_EVENTS socket option has one issue for future compatibility.
3090 As new features are added, the structure (sctp_event_subscribe) must
3091 be expanded. This can cause an application binary interface (ABI)
3092 issue unless an implementation has added padding at the end of the
3093 structure. To avoid this problem, SCTP_EVENTS has been deprecated
3094 and a new socket option SCTP_EVENT has taken its place. The option
3095 is used with the following structure:
3096
3097 struct sctp_event {
3098 sctp_assoc_t se_assoc_id;
3099 uint16_t se_type;
3100 uint8_t se_on;
3101 };
3102
3103 se_assoc_id: The se_assoc_id field is ignored for one-to-one style
3104 sockets. For one-to-many style sockets, this field can be a
3105 particular association identifier or SCTP_{FUTURE|CURRENT|
3106 ALL}_ASSOC.
3107
3108 se_type: The se_type field can be filled with any value that would
3109 show up in the respective sn_type field (in the sctp_tlv structure
3110 of the notification).
3111
3112 se_on: The se_on field is set to 1 to turn on an event and set to 0
3113 to turn off an event.
3114
3115 To use this option, the user fills in this structure and then calls
3116 setsockopt() to turn on or off an individual event. The following is
3117 an example use of this option:
3118
3119 {
3120 struct sctp_event event;
3121
3122 memset(&event, 0, sizeof(event));
3123
3124 event.se_assoc_id = SCTP_FUTURE_ASSOC;
3125 event.se_type = SCTP_SENDER_DRY_EVENT;
3126 event.se_on = 1;
3127 setsockopt(sd, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(event));
3128 }
3129
3130 By default, both the one-to-one style and the one-to-many style
3131 socket do not subscribe to any notification.
3132
3133
3134
3135
3136
3137
3138Stewart, et al. Informational [Page 56]
3139
3140RFC 6458 SCTP Sockets API December 2011
3141
3142
31437. Common Operations for Both Styles
3144
31457.1. send(), recv(), sendto(), and recvfrom()
3146
3147 Applications can use send() and sendto() to transmit data to the peer
3148 of an SCTP endpoint. recv() and recvfrom() can be used to receive
3149 data from the peer.
3150
3151 The function prototypes are
3152
3153 ssize_t send(int sd,
3154 const void *msg,
3155 size_t len,
3156 int flags);
3157
3158 ssize_t sendto(int sd,
3159 const void *msg,
3160 size_t len,
3161 int flags,
3162 const struct sockaddr *to,
3163 socklen_t tolen);
3164
3165 ssize_t recv(int sd,
3166 void *buf,
3167 size_t len,
3168 int flags);
3169
3170 ssize_t recvfrom(int sd,
3171 void *buf,
3172 size_t len,
3173 int flags,
3174 struct sockaddr *from,
3175 socklen_t *fromlen);
3176
3177 and the arguments are
3178
3179 sd: The socket descriptor of an SCTP endpoint.
3180
3181 msg: The message to be sent.
3182
3183 len: The size of the message or the size of the buffer.
3184
3185 to: One of the peer addresses of the association to be used to send
3186 the message.
3187
3188 tolen: The size of the address.
3189
3190 buf: The buffer to store a received message.
3191
3192
3193
3194Stewart, et al. Informational [Page 57]
3195
3196RFC 6458 SCTP Sockets API December 2011
3197
3198
3199 from: The buffer to store the peer address used to send the received
3200 message.
3201
3202 fromlen: The size of the from address.
3203
3204 flags: (described below).
3205
3206 These calls give access to only basic SCTP protocol features. If
3207 either peer in the association uses multiple streams, or sends
3208 unordered data, these calls will usually be inadequate and may
3209 deliver the data in unpredictable ways.
3210
3211 SCTP has the concept of multiple streams in one association. The
3212 above calls do not allow the caller to specify on which stream a
3213 message should be sent. The system uses stream 0 as the default
3214 stream for send() and sendto(). recv() and recvfrom() return data
3215 from any stream, but the caller cannot distinguish the different
3216 streams. This may result in data seeming to arrive out of order.
3217 Similarly, if a DATA chunk is sent unordered, recv() and recvfrom()
3218 provide no indication.
3219
3220 SCTP is message based. The msg buffer above in send() and sendto()
3221 is considered to be a single message. This means that if the caller
3222 wants to send a message that is composed by several buffers, the
3223 caller needs to combine them before calling send() or sendto().
3224 Alternately, the caller can use sendmsg() to do that without
3225 combining them. Sending a message using send() or sendto() is atomic
3226 unless explicit EOR marking is enabled on the socket specified by sd.
3227 Using sendto() on a non-connected one-to-one style socket for
3228 implicit connection setup may or may not work, depending on the SCTP
3229 implementation. recv() and recvfrom() cannot distinguish message
3230 boundaries (i.e., there is no way to observe the MSG_EOR flag to
3231 detect partial delivery).
3232
3233 When receiving, if the buffer supplied is not large enough to hold a
3234 complete message, the receive call acts like a stream socket and
3235 returns as much data as will fit in the buffer.
3236
3237 Note that the send() and recv() calls may not be used for a one-to-
3238 many style socket.
3239
3240 Note that if an application calls a send() or sendto() function with
3241 no user data, the SCTP implementation should reject the request with
3242 an appropriate error message. An implementation is not allowed to
3243 send a DATA chunk with no user data [RFC4960].
3244
3245
3246
3247
3248
3249
3250Stewart, et al. Informational [Page 58]
3251
3252RFC 6458 SCTP Sockets API December 2011
3253
3254
32557.2. setsockopt() and getsockopt()
3256
3257 Applications use setsockopt() and getsockopt() to set or retrieve
3258 socket options. Socket options are used to change the default
3259 behavior of socket calls. They are described in Section 8.
3260
3261 The function prototypes are
3262
3263 int getsockopt(int sd,
3264 int level,
3265 int optname,
3266 void *optval,
3267 socklen_t *optlen);
3268
3269 and
3270
3271 int setsockopt(int sd,
3272 int level,
3273 int optname,
3274 const void *optval,
3275 socklen_t optlen);
3276
3277 and the arguments are
3278
3279 sd: The socket descriptor.
3280
3281 level: Set to IPPROTO_SCTP for all SCTP options.
3282
3283 optname: The option name.
3284
3285 optval: The buffer to store the value of the option.
3286
3287 optlen: The size of the buffer (or the length of the option
3288 returned).
3289
3290 These functions return 0 on success and -1 in case of an error.
3291
3292 All socket options set on a one-to-one style listening socket also
3293 apply to all future accepted sockets. For one-to-many style sockets,
3294 often a socket option will pass a structure that includes an assoc_id
3295 field. This field can be filled with the association identifier of a
3296 particular association and unless otherwise specified can be filled
3297 with one of the following constants:
3298
3299 SCTP_FUTURE_ASSOC: Specifies that only future associations created
3300 after this socket option will be affected by this call.
3301
3302
3303
3304
3305
3306Stewart, et al. Informational [Page 59]
3307
3308RFC 6458 SCTP Sockets API December 2011
3309
3310
3311 SCTP_CURRENT_ASSOC: Specifies that only currently existing
3312 associations will be affected by this call, and future
3313 associations will still receive the previous default value.
3314
3315 SCTP_ALL_ASSOC: Specifies that all current and future associations
3316 will be affected by this call.
3317
33187.3. read() and write()
3319
3320 Applications can use read() and write() to receive and send data from
3321 and to a peer. They have the same semantics as recv() and send(),
3322 except that the flags parameter cannot be used.
3323
33247.4. getsockname()
3325
3326 Applications use getsockname() to retrieve the locally bound socket
3327 address of the specified socket. This is especially useful if the
3328 caller let SCTP choose a local port. This call is for single-homed
3329 endpoints. It does not work well with multi-homed endpoints. See
3330 Section 9.5 for a multi-homed version of the call.
3331
3332 The function prototype is
3333
3334 int getsockname(int sd,
3335 struct sockaddr *address,
3336 socklen_t *len);
3337
3338 and the arguments are
3339
3340 sd: The socket descriptor to be queried.
3341
3342 address: On return, one locally bound address (chosen by the SCTP
3343 stack) is stored in this buffer. If the socket is an IPv4 socket,
3344 the address will be IPv4. If the socket is an IPv6 socket, the
3345 address will be either an IPv6 or IPv4 address.
3346
3347 len: The caller should set the length of the address here. On
3348 return, this is set to the length of the returned address.
3349
3350 getsockname() returns 0 on success and -1 in case of an error.
3351
3352 If the actual length of the address is greater than the length of the
3353 supplied sockaddr structure, the stored address will be truncated.
3354
3355 If the socket has not been bound to a local name, the value stored in
3356 the object pointed to by address is unspecified.
3357
3358
3359
3360
3361
3362Stewart, et al. Informational [Page 60]
3363
3364RFC 6458 SCTP Sockets API December 2011
3365
3366
33677.5. Implicit Association Setup
3368
3369 The application can begin sending and receiving data using the
3370 sendmsg()/recvmsg() or sendto()/recvfrom() calls, without going
3371 through any explicit association setup procedures (i.e., no connect()
3372 calls required).
3373
3374 Whenever sendmsg() or sendto() is called and the SCTP stack at the
3375 sender finds that no association exists between the sender and the
3376 intended receiver (identified by the address passed either in the
3377 msg_name field of the msghdr structure in the sendmsg() call or the
3378 dest_addr field in the sendto() call), the SCTP stack will
3379 automatically set up an association to the intended receiver.
3380
3381 Upon successful association setup, an SCTP_COMM_UP notification will
3382 be dispatched to the socket at both the sender and receiver side.
3383 This notification can be read by the recvmsg() system call (see
3384 Section 3.1.4).
3385
3386 Note that if the SCTP stack at the sender side supports bundling, the
3387 first user message may be bundled with the COOKIE ECHO message
3388 [RFC4960].
3389
3390 When the SCTP stack sets up a new association implicitly, the
3391 SCTP_INIT type ancillary data may also be passed along (see
3392 Section 5.3.1 for details of the data structures) to change some
3393 parameters used in setting up a new association.
3394
3395 If this information is not present in the sendmsg() call, or if the
3396 implicit association setup is triggered by a sendto() call, the
3397 default association initialization parameters will be used. These
3398 default association parameters may be set with respective
3399 setsockopt() calls or be left to the system defaults.
3400
3401 Implicit association setup cannot be initiated by send() calls.
3402
34038. Socket Options
3404
3405 The following subsection describes various SCTP-level socket options
3406 that are common to both styles. SCTP associations can be
3407 multi-homed. Therefore, certain option parameters include a
3408 sockaddr_storage structure to select to which peer address the option
3409 should be applied.
3410
3411 For the one-to-many style sockets, an sctp_assoc_t (association
3412 identifier) parameter is used to identify the association instance
3413 that the operation affects. So it must be set when using this style.
3414
3415
3416
3417
3418Stewart, et al. Informational [Page 61]
3419
3420RFC 6458 SCTP Sockets API December 2011
3421
3422
3423 For the one-to-one style sockets and branched-off one-to-many style
3424 sockets (see Section 9.2), this association ID parameter is ignored.
3425
3426 Note that socket- or IP-level options are set or retrieved per
3427 socket. This means that for one-to-many style sockets, the options
3428 will be applied to all associations (similar to using SCTP_ALL_ASSOC
3429 as the association identifier) belonging to the socket. For the one-
3430 to-one style, these options will be applied to all peer addresses of
3431 the association controlled by the socket. Applications should be
3432 careful in setting those options.
3433
3434 For some IP stacks, getsockopt() is read-only, so a new interface
3435 will be needed when information must be passed both into and out of
3436 the SCTP stack. The syntax for sctp_opt_info() is
3437
3438 int sctp_opt_info(int sd,
3439 sctp_assoc_t id,
3440 int opt,
3441 void *arg,
3442 socklen_t *size);
3443
3444 The sctp_opt_info() call is a replacement for getsockopt() only and
3445 will not set any options associated with the specified socket. A
3446 setsockopt() call must be used to set any writable option.
3447
3448 For one-to-many style sockets, id specifies the association to query.
3449 For one-to-one style sockets, id is ignored. For one-to-many style
3450 sockets, any association identifier in the structure provided as arg
3451 is ignored, and id takes precedence.
3452
3453 Note that SCTP_CURRENT_ASSOC and SCTP_ALL_ASSOC cannot be used with
3454 sctp_opt_info() or in getsockopt() calls. Using them will result in
3455 an error (returning -1 and errno set to EINVAL). SCTP_FUTURE_ASSOC
3456 can be used to query information for future associations.
3457
3458 The field opt specifies which SCTP socket option to get. It can get
3459 any socket option currently supported that requests information
3460 (either read/write options or read-only) such as
3461
3462 SCTP_RTOINFO
3463
3464 SCTP_ASSOCINFO
3465
3466 SCTP_PRIMARY_ADDR
3467
3468 SCTP_PEER_ADDR_PARAMS
3469
3470 SCTP_DEFAULT_SEND_PARAM
3471
3472
3473
3474Stewart, et al. Informational [Page 62]
3475
3476RFC 6458 SCTP Sockets API December 2011
3477
3478
3479 SCTP_MAX_SEG
3480
3481 SCTP_AUTH_ACTIVE_KEY
3482
3483 SCTP_DELAYED_SACK
3484
3485 SCTP_MAX_BURST
3486
3487 SCTP_CONTEXT
3488
3489 SCTP_EVENT
3490
3491 SCTP_DEFAULT_SNDINFO
3492
3493 SCTP_DEFAULT_PRINFO
3494
3495 SCTP_STATUS
3496
3497 SCTP_GET_PEER_ADDR_INFO
3498
3499 SCTP_PEER_AUTH_CHUNKS
3500
3501 SCTP_LOCAL_AUTH_CHUNKS
3502
3503 The arg field is an option-specific structure buffer provided by the
3504 caller. See the rest of this section for more information on these
3505 options and option-specific structures.
3506
3507 sctp_opt_info() returns 0 on success, or on failure returns -1 and
3508 sets errno to the appropriate error code.
3509
35108.1. Read/Write Options
3511
35128.1.1. Retransmission Timeout Parameters (SCTP_RTOINFO)
3513
3514 The protocol parameters used to initialize and limit the
3515 retransmission timeout (RTO) are tunable. See [RFC4960] for more
3516 information on how these parameters are used in RTO calculation.
3517
3518 The following structure is used to access and modify these
3519 parameters:
3520
3521 struct sctp_rtoinfo {
3522 sctp_assoc_t srto_assoc_id;
3523 uint32_t srto_initial;
3524 uint32_t srto_max;
3525 uint32_t srto_min;
3526 };
3527
3528
3529
3530Stewart, et al. Informational [Page 63]
3531
3532RFC 6458 SCTP Sockets API December 2011
3533
3534
3535 srto_assoc_id: This parameter is ignored for one-to-one style
3536 sockets. For one-to-many style sockets, the application may fill
3537 in an association identifier or SCTP_FUTURE_ASSOC. It is an error
3538 to use SCTP_{CURRENT|ALL}_ASSOC in srto_assoc_id.
3539
3540 srto_initial: This parameter contains the initial RTO value.
3541
3542 srto_max and srto_min: These parameters contain the maximum and
3543 minimum bounds for all RTOs.
3544
3545 All times are given in milliseconds. A value of 0, when modifying
3546 the parameters, indicates that the current value should not be
3547 changed.
3548
3549 To access or modify these parameters, the application should call
3550 getsockopt() or setsockopt(), respectively, with the option name
3551 SCTP_RTOINFO.
3552
35538.1.2. Association Parameters (SCTP_ASSOCINFO)
3554
3555 This option is used to both examine and set various association and
3556 endpoint parameters. See [RFC4960] for more information on how these
3557 parameters are used.
3558
3559 The following structure is used to access and modify these
3560 parameters:
3561
3562 struct sctp_assocparams {
3563 sctp_assoc_t sasoc_assoc_id;
3564 uint16_t sasoc_asocmaxrxt;
3565 uint16_t sasoc_number_peer_destinations;
3566 uint32_t sasoc_peer_rwnd;
3567 uint32_t sasoc_local_rwnd;
3568 uint32_t sasoc_cookie_life;
3569 };
3570
3571 sasoc_assoc_id: This parameter is ignored for one-to-one style
3572 sockets. For one-to-many style sockets, the application may fill
3573 in an association identifier or SCTP_FUTURE_ASSOC. It is an error
3574 to use SCTP_{CURRENT|ALL}_ASSOC in sasoc_assoc_id.
3575
3576 sasoc_asocmaxrxt: This parameter contains the maximum retransmission
3577 attempts to make for the association.
3578
3579 sasoc_number_peer_destinations: This parameter is the number of
3580 destination addresses that the peer has.
3581
3582
3583
3584
3585
3586Stewart, et al. Informational [Page 64]
3587
3588RFC 6458 SCTP Sockets API December 2011
3589
3590
3591 sasoc_peer_rwnd: This parameter holds the current value of the
3592 peer's rwnd (reported in the last selective acknowledgment (SACK))
3593 minus any outstanding data (i.e., data in flight).
3594
3595 sasoc_local_rwnd: This parameter holds the last reported rwnd that
3596 was sent to the peer.
3597
3598 sasoc_cookie_life: This parameter is the association's cookie life
3599 value used when issuing cookies.
3600
3601 The value of sasoc_peer_rwnd is meaningless when examining endpoint
3602 information (i.e., it is only valid when examining information on a
3603 specific association).
3604
3605 All time values are given in milliseconds. A value of 0, when
3606 modifying the parameters, indicates that the current value should not
3607 be changed.
3608
3609 The values of sasoc_asocmaxrxt and sasoc_cookie_life may be set on
3610 either an endpoint or association basis. The rwnd and destination
3611 counts (sasoc_number_peer_destinations, sasoc_peer_rwnd,
3612 sasoc_local_rwnd) are not settable, and any value placed in these is
3613 ignored.
3614
3615 To access or modify these parameters, the application should call
3616 getsockopt() or setsockopt(), respectively, with the option name
3617 SCTP_ASSOCINFO.
3618
3619 The maximum number of retransmissions before an address is considered
3620 unreachable is also tunable, but is address-specific, so it is
3621 covered in a separate option. If an application attempts to set the
3622 value of the association's maximum retransmission parameter to more
3623 than the sum of all maximum retransmission parameters, setsockopt()
3624 may return an error. The reason for this, from Section 8.2 of
3625 [RFC4960], is as follows:
3626
3627 Note: When configuring the SCTP endpoint, the user should avoid
3628 having the value of 'Association.Max.Retrans' (sasoc_maxrxt in
3629 this option) larger than the summation of the 'Path.Max.Retrans'
3630 (see spp_pathmaxrxt in Section 8.1.12) of all of the destination
3631 addresses for the remote endpoint. Otherwise, all of the
3632 destination addresses may become inactive while the endpoint still
3633 considers the peer endpoint reachable.
3634
3635
3636
3637
3638
3639
3640
3641
3642Stewart, et al. Informational [Page 65]
3643
3644RFC 6458 SCTP Sockets API December 2011
3645
3646
36478.1.3. Initialization Parameters (SCTP_INITMSG)
3648
3649 Applications can specify protocol parameters for the default
3650 association initialization. The structure used to access and modify
3651 these parameters is defined in Section 5.3.1. The option name
3652 argument to setsockopt() and getsockopt() is SCTP_INITMSG.
3653
3654 Setting initialization parameters is effective only on an unconnected
3655 socket (for one-to-many style sockets, only future associations are
3656 affected by the change).
3657
36588.1.4. SO_LINGER
3659
3660 An application can use this option to perform the SCTP ABORT
3661 primitive. This option affects all associations related to the
3662 socket.
3663
3664 The linger option structure is
3665
3666 struct linger {
3667 int l_onoff; /* option on/off */
3668 int l_linger; /* linger time */
3669 };
3670
3671 To enable the option, set l_onoff to 1. If the l_linger value is set
3672 to 0, calling close() is the same as the ABORT primitive. If the
3673 value is set to a negative value, the setsockopt() call will return
3674 an error. If the value is set to a positive value linger_time, the
3675 close() can be blocked for at most linger_time. Please note that the
3676 time unit is in seconds, according to POSIX, but might be different
3677 on specific platforms. If the graceful shutdown phase does not
3678 finish during this period, close() will return, but the graceful
3679 shutdown phase will continue in the system.
3680
3681 Note that this is a socket-level option, not an SCTP-level option.
3682 When using this option, an application must specify a level of
3683 SOL_SOCKET in the call.
3684
36858.1.5. SCTP_NODELAY
3686
3687 This option turns on/off any Nagle-like algorithm. This means that
3688 packets are generally sent as soon as possible, and no unnecessary
3689 delays are introduced, at the cost of more packets in the network.
3690 In particular, not using any Nagle-like algorithm might reduce the
3691 bundling of small user messages in cases where this would require an
3692 additional delay.
3693
3694 Turning this option on disables any Nagle-like algorithm.
3695
3696
3697
3698Stewart, et al. Informational [Page 66]
3699
3700RFC 6458 SCTP Sockets API December 2011
3701
3702
3703 This option expects an integer boolean flag, where a non-zero value
3704 turns on the option, and a zero value turns off the option.
3705
37068.1.6. SO_RCVBUF
3707
3708 This option sets the receive buffer size in octets. For SCTP one-to-
3709 one style sockets, this option controls the receiver window size.
3710 For one-to-many style sockets, the meaning is implementation
3711 dependent. It might control the receive buffer for each association
3712 bound to the socket descriptor, or it might control the receive
3713 buffer for the whole socket. This option expects an integer.
3714
3715 Note that this is a socket-level option, not an SCTP-level option.
3716 When using this option, an application must specify a level of
3717 SOL_SOCKET in the call.
3718
37198.1.7. SO_SNDBUF
3720
3721 This option sets the send buffer size. For SCTP one-to-one style
3722 sockets, this option controls the amount of data SCTP may have
3723 waiting in internal buffers to be sent. This option therefore bounds
3724 the maximum size of data that can be sent in a single send call. For
3725 one-to-many style sockets, the effect is the same, except that it
3726 applies to one or all associations (see Section 3.3) bound to the
3727 socket descriptor used in the setsockopt() or getsockopt() call. The
3728 option applies to each association's window size separately. This
3729 option expects an integer.
3730
3731 Note that this is a socket-level option, not an SCTP-level option.
3732 When using this option, an application must specify a level of
3733 SOL_SOCKET in the call.
3734
37358.1.8. Automatic Close of Associations (SCTP_AUTOCLOSE)
3736
3737 This socket option is applicable to the one-to-many style socket
3738 only. When set, it will cause associations that are idle for more
3739 than the specified number of seconds to automatically close using the
3740 graceful shutdown procedure. An idle association is defined as an
3741 association that has not sent or received user data. The special
3742 value of '0' indicates that no automatic close of any association
3743 should be performed; this is the default value. This option expects
3744 an integer defining the number of seconds of idle time before an
3745 association is closed.
3746
3747
3748
3749
3750
3751
3752
3753
3754Stewart, et al. Informational [Page 67]
3755
3756RFC 6458 SCTP Sockets API December 2011
3757
3758
3759 An application using this option should enable the ability to receive
3760 the association change notification. This is the only mechanism by
3761 which an application is informed about the closing of an association.
3762 After an association is closed, the association identifier assigned
3763 to it can be reused. An application should be aware of this to avoid
3764 the possible problem of sending data to an incorrect peer endpoint.
3765
37668.1.9. Set Primary Address (SCTP_PRIMARY_ADDR)
3767
3768 This option requests that the local SCTP stack uses the enclosed peer
3769 address as the association's primary. The enclosed address must be
3770 one of the association peer's addresses.
3771
3772 The following structure is used to make a set peer primary request:
3773
3774 struct sctp_setprim {
3775 sctp_assoc_t ssp_assoc_id;
3776 struct sockaddr_storage ssp_addr;
3777 };
3778
3779 ssp_assoc_id: This parameter is ignored for one-to-one style
3780 sockets. For one-to-many style sockets, it identifies the
3781 association for this request. Note that the special sctp_assoc_t
3782 SCTP_{FUTURE|ALL|CURRENT}_ASSOC are not allowed.
3783
3784 ssp_addr: This parameter is the address to set as primary. No
3785 wildcard address is allowed.
3786
37878.1.10. Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER)
3788
3789 This option requests that the local endpoint set the specified
3790 Adaptation Layer Indication parameter for all future INIT and
3791 INIT-ACK exchanges.
3792
3793 The following structure is used to access and modify this parameter:
3794
3795 struct sctp_setadaptation {
3796 uint32_t ssb_adaptation_ind;
3797 };
3798
3799 ssb_adaptation_ind: The adaptation layer indicator that will be
3800 included in any outgoing Adaptation Layer Indication parameter.
3801
38028.1.11. Enable/Disable Message Fragmentation (SCTP_DISABLE_FRAGMENTS)
3803
3804 This option is an on/off flag and is passed as an integer, where a
3805 non-zero is on and a zero is off. If enabled, no SCTP message
3806 fragmentation will be performed. The effect of enabling this option
3807
3808
3809
3810Stewart, et al. Informational [Page 68]
3811
3812RFC 6458 SCTP Sockets API December 2011
3813
3814
3815 is that if a message being sent exceeds the current Path MTU (PMTU)
3816 size, the message will not be sent and instead an error will be
3817 indicated to the user. If this option is disabled (the default),
3818 then a message exceeding the size of the PMTU will be fragmented and
3819 reassembled by the peer.
3820
38218.1.12. Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
3822
3823 Applications can enable or disable heartbeats for any peer address of
3824 an association, modify an address's heartbeat interval, force a
3825 heartbeat to be sent immediately, and adjust the address's maximum
3826 number of retransmissions sent before an address is considered
3827 unreachable.
3828
3829 The following structure is used to access and modify an address's
3830 parameters:
3831
3832 struct sctp_paddrparams {
3833 sctp_assoc_t spp_assoc_id;
3834 struct sockaddr_storage spp_address;
3835 uint32_t spp_hbinterval;
3836 uint16_t spp_pathmaxrxt;
3837 uint32_t spp_pathmtu;
3838 uint32_t spp_flags;
3839 uint32_t spp_ipv6_flowlabel;
3840 uint8_t spp_dscp;
3841 };
3842
3843 spp_assoc_id: This parameter is ignored for one-to-one style
3844 sockets. For one-to-many style sockets, the application may fill
3845 in an association identifier or SCTP_FUTURE_ASSOC for this query.
3846 It is an error to use SCTP_{CURRENT|ALL}_ASSOC in spp_assoc_id.
3847
3848 spp_address: This specifies which address is of interest. If a
3849 wildcard address is provided, it applies to all current and future
3850 paths.
3851
3852 spp_hbinterval: This contains the value of the heartbeat interval,
3853 in milliseconds (HB.Interval in [RFC4960]). Note that unless the
3854 spp_flags field is set to SPP_HB_ENABLE, the value of this field
3855 is ignored. Note also that a value of zero indicates that the
3856 current setting should be left unchanged. To set an actual value
3857 of zero, the SPP_HB_TIME_IS_ZERO flag should be used. Even when
3858 it is set to 0, it does not mean that SCTP will continuously send
3859 out heartbeats, since the actual interval also includes the
3860 current RTO and jitter (see Section 8.3 of [RFC4960]).
3861
3862
3863
3864
3865
3866Stewart, et al. Informational [Page 69]
3867
3868RFC 6458 SCTP Sockets API December 2011
3869
3870
3871 spp_pathmaxrxt: This contains the maximum number of retransmissions
3872 before this address shall be considered unreachable. Note that a
3873 value of zero indicates that the current setting should be left
3874 unchanged.
3875
3876 spp_pathmtu: This field contains the current Path MTU of the peer
3877 address. It is the number of bytes available in an SCTP packet
3878 for chunks. Providing a value of 0 does not change the current
3879 setting. If a positive value is provided and SPP_PMTUD_DISABLE is
3880 set in the spp_flags field, the given value is used as the Path
3881 MTU. If SPP_PMTUD_ENABLE is set in the spp_flags field, the
3882 spp_pathmtu field is ignored.
3883
3884 spp_flags: These flags are used to control various features on an
3885 association. The flag field is a bitmask that may contain zero or
3886 more of the following options:
3887
3888 SPP_HB_ENABLE: This field enables heartbeats on the specified
3889 address.
3890
3891 SPP_HB_DISABLE: This field disables heartbeats on the specified
3892 address. Note that SPP_HB_ENABLE and SPP_HB_DISABLE are
3893 mutually exclusive; only one of these two should be specified.
3894 Enabling both fields will yield undetermined results.
3895
3896 SPP_HB_DEMAND: This field requests that a user-initiated
3897 heartbeat be made immediately. This must not be used in
3898 conjunction with a wildcard address.
3899
3900 SPP_HB_TIME_IS_ZERO: This field specifies that the time for
3901 heartbeat delay is to be set to 0 milliseconds.
3902
3903 SPP_PMTUD_ENABLE: This field will enable PMTU discovery on the
3904 specified address.
3905
3906 SPP_PMTUD_DISABLE: This field will disable PMTU discovery on the
3907 specified address. Note that if the address field is empty,
3908 then all addresses on the association are affected. Note also
3909 that SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually
3910 exclusive. Enabling both fields will yield undetermined
3911 results.
3912
3913 SPP_IPV6_FLOWLABEL: Setting this flag enables the setting of the
3914 IPV6 flow label value. The value is contained in the
3915 spp_ipv6_flowlabel field.
3916
3917
3918
3919
3920
3921
3922Stewart, et al. Informational [Page 70]
3923
3924RFC 6458 SCTP Sockets API December 2011
3925
3926
3927 Upon retrieval, this flag will be set to indicate that the
3928 spp_ipv6_flowlabel field has a valid value returned. If a
3929 specific destination address is set (in the spp_address field),
3930 then the value returned is that of the address. If just an
3931 association is specified (and no address), then the
3932 association's default flow label is returned. If neither an
3933 association nor a destination is specified, then the socket's
3934 default flow label is returned. For non-IPv6 sockets, this
3935 flag will be left cleared.
3936
3937 SPP_DSCP: Setting this flag enables the setting of the
3938 Differentiated Services Code Point (DSCP) value associated with
3939 either the association or a specific address. The value is
3940 obtained in the spp_dscp field.
3941
3942 Upon retrieval, this flag will be set to indicate that the
3943 spp_dscp field has a valid value returned. If a specific
3944 destination address is set when called (in the spp_address
3945 field), then that specific destination address's DSCP value is
3946 returned. If just an association is specified, then the
3947 association's default DSCP is returned. If neither an
3948 association nor a destination is specified, then the socket's
3949 default DSCP is returned.
3950
3951 spp_ipv6_flowlabel: This field is used in conjunction with the
3952 SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label. The 20
3953 least significant bits are used for the flow label. This setting
3954 has precedence over any IPv6-layer setting.
3955
3956 spp_dscp: This field is used in conjunction with the SPP_DSCP flag
3957 and contains the DSCP. The 6 most significant bits are used for
3958 the DSCP. This setting has precedence over any IPv4- or IPv6-
3959 layer setting.
3960
3961 Please note that changing the flow label or DSCP value will affect
3962 all packets sent by the SCTP stack after setting these parameters.
3963 The flow label might also be set via the sin6_flowinfo field of the
3964 sockaddr_in6 structure.
3965
39668.1.13. Set Default Send Parameters (SCTP_DEFAULT_SEND_PARAM) -
3967 DEPRECATED
3968
3969 Please note that this option is deprecated. SCTP_DEFAULT_SNDINFO
3970 (Section 8.1.31) should be used instead.
3971
3972 Applications that wish to use the sendto() system call may wish to
3973 specify a default set of parameters that would normally be supplied
3974 through the inclusion of ancillary data. This socket option allows
3975
3976
3977
3978Stewart, et al. Informational [Page 71]
3979
3980RFC 6458 SCTP Sockets API December 2011
3981
3982
3983 such an application to set the default sctp_sndrcvinfo structure.
3984 The application that wishes to use this socket option simply passes
3985 the sctp_sndrcvinfo structure (defined in Section 5.3.2) to this
3986 call. The input parameters accepted by this call include
3987 sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, and
3988 sinfo_timetolive. The sinfo_flags field is composed of a bitwise OR
3989 of SCTP_UNORDERED, SCTP_EOF, and SCTP_SENDALL. The sinfo_assoc_id
3990 field specifies the association to which to apply the parameters.
3991 For a one-to-many style socket, any of the predefined constants are
3992 also allowed in this field. The field is ignored for one-to-one
3993 style sockets.
3994
39958.1.14. Set Notification and Ancillary Events (SCTP_EVENTS) -
3996 DEPRECATED
3997
3998 This socket option is used to specify various notifications and
3999 ancillary data the user wishes to receive. Please see Section 6.2.1
4000 for a full description of this option and its usage. Note that this
4001 option is considered deprecated and is present for backward
4002 compatibility. New applications should use the SCTP_EVENT option.
4003 See Section 6.2.2 for a full description of that option as well.
4004
40058.1.15. Set/Clear IPv4 Mapped Addresses (SCTP_I_WANT_MAPPED_V4_ADDR)
4006
4007 This socket option is a boolean flag that turns on or off the mapping
4008 of IPv4 addresses. If this option is turned on, then IPv4 addresses
4009 will be mapped to IPv6 representation. If this option is turned off,
4010 then no mapping will be done of IPv4 addresses, and a user will
4011 receive both PF_INET6 and PF_INET type addresses on the socket. See
4012 [RFC3542] for more details on mapped IPv6 addresses.
4013
4014 If this socket option is used on a socket of type PF_INET, an error
4015 is returned.
4016
4017 By default, this option is turned off and expects an integer to be
4018 passed where a non-zero value turns on the option and a zero value
4019 turns off the option.
4020
40218.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
4022
4023 This option will get or set the maximum size to put in any outgoing
4024 SCTP DATA chunk. If a message is larger than this maximum size, it
4025 will be fragmented by SCTP into the specified size. Note that the
4026 underlying SCTP implementation may fragment into smaller sized chunks
4027 when the PMTU of the underlying association is smaller than the value
4028 set by the user. The default value for this option is '0', which
4029 indicates that the user is not limiting fragmentation and only the
4030 PMTU will affect SCTP's choice of DATA chunk size. Note also that
4031
4032
4033
4034Stewart, et al. Informational [Page 72]
4035
4036RFC 6458 SCTP Sockets API December 2011
4037
4038
4039 values set larger than the maximum size of an IP datagram will
4040 effectively let SCTP control fragmentation (i.e., the same as setting
4041 this option to 0).
4042
4043 The following structure is used to access and modify this parameter:
4044
4045 struct sctp_assoc_value {
4046 sctp_assoc_t assoc_id;
4047 uint32_t assoc_value;
4048 };
4049
4050 assoc_id: This parameter is ignored for one-to-one style sockets.
4051 For one-to-many style sockets, this parameter indicates upon which
4052 association the user is performing an action. It is an error to
4053 use SCTP_{CURRENT|ALL}_ASSOC in assoc_id.
4054
4055 assoc_value: This parameter specifies the maximum size in bytes.
4056
40578.1.17. Get or Set the List of Supported HMAC Identifiers
4058 (SCTP_HMAC_IDENT)
4059
4060 This option gets or sets the list of Hashed Message Authentication
4061 Code (HMAC) algorithms that the local endpoint requires the peer
4062 to use.
4063
4064 The following structure is used to get or set these identifiers:
4065
4066 struct sctp_hmacalgo {
4067 uint32_t shmac_number_of_idents;
4068 uint16_t shmac_idents[];
4069 };
4070
4071 shmac_number_of_idents: This field gives the number of elements
4072 present in the array shmac_idents.
4073
4074 shmac_idents: This parameter contains an array of HMAC identifiers
4075 that the local endpoint is requesting the peer to use, in priority
4076 order. The following identifiers are valid:
4077
4078 * SCTP_AUTH_HMAC_ID_SHA1
4079
4080 * SCTP_AUTH_HMAC_ID_SHA256
4081
4082 Note that the list supplied must include SCTP_AUTH_HMAC_ID_SHA1 and
4083 may include any of the other values in its preferred order (lowest
4084 list position has the highest preference in algorithm selection).
4085
4086
4087
4088
4089
4090Stewart, et al. Informational [Page 73]
4091
4092RFC 6458 SCTP Sockets API December 2011
4093
4094
4095 Note also that the lack of SCTP_AUTH_HMAC_ID_SHA1, or the inclusion
4096 of an unknown HMAC identifier (including optional identifiers unknown
4097 to the implementation), will cause the set option to fail and return
4098 an error.
4099
41008.1.18. Get or Set the Active Shared Key (SCTP_AUTH_ACTIVE_KEY)
4101
4102 This option will get or set the active shared key to be used to build
4103 the association shared key.
4104
4105 The following structure is used to access and modify these
4106 parameters:
4107
4108 struct sctp_authkeyid {
4109 sctp_assoc_t scact_assoc_id;
4110 uint16_t scact_keynumber;
4111 };
4112
4113 scact_assoc_id: This parameter sets the active key of the specified
4114 association. The special SCTP_{FUTURE|CURRENT|ALL}_ASSOC can be
4115 used. For one-to-one style sockets, this parameter is ignored.
4116 Note, however, that this option will set the active key on the
4117 association if the socket is connected; otherwise, this option
4118 will set the default active key for the endpoint.
4119
4120 scact_keynumber: This parameter is the shared key identifier that
4121 the application is requesting to become the active shared key to
4122 be used for sending authenticated chunks. The key identifier must
4123 correspond to an existing shared key. Note that shared key
4124 identifier '0' defaults to a null key.
4125
4126 When used with setsockopt(), the SCTP implementation must use the
4127 indicated shared key identifier for all messages being given to an
4128 SCTP implementation via a send call after the setsockopt() call,
4129 until changed again. Therefore, the SCTP implementation must not
4130 bundle user messages that should be authenticated using different
4131 shared key identifiers.
4132
4133 Initially, the key with key identifier 0 is the active key.
4134
41358.1.19. Get or Set Delayed SACK Timer (SCTP_DELAYED_SACK)
4136
4137 This option will affect the way delayed SACKs are performed. This
4138 option allows the application to get or set the delayed SACK time, in
4139 milliseconds. It also allows changing the delayed SACK frequency.
4140 Changing the frequency to 1 disables the delayed SACK algorithm.
4141 Note that if sack_delay or sack_freq is 0 when setting this option,
4142 the current values will remain unchanged.
4143
4144
4145
4146Stewart, et al. Informational [Page 74]
4147
4148RFC 6458 SCTP Sockets API December 2011
4149
4150
4151 The following structure is used to access and modify these
4152 parameters:
4153
4154 struct sctp_sack_info {
4155 sctp_assoc_t sack_assoc_id;
4156 uint32_t sack_delay;
4157 uint32_t sack_freq;
4158 };
4159
4160 sack_assoc_id: This parameter is ignored for one-to-one style
4161 sockets. For one-to-many style sockets, this parameter indicates
4162 upon which association the user is performing an action. The
4163 special SCTP_{FUTURE|CURRENT|ALL}_ASSOC can also be used.
4164
4165 sack_delay: This parameter contains the number of milliseconds the
4166 user is requesting that the delayed SACK timer be set to. Note
4167 that this value is defined in [RFC4960] to be between 200 and 500
4168 milliseconds.
4169
4170 sack_freq: This parameter contains the number of packets that must
4171 be received before a SACK is sent without waiting for the delay
4172 timer to expire. The default value is 2; setting this value to 1
4173 will disable the delayed SACK algorithm.
4174
41758.1.20. Get or Set Fragmented Interleave (SCTP_FRAGMENT_INTERLEAVE)
4176
4177 Fragmented interleave controls how the presentation of messages
4178 occurs for the message receiver. There are three levels of fragment
4179 interleave defined. Two of the levels affect one-to-one style
4180 sockets, while one-to-many style sockets are affected by all three
4181 levels.
4182
4183 This option takes an integer value. It can be set to a value of 0,
4184 1, or 2. Attempting to set this level to other values will return an
4185 error.
4186
4187 Setting the three levels provides the following receiver
4188 interactions:
4189
4190 level 0: Prevents the interleaving of any messages. This means that
4191 when a partial delivery begins, no other messages will be received
4192 except the message being partially delivered. If another message
4193 arrives on a different stream (or association) that could be
4194 delivered, it will be blocked waiting for the user to read all of
4195 the partially delivered message.
4196
4197
4198
4199
4200
4201
4202Stewart, et al. Informational [Page 75]
4203
4204RFC 6458 SCTP Sockets API December 2011
4205
4206
4207 level 1: Allows interleaving of messages that are from different
4208 associations. For one-to-one style sockets, level 0 and level 1
4209 thus have the same meaning, since a one-to-one style socket always
4210 receives messages from the same association. Note that setting a
4211 one-to-many style socket to this level may cause multiple partial
4212 deliveries from different associations, but for any given
4213 association, only one message will be delivered until all parts of
4214 a message have been delivered. This means that one large message,
4215 being read with an association identifier of "X", will block other
4216 messages from association "X" from being delivered.
4217
4218 level 2: Allows complete interleaving of messages. This level
4219 requires that the sender not only carefully observe the peer
4220 association identifier (or address) but also pay careful attention
4221 to the stream number. With this option enabled, a partially
4222 delivered message may begin being delivered for association "X"
4223 stream "Y", and the next subsequent receive may return a message
4224 from association "X" stream "Z". Note that no other messages
4225 would be delivered for association "X" stream "Y" until all of
4226 stream "Y"'s partially delivered message was read. Note that this
4227 option also affects one-to-one style sockets. Also note that for
4228 one-to-many style sockets, not only another stream's message from
4229 the same association may be delivered upon the next receive, but
4230 some other association's message may also be delivered upon the
4231 next receive.
4232
4233 An implementation should default one-to-many style sockets to level
4234 1, because otherwise, it is possible that a peer could begin sending
4235 a partial message and thus block all other peers from sending data.
4236 However, a setting of level 2 requires that the application not only
4237 be aware of the association (via the association identifier or peer's
4238 address) but also the stream number. The stream number is not
4239 present unless the user has subscribed to the sctp_data_io_event (see
4240 Section 6.2), which is deprecated, or has enabled the
4241 SCTP_RECVRCVINFO socket option (see Section 8.1.29). This is also
4242 why we recommend that one-to-one style sockets be defaulted to level
4243 0 (level 1 for one-to-one style sockets has no effect). Note that an
4244 implementation should return an error if an application attempts to
4245 set the level to 2 and has not subscribed to the sctp_data_io_event
4246 event, which is deprecated, or has enabled the SCTP_RECVRCVINFO
4247 socket option.
4248
4249 For applications that have subscribed to events, those events appear
4250 in the normal socket buffer data stream. This means that unless the
4251 user has set the fragmentation interleave level to 0, notifications
4252 may also be interleaved with partially delivered messages.
4253
4254
4255
4256
4257
4258Stewart, et al. Informational [Page 76]
4259
4260RFC 6458 SCTP Sockets API December 2011
4261
4262
42638.1.21. Set or Get the SCTP Partial Delivery Point
4264 (SCTP_PARTIAL_DELIVERY_POINT)
4265
4266 This option will set or get the SCTP partial delivery point. This
4267 point is the size of a message where the partial delivery API will be
4268 invoked to help free up rwnd space for the peer. Setting this to a
4269 lower value will cause partial deliveries to happen more often. This
4270 option expects an integer that sets or gets the partial delivery
4271 point in bytes. Note also that the call will fail if the user
4272 attempts to set this value larger than the socket receive buffer
4273 size.
4274
4275 Note that any single message having a length smaller than or equal to
4276 the SCTP partial delivery point will be delivered in a single read
4277 call as long as the user-provided buffer is large enough to hold the
4278 message.
4279
42808.1.22. Set or Get the Use of Extended Receive Info
4281 (SCTP_USE_EXT_RCVINFO) - DEPRECATED
4282
4283 This option will enable or disable the use of the extended version of
4284 the sctp_sndrcvinfo structure. If this option is disabled, then the
4285 normal sctp_sndrcvinfo structure is returned in all receive message
4286 calls. If this option is enabled, then the sctp_extrcvinfo structure
4287 is returned in all receive message calls. The default is off.
4288
4289 Note that the sctp_extrcvinfo structure is never used in any send
4290 call.
4291
4292 This option is present for compatibility with older applications and
4293 is deprecated. Future applications should use SCTP_NXTINFO to
4294 retrieve this same information via ancillary data.
4295
42968.1.23. Set or Get the Auto ASCONF Flag (SCTP_AUTO_ASCONF)
4297
4298 This option will enable or disable the use of the automatic
4299 generation of ASCONF chunks to add and delete addresses to an
4300 existing association. Note that this option has two caveats, namely
4301 a) it only affects sockets that are bound to all addresses available
4302 to the SCTP stack, and b) the system administrator may have an
4303 overriding control that turns the ASCONF feature off no matter what
4304 setting the socket option may have.
4305
4306 This option expects an integer boolean flag, where a non-zero value
4307 turns on the option, and a zero value turns off the option.
4308
4309
4310
4311
4312
4313
4314Stewart, et al. Informational [Page 77]
4315
4316RFC 6458 SCTP Sockets API December 2011
4317
4318
43198.1.24. Set or Get the Maximum Burst (SCTP_MAX_BURST)
4320
4321 This option will allow a user to change the maximum burst of packets
4322 that can be emitted by this association. Note that the default value
4323 is 4, and some implementations may restrict this setting so that it
4324 can only be lowered to positive values.
4325
4326 To set or get this option, the user fills in the following structure:
4327
4328 struct sctp_assoc_value {
4329 sctp_assoc_t assoc_id;
4330 uint32_t assoc_value;
4331 };
4332
4333 assoc_id: This parameter is ignored for one-to-one style sockets.
4334 For one-to-many style sockets, this parameter indicates upon which
4335 association the user is performing an action. The special
4336 SCTP_{FUTURE|CURRENT|ALL}_ASSOC can also be used.
4337
4338 assoc_value: This parameter contains the maximum burst. Setting the
4339 value to 0 disables burst mitigation.
4340
43418.1.25. Set or Get the Default Context (SCTP_CONTEXT)
4342
4343 The context field in the sctp_sndrcvinfo structure is normally only
4344 used when a failed message is retrieved holding the value that was
4345 sent down on the actual send call. This option allows the setting,
4346 on an association basis, of a default context that will be received
4347 on reading messages from the peer. This is especially helpful for an
4348 application when using one-to-many style sockets to keep some
4349 reference to an internal state machine that is processing messages on
4350 the association. Note that the setting of this value only affects
4351 received messages from the peer and does not affect the value that is
4352 saved with outbound messages.
4353
4354 To set or get this option, the user fills in the following structure:
4355
4356 struct sctp_assoc_value {
4357 sctp_assoc_t assoc_id;
4358 uint32_t assoc_value;
4359 };
4360
4361 assoc_id: This parameter is ignored for one-to-one style sockets.
4362 For one-to-many style sockets, this parameter indicates upon which
4363 association the user is performing an action. The special
4364 SCTP_{FUTURE|CURRENT|ALL}_ASSOC can also be used.
4365
4366 assoc_value: This parameter contains the context.
4367
4368
4369
4370Stewart, et al. Informational [Page 78]
4371
4372RFC 6458 SCTP Sockets API December 2011
4373
4374
43758.1.26. Enable or Disable Explicit EOR Marking (SCTP_EXPLICIT_EOR)
4376
4377 This boolean flag is used to enable or disable explicit end of record
4378 (EOR) marking. When this option is enabled, a user may make multiple
4379 send system calls to send a record and must indicate that they are
4380 finished sending a particular record by including the SCTP_EOR flag.
4381 If this boolean flag is disabled, then each individual send system
4382 call is considered to have an SCTP_EOR indicator set on it implicitly
4383 without the user having to explicitly add this flag. The default
4384 is off.
4385
4386 This option expects an integer boolean flag, where a non-zero value
4387 turns on the option, and a zero value turns off the option.
4388
43898.1.27. Enable SCTP Port Reusage (SCTP_REUSE_PORT)
4390
4391 This option only supports one-to-one style SCTP sockets. If used on
4392 a one-to-many style SCTP socket, an error is indicated.
4393
4394 This option expects an integer boolean flag, where a non-zero value
4395 turns on the option, and a zero value turns off the option.
4396
4397 This socket option must not be used after calling bind() or
4398 sctp_bindx() for a one-to-one style SCTP socket. If using bind() or
4399 sctp_bindx() on a socket with the SCTP_REUSE_PORT option, all other
4400 SCTP sockets bound to the same port must have set the SCTP_REUSE_PORT
4401 option. Calling bind() or sctp_bindx() for a socket without having
4402 set the SCTP_REUSE_PORT option will fail if there are other sockets
4403 bound to the same port. At most one socket being bound to the same
4404 port may be listening.
4405
4406 It should be noted that the behavior of the socket-level socket
4407 option to reuse ports and/or addresses for SCTP sockets is
4408 unspecified.
4409
44108.1.28. Set Notification Event (SCTP_EVENT)
4411
4412 This socket option is used to set a specific notification option.
4413 Please see Section 6.2.2 for a full description of this option and
4414 its usage.
4415
44168.1.29. Enable or Disable the Delivery of SCTP_RCVINFO as Ancillary
4417 Data (SCTP_RECVRCVINFO)
4418
4419 Setting this option specifies that SCTP_RCVINFO (defined in
4420 Section 5.3.5) is returned as ancillary data by recvmsg().
4421
4422
4423
4424
4425
4426Stewart, et al. Informational [Page 79]
4427
4428RFC 6458 SCTP Sockets API December 2011
4429
4430
4431 This option expects an integer boolean flag, where a non-zero value
4432 turns on the option, and a zero value turns off the option.
4433
44348.1.30. Enable or Disable the Delivery of SCTP_NXTINFO as Ancillary
4435 Data (SCTP_RECVNXTINFO)
4436
4437 Setting this option specifies that SCTP_NXTINFO (defined in
4438 Section 5.3.6) is returned as ancillary data by recvmsg().
4439
4440 This option expects an integer boolean flag, where a non-zero value
4441 turns on the option, and a zero value turns off the option.
4442
44438.1.31. Set Default Send Parameters (SCTP_DEFAULT_SNDINFO)
4444
4445 Applications that wish to use the sendto() system call may wish to
4446 specify a default set of parameters that would normally be supplied
4447 through the inclusion of ancillary data. This socket option allows
4448 such an application to set the default sctp_sndinfo structure. The
4449 application that wishes to use this socket option simply passes the
4450 sctp_sndinfo structure (defined in Section 5.3.4) to this call. The
4451 input parameters accepted by this call include snd_sid, snd_flags,
4452 snd_ppid, and snd_context. The snd_flags parameter is composed of a
4453 bitwise OR of SCTP_UNORDERED, SCTP_EOF, and SCTP_SENDALL. The
4454 snd_assoc_id field specifies the association to which to apply the
4455 parameters. For a one-to-many style socket, any of the predefined
4456 constants are also allowed in this field. The field is ignored for
4457 one-to-one style sockets.
4458
44598.1.32. Set Default PR-SCTP Parameters (SCTP_DEFAULT_PRINFO)
4460
4461 This option sets and gets the default parameters for PR-SCTP. They
4462 can be overwritten by specific information provided in send calls.
4463
4464 The following structure is used to access and modify these
4465 parameters:
4466
4467 struct sctp_default_prinfo {
4468 uint16_t pr_policy;
4469 uint32_t pr_value;
4470 sctp_assoc_t pr_assoc_id;
4471 };
4472
4473 pr_policy: This field is the same as that described in
4474 Section 5.3.7.
4475
4476 pr_value: This field is the same as that described in Section 5.3.7.
4477
4478
4479
4480
4481
4482Stewart, et al. Informational [Page 80]
4483
4484RFC 6458 SCTP Sockets API December 2011
4485
4486
4487 pr_assoc_id: This field is ignored for one-to-one style sockets.
4488 For one-to-many style sockets, pr_assoc_id can be a particular
4489 association identifier or SCTP_{FUTURE|CURRENT|ALL}_ASSOC.
4490
44918.2. Read-Only Options
4492
4493 The options defined in this subsection are read-only. Using this
4494 option in a setsockopt() call will result in an error indicating
4495 EOPNOTSUPP.
4496
44978.2.1. Association Status (SCTP_STATUS)
4498
4499 Applications can retrieve current status information about an
4500 association, including association state, peer receiver window size,
4501 number of unacknowledged DATA chunks, and number of DATA chunks
4502 pending receipt. This information is read-only.
4503
4504 The following structure is used to access this information:
4505
4506 struct sctp_status {
4507 sctp_assoc_t sstat_assoc_id;
4508 int32_t sstat_state;
4509 uint32_t sstat_rwnd;
4510 uint16_t sstat_unackdata;
4511 uint16_t sstat_penddata;
4512 uint16_t sstat_instrms;
4513 uint16_t sstat_outstrms;
4514 uint32_t sstat_fragmentation_point;
4515 struct sctp_paddrinfo sstat_primary;
4516 };
4517
4518 sstat_assoc_id: This parameter is ignored for one-to-one style
4519 sockets. For one-to-many style sockets, it holds the identifier
4520 for the association. All notifications for a given association
4521 have the same association identifier. The special SCTP_{FUTURE|
4522 CURRENT|ALL}_ASSOC cannot be used.
4523
4524 sstat_state: This contains the association's current state, i.e.,
4525 one of the following values:
4526
4527 * SCTP_CLOSED
4528
4529 * SCTP_BOUND
4530
4531 * SCTP_LISTEN
4532
4533 * SCTP_COOKIE_WAIT
4534
4535
4536
4537
4538Stewart, et al. Informational [Page 81]
4539
4540RFC 6458 SCTP Sockets API December 2011
4541
4542
4543 * SCTP_COOKIE_ECHOED
4544
4545 * SCTP_ESTABLISHED
4546
4547 * SCTP_SHUTDOWN_PENDING
4548
4549 * SCTP_SHUTDOWN_SENT
4550
4551 * SCTP_SHUTDOWN_RECEIVED
4552
4553 * SCTP_SHUTDOWN_ACK_SENT
4554
4555 sstat_rwnd: This contains the association peer's current receiver
4556 window size.
4557
4558 sstat_unackdata: This is the number of unacknowledged DATA chunks.
4559
4560 sstat_penddata: This is the number of DATA chunks pending receipt.
4561
4562 sstat_instrms: This is the number of streams that the peer will be
4563 using outbound.
4564
4565 sstat_outstrms: This is the number of outbound streams that the
4566 endpoint is allowed to use.
4567
4568 sstat_fragmentation_point: This is the size at which SCTP
4569 fragmentation will occur.
4570
4571 sstat_primary: This is information on the current primary peer
4572 address.
4573
4574 To access these status values, the application calls getsockopt()
4575 with the option name SCTP_STATUS.
4576
45778.2.2. Peer Address Information (SCTP_GET_PEER_ADDR_INFO)
4578
4579 Applications can retrieve information about a specific peer address
4580 of an association, including its reachability state, congestion
4581 window, and retransmission timer values. This information is
4582 read-only.
4583
4584 The following structure is used to access this information:
4585
4586 struct sctp_paddrinfo {
4587 sctp_assoc_t spinfo_assoc_id;
4588 struct sockaddr_storage spinfo_address;
4589 int32_t spinfo_state;
4590 uint32_t spinfo_cwnd;
4591
4592
4593
4594Stewart, et al. Informational [Page 82]
4595
4596RFC 6458 SCTP Sockets API December 2011
4597
4598
4599 uint32_t spinfo_srtt;
4600 uint32_t spinfo_rto;
4601 uint32_t spinfo_mtu;
4602 };
4603
4604 spinfo_assoc_id: This parameter is ignored for one-to-one style
4605 sockets.
4606
4607 For one-to-many style sockets, this field may be filled by the
4608 application, and if so, this field will have priority in looking
4609 up the association instead of using the address specified in
4610 spinfo_address. Note that if the address does not belong to the
4611 association specified, then this call will fail. If the
4612 application does not fill in the spinfo_assoc_id, then the address
4613 will be used to look up the association, and on return, this field
4614 will have the valid association identifier. In other words, this
4615 call can be used to translate an address into an association
4616 identifier. Note that the predefined constants are not allowed
4617 for this option.
4618
4619 spinfo_address: This is filled by the application and contains the
4620 peer address of interest.
4621
4622 spinfo_state: This contains the peer address's state:
4623
4624 SCTP_UNCONFIRMED: This is the initial state of a peer address.
4625
4626 SCTP_ACTIVE: This state is entered the first time after path
4627 verification. It can also be entered if the state is
4628 SCTP_INACTIVE and the path supervision detects that the peer
4629 address is reachable again.
4630
4631 SCTP_INACTIVE: This state is entered whenever a path failure is
4632 detected.
4633
4634 spinfo_cwnd: This contains the peer address's current congestion
4635 window.
4636
4637 spinfo_srtt: This contains the peer address's current smoothed
4638 round-trip time calculation in milliseconds.
4639
4640 spinfo_rto: This contains the peer address's current retransmission
4641 timeout value in milliseconds.
4642
4643 spinfo_mtu: This is the current Path MTU of the peer address. It is
4644 the number of bytes available in an SCTP packet for chunks.
4645
4646
4647
4648
4649
4650Stewart, et al. Informational [Page 83]
4651
4652RFC 6458 SCTP Sockets API December 2011
4653
4654
46558.2.3. Get the List of Chunks the Peer Requires to Be Authenticated
4656 (SCTP_PEER_AUTH_CHUNKS)
4657
4658 This option gets a list of chunk types (see [RFC4960]) for a
4659 specified association that the peer requires to be received
4660 authenticated only.
4661
4662 The following structure is used to access these parameters:
4663
4664 struct sctp_authchunks {
4665 sctp_assoc_t gauth_assoc_id;
4666 uint32_t gauth_number_of_chunks
4667 uint8_t gauth_chunks[];
4668 };
4669
4670 gauth_assoc_id: This parameter indicates for which association the
4671 user is requesting the list of peer-authenticated chunks. For
4672 one-to-one style sockets, this parameter is ignored. Note that
4673 the predefined constants are not allowed with this option.
4674
4675 gauth_number_of_chunks: This parameter gives the number of elements
4676 in the array gauth_chunks.
4677
4678 gauth_chunks: This parameter contains an array of chunk types that
4679 the peer is requesting to be authenticated. If the passed-in
4680 buffer size is not large enough to hold the list of chunk types,
4681 ENOBUFS is returned.
4682
46838.2.4. Get the List of Chunks the Local Endpoint Requires to Be
4684 Authenticated (SCTP_LOCAL_AUTH_CHUNKS)
4685
4686 This option gets a list of chunk types (see [RFC4960]) for a
4687 specified association that the local endpoint requires to be received
4688 authenticated only.
4689
4690 The following structure is used to access these parameters:
4691
4692 struct sctp_authchunks {
4693 sctp_assoc_t gauth_assoc_id;
4694 uint32_t gauth_number_of_chunks;
4695 uint8_t gauth_chunks[];
4696 };
4697
4698 gauth_assoc_id: This parameter is ignored for one-to-one style
4699 sockets. For one-to-many style sockets, the application may fill
4700 in an association identifier or SCTP_FUTURE_ASSOC. It is an error
4701 to use SCTP_{CURRENT|ALL}_ASSOC in gauth_assoc_id.
4702
4703
4704
4705
4706Stewart, et al. Informational [Page 84]
4707
4708RFC 6458 SCTP Sockets API December 2011
4709
4710
4711 gauth_number_of_chunks: This parameter gives the number of elements
4712 in the array gauth_chunks.
4713
4714 gauth_chunks: This parameter contains an array of chunk types that
4715 the local endpoint is requesting to be authenticated. If the
4716 passed-in buffer is not large enough to hold the list of chunk
4717 types, ENOBUFS is returned.
4718
47198.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
4720
4721 This option gets the current number of associations that are attached
4722 to a one-to-many style socket. The option value is an uint32_t.
4723 Note that this number is only a snapshot. This means that the number
4724 of associations may have changed when the caller gets back the option
4725 result.
4726
4727 For a one-to-one style socket, this socket option results in an
4728 error.
4729
47308.2.6. Get the Current Identifiers of Associations
4731 (SCTP_GET_ASSOC_ID_LIST)
4732
4733 This option gets the current list of SCTP association identifiers of
4734 the SCTP associations handled by a one-to-many style socket.
4735
4736 The option value has the structure
4737
4738 struct sctp_assoc_ids {
4739 uint32_t gaids_number_of_ids;
4740 sctp_assoc_t gaids_assoc_id[];
4741 };
4742
4743 The caller must provide a large enough buffer to hold all association
4744 identifiers. If the buffer is too small, an error must be returned.
4745 The user can use the SCTP_GET_ASSOC_NUMBER socket option to get an
4746 idea of how large the buffer has to be. gaids_number_of_ids gives
4747 the number of elements in the array gaids_assoc_id. Note also that
4748 some or all of sctp_assoc_t returned in the array may become invalid
4749 by the time the caller gets back the result.
4750
4751 For a one-to-one style socket, this socket option results in an
4752 error.
4753
47548.3. Write-Only Options
4755
4756 The options defined in this subsection are write-only. Using this
4757 option in a getsockopt() or sctp_opt_info() call will result in an
4758 error indicating EOPNOTSUPP.
4759
4760
4761
4762Stewart, et al. Informational [Page 85]
4763
4764RFC 6458 SCTP Sockets API December 2011
4765
4766
47678.3.1. Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
4768
4769 This call requests that the peer mark the enclosed address as the
4770 association primary (see [RFC5061]). The enclosed address must be
4771 one of the association's locally bound addresses.
4772
4773 The following structure is used to make a set peer primary request:
4774
4775 struct sctp_setpeerprim {
4776 sctp_assoc_t sspp_assoc_id;
4777 struct sockaddr_storage sspp_addr;
4778 };
4779
4780 sspp_assoc_id: This parameter is ignored for one-to-one style
4781 sockets. For one-to-many style sockets, it identifies the
4782 association for this request. Note that the predefined constants
4783 are not allowed for this option.
4784
4785 sspp_addr: The address to set as primary.
4786
47878.3.2. Add a Chunk That Must Be Authenticated (SCTP_AUTH_CHUNK)
4788
4789 This set option adds a chunk type that the user is requesting to be
4790 received only in an authenticated way. Changes to the list of chunks
4791 will only affect future associations on the socket.
4792
4793 The following structure is used to add a chunk:
4794
4795 struct sctp_authchunk {
4796 uint8_t sauth_chunk;
4797 };
4798
4799 sauth_chunk: This parameter contains a chunk type that the user is
4800 requesting to be authenticated.
4801
4802 The chunk types for INIT, INIT-ACK, SHUTDOWN-COMPLETE, and AUTH
4803 chunks must not be used. If they are used, an error must be
4804 returned. The usage of this option enables SCTP AUTH in cases where
4805 it is not required by other means (for example, the use of dynamic
4806 address reconfiguration).
4807
48088.3.3. Set a Shared Key (SCTP_AUTH_KEY)
4809
4810 This option will set a shared secret key that is used to build an
4811 association shared key.
4812
4813 The following structure is used to access and modify these
4814 parameters:
4815
4816
4817
4818Stewart, et al. Informational [Page 86]
4819
4820RFC 6458 SCTP Sockets API December 2011
4821
4822
4823 struct sctp_authkey {
4824 sctp_assoc_t sca_assoc_id;
4825 uint16_t sca_keynumber;
4826 uint16_t sca_keylength;
4827 uint8_t sca_key[];
4828 };
4829
4830 sca_assoc_id: This parameter indicates on what association the
4831 shared key is being set. The special SCTP_{FUTURE|CURRENT|
4832 ALL}_ASSOC can be used. For one-to-one style sockets, this
4833 parameter is ignored. Note, however, that on one-to-one style
4834 sockets, this option will set a key on the association if the
4835 socket is connected; otherwise, this option will set a key on the
4836 endpoint.
4837
4838 sca_keynumber: This parameter is the shared key identifier by which
4839 the application will refer to this shared key. If a key of the
4840 specified index already exists, then this new key will replace the
4841 old existing key. Note that shared key identifier '0' defaults to
4842 a null key.
4843
4844 sca_keylength: This parameter is the length of the array sca_key.
4845
4846 sca_key: This parameter contains an array of bytes that is to be
4847 used by the endpoint (or association) as the shared secret key.
4848 Note that if the length of this field is zero, a null key is set.
4849
48508.3.4. Deactivate a Shared Key (SCTP_AUTH_DEACTIVATE_KEY)
4851
4852 This set option indicates that the application will no longer send
4853 user messages using the indicated key identifier.
4854
4855 struct sctp_authkeyid {
4856 sctp_assoc_t scact_assoc_id;
4857 uint16_t scact_keynumber;
4858 };
4859
4860 scact_assoc_id: This parameter indicates from which association the
4861 shared key identifier is being deleted. The special SCTP_{FUTURE|
4862 CURRENT|ALL}_ASSOC can be used. For one-to-one style sockets,
4863 this parameter is ignored. Note, however, that this option will
4864 deactivate the key from the association if the socket is
4865 connected; otherwise, this option will deactivate the key from the
4866 endpoint.
4867
4868
4869
4870
4871
4872
4873
4874Stewart, et al. Informational [Page 87]
4875
4876RFC 6458 SCTP Sockets API December 2011
4877
4878
4879 scact_keynumber: This parameter is the shared key identifier that
4880 the application is requesting to be deactivated. The key
4881 identifier must correspond to an existing shared key. Note that
4882 if this parameter is zero, use of the null key identifier '0' is
4883 deactivated on the endpoint and/or association.
4884
4885 The currently active key cannot be deactivated.
4886
48878.3.5. Delete a Shared Key (SCTP_AUTH_DELETE_KEY)
4888
4889 This set option will delete an SCTP association's shared secret key
4890 that has been deactivated.
4891
4892 struct sctp_authkeyid {
4893 sctp_assoc_t scact_assoc_id;
4894 uint16_t scact_keynumber;
4895 };
4896
4897 scact_assoc_id: This parameter indicates from which association the
4898 shared key identifier is being deleted. The special SCTP_{FUTURE|
4899 CURRENT|ALL}_ASSOC can be used. For one-to-one style sockets,
4900 this parameter is ignored. Note, however, that this option will
4901 delete the key from the association if the socket is connected;
4902 otherwise, this option will delete the key from the endpoint.
4903
4904 scact_keynumber: This parameter is the shared key identifier that
4905 the application is requesting to be deleted. The key identifier
4906 must correspond to an existing shared key and must not be in use
4907 for any packet being sent by the SCTP implementation. This means,
4908 in particular, that it must be deactivated first. Note that if
4909 this parameter is zero, use of the null key identifier '0' is
4910 deleted from the endpoint and/or association.
4911
4912 Only deactivated keys that are no longer used by an association can
4913 be deleted.
4914
49159. New Functions
4916
4917 Depending on the system, the following interface can be implemented
4918 as a system call or library function.
4919
49209.1. sctp_bindx()
4921
4922 This function allows the user to bind a specific subset of addresses
4923 or, if the SCTP extension described in [RFC5061] is supported, add or
4924 delete specific addresses.
4925
4926
4927
4928
4929
4930Stewart, et al. Informational [Page 88]
4931
4932RFC 6458 SCTP Sockets API December 2011
4933
4934
4935 The function prototype is
4936
4937 int sctp_bindx(int sd,
4938 struct sockaddr *addrs,
4939 int addrcnt,
4940 int flags);
4941
4942 If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
4943 If the sd is an IPv6 socket, the addresses passed can either be IPv4
4944 or IPv6 addresses.
4945
4946 A single address may be specified as INADDR_ANY for an IPv4 address,
4947 or as IN6ADDR_ANY_INIT or in6addr_any for an IPv6 address; see
4948 Section 3.1.2 for this usage.
4949
4950 addrs is a pointer to an array of one or more socket addresses. Each
4951 address is contained in its appropriate structure. For an IPv6
4952 socket, an array of sockaddr_in6 is used. For an IPv4 socket, an
4953 array of sockaddr_in is used. The caller specifies the number of
4954 addresses in the array with addrcnt. Note that the wildcard
4955 addresses cannot be used in combination with non-wildcard addresses
4956 on a socket with this function; doing so will result in an error.
4957
4958 On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns
4959 -1 and sets errno to the appropriate error code.
4960
4961 For SCTP, the port given in each socket address must be the same, or
4962 sctp_bindx() will fail, setting errno to EINVAL.
4963
4964 The flags parameter is formed from the bitwise OR of zero or more of
4965 the following currently defined flags:
4966
4967 o SCTP_BINDX_ADD_ADDR
4968
4969 o SCTP_BINDX_REM_ADDR
4970
4971 SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the
4972 socket (i.e., endpoint), and SCTP_BINDX_REM_ADDR directs SCTP to
4973 remove the given addresses from the socket. The two flags are
4974 mutually exclusive; if both are given, sctp_bindx() will fail with
4975 EINVAL. A caller may not remove all addresses from a socket;
4976 sctp_bindx() will reject such an attempt with EINVAL.
4977
4978 An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate
4979 additional addresses with an endpoint after calling bind(). Or, an
4980 application can use sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some
4981 addresses with which a listening socket is associated, so that no new
4982 association accepted will be associated with these addresses. If the
4983
4984
4985
4986Stewart, et al. Informational [Page 89]
4987
4988RFC 6458 SCTP Sockets API December 2011
4989
4990
4991 endpoint supports dynamic address reconfiguration, an
4992 SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause an endpoint to
4993 send the appropriate message to its peers to change the peers'
4994 address lists.
4995
4996 Adding and removing addresses from established associations is an
4997 optional functionality. Implementations that do not support this
4998 functionality should return -1 and set errno to EOPNOTSUPP.
4999
5000 sctp_bindx() can be called on an already bound socket or on an
5001 unbound socket. If the socket is unbound and the first port number
5002 in the addrs parameter is zero, the kernel will choose a port number.
5003 All port numbers after the first one being 0 must also be zero. If
5004 the first port number is not zero, the following port numbers must be
5005 zero or have the same value as the first one. For an already bound
5006 socket, all port numbers provided must be the bound one or 0.
5007
5008 sctp_bindx() is an atomic operation. Therefore, the binding will
5009 either succeed on all addresses or fail on all addresses. If
5010 multiple addresses are provided and the sctp_bindx() call fails,
5011 there is no indication of which address is responsible for the
5012 failure. The only way to identify the specific error indication is
5013 to call sctp_bindx() sequentially with only one address per call.
5014
50159.2. sctp_peeloff()
5016
5017 After an association is established on a one-to-many style socket,
5018 the application may wish to branch off the association into a
5019 separate socket/file descriptor.
5020
5021 This is particularly desirable when, for instance, the application
5022 wishes to have a number of sporadic message senders/receivers remain
5023 under the original one-to-many style socket but branch off these
5024 associations carrying high-volume data traffic into their own
5025 separate socket descriptors.
5026
5027 The application uses the sctp_peeloff() call to branch off an
5028 association into a separate socket. (Note that the semantics are
5029 somewhat changed from the traditional one-to-one style accept()
5030 call.) Note also that the new socket is a one-to-one style socket.
5031 Thus, it will be confined to operations allowed for a one-to-one
5032 style socket.
5033
5034 The function prototype is
5035
5036 int sctp_peeloff(int sd,
5037 sctp_assoc_t assoc_id);
5038
5039
5040
5041
5042Stewart, et al. Informational [Page 90]
5043
5044RFC 6458 SCTP Sockets API December 2011
5045
5046
5047 and the arguments are
5048
5049 sd: The original one-to-many style socket descriptor returned from
5050 the socket() system call (see Section 3.1.1).
5051
5052 assoc_id: The specified identifier of the association that is to be
5053 branched off to a separate file descriptor. (Note that in a
5054 traditional one-to-one style accept() call, this would be an out
5055 parameter, but for the one-to-many style call, this is an in
5056 parameter.)
5057
5058 The function returns a non-negative file descriptor representing the
5059 branched-off association, or -1 if an error occurred. The variable
5060 errno is then set appropriately.
5061
50629.3. sctp_getpaddrs()
5063
5064 sctp_getpaddrs() returns all peer addresses in an association.
5065
5066 The function prototype is
5067
5068 int sctp_getpaddrs(int sd,
5069 sctp_assoc_t id,
5070 struct sockaddr **addrs);
5071
5072 On return, addrs will point to a dynamically allocated array of
5073 sockaddr structures of the appropriate type for the socket type. The
5074 caller should use sctp_freepaddrs() to free the memory. Note that
5075 the in/out parameter addrs must not be NULL.
5076
5077 If sd is an IPv4 socket, the addresses returned will be all IPv4
5078 addresses. If sd is an IPv6 socket, the addresses returned can be a
5079 mix of IPv4 or IPv6 addresses, with IPv4 addresses returned according
5080 to the SCTP_I_WANT_MAPPED_V4_ADDR option setting.
5081
5082 For one-to-many style sockets, id specifies the association to query.
5083 For one-to-one style sockets, id is ignored.
5084
5085 On success, sctp_getpaddrs() returns the number of peer addresses in
5086 the association. If there is no association on this socket,
5087 sctp_getpaddrs() returns 0, and the value of *addrs is undefined. If
5088 an error occurs, sctp_getpaddrs() returns -1, and the value of *addrs
5089 is undefined.
5090
5091
5092
5093
5094
5095
5096
5097
5098Stewart, et al. Informational [Page 91]
5099
5100RFC 6458 SCTP Sockets API December 2011
5101
5102
51039.4. sctp_freepaddrs()
5104
5105 sctp_freepaddrs() frees all resources allocated by sctp_getpaddrs().
5106
5107 The function prototype is
5108
5109 void sctp_freepaddrs(struct sockaddr *addrs);
5110
5111 and addrs is the array of peer addresses returned by
5112 sctp_getpaddrs().
5113
51149.5. sctp_getladdrs()
5115
5116 sctp_getladdrs() returns all locally bound addresses on a socket.
5117
5118 The function prototype is
5119
5120 int sctp_getladdrs(int sd,
5121 sctp_assoc_t id,
5122 struct sockaddr **addrs);
5123
5124 On return, addrs will point to a dynamically allocated array of
5125 sockaddr structures of the appropriate type for the socket type. The
5126 caller should use sctp_freeladdrs() to free the memory. Note that
5127 the in/out parameter addrs must not be NULL.
5128
5129 If sd is an IPv4 socket, the addresses returned will be all IPv4
5130 addresses. If sd is an IPv6 socket, the addresses returned can be a
5131 mix of IPv4 or IPv6 addresses, with IPv4 addresses returned according
5132 to the SCTP_I_WANT_MAPPED_V4_ADDR option setting.
5133
5134 For one-to-many style sockets, id specifies the association to query.
5135 For one-to-one style sockets, id is ignored.
5136
5137 If the id field is set to the value '0', then the locally bound
5138 addresses are returned without regard to any particular association.
5139
5140 On success, sctp_getladdrs() returns the number of local addresses
5141 bound to the socket. If the socket is unbound, sctp_getladdrs()
5142 returns 0, and the value of *addrs is undefined. If an error occurs,
5143 sctp_getladdrs() returns -1, and the value of *addrs is undefined.
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154Stewart, et al. Informational [Page 92]
5155
5156RFC 6458 SCTP Sockets API December 2011
5157
5158
51599.6. sctp_freeladdrs()
5160
5161 sctp_freeladdrs() frees all resources allocated by sctp_getladdrs().
5162
5163 The function prototype is
5164
5165 void sctp_freeladdrs(struct sockaddr *addrs);
5166
5167 and addrs is the array of local addresses returned by
5168 sctp_getladdrs().
5169
51709.7. sctp_sendmsg() - DEPRECATED
5171
5172 This function is deprecated; sctp_sendv() (see Section 9.12) should
5173 be used instead.
5174
5175 An implementation may provide a library function (or possibly system
5176 call) to assist the user with the advanced features of SCTP.
5177
5178 The function prototype is
5179
5180 ssize_t sctp_sendmsg(int sd,
5181 const void *msg,
5182 size_t len,
5183 const struct sockaddr *to,
5184 socklen_t tolen,
5185 uint32_t ppid,
5186 uint32_t flags,
5187 uint16_t stream_no,
5188 uint32_t timetolive,
5189 uint32_t context);
5190
5191 and the arguments are
5192
5193 sd: The socket descriptor.
5194
5195 msg: The message to be sent.
5196
5197 len: The length of the message.
5198
5199 to: The destination address of the message.
5200
5201 tolen: The length of the destination address.
5202
5203 ppid: The same as sinfo_ppid (see Section 5.3.2).
5204
5205 flags: The same as sinfo_flags (see Section 5.3.2).
5206
5207
5208
5209
5210Stewart, et al. Informational [Page 93]
5211
5212RFC 6458 SCTP Sockets API December 2011
5213
5214
5215 stream_no: The same as sinfo_stream (see Section 5.3.2).
5216
5217 timetolive: The same as sinfo_timetolive (see Section 5.3.2).
5218
5219 context: The same as sinfo_context (see Section 5.3.2).
5220
5221 The call returns the number of characters sent, or -1 if an error
5222 occurred. The variable errno is then set appropriately.
5223
5224 Sending a message using sctp_sendmsg() is atomic (unless explicit EOR
5225 marking is enabled on the socket specified by sd).
5226
5227 Using sctp_sendmsg() on a non-connected one-to-one style socket for
5228 implicit connection setup may or may not work, depending on the SCTP
5229 implementation.
5230
52319.8. sctp_recvmsg() - DEPRECATED
5232
5233 This function is deprecated; sctp_recvv() (see Section 9.13) should
5234 be used instead.
5235
5236 An implementation may provide a library function (or possibly system
5237 call) to assist the user with the advanced features of SCTP. Note
5238 that in order for the sctp_sndrcvinfo structure to be filled in by
5239 sctp_recvmsg(), the caller must enable the sctp_data_io_event with
5240 the SCTP_EVENTS option. Note that the setting of the
5241 SCTP_USE_EXT_RCVINFO will affect this function as well, causing the
5242 sctp_sndrcvinfo information to be extended.
5243
5244 The function prototype is
5245
5246 ssize_t sctp_recvmsg(int sd,
5247 void *msg,
5248 size_t len,
5249 struct sockaddr *from,
5250 socklen_t *fromlen
5251 struct sctp_sndrcvinfo *sinfo
5252 int *msg_flags);
5253
5254 and the arguments are
5255
5256 sd: The socket descriptor.
5257
5258 msg: The message buffer to be filled.
5259
5260 len: The length of the message buffer.
5261
5262
5263
5264
5265
5266Stewart, et al. Informational [Page 94]
5267
5268RFC 6458 SCTP Sockets API December 2011
5269
5270
5271 from: A pointer to an address to be filled with the address of the
5272 sender of this message.
5273
5274 fromlen: An in/out parameter describing the from length.
5275
5276 sinfo: A pointer to an sctp_sndrcvinfo structure to be filled upon
5277 receipt of the message.
5278
5279 msg_flags: A pointer to an integer to be filled with any message
5280 flags (e.g., MSG_NOTIFICATION). Note that this field is an in-out
5281 field. Options for the receive may also be passed into the value
5282 (e.g., MSG_PEEK). On return from the call, the msg_flags value
5283 will be different than what was sent in to the call. If
5284 implemented via a recvmsg() call, the msg_flags parameter should
5285 only contain the value of the flags from the recvmsg() call.
5286
5287 The call returns the number of bytes received, or -1 if an error
5288 occurred. The variable errno is then set appropriately.
5289
52909.9. sctp_connectx()
5291
5292 An implementation may provide a library function (or possibly system
5293 call) to assist the user with associating to an endpoint that is
5294 multi-homed. Much like sctp_bindx(), this call allows a caller to
5295 specify multiple addresses at which a peer can be reached. The way
5296 the SCTP stack uses the list of addresses to set up the association
5297 is implementation dependent. This function only specifies that the
5298 stack will try to make use of all of the addresses in the list when
5299 needed.
5300
5301 Note that the list of addresses passed in is only used for setting up
5302 the association. It does not necessarily equal the set of addresses
5303 the peer uses for the resulting association. If the caller wants to
5304 find out the set of peer addresses, it must use sctp_getpaddrs() to
5305 retrieve them after the association has been set up.
5306
5307 The function prototype is
5308
5309 int sctp_connectx(int sd,
5310 struct sockaddr *addrs,
5311 int addrcnt,
5312 sctp_assoc_t *id);
5313
5314 and the arguments are
5315
5316 sd: The socket descriptor.
5317
5318 addrs: An array of addresses.
5319
5320
5321
5322Stewart, et al. Informational [Page 95]
5323
5324RFC 6458 SCTP Sockets API December 2011
5325
5326
5327 addrcnt: The number of addresses in the array.
5328
5329 id: An output parameter that, if passed in as non-NULL, will return
5330 the association identifier for the newly created association (if
5331 successful).
5332
5333 The call returns 0 on success or -1 if an error occurred. The
5334 variable errno is then set appropriately.
5335
53369.10. sctp_send() - DEPRECATED
5337
5338 This function is deprecated; sctp_sendv() should be used instead.
5339
5340 An implementation may provide another alternative function or system
5341 call to assist an application with the sending of data without the
5342 use of the cmsghdr structures.
5343
5344 The function prototype is
5345
5346 ssize_t sctp_send(int sd,
5347 const void *msg,
5348 size_t len,
5349 const struct sctp_sndrcvinfo *sinfo,
5350 int flags);
5351
5352 and the arguments are
5353
5354 sd: The socket descriptor.
5355
5356 msg: The message to be sent.
5357
5358 len: The length of the message.
5359
5360 sinfo: A pointer to an sctp_sndrcvinfo structure used as described
5361 in Section 5.3.2 for a sendmsg() call.
5362
5363 flags: The same flags as used by the sendmsg() call flags (e.g.,
5364 MSG_DONTROUTE).
5365
5366 The call returns the number of bytes sent, or -1 if an error
5367 occurred. The variable errno is then set appropriately.
5368
5369 This function call may also be used to terminate an association using
5370 an association identifier by setting the sinfo.sinfo_flags to
5371 SCTP_EOF and the sinfo.sinfo_assoc_id to the association that needs
5372 to be terminated. In such a case, len can be zero.
5373
5374
5375
5376
5377
5378Stewart, et al. Informational [Page 96]
5379
5380RFC 6458 SCTP Sockets API December 2011
5381
5382
5383 Using sctp_send() on a non-connected one-to-one style socket for
5384 implicit connection setup may or may not work, depending on the SCTP
5385 implementation.
5386
5387 Sending a message using sctp_send() is atomic unless explicit EOR
5388 marking is enabled on the socket specified by sd.
5389
53909.11. sctp_sendx() - DEPRECATED
5391
5392 This function is deprecated; sctp_sendv() should be used instead.
5393
5394 An implementation may provide another alternative function or system
5395 call to assist an application with the sending of data without the
5396 use of the cmsghdr structure, and to provide a list of addresses.
5397 The list of addresses is provided for implicit association setup. In
5398 such a case, the list of addresses serves the same purpose as the
5399 addresses given in sctp_connectx() (see Section 9.9).
5400
5401 The function prototype is
5402
5403 ssize_t sctp_sendx(int sd,
5404 const void *msg,
5405 size_t len,
5406 struct sockaddr *addrs,
5407 int addrcnt,
5408 struct sctp_sndrcvinfo *sinfo,
5409 int flags);
5410
5411 and the arguments are
5412
5413 sd: The socket descriptor.
5414
5415 msg: The message to be sent.
5416
5417 len: The length of the message.
5418
5419 addrs: An array of addresses.
5420
5421 addrcnt: The number of addresses in the array.
5422
5423 sinfo: A pointer to an sctp_sndrcvinfo structure used as described
5424 in Section 5.3.2 for a sendmsg() call.
5425
5426 flags: The same flags as used by the sendmsg() call flags (e.g.,
5427 MSG_DONTROUTE).
5428
5429 The call returns the number of bytes sent, or -1 if an error
5430 occurred. The variable errno is then set appropriately.
5431
5432
5433
5434Stewart, et al. Informational [Page 97]
5435
5436RFC 6458 SCTP Sockets API December 2011
5437
5438
5439 Note that in the case of implicit connection setup, on return from
5440 this call, the sinfo_assoc_id field of the sinfo structure will
5441 contain the new association identifier.
5442
5443 This function call may also be used to terminate an association using
5444 an association identifier by setting the sinfo.sinfo_flags to
5445 SCTP_EOF and the sinfo.sinfo_assoc_id to the association that needs
5446 to be terminated. In such a case, len would be zero.
5447
5448 Sending a message using sctp_sendx() is atomic unless explicit EOR
5449 marking is enabled on the socket specified by sd.
5450
5451 Using sctp_sendx() on a non-connected one-to-one style socket for
5452 implicit connection setup may or may not work, depending on the SCTP
5453 implementation.
5454
54559.12. sctp_sendv()
5456
5457 The function prototype is
5458
5459 ssize_t sctp_sendv(int sd,
5460 const struct iovec *iov,
5461 int iovcnt,
5462 struct sockaddr *addrs,
5463 int addrcnt,
5464 void *info,
5465 socklen_t infolen,
5466 unsigned int infotype,
5467 int flags);
5468
5469 The function sctp_sendv() provides an extensible way for an
5470 application to communicate different send attributes to the SCTP
5471 stack when sending a message. An implementation may provide
5472 sctp_sendv() as a library function or a system call.
5473
5474 This document defines three types of attributes that can be used to
5475 describe a message to be sent. They are struct sctp_sndinfo
5476 (Section 5.3.4), struct sctp_prinfo (Section 5.3.7), and struct
5477 sctp_authinfo (Section 5.3.8). The following structure,
5478 sctp_sendv_spa, is defined to be used when more than one of the above
5479 attributes are needed to describe a message to be sent.
5480
5481 struct sctp_sendv_spa {
5482 uint32_t sendv_flags;
5483 struct sctp_sndinfo sendv_sndinfo;
5484 struct sctp_prinfo sendv_prinfo;
5485 struct sctp_authinfo sendv_authinfo;
5486 };
5487
5488
5489
5490Stewart, et al. Informational [Page 98]
5491
5492RFC 6458 SCTP Sockets API December 2011
5493
5494
5495 The sendv_flags field holds a bitwise OR of SCTP_SEND_SNDINFO_VALID,
5496 SCTP_SEND_PRINFO_VALID, and SCTP_SEND_AUTHINFO_VALID indicating if
5497 the sendv_sndinfo/sendv_prinfo/sendv_authinfo fields contain valid
5498 information.
5499
5500 In future, when new send attributes are needed, new structures can be
5501 defined. But those new structures do not need to be based on any of
5502 the above defined structures.
5503
5504 The function takes the following arguments:
5505
5506 sd: The socket descriptor.
5507
5508 iov: The gather buffer. The data in the buffer is treated as a
5509 single user message.
5510
5511 iovcnt: The number of elements in iov.
5512
5513 addrs: An array of addresses to be used to set up an association or
5514 a single address to be used to send the message. NULL is passed
5515 in if the caller neither wants to set up an association nor wants
5516 to send the message to a specific address.
5517
5518 addrcnt: The number of addresses in the addrs array.
5519
5520 info: A pointer to the buffer containing the attribute associated
5521 with the message to be sent. The type is indicated by the
5522 info_type parameter.
5523
5524 infolen: The length of info, in bytes.
5525
5526 infotype: Identifies the type of the information provided in info.
5527 The current defined values are as follows:
5528
5529 SCTP_SENDV_NOINFO: No information is provided. The parameter
5530 info is a NULL pointer, and infolen is 0.
5531
5532 SCTP_SENDV_SNDINFO: The parameter info is pointing to a struct
5533 sctp_sndinfo.
5534
5535 SCTP_SENDV_PRINFO: The parameter info is pointing to a struct
5536 sctp_prinfo.
5537
5538 SCTP_SENDV_AUTHINFO: The parameter info is pointing to a struct
5539 sctp_authinfo.
5540
5541 SCTP_SENDV_SPA: The parameter info is pointing to a struct
5542 sctp_sendv_spa.
5543
5544
5545
5546Stewart, et al. Informational [Page 99]
5547
5548RFC 6458 SCTP Sockets API December 2011
5549
5550
5551 flags: The same flags as used by the sendmsg() call flags (e.g.,
5552 MSG_DONTROUTE).
5553
5554 The call returns the number of bytes sent, or -1 if an error
5555 occurred. The variable errno is then set appropriately.
5556
5557 A note on the one-to-many style socket: The struct sctp_sndinfo
5558 attribute must always be used in order to specify the association on
5559 which the message is to be sent. The only case where it is not
5560 needed is when this call is used to set up a new association.
5561
5562 The caller provides a list of addresses in the addrs parameter to set
5563 up an association. This function will behave like calling
5564 sctp_connectx() (see Section 9.9), first using the list of addresses
5565 and then calling sendmsg() with the given message and attributes.
5566 For a one-to-many style socket, if the struct sctp_sndinfo attribute
5567 is provided, the snd_assoc_id field must be 0. When this function
5568 returns, the snd_assoc_id field will contain the association
5569 identifier of the newly established association. Note that the
5570 struct sctp_sndinfo attribute is not required to set up an
5571 association for a one-to-many style socket. If this attribute is not
5572 provided, the caller can enable the SCTP_ASSOC_CHANGE notification
5573 and use the SCTP_COMM_UP message to find out the association
5574 identifier.
5575
5576 If the caller wants to send the message to a specific peer address
5577 (hence overriding the primary address), it can provide the specific
5578 address in the addrs parameter and provide a struct sctp_sndinfo
5579 attribute with the field snd_flags set to SCTP_ADDR_OVER.
5580
5581 This function call may also be used to terminate an association. The
5582 caller provides an sctp_sndinfo attribute with the snd_flags set to
5583 SCTP_EOF. In this case, len would be zero.
5584
5585 Sending a message using sctp_sendv() is atomic unless explicit EOR
5586 marking is enabled on the socket specified by sd.
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602Stewart, et al. Informational [Page 100]
5603
5604RFC 6458 SCTP Sockets API December 2011
5605
5606
56079.13. sctp_recvv()
5608
5609 The function prototype is
5610
5611 ssize_t sctp_recvv(int sd,
5612 const struct iovec *iov,
5613 int iovlen,
5614 struct sockaddr *from,
5615 socklen_t *fromlen,
5616 void *info,
5617 socklen_t *infolen,
5618 unsigned int *infotype,
5619 int *flags);
5620
5621 The function sctp_recvv() provides an extensible way for the SCTP
5622 stack to pass up different SCTP attributes associated with a received
5623 message to an application. An implementation may provide
5624 sctp_recvv() as a library function or as a system call.
5625
5626 This document defines two types of attributes that can be returned by
5627 this call: the attribute of the received message and the attribute of
5628 the next message in the receive buffer. The caller enables the
5629 SCTP_RECVRCVINFO and SCTP_RECVNXTINFO socket options, respectively,
5630 to receive these attributes. Attributes of the received message are
5631 returned in struct sctp_rcvinfo (Section 5.3.5), and attributes of
5632 the next message are returned in struct sctp_nxtinfo (Section 5.3.6).
5633 If both options are enabled, both attributes are returned using the
5634 following structure.
5635
5636 struct sctp_recvv_rn {
5637 struct sctp_rcvinfo recvv_rcvinfo;
5638 struct sctp_nxtinfo recvv_nxtinfo;
5639 };
5640
5641 In future, new structures can be defined to hold new types of
5642 attributes. The new structures do not need to be based on struct
5643 sctp_recvv_rn or struct sctp_rcvinfo.
5644
5645 This function takes the following arguments:
5646
5647 sd: The socket descriptor.
5648
5649 iov: The scatter buffer. Only one user message is returned in this
5650 buffer.
5651
5652 iovlen: The number of elements in iov.
5653
5654
5655
5656
5657
5658Stewart, et al. Informational [Page 101]
5659
5660RFC 6458 SCTP Sockets API December 2011
5661
5662
5663 from: A pointer to an address to be filled with the sender of the
5664 received message's address.
5665
5666 fromlen: An in/out parameter describing the from length.
5667
5668 info: A pointer to the buffer to hold the attributes of the received
5669 message. The structure type of info is determined by the
5670 info_type parameter.
5671
5672 infolen: An in/out parameter describing the size of the info buffer.
5673
5674 infotype: On return, *info_type is set to the type of the info
5675 buffer. The current defined values are as follows:
5676
5677 SCTP_RECVV_NOINFO: If both SCTP_RECVRCVINFO and SCTP_RECVNXTINFO
5678 options are not enabled, no attribute will be returned. If
5679 only the SCTP_RECVNXTINFO option is enabled but there is no
5680 next message in the buffer, no attribute will be returned. In
5681 these cases, *info_type will be set to SCTP_RECVV_NOINFO.
5682
5683 SCTP_RECVV_RCVINFO: The type of info is struct sctp_rcvinfo, and
5684 the attribute relates to the received message.
5685
5686 SCTP_RECVV_NXTINFO: The type of info is struct sctp_nxtinfo, and
5687 the attribute relates to the next message in the receive
5688 buffer. This is the case when only the SCTP_RECVNXTINFO option
5689 is enabled and there is a next message in the buffer.
5690
5691 SCTP_RECVV_RN: The type of info is struct sctp_recvv_rn. The
5692 recvv_rcvinfo field is the attribute of the received message,
5693 and the recvv_nxtinfo field is the attribute of the next
5694 message in the buffer. This is the case when both
5695 SCTP_RECVRCVINFO and SCTP_RECVNXTINFO options are enabled and
5696 there is a next message in the receive buffer.
5697
5698 flags: A pointer to an integer to be filled with any message flags
5699 (e.g., MSG_NOTIFICATION). Note that this field is an in/out
5700 parameter. Options for the receive may also be passed into the
5701 value (e.g., MSG_PEEK). On return from the call, the flags value
5702 will be different than what was sent in to the call. If
5703 implemented via a recvmsg() call, the flags should only contain
5704 the value of the flags from the recvmsg() call when calling
5705 sctp_recvv(), and on return it has the value from msg_flags.
5706
5707 The call returns the number of bytes received, or -1 if an error
5708 occurred. The variable errno is then set appropriately.
5709
5710
5711
5712
5713
5714Stewart, et al. Informational [Page 102]
5715
5716RFC 6458 SCTP Sockets API December 2011
5717
5718
571910. Security Considerations
5720
5721 Many TCP and UDP implementations reserve port numbers below 1024 for
5722 privileged users. If the target platform supports privileged users,
5723 the SCTP implementation should restrict the ability to call bind() or
5724 sctp_bindx() on these port numbers to privileged users.
5725
5726 Similarly, unprivileged users should not be able to set protocol
5727 parameters that could result in the congestion control algorithm
5728 being more aggressive than permitted on the public Internet. These
5729 parameters are as follows:
5730
5731 o struct sctp_rtoinfo
5732
5733 If an unprivileged user inherits a one-to-many style socket with open
5734 associations on a privileged port, accepting new associations might
5735 be permitted, but opening new associations should not be permitted.
5736 This could be relevant for the r* family (rsh, rlogin, rwho, ...) of
5737 protocols.
5738
5739 Applications using the one-to-many style sockets and using the
5740 interleave level (if 0) are subject to denial-of-service attacks, as
5741 described in Section 8.1.20.
5742
5743 Applications needing transport layer security can use Datagram
5744 Transport Layer Security/SCTP (DTLS/SCTP) as specified in [RFC6083].
5745 This can be implemented using the sockets API described in this
5746 document.
5747
574811. Acknowledgments
5749
5750 Special acknowledgment is given to Ken Fujita, Jonathan Woods,
5751 Qiaobing Xie, and La Monte Yarroll, who helped extensively in the
5752 early formation of this document.
5753
5754 The authors also wish to thank Kavitha Baratakke, Mike Bartlett,
5755 Martin Becke, Jon Berger, Mark Butler, Thomas Dreibholz, Andreas
5756 Fink, Scott Kimble, Jonathan Leighton, Renee Revis, Irene Ruengeler,
5757 Dan Wing, and many others on the TSVWG mailing list for contributing
5758 valuable comments.
5759
5760 A special thanks to Phillip Conrad, for his suggested text, quick and
5761 constructive insights, and most of all his persistent fighting to
5762 keep the interface to SCTP usable for the application programmer.
5763
5764
5765
5766
5767
5768
5769
5770Stewart, et al. Informational [Page 103]
5771
5772RFC 6458 SCTP Sockets API December 2011
5773
5774
577512. References
5776
577712.1. Normative References
5778
5779 [IEEE-1003.1-2008]
5780 Institute of Electrical and Electronics Engineers,
5781 "Information Technology - Portable Operating System
5782 Interface (POSIX)", IEEE Standard 1003.1, 2008.
5783
5784 [RFC3493] Gilligan, R., Thomson, S., Bound, J., McCann, J., and W.
5785 Stevens, "Basic Socket Interface Extensions for IPv6",
5786 RFC 3493, February 2003.
5787
5788 [RFC3542] Stevens, W., Thomas, M., Nordmark, E., and T. Jinmei,
5789 "Advanced Sockets Application Program Interface (API) for
5790 IPv6", RFC 3542, May 2003.
5791
5792 [RFC3758] Stewart, R., Ramalho, M., Xie, Q., Tuexen, M., and P.
5793 Conrad, "Stream Control Transmission Protocol (SCTP)
5794 Partial Reliability Extension", RFC 3758, May 2004.
5795
5796 [RFC4895] Tuexen, M., Stewart, R., Lei, P., and E. Rescorla,
5797 "Authenticated Chunks for the Stream Control Transmission
5798 Protocol (SCTP)", RFC 4895, August 2007.
5799
5800 [RFC4960] Stewart, R., Ed., "Stream Control Transmission Protocol",
5801 RFC 4960, September 2007.
5802
5803 [RFC5061] Stewart, R., Xie, Q., Tuexen, M., Maruyama, S., and M.
5804 Kozuka, "Stream Control Transmission Protocol (SCTP)
5805 Dynamic Address Reconfiguration", RFC 5061,
5806 September 2007.
5807
580812.2. Informative References
5809
5810 [RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768,
5811 August 1980.
5812
5813 [RFC0793] Postel, J., "Transmission Control Protocol", STD 7,
5814 RFC 793, September 1981.
5815
5816 [RFC1644] Braden, R., "T/TCP -- TCP Extensions for Transactions
5817 Functional Specification", RFC 1644, July 1994.
5818
5819
5820
5821
5822
5823
5824
5825
5826Stewart, et al. Informational [Page 104]
5827
5828RFC 6458 SCTP Sockets API December 2011
5829
5830
5831 [RFC6083] Tuexen, M., Seggelmann, R., and E. Rescorla, "Datagram
5832 Transport Layer Security (DTLS) for Stream Control
5833 Transmission Protocol (SCTP)", RFC 6083, January 2011.
5834
5835 [RFC6247] Eggert, L., "Moving the Undeployed TCP Extensions RFC
5836 1072, RFC 1106, RFC 1110, RFC 1145, RFC 1146, RFC 1379,
5837 RFC 1644, and RFC 1693 to Historic Status", RFC 6247,
5838 May 2011.
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882Stewart, et al. Informational [Page 105]
5883
5884RFC 6458 SCTP Sockets API December 2011
5885
5886
5887Appendix A. Example Using One-to-One Style Sockets
5888
5889 The following code is an implementation of a simple client that sends
5890 a number of messages marked for unordered delivery to an echo server
5891 making use of all outgoing streams. The example shows how to use
5892 some features of one-to-one style IPv4 SCTP sockets, including
5893
5894 o Creating and connecting an SCTP socket.
5895
5896 o Making a request to negotiate a number of outgoing streams.
5897
5898 o Determining the negotiated number of outgoing streams.
5899
5900 o Setting an adaptation layer indication.
5901
5902 o Sending messages with a given payload protocol identifier on a
5903 particular stream using sctp_sendv().
5904
5905 <CODE BEGINS>
5906 /*
5907
5908 Copyright (c) 2011 IETF Trust and the persons identified
5909 as authors of the code. All rights reserved.
5910
5911 Redistribution and use in source and binary forms, with
5912 or without modification, is permitted pursuant to, and subject
5913 to the license terms contained in, the Simplified BSD License
5914 set forth in Section 4.c of the IETF Trust's Legal Provisions
5915 Relating to IETF Documents (http://trustee.ietf.org/license-info).
5916
5917 */
5918
5919 #include <sys/types.h>
5920 #include <sys/socket.h>
5921 #include <netinet/in.h>
5922 #include <netinet/sctp.h>
5923 #include <arpa/inet.h>
5924 #include <string.h>
5925 #include <stdio.h>
5926 #include <unistd.h>
5927 #include <stdlib.h>
5928
5929 #define PORT 9
5930 #define ADDR "127.0.0.1"
5931 #define SIZE_OF_MESSAGE 1000
5932 #define NUMBER_OF_MESSAGES 10
5933 #define PPID 1234
5934
5935
5936
5937
5938Stewart, et al. Informational [Page 106]
5939
5940RFC 6458 SCTP Sockets API December 2011
5941
5942
5943 int
5944 main(void) {
5945 unsigned int i;
5946 int sd;
5947 struct sockaddr_in addr;
5948 char buffer[SIZE_OF_MESSAGE];
5949 struct iovec iov;
5950 struct sctp_status status;
5951 struct sctp_initmsg init;
5952 struct sctp_sndinfo info;
5953 struct sctp_setadaptation ind;
5954 socklen_t opt_len;
5955
5956 /* Create a one-to-one style SCTP socket. */
5957 if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
5958 perror("socket");
5959 exit(1);
5960 }
5961
5962 /* Prepare for requesting 2048 outgoing streams. */
5963 memset(&init, 0, sizeof(init));
5964 init.sinit_num_ostreams = 2048;
5965 if (setsockopt(sd, IPPROTO_SCTP, SCTP_INITMSG,
5966 &init, (socklen_t)sizeof(init)) < 0) {
5967 perror("setsockopt");
5968 exit(1);
5969 }
5970
5971 ind.ssb_adaptation_ind = 0x01020304;
5972 if (setsockopt(sd, IPPROTO_SCTP, SCTP_ADAPTATION_LAYER,
5973 &ind, (socklen_t)sizeof(ind)) < 0) {
5974 perror("setsockopt");
5975 exit(1);
5976 }
5977
5978 /* Connect to the discard server. */
5979 memset(&addr, 0, sizeof(addr));
5980 #ifdef HAVE_SIN_LEN
5981 addr.sin_len = sizeof(struct sockaddr_in);
5982 #endif
5983 addr.sin_family = AF_INET;
5984 addr.sin_port = htons(PORT);
5985 addr.sin_addr.s_addr = inet_addr(ADDR);
5986
5987
5988
5989
5990
5991
5992
5993
5994Stewart, et al. Informational [Page 107]
5995
5996RFC 6458 SCTP Sockets API December 2011
5997
5998
5999 if (connect(sd,
6000 (const struct sockaddr *)&addr,
6001 sizeof(struct sockaddr_in)) < 0) {
6002 perror("connect");
6003 exit(1);
6004 }
6005
6006 /* Get the actual number of outgoing streams. */
6007 memset(&status, 0, sizeof(status));
6008 opt_len = (socklen_t)sizeof(status);
6009 if (getsockopt(sd, IPPROTO_SCTP, SCTP_STATUS,
6010 &status, &opt_len) < 0) {
6011 perror("getsockopt");
6012 exit(1);
6013 }
6014
6015 memset(&info, 0, sizeof(info));
6016 info.snd_ppid = htonl(PPID);
6017 info.snd_flags = SCTP_UNORDERED;
6018 memset(buffer, 'A', SIZE_OF_MESSAGE);
6019 iov.iov_base = buffer;
6020 iov.iov_len = SIZE_OF_MESSAGE;
6021 for (i = 0; i < NUMBER_OF_MESSAGES; i++) {
6022 info.snd_sid = i % status.sstat_outstrms;
6023 if (sctp_sendv(sd,
6024 (const struct iovec *)&iov, 1,
6025 NULL, 0,
6026 &info, sizeof(info), SCTP_SENDV_SNDINFO,
6027 0) < 0) {
6028 perror("sctp_sendv");
6029 exit(1);
6030 }
6031 }
6032
6033 if (close(sd) < 0) {
6034 perror("close");
6035 exit(1);
6036 }
6037 return(0);
6038 }
6039 <CODE ENDS>
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050Stewart, et al. Informational [Page 108]
6051
6052RFC 6458 SCTP Sockets API December 2011
6053
6054
6055Appendix B. Example Using One-to-Many Style Sockets
6056
6057 The following code is a simple implementation of a discard server
6058 over SCTP. The example shows how to use some features of one-to-many
6059 style IPv6 SCTP sockets, including
6060
6061 o Opening and binding of a socket.
6062
6063 o Enabling notifications.
6064
6065 o Handling notifications.
6066
6067 o Configuring the auto-close timer.
6068
6069 o Using sctp_recvv() to receive messages.
6070
6071 Please note that this server can be used in combination with the
6072 client described in Appendix A.
6073
6074 <CODE BEGINS>
6075 /*
6076
6077 Copyright (c) 2011 IETF Trust and the persons identified
6078 as authors of the code. All rights reserved.
6079
6080 Redistribution and use in source and binary forms, with
6081 or without modification, is permitted pursuant to, and subject
6082 to the license terms contained in, the Simplified BSD License
6083 set forth in Section 4.c of the IETF Trust's Legal Provisions
6084 Relating to IETF Documents (http://trustee.ietf.org/license-info).
6085
6086 */
6087
6088 #include <sys/types.h>
6089 #include <sys/socket.h>
6090 #include <netinet/in.h>
6091 #include <netinet/sctp.h>
6092 #include <arpa/inet.h>
6093 #include <string.h>
6094 #include <stdio.h>
6095 #include <stdlib.h>
6096 #include <unistd.h>
6097
6098 #define BUFFER_SIZE (1<<16)
6099 #define PORT 9
6100 #define ADDR "0.0.0.0"
6101 #define TIMEOUT 5
6102
6103
6104
6105
6106Stewart, et al. Informational [Page 109]
6107
6108RFC 6458 SCTP Sockets API December 2011
6109
6110
6111 static void
6112 print_notification(void *buf)
6113 {
6114 struct sctp_assoc_change *sac;
6115 struct sctp_paddr_change *spc;
6116 struct sctp_adaptation_event *sad;
6117 union sctp_notification *snp;
6118 char addrbuf[INET6_ADDRSTRLEN];
6119 const char *ap;
6120 struct sockaddr_in *sin;
6121 struct sockaddr_in6 *sin6;
6122
6123 snp = buf;
6124
6125 switch (snp->sn_header.sn_type) {
6126 case SCTP_ASSOC_CHANGE:
6127 sac = &snp->sn_assoc_change;
6128 printf("^^^ Association change: ");
6129 switch (sac->sac_state) {
6130 case SCTP_COMM_UP:
6131 printf("Communication up (streams (in/out)=(%u/%u)).\n",
6132 sac->sac_inbound_streams, sac->sac_outbound_streams);
6133 break;
6134 case SCTP_COMM_LOST:
6135 printf("Communication lost (error=%d).\n", sac->sac_error);
6136 break;
6137 case SCTP_RESTART:
6138 printf("Communication restarted (streams (in/out)=(%u/%u).\n",
6139 sac->sac_inbound_streams, sac->sac_outbound_streams);
6140 break;
6141 case SCTP_SHUTDOWN_COMP:
6142 printf("Communication completed.\n");
6143 break;
6144 case SCTP_CANT_STR_ASSOC:
6145 printf("Communication couldn't be started.\n");
6146 break;
6147 default:
6148 printf("Unknown state: %d.\n", sac->sac_state);
6149 break;
6150 }
6151 break;
6152 case SCTP_PEER_ADDR_CHANGE:
6153 spc = &snp->sn_paddr_change;
6154 if (spc->spc_aaddr.ss_family == AF_INET) {
6155 sin = (struct sockaddr_in *)&spc->spc_aaddr;
6156 ap = inet_ntop(AF_INET, &sin->sin_addr,
6157 addrbuf, INET6_ADDRSTRLEN);
6158 } else {
6159
6160
6161
6162Stewart, et al. Informational [Page 110]
6163
6164RFC 6458 SCTP Sockets API December 2011
6165
6166
6167 sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr;
6168 ap = inet_ntop(AF_INET6, &sin6->sin6_addr,
6169 addrbuf, INET6_ADDRSTRLEN);
6170 }
6171 printf("^^^ Peer Address change: %s ", ap);
6172 switch (spc->spc_state) {
6173 case SCTP_ADDR_AVAILABLE:
6174 printf("is available.\n");
6175 break;
6176 case SCTP_ADDR_UNREACHABLE:
6177 printf("is not available (error=%d).\n", spc->spc_error);
6178 break;
6179 case SCTP_ADDR_REMOVED:
6180 printf("was removed.\n");
6181 break;
6182 case SCTP_ADDR_ADDED:
6183 printf("was added.\n");
6184 break;
6185 case SCTP_ADDR_MADE_PRIM:
6186 printf("is primary.\n");
6187 break;
6188 default:
6189 printf("unknown state (%d).\n", spc->spc_state);
6190 break;
6191 }
6192 break;
6193 case SCTP_SHUTDOWN_EVENT:
6194 printf("^^^ Shutdown received.\n");
6195 break;
6196 case SCTP_ADAPTATION_INDICATION:
6197 sad = &snp->sn_adaptation_event;
6198 printf("^^^ Adaptation indication 0x%08x received.\n",
6199 sad->sai_adaptation_ind);
6200 break;
6201 default:
6202 printf("^^^ Unknown event of type: %u.\n",
6203 snp->sn_header.sn_type);
6204 break;
6205 };
6206 }
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218Stewart, et al. Informational [Page 111]
6219
6220RFC 6458 SCTP Sockets API December 2011
6221
6222
6223 int
6224 main(void) {
6225 int sd, flags, timeout, on;
6226 ssize_t n;
6227 unsigned int i;
6228 union {
6229 struct sockaddr sa;
6230 struct sockaddr_in sin;
6231 struct sockaddr_in6 sin6;
6232 } addr;
6233 socklen_t fromlen, infolen;
6234 struct sctp_rcvinfo info;
6235 unsigned int infotype;
6236 struct iovec iov;
6237 char buffer[BUFFER_SIZE];
6238 struct sctp_event event;
6239 uint16_t event_types[] = {SCTP_ASSOC_CHANGE,
6240 SCTP_PEER_ADDR_CHANGE,
6241 SCTP_SHUTDOWN_EVENT,
6242 SCTP_ADAPTATION_INDICATION};
6243
6244 /* Create a one-to-many style SCTP socket. */
6245 if ((sd = socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
6246 perror("socket");
6247 exit(1);
6248 }
6249
6250 /* Enable the events of interest. */
6251 memset(&event, 0, sizeof(event));
6252 event.se_assoc_id = SCTP_FUTURE_ASSOC;
6253 event.se_on = 1;
6254 for (i = 0; i < sizeof(event_types)/sizeof(uint16_t); i++) {
6255 event.se_type = event_types[i];
6256 if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENT,
6257 &event, sizeof(event)) < 0) {
6258 perror("setsockopt");
6259 exit(1);
6260 }
6261 }
6262
6263 /* Configure auto-close timer. */
6264 timeout = TIMEOUT;
6265 if (setsockopt(sd, IPPROTO_SCTP, SCTP_AUTOCLOSE,
6266 &timeout, sizeof(timeout)) < 0) {
6267 perror("setsockopt SCTP_AUTOCLOSE");
6268 exit(1);
6269 }
6270
6271
6272
6273
6274Stewart, et al. Informational [Page 112]
6275
6276RFC 6458 SCTP Sockets API December 2011
6277
6278
6279 /* Enable delivery of SCTP_RCVINFO. */
6280 on = 1;
6281 if (setsockopt(sd, IPPROTO_SCTP, SCTP_RECVRCVINFO,
6282 &on, sizeof(on)) < 0) {
6283 perror("setsockopt SCTP_RECVRCVINFO");
6284 exit(1);
6285 }
6286
6287 /* Bind the socket to all local addresses. */
6288 memset(&addr, 0, sizeof(addr));
6289 #ifdef HAVE_SIN6_LEN
6290 addr.sin6.sin6_len = sizeof(addr.sin6);
6291 #endif
6292 addr.sin6.sin6_family = AF_INET6;
6293 addr.sin6.sin6_port = htons(PORT);
6294 addr.sin6.sin6_addr = in6addr_any;
6295 if (bind(sd, &addr.sa, sizeof(addr.sin6)) < 0) {
6296 perror("bind");
6297 exit(1);
6298 }
6299 /* Enable accepting associations. */
6300 if (listen(sd, 1) < 0) {
6301 perror("listen");
6302 exit(1);
6303 }
6304
6305 for (;;) {
6306 flags = 0;
6307 memset(&addr, 0, sizeof(addr));
6308 fromlen = (socklen_t)sizeof(addr);
6309 memset(&info, 0, sizeof(info));
6310 infolen = (socklen_t)sizeof(info);
6311 infotype = 0;
6312 iov.iov_base = buffer;
6313 iov.iov_len = BUFFER_SIZE;
6314
6315 n = sctp_recvv(sd, &iov, 1,
6316 &addr.sa, &fromlen,
6317 &info, &infolen, &infotype,
6318 &flags);
6319
6320 if (flags & MSG_NOTIFICATION) {
6321 print_notification(iov.iov_base);
6322 } else {
6323 char addrbuf[INET6_ADDRSTRLEN];
6324 const char *ap;
6325 in_port_t port;
6326
6327
6328
6329
6330Stewart, et al. Informational [Page 113]
6331
6332RFC 6458 SCTP Sockets API December 2011
6333
6334
6335 if (addr.sa.sa_family == AF_INET) {
6336 ap = inet_ntop(AF_INET, &addr.sin.sin_addr,
6337 addrbuf, INET6_ADDRSTRLEN);
6338 port = ntohs(addr.sin.sin_port);
6339 } else {
6340 ap = inet_ntop(AF_INET6, &addr.sin6.sin6_addr,
6341 addrbuf, INET6_ADDRSTRLEN);
6342 port = ntohs(addr.sin6.sin6_port);
6343 }
6344 printf("Message received from %s:%u: len=%d",
6345 ap, port, (int)n);
6346 switch (infotype) {
6347 case SCTP_RECVV_RCVINFO:
6348 printf(", sid=%u", info.rcv_sid);
6349 if (info.rcv_flags & SCTP_UNORDERED) {
6350 printf(", unordered");
6351 } else {
6352 printf(", ssn=%u", info.rcv_ssn);
6353 }
6354 printf(", tsn=%u", info.rcv_tsn);
6355 printf(", ppid=%u.\n", ntohl(info.rcv_ppid));
6356 break;
6357 case SCTP_RECVV_NOINFO:
6358 case SCTP_RECVV_NXTINFO:
6359 case SCTP_RECVV_RN:
6360 printf(".\n");
6361 break;
6362 default:
6363 printf(" unknown infotype.\n");
6364 }
6365 }
6366 }
6367
6368 if (close(sd) < 0) {
6369 perror("close");
6370 exit(1);
6371 }
6372
6373 return (0);
6374 }
6375 <CODE ENDS>
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386Stewart, et al. Informational [Page 114]
6387
6388RFC 6458 SCTP Sockets API December 2011
6389
6390
6391Authors' Addresses
6392
6393 Randall R. Stewart
6394 Adara Networks
6395 Chapin, SC 29036
6396 USA
6397
6398 EMail: randall@lakerest.net
6399
6400
6401 Michael Tuexen
6402 Muenster University of Applied Sciences
6403 Stegerwaldstr. 39
6404 48565 Steinfurt
6405 Germany
6406
6407 EMail: tuexen@fh-muenster.de
6408
6409
6410 Kacheong Poon
6411 Oracle Corporation
6412
6413 EMail: ka-cheong.poon@oracle.com
6414
6415
6416 Peter Lei
6417 Cisco Systems, Inc.
6418 9501 Technology Blvd.
6419 West Office Center
6420 Rosemont, IL 60018
6421 USA
6422
6423 EMail: peterlei@cisco.com
6424
6425
6426 Vladislav Yasevich
6427 HP
6428 110 Spitrook Rd.
6429 Nashua, NH 03062
6430 USA
6431
6432 EMail: vladislav.yasevich@hp.com
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442Stewart, et al. Informational [Page 115]
6443