Stream Control Transmission Protocol (SCTP) Associations

 in
This second in a series of articles on the SCTP network protocol examines associations and connections.

where the field sinfo_stream of sinfo has been set.

The call to read is, conversely:

ssize_t sctp_recvmsg(int sd, 
                     void *msg, 
                     size_t len, 
                     struct sockaddr *from, 
                     socklen_t *fromlen 
                     struct sctp_sndrcvinfo *sinfo 
                     int *msg_flags)

The stream number is then available in sinfo.sinfo_stream.

The SCTP stack keeps a lot of information about each message that passes between peers. It also keeps information about the state of each association. To avoid overloading applications, most of this information is suppressed and is not passed to the application. In particular, by default, the structure sctp_sndrcvinfo is not filled in, so a reader cannot tell on which stream a read occurred! To enable this to be filled, a socket option must be called first as:


struct sctp_event_subscribe events; 
bzero(&events, sizeof(events)); 
events.sctp_data_io_event = 1; 
setsockopt(sockfd, IPPROTO_SCTP, 
           SCTP_EVENTS, &events, sizeof(events));

(More details on SCTP events will be given in the next article.) See Listings 4 (streamsend_echo_client.c) and 5 (streamsend_echo_server.c) for an example of a client and server using a specific stream for communication. .

There is no way to specify from which stream to read. This is deliberate; the intention is that when data is ready on any stream, then you read it. Otherwise, data could be blocked on a stream with no one to read it, which eventually could fill up system buffers. So, you can't restrict reading to any particular stream. But, once a read is done, you can tell which stream it has come from by using the mechanism above.

Typically, a server that reads and handles a message will have (pseudocode) that looks like this:


while (true) { 
    nread = sctp_recvmsg(..., msg, ..., &sinfo, ...) 
    if (nread <= 0) break; 
    assoc_id = sinfo.sinfo_assoc_id; 
    stream = sinfo.sinfo_stream; 
    handle_mesg(assoc_id, stream, msg, nread); 
}

This is a single-threaded read loop. It ensures that information is read, no matter what association or stream it is sent on. The application function handle_mesg() can, of course, dispatch the message to different threads if it wants. Writes, on the other hand can be sent from multiple threads if desired.

______________________

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions