blob: 1019ee27b06a24c735d9d2432b1026f7feb30650 [file] [log] [blame]
James Kuszmaul4cb043c2021-01-17 11:25:51 -08001/*-
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.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
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.
15 *
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.
19 *
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.
31 */
32
33#ifdef __FreeBSD__
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 309682 2016-12-07 19:30:59Z tuexen $");
36#endif
37
38#ifndef _NETINET_SCTP_HEADER_H_
39#define _NETINET_SCTP_HEADER_H_
40
41#if defined(__Windows__) && !defined(__Userspace_os_Windows)
42#include <packon.h>
43#endif
44#if !defined(__Userspace_os_Windows)
45#include <sys/time.h>
46#endif
47#include <netinet/sctp.h>
48#include <netinet/sctp_constants.h>
49
50#if !defined(__Userspace_os_Windows)
51#define SCTP_PACKED __attribute__((packed))
52#else
53#pragma pack (push, 1)
54#define SCTP_PACKED
55#endif
56
57/*
58 * Parameter structures
59 */
60struct sctp_ipv4addr_param {
61 struct sctp_paramhdr ph;/* type=SCTP_IPV4_PARAM_TYPE, len=8 */
62 uint32_t addr; /* IPV4 address */
63} SCTP_PACKED;
64
65#define SCTP_V6_ADDR_BYTES 16
66
67
68struct sctp_ipv6addr_param {
69 struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
70 uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
71} SCTP_PACKED;
72
73/* Cookie Preservative */
74struct sctp_cookie_perserve_param {
75 struct sctp_paramhdr ph;/* type=SCTP_COOKIE_PRESERVE, len=8 */
76 uint32_t time; /* time in ms to extend cookie */
77} SCTP_PACKED;
78
79#define SCTP_ARRAY_MIN_LEN 1
80/* Host Name Address */
81struct sctp_host_name_param {
82 struct sctp_paramhdr ph;/* type=SCTP_HOSTNAME_ADDRESS */
83 char name[SCTP_ARRAY_MIN_LEN]; /* host name */
84} SCTP_PACKED;
85
86/*
87 * This is the maximum padded size of a s-a-p
88 * so paramheadr + 3 address types (6 bytes) + 2 byte pad = 12
89 */
90#define SCTP_MAX_ADDR_PARAMS_SIZE 12
91/* supported address type */
92struct sctp_supported_addr_param {
93 struct sctp_paramhdr ph;/* type=SCTP_SUPPORTED_ADDRTYPE */
94 uint16_t addr_type[2]; /* array of supported address types */
95} SCTP_PACKED;
96
97/* heartbeat info parameter */
98struct sctp_heartbeat_info_param {
99 struct sctp_paramhdr ph;
100 uint32_t time_value_1;
101 uint32_t time_value_2;
102 uint32_t random_value1;
103 uint32_t random_value2;
104 uint8_t addr_family;
105 uint8_t addr_len;
106 /* make sure that this structure is 4 byte aligned */
107 uint8_t padding[2];
108 char address[SCTP_ADDRMAX];
109} SCTP_PACKED;
110
111
112/* draft-ietf-tsvwg-prsctp */
113/* PR-SCTP supported parameter */
114struct sctp_prsctp_supported_param {
115 struct sctp_paramhdr ph;
116} SCTP_PACKED;
117
118
119/* draft-ietf-tsvwg-addip-sctp */
120struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
121 struct sctp_paramhdr ph;/* a SCTP parameter header */
122 uint32_t correlation_id;/* correlation id for this param */
123} SCTP_PACKED;
124
125struct sctp_asconf_addr_param { /* an ASCONF address parameter */
126 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
127 struct sctp_ipv6addr_param addrp; /* max storage size */
128} SCTP_PACKED;
129
130
131struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
132 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
133 uint32_t local_vtag;
134 uint32_t remote_vtag;
135} SCTP_PACKED;
136
137
138struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
139 struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
140 struct sctp_ipv4addr_param addrp; /* max storage size */
141} SCTP_PACKED;
142
143#define SCTP_MAX_SUPPORTED_EXT 256
144
145struct sctp_supported_chunk_types_param {
146 struct sctp_paramhdr ph;/* type = 0x8008 len = x */
147 uint8_t chunk_types[];
148} SCTP_PACKED;
149
150
151/*
152 * Structures for DATA chunks
153 */
154struct sctp_data {
155 uint32_t tsn;
156 uint16_t sid;
157 uint16_t ssn;
158 uint32_t ppid;
159 /* user data follows */
160} SCTP_PACKED;
161
162struct sctp_data_chunk {
163 struct sctp_chunkhdr ch;
164 struct sctp_data dp;
165} SCTP_PACKED;
166
167struct sctp_idata {
168 uint32_t tsn;
169 uint16_t sid;
170 uint16_t reserved; /* Where does the SSN go? */
171 uint32_t mid;
172 union {
173 uint32_t ppid;
174 uint32_t fsn; /* Fragment Sequence Number */
175 } ppid_fsn;
176 /* user data follows */
177} SCTP_PACKED;
178
179struct sctp_idata_chunk {
180 struct sctp_chunkhdr ch;
181 struct sctp_idata dp;
182} SCTP_PACKED;
183
184/*
185 * Structures for the control chunks
186 */
187
188/* Initiate (INIT)/Initiate Ack (INIT ACK) */
189struct sctp_init {
190 uint32_t initiate_tag; /* initiate tag */
191 uint32_t a_rwnd; /* a_rwnd */
192 uint16_t num_outbound_streams; /* OS */
193 uint16_t num_inbound_streams; /* MIS */
194 uint32_t initial_tsn; /* I-TSN */
195 /* optional param's follow */
196} SCTP_PACKED;
197#define SCTP_IDENTIFICATION_SIZE 16
198#define SCTP_ADDRESS_SIZE 4
199#if defined(__Userspace__)
200#define SCTP_RESERVE_SPACE 5
201#else
202#define SCTP_RESERVE_SPACE 6
203#endif
204/* state cookie header */
205struct sctp_state_cookie { /* this is our definition... */
206 uint8_t identification[SCTP_IDENTIFICATION_SIZE];/* id of who we are */
207 struct timeval time_entered; /* the time I built cookie */
208 uint32_t cookie_life; /* life I will award this cookie */
209 uint32_t tie_tag_my_vtag; /* my tag in old association */
210
211 uint32_t tie_tag_peer_vtag; /* peers tag in old association */
212 uint32_t peers_vtag; /* peers tag in INIT (for quick ref) */
213
214 uint32_t my_vtag; /* my tag in INIT-ACK (for quick ref) */
215 uint32_t address[SCTP_ADDRESS_SIZE]; /* 4 ints/128 bits */
216 uint32_t addr_type; /* address type */
217 uint32_t laddress[SCTP_ADDRESS_SIZE]; /* my local from address */
218 uint32_t laddr_type; /* my local from address type */
219 uint32_t scope_id; /* v6 scope id for link-locals */
220
221 uint16_t peerport; /* port address of the peer in the INIT */
222 uint16_t myport; /* my port address used in the INIT */
223 uint8_t ipv4_addr_legal;/* Are V4 addr legal? */
224 uint8_t ipv6_addr_legal;/* Are V6 addr legal? */
225#if defined(__Userspace__)
226 uint8_t conn_addr_legal;
227#endif
228 uint8_t local_scope; /* IPv6 local scope flag */
229 uint8_t site_scope; /* IPv6 site scope flag */
230
231 uint8_t ipv4_scope; /* IPv4 private addr scope */
232 uint8_t loopback_scope; /* loopback scope information */
233 uint8_t reserved[SCTP_RESERVE_SPACE]; /* Align to 64 bits */
234 /*
235 * at the end is tacked on the INIT chunk and the INIT-ACK chunk
236 * (minus the cookie).
237 */
238} SCTP_PACKED;
239
240/* state cookie parameter */
241struct sctp_state_cookie_param {
242 struct sctp_paramhdr ph;
243 struct sctp_state_cookie cookie;
244} SCTP_PACKED;
245
246struct sctp_init_chunk {
247 struct sctp_chunkhdr ch;
248 struct sctp_init init;
249} SCTP_PACKED;
250
251struct sctp_init_msg {
252 struct sctphdr sh;
253 struct sctp_init_chunk msg;
254} SCTP_PACKED;
255
256/* ... used for both INIT and INIT ACK */
257#define sctp_init_ack sctp_init
258#define sctp_init_ack_chunk sctp_init_chunk
259#define sctp_init_ack_msg sctp_init_msg
260
261
262/* Selective Ack (SACK) */
263struct sctp_gap_ack_block {
264 uint16_t start; /* Gap Ack block start */
265 uint16_t end; /* Gap Ack block end */
266} SCTP_PACKED;
267
268struct sctp_sack {
269 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
270 uint32_t a_rwnd; /* updated a_rwnd of sender */
271 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
272 uint16_t num_dup_tsns; /* number of duplicate TSNs */
273 /* struct sctp_gap_ack_block's follow */
274 /* uint32_t duplicate_tsn's follow */
275} SCTP_PACKED;
276
277struct sctp_sack_chunk {
278 struct sctp_chunkhdr ch;
279 struct sctp_sack sack;
280} SCTP_PACKED;
281
282struct sctp_nr_sack {
283 uint32_t cum_tsn_ack; /* cumulative TSN Ack */
284 uint32_t a_rwnd; /* updated a_rwnd of sender */
285 uint16_t num_gap_ack_blks; /* number of Gap Ack blocks */
286 uint16_t num_nr_gap_ack_blks; /* number of NR Gap Ack blocks */
287 uint16_t num_dup_tsns; /* number of duplicate TSNs */
288 uint16_t reserved; /* not currently used*/
289 /* struct sctp_gap_ack_block's follow */
290 /* uint32_t duplicate_tsn's follow */
291} SCTP_PACKED;
292
293struct sctp_nr_sack_chunk {
294 struct sctp_chunkhdr ch;
295 struct sctp_nr_sack nr_sack;
296} SCTP_PACKED;
297
298
299/* Heartbeat Request (HEARTBEAT) */
300struct sctp_heartbeat {
301 struct sctp_heartbeat_info_param hb_info;
302} SCTP_PACKED;
303
304struct sctp_heartbeat_chunk {
305 struct sctp_chunkhdr ch;
306 struct sctp_heartbeat heartbeat;
307} SCTP_PACKED;
308
309/* ... used for Heartbeat Ack (HEARTBEAT ACK) */
310#define sctp_heartbeat_ack sctp_heartbeat
311#define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
312
313
314/* Abort Asssociation (ABORT) */
315struct sctp_abort_chunk {
316 struct sctp_chunkhdr ch;
317 /* optional error cause may follow */
318} SCTP_PACKED;
319
320struct sctp_abort_msg {
321 struct sctphdr sh;
322 struct sctp_abort_chunk msg;
323} SCTP_PACKED;
324
325
326/* Shutdown Association (SHUTDOWN) */
327struct sctp_shutdown_chunk {
328 struct sctp_chunkhdr ch;
329 uint32_t cumulative_tsn_ack;
330} SCTP_PACKED;
331
332
333/* Shutdown Acknowledgment (SHUTDOWN ACK) */
334struct sctp_shutdown_ack_chunk {
335 struct sctp_chunkhdr ch;
336} SCTP_PACKED;
337
338
339/* Operation Error (ERROR) */
340struct sctp_error_chunk {
341 struct sctp_chunkhdr ch;
342 /* optional error causes follow */
343} SCTP_PACKED;
344
345
346/* Cookie Echo (COOKIE ECHO) */
347struct sctp_cookie_echo_chunk {
348 struct sctp_chunkhdr ch;
349 struct sctp_state_cookie cookie;
350} SCTP_PACKED;
351
352/* Cookie Acknowledgment (COOKIE ACK) */
353struct sctp_cookie_ack_chunk {
354 struct sctp_chunkhdr ch;
355} SCTP_PACKED;
356
357/* Explicit Congestion Notification Echo (ECNE) */
358struct old_sctp_ecne_chunk {
359 struct sctp_chunkhdr ch;
360 uint32_t tsn;
361} SCTP_PACKED;
362
363struct sctp_ecne_chunk {
364 struct sctp_chunkhdr ch;
365 uint32_t tsn;
366 uint32_t num_pkts_since_cwr;
367} SCTP_PACKED;
368
369/* Congestion Window Reduced (CWR) */
370struct sctp_cwr_chunk {
371 struct sctp_chunkhdr ch;
372 uint32_t tsn;
373} SCTP_PACKED;
374
375/* Shutdown Complete (SHUTDOWN COMPLETE) */
376struct sctp_shutdown_complete_chunk {
377 struct sctp_chunkhdr ch;
378} SCTP_PACKED;
379
380struct sctp_adaptation_layer_indication {
381 struct sctp_paramhdr ph;
382 uint32_t indication;
383} SCTP_PACKED;
384
385/*
386 * draft-ietf-tsvwg-addip-sctp
387 */
388/* Address/Stream Configuration Change (ASCONF) */
389struct sctp_asconf_chunk {
390 struct sctp_chunkhdr ch;
391 uint32_t serial_number;
392 /* lookup address parameter (mandatory) */
393 /* asconf parameters follow */
394} SCTP_PACKED;
395
396/* Address/Stream Configuration Acknowledge (ASCONF ACK) */
397struct sctp_asconf_ack_chunk {
398 struct sctp_chunkhdr ch;
399 uint32_t serial_number;
400 /* asconf parameters follow */
401} SCTP_PACKED;
402
403/* draft-ietf-tsvwg-prsctp */
404/* Forward Cumulative TSN (FORWARD TSN) */
405struct sctp_forward_tsn_chunk {
406 struct sctp_chunkhdr ch;
407 uint32_t new_cumulative_tsn;
408 /* stream/sequence pairs (sctp_strseq) follow */
409} SCTP_PACKED;
410
411struct sctp_strseq {
412 uint16_t sid;
413 uint16_t ssn;
414} SCTP_PACKED;
415
416struct sctp_strseq_mid {
417 uint16_t sid;
418 uint16_t flags;
419 uint32_t mid;
420};
421
422struct sctp_forward_tsn_msg {
423 struct sctphdr sh;
424 struct sctp_forward_tsn_chunk msg;
425} SCTP_PACKED;
426
427/* should be a multiple of 4 - 1 aka 3/7/11 etc. */
428
429#define SCTP_NUM_DB_TO_VERIFY 31
430
431struct sctp_chunk_desc {
432 uint8_t chunk_type;
433 uint8_t data_bytes[SCTP_NUM_DB_TO_VERIFY];
434 uint32_t tsn_ifany;
435} SCTP_PACKED;
436
437
438struct sctp_pktdrop_chunk {
439 struct sctp_chunkhdr ch;
440 uint32_t bottle_bw;
441 uint32_t current_onq;
442 uint16_t trunc_len;
443 uint16_t reserved;
444 uint8_t data[];
445} SCTP_PACKED;
446
447/**********STREAM RESET STUFF ******************/
448
449struct sctp_stream_reset_request {
450 struct sctp_paramhdr ph;
451 uint32_t request_seq;
452} SCTP_PACKED;
453
454struct sctp_stream_reset_out_request {
455 struct sctp_paramhdr ph;
456 uint32_t request_seq; /* monotonically increasing seq no */
457 uint32_t response_seq; /* if a response, the resp seq no */
458 uint32_t send_reset_at_tsn; /* last TSN I assigned outbound */
459 uint16_t list_of_streams[]; /* if not all list of streams */
460} SCTP_PACKED;
461
462struct sctp_stream_reset_in_request {
463 struct sctp_paramhdr ph;
464 uint32_t request_seq;
465 uint16_t list_of_streams[]; /* if not all list of streams */
466} SCTP_PACKED;
467
468struct sctp_stream_reset_tsn_request {
469 struct sctp_paramhdr ph;
470 uint32_t request_seq;
471} SCTP_PACKED;
472
473struct sctp_stream_reset_response {
474 struct sctp_paramhdr ph;
475 uint32_t response_seq; /* if a response, the resp seq no */
476 uint32_t result;
477} SCTP_PACKED;
478
479struct sctp_stream_reset_response_tsn {
480 struct sctp_paramhdr ph;
481 uint32_t response_seq; /* if a response, the resp seq no */
482 uint32_t result;
483 uint32_t senders_next_tsn;
484 uint32_t receivers_next_tsn;
485} SCTP_PACKED;
486
487struct sctp_stream_reset_add_strm {
488 struct sctp_paramhdr ph;
489 uint32_t request_seq;
490 uint16_t number_of_streams;
491 uint16_t reserved;
492} SCTP_PACKED;
493
494#define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
495#define SCTP_STREAM_RESET_RESULT_PERFORMED 0x00000001
496#define SCTP_STREAM_RESET_RESULT_DENIED 0x00000002
497#define SCTP_STREAM_RESET_RESULT_ERR__WRONG_SSN 0x00000003 /* XXX: unused */
498#define SCTP_STREAM_RESET_RESULT_ERR_IN_PROGRESS 0x00000004
499#define SCTP_STREAM_RESET_RESULT_ERR_BAD_SEQNO 0x00000005
500#define SCTP_STREAM_RESET_RESULT_IN_PROGRESS 0x00000006 /* XXX: unused */
501
502/*
503 * convience structures, note that if you are making a request for specific
504 * streams then the request will need to be an overlay structure.
505 */
506
507struct sctp_stream_reset_tsn_req {
508 struct sctp_chunkhdr ch;
509 struct sctp_stream_reset_tsn_request sr_req;
510} SCTP_PACKED;
511
512struct sctp_stream_reset_resp {
513 struct sctp_chunkhdr ch;
514 struct sctp_stream_reset_response sr_resp;
515} SCTP_PACKED;
516
517/* respone only valid with a TSN request */
518struct sctp_stream_reset_resp_tsn {
519 struct sctp_chunkhdr ch;
520 struct sctp_stream_reset_response_tsn sr_resp;
521} SCTP_PACKED;
522
523/****************************************************/
524
525/*
526 * Authenticated chunks support draft-ietf-tsvwg-sctp-auth
527 */
528
529/* Should we make the max be 32? */
530#define SCTP_RANDOM_MAX_SIZE 256
531struct sctp_auth_random {
532 struct sctp_paramhdr ph;/* type = 0x8002 */
533 uint8_t random_data[];
534} SCTP_PACKED;
535
536struct sctp_auth_chunk_list {
537 struct sctp_paramhdr ph;/* type = 0x8003 */
538 uint8_t chunk_types[];
539} SCTP_PACKED;
540
541struct sctp_auth_hmac_algo {
542 struct sctp_paramhdr ph;/* type = 0x8004 */
543 uint16_t hmac_ids[];
544} SCTP_PACKED;
545
546struct sctp_auth_chunk {
547 struct sctp_chunkhdr ch;
548 uint16_t shared_key_id;
549 uint16_t hmac_id;
550 uint8_t hmac[];
551} SCTP_PACKED;
552
553/*
554 * we pre-reserve enough room for a ECNE or CWR AND a SACK with no missing
555 * pieces. If ENCE is missing we could have a couple of blocks. This way we
556 * optimize so we MOST likely can bundle a SACK/ECN with the smallest size
557 * data chunk I will split into. We could increase throughput slightly by
558 * taking out these two but the 24-sack/8-CWR i.e. 32 bytes I pre-reserve I
559 * feel is worth it for now.
560 */
561#ifndef SCTP_MAX_OVERHEAD
562#ifdef INET6
563#define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
564 sizeof(struct sctphdr) + \
565 sizeof(struct sctp_ecne_chunk) + \
566 sizeof(struct sctp_sack_chunk) + \
567 sizeof(struct ip6_hdr))
568
569#define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
570 sizeof(struct sctphdr) + \
571 sizeof(struct ip6_hdr))
572
573
574#define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
575 sizeof(struct sctphdr))
576
577#else
578#define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
579 sizeof(struct sctphdr) + \
580 sizeof(struct sctp_ecne_chunk) + \
581 sizeof(struct sctp_sack_chunk) + \
582 sizeof(struct ip))
583
584#define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
585 sizeof(struct sctphdr) + \
586 sizeof(struct ip))
587
588
589#define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
590 sizeof(struct sctphdr))
591
592#endif /* INET6 */
593#endif /* !SCTP_MAX_OVERHEAD */
594
595#define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
596 sizeof(struct sctphdr) + \
597 sizeof(struct ip))
598
599#define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
600 sizeof(struct sctphdr))
601
602#if defined(__Windows__)
603#include <packoff.h>
604#endif
605#if defined(__Userspace_os_Windows)
606#pragma pack ()
607#endif
608#undef SCTP_PACKED
609#endif /* !__sctp_header_h__ */