1 /* $Id$ 2 * -------------------------------------------------------------------------- 3 * 4 * //===== //===== ===//=== //===// // // //===// 5 * // // // // // // // // // 6 * //====// // // //===// // // //===<< 7 * // // // // // // // // 8 * ======// //===== // // //===== // //===// 9 * 10 * -------------- An SCTP implementation according to RFC 4960 -------------- 11 * 12 * Copyright (C) 2000 by Siemens AG, Munich, Germany. 13 * Copyright (C) 2001-2004 Andreas Jungmaier 14 * Copyright (C) 2004-2019 Thomas Dreibholz 15 * 16 * Acknowledgements: 17 * Realized in co-operation between Siemens AG and the University of 18 * Duisburg-Essen, Institute for Experimental Mathematics, Computer 19 * Networking Technology group. 20 * This work was partially funded by the Bundesministerium fuer Bildung und 21 * Forschung (BMBF) of the Federal Republic of Germany 22 * (Förderkennzeichen 01AK045). 23 * The authors alone are responsible for the contents. 24 * 25 * This library is free software: you can redistribute it and/or modify it 26 * under the terms of the GNU Lesser General Public License as published by 27 * the Free Software Foundation, either version 2.1 of the License, or 28 * (at your option) any later version. 29 * 30 * This library is distributed in the hope that it will be useful, 31 * but WITHOUT ANY WARRANTY; without even the implied warranty of 32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 * GNU General Public License for more details. 34 * 35 * You should have received a copy of the GNU Lesser General Public License 36 * along with this program. If not, see <http://www.gnu.org/licenses/>. 37 * 38 * Contact: sctp-discussion@sctp.de 39 * dreibh@iem.uni-due.de 40 * tuexen@fh-muenster.de 41 * andreas.jungmaier@web.de 42 */ 43 44 #ifndef DISTRIBUTION_H 45 #define DISTRIBUTION_H 46 47 #ifdef HAVE_CONFIG_H 48 #include <config.h> 49 #endif 50 51 #include "globals.h" /* for public association data structure */ 52 #include "messages.h" 53 54 /* define some important constants */ 55 #define ASSOCIATION_MAX_RETRANS 10 56 #define MAX_INIT_RETRANSMITS 8 57 #define MAX_PATH_RETRANSMITS 5 58 #define VALID_COOKIE_LIFE_TIME 10000 59 /* 60 #define RWND_CONST 64000 61 */ 62 #define SACK_DELAY 200 63 #define RTO_INITIAL 3000 64 #define IPTOS_DEFAULT 0x10 /* IPTOS_LOWDELAY */ 65 #define RTO_MIN 1000 66 #define DEFAULT_MAX_SENDQUEUE 0 /* unlimited send queue */ 67 #define DEFAULT_MAX_RECVQUEUE 0 /* unlimited recv queue - unused really */ 68 #define DEFAULT_MAX_BURST 4 /* maximum burst parameter */ 69 #define RTO_MAX 60000 70 71 72 /******************** Function Definitions ********************************************************/ 73 74 /*------------------- Functions called by the ULP ------------------------------------------------*/ 75 76 /* This functions are defined in a seperate header file sctp.h in order to seperate the interface to 77 the ULP and the interface to other modules within SCTP. 78 */ 79 80 /*------------------- Functions called by the Unix-Interface -------------------------------------*/ 81 82 /** 83 * \fn mdi_receiveMessage 84 * mdi_receiveMessage is the callback function of the SCTP-message distribution. 85 * It is called by the Unix-interface module when a new datagramm is received. 86 * This function also performs OOTB handling, tag verification etc. 87 * (see also RFC 4960, section 8.5.1.B) and sends data to the bundling module of 88 * the right association 89 * 90 * @param socket_fd the socket file discriptor 91 * @param buffer pointer to arrived datagram 92 * @param bufferlength length of datagramm 93 * @param fromAddress source address of DG 94 * @param portnum bogus port number 95 */ 96 void mdi_receiveMessage(gint socket_fd, unsigned char *buffer, 97 int bufferLength, union sockunion * source_addr, 98 union sockunion * dest_addr); 99 100 /*------------------- Functions called by the SCTP bundling --------------------------------------*/ 101 102 /* Used by bundling to send a SCTP-daatagramm. 103 Before calling send_message at the adaption-layer, this function does: 104 - add the SCTP common header to the message 105 - convert the SCTP message to a byte string 106 - retrieve the socket-file descriptor of the SCTP-instance 107 - retrieve the destination address 108 @param SCTP_message SCTP message (UDP-datapart) as a struct 109 @param length length of SCTP message. 110 @param destAddresIndex Index of address in the destination address list. 111 @return Errorcode. 112 */ 113 114 int mdi_send_message(SCTP_message * message, unsigned int length, short destAddressIndex); 115 116 117 118 /*------------------- Functions called by the SCTP to forward primitives to ULP ------------------*/ 119 120 121 /** 122 * indicates new data (i.e. length bytes) have arrived from peer (chapter 10.2.A). 123 * @param streamID data has arrived for this stream 124 * @param length number of bytes thet have arrived 125 * @param unordered unordered flag (TRUE==1==unordered, FALSE==0==normal,numbered chunk) 126 */ 127 void mdi_dataArriveNotif(unsigned short streamID, unsigned int length, unsigned short streamSN, 128 unsigned int tsn, unsigned int protoID, unsigned int unordered); 129 130 131 132 /* indicates a change of network status (chapter 10.2.C). 133 params: 1. destinationAddresses 134 2. newState 135 */ 136 void mdi_networkStatusChangeNotif(short destinationAddress, unsigned short newState); 137 138 139 /** 140 * indicates a send failure (chapter 10.2.B). 141 * params: pointer to data not sent 142 * dataLength 143 * context from sendChunk 144 */ 145 void mdi_sendFailureNotif(unsigned char *data, unsigned int dataLength, unsigned int *context); 146 147 148 149 /** 150 * indicates that communication was lost to peer (chapter 10.2.E). 151 * params: status, type of event 152 */ 153 void mdi_communicationLostNotif(unsigned short status); 154 155 /* 156 * indicates that peer wished to shutdown this assoc 157 */ 158 void mdi_peerShutdownReceivedNotif(void); 159 160 /* 161 *indicates that communication has been gracefully terminated (10.2.H). 162 */ 163 void mdi_shutdownCompleteNotif(void); 164 165 /* indicates that a restart has occured (10.2.G.) */ 166 void mdi_restartNotif(void); 167 168 169 170 /* indicates that a association is established (chapter 10.2.D). 171 params: status, type of event 172 */ 173 void mdi_communicationUpNotif(unsigned short status); 174 175 /** 176 * Function that notifies the ULP of a change in the queue status. 177 * I.e. a limit may be exceeded, and therefore subsequent send-primitives will 178 * fail, OR the queue length has dropped below a previously set queue length 179 * 180 * @param queueType i.e. an outbound queue, stream-engine queue, per stream queue (?) 181 * @param queueId i.e. i.e. stream id for a per stream queue 182 * @param queueLen in bytes or in messages, depending on the queue type 183 */ 184 void mdi_queueStatusChangeNotif(int queueType, int queueId, int queueLen); 185 186 187 int mdi_updateMyAddressList(void); 188 189 190 /*------------------- Functions called by the SCTP to get current association data----------------*/ 191 192 /* When processing external events from outside the SCTP (socket events, timer events and 193 function calls from the ULP), first the data of the addressed association are read 194 from the list of associations and stored in a private but static datastructure. 195 Elements of this association data can be read by the following functions. 196 */ 197 198 199 /* The following functions return pointer to data of modules of the SCTP. As only these 200 modules know the exact type of these data structures, so the returned pointer are 201 of type void. 202 */ 203 204 205 /* The following functions return pointer to data of modules of the SCTP. As only these 206 modules know the exact type of these data structures, so the returned pointer are 207 of type void. 208 */ 209 210 /* 211 * returns: pointer to the flow control data structure. 212 * null in case of error. 213 */ 214 void *mdi_readFlowControl(void); 215 216 217 218 /* 219 * returns: pointer to the reliable transfer data structure. 220 * null in case of error. 221 */ 222 void *mdi_readReliableTransfer(void); 223 224 225 226 /* 227 * returns: pointer to the RX-control data structure. 228 * null in case of error. 229 */ 230 void *mdi_readRX_control(void); 231 232 233 234 /* 235 * returns: pointer to the stream engine data structure. 236 * null in case of error. 237 */ 238 void *mdi_readStreamEngine(void); 239 240 241 242 /* 243 * returns: pointer to the pathmanagement data structure. 244 * null in case of error. 245 */ 246 void *mdi_readPathMan(void); 247 248 249 250 /* 251 * returns: pointer to the bundling data structure. 252 * null in case of error. 253 */ 254 void *mdi_readBundling(void); 255 256 257 258 /* 259 * returns: pointer to the SCTP-control data structure. 260 * null in case of error. 261 */ 262 void *mdi_readSCTP_control(void); 263 264 265 266 /* 267 * returns: association-ID of the curent association 268 * 0 means the association is not set (an error). 269 */ 270 unsigned int mdi_readAssociationID(void); 271 272 273 274 /* returns: a ID for new association */ 275 unsigned int mdi_generateTag(void); 276 277 278 279 unsigned int mdi_readTagRemote(void); 280 unsigned int mdi_readLocalTag(void); 281 282 283 284 /* returns: a the start TSN for new association */ 285 unsigned int mdi_generateStartTSN(void); 286 287 288 289 /*------------- functions to for the cookie mechanism --------------------------------------------*/ 290 /* each time a datagram is received, its source address, source port and destination port 291 is saved. This address-info is used in the following cases: 292 - z-side: for sending the initAck (no association exists from which the addresses could be read). 293 - a-side: if the initAck ?? 294 - z-side: if the cookie-chunk does not contain addresses of the a-side, lastFromAddress_in 295 is used as the only destination address. 296 */ 297 298 gboolean mdi_addressListContainsLocalhost(unsigned int noOfAddresses, 299 union sockunion* addressList); 300 301 302 /* sets the address from which the last datagramm was received (host byte order). 303 Returns 0 if successful, 1 if address could not be set ! 304 */ 305 int mdi_readLastFromAddress(union sockunion* fromAddress); 306 307 308 /* reads the path from which the last DG was received. -1 is returned if no DG was received. 309 */ 310 short mdi_readLastFromPath(void); 311 312 313 /* returns the port of the sender of the last received DG. 314 */ 315 unsigned short mdi_readLastFromPort(void); 316 317 318 /* returns the port of the destination of the last received DG. 319 */ 320 unsigned short mdi_readLastDestPort(void); 321 322 323 unsigned int mdi_readLastInitiateTag(void); 324 /* write the initiate tag of a-side to be used as verification tag for the initAck */ 325 void mdi_writeLastInitiateTag(unsigned int initiateTag); 326 327 328 /* rewrite the initiate tag of peer in case of a peer restart. */ 329 void mdi_rewriteTagRemote(unsigned int newInitiateTag); 330 331 /* rewrite my local tag in case of a restart. */ 332 void mdi_rewriteLocalTag(unsigned int newTag); 333 334 /** 335 * Function that returns the number of incoming streams that this instance 336 * is willing to handle ! 337 * @return maximum number of in-streams 338 */ 339 unsigned short mdi_readLocalInStreams(void); 340 341 /** 342 * Function that returns the number of outgoing streams that this instance 343 * is willing to handle ! 344 * @return maximum number of out-streams 345 */ 346 unsigned short mdi_readLocalOutStreams(void); 347 348 int mdi_getDefaultRtoInitial(void* sctpInstance); 349 int mdi_getDefaultValidCookieLife(void* sctpInstance); 350 int mdi_getDefaultAssocMaxRetransmits(void* sctpInstance); 351 int mdi_getDefaultPathMaxRetransmits(void* sctpInstance); 352 int mdi_getDefaultRtoMin(void* sctpInstance); 353 int mdi_getDefaultRtoMax(void* sctpInstance); 354 int mdi_getDefaultMaxInitRetransmits(void* sctpInstance); 355 int mdi_getDefaultMyRwnd(void); 356 int mdi_getDefaultDelay(void* sctpInstance); 357 int mdi_getDefaultIpTos(void* sctpInstance); 358 int mdi_getDefaultMaxSendQueue(void* sctpInstance); 359 int mdi_getDefaultMaxRecvQueue(void* sctpInstance); 360 int mdi_getDefaultMaxBurst(void); 361 362 unsigned int mdi_getSupportedAddressTypes(void); 363 364 gboolean mdi_supportsPRSCTP(void); 365 gboolean mdi_peerSupportsPRSCTP(void); 366 /*------------- functions to write and read addresses --------------------------------------------*/ 367 368 void mdi_writeDestinationAddresses(union sockunion addresses[MAX_NUM_ADDRESSES], int noOfAddresses); 369 370 void mdi_readLocalAddresses(union sockunion laddresses[MAX_NUM_ADDRESSES], 371 guint16 * noOfAddresses, 372 union sockunion *peerAddress, 373 unsigned int numPeerAddresses, 374 unsigned int addressTypes, 375 gboolean receivedFromPeer); 376 377 short mdi_getIndexForAddress(union sockunion* address); 378 379 /*------------- functions to set and clear the association data ----------------------------------*/ 380 381 /* Each module within SCTP that has timers implements its own timer call back 382 functions. These are registered at the adaption layer when a timer is started 383 and called directly at the module when the timer expires. 384 setAssociation allows SCTP-modules with timers to retrieve the data of the 385 addressed association from the list of associations. 386 For this purpose the association-ID must be included in one of the 387 parameters of the start_timer function of the adaption-layer. 388 Params: associationID: the ID of the association 389 returns: 0 if successfull 390 1 if the association does not exist in the list. 391 */ 392 unsigned short mdi_setAssociationData(unsigned int associationID); 393 394 395 396 /* Clear the global association data. 397 This function must be called after the association retrieved from the list 398 with setAssociationData is no longer needed. This is the case after a timer 399 event has been handled. 400 returns: 0 if successful. 401 1 if association data have not been set. 402 */ 403 unsigned short mdi_clearAssociationData(void); 404 405 406 /*------------------- Functions to create and delete associations --------------------------------*/ 407 408 /* This function allocates memory for a new association. 409 For the active side of an association, this function is called when the associate is called from 410 the ULP. 411 For the passive side this function is called when a cookie message is received. 412 It also creates all the modules of an association supplying to them the data needed as far they 413 they are determined at time the this module is called. 414 415 If successfull, the global variable current_association points to the association structure 416 created. 417 */ 418 unsigned short mdi_newAssociation(void* sInstance, 419 unsigned short local_port, 420 unsigned short remote_port, 421 unsigned int tagLocal, 422 short primaryDestinitionAddress, 423 short noOfDestinationAddresses, 424 union sockunion *destinationAddressList); 425 426 427 428 /* An association is created in two steps because data become available in two steps: 429 1. associate 430 2. init acknowledgement 431 after calling this function, the initialisation is completed. 432 */ 433 unsigned short 434 mdi_initAssociation(unsigned int remoteSideReceiverWindow, 435 unsigned short noOfInStreams, 436 unsigned short noOfOutStreams, 437 unsigned int remoteInitialTSN, 438 unsigned int tagRemote, unsigned int localInitialTSN, 439 gboolean assocSupportsPRSCTP, gboolean assocSupportsADDIP); 440 441 442 unsigned short 443 mdi_restartAssociation(unsigned short noOfInStreams, 444 unsigned short noOfOutStreams, 445 unsigned int new_rwnd, 446 unsigned int remoteInitialTSN, 447 unsigned int localInitialTSN, 448 short noOfPaths, 449 short primaryAddress, 450 union sockunion *destinationAddressList, 451 gboolean assocSupportsPRSCTP, gboolean assocSupportsADDIP); 452 453 454 455 void mdi_deleteCurrentAssociation(void); 456 457 458 459 #endif 460