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 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #ifndef _NETINET_SCTP_HEADER_H_
39 #define _NETINET_SCTP_HEADER_H_
42 #include <netinet/sctp.h>
43 #include <netinet/sctp_constants.h>
45 #define SCTP_PACKED __attribute__((packed))
48 * Parameter structures
50 struct sctp_ipv4addr_param {
51 struct sctp_paramhdr ph; /* type=SCTP_IPV4_PARAM_TYPE, len=8 */
52 uint32_t addr; /* IPV4 address */
55 #define SCTP_V6_ADDR_BYTES 16
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 */
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 */
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 */
77 * This is the maximum padded size of a s-a-p
78 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
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 */
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;
96 /* make sure that this structure is 4 byte aligned */
98 char address[SCTP_ADDRMAX];
102 /* draft-ietf-tsvwg-prsctp */
103 /* PR-SCTP supported parameter */
104 struct sctp_prsctp_supported_param {
105 struct sctp_paramhdr ph;
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 */
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 */
121 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
122 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
124 uint32_t remote_vtag;
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 */
133 #define SCTP_MAX_SUPPORTED_EXT 256
135 struct sctp_supported_chunk_types_param {
136 struct sctp_paramhdr ph; /* type = 0x8008 len = x */
137 uint8_t chunk_types[];
142 * Structures for DATA chunks
149 /* user data follows */
152 struct sctp_data_chunk {
153 struct sctp_chunkhdr ch;
160 uint16_t reserved; /* Where does the SSN go? */
164 uint32_t fsn; /* Fragment Sequence Number */
166 /* user data follows */
169 struct sctp_idata_chunk {
170 struct sctp_chunkhdr ch;
171 struct sctp_idata dp;
175 * Structures for the control chunks
178 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
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 */
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 */
197 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
198 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
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 */
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 */
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).
223 /* state cookie parameter */
224 struct sctp_state_cookie_param {
225 struct sctp_paramhdr ph;
226 struct sctp_state_cookie cookie;
229 struct sctp_init_chunk {
230 struct sctp_chunkhdr ch;
231 struct sctp_init init;
234 struct sctp_init_msg {
236 struct sctp_init_chunk msg;
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
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 */
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 */
260 struct sctp_sack_chunk {
261 struct sctp_chunkhdr ch;
262 struct sctp_sack sack;
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 */
276 struct sctp_nr_sack_chunk {
277 struct sctp_chunkhdr ch;
278 struct sctp_nr_sack nr_sack;
282 /* Heartbeat Request (HEARTBEAT) */
283 struct sctp_heartbeat {
284 struct sctp_heartbeat_info_param hb_info;
287 struct sctp_heartbeat_chunk {
288 struct sctp_chunkhdr ch;
289 struct sctp_heartbeat heartbeat;
292 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
293 #define sctp_heartbeat_ack sctp_heartbeat
294 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
297 /* Abort Asssociation (ABORT) */
298 struct sctp_abort_chunk {
299 struct sctp_chunkhdr ch;
300 /* optional error cause may follow */
303 struct sctp_abort_msg {
305 struct sctp_abort_chunk msg;
309 /* Shutdown Association (SHUTDOWN) */
310 struct sctp_shutdown_chunk {
311 struct sctp_chunkhdr ch;
312 uint32_t cumulative_tsn_ack;
316 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
317 struct sctp_shutdown_ack_chunk {
318 struct sctp_chunkhdr ch;
322 /* Operation Error (ERROR) */
323 struct sctp_error_chunk {
324 struct sctp_chunkhdr ch;
325 /* optional error causes follow */
329 /* Cookie Echo (COOKIE ECHO) */
330 struct sctp_cookie_echo_chunk {
331 struct sctp_chunkhdr ch;
332 struct sctp_state_cookie cookie;
335 /* Cookie Acknowledgment (COOKIE ACK) */
336 struct sctp_cookie_ack_chunk {
337 struct sctp_chunkhdr ch;
340 /* Explicit Congestion Notification Echo (ECNE) */
341 struct old_sctp_ecne_chunk {
342 struct sctp_chunkhdr ch;
346 struct sctp_ecne_chunk {
347 struct sctp_chunkhdr ch;
349 uint32_t num_pkts_since_cwr;
352 /* Congestion Window Reduced (CWR) */
353 struct sctp_cwr_chunk {
354 struct sctp_chunkhdr ch;
358 /* Shutdown Complete (SHUTDOWN COMPLETE) */
359 struct sctp_shutdown_complete_chunk {
360 struct sctp_chunkhdr ch;
363 struct sctp_adaptation_layer_indication {
364 struct sctp_paramhdr ph;
369 * draft-ietf-tsvwg-addip-sctp
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 */
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 */
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 */
399 struct sctp_strseq_mid {
405 struct sctp_forward_tsn_msg {
407 struct sctp_forward_tsn_chunk msg;
410 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
412 #define SCTP_NUM_DB_TO_VERIFY 31
414 struct sctp_chunk_desc {
416 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
421 struct sctp_pktdrop_chunk {
422 struct sctp_chunkhdr ch;
424 uint32_t current_onq;
430 /**********STREAM RESET STUFF ******************/
432 struct sctp_stream_reset_request {
433 struct sctp_paramhdr ph;
434 uint32_t request_seq;
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 */
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 */
451 struct sctp_stream_reset_tsn_request {
452 struct sctp_paramhdr ph;
453 uint32_t request_seq;
456 struct sctp_stream_reset_response {
457 struct sctp_paramhdr ph;
458 uint32_t response_seq; /* if a response, the resp seq no */
462 struct sctp_stream_reset_response_tsn {
463 struct sctp_paramhdr ph;
464 uint32_t response_seq; /* if a response, the resp seq no */
466 uint32_t senders_next_tsn;
467 uint32_t receivers_next_tsn;
470 struct sctp_stream_reset_add_strm {
471 struct sctp_paramhdr ph;
472 uint32_t request_seq;
473 uint16_t number_of_streams;
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 */
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.
490 struct sctp_stream_reset_tsn_req {
491 struct sctp_chunkhdr ch;
492 struct sctp_stream_reset_tsn_request sr_req;
495 struct sctp_stream_reset_resp {
496 struct sctp_chunkhdr ch;
497 struct sctp_stream_reset_response sr_resp;
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;
506 /****************************************************/
509 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
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[];
519 struct sctp_auth_chunk_list {
520 struct sctp_paramhdr ph; /* type = 0x8003 */
521 uint8_t chunk_types[];
524 struct sctp_auth_hmac_algo {
525 struct sctp_paramhdr ph; /* type = 0x8004 */
529 struct sctp_auth_chunk {
530 struct sctp_chunkhdr ch;
531 uint16_t shared_key_id;
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.
544 #ifndef SCTP_MAX_OVERHEAD
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))
552 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
553 sizeof(struct sctphdr) + \
554 sizeof(struct ip6_hdr))
557 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
558 sizeof(struct sctphdr))
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) + \
567 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
568 sizeof(struct sctphdr) + \
572 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
573 sizeof(struct sctphdr))
576 #endif /* !SCTP_MAX_OVERHEAD */
578 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
579 sizeof(struct sctphdr) + \
582 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
583 sizeof(struct sctphdr))
586 #endif /* !__sctp_header_h__ */