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 _ISCSIT_COMMON_H_ 27 #define _ISCSIT_COMMON_H_ 28 29 #ifdef _KERNEL 30 #include <sys/nvpair.h> 31 #else 32 #include <libnvpair.h> 33 #endif 34 /* 35 * XXX Need to reverse this dependency, libiscsit.h should include 36 * iscsit_common.h, and iscsit_common.h should have all the core 37 * definitions. Kernel drivers should not pull in library header files. 38 */ 39 #include <libiscsit.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 #define ISCSIT_API_VERS0 0 46 47 typedef enum { 48 ITCFG_SUCCESS = 0, 49 ITCFG_INVALID, 50 ITCFG_TGT_CREATE_ERR, 51 ITCFG_MISC_ERR 52 } it_cfg_status_t; 53 54 /* 55 * This structure is passed back to the driver during ISCSIT_IOC_ENABLE_SVC 56 * in order to provide the fully qualified hostname for use as the EID 57 * by iSNS. 58 */ 59 60 #define ISCSIT_MAX_HOSTNAME_LEN 256 61 62 typedef struct iscsit_hostinfo_s { 63 uint32_t length; 64 char fqhn[ISCSIT_MAX_HOSTNAME_LEN]; 65 } iscsit_hostinfo_t; 66 67 #define ISCSIT_IOC_SET_CONFIG 1 68 #define ISCSIT_IOC_GET_STATE 2 69 #define ISCSIT_IOC_ENABLE_SVC 101 70 #define ISCSIT_IOC_DISABLE_SVC 102 71 72 /* XXX Rationalize these with other error values (used in it_smf.c */ 73 #define ITADM_SUCCESS 0 74 #define ITADM_FATAL_ERROR 0x1 75 #define ITADM_NO_MEM 0x2 76 #define ITADM_INVALID 0x4 77 #define ITADM_NODATA 0x8 78 #define ITADM_PERM 0x10 79 80 81 #define PROP_AUTH "auth" 82 #define PROP_ALIAS "alias" 83 #define PROP_CHAP_USER "chapuser" 84 #define PROP_CHAP_SECRET "chapsecret" 85 #define PROP_TARGET_CHAP_USER "targetchapuser" 86 #define PROP_TARGET_CHAP_SECRET "targetchapsecret" 87 #define PROP_RADIUS_SERVER "radiusserver" 88 #define PROP_RADIUS_SECRET "radiussecret" 89 #define PROP_ISNS_ENABLED "isns" 90 #define PROP_ISNS_SERVER "isnsserver" 91 #define PROP_OLD_TARGET_NAME "oldtargetname" 92 93 #define PA_AUTH_RADIUS "radius" 94 #define PA_AUTH_CHAP "chap" 95 #define PA_AUTH_NONE "none" 96 97 typedef struct { 98 int set_cfg_vers; 99 int set_cfg_pnvlist_len; 100 caddr_t set_cfg_pnvlist; 101 } iscsit_ioc_set_config_t; 102 103 typedef struct { 104 int getst_vers; 105 int getst_pnvlist_len; 106 char *getst_pnvlist; 107 } iscsit_ioc_getstate_t; 108 109 #ifdef _SYSCALL32 110 typedef struct { 111 int set_cfg_vers; 112 int set_cfg_pnvlist_len; 113 caddr32_t set_cfg_pnvlist; 114 } iscsit_ioc_set_config32_t; 115 116 typedef struct { 117 int getst_vers; 118 int getst_pnvlist_len; 119 caddr32_t getst_pnvlist; 120 } iscsit_ioc_getstate32_t; 121 #endif /* _SYSCALL32 */ 122 123 /* Functions to convert iSCSI target structures to/from nvlists. */ 124 int 125 it_config_to_nv(it_config_t *cfg, nvlist_t **nvl); 126 127 /* 128 * nvlist version of config is 3 list-of-list, + 1 proplist. arrays 129 * are interesting, but lists-of-lists are more useful when doing 130 * individual lookups when we later add support for it. Also, no 131 * need to store name in individual struct representation. 132 */ 133 int 134 it_nv_to_config(nvlist_t *nvl, it_config_t **cfg); 135 136 int 137 it_nv_to_tgtlist(nvlist_t *nvl, uint32_t *count, it_tgt_t **tgtlist); 138 139 int 140 it_tgtlist_to_nv(it_tgt_t *tgtlist, nvlist_t **nvl); 141 142 int 143 it_tgt_to_nv(it_tgt_t *tgt, nvlist_t **nvl); 144 145 int 146 it_nv_to_tgt(nvlist_t *nvl, char *name, it_tgt_t **tgt); 147 148 int 149 it_tpgt_to_nv(it_tpgt_t *tpgt, nvlist_t **nvl); 150 151 int 152 it_nv_to_tpgt(nvlist_t *nvl, char *name, it_tpgt_t **tpgt); 153 154 int 155 it_tpgtlist_to_nv(it_tpgt_t *tpgtlist, nvlist_t **nvl); 156 157 int 158 it_nv_to_tpgtlist(nvlist_t *nvl, uint32_t *count, it_tpgt_t **tpgtlist); 159 160 int 161 it_tpg_to_nv(it_tpg_t *tpg, nvlist_t **nvl); 162 163 int 164 it_nv_to_tpg(nvlist_t *nvl, char *name, it_tpg_t **tpg); 165 166 int 167 it_tpglist_to_nv(it_tpg_t *tpglist, nvlist_t **nvl); 168 169 int 170 it_nv_to_tpglist(nvlist_t *nvl, uint32_t *count, it_tpg_t **tpglist); 171 172 int 173 it_ini_to_nv(it_ini_t *ini, nvlist_t **nvl); 174 175 int 176 it_nv_to_ini(nvlist_t *nvl, char *name, it_ini_t **ini); 177 178 int 179 it_inilist_to_nv(it_ini_t *inilist, nvlist_t **nvl); 180 181 int 182 it_nv_to_inilist(nvlist_t *nvl, uint32_t *count, it_ini_t **inilist); 183 184 it_tgt_t * 185 it_tgt_lookup(it_config_t *cfg, char *tgt_name); 186 187 it_tpg_t * 188 it_tpg_lookup(it_config_t *cfg, char *tpg_name); 189 190 it_portal_t * 191 it_sns_svr_lookup(it_config_t *cfg, struct sockaddr_storage *sa); 192 193 it_portal_t * 194 it_portal_lookup(it_tpg_t *cfg_tpg, struct sockaddr_storage *sa); 195 196 int 197 it_sa_compare(struct sockaddr_storage *sa1, struct sockaddr_storage *sa2); 198 199 /* 200 * Convert a sockaddr to the string representation, suitable for 201 * storing in an nvlist or printing out in a list. 202 */ 203 int 204 sockaddr_to_str(struct sockaddr_storage *sa, char **addr); 205 206 /* 207 * Convert a char string to a sockaddr structure 208 * 209 * default_port should be the port to be used, if not specified 210 * as part of the supplied string 'arg'. 211 */ 212 struct sockaddr_storage * 213 it_common_convert_sa(char *arg, struct sockaddr_storage *buf, 214 uint32_t default_port); 215 216 /* 217 * Convert an string array of IP-addr:port to a portal list 218 */ 219 int 220 it_array_to_portallist(char **arr, uint32_t count, uint32_t default_port, 221 it_portal_t **portallist, uint32_t *list_count); 222 223 /* 224 * Function: it_config_free_cmn() 225 * 226 * Free any resources associated with the it_config_t structure. 227 * 228 * Parameters: 229 * cfg A C representation of the current iSCSI configuration 230 */ 231 void 232 it_config_free_cmn(it_config_t *cfg); 233 234 /* 235 * Function: it_tgt_free_cmn() 236 * 237 * Frees an it_tgt_t structure. If tgt_next is not NULL, frees 238 * all structures in the list. 239 */ 240 void 241 it_tgt_free_cmn(it_tgt_t *tgt); 242 243 /* 244 * Function: it_tpgt_free_cmn() 245 * 246 * Deallocates resources of an it_tpgt_t structure. If tpgt->next 247 * is not NULL, frees all members of the list. 248 */ 249 void 250 it_tpgt_free_cmn(it_tpgt_t *tpgt); 251 252 /* 253 * Function: it_tpg_free_cmn() 254 * 255 * Deallocates resources associated with an it_tpg_t structure. 256 * If tpg->next is not NULL, frees all members of the list. 257 */ 258 void 259 it_tpg_free_cmn(it_tpg_t *tpg); 260 261 /* 262 * Function: it_ini_free_cmn() 263 * 264 * Deallocates resources of an it_ini_t structure. If ini->next is 265 * not NULL, frees all members of the list. 266 */ 267 void 268 it_ini_free_cmn(it_ini_t *ini); 269 270 /* 271 * Function: iscsi_binary_to_base64_str() 272 * 273 * Encodes a byte array into a base64 string. 274 */ 275 int 276 iscsi_binary_to_base64_str(uint8_t *in_buf, int in_buf_len, 277 char *base64_str_buf, int base64_buf_len); 278 279 /* 280 * Function: iscsi_base64_str_to_binary() 281 * 282 * Decodes a base64 string into a byte array 283 */ 284 int 285 iscsi_base64_str_to_binary(char *hstr, int hstr_len, 286 uint8_t *binary, int binary_buf_len, int *out_len); 287 288 #ifdef __cplusplus 289 } 290 #endif 291 292 #endif /* _ISCSIT_COMMON_H_ */ 293