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