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
57 struct sctp_ipv6addr_param {
58 struct sctp_paramhdr ph; /* type=SCTP_IPV6_PARAM_TYPE, len=20 */
59 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
62 /* Cookie Preservative */
63 struct sctp_cookie_perserve_param {
64 struct sctp_paramhdr ph; /* type=SCTP_COOKIE_PRESERVE, len=8 */
65 uint32_t time; /* time in ms to extend cookie */
68 #define SCTP_ARRAY_MIN_LEN 1
69 /* Host Name Address */
70 struct sctp_host_name_param {
71 struct sctp_paramhdr ph; /* type=SCTP_HOSTNAME_ADDRESS */
72 char name[SCTP_ARRAY_MIN_LEN]; /* host name */
76 * This is the maximum padded size of a s-a-p
77 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
79 #define SCTP_MAX_ADDR_PARAMS_SIZE 12
80 /* supported address type */
81 struct sctp_supported_addr_param {
82 struct sctp_paramhdr ph; /* type=SCTP_SUPPORTED_ADDRTYPE */
83 uint16_t addr_type[2]; /* array of supported address types */
86 /* heartbeat info parameter */
87 struct sctp_heartbeat_info_param {
88 struct sctp_paramhdr ph;
89 uint32_t time_value_1;
90 uint32_t time_value_2;
91 uint32_t random_value1;
92 uint32_t random_value2;
95 /* make sure that this structure is 4 byte aligned */
97 char address[SCTP_ADDRMAX];
100 /* draft-ietf-tsvwg-prsctp */
101 /* PR-SCTP supported parameter */
102 struct sctp_prsctp_supported_param {
103 struct sctp_paramhdr ph;
106 /* draft-ietf-tsvwg-addip-sctp */
107 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
108 struct sctp_paramhdr ph; /* a SCTP parameter header */
109 uint32_t correlation_id; /* correlation id for this param */
112 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
113 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
114 struct sctp_ipv6addr_param addrp; /* max storage size */
117 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
118 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
120 uint32_t remote_vtag;
123 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
124 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
125 struct sctp_ipv4addr_param addrp; /* max storage size */
128 #define SCTP_MAX_SUPPORTED_EXT 256
130 struct sctp_supported_chunk_types_param {
131 struct sctp_paramhdr ph; /* type = 0x8008 len = x */
132 uint8_t chunk_types[];
136 * Structures for DATA chunks
143 /* user data follows */
146 struct sctp_data_chunk {
147 struct sctp_chunkhdr ch;
154 uint16_t reserved; /* Where does the SSN go? */
158 uint32_t fsn; /* Fragment Sequence Number */
160 /* user data follows */
163 struct sctp_idata_chunk {
164 struct sctp_chunkhdr ch;
165 struct sctp_idata dp;
169 * Structures for the control chunks
172 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
174 uint32_t initiate_tag; /* initiate tag */
175 uint32_t a_rwnd; /* a_rwnd */
176 uint16_t num_outbound_streams; /* OS */
177 uint16_t num_inbound_streams; /* MIS */
178 uint32_t initial_tsn; /* I-TSN */
179 /* optional param's follow */
181 #define SCTP_IDENTIFICATION_SIZE 16
182 #define SCTP_ADDRESS_SIZE 4
183 #define SCTP_RESERVE_SPACE 5
184 /* state cookie header */
185 struct sctp_state_cookie { /* this is our definition... */
186 uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */
187 struct timeval time_entered; /* the time I built cookie */
188 uint32_t cookie_life; /* life I will award this cookie */
189 uint32_t tie_tag_my_vtag; /* my tag in old association */
191 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
192 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
194 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
195 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
196 uint32_t addr_type; /* address type */
197 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
198 uint32_t laddr_type; /* my local from address type */
199 uint32_t scope_id; /* v6 scope id for link-locals */
201 uint16_t peerport; /* port address of the peer in the INIT */
202 uint16_t myport; /* my port address used in the INIT */
203 uint8_t ipv4_addr_legal; /* Are V4 addr legal? */
204 uint8_t ipv6_addr_legal; /* Are V6 addr legal? */
205 uint8_t local_scope; /* IPv6 local scope flag */
206 uint8_t site_scope; /* IPv6 site scope flag */
208 uint8_t ipv4_scope; /* IPv4 private addr scope */
209 uint8_t loopback_scope; /* loopback scope information */
210 uint8_t zero_checksum; /* copy of the inp value */
211 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
213 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
214 * (minus the cookie).
218 /* state cookie parameter */
219 struct sctp_state_cookie_param {
220 struct sctp_paramhdr ph;
221 struct sctp_state_cookie cookie;
224 struct sctp_init_chunk {
225 struct sctp_chunkhdr ch;
226 struct sctp_init init;
229 struct sctp_init_msg {
231 struct sctp_init_chunk msg;
234 /* ... used for both INIT and INIT ACK */
235 #define sctp_init_ack sctp_init
236 #define sctp_init_ack_chunk sctp_init_chunk
237 #define sctp_init_ack_msg sctp_init_msg
239 /* Selective Ack (SACK) */
240 struct sctp_gap_ack_block {
241 uint16_t start; /* Gap Ack block start */
242 uint16_t end; /* Gap Ack block end */
246 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
247 uint32_t a_rwnd; /* updated a_rwnd of sender */
248 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
249 uint16_t num_dup_tsns; /* number of duplicate TSNs */
250 /* struct sctp_gap_ack_block's follow */
251 /* uint32_t duplicate_tsn's follow */
254 struct sctp_sack_chunk {
255 struct sctp_chunkhdr ch;
256 struct sctp_sack sack;
259 struct sctp_nr_sack {
260 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
261 uint32_t a_rwnd; /* updated a_rwnd of sender */
262 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
263 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
264 uint16_t num_dup_tsns; /* number of duplicate TSNs */
265 uint16_t reserved; /* not currently used */
266 /* struct sctp_gap_ack_block's follow */
267 /* uint32_t duplicate_tsn's follow */
270 struct sctp_nr_sack_chunk {
271 struct sctp_chunkhdr ch;
272 struct sctp_nr_sack nr_sack;
275 /* Heartbeat Request (HEARTBEAT) */
276 struct sctp_heartbeat {
277 struct sctp_heartbeat_info_param hb_info;
280 struct sctp_heartbeat_chunk {
281 struct sctp_chunkhdr ch;
282 struct sctp_heartbeat heartbeat;
285 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
286 #define sctp_heartbeat_ack sctp_heartbeat
287 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
289 /* Abort Asssociation (ABORT) */
290 struct sctp_abort_chunk {
291 struct sctp_chunkhdr ch;
292 /* optional error cause may follow */
295 struct sctp_abort_msg {
297 struct sctp_abort_chunk msg;
300 /* Shutdown Association (SHUTDOWN) */
301 struct sctp_shutdown_chunk {
302 struct sctp_chunkhdr ch;
303 uint32_t cumulative_tsn_ack;
306 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
307 struct sctp_shutdown_ack_chunk {
308 struct sctp_chunkhdr ch;
311 /* Operation Error (ERROR) */
312 struct sctp_error_chunk {
313 struct sctp_chunkhdr ch;
314 /* optional error causes follow */
317 /* Cookie Echo (COOKIE ECHO) */
318 struct sctp_cookie_echo_chunk {
319 struct sctp_chunkhdr ch;
320 struct sctp_state_cookie cookie;
323 /* Cookie Acknowledgment (COOKIE ACK) */
324 struct sctp_cookie_ack_chunk {
325 struct sctp_chunkhdr ch;
328 /* Explicit Congestion Notification Echo (ECNE) */
329 struct old_sctp_ecne_chunk {
330 struct sctp_chunkhdr ch;
334 struct sctp_ecne_chunk {
335 struct sctp_chunkhdr ch;
337 uint32_t num_pkts_since_cwr;
340 /* Congestion Window Reduced (CWR) */
341 struct sctp_cwr_chunk {
342 struct sctp_chunkhdr ch;
346 /* Shutdown Complete (SHUTDOWN COMPLETE) */
347 struct sctp_shutdown_complete_chunk {
348 struct sctp_chunkhdr ch;
351 struct sctp_adaptation_layer_indication {
352 struct sctp_paramhdr ph;
357 * draft-ietf-tsvwg-addip-sctp
359 /* Address/Stream Configuration Change (ASCONF) */
360 struct sctp_asconf_chunk {
361 struct sctp_chunkhdr ch;
362 uint32_t serial_number;
363 /* lookup address parameter (mandatory) */
364 /* asconf parameters follow */
367 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */
368 struct sctp_asconf_ack_chunk {
369 struct sctp_chunkhdr ch;
370 uint32_t serial_number;
371 /* asconf parameters follow */
374 /* draft-ietf-tsvwg-prsctp */
375 /* Forward Cumulative TSN (FORWARD TSN) */
376 struct sctp_forward_tsn_chunk {
377 struct sctp_chunkhdr ch;
378 uint32_t new_cumulative_tsn;
379 /* stream/sequence pairs (sctp_strseq) follow */
387 struct sctp_strseq_mid {
393 struct sctp_forward_tsn_msg {
395 struct sctp_forward_tsn_chunk msg;
398 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
400 #define SCTP_NUM_DB_TO_VERIFY 31
402 struct sctp_chunk_desc {
404 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
408 struct sctp_pktdrop_chunk {
409 struct sctp_chunkhdr ch;
411 uint32_t current_onq;
417 /**********STREAM RESET STUFF ******************/
419 struct sctp_stream_reset_request {
420 struct sctp_paramhdr ph;
421 uint32_t request_seq;
424 struct sctp_stream_reset_out_request {
425 struct sctp_paramhdr ph;
426 uint32_t request_seq; /* monotonically increasing seq no */
427 uint32_t response_seq; /* if a response, the resp seq no */
428 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
429 uint16_t list_of_streams[]; /* if not all list of streams */
432 struct sctp_stream_reset_in_request {
433 struct sctp_paramhdr ph;
434 uint32_t request_seq;
435 uint16_t list_of_streams[]; /* if not all list of streams */
438 struct sctp_stream_reset_tsn_request {
439 struct sctp_paramhdr ph;
440 uint32_t request_seq;
443 struct sctp_stream_reset_response {
444 struct sctp_paramhdr ph;
445 uint32_t response_seq; /* if a response, the resp seq no */
449 struct sctp_stream_reset_response_tsn {
450 struct sctp_paramhdr ph;
451 uint32_t response_seq; /* if a response, the resp seq no */
453 uint32_t senders_next_tsn;
454 uint32_t receivers_next_tsn;
457 struct sctp_stream_reset_add_strm {
458 struct sctp_paramhdr ph;
459 uint32_t request_seq;
460 uint16_t number_of_streams;
464 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
465 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
466 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
467 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
468 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
469 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
470 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
473 * convience structures, note that if you are making a request for specific
474 * streams then the request will need to be an overlay structure.
477 struct sctp_stream_reset_tsn_req {
478 struct sctp_chunkhdr ch;
479 struct sctp_stream_reset_tsn_request sr_req;
482 struct sctp_stream_reset_resp {
483 struct sctp_chunkhdr ch;
484 struct sctp_stream_reset_response sr_resp;
487 /* respone only valid with a TSN request */
488 struct sctp_stream_reset_resp_tsn {
489 struct sctp_chunkhdr ch;
490 struct sctp_stream_reset_response_tsn sr_resp;
493 /****************************************************/
496 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
499 /* Should we make the max be 32? */
500 #define SCTP_RANDOM_MAX_SIZE 256
501 struct sctp_auth_random {
502 struct sctp_paramhdr ph; /* type = 0x8002 */
503 uint8_t random_data[];
506 struct sctp_auth_chunk_list {
507 struct sctp_paramhdr ph; /* type = 0x8003 */
508 uint8_t chunk_types[];
511 struct sctp_auth_hmac_algo {
512 struct sctp_paramhdr ph; /* type = 0x8004 */
516 struct sctp_auth_chunk {
517 struct sctp_chunkhdr ch;
518 uint16_t shared_key_id;
524 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
525 * pieces. If ENCE is missing we could have a couple of blocks. This way we
526 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
527 * data chunk I will split into. We could increase throughput slightly by
528 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
529 * feel is worth it for now.
531 #ifndef SCTP_MAX_OVERHEAD
533 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
534 sizeof(struct sctphdr) + \
535 sizeof(struct sctp_ecne_chunk) + \
536 sizeof(struct sctp_sack_chunk) + \
537 sizeof(struct ip6_hdr))
539 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
540 sizeof(struct sctphdr) + \
541 sizeof(struct ip6_hdr))
543 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
544 sizeof(struct sctphdr))
547 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
548 sizeof(struct sctphdr) + \
549 sizeof(struct sctp_ecne_chunk) + \
550 sizeof(struct sctp_sack_chunk) + \
553 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
554 sizeof(struct sctphdr) + \
557 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
558 sizeof(struct sctphdr))
561 #endif /* !SCTP_MAX_OVERHEAD */
563 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
564 sizeof(struct sctphdr) + \
567 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
568 sizeof(struct sctphdr))
571 #endif /* !__sctp_header_h__ */