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