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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #ifndef _NETINET_SCTP_HEADER_H_
37 #define _NETINET_SCTP_HEADER_H_
40 #include <netinet/sctp.h>
41 #include <netinet/sctp_constants.h>
43 #define SCTP_PACKED __attribute__((packed))
46 * Parameter structures
48 struct sctp_ipv4addr_param {
49 struct sctp_paramhdr ph;/* type=SCTP_IPV4_PARAM_TYPE, len=8 */
50 uint32_t addr; /* IPV4 address */
53 #define SCTP_V6_ADDR_BYTES 16
56 struct sctp_ipv6addr_param {
57 struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
58 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
61 /* Cookie Preservative */
62 struct sctp_cookie_perserve_param {
63 struct sctp_paramhdr ph;/* type=SCTP_COOKIE_PRESERVE, len=8 */
64 uint32_t time; /* time in ms to extend cookie */
67 #define SCTP_ARRAY_MIN_LEN 1
68 /* Host Name Address */
69 struct sctp_host_name_param {
70 struct sctp_paramhdr ph;/* type=SCTP_HOSTNAME_ADDRESS */
71 char name[SCTP_ARRAY_MIN_LEN]; /* host name */
75 * This is the maximum padded size of a s-a-p
76 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
78 #define SCTP_MAX_ADDR_PARAMS_SIZE 12
79 /* supported address type */
80 struct sctp_supported_addr_param {
81 struct sctp_paramhdr ph;/* type=SCTP_SUPPORTED_ADDRTYPE */
82 uint16_t addr_type[2]; /* array of supported address types */
85 /* heartbeat info parameter */
86 struct sctp_heartbeat_info_param {
87 struct sctp_paramhdr ph;
88 uint32_t time_value_1;
89 uint32_t time_value_2;
90 uint32_t random_value1;
91 uint32_t random_value2;
94 /* make sure that this structure is 4 byte aligned */
96 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;
107 /* draft-ietf-tsvwg-addip-sctp */
108 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
109 struct sctp_paramhdr ph;/* a SCTP parameter header */
110 uint32_t correlation_id;/* correlation id for this param */
113 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
114 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
115 struct sctp_ipv6addr_param addrp; /* max storage size */
119 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
120 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
122 uint32_t remote_vtag;
126 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
127 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
128 struct sctp_ipv4addr_param addrp; /* max storage size */
131 #define SCTP_MAX_SUPPORTED_EXT 256
133 struct sctp_supported_chunk_types_param {
134 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
135 uint8_t chunk_types[];
140 * Structures for DATA chunks
147 /* user data follows */
150 struct sctp_data_chunk {
151 struct sctp_chunkhdr ch;
158 uint16_t reserved; /* Where does the SSN go? */
162 uint32_t fsn; /* Fragment Sequence Number */
164 /* user data follows */
167 struct sctp_idata_chunk {
168 struct sctp_chunkhdr ch;
169 struct sctp_idata dp;
173 * Structures for the control chunks
176 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
178 uint32_t initiate_tag; /* initiate tag */
179 uint32_t a_rwnd; /* a_rwnd */
180 uint16_t num_outbound_streams; /* OS */
181 uint16_t num_inbound_streams; /* MIS */
182 uint32_t initial_tsn; /* I-TSN */
183 /* optional param's follow */
185 #define SCTP_IDENTIFICATION_SIZE 16
186 #define SCTP_ADDRESS_SIZE 4
187 #define SCTP_RESERVE_SPACE 6
188 /* state cookie header */
189 struct sctp_state_cookie { /* this is our definition... */
190 uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */
191 struct timeval time_entered; /* the time I built cookie */
192 uint32_t cookie_life; /* life I will award this cookie */
193 uint32_t tie_tag_my_vtag; /* my tag in old association */
195 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
196 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
198 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
199 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
200 uint32_t addr_type; /* address type */
201 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
202 uint32_t laddr_type; /* my local from address type */
203 uint32_t scope_id; /* v6 scope id for link-locals */
205 uint16_t peerport; /* port address of the peer in the INIT */
206 uint16_t myport; /* my port address used in the INIT */
207 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
208 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
209 uint8_t local_scope; /* IPv6 local scope flag */
210 uint8_t site_scope; /* IPv6 site scope flag */
212 uint8_t ipv4_scope; /* IPv4 private addr scope */
213 uint8_t loopback_scope; /* loopback scope information */
214 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
216 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
217 * (minus the cookie).
221 /* state cookie parameter */
222 struct sctp_state_cookie_param {
223 struct sctp_paramhdr ph;
224 struct sctp_state_cookie cookie;
227 struct sctp_init_chunk {
228 struct sctp_chunkhdr ch;
229 struct sctp_init init;
232 struct sctp_init_msg {
234 struct sctp_init_chunk msg;
237 /* ... used for both INIT and INIT ACK */
238 #define sctp_init_ack sctp_init
239 #define sctp_init_ack_chunk sctp_init_chunk
240 #define sctp_init_ack_msg sctp_init_msg
243 /* Selective Ack (SACK) */
244 struct sctp_gap_ack_block {
245 uint16_t start; /* Gap Ack block start */
246 uint16_t end; /* Gap Ack block end */
250 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
251 uint32_t a_rwnd; /* updated a_rwnd of sender */
252 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
253 uint16_t num_dup_tsns; /* number of duplicate TSNs */
254 /* struct sctp_gap_ack_block's follow */
255 /* uint32_t duplicate_tsn's follow */
258 struct sctp_sack_chunk {
259 struct sctp_chunkhdr ch;
260 struct sctp_sack sack;
263 struct sctp_nr_sack {
264 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
265 uint32_t a_rwnd; /* updated a_rwnd of sender */
266 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
267 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
268 uint16_t num_dup_tsns; /* number of duplicate TSNs */
269 uint16_t reserved; /* not currently used */
270 /* struct sctp_gap_ack_block's follow */
271 /* uint32_t duplicate_tsn's follow */
274 struct sctp_nr_sack_chunk {
275 struct sctp_chunkhdr ch;
276 struct sctp_nr_sack nr_sack;
280 /* Heartbeat Request (HEARTBEAT) */
281 struct sctp_heartbeat {
282 struct sctp_heartbeat_info_param hb_info;
285 struct sctp_heartbeat_chunk {
286 struct sctp_chunkhdr ch;
287 struct sctp_heartbeat heartbeat;
290 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
291 #define sctp_heartbeat_ack sctp_heartbeat
292 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
295 /* Abort Asssociation (ABORT) */
296 struct sctp_abort_chunk {
297 struct sctp_chunkhdr ch;
298 /* optional error cause may follow */
301 struct sctp_abort_msg {
303 struct sctp_abort_chunk msg;
307 /* Shutdown Association (SHUTDOWN) */
308 struct sctp_shutdown_chunk {
309 struct sctp_chunkhdr ch;
310 uint32_t cumulative_tsn_ack;
314 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
315 struct sctp_shutdown_ack_chunk {
316 struct sctp_chunkhdr ch;
320 /* Operation Error (ERROR) */
321 struct sctp_error_chunk {
322 struct sctp_chunkhdr ch;
323 /* optional error causes follow */
327 /* Cookie Echo (COOKIE ECHO) */
328 struct sctp_cookie_echo_chunk {
329 struct sctp_chunkhdr ch;
330 struct sctp_state_cookie cookie;
333 /* Cookie Acknowledgment (COOKIE ACK) */
334 struct sctp_cookie_ack_chunk {
335 struct sctp_chunkhdr ch;
338 /* Explicit Congestion Notification Echo (ECNE) */
339 struct old_sctp_ecne_chunk {
340 struct sctp_chunkhdr ch;
344 struct sctp_ecne_chunk {
345 struct sctp_chunkhdr ch;
347 uint32_t num_pkts_since_cwr;
350 /* Congestion Window Reduced (CWR) */
351 struct sctp_cwr_chunk {
352 struct sctp_chunkhdr ch;
356 /* Shutdown Complete (SHUTDOWN COMPLETE) */
357 struct sctp_shutdown_complete_chunk {
358 struct sctp_chunkhdr ch;
361 struct sctp_adaptation_layer_indication {
362 struct sctp_paramhdr ph;
367 * draft-ietf-tsvwg-addip-sctp
369 /* Address/Stream Configuration Change (ASCONF) */
370 struct sctp_asconf_chunk {
371 struct sctp_chunkhdr ch;
372 uint32_t serial_number;
373 /* lookup address parameter (mandatory) */
374 /* asconf parameters follow */
377 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */
378 struct sctp_asconf_ack_chunk {
379 struct sctp_chunkhdr ch;
380 uint32_t serial_number;
381 /* asconf parameters follow */
384 /* draft-ietf-tsvwg-prsctp */
385 /* Forward Cumulative TSN (FORWARD TSN) */
386 struct sctp_forward_tsn_chunk {
387 struct sctp_chunkhdr ch;
388 uint32_t new_cumulative_tsn;
389 /* stream/sequence pairs (sctp_strseq) follow */
397 struct sctp_strseq_mid {
403 struct sctp_forward_tsn_msg {
405 struct sctp_forward_tsn_chunk msg;
408 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
410 #define SCTP_NUM_DB_TO_VERIFY 31
412 struct sctp_chunk_desc {
414 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
419 struct sctp_pktdrop_chunk {
420 struct sctp_chunkhdr ch;
422 uint32_t current_onq;
428 /**********STREAM RESET STUFF ******************/
430 struct sctp_stream_reset_request {
431 struct sctp_paramhdr ph;
432 uint32_t request_seq;
435 struct sctp_stream_reset_out_request {
436 struct sctp_paramhdr ph;
437 uint32_t request_seq; /* monotonically increasing seq no */
438 uint32_t response_seq; /* if a response, the resp seq no */
439 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
440 uint16_t list_of_streams[]; /* if not all list of streams */
443 struct sctp_stream_reset_in_request {
444 struct sctp_paramhdr ph;
445 uint32_t request_seq;
446 uint16_t list_of_streams[]; /* if not all list of streams */
449 struct sctp_stream_reset_tsn_request {
450 struct sctp_paramhdr ph;
451 uint32_t request_seq;
454 struct sctp_stream_reset_response {
455 struct sctp_paramhdr ph;
456 uint32_t response_seq; /* if a response, the resp seq no */
460 struct sctp_stream_reset_response_tsn {
461 struct sctp_paramhdr ph;
462 uint32_t response_seq; /* if a response, the resp seq no */
464 uint32_t senders_next_tsn;
465 uint32_t receivers_next_tsn;
468 struct sctp_stream_reset_add_strm {
469 struct sctp_paramhdr ph;
470 uint32_t request_seq;
471 uint16_t number_of_streams;
475 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
476 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
477 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
478 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
479 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
480 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
481 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
484 * convience structures, note that if you are making a request for specific
485 * streams then the request will need to be an overlay structure.
488 struct sctp_stream_reset_tsn_req {
489 struct sctp_chunkhdr ch;
490 struct sctp_stream_reset_tsn_request sr_req;
493 struct sctp_stream_reset_resp {
494 struct sctp_chunkhdr ch;
495 struct sctp_stream_reset_response sr_resp;
498 /* respone only valid with a TSN request */
499 struct sctp_stream_reset_resp_tsn {
500 struct sctp_chunkhdr ch;
501 struct sctp_stream_reset_response_tsn sr_resp;
504 /****************************************************/
507 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
510 /* Should we make the max be 32? */
511 #define SCTP_RANDOM_MAX_SIZE 256
512 struct sctp_auth_random {
513 struct sctp_paramhdr ph;/* type = 0x8002 */
514 uint8_t random_data[];
517 struct sctp_auth_chunk_list {
518 struct sctp_paramhdr ph;/* type = 0x8003 */
519 uint8_t chunk_types[];
522 struct sctp_auth_hmac_algo {
523 struct sctp_paramhdr ph;/* type = 0x8004 */
527 struct sctp_auth_chunk {
528 struct sctp_chunkhdr ch;
529 uint16_t shared_key_id;
535 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
536 * pieces. If ENCE is missing we could have a couple of blocks. This way we
537 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
538 * data chunk I will split into. We could increase throughput slightly by
539 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
540 * feel is worth it for now.
542 #ifndef SCTP_MAX_OVERHEAD
544 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
545 sizeof(struct sctphdr) + \
546 sizeof(struct sctp_ecne_chunk) + \
547 sizeof(struct sctp_sack_chunk) + \
548 sizeof(struct ip6_hdr))
550 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
551 sizeof(struct sctphdr) + \
552 sizeof(struct ip6_hdr))
555 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
556 sizeof(struct sctphdr))
559 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
560 sizeof(struct sctphdr) + \
561 sizeof(struct sctp_ecne_chunk) + \
562 sizeof(struct sctp_sack_chunk) + \
565 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
566 sizeof(struct sctphdr) + \
570 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
571 sizeof(struct sctphdr))
574 #endif /* !SCTP_MAX_OVERHEAD */
576 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
577 sizeof(struct sctphdr) + \
580 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
581 sizeof(struct sctphdr))
584 #endif /* !__sctp_header_h__ */