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