2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, 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 /* $KAME: sctp_header.h,v 1.14 2005/03/06 16:04:17 itojun Exp $ */
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #ifndef __sctp_header_h__
39 #define __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 */
88 struct sctp_ecn_supported_param {
89 struct sctp_paramhdr ph;/* type=SCTP_ECN_CAPABLE */
93 /* heartbeat info parameter */
94 struct sctp_heartbeat_info_param {
95 struct sctp_paramhdr ph;
96 uint32_t time_value_1;
97 uint32_t time_value_2;
98 uint32_t random_value1;
99 uint32_t random_value2;
102 /* make sure that this structure is 4 byte aligned */
104 char address[SCTP_ADDRMAX];
108 /* draft-ietf-tsvwg-prsctp */
109 /* PR-SCTP supported parameter */
110 struct sctp_prsctp_supported_param {
111 struct sctp_paramhdr ph;
115 /* draft-ietf-tsvwg-addip-sctp */
116 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
117 struct sctp_paramhdr ph;/* a SCTP parameter header */
118 uint32_t correlation_id;/* correlation id for this param */
121 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
122 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
123 struct sctp_ipv6addr_param addrp; /* max storage size */
127 struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
128 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
130 uint32_t remote_vtag;
134 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
135 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
136 struct sctp_ipv4addr_param addrp; /* max storage size */
139 #define SCTP_MAX_SUPPORTED_EXT 256
141 struct sctp_supported_chunk_types_param {
142 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
143 uint8_t chunk_types[];
148 * Structures for DATA chunks
153 uint16_t stream_sequence;
154 uint32_t protocol_id;
155 /* user data follows */
158 struct sctp_data_chunk {
159 struct sctp_chunkhdr ch;
164 * Structures for the control chunks
167 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
169 uint32_t initiate_tag; /* initiate tag */
170 uint32_t a_rwnd; /* a_rwnd */
171 uint16_t num_outbound_streams; /* OS */
172 uint16_t num_inbound_streams; /* MIS */
173 uint32_t initial_tsn; /* I-TSN */
174 /* optional param's follow */
177 #define SCTP_IDENTIFICATION_SIZE 16
178 #define SCTP_ADDRESS_SIZE 4
179 #define SCTP_RESERVE_SPACE 6
180 /* state cookie header */
181 struct sctp_state_cookie { /* this is our definition... */
182 uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */
183 struct timeval time_entered; /* the time I built cookie */
184 uint32_t cookie_life; /* life I will award this cookie */
185 uint32_t tie_tag_my_vtag; /* my tag in old association */
187 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
188 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
190 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
191 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
192 uint32_t addr_type; /* address type */
193 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
194 uint32_t laddr_type; /* my local from address type */
195 uint32_t scope_id; /* v6 scope id for link-locals */
197 uint16_t peerport; /* port address of the peer in the INIT */
198 uint16_t myport; /* my port address used in the INIT */
199 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
200 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
201 uint8_t local_scope; /* IPv6 local scope flag */
202 uint8_t site_scope; /* IPv6 site scope flag */
204 uint8_t ipv4_scope; /* IPv4 private addr scope */
205 uint8_t loopback_scope; /* loopback scope information */
206 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
208 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
209 * (minus the cookie).
214 /* Used for NAT state error cause */
215 struct sctp_missing_nat_state {
222 struct sctp_inv_mandatory_param {
228 * We include this to 0 it since only a missing cookie will cause
234 struct sctp_unresolv_addr {
238 uint16_t reserved; /* Only one invalid addr type */
241 /* state cookie parameter */
242 struct sctp_state_cookie_param {
243 struct sctp_paramhdr ph;
244 struct sctp_state_cookie cookie;
247 struct sctp_init_chunk {
248 struct sctp_chunkhdr ch;
249 struct sctp_init init;
252 struct sctp_init_msg {
254 struct sctp_init_chunk msg;
257 /* ... used for both INIT and INIT ACK */
258 #define sctp_init_ack sctp_init
259 #define sctp_init_ack_chunk sctp_init_chunk
260 #define sctp_init_ack_msg sctp_init_msg
263 /* Selective Ack (SACK) */
264 struct sctp_gap_ack_block {
265 uint16_t start; /* Gap Ack block start */
266 uint16_t end; /* Gap Ack block end */
270 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
271 uint32_t a_rwnd; /* updated a_rwnd of sender */
272 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
273 uint16_t num_dup_tsns; /* number of duplicate TSNs */
274 /* struct sctp_gap_ack_block's follow */
275 /* uint32_t duplicate_tsn's follow */
278 struct sctp_sack_chunk {
279 struct sctp_chunkhdr ch;
280 struct sctp_sack sack;
283 struct sctp_nr_sack {
284 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
285 uint32_t a_rwnd; /* updated a_rwnd of sender */
286 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
287 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
288 uint16_t num_dup_tsns; /* number of duplicate TSNs */
289 uint16_t reserved; /* not currently used */
290 /* struct sctp_gap_ack_block's follow */
291 /* uint32_t duplicate_tsn's follow */
294 struct sctp_nr_sack_chunk {
295 struct sctp_chunkhdr ch;
296 struct sctp_nr_sack nr_sack;
300 /* Heartbeat Request (HEARTBEAT) */
301 struct sctp_heartbeat {
302 struct sctp_heartbeat_info_param hb_info;
305 struct sctp_heartbeat_chunk {
306 struct sctp_chunkhdr ch;
307 struct sctp_heartbeat heartbeat;
310 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
311 #define sctp_heartbeat_ack sctp_heartbeat
312 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
315 /* Abort Asssociation (ABORT) */
316 struct sctp_abort_chunk {
317 struct sctp_chunkhdr ch;
318 /* optional error cause may follow */
321 struct sctp_abort_msg {
323 struct sctp_abort_chunk msg;
327 /* Shutdown Association (SHUTDOWN) */
328 struct sctp_shutdown_chunk {
329 struct sctp_chunkhdr ch;
330 uint32_t cumulative_tsn_ack;
334 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
335 struct sctp_shutdown_ack_chunk {
336 struct sctp_chunkhdr ch;
340 /* Operation Error (ERROR) */
341 struct sctp_error_chunk {
342 struct sctp_chunkhdr ch;
343 /* optional error causes follow */
347 /* Cookie Echo (COOKIE ECHO) */
348 struct sctp_cookie_echo_chunk {
349 struct sctp_chunkhdr ch;
350 struct sctp_state_cookie cookie;
353 /* Cookie Acknowledgment (COOKIE ACK) */
354 struct sctp_cookie_ack_chunk {
355 struct sctp_chunkhdr ch;
358 /* Explicit Congestion Notification Echo (ECNE) */
359 struct old_sctp_ecne_chunk {
360 struct sctp_chunkhdr ch;
364 struct sctp_ecne_chunk {
365 struct sctp_chunkhdr ch;
367 uint32_t num_pkts_since_cwr;
370 /* Congestion Window Reduced (CWR) */
371 struct sctp_cwr_chunk {
372 struct sctp_chunkhdr ch;
376 /* Shutdown Complete (SHUTDOWN COMPLETE) */
377 struct sctp_shutdown_complete_chunk {
378 struct sctp_chunkhdr ch;
381 /* Oper error holding a stale cookie */
382 struct sctp_stale_cookie_msg {
383 struct sctp_paramhdr ph;/* really an error cause */
387 struct sctp_adaptation_layer_indication {
388 struct sctp_paramhdr ph;
392 struct sctp_cookie_while_shutting_down {
394 struct sctp_chunkhdr ch;
395 struct sctp_paramhdr ph;/* really an error cause */
398 struct sctp_shutdown_complete_msg {
400 struct sctp_shutdown_complete_chunk shut_cmp;
404 * draft-ietf-tsvwg-addip-sctp
406 /* Address/Stream Configuration Change (ASCONF) */
407 struct sctp_asconf_chunk {
408 struct sctp_chunkhdr ch;
409 uint32_t serial_number;
410 /* lookup address parameter (mandatory) */
411 /* asconf parameters follow */
414 /* Address/Stream Configuration Acknowledge (ASCONF ACK) */
415 struct sctp_asconf_ack_chunk {
416 struct sctp_chunkhdr ch;
417 uint32_t serial_number;
418 /* asconf parameters follow */
421 /* draft-ietf-tsvwg-prsctp */
422 /* Forward Cumulative TSN (FORWARD TSN) */
423 struct sctp_forward_tsn_chunk {
424 struct sctp_chunkhdr ch;
425 uint32_t new_cumulative_tsn;
426 /* stream/sequence pairs (sctp_strseq) follow */
434 struct sctp_forward_tsn_msg {
436 struct sctp_forward_tsn_chunk msg;
439 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
441 #define SCTP_NUM_DB_TO_VERIFY 31
443 struct sctp_chunk_desc {
445 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
450 struct sctp_pktdrop_chunk {
451 struct sctp_chunkhdr ch;
453 uint32_t current_onq;
459 /**********STREAM RESET STUFF ******************/
461 struct sctp_stream_reset_out_request {
462 struct sctp_paramhdr ph;
463 uint32_t request_seq; /* monotonically increasing seq no */
464 uint32_t response_seq; /* if a response, the resp seq no */
465 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
466 uint16_t list_of_streams[]; /* if not all list of streams */
469 struct sctp_stream_reset_in_request {
470 struct sctp_paramhdr ph;
471 uint32_t request_seq;
472 uint16_t list_of_streams[]; /* if not all list of streams */
476 struct sctp_stream_reset_tsn_request {
477 struct sctp_paramhdr ph;
478 uint32_t request_seq;
481 struct sctp_stream_reset_response {
482 struct sctp_paramhdr ph;
483 uint32_t response_seq; /* if a response, the resp seq no */
487 struct sctp_stream_reset_response_tsn {
488 struct sctp_paramhdr ph;
489 uint32_t response_seq; /* if a response, the resp seq no */
491 uint32_t senders_next_tsn;
492 uint32_t receivers_next_tsn;
495 struct sctp_stream_reset_add_strm {
496 struct sctp_paramhdr ph;
497 uint32_t request_seq;
498 uint16_t number_of_streams;
502 #define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
503 #define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
504 #define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
505 #define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
506 #define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
507 #define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
508 #define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
511 * convience structures, note that if you are making a request for specific
512 * streams then the request will need to be an overlay structure.
515 struct sctp_stream_reset_out_req {
516 struct sctp_chunkhdr ch;
517 struct sctp_stream_reset_out_request sr_req;
520 struct sctp_stream_reset_in_req {
521 struct sctp_chunkhdr ch;
522 struct sctp_stream_reset_in_request sr_req;
525 struct sctp_stream_reset_tsn_req {
526 struct sctp_chunkhdr ch;
527 struct sctp_stream_reset_tsn_request sr_req;
530 struct sctp_stream_reset_resp {
531 struct sctp_chunkhdr ch;
532 struct sctp_stream_reset_response sr_resp;
535 /* respone only valid with a TSN request */
536 struct sctp_stream_reset_resp_tsn {
537 struct sctp_chunkhdr ch;
538 struct sctp_stream_reset_response_tsn sr_resp;
541 /****************************************************/
544 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
547 /* Should we make the max be 32? */
548 #define SCTP_RANDOM_MAX_SIZE 256
549 struct sctp_auth_random {
550 struct sctp_paramhdr ph;/* type = 0x8002 */
551 uint8_t random_data[];
554 struct sctp_auth_chunk_list {
555 struct sctp_paramhdr ph;/* type = 0x8003 */
556 uint8_t chunk_types[];
559 struct sctp_auth_hmac_algo {
560 struct sctp_paramhdr ph;/* type = 0x8004 */
564 struct sctp_auth_chunk {
565 struct sctp_chunkhdr ch;
566 uint16_t shared_key_id;
571 struct sctp_auth_invalid_hmac {
572 struct sctp_paramhdr ph;
578 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
579 * pieces. If ENCE is missing we could have a couple of blocks. This way we
580 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
581 * data chunk I will split into. We could increase throughput slightly by
582 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
583 * feel is worth it for now.
585 #ifndef SCTP_MAX_OVERHEAD
587 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
588 sizeof(struct sctphdr) + \
589 sizeof(struct sctp_ecne_chunk) + \
590 sizeof(struct sctp_sack_chunk) + \
591 sizeof(struct ip6_hdr))
593 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
594 sizeof(struct sctphdr) + \
595 sizeof(struct ip6_hdr))
598 #define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
599 sizeof(struct sctphdr))
602 #define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
603 sizeof(struct sctphdr) + \
604 sizeof(struct sctp_ecne_chunk) + \
605 sizeof(struct sctp_sack_chunk) + \
608 #define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
609 sizeof(struct sctphdr) + \
613 #define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
614 sizeof(struct sctphdr))
617 #endif /* !SCTP_MAX_OVERHEAD */
619 #define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
620 sizeof(struct sctphdr) + \
623 #define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
624 sizeof(struct sctphdr))
627 #endif /* !__sctp_header_h__ */