1% 2% Copyright (C) 2012-2015 Irene Ruengeler 3% Copyright (C) 2012-2015 Michael Tuexen 4% 5% All rights reserved. 6% 7% Redistribution and use in source and binary forms, with or without 8% modification, are permitted provided that the following conditions 9% are met: 10% 1. Redistributions of source code must retain the above copyright 11% notice, this list of conditions and the following disclaimer. 12% 2. Redistributions in binary form must reproduce the above copyright 13% notice, this list of conditions and the following disclaimer in the 14% documentation and/or other materials provided with the distribution. 15% 3. Neither the name of the project nor the names of its contributors 16% may be used to endorse or promote products derived from this software 17% without specific prior written permission. 18% 19% THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22% ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25% OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26% HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29% SUCH DAMAGE. 30% 31\documentclass[a4paper]{article} 32% 33\usepackage{longtable} 34% 35\title{Socket API for the SCTP User-land Implementation (usrsctp)} 36\author{I.~R\"ungeler% 37 \thanks{M\"unster University of Applied Sciences, 38 Department of Electrical Engineering 39 and Computer Science, 40 Stegerwaldstr.~39, 41 D-48565 Steinfurt, 42 Germany, 43 \texttt{i.ruengeler@fh-muenster.de}.} 44 \and 45 M.~T\"uxen% 46 \thanks{M\"unster University of Applied Sciences, 47 Department of Electrical Engineering 48 and Computer Science, 49 Stegerwaldstr.~39, 50 D-48565 Steinfurt, 51 Germany, 52 \texttt{tuexen@fh-muenster.de}.} 53} 54% 55\begin{document} 56\setcounter{secnumdepth}{4} 57\setcounter{tocdepth}{4} 58\maketitle 59\tableofcontents 60 61\section{Introduction} 62In this manual the socket API for the SCTP User-land implementation will be described. 63It is based on RFC 6458~\cite{socketAPI}. The main focus of this document is on pointing out 64 the differences to the SCTP Sockets API. For all aspects of the sockets API that are not 65 mentioned in this document, please refer to RFC~6458. Questions about SCTP can hopefully be 66 answered by RFC~4960~\cite{SCTP}. 67 68\section{Getting Started} 69The User-land stack has been tested on FreeBSD 10.0, Ubuntu 11.10, Windows 7, Mac OS X 10.6, 70and MAC OS X 10.7. 71The current version of the User-land stack is provided on \textit{http://sctp.fh-muenster.de/sctp-user-land-stack.html}. 72Download the tarball and untar it in a folder of your choice. 73The tarball contains all the sources to build the libusrsctp, which has to be linked to the object file of an 74example program. In addition there are two applications in the folder \textit{programs} that can be built and run. 75 76\subsection{Building the Library and the Applications} 77\subsubsection{Unix-like Operating Systems} 78In the folder \textit{usrsctp} type 79\begin{verbatim} 80./bootstrap 81./configure 82make 83\end{verbatim} 84Now, the library \textit{libusrsctp.la} has been built in the subdirectory \textit{usrsctplib}, and the example 85programs are ready to run from the subdirectory \textit{programs}. 86 87If you have root privileges or are in the sudoer group, you can install the library in \textit{/usr/local/lib} 88and copy the header file to \textit{/usr/include} with the command 89\begin{verbatim} 90sudo make install 91\end{verbatim} 92 93\subsubsection{Windows} 94On Windows you need a compiler like Microsoft Visual Studio. You can build the library and the 95example programs with the command line tool of the compiler by typing 96\begin{verbatim} 97nmake -f Makefile.nmake 98\end{verbatim} 99in the directory \textit{usrsctp}. 100 101\subsection{Running the Test Programs} 102There are two test programs included, a discard server and a client. You can run both to send data from the 103client to the server. The client reads data from stdin and sends them to the server, which prints the message 104in the terminal and discards it. The sources of the server are also provided in Section~\ref{server} and those 105of the client in Section~\ref{client}. 106 107\subsubsection{Using UDP Encapsulation} 108Both programs can either send data over SCTP directly or use UDP encapsulation, thus encapsulating the 109SCTP packet in a UDP datagram. The first mode works on loopback or in a protected setup without any 110NAT boxes involved. In all other cases it is better to use UDP encapsulation. 111 112The usage of the discard\_server is 113\begin{verbatim} 114discard_server [local_encaps_port remote_encaps_port] 115\end{verbatim} 116For UDP encapsulation the ports have to be specified. The local and remote encapsulation ports can be arbitrarily 117set. 118For example, you can call 119\begin{verbatim} 120./discard_server 11111 22222 121\end{verbatim} 122on a Unix-like OS and 123\begin{verbatim} 124discard_server.exe 11111 22222 125\end{verbatim} 126on Windows. 127 128The client needs two additional parameters, the server's address and its port. 129Its usage is 130\begin{verbatim} 131client remote_addr remote_port [local_port local_encaps_port remote_encaps_port] 132\end{verbatim} 133The remote address is the server's address. If client and server are started on the same machine, 134the loopback address 127.0.0.1 can be used for Unix-like OSs and the local address on Windows. 135The discard port is 9, thus 9 has to be taken as remote port. The encapsulation ports have to 136match those of the server, i.e. the server's local\_encaps\_port is the client's 137remote\_encaps\_port and vice versa. Thus, the client can be started with 138\begin{verbatim} 139./client 127.0.0.1 9 0 22222 11111 140\end{verbatim} 141on a Unix-like OS and 142\begin{verbatim} 143client.exe 192.168.0.1 9 0 22222 11111 144\end{verbatim} 145on Windows provided your local IP address is 192.168.0.1. 146 147\subsubsection{Sending over SCTP} 148To send data over SCTP directly you might need root privileges because raw sockets are used. 149Thus instead of specifying the encapsulation ports you have to start the programs prepending 150\texttt{sudo} or in case of Windows start the program from an administrator console. 151 152\subsubsection{Using the Callback API} 153Instead of asking constantly for new data, a callback API can be used that is triggered by 154SCTP. A callback function has to be registered that will be called whenever data is ready to 155be delivered to the application. 156 157The discard\_server has a flag to switch between the two modi. If use\_cb is set to 1, the 158callback API will be used. To change the setting, just set the flag and compile the program again. 159 160 161 162 163\section{Basic Operations} 164All system calls start with the prefix \textit{usrsctp\_} to distinguish them from the kernel variants. 165Some of them are changed to account for the different demands in the userland environment. 166 167\subsection{Differences to RFC 6458} 168\subsubsection{usrsctp\_init()} 169Every application has to start with \textit{usrsctp\_init()}. This function calls \textit{sctp\_init()} and reserves 170the memory necessary to administer the data transfer. 171The function prototype is 172\begin{verbatim} 173void 174usrsctp_init(uint16_t udp_port) 175\end{verbatim} 176As it is not always possible to send data directly over SCTP because not all NAT boxes can 177process SCTP packets, the data can be sent over UDP. To encapsulate SCTP into UDP 178a UDP port has to be specified, to which the datagrams can be sent. This local UDP port is set 179with the parameter \texttt{udp\_port}. The default value is 9899, the standard UDP encapsulation port. 180If UDP encapsulation is not necessary, the UDP port has to be set to 0. 181 182\subsubsection{usrsctp\_finish()} 183At the end of the program \textit{usrsctp\_finish()} should be called to free all the memory that has been 184allocated before. 185The function prototype is 186\begin{verbatim} 187int 188usrsctp_finish(void). 189\end{verbatim} 190The return code is 0 on success and -1 in case of an error. 191 192\subsubsection{usrsctp\_socket()} 193A representation of an SCTP endpoint is a socket. Is it created with \textit{usrsctp\_socket()}. 194The function prototype is: 195\begin{verbatim} 196struct socket * 197usrsctp_socket(int domain, 198 int type, 199 int protocol, 200 int (*receive_cb)(struct socket *sock, 201 union sctp_sockstore addr, 202 void *data, 203 size_t datalen, 204 struct sctp_rcvinfo, 205 int flags, 206 void *ulp_info), 207 int (*send_cb)(struct socket *sock, 208 uint32_t sb_free), 209 uint32_t sb_threshold, 210 void *ulp_info). 211\end{verbatim} 212The arguments taken from RFC~6458 are: 213\begin{itemize} 214\item domain: PF\_INET or PF\_INET6 can be used. 215\item type: In case of a one-to-many style socket it is SOCK\_SEQPACKET, in case of a one-to-one style 216socket it is SOCK\_STREAM. For an explanation of the differences between the socket types please 217refer to RFC~6458. 218\item protocol: Set IPPROTO\_SCTP. 219\end{itemize} 220 221In usrsctp, a callback API can be used. 222\begin{itemize} 223\item The function pointers of the receive and send callbacks are new arguments to the socket call. If no callback API is used, these must be \textit{NULL}. 224\item The \textit{sb\_threshold} specifies the amount of free space in the send socket buffer before the send function in the application is called. If a send callback function is specified and \textit{sb\_threshold} is 0, the function is called whenever there is room in the send socket buffer. 225\item Additional data may be passed along within the \textit{ulp\_info} parameter. This value will be passed to the \textit{receive\_cb} when it is invoked. 226\end{itemize} 227 228On success \textit{usrsctp\_socket()} returns the pointer to the new socket in the \texttt{struct socket} data type. 229It will be needed in all other system calls. In case of a failure NULL is returned and 230errno is set to the appropriate error code. 231 232\subsubsection{usrsctp\_close()} 233 234The function prototype of \textit{usrsctp\_close()} is 235\begin{verbatim} 236void 237usrsctp_close(struct socket *so). 238 \end{verbatim} 239Thus the only difference is the absence of a return code. 240 241\subsection{Same Functionality as RFC 6458} 242The following functions have the same functionality as their kernel pendants. There prototypes 243are described in the following subsections. For a detailed description please refer to RFC~6458. 244 245\subsubsection{usrsctp\_bind()} 246The function prototype of \textit{usrsctp\_bind()} is 247\begin{verbatim} 248int 249usrsctp_bind(struct socket *so, 250 struct sockaddr *addr, 251 socklen_t addrlen). 252\end{verbatim} 253The arguments are 254\begin{itemize} 255\item so: Pointer to the socket as returned by \textit{usrsctp\_socket()}. 256\item addr: The address structure (struct sockaddr\_in for an IPv4 address 257 or struct sockaddr\_in6 for an IPv6 address). 258\item addrlen: The size of the address structure. 259\end{itemize} 260\textit{usrsctp\_bind()} returns 0 on success and -1 in case of an error. 261 262\subsubsection{usrsctp\_listen()} 263The function prototype of \textit{usrsctp\_listen()} is 264\begin{verbatim} 265int 266usrsctp_listen(struct socket *so, 267 int backlog). 268 \end{verbatim} 269The arguments are 270\begin{itemize} 271\item so: Pointer to the socket as returned by \textit{usrsctp\_socket()}. 272\item backlog: If backlog is non-zero, enable listening, else disable 273 listening. 274\end{itemize} 275\textit{usrsctp\_listen()} returns 0 on success and -1 in case of an error. 276 277\subsubsection{usrsctp\_accept()} 278The function prototype of \textit{usrsctp\_accept()} is 279\begin{verbatim} 280struct socket * 281usrsctp_accept(struct socket *so, 282 struct sockaddr * addr, 283 socklen_t * addrlen). 284 \end{verbatim} 285 The arguments are 286\begin{itemize} 287\item so: Pointer to the socket as returned by \textit{usrsctp\_socket()}. 288\item addr: On return, the primary address of the peer (struct sockaddr\_in for an IPv4 address or 289 struct sockaddr\_in6 for an IPv6 address). 290\item addrlen: Size of the returned address structure. 291\end{itemize} 292\textit{usrsctp\_accept()} returns the accepted socket on success and NULL in case of an error. 293 294\subsubsection{usrsctp\_connect()} 295The function prototype of \textit{usrsctp\_connect()} is 296\begin{verbatim} 297int 298usrsctp_connect(struct socket *so, 299 struct sockaddr *name, 300 socklen_t addrlen) 301 \end{verbatim} 302The arguments are 303\begin{itemize} 304\item so: Pointer to the socket as returned by \textit{usrsctp\_socket()}. 305 \item name: Address of the peer to connect to (struct sockaddr\_in for an IPv4 address or 306 struct sockaddr\_in6 for an IPv6 address). 307\item addrlen: Size of the peer's address. 308\end{itemize} 309\textit{usrsctp\_connect()} returns 0 on success and -1 in case of an error. 310 311\subsubsection{usrsctp\_shutdown()} 312The function prototype of \textit{usrsctp\_shutdown()} is 313\begin{verbatim} 314int 315usrsctp_shutdown(struct socket *so, int how). 316\end{verbatim} 317The arguments are 318\begin{itemize} 319\item so: Pointer to the socket of the association to be closed. 320\item how: Specifies the type of shutdown. The values are as follows: 321\begin{itemize} 322\item SHUT\_RD: Disables further receive operations. No SCTP protocol 323 action is taken. 324\item SHUT\_WR: Disables further send operations, and initiates the SCTP 325 shutdown sequence. 326\item SHUT\_RDWR: Disables further send and receive operations, and 327 initiates the SCTP shutdown sequence. 328\end{itemize} 329\end{itemize} 330\textit{usrsctp\_shutdown()} returns 0 on success and -1 in case of an error. 331 332\section{Sending and Receiving Data} 333Since the publication of RFC~6458 there is only one function for sending and one for receiving 334that is not deprecated. Therefore, only these two are described here. 335 336\subsection{usrsctp\_sendv()} 337The function prototype is 338\begin{verbatim} 339ssize_t 340usrsctp_sendv(struct socket *so, 341 const void *data, 342 size_t len, 343 struct sockaddr *addrs, 344 int addrcnt, 345 void *info, 346 socklen_t infolen, 347 unsigned int infotype, 348 int flags). 349\end{verbatim} 350The arguments are 351\begin{itemize} 352\item so: The socket to send data on. 353\item data: As it is more convenient to send data in a buffer and not a \texttt{struct iovec} data structure, we 354chose to pass the data as a void pointer. 355\item len: Length of the data. 356\item addrs: In this version of usrsctp at most one destination address is supported. In the case of a connected 357socket, the parameter \texttt{addrs} can be set to NULL. 358\item addrcnt: Number of addresses. As at most one address is supported, addrcnt is 0 if addrs is NULL and 3591 otherwise. 360\item info: Additional information for a message is stored in \texttt{void *info}. The data types \texttt{struct~sctp\_sndinfo}, 361\texttt{struct~sctp\_prinfo}, and \texttt{struct} \linebreak \texttt{sctp\_sendv\_spa} are supported as defined in 362RFC~6458. Support for \texttt{structsctp\_authinfo} is not implemented yet, therefore, errno is set EINVAL 363and -1 will be returned, if it is used. 364\item infolen: Length of info in bytes. 365\item infotype: Identifies the type of the information provided in info. Possible values are 366SCTP\_SENDV\_NOINFO, SCTP\_SENDV\_SNDINFO, \linebreak SCTP\_SENDV\_PRINFO, SCTP\_SENDV\_SPA. 367For additional information please refer to RFC~6458. 368\item flags: Flags as described in RFC~6458. 369\end{itemize} 370 371\textit{usrsctp\_sendv()} returns the number of bytes sent, or -1 if an error 372occurred. The variable errno is then set appropriately. 373 374\subsection{usrsctp\_recvv()} 375The function prototype is 376\begin{verbatim} 377ssize_t 378usrsctp_recvv(struct socket *so, 379 void *dbuf, 380 size_t len, 381 struct sockaddr *from, 382 socklen_t * fromlen, 383 void *info, 384 socklen_t *infolen, 385 unsigned int *infotype, 386 int *msg_flags). 387\end{verbatim} 388The arguments are 389\begin{itemize} 390\item so: The socket to receive data on. 391\item dbuf: Analog to \textit{usrsctp\_sendv()} the data is returned in a buffer. 392\item len: Length of the buffer in bytes. 393\item from: A pointer to an address to be filled with the sender of the 394 received message's address. 395\item fromlen: An in/out parameter describing the from length. 396\item info: A pointer to the buffer to hold the attributes of the received 397 message. The structure type of info is determined by the 398 infotype parameter. The attributes returned in \texttt{info} have to be 399 handled in the same way as specified in RFC~6458. 400\item infolen: An in/out parameter describing the size of the info buffer. 401\item infotype: On return, *infotype is set to the type of the info 402 buffer. The current defined values are SCTP\_RECVV\_NOINFO, 403 SCTP\_RECVV\_RCVINFO, SCTP\_RECVV\_NXTINFO, and 404 SCTP\_RECVV\_RN. A detailed description is given in RFC~6458. 405\item flags: A pointer to an integer to be filled with any message flags 406 (e.g., MSG\_NOTIFICATION). Note that this field is an in/out 407 parameter. Options for the receive may also be passed into the 408 value (e.g., MSG\_EOR). Returning from the call, the flags' value 409 will differ from its original value. 410\end{itemize} 411 412\textit{usrsctp\_recvv()} returns the number of bytes sent, or -1 if an error 413occurred. The variable errno is then set appropriately. 414 415 416 417\section{Socket Options} 418Socket options are used to change the default behavior of socket calls. 419Their behavior is specified in RFC~6458. The functions to get or set them are 420 421\begin{verbatim} 422int 423usrsctp_getsockopt(struct socket *so, 424 int level, 425 int optname, 426 void *optval, 427 socklen_t *optlen) 428\end{verbatim} 429and 430\begin{verbatim} 431int 432usrsctp_setsockopt(struct socket *so, 433 int level, 434 int optname, 435 const void *optval, 436 socklen_t optlen). 437\end{verbatim} 438 439and the arguments are 440\begin{itemize} 441\item so: The socket of type struct socket. 442\item level: Set to IPPROTO\_SCTP for all SCTP options. 443\item optname: The option name as specified in Table~\ref{options}. 444\item optval: The buffer to store the value of the option as specified in the second column of Table~\ref{options}. 445\item optlen: The size of the buffer (or the length of the option 446 returned in case of \textit{usrsctp\_getsockopt}). 447\end{itemize} 448 449These functions return 0 on success and -1 in case of an error. 450 451\begin{longtable}{|l|l|c|} 452\hline 453{\bfseries Option}&{\bfseries Datatype} &{\bfseries r/w}\tabularnewline 454\endhead 455\hline 456SCTP\_RTOINFO&struct sctp\_rtoinfo&r/w\tabularnewline \hline 457SCTP\_ASSOCINFO&struct sctp\_assocparams&r/w\tabularnewline \hline 458SCTP\_INITMSG&struct sctp\_initmsg&r/w\tabularnewline \hline 459SCTP\_NODELAY&int&r/w\tabularnewline \hline 460SCTP\_AUTOCLOSE&int&r/w\tabularnewline \hline 461SCTP\_PRIMARY\_ADDR&struct sctp\_setprim&r/w\tabularnewline \hline 462SCTP\_ADAPTATION\_LAYER&struct sctp\_setadaptation&r/w\tabularnewline \hline 463SCTP\_DISABLE\_FRAGMENTS&int&r/w\tabularnewline \hline 464SCTP\_PEER\_ADDR\_PARAMS&struct sctp\_paddrparams&r/w\tabularnewline \hline 465SCTP\_I\_WANT\_MAPPED\_V4\_ADDR&int&r/w\tabularnewline \hline 466SCTP\_MAXSEG&struct sctp\_assoc\_value&r/w\tabularnewline \hline 467SCTP\_DELAYED\_SACK&struct sctp\_sack\_info&r/w\tabularnewline \hline 468SCTP\_FRAGMENT\_INTERLEAVE&int&r/w\tabularnewline \hline 469SCTP\_PARTIAL\_DELIVERY\_POINT&int&r/w\tabularnewline \hline 470SCTP\_HMAC\_IDENT&struct sctp\_hmacalgo&r/w\tabularnewline \hline 471SCTP\_AUTH\_ACTIVE\_KEY&struct sctp\_authkeyid&r/w\tabularnewline \hline 472SCTP\_AUTO\_ASCONF&int&r/w\tabularnewline \hline 473SCTP\_MAX\_BURST&struct sctp\_assoc\_value&r/w\tabularnewline \hline 474SCTP\_CONTEXT&struct sctp\_assoc\_value&r/w\tabularnewline \hline 475SCTP\_EXPLICIT\_EOR&int&r/w\tabularnewline \hline 476SCTP\_REUSE\_PORT&int&r/w\tabularnewline \hline 477SCTP\_EVENT&struct sctp\_event&r/w\tabularnewline \hline 478SCTP\_RECVRCVINFO&int&r/w\tabularnewline \hline 479SCTP\_RECVNXTINFO&int&r/w\tabularnewline \hline 480SCTP\_DEFAULT\_SNDINFO&struct sctp\_sndinfo&r/w\tabularnewline \hline 481SCTP\_DEFAULT\_PRINFO&struct sctp\_default\_prinfo&r/w\tabularnewline \hline 482SCTP\_REMOTE\_UDP\_ENCAPS\_PORT&int&r/w\tabularnewline \hline 483SCTP\_ENABLE\_STREAM\_RESET&struct sctp\_assoc\_value&r/w\tabularnewline \hline 484SCTP\_STATUS&struct sctp\_status&r\tabularnewline \hline 485SCTP\_GET\_PEER\_ADDR\_INFO&struct sctp\_paddrinfo&r\tabularnewline \hline 486SCTP\_PEER\_AUTH\_CHUNKS&struct sctp\_authchunks&r\tabularnewline \hline 487SCTP\_LOCAL\_AUTH\_CHUNKS&struct sctp\_authchunks&r\tabularnewline \hline 488SCTP\_GET\_ASSOC\_NUMBER&uint32\_t&r\tabularnewline \hline 489SCTP\_GET\_ASSOC\_ID\_LIST&struct sctp\_assoc\_ids&r\tabularnewline \hline 490SCTP\_RESET\_STREAMS&struct sctp\_reset\_streams&w\tabularnewline \hline 491SCTP\_RESET\_ASSOC&struct sctp\_assoc\_t&w\tabularnewline \hline 492SCTP\_ADD\_STREAMS&struct sctp\_add\_streams&w\tabularnewline \hline 493\caption{Socket Options supported by usrsctp} 494\label{options} 495\end{longtable} 496An overview of the supported options is given in Table~\ref{options}. Their use is described in RFC~6458~\cite{socketAPI}, RFC~6525~\cite{streamReset}, and~\cite{udpencaps}. 497 498\section{Sysctl variables} 499 500In kernel implementations like for instance FreeBSD, it is possible to change parameters 501in the operating system. These parameters are called sysctl variables. 502 503In usrsctp applications can set or retrieve these variables with the functions 504\begin{verbatim} 505void 506usrsctp_sysctl_set_ ## (uint32_t value) 507\end{verbatim} 508and 509\begin{verbatim} 510uint32_t 511usrsctp_sysctl_get_ ## (void) 512\end{verbatim} 513respectively, where \#\# stands for the name of the variable. 514 515In the following paragraphs a short description of the parameters will be given. 516 517\subsection{Manipulate Memory} 518\subsubsection{usrsctp\_sysctl\_set\_sctp\_sendspace()} 519The space of the available send buffer can be changed from its default value of 262,144 bytes 520to a value between 0 and $2^{32}-1$ bytes. 521 522\subsubsection{usrsctp\_sysctl\_set\_sctp\_recvspace()} 523The space of the available receive buffer can be changed from its default value of 262,144 bytes 524to a value between 0 and $2^{32}-1$ bytes. 525 526\subsubsection{usrsctp\_sysctl\_set\_sctp\_hashtblsize()} 527The TCB (Thread Control Block) hash table sizes, i.e. the size of one TCB in the hash table, can be tuned between 5281 and $2^{32}-1$ bytes. The default value is 1,024 bytes. A TCB contains for instance pointers to the socket, the 529endpoint, information about the association and some statistic data. 530 531\subsubsection{usrsctp\_sysctl\_set\_sctp\_pcbtblsize()} 532The PCB (Protocol Control Block) hash table sizes, i.e. the size of one PCB in the hash table, can be tuned between 5331 and $2^{32}-1$ bytes. The default value is 256 bytes. The PCB contains all variables that characterize an endpoint. 534 535\subsubsection{usrsctp\_sysctl\_set\_sctp\_system\_free\_resc\_limit()} 536This parameters tunes the maximum number of cached resources in the system. It can be set between 5370 and $2^{32}-1$. The default value is 1000. 538 539\subsubsection{usrsctp\_sysctl\_set\_sctp\_asoc\_free\_resc\_limit()} 540This parameters tunes the maximum number of cached resources in an association. It can be set between 5410 and $2^{32}-1$. The default value is 10. 542 543\subsubsection{usrsctp\_sysctl\_set\_sctp\_mbuf\_threshold\_count()} 544Data is stored in mbufs. Several mbufs can be chained together. The maximum number of small mbufs in a chain 545can be set with this parameter, before an mbuf cluset is used. The default is 5. 546 547\subsubsection{usrsctp\_sysctl\_set\_sctp\_add\_more\_threshold()} 548TBD 549This parameter configures the threshold below which more space should be added to a socket send buffer. 550The default value is 1452 bytes. 551 552 553\subsection{Configure RTO} 554The retransmission timeout (RTO), i.e. the time that controls the retransmission of messages, has 555several parameters, that can be changed, for example to shorten the time, before a message is 556retransmitted. The range of these parameters is between 0 and $2^{32}-1$~ms. 557 558\subsubsection{usrsctp\_sysctl\_set\_sctp\_rto\_max\_default()} 559The default value for the maximum retransmission timeout in ms is 60,000 (60~secs). 560 561\subsubsection{usrsctp\_sysctl\_set\_sctp\_rto\_min\_default()} 562The default value for the minimum retransmission timeout in ms is 1,000 (1~sec). 563 564\subsubsection{usrsctp\_sysctl\_set\_sctp\_rto\_initial\_default()} 565The default value for the initial retransmission timeout in ms is 3,000 (3~sec). This value is only 566needed before the first calculation of a round trip time took place. 567 568\subsubsection{usrsctp\_sysctl\_set\_sctp\_init\_rto\_max\_default()} 569The default value for the maximum retransmission timeout for an INIT chunk in ms is 60,000 (60~secs). 570 571 572\subsection{Set Timers} 573\subsubsection{usrsctp\_sysctl\_set\_sctp\_valid\_cookie\_life\_default()} 574A cookie has a specified life time. If it expires the cookie is not valid any more and an ABORT is sent. 575The default value in ms is 60,000 (60~secs). 576 577\subsubsection{usrsctp\_sysctl\_set\_sctp\_heartbeat\_interval\_default()} 578Set the default time between two heartbeats. The default is 30,000~ms. 579 580\subsubsection{usrsctp\_sysctl\_set\_sctp\_shutdown\_guard\_time\_default()} 581If a SHUTDOWN is not answered with a SHUTDOWN-ACK while the shutdown guard timer is still 582running, the association will be aborted after the default of 180~secs. 583 584\subsubsection{usrsctp\_sysctl\_set\_sctp\_pmtu\_raise\_time\_default()} 585TBD 586To set the size of the packets to the highest value possible, the maximum transfer unit (MTU) 587of the complete path has to be known. The default time interval for the path mtu discovery 588is 600~secs. 589 590\subsubsection{usrsctp\_sysctl\_set\_sctp\_secret\_lifetime\_default()} 591TBD 592The default secret lifetime of a server is 3600~secs. 593 594\subsubsection{usrsctp\_sysctl\_set\_sctp\_vtag\_time\_wait()} 595TBD 596Vtag time wait time, 0 disables it. Default: 60~secs 597 598 599\subsection{Set Failure Limits} 600Transmissions and retransmissions of messages might fail. To protect the system against too many 601retransmissions, limits have to be defined. 602 603\subsubsection{usrsctp\_sysctl\_set\_sctp\_init\_rtx\_max\_default()} 604The default maximum number of retransmissions of an INIT chunks is 8, before an ABORT is sent. 605 606\subsubsection{usrsctp\_sysctl\_set\_sctp\_assoc\_rtx\_max\_default()} 607This parameter sets the maximum number of failed retransmissions before the association is aborted. 608The default value is 10. 609 610\subsubsection{usrsctp\_sysctl\_set\_sctp\_path\_rtx\_max\_default()} 611This parameter sets the maximum number of path failures before the association is aborted. 612The default value is 5. Notice that the number of paths multiplied by this value should be 613equal to sctp\_assoc\_rtx\_max\_default. That means that the default configuration is good for two 614paths. 615 616\subsubsection{usrsctp\_sysctl\_set\_sctp\_max\_retran\_chunk()} 617The parameter configures how many times an unlucky chunk can be retransmitted before the 618association aborts. The default is set to 30. 619 620\subsubsection{usrsctp\_sysctl\_set\_sctp\_path\_pf\_threshold()} 621TBD 622Default potentially failed threshold. Default: 65535 623 624\subsubsection{usrsctp\_sysctl\_set\_sctp\_abort\_if\_one\_2\_one\_hits\_limit()} 625TBD 626When one-2-one hits qlimit abort. Default: 0 627 628 629\subsection{Control the Sending of SACKs} 630\subsubsection{usrsctp\_sysctl\_set\_sctp\_sack\_freq\_default()} 631The SACK frequency defines the number of packets that are awaited, before a SACK is sent. 632The default value is 2. 633 634\subsubsection{usrsctp\_sysctl\_set\_sctp\_delayed\_sack\_time\_default()} 635As a SACK (Selective Acknowlegment) is sent after every other packet, a timer is set to send a 636SACK in case another packet does not arrive in due time. The default value for this timer is 637200~ms. 638 639\subsubsection{usrsctp\_sysctl\_set\_sctp\_strict\_sacks()} 640TBD 641This is a flag to turn the controlling of the coherence of SACKs on or off. The default value is 6421 (on). 643 644\subsubsection{usrsctp\_sysctl\_set\_sctp\_nr\_sack\_on\_off()} 645If a slow hosts receives data on a lossy link it is possible that its receiver window is full and new 646data can only be accepted if one chunk with a higher TSN (Transmission Sequence Number) that has 647previously been acknowledged is dropped. As a consequence the sender has to store data, even if 648they have been acknowledged in case they have to be retransmitted. If this behavior is not necessary, 649non-renegable SACKs can be turned on. 650By default the use of non-renegable SACKs is turned off. 651 652\subsubsection{usrsctp\_sysctl\_set\_sctp\_enable\_sack\_immediately()} 653In some cases it is not desirable to wait for the SACK timer to expire before a SACK is sent. In these 654cases a bit called SACK-IMMEDIATELY~\cite{sack-imm} can be set to provoke the instant sending of a SACK. 655The default is to turn it off. 656 657\subsubsection{usrsctp\_sysctl\_set\_sctp\_L2\_abc\_variable()} 658TBD 659SCTP ABC max increase per SACK (L). Default: 1 660 661\subsection{Change Max Burst} 662Max burst defines the maximum number of packets that may be sent in one flight. 663 664\subsubsection{usrsctp\_sysctl\_set\_sctp\_max\_burst\_default()} 665The default value for max burst is 0, which means that the number of packets sent as a flight 666is not limited by this parameter, but may be by another one, see the next paragraph. 667 668\subsubsection{usrsctp\_sysctl\_set\_sctp\_use\_cwnd\_based\_maxburst()} 669The use of max burst is based on the size of the congestion window (cwnd). 670This parameter is set by default. 671 672\subsubsection{usrsctp\_sysctl\_set\_sctp\_hb\_maxburst()} 673Heartbeats are mostly used to verify a path. Their number can be limited. The default is 4. 674 675\subsubsection{usrsctp\_sysctl\_set\_sctp\_fr\_max\_burst\_default()} 676In the state of fast retransmission the number of packet bursts can be limited. The default 677value is 4. 678 679 680\subsection{Handle Chunks} 681\subsubsection{usrsctp\_sysctl\_set\_sctp\_peer\_chunk\_oh()} 682In order to keep track of the peer's advertised receiver window, the sender calculates the window by 683subtracting the amount of data sent. Yet, some OSs reduce the receiver window by the real space needed 684to store the data. This parameter sets the additional amount to debit the peer's receiver window per 685chunk sent. The default value is 256, which is the value needed by FreeBSD. 686 687\subsubsection{usrsctp\_sysctl\_set\_sctp\_max\_chunks\_on\_queue()} 688This parameter sets the maximum number of chunks that can be queued per association. The default 689value is 512. 690 691\subsubsection{usrsctp\_sysctl\_set\_sctp\_min\_split\_point()} 692TBD 693The minimum size when splitting a chunk is 2904 bytes by default. 694 695\subsubsection{usrsctp\_sysctl\_set\_sctp\_chunkscale()} 696TBD 697This parameter can be tuned for scaling of number of chunks and messages. The default is10. 698 699\subsubsection{usrsctp\_sysctl\_set\_sctp\_min\_residual()} 700TBD 701This parameter configures the minimum size of the residual data chunk in the second 702part of the split. The default is 1452. 703 704 705\subsection{Calculate RTT} 706The calculation of the round trip time (RTT) depends on several parameters. 707 708\subsubsection{usrsctp\_sysctl\_set\_sctp\_rttvar\_bw()} 709TBD 710Shift amount for bw smoothing on rtt calc. Default: 4 711 712\subsubsection{usrsctp\_sysctl\_set\_sctp\_rttvar\_rtt()} 713TBD 714Shift amount for rtt smoothing on rtt calc. Default: 5 715 716\subsubsection{usrsctp\_sysctl\_set\_sctp\_rttvar\_eqret()} 717TBD 718What to return when rtt and bw are unchanged. Default: 0 719 720 721\subsection{Influence the Congestion Control} 722The congestion control should protect the network against fast senders. 723 724\subsubsection{usrsctp\_sysctl\_set\_sctp\_ecn\_enable} 725Explicit congestion notifications are turned on by default. 726 727\subsubsection{usrsctp\_sysctl\_set\_sctp\_default\_cc\_module()} 728This parameter sets the default algorithm for the congestion control. 729Default is 0, i.e. the one specified in RFC~4960. 730 731\subsubsection{usrsctp\_sysctl\_set\_sctp\_initial\_cwnd()} 732Set the initial congestion window in MTUs. The default is 3. 733 734\subsubsection{usrsctp\_sysctl\_set\_sctp\_use\_dccc\_ecn()} 735TBD 736Enable for RTCC CC datacenter ECN. Default: 1 737 738\subsubsection{usrsctp\_sysctl\_set\_sctp\_steady\_step()} 739TBD 740How many the sames it takes to try step down of cwnd. Default: 20 741 742 743\subsection{Configure AUTH and ADD-IP} 744An important extension of SCTP is the dynamic address reconfiguration~\cite{addip}, also known as 745ADD-IP, which allows the changing of addresses during the lifetime of an association. 746For this feature the AUTH extension~\cite{auth} is necessary. 747 748\subsubsection{usrsctp\_sysctl\_set\_sctp\_auto\_asconf()} 749If SCTP Auto-ASCONF is enabled, the peer is informed automatically when a new address 750is added or removed. This feature is enabled by default. 751 752\subsubsection{usrsctp\_sysctl\_set\_sctp\_multiple\_asconfs()} 753By default the sending of multiple ASCONFs is disabled. 754 755\subsubsection{usrsctp\_sysctl\_set\_sctp\_auth\_disable()} 756The use of AUTH, which is normally turned on, can be disabled by setting this parameter to 1. 757 758\subsubsection{usrsctp\_sysctl\_set\_sctp\_asconf\_auth\_nochk()} 759It is also possible to disable the requirement to use AUTH in conjunction with ADD-IP by setting this parameter 760to 1. 761 762 763\subsection{Concurrent Multipath Transfer (CMT)} 764A prominent feature of SCTP is the possibility to use several addresses for the same association. 765One is the primary path, and the others are needed in case of a path failure. Using CMT the data is sent 766on several paths to enhance the throughput. 767 768\subsubsection{usrsctp\_sysctl\_set\_sctp\_cmt\_on\_off()} 769To turn CMT on, this parameter has to be set to 1. 770 771\subsubsection{usrsctp\_sysctl\_set\_sctp\_cmt\_use\_dac()} 772To use delayed acknowledgments with CMT this parameter has to be set to 1. 773 774\subsubsection{usrsctp\_sysctl\_set\_sctp\_buffer\_splitting()} 775For CMT it makes sense to split the send and receive buffer to have shares for each path. 776By default buffer splitting is turned off. 777 778 779\subsection{Network Address Translation (NAT)} 780To be able to pass NAT boxes, the boxes have to handle SCTP packets in a specific way. 781 782\subsubsection{usrsctp\_sysctl\_set\_sctp\_nat\_friendly()} 783SCTP NAT friendly operation. Default:1 784 785\subsubsection{usrsctp\_sysctl\_set\_sctp\_inits\_include\_nat\_friendly()} 786Enable sending of the nat-friendly SCTP option on INITs. Default: 0 787 788\subsubsection{usrsctp\_sysctl\_set\_sctp\_udp\_tunneling\_port()} 789Set the SCTP/UDP tunneling port. Default: 9899 790 791\subsection{SCTP Mobility} 792\subsubsection{usrsctp\_sysctl\_set\_sctp\_mobility\_base()} 793TBD 794Enable SCTP base mobility. Default: 0 795 796 797\subsubsection{usrsctp\_sysctl\_set\_sctp\_mobility\_fasthandoff()} 798TBD 799Enable SCTP fast handoff. default: 0 800 801 802\subsection{Miscellaneous} 803\subsubsection{usrsctp\_sysctl\_set\_sctp\_no\_csum\_on\_loopback()} 804Calculating the checksum for packets sent on loopback is turned off by default. 805To turn it on, set this parameter to 0. 806 807\subsubsection{usrsctp\_sysctl\_set\_sctp\_nr\_outgoing\_streams\_default()} 808The peer is notified about the number of outgoing streams in the INIT or INIT-ACK chunk. 809The default is 10. 810 811\subsubsection{usrsctp\_sysctl\_set\_sctp\_do\_drain()} 812Determines whether SCTP should respond to the drain calls. Default: 1 813 814\subsubsection{usrsctp\_sysctl\_set\_sctp\_strict\_data\_order()} 815TBD 816Enforce strict data ordering, abort if control inside data. Default: 0 817 818\subsubsection{usrsctp\_sysctl\_set\_sctp\_default\_ss\_module()} 819Set the default stream scheduling module. Implemented modules are: 820SCTP\_SS\_DEFAULT, SCTP\_SS\_ROUND\_ROBIN, SCTP\_SS\_ROUND\_ROBIN\_PACKET, 821SCTP\_SS\_PRIORITY, SCTP\_SS\_FAIR\_BANDWITH, and SCTP\_SS\_FIRST\_COME. 822 823\subsubsection{usrsctp\_sysctl\_set\_sctp\_default\_frag\_interleave()} 824TBD 825Default fragment interleave level. Default: 1 826 827\subsubsection{usrsctp\_sysctl\_set\_sctp\_blackhole()} 828TBD 829Enable SCTP blackholing. Default: 0 830 831\subsubsection{usrsctp\_sysctl\_set\_sctp\_logging\_level()} 832Set the logging level. The default is 0. 833 834 835\subsubsection{usrsctp\_sysctl\_set\_sctp\_debug\_on()} 836Turn debug output on or off. It is disabled by default. To obtain debug output, 837SCTP\_DEBUG has to be set as a compile flag. 838 839 840%The following variables are supported: 841%\begin{longtable}{|l|l|c|} 842%\hline 843%{\bfseries Parameter}&{\bfseries Meaning}&{\bfseries Default Value} \tabularnewline 844%\endhead 845%\hline 846%sctp\_sendspace&Send buffer space&1864135\tabularnewline \hline 847%sctp\_recvspace&Receive buffer space&1864135 \tabularnewline \hline 848%sctp\_hashtblsize&Tunable for TCB hash table sizes&1024 \tabularnewline \hline 849%sctp\_pcbtblsize&Tunable for PCB hash table sizes&256 \tabularnewline \hline 850%sctp\_system\_free\_resc\_limit&Cached resources in the system&1000 \tabularnewline \hline 851%sctp\_asoc\_free\_resc\_limit&Cashed resources in an association&10 \tabularnewline \hline 852%sctp\_rto\_max\_default&Default value for RTO\_max&60000~ms \tabularnewline \hline 853%sctp\_rto\_min\_default&Default value for RTO\_min&1000~ms \tabularnewline \hline 854%sctp\_rto\_initial\_default&Default value for RTO\_initial&3000~ms \tabularnewline \hline 855%sctp\_init\_rto\_max\_default&Default value for the maximum RTO&60000~ms \tabularnewline 856 % &for sending an INIT& \tabularnewline \hline 857%sctp\_valid\_cookie\_life\_default&Valid cookie life time&60000~ms \tabularnewline \hline 858%sctp\_init\_rtx\_max\_default&Maximum number of INIT retransmissions&8 \tabularnewline \hline 859%sctp\_assoc\_rtx\_max\_default&Maximum number of failed retransmissions&10\tabularnewline 860% & before the association is aborted&\tabularnewline \hline 861%sctp\_path\_rtx\_max\_default&Maximum number of failed retransmissions&5\tabularnewline 862% &before a path fails&\tabularnewline \hline 863%sctp\_ecn\_enable&Enabling explicit congestion notifications&1\tabularnewline \hline 864%sctp\_strict\_sacks&Control the coherence of SACKs&1 \tabularnewline \hline 865%sctp\_delayed\_sack\_time\_default&Default delayed SACK timer&200~ms\tabularnewline \hline 866%sctp\_sack\_freq\_default&Default SACK frequency&2 \tabularnewline \hline 867%sctp\_nr\_sack\_on\_off&Turn non-renegable SACKs on or off&0 \tabularnewline \hline 868%sctp\_enable\_sack\_immediately&Enable sending of the SACK-&0 \tabularnewline &IMMEDIATELY bit.&\tabularnewline \hline 869%sctp\_no\_csum\_on\_loopback&Enable the compilation of the checksum on&1 \tabularnewline 870% &packets sent on loopback&\tabularnewline \hline 871%sctp\_peer\_chunk\_oh&Amount to debit peers rwnd per chunk sent&256 \tabularnewline \hline 872%sctp\_max\_burst\_default&Default max burst for SCTP endpoints&0 \tabularnewline \hline 873%sctp\_use\_cwnd\_based\_maxburst&Use max burst based on the size of &1\tabularnewline % &the congestion window&\tabularnewline \hline 874%sctp\_hb\_maxburst&Confirmation Heartbeat max burst&4 \tabularnewline \hline 875%sctp\_max\_chunks\_on\_queue&Default max chunks on queue per asoc&512 \tabularnewline \hline 876%sctp\_min\_split\_point&Minimum size when splitting a chunk&2904 \tabularnewline \hline 877%sctp\_chunkscale&Tunable for Scaling of number of chunks and&10\tabularnewline 878% &messages&\tabularnewline \hline 879%sctp\_mbuf\_threshold\_count&Maximum number of small mbufs in a chain&5\tabularnewline \hline 880%sctp\_heartbeat\_interval\_default&Deafult time between two Heartbeats&30000~ms\tabularnewline \hline 881%sctp\_pmtu\_raise\_time\_default&Default PMTU raise timer&600~secs\tabularnewline \hline 882%sctp\_shutdown\_guard\_time\_default&Default shutdown guard timer&180~secs\tabularnewline \hline 883%sctp\_secret\_lifetime\_default&Default secret lifetime&3600~secs \tabularnewline \hline 884%sctp\_add\_more\_threshold&Threshold when more space should &1452\tabularnewline 885% &be added to a socket send buffer&\tabularnewline \hline 886%sctp\_nr\_outgoing\_streams\_default&Default number of outgoing streams&10\tabularnewline \hline 887%sctp\_cmt\_on\_off&Turn CMT on or off.&0\tabularnewline \hline 888%sctp\_cmt\_use\_dac&Use delayed acknowledgment for CMT&0\tabularnewline \hline 889%sctp\_fr\_max\_burst\_default&Default max burst for SCTP endpoints when &4\tabularnewline 890% &fast retransmitting&\tabularnewline \hline 891%sctp\_auto\_asconf&Enable SCTP Auto-ASCONF&1\tabularnewline \hline 892%sctp\_multiple\_asconfs&Enable SCTP Muliple-ASCONFs&0 \tabularnewline \hline 893%sctp\_asconf\_auth\_nochk&Disable SCTP ASCONF AUTH requirement&0\tabularnewline \hline 894%sctp\_auth\_disable&Disable SCTP AUTH function&0\tabularnewline \hline 895%sctp\_nat\_friendly&SCTP NAT friendly operation&1\tabularnewline \hline 896%sctp\_inits\_include\_nat\_friendly&Enable sending of the nat-friendly &0\tabularnewline 897% &SCTP option on INITs.&\tabularnewline \hline 898%sctp\_udp\_tunneling\_port&Set the SCTP/UDP tunneling port&9899\tabularnewline \hline 899%sctp\_do\_drain&Determines whether SCTP should respond&1\tabularnewline 900% &to the drain calls&\tabularnewline \hline 901%sctp\_abort\_if\_one\_2\_one\_hits\_limit&When one-2-one hits qlimit abort&0 \tabularnewline \hline 902%sctp\_strict\_data\_order&Enforce strict data ordering, abort if control&0\tabularnewline 903% &inside data&\tabularnewline \hline 904%sctp\_min\_residual&Minimum residual data chunk in second&1452\tabularnewline 905% &part of split&\tabularnewline \hline 906%sctp\_max\_retran\_chunk&Maximum times an unlucky chunk can be&30\tabularnewline 907% & retransmitted before the association aborts&\tabularnewline \hline 908%sctp\_default\_cc\_module&Default congestion control module&0\tabularnewline \hline 909%sctp\_default\_ss\_module&Default stream scheduling module&0 \tabularnewline \hline 910%sctp\_default\_frag\_interleave&Default fragment interleave level&1\tabularnewline \hline 911%sctp\_mobility\_base&Enable SCTP base mobility&0\tabularnewline \hline 912%sctp\_mobility\_fasthandoff&Enable SCTP fast handoff&0\tabularnewline \hline 913%sctp\_L2\_abc\_variable&SCTP ABC max increase per SACK (L)&1\tabularnewline \hline 914%sctp\_vtag\_time\_wait&Vtag time wait time, 0 disables it.&60~secs\tabularnewline \hline 915%sctp\_blackhole&Enable SCTP blackholing&0\tabularnewline \hline 916%sctp\_path\_pf\_threshold&Default potentially failed threshold&65535\tabularnewline \hline 917%sctp\_rttvar\_bw&Shift amount for bw smoothing on rtt calc&4 \tabularnewline \hline 918%sctp\_rttvar\_rtt&Shift amount for rtt smoothing on rtt calc&5 \tabularnewline \hline 919%sctp\_rttvar\_eqret &What to return when rtt and bw are&0\tabularnewline 920% &unchanged&\tabularnewline \hline 921%sctp\_steady\_step&How many the sames it takes to try step&20\tabularnewline 922% &down of cwnd&\tabularnewline \hline 923%sctp\_use\_dccc\_ecn&Enable for RTCC CC datacenter ECN&1 \tabularnewline \hline 924%sctp\_buffer\_splitting&Enable send/receive buffer splitting&0 \tabularnewline \hline 925%sctp\_initial\_cwnd&Initial congestion window in MTUs&3\tabularnewline \hline 926%sctp\_logging\_level&Logging level&0 \tabularnewline \hline 927%sctp\_debug\_on&Turns debug output on or off.&0 \tabularnewline \hline 928 929%\caption{Sysctl variables supported by usrsctp} 930%\end{longtable} 931 932\section{Examples} 933\subsection{Discard Server}\label{server} 934\begin{verbatim} 935/* 936 * Copyright (C) 2011-2012 Michael Tuexen 937 * 938 * All rights reserved. 939 * 940 * Redistribution and use in source and binary forms, with or without 941 * modification, are permitted provided that the following conditions 942 * are met: 943 * 1. Redistributions of source code must retain the above copyright 944 * notice, this list of conditions and the following disclaimer. 945 * 2. Redistributions in binary form must reproduce the above copyright 946 * notice, this list of conditions and the following disclaimer in the 947 * documentation and/or other materials provided with the distribution. 948 * 3. Neither the name of the project nor the names of its contributors 949 * may be used to endorse or promote products derived from this software 950 * without specific prior written permission. 951 * 952 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 953 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 954 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 955 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 956 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 957 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 958 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 959 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 960 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 961 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 962 * SUCH DAMAGE. 963 */ 964 965/* 966 * Usage: discard_server [local_encaps_port] [remote_encaps_port] 967 */ 968 969#include <stdio.h> 970#include <stdlib.h> 971#include <string.h> 972#include <sys/types.h> 973#if !defined(__Userspace_os_Windows) 974#include <unistd.h> 975#include <sys/socket.h> 976#include <netinet/in.h> 977#include <arpa/inet.h> 978#endif 979#include <usrsctp.h> 980 981#define BUFFER_SIZE 10240 982 983const int use_cb = 0; 984 985static int 986receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, 987 size_t datalen, struct sctp_rcvinfo rcv, int flags) 988{ 989 char name[INET6_ADDRSTRLEN]; 990 991 if (data) { 992 if (flags & MSG_NOTIFICATION) { 993 printf("Notification of length %d received.\n", (int)datalen); 994 } else { 995 printf("Msg of length %d received from %s:%u on stream %d with " 996 "SSN %u and TSN %u, PPID %d, context %u.\n", 997 (int)datalen, 998 addr.sa.sa_family == AF_INET ? 999 inet_ntop(AF_INET, &addr.sin.sin_addr, name, 1000 INET6_ADDRSTRLEN): 1001 inet_ntop(AF_INET6, &addr.sin6.sin6_addr, name, 1002 INET6_ADDRSTRLEN), 1003 ntohs(addr.sin.sin_port), 1004 rcv.rcv_sid, 1005 rcv.rcv_ssn, 1006 rcv.rcv_tsn, 1007 ntohl(rcv.rcv_ppid), 1008 rcv.rcv_context); 1009 } 1010 free(data); 1011 } 1012 return 1; 1013} 1014 1015int 1016main(int argc, char *argv[]) 1017{ 1018 struct socket *sock; 1019 struct sockaddr_in6 addr; 1020 struct sctp_udpencaps encaps; 1021 struct sctp_event event; 1022 uint16_t event_types[] = {SCTP_ASSOC_CHANGE, 1023 SCTP_PEER_ADDR_CHANGE, 1024 SCTP_REMOTE_ERROR, 1025 SCTP_SHUTDOWN_EVENT, 1026 SCTP_ADAPTATION_INDICATION, 1027 SCTP_PARTIAL_DELIVERY_EVENT}; 1028 unsigned int i; 1029 struct sctp_assoc_value av; 1030 const int on = 1; 1031 int n, flags; 1032 socklen_t from_len; 1033 char buffer[BUFFER_SIZE]; 1034 char name[INET6_ADDRSTRLEN]; 1035 struct sctp_recvv_rn rn; 1036 socklen_t infolen = sizeof(struct sctp_recvv_rn); 1037 struct sctp_rcvinfo rcv; 1038 struct sctp_nxtinfo nxt; 1039 unsigned int infotype = 0; 1040 1041 if (argc > 1) { 1042 usrsctp_init(atoi(argv[1])); 1043 } else { 1044 usrsctp_init(9899); 1045 } 1046 usrsctp_sysctl_set_sctp_debug_on(0); 1047 usrsctp_sysctl_set_sctp_blackhole(2); 1048 1049 if ((sock = usrsctp_socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, 1050 use_cb?receive_cb:NULL, NULL, 0)) == NULL) { 1051 perror("userspace_socket"); 1052 } 1053 if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_I_WANT_MAPPED_V4_ADDR, 1054 (const void*)&on, (socklen_t)sizeof(int)) < 0) { 1055 perror("setsockopt"); 1056 } 1057 memset(&av, 0, sizeof(struct sctp_assoc_value)); 1058 av.assoc_id = SCTP_ALL_ASSOC; 1059 av.assoc_value = 47; 1060 1061 if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_CONTEXT, (const void*)&av, 1062 (socklen_t)sizeof(struct sctp_assoc_value)) < 0) { 1063 perror("setsockopt"); 1064 } 1065 if (argc > 2) { 1066 memset(&encaps, 0, sizeof(struct sctp_udpencaps)); 1067 encaps.sue_address.ss_family = AF_INET6; 1068 encaps.sue_port = htons(atoi(argv[2])); 1069 if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_REMOTE_UDP_ENCAPS_PORT, 1070 (const void*)&encaps, 1071 (socklen_t)sizeof(struct sctp_udpencaps)) < 0) { 1072 perror("setsockopt"); 1073 } 1074 } 1075 memset(&event, 0, sizeof(event)); 1076 event.se_assoc_id = SCTP_FUTURE_ASSOC; 1077 event.se_on = 1; 1078 for (i = 0; i < (unsigned int)(sizeof(event_types)/sizeof(uint16_t)); i++) { 1079 event.se_type = event_types[i]; 1080 if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_EVENT, &event, 1081 sizeof(struct sctp_event)) < 0) { 1082 perror("userspace_setsockopt"); 1083 } 1084 } 1085 memset((void *)&addr, 0, sizeof(struct sockaddr_in6)); 1086#ifdef HAVE_SIN_LEN 1087 addr.sin6_len = sizeof(struct sockaddr_in6); 1088#endif 1089 addr.sin6_family = AF_INET6; 1090 addr.sin6_port = htons(9); 1091 addr.sin6_addr = in6addr_any; 1092 if (usrsctp_bind(sock, (struct sockaddr *)&addr, 1093 sizeof(struct sockaddr_in6)) < 0) { 1094 perror("userspace_bind"); 1095 } 1096 if (usrsctp_listen(sock, 1) < 0) { 1097 perror("userspace_listen"); 1098 } 1099 while (1) { 1100 if (use_cb) { 1101#if defined (__Userspace_os_Windows) 1102 Sleep(1*1000); 1103#else 1104 sleep(1); 1105#endif 1106 } else { 1107 from_len = (socklen_t)sizeof(struct sockaddr_in6); 1108 flags = 0; 1109 rn.recvv_rcvinfo = rcv; 1110 rn.recvv_nxtinfo = nxt; 1111 n = usrsctp_recvv(sock, (void*)buffer, BUFFER_SIZE, 1112 (struct sockaddr *) &addr, &from_len, (void *)&rn, 1113 &infolen, &infotype, &flags); 1114 if (n > 0) { 1115 if (flags & MSG_NOTIFICATION) { 1116 printf("Notification of length %d received.\n", n); 1117 } else { 1118 printf("Msg of length %d received from %s:%u on stream " 1119 "%d with SSN %u and TSN %u, PPID %d, context %u, " 1120 "complete %d.\n", 1121 n, 1122 inet_ntop(AF_INET6, &addr.sin6_addr, name, 1123 INET6_ADDRSTRLEN), ntohs(addr.sin6_port), 1124 rn.recvv_rcvinfo.rcv_sid, 1125 rn.recvv_rcvinfo.rcv_ssn, 1126 rn.recvv_rcvinfo.rcv_tsn, 1127 ntohl(rn.recvv_rcvinfo.rcv_ppid), 1128 rn.recvv_rcvinfo.rcv_context, 1129 (flags & MSG_EOR) ? 1 : 0); 1130 } 1131 } 1132 } 1133 } 1134 usrsctp_close(sock); 1135 while (usrsctp_finish() != 0) { 1136#if defined (__Userspace_os_Windows) 1137 Sleep(1000); 1138#else 1139 sleep(1); 1140#endif 1141 } 1142 return (0); 1143} 1144 1145\end{verbatim} 1146 1147\subsection{Client}\label{client} 1148\begin{verbatim} 1149/* 1150 * Copyright (C) 2011-2012 Michael Tuexen 1151 * 1152 * All rights reserved. 1153 * 1154 * Redistribution and use in source and binary forms, with or without 1155 * modification, are permitted provided that the following conditions 1156 * are met: 1157 * 1. Redistributions of source code must retain the above copyright 1158 * notice, this list of conditions and the following disclaimer. 1159 * 2. Redistributions in binary form must reproduce the above copyright 1160 * notice, this list of conditions and the following disclaimer in the 1161 * documentation and/or other materials provided with the distribution. 1162 * 3. Neither the name of the project nor the names of its contributors 1163 * may be used to endorse or promote products derived from this software 1164 * without specific prior written permission. 1165 * 1166 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1167 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1168 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1169 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 1170 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1171 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1172 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1173 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1174 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1175 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1176 * SUCH DAMAGE. 1177 */ 1178 1179/* 1180 * Usage: client remote_addr remote_port [local_encaps_port remote_encaps_port] 1181 */ 1182 1183#include <stdio.h> 1184#include <stdlib.h> 1185#include <string.h> 1186#if !defined(__Userspace_os_Windows) 1187#include <unistd.h> 1188#endif 1189#include <sys/types.h> 1190#if !defined(__Userspace_os_Windows) 1191#include <sys/socket.h> 1192#include <netinet/in.h> 1193#include <arpa/inet.h> 1194#endif 1195#include <usrsctp.h> 1196 1197int done = 0; 1198 1199static int 1200receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, 1201 size_t datalen, struct sctp_rcvinfo rcv, int flags) 1202{ 1203 if (data == NULL) { 1204 done = 1; 1205 usrsctp_close(sock); 1206 } else { 1207 write(fileno(stdout), data, datalen); 1208 free(data); 1209 } 1210 return 1; 1211} 1212 1213int 1214main(int argc, char *argv[]) 1215{ 1216 struct socket *sock; 1217 struct sockaddr_in addr4; 1218 struct sockaddr_in6 addr6; 1219 struct sctp_udpencaps encaps; 1220 char buffer[80]; 1221 1222 if (argc > 3) { 1223 usrsctp_init(atoi(argv[3])); 1224 } else { 1225 usrsctp_init(9899); 1226 } 1227 usrsctp_sysctl_set_sctp_debug_on(0); 1228 usrsctp_sysctl_set_sctp_blackhole(2); 1229 if ((sock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, 1230 receive_cb, NULL, 0)) == NULL) { 1231 perror("userspace_socket ipv6"); 1232 } 1233 if (argc > 4) { 1234 memset(&encaps, 0, sizeof(struct sctp_udpencaps)); 1235 encaps.sue_address.ss_family = AF_INET6; 1236 encaps.sue_port = htons(atoi(argv[4])); 1237 if (usrsctp_setsockopt(sock, IPPROTO_SCTP, SCTP_REMOTE_UDP_ENCAPS_PORT, 1238 (const void*)&encaps, 1239 (socklen_t)sizeof(struct sctp_udpencaps)) < 0) { 1240 perror("setsockopt"); 1241 } 1242 } 1243 memset((void *)&addr4, 0, sizeof(struct sockaddr_in)); 1244 memset((void *)&addr6, 0, sizeof(struct sockaddr_in6)); 1245#if !defined(__Userspace_os_Linux) && !defined(__Userspace_os_Windows) 1246 addr4.sin_len = sizeof(struct sockaddr_in); 1247 addr6.sin6_len = sizeof(struct sockaddr_in6); 1248#endif 1249 addr4.sin_family = AF_INET; 1250 addr6.sin6_family = AF_INET6; 1251 addr4.sin_port = htons(atoi(argv[2])); 1252 addr6.sin6_port = htons(atoi(argv[2])); 1253 if (inet_pton(AF_INET6, argv[1], &addr6.sin6_addr) == 1) { 1254 if (usrsctp_connect(sock, (struct sockaddr *)&addr6, 1255 sizeof(struct sockaddr_in6)) < 0) { 1256 perror("userspace_connect"); 1257 } 1258 } else if (inet_pton(AF_INET, argv[1], &addr4.sin_addr) == 1) { 1259 if (usrsctp_connect(sock, (struct sockaddr *)&addr4, 1260 sizeof(struct sockaddr_in)) < 0) { 1261 perror("userspace_connect"); 1262 } 1263 } else { 1264 printf("Illegal destination address.\n"); 1265 } 1266 while ((fgets(buffer, sizeof(buffer), stdin) != NULL) && !done) { 1267 usrsctp_sendv(sock, buffer, strlen(buffer), NULL, 0, 1268 NULL, 0, SCTP_SENDV_NOINFO, 0); 1269 } 1270 if (!done) { 1271 usrsctp_shutdown(sock, SHUT_WR); 1272 } 1273 while (!done) { 1274#if defined (__Userspace_os_Windows) 1275 Sleep(1*1000); 1276#else 1277 sleep(1); 1278#endif 1279 } 1280 while (usrsctp_finish() != 0) { 1281#if defined (__Userspace_os_Windows) 1282 Sleep(1000); 1283#else 1284 sleep(1); 1285#endif 1286 } 1287 return(0); 1288} 1289 1290\end{verbatim} 1291\bibliographystyle{plain} 1292% 1293\begin{thebibliography}{99} 1294 1295\bibitem{socketAPI} 1296R.~Stewart, M.~T\"uxen, K.~Poon, and V.~Yasevich: 1297\textit{Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)}. 1298RFC~6458, Dezember~2011. 1299 1300\bibitem{SCTP} 1301R.~Stewart: 1302\textit{Stream Control Transmission Protocol}. 1303RFC~4960, September~2007. 1304 1305 1306\bibitem{auth} 1307M.~T\"uxen, R.~Stewart, P.~Lei, and E.~Rescorla: 1308\textit{Authenticated Chunks for the Stream Control Transmission Protocol (SCTP)}. 1309RFC~4895, August~2007. 1310 1311\bibitem{streamReset} 1312R.~Stewart, M.~T\"uxen, and P.~Lei: 1313\textit{Stream Control Transmission Protocol (SCTP) Stream Reconfiguration}. 1314RFC~6525, February~2012. 1315 1316 1317\bibitem{addip} 1318R.~Stewart, Q.~Xie, M.~T\"uxen, S.~Maruyama, and M.~Kozuka: 1319\textit{Stream Control Transmission Protocol (SCTP) Dynamic Address Reconfiguration}. 1320RFC~5061, September~2007. 1321 1322\bibitem{sack-imm} 1323M.~T\"uxen, I.~R\"ungeler, and R.~Stewart: 1324\textit{SACK-IMMEDIATELY Extension for the Stream Control Transmission Protocol}. 1325draft-tuexen-tsvwg-sctp-sack-immediately-09 (work in progress), April~2012. 1326 1327\bibitem{udpencaps} 1328M.~T\"uxen and R.~Stewart 1329\textit{UDP Encapsulation of SCTP Packetsl}. 1330draft-ietf-tsvwg-sctp-udp-encaps-03 (work in progress), March~2012. 1331 1332\end{thebibliography} 1333\end{document} 1334