xref: /titanic_41/usr/src/uts/common/inet/sockmods/socksctp.h (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
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	_SOCKSCTP_H_
27 #define	_SOCKSCTP_H_
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * SCTP socket structure.
35  *
36  * The opaque pointer passed in upcalls is either a pointer to sctp_sonode,
37  * or sctp_soassoc. The identification is done through the first element
38  * in data structure (if it cannot be identified by upcall which gets called).
39  */
40 struct sctp_sonode {
41 	int			ss_type;	/* sonode or soassoc */
42 	struct sonode		ss_so;
43 	sctp_assoc_t		ss_maxassoc;	/* assoc array size for 1-N */
44 	sctp_assoc_t		ss_assoccnt;	/* current # of assocs */
45 	struct sctp_sa_id	*ss_assocs;	/* assoc array for 1-N */
46 #define	ss_wroff	ss_so.so_proto_props.sopp_wroff
47 #define	ss_wrsize	ss_so.so_proto_props.sopp_maxblk
48 };
49 
50 /*
51  * Association for 1-N sockets.
52  */
53 struct sctp_soassoc {
54 	int			ssa_type;
55 	sctp_assoc_t		ssa_id;		/* association ID */
56 	uint_t			ssa_refcnt;
57 	struct sctp_sonode	*ssa_sonode;
58 	struct sctp_s		*ssa_conn;	/* opaque ptr passed to SCTP */
59 	uint_t			ssa_state;	/* same as so_state */
60 	int			ssa_error;	/* same as so_error */
61 	boolean_t		ssa_snd_qfull;
62 	int			ssa_wroff;
63 	size_t			ssa_wrsize;
64 	int			ssa_rcv_queued;	/* queued rx bytes/# of conn */
65 };
66 
67 /* 1-N socket association cache defined in socksctp.c */
68 
69 /*
70  * Association array element.
71  *
72  * Association data structures for 1-N socket are stored in
73  * an array in similar manner to file descriptor array.
74  * Each association is identified by its association ID, which also
75  * is used as an index to this array (again, like file descriptor number).
76  */
77 struct sctp_sa_id {
78 	sctp_assoc_t		ssi_alloc;
79 	struct sctp_soassoc	*ssi_assoc;
80 };
81 
82 extern sonodeops_t sosctp_sonodeops;
83 extern sonodeops_t sosctp_seq_sonodeops;
84 extern sock_upcalls_t sosctp_sock_upcalls;
85 extern sock_upcalls_t sosctp_assoc_upcalls;
86 
87 extern struct sonode *socksctp_create(struct sockparams *, int, int,
88     int, int, int, int *, cred_t *);
89 extern void sosctp_fini(struct sonode *, struct cred *);
90 extern int sosctp_aid_grow(struct sctp_sonode *ss, sctp_assoc_t maxid,
91     int kmflags);
92 extern sctp_assoc_t sosctp_aid_get(struct sctp_sonode *ss);
93 extern void sosctp_aid_reserve(struct sctp_sonode *ss, sctp_assoc_t id,
94     int incr);
95 extern struct cmsghdr *sosctp_find_cmsg(const uchar_t *control, socklen_t clen,
96     int type);
97 extern void sosctp_pack_cmsg(const uchar_t *, struct nmsghdr *, int);
98 
99 extern int sosctp_assoc(struct sctp_sonode *ss, sctp_assoc_t id,
100     struct sctp_soassoc **ssa);
101 extern struct sctp_soassoc *sosctp_assoc_create(struct sctp_sonode *ss,
102     int kmflags);
103 extern void sosctp_assoc_free(struct sctp_sonode *ss, struct sctp_soassoc *ssa);
104 extern int sosctp_assoc_createconn(struct sctp_sonode *ss,
105     const struct sockaddr *name, socklen_t namelen,
106     const uchar_t *control, socklen_t controllen, int fflag, struct cred *,
107     struct sctp_soassoc **ssap);
108 extern void sosctp_assoc_move(struct sctp_sonode *ss, struct sctp_sonode *nss,
109     struct sctp_soassoc *ssa);
110 extern void sosctp_so_inherit(struct sctp_sonode *lss, struct sctp_sonode *nss);
111 
112 extern void sosctp_assoc_isconnecting(struct sctp_soassoc *ssa);
113 extern void sosctp_assoc_isconnected(struct sctp_soassoc *ssa);
114 extern void sosctp_assoc_isdisconnecting(struct sctp_soassoc *ssa);
115 extern void sosctp_assoc_isdisconnected(struct sctp_soassoc *ssa, int error);
116 
117 extern int sosctp_waitconnected(struct sonode *so, int fmode);
118 extern int sosctp_uiomove(mblk_t *hdr_mp, ssize_t count, ssize_t blk_size,
119     int wroff, struct uio *uiop, int flags, cred_t *cr);
120 
121 /*
122  * Data structure types.
123  */
124 #define	SOSCTP_SOCKET	0x1
125 #define	SOSCTP_ASSOC	0x2
126 
127 #define	SOTOSSO(so) ((struct sctp_sonode *)(((char *)so) -	\
128 			offsetof(struct sctp_sonode, ss_so)))
129 
130 #define	SSA_REFHOLD(ssa)					\
131 {								\
132 	ASSERT(MUTEX_HELD(&(ssa)->ssa_sonode->ss_so.so_lock));	\
133 	ASSERT((ssa)->ssa_refcnt > 0);				\
134 	++(ssa)->ssa_refcnt;					\
135 	dprint(3, ("ssa_refhold on %p %d (%s,%d)\n", 		\
136 		(void *)(ssa), (ssa)->ssa_refcnt,		\
137 		__FILE__, __LINE__));				\
138 }
139 
140 
141 #define	SSA_REFRELE(ss, ssa)					\
142 {								\
143 	dprint(3, ("ssa_refrele on %p %d (%s, %d)\n",		\
144 		(void *)(ssa),					\
145 		(ssa)->ssa_refcnt-1, __FILE__, __LINE__));	\
146 	ASSERT((ssa)->ssa_refcnt > 0);				\
147 	if (--(ssa)->ssa_refcnt == 0) {				\
148 		sosctp_assoc_free(ss, ssa);			\
149 	}							\
150 }
151 
152 #ifdef	__cplusplus
153 }
154 #endif
155 
156 #endif /* _SOCKSCTP_H_ */
157