2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_header.h,v 1.14 2005/03/06 16:04:17 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #ifndef __sctp_header_h__
37 #define __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[SCTP_ARRAY_MIN_LEN]; /* array of supported address
87 struct sctp_ecn_supported_param {
88 struct sctp_paramhdr ph;/* type=SCTP_ECN_CAPABLE */
92 /* heartbeat info parameter */
93 struct sctp_heartbeat_info_param {
94 struct sctp_paramhdr ph;
95 uint32_t time_value_1;
96 uint32_t time_value_2;
97 uint32_t random_value1;
98 uint32_t random_value2;
102 char address[SCTP_ADDRMAX];
106 /* draft-ietf-tsvwg-prsctp */
107 /* PR-SCTP supported parameter */
108 struct sctp_prsctp_supported_param {
109 struct sctp_paramhdr ph;
113 /* draft-ietf-tsvwg-addip-sctp */
114 struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
115 struct sctp_paramhdr ph;/* a SCTP parameter header */
116 uint32_t correlation_id;/* correlation id for this param */
119 struct sctp_asconf_addr_param { /* an ASCONF address parameter */
120 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
121 struct sctp_ipv6addr_param addrp; /* max storage size */
124 struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
125 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
126 struct sctp_ipv4addr_param addrp; /* max storage size */
129 #define SCTP_MAX_SUPPORTED_EXT 256
131 struct sctp_supported_chunk_types_param {
132 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
133 uint8_t chunk_types[0];
137 /* ECN Nonce: draft-ladha-sctp-ecn-nonce */
138 struct sctp_ecn_nonce_supported_param {
139 struct sctp_paramhdr ph;/* type = 0x8001 len = 4 */
144 * Structures for DATA chunks
149 uint16_t stream_sequence;
150 uint32_t protocol_id;
151 /* user data follows */
154 struct sctp_data_chunk {
155 struct sctp_chunkhdr ch;
160 * Structures for the control chunks
163 /* Initiate (INIT)/Initiate Ack (INIT ACK) */
165 uint32_t initiate_tag; /* initiate tag */
166 uint32_t a_rwnd; /* a_rwnd */
167 uint16_t num_outbound_streams; /* OS */
168 uint16_t num_inbound_streams; /* MIS */
169 uint32_t initial_tsn; /* I-TSN */
170 /* optional param's follow */
173 #define SCTP_IDENTIFICATION_SIZE 16
174 #define SCTP_ADDRESS_SIZE 4
175 #define SCTP_RESERVE_SPACE 6
176 /* state cookie header */
177 struct sctp_state_cookie { /* this is our definition... */
178 uint8_t identification[SCTP_IDENTIFICATION_SIZE]; /* id of who we are */
179 struct timeval time_entered; /* the time I built cookie */
180 uint32_t cookie_life; /* life I will award this cookie */
181 uint32_t tie_tag_my_vtag; /* my tag in old association */
183 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
184 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
186 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
187 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
188 uint32_t addr_type; /* address type */
189 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
190 uint32_t laddr_type; /* my local from address type */
191 uint32_t scope_id; /* v6 scope id for link-locals */
193 uint16_t peerport; /* port address of the peer in the INIT */
194 uint16_t myport; /* my port address used in the INIT */
195 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
196 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
197 uint8_t local_scope; /* IPv6 local scope flag */
198 uint8_t site_scope; /* IPv6 site scope flag */
200 uint8_t ipv4_scope; /* IPv4 private addr scope */
201 uint8_t loopback_scope; /* loopback scope information */
202 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
204 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
205 * (minus the cookie).
209 struct sctp_inv_mandatory_param {
215 * We include this to 0 it since only a missing cookie will cause
221 struct sctp_unresolv_addr {
225 uint16_t reserved; /* Only one invalid addr type */
228 /* state cookie parameter */
229 struct sctp_state_cookie_param {
230 struct sctp_paramhdr ph;
231 struct sctp_state_cookie cookie;
234 struct sctp_init_chunk {
235 struct sctp_chunkhdr ch;
236 struct sctp_init init;
239 struct sctp_init_msg {
241 struct sctp_init_chunk msg;
244 /* ... used for both INIT and INIT ACK */
245 #define sctp_init_ack sctp_init
246 #define sctp_init_ack_chunk sctp_init_chunk
247 #define sctp_init_ack_msg sctp_init_msg
250 /* Selective Ack (SACK) */
251 struct sctp_gap_ack_block {
252 uint16_t start; /* Gap Ack block start */
253 uint16_t end; /* Gap Ack block end */
257 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
258 uint32_t a_rwnd; /* updated a_rwnd of sender */
259 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
260 uint16_t num_dup_tsns; /* number of duplicate TSNs */
261 /* struct sctp_gap_ack_block's follow */
262 /* uint32_t duplicate_tsn's follow */
265 struct sctp_sack_chunk {
266 struct sctp_chunkhdr ch;
267 struct sctp_sack sack;
271 /* Heartbeat Request (HEARTBEAT) */
272 struct sctp_heartbeat {
273 struct sctp_heartbeat_info_param hb_info;
276 struct sctp_heartbeat_chunk {
277 struct sctp_chunkhdr ch;
278 struct sctp_heartbeat heartbeat;
281 /* ... used for Heartbeat Ack (HEARTBEAT ACK) */
282 #define sctp_heartbeat_ack sctp_heartbeat
283 #define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
286 /* Abort Asssociation (ABORT) */
287 struct sctp_abort_chunk {
288 struct sctp_chunkhdr ch;
289 /* optional error cause may follow */
292 struct sctp_abort_msg {
294 struct sctp_abort_chunk msg;
298 /* Shutdown Association (SHUTDOWN) */
299 struct sctp_shutdown_chunk {
300 struct sctp_chunkhdr ch;
301 uint32_t cumulative_tsn_ack;
305 /* Shutdown Acknowledgment (SHUTDOWN ACK) */
306 struct sctp_shutdown_ack_chunk {
307 struct sctp_chunkhdr ch;
311 /* Operation Error (ERROR) */
312 struct sctp_error_chunk {
313 struct sctp_chunkhdr ch;
314 /* optional error causes follow */
318 /* Cookie Echo (COOKIE ECHO) */
319 struct sctp_cookie_echo_chunk {
320 struct sctp_chunkhdr ch;
321 struct sctp_state_cookie cookie;
324 /* Cookie Acknowledgment (COOKIE ACK) */
325 struct sctp_cookie_ack_chunk {
326 struct sctp_chunkhdr ch;
329 /* Explicit Congestion Notification Echo (ECNE) */
330 struct sctp_ecne_chunk {
331 struct sctp_chunkhdr ch;
335 /* Congestion Window Reduced (CWR) */
336 struct sctp_cwr_chunk {
337 struct sctp_chunkhdr ch;
341 /* Shutdown Complete (SHUTDOWN COMPLETE) */
342 struct sctp_shutdown_complete_chunk {
343 struct sctp_chunkhdr ch;
346 /* Oper error holding a stale cookie */
347 struct sctp_stale_cookie_msg {
348 struct sctp_paramhdr ph;/* really an error cause */
352 struct sctp_adaptation_layer_indication {
353 struct sctp_paramhdr ph;
357 struct sctp_cookie_while_shutting_down {
359 struct sctp_chunkhdr ch;
360 struct sctp_paramhdr ph;/* really an error cause */
363 struct sctp_shutdown_complete_msg {
365 struct sctp_shutdown_complete_chunk shut_cmp;
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_forward_tsn_msg {
401 struct sctp_forward_tsn_chunk msg;
404 /* should be a multiple of 4 - 1 aka 3/7/11 etc. */
406 #define SCTP_NUM_DB_TO_VERIFY 31
408 struct sctp_chunk_desc {
410 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
415 struct sctp_pktdrop_chunk {
416 struct sctp_chunkhdr ch;
418 uint32_t current_onq;
424 /**********STREAM RESET STUFF ******************/
426 struct sctp_stream_reset_out_request {
427 struct sctp_paramhdr ph;
428 uint32_t request_seq; /* monotonically increasing seq no */
429 uint32_t response_seq; /* if a response, the resp seq no */
430 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
431 uint16_t list_of_streams[0]; /* if not all list of streams */
434 struct sctp_stream_reset_in_request {
435 struct sctp_paramhdr ph;
436 uint32_t request_seq;
437 uint16_t list_of_streams[0]; /* if not all list of streams */
441 struct sctp_stream_reset_tsn_request {
442 struct sctp_paramhdr ph;
443 uint32_t request_seq;
446 struct sctp_stream_reset_response {
447 struct sctp_paramhdr ph;
448 uint32_t response_seq; /* if a response, the resp seq no */
452 struct sctp_stream_reset_response_tsn {
453 struct sctp_paramhdr ph;
454 uint32_t response_seq; /* if a response, the resp seq no */
456 uint32_t senders_next_tsn;
457 uint32_t receivers_next_tsn;
462 #define SCTP_STREAM_RESET_NOTHING 0x00000000 /* Nothing for me to do */
463 #define SCTP_STREAM_RESET_PERFORMED 0x00000001 /* Did it */
464 #define SCTP_STREAM_RESET_DENIED 0x00000002 /* refused to do it */
465 #define SCTP_STREAM_RESET_ERROR_STR 0x00000003 /* bad Stream no */
466 #define SCTP_STREAM_RESET_TRY_LATER 0x00000004 /* collision, try again */
467 #define SCTP_STREAM_RESET_BAD_SEQNO 0x00000005 /* bad str-reset seq no */
470 * convience structures, note that if you are making a request for specific
471 * streams then the request will need to be an overlay structure.
474 struct sctp_stream_reset_out_req {
475 struct sctp_chunkhdr ch;
476 struct sctp_stream_reset_out_request sr_req;
479 struct sctp_stream_reset_in_req {
480 struct sctp_chunkhdr ch;
481 struct sctp_stream_reset_in_request sr_req;
484 struct sctp_stream_reset_tsn_req {
485 struct sctp_chunkhdr ch;
486 struct sctp_stream_reset_tsn_request sr_req;
489 struct sctp_stream_reset_resp {
490 struct sctp_chunkhdr ch;
491 struct sctp_stream_reset_response sr_resp;
494 /* respone only valid with a TSN request */
495 struct sctp_stream_reset_resp_tsn {
496 struct sctp_chunkhdr ch;
497 struct sctp_stream_reset_response_tsn sr_resp;
500 /****************************************************/
503 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
506 /* Should we make the max be 32? */
507 #define SCTP_RANDOM_MAX_SIZE 256
508 struct sctp_auth_random {
509 struct sctp_paramhdr ph;/* type = 0x8002 */
510 uint8_t random_data[0];
513 struct sctp_auth_chunk_list {
514 struct sctp_paramhdr ph;/* type = 0x8003 */
515 uint8_t chunk_types[0];
518 struct sctp_auth_hmac_algo {
519 struct sctp_paramhdr ph;/* type = 0x8004 */
520 uint16_t hmac_ids[0];
523 struct sctp_auth_chunk {
524 struct sctp_chunkhdr ch;
525 uint16_t shared_key_id;
530 struct sctp_auth_invalid_hmac {
531 struct sctp_paramhdr ph;
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__ */