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