2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 273168 2014-10-16 15:36:04Z tuexen $");
38 #ifndef _NETINET_SCTP_HEADER_H_
39 #define _NETINET_SCTP_HEADER_H_
41 #if defined(__Windows__) && !defined(__Userspace_os_Windows)
44 #if !defined(__Userspace_os_Windows)
47 #include <netinet/sctp.h>
48 #include <netinet/sctp_constants.h>
50 #if !defined(__Userspace_os_Windows)
51 #define SCTP_PACKED __attribute__((packed))
53 #pragma pack (push, 1)
58 * Parameter structures
60 struct sctp_ipv4addr_param {
61 struct sctp_paramhdr ph;/* type=SCTP_IPV4_PARAM_TYPE, len=8 */
62 uint32_t addr; /* IPV4 address */
65 #define SCTP_V6_ADDR_BYTES 16
68 struct sctp_ipv6addr_param {
69 struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
70 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
73 /* Cookie Preservative */
74 struct sctp_cookie_perserve_param {
75 struct sctp_paramhdr ph;/* type=SCTP_COOKIE_PRESERVE, len=8 */
76 uint32_t time; /* time in ms to extend cookie */
79 #define SCTP_ARRAY_MIN_LEN 1
80 /* Host Name Address */
81 struct sctp_host_name_param {
82 struct sctp_paramhdr ph;/* type=SCTP_HOSTNAME_ADDRESS */
83 char name[SCTP_ARRAY_MIN_LEN]; /* host name */
87 * This is the maximum padded size of a s-a-p
88 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
90 #define SCTP_MAX_ADDR_PARAMS_SIZE 12
91 /* supported address type */
92 struct sctp_supported_addr_param {
93 struct sctp_paramhdr ph;/* type=SCTP_SUPPORTED_ADDRTYPE */
94 uint16_t addr_type[2]; /* array of supported address types */
97 /* heartbeat info parameter */
98 struct sctp_heartbeat_info_param {
99 struct sctp_paramhdr ph;
100 uint32_t time_value_1;
101 uint32_t time_value_2;
102 uint32_t random_value1;
103 uint32_t random_value2;
106 /* make sure that this structure is 4 byte aligned */
108 char address[SCTP_ADDRMAX];
112 /* draft-ietf-tsvwg-prsctp */
113 /* PR-SCTP supported parameter */
114 struct sctp_prsctp_supported_param {
115 struct sctp_paramhdr ph;
119 /* draft-ietf-tsvwg-addip-sctp */
120 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
121 struct sctp_paramhdr ph;/* a SCTP parameter header */
122 uint32_t correlation_id;/* correlation id for this param */
125 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
126 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
127 struct sctp_ipv6addr_param addrp; /* max storage size */
131 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
132 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
134 uint32_t remote_vtag;
138 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
139 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
140 struct sctp_ipv4addr_param addrp; /* max storage size */
143 #define SCTP_MAX_SUPPORTED_EXT 256
145 struct sctp_supported_chunk_types_param {
146 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
147 uint8_t chunk_types[];
152 * Structures for DATA chunks
157 uint16_t stream_sequence;
158 uint32_t protocol_id;
159 /* user data follows */
162 struct sctp_data_chunk {
163 struct sctp_chunkhdr ch;
168 * Structures for the control chunks
171 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
173 uint32_t initiate_tag; /* initiate tag */
174 uint32_t a_rwnd; /* a_rwnd */
175 uint16_t num_outbound_streams; /* OS */
176 uint16_t num_inbound_streams; /* MIS */
177 uint32_t initial_tsn; /* I-TSN */
178 /* optional param's follow */
180 #define SCTP_IDENTIFICATION_SIZE 16
181 #define SCTP_ADDRESS_SIZE 4
182 #if defined(__Userspace__)
183 #define SCTP_RESERVE_SPACE 5
185 #define SCTP_RESERVE_SPACE 6
187 /* state cookie header */
188 struct sctp_state_cookie { /* this is our definition... */
189 uint8_t identification[SCTP_IDENTIFICATION_SIZE];/* id of who we are */
190 struct timeval time_entered; /* the time I built cookie */
191 uint32_t cookie_life; /* life I will award this cookie */
192 uint32_t tie_tag_my_vtag; /* my tag in old association */
194 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
195 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
197 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
198 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
199 uint32_t addr_type; /* address type */
200 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
201 uint32_t laddr_type; /* my local from address type */
202 uint32_t scope_id; /* v6 scope id for link-locals */
204 uint16_t peerport; /* port address of the peer in the INIT */
205 uint16_t myport; /* my port address used in the INIT */
206 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
207 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
208 #if defined(__Userspace__)
209 uint8_t conn_addr_legal;
211 uint8_t local_scope; /* IPv6 local scope flag */
212 uint8_t site_scope; /* IPv6 site scope flag */
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 */
218 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
219 * (minus the cookie).
224 /* Used for NAT state error cause */
225 struct sctp_missing_nat_state {
232 struct sctp_inv_mandatory_param {
238 * We include this to 0 it since only a missing cookie will cause
244 struct sctp_unresolv_addr {
248 uint16_t reserved; /* Only one invalid addr type */
251 /* state cookie parameter */
252 struct sctp_state_cookie_param {
253 struct sctp_paramhdr ph;
254 struct sctp_state_cookie cookie;
257 struct sctp_init_chunk {
258 struct sctp_chunkhdr ch;
259 struct sctp_init init;
262 struct sctp_init_msg {
264 struct sctp_init_chunk msg;
267 /* ... used for both INIT and INIT ACK */
268 #define sctp_init_ack sctp_init
269 #define sctp_init_ack_chunk sctp_init_chunk
270 #define sctp_init_ack_msg sctp_init_msg
273 /* Selective Ack (SACK) */
274 struct sctp_gap_ack_block {
275 uint16_t start; /* Gap Ack block start */
276 uint16_t end; /* Gap Ack block end */
280 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
281 uint32_t a_rwnd; /* updated a_rwnd of sender */
282 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
283 uint16_t num_dup_tsns; /* number of duplicate TSNs */
284 /* struct sctp_gap_ack_block's follow */
285 /* uint32_t duplicate_tsn's follow */
288 struct sctp_sack_chunk {
289 struct sctp_chunkhdr ch;
290 struct sctp_sack sack;
293 struct sctp_nr_sack {
294 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
295 uint32_t a_rwnd; /* updated a_rwnd of sender */
296 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
297 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
298 uint16_t num_dup_tsns; /* number of duplicate TSNs */
299 uint16_t reserved; /* not currently used*/
300 /* struct sctp_gap_ack_block's follow */
301 /* uint32_t duplicate_tsn's follow */
304 struct sctp_nr_sack_chunk {
305 struct sctp_chunkhdr ch;
306 struct sctp_nr_sack nr_sack;
310 /* Heartbeat Request (HEARTBEAT) */
311 struct sctp_heartbeat {
312 struct sctp_heartbeat_info_param hb_info;
315 struct sctp_heartbeat_chunk {
316 struct sctp_chunkhdr ch;
317 struct sctp_heartbeat heartbeat;
320 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
321 #define sctp_heartbeat_ack sctp_heartbeat
322 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
325 /* Abort Asssociation (ABORT) */
326 struct sctp_abort_chunk {
327 struct sctp_chunkhdr ch;
328 /* optional error cause may follow */
331 struct sctp_abort_msg {
333 struct sctp_abort_chunk msg;
337 /* Shutdown Association (SHUTDOWN) */
338 struct sctp_shutdown_chunk {
339 struct sctp_chunkhdr ch;
340 uint32_t cumulative_tsn_ack;
344 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
345 struct sctp_shutdown_ack_chunk {
346 struct sctp_chunkhdr ch;
350 /* Operation Error (ERROR) */
351 struct sctp_error_chunk {
352 struct sctp_chunkhdr ch;
353 /* optional error causes follow */
357 /* Cookie Echo (COOKIE ECHO) */
358 struct sctp_cookie_echo_chunk {
359 struct sctp_chunkhdr ch;
360 struct sctp_state_cookie cookie;
363 /* Cookie Acknowledgment (COOKIE ACK) */
364 struct sctp_cookie_ack_chunk {
365 struct sctp_chunkhdr ch;
368 /* Explicit Congestion Notification Echo (ECNE) */
369 struct old_sctp_ecne_chunk {
370 struct sctp_chunkhdr ch;
374 struct sctp_ecne_chunk {
375 struct sctp_chunkhdr ch;
377 uint32_t num_pkts_since_cwr;
380 /* Congestion Window Reduced (CWR) */
381 struct sctp_cwr_chunk {
382 struct sctp_chunkhdr ch;
386 /* Shutdown Complete (SHUTDOWN COMPLETE) */
387 struct sctp_shutdown_complete_chunk {
388 struct sctp_chunkhdr ch;
391 /* Oper error holding a stale cookie */
392 struct sctp_stale_cookie_msg {
393 struct sctp_paramhdr ph;/* really an error cause */
397 struct sctp_adaptation_layer_indication {
398 struct sctp_paramhdr ph;
402 struct sctp_cookie_while_shutting_down {
404 struct sctp_chunkhdr ch;
405 struct sctp_paramhdr ph;/* really an error cause */
408 struct sctp_shutdown_complete_msg {
410 struct sctp_shutdown_complete_chunk shut_cmp;
414 * draft-ietf-tsvwg-addip-sctp
416 /* Address/Stream Configuration Change (ASCONF) */
417 struct sctp_asconf_chunk {
418 struct sctp_chunkhdr ch;
419 uint32_t serial_number;
420 /* lookup address parameter (mandatory) */
421 /* asconf parameters follow */
424 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */
425 struct sctp_asconf_ack_chunk {
426 struct sctp_chunkhdr ch;
427 uint32_t serial_number;
428 /* asconf parameters follow */
431 /* draft-ietf-tsvwg-prsctp */
432 /* Forward Cumulative TSN (FORWARD TSN) */
433 struct sctp_forward_tsn_chunk {
434 struct sctp_chunkhdr ch;
435 uint32_t new_cumulative_tsn;
436 /* stream/sequence pairs (sctp_strseq) follow */
444 struct sctp_forward_tsn_msg {
446 struct sctp_forward_tsn_chunk msg;
449 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
451 #define SCTP_NUM_DB_TO_VERIFY 31
453 struct sctp_chunk_desc {
455 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
460 struct sctp_pktdrop_chunk {
461 struct sctp_chunkhdr ch;
463 uint32_t current_onq;
469 /**********STREAM RESET STUFF ******************/
471 struct sctp_stream_reset_request {
472 struct sctp_paramhdr ph;
473 uint32_t request_seq;
476 struct sctp_stream_reset_out_request {
477 struct sctp_paramhdr ph;
478 uint32_t request_seq; /* monotonically increasing seq no */
479 uint32_t response_seq; /* if a response, the resp seq no */
480 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
481 uint16_t list_of_streams[]; /* if not all list of streams */
484 struct sctp_stream_reset_in_request {
485 struct sctp_paramhdr ph;
486 uint32_t request_seq;
487 uint16_t list_of_streams[]; /* if not all list of streams */
490 struct sctp_stream_reset_tsn_request {
491 struct sctp_paramhdr ph;
492 uint32_t request_seq;
495 struct sctp_stream_reset_response {
496 struct sctp_paramhdr ph;
497 uint32_t response_seq; /* if a response, the resp seq no */
501 struct sctp_stream_reset_response_tsn {
502 struct sctp_paramhdr ph;
503 uint32_t response_seq; /* if a response, the resp seq no */
505 uint32_t senders_next_tsn;
506 uint32_t receivers_next_tsn;
509 struct sctp_stream_reset_add_strm {
510 struct sctp_paramhdr ph;
511 uint32_t request_seq;
512 uint16_t number_of_streams;
516 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
517 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
518 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
519 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
520 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
521 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
522 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
525 * convience structures, note that if you are making a request for specific
526 * streams then the request will need to be an overlay structure.
529 struct sctp_stream_reset_tsn_req {
530 struct sctp_chunkhdr ch;
531 struct sctp_stream_reset_tsn_request sr_req;
534 struct sctp_stream_reset_resp {
535 struct sctp_chunkhdr ch;
536 struct sctp_stream_reset_response sr_resp;
539 /* respone only valid with a TSN request */
540 struct sctp_stream_reset_resp_tsn {
541 struct sctp_chunkhdr ch;
542 struct sctp_stream_reset_response_tsn sr_resp;
545 /****************************************************/
548 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
551 /* Should we make the max be 32? */
552 #define SCTP_RANDOM_MAX_SIZE 256
553 struct sctp_auth_random {
554 struct sctp_paramhdr ph;/* type = 0x8002 */
555 uint8_t random_data[];
558 struct sctp_auth_chunk_list {
559 struct sctp_paramhdr ph;/* type = 0x8003 */
560 uint8_t chunk_types[];
563 struct sctp_auth_hmac_algo {
564 struct sctp_paramhdr ph;/* type = 0x8004 */
568 struct sctp_auth_chunk {
569 struct sctp_chunkhdr ch;
570 uint16_t shared_key_id;
575 struct sctp_auth_invalid_hmac {
576 struct sctp_paramhdr ph;
582 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
583 * pieces. If ENCE is missing we could have a couple of blocks. This way we
584 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
585 * data chunk I will split into. We could increase throughput slightly by
586 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
587 * feel is worth it for now.
589 #ifndef SCTP_MAX_OVERHEAD
591 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
592 sizeof(struct sctphdr) + \
593 sizeof(struct sctp_ecne_chunk) + \
594 sizeof(struct sctp_sack_chunk) + \
595 sizeof(struct ip6_hdr))
597 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
598 sizeof(struct sctphdr) + \
599 sizeof(struct ip6_hdr))
602 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
603 sizeof(struct sctphdr))
606 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
607 sizeof(struct sctphdr) + \
608 sizeof(struct sctp_ecne_chunk) + \
609 sizeof(struct sctp_sack_chunk) + \
612 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
613 sizeof(struct sctphdr) + \
617 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
618 sizeof(struct sctphdr))
621 #endif /* !SCTP_MAX_OVERHEAD */
623 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
624 sizeof(struct sctphdr) + \
627 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
628 sizeof(struct sctphdr))
630 #if defined(__Windows__)
633 #if defined(__Userspace_os_Windows)
637 #endif /* !__sctp_header_h__ */