1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * a) Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  *
14  * b) Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the distribution.
17  *
18  * c) Neither the name of Cisco Systems, Inc. nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #if defined(__FreeBSD__) && !defined(__Userspace__)
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD: head/sys/netinet/sctp_uio.h 362473 2020-06-21 23:12:56Z tuexen $");
38 #endif
39 
40 #ifndef _NETINET_SCTP_UIO_H_
41 #define _NETINET_SCTP_UIO_H_
42 
43 #if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
44 #ifndef _KERNEL
45 #define _KERNEL
46 #endif
47 #endif
48 
49 #if !defined(_WIN32)
50 #if !defined(_KERNEL)
51 #include <stdint.h>
52 #endif
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
56 #endif
57 #if defined(_WIN32) && !defined(__Userspace__)
58 #pragma warning(push)
59 #pragma warning(disable: 4200)
60 #if defined(_KERNEL)
61 #include <sys/types.h>
62 #include <sys/socket.h>
63 #include <netinet/in.h>
64 #endif
65 #endif
66 
67 typedef uint32_t sctp_assoc_t;
68 
69 #define SCTP_FUTURE_ASSOC  0
70 #define SCTP_CURRENT_ASSOC 1
71 #define SCTP_ALL_ASSOC     2
72 
73 struct sctp_event {
74 	sctp_assoc_t se_assoc_id;
75 	uint16_t     se_type;
76 	uint8_t      se_on;
77 };
78 
79 /* Compatibility to previous define's */
80 #define sctp_stream_reset_events sctp_stream_reset_event
81 
82 /* On/Off setup for subscription to events */
83 struct sctp_event_subscribe {
84 	uint8_t sctp_data_io_event;
85 	uint8_t sctp_association_event;
86 	uint8_t sctp_address_event;
87 	uint8_t sctp_send_failure_event;
88 	uint8_t sctp_peer_error_event;
89 	uint8_t sctp_shutdown_event;
90 	uint8_t sctp_partial_delivery_event;
91 	uint8_t sctp_adaptation_layer_event;
92 	uint8_t sctp_authentication_event;
93 	uint8_t sctp_sender_dry_event;
94 	uint8_t sctp_stream_reset_event;
95 };
96 
97 /* ancillary data types */
98 #define SCTP_INIT	0x0001
99 #define SCTP_SNDRCV	0x0002
100 #define SCTP_EXTRCV	0x0003
101 #define SCTP_SNDINFO    0x0004
102 #define SCTP_RCVINFO    0x0005
103 #define SCTP_NXTINFO    0x0006
104 #define SCTP_PRINFO     0x0007
105 #define SCTP_AUTHINFO   0x0008
106 #define SCTP_DSTADDRV4  0x0009
107 #define SCTP_DSTADDRV6  0x000a
108 
109 /*
110  * ancillary data structures
111  */
112 struct sctp_initmsg {
113 	uint16_t sinit_num_ostreams;
114 	uint16_t sinit_max_instreams;
115 	uint16_t sinit_max_attempts;
116 	uint16_t sinit_max_init_timeo;
117 };
118 
119 /* We add 96 bytes to the size of sctp_sndrcvinfo.
120  * This makes the current structure 128 bytes long
121  * which is nicely 64 bit aligned but also has room
122  * for us to add more and keep ABI compatibility.
123  * For example, already we have the sctp_extrcvinfo
124  * when enabled which is 48 bytes.
125  */
126 
127 /*
128  * The assoc up needs a verfid
129  * all sendrcvinfo's need a verfid for SENDING only.
130  */
131 
132 
133 #define SCTP_ALIGN_RESV_PAD 92
134 #define SCTP_ALIGN_RESV_PAD_SHORT 76
135 
136 struct sctp_sndrcvinfo {
137 	uint16_t sinfo_stream;
138 	uint16_t sinfo_ssn;
139 	uint16_t sinfo_flags;
140 	uint32_t sinfo_ppid;
141 	uint32_t sinfo_context;
142 	uint32_t sinfo_timetolive;
143 	uint32_t sinfo_tsn;
144 	uint32_t sinfo_cumtsn;
145 	sctp_assoc_t sinfo_assoc_id;
146 	uint16_t sinfo_keynumber;
147 	uint16_t sinfo_keynumber_valid;
148 	uint8_t  __reserve_pad[SCTP_ALIGN_RESV_PAD];
149 };
150 
151 struct sctp_extrcvinfo {
152 	uint16_t sinfo_stream;
153 	uint16_t sinfo_ssn;
154 	uint16_t sinfo_flags;
155 	uint32_t sinfo_ppid;
156 	uint32_t sinfo_context;
157 	uint32_t sinfo_timetolive; /* should have been sinfo_pr_value */
158 	uint32_t sinfo_tsn;
159 	uint32_t sinfo_cumtsn;
160 	sctp_assoc_t sinfo_assoc_id;
161 	uint16_t serinfo_next_flags;
162 	uint16_t serinfo_next_stream;
163 	uint32_t serinfo_next_aid;
164 	uint32_t serinfo_next_length;
165 	uint32_t serinfo_next_ppid;
166 	uint16_t sinfo_keynumber;
167 	uint16_t sinfo_keynumber_valid;
168 	uint8_t  __reserve_pad[SCTP_ALIGN_RESV_PAD_SHORT];
169 };
170 #define sinfo_pr_value sinfo_timetolive
171 #define sreinfo_next_flags serinfo_next_flags
172 #define sreinfo_next_stream serinfo_next_stream
173 #define sreinfo_next_aid serinfo_next_aid
174 #define sreinfo_next_length serinfo_next_length
175 #define sreinfo_next_ppid serinfo_next_ppid
176 
177 struct sctp_sndinfo {
178 	uint16_t snd_sid;
179 	uint16_t snd_flags;
180 	uint32_t snd_ppid;
181 	uint32_t snd_context;
182 	sctp_assoc_t snd_assoc_id;
183 };
184 
185 struct sctp_prinfo {
186 	uint16_t pr_policy;
187 	uint32_t pr_value;
188 };
189 
190 struct sctp_default_prinfo {
191 	uint16_t pr_policy;
192 	uint32_t pr_value;
193 	sctp_assoc_t pr_assoc_id;
194 };
195 
196 struct sctp_authinfo {
197 	uint16_t auth_keynumber;
198 };
199 
200 struct sctp_rcvinfo {
201 	uint16_t rcv_sid;
202 	uint16_t rcv_ssn;
203 	uint16_t rcv_flags;
204 	uint32_t rcv_ppid;
205 	uint32_t rcv_tsn;
206 	uint32_t rcv_cumtsn;
207 	uint32_t rcv_context;
208 	sctp_assoc_t rcv_assoc_id;
209 };
210 
211 struct sctp_nxtinfo {
212 	uint16_t nxt_sid;
213 	uint16_t nxt_flags;
214 	uint32_t nxt_ppid;
215 	uint32_t nxt_length;
216 	sctp_assoc_t nxt_assoc_id;
217 };
218 
219 #define SCTP_NO_NEXT_MSG           0x0000
220 #define SCTP_NEXT_MSG_AVAIL        0x0001
221 #define SCTP_NEXT_MSG_ISCOMPLETE   0x0002
222 #define SCTP_NEXT_MSG_IS_UNORDERED 0x0004
223 #define SCTP_NEXT_MSG_IS_NOTIFICATION 0x0008
224 
225 struct sctp_recvv_rn {
226 	struct sctp_rcvinfo recvv_rcvinfo;
227 	struct sctp_nxtinfo recvv_nxtinfo;
228 };
229 
230 #define SCTP_RECVV_NOINFO  0
231 #define SCTP_RECVV_RCVINFO 1
232 #define SCTP_RECVV_NXTINFO 2
233 #define SCTP_RECVV_RN      3
234 
235 #define SCTP_SENDV_NOINFO   0
236 #define SCTP_SENDV_SNDINFO  1
237 #define SCTP_SENDV_PRINFO   2
238 #define SCTP_SENDV_AUTHINFO 3
239 #define SCTP_SENDV_SPA      4
240 
241 struct sctp_sendv_spa {
242 	uint32_t sendv_flags;
243 	struct sctp_sndinfo sendv_sndinfo;
244 	struct sctp_prinfo sendv_prinfo;
245 	struct sctp_authinfo sendv_authinfo;
246 };
247 
248 #define SCTP_SEND_SNDINFO_VALID  0x00000001
249 #define SCTP_SEND_PRINFO_VALID   0x00000002
250 #define SCTP_SEND_AUTHINFO_VALID 0x00000004
251 
252 struct sctp_snd_all_completes {
253 	uint16_t sall_stream;
254 	uint16_t sall_flags;
255 	uint32_t sall_ppid;
256 	uint32_t sall_context;
257 	uint32_t sall_num_sent;
258 	uint32_t sall_num_failed;
259 };
260 
261 /* Flags that go into the sinfo->sinfo_flags field */
262 #define SCTP_NOTIFICATION     0x0010 /* next message is a notification */
263 #define SCTP_COMPLETE         0x0020 /* next message is complete */
264 #define SCTP_EOF              0x0100 /* Start shutdown procedures */
265 #define SCTP_ABORT            0x0200 /* Send an ABORT to peer */
266 #define SCTP_UNORDERED        0x0400 /* Message is un-ordered */
267 #define SCTP_ADDR_OVER        0x0800 /* Override the primary-address */
268 #define SCTP_SENDALL          0x1000 /* Send this on all associations */
269 #define SCTP_EOR              0x2000 /* end of message signal */
270 #define SCTP_SACK_IMMEDIATELY 0x4000 /* Set I-Bit */
271 
272 #define INVALID_SINFO_FLAG(x) (((x) & 0xfffffff0 \
273                                     & ~(SCTP_EOF | SCTP_ABORT | SCTP_UNORDERED |\
274 				        SCTP_ADDR_OVER | SCTP_SENDALL | SCTP_EOR |\
275 					SCTP_SACK_IMMEDIATELY)) != 0)
276 /* for the endpoint */
277 
278 /* The lower four bits is an enumeration of PR-SCTP policies */
279 #define SCTP_PR_SCTP_NONE 0x0000 /* Reliable transfer */
280 #define SCTP_PR_SCTP_TTL  0x0001 /* Time based PR-SCTP */
281 #define SCTP_PR_SCTP_PRIO 0x0002 /* Buffer based PR-SCTP */
282 #define SCTP_PR_SCTP_BUF  SCTP_PR_SCTP_PRIO /* For backwards compatibility */
283 #define SCTP_PR_SCTP_RTX  0x0003 /* Number of retransmissions based PR-SCTP */
284 #define SCTP_PR_SCTP_MAX  SCTP_PR_SCTP_RTX
285 #define SCTP_PR_SCTP_ALL  0x000f /* Used for aggregated stats */
286 
287 #define PR_SCTP_POLICY(x)         ((x) & 0x0f)
288 #define PR_SCTP_ENABLED(x)        ((PR_SCTP_POLICY(x) != SCTP_PR_SCTP_NONE) && \
289                                    (PR_SCTP_POLICY(x) != SCTP_PR_SCTP_ALL))
290 #define PR_SCTP_TTL_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_TTL)
291 #define PR_SCTP_BUF_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_BUF)
292 #define PR_SCTP_RTX_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_RTX)
293 #define PR_SCTP_INVALID_POLICY(x) (PR_SCTP_POLICY(x) > SCTP_PR_SCTP_MAX)
294 #define PR_SCTP_VALID_POLICY(x)   (PR_SCTP_POLICY(x) <= SCTP_PR_SCTP_MAX)
295 
296 /* Stat's */
297 struct sctp_pcbinfo {
298 	uint32_t ep_count;
299 	uint32_t asoc_count;
300 	uint32_t laddr_count;
301 	uint32_t raddr_count;
302 	uint32_t chk_count;
303 	uint32_t readq_count;
304 	uint32_t free_chunks;
305 	uint32_t stream_oque;
306 };
307 
308 struct sctp_sockstat {
309 	sctp_assoc_t ss_assoc_id;
310 	uint32_t ss_total_sndbuf;
311 	uint32_t ss_total_recv_buf;
312 };
313 
314 /*
315  * notification event structures
316  */
317 
318 /*
319  * association change event
320  */
321 struct sctp_assoc_change {
322 	uint16_t sac_type;
323 	uint16_t sac_flags;
324 	uint32_t sac_length;
325 	uint16_t sac_state;
326 	uint16_t sac_error;
327 	uint16_t sac_outbound_streams;
328 	uint16_t sac_inbound_streams;
329 	sctp_assoc_t sac_assoc_id;
330 	uint8_t sac_info[];
331 };
332 
333 /* sac_state values */
334 #define SCTP_COMM_UP            0x0001
335 #define SCTP_COMM_LOST          0x0002
336 #define SCTP_RESTART            0x0003
337 #define SCTP_SHUTDOWN_COMP      0x0004
338 #define SCTP_CANT_STR_ASSOC     0x0005
339 
340 /* sac_info values */
341 #define SCTP_ASSOC_SUPPORTS_PR			0x01
342 #define SCTP_ASSOC_SUPPORTS_AUTH		0x02
343 #define SCTP_ASSOC_SUPPORTS_ASCONF		0x03
344 #define SCTP_ASSOC_SUPPORTS_MULTIBUF		0x04
345 #define SCTP_ASSOC_SUPPORTS_RE_CONFIG		0x05
346 #define SCTP_ASSOC_SUPPORTS_INTERLEAVING	0x06
347 #define SCTP_ASSOC_SUPPORTS_MAX			0x06
348 /*
349  * Address event
350  */
351 struct sctp_paddr_change {
352 	uint16_t spc_type;
353 	uint16_t spc_flags;
354 	uint32_t spc_length;
355 	struct sockaddr_storage spc_aaddr;
356 	uint32_t spc_state;
357 	uint32_t spc_error;
358 	sctp_assoc_t spc_assoc_id;
359 };
360 
361 /* paddr state values */
362 #define SCTP_ADDR_AVAILABLE	0x0001
363 #define SCTP_ADDR_UNREACHABLE	0x0002
364 #define SCTP_ADDR_REMOVED	0x0003
365 #define SCTP_ADDR_ADDED		0x0004
366 #define SCTP_ADDR_MADE_PRIM	0x0005
367 #define SCTP_ADDR_CONFIRMED	0x0006
368 
369 #define SCTP_ACTIVE		0x0001	/* SCTP_ADDR_REACHABLE */
370 #define SCTP_INACTIVE		0x0002	/* neither SCTP_ADDR_REACHABLE
371 					   nor SCTP_ADDR_UNCONFIRMED */
372 #define SCTP_UNCONFIRMED	0x0200	/* SCTP_ADDR_UNCONFIRMED */
373 
374 /* remote error events */
375 struct sctp_remote_error {
376 	uint16_t sre_type;
377 	uint16_t sre_flags;
378 	uint32_t sre_length;
379 	uint16_t sre_error;
380 	sctp_assoc_t sre_assoc_id;
381 	uint8_t sre_data[];
382 };
383 
384 /* data send failure event (deprecated) */
385 struct sctp_send_failed {
386 	uint16_t ssf_type;
387 	uint16_t ssf_flags;
388 	uint32_t ssf_length;
389 	uint32_t ssf_error;
390 	struct sctp_sndrcvinfo ssf_info;
391 	sctp_assoc_t ssf_assoc_id;
392 	uint8_t ssf_data[];
393 };
394 
395 /* data send failure event (not deprecated) */
396 struct sctp_send_failed_event {
397 	uint16_t ssfe_type;
398 	uint16_t ssfe_flags;
399 	uint32_t ssfe_length;
400 	uint32_t ssfe_error;
401 	struct sctp_sndinfo ssfe_info;
402 	sctp_assoc_t ssfe_assoc_id;
403 	uint8_t  ssfe_data[];
404 };
405 
406 /* flag that indicates state of data */
407 #define SCTP_DATA_UNSENT	0x0001	/* inqueue never on wire */
408 #define SCTP_DATA_SENT		0x0002	/* on wire at failure */
409 
410 /* shutdown event */
411 struct sctp_shutdown_event {
412 	uint16_t sse_type;
413 	uint16_t sse_flags;
414 	uint32_t sse_length;
415 	sctp_assoc_t sse_assoc_id;
416 };
417 
418 /* Adaptation layer indication stuff */
419 struct sctp_adaptation_event {
420 	uint16_t sai_type;
421 	uint16_t sai_flags;
422 	uint32_t sai_length;
423 	uint32_t sai_adaptation_ind;
424 	sctp_assoc_t sai_assoc_id;
425 };
426 
427 struct sctp_setadaptation {
428 	uint32_t ssb_adaptation_ind;
429 };
430 
431 /* compatible old spelling */
432 struct sctp_adaption_event {
433 	uint16_t sai_type;
434 	uint16_t sai_flags;
435 	uint32_t sai_length;
436 	uint32_t sai_adaption_ind;
437 	sctp_assoc_t sai_assoc_id;
438 };
439 
440 struct sctp_setadaption {
441 	uint32_t ssb_adaption_ind;
442 };
443 
444 
445 /*
446  * Partial Delivery API event
447  */
448 struct sctp_pdapi_event {
449 	uint16_t pdapi_type;
450 	uint16_t pdapi_flags;
451 	uint32_t pdapi_length;
452 	uint32_t pdapi_indication;
453 	uint16_t pdapi_stream;
454 	uint16_t pdapi_seq;
455 	sctp_assoc_t pdapi_assoc_id;
456 };
457 
458 /* indication values */
459 #define SCTP_PARTIAL_DELIVERY_ABORTED	0x0001
460 
461 
462 /*
463  * authentication key event
464  */
465 struct sctp_authkey_event {
466 	uint16_t auth_type;
467 	uint16_t auth_flags;
468 	uint32_t auth_length;
469 	uint16_t auth_keynumber;
470 	uint16_t auth_altkeynumber;
471 	uint32_t auth_indication;
472 	sctp_assoc_t auth_assoc_id;
473 };
474 
475 /* indication values */
476 #define SCTP_AUTH_NEW_KEY	0x0001
477 #define SCTP_AUTH_NEWKEY	SCTP_AUTH_NEW_KEY
478 #define SCTP_AUTH_NO_AUTH	0x0002
479 #define SCTP_AUTH_FREE_KEY	0x0003
480 
481 
482 struct sctp_sender_dry_event {
483 	uint16_t sender_dry_type;
484 	uint16_t sender_dry_flags;
485 	uint32_t sender_dry_length;
486 	sctp_assoc_t sender_dry_assoc_id;
487 };
488 
489 
490 /*
491  * Stream reset event - subscribe to SCTP_STREAM_RESET_EVENT
492  */
493 struct sctp_stream_reset_event {
494 	uint16_t strreset_type;
495 	uint16_t strreset_flags;
496 	uint32_t strreset_length;
497 	sctp_assoc_t strreset_assoc_id;
498 	uint16_t strreset_stream_list[];
499 };
500 
501 /* flags in stream_reset_event (strreset_flags) */
502 #define SCTP_STREAM_RESET_INCOMING_SSN  0x0001
503 #define SCTP_STREAM_RESET_OUTGOING_SSN  0x0002
504 #define SCTP_STREAM_RESET_DENIED        0x0004
505 #define SCTP_STREAM_RESET_FAILED        0x0008
506 
507 /*
508  * Assoc reset event - subscribe to SCTP_ASSOC_RESET_EVENT
509  */
510 struct sctp_assoc_reset_event {
511 	uint16_t 	assocreset_type;
512 	uint16_t	assocreset_flags;
513 	uint32_t	assocreset_length;
514 	sctp_assoc_t	assocreset_assoc_id;
515 	uint32_t	assocreset_local_tsn;
516 	uint32_t	assocreset_remote_tsn;
517 };
518 
519 #define SCTP_ASSOC_RESET_DENIED		0x0004
520 #define SCTP_ASSOC_RESET_FAILED		0x0008
521 
522 /*
523  * Stream change event - subscribe to SCTP_STREAM_CHANGE_EVENT
524  */
525 struct sctp_stream_change_event {
526 	uint16_t	strchange_type;
527 	uint16_t	strchange_flags;
528 	uint32_t	strchange_length;
529 	sctp_assoc_t	strchange_assoc_id;
530 	uint16_t	strchange_instrms;
531 	uint16_t	strchange_outstrms;
532 };
533 
534 #define SCTP_STREAM_CHANGE_DENIED	0x0004
535 #define SCTP_STREAM_CHANGE_FAILED	0x0008
536 
537 
538 /* SCTP notification event */
539 struct sctp_tlv {
540 	uint16_t sn_type;
541 	uint16_t sn_flags;
542 	uint32_t sn_length;
543 };
544 
545 union sctp_notification {
546 	struct sctp_tlv sn_header;
547 	struct sctp_assoc_change sn_assoc_change;
548 	struct sctp_paddr_change sn_paddr_change;
549 	struct sctp_remote_error sn_remote_error;
550 	struct sctp_send_failed sn_send_failed;
551 	struct sctp_shutdown_event sn_shutdown_event;
552 	struct sctp_adaptation_event sn_adaptation_event;
553 	/* compatibility same as above */
554 	struct sctp_adaption_event sn_adaption_event;
555 	struct sctp_pdapi_event sn_pdapi_event;
556 	struct sctp_authkey_event sn_auth_event;
557 	struct sctp_sender_dry_event sn_sender_dry_event;
558 	struct sctp_send_failed_event sn_send_failed_event;
559 	struct sctp_stream_reset_event sn_strreset_event;
560 	struct sctp_assoc_reset_event  sn_assocreset_event;
561 	struct sctp_stream_change_event sn_strchange_event;
562 };
563 
564 /* notification types */
565 #define SCTP_ASSOC_CHANGE                       0x0001
566 #define SCTP_PEER_ADDR_CHANGE                   0x0002
567 #define SCTP_REMOTE_ERROR                       0x0003
568 #define SCTP_SEND_FAILED                        0x0004
569 #define SCTP_SHUTDOWN_EVENT                     0x0005
570 #define SCTP_ADAPTATION_INDICATION              0x0006
571 /* same as above */
572 #define SCTP_ADAPTION_INDICATION                0x0006
573 #define SCTP_PARTIAL_DELIVERY_EVENT             0x0007
574 #define SCTP_AUTHENTICATION_EVENT               0x0008
575 #define SCTP_STREAM_RESET_EVENT                 0x0009
576 #define SCTP_SENDER_DRY_EVENT                   0x000a
577 #define SCTP_NOTIFICATIONS_STOPPED_EVENT        0x000b /* we don't send this*/
578 #define SCTP_ASSOC_RESET_EVENT                  0x000c
579 #define SCTP_STREAM_CHANGE_EVENT                0x000d
580 #define SCTP_SEND_FAILED_EVENT                  0x000e
581 /*
582  * socket option structs
583  */
584 
585 struct sctp_paddrparams {
586 	struct sockaddr_storage spp_address;
587 	sctp_assoc_t spp_assoc_id;
588 	uint32_t spp_hbinterval;
589 	uint32_t spp_pathmtu;
590 	uint32_t spp_flags;
591 	uint32_t spp_ipv6_flowlabel;
592 	uint16_t spp_pathmaxrxt;
593 	uint8_t spp_dscp;
594 };
595 #define spp_ipv4_tos spp_dscp
596 
597 #define SPP_HB_ENABLE		0x00000001
598 #define SPP_HB_DISABLE		0x00000002
599 #define SPP_HB_DEMAND		0x00000004
600 #define SPP_PMTUD_ENABLE	0x00000008
601 #define SPP_PMTUD_DISABLE	0x00000010
602 #define SPP_HB_TIME_IS_ZERO     0x00000080
603 #define SPP_IPV6_FLOWLABEL      0x00000100
604 #define SPP_DSCP                0x00000200
605 #define SPP_IPV4_TOS            SPP_DSCP
606 
607 struct sctp_paddrthlds {
608 	struct sockaddr_storage spt_address;
609 	sctp_assoc_t spt_assoc_id;
610 	uint16_t spt_pathmaxrxt;
611 	uint16_t spt_pathpfthld;
612 	uint16_t spt_pathcpthld;
613 };
614 
615 struct sctp_paddrinfo {
616 	struct sockaddr_storage spinfo_address;
617 	sctp_assoc_t spinfo_assoc_id;
618 	int32_t spinfo_state;
619 	uint32_t spinfo_cwnd;
620 	uint32_t spinfo_srtt;
621 	uint32_t spinfo_rto;
622 	uint32_t spinfo_mtu;
623 };
624 
625 struct sctp_rtoinfo {
626 	sctp_assoc_t srto_assoc_id;
627 	uint32_t srto_initial;
628 	uint32_t srto_max;
629 	uint32_t srto_min;
630 };
631 
632 struct sctp_assocparams {
633 	sctp_assoc_t sasoc_assoc_id;
634 	uint32_t sasoc_peer_rwnd;
635 	uint32_t sasoc_local_rwnd;
636 	uint32_t sasoc_cookie_life;
637 	uint16_t sasoc_asocmaxrxt;
638 	uint16_t sasoc_number_peer_destinations;
639 };
640 
641 struct sctp_setprim {
642 	struct sockaddr_storage ssp_addr;
643 	sctp_assoc_t ssp_assoc_id;
644 	uint8_t ssp_padding[4];
645 };
646 
647 struct sctp_setpeerprim {
648 	struct sockaddr_storage sspp_addr;
649 	sctp_assoc_t sspp_assoc_id;
650 	uint8_t sspp_padding[4];
651 };
652 
653 union sctp_sockstore {
654 	struct sockaddr_in sin;
655 	struct sockaddr_in6 sin6;
656 #if defined(__Userspace__)
657 	struct sockaddr_conn sconn;
658 #endif
659 	struct sockaddr sa;
660 };
661 
662 struct sctp_getaddresses {
663 	sctp_assoc_t sget_assoc_id;
664 	union sctp_sockstore addr[];
665 };
666 
667 struct sctp_status {
668 	sctp_assoc_t sstat_assoc_id;
669 	int32_t sstat_state;
670 	uint32_t sstat_rwnd;
671 	uint16_t sstat_unackdata;
672 	uint16_t sstat_penddata;
673 	uint16_t sstat_instrms;
674 	uint16_t sstat_outstrms;
675 	uint32_t sstat_fragmentation_point;
676 	struct sctp_paddrinfo sstat_primary;
677 };
678 
679 /*
680  * AUTHENTICATION support
681  */
682 /* SCTP_AUTH_CHUNK */
683 struct sctp_authchunk {
684 	uint8_t sauth_chunk;
685 };
686 
687 /* SCTP_AUTH_KEY */
688 struct sctp_authkey {
689 	sctp_assoc_t sca_assoc_id;
690 	uint16_t sca_keynumber;
691 	uint16_t sca_keylength;
692 	uint8_t sca_key[];
693 };
694 
695 /* SCTP_HMAC_IDENT */
696 struct sctp_hmacalgo {
697 	uint32_t shmac_number_of_idents;
698 	uint16_t shmac_idents[];
699 };
700 
701 /* AUTH hmac_id */
702 #define SCTP_AUTH_HMAC_ID_RSVD		0x0000
703 #define SCTP_AUTH_HMAC_ID_SHA1		0x0001	/* default, mandatory */
704 #define SCTP_AUTH_HMAC_ID_SHA256	0x0003
705 
706 /* SCTP_AUTH_ACTIVE_KEY / SCTP_AUTH_DELETE_KEY */
707 struct sctp_authkeyid {
708 	sctp_assoc_t scact_assoc_id;
709 	uint16_t scact_keynumber;
710 };
711 
712 /* SCTP_PEER_AUTH_CHUNKS / SCTP_LOCAL_AUTH_CHUNKS */
713 struct sctp_authchunks {
714 	sctp_assoc_t gauth_assoc_id;
715 	uint32_t gauth_number_of_chunks;
716 	uint8_t gauth_chunks[];
717 };
718 
719 struct sctp_assoc_value {
720 	sctp_assoc_t assoc_id;
721 	uint32_t assoc_value;
722 };
723 
724 struct sctp_cc_option {
725 	int option;
726 	struct sctp_assoc_value aid_value;
727 };
728 
729 struct sctp_stream_value {
730 	sctp_assoc_t assoc_id;
731 	uint16_t stream_id;
732 	uint16_t stream_value;
733 };
734 
735 struct sctp_assoc_ids {
736 	uint32_t gaids_number_of_ids;
737 	sctp_assoc_t gaids_assoc_id[];
738 };
739 
740 struct sctp_sack_info {
741 	sctp_assoc_t sack_assoc_id;
742 	uint32_t sack_delay;
743 	uint32_t sack_freq;
744 };
745 
746 struct sctp_timeouts {
747 	sctp_assoc_t stimo_assoc_id;
748 	uint32_t stimo_init;
749 	uint32_t stimo_data;
750 	uint32_t stimo_sack;
751 	uint32_t stimo_shutdown;
752 	uint32_t stimo_heartbeat;
753 	uint32_t stimo_cookie;
754 	uint32_t stimo_shutdownack;
755 };
756 
757 struct sctp_udpencaps {
758 	struct sockaddr_storage sue_address;
759 	sctp_assoc_t sue_assoc_id;
760 	uint16_t sue_port;
761 };
762 
763 struct sctp_prstatus {
764 	sctp_assoc_t sprstat_assoc_id;
765 	uint16_t sprstat_sid;
766 	uint16_t sprstat_policy;
767 	uint64_t sprstat_abandoned_unsent;
768 	uint64_t sprstat_abandoned_sent;
769 };
770 
771 struct sctp_cwnd_args {
772 	struct sctp_nets *net;	/* network to */ /* FIXME: LP64 issue */
773 	uint32_t cwnd_new_value;/* cwnd in k */
774 	uint32_t pseudo_cumack;
775 	uint16_t inflight;	/* flightsize in k */
776 	uint16_t cwnd_augment;	/* increment to it */
777 	uint8_t meets_pseudo_cumack;
778 	uint8_t need_new_pseudo_cumack;
779 	uint8_t cnt_in_send;
780 	uint8_t cnt_in_str;
781 };
782 
783 struct sctp_blk_args {
784 	uint32_t onsb;		/* in 1k bytes */
785 	uint32_t sndlen;	/* len of send being attempted */
786 	uint32_t peer_rwnd;	/* rwnd of peer */
787 	uint16_t send_sent_qcnt;/* chnk cnt */
788 	uint16_t stream_qcnt;	/* chnk cnt */
789 	uint16_t chunks_on_oque;/* chunks out */
790 	uint16_t flight_size;   /* flight size in k */
791 };
792 
793 /*
794  * Max we can reset in one setting, note this is dictated not by the define
795  * but the size of a mbuf cluster so don't change this define and think you
796  * can specify more. You must do multiple resets if you want to reset more
797  * than SCTP_MAX_EXPLICIT_STR_RESET.
798  */
799 #define SCTP_MAX_EXPLICT_STR_RESET   1000
800 
801 struct sctp_reset_streams {
802 	sctp_assoc_t srs_assoc_id;
803 	uint16_t srs_flags;
804 	uint16_t srs_number_streams;	/* 0 == ALL */
805 	uint16_t srs_stream_list[];/* list if strrst_num_streams is not 0 */
806 };
807 
808 struct sctp_add_streams {
809 	sctp_assoc_t	sas_assoc_id;
810 	uint16_t	sas_instrms;
811 	uint16_t	sas_outstrms;
812 };
813 
814 struct sctp_get_nonce_values {
815 	sctp_assoc_t gn_assoc_id;
816 	uint32_t gn_peers_tag;
817 	uint32_t gn_local_tag;
818 };
819 
820 /* Debugging logs */
821 struct sctp_str_log {
822 	void *stcb; /* FIXME: LP64 issue */
823 	uint32_t n_tsn;
824 	uint32_t e_tsn;
825 	uint16_t n_sseq;
826 	uint16_t e_sseq;
827 	uint16_t strm;
828 };
829 
830 struct sctp_sb_log {
831 	void  *stcb; /* FIXME: LP64 issue */
832 	uint32_t so_sbcc;
833 	uint32_t stcb_sbcc;
834 	uint32_t incr;
835 };
836 
837 struct sctp_fr_log {
838 	uint32_t largest_tsn;
839 	uint32_t largest_new_tsn;
840 	uint32_t tsn;
841 };
842 
843 struct sctp_fr_map {
844 	uint32_t base;
845 	uint32_t cum;
846 	uint32_t high;
847 };
848 
849 struct sctp_rwnd_log {
850 	uint32_t rwnd;
851 	uint32_t send_size;
852 	uint32_t overhead;
853 	uint32_t new_rwnd;
854 };
855 
856 struct sctp_mbcnt_log {
857 	uint32_t total_queue_size;
858 	uint32_t size_change;
859 	uint32_t total_queue_mb_size;
860 	uint32_t mbcnt_change;
861 };
862 
863 struct sctp_sack_log {
864 	uint32_t cumack;
865 	uint32_t oldcumack;
866 	uint32_t tsn;
867 	uint16_t numGaps;
868 	uint16_t numDups;
869 };
870 
871 struct sctp_lock_log {
872 	void *sock;  /* FIXME: LP64 issue */
873 	void *inp; /* FIXME: LP64 issue */
874 	uint8_t tcb_lock;
875 	uint8_t inp_lock;
876 	uint8_t info_lock;
877 	uint8_t sock_lock;
878 	uint8_t sockrcvbuf_lock;
879 	uint8_t socksndbuf_lock;
880 	uint8_t create_lock;
881 	uint8_t resv;
882 };
883 
884 struct sctp_rto_log {
885 	void * net; /* FIXME: LP64 issue */
886 	uint32_t rtt;
887 };
888 
889 struct sctp_nagle_log {
890 	void  *stcb; /* FIXME: LP64 issue */
891 	uint32_t total_flight;
892 	uint32_t total_in_queue;
893 	uint16_t count_in_queue;
894 	uint16_t count_in_flight;
895 };
896 
897 struct sctp_sbwake_log {
898 	void *stcb; /* FIXME: LP64 issue */
899 	uint16_t send_q;
900 	uint16_t sent_q;
901 	uint16_t flight;
902 	uint16_t wake_cnt;
903 	uint8_t stream_qcnt;	/* chnk cnt */
904 	uint8_t chunks_on_oque;/* chunks out */
905 	uint8_t sbflags;
906 	uint8_t sctpflags;
907 };
908 
909 struct sctp_misc_info {
910 	uint32_t log1;
911 	uint32_t log2;
912 	uint32_t log3;
913 	uint32_t log4;
914 };
915 
916 struct sctp_log_closing {
917 	void *inp; /* FIXME: LP64 issue */
918 	void *stcb;  /* FIXME: LP64 issue */
919 	uint32_t sctp_flags;
920 	uint16_t  state;
921 	int16_t  loc;
922 };
923 
924 struct sctp_mbuf_log {
925 	struct mbuf *mp; /* FIXME: LP64 issue */
926 	caddr_t  ext;
927 	caddr_t  data;
928 	uint16_t size;
929 	uint8_t  refcnt;
930 	uint8_t  mbuf_flags;
931 };
932 
933 struct sctp_cwnd_log {
934 	uint64_t time_event;
935 	uint8_t  from;
936 	uint8_t  event_type;
937 	uint8_t  resv[2];
938 	union {
939 		struct sctp_log_closing close;
940 		struct sctp_blk_args blk;
941 		struct sctp_cwnd_args cwnd;
942 		struct sctp_str_log strlog;
943 		struct sctp_fr_log fr;
944 		struct sctp_fr_map map;
945 		struct sctp_rwnd_log rwnd;
946 		struct sctp_mbcnt_log mbcnt;
947 		struct sctp_sack_log sack;
948 		struct sctp_lock_log lock;
949 		struct sctp_rto_log rto;
950 		struct sctp_sb_log sb;
951 		struct sctp_nagle_log nagle;
952 		struct sctp_sbwake_log wake;
953 		struct sctp_mbuf_log mb;
954 		struct sctp_misc_info misc;
955 	}     x;
956 };
957 
958 struct sctp_cwnd_log_req {
959 	int32_t num_in_log;		/* Number in log */
960 	int32_t num_ret;		/* Number returned */
961 	int32_t start_at;		/* start at this one */
962 	int32_t end_at;		        /* end at this one */
963 	struct sctp_cwnd_log log[];
964 };
965 
966 struct sctp_timeval {
967 	uint32_t tv_sec;
968 	uint32_t tv_usec;
969 };
970 
971 struct sctpstat {
972 	struct sctp_timeval sctps_discontinuitytime; /* sctpStats 18 (TimeStamp) */
973 	/* MIB according to RFC 3873 */
974 	uint32_t  sctps_currestab;           /* sctpStats  1   (Gauge32) */
975 	uint32_t  sctps_activeestab;         /* sctpStats  2 (Counter32) */
976 	uint32_t  sctps_restartestab;
977 	uint32_t  sctps_collisionestab;
978 	uint32_t  sctps_passiveestab;        /* sctpStats  3 (Counter32) */
979 	uint32_t  sctps_aborted;             /* sctpStats  4 (Counter32) */
980 	uint32_t  sctps_shutdown;            /* sctpStats  5 (Counter32) */
981 	uint32_t  sctps_outoftheblue;        /* sctpStats  6 (Counter32) */
982 	uint32_t  sctps_checksumerrors;      /* sctpStats  7 (Counter32) */
983 	uint32_t  sctps_outcontrolchunks;    /* sctpStats  8 (Counter64) */
984 	uint32_t  sctps_outorderchunks;      /* sctpStats  9 (Counter64) */
985 	uint32_t  sctps_outunorderchunks;    /* sctpStats 10 (Counter64) */
986 	uint32_t  sctps_incontrolchunks;     /* sctpStats 11 (Counter64) */
987 	uint32_t  sctps_inorderchunks;       /* sctpStats 12 (Counter64) */
988 	uint32_t  sctps_inunorderchunks;     /* sctpStats 13 (Counter64) */
989 	uint32_t  sctps_fragusrmsgs;         /* sctpStats 14 (Counter64) */
990 	uint32_t  sctps_reasmusrmsgs;        /* sctpStats 15 (Counter64) */
991 	uint32_t  sctps_outpackets;          /* sctpStats 16 (Counter64) */
992 	uint32_t  sctps_inpackets;           /* sctpStats 17 (Counter64) */
993 
994 	/* input statistics: */
995 	uint32_t  sctps_recvpackets;         /* total input packets        */
996 	uint32_t  sctps_recvdatagrams;       /* total input datagrams      */
997 	uint32_t  sctps_recvpktwithdata;     /* total packets that had data */
998 	uint32_t  sctps_recvsacks;           /* total input SACK chunks    */
999 	uint32_t  sctps_recvdata;            /* total input DATA chunks    */
1000 	uint32_t  sctps_recvdupdata;         /* total input duplicate DATA chunks */
1001 	uint32_t  sctps_recvheartbeat;       /* total input HB chunks      */
1002 	uint32_t  sctps_recvheartbeatack;    /* total input HB-ACK chunks  */
1003 	uint32_t  sctps_recvecne;            /* total input ECNE chunks    */
1004 	uint32_t  sctps_recvauth;            /* total input AUTH chunks    */
1005 	uint32_t  sctps_recvauthmissing;     /* total input chunks missing AUTH */
1006 	uint32_t  sctps_recvivalhmacid;      /* total number of invalid HMAC ids received */
1007 	uint32_t  sctps_recvivalkeyid;       /* total number of invalid secret ids received */
1008 	uint32_t  sctps_recvauthfailed;      /* total number of auth failed */
1009 	uint32_t  sctps_recvexpress;         /* total fast path receives all one chunk */
1010 	uint32_t  sctps_recvexpressm;        /* total fast path multi-part data */
1011 	uint32_t  sctps_recv_spare;          /* formerly sctps_recvnocrc */
1012 	uint32_t  sctps_recvswcrc;
1013 	uint32_t  sctps_recvhwcrc;
1014 
1015 	/* output statistics: */
1016 	uint32_t  sctps_sendpackets;         /* total output packets       */
1017 	uint32_t  sctps_sendsacks;           /* total output SACKs         */
1018 	uint32_t  sctps_senddata;            /* total output DATA chunks   */
1019 	uint32_t  sctps_sendretransdata;     /* total output retransmitted DATA chunks */
1020 	uint32_t  sctps_sendfastretrans;     /* total output fast retransmitted DATA chunks */
1021 	uint32_t  sctps_sendmultfastretrans; /* total FR's that happened more than once
1022 	                                      * to same chunk (u-del multi-fr algo).
1023 	                                      */
1024 	uint32_t  sctps_sendheartbeat;       /* total output HB chunks     */
1025 	uint32_t  sctps_sendecne;            /* total output ECNE chunks    */
1026 	uint32_t  sctps_sendauth;            /* total output AUTH chunks FIXME   */
1027 	uint32_t  sctps_senderrors;          /* ip_output error counter */
1028 	uint32_t  sctps_send_spare;          /* formerly sctps_sendnocrc */
1029 	uint32_t  sctps_sendswcrc;
1030 	uint32_t  sctps_sendhwcrc;
1031 	/* PCKDROPREP statistics: */
1032 	uint32_t  sctps_pdrpfmbox;           /* Packet drop from middle box */
1033 	uint32_t  sctps_pdrpfehos;           /* P-drop from end host */
1034 	uint32_t  sctps_pdrpmbda;            /* P-drops with data */
1035 	uint32_t  sctps_pdrpmbct;            /* P-drops, non-data, non-endhost */
1036 	uint32_t  sctps_pdrpbwrpt;           /* P-drop, non-endhost, bandwidth rep only */
1037 	uint32_t  sctps_pdrpcrupt;           /* P-drop, not enough for chunk header */
1038 	uint32_t  sctps_pdrpnedat;           /* P-drop, not enough data to confirm */
1039 	uint32_t  sctps_pdrppdbrk;           /* P-drop, where process_chunk_drop said break */
1040 	uint32_t  sctps_pdrptsnnf;           /* P-drop, could not find TSN */
1041 	uint32_t  sctps_pdrpdnfnd;           /* P-drop, attempt reverse TSN lookup */
1042 	uint32_t  sctps_pdrpdiwnp;           /* P-drop, e-host confirms zero-rwnd */
1043 	uint32_t  sctps_pdrpdizrw;           /* P-drop, midbox confirms no space */
1044 	uint32_t  sctps_pdrpbadd;            /* P-drop, data did not match TSN */
1045 	uint32_t  sctps_pdrpmark;            /* P-drop, TSN's marked for Fast Retran */
1046 	/* timeouts */
1047 	uint32_t  sctps_timoiterator;        /* Number of iterator timers that fired */
1048 	uint32_t  sctps_timodata;            /* Number of T3 data time outs */
1049 	uint32_t  sctps_timowindowprobe;     /* Number of window probe (T3) timers that fired */
1050 	uint32_t  sctps_timoinit;            /* Number of INIT timers that fired */
1051 	uint32_t  sctps_timosack;            /* Number of sack timers that fired */
1052 	uint32_t  sctps_timoshutdown;        /* Number of shutdown timers that fired */
1053 	uint32_t  sctps_timoheartbeat;       /* Number of heartbeat timers that fired */
1054 	uint32_t  sctps_timocookie;          /* Number of times a cookie timeout fired */
1055 	uint32_t  sctps_timosecret;          /* Number of times an endpoint changed its cookie secret*/
1056 	uint32_t  sctps_timopathmtu;         /* Number of PMTU timers that fired */
1057 	uint32_t  sctps_timoshutdownack;     /* Number of shutdown ack timers that fired */
1058 	uint32_t  sctps_timoshutdownguard;   /* Number of shutdown guard timers that fired */
1059 	uint32_t  sctps_timostrmrst;         /* Number of stream reset timers that fired */
1060 	uint32_t  sctps_timoearlyfr;         /* Number of early FR timers that fired */
1061 	uint32_t  sctps_timoasconf;          /* Number of times an asconf timer fired */
1062 	uint32_t  sctps_timodelprim;	     /* Number of times a prim_deleted timer fired */
1063 	uint32_t  sctps_timoautoclose;       /* Number of times auto close timer fired */
1064 	uint32_t  sctps_timoassockill;       /* Number of asoc free timers expired */
1065 	uint32_t  sctps_timoinpkill;         /* Number of inp free timers expired */
1066 	/* former early FR counters */
1067 	uint32_t  sctps_spare[11];
1068 	/* others */
1069 	uint32_t  sctps_hdrops;	          /* packet shorter than header */
1070 	uint32_t  sctps_badsum;	          /* checksum error             */
1071 	uint32_t  sctps_noport;           /* no endpoint for port       */
1072 	uint32_t  sctps_badvtag;          /* bad v-tag                  */
1073 	uint32_t  sctps_badsid;           /* bad SID                    */
1074 	uint32_t  sctps_nomem;            /* no memory                  */
1075 	uint32_t  sctps_fastretransinrtt; /* number of multiple FR in a RTT window */
1076 	uint32_t  sctps_markedretrans;
1077 	uint32_t  sctps_naglesent;        /* nagle allowed sending      */
1078 	uint32_t  sctps_naglequeued;      /* nagle doesn't allow sending */
1079 	uint32_t  sctps_maxburstqueued;   /* max burst doesn't allow sending */
1080 	uint32_t  sctps_ifnomemqueued;    /* look ahead tells us no memory in
1081                                          * interface ring buffer OR we had a
1082 					 * send error and are queuing one send.
1083                                          */
1084 	uint32_t  sctps_windowprobed;     /* total number of window probes sent */
1085 	uint32_t  sctps_lowlevelerr;	/* total times an output error causes us
1086 					 * to clamp down on next user send.
1087 					 */
1088 	uint32_t  sctps_lowlevelerrusr;	/* total times sctp_senderrors were caused from
1089 					 * a user send from a user invoked send not
1090 					 * a sack response
1091 					 */
1092 	uint32_t  sctps_datadropchklmt;	/* Number of in data drops due to chunk limit reached */
1093 	uint32_t  sctps_datadroprwnd;	/* Number of in data drops due to rwnd limit reached */
1094 	uint32_t  sctps_ecnereducedcwnd;  /* Number of times a ECN reduced the cwnd */
1095 	uint32_t  sctps_vtagexpress;	/* Used express lookup via vtag */
1096 	uint32_t  sctps_vtagbogus;	/* Collision in express lookup. */
1097 	uint32_t  sctps_primary_randry;	/* Number of times the sender ran dry of user data on primary */
1098 	uint32_t  sctps_cmt_randry;       /* Same for above */
1099 	uint32_t  sctps_slowpath_sack;    /* Sacks the slow way */
1100 	uint32_t  sctps_wu_sacks_sent;	/* Window Update only sacks sent */
1101 	uint32_t  sctps_sends_with_flags; /* number of sends with sinfo_flags !=0 */
1102 	uint32_t  sctps_sends_with_unord; /* number of unordered sends */
1103 	uint32_t  sctps_sends_with_eof; 	/* number of sends with EOF flag set */
1104 	uint32_t  sctps_sends_with_abort; /* number of sends with ABORT flag set */
1105 	uint32_t  sctps_protocol_drain_calls;	/* number of times protocol drain called */
1106 	uint32_t  sctps_protocol_drains_done; 	/* number of times we did a protocol drain */
1107 	uint32_t  sctps_read_peeks;	/* Number of times recv was called with peek */
1108 	uint32_t  sctps_cached_chk;       /* Number of cached chunks used */
1109 	uint32_t  sctps_cached_strmoq;    /* Number of cached stream oq's used */
1110 	uint32_t  sctps_left_abandon;     /* Number of unread messages abandoned by close */
1111 	uint32_t  sctps_send_burst_avoid; /* Unused */
1112 	uint32_t  sctps_send_cwnd_avoid;  /* Send cwnd full  avoidance, already max burst inflight to net */
1113 	uint32_t  sctps_fwdtsn_map_over;  /* number of map array over-runs via fwd-tsn's */
1114 	uint32_t  sctps_queue_upd_ecne;  /* Number of times we queued or updated an ECN chunk on send queue */
1115 	uint32_t  sctps_reserved[31];     /* Future ABI compat - remove int's from here when adding new */
1116 };
1117 
1118 #define SCTP_STAT_INCR(_x) SCTP_STAT_INCR_BY(_x,1)
1119 #define SCTP_STAT_DECR(_x) SCTP_STAT_DECR_BY(_x,1)
1120 #if defined(__FreeBSD__) && !defined(__Userspace__)
1121 #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
1122 #define SCTP_STAT_INCR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x += _d)
1123 #define SCTP_STAT_DECR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x -= _d)
1124 #else
1125 #define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
1126 #define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
1127 #endif
1128 #else
1129 #define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
1130 #define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
1131 #endif
1132 /* The following macros are for handling MIB values, */
1133 #define SCTP_STAT_INCR_COUNTER32(_x) SCTP_STAT_INCR(_x)
1134 #define SCTP_STAT_INCR_COUNTER64(_x) SCTP_STAT_INCR(_x)
1135 #define SCTP_STAT_INCR_GAUGE32(_x) SCTP_STAT_INCR(_x)
1136 #define SCTP_STAT_DECR_COUNTER32(_x) SCTP_STAT_DECR(_x)
1137 #define SCTP_STAT_DECR_COUNTER64(_x) SCTP_STAT_DECR(_x)
1138 #define SCTP_STAT_DECR_GAUGE32(_x) SCTP_STAT_DECR(_x)
1139 
1140 
1141 /***********************************/
1142 /* And something for us old timers */
1143 /***********************************/
1144 
1145 #if !(defined(__APPLE__) && !defined(__Userspace__))
1146 #if !defined(__Userspace__)
1147 #ifndef ntohll
1148 #if defined(__linux__)
1149 #ifndef _BSD_SOURCE
1150 #define _BSD_SOURCE
1151 #endif
1152 #include <endian.h>
1153 #else
1154 #include <sys/endian.h>
1155 #endif
1156 #define ntohll(x) be64toh(x)
1157 #endif
1158 
1159 #ifndef htonll
1160 #if defined(__linux__)
1161 #ifndef _BSD_SOURCE
1162 #define _BSD_SOURCE
1163 #endif
1164 #include <endian.h>
1165 #else
1166 #include <sys/endian.h>
1167 #endif
1168 #define htonll(x) htobe64(x)
1169 #endif
1170 #endif
1171 #endif
1172 /***********************************/
1173 
1174 
1175 struct xsctp_inpcb {
1176 	uint32_t last;
1177 	uint32_t flags;
1178 	uint64_t features;
1179 	uint32_t total_sends;
1180 	uint32_t total_recvs;
1181 	uint32_t total_nospaces;
1182 	uint32_t fragmentation_point;
1183 	uint16_t local_port;
1184 #if defined(__FreeBSD__) && !defined(__Userspace__)
1185 	uint16_t qlen_old;
1186 	uint16_t maxqlen_old;
1187 #else
1188 	uint16_t qlen;
1189 	uint16_t maxqlen;
1190 #endif
1191 	uint16_t __spare16;
1192 #if defined(__FreeBSD__) && !defined(__Userspace__)
1193 	kvaddr_t socket;
1194 #else
1195 	void *socket;
1196 #endif
1197 #if defined(__FreeBSD__) && !defined(__Userspace__)
1198 	uint32_t qlen;
1199 	uint32_t maxqlen;
1200 #endif
1201 	uint32_t extra_padding[26]; /* future */
1202 };
1203 
1204 struct xsctp_tcb {
1205 	union sctp_sockstore primary_addr;      /* sctpAssocEntry 5/6 */
1206 	uint32_t last;
1207 	uint32_t heartbeat_interval;            /* sctpAssocEntry 7   */
1208 	uint32_t state;                         /* sctpAssocEntry 8   */
1209 	uint32_t in_streams;                    /* sctpAssocEntry 9   */
1210 	uint32_t out_streams;                   /* sctpAssocEntry 10  */
1211 	uint32_t max_nr_retrans;                /* sctpAssocEntry 11  */
1212 	uint32_t primary_process;               /* sctpAssocEntry 12  */
1213 	uint32_t T1_expireries;                 /* sctpAssocEntry 13  */
1214 	uint32_t T2_expireries;                 /* sctpAssocEntry 14  */
1215 	uint32_t retransmitted_tsns;            /* sctpAssocEntry 15  */
1216 	uint32_t total_sends;
1217 	uint32_t total_recvs;
1218 	uint32_t local_tag;
1219 	uint32_t remote_tag;
1220 	uint32_t initial_tsn;
1221 	uint32_t highest_tsn;
1222 	uint32_t cumulative_tsn;
1223 	uint32_t cumulative_tsn_ack;
1224 	uint32_t mtu;
1225 	uint32_t refcnt;
1226 	uint16_t local_port;                    /* sctpAssocEntry 3   */
1227 	uint16_t remote_port;                   /* sctpAssocEntry 4   */
1228 	struct sctp_timeval start_time;         /* sctpAssocEntry 16  */
1229 	struct sctp_timeval discontinuity_time; /* sctpAssocEntry 17  */
1230 	uint32_t peers_rwnd;
1231 	sctp_assoc_t assoc_id;                  /* sctpAssocEntry 1   */
1232 	uint32_t extra_padding[32];              /* future */
1233 };
1234 
1235 struct xsctp_laddr {
1236 	union sctp_sockstore address;    /* sctpAssocLocalAddrEntry 1/2 */
1237 	uint32_t last;
1238 	struct sctp_timeval start_time;  /* sctpAssocLocalAddrEntry 3   */
1239 	uint32_t extra_padding[32];       /* future */
1240 };
1241 
1242 struct xsctp_raddr {
1243 	union sctp_sockstore address;      /* sctpAssocLocalRemEntry 1/2 */
1244 	uint32_t last;
1245 	uint32_t rto;                      /* sctpAssocLocalRemEntry 5   */
1246 	uint32_t max_path_rtx;             /* sctpAssocLocalRemEntry 6   */
1247 	uint32_t rtx;                      /* sctpAssocLocalRemEntry 7   */
1248 	uint32_t error_counter;            /*                            */
1249 	uint32_t cwnd;                     /*                            */
1250 	uint32_t flight_size;              /*                            */
1251 	uint32_t mtu;                      /*                            */
1252 	uint8_t active;                    /* sctpAssocLocalRemEntry 3   */
1253 	uint8_t confirmed;                 /*                            */
1254 	uint8_t heartbeat_enabled;         /* sctpAssocLocalRemEntry 4   */
1255 	uint8_t potentially_failed;
1256 	struct sctp_timeval start_time;    /* sctpAssocLocalRemEntry 8   */
1257 	uint32_t rtt;
1258 	uint32_t heartbeat_interval;
1259 	uint32_t ssthresh;
1260 	uint16_t encaps_port;
1261 	uint16_t state;
1262 	uint32_t extra_padding[29];              /* future */
1263 };
1264 
1265 #define SCTP_MAX_LOGGING_SIZE 30000
1266 #define SCTP_TRACE_PARAMS 6                /* This number MUST be even   */
1267 
1268 struct sctp_log_entry {
1269 	uint64_t timestamp;
1270 	uint32_t subsys;
1271 	uint32_t padding;
1272 	uint32_t params[SCTP_TRACE_PARAMS];
1273 };
1274 
1275 struct sctp_log {
1276 	struct sctp_log_entry entry[SCTP_MAX_LOGGING_SIZE];
1277 	uint32_t index;
1278 	uint32_t padding;
1279 };
1280 
1281 /*
1282  * Kernel defined for sctp_send
1283  */
1284 #if defined(_KERNEL) || defined(__Userspace__)
1285 int
1286 sctp_lower_sosend(struct socket *so,
1287     struct sockaddr *addr,
1288     struct uio *uio,
1289     struct mbuf *i_pak,
1290     struct mbuf *control,
1291     int flags,
1292     struct sctp_sndrcvinfo *srcv
1293 #if !defined(__Userspace__)
1294 #if defined(__FreeBSD__)
1295     ,struct thread *p
1296 #elif defined(_WIN32)
1297     , PKTHREAD p
1298 #else
1299     ,struct proc *p
1300 #endif
1301 #endif
1302 );
1303 
1304 int
1305 sctp_sorecvmsg(struct socket *so,
1306     struct uio *uio,
1307     struct mbuf **mp,
1308     struct sockaddr *from,
1309     int fromlen,
1310     int *msg_flags,
1311     struct sctp_sndrcvinfo *sinfo,
1312     int filling_sinfo);
1313 #endif
1314 
1315 /*
1316  * API system calls
1317  */
1318 #if !(defined(_KERNEL)) && !(defined(__Userspace__))
1319 
1320 __BEGIN_DECLS
1321 int	sctp_peeloff(int, sctp_assoc_t);
1322 int	sctp_bindx(int, struct sockaddr *, int, int);
1323 int	sctp_connectx(int, const struct sockaddr *, int, sctp_assoc_t *);
1324 int	sctp_getaddrlen(sa_family_t);
1325 int	sctp_getpaddrs(int, sctp_assoc_t, struct sockaddr **);
1326 void	sctp_freepaddrs(struct sockaddr *);
1327 int	sctp_getladdrs(int, sctp_assoc_t, struct sockaddr **);
1328 void	sctp_freeladdrs(struct sockaddr *);
1329 int	sctp_opt_info(int, sctp_assoc_t, int, void *, socklen_t *);
1330 
1331 /* deprecated */
1332 ssize_t	sctp_sendmsg(int, const void *, size_t, const struct sockaddr *,
1333 	    socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t);
1334 
1335 /* deprecated */
1336 ssize_t	sctp_send(int, const void *, size_t,
1337 	    const struct sctp_sndrcvinfo *, int);
1338 
1339 /* deprecated */
1340 ssize_t	sctp_sendx(int, const void *, size_t, struct sockaddr *,
1341 	    int, struct sctp_sndrcvinfo *, int);
1342 
1343 /* deprecated */
1344 ssize_t	sctp_sendmsgx(int sd, const void *, size_t, struct sockaddr *,
1345 	    int, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t);
1346 
1347 sctp_assoc_t	sctp_getassocid(int, struct sockaddr *);
1348 
1349 /* deprecated */
1350 ssize_t	sctp_recvmsg(int, void *, size_t, struct sockaddr *, socklen_t *,
1351 	    struct sctp_sndrcvinfo *, int *);
1352 
1353 ssize_t	sctp_sendv(int, const struct iovec *, int, struct sockaddr *,
1354 	    int, void *, socklen_t, unsigned int, int);
1355 
1356 ssize_t	sctp_recvv(int, const struct iovec *, int, struct sockaddr *,
1357 	    socklen_t *, void *, socklen_t *, unsigned int *, int *);
1358 __END_DECLS
1359 
1360 #endif				/* !_KERNEL */
1361 #endif				/* !__sctp_uio_h__ */
1362