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 /* 23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 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 ushort_t ssa_wroff; 63 ssize_t ssa_wrsize; 64 int ssa_rcv_queued; /* queued rx bytes/# of conn */ 65 boolean_t ssa_flowctrld; /* receive flow controlled */ 66 }; 67 68 /* 1-N socket association cache defined in socksctp.c */ 69 70 /* 71 * Association array element. 72 * 73 * Association data structures for 1-N socket are stored in 74 * an array in similar manner to file descriptor array. 75 * Each association is identified by its association ID, which also 76 * is used as an index to this array (again, like file descriptor number). 77 */ 78 struct sctp_sa_id { 79 sctp_assoc_t ssi_alloc; 80 struct sctp_soassoc *ssi_assoc; 81 }; 82 83 extern sonodeops_t sosctp_sonodeops; 84 extern sonodeops_t sosctp_seq_sonodeops; 85 extern sock_upcalls_t sosctp_sock_upcalls; 86 extern sock_upcalls_t sosctp_assoc_upcalls; 87 88 extern struct sonode *socksctp_create(struct sockparams *, int, int, 89 int, int, int, int *, cred_t *); 90 extern void sosctp_fini(struct sonode *, struct cred *); 91 extern int sosctp_aid_grow(struct sctp_sonode *ss, sctp_assoc_t maxid, 92 int kmflags); 93 extern sctp_assoc_t sosctp_aid_get(struct sctp_sonode *ss); 94 extern void sosctp_aid_reserve(struct sctp_sonode *ss, sctp_assoc_t id, 95 int incr); 96 extern struct cmsghdr *sosctp_find_cmsg(const uchar_t *control, socklen_t clen, 97 int type); 98 extern void sosctp_pack_cmsg(const uchar_t *, struct nmsghdr *, int); 99 100 extern int sosctp_assoc(struct sctp_sonode *ss, sctp_assoc_t id, 101 struct sctp_soassoc **ssa); 102 extern struct sctp_soassoc *sosctp_assoc_create(struct sctp_sonode *ss, 103 int kmflags); 104 extern void sosctp_assoc_free(struct sctp_sonode *ss, struct sctp_soassoc *ssa); 105 extern int sosctp_assoc_createconn(struct sctp_sonode *ss, 106 const struct sockaddr *name, socklen_t namelen, 107 const uchar_t *control, socklen_t controllen, int fflag, struct cred *, 108 struct sctp_soassoc **ssap); 109 extern void sosctp_assoc_move(struct sctp_sonode *ss, struct sctp_sonode *nss, 110 struct sctp_soassoc *ssa); 111 extern void sosctp_so_inherit(struct sctp_sonode *lss, struct sctp_sonode *nss); 112 113 extern void sosctp_assoc_isconnecting(struct sctp_soassoc *ssa); 114 extern void sosctp_assoc_isconnected(struct sctp_soassoc *ssa); 115 extern void sosctp_assoc_isdisconnecting(struct sctp_soassoc *ssa); 116 extern void sosctp_assoc_isdisconnected(struct sctp_soassoc *ssa, int error); 117 118 extern int sosctp_waitconnected(struct sonode *so, int fmode); 119 extern int sosctp_uiomove(mblk_t *hdr_mp, ssize_t count, ssize_t blk_size, 120 int wroff, struct uio *uiop, int flags); 121 122 /* 123 * Data structure types. 124 */ 125 #define SOSCTP_SOCKET 0x1 126 #define SOSCTP_ASSOC 0x2 127 128 #define SOTOSSO(so) ((struct sctp_sonode *)(((char *)so) - \ 129 offsetof(struct sctp_sonode, ss_so))) 130 131 #define SSA_REFHOLD(ssa) \ 132 { \ 133 ASSERT(MUTEX_HELD(&(ssa)->ssa_sonode->ss_so.so_lock)); \ 134 ASSERT((ssa)->ssa_refcnt > 0); \ 135 ++(ssa)->ssa_refcnt; \ 136 dprint(3, ("ssa_refhold on %p %d (%s,%d)\n", \ 137 (void *)(ssa), (ssa)->ssa_refcnt, \ 138 __FILE__, __LINE__)); \ 139 } 140 141 142 #define SSA_REFRELE(ss, ssa) \ 143 { \ 144 dprint(3, ("ssa_refrele on %p %d (%s, %d)\n", \ 145 (void *)(ssa), \ 146 (ssa)->ssa_refcnt-1, __FILE__, __LINE__)); \ 147 ASSERT((ssa)->ssa_refcnt > 0); \ 148 if (--(ssa)->ssa_refcnt == 0) { \ 149 sosctp_assoc_free(ss, ssa); \ 150 } \ 151 } 152 153 #ifdef __cplusplus 154 } 155 #endif 156 157 #endif /* _SOCKSCTP_H_ */ 158