DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere

1 (52)

SCTP Application Guide

Document type: Creator: Reviewer: Approver: Date approved: Function:

User’s Guide Zhao Kai Huang Hui 2002-12-6

Version History
Version 1.0 1.1 1.2 1.21. Date 2002-12-16 2002-12-16 2002-12-17 2002-12-20 Handled by Zhao kai Zhao kai Zhao kai Nie Sen Shijinyang/ Moltchanov Vladimir WangLan Version history Skeleton 3, 4 2.5 2.2-2.4 2.6-2.8

1.3

2002-12-30

1.4

18.8.2004

J Leppänen

Change 2.3,2.4,2.7 as appendix 2.3, 2.4 is new give explainings and examples in 2.5, 2.6, 2.7 complete part 2.8 give function table of socket options in 2.9 complete part 2.10 give an compared integrated examples in 5 Added Chapter 6.

DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere Table of Contents TypeDateHere

2 (52)

1. INTRODUCTION .............................................................................................................................4 1.1 Purpose.......................................................................................................................................4 1.2 Scope..........................................................................................................................................4 1.3 Glossary......................................................................................................................................4 1.3.1 Abbreviations.......................................................................................................................4 2. Socket API .......................................................................................................................................4 2.1 Objectives...................................................................................................................................4 2.1.1 Maintain consistency with existing sockets APIs:.................................................................4 2.1.2 Support a one to many style interface..................................................................................4 2.1.3 Support a one to one style interface.....................................................................................4 2.2 Data Types..................................................................................................................................5 2.3 How to program..........................................................................................................................5 2.4 Basic socket functions.................................................................................................................6 2.4.1 introduction...........................................................................................................................6 2.4.2 socket address.....................................................................................................................6 2.4.3 byte-order.............................................................................................................................6 2.4.4 socket operations................................................................................................................7 2.4.5 Non-blocking mode............................................................................................................10 2.5 Header data structures and event data structures.....................................................................10 2.5.1 The msghdr and cmsghdr Structures ................................................................................10 2.5.2 SCTP msg_control Structures............................................................................................11 2.5.3 SCTP Events and Notifications in /include/net/sctp/sctp_user.h.........................................12 2.6 Super socket operations for Both Styles...................................................................................14 2.6.1 send(), recv(), sendto(), recvfrom() ..................................................................................14 2.6.2 sendmsg() and recvmsg().................................................................................................15 2.6.3 read() and wirte()................................................................................................................16 2.6.4 getsockname() ..................................................................................................................16 2.6.5 setsockopt(), getsockopt()..................................................................................................17 2.7 The function of event and how to use........................................................................................17 2.8 Ancillary Data Considerations and Semantics...........................................................................19 2.8.1 Multiple Items and Ordering...............................................................................................19 2.8.2 Accessing and Manipulating Ancillary Data........................................................................19 2.8.3 Control Message Buffer Sizing .........................................................................................20 2.8.4 How to use data structures when programming.................................................................20 2.9 Socket Options..........................................................................................................................20 2.9.1 table of socket options’ functions........................................................................................21 2.10 New Interfaces........................................................................................................................22 2.10.1 sctp_bindx() .....................................................................................................................22 2.10.2 sctp_peeloff()..................................................................................................................23 2.10.3 sctp_getpaddrs()..............................................................................................................23 2.10.4 sctp_freepaddrs() ............................................................................................................24 2.10.5 sctp_getladdrs()................................................................................................................24 2.10.6 sctp_freeladdrs() .............................................................................................................25 2.10.7 sctp_sendmsg()................................................................................................................25 2.10.8 sctp_recvmsg().................................................................................................................25 3. Installation Guide............................................................................................................................26 3.1 account in isource.nokia.com....................................................................................................26 3.2 Create the source tree (based on Linux Kernel 2.4.18).............................................................26 3.3 File list.......................................................................................................................................27 3.4 Compile.....................................................................................................................................27 3.4.1 Compile lksctp in kernel.....................................................................................................27

DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere

3 (52)

3.4.2 Compile lksctp as a kernel..................................................................................................28 4. Refference......................................................................................................................................28 5. Examples........................................................................................................................................28 5.1 Server.......................................................................................................................................28 5.2 Client.........................................................................................................................................30 6. SCTP in FlexiServer.......................................................................................................................35 6.1 Configuration, Installation and Storage.....................................................................................35 6.2 The SCTP Header.....................................................................................................................35 6.3 The SCTP Library.....................................................................................................................35 6.4 LBSCTP Sockets......................................................................................................................36 APPENDIX A...................................................................................................................................38 A.1 UDP-style Interface ................................................................................................................38 A.1.1 Basic Operation................................................................................................................38 A.1.2 Implicit Association Setup.................................................................................................39 A.1.3 Non-blocking mode .........................................................................................................39 A.2 TCP-style Interface..................................................................................................................39 A.2.1 Basic Operation ..............................................................................................................39 APPENDIX B.....................................................................................................................................43 B.1 Read / Write Options ...............................................................................................................43 B.1.1 Retransmission Timeout Parameters (SCTP_RTOINFO) ...............................................43 B.1.2 Association Parameters (SCTP_ASSOCINFO) ..............................................................43 B.1.3 Initialization Parameters (SCTP_INITMSG).....................................................................44 B.1.4 SO_LINGER ....................................................................................................................45 B.1.5 SO_NODELAY ................................................................................................................45 B.1.6 SO_RCVBUF ...................................................................................................................46 B.1.7 SO_SNDBUF ...................................................................................................................46 B.1.8 Automatic close of associations (SCTP_AUTOCLOSE)...................................................46 B.1.9 Set Primary Address (SCTP_SET_PRIMARY_ADDR).....................................................46 B.1.10 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)...............................46 B.1.11 Set Adaption Layer Indicator (SCTP_SET_ADAPTION_LAYER)...................................47 B.1.12 Set default message time outs (SCTP_SET_STREAM_TIMEOUTS).............................47 B.1.13 Enable/Disable message fragmentation(SCTP_DISABLE_FRAGMENTS).....................47 B.1.14 Peer Address Parameters (SCTP_SET_PEER_ADDR_PARAMS)................................48 B.1.15 Set default send parameters (SET_DEFAULT_SEND_PARAM)....................................48 B.1.16 Set notification and ancillary events (SCTP_SET_EVENTS) .........................................50 B.2 Read only options....................................................................................................................50 B.2.1 Association Status (SCTP_STATUS) ...............................................................................50 B.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO).........................................51

DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere 1. 1.1 INTRODUCTION Purpose TypeDateHere

4 (52)

This document is the application guide for Nokia Linux kernel SCTP implementation. The instructions herein are meant for the developers of SCTP user applications in. This document was originally written by members of the noklksctp team at NRC Beijing. 1.2 Scope This document has 3 parts: including SCTP socket API description and LKSCTP installation and configuration guide. The third part is Chapter 6 SCTP in FlexiServer, which contains FlexiServer-specific SCTP information. 1.3 1.3.1 Glossary Abbreviations

SCTP LKSCTP

Stream Control Transmission Protocol Linux Kernel SCTP

2. 2.1

SOCKET API Objectives Defines a method to map the existing sockets API for use with SCTP, providing both a base for access to new features and compatibility so that most existing TCP applications can be migrated to SCTP with few (if any) changes. There are three basic design objectives:

2.1.1

Maintain consistency with existing sockets APIs: We define a sockets mapping for SCTP that is consistent with other sockets API protocol mappings (for instance, UDP, TCP, IPv4, and IPv6).

2.1.2

Support a one to many style interface This set of semantics is similar to that defined for connectionless protocols, such as UDP. It is more efficient than a TCP-like connection-oriented interface in terms of exploring the new features of SCTP. Note that SCTP is connection-oriented in nature, and it does not support broadcast or multicast communications, as UDP does.

2.1.3

Support a one to one style interface This interface supports the same basic semantics as sockets for connection-oriented protocols, such as TCP.

DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere

5 (52)

The purpose of defining this interface is to allow existing applications built on connectionoriented protocols be ported to use SCTP with very little effort, and developers familiar with those semantics can easily adapt to SCTP. Extensions will be added to this mapping to provide mechanisms to exploit new features of SCTP. Goals 2 and 3 are not compatible, so in this document we define two modes of mapping, namely the one to many style(UDP style) mapping and the one to one style(TCP-style) mapping. These two modes share some common data structures and operations, but will require the use of two different application programming models. A mechanism is defined to convert a UDP-style SCTP association into a TCP-style socket. Some of the SCTP mechanisms cannot be adequately mapped to existing socket interface. In some cases, it is more desirable to have new interface instead of using existing socket calls. This document also describes those new interface. 2.2 Data Types Whenever possible, data types from Draft 6.6 (March 1997) of POSIX 1003.1g are used: uintN_t means an unsigned integer of exactly N bits (e.g., uint16_t). We also assume the argument data types from 1003.1g when possible (e.g., the final argument to setsockopt() is a size_t value). Whenever buffer sizes are specified, the POSIX 1003.1 size_t data type is used. 2.3 How to program When a programmer begins his/her programming, he/she has one step which must be done before programming. That is he/she should copy some files provided by us to his/her own directory or to the place according to necessary. Now, we put those files in noklksctp/test/libc/include/netinet/. E.g., we put data structures and event structures in sctp.h. Users clould named his/her directory if only the directory include these files. Why files are included: The data structures of events and socket options which are already included in linux kernel. While linux operating system will only auto read files in <sys/>, therefore, for the users’ program, it could not find those SCTP data structures although they are already belong to linux kernel. Library functions: Nokia linux kernel support some lirary functions according to draft api, such as sctp_bindx(); sctp_sendmsg(); sctp_recvmsg() and so on. Their aim is to provide convenience to the user. Each function is elaborately described in section 2.10. Now, all these library fuctions are included in /noklksctp/test/sctp_lib.c. Since our c program are all in the same directory, it is no use to point at the directrory in makefile. However, if users want to put sctp_lib.c in his/her directory, he/her must point at the directory. User could use makefile to include the directory which include those files.

sin_addr. /* type of address. sin_port.4.g.4. Each protocol used different socket address format.3 byte-order there are four libaray functions to provide change or byte-order. in order to compatible with . while should include <sys/socket.h> and <netinet/in. }. 2. */ /* port */ /* internet address */ /* pad. unsigned long in htonl(unsigned long int hostlong).4. (2) port and address in struct sockaddr_in are all stored in host byte-order. More elaborately functions will be described in attachment. l---long.h> and <linux/in. In order to keep code could be transplanted. */ } note: (1) <linux/socket. It is: struct sockaddr_in { short int unsigned shot int struct in_addr. #include <netinet/in. Then discuss basic socket functions. /* type of address.h> unsigned short in htons(unsigned short int hostshort). AF_**** */ /*address */ e. linux has defined a common socket address in <linux/socket. 2.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere 2.4 2. unsigned char BSD. It support several protocols. char sa_data[14].2 socket address Socket of linux operating system is a universal network programming interface.1 Basic socket functions introduction TypeDateHere 6 (52) Linux provide socket mechanism to access network protocol of lower layer. n---network. pad.h> which have no relationship with platform.h>. we use AF_INET and AF_INET6 for TCP/IP protocol cluster. They should be converted to network byte-order when programming. unsigned short in ntohs(unsigned short int hostshort). s---short. SCTP/IP uses the address of TCP/IP protocol cluster. unsigned long in ntohl(unsigned long int hostlong). The following firstly introduce address format and byte-orders which are used by socket functions. In order to keep parameters’ consistency when calling socket functions. note: (1) h---host. sin_family.h> is head files which specially owned by linux. we should not include these two files. struct sockaddr { unsigned short sa_family.

Under the table. then a socket descriptor with port is a telephone with line.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 7 (52) (2) when programming. In TCP protocol. socklen_t addrlen) bind(int sd. That parameter is used to mark the style of the socket. Elaberation of the fuction and parameters list in the appendix. Note: Use wild-card is need to use parameters INADDR_ANY. whose index number is written down in the table. whereas in TCP protocol. when a server use INADDR_ANY for binding address. Difference: only the second parameter in the bracket has difference.4 socket operations The following table compares the socket operations of UDP style and TCP style. When a client use this address. socket() Style Description UDP TCP socket(PF_INET. I. using this parameter means that host will choose multiple address for communication. struct sockaddr *addr. if a socket descriptor is a telephone. it had better use these functions while not depending on special machines. bind() Style Description UDP TCP bind(int sd. 2. which use to communicate with peer. It has some difference with TCP protocol. to create a data struct of sock.IPPROTO_SCTP) Elaberation Function: creating a socket descriptor. it means the server will accept any connection whatever the clients’ address are. socklen_t addrlen) Elaberation Function: binding a socket descriptor with a port. that is to say..IPPROTO_SCTP) socket(PF_INET.e. We alse have some examples in the attachment for each socket operation. this parameter has two meanings. it means local host.STREAM. we state the functions and difference of UDP and TCP styles simply. struct sockaddr *addr. .4. In SCTP.SEQ_PACKET.

It means the second parameter in listen() is “false”.1. Difference: although there is no defference in form for the two style.6 2. const struct sockaddr *nam.5. . connect() Style Description UDP TCP connect(int sd. const struct sockaddr *addr.5 Function: it belongs to clients action which to apply a connection. while the parameter----backlog is not supported by UDP. It means that UDP socket support auto bind whereas TCP can’t. socklen_t len) Elaberation 2. Firstly.1. accept() Style Description UDP TCP --accept(int sd. while UDP can build association without call bind(). to create a corresponding socket to the client to prepare communicate. listen() Style Description UDP TCP listen(int socket. socklen_t len) connect(int sd.4. const struct sockaddr *nam. int backlog) listen(int socket.1. it will monitor whether it could accept an other client’s connection. socklen_t addrlen) Elaberation ---2.5.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 8 (52) Difference: although they seems same in style. Secondly. Difference: although they seems same in style. UDP socket always use sendmsg() or sendto() to establish association.4 Function: it is to move the socket from the listen socket so as to build one-to-one style communication mechanism. int backlog) Elaberation Function: the operation is only used in server. while in practice UDP style seldom use connect().

1. then close() will return normally. otherwise it means there is some other course using the descriptor. getsockname() & getpeername() Style Description UDP TCP getsockname(int socket. struct sockaddr *address.1.1. While close() always be called after finishing of communication. Elaberation . int how) Elaberation ---2.7 Fuction: gracefully shutdown when necessary. shutdown() Style Description UDP TCP ----shutdown(int socket. which are described in appendix A.6 Function: close() will decrease the counter of socket descriptor. If it is decresed to zero. getsockname(int socket.5. struct sockaddr *address. socklen_t *len). close() Style Description UDP TCP close(int sd) close(int sd) Elaberation 2. Difference: only used by TCP style. descriptor will be free. socklen_t *len). It could be called whenever the program want.5 2.4. while it has similar operation which is named peel off().4. socklen_t *len). TCP style in SCTP has some different points with TCP. getpeername(int socket. No difference between TCP and UDP. the descriptor will be freed. Until there is no any course using the descriptor.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 9 (52) Difference: It is clear that UDP do not support accept(). struct sockaddr *address.

struct iovec * msg_iov. Firstly. Difference :getpeername() is TCP only. The function returns immediately.(2) After connected.5.1.4. In order to shutdown the association gracefully.1) to show how msghdr and cmsghdr is used.h struct msghdr { void *msg_name. Those event(s) can be received by the user calling of recvmsg(). 2. the user must call sendmsg() with no data and with the MSG_EOF flag set.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 10 (52) Function: (1)after the client calls connect(). the application must set the non-blocking option by a fcntl() (such as O_NONBLOCK). after calling this. If user data could not be sent (due to a CANT_START_ASSOC).1 The msghdr and cmsghdr Structures struct msghdr in /include/linux/socket. 2.1 2. and the success or failure of the data message (and possible SCTP_INITMSG parameters) will be signaled by the SCTP_ASSOC_CHANGE event with SCTP_COMM_UP or CANT_START_ASSOC. we use socket interface sendmsg()(2. we introduce the functions and usage of these two kinds of structure. Whenever the user which want to avoid blocking must call select() before calling Sendmsg()/sendto() and recvmsg()/recvfrom(). getpeername() used by server.5 Non-blocking mode Some SCTP users might want to avoid blocking when they call socket interface function. control message header structure and some event structures. And in the following two parts. server may get the address and port of remote host. A server (having called listen()) is also notified of an association up event by the reception of a SCTP_ASSOC_CHANGE with SCTP_COMM_UP via the calling of recvmsg() and possibly the reception of the first data message. if the status is not readable.5 Header data structures and event data structures In this part. If the socket status is not writable sendmsg() and sendto() return EAGAIN and do not transmit the message. int msg_namelen. */ /* Socket name*/ /* Length of name*/ /* Data blocks .1) and explain how these events work. recvmsg() and recvfrom() return EAGAIN. getsockname() may get the address and port of local host. Similarly. and check the socket status is writable or readable. After which the sendmsg() function returns immediately. 2.5. then we inscribe a table to list each event(2. the sender will also receive a SCTP_SEND_FAILED event. and completion of the graceful shutdown is indicated by an SCTP_ASSOC_CHANGE notification of type SHUTDOWN_COMPLET.5. we introduce message header structure.6. Once all bind() calls are complete on a one-to-many style socket.

sctp_cmsg_data_t corresponding to sctp_sndrcvinfo structure. /* protocol-specific type */ cmsg_data.h struct SCTP_cmsghdr { size_t int sctp_cmsg_t sctp_cmsg_data_t }.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere __kernel_size_t void (eg BSD file descriptor passing) */ __kernel_size_t unsigned }.1.h / * cmsg_level cmsg_type cmsg_data[] * -----------.5.1. 11 (52) /* Number of blocks*/ /* Per protocol magic /* Length of cmsg list */ /* data byte count. This structure provides classification of control message header. cmsg_len.1) 2.3 struct SCTP_cmsghdr in /include/net/sctp/sctp_user. cmsg_len. the other is SCTP_SNDRCV. */ iov_len.1. including this header */ cmsg_level.2.5.5. iov_base. including hdr */ /* originating protocol */ /* protocol-specific type */ The use of the above two structures is same with TCP/UDP protocol.5. *msg_control. uint16_t sinit_max_attempts. cmsg_type has two options.---------------------* IPPROTO_SCTP SCTP_INIT struct sctp_initmsg */ struct sctp_initmsg { uint16_t sinit_num_ostreams. cmsg_type. /* beginning address of buffer. /* the size of the buffer. cmsg_level. one is SCTP_INIT. 2.-----------.1 SCTP Initiation Structure (SCTP_INIT) in /include/net/sctp/sctp_user.2 SCTP msg_control Structures Defined in struct msghdr (2. cmsg_level is IPPROTO_SCTP in SCTP protocol. 2. */ TypeDateHere msg_iovlen.2 struct cmsghdr in /include/linux/socket. sctp_cmsg_data_t corresponding to sctp_sctp_initmsg strucure. . struct iovec { void size_t } 2. msg_controllen. /* originating protocol */ cmsg_type. Programmers use it according to situation.h struct cmsghdr { __kernel_size_t int int }.5. /* #bytes. msg_flags. uint16_t sinit_max_instreams.

2. uint32_t sinfo_tsn. uint16_t sinfo_ssn.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere uint16_t sinit_max_init_timeo. sctp_assoc_t sinfo_assoc_id. This structure is notification to the user. let ULP know which event has happened. SCTP_SEND_FAILED.h /* cmsg_level cmsg_type cmsg_data[] * -----------. uint16_t sac_error.3 SCTP Events and Notifications in /include/net/sctp/sctp_user. }. uint16_t sac_outbound_streams. This structure is not used for recvmsg().5. SCTP_REMOTE_ERROR.---------------------* IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo */ struct sctp_sndrcvinfo { uint16_t sinfo_stream.h enum sctp_sn_type { SCTP_SN_TYPE_BASE = (1<<15). uint32_t sinfo_ppid. SCTP_ASSOC_CHANGE.2 Header Information Structure (SCTP_SNDRCV) in /include/net/sctp/sctp_user. uint32_t sinfo_timetolive.1 SCTP_ASSOC_CHANGE struct sctp_assoc_change { uint16_t sac_type. }. uint16_t sac_flags. SCTP_SHUTDOWN_EVENT.3. The SCTP_INITMSG socket option used this same data structure. uint16_t sinfo_flags. 2. SCTP_ADAPTION_INDICATION. uint16_t sac_state. uint32_t sinfo_cumtsn.5. uint32_t sinfo_context.2.-----------. TypeDateHere 12 (52) This cmsghdr structure provides information for initializing new SCTP associations with sendmsg(). uint32_t sac_length. This cmsghdr structure specifies SCTP options for sendmsg() and describes SCTP header information about a received message through recvmsg(). SCTP_PEER_ADDR_CHANGE.5. SCTP_PARTIAL_DELIVERY_EVENT. 2. }. .

uint16_t sre_error. }. uint32_t spc_length.5. uint32_t sre_length. sctp_assoc_t sre_assoc_id. uint32_t ssf_error.3 SCTP_REMOTE_ERROR struct sctp_remote_error { uint16_t sre_type.3. uint8_t ssf_data[0].3. If a host can not deliver a message to peer. When a destination address on a multi-homed peer encounters a change an interface details enent is sent by this structure. struct sctp_sndrcvinfo ssf_info. }. sctp_assoc_t spc_assoc_id. .5. uint32_t ssf_length. sctp_assoc_t sac_assoc_id. int spc_state. uint8_t sre_data[0]. 2. it will notify ULP with SCTP_SEND_FAILED event by this structure. }. 2.2 SCTP_PEER_ADDR_CHANGE struct sctp_paddr_change{ uint16_t spc_type.5. uint16_t ssf_flags.4 SCTP_SEND_FAILED struct sctp_send_failed { uint16_t ssf_type. }. Communication notifications inform ULP that SCTP association has either begun or ended.3. Of course attached data in this structure can not be delivered to peer. sctp_assoc_t ssf_assoc_id. uint16_t spc_flags. int spc_error. uint16_t sre_flags.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 13 (52) uint16_t sac_inbound_streams. 2. struct sockaddr_storage spc_aaddr. uint8_t sac_info[0]. it will send the error by this structure. When peer encounter an operational error.

size_t len. uint16_t sse_flags. ssize_t recvfrom(int sd. uint32_t sai_length.3. const void *msg.5. sctp_assoc_t sse_assoc_id. sd . uint16_t sai_flags.5. }. 2. 2. uint32_t pdapi_length. sctp_assoc_t sse_assoc_id. . ssize_t sendto(int sd. struct sockaddr *from. }. int flags. void *buf.1 Super socket operations for Both Styles send(). int tolen). When a peer sends a Adaption Layer Indication parameter .6 2.6. recvfrom() Applications can use send() and sendto() to transmit data to the peer of an SCTP endpoint.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 14 (52) 2.6 SCTP_ADAPTION_INDICATION struct sctp_adaption_event { uint16_t sai_type. int flags.3. sendto(). int flags). recv(). size_t len. ssize_t recv(int sd. int *fromlen). void *buf. When a receiver is engaged in a partial delivery of a message this notification will be used to indicate various events. }.5 SCTP_SHUTDOWN_EVENT struct sctp_shutdown_event { uint16_t sse_type. recv() and recvfrom() can be used to receive data from the peer.5. uint32_t sai_adaptation_ind. sctp_assoc_t pdapi_assoc_id.7 SCTP_PARTIAL_DELIVERY_EVENT struct sctp_rcv_pdapi_event { uint16_t pdapi_type. uint32_t sse_length.3. size_t len. The syntax is: ssize_t send(int sd. const struct sockaddr *to. uint16_t pdapi_flags.the socket descriptor of an SCTP endpoint. size_t len. int flags). uint32_t pdapi_indication. SCTP delivers this notification to inform the application that of the peers requested adaption layer. connst void *msg. 2.

but the caller can not distinguish the different streams. int flags). from . Similarly. to . This means that if the caller wants to send a message which is composed by several buffers. An implementation is NOT allowed to send a Data chunk with no user data. or sends unordered data these calls will usually be inadequate. Note. These calls give access to only basic SCTP protocol features. const struct msghdr *message. SCTP has the concept of multiple streams in one association. tolen .No new flags are defined for SCTP at this level.2).the socket descriptor of the endpoint message .pointer to the msghdr structure which contains a single user message and possibly some ancillary data. and may deliver the data in unpredictable ways.6. .the size of the message or the size of buffer. flags has the same meaning of flags in send(). 2. int flags). The system uses stream 0 as the default stream for send() and sendto().5.the buffer to store the peer address used to send the received message. recv() and recvfrom() return data from any stream. The msg buffer above in send() and sendto() is considered to be a single message. We have introduced the structure of msghdr in 2. In receiving. struct msghdr *message.the size of the from address flags . the send and recv calls. socket .1. buf . if an application calls a send function with no user data and no ancillary data the SCTP implementation should reject the request with an appropriate error message.1. if the buffer supplied is not large enough to hold a complete message. ssize_t recvmsg(int socket. Note. Alternately. This may result in data seeming to arrive out of order.the message to be sent.2 sendmsg() and recvmsg() ssize_t sendmsg(int socket. SCTP is message based. fromlen . the receive call acts like a stream socket and returns as much data as will fit in the buffer.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 15 (52) msg . len . The above calls do not allow the caller to specify on which stream a message should be sent.the buffer to store a received message. recv() and recvfrom() cannot distinguish message boundaries.(described below).8. may only be used with branched off socket descriptors (see Section 2. recv() and recvfrom() provide no indication. flags . the caller can use sendmsg() to do that without combining them. if a data chunk is sent unordered.one of the peer addresses of the association to be used to send the message. If either peer in the association uses multiple streams.the size of the address. when used in the UDP-style model. When . the caller needs to combine them before calling send() or sendto(). These two functions encapsulate most parameters in struct msghdr.

the socket descriptor to be queried.5 for a multi-homed version of the call. …… hdr. See Section 8. msg_namelen is the length of the address. 2. struct sockaddr_in addr. Recvmsg() store the address of receiver in these two fields. On return. &hdr. may only be used with branched off socket descriptors . len .6.The caller should set the length of address here. this is set to the length of the returned address.6. 2. If the socket is an IPv6 socket. If the actual length of the address is greater than the length of the supplied sockaddr structure. This is especially useful if the caller let SCTP chose a local port. the address will be IPv4. It does not work well with multi-homed sockets. Note. This call is for where the endpoint is not multi-homed. these calls.On return. one locally bound address (chosen by the SCTP stack) is stored in this buffer.4 getsockname() Applications use getsockname() to retrieve the locally-bound socket address of the specified socket.3 read() and wirte() Applications can use read() and write() to send and receive data to and from peer. They have the same semantics as send() and recv() except that the flags parameter cannot be used. the value stored in the object pointed to by address is unspecified.msg_namelen = sizeof(addr). the address will be either an IPv6 or IPv4 address. msg_name is a pointer which point at a variable of struct sockaddr. In fact. socklen_t *len).sin_family = AF_INET. The following is an example: struct msghdr hdr. hdr. If the socket has not been bound to a local name. …… sendmsg(sockfd.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 16 (52) programming. when used in the one to many style model. …… addr. The syntax is: int getsockname(int socket. msg_name and msg_namelen record the address of peer. sd . address . 0). If the socket is an IPv4 socket. struct sockaddr *address.msg_name = (struct sockaddr *)&addr. . the stored address will be truncated.

3) 6.3.5. .3. optval .the size of the buffer (or the length of the option returned). optname . SSN. The syntax is: ret = getsockopt(int sd.4) 5.7) 8. sd .6.5.3. optlen .5.stream number. int level.5) 7.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere 2.7. getsockopt() TypeDateHere 17 (52) Applications use setsockopt() and getsockopt() to set or retrieve socket options. size_t *optlen).5. ret = setsockopt(int sd. const void *optval. 2. SCTP_ASSOC_CHANGE (sctp_association_event): (described in Section 2. etc. SCTP_SNDRCV (sctp_data_io_event): Per-message information (i.3. first the application registers it's interest by calling the SCTP_EVENTS setsockopt() with the following structure.the buffer to store the value of the option.e. SCTP_PEER_ADDR_CHANGE (sctp_address_event): (described in Section 2.2) 4. TSN. To receive any ancillary data or notifications. int level. Socket options are used to change the default behavior of sockets calls. described in Section 2.3.the option name.the socket descript. level .7 The function of event and how to use Applications can receive per-message ancillary information and notifications of certain SCTP events with recvmsg(). The following optional information is available to the application: 1. SCTP_ADAPTION_INDICATION (sctp_adaption_layer_event): (described in section 2.6). SCTP_REMOTE_ERROR (sctp_peer_error_event): (described in Section 2. They are described in Section 2.5.2. u_int8_t sctp_association_event. int optname. 2. size_t optlen).3. int optname.set to SOL_SCTP for all SCTP options.5.5 setsockopt(). void *optval. SCTP_PARTIAL_DELIVERY_EVENT (sctp_partial_delivery_event): (described in Section 2.5. SCTP_SHUTDOWN_EVENT (sctp_shtudown_event): (described in Section2.1) 3.2). struct sctp_event_subscribe{ u_int8_t sctp_data_io_event.5.3. SCTP_SEND_FAILED (sctp_send_failure_event): (described in Section 2.

The following is an example. Setting the flag to 0 will disable reception of the message control information. sctp_send_failure_event .Setting this flag to 1 will enable the reception of peer error event notifications. setsockopt (fd. Setting the flag to 0 will disable adaption layer event notifications. sctp_shutdown_event . The application will need to use the recvmsg() interface so that it can receive the event information contained in the msg_control field.Setting this flag to 1 will enable the reception of adaption layer notifications.sizeof(event)).Setting this flag to 1 will enable the reception of association event notifications.sctp_data_io_event = 1. u_int8_t sctp_adaption_layer_event.Setting this flag to 1 will enable the reception of send failure event notifications. /* this will receive a notification. */ test_check_message(&inmessage.Setting this flag to 1 will enable the reception of address event notifications. sctp_association_event . struct sctp_event_subscribe event. IPPROTO_SCTP. memset(&event. sctp_address_event . u_int8_t sctp_send_failure_event. event. SCTP_EVENT. …… . Setting the flag to 0 will disable partial delivery event notifications. Setting the flag to 0 will disable shutdown event notifications. sizeof(event)). Setting the flag to 0 will disable address event notifications. SCTP_SNDRCV).Setting this flag to 1 will enable the reception of shutdown event notifications.Setting this flag to 1 will enable the reception of partial delivery notifications. u_int8_t sctp_peer_error_event. sctp_partial_delivery_event . sctp_peer_error_event . …… error = recvmsg(fd.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 18 (52) u_int8_t sctp_address_event. u_int8_t sctp_shutdown_event. &event. Setting the flag to 0 will disable peer error event notifications. CMSG_SPACE(sizeof(struce sctp_sndrcvinfo)). &inmessage. u_int8_t sctp_partial_delivery_event. Setting the flag to 0 will disable send failure event notifications.0. }. sctp_data_io_event .Setting this flag to 1 will cause the reception of SCTP_SNDRCV information on a per message basis. Setting the flag to 0 will disable association event notifications. MSG_WAITALL). sctp_adaption_layer_event .

There can be only a single SCTP_SNDRCV info for each sendmsg() or recvmsg() call. } /* test_check_message() */ All those test functions we have examples in /noklksctp/test/funutil. these may include multiple SCTP or non-SCTP items. } return 1. int controllen. Implementations may have different padding quirements for ancillary data.8. int test_check_message(struct msghdr *msg. so portable applications should make use of the . SCTP_SNDRCV items must always correspond to the data in the msghdr's msg_iov member. DUMP_CORE.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 19 (52) note: function test_check_message() will be included in another file which could be written like the following. sctp_cmsg_t event) { if (msg->msg_controllen != controllen) { printf("Got control structure of length %d.2 Accessing and Manipulating Ancillary Data Applications can infer the presence of data or ancillary data by examining the msg_iovlen and msg_controllen msghdr members. so applications must not depend on any ordering. 2. respectively. CMSG_FIRSTHDR(msg)->cmsg_type. not %d\n".c. msg->msg_controllen.8 Ancillary Data Considerations and Semantics Programming with ancillary socket data contains some subtleties and pitfalls. or both. 2. DUMP_CORE. which are discussed below. The ordering of ancillary data items (either by SCTP or another protocol) is not significant and is implementationdependent. event).1 Multiple Items and Ordering Multiple ancillary data items may be included in any call to sendmsg() or recvmsg(). not %d\n".8. controllen). } if (controllen > 0 && event != CMSG_FIRSTHDR(msg)->cmsg_type) { printf("Wrong kind of event: %d. Users clould use it as a guide. 2.

See RFC2292 and your SCTP implementation's documentation for more information... If the buffer is too small.h file.3 Control Message Buffer Sizing The information conveyed via SCTP_SNDRCV events will often be fundamental to the correct and sane operation of the sockets application.9 Socket Options The implementation supplies various SCTP level socket options that are common to both models. CMSG_DATA. the files name could be named by the programmer. CMSG_SPACE. Given that some ancillary data is critical. /* process data pointed to by ptr */ } } 2. In the cases noted below where the parameter is ignored. all the data structures should be included in a . Therefore. This is particularly true of the one-tomany semantics.8) this association ID parameter is ignored. CMSG_NXTHDR. while the .. /* fill in msg */ struct cmsghdr *cmsgptr.8. cmsgptr)) { if (cmsgptr->cmsg_level == . SCTP associations can be multi-homed. it may pose a fatal error condition.sizeof (struct sctp_assoc_t)). from RFC2292. 2. For example. . cmsgptr = CMSG_NXTHDR(&msg. 2.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 20 (52) macros CMSG_FIRSTHDR. For the one to one style sockets and branched off one to one style sockets (see Section 2. an application can pass to the system a corresponding option structure similar to those described below but without the association ID parameter.4 How to use data structures when programming Although lksctp has data structures in linux kernel.e. certain option parameters include a sockaddr_storage structure to select which peer address the option should be applied to.8. sizeof (option parameter) . an sctp_assoc_t structure (association ID) is used to identify the the association instance that the operation affects. and crucial data is truncated. && cmsgptr->cmsg_type == . This can make the option setting/getting operation more efficient. So it must be set when using this model. it should also specify an appropriate optlen value (i.. If an application does this. ) { u_char *ptr. ptr = CMSG_DATA(cmsgptr). /* call recvmsg() */ for (cmsgptr = CMSG_FIRSTHDR(&msg). demonstrating the use of these macros to access ancillary data: struct msghdr msg. but also of the one-ton-one semantics. cmsgptr != NULL.h file must be clearly indicated its directory in the makefile. which should be the last field of the option structure. SCTP_SNDRCV events are indispensable. if an application needs to send and receive data on different SCTP streams. and CMSG_LEN. and that multiple ancillary data items may appear in any order. Following is an example. For the one to many style sockets. applications should be carefully written to always provide a large enough buffer to contain all possible ancillary data that can be presented by recvmsg().

1 table of socket options’ functions Corresponding structure sctp_rtoinfo sctp_associnfo sctp_initmsg Linger (no corresponding structure only a parameter) (no corresponding structure only a parameter) (no corresponding structure only a parameter) (no corresponding structure only a parameter) Sctp_setpeerprim Option event SCTP_RTOINFO SCTP_ASSOCINFO SCTP_INITMSG SO_LINGER(TCP only) SCTP_NODELAY SO_RCVBUF SO_SNDBUF SCTP_AUTOCLOSE(UDP only) SCTP_SET_PEER_PRIMARY Option function Modifiy and examine retransmission timeout parameters Modify and examine association and endpoint parameters Modify and examine initialization parameters Perform SCTP ABORT primitive Turn on/off any nagle-like algorithm Sets receive buffer size Sets send buffer size Perform wether the association could auto close. Requests that the peer mark the enclosed address as the association primary. and adjust the SCTP_PRIMARY_ADDR sctp_setprim SCTP_ADAPTION_LAYER sctp_setadaption SCTP_DISABLE_FRAGMENTS SCTP_PEER_ADDR_PARAM (no corresponding structure only a parameter) sctp_paddrparams . Applications should be very careful in setting those options. those options will be applied to all peer addresses of the association controlled by the socket. 2. And for TCP-style model. Requests that the local endpoint set the specified Adaption Layer Indication parameter for all future INIT and INITACK exchanges. Turn on/off fragments of a message enable or disable heartbeats for any peer address of an association. This means that for one to one style sockets.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 21 (52) Note that socket or IP level options is set or retrieved per socket. force a heartbeat to be sent immediately. those options will be applied to all associations belonging to the socket. modify an address's heartbeat interval. Requests that the local SCTP stack use the enclosed peer address as the association primary.9.

or sctp_bindx() will fail. setting errno to EINVAL.10 2. the addresses passed can either be IPv4 or IPv6 addresses.10. On success.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 22 (52) SCTP_DEFAULT_SEND_PARAM SCTP_EVENTS sctp_sndrcvinfo Each event correspond a data structure (no corresponding structure only a parameter) (no corresponding structure only a parameter) sctp_status sctp_paddrinfo SCTP_I_WANT_MAPPED_V4_ADDR SCTP_MAXSEG SCTP_STATUS(read only) SCTP_GET_PEER_ADDR_INFO address's maximum number of retransmissions specify a default set of parameters specify various notifications and ancillary data the user wishes to receive.3. The flags parameter is formed from the bitwise OR of zero or more of the following currently defined flags: SCTP_BINDX_ADD_ADDR SCTP_BINDX_REM_ADDR . sctp_bindx() returns -1. see Section 2. addrs is a pointer to an array of one or more socket addresses. so each address is a fixed length. int sctp_bindx(int sd. The caller specifies the number of addresses in the array with addrcnt. sctp_bindx() returns 0. int addrcnt. A single address may be specified as INADDR_ANY or IN6ADDR_ANY. On failure. and sets errno to the appropriate error code. For SCTP. the addresses passed must be IPv4 addresses.2 for this usage. etrieve current status information retrieve information about a specific peer address of an association 2. Each address is contained in a struct sockaddr_storage. struct sockaddr_storage *addrs.1. If sd is an IPv4 socket. Turn on/off whether v4 address can be mapped v6 address specifies the maximum size to put in any outgoing SCTP DATA chunk. the port given in each socket address must be the same. If the sd is an IPv6 socket.1 New Interfaces sctp_bindx() The syntax of sctp_bindx() is. int flags).

An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate additional addresses with an endpoint after calling bind(). A caller may not remove all addresses from an association. .2 sctp_peeloff() After an association is established on a UDP-style socket. The application uses sctp_peeloff() call to branch off an association into a separate socket (Note the semantics are somewhat changed from the traditional TCP-style accept() call). for instance. The syntax is: new_sd = sctp_peeloff(int sd. sctp_assoc_t id. and SCTP_BINDX_REM_ADDR directs SCTP to remove the given addresses from the association. sctp_assoc_t *assoc_id). This interface is implemented as a system call. The syntax is.1. the application wishes to have a number of sporadic message senders/receivers remain under the original UDP-style socket but branch off those associations carrying high volume data traffic into their own separate socket descriptors. The two flags are mutually exclusive. in a traditional TCP-style accept() call.10. but for the UDP-style call. This interface is implemented as a system call.3 sctp_getpaddrs() sctp_getpaddrs() returns all peer addresses in an association. 2.1). if both are given. struct sockaddr_storage **addrs). Or use sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some addresses a listening socket is associated with so that no new association accepted will be associated with those addresses. int sctp_getpaddrs(int sd. If the endpoint supports dynamic address a SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause a endpoint to send the appropriate message to the peer to change the peers address lists. This is particularly desirable when.10. sctp_bindx() will fail with EINVAL. the original UDP-style socket descriptor returned from the socket() system call (see Section 3. this is an in parameter). this would be an out parameter. the new socket descriptor representing the branched-off association. 2.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 23 (52) SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the association. the application may wish to branch off the association into a separate socket/file descriptor. sctp_bindx() will reject such an attempt with EINVAL. the specified identifier of the association that is to be branched off to a separate file descriptor (Note.

addrs must not be NULL. sctp_assoc_t id. On return. sctp_getladdrs() returns 0. the addresses returned will be all IPv4 addresses. int sctp_getladdrs(int sock. The caller should use sctp_freepaddrs() to free the memory. the addresses returned can be a mix of IPv4 or IPv6 addresses. and the value of *addrs is undefined. This interface is implemented as a library function. This interface is implemented as a library function. For TCP-style sockets. sctp_getpaddrs() returns 0. and the value of *addrs is undefined. addrs must not be NULL. one for each local address. id specifies the association to query. For TCP-style sockets. id is ignored. 2. 2.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 24 (52) On return. For UDP-style sockets. On success. The syntax is. id is ignored. If sd is an IPv4 socket. If sd is an IPv6 socket.5 sctp_getladdrs() sctp_getladdrs() returns all locally bound address on a socket. If an error occurs. If there is no association on this socket. If sd is an IPv6 socket. void sctp_freepaddrs(struct sockaddr_storage *addrs). For UDP-style sockets. sctp_getladdrs() returns the number of local addresses bound to the socket. sctp_getladdrs() returns -1. addrs will point to a dynamically allocated array of struct sockaddr_storages.4 sctp_freepaddrs() sctp_freepaddrs() frees all resources allocated by sctp_getpaddrs(). struct sockaddr_storage **ss). If sd is an IPv4 socket. On success. and the value of *addrs is undefined. . id specifies the association to query. addrs is the array of peer addresses returned by sctp_getpaddrs(). sctp_getpaddrs() returns the number of peer addresses in the association.10. This interface is implemented as a library function. one for each peer address. sctp_getpaddrs() returns -1. If the socket is unbound. addrs will point to a dynamically allocated array of struct sockaddr_storages. the addresses returned can be a mix of IPv4 or IPv6 addresses. If an error occurs. and the value of *addrs is undefined.10. Its syntax is. If the id field is set to the value '0' then the locally bound addresses are returned without regard to any particular association. The caller should use sctp_freeladdrs() to free the memory. the addresses returned will be all IPv4 addresses.

10.is the message to be sent.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 25 (52) 2.is the same as sinfo_context 2.is the same as sinfo_flags stream_no . tolen . uint16_t stream_no. uint32_t ppid. const void *msg.is a message buffer to be filled.is the destination address of the message.is the socket descriptor .6 sctp_freeladdrs() sctp_freeladdrs() frees all resources allocated by sctp_getladdrs().7 sctp_sendmsg() sctp_sendmsg().is the same as sinfo_stream timetolive .is the same as sinfo_timetolive context .is the socket descriptor msg . uint32_t timetolive. 2.8 sctp_recvmsg() sctp_recvmsg().is the length of the message. void *msg. uint32_t context) s . size_t len. struct sockaddr *from. addrs is the array of peer addresses returned by sctp_getladdrs(). uint32_t flags. len . ssize_t sctp_recvmsg(int s.10. socklen_t *fromlen struct sctp_sndrcvinfo *sinfo int *msg_flags) s msg . ssize_t sctp_sendmsg(int s. struct sockaddr *to. Its syntax is.10. socklen_t tolen. to . ppid .is the same as sinfo_ppid flags . size_t *len. Its syntax is. .is the length of the destination address. Its syntax is. void sctp_freeladdrs(struct sockaddr_storage *addrs).

h 3. So any application that is to make use of these functions has to have sctpulib. . Give the userid to project manager and add you to noklksctp developer list. fromlen .h. these functions are plemented with the use of other system calls to interface kernel back-end from the user-level front-end.is the from length. Header file is sctpulib.A pointer to a integer to be filled with any message flags (e.nokia.freepaddrs().net/ Create a account for yourself in http://isource.is a pointer to a address to be filled with the sender of this messages address.A pointer to a sctp_sndrcvinfo structure to be filled upon receipt of the message.is the length of the message buffer.nokia.18) $ tar xvfz noklksctp. Notes: The four interfaces getpaddrs().DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere len from TypeDateHere 26 (52) . These APIs of the sctp are not part of the standard set of system calls in linux kernel.com:/isource/cvsroot/noklksctp co noklksctp userid@isource.2 Create the source tree (based on Linux Kernel 2.tgz $ cvs -duserid@isource.1 INSTALLATION GUIDE account in isource. msg_flags .4.c source file as its part.sh . 3.sourceforge./mklinux_sctp.c sctpulib.com Reference http://www.nokia. getladdrs().freeladdrs() are non-system call API. These files: sctpulib.nokia.com/ . MSG_NOTIFICATION).g.com's password: cvs server: Updating noklksctp U noklksctp/CHANGES cvs server: Updating noklksctp/docs cvs server: Updating noklksctp/docs/withdrawn cvs server: Updating noklksctp/sctp_cvs cvs server: Updating noklksctp/sctp_cvs/include cvs server: Updating noklksctp/sctp_cvs/include/linux cvs server: Updating noklksctp/sctp_cvs/include/net cvs server: Updating noklksctp/sctp_cvs/include/net/sctp …… $ cd noklksctp $ mkdir linux_sctp $ cd tools $ . 3. For that reason. sinfo .

An empty file :-).1 . Compile Compile lksctp in kernel $ cd test.4. README file. sctp_cvs/include/net/sctp/ All the SCTP-specific headers.sh. test/linux/include This include heirarchy includes special versions of kernel include files needed by the user-space test frame.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere $ .sh This script pushes the modified SCTP specific files from sctp_cvs to linux_sctp. The original announcement of the Developers' Release. make dep make bzImage. the unit tests.cd . you probably want to start with some other program..conf 3. Use the Makefile in this directory to run all the automated tests.make chicken./linux_sctp $ make xconfig Code Maturity->Development->Yes.sh This script pulls the modified SCTP specific files from linux_sctp and updates the corresponding files in sctp_cvs. This directory hierarchy contains the bulk of our code including the modified files from the stock linux kernel source tree. Networking->IP: Enable SCTP->Yes.sh This script creates links from linux into the linux_sctp directory and is called by the above mklinux_sctp.. What has changed since the last release? This is the current set of XP stories we've identified./updatelinux_sctp. tools/mklinks. Read this before developing..txt All the relevant Internet Drafts and RFC's. su cp arch/i386/boot/bzImage /boot/vmlinuz-sctp vi /etc/grub. sctp_cvs/net/sctp All the SCTP-specific source files..sh This script creates linux_sctp directory formed by merging stock 2.4.sh 3.18 kernel from linux directory and the SCTP specific files from sctp_cvs directory. tools/mklinux_sctp. These are bugs not documented in the code itself. and the user space test frame here..3 File list COPYING README ANNOUNCEMENT BUGS CHANGES STORIES sctp_cvs/ TypeDateHere 27 (52) If you haven't seen this. docs/ docs/states. test/libc/include This include hierarchy contains header files needed by the user-space SCTP test programs. This is a detailed state table for SCTP. tools/updatesctp_cvs.4 3. It makes a pretty good index for RFC2960 too. test/ Find the functional tests. tools/updatelinux_sctp.

h> <sctp.4.h> <errno.h> <sys/socket.h> <sys/uio.h */ /* for sockaddr_in */ int main(void) { . #include #include #include #include #include #include #include #include #include <stdio. REFFERENCE 1. draft-ietf-tsvwg-sctpsocket-05.conf title Red Hat Linux (sctp) root (hd0. accept() and close(). 5. make modules_install insmod ipv6 insmod sctp 4. bind().h> <netinet/in.com/nokia/www/cnrdait.nsf/document/BE045C55X4?OpenDocument 5.txt 2.h> <sys/errno.nokia. server finish the function of socket().1 EXAMPLES Server In this TCP style example. su cp arch/i386/boot/bzImage /boot/vmlinuz-sctp vi /etc/grub.h> <stdlib.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 28 (52) title Red Hat Linux (sctp) root (hd0.0) kernel /boot/vmlinuz-sctp ro root=/dev/hda1 reboot 3.h> <sys/types.h> /* needed by linux/sctp.0) kernel /boot/vmlinuz-sctp ro root=/dev/hda1 reboot make modules.china.txt 3. rfc2960.2 Compile lksctp as a kernel cd linux_sctp make xconfig code materity -> yes Networking -> IPv6 -> Module Networking -> SCTP -> Module make dep make bzImage. listen(). project webpage http://www.

v6. loopSer. notAccepted. sys_errlist[errno]). notAccepted = 1. struct sockaddr newAddr.v4.sin_port = htons(S_PORT). loopSer. &len). sys_errlist[errno]). } printf("Listening . if (0 != error) { printf("\n\n\t\tFailure: %s.\n"). IPPROTO_SCTP). if (0 != close(sk) || 0 != close(newsk)) { 29 (52) TypeDateHere %s.. #endif sk = socket(pf_class.v6..DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere int sk. int newsk. #else pf_class = PF_INET..sin_addr). #if TEST_V6 pf_class = PF_INET6. } sleep (3). 1). &loopSer.\n"). inet_aton(SERVER.v4.sa.. if (sk == -1) { printf("Can not creat a socket!\n"). if (0 >= newsk) { printf("Can not open as new socket.sin_family = AF_INET.v6. inet_aton(SERVER. sizeof(loopSer)).\n\n\n". } error = bind(sk. (struct sockaddr *)&loopSer.\n"). loopSer.\n\n\n". } printf("Socket is opened.v4. while(notAccepted) { newsk = accept(sk. exit(1).sin_family = AF_INET6. int pf_class. sockaddr_storage_t loopSer. SOCK_STREAM. } error = listen(sk. int error = 0. notAccepted = 0.sin_addr). int len. if (0 != error) { printf("\n\n\t\tFailure: exit(1). exit(1). .sin_port = htons(S_PORT). loopSer. (struct sockaddr *)&newAddr. &loopSer. exit(1).

printf("Socket is closed. optlen. ) #include #include #include #include #include #include #include #include #include <stdio.v4.v6. SOCK_STREAM.sin_family = AF_INET.sin_port = htons(C_PORT). #endif sk = socket(pf_class. int int int int error. loopClt. it shows the function of socket(). loopClt.2 Client Note: in this TCP style example(which corresponding to the above. inet_aton(SERVER.. struct sctp_initmsg initmsg.h> <sys/socket. loopSer. inet_aton(CLIENT. &loopSer. loopClt. int pf_class. IPPROTO_SCTP).v6.\n").\n"). } printf("Can not close connections .v4.sin_addr).sin_addr). renodelay = 0. loopClt. 5. inet_aton(SERVER.sin_family = AF_INET6.v4. reinitmsg. loopSer. connect().sin_family = AF_INET.h> <stdlib. bind().v4.h> <sys/errno.sin_addr). #if TEST_V6 pf_class = PF_INET6. &loopClt. sbuf.h */ /* for sockaddr_in */ int main(void) { int sk.v4.sin_family = AF_INET6.sin_addr).sin_port = htons(C_PORT).DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 30 (52) }else{ } return 0. sockaddr_storage_t loopClt.v6. loopSer.h> <sys/uio. return -1..v6. struct sctp_assocparams asocparam. nodelay = 0 . loopSer.sin_port = htons(S_PORT). &loopSer.h> <sctp.h> <sys/types. inet_aton(CLIENT. setsockopt(). . loopSer. resbuf.sin_port = htons(S_PORT).setparam. getsockopt().v6. #else pf_class = PF_INET.v4. &loopClt.h> /* needed by linux/sctp.v6.h> <netinet/in.h> <errno.

/* ignored */ setparam. . *which is Summation of path. SOL_SCTP.sasoc_peer_rwnd./* ignored*/ setparam. SCTP_ASSOCINFO. if (0 != error) { printf("bind to port %d error\n". sizeof(loopClt)). /* another */ setparam.error). sys_errlist[errno]).*/ /* The asocmaxrtx should be less than 5./* ignored*/ setparam.. } printf("Connecting . error = connect(sk.1. } // test case 11./* nothing for ep*/ asocparam./* DEFAULT? for ep */ /* We change the endpoint default AsocRtxInfo parameters. exit(-1). asocparam.sa. printf("%s\n".retrans */ setparam. sizeof(struct sctp_assocparams)). &loopSer. exit(1).*/ printf("This is default value!\n The endpoint: uint16_t sasoc_asocmaxrxt:%d\n uint16_t sasoc_number_peer_destinations:%d\n uint32_t sasoc_peer_rwnd:%d\n uint32_t sasoc_local_rwnd:%d\n uint32_t sasoc_cookie_life:%d milliseconds\n\n". &optlen).sasoc_assoc_id = 0. exit(-1).sa.sasoc_cookie_life). } error = bind(sk. printf("error is: %d\n". error = getsockopt(sk.. (char *)&asocparam.sasoc_asocmaxrxt = 4./* DEFAULT_MAX_WINDOW? for ep*/ asocparam. sizeof(struct sctp_assocparams)). } /* check the option value. (char *)&setparam./*0? for ep */ asocparam. if (error != 0) { printf("set socket option error!\n"). */ memset(&asocparam. if (error != 0) { printf("Error connecting!\n").3000).sasoc_asocmaxrxt./* 1 second */ error = setsockopt(sk. (struct sockaddr *)&loopClt. asocparam.max.sasoc_cookie_life = 1000000.2: SCTP_ASSOCINFO socket option.sasoc_number_peer_destinations. sizeof(loopSer)).sasoc_local_rwnd. 0x00.sasoc_local_rwnd = 0. optlen = sizeof(struct sctp_assocparams). exit(1).sasoc_peer_rwnd = 0. SCTP_ASSOCINFO.sasoc_assoc_id = 0.\n").2 /* TEST #7./* ignored*/ setparam. SOL_SCTP.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 31 (52) if (sk == -1) { printf("Can not creat a socket\n")./* 10? for ep*/ asocparam.sasoc_number_peer_destinations = 0.

sinit_max_attempts = 4. error = getsockopt(sk./*1? */ asocparam. .DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 32 (52) if (error != 0) { printf("set socket option error!\n"). &optlen).\n").sasoc_asocmaxrxt. initmsg. if (error != 0) { printf("get socket option error!"). asocparam. printf("errno is :%s\n". sys_errlist[errno]). SOL_SCTP. exit(-1). error = getsockopt(sk. optlen = sizeof(struct sctp_assocparams). exit(-1). } /*== We check the association AsocRtxInfo parameters. sizeof(struct sctp_assocparams)). SOL_SCTP. (char *)&asocparam. printf("set socket option cookie_life = 1000000.3 */ /* draft socket api 7. 0x00./* ? */ asocparam. &optlen).sinit_num_ostreams = 9. SCTP_INITMSG. if (error != 0) { printf("get socket option error!\n"). /* test case 11. sizeof(struct sctp_initmsg)). sizeof(struct sctp_initmsg)). initmsg. } /* Set socket option*/ memset(&initmsg.3 */ memset(&reinitmsg. initmsg.sasoc_assoc_id = 0.*/ memset(&asocparam./* 8? */ asocparam./* DEFAULT_MAX_WINDOW? */ asocparam.sasoc_local_rwnd.1. error = setsockopt(sk.sinit_max_instreams = 9.sinit_max_init_timeo = 100. (char *)&reinitmsg. } /* check the option value. (char *)&initmsg.sasoc_number_peer_destinations. SCTP_INITMSG. }else{ printf("set socket option asocmaxrtx = 4. initmsg. sizeof(struct sctp_initmsg)).*/ printf("\n The association 1: uint16_t sasoc_asocmaxrxt:%d\n uint16_t sasoc_number_peer_destinations:%d\n uint32_t sasoc_peer_rwnd:%d\n uint32_t sasoc_local_rwnd:%d\n uint32_t sasoc_cookie_life:%d milliseconds\n\n".2 for SCTP_ASSOCINFO passes!\n\n\n"). exit(1). 0x00.\n"). asocparam. SCTP_ASSOCINFO. 0x00.sasoc_peer_rwnd.sasoc_cookie_life). optlen = sizeof(struct sctp_initmsg)./* 1000000? */ printf("Test case 11. exit(1). if (error != 0) { printf("get socket option error!"). SOL_SCTP.

if (error != 0) { printf("set socket option error. error = setsockopt(sk. */ /* Get the parameters of nodelay*/ renodelay = 1. SOL_SCTP. 0x00. } 33 (52) TypeDateHere if ((initmsg. SCTP_INITMSG.renodelay).\n". } /* Get the parameters of nodelay*/ renodelay = 0.5: SCTP_NODELAY socket option.sinit_num_ostreams)|| (initmsg.sinit_max_instreams)|| (initmsg.\n"). exit(-1). sizeof(struct sctp_initmsg)).\n").3: SCTP_INITMSG socket option.2 for SCTP_INITMSG Fail. SOL_SCTP.\n\n").sinit_max_attempts != initmsg. (char *)&nodelay. (char *)&renodelay.renodelay). } /* End of TEST case 11. optlen = sizeof(int). if (error != 0) { printf("get socket option error. error = getsockopt(sk.2 for SCTP_INITMSG passes!\n\n"). exit(-1).\n". SOL_SCTP. SCTP_NODELAY. error = getsockopt(sk. } printf("SCTP_NODELAY is set to be %d now.sinit_max_init_timeo)) { printf("Test case 11. } printf("\nSCTP_NODELAY is set to be %d by default.sinit_max_instreams != initmsg. (char *)&renodelay.sinit_max_attempts )|| (initmsg. SCTP_NODELAY. SCTP_NODELAY. &optlen). }else{ printf("Test case 11.sinit_max_init_timeo !=initmsg.*/ /* TEST case 11. sizeof(int)). &optlen). if (error != 0) { printf("get socket option error!").\n"). error = getsockopt(sk. exit(-1). if (error != 0) { printf("get socket option error. /* Set socket option */ nodelay = 1. . &optlen). exit(-1). optlen = sizeof(int). (char *)&reinitmsg. exit(-1).sinit_num_ostreams != reinitmsg.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere } /* Get the parameters*/ memset(&reinitmsg. optlen = sizeof(struct sctp_initmsg). SOL_SCTP.

6 */ resbuf = 0. exit(-1).DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 34 (52) if (renodelay == nodelay){ printf("Test case 11. /* Get the skn's rcvbuf and check */ error = getsockopt(sk.. SOL_SCTP.5 for SCTP_NODELAY Fail.7: SO_SNDBUF socket option.6 passes!\n\n"). exit(-1). error = setsockopt(sk.sbuf). } .\n"). SOL_SCTP. }else{ printf("SO_SNDBUF is %d!\n". &optlen). }else{ printf("Test case 11. printf("Test case 11. sizeof(uint32_t)).\n\n\n"). if (error != 0) { printf("get socket option Fail. } if (resbuf != sbuf){ printf("\n\n\t\tSO_SNDBUF Fail. SO_SNDBUF. optlen = sizeof(uint32_t). SO_SNDBUF. } return 0. exit(-1).\n"). ---*/ /* test draft socket api 7. error = getsockopt(sk. return -1. SOL_SCTP.5 for SCTP_NODELAY passes!\n\n\n").. (char *)&resbuf.\n").\n\n"). SO_SNDBUF. } /* TEST case 11. sbuf = resbuf * 2. &optlen). optlen = sizeof(uint32_t). (char *)&resbuf. } if (0 != close(sk)) { printf("Error closing . } resbuf = 0. (char *)&sbuf.1. if (error != 0) { printf("set socket option Fail.

Note that it should be the first include path in the list in order to override other sctp. int tolen. However. In case of any conflicts. int sctp_sendmsg(int s.h is included in source modules normally. int *len. 6. netinet/sctp. just put it in CXXLOCALOPTS: CXXLOCALOPTS = -I$(SCTP_INC) -O3 -Wall 6. Example: INCFLAGS = \ -I$(SCTP_INC) \ -I$(SRCDIR) \ -I$(TTEN_HOME)/include Or if INCFLAGS doesn't place SCTP_INC sufficiently close to the start of the compiler command. the instructions in this chapter override the instructions elsewhere in this document. int addrcnt. If you're running FlexiOS. int *from_len. Installation and Storage TypeDateHere 35 (52) There are no user or operator configurable parameters in SCTP. const void *msg. struct sockaddr *from. int sctp_peeloff(int fd. uint32_t flags. uint32_t stream_no.1 SCTP IN FLEXISERVER Configuration.3 The SCTP Library The SCTP Library.h. in order to get the correct version of sctp. $(SCTP_INC) must be added to include paths in makefile. you have SCTP support. int len.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere 6. libsctp. 6. sctp_assoc_t *associd). . uint32_t ppid. int sctp_recvmsg(int s.h files found in any other include paths. struct sockaddr *to. struct sockaddr_storage *bindx_addr.2 The SCTP Header The general instructions in the previous chapters apply. void *msg. The source code is part of the kernel source code and resides in net/sctp/ directory in the kernel source tree. uint32_t timetolive. The implementation is an integral part of the FlexiOS kernel and it is statically linked in the kernel. provides the following functions for the SCTP user: unsigned long bindx(int fd. int flags). uint32_t context).

in order to address a specific node. LBSCTP sockets are used exactly like normal SCTP sockets. Section 2. sctp_assoc_t id. The user code must define the following: AF_INET6 and SOCK_STREAM are also valid with LBSCTP sockets just like they are valid with normal SCTP sockets. the subsystem acts simply as a storage place for libsctp. with the exceptions explained below. int sctp_getpaddrs(int sd.4 LBSCTP Sockets An LBSCTP (Load Balancer SCTP) socket is a special kind of SCTP socket specific to the FlexiServer IPD kernel. libsctp is used like any other library in FlexiServer. Source modules that use any of the functions listed above. struct sockaddr_storage **addrs). int sctp_freepaddrs(struct sockaddr_storage *addrs). struct sockaddr_storage **addrs). Hence. IPPROTO_LBSCTP) . int sctp_freeladdrs(struct sockaddr_storage *addrs). that is. libsctp is a static library that resides in SS_LibSS7Stack/sctp. all Recovery Units of an Recovery Group in all nodes are addressed with the same IP. #ifndef IPPROTO2LB #define IPPROTO2LB(arg) ((arg) | 0x100) #define LB2IPPROTO(arg) ((arg) & ~0x100) #define IPPROTO_LBSCTP IPPROTO2LB(IPPROTO_SCTP) #endif /* !IPPROTO2LB */ #ifndef AF_LBHWADDR #define AF_LBHWADDR 30 #define PF_LBHWADDR AF_LBHWADDR #endif /* !AF_LBHWADDR */ An LBSCTP socket is created with the socket() call. using IPPROTO_LBSCTP: fd = socket(AF_INET. int sctp_getladdrs(int sd. FlexiServer Recovery Groups have virtual IPs. the node's MAC address is required in addition to the IP. SOCK_SEQPACKET.h.a APPLIBS = -L$(DIR_SS_LIBSS7STACK)/sctp/build -lsctp 6. The following settings must be added in makefile in order to compile and link with libsctp: INCFLAGS = -I$(DIR_SS_LIBSS7STACK)/sctp/src/ LIBRARIES = $(DIR_SS_LIBSS7STACK)/sctp/build/libsctp. 36 (52) These are documented in the SCTP Sockets API Draft (IETF). int *msg_flags). LBSCTP sockets are used in the IPD for handling multiplexed associations to internal nodes.10. must include sctp_lib. For load balancing purposes. sctp_assoc_t id. and also in this document.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere struct sctp_sndrcvinfo *sinfo. The library is not related to SS_LibSS7Stack as such.

it can be used in any calls requiring the peer address. sizeof(address)).ip_addr.ip_addr. so getpeername() does not support one-to-many sockets. Hence.ip_addr. All of the above is valid for IPv6 also. Such a server socket must be bound to IPADDR_ANY and a given port.mac_addr. There is no parameter in getpeername() to specify an association in a oneto-many socket. the association is in fact formed to a server process in IPD. memcpy(&address. mac_addr. An LBSCTP socket can also be used as a server socket in IPD. an sctp_getladdr() call for that association will return the IP to which the association was being formed to from the internal node.sa_family = AF_LBHWADDR. The server socket will then accept connections from the internal nodes to any IP address. For one-to-one LBSCTP sockets in IPD. For this purpose. sizeof(*ip_addr)).sin_addr. the association is "hijacked" by a loadbalancer process in IPD and the IPD poses as the external peer for the application in the internal node. the user code should define an address structure: struct { struct sockaddr mac_addr.sa_data. An example connect() call: connect(fd. Prior to the recvmsg() call the address structure must be filled with zeroes. listening to connections from the internal nodes.mac_addr. After a new association has been formed using an LBSCTP server socket. This is what the SS7 Load Balancer does. address. After the address structure is filled. /* 6 bytes */ address. as long as the connection is made using the given port and the client socket in the internal node is bound to a virtual IP. sizeof(address) instead of just sizeof(sockaddr_in). In other words. Since recvmsg() returns the address of the peer in msg_name member of struct msghdr. getpeername() returns struct address (including MAC and IP) containing the address of the internal node. the server process in IPD can get the internal node's address from the COMM_UP notification when the association is formed.sin_port = port.sin_family = AF_INET. memcpy(&address. with sockaddr_in6 instead of sockaddr_in and AF_INET6 instead of AF_INET.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 37 (52) All calls involving the peer address (the address of an internal node) must include the MAC address in addition to the virtual IP address. the IP address of the external peer. Regardless of the external peer's IP address. the address structure is of course filled by the recvmsg() call. Effectively. The idea is that an application in an internal node attempts to form an SCTP association to an external peer. Fill the address structure: address. ip_addr. /* virtual IP (in this case IPv4) */ } address. The size of the address structure must include the MAC as well as the IP. such as connect() and sendmsg(). &address. /* MAC */ struct sockaddr_in ip_addr. 6). . recvmsg() works similarly.

PF_INET only support Ipv4 address.1.1.UDP Style Syntax int listen(int socket. socket .UDP Style Syntax sd = socket(PF_INET.UDP Style Syntax ssize_t sendmsg(int socket. sd = socket(PF_INET6. .1. sd .UDP Style Syntax ret = close(int sd). int addrlen). A. while PF_INET6 can support both IPv4 and IPv6 address.the size of the address structure. flags . socket .No new flags are defined for SCTP at this level.ignored for UDP-style sockets. SOCK_SEQPACKET.1. A. SCTP allow a mapped IPv6 address communicate with a host which has IPv4 address.1.1 UDP-style Interface The UDP-style interface has the following characteristics: A) Outbound association setup is implicit.the socket descriptor of the endpoint.1. struct sockaddr *addr.1.1.1. IPPROTO_SCTP).3 listen() .1.1 socket() . SOCK_SEQPACKET. int flags).1. C) There is a 1 to MANY relationship between socket and association.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 38 (52) APPENDIX A A. s).2 bind() .1 Basic Operation A. struct msghdr *message. IPPROTO_SCTP). A.UDP Style Syntax ret = bind(int sd.the address structure (struct sockaddr_in or struct sockaddr_in6 [RFC 2553]). int backlog). or. addr . addrlen .4 sendmsg() and recvmsg() .the socket descriptor of the endpoint message .pointer to the msghdr structure which contains a single user message and possibly some ancillary data. B) Messages are delivered in complete messages (with one notable exception). A. A.5 close() . const struct msghdr *message.the socket descriptor returned by socket(). int flag ssize_t recvmsg(int socket. backlog .

IPPROTO_SCTP).UDP Style Syntax ret = connect(int sd.the address structure (either struct sockaddr_in or struct sockaddr_in6 defined [RFC 2553]). Whenever the user which want to avoid blocking must call select() before calling sendmsg()/sendto() and recvmsg()/recvfrom(). the user must call sendmsg() with no data and with the MSG_EOF flag set. the application can begin sending and receiving data using the sendmsg()/recvmsg() or sendto()/recvfrom() calls.6 connect() .1.1 socket() . int len). In order to shutdown the association gracefully.3 Non-blocking mode Some SCTP users might want to avoid blocking when they call socket interface function. int socket(PF_INET6. the application must set the non-blocking option by a fcntl() (such as O_NONBLOCK).1.1. SOCK_STREAM.1. and check the socket status is writable or readable. A.2. const struct sockaddr *nam.2 Implicit Association Setup 1. in nam . 2. without bind() Whenever sendmsg() or sendto() is called and the SCTP stack at the sender finds that there is no association existing between the sender and the intended receiver (identified by the address passed either in the msg_name field of msghdr structure in the sendmsg() call or the dest_addr field in the sendto() call). A. A.2 TCP-style Interface This model enables existing applications using connection oriented protocols to be ported to SCTP with very little effort.2. IPPROTO_SCTP). without going through any explicit association setup procedures (i..e. no connect() calls required).DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere sd TypeDateHere 39 (52) . len .1.TCP Style Syntax int socket(PF_INET. Note that some new SCTP features and some new SCTP socket options can only be utilized through the use of sendmsg() and recvmsg() calls. A. sd .the size of the address. the SCTP stack will automatically setup an association to the intended receiver.1 Basic Operation A.using bind() Once all bind() calls are complete on a UDP-style socket. or.the socket descriptor of the associations to be closed. . A. SOCK_STREAM. Once all bind() calls are complete on a UDP-style socket.the socket descriptor to have a new association added to.

backlog .2. how .on return. sd . Note. SCTP allow a mapped IPv6 address communicate with a host which has IPv4 address. The values are as follows: SHUT_RD . addr . will contain the size of addr. sd .the socket descriptor of the association to be closed. sd . sd .1. while PF_INET6 can support both IPv4 and IPv6 address. new_sd .1. addr . A.TCP Style Syntax int connect(int sd.7 shutdown() .the size of the address structure. sd . int addrlen).2.2.2. int addrlen).1. int backlog).TCP Style Syntax int listen(int sd. will contain the primary address of the peer endpoint.TCP Style Syntax int close(int sd).1. addrlen . These are the associations that have finished the four-way initiation handshake (see Section 5 of [SCTP]) and are in the ESTABLISHED state.on return. A.3 listen() . const struct sockaddr *addr. A. struct sockaddr *addr.the address structure (either struct sockaddr_in or struct sockaddr_in6 defined in [RFC 2553]).1.1.the socket descriptor returned by socket() call. int how). A.the size of the address.2.the socket descriptor of the endpoint.TCP Style Syntax new_sd = accept(int sd.the socket descriptor of the association to be closed. addr . addrlen .2 bind() .this specifies the max number of outstanding associations allowed in the socket's accept queue.the listening socket descriptor.the peer's address.Specifies the type of shutdown. A.TCP Style Syntax int bind(int sd.5 connect() . sd . A.the socket descriptor of the SCTP endpoint. a backlog of '0' indicates that the caller no longer wishes to receive new.2.6 close() .DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 40 (52) PF_INET only support Ipv4 address.4 accept() .the socket descriptor for the newly formed association. socklen_t *addrlen). addrlen . struct sockaddr *addr.TCP Style Syntax int shutdown(int socket.

rather it is used to indicate a different peer address if the sender does not want to send the message over the primary address of the receiver. A. Note: Socket who calls the shutdown(sd. the SCTP stack will fill in the msg_name field on return so that the application can retrieve the source address information of the received message. Socket who receive the shutdown signal: nothing else will be different with the socket. the msg_name field in the msghdr is not used to specify the intended receiver. if send() or sendto() will be called. instead it will return 0 indicating EOF. while it could sends messages and datas. Note: Socket who calls the shutdown(sd.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 41 (52) Disables further receive operations. It must not use the . call recv() on the socket will not return error. or use SO_LINGER option with close() to abort an association(2. SHUT_WR Disables further send operations. and initiates the SCTP shutdown sequence. When receiving.1.1. 0 will be returned. an error will returnd. No SCTP protocol action is taken. but it could not send any messages or datas. If recv() is called.3.8 sendmsg() and recvmsg() . SHUT_WR): it still could receive messages or datas from the peer until it receives shutdown ack signal. After call shutdown(sd. SHUT_RD): it could not receive messages and datas any more even the peer continuously sends messages and datas.4).4).2. each time the socket call recv. neither of them could receive any messages and datas. the data will not be sent and a SCTP_SEND_FAILED event will be delivered to the application if send failure events are enabled. SHUT_RD). if a message is not received from the primary address.TCP Style Syntax The semantics is similar to those used in the UDP-style model (section 2. 0 will be returned indicating EOF. If the transport address given is not part of the current association. Note: Neither of the sockets could send messages or datas. SHUT_RDWR Disables further send and receive operations and initiates the SCTP shutdown sequence.7.1. 2) An application must use close() to gracefully shutdown an association. with the following differences: 1) When sending. Socket who receives the shutdown ack: if it receives shutdown signal.

sd . If the socket is an IPv6 socket.2.the socket descriptor to be queried. socklen_t *len). On return. address . the address will be either an IPv6 or mapped IPv4 address. the peer primary address is stored in this buffer.On return. len . A. this is set to the length of the returned address. struct sockaddr *address. If the socket is an IPv4 socket.The caller should set the length of address here.9 getpeername() int getpeername(int socket. The system returns an error if an application tries to do so. .1. the address will be IPv4.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 42 (52) MSG_ABORT or MSG_EOF flag in sendmsg().

(UDP style socket) This is filled in the application. If this parameter is missing (on a UDP style socket). The following structure is used to access and modify this parameters: struct sctp_assocparams { sctp_assoc_t sasoc_assoc_id.1. }.This contains the maximum retransmission attempts to make for the association. All parameters are time values. in milliseconds.1. A value of 0. . uint32_t sasoc_cookie_life. uint32_t sasoc_peer_rwnd. sasoc_number_peer_destinations . sasoc_asocmaxrxt . srto_max and srto_min . uint16_t sasoc_asocmaxrxt. sasoc_peer_rwnd . data inflight). indicates that the current value should not be changed. uint32_t srto_max. then the change effects the entire endpoint. The following structure is used to access and modify these parameters: struct sctp_rtoinfo { sctp_assoc_t srto_assoc_id. and identifies the association for this query. uint32_t srto_initial. the application should call getsockopt or setsockopt() respectively with the option name SCTP_RTOINFO. B. The peer address parameter is ignored for TCP style socket.These contain the maximum and minimum bounds for all RTOs.This contains the initial RTO value.1 Retransmission Timeout Parameters (SCTP_RTOINFO) TypeDateHere 43 (52) The protocol parameters used to initialize and bound retransmission timeout (RTO) are tunable. when modifying the parameters.1 Read / Write Options B. uint16_t sasoc_number_peer_destinations.2 Association Parameters (SCTP_ASSOCINFO) This option is used to both examine and set various association and endpoint parameters.This holds the current value of the peers rwnd (reported in the last SACK) minus any outstanding data (i. uint32_t sasoc_local_rwnd. srto_assoc_id . srto_initial .DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere APPENDIX B B. }. To access or modify these parameters. uint32_t srto_min. The peer address parameter is ignored for TCP style socket.e.This is the number of destination address that the peer considers valid.

but is address-specific. sinit_max_instreams: 16 bits (unsigned integer) .sasoc_local_rwnd) are NOT settable and any value placed in these is ignored. The default value of 0 indicates to use the endpoint default value. The values of the sasoc_peer_rwnd is meaningless when examining endpoint information.Max. struct sctp_initmsg { uint16_t sinit_num_ostreams.Retrans' of all the destination addresses for the remote endpoint.(UDP style socket) This is filled in the application.5. uint16_t sinit_max_attempts. This number is confirmed in the SCTP_COMM_UP notification and must be verified since it is a negotiated number with the remote endpoint. so it is covered in a separate option. uint16_t sinit_max_instreams.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 44 (52) sasoc_local_rwnd . sinit_num_ostreams: 16 bits (unsigned integer) This is an integer number representing the number of streams that the application wishes to be able to send to.1. The values of the sasoc_asocmaxrxt and sasoc_cookie_life may be set on either an endpoint or association basis. Otherwise.Max. To examine a endpoints default parameters the association id (sasoc_assoc_id) should must be set to the value '0'.Retrans' larger than the summation of the 'Path. B. Note: When configuring the SCTP endpoint. all the destination addressesmay become inactive while the endpoint still considers the peer endpoint reachable.This holds the last reported rwnd that was sent to the peer.3 Initialization Parameters (SCTP_INITMSG) Applications can specify protocol parameters for the default association initialization. sasoc_cookie_life . If an application attempts to set the value of the association maximum retransmission parameter to more than the sum of all maximum retransmission parameters. The maximum number of retransmissions before an address is considered unreachable is also tunable. and identifies the association for this query. the user should avoid having the value of 'Association. The option name argument to setsockopt() and getsockopt() is SCTP_INITMSG. }. The structure used to access and modify these parameters is defined in Section 2. uint16_t sinit_max_init_timeo. This information may be examined for either the endpoint or a specific association. setsockopt() shall return an error. The rwnd and destination counts (sasoc_number_peer_destinations.This is the associations cookie life value used when issuing cookies. sasoc_assoc_id . sasoc_peer_rwnd. the application should call getsockopt or setsockopt() respectively with the option name SCTP_ASSOCRTXINFO. To access or modify these parameters.2.1).

including our Linux Kernel SCTP.5 SO_NODELAY Turn on/off any Nagle-like algorithm. This value MUST NOT influence 'RTO. B. The linger option structure is: struct linger { int l_onoff. If the graceful shutdown phase does not finish during this period.Retransmits' value. Normally the 'RTO.Max' value (60 seconds). With TCP-style sockets. sinit_max_attempts: 16 bits (unsigned integer) This integer specifies how many attempts the SCTP endpoint should make at resending the INIT. If the value is set to a negative value. .Max' is used to limit the doubling of the RTO upon timeout. B. It is need to be extended later. at the cost of more packets in the network. the setsockopt() call will return an error. A default value of 0 indicates to use the endpoint's default value. close() will return but the graceful shutdown phase continues in the system. calling close() is the same as the ABORT primitive. the close() can be blocked for at most linger_time ms. If the l_linger value is set to 0. This value overrides the system SCTP 'Max. this option is inherited by sockets derived from a listener socket.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 45 (52) This value represents the maximum number of inbound streams the application is prepared to support.Max' during data transmission and is only used to bound the initial setup time.4 SO_LINGER An application using the TCP-style socket can use this option to perform the SCTP ABORT primitive.Init. Setting initialization parameters is effective only on an unconnected socket (for UDP-style sockets only future associations are effected by the change). Expects an integer boolean flag. This is normally set to the system's TO. This is normally set to the system's default 'Max.Init. For the INIT message this value MAY override 'RTO. In other words the user MAY be able to support more streams than the Operating System. /* option on/off */ /* linger time */ To enable the option. }. int l_linger.Retransmit' value. If the value is set to a positive value linger_time. set l_onoff to 1.1. This value is bounded by the actual implementation. the Operating System limit overrides the value requested by the user. The default value of 0 indicates to use the endpoint's default value.Max'. In such a case. The default value of 0 indicates to use the endpoint's default value.1. Note that all the current SCTP implementations still have no Nagle like algorithm. sinit_max_init_timeo: 16 bits (unsigned integer) This value represents the largest Time-Out or RTO value to use in attempting a INIT. This means that packets are generally sent as soon as possible and no unnecessary delays are introduced.

it is a set-only option. This functionality is optional. The option applies to each association's window size separately. this controls the receiver window size.1. The option expects an integer defining the number of seconds of idle time before an association is closed. The following structure is used to make a set primary request: struct sctp_setprim { sctp_assoc_t ssp_assoc_id. When set it will cause associations that are idle for more than the specified number of seconds to automatically close. ssp_addr The address to set as primary ssp_assoc_id (UDP style socket) This is filled in by the application. B. For UDP-style sockets. this controls the amount of data SCTP may have waiting in internal buffers to be sent.8 Automatic close of associations (SCTP_AUTOCLOSE) This socket option is applicable to the UDP-style socket only.1.1. this controls the receiver window size for all associations bound to the socket descriptor used in the setsockopt() or getsockopt() call. struct sockaddr_storage ssp_addr. For SCTP TCP-style sockets. The special value of '0' indicates that no automatic close of any associations should be performed.1. An association being idle is defined an association that has NOT sent or received user data. within the extension.10 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR) Requests that the local SCTP stack use the enclosed peer address as the association primary. the effect is the same. B. }.6 SO_RCVBUF Sets receive buffer size. For SCTP TCP-style sockets. The enclosed address must be one of the association's locally bound addresses.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 46 (52) The option name argument to setsockopt() and getsockopt() is SO_NODELAY.7 SO_SNDBUF Sets send buffer size. This option therefore bounds the maximum size of data that can be sent in a single send call. The option name argument to setsockopt() is SCTP_SET_PRIMARY_ADDR. In our implementation. The following structure is used to make a set peer primary request: struct sctp_setpeerprim { .1. For UDP-style sockets. the getsockopt operation is not supported. B. B. and identifies the association for this request. The enclosed address must be one of the association peer's addresses. B. Expects an integer or uint32_t. The option applies to each association's window size separately. except that it applies to all associations bound to the socket descriptor used in the setsockopt() or getsockopt() call.9 Set Primary Address (SCTP_SET_PRIMARY_ADDR) Requests that the peer mark the enclosed address as the association primary. Expects an integer or uint32_t.

. sspp_addr sspp_assoc_id The address to set as primary (UDP style socket) This is filled in by the application. }. B. u_int32_t ssto_timeout. B.1.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 47 (52) sctp_assoc_t sspp_assoc_id. u_int16_t ssto_streamid_end. the message will NOT be sent and instead a error will be indicated to the user.12 Set default message time outs (SCTP_SET_STREAM_TIMEOUTS) This option requests that the requested stream apply a default time-out for messages in queue. ssto_timeout The maximum time in milliseconds that messages should be held inqueue before failure. and need to be extended later. struct sctp_setstrm_timeout { sctp_assoc_t ssto_assoc_id. ssto_streamid_end The ending stream identifier to apply this default against. The default value is used when the application does not specify a timeout in the sendrcvinfo structure (sinfo_timetolive element see Section 2. struct sockaddr_storage sspp_addr. and identifies the association for this request. ssto_assoc_id (UDP style socket) This is filled in by the application. The option name argument to setsockopt() and getsockopt() is SCTP_SET_STREAM_TIMEOUTS. It is within the PR-SCTP extension. }. Instead if a message being sent exceeds the current PMTU size.1.2).5. Note that the current SCTP implementations still don`t support the time-out for messages in queue. u_int16_t ssto_streamid_start. ssto_streamid_start The beginning stream identifier to apply this default against. struct sctp_setadaption { u_int32_t ssb_adaption_ind.13 Enable/Disable message fragmentation(SCTP_DISABLE_FRAGMENTS) This option is an on/off flag. }. ssb_adaption_ind The adaption layer indicator that will be included in any outgoing Adaption Layer Indication parameter. and identifies the association for this request.2. If enabled no SCTP message fragmentation will be performed.11 Set Adaption Layer Indicator (SCTP_SET_ADAPTION_LAYER) Requests that the local endpoint set the specified Adaption Layer Indication parameter for all future INIT and INIT-ACK exchanges. B.1.

and adjust the address's maximum number of retransmissions sent before an address is considered unreachable.5. This socket option allows such an application to set the default sctp_sndrcvinfo structure.This specifies which address is of interest. }.(UDP style socket) This is filled in the application. uint32_t sinfo_cumtsn. force a heartbeat to be sent immediately.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 48 (52) B. struct sctp_sndrcvinfo { uint16_t sinfo_stream. sctp_assoc_t sinfo_assoc_id.15 Set default send parameters (SET_DEFAULT_SEND_PARAM) Applications that wish to use the sendto() system call may wish to specify a default set of parameters that would normally be supplied through the inclusion of ancillary data. B. The following structure is used to access and modify an address's parameters: struct sctp_paddrparams { sctp_assoc_t spp_assoc_id. sinfo_stream: 16 bits (unsigned integer) .This contains the value of the heartbeat interval. sinfo_timetolive. spp_assoc_id . specifies that a heartbeat should be sent immediately to the peer address.2. uint16_t sinfo_flags. A value of UINT32_MAX (4294967295).2) The input parameters accepted by this call include sinfo_stream. uint32_t sinfo_timetolive. uint32_t sinfo_ppid. sinfo_ppid. and identifies the association for this query. and the current interval should remain unchanged. The application that wishes to use this socket option simply passes in to this call the sctp_sndrcvinfo structure defined in Section 2. in milliseconds. sinfo_flags.1. spp_pathmaxrxt . when modifying the parameter.14 Peer Address Parameters (SCTP_SET_PEER_ADDR_PARAMS) Applications can enable or disable heartbeats for any peer address of an association.This contains the maximum number of retransmissions before this address shall be considered unreachable. uint16_t spp_pathmaxrxt. uint32_t spp_hbinterval. spp_address . sinfo_context. when modifying the parameter.1. specifies that the heartbeat on this address should be disabled. modify an address's heartbeat interval. spp_hbinterval . uint32_t sinfo_context. uint16_t sinfo_ssn. }. uint32_t sinfo_tsn. A value of 0. struct sockaddr_storage spp_address.

MSG_ABORT . . sinfo_ssn: 16 bits (unsigned integer) This parameter is ignored.Setting this flag causes the specified association to abort by sending an ABORT message to the peer (UDP-style only). requests the SCTP stack to override the primary destination address with the address found with the sendto/sendmsg call. The cause specific information of this error cause is provided in msg_iov. If this flag is clear the datagram is considered an ordered send. MSG_ADDR_OVER . This value is passed back to the upper layer if a error occurs on the send of a message and is retrieved with each undelivered message (Note: if a endpoint has done multiple sends. . sendmsg() flags: MSG_UNORDERED . this field contains the message time to live in milliseconds. This value will override any default value set using any socket option. One with each user data message). Please note that byte order issues are NOT accounted for and this information is passed opaquely by the SCTP stack from one end to the other.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 49 (52) For sendmsg() this value holds the stream number that the application wishes to send this message to. MSG_EOF sinfo_timetolive: 32 bit (unsigned integer) For the sending side. Also note that the value of 0 is special in that it indicates no timeout should occur on this message. The sending side will expire the message within the specified time period if the message as not been sent to the peer within this time period. Graceful shutdown assures that all data enqueued by both endpoints is successfully transmitted before closing the association (UDP-style only). multiple different sinfo_context values will be returned. sinfo_context: 32 bits (unsigned integer) This value is an opaque 32 bit context datum that is used in the sendmsg() function. sinfo_flags: 16 bits (unsigned integer) This field may contain any of the following flags and is composed of a bitwise OR of these values. sinfo_ppid: 32 bits (unsigned integer) This value in sendmsg() is an opaque unsigned value that is passed to the remote end in each user message. If a sender specifies an invalid stream number an error indication is returned and the call fails. in the UDP model.This flag requests the un-ordered delivery of the message.This flag.Setting this flag invokes the SCTP graceful shutdown procedures on the specified association. all of which fail. The ABORT chunk will contain an error cause 'User Initiated Abort' with cause code 12.

int32_t sstat_state. B. This information is read-only.16 Set notification and ancillary events (SCTP_SET_EVENTS) This socket option is used to specify various notifications and ancillary data the user wishes to receive. sinfo_assoc_id: sizeof (sctp_assoc_t) The association handle field. uint16_t sstat_unackdata. sinfo_cumtsn: 32 bit (unsigned integer) This parameter is ignored. struct sctp_event_subscribe{ u_int8_t sctp_data_io_event. u_int8_t sctp_address_event. u_int8_t sctp_send_failure_event.1. sinfo_assoc_id. u_int8_t sctp_adaption_layer_event. u_int8_t sctp_partial_delivery_event. u_int8_t sctp_peer_error_event.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 50 (52) sinfo_tsn: 32 bit (unsigned integer) This parameter is ignored.2 Read only options B. uint16_t sstat_penddata. peer receiver window size. uint16_t sstat_instrms. Ignored for TCP-style sockets. The following structure is used to access this information: struct sctp_status { sctp_assoc_t sstat_assoc_id. }.7.2. . holds the identifier for the association announced in the SCTP_COMM_UP notification. B. The user must provide the sinfo_assoc_id field in to this call if the caller is using the UDP model. All notifications for a given association have the same identifier. u_int8_t sctp_shutdown_event. and number of data chunks pending receipt. uint32_t sstat_rwnd. Please see Section 2.1 Association Status (SCTP_STATUS) Applications can retrieve current status information about an association. number of unacked data chunks. including association state.3 for a full description of this option and its usage. u_int8_t sctp_association_event.

This contains the association peer's current receiver window size. To access these status values. B.This contains the association's current state one of the following values: SCTP_CLOSED SCTP_BOUND SCTP_LISTEN SCTP_COOKIE_WAIT SCTP_COOKIE_ECHOED SCTP_ESTABLISHED SCTP_SHUTDOWN_PENDING SCTP_SHUTDOWN_SENT SCTP_SHUTDOWN_RECEIVED SCTP_SHUTDOWN_ACK_SENT sstat_rwnd .This is the number of data chunks pending receipt. sstat_fragmentation_point . uint32_t spinfo_rto.This is the number of unacked data chunks. uint32_t spinfo_mtu.The number of streams that the endpoint is allowed to use outbound. sstat_instrms . the application calls getsockopt() with the option name SCTP_STATUS.The number of streams that the peer will be using inbound. . The sstat_assoc_id parameter is ignored for TCP style socket.This is information on the current primary peer address.(UDP style socket) This holds the an identifier for the association. congestion window. All notifications for a given association have the same association identifier. uint32_t sstat_fragmentation_point.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 51 (52) uint16_t sstat_outstrms.The size at which SCTP fragmentation will occur. int32_t spinfo_state. This information is read-only. including its reachability state. sstat_unackdata . uint32_t spinfo_cwnd. sstat_outstrms . sstat_state . struct sockaddr_storage spinfo_address. sstat_penddata .2. The following structure is used to access this information: struct sctp_paddrinfo { sctp_assoc_t spinfo_assoc_id.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO) Applications can retrieve information about a specific peer address of an association. }. sstat_assoc_id . and retransmission timer values. struct sctp_paddrinfo sstat_primary. uint32_t spinfo_srtt. }. sstat_primary .

(UDP style socket) This is filled in the application.This is filled in the application. spinfo_assoc_id . spinfo_rto . and contains the peer address of interest. On return from getsockopt(): spinfo_state .This contains the peer addresses's current retransmission timeout value in milliseconds. spinfo_mtu .The current P-MTU of this address.DOCUMENTTYPE TypeUnitOrDepartmentHere TypeYourNameHere TypeDateHere 52 (52) spinfo_address . and identifies the association for this query.This contains the peer addresses's state (either SCTP_ACTIVE or SCTP_INACTIVE). . spinfo_cwnd .This contains the peer addresses's current congestion window.This contains the peer addresses's current smoothed round-trip time calculation in milliseconds. spinfo_srtt .

Sign up to vote on this title
UsefulNot useful