xref: /illumos-gate/usr/src/uts/common/netinet/sctp.h (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_NETINET_SCTP_H
27 #define	_NETINET_SCTP_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 
35 /*
36  * This file contains the structure defintions and function prototypes
37  * described in the IETF SCTP socket API document.
38  */
39 
40 /* SCTP association ID type. */
41 typedef int	sctp_assoc_t;
42 typedef int32_t	sctp_assoc32_t;
43 
44 /*
45  * SCTP socket options
46  */
47 #define	SCTP_RTOINFO			1
48 #define	SCTP_ASSOCINFO			2
49 #define	SCTP_INITMSG			3
50 #define	SCTP_NODELAY			4
51 #define	SCTP_AUTOCLOSE			5
52 #define	SCTP_SET_PEER_PRIMARY_ADDR	6
53 #define	SCTP_PRIMARY_ADDR		7
54 #define	SCTP_ADAPTATION_LAYER		8
55 #define	SCTP_DISABLE_FRAGMENTS		9
56 #define	SCTP_PEER_ADDR_PARAMS		10
57 #define	SCTP_DEFAULT_SEND_PARAM		11
58 #define	SCTP_EVENTS			12
59 #define	SCTP_I_WANT_MAPPED_V4_ADDR	13
60 #define	SCTP_MAXSEG			14
61 #define	SCTP_STATUS			15
62 #define	SCTP_GET_PEER_ADDR_INFO		16
63 
64 /*
65  * Private socket options
66  */
67 #define	SCTP_GET_NLADDRS		17
68 #define	SCTP_GET_LADDRS			18
69 #define	SCTP_GET_NPADDRS		19
70 #define	SCTP_GET_PADDRS			20
71 #define	SCTP_ADD_ADDR			21
72 #define	SCTP_REM_ADDR			22
73 
74 /*
75  * Additional SCTP socket options. This socket option is used to enable or
76  * disable PR-SCTP support prior to establishing an association. By default,
77  * PR-SCTP support is disabled.
78  */
79 #define	SCTP_PRSCTP			23
80 
81 /*
82  * SCTP socket option used to read per endpoint association statistics.
83  */
84 #define	SCTP_GET_ASSOC_STATS		24
85 
86 /*
87  * Ancillary data identifiers
88  */
89 #define	SCTP_SNDRCV		0x100
90 #define	SCTP_INIT		0x101
91 
92 /*
93  * Notification types
94  */
95 #define	SCTP_ASSOC_CHANGE		1
96 #define	SCTP_PEER_ADDR_CHANGE		2
97 #define	SCTP_REMOTE_ERROR		3
98 #define	SCTP_SEND_FAILED		4
99 #define	SCTP_SHUTDOWN_EVENT		5
100 #define	SCTP_ADAPTATION_INDICATION	6
101 #define	SCTP_PARTIAL_DELIVERY_EVENT	7
102 
103 /*
104  * SCTP Ancillary Data Definitions
105  */
106 
107 /*
108  * sctp_initmsg structure provides information for initializing new SCTP
109  * associations with sendmsg().  The SCTP_INITMSG socket option uses
110  * this same data structure.
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 /*
120  * sctp_sndrcvinfo structure specifies SCTP options for sendmsg() and
121  * describes SCTP header information about a received message through
122  * recvmsg().
123  */
124 struct sctp_sndrcvinfo {
125 	uint16_t	sinfo_stream;
126 	uint16_t	sinfo_ssn;
127 	uint16_t	sinfo_flags;
128 	uint32_t	sinfo_ppid;
129 	uint32_t	sinfo_context;
130 	uint32_t	sinfo_timetolive;
131 	uint32_t	sinfo_tsn;
132 	uint32_t	sinfo_cumtsn;
133 	sctp_assoc_t	sinfo_assoc_id;
134 };
135 
136 /* sinfo_flags */
137 #define	MSG_UNORDERED	0x01		/* Unordered data */
138 #define	MSG_ABORT	0x02		/* Abort the connection */
139 #define	MSG_EOF		0x04		/* Shutdown the connection */
140 
141 /*
142  * Use destination addr passed as parameter, not the association primary one.
143  */
144 #define	MSG_ADDR_OVER	0x08
145 /*
146  * This flag when set in sinfo_flags is used alongwith sinfo_timetolive to
147  * implement the "timed reliability" service discussed in RFC 3758.
148  */
149 #define	MSG_PR_SCTP	0x10
150 /*
151  * SCTP notification definitions
152  */
153 
154 /*
155  * To receive any ancillary data or notifications, the application can
156  * register it's interest by calling the SCTP_EVENTS setsockopt() with
157  * the sctp_event_subscribe structure.
158  */
159 struct sctp_event_subscribe {
160 	uint8_t	sctp_data_io_event;
161 	uint8_t sctp_association_event;
162 	uint8_t sctp_address_event;
163 	uint8_t sctp_send_failure_event;
164 	uint8_t sctp_peer_error_event;
165 	uint8_t sctp_shutdown_event;
166 	uint8_t sctp_partial_delivery_event;
167 	uint8_t sctp_adaptation_layer_event;
168 };
169 
170 /* Association events used in sctp_assoc_change structure */
171 #define	SCTP_COMM_UP		0
172 #define	SCTP_COMM_LOST		1
173 #define	SCTP_RESTART		2
174 #define	SCTP_SHUTDOWN_COMP	3
175 #define	SCTP_CANT_STR_ASSOC	4
176 
177 /*
178  * Association flags. This flags is filled in the sac_flags for a SCTP_COMM_UP
179  * event if the association supports PR-SCTP.
180  */
181 #define	SCTP_PRSCTP_CAPABLE	0x01
182 
183 /*
184  * sctp_assoc_change notification informs the socket that an SCTP association
185  * has either begun or ended.  The identifier for a new association is
186  * provided by this notification.
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 	 * The assoc ID can be followed by the ABORT chunk if available.
199 	 */
200 };
201 
202 /*
203  * A remote peer may send an Operational Error message to its peer. This
204  * message indicates a variety of error conditions on an association.
205  * The entire ERROR chunk as it appears on the wire is included in a
206  * SCTP_REMOTE_ERROR event.  Refer to the SCTP specification RFC2960
207  * and any extensions for a list of possible error formats.
208  */
209 struct sctp_remote_error {
210 	uint16_t	sre_type;
211 	uint16_t	sre_flags;
212 	uint32_t	sre_length;
213 	uint16_t	sre_error;
214 	sctp_assoc_t	sre_assoc_id;
215 	/*
216 	 * The assoc ID is followed by the actual error chunk.
217 	 */
218 };
219 
220 /*
221  * Note:
222  *
223  * In order to keep the offsets and size of the structure having a
224  * struct sockaddr_storage field the same between a 32-bit application
225  * and a 64-bit amd64 kernel, we use a #pragma pack(4) for those
226  * structures.
227  */
228 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
229 #pragma pack(4)
230 #endif
231 
232 /* Address change event state */
233 #define	SCTP_ADDR_AVAILABLE	0
234 #define	SCTP_ADDR_UNREACHABLE	1
235 #define	SCTP_ADDR_REMOVED	2
236 #define	SCTP_ADDR_ADDED		3
237 #define	SCTP_ADDR_MADE_PRIM	4
238 
239 /*
240  * When a destination address on a multi-homed peer encounters a change,
241  * an interface details event, sctp_paddr_change, is sent to the socket.
242  */
243 struct sctp_paddr_change {
244 	uint16_t	spc_type;
245 	uint16_t	spc_flags;
246 	uint32_t	spc_length;
247 	struct sockaddr_storage spc_aaddr;
248 	int		spc_state;
249 	int		spc_error;
250 	sctp_assoc_t	spc_assoc_id;
251 };
252 
253 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
254 #pragma pack()
255 #endif
256 
257 /* flags used in sctp_send_failed notification. */
258 #define	SCTP_DATA_UNSENT	1
259 #define	SCTP_DATA_SENT		2
260 
261 /*
262  * If SCTP cannot deliver a message it may return the message as a
263  * notification using the following structure.
264  */
265 struct sctp_send_failed {
266 	uint16_t	ssf_type;
267 	uint16_t	ssf_flags;
268 	uint32_t	ssf_length;
269 	uint32_t	ssf_error;
270 	struct sctp_sndrcvinfo ssf_info;
271 	sctp_assoc_t	ssf_assoc_id;
272 	/*
273 	 * The assoc ID is followed by the failed message.
274 	 */
275 };
276 
277 /*
278  * When a peer sends a SHUTDOWN, SCTP delivers the sctp_shutdown_event
279  * notification to inform the socket user that it should cease sending data.
280  */
281 struct sctp_shutdown_event {
282 	uint16_t	sse_type;
283 	uint16_t	sse_flags;
284 	uint16_t	sse_length;
285 	sctp_assoc_t	sse_assoc_id;
286 };
287 
288 /*
289  * When a peer sends an Adaptation Layer Indication parameter, SCTP
290  * delivers the sctp_adaptation_event notification to inform the socket
291  * user the peer's requested adaptation layer.
292  */
293 struct sctp_adaptation_event {
294 	uint16_t	sai_type;
295 	uint16_t	sai_flags;
296 	uint32_t	sai_length;
297 	uint32_t	sai_adaptation_ind;
298 	sctp_assoc_t	sai_assoc_id;
299 };
300 
301 /* Possible values in pdapi_indication for sctp_pdapi_event notification. */
302 #define	SCTP_PARTIAL_DELIVERY_ABORTED	1
303 
304 /*
305  * When a receiver is engaged in a partial delivery of a message the
306  * sctp_pdapi_event notification is used to indicate various events.
307  */
308 struct sctp_pdapi_event {
309 	uint16_t	pdapi_type;
310 	uint16_t	pdapi_flags;
311 	uint32_t	pdapi_length;
312 	uint32_t	pdapi_indication;
313 	sctp_assoc_t	pdapi_assoc_id;
314 };
315 
316 /*
317  * The sctp_notification structure is defined as the union of all
318  * notification types defined above.
319  */
320 union sctp_notification {
321 	struct {
322 		uint16_t		sn_type; /* Notification type. */
323 		uint16_t		sn_flags;
324 		uint32_t		sn_length;
325 	} sn_header;
326 	struct sctp_assoc_change	sn_assoc_change;
327 	struct sctp_paddr_change	sn_paddr_change;
328 	struct sctp_remote_error	sn_remote_error;
329 	struct sctp_send_failed		sn_send_failed;
330 	struct sctp_shutdown_event	sn_shutdown_event;
331 	struct sctp_adaptation_event	sn_adaptation_event;
332 	struct sctp_pdapi_event		sn_pdapi_event;
333 };
334 
335 /*
336  * sctp_opt_info() option definitions
337  */
338 
339 /*
340  * The protocol parameters used to initialize and bound retransmission
341  * timeout (RTO) are tunable.  See RFC2960 for more information on
342  * how these parameters are used in RTO calculation.
343  *
344  * The sctp_rtoinfo structure is used to access and modify these
345  * parameters.
346  */
347 struct sctp_rtoinfo {
348 	sctp_assoc_t	srto_assoc_id;
349 	uint32_t	srto_initial;
350 	uint32_t	srto_max;
351 	uint32_t	srto_min;
352 };
353 
354 /*
355  * The sctp_assocparams option is used to both examine and set various
356  * association and endpoint parameters.  See RFC2960 for more information
357  * on how this parameter is used.  The peer address parameter is ignored
358  * for one-to-one style socket.
359  */
360 struct sctp_assocparams {
361 	sctp_assoc_t	sasoc_assoc_id;
362 	uint16_t	sasoc_asocmaxrxt;
363 	uint16_t	sasoc_number_peer_destinations;
364 	uint32_t	sasoc_peer_rwnd;
365 	uint32_t	sasoc_local_rwnd;
366 	uint32_t	sasoc_cookie_life;
367 };
368 
369 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
370 #pragma pack(4)
371 #endif
372 
373 /* sctp_paddrinfo reachability state. */
374 #define	SCTP_INACTIVE	1
375 #define	SCTP_ACTIVE	2
376 
377 /*
378  * Applications can retrieve information about a specific peer address
379  * of an association, including its reachability state, congestion
380  * window, and retransmission timer values.  This information is
381  * read-only. The sctp_paddrinfo structure is used to access this
382  * information:
383  */
384 struct sctp_paddrinfo {
385 	sctp_assoc_t	spinfo_assoc_id;
386 	struct sockaddr_storage spinfo_address;
387 	int32_t		spinfo_state;
388 	uint32_t	spinfo_cwnd;
389 	uint32_t	spinfo_srtt;
390 	uint32_t	spinfo_rto;
391 	uint32_t	spinfo_mtu;
392 };
393 
394 /*
395  * Applications can enable or disable heartbeats for any peer address of
396  * an association, modify an address's heartbeat interval, force a
397  * heartbeat to be sent immediately, and adjust the address's maximum
398  * number of retransmissions sent before an address is considered
399  * unreachable.  The sctp_paddrparams structure is used to access and modify
400  * an address' parameters.
401  */
402 struct sctp_paddrparams {
403 	sctp_assoc_t		spp_assoc_id;
404 	struct sockaddr_storage	spp_address;
405 	uint32_t		spp_hbinterval;
406 	uint16_t		spp_pathmaxrxt;
407 };
408 
409 /*
410  * A socket user can request that the peer mark the enclosed address as the
411  * association's primary.  The enclosed address must be one of the
412  * association's locally bound addresses. The sctp_setpeerprim structure is
413  * used to make such request.
414  */
415 struct sctp_setpeerprim {
416 	sctp_assoc_t		sspp_assoc_id;
417 	struct sockaddr_storage	sspp_addr;
418 };
419 
420 /*
421  * A socket user can request that the local SCTP stack use the enclosed peer
422  * address as the association primary.  The enclosed address must be one of
423  * the association peer's addresses.  The sctp_setprim structure is used to
424  * make such request.
425  */
426 struct sctp_setprim {
427 	sctp_assoc_t		ssp_assoc_id;
428 	struct sockaddr_storage	ssp_addr;
429 };
430 
431 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
432 #pragma pack()
433 #endif
434 
435 /* SCTP association states */
436 #define	SCTPS_IDLE		-5	/* idle (opened, but not bound) */
437 #define	SCTPS_BOUND		-4	/* bound, ready to connect or accept */
438 #define	SCTPS_LISTEN		-3	/* listening for connection */
439 #define	SCTPS_COOKIE_WAIT	-2
440 #define	SCTPS_COOKIE_ECHOED	-1
441 /* states < SCTPS_ESTABLISHED are those where connections not established */
442 #define	SCTPS_ESTABLISHED	0	/* established */
443 #define	SCTPS_SHUTDOWN_PENDING	1
444 #define	SCTPS_SHUTDOWN_SENT	2
445 #define	SCTPS_SHUTDOWN_RECEIVED	3
446 #define	SCTPS_SHUTDOWN_ACK_SENT	4
447 
448 /*
449  * Applications can retrieve current status information about an
450  * association, including association state, peer receiver window size,
451  * number of unacked data chunks, and number of data chunks pending
452  * receipt.  This information is read-only.  The sctp_status structure is
453  * used to access this information:
454  */
455 struct sctp_status {
456 	sctp_assoc_t		sstat_assoc_id;
457 	int32_t			sstat_state;
458 	uint32_t		sstat_rwnd;
459 	uint16_t		sstat_unackdata;
460 	uint16_t		sstat_penddata;
461 	uint16_t		sstat_instrms;
462 	uint16_t		sstat_outstrms;
463 	uint32_t		sstat_fragmentation_point;
464 	struct sctp_paddrinfo	sstat_primary;
465 };
466 
467 /* Possible values for sstat_state */
468 #define	SCTP_CLOSED		SCTPS_IDLE
469 #define	SCTP_BOUND		SCTPS_BOUND
470 #define	SCTP_LISTEN		SCTPS_LISTEN
471 #define	SCTP_COOKIE_WAIT	SCTPS_COOKIE_WAIT
472 #define	SCTP_COOKIE_ECHOED	SCTPS_COOKIE_ECHOED
473 #define	SCTP_ESTABLISHED	SCTPS_ESTABLISHED
474 #define	SCTP_SHUTDOWN_PENDING	SCTPS_SHUTDOWN_PENDING
475 #define	SCTP_SHUTDOWN_SENT	SCTPS_SHUTDOWN_SENT
476 #define	SCTP_SHUTDOWN_RECEIVED	SCTPS_SHUTDOWN_RECEIVED
477 #define	SCTP_SHUTDOWN_ACK_SENT	SCTPS_SHUTDOWN_ACK_SENT
478 
479 /*
480  * A socket user can request that the local endpoint set the specified
481  * Adaptation Layer Indication parameter for all future INIT and INIT-ACK
482  * exchanges.  The sctp_setadaptation structure is used to make such request.
483  */
484 struct sctp_setadaptation {
485 	uint32_t   ssb_adaptation_ind;
486 };
487 
488 /*
489  * A socket user request reads local per endpoint association stats.
490  * All stats are counts except sas_maxrto, which is the max value
491  * since the last user request for stats on this endpoint.
492  */
493 typedef struct sctp_assoc_stats {
494 	uint64_t	sas_rtxchunks; /* Retransmitted Chunks */
495 	uint64_t	sas_gapcnt; /* Gap Acknowledgements Received */
496 	uint64_t	sas_maxrto; /* Maximum Observed RTO this period */
497 	uint64_t	sas_outseqtsns; /* TSN received > next expected */
498 	uint64_t	sas_osacks; /* SACKs sent */
499 	uint64_t	sas_isacks; /* SACKs received */
500 	uint64_t	sas_octrlchunks; /* Control chunks sent - no dups */
501 	uint64_t	sas_ictrlchunks; /* Control chunks received - no dups */
502 	uint64_t	sas_oodchunks; /* Ordered data chunks sent */
503 	uint64_t	sas_iodchunks; /* Ordered data chunks received */
504 	uint64_t	sas_ouodchunks; /* Unordered data chunks sent */
505 	uint64_t	sas_iuodchunks; /* Unordered data chunks received */
506 	uint64_t	sas_idupchunks; /* Dups received (ordered+unordered) */
507 } sctp_assoc_stats_t;
508 
509 /*
510  * Private ioctl option structure
511  */
512 struct sctpopt {
513 	sctp_assoc_t	sopt_aid;
514 	int		sopt_name;
515 	uint_t		sopt_len;
516 	caddr_t		sopt_val;
517 };
518 
519 #if defined(_SYSCALL32)
520 struct sctpopt32 {
521 	sctp_assoc32_t	sopt_aid;
522 	int32_t		sopt_name;
523 	uint32_t	sopt_len;
524 	caddr32_t	sopt_val;
525 };
526 #endif	/* _SYSCALL32 */
527 
528 /* Forward Cumulative TSN chunk entry. */
529 typedef struct ftsn_entry_s {
530 	uint16_t	ftsn_sid;
531 	uint16_t	ftsn_ssn;
532 } ftsn_entry_t;
533 
534 /*
535  * New socket functions for SCTP
536  */
537 
538 /* sctp_bindx() operations. */
539 #define	SCTP_BINDX_ADD_ADDR	1
540 #define	SCTP_BINDX_REM_ADDR	2
541 
542 #if !defined(_KERNEL) || defined(_BOOT)
543 #ifdef	__STDC__
544 extern int sctp_bindx(int, void *, int, int);
545 extern void sctp_freeladdrs(void *);
546 extern void sctp_freepaddrs(void *);
547 extern int sctp_getladdrs(int, sctp_assoc_t, void **);
548 extern int sctp_getpaddrs(int, sctp_assoc_t, void **);
549 extern int sctp_opt_info(int, sctp_assoc_t, int, void *, socklen_t *);
550 extern int sctp_peeloff(int, sctp_assoc_t);
551 extern ssize_t sctp_recvmsg(int, void *, size_t, struct sockaddr *,
552     socklen_t *, struct sctp_sndrcvinfo *, int *msg_flags);
553 extern ssize_t sctp_send(int, const void *, size_t,
554     const struct sctp_sndrcvinfo *, int);
555 extern ssize_t sctp_sendmsg(int, const void *, size_t, const struct sockaddr *,
556     socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t);
557 #else	/* __STDC__ */
558 extern int sctp_bindx();
559 extern void sctp_freeladdrs();
560 extern void sctp_freepaddrs();
561 extern int sctp_getladdrs();
562 extern int sctp_getpaddrs();
563 extern int sctp_opt_info();
564 extern int sctp_peeloff();
565 extern ssize_t sctp_recvmsg();
566 extern ssize_t sctp_send();
567 extern ssize_t sctp_sendmsg();
568 #endif	/* __STDC__ */
569 #endif	/* !defined(_KERNEL) || defined(_BOOT) */
570 
571 
572 /*
573  * SCTP protocol related elements.
574  */
575 
576 /* All SCTP chunks and parameters are 32-bit aligned */
577 #define	SCTP_ALIGN	4
578 
579 /*
580  * SCTP association optional parameter handling. The top two bits
581  * of the parameter type define how this and further parameters in
582  * the received chunk should be handled.
583  */
584 #define	SCTP_UNREC_PARAM_MASK	0xc000
585 /* Continue processing parameters after an unrecognized optional param? */
586 #define	SCTP_CONT_PROC_PARAMS	0x8000
587 /* Report this unreconized optional parameter or silently ignore it? */
588 #define	SCTP_REPORT_THIS_PARAM	0x4000
589 
590 /*
591  * Data chunk bit manipulations
592  */
593 #define	SCTP_DATA_EBIT	0x01
594 #define	SCTP_TBIT	0x01
595 #define	SCTP_DATA_BBIT	0x02
596 #define	SCTP_DATA_UBIT	0x04
597 
598 #define	SCTP_DATA_GET_BBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_BBIT)
599 #define	SCTP_GET_TBIT(cp)	((cp)->sch_flags & SCTP_TBIT)
600 #define	SCTP_DATA_GET_EBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_EBIT)
601 #define	SCTP_DATA_GET_UBIT(sdc)	((sdc)->sdh_flags & SCTP_DATA_UBIT)
602 
603 #define	SCTP_DATA_SET_BBIT(sdc)	((sdc)->sdh_flags |= SCTP_DATA_BBIT)
604 #define	SCTP_SET_TBIT(cp)	((cp)->sch_flags |= SCTP_TBIT)
605 #define	SCTP_DATA_SET_EBIT(sdc)	((sdc)->sdh_flags |= SCTP_DATA_EBIT)
606 #define	SCTP_DATA_SET_UBIT(sdc)	((sdc)->sdh_flags |=  SCTP_DATA_UBIT)
607 
608 /* SCTP common header */
609 typedef struct sctp_hdr {
610 	uint16_t	sh_sport;
611 	uint16_t	sh_dport;
612 	uint32_t	sh_verf;
613 	uint32_t	sh_chksum;
614 } sctp_hdr_t;
615 
616 /* Chunk IDs */
617 typedef enum {
618 	CHUNK_DATA,
619 	CHUNK_INIT,
620 	CHUNK_INIT_ACK,
621 	CHUNK_SACK,
622 	CHUNK_HEARTBEAT,
623 	CHUNK_HEARTBEAT_ACK,
624 	CHUNK_ABORT,
625 	CHUNK_SHUTDOWN,
626 	CHUNK_SHUTDOWN_ACK,
627 	CHUNK_ERROR,
628 	CHUNK_COOKIE,
629 	CHUNK_COOKIE_ACK,
630 	CHUNK_ECNE,
631 	CHUNK_CWR,
632 	CHUNK_SHUTDOWN_COMPLETE,
633 	CHUNK_ASCONF_ACK = 128,
634 	CHUNK_FORWARD_TSN = 192,
635 	CHUNK_ASCONF = 193
636 } sctp_chunk_id_t;
637 
638 /* Common chunk header */
639 typedef struct sctp_chunk_hdr {
640 	uint8_t		sch_id;
641 	uint8_t		sch_flags;
642 	uint16_t	sch_len;
643 } sctp_chunk_hdr_t;
644 
645 /* INIT chunk data definition */
646 typedef struct sctp_init_chunk {
647 	uint32_t	sic_inittag;
648 	uint32_t	sic_a_rwnd;
649 	uint16_t	sic_outstr;
650 	uint16_t	sic_instr;
651 	uint32_t	sic_inittsn;
652 } sctp_init_chunk_t;
653 
654 /* SCTP DATA chunk */
655 typedef struct sctp_data_chunk {
656 	uint32_t	sdc_tsn;
657 	uint16_t	sdc_sid;
658 	uint16_t	sdc_ssn;
659 	uint32_t	sdc_payload_id;
660 } sctp_data_chunk_t;
661 
662 /* sctp_data_hdr includes the SCTP chunk hdr and the DATA chunk */
663 typedef struct sctp_data_hdr {
664 	sctp_chunk_hdr_t	sdh_chdr;
665 	sctp_data_chunk_t	sdh_data;
666 #define	sdh_id		sdh_chdr.sch_id
667 #define	sdh_flags	sdh_chdr.sch_flags
668 #define	sdh_len		sdh_chdr.sch_len
669 #define	sdh_tsn		sdh_data.sdc_tsn
670 #define	sdh_sid		sdh_data.sdc_sid
671 #define	sdh_ssn		sdh_data.sdc_ssn
672 #define	sdh_payload_id	sdh_data.sdc_payload_id
673 } sctp_data_hdr_t;
674 
675 typedef struct sctp_sack_chunk {
676 	uint32_t	ssc_cumtsn;
677 	uint32_t	ssc_a_rwnd;
678 	uint16_t	ssc_numfrags;
679 	uint16_t	ssc_numdups;
680 } sctp_sack_chunk_t;
681 
682 typedef struct sctp_sack_frag {
683 	uint16_t	ssf_start;
684 	uint16_t	ssf_end;
685 } sctp_sack_frag_t;
686 
687 /* Parameter types */
688 #define	PARM_UNKNOWN		0
689 #define	PARM_HBINFO		1
690 #define	PARM_ADDR4		5
691 #define	PARM_ADDR6		6
692 #define	PARM_COOKIE		7
693 #define	PARM_UNRECOGNIZED	8
694 #define	PARM_COOKIE_PRESERVE	9
695 #define	PARM_ADDR_HOST_NAME	11
696 #define	PARM_SUPP_ADDRS		12
697 #define	PARM_ECN		0x8000
698 #define	PARM_ECN_CAPABLE	PARM_ECN
699 #define	PARM_FORWARD_TSN	0xc000
700 #define	PARM_ADD_IP		0xc001
701 #define	PARM_DEL_IP		0xc002
702 #define	PARM_ERROR_IND		0xc003
703 #define	PARM_ASCONF_ERROR	PARM_ERROR_IND
704 #define	PARM_SET_PRIMARY	0xc004
705 #define	PARM_PRIMARY_ADDR	PARM_SET_PRIMARY
706 #define	PARM_SUCCESS		0xc005
707 #define	PARM_ASCONF_SUCCESS	PARM_SUCCESS
708 #define	PARM_ADAPT_LAYER_IND	0xc006
709 
710 
711 /* Lengths from SCTP spec */
712 #define	PARM_ADDR4_LEN		8
713 #define	PARM_ADDR6_LEN		20
714 
715 /* Parameter header */
716 typedef struct sctp_parm_hdr {
717 	uint16_t	sph_type;
718 	uint16_t	sph_len;
719 } sctp_parm_hdr_t;
720 
721 /*
722  * The following extend sctp_parm_hdr_t
723  * with cause-specfic content used to fill
724  * CAUSE blocks in ABORT or ERROR chunks.
725  * The overall size of the CAUSE block will
726  * be sizeof (sctp_parm_hdr_t) plus the size
727  * of the extended cause structure,
728  */
729 
730 /*
731  * Invalid stream-identifier extended cause.
732  * SCTP_ERR_BAD_SID
733  */
734 typedef struct sctp_bsc {
735 	uint16_t	bsc_sid;
736 	uint16_t	bsc_pad; /* RESV = 0 */
737 } sctp_bsc_t;
738 
739 /*
740  * Missing parameter extended cause, currently
741  * only one missing parameter is supported.
742  * SCTP_ERR_MISSING_PARM
743  */
744 typedef struct sctp_mpc {
745 	uint32_t	mpc_num;
746 	uint16_t	mpc_param;
747 	uint16_t	mpc_pad;
748 } sctp_mpc_t;
749 
750 /* Error causes */
751 #define	SCTP_ERR_UNKNOWN		0
752 #define	SCTP_ERR_BAD_SID		1
753 #define	SCTP_ERR_MISSING_PARM		2
754 #define	SCTP_ERR_STALE_COOKIE		3
755 #define	SCTP_ERR_NO_RESOURCES		4
756 #define	SCTP_ERR_BAD_ADDR		5
757 #define	SCTP_ERR_UNREC_CHUNK		6
758 #define	SCTP_ERR_BAD_MANDPARM		7
759 #define	SCTP_ERR_UNREC_PARM		8
760 #define	SCTP_ERR_NO_USR_DATA		9
761 #define	SCTP_ERR_COOKIE_SHUT		10
762 #define	SCTP_ERR_RESTART_NEW_ADDRS	11
763 #define	SCTP_ERR_USER_ABORT		12
764 #define	SCTP_ERR_DELETE_LASTADDR	256
765 #define	SCTP_ERR_RESOURCE_SHORTAGE	257
766 #define	SCTP_ERR_DELETE_SRCADDR		258
767 #define	SCTP_ERR_AUTH_ERR		260
768 
769 /*
770  * Extensions
771  */
772 
773 /* Extended Chunk Types */
774 #define	CHUNK_ASCONF		0xc1
775 #define	CHUNK_ASCONF_ACK	0x80
776 
777 /* Extension Error Causes */
778 #define	SCTP_ERR_DEL_LAST_ADDR	0x0100
779 #define	SCTP_ERR_RES_SHORTAGE	0x0101
780 #define	SCTP_ERR_DEL_SRC_ADDR	0x0102
781 #define	SCTP_ERR_ILLEGAL_ACK	0x0103
782 #define	SCTP_ERR_UNAUTHORIZED	0x0104
783 
784 typedef struct sctp_addip4 {
785 	sctp_parm_hdr_t		sad4_addip_ph;
786 	uint32_t		asconf_req_cid;
787 	sctp_parm_hdr_t		sad4_addr4_ph;
788 	ipaddr_t		sad4_addr;
789 } sctp_addip4_t;
790 
791 typedef struct sctp_addip6 {
792 	sctp_parm_hdr_t		sad6_addip_ph;
793 	uint32_t		asconf_req_cid;
794 	sctp_parm_hdr_t		sad6_addr6_ph;
795 	in6_addr_t		sad6_addr;
796 } sctp_addip6_t;
797 
798 #ifdef __cplusplus
799 }
800 #endif
801 
802 #endif	/* _NETINET_SCTP_H */
803