2 * SPDX-License-Identifier: BSD-3-Clause
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.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
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.
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.
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.
35 #if defined(__FreeBSD__) && !defined(__Userspace__)
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 309682 2016-12-07 19:30:59Z tuexen $");
40 #ifndef _NETINET_SCTP_HEADER_H_
41 #define _NETINET_SCTP_HEADER_H_
43 #if defined(_WIN32) && !defined(__Userspace__)
49 #include <netinet/sctp.h>
50 #include <netinet/sctp_constants.h>
53 #define SCTP_PACKED __attribute__((packed))
55 #pragma pack (push, 1)
60 * Parameter structures
62 struct sctp_ipv4addr_param {
63 struct sctp_paramhdr ph;/* type=SCTP_IPV4_PARAM_TYPE, len=8 */
64 uint32_t addr; /* IPV4 address */
67 #define SCTP_V6_ADDR_BYTES 16
70 struct sctp_ipv6addr_param {
71 struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
72 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
75 /* Cookie Preservative */
76 struct sctp_cookie_perserve_param {
77 struct sctp_paramhdr ph;/* type=SCTP_COOKIE_PRESERVE, len=8 */
78 uint32_t time; /* time in ms to extend cookie */
81 #define SCTP_ARRAY_MIN_LEN 1
82 /* Host Name Address */
83 struct sctp_host_name_param {
84 struct sctp_paramhdr ph;/* type=SCTP_HOSTNAME_ADDRESS */
85 char name[SCTP_ARRAY_MIN_LEN]; /* host name */
89 * This is the maximum padded size of a s-a-p
90 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
92 #define SCTP_MAX_ADDR_PARAMS_SIZE 12
93 /* supported address type */
94 struct sctp_supported_addr_param {
95 struct sctp_paramhdr ph;/* type=SCTP_SUPPORTED_ADDRTYPE */
96 uint16_t addr_type[2]; /* array of supported address types */
99 /* heartbeat info parameter */
100 struct sctp_heartbeat_info_param {
101 struct sctp_paramhdr ph;
102 uint32_t time_value_1;
103 uint32_t time_value_2;
104 uint32_t random_value1;
105 uint32_t random_value2;
108 /* make sure that this structure is 4 byte aligned */
110 char address[SCTP_ADDRMAX];
114 /* draft-ietf-tsvwg-prsctp */
115 /* PR-SCTP supported parameter */
116 struct sctp_prsctp_supported_param {
117 struct sctp_paramhdr ph;
121 /* draft-ietf-tsvwg-addip-sctp */
122 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
123 struct sctp_paramhdr ph;/* a SCTP parameter header */
124 uint32_t correlation_id;/* correlation id for this param */
127 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
128 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
129 struct sctp_ipv6addr_param addrp; /* max storage size */
133 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
134 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
136 uint32_t remote_vtag;
140 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
141 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
142 struct sctp_ipv4addr_param addrp; /* max storage size */
145 #define SCTP_MAX_SUPPORTED_EXT 256
147 struct sctp_supported_chunk_types_param {
148 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
149 uint8_t chunk_types[];
154 * Structures for DATA chunks
161 /* user data follows */
164 struct sctp_data_chunk {
165 struct sctp_chunkhdr ch;
172 uint16_t reserved; /* Where does the SSN go? */
176 uint32_t fsn; /* Fragment Sequence Number */
178 /* user data follows */
181 struct sctp_idata_chunk {
182 struct sctp_chunkhdr ch;
183 struct sctp_idata dp;
187 * Structures for the control chunks
190 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
192 uint32_t initiate_tag; /* initiate tag */
193 uint32_t a_rwnd; /* a_rwnd */
194 uint16_t num_outbound_streams; /* OS */
195 uint16_t num_inbound_streams; /* MIS */
196 uint32_t initial_tsn; /* I-TSN */
197 /* optional param's follow */
199 #define SCTP_IDENTIFICATION_SIZE 16
200 #define SCTP_ADDRESS_SIZE 4
201 #if defined(__Userspace__)
202 #define SCTP_RESERVE_SPACE 5
204 #define SCTP_RESERVE_SPACE 6
206 /* state cookie header */
207 struct sctp_state_cookie { /* this is our definition... */
208 uint8_t identification[SCTP_IDENTIFICATION_SIZE];/* id of who we are */
209 struct timeval time_entered; /* the time I built cookie */
210 uint32_t cookie_life; /* life I will award this cookie */
211 uint32_t tie_tag_my_vtag; /* my tag in old association */
213 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
214 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
216 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
217 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
218 uint32_t addr_type; /* address type */
219 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
220 uint32_t laddr_type; /* my local from address type */
221 uint32_t scope_id; /* v6 scope id for link-locals */
223 uint16_t peerport; /* port address of the peer in the INIT */
224 uint16_t myport; /* my port address used in the INIT */
225 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
226 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
227 #if defined(__Userspace__)
228 uint8_t conn_addr_legal;
230 uint8_t local_scope; /* IPv6 local scope flag */
231 uint8_t site_scope; /* IPv6 site scope flag */
233 uint8_t ipv4_scope; /* IPv4 private addr scope */
234 uint8_t loopback_scope; /* loopback scope information */
235 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
237 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
238 * (minus the cookie).
242 /* state cookie parameter */
243 struct sctp_state_cookie_param {
244 struct sctp_paramhdr ph;
245 struct sctp_state_cookie cookie;
248 struct sctp_init_chunk {
249 struct sctp_chunkhdr ch;
250 struct sctp_init init;
253 struct sctp_init_msg {
255 struct sctp_init_chunk msg;
258 /* ... used for both INIT and INIT ACK */
259 #define sctp_init_ack sctp_init
260 #define sctp_init_ack_chunk sctp_init_chunk
261 #define sctp_init_ack_msg sctp_init_msg
264 /* Selective Ack (SACK) */
265 struct sctp_gap_ack_block {
266 uint16_t start; /* Gap Ack block start */
267 uint16_t end; /* Gap Ack block end */
271 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
272 uint32_t a_rwnd; /* updated a_rwnd of sender */
273 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
274 uint16_t num_dup_tsns; /* number of duplicate TSNs */
275 /* struct sctp_gap_ack_block's follow */
276 /* uint32_t duplicate_tsn's follow */
279 struct sctp_sack_chunk {
280 struct sctp_chunkhdr ch;
281 struct sctp_sack sack;
284 struct sctp_nr_sack {
285 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
286 uint32_t a_rwnd; /* updated a_rwnd of sender */
287 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
288 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
289 uint16_t num_dup_tsns; /* number of duplicate TSNs */
290 uint16_t reserved; /* not currently used*/
291 /* struct sctp_gap_ack_block's follow */
292 /* uint32_t duplicate_tsn's follow */
295 struct sctp_nr_sack_chunk {
296 struct sctp_chunkhdr ch;
297 struct sctp_nr_sack nr_sack;
301 /* Heartbeat Request (HEARTBEAT) */
302 struct sctp_heartbeat {
303 struct sctp_heartbeat_info_param hb_info;
306 struct sctp_heartbeat_chunk {
307 struct sctp_chunkhdr ch;
308 struct sctp_heartbeat heartbeat;
311 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
312 #define sctp_heartbeat_ack sctp_heartbeat
313 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
316 /* Abort Asssociation (ABORT) */
317 struct sctp_abort_chunk {
318 struct sctp_chunkhdr ch;
319 /* optional error cause may follow */
322 struct sctp_abort_msg {
324 struct sctp_abort_chunk msg;
328 /* Shutdown Association (SHUTDOWN) */
329 struct sctp_shutdown_chunk {
330 struct sctp_chunkhdr ch;
331 uint32_t cumulative_tsn_ack;
335 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
336 struct sctp_shutdown_ack_chunk {
337 struct sctp_chunkhdr ch;
341 /* Operation Error (ERROR) */
342 struct sctp_error_chunk {
343 struct sctp_chunkhdr ch;
344 /* optional error causes follow */
348 /* Cookie Echo (COOKIE ECHO) */
349 struct sctp_cookie_echo_chunk {
350 struct sctp_chunkhdr ch;
351 struct sctp_state_cookie cookie;
354 /* Cookie Acknowledgment (COOKIE ACK) */
355 struct sctp_cookie_ack_chunk {
356 struct sctp_chunkhdr ch;
359 /* Explicit Congestion Notification Echo (ECNE) */
360 struct old_sctp_ecne_chunk {
361 struct sctp_chunkhdr ch;
365 struct sctp_ecne_chunk {
366 struct sctp_chunkhdr ch;
368 uint32_t num_pkts_since_cwr;
371 /* Congestion Window Reduced (CWR) */
372 struct sctp_cwr_chunk {
373 struct sctp_chunkhdr ch;
377 /* Shutdown Complete (SHUTDOWN COMPLETE) */
378 struct sctp_shutdown_complete_chunk {
379 struct sctp_chunkhdr ch;
382 struct sctp_adaptation_layer_indication {
383 struct sctp_paramhdr ph;
388 * draft-ietf-tsvwg-addip-sctp
390 /* Address/Stream Configuration Change (ASCONF) */
391 struct sctp_asconf_chunk {
392 struct sctp_chunkhdr ch;
393 uint32_t serial_number;
394 /* lookup address parameter (mandatory) */
395 /* asconf parameters follow */
398 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */
399 struct sctp_asconf_ack_chunk {
400 struct sctp_chunkhdr ch;
401 uint32_t serial_number;
402 /* asconf parameters follow */
405 /* draft-ietf-tsvwg-prsctp */
406 /* Forward Cumulative TSN (FORWARD TSN) */
407 struct sctp_forward_tsn_chunk {
408 struct sctp_chunkhdr ch;
409 uint32_t new_cumulative_tsn;
410 /* stream/sequence pairs (sctp_strseq) follow */
418 struct sctp_strseq_mid {
424 struct sctp_forward_tsn_msg {
426 struct sctp_forward_tsn_chunk msg;
429 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
431 #define SCTP_NUM_DB_TO_VERIFY 31
433 struct sctp_chunk_desc {
435 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
440 struct sctp_pktdrop_chunk {
441 struct sctp_chunkhdr ch;
443 uint32_t current_onq;
449 /**********STREAM RESET STUFF ******************/
451 struct sctp_stream_reset_request {
452 struct sctp_paramhdr ph;
453 uint32_t request_seq;
456 struct sctp_stream_reset_out_request {
457 struct sctp_paramhdr ph;
458 uint32_t request_seq; /* monotonically increasing seq no */
459 uint32_t response_seq; /* if a response, the resp seq no */
460 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
461 uint16_t list_of_streams[]; /* if not all list of streams */
464 struct sctp_stream_reset_in_request {
465 struct sctp_paramhdr ph;
466 uint32_t request_seq;
467 uint16_t list_of_streams[]; /* if not all list of streams */
470 struct sctp_stream_reset_tsn_request {
471 struct sctp_paramhdr ph;
472 uint32_t request_seq;
475 struct sctp_stream_reset_response {
476 struct sctp_paramhdr ph;
477 uint32_t response_seq; /* if a response, the resp seq no */
481 struct sctp_stream_reset_response_tsn {
482 struct sctp_paramhdr ph;
483 uint32_t response_seq; /* if a response, the resp seq no */
485 uint32_t senders_next_tsn;
486 uint32_t receivers_next_tsn;
489 struct sctp_stream_reset_add_strm {
490 struct sctp_paramhdr ph;
491 uint32_t request_seq;
492 uint16_t number_of_streams;
496 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
497 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
498 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
499 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
500 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
501 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
502 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
505 * convience structures, note that if you are making a request for specific
506 * streams then the request will need to be an overlay structure.
509 struct sctp_stream_reset_tsn_req {
510 struct sctp_chunkhdr ch;
511 struct sctp_stream_reset_tsn_request sr_req;
514 struct sctp_stream_reset_resp {
515 struct sctp_chunkhdr ch;
516 struct sctp_stream_reset_response sr_resp;
519 /* respone only valid with a TSN request */
520 struct sctp_stream_reset_resp_tsn {
521 struct sctp_chunkhdr ch;
522 struct sctp_stream_reset_response_tsn sr_resp;
525 /****************************************************/
528 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
531 /* Should we make the max be 32? */
532 #define SCTP_RANDOM_MAX_SIZE 256
533 struct sctp_auth_random {
534 struct sctp_paramhdr ph;/* type = 0x8002 */
535 uint8_t random_data[];
538 struct sctp_auth_chunk_list {
539 struct sctp_paramhdr ph;/* type = 0x8003 */
540 uint8_t chunk_types[];
543 struct sctp_auth_hmac_algo {
544 struct sctp_paramhdr ph;/* type = 0x8004 */
548 struct sctp_auth_chunk {
549 struct sctp_chunkhdr ch;
550 uint16_t shared_key_id;
556 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
557 * pieces. If ENCE is missing we could have a couple of blocks. This way we
558 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
559 * data chunk I will split into. We could increase throughput slightly by
560 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
561 * feel is worth it for now.
563 #ifndef SCTP_MAX_OVERHEAD
565 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
566 sizeof(struct sctphdr) + \
567 sizeof(struct sctp_ecne_chunk) + \
568 sizeof(struct sctp_sack_chunk) + \
569 sizeof(struct ip6_hdr))
571 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
572 sizeof(struct sctphdr) + \
573 sizeof(struct ip6_hdr))
576 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
577 sizeof(struct sctphdr))
580 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
581 sizeof(struct sctphdr) + \
582 sizeof(struct sctp_ecne_chunk) + \
583 sizeof(struct sctp_sack_chunk) + \
586 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
587 sizeof(struct sctphdr) + \
591 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
592 sizeof(struct sctphdr))
595 #endif /* !SCTP_MAX_OVERHEAD */
597 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
598 sizeof(struct sctphdr) + \
601 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
602 sizeof(struct sctphdr))
604 #if defined(_WIN32) && !defined(__Userspace__)
607 #if defined(_WIN32) && defined(__Userspace__)
611 #endif /* !__sctp_header_h__ */