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