xref: /illumos-gate/usr/src/uts/common/sys/ib/clients/rds/rds.h (revision 85f4cb87104c72587029a6e0f1663332c85ba118)
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 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_RDS_H
27 #define	_RDS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/t_lock.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/buf.h>
40 #include <sys/vfs.h>
41 #include <sys/vnode.h>
42 #include <sys/debug.h>
43 #include <sys/errno.h>
44 #include <sys/stropts.h>
45 #include <sys/cmn_err.h>
46 #include <sys/sysmacros.h>
47 
48 #include <sys/project.h>
49 #include <sys/tihdr.h>
50 #include <sys/strsubr.h>
51 
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
54 #include <sys/strsun.h>
55 
56 #include <inet/common.h>
57 #include <inet/ip.h>
58 #include <inet/optcom.h>
59 
60 #include <sys/sunldi.h>
61 #include <sys/dlpi.h>
62 
63 #include <inet/ip_ire.h>
64 
65 #undef  dprint
66 #ifdef DEBUG
67 extern int rdsdebug;
68 #define	dprint(level, args)	{ if (rdsdebug > (level)) printf args; }
69 #else
70 #define	dprint(level, args) {}
71 #endif
72 
73 typedef struct rds_s {
74 	kmutex_t	rds_lock;	/* protects rds_refcnt */
75 	int		rds_refcnt;
76 	kcondvar_t	rds_refcv;
77 	uint32_t	rds_state;	/* TPI state */
78 	uint32_t	rds_flags;
79 	sa_family_t	rds_family;	/* Family from socket() call */
80 	cred_t		*rds_cred;
81 	in_port_t	rds_port;	/* Port bound to this stream */
82 	ipaddr_t	rds_src;	/* Source address of this stream */
83 	void		*rds_ulpd;	/* queue to send message on */
84 	struct rds_s	*rds_bind_hash;	/* Bind hash chain */
85 	struct rds_s	**rds_ptpbhn;	/* Ptr to previous bind hash next. */
86 	ulong_t		rds_port_quota; /* Port quota */
87 	zoneid_t	rds_zoneid;
88 } rds_t;
89 
90 #define	RDS_CLOSING 	0x1
91 
92 #define	RDS_INCR_REF_CNT(rds)  { 	\
93 	mutex_enter(&rds->rds_lock);	\
94 	rds->rds_refcnt++;	\
95 	ASSERT(rds->rds_refcnt != 0); \
96 	mutex_exit(&rds->rds_lock); \
97 }
98 
99 #define	RDS_DEC_REF_CNT(rds)  { 	\
100 	mutex_enter(&rds->rds_lock);	\
101 	ASSERT(rds->rds_refcnt > 0); \
102 	rds->rds_refcnt--;	\
103 	if (rds->rds_refcnt == 1)	\
104 		cv_broadcast(&(rds)->rds_refcv); \
105 	if (rds->rds_refcnt == 0) {	\
106 		rds_free(rds);	\
107 	} else {	\
108 		mutex_exit(&rds->rds_lock); \
109 	}	\
110 }
111 
112 
113 #define	RDS_MATCH(rdsp, lport, laddr)               \
114 	(((rdsp)->rds_port == lport) &&		\
115 	((rdsp)->rds_src == laddr))
116 
117 /* RDS bind fanout hash structure. */
118 typedef struct rds_bind_fanout_s {
119 	rds_t *rds_bf_rds;
120 	kmutex_t rds_bf_lock;
121 #if defined(_LP64) || defined(_I32LPx)
122 	char    bf_pad[48];
123 #else
124 	char    bf_pad[56];
125 #endif
126 }rds_bf_t;
127 
128 extern ldi_ident_t rds_li;
129 
130 #define	RDS_BIND_FANOUT_SIZE    512
131 #define	RDS_BIND_HASH(lport) \
132 	((ntohs((uint16_t)lport)) & (rds_bind_fanout_size - 1))
133 
134 #define	AF_INET_OFFLOAD 30
135 
136 extern	uint_t rds_bind_fanout_size;
137 extern	rds_bf_t *rds_bind_fanout;
138 
139 extern optdb_obj_t rds_opt_obj;
140 
141 extern void rds_hash_init();
142 
143 extern	void rds_free(rds_t *rds);
144 extern rds_t *rds_create(void *rds_ulpd, cred_t *credp);
145 
146 extern void rds_bind_hash_remove(rds_t *rds, boolean_t);
147 extern void rds_bind_hash_insert(rds_bf_t *, rds_t *);
148 extern rds_t *rds_fanout(ipaddr_t, ipaddr_t, in_port_t, in_port_t, zoneid_t);
149 extern void rds_add_new_msg(mblk_t *mp, ipaddr_t, ipaddr_t, in_port_t,
150     in_port_t);
151 extern boolean_t rds_verify_bind_address(ipaddr_t addr);
152 extern boolean_t rds_islocal(ipaddr_t addr);
153 extern boolean_t rds_if_lookup_by_name(char *if_name);
154 extern boolean_t rds_if_lookup_by_addr(ipaddr_t addr);
155 
156 
157 extern void rds_init();
158 extern void rds_fini();
159 
160 
161 #ifdef	__cplusplus
162 }
163 #endif
164 
165 #endif	/* _RDS_H */
166