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