xref: /freebsd/sys/netinet/sctp_uio.h (revision 18242d3b09dbc3f5e278e39baaa3c3b76624c901)
1 /*-
2  * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * a) Redistributions of source code must retain the above copyright notice,
8  *   this list of conditions and the following disclaimer.
9  *
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.
13  *
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.
17  *
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.
29  */
30 
31 /* $KAME: sctp_uio.h,v 1.11 2005/03/06 16:04:18 itojun Exp $	 */
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 
35 #ifndef __sctp_uio_h__
36 #define __sctp_uio_h__
37 
38 
39 #if ! defined(_KERNEL)
40 #include <stdint.h>
41 #endif
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/time.h>
45 #include <netinet/in.h>
46 
47 typedef uint32_t sctp_assoc_t;
48 
49 /* On/Off setup for subscription to events */
50 struct sctp_event_subscribe {
51 	uint8_t sctp_data_io_event;
52 	uint8_t sctp_association_event;
53 	uint8_t sctp_address_event;
54 	uint8_t sctp_send_failure_event;
55 	uint8_t sctp_peer_error_event;
56 	uint8_t sctp_shutdown_event;
57 	uint8_t sctp_partial_delivery_event;
58 	uint8_t sctp_adaptation_layer_event;
59 	uint8_t sctp_authentication_event;
60 	uint8_t sctp_stream_reset_events;
61 };
62 
63 /* ancillary data types */
64 #define SCTP_INIT	0x0001
65 #define SCTP_SNDRCV	0x0002
66 #define SCTP_EXTRCV	0x0003
67 /*
68  * ancillary data structures
69  */
70 struct sctp_initmsg {
71 	uint32_t sinit_num_ostreams;
72 	uint32_t sinit_max_instreams;
73 	uint16_t sinit_max_attempts;
74 	uint16_t sinit_max_init_timeo;
75 };
76 
77 /* We add 96 bytes to the size of sctp_sndrcvinfo.
78  * This makes the current structure 128 bytes long
79  * which is nicely 64 bit aligned but also has room
80  * for us to add more and keep ABI compatability.
81  * For example, already we have the sctp_extrcvinfo
82  * when enabled which is 48 bytes.
83  */
84 
85 /*
86  * The assoc up needs a verfid
87  * all sendrcvinfo's need a verfid for SENDING only.
88  */
89 
90 
91 #define SCTP_ALIGN_RESV_PAD 96
92 #define SCTP_ALIGN_RESV_PAD_SHORT 80
93 
94 struct sctp_sndrcvinfo {
95 	uint16_t sinfo_stream;
96 	uint16_t sinfo_ssn;
97 	uint16_t sinfo_flags;
98 	uint32_t sinfo_ppid;
99 	uint32_t sinfo_context;
100 	uint32_t sinfo_timetolive;
101 	uint32_t sinfo_tsn;
102 	uint32_t sinfo_cumtsn;
103 	sctp_assoc_t sinfo_assoc_id;
104 	uint8_t __reserve_pad[SCTP_ALIGN_RESV_PAD];
105 };
106 
107 struct sctp_extrcvinfo {
108 	uint16_t sinfo_stream;
109 	uint16_t sinfo_ssn;
110 	uint16_t sinfo_flags;
111 	uint32_t sinfo_ppid;
112 	uint32_t sinfo_context;
113 	uint32_t sinfo_timetolive;
114 	uint32_t sinfo_tsn;
115 	uint32_t sinfo_cumtsn;
116 	sctp_assoc_t sinfo_assoc_id;
117 	uint16_t next_flags;
118 	uint16_t next_stream;
119 	uint32_t next_asocid;
120 	uint32_t next_length;
121 	uint32_t next_ppid;
122 	uint8_t __reserve_pad[SCTP_ALIGN_RESV_PAD_SHORT];
123 };
124 
125 #define SCTP_NO_NEXT_MSG           0x0000
126 #define SCTP_NEXT_MSG_AVAIL        0x0001
127 #define SCTP_NEXT_MSG_ISCOMPLETE   0x0002
128 #define SCTP_NEXT_MSG_IS_UNORDERED 0x0004
129 #define SCTP_NEXT_MSG_IS_NOTIFICATION 0x0008
130 
131 struct sctp_snd_all_completes {
132 	uint16_t sall_stream;
133 	uint16_t sall_flags;
134 	uint32_t sall_ppid;
135 	uint32_t sall_context;
136 	uint32_t sall_num_sent;
137 	uint32_t sall_num_failed;
138 };
139 
140 /* Flags that go into the sinfo->sinfo_flags field */
141 #define SCTP_EOF 	  0x0100/* Start shutdown procedures */
142 #define SCTP_ABORT	  0x0200/* Send an ABORT to peer */
143 #define SCTP_UNORDERED 	  0x0400/* Message is un-ordered */
144 #define SCTP_ADDR_OVER	  0x0800/* Override the primary-address */
145 #define SCTP_SENDALL      0x1000/* Send this on all associations */
146 #define SCTP_EOR          0x2000/* end of message signal */
147 #define INVALID_SINFO_FLAG(x) (((x) & 0xffffff00 \
148                                     & ~(SCTP_EOF | SCTP_ABORT | SCTP_UNORDERED |\
149 				        SCTP_ADDR_OVER | SCTP_SENDALL | SCTP_EOR)) != 0)
150 /* for the endpoint */
151 
152 /* The lower byte is an enumeration of PR-SCTP policies */
153 #define SCTP_PR_SCTP_TTL  0x0001/* Time based PR-SCTP */
154 #define SCTP_PR_SCTP_BUF  0x0002/* Buffer based PR-SCTP */
155 #define SCTP_PR_SCTP_RTX  0x0003/* Number of retransmissions based PR-SCTP */
156 
157 #define PR_SCTP_POLICY(x)         ((x) & 0xff)
158 #define PR_SCTP_ENABLED(x)        (PR_SCTP_POLICY(x) != 0)
159 #define PR_SCTP_TTL_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_TTL)
160 #define PR_SCTP_BUF_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_BUF)
161 #define PR_SCTP_RTX_ENABLED(x)    (PR_SCTP_POLICY(x) == SCTP_PR_SCTP_RTX)
162 #define PR_SCTP_INVALID_POLICY(x) (PR_SCTP_POLICY(x) > SCTP_PR_SCTP_RTX)
163 /* Stat's */
164 struct sctp_pcbinfo {
165 	uint32_t ep_count;
166 	uint32_t asoc_count;
167 	uint32_t laddr_count;
168 	uint32_t raddr_count;
169 	uint32_t chk_count;
170 	uint32_t readq_count;
171 	uint32_t free_chunks;
172 	uint32_t stream_oque;
173 };
174 
175 struct sctp_sockstat {
176 	sctp_assoc_t ss_assoc_id;
177 	uint32_t ss_total_sndbuf;
178 	uint32_t ss_total_recv_buf;
179 };
180 
181 /*
182  * notification event structures
183  */
184 
185 /*
186  * association change event
187  */
188 struct sctp_assoc_change {
189 	uint16_t sac_type;
190 	uint16_t sac_flags;
191 	uint32_t sac_length;
192 	uint16_t sac_state;
193 	uint16_t sac_error;
194 	uint16_t sac_outbound_streams;
195 	uint16_t sac_inbound_streams;
196 	sctp_assoc_t sac_assoc_id;
197 };
198 
199 /* sac_state values */
200 #define SCTP_COMM_UP		0x0001
201 #define SCTP_COMM_LOST		0x0002
202 #define SCTP_RESTART		0x0003
203 #define SCTP_SHUTDOWN_COMP	0x0004
204 #define SCTP_CANT_STR_ASSOC	0x0005
205 
206 
207 /*
208  * Address event
209  */
210 struct sctp_paddr_change {
211 	uint16_t spc_type;
212 	uint16_t spc_flags;
213 	uint32_t spc_length;
214 	struct sockaddr_storage spc_aaddr;
215 	uint32_t spc_state;
216 	uint32_t spc_error;
217 	sctp_assoc_t spc_assoc_id;
218 };
219 
220 /* paddr state values */
221 #define SCTP_ADDR_AVAILABLE	0x0001
222 #define SCTP_ADDR_UNREACHABLE	0x0002
223 #define SCTP_ADDR_REMOVED	0x0003
224 #define SCTP_ADDR_ADDED		0x0004
225 #define SCTP_ADDR_MADE_PRIM	0x0005
226 #define SCTP_ADDR_CONFIRMED	0x0006
227 
228 /*
229  * CAUTION: these are user exposed SCTP addr reachability states must be
230  * compatible with SCTP_ADDR states in sctp_constants.h
231  */
232 #ifdef SCTP_ACTIVE
233 #undef SCTP_ACTIVE
234 #endif
235 #define SCTP_ACTIVE		0x0001	/* SCTP_ADDR_REACHABLE */
236 
237 #ifdef SCTP_INACTIVE
238 #undef SCTP_INACTIVE
239 #endif
240 #define SCTP_INACTIVE		0x0002	/* SCTP_ADDR_NOT_REACHABLE */
241 
242 #ifdef SCTP_UNCONFIRMED
243 #undef SCTP_UNCONFIRMED
244 #endif
245 #define SCTP_UNCONFIRMED	0x0200	/* SCTP_ADDR_UNCONFIRMED */
246 
247 #ifdef SCTP_NOHEARTBEAT
248 #undef SCTP_NOHEARTBEAT
249 #endif
250 #define SCTP_NOHEARTBEAT	0x0040	/* SCTP_ADDR_NOHB */
251 
252 
253 /* remote error events */
254 struct sctp_remote_error {
255 	uint16_t sre_type;
256 	uint16_t sre_flags;
257 	uint32_t sre_length;
258 	uint16_t sre_error;
259 	sctp_assoc_t sre_assoc_id;
260 	uint8_t sre_data[4];
261 };
262 
263 /* data send failure event */
264 struct sctp_send_failed {
265 	uint16_t ssf_type;
266 	uint16_t ssf_flags;
267 	uint32_t ssf_length;
268 	uint32_t ssf_error;
269 	struct sctp_sndrcvinfo ssf_info;
270 	sctp_assoc_t ssf_assoc_id;
271 	uint8_t ssf_data[4];
272 };
273 
274 /* flag that indicates state of data */
275 #define SCTP_DATA_UNSENT	0x0001	/* inqueue never on wire */
276 #define SCTP_DATA_SENT		0x0002	/* on wire at failure */
277 
278 /* shutdown event */
279 struct sctp_shutdown_event {
280 	uint16_t sse_type;
281 	uint16_t sse_flags;
282 	uint32_t sse_length;
283 	sctp_assoc_t sse_assoc_id;
284 };
285 
286 /* Adaptation layer indication stuff */
287 struct sctp_adaptation_event {
288 	uint16_t sai_type;
289 	uint16_t sai_flags;
290 	uint32_t sai_length;
291 	uint32_t sai_adaptation_ind;
292 	sctp_assoc_t sai_assoc_id;
293 };
294 
295 struct sctp_setadaptation {
296 	uint32_t ssb_adaptation_ind;
297 };
298 
299 /* compatable old spelling */
300 struct sctp_adaption_event {
301 	uint16_t sai_type;
302 	uint16_t sai_flags;
303 	uint32_t sai_length;
304 	uint32_t sai_adaption_ind;
305 	sctp_assoc_t sai_assoc_id;
306 };
307 
308 struct sctp_setadaption {
309 	uint32_t ssb_adaption_ind;
310 };
311 
312 
313 /*
314  * Partial Delivery API event
315  */
316 struct sctp_pdapi_event {
317 	uint16_t pdapi_type;
318 	uint16_t pdapi_flags;
319 	uint32_t pdapi_length;
320 	uint32_t pdapi_indication;
321 	sctp_assoc_t pdapi_assoc_id;
322 };
323 
324 /* indication values */
325 #define SCTP_PARTIAL_DELIVERY_ABORTED	0x0001
326 
327 
328 /*
329  * authentication key event
330  */
331 struct sctp_authkey_event {
332 	uint16_t auth_type;
333 	uint16_t auth_flags;
334 	uint32_t auth_length;
335 	uint16_t auth_keynumber;
336 	uint16_t auth_altkeynumber;
337 	uint32_t auth_indication;
338 	sctp_assoc_t auth_assoc_id;
339 };
340 
341 /* indication values */
342 #define SCTP_AUTH_NEWKEY	0x0001
343 
344 
345 /*
346  * stream reset event
347  */
348 struct sctp_stream_reset_event {
349 	uint16_t strreset_type;
350 	uint16_t strreset_flags;
351 	uint32_t strreset_length;
352 	sctp_assoc_t strreset_assoc_id;
353 	uint16_t strreset_list[0];
354 };
355 
356 /* flags in strreset_flags field */
357 #define SCTP_STRRESET_INBOUND_STR  0x0001
358 #define SCTP_STRRESET_OUTBOUND_STR 0x0002
359 #define SCTP_STRRESET_ALL_STREAMS  0x0004
360 #define SCTP_STRRESET_STREAM_LIST  0x0008
361 #define SCTP_STRRESET_FAILED       0x0010
362 
363 
364 /* SCTP notification event */
365 struct sctp_tlv {
366 	uint16_t sn_type;
367 	uint16_t sn_flags;
368 	uint32_t sn_length;
369 };
370 
371 union sctp_notification {
372 	struct sctp_tlv sn_header;
373 	struct sctp_assoc_change sn_assoc_change;
374 	struct sctp_paddr_change sn_paddr_change;
375 	struct sctp_remote_error sn_remote_error;
376 	struct sctp_send_failed sn_send_failed;
377 	struct sctp_shutdown_event sn_shutdown_event;
378 	struct sctp_adaptation_event sn_adaptation_event;
379 	/* compatability same as above */
380 	struct sctp_adaption_event sn_adaption_event;
381 	struct sctp_pdapi_event sn_pdapi_event;
382 	struct sctp_authkey_event sn_auth_event;
383 	struct sctp_stream_reset_event sn_strreset_event;
384 };
385 
386 /* notification types */
387 #define SCTP_ASSOC_CHANGE		0x0001
388 #define SCTP_PEER_ADDR_CHANGE		0x0002
389 #define SCTP_REMOTE_ERROR		0x0003
390 #define SCTP_SEND_FAILED		0x0004
391 #define SCTP_SHUTDOWN_EVENT		0x0005
392 #define SCTP_ADAPTATION_INDICATION	0x0006
393 /* same as above */
394 #define SCTP_ADAPTION_INDICATION	0x0006
395 #define SCTP_PARTIAL_DELIVERY_EVENT	0x0007
396 #define SCTP_AUTHENTICATION_EVENT	0x0008
397 #define SCTP_STREAM_RESET_EVENT		0x0009
398 
399 
400 /*
401  * socket option structs
402  */
403 
404 struct sctp_paddrparams {
405 	sctp_assoc_t spp_assoc_id;
406 	struct sockaddr_storage spp_address;
407 	uint32_t spp_hbinterval;
408 	uint16_t spp_pathmaxrxt;
409 	uint32_t spp_pathmtu;
410 	uint32_t spp_flags;
411 	uint32_t spp_ipv6_flowlabel;
412 	uint8_t spp_ipv4_tos;
413 
414 };
415 
416 #define SPP_HB_ENABLE		0x00000001
417 #define SPP_HB_DISABLE		0x00000002
418 #define SPP_HB_DEMAND		0x00000004
419 #define SPP_PMTUD_ENABLE	0x00000008
420 #define SPP_PMTUD_DISABLE	0x00000010
421 #define SPP_SACKDELAY_ENABLE	0x00000020
422 #define SPP_SACKDELAY_DISABLE	0x00000040
423 #define SPP_HB_TIME_IS_ZERO     0x00000080
424 #define SPP_IPV6_FLOWLABEL      0x00000100
425 #define SPP_IPV4_TOS            0x00000200
426 
427 struct sctp_paddrinfo {
428 	sctp_assoc_t spinfo_assoc_id;
429 	struct sockaddr_storage spinfo_address;
430 	int32_t spinfo_state;
431 	uint32_t spinfo_cwnd;
432 	uint32_t spinfo_srtt;
433 	uint32_t spinfo_rto;
434 	uint32_t spinfo_mtu;
435 };
436 
437 struct sctp_rtoinfo {
438 	sctp_assoc_t srto_assoc_id;
439 	uint32_t srto_initial;
440 	uint32_t srto_max;
441 	uint32_t srto_min;
442 };
443 
444 struct sctp_assocparams {
445 	sctp_assoc_t sasoc_assoc_id;
446 	uint16_t sasoc_asocmaxrxt;
447 	uint16_t sasoc_number_peer_destinations;
448 	uint32_t sasoc_peer_rwnd;
449 	uint32_t sasoc_local_rwnd;
450 	uint32_t sasoc_cookie_life;
451 	uint32_t sasoc_sack_delay;
452 	uint32_t sasoc_sack_freq;
453 };
454 
455 struct sctp_setprim {
456 	sctp_assoc_t ssp_assoc_id;
457 	struct sockaddr_storage ssp_addr;
458 };
459 
460 struct sctp_setpeerprim {
461 	sctp_assoc_t sspp_assoc_id;
462 	struct sockaddr_storage sspp_addr;
463 };
464 
465 struct sctp_getaddresses {
466 	sctp_assoc_t sget_assoc_id;
467 	/* addr is filled in for N * sockaddr_storage */
468 	struct sockaddr addr[1];
469 };
470 
471 struct sctp_setstrm_timeout {
472 	sctp_assoc_t ssto_assoc_id;
473 	uint32_t ssto_timeout;
474 	uint32_t ssto_streamid_start;
475 	uint32_t ssto_streamid_end;
476 };
477 
478 struct sctp_status {
479 	sctp_assoc_t sstat_assoc_id;
480 	int32_t sstat_state;
481 	uint32_t sstat_rwnd;
482 	uint16_t sstat_unackdata;
483 	uint16_t sstat_penddata;
484 	uint16_t sstat_instrms;
485 	uint16_t sstat_outstrms;
486 	uint32_t sstat_fragmentation_point;
487 	struct sctp_paddrinfo sstat_primary;
488 };
489 
490 /*
491  * AUTHENTICATION support
492  */
493 /* SCTP_AUTH_CHUNK */
494 struct sctp_authchunk {
495 	uint8_t sauth_chunk;
496 };
497 
498 /* SCTP_AUTH_KEY */
499 struct sctp_authkey {
500 	sctp_assoc_t sca_assoc_id;
501 	uint16_t sca_keynumber;
502 	uint8_t sca_key[0];
503 };
504 
505 /* SCTP_HMAC_IDENT */
506 struct sctp_hmacalgo {
507 	uint16_t shmac_idents[0];
508 };
509 
510 /* AUTH hmac_id */
511 #define SCTP_AUTH_HMAC_ID_RSVD		0x0000
512 #define SCTP_AUTH_HMAC_ID_SHA1		0x0001	/* default, mandatory */
513 #define SCTP_AUTH_HMAC_ID_MD5		0x0002	/* deprecated */
514 #define SCTP_AUTH_HMAC_ID_SHA256	0x0003
515 #define SCTP_AUTH_HMAC_ID_SHA224	0x8001
516 #define SCTP_AUTH_HMAC_ID_SHA384	0x8002
517 #define SCTP_AUTH_HMAC_ID_SHA512	0x8003
518 
519 
520 /* SCTP_AUTH_ACTIVE_KEY / SCTP_AUTH_DELETE_KEY */
521 struct sctp_authkeyid {
522 	sctp_assoc_t scact_assoc_id;
523 	uint16_t scact_keynumber;
524 };
525 
526 /* SCTP_PEER_AUTH_CHUNKS / SCTP_LOCAL_AUTH_CHUNKS */
527 struct sctp_authchunks {
528 	sctp_assoc_t gauth_assoc_id;
529 	uint8_t gauth_chunks[0];
530 };
531 
532 struct sctp_assoc_value {
533 	sctp_assoc_t assoc_id;
534 	uint32_t assoc_value;
535 };
536 
537 #define MAX_ASOC_IDS_RET 255
538 struct sctp_assoc_ids {
539 	uint16_t asls_assoc_start;	/* array of index's start at 0 */
540 	uint8_t asls_numb_present;
541 	uint8_t asls_more_to_get;
542 	sctp_assoc_t asls_assoc_id[MAX_ASOC_IDS_RET];
543 };
544 
545 struct sctp_cwnd_args {
546 	struct sctp_nets *net;	/* network to */
547 	uint32_t cwnd_new_value;/* cwnd in k */
548 	uint32_t inflight;	/* flightsize in k */
549 	uint32_t pseudo_cumack;
550 	int cwnd_augment;	/* increment to it */
551 	uint8_t meets_pseudo_cumack;
552 	uint8_t need_new_pseudo_cumack;
553 	uint8_t cnt_in_send;
554 	uint8_t cnt_in_str;
555 };
556 
557 struct sctp_blk_args {
558 	uint32_t onsb;		/* in 1k bytes */
559 	uint32_t sndlen;	/* len of send being attempted */
560 	uint32_t peer_rwnd;	/* rwnd of peer */
561 	uint16_t send_sent_qcnt;/* chnk cnt */
562 	uint16_t stream_qcnt;	/* chnk cnt */
563 	uint16_t chunks_on_oque;/* chunks out */
564 	uint16_t flight_size;	/* flight size in k */
565 };
566 
567 /*
568  * Max we can reset in one setting, note this is dictated not by the define
569  * but the size of a mbuf cluster so don't change this define and think you
570  * can specify more. You must do multiple resets if you want to reset more
571  * than SCTP_MAX_EXPLICIT_STR_RESET.
572  */
573 #define SCTP_MAX_EXPLICT_STR_RESET   1000
574 
575 #define SCTP_RESET_LOCAL_RECV  0x0001
576 #define SCTP_RESET_LOCAL_SEND  0x0002
577 #define SCTP_RESET_BOTH        0x0003
578 #define SCTP_RESET_TSN         0x0004
579 
580 struct sctp_stream_reset {
581 	sctp_assoc_t strrst_assoc_id;
582 	uint16_t strrst_flags;
583 	uint16_t strrst_num_streams;	/* 0 == ALL */
584 	uint16_t strrst_list[0];/* list if strrst_num_streams is not 0 */
585 };
586 
587 
588 struct sctp_get_nonce_values {
589 	sctp_assoc_t gn_assoc_id;
590 	uint32_t gn_peers_tag;
591 	uint32_t gn_local_tag;
592 };
593 
594 /* Debugging logs */
595 struct sctp_str_log {
596 	void *stcb;
597 	uint32_t n_tsn;
598 	uint32_t e_tsn;
599 	uint16_t n_sseq;
600 	uint16_t e_sseq;
601 	uint16_t strm;
602 };
603 
604 struct sctp_sb_log {
605 	void *stcb;
606 	uint32_t so_sbcc;
607 	uint32_t stcb_sbcc;
608 	uint32_t incr;
609 };
610 
611 struct sctp_fr_log {
612 	uint32_t largest_tsn;
613 	uint32_t largest_new_tsn;
614 	uint32_t tsn;
615 };
616 
617 struct sctp_fr_map {
618 	uint32_t base;
619 	uint32_t cum;
620 	uint32_t high;
621 };
622 
623 struct sctp_rwnd_log {
624 	uint32_t rwnd;
625 	uint32_t send_size;
626 	uint32_t overhead;
627 	uint32_t new_rwnd;
628 };
629 
630 struct sctp_mbcnt_log {
631 	uint32_t total_queue_size;
632 	uint32_t size_change;
633 	uint32_t total_queue_mb_size;
634 	uint32_t mbcnt_change;
635 };
636 
637 struct sctp_sack_log {
638 	uint32_t cumack;
639 	uint32_t oldcumack;
640 	uint32_t tsn;
641 	uint16_t numGaps;
642 	uint16_t numDups;
643 };
644 
645 struct sctp_lock_log {
646 	void *sock;
647 	void *inp;
648 	uint8_t tcb_lock;
649 	uint8_t inp_lock;
650 	uint8_t info_lock;
651 	uint8_t sock_lock;
652 	uint8_t sockrcvbuf_lock;
653 	uint8_t socksndbuf_lock;
654 	uint8_t create_lock;
655 	uint8_t resv;
656 };
657 
658 struct sctp_rto_log {
659 	void *net;
660 	uint32_t rtt;
661 };
662 
663 struct sctp_nagle_log {
664 	void *stcb;
665 	uint32_t total_flight;
666 	uint32_t total_in_queue;
667 	uint16_t count_in_queue;
668 	uint16_t count_in_flight;
669 };
670 
671 struct sctp_sbwake_log {
672 	void *stcb;
673 	uint16_t send_q;
674 	uint16_t sent_q;
675 	uint16_t flight;
676 	uint16_t wake_cnt;
677 	uint8_t stream_qcnt;	/* chnk cnt */
678 	uint8_t chunks_on_oque;	/* chunks out */
679 	uint8_t sbflags;
680 	uint8_t sctpflags;
681 };
682 
683 struct sctp_misc_info {
684 	uint32_t log1;
685 	uint32_t log2;
686 	uint32_t log3;
687 	uint32_t log4;
688 };
689 
690 struct sctp_log_closing {
691 	void *inp;
692 	void *stcb;
693 	uint32_t sctp_flags;
694 	uint16_t state;
695 	int16_t loc;
696 };
697 
698 struct sctp_mbuf_log {
699 	struct mbuf *mp;
700 	caddr_t ext;
701 	caddr_t data;
702 	uint16_t size;
703 	uint8_t refcnt;
704 	uint8_t mbuf_flags;
705 };
706 
707 struct sctp_cwnd_log {
708 	uint32_t time_event;
709 	uint8_t from;
710 	uint8_t event_type;
711 	uint8_t resv[2];
712 	union {
713 		struct sctp_log_closing close;
714 		struct sctp_blk_args blk;
715 		struct sctp_cwnd_args cwnd;
716 		struct sctp_str_log strlog;
717 		struct sctp_fr_log fr;
718 		struct sctp_fr_map map;
719 		struct sctp_rwnd_log rwnd;
720 		struct sctp_mbcnt_log mbcnt;
721 		struct sctp_sack_log sack;
722 		struct sctp_lock_log lock;
723 		struct sctp_rto_log rto;
724 		struct sctp_sb_log sb;
725 		struct sctp_nagle_log nagle;
726 		struct sctp_sbwake_log wake;
727 		struct sctp_mbuf_log mb;
728 		struct sctp_misc_info misc;
729 	}     x;
730 };
731 
732 struct sctp_cwnd_log_req {
733 	int num_in_log;		/* Number in log */
734 	int num_ret;		/* Number returned */
735 	int start_at;		/* start at this one */
736 	int end_at;		/* end at this one */
737 	struct sctp_cwnd_log log[0];
738 };
739 
740 struct sctpstat {
741 	/* MIB according to RFC 3873 */
742 	u_long sctps_currestab;	/* sctpStats  1   (Gauge32) */
743 	u_long sctps_activeestab;	/* sctpStats  2 (Counter32) */
744 	u_long sctps_restartestab;
745 	u_long sctps_collisionestab;
746 	u_long sctps_passiveestab;	/* sctpStats  3 (Counter32) */
747 	u_long sctps_aborted;	/* sctpStats  4 (Counter32) */
748 	u_long sctps_shutdown;	/* sctpStats  5 (Counter32) */
749 	u_long sctps_outoftheblue;	/* sctpStats  6 (Counter32) */
750 	u_long sctps_checksumerrors;	/* sctpStats  7 (Counter32) */
751 	u_long sctps_outcontrolchunks;	/* sctpStats  8 (Counter64) */
752 	u_long sctps_outorderchunks;	/* sctpStats  9 (Counter64) */
753 	u_long sctps_outunorderchunks;	/* sctpStats 10 (Counter64) */
754 	u_long sctps_incontrolchunks;	/* sctpStats 11 (Counter64) */
755 	u_long sctps_inorderchunks;	/* sctpStats 12 (Counter64) */
756 	u_long sctps_inunorderchunks;	/* sctpStats 13 (Counter64) */
757 	u_long sctps_fragusrmsgs;	/* sctpStats 14 (Counter64) */
758 	u_long sctps_reasmusrmsgs;	/* sctpStats 15 (Counter64) */
759 	u_long sctps_outpackets;/* sctpStats 16 (Counter64) */
760 	u_long sctps_inpackets;	/* sctpStats 17 (Counter64) */
761 	struct timeval sctps_discontinuitytime;	/* sctpStats 18 (TimeStamp) */
762 	/* input statistics: */
763 	u_long sctps_recvpackets;	/* total input packets        */
764 	u_long sctps_recvdatagrams;	/* total input datagrams      */
765 	u_long sctps_recvpktwithdata;	/* total packets that had data */
766 	u_long sctps_recvsacks;	/* total input SACK chunks    */
767 	u_long sctps_recvdata;	/* total input DATA chunks    */
768 	u_long sctps_recvdupdata;	/* total input duplicate DATA chunks */
769 	u_long sctps_recvheartbeat;	/* total input HB chunks      */
770 	u_long sctps_recvheartbeatack;	/* total input HB-ACK chunks  */
771 	u_long sctps_recvecne;	/* total input ECNE chunks    */
772 	u_long sctps_recvauth;	/* total input AUTH chunks    */
773 	u_long sctps_recvauthmissing;	/* total input chunks missing AUTH */
774 	u_long sctps_recvivalhmacid;	/* total number of invalid HMAC ids
775 					 * received */
776 	u_long sctps_recvivalkeyid;	/* total number of invalid secret ids
777 					 * received */
778 	u_long sctps_recvauthfailed;	/* total number of auth failed */
779 	u_long sctps_recvexpress;	/* total fast path receives all one
780 					 * chunk */
781 	u_long sctps_recvexpressm;	/* total fast path multi-part data */
782 	/* output statistics: */
783 	u_long sctps_sendpackets;	/* total output packets       */
784 	u_long sctps_sendsacks;	/* total output SACKs         */
785 	u_long sctps_senddata;	/* total output DATA chunks   */
786 	u_long sctps_sendretransdata;	/* total output retransmitted DATA
787 					 * chunks */
788 	u_long sctps_sendfastretrans;	/* total output fast retransmitted
789 					 * DATA chunks */
790 	u_long sctps_sendmultfastretrans;	/* total FR's that happened
791 						 * more than once to same
792 						 * chunk (u-del multi-fr
793 						 * algo). */
794 	u_long sctps_sendheartbeat;	/* total output HB chunks     */
795 	u_long sctps_sendecne;	/* total output ECNE chunks    */
796 	u_long sctps_sendauth;	/* total output AUTH chunks FIXME   */
797 	u_long sctps_senderrors;/* ip_output error counter */
798 	/* PCKDROPREP statistics: */
799 	u_long sctps_pdrpfmbox;	/* Packet drop from middle box */
800 	u_long sctps_pdrpfehos;	/* P-drop from end host */
801 	u_long sctps_pdrpmbda;	/* P-drops with data */
802 	u_long sctps_pdrpmbct;	/* P-drops, non-data, non-endhost */
803 	u_long sctps_pdrpbwrpt;	/* P-drop, non-endhost, bandwidth rep only */
804 	u_long sctps_pdrpcrupt;	/* P-drop, not enough for chunk header */
805 	u_long sctps_pdrpnedat;	/* P-drop, not enough data to confirm */
806 	u_long sctps_pdrppdbrk;	/* P-drop, where process_chunk_drop said break */
807 	u_long sctps_pdrptsnnf;	/* P-drop, could not find TSN */
808 	u_long sctps_pdrpdnfnd;	/* P-drop, attempt reverse TSN lookup */
809 	u_long sctps_pdrpdiwnp;	/* P-drop, e-host confirms zero-rwnd */
810 	u_long sctps_pdrpdizrw;	/* P-drop, midbox confirms no space */
811 	u_long sctps_pdrpbadd;	/* P-drop, data did not match TSN */
812 	u_long sctps_pdrpmark;	/* P-drop, TSN's marked for Fast Retran */
813 	/* timeouts */
814 	u_long sctps_timoiterator;	/* Number of iterator timers that
815 					 * fired */
816 	u_long sctps_timodata;	/* Number of T3 data time outs */
817 	u_long sctps_timowindowprobe;	/* Number of window probe (T3) timers
818 					 * that fired */
819 	u_long sctps_timoinit;	/* Number of INIT timers that fired */
820 	u_long sctps_timosack;	/* Number of sack timers that fired */
821 	u_long sctps_timoshutdown;	/* Number of shutdown timers that
822 					 * fired */
823 	u_long sctps_timoheartbeat;	/* Number of heartbeat timers that
824 					 * fired */
825 	u_long sctps_timocookie;/* Number of times a cookie timeout fired */
826 	u_long sctps_timosecret;/* Number of times an endpoint changed its
827 				 * cookie secret */
828 	u_long sctps_timopathmtu;	/* Number of PMTU timers that fired */
829 	u_long sctps_timoshutdownack;	/* Number of shutdown ack timers that
830 					 * fired */
831 	u_long sctps_timoshutdownguard;	/* Number of shutdown guard timers
832 					 * that fired */
833 	u_long sctps_timostrmrst;	/* Number of stream reset timers that
834 					 * fired */
835 	u_long sctps_timoearlyfr;	/* Number of early FR timers that
836 					 * fired */
837 	u_long sctps_timoasconf;/* Number of times an asconf timer fired */
838 	u_long sctps_timoautoclose;	/* Number of times auto close timer
839 					 * fired */
840 	u_long sctps_timoassockill;	/* Number of asoc free timers expired */
841 	u_long sctps_timoinpkill;	/* Number of inp free timers expired */
842 	/* Early fast retransmission counters */
843 	u_long sctps_earlyfrstart;
844 	u_long sctps_earlyfrstop;
845 	u_long sctps_earlyfrmrkretrans;
846 	u_long sctps_earlyfrstpout;
847 	u_long sctps_earlyfrstpidsck1;
848 	u_long sctps_earlyfrstpidsck2;
849 	u_long sctps_earlyfrstpidsck3;
850 	u_long sctps_earlyfrstpidsck4;
851 	u_long sctps_earlyfrstrid;
852 	u_long sctps_earlyfrstrout;
853 	u_long sctps_earlyfrstrtmr;
854 	/* otheres */
855 	u_long sctps_hdrops;	/* packet shorter than header */
856 	u_long sctps_badsum;	/* checksum error             */
857 	u_long sctps_noport;	/* no endpoint for port       */
858 	u_long sctps_badvtag;	/* bad v-tag                  */
859 	u_long sctps_badsid;	/* bad SID                    */
860 	u_long sctps_nomem;	/* no memory                  */
861 	u_long sctps_fastretransinrtt;	/* number of multiple FR in a RTT
862 					 * window */
863 	u_long sctps_markedretrans;
864 	u_long sctps_naglesent;	/* nagle allowed sending      */
865 	u_long sctps_naglequeued;	/* nagle does't allow sending */
866 	u_long sctps_maxburstqueued;	/* max burst dosn't allow sending */
867 	u_long sctps_ifnomemqueued;	/* look ahead tells us no memory in
868 					 * interface ring buffer OR we had a
869 					 * send error and are queuing one
870 					 * send. */
871 	u_long sctps_windowprobed;	/* total number of window probes sent */
872 	u_long sctps_lowlevelerr;	/* total times an output error causes
873 					 * us to clamp down on next user send. */
874 	u_long sctps_lowlevelerrusr;	/* total times sctp_senderrors were
875 					 * caused from a user send from a user
876 					 * invoked send not a sack response */
877 	u_long sctps_datadropchklmt;	/* Number of in data drops due to
878 					 * chunk limit reached */
879 	u_long sctps_datadroprwnd;	/* Number of in data drops due to rwnd
880 					 * limit reached */
881 	u_long sctps_ecnereducedcwnd;	/* Number of times a ECN reduced the
882 					 * cwnd */
883 	u_long sctps_vtagexpress;	/* Used express lookup via vtag */
884 	u_long sctps_vtagbogus;	/* Collision in express lookup. */
885 	u_long sctps_primary_randry;	/* Number of times the sender ran dry
886 					 * of user data on primary */
887 	u_long sctps_cmt_randry;/* Same for above */
888 	u_long sctps_slowpath_sack;	/* Sacks the slow way */
889 	u_long sctps_wu_sacks_sent;	/* Window Update only sacks sent */
890 	u_long sctps_sends_with_flags;	/* number of sends with sinfo_flags
891 					 * !=0 */
892 	u_long sctps_sends_with_unord /* number of undordered sends */ ;
893 	u_long sctps_sends_with_eof;	/* number of sends with EOF flag set */
894 	u_long sctps_sends_with_abort;	/* number of sends with ABORT flag set */
895 	u_long sctps_protocol_drain_calls;	/* number of times protocol
896 						 * drain called */
897 	u_long sctps_protocol_drains_done;	/* number of times we did a
898 						 * protocol drain */
899 	u_long sctps_read_peeks;/* Number of times recv was called with peek */
900 	u_long sctps_cached_chk;/* Number of cached chunks used */
901 	u_long sctps_cached_strmoq;	/* Number of cached stream oq's used */
902 };
903 
904 #define SCTP_STAT_INCR(_x) SCTP_STAT_INCR_BY(_x,1)
905 #define SCTP_STAT_DECR(_x) SCTP_STAT_DECR_BY(_x,1)
906 #define SCTP_STAT_INCR_BY(_x,_d) atomic_add_long(&sctpstat._x, _d)
907 #define SCTP_STAT_DECR_BY(_x,_d) atomic_add_long(&sctpstat._x, -(_d))
908 /* The following macros are for handling MIB values, */
909 #define SCTP_STAT_INCR_COUNTER32(_x) SCTP_STAT_INCR(_x)
910 #define SCTP_STAT_INCR_COUNTER64(_x) SCTP_STAT_INCR(_x)
911 #define SCTP_STAT_INCR_GAUGE32(_x) SCTP_STAT_INCR(_x)
912 #define SCTP_STAT_DECR_COUNTER32(_x) SCTP_STAT_DECR(_x)
913 #define SCTP_STAT_DECR_COUNTER64(_x) SCTP_STAT_DECR(_x)
914 #define SCTP_STAT_DECR_GAUGE32(_x) SCTP_STAT_DECR(_x)
915 
916 union sctp_sockstore {
917 #if defined(INET) || !defined(_KERNEL)
918 	struct sockaddr_in sin;
919 #endif
920 #if defined(INET6) || !defined(_KERNEL)
921 	struct sockaddr_in6 sin6;
922 #endif
923 	struct sockaddr sa;
924 };
925 
926 struct xsctp_inpcb {
927 	uint32_t last;
928 	uint16_t local_port;
929 	uint16_t number_local_addresses;
930 	uint32_t number_associations;
931 	uint32_t flags;
932 	uint32_t features;
933 	uint32_t total_sends;
934 	uint32_t total_recvs;
935 	uint32_t total_nospaces;
936 	/* add more endpoint specific data here */
937 };
938 
939 struct xsctp_tcb {
940 	uint16_t LocalPort;	/* sctpAssocEntry 3   */
941 	uint16_t RemPort;	/* sctpAssocEntry 4   */
942 	union sctp_sockstore RemPrimAddr;	/* sctpAssocEntry 5/6 */
943 	uint32_t HeartBeatInterval;	/* sctpAssocEntry 7   */
944 	uint32_t State;		/* sctpAssocEntry 8   */
945 	uint32_t InStreams;	/* sctpAssocEntry 9   */
946 	uint32_t OutStreams;	/* sctpAssocEntry 10  */
947 	uint32_t MaxRetr;	/* sctpAssocEntry 11  */
948 	uint32_t PrimProcess;	/* sctpAssocEntry 12  */
949 	uint32_t T1expireds;	/* sctpAssocEntry 13  */
950 	uint32_t T2expireds;	/* sctpAssocEntry 14  */
951 	uint32_t RtxChunks;	/* sctpAssocEntry 15  */
952 	struct timeval StartTime;	/* sctpAssocEntry 16  */
953 	struct timeval DiscontinuityTime;	/* sctpAssocEntry 17  */
954 	uint32_t total_sends;
955 	uint32_t total_recvs;
956 	uint32_t local_tag;
957 	uint32_t remote_tag;
958 	uint32_t initial_tsn;
959 	uint32_t highest_tsn;
960 	uint32_t cumulative_tsn;
961 	uint32_t cumulative_tsn_ack;
962 	/* add more association specific data here */
963 	uint16_t number_local_addresses;
964 	uint16_t number_remote_addresses;
965 };
966 
967 struct xsctp_laddr {
968 	union sctp_sockstore LocalAddr;	/* sctpAssocLocalAddrEntry 1/2 */
969 	struct timeval LocalStartTime;	/* sctpAssocLocalAddrEntry 3   */
970 	/* add more local address specific data */
971 };
972 
973 struct xsctp_raddr {
974 	union sctp_sockstore RemAddr;	/* sctpAssocLocalRemEntry 1/2 */
975 	uint8_t RemAddrActive;	/* sctpAssocLocalRemEntry 3   */
976 	uint8_t RemAddrConfirmed;	/* */
977 	uint8_t RemAddrHBActive;/* sctpAssocLocalRemEntry 4   */
978 	uint32_t RemAddrRTO;	/* sctpAssocLocalRemEntry 5   */
979 	uint32_t RemAddrMaxPathRtx;	/* sctpAssocLocalRemEntry 6   */
980 	uint32_t RemAddrRtx;	/* sctpAssocLocalRemEntry 7   */
981 	uint32_t RemAddrErrorCounter;	/* */
982 	uint32_t RemAddrCwnd;	/* */
983 	uint32_t RemAddrFlightSize;	/* */
984 	struct timeval RemAddrStartTime;	/* sctpAssocLocalRemEntry 8   */
985 	/* add more remote address specific data */
986 };
987 
988 /*
989  * Kernel defined for sctp_send
990  */
991 #if defined(_KERNEL)
992 int
993 sctp_lower_sosend(struct socket *so,
994     struct sockaddr *addr,
995     struct uio *uio,
996 
997     struct mbuf *top,
998     struct mbuf *control,
999     int flags,
1000     int use_rcvinfo,
1001     struct sctp_sndrcvinfo *srcv
1002     ,struct thread *p
1003 );
1004 
1005 int
1006 sctp_sorecvmsg(struct socket *so,
1007     struct uio *uio,
1008     struct mbuf **mp,
1009     struct sockaddr *from,
1010     int fromlen,
1011     int *msg_flags,
1012     struct sctp_sndrcvinfo *sinfo,
1013     int filling_sinfo);
1014 
1015 
1016 #endif
1017 
1018 /*
1019  * API system calls
1020  */
1021 #if !(defined(_KERNEL))
1022 
1023 __BEGIN_DECLS
1024 int sctp_peeloff __P((int, sctp_assoc_t));
1025 int sctp_bindx __P((int, struct sockaddr *, int, int));
1026 int sctp_connectx __P((int, const struct sockaddr *, int, sctp_assoc_t *));
1027 int sctp_getaddrlen __P((sa_family_t));
1028 int sctp_getpaddrs __P((int, sctp_assoc_t, struct sockaddr **));
1029 void sctp_freepaddrs __P((struct sockaddr *));
1030 int sctp_getladdrs __P((int, sctp_assoc_t, struct sockaddr **));
1031 void sctp_freeladdrs __P((struct sockaddr *));
1032 int sctp_opt_info __P((int, sctp_assoc_t, int, void *, socklen_t *));
1033 
1034 ssize_t sctp_sendmsg
1035 __P((int, const void *, size_t,
1036     const struct sockaddr *,
1037     socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
1038 
1039 	ssize_t sctp_send __P((int sd, const void *msg, size_t len,
1040               const struct sctp_sndrcvinfo *sinfo, int flags));
1041 
1042 	ssize_t
1043 	sctp_sendx __P((int sd, const void *msg, size_t len,
1044                struct sockaddr *addrs, int addrcnt,
1045                struct sctp_sndrcvinfo *sinfo, int flags));
1046 	ssize_t
1047 	sctp_sendmsgx __P((int sd, const void *, size_t,
1048                   struct sockaddr *, int,
1049                   uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
1050 
1051 sctp_assoc_t
1052 sctp_getassocid __P((int sd, struct sockaddr *sa));
1053 
1054 	ssize_t sctp_recvmsg __P((int, void *, size_t, struct sockaddr *,
1055                  socklen_t *, struct sctp_sndrcvinfo *, int *));
1056 
1057 __END_DECLS
1058 
1059 #endif				/* !_KERNEL */
1060 #endif				/* !__sctp_uio_h__ */
1061