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