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