1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * a) Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * b) Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the distribution. 17 * 18 * c) Neither the name of Cisco Systems, Inc. nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef _NETINET_SCTP_HEADER_H_ 36 #define _NETINET_SCTP_HEADER_H_ 37 38 #include <sys/time.h> 39 #include <netinet/sctp.h> 40 #include <netinet/sctp_constants.h> 41 42 #define SCTP_PACKED __attribute__((packed)) 43 44 /* 45 * Parameter structures 46 */ 47 struct sctp_ipv4addr_param { 48 struct sctp_paramhdr ph; /* type=SCTP_IPV4_PARAM_TYPE, len=8 */ 49 uint32_t addr; /* IPV4 address */ 50 } SCTP_PACKED; 51 52 #define SCTP_V6_ADDR_BYTES 16 53 54 struct sctp_ipv6addr_param { 55 struct sctp_paramhdr ph; /* type=SCTP_IPV6_PARAM_TYPE, len=20 */ 56 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */ 57 } SCTP_PACKED; 58 59 /* Cookie Preservative */ 60 struct sctp_cookie_perserve_param { 61 struct sctp_paramhdr ph; /* type=SCTP_COOKIE_PRESERVE, len=8 */ 62 uint32_t time; /* time in ms to extend cookie */ 63 } SCTP_PACKED; 64 65 #define SCTP_ARRAY_MIN_LEN 1 66 /* Host Name Address */ 67 struct sctp_host_name_param { 68 struct sctp_paramhdr ph; /* type=SCTP_HOSTNAME_ADDRESS */ 69 char name[SCTP_ARRAY_MIN_LEN]; /* host name */ 70 } SCTP_PACKED; 71 72 /* 73 * This is the maximum padded size of a s-a-p 74 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12 75 */ 76 #define SCTP_MAX_ADDR_PARAMS_SIZE 12 77 /* supported address type */ 78 struct sctp_supported_addr_param { 79 struct sctp_paramhdr ph; /* type=SCTP_SUPPORTED_ADDRTYPE */ 80 uint16_t addr_type[2]; /* array of supported address types */ 81 } SCTP_PACKED; 82 83 /* heartbeat info parameter */ 84 struct sctp_heartbeat_info_param { 85 struct sctp_paramhdr ph; 86 uint32_t time_value_1; 87 uint32_t time_value_2; 88 uint32_t random_value1; 89 uint32_t random_value2; 90 uint8_t addr_family; 91 uint8_t addr_len; 92 /* make sure that this structure is 4 byte aligned */ 93 uint8_t padding[2]; 94 char address[SCTP_ADDRMAX]; 95 } SCTP_PACKED; 96 97 /* draft-ietf-tsvwg-prsctp */ 98 /* PR-SCTP supported parameter */ 99 struct sctp_prsctp_supported_param { 100 struct sctp_paramhdr ph; 101 } SCTP_PACKED; 102 103 /* draft-ietf-tsvwg-addip-sctp */ 104 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */ 105 struct sctp_paramhdr ph; /* a SCTP parameter header */ 106 uint32_t correlation_id; /* correlation id for this param */ 107 } SCTP_PACKED; 108 109 struct sctp_asconf_addr_param { /* an ASCONF address parameter */ 110 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */ 111 struct sctp_ipv6addr_param addrp; /* max storage size */ 112 } SCTP_PACKED; 113 114 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */ 115 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */ 116 uint32_t local_vtag; 117 uint32_t remote_vtag; 118 } SCTP_PACKED; 119 120 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */ 121 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */ 122 struct sctp_ipv4addr_param addrp; /* max storage size */ 123 } SCTP_PACKED; 124 125 #define SCTP_MAX_SUPPORTED_EXT 256 126 127 struct sctp_supported_chunk_types_param { 128 struct sctp_paramhdr ph; /* type = 0x8008 len = x */ 129 uint8_t chunk_types[]; 130 } SCTP_PACKED; 131 132 /* 133 * Structures for DATA chunks 134 */ 135 struct sctp_data { 136 uint32_t tsn; 137 uint16_t sid; 138 uint16_t ssn; 139 uint32_t ppid; 140 /* user data follows */ 141 } SCTP_PACKED; 142 143 struct sctp_data_chunk { 144 struct sctp_chunkhdr ch; 145 struct sctp_data dp; 146 } SCTP_PACKED; 147 148 struct sctp_idata { 149 uint32_t tsn; 150 uint16_t sid; 151 uint16_t reserved; /* Where does the SSN go? */ 152 uint32_t mid; 153 union { 154 uint32_t ppid; 155 uint32_t fsn; /* Fragment Sequence Number */ 156 } ppid_fsn; 157 /* user data follows */ 158 } SCTP_PACKED; 159 160 struct sctp_idata_chunk { 161 struct sctp_chunkhdr ch; 162 struct sctp_idata dp; 163 } SCTP_PACKED; 164 165 /* 166 * Structures for the control chunks 167 */ 168 169 /* Initiate (INIT)/Initiate Ack (INIT ACK) */ 170 struct sctp_init { 171 uint32_t initiate_tag; /* initiate tag */ 172 uint32_t a_rwnd; /* a_rwnd */ 173 uint16_t num_outbound_streams; /* OS */ 174 uint16_t num_inbound_streams; /* MIS */ 175 uint32_t initial_tsn; /* I-TSN */ 176 /* optional param's follow */ 177 } SCTP_PACKED; 178 #define SCTP_IDENTIFICATION_SIZE 16 179 #define SCTP_ADDRESS_SIZE 4 180 #define SCTP_RESERVE_SPACE 5 181 /* state cookie header */ 182 struct sctp_state_cookie { /* this is our definition... */ 183 uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */ 184 struct timeval time_entered; /* the time I built cookie */ 185 uint32_t cookie_life; /* life I will award this cookie */ 186 uint32_t tie_tag_my_vtag; /* my tag in old association */ 187 188 uint32_t tie_tag_peer_vtag; /* peers tag in old association */ 189 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */ 190 191 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */ 192 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */ 193 uint32_t addr_type; /* address type */ 194 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */ 195 uint32_t laddr_type; /* my local from address type */ 196 uint32_t scope_id; /* v6 scope id for link-locals */ 197 198 uint16_t peerport; /* port address of the peer in the INIT */ 199 uint16_t myport; /* my port address used in the INIT */ 200 uint8_t ipv4_addr_legal; /* Are V4 addr legal? */ 201 uint8_t ipv6_addr_legal; /* Are V6 addr legal? */ 202 uint8_t local_scope; /* IPv6 local scope flag */ 203 uint8_t site_scope; /* IPv6 site scope flag */ 204 205 uint8_t ipv4_scope; /* IPv4 private addr scope */ 206 uint8_t loopback_scope; /* loopback scope information */ 207 uint8_t rcv_edmid; /* copy of the inp value */ 208 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */ 209 /* 210 * at the end is tacked on the INIT chunk and the INIT-ACK chunk 211 * (minus the cookie). 212 */ 213 } SCTP_PACKED; 214 215 /* state cookie parameter */ 216 struct sctp_state_cookie_param { 217 struct sctp_paramhdr ph; 218 struct sctp_state_cookie cookie; 219 } SCTP_PACKED; 220 221 struct sctp_init_chunk { 222 struct sctp_chunkhdr ch; 223 struct sctp_init init; 224 } SCTP_PACKED; 225 226 struct sctp_init_msg { 227 struct sctphdr sh; 228 struct sctp_init_chunk msg; 229 } SCTP_PACKED; 230 231 /* ... used for both INIT and INIT ACK */ 232 #define sctp_init_ack sctp_init 233 #define sctp_init_ack_chunk sctp_init_chunk 234 #define sctp_init_ack_msg sctp_init_msg 235 236 /* Selective Ack (SACK) */ 237 struct sctp_gap_ack_block { 238 uint16_t start; /* Gap Ack block start */ 239 uint16_t end; /* Gap Ack block end */ 240 } SCTP_PACKED; 241 242 struct sctp_sack { 243 uint32_t cum_tsn_ack; /* cumulative TSN Ack */ 244 uint32_t a_rwnd; /* updated a_rwnd of sender */ 245 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */ 246 uint16_t num_dup_tsns; /* number of duplicate TSNs */ 247 /* struct sctp_gap_ack_block's follow */ 248 /* uint32_t duplicate_tsn's follow */ 249 } SCTP_PACKED; 250 251 struct sctp_sack_chunk { 252 struct sctp_chunkhdr ch; 253 struct sctp_sack sack; 254 } SCTP_PACKED; 255 256 struct sctp_nr_sack { 257 uint32_t cum_tsn_ack; /* cumulative TSN Ack */ 258 uint32_t a_rwnd; /* updated a_rwnd of sender */ 259 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */ 260 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */ 261 uint16_t num_dup_tsns; /* number of duplicate TSNs */ 262 uint16_t reserved; /* not currently used */ 263 /* struct sctp_gap_ack_block's follow */ 264 /* uint32_t duplicate_tsn's follow */ 265 } SCTP_PACKED; 266 267 struct sctp_nr_sack_chunk { 268 struct sctp_chunkhdr ch; 269 struct sctp_nr_sack nr_sack; 270 } SCTP_PACKED; 271 272 /* Heartbeat Request (HEARTBEAT) */ 273 struct sctp_heartbeat { 274 struct sctp_heartbeat_info_param hb_info; 275 } SCTP_PACKED; 276 277 struct sctp_heartbeat_chunk { 278 struct sctp_chunkhdr ch; 279 struct sctp_heartbeat heartbeat; 280 } SCTP_PACKED; 281 282 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */ 283 #define sctp_heartbeat_ack sctp_heartbeat 284 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk 285 286 /* Abort Asssociation (ABORT) */ 287 struct sctp_abort_chunk { 288 struct sctp_chunkhdr ch; 289 /* optional error cause may follow */ 290 } SCTP_PACKED; 291 292 struct sctp_abort_msg { 293 struct sctphdr sh; 294 struct sctp_abort_chunk msg; 295 } SCTP_PACKED; 296 297 /* Shutdown Association (SHUTDOWN) */ 298 struct sctp_shutdown_chunk { 299 struct sctp_chunkhdr ch; 300 uint32_t cumulative_tsn_ack; 301 } SCTP_PACKED; 302 303 /* Shutdown Acknowledgment (SHUTDOWN ACK) */ 304 struct sctp_shutdown_ack_chunk { 305 struct sctp_chunkhdr ch; 306 } SCTP_PACKED; 307 308 /* Operation Error (ERROR) */ 309 struct sctp_error_chunk { 310 struct sctp_chunkhdr ch; 311 /* optional error causes follow */ 312 } SCTP_PACKED; 313 314 /* Cookie Echo (COOKIE ECHO) */ 315 struct sctp_cookie_echo_chunk { 316 struct sctp_chunkhdr ch; 317 struct sctp_state_cookie cookie; 318 } SCTP_PACKED; 319 320 /* Cookie Acknowledgment (COOKIE ACK) */ 321 struct sctp_cookie_ack_chunk { 322 struct sctp_chunkhdr ch; 323 } SCTP_PACKED; 324 325 /* Explicit Congestion Notification Echo (ECNE) */ 326 struct old_sctp_ecne_chunk { 327 struct sctp_chunkhdr ch; 328 uint32_t tsn; 329 } SCTP_PACKED; 330 331 struct sctp_ecne_chunk { 332 struct sctp_chunkhdr ch; 333 uint32_t tsn; 334 uint32_t num_pkts_since_cwr; 335 } SCTP_PACKED; 336 337 /* Congestion Window Reduced (CWR) */ 338 struct sctp_cwr_chunk { 339 struct sctp_chunkhdr ch; 340 uint32_t tsn; 341 } SCTP_PACKED; 342 343 /* Shutdown Complete (SHUTDOWN COMPLETE) */ 344 struct sctp_shutdown_complete_chunk { 345 struct sctp_chunkhdr ch; 346 } SCTP_PACKED; 347 348 struct sctp_adaptation_layer_indication { 349 struct sctp_paramhdr ph; 350 uint32_t indication; 351 } SCTP_PACKED; 352 353 /* 354 * draft-ietf-tsvwg-addip-sctp 355 */ 356 /* Address/Stream Configuration Change (ASCONF) */ 357 struct sctp_asconf_chunk { 358 struct sctp_chunkhdr ch; 359 uint32_t serial_number; 360 /* lookup address parameter (mandatory) */ 361 /* asconf parameters follow */ 362 } SCTP_PACKED; 363 364 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */ 365 struct sctp_asconf_ack_chunk { 366 struct sctp_chunkhdr ch; 367 uint32_t serial_number; 368 /* asconf parameters follow */ 369 } SCTP_PACKED; 370 371 /* draft-ietf-tsvwg-prsctp */ 372 /* Forward Cumulative TSN (FORWARD TSN) */ 373 struct sctp_forward_tsn_chunk { 374 struct sctp_chunkhdr ch; 375 uint32_t new_cumulative_tsn; 376 /* stream/sequence pairs (sctp_strseq) follow */ 377 } SCTP_PACKED; 378 379 struct sctp_strseq { 380 uint16_t sid; 381 uint16_t ssn; 382 } SCTP_PACKED; 383 384 struct sctp_strseq_mid { 385 uint16_t sid; 386 uint16_t flags; 387 uint32_t mid; 388 }; 389 390 struct sctp_forward_tsn_msg { 391 struct sctphdr sh; 392 struct sctp_forward_tsn_chunk msg; 393 } SCTP_PACKED; 394 395 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */ 396 397 #define SCTP_NUM_DB_TO_VERIFY 31 398 399 struct sctp_chunk_desc { 400 uint8_t chunk_type; 401 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY]; 402 uint32_t tsn_ifany; 403 } SCTP_PACKED; 404 405 struct sctp_pktdrop_chunk { 406 struct sctp_chunkhdr ch; 407 uint32_t bottle_bw; 408 uint32_t current_onq; 409 uint16_t trunc_len; 410 uint16_t reserved; 411 uint8_t data[]; 412 } SCTP_PACKED; 413 414 /**********STREAM RESET STUFF ******************/ 415 416 struct sctp_stream_reset_request { 417 struct sctp_paramhdr ph; 418 uint32_t request_seq; 419 } SCTP_PACKED; 420 421 struct sctp_stream_reset_out_request { 422 struct sctp_paramhdr ph; 423 uint32_t request_seq; /* monotonically increasing seq no */ 424 uint32_t response_seq; /* if a response, the resp seq no */ 425 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */ 426 uint16_t list_of_streams[]; /* if not all list of streams */ 427 } SCTP_PACKED; 428 429 struct sctp_stream_reset_in_request { 430 struct sctp_paramhdr ph; 431 uint32_t request_seq; 432 uint16_t list_of_streams[]; /* if not all list of streams */ 433 } SCTP_PACKED; 434 435 struct sctp_stream_reset_tsn_request { 436 struct sctp_paramhdr ph; 437 uint32_t request_seq; 438 } SCTP_PACKED; 439 440 struct sctp_stream_reset_response { 441 struct sctp_paramhdr ph; 442 uint32_t response_seq; /* if a response, the resp seq no */ 443 uint32_t result; 444 } SCTP_PACKED; 445 446 struct sctp_stream_reset_response_tsn { 447 struct sctp_paramhdr ph; 448 uint32_t response_seq; /* if a response, the resp seq no */ 449 uint32_t result; 450 uint32_t senders_next_tsn; 451 uint32_t receivers_next_tsn; 452 } SCTP_PACKED; 453 454 struct sctp_stream_reset_add_strm { 455 struct sctp_paramhdr ph; 456 uint32_t request_seq; 457 uint16_t number_of_streams; 458 uint16_t reserved; 459 } SCTP_PACKED; 460 461 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */ 462 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001 463 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002 464 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */ 465 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004 466 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005 467 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */ 468 469 /* 470 * convience structures, note that if you are making a request for specific 471 * streams then the request will need to be an overlay structure. 472 */ 473 474 struct sctp_stream_reset_tsn_req { 475 struct sctp_chunkhdr ch; 476 struct sctp_stream_reset_tsn_request sr_req; 477 } SCTP_PACKED; 478 479 struct sctp_stream_reset_resp { 480 struct sctp_chunkhdr ch; 481 struct sctp_stream_reset_response sr_resp; 482 } SCTP_PACKED; 483 484 /* respone only valid with a TSN request */ 485 struct sctp_stream_reset_resp_tsn { 486 struct sctp_chunkhdr ch; 487 struct sctp_stream_reset_response_tsn sr_resp; 488 } SCTP_PACKED; 489 490 /****************************************************/ 491 492 /* 493 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth 494 */ 495 496 /* Should we make the max be 32? */ 497 #define SCTP_RANDOM_MAX_SIZE 256 498 struct sctp_auth_random { 499 struct sctp_paramhdr ph; /* type = 0x8002 */ 500 uint8_t random_data[]; 501 } SCTP_PACKED; 502 503 struct sctp_auth_chunk_list { 504 struct sctp_paramhdr ph; /* type = 0x8003 */ 505 uint8_t chunk_types[]; 506 } SCTP_PACKED; 507 508 struct sctp_auth_hmac_algo { 509 struct sctp_paramhdr ph; /* type = 0x8004 */ 510 uint16_t hmac_ids[]; 511 } SCTP_PACKED; 512 513 struct sctp_auth_chunk { 514 struct sctp_chunkhdr ch; 515 uint16_t shared_key_id; 516 uint16_t hmac_id; 517 uint8_t hmac[]; 518 } SCTP_PACKED; 519 520 /* Zero checksum support draft-ietf-tsvwg-sctp-zero-checksum */ 521 522 struct sctp_zero_checksum_acceptable { 523 struct sctp_paramhdr ph; 524 uint32_t edmid; 525 } SCTP_PACKED; 526 527 /* 528 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing 529 * pieces. If ENCE is missing we could have a couple of blocks. This way we 530 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size 531 * data chunk I will split into. We could increase throughput slightly by 532 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I 533 * feel is worth it for now. 534 */ 535 #ifndef SCTP_MAX_OVERHEAD 536 #ifdef INET6 537 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \ 538 sizeof(struct sctphdr) + \ 539 sizeof(struct sctp_ecne_chunk) + \ 540 sizeof(struct sctp_sack_chunk) + \ 541 sizeof(struct ip6_hdr)) 542 543 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \ 544 sizeof(struct sctphdr) + \ 545 sizeof(struct ip6_hdr)) 546 547 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \ 548 sizeof(struct sctphdr)) 549 550 #else 551 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \ 552 sizeof(struct sctphdr) + \ 553 sizeof(struct sctp_ecne_chunk) + \ 554 sizeof(struct sctp_sack_chunk) + \ 555 sizeof(struct ip)) 556 557 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \ 558 sizeof(struct sctphdr) + \ 559 sizeof(struct ip)) 560 561 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \ 562 sizeof(struct sctphdr)) 563 564 #endif /* INET6 */ 565 #endif /* !SCTP_MAX_OVERHEAD */ 566 567 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \ 568 sizeof(struct sctphdr) + \ 569 sizeof(struct ip)) 570 571 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \ 572 sizeof(struct sctphdr)) 573 574 #undef SCTP_PACKED 575 #endif /* !__sctp_header_h__ */ 576