xref: /titanic_52/usr/src/uts/common/inet/sockmods/socksctp.h (revision a215d4eb400e2ff52f7a17e0781964c37aabfc04)
10f1702c5SYu Xiangning /*
20f1702c5SYu Xiangning  * CDDL HEADER START
30f1702c5SYu Xiangning  *
40f1702c5SYu Xiangning  * The contents of this file are subject to the terms of the
50f1702c5SYu Xiangning  * Common Development and Distribution License (the "License").
60f1702c5SYu Xiangning  * You may not use this file except in compliance with the License.
70f1702c5SYu Xiangning  *
80f1702c5SYu Xiangning  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90f1702c5SYu Xiangning  * or http://www.opensolaris.org/os/licensing.
100f1702c5SYu Xiangning  * See the License for the specific language governing permissions
110f1702c5SYu Xiangning  * and limitations under the License.
120f1702c5SYu Xiangning  *
130f1702c5SYu Xiangning  * When distributing Covered Code, include this CDDL HEADER in each
140f1702c5SYu Xiangning  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150f1702c5SYu Xiangning  * If applicable, add the following below this CDDL HEADER, with the
160f1702c5SYu Xiangning  * fields enclosed by brackets "[]" replaced with your own identifying
170f1702c5SYu Xiangning  * information: Portions Copyright [yyyy] [name of copyright owner]
180f1702c5SYu Xiangning  *
190f1702c5SYu Xiangning  * CDDL HEADER END
200f1702c5SYu Xiangning  */
21*a215d4ebSKacheong Poon 
220f1702c5SYu Xiangning /*
23*a215d4ebSKacheong Poon  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240f1702c5SYu Xiangning  */
250f1702c5SYu Xiangning 
260f1702c5SYu Xiangning #ifndef	_SOCKSCTP_H_
270f1702c5SYu Xiangning #define	_SOCKSCTP_H_
280f1702c5SYu Xiangning 
290f1702c5SYu Xiangning #ifdef	__cplusplus
300f1702c5SYu Xiangning extern "C" {
310f1702c5SYu Xiangning #endif
320f1702c5SYu Xiangning 
330f1702c5SYu Xiangning /*
340f1702c5SYu Xiangning  * SCTP socket structure.
350f1702c5SYu Xiangning  *
360f1702c5SYu Xiangning  * The opaque pointer passed in upcalls is either a pointer to sctp_sonode,
370f1702c5SYu Xiangning  * or sctp_soassoc. The identification is done through the first element
380f1702c5SYu Xiangning  * in data structure (if it cannot be identified by upcall which gets called).
390f1702c5SYu Xiangning  */
400f1702c5SYu Xiangning struct sctp_sonode {
410f1702c5SYu Xiangning 	int			ss_type;	/* sonode or soassoc */
420f1702c5SYu Xiangning 	struct sonode		ss_so;
430f1702c5SYu Xiangning 	sctp_assoc_t		ss_maxassoc;	/* assoc array size for 1-N */
440f1702c5SYu Xiangning 	sctp_assoc_t		ss_assoccnt;	/* current # of assocs */
450f1702c5SYu Xiangning 	struct sctp_sa_id	*ss_assocs;	/* assoc array for 1-N */
460f1702c5SYu Xiangning #define	ss_wroff	ss_so.so_proto_props.sopp_wroff
470f1702c5SYu Xiangning #define	ss_wrsize	ss_so.so_proto_props.sopp_maxblk
480f1702c5SYu Xiangning };
490f1702c5SYu Xiangning 
500f1702c5SYu Xiangning /*
510f1702c5SYu Xiangning  * Association for 1-N sockets.
520f1702c5SYu Xiangning  */
530f1702c5SYu Xiangning struct sctp_soassoc {
540f1702c5SYu Xiangning 	int			ssa_type;
550f1702c5SYu Xiangning 	sctp_assoc_t		ssa_id;		/* association ID */
560f1702c5SYu Xiangning 	uint_t			ssa_refcnt;
570f1702c5SYu Xiangning 	struct sctp_sonode	*ssa_sonode;
580f1702c5SYu Xiangning 	struct sctp_s		*ssa_conn;	/* opaque ptr passed to SCTP */
590f1702c5SYu Xiangning 	uint_t			ssa_state;	/* same as so_state */
600f1702c5SYu Xiangning 	int			ssa_error;	/* same as so_error */
610f1702c5SYu Xiangning 	boolean_t		ssa_snd_qfull;
62*a215d4ebSKacheong Poon 	ushort_t		ssa_wroff;
63*a215d4ebSKacheong Poon 	ssize_t			ssa_wrsize;
640f1702c5SYu Xiangning 	int			ssa_rcv_queued;	/* queued rx bytes/# of conn */
65*a215d4ebSKacheong Poon 	boolean_t		ssa_flowctrld;	/* receive flow controlled */
660f1702c5SYu Xiangning };
670f1702c5SYu Xiangning 
680f1702c5SYu Xiangning /* 1-N socket association cache defined in socksctp.c */
690f1702c5SYu Xiangning 
700f1702c5SYu Xiangning /*
710f1702c5SYu Xiangning  * Association array element.
720f1702c5SYu Xiangning  *
730f1702c5SYu Xiangning  * Association data structures for 1-N socket are stored in
740f1702c5SYu Xiangning  * an array in similar manner to file descriptor array.
750f1702c5SYu Xiangning  * Each association is identified by its association ID, which also
760f1702c5SYu Xiangning  * is used as an index to this array (again, like file descriptor number).
770f1702c5SYu Xiangning  */
780f1702c5SYu Xiangning struct sctp_sa_id {
790f1702c5SYu Xiangning 	sctp_assoc_t		ssi_alloc;
800f1702c5SYu Xiangning 	struct sctp_soassoc	*ssi_assoc;
810f1702c5SYu Xiangning };
820f1702c5SYu Xiangning 
830f1702c5SYu Xiangning extern sonodeops_t sosctp_sonodeops;
840f1702c5SYu Xiangning extern sonodeops_t sosctp_seq_sonodeops;
850f1702c5SYu Xiangning extern sock_upcalls_t sosctp_sock_upcalls;
860f1702c5SYu Xiangning extern sock_upcalls_t sosctp_assoc_upcalls;
870f1702c5SYu Xiangning 
880f1702c5SYu Xiangning extern struct sonode *socksctp_create(struct sockparams *, int, int,
890f1702c5SYu Xiangning     int, int, int, int *, cred_t *);
900f1702c5SYu Xiangning extern void sosctp_fini(struct sonode *, struct cred *);
910f1702c5SYu Xiangning extern int sosctp_aid_grow(struct sctp_sonode *ss, sctp_assoc_t maxid,
920f1702c5SYu Xiangning     int kmflags);
930f1702c5SYu Xiangning extern sctp_assoc_t sosctp_aid_get(struct sctp_sonode *ss);
940f1702c5SYu Xiangning extern void sosctp_aid_reserve(struct sctp_sonode *ss, sctp_assoc_t id,
950f1702c5SYu Xiangning     int incr);
960f1702c5SYu Xiangning extern struct cmsghdr *sosctp_find_cmsg(const uchar_t *control, socklen_t clen,
970f1702c5SYu Xiangning     int type);
980f1702c5SYu Xiangning extern void sosctp_pack_cmsg(const uchar_t *, struct nmsghdr *, int);
990f1702c5SYu Xiangning 
1000f1702c5SYu Xiangning extern int sosctp_assoc(struct sctp_sonode *ss, sctp_assoc_t id,
1010f1702c5SYu Xiangning     struct sctp_soassoc **ssa);
1020f1702c5SYu Xiangning extern struct sctp_soassoc *sosctp_assoc_create(struct sctp_sonode *ss,
1030f1702c5SYu Xiangning     int kmflags);
1040f1702c5SYu Xiangning extern void sosctp_assoc_free(struct sctp_sonode *ss, struct sctp_soassoc *ssa);
1050f1702c5SYu Xiangning extern int sosctp_assoc_createconn(struct sctp_sonode *ss,
1060f1702c5SYu Xiangning     const struct sockaddr *name, socklen_t namelen,
1070f1702c5SYu Xiangning     const uchar_t *control, socklen_t controllen, int fflag, struct cred *,
1080f1702c5SYu Xiangning     struct sctp_soassoc **ssap);
1090f1702c5SYu Xiangning extern void sosctp_assoc_move(struct sctp_sonode *ss, struct sctp_sonode *nss,
1100f1702c5SYu Xiangning     struct sctp_soassoc *ssa);
1110f1702c5SYu Xiangning extern void sosctp_so_inherit(struct sctp_sonode *lss, struct sctp_sonode *nss);
1120f1702c5SYu Xiangning 
1130f1702c5SYu Xiangning extern void sosctp_assoc_isconnecting(struct sctp_soassoc *ssa);
1140f1702c5SYu Xiangning extern void sosctp_assoc_isconnected(struct sctp_soassoc *ssa);
1150f1702c5SYu Xiangning extern void sosctp_assoc_isdisconnecting(struct sctp_soassoc *ssa);
1160f1702c5SYu Xiangning extern void sosctp_assoc_isdisconnected(struct sctp_soassoc *ssa, int error);
1170f1702c5SYu Xiangning 
1180f1702c5SYu Xiangning extern int sosctp_waitconnected(struct sonode *so, int fmode);
1190f1702c5SYu Xiangning extern int sosctp_uiomove(mblk_t *hdr_mp, ssize_t count, ssize_t blk_size,
120bd670b35SErik Nordmark     int wroff, struct uio *uiop, int flags);
1210f1702c5SYu Xiangning 
1220f1702c5SYu Xiangning /*
1230f1702c5SYu Xiangning  * Data structure types.
1240f1702c5SYu Xiangning  */
1250f1702c5SYu Xiangning #define	SOSCTP_SOCKET	0x1
1260f1702c5SYu Xiangning #define	SOSCTP_ASSOC	0x2
1270f1702c5SYu Xiangning 
1280f1702c5SYu Xiangning #define	SOTOSSO(so) ((struct sctp_sonode *)(((char *)so) -	\
1290f1702c5SYu Xiangning 			offsetof(struct sctp_sonode, ss_so)))
1300f1702c5SYu Xiangning 
1310f1702c5SYu Xiangning #define	SSA_REFHOLD(ssa)					\
1320f1702c5SYu Xiangning {								\
1330f1702c5SYu Xiangning 	ASSERT(MUTEX_HELD(&(ssa)->ssa_sonode->ss_so.so_lock));	\
1340f1702c5SYu Xiangning 	ASSERT((ssa)->ssa_refcnt > 0);				\
1350f1702c5SYu Xiangning 	++(ssa)->ssa_refcnt;					\
1360f1702c5SYu Xiangning 	dprint(3, ("ssa_refhold on %p %d (%s,%d)\n", 		\
1370f1702c5SYu Xiangning 		(void *)(ssa), (ssa)->ssa_refcnt,		\
1380f1702c5SYu Xiangning 		__FILE__, __LINE__));				\
1390f1702c5SYu Xiangning }
1400f1702c5SYu Xiangning 
1410f1702c5SYu Xiangning 
1420f1702c5SYu Xiangning #define	SSA_REFRELE(ss, ssa)					\
1430f1702c5SYu Xiangning {								\
1440f1702c5SYu Xiangning 	dprint(3, ("ssa_refrele on %p %d (%s, %d)\n",		\
1450f1702c5SYu Xiangning 		(void *)(ssa),					\
1460f1702c5SYu Xiangning 		(ssa)->ssa_refcnt-1, __FILE__, __LINE__));	\
1470f1702c5SYu Xiangning 	ASSERT((ssa)->ssa_refcnt > 0);				\
1480f1702c5SYu Xiangning 	if (--(ssa)->ssa_refcnt == 0) {				\
1490f1702c5SYu Xiangning 		sosctp_assoc_free(ss, ssa);			\
1500f1702c5SYu Xiangning 	}							\
1510f1702c5SYu Xiangning }
1520f1702c5SYu Xiangning 
1530f1702c5SYu Xiangning #ifdef	__cplusplus
1540f1702c5SYu Xiangning }
1550f1702c5SYu Xiangning #endif
1560f1702c5SYu Xiangning 
1570f1702c5SYu Xiangning #endif /* _SOCKSCTP_H_ */
158