1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 22fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23fcf3ce44SJohn Forte * Use is subject to license terms. 24fcf3ce44SJohn Forte */ 25fcf3ce44SJohn Forte 26fcf3ce44SJohn Forte #include <arpa/inet.h> 27fcf3ce44SJohn Forte #include <sys/socket.h> 28fcf3ce44SJohn Forte #include <sys/types.h> 29fcf3ce44SJohn Forte #include <stdarg.h> 30fcf3ce44SJohn Forte #include <stdlib.h> 31fcf3ce44SJohn Forte #include <string.h> 32fcf3ce44SJohn Forte #include <strings.h> 33fcf3ce44SJohn Forte #include <unistd.h> 34fcf3ce44SJohn Forte #include <syslog.h> 35fcf3ce44SJohn Forte #include <errno.h> 36fcf3ce44SJohn Forte 37fcf3ce44SJohn Forte #include <fcntl.h> 38fcf3ce44SJohn Forte #include <stdio.h> 39fcf3ce44SJohn Forte #include <time.h> 40fcf3ce44SJohn Forte #include <libdevinfo.h> 41fcf3ce44SJohn Forte 42fcf3ce44SJohn Forte #include <sys/scsi/adapters/iscsi_if.h> 43fcf3ce44SJohn Forte #include <sys/scsi/adapters/iscsi_protocol.h> 44fcf3ce44SJohn Forte #include <ima.h> 45fcf3ce44SJohn Forte #include "iscsiadm.h" 46fcf3ce44SJohn Forte #include "sun_ima.h" 47fcf3ce44SJohn Forte 48fcf3ce44SJohn Forte #define LIBRARY_PROPERTY_SUPPORTED_IMA_VERSION 1 49fcf3ce44SJohn Forte #define LIBRARY_PROPERTY_IMPLEMENTATION_VERSION L"1.0.0" 50fcf3ce44SJohn Forte #define LIBRARY_PROPERTY_VENDOR L"Sun Microsystems, Inc." 51fcf3ce44SJohn Forte #define DEFAULT_NODE_NAME_FORMAT "iqn.2003-13.com.ima.%s" 52fcf3ce44SJohn Forte #define PLUGIN_OWNER 1 53*6cefaae1SJack Meng #define MAX_CHAP_SECRET_LEN 16 54fcf3ce44SJohn Forte 55fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 56fcf3ce44SJohn Forte static IMA_INT32 number_of_plugins = -1; 57fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 58fcf3ce44SJohn Forte static IMA_NODE_NAME sharedNodeName; 59fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 60fcf3ce44SJohn Forte static IMA_NODE_ALIAS sharedNodeAlias; 61fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 62fcf3ce44SJohn Forte static IMA_PLUGIN_PROPERTIES PluginProperties; 63fcf3ce44SJohn Forte 64fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 65fcf3ce44SJohn Forte static IMA_OID pluginOid; 66fcf3ce44SJohn Forte static IMA_OID lhbaObjectId; 67fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 68fcf3ce44SJohn Forte static boolean_t pluginInit = B_FALSE; 69fcf3ce44SJohn Forte 70fcf3ce44SJohn Forte /* Forward declaration */ 71fcf3ce44SJohn Forte #define BOOL_PARAM 1 72fcf3ce44SJohn Forte #define MIN_MAX_PARAM 2 73fcf3ce44SJohn Forte #define PARAM_OP_OK 0 74fcf3ce44SJohn Forte #define PARAM_OP_FAILED 1 75fcf3ce44SJohn Forte 76fcf3ce44SJohn Forte static int open_driver(int *fd); 77fcf3ce44SJohn Forte static IMA_STATUS getISCSINodeParameter(int paramType, 78fcf3ce44SJohn Forte IMA_OID *oid, 79fcf3ce44SJohn Forte void *pProps, 80fcf3ce44SJohn Forte uint32_t paramIndex); 81fcf3ce44SJohn Forte static IMA_STATUS setISCSINodeParameter(int paramType, 82fcf3ce44SJohn Forte IMA_OID *oid, 83fcf3ce44SJohn Forte void *pProps, 84fcf3ce44SJohn Forte uint32_t paramIndex); 85fcf3ce44SJohn Forte static IMA_STATUS getDigest(IMA_OID oid, int ioctlCmd, 86fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm); 87fcf3ce44SJohn Forte static IMA_STATUS setAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount, 88fcf3ce44SJohn Forte const IMA_AUTHMETHOD *pMethodList); 89fcf3ce44SJohn Forte static IMA_STATUS getAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount, 90fcf3ce44SJohn Forte IMA_AUTHMETHOD *pMethodList); 91fcf3ce44SJohn Forte IMA_STATUS getNegotiatedDigest(int digestType, 92fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm, 93fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES *connProps); 94fcf3ce44SJohn Forte 95fcf3ce44SJohn Forte /* OK */ 96fcf3ce44SJohn Forte #define DISC_ADDR_OK 0 97fcf3ce44SJohn Forte /* Incorrect IP address */ 98fcf3ce44SJohn Forte #define DISC_ADDR_INTEGRITY_ERROR 1 99fcf3ce44SJohn Forte /* Error converting text IP address to numeric binary form */ 100fcf3ce44SJohn Forte #define DISC_ADDR_IP_CONV_ERROR 2 101fcf3ce44SJohn Forte static int prepare_discovery_entry(SUN_IMA_TARGET_ADDRESS discoveryAddress, 102fcf3ce44SJohn Forte entry_t *entry); 103fcf3ce44SJohn Forte static int prepare_discovery_entry_IMA(IMA_TARGET_ADDRESS discoveryAddress, 104fcf3ce44SJohn Forte entry_t *entry); 105fcf3ce44SJohn Forte 106fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 107fcf3ce44SJohn Forte static IMA_STATUS configure_discovery_method(IMA_BOOL enable, 108fcf3ce44SJohn Forte iSCSIDiscoveryMethod_t method); 109fcf3ce44SJohn Forte 110fcf3ce44SJohn Forte static IMA_STATUS get_target_oid_list(uint32_t targetListType, 111fcf3ce44SJohn Forte IMA_OID_LIST **ppList); 112fcf3ce44SJohn Forte 113fcf3ce44SJohn Forte static IMA_STATUS get_target_lun_oid_list(IMA_OID * targetOid, 114fcf3ce44SJohn Forte iscsi_lun_list_t **ppLunList); 115fcf3ce44SJohn Forte 116fcf3ce44SJohn Forte static int get_lun_devlink(di_devlink_t link, void *osDeviceName); 117fcf3ce44SJohn Forte 118fcf3ce44SJohn Forte static IMA_STATUS getConnOidList( 119fcf3ce44SJohn Forte IMA_OID *oid, 120fcf3ce44SJohn Forte iscsi_conn_list_t **ppConnList); 121fcf3ce44SJohn Forte 122fcf3ce44SJohn Forte static IMA_STATUS getConnProps( 123fcf3ce44SJohn Forte iscsi_if_conn_t *pConn, 124fcf3ce44SJohn Forte iscsi_conn_props_t **ppConnProps); 125fcf3ce44SJohn Forte 126fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 127fcf3ce44SJohn Forte static void libSwprintf(wchar_t *wcs, const wchar_t *lpszFormat, ...) 128fcf3ce44SJohn Forte { 129fcf3ce44SJohn Forte va_list args; 130fcf3ce44SJohn Forte va_start(args, lpszFormat); 131fcf3ce44SJohn Forte (void) vswprintf(wcs, 255, lpszFormat, args); 132fcf3ce44SJohn Forte va_end(args); 133fcf3ce44SJohn Forte } 134fcf3ce44SJohn Forte 135fcf3ce44SJohn Forte 136fcf3ce44SJohn Forte char * 137fcf3ce44SJohn Forte _strlwr(char *s) 138fcf3ce44SJohn Forte { 139fcf3ce44SJohn Forte char *t = s; 140fcf3ce44SJohn Forte while (t != NULL && *t) { 141fcf3ce44SJohn Forte if (*t >= 'A' && *t <= 'Z') 142fcf3ce44SJohn Forte *t += 32; 143fcf3ce44SJohn Forte t++; 144fcf3ce44SJohn Forte } 145fcf3ce44SJohn Forte return (s); 146fcf3ce44SJohn Forte } 147fcf3ce44SJohn Forte 148fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 149fcf3ce44SJohn Forte static void GetBuildTime(IMA_DATETIME* pdatetime) 150fcf3ce44SJohn Forte { 151fcf3ce44SJohn Forte #if defined(BUILD_DATE) 152fcf3ce44SJohn Forte if (strptime(BUILD_DATE, "%Y/%m/%d %T %Z", pdatetime) == NULL) { 153fcf3ce44SJohn Forte (void) memset(pdatetime, 0, sizeof (IMA_DATETIME)); 154fcf3ce44SJohn Forte } 155fcf3ce44SJohn Forte #else 156fcf3ce44SJohn Forte (void) memset(pdatetime, 0, sizeof (IMA_DATETIME)); 157fcf3ce44SJohn Forte #endif 158fcf3ce44SJohn Forte } 159fcf3ce44SJohn Forte 160fcf3ce44SJohn Forte /* 161fcf3ce44SJohn Forte * Non-IMA defined function. 162fcf3ce44SJohn Forte */ 163fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetDiscoveryAddressPropertiesList( 164fcf3ce44SJohn Forte SUN_IMA_DISC_ADDR_PROP_LIST **ppList 165fcf3ce44SJohn Forte ) 166fcf3ce44SJohn Forte { 167fcf3ce44SJohn Forte char discovery_addr_str[256]; 168fcf3ce44SJohn Forte int fd; 169fcf3ce44SJohn Forte int i; 170fcf3ce44SJohn Forte int discovery_addr_list_size; 171fcf3ce44SJohn Forte int status; 172fcf3ce44SJohn Forte int out_cnt; 173fcf3ce44SJohn Forte iscsi_addr_list_t *ialp; 174fcf3ce44SJohn Forte /* LINTED E_FUNC_SET_NOT_USED */ 175fcf3ce44SJohn Forte IMA_IP_ADDRESS *ipAddr; 176fcf3ce44SJohn Forte 177fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 178fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 179fcf3ce44SJohn Forte } 180fcf3ce44SJohn Forte 181fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, sizeof (iscsi_addr_list_t)); 182fcf3ce44SJohn Forte if (ialp == NULL) { 183fcf3ce44SJohn Forte (void) close(fd); 184fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 185fcf3ce44SJohn Forte } 186fcf3ce44SJohn Forte 187fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 188fcf3ce44SJohn Forte ialp->al_in_cnt = ialp->al_out_cnt = 1; 189fcf3ce44SJohn Forte 190fcf3ce44SJohn Forte /* 191fcf3ce44SJohn Forte * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl 192fcf3ce44SJohn Forte * We have allocated space for one entry, if more than one 193fcf3ce44SJohn Forte * address is going to be returned, we will re-issue the ioctl 194fcf3ce44SJohn Forte */ 195fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, ialp) != 0) { 196fcf3ce44SJohn Forte (void) close(fd); 197fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 198fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d", 199fcf3ce44SJohn Forte errno); 200fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 201fcf3ce44SJohn Forte } 202fcf3ce44SJohn Forte 203fcf3ce44SJohn Forte if (ialp->al_out_cnt > 1) { 204fcf3ce44SJohn Forte /* 205fcf3ce44SJohn Forte * we need to allocate more space, save off the out_cnt 206fcf3ce44SJohn Forte * and free ialp 207fcf3ce44SJohn Forte */ 208fcf3ce44SJohn Forte out_cnt = ialp->al_out_cnt; 209fcf3ce44SJohn Forte free(ialp); 210fcf3ce44SJohn Forte 211fcf3ce44SJohn Forte discovery_addr_list_size = sizeof (iscsi_addr_list_t); 212fcf3ce44SJohn Forte discovery_addr_list_size += (sizeof (iscsi_addr_t) * 213fcf3ce44SJohn Forte out_cnt - 1); 214fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, discovery_addr_list_size); 215fcf3ce44SJohn Forte if (ialp == NULL) { 216fcf3ce44SJohn Forte (void) close(fd); 217fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 218fcf3ce44SJohn Forte } 219fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 220fcf3ce44SJohn Forte ialp->al_in_cnt = out_cnt; 221fcf3ce44SJohn Forte 222fcf3ce44SJohn Forte /* 223fcf3ce44SJohn Forte * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl again to obtain all 224fcf3ce44SJohn Forte * the discovery addresses. 225fcf3ce44SJohn Forte */ 226fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, ialp) != 0) { 227fcf3ce44SJohn Forte #define ERROR_STR "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno :%d" 228fcf3ce44SJohn Forte free(ialp); 229fcf3ce44SJohn Forte (void) close(fd); 230fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 231fcf3ce44SJohn Forte ERROR_STR, errno); 232fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 233fcf3ce44SJohn Forte #undef ERROR_STR 234fcf3ce44SJohn Forte 235fcf3ce44SJohn Forte } 236fcf3ce44SJohn Forte } 237fcf3ce44SJohn Forte 238fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *)calloc(1, 239fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) + 240fcf3ce44SJohn Forte ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES)); 241fcf3ce44SJohn Forte if (*ppList == NULL) { 242fcf3ce44SJohn Forte free(ialp); 243fcf3ce44SJohn Forte (void) close(fd); 244fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 245fcf3ce44SJohn Forte } 246fcf3ce44SJohn Forte (*ppList)->discAddrCount = ialp->al_out_cnt; 247fcf3ce44SJohn Forte 248fcf3ce44SJohn Forte for (i = 0; i < ialp->al_out_cnt; i++) { 249fcf3ce44SJohn Forte if (ialp->al_addrs[i].a_addr.i_insize == 250fcf3ce44SJohn Forte sizeof (struct in_addr)) { 251fcf3ce44SJohn Forte 252fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 253fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_TRUE; 254fcf3ce44SJohn Forte 255fcf3ce44SJohn Forte } else if (ialp->al_addrs[i].a_addr.i_insize == 256fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 257fcf3ce44SJohn Forte 258fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 259fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_FALSE; 260fcf3ce44SJohn Forte 261fcf3ce44SJohn Forte } else { 262fcf3ce44SJohn Forte (void) strlcpy(discovery_addr_str, "unknown", 263fcf3ce44SJohn Forte sizeof (discovery_addr_str)); 264fcf3ce44SJohn Forte } 265fcf3ce44SJohn Forte 266fcf3ce44SJohn Forte ipAddr = &(*ppList)->props[i].discoveryAddress. 267fcf3ce44SJohn Forte hostnameIpAddress.id.ipAddress; 268fcf3ce44SJohn Forte 269fcf3ce44SJohn Forte bcopy(&ialp->al_addrs[i].a_addr.i_addr, 270fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress.id. 271fcf3ce44SJohn Forte ipAddress.ipAddress, 272fcf3ce44SJohn Forte sizeof (ipAddr->ipAddress)); 273fcf3ce44SJohn Forte 274fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.portNumber = 275fcf3ce44SJohn Forte ialp->al_addrs[i].a_port; 276fcf3ce44SJohn Forte } 277fcf3ce44SJohn Forte 278fcf3ce44SJohn Forte free(ialp); 279fcf3ce44SJohn Forte (void) close(fd); 280fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 281fcf3ce44SJohn Forte } 282fcf3ce44SJohn Forte 283fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetStaticTargetProperties( 284fcf3ce44SJohn Forte IMA_OID staticTargetOid, 285fcf3ce44SJohn Forte SUN_IMA_STATIC_TARGET_PROPERTIES *pProps 286fcf3ce44SJohn Forte ) 287fcf3ce44SJohn Forte { 288fcf3ce44SJohn Forte int fd; 289fcf3ce44SJohn Forte int status; 290fcf3ce44SJohn Forte iscsi_static_property_t prop; 291fcf3ce44SJohn Forte /* LINTED */ 292fcf3ce44SJohn Forte IMA_IP_ADDRESS *ipAddr; 293fcf3ce44SJohn Forte 294fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 295fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 296fcf3ce44SJohn Forte } 297fcf3ce44SJohn Forte 298fcf3ce44SJohn Forte (void) memset(&prop, 0, sizeof (iscsi_static_property_t)); 299fcf3ce44SJohn Forte prop.p_vers = ISCSI_INTERFACE_VERSION; 300fcf3ce44SJohn Forte prop.p_oid = (uint32_t)staticTargetOid.objectSequenceNumber; 301fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_STATIC_GET, &prop) != 0) { 302fcf3ce44SJohn Forte status = errno; 303fcf3ce44SJohn Forte (void) close(fd); 304fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 305fcf3ce44SJohn Forte "ISCSI_STATIC_GET ioctl failed, errno: %d", status); 306fcf3ce44SJohn Forte if (status == ENOENT) { 307fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 308fcf3ce44SJohn Forte } else { 309fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 310fcf3ce44SJohn Forte } 311fcf3ce44SJohn Forte } 312fcf3ce44SJohn Forte (void) close(fd); 313fcf3ce44SJohn Forte 314fcf3ce44SJohn Forte (void) mbstowcs(pProps->staticTarget.targetName, (char *)prop.p_name, 315fcf3ce44SJohn Forte sizeof (pProps->staticTarget.targetName)/sizeof (IMA_WCHAR)); 316fcf3ce44SJohn Forte 317fcf3ce44SJohn Forte if (prop.p_addr_list.al_addrs[0].a_addr.i_insize == 318fcf3ce44SJohn Forte sizeof (struct in_addr)) { 319fcf3ce44SJohn Forte /* IPv4 */ 320fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.imaStruct.hostnameIpAddress. 321fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_TRUE; 322fcf3ce44SJohn Forte } else if (prop.p_addr_list.al_addrs[0].a_addr.i_insize == 323fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 324fcf3ce44SJohn Forte /* IPv6 */ 325fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.imaStruct.hostnameIpAddress. 326fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_FALSE; 327fcf3ce44SJohn Forte } else { 328fcf3ce44SJohn Forte /* Should not happen */ 329fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 330fcf3ce44SJohn Forte "ISCSI_STATIC_GET returned bad address"); 331fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 332fcf3ce44SJohn Forte } 333fcf3ce44SJohn Forte 334fcf3ce44SJohn Forte ipAddr = &pProps->staticTarget.targetAddress.imaStruct. 335fcf3ce44SJohn Forte hostnameIpAddress.id.ipAddress; 336fcf3ce44SJohn Forte 337fcf3ce44SJohn Forte bcopy(&prop.p_addr_list.al_addrs[0].a_addr.i_addr, 338fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.imaStruct.hostnameIpAddress.id. 339fcf3ce44SJohn Forte ipAddress.ipAddress, sizeof (ipAddr->ipAddress)); 340fcf3ce44SJohn Forte 341fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.imaStruct.portNumber = 342fcf3ce44SJohn Forte prop.p_addr_list.al_addrs[0].a_port; 343fcf3ce44SJohn Forte 344fcf3ce44SJohn Forte 345fcf3ce44SJohn Forte if (prop.p_addr_list.al_tpgt == (uint32_t)ISCSI_DEFAULT_TPGT) { 346fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.defaultTpgt = IMA_TRUE; 347fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.tpgt = 0; 348fcf3ce44SJohn Forte } else { 349fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.defaultTpgt = IMA_FALSE; 350fcf3ce44SJohn Forte pProps->staticTarget.targetAddress.tpgt = 351fcf3ce44SJohn Forte prop.p_addr_list.al_tpgt; 352fcf3ce44SJohn Forte } 353fcf3ce44SJohn Forte 354fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 355fcf3ce44SJohn Forte } 356fcf3ce44SJohn Forte 357fcf3ce44SJohn Forte /*ARGSUSED*/ 358fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_AddStaticTarget( 359fcf3ce44SJohn Forte IMA_OID lhbaOid, 360fcf3ce44SJohn Forte const SUN_IMA_STATIC_DISCOVERY_TARGET staticConfig, 361fcf3ce44SJohn Forte IMA_OID *pTargetOid 362fcf3ce44SJohn Forte ) 363fcf3ce44SJohn Forte { 364fcf3ce44SJohn Forte iscsi_target_entry_t target; 365fcf3ce44SJohn Forte int fd; 366fcf3ce44SJohn Forte int target_in_addr_size; 367fcf3ce44SJohn Forte int status; 368fcf3ce44SJohn Forte union { 369fcf3ce44SJohn Forte struct in_addr u_in4; 370fcf3ce44SJohn Forte struct in6_addr u_in6; 371fcf3ce44SJohn Forte } target_in; 372fcf3ce44SJohn Forte 373fcf3ce44SJohn Forte /* 374fcf3ce44SJohn Forte * staticConfig.address may come in with port number at its trailer. 375fcf3ce44SJohn Forte * Parse it to separate the IP address and port number. 376fcf3ce44SJohn Forte * Also translate the hostname to IP address if needed. 377fcf3ce44SJohn Forte */ 378fcf3ce44SJohn Forte 379fcf3ce44SJohn Forte if (staticConfig.targetAddress.imaStruct.hostnameIpAddress.id.ipAddress. 380fcf3ce44SJohn Forte ipv4Address == IMA_FALSE) { 381fcf3ce44SJohn Forte 382fcf3ce44SJohn Forte bcopy(staticConfig.targetAddress.imaStruct.hostnameIpAddress. 383fcf3ce44SJohn Forte id.ipAddress.ipAddress, &target_in.u_in6, 384fcf3ce44SJohn Forte sizeof (target_in.u_in6)); 385fcf3ce44SJohn Forte 386fcf3ce44SJohn Forte target_in_addr_size = sizeof (struct in6_addr); 387fcf3ce44SJohn Forte } else { 388fcf3ce44SJohn Forte 389fcf3ce44SJohn Forte bcopy(staticConfig.targetAddress.imaStruct.hostnameIpAddress. 390fcf3ce44SJohn Forte id.ipAddress.ipAddress, &target_in.u_in4, 391fcf3ce44SJohn Forte sizeof (target_in.u_in4)); 392fcf3ce44SJohn Forte 393fcf3ce44SJohn Forte target_in_addr_size = sizeof (struct in_addr); 394fcf3ce44SJohn Forte } 395fcf3ce44SJohn Forte 396fcf3ce44SJohn Forte (void) memset(&target, 0, sizeof (iscsi_target_entry_t)); 397fcf3ce44SJohn Forte target.te_entry.e_vers = ISCSI_INTERFACE_VERSION; 398fcf3ce44SJohn Forte target.te_entry.e_oid = ISCSI_OID_NOTSET; 399fcf3ce44SJohn Forte 400fcf3ce44SJohn Forte (void) wcstombs((char *)target.te_name, staticConfig.targetName, 401fcf3ce44SJohn Forte ISCSI_MAX_NAME_LEN); 402fcf3ce44SJohn Forte 403fcf3ce44SJohn Forte target.te_entry.e_insize = target_in_addr_size; 404fcf3ce44SJohn Forte if (target.te_entry.e_insize == sizeof (struct in_addr)) { 405fcf3ce44SJohn Forte target.te_entry.e_u.u_in4.s_addr = target_in.u_in4.s_addr; 406fcf3ce44SJohn Forte } else if (target.te_entry.e_insize == sizeof (struct in6_addr)) { 407fcf3ce44SJohn Forte bcopy(target_in.u_in6.s6_addr, 408fcf3ce44SJohn Forte target.te_entry.e_u.u_in6.s6_addr, 409fcf3ce44SJohn Forte sizeof (struct in6_addr)); 410fcf3ce44SJohn Forte } else { 411fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 412fcf3ce44SJohn Forte } 413fcf3ce44SJohn Forte 414fcf3ce44SJohn Forte target.te_entry.e_port = 415fcf3ce44SJohn Forte staticConfig.targetAddress.imaStruct.portNumber; 416fcf3ce44SJohn Forte 417fcf3ce44SJohn Forte if (staticConfig.targetAddress.defaultTpgt == IMA_TRUE) { 418fcf3ce44SJohn Forte target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT; 419fcf3ce44SJohn Forte } else { 420fcf3ce44SJohn Forte target.te_entry.e_tpgt = staticConfig.targetAddress.tpgt; 421fcf3ce44SJohn Forte } 422fcf3ce44SJohn Forte 423fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 424fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 425fcf3ce44SJohn Forte } 426fcf3ce44SJohn Forte 427fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_STATIC_SET, &target)) { 428fcf3ce44SJohn Forte /* 429fcf3ce44SJohn Forte * Encountered problem setting the IP address and port for 430fcf3ce44SJohn Forte * the target just added. 431fcf3ce44SJohn Forte */ 432fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 433fcf3ce44SJohn Forte "ISCSI_STATIC_SET ioctl failed, errno: %d", errno); 434fcf3ce44SJohn Forte (void) close(fd); 435fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 436fcf3ce44SJohn Forte } 437fcf3ce44SJohn Forte 438fcf3ce44SJohn Forte pTargetOid->objectType = IMA_OBJECT_TYPE_TARGET; 439fcf3ce44SJohn Forte pTargetOid->ownerId = 1; 440fcf3ce44SJohn Forte pTargetOid->objectSequenceNumber = target.te_entry.e_oid; 441fcf3ce44SJohn Forte 442fcf3ce44SJohn Forte (void) close(fd); 443fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 444fcf3ce44SJohn Forte } 445fcf3ce44SJohn Forte 446fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetTargetProperties( 447fcf3ce44SJohn Forte IMA_OID targetId, 448fcf3ce44SJohn Forte SUN_IMA_TARGET_PROPERTIES *pProps 449fcf3ce44SJohn Forte ) 450fcf3ce44SJohn Forte { 451fcf3ce44SJohn Forte int fd; 452fcf3ce44SJohn Forte int status; 453fcf3ce44SJohn Forte iscsi_property_t prop; 454fcf3ce44SJohn Forte 455fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 456fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 457fcf3ce44SJohn Forte } 458fcf3ce44SJohn Forte 459fcf3ce44SJohn Forte (void) memset(&prop, 0, sizeof (iscsi_property_t)); 460fcf3ce44SJohn Forte prop.p_vers = ISCSI_INTERFACE_VERSION; 461fcf3ce44SJohn Forte prop.p_oid = (uint32_t)targetId.objectSequenceNumber; 462fcf3ce44SJohn Forte 463fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_PROPS_GET, &prop) != 0) { 464fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 465fcf3ce44SJohn Forte "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno); 466fcf3ce44SJohn Forte (void) close(fd); 467fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 468fcf3ce44SJohn Forte } 469fcf3ce44SJohn Forte 470fcf3ce44SJohn Forte (void) mbstowcs(pProps->imaProps.name, 471fcf3ce44SJohn Forte (char *)prop.p_name, IMA_NODE_NAME_LEN); 472fcf3ce44SJohn Forte (void) memset(pProps->imaProps.alias, 0, 473fcf3ce44SJohn Forte (sizeof (IMA_WCHAR) * SUN_IMA_NODE_ALIAS_LEN)); 474fcf3ce44SJohn Forte if (prop.p_alias_len > 0) { 475fcf3ce44SJohn Forte (void) mbstowcs(pProps->imaProps.alias, (char *)prop.p_alias, 476fcf3ce44SJohn Forte SUN_IMA_NODE_ALIAS_LEN); 477fcf3ce44SJohn Forte } 478fcf3ce44SJohn Forte 479fcf3ce44SJohn Forte /* Initialize the discovery method to unknown method. */ 480fcf3ce44SJohn Forte pProps->imaProps.discoveryMethodFlags = 481fcf3ce44SJohn Forte IMA_TARGET_DISCOVERY_METHOD_UNKNOWN; 482fcf3ce44SJohn Forte if (!((prop.p_discovery & iSCSIDiscoveryMethodStatic) ^ 483fcf3ce44SJohn Forte iSCSIDiscoveryMethodStatic)) { 484fcf3ce44SJohn Forte pProps->imaProps.discoveryMethodFlags |= 485fcf3ce44SJohn Forte IMA_TARGET_DISCOVERY_METHOD_STATIC; 486fcf3ce44SJohn Forte } 487fcf3ce44SJohn Forte 488fcf3ce44SJohn Forte if (!((prop.p_discovery & iSCSIDiscoveryMethodSLP) ^ 489fcf3ce44SJohn Forte iSCSIDiscoveryMethodSLP)) { 490fcf3ce44SJohn Forte pProps->imaProps.discoveryMethodFlags |= 491fcf3ce44SJohn Forte IMA_TARGET_DISCOVERY_METHOD_SLP; 492fcf3ce44SJohn Forte } 493fcf3ce44SJohn Forte 494fcf3ce44SJohn Forte if (!((prop.p_discovery & iSCSIDiscoveryMethodISNS) ^ 495fcf3ce44SJohn Forte iSCSIDiscoveryMethodISNS)) { 496fcf3ce44SJohn Forte pProps->imaProps.discoveryMethodFlags |= 497fcf3ce44SJohn Forte iSCSIDiscoveryMethodISNS; 498fcf3ce44SJohn Forte } 499fcf3ce44SJohn Forte 500fcf3ce44SJohn Forte if (!((prop.p_discovery & iSCSIDiscoveryMethodSendTargets) ^ 501fcf3ce44SJohn Forte iSCSIDiscoveryMethodSendTargets)) { 502fcf3ce44SJohn Forte pProps->imaProps.discoveryMethodFlags |= 503fcf3ce44SJohn Forte iSCSIDiscoveryMethodSendTargets; 504fcf3ce44SJohn Forte } 505fcf3ce44SJohn Forte 506fcf3ce44SJohn Forte if (prop.p_tpgt_conf == ISCSI_DEFAULT_TPGT) { 507fcf3ce44SJohn Forte pProps->defaultTpgtConf = IMA_TRUE; 508fcf3ce44SJohn Forte pProps->tpgtConf = 0; 509fcf3ce44SJohn Forte } else { 510fcf3ce44SJohn Forte pProps->defaultTpgtConf = IMA_FALSE; 511fcf3ce44SJohn Forte pProps->tpgtConf = prop.p_tpgt_conf; 512fcf3ce44SJohn Forte } 513fcf3ce44SJohn Forte 514fcf3ce44SJohn Forte if (prop.p_tpgt_nego == ISCSI_DEFAULT_TPGT) { 515fcf3ce44SJohn Forte pProps->defaultTpgtNego = IMA_TRUE; 516fcf3ce44SJohn Forte pProps->tpgtNego = 0; 517fcf3ce44SJohn Forte } else { 518fcf3ce44SJohn Forte pProps->defaultTpgtNego = IMA_FALSE; 519fcf3ce44SJohn Forte pProps->tpgtNego = prop.p_tpgt_nego; 520fcf3ce44SJohn Forte } 521fcf3ce44SJohn Forte 522fcf3ce44SJohn Forte bcopy(prop.p_isid, pProps->isid, ISCSI_ISID_LEN); 523fcf3ce44SJohn Forte 524fcf3ce44SJohn Forte (void) close(fd); 525fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 526fcf3ce44SJohn Forte } 527fcf3ce44SJohn Forte 528fcf3ce44SJohn Forte /* 529fcf3ce44SJohn Forte * This function only sets CHAP params since we only support CHAP for now. 530fcf3ce44SJohn Forte */ 531fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetTargetAuthParams( 532fcf3ce44SJohn Forte IMA_OID targetOid, 533fcf3ce44SJohn Forte IMA_AUTHMETHOD method, 534fcf3ce44SJohn Forte const IMA_INITIATOR_AUTHPARMS *pParms 535fcf3ce44SJohn Forte ) 536fcf3ce44SJohn Forte { 537fcf3ce44SJohn Forte int fd; 538fcf3ce44SJohn Forte iscsi_chap_props_t chap_p; 539fcf3ce44SJohn Forte 540fcf3ce44SJohn Forte if (method != IMA_AUTHMETHOD_CHAP) 541fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 542fcf3ce44SJohn Forte 543fcf3ce44SJohn Forte if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 544fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 545fcf3ce44SJohn Forte ISCSI_DRIVER_DEVCTL, errno); 546fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 547fcf3ce44SJohn Forte } 548fcf3ce44SJohn Forte 549fcf3ce44SJohn Forte (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 550fcf3ce44SJohn Forte chap_p.c_vers = ISCSI_INTERFACE_VERSION; 551fcf3ce44SJohn Forte chap_p.c_oid = (uint32_t)targetOid.objectSequenceNumber; 552fcf3ce44SJohn Forte 553fcf3ce44SJohn Forte chap_p.c_user_len = 554fcf3ce44SJohn Forte pParms->chapParms.nameLength; 555fcf3ce44SJohn Forte (void) memcpy(chap_p.c_user, 556fcf3ce44SJohn Forte pParms->chapParms.name, chap_p.c_user_len); 557fcf3ce44SJohn Forte 558fcf3ce44SJohn Forte chap_p.c_secret_len = 559fcf3ce44SJohn Forte pParms->chapParms.challengeSecretLength; 560fcf3ce44SJohn Forte (void) memcpy(chap_p.c_secret, 561fcf3ce44SJohn Forte pParms->chapParms.challengeSecret, 562fcf3ce44SJohn Forte chap_p.c_secret_len); 563fcf3ce44SJohn Forte 564fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CHAP_SET, &chap_p) != 0) { 565fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 566fcf3ce44SJohn Forte "ISCSI_CHAP_SET ioctl failed, errno: %d", errno); 567fcf3ce44SJohn Forte (void) close(fd); 568fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 569fcf3ce44SJohn Forte } 570fcf3ce44SJohn Forte 571fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 572fcf3ce44SJohn Forte } 573fcf3ce44SJohn Forte 574fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetTargetAuthMethods( 575fcf3ce44SJohn Forte IMA_OID lhbaOid, 576fcf3ce44SJohn Forte IMA_OID targetOid, 577fcf3ce44SJohn Forte IMA_UINT *pMethodCount, 578fcf3ce44SJohn Forte IMA_AUTHMETHOD *pMethodList 579fcf3ce44SJohn Forte ) 580fcf3ce44SJohn Forte { 581fcf3ce44SJohn Forte if (getAuthMethods(targetOid, pMethodCount, pMethodList) 582fcf3ce44SJohn Forte != IMA_STATUS_SUCCESS) { 583fcf3ce44SJohn Forte return (getAuthMethods(lhbaOid, pMethodCount, pMethodList)); 584fcf3ce44SJohn Forte } 585fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 586fcf3ce44SJohn Forte } 587fcf3ce44SJohn Forte 588fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetInitiatorRadiusConfig( 589fcf3ce44SJohn Forte IMA_OID lhbaOid, 590fcf3ce44SJohn Forte SUN_IMA_RADIUS_CONFIG *config 591fcf3ce44SJohn Forte ) 592fcf3ce44SJohn Forte { 593fcf3ce44SJohn Forte int af; 594fcf3ce44SJohn Forte int fd; 595fcf3ce44SJohn Forte int status; 596fcf3ce44SJohn Forte iscsi_radius_props_t radius; 597fcf3ce44SJohn Forte union { 598fcf3ce44SJohn Forte struct in_addr u_in4; 599fcf3ce44SJohn Forte struct in6_addr u_in6; 600fcf3ce44SJohn Forte } radius_in; 601fcf3ce44SJohn Forte 602fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 603fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 604fcf3ce44SJohn Forte } 605fcf3ce44SJohn Forte 606fcf3ce44SJohn Forte (void) memset(&radius, 0, sizeof (iscsi_radius_props_t)); 607fcf3ce44SJohn Forte radius.r_vers = ISCSI_INTERFACE_VERSION; 608fcf3ce44SJohn Forte radius.r_oid = (uint32_t)lhbaOid.objectSequenceNumber; 609fcf3ce44SJohn Forte /* Get first because other data fields may already exist */ 610fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_GET, &radius) != 0) { 611fcf3ce44SJohn Forte /* EMPTY */ 612fcf3ce44SJohn Forte /* It's fine if other data fields are not there. */ 613fcf3ce44SJohn Forte } 614fcf3ce44SJohn Forte 615fcf3ce44SJohn Forte if (config->isIpv6 == IMA_TRUE) { 616fcf3ce44SJohn Forte af = AF_INET6; 617fcf3ce44SJohn Forte } else { 618fcf3ce44SJohn Forte af = AF_INET; 619fcf3ce44SJohn Forte } 620fcf3ce44SJohn Forte 621fcf3ce44SJohn Forte if (inet_pton(af, config->hostnameIpAddress, &radius_in.u_in4) != 1) { 622fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 623fcf3ce44SJohn Forte } 624fcf3ce44SJohn Forte 625fcf3ce44SJohn Forte switch (af) { 626fcf3ce44SJohn Forte case AF_INET: 627fcf3ce44SJohn Forte radius.r_addr.u_in4.s_addr = radius_in.u_in4.s_addr; 628fcf3ce44SJohn Forte radius.r_insize = sizeof (struct in_addr); 629fcf3ce44SJohn Forte break; 630fcf3ce44SJohn Forte case AF_INET6: 631fcf3ce44SJohn Forte (void) memcpy(radius.r_addr.u_in6.s6_addr, 632fcf3ce44SJohn Forte radius_in.u_in6.s6_addr, 16); 633fcf3ce44SJohn Forte radius.r_insize = sizeof (struct in6_addr); 634fcf3ce44SJohn Forte break; 635fcf3ce44SJohn Forte } 636fcf3ce44SJohn Forte radius.r_port = config->port; 637fcf3ce44SJohn Forte radius.r_radius_config_valid = B_TRUE; 638fcf3ce44SJohn Forte /* Allow resetting the RADIUS shared secret to NULL */ 639fcf3ce44SJohn Forte if (config->sharedSecretValid == IMA_TRUE) { 640fcf3ce44SJohn Forte radius.r_shared_secret_len = config->sharedSecretLength; 641fcf3ce44SJohn Forte (void) memset(&radius.r_shared_secret[0], 0, 642fcf3ce44SJohn Forte MAX_RAD_SHARED_SECRET_LEN); 643fcf3ce44SJohn Forte (void) memcpy(&radius.r_shared_secret[0], config->sharedSecret, 644fcf3ce44SJohn Forte config->sharedSecretLength); 645fcf3ce44SJohn Forte } 646fcf3ce44SJohn Forte 647fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_SET, &radius) != 0) { 648fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 649fcf3ce44SJohn Forte "ISCSI_RADIUS_SET ioctl failed, errno: %d", errno); 650fcf3ce44SJohn Forte (void) close(fd); 651fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 652fcf3ce44SJohn Forte } 653fcf3ce44SJohn Forte 654fcf3ce44SJohn Forte (void) close(fd); 655fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 656fcf3ce44SJohn Forte } 657fcf3ce44SJohn Forte 658fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetInitiatorRadiusConfig( 659fcf3ce44SJohn Forte IMA_OID lhbaOid, 660fcf3ce44SJohn Forte SUN_IMA_RADIUS_CONFIG *config 661fcf3ce44SJohn Forte ) 662fcf3ce44SJohn Forte { 663fcf3ce44SJohn Forte int af; 664fcf3ce44SJohn Forte int fd; 665fcf3ce44SJohn Forte int status; 666fcf3ce44SJohn Forte iscsi_radius_props_t radius; 667fcf3ce44SJohn Forte 668fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 669fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 670fcf3ce44SJohn Forte } 671fcf3ce44SJohn Forte 672fcf3ce44SJohn Forte (void) memset(&radius, 0, sizeof (iscsi_radius_props_t)); 673fcf3ce44SJohn Forte radius.r_vers = ISCSI_INTERFACE_VERSION; 674fcf3ce44SJohn Forte radius.r_oid = (uint32_t)lhbaOid.objectSequenceNumber; 675fcf3ce44SJohn Forte 676fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_GET, &radius) != 0) { 677fcf3ce44SJohn Forte (void) close(fd); 678fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 679fcf3ce44SJohn Forte } 680fcf3ce44SJohn Forte 681fcf3ce44SJohn Forte (void) memset(config, 0, sizeof (SUN_IMA_RADIUS_CONFIG)); 682fcf3ce44SJohn Forte if (radius.r_insize == sizeof (struct in_addr)) { 683fcf3ce44SJohn Forte /* IPv4 */ 684fcf3ce44SJohn Forte af = AF_INET; 685fcf3ce44SJohn Forte } else if (radius.r_insize == sizeof (struct in6_addr)) { 686fcf3ce44SJohn Forte /* IPv6 */ 687fcf3ce44SJohn Forte af = AF_INET6; 688fcf3ce44SJohn Forte } else { 689fcf3ce44SJohn Forte /* 690fcf3ce44SJohn Forte * It's legitimate that the existing RADIUS record does not 691fcf3ce44SJohn Forte * have configuration data. 692fcf3ce44SJohn Forte */ 693fcf3ce44SJohn Forte config->hostnameIpAddress[0] = '\0'; 694fcf3ce44SJohn Forte config->port = 0; 695fcf3ce44SJohn Forte (void) close(fd); 696fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 697fcf3ce44SJohn Forte } 698fcf3ce44SJohn Forte (void) inet_ntop(af, (void *)&radius.r_addr.u_in4, 699fcf3ce44SJohn Forte config->hostnameIpAddress, 256); 700fcf3ce44SJohn Forte config->port = radius.r_port; 701fcf3ce44SJohn Forte (void) memcpy(config->sharedSecret, &radius.r_shared_secret[0], 702fcf3ce44SJohn Forte radius.r_shared_secret_len); 703fcf3ce44SJohn Forte config->sharedSecretLength = radius.r_shared_secret_len; 704fcf3ce44SJohn Forte config->sharedSecretValid = B_TRUE; 705fcf3ce44SJohn Forte 706fcf3ce44SJohn Forte (void) close(fd); 707fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 708fcf3ce44SJohn Forte } 709fcf3ce44SJohn Forte 710fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetInitiatorRadiusAccess( 711fcf3ce44SJohn Forte IMA_OID lhbaOid, 712fcf3ce44SJohn Forte IMA_BOOL radiusAccess 713fcf3ce44SJohn Forte ) 714fcf3ce44SJohn Forte { 715fcf3ce44SJohn Forte int fd; 716fcf3ce44SJohn Forte int status; 717fcf3ce44SJohn Forte iscsi_radius_props_t radius; 718fcf3ce44SJohn Forte 719fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 720fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 721fcf3ce44SJohn Forte } 722fcf3ce44SJohn Forte 723fcf3ce44SJohn Forte (void) memset(&radius, 0, sizeof (iscsi_radius_props_t)); 724fcf3ce44SJohn Forte radius.r_vers = ISCSI_INTERFACE_VERSION; 725fcf3ce44SJohn Forte radius.r_oid = (uint32_t)lhbaOid.objectSequenceNumber; 726fcf3ce44SJohn Forte /* Get first because other data fields may already exist */ 727fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_GET, &radius) != 0) { 728fcf3ce44SJohn Forte if (radiusAccess == IMA_TRUE) { 729fcf3ce44SJohn Forte /* 730fcf3ce44SJohn Forte * Cannot enable RADIUS if no RADIUS configuration 731fcf3ce44SJohn Forte * can be found. 732fcf3ce44SJohn Forte */ 733fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 734fcf3ce44SJohn Forte "RADIUS config data not found - " 735fcf3ce44SJohn Forte "cannot enable RADIUS, errno: %d", errno); 736fcf3ce44SJohn Forte (void) close(fd); 737fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 738fcf3ce44SJohn Forte } else { 739fcf3ce44SJohn Forte /* EMPTY */ 740fcf3ce44SJohn Forte /* Otherwise it's fine to disable RADIUS */ 741fcf3ce44SJohn Forte } 742fcf3ce44SJohn Forte } 743fcf3ce44SJohn Forte 744fcf3ce44SJohn Forte if ((radius.r_insize != sizeof (struct in_addr)) && 745fcf3ce44SJohn Forte (radius.r_insize != sizeof (struct in6_addr))) { 746fcf3ce44SJohn Forte /* 747fcf3ce44SJohn Forte * Cannot enable RADIUS if no RADIUS configuration 748fcf3ce44SJohn Forte * can be found. 749fcf3ce44SJohn Forte */ 750fcf3ce44SJohn Forte if (radiusAccess == IMA_TRUE) { 751fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 752fcf3ce44SJohn Forte "RADIUS config data not found - " 753fcf3ce44SJohn Forte "cannot enable RADIUS"); 754fcf3ce44SJohn Forte (void) close(fd); 755fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 756fcf3ce44SJohn Forte } 757fcf3ce44SJohn Forte } 758fcf3ce44SJohn Forte 759fcf3ce44SJohn Forte radius.r_radius_access = (radiusAccess == IMA_TRUE) ? 760fcf3ce44SJohn Forte B_TRUE : B_FALSE; 761fcf3ce44SJohn Forte 762fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_SET, &radius) != 0) { 763fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 764fcf3ce44SJohn Forte "ISCSI_RADIUS_SET ioctl failed, errno: %d", errno); 765fcf3ce44SJohn Forte (void) close(fd); 766fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 767fcf3ce44SJohn Forte } 768fcf3ce44SJohn Forte 769fcf3ce44SJohn Forte (void) close(fd); 770fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 771fcf3ce44SJohn Forte } 772fcf3ce44SJohn Forte 773fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetInitiatorRadiusAccess( 774fcf3ce44SJohn Forte IMA_OID lhbaOid, 775fcf3ce44SJohn Forte IMA_BOOL *radiusAccess 776fcf3ce44SJohn Forte ) 777fcf3ce44SJohn Forte { 778fcf3ce44SJohn Forte int fd; 779fcf3ce44SJohn Forte int status; 780fcf3ce44SJohn Forte iscsi_radius_props_t radius; 781fcf3ce44SJohn Forte 782fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 783fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 784fcf3ce44SJohn Forte } 785fcf3ce44SJohn Forte 786fcf3ce44SJohn Forte (void) memset(&radius, 0, sizeof (iscsi_radius_props_t)); 787fcf3ce44SJohn Forte radius.r_vers = ISCSI_INTERFACE_VERSION; 788fcf3ce44SJohn Forte radius.r_oid = (uint32_t)lhbaOid.objectSequenceNumber; 789fcf3ce44SJohn Forte 790fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_RADIUS_GET, &radius) != 0) { 791fcf3ce44SJohn Forte (void) close(fd); 792fcf3ce44SJohn Forte if (errno == ENOENT) { 793fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 794fcf3ce44SJohn Forte } else { 795fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 796fcf3ce44SJohn Forte } 797fcf3ce44SJohn Forte } 798fcf3ce44SJohn Forte 799fcf3ce44SJohn Forte *radiusAccess = (radius.r_radius_access == B_TRUE) ? 800fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 801fcf3ce44SJohn Forte 802fcf3ce44SJohn Forte (void) close(fd); 803fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 804fcf3ce44SJohn Forte } 805fcf3ce44SJohn Forte 806fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SendTargets( 807fcf3ce44SJohn Forte IMA_NODE_NAME nodeName, 808fcf3ce44SJohn Forte IMA_TARGET_ADDRESS address, 809fcf3ce44SJohn Forte SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList 810fcf3ce44SJohn Forte ) 811fcf3ce44SJohn Forte { 812fcf3ce44SJohn Forte char *colonPos; 813fcf3ce44SJohn Forte char discAddrStr[256]; 814fcf3ce44SJohn Forte char nodeNameStr[ISCSI_MAX_NAME_LEN]; 815fcf3ce44SJohn Forte int fd; 816fcf3ce44SJohn Forte int ctr; 817fcf3ce44SJohn Forte int stl_sz; 818fcf3ce44SJohn Forte int status; 819fcf3ce44SJohn Forte iscsi_sendtgts_list_t *stl_hdr = NULL; 820fcf3ce44SJohn Forte IMA_BOOL retry = IMA_TRUE; 821fcf3ce44SJohn Forte /* LINTED */ 822fcf3ce44SJohn Forte IMA_IP_ADDRESS *ipAddr; 823fcf3ce44SJohn Forte 824fcf3ce44SJohn Forte #define SENDTGTS_DEFAULT_NUM_TARGETS 10 825fcf3ce44SJohn Forte 826fcf3ce44SJohn Forte stl_sz = sizeof (*stl_hdr) + ((SENDTGTS_DEFAULT_NUM_TARGETS - 1) * 827fcf3ce44SJohn Forte sizeof (iscsi_sendtgts_entry_t)); 828fcf3ce44SJohn Forte stl_hdr = (iscsi_sendtgts_list_t *)calloc(1, stl_sz); 829fcf3ce44SJohn Forte if (stl_hdr == NULL) { 830fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 831fcf3ce44SJohn Forte } 832fcf3ce44SJohn Forte stl_hdr->stl_entry.e_vers = ISCSI_INTERFACE_VERSION; 833fcf3ce44SJohn Forte stl_hdr->stl_in_cnt = SENDTGTS_DEFAULT_NUM_TARGETS; 834fcf3ce44SJohn Forte 835fcf3ce44SJohn Forte (void) wcstombs(nodeNameStr, nodeName, ISCSI_MAX_NAME_LEN); 836fcf3ce44SJohn Forte 837fcf3ce44SJohn Forte colonPos = strchr(discAddrStr, ':'); 838fcf3ce44SJohn Forte if (colonPos == NULL) { 839fcf3ce44SJohn Forte /* IPv4 */ 840fcf3ce44SJohn Forte stl_hdr->stl_entry.e_insize = sizeof (struct in_addr); 841fcf3ce44SJohn Forte } else { 842fcf3ce44SJohn Forte /* IPv6 */ 843fcf3ce44SJohn Forte stl_hdr->stl_entry.e_insize = sizeof (struct in6_addr); 844fcf3ce44SJohn Forte } 845fcf3ce44SJohn Forte 846fcf3ce44SJohn Forte ipAddr = &address.hostnameIpAddress.id.ipAddress; 847fcf3ce44SJohn Forte 848fcf3ce44SJohn Forte bcopy(address.hostnameIpAddress.id.ipAddress.ipAddress, 849fcf3ce44SJohn Forte &stl_hdr->stl_entry.e_u, sizeof (ipAddr->ipAddress)); 850fcf3ce44SJohn Forte 851fcf3ce44SJohn Forte stl_hdr->stl_entry.e_port = address.portNumber; 852fcf3ce44SJohn Forte 853fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 854fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 855fcf3ce44SJohn Forte } 856fcf3ce44SJohn Forte 857fcf3ce44SJohn Forte retry_sendtgts: 858fcf3ce44SJohn Forte /* 859fcf3ce44SJohn Forte * Issue ioctl to obtain the SendTargets list 860fcf3ce44SJohn Forte */ 861fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_SENDTGTS_GET, stl_hdr) != 0) { 862fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 863fcf3ce44SJohn Forte "ISCSI_SENDTGTS_GET ioctl failed, errno: %d", errno); 864fcf3ce44SJohn Forte (void) close(fd); 865fcf3ce44SJohn Forte free(stl_hdr); 866fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 867fcf3ce44SJohn Forte } 868fcf3ce44SJohn Forte 869fcf3ce44SJohn Forte /* check if all targets received */ 870fcf3ce44SJohn Forte if (stl_hdr->stl_in_cnt < stl_hdr->stl_out_cnt) { 871fcf3ce44SJohn Forte if (retry == IMA_TRUE) { 872fcf3ce44SJohn Forte stl_sz = sizeof (*stl_hdr) + 873fcf3ce44SJohn Forte ((stl_hdr->stl_out_cnt - 1) * 874fcf3ce44SJohn Forte sizeof (iscsi_sendtgts_entry_t)); 875fcf3ce44SJohn Forte stl_hdr = (iscsi_sendtgts_list_t *) 876fcf3ce44SJohn Forte realloc(stl_hdr, stl_sz); 877fcf3ce44SJohn Forte if (stl_hdr == NULL) { 878fcf3ce44SJohn Forte (void) close(fd); 879fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 880fcf3ce44SJohn Forte } 881fcf3ce44SJohn Forte stl_hdr->stl_in_cnt = stl_hdr->stl_out_cnt; 882fcf3ce44SJohn Forte retry = IMA_FALSE; 883fcf3ce44SJohn Forte goto retry_sendtgts; 884fcf3ce44SJohn Forte } else { 885fcf3ce44SJohn Forte /* 886fcf3ce44SJohn Forte * don't retry after 2 attempts. The target list 887fcf3ce44SJohn Forte * shouldn't continue to growing. Justs continue 888fcf3ce44SJohn Forte * on and display what was found. 889fcf3ce44SJohn Forte */ 890fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 891fcf3ce44SJohn Forte "ISCSI_SENDTGTS_GET overflow: " 892fcf3ce44SJohn Forte "failed to obtain all targets"); 893fcf3ce44SJohn Forte stl_hdr->stl_out_cnt = stl_hdr->stl_in_cnt; 894fcf3ce44SJohn Forte } 895fcf3ce44SJohn Forte } 896fcf3ce44SJohn Forte 897fcf3ce44SJohn Forte (void) close(fd); 898fcf3ce44SJohn Forte 899fcf3ce44SJohn Forte /* allocate for caller return buffer */ 900fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1, 901fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) + 902fcf3ce44SJohn Forte stl_hdr->stl_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY)); 903fcf3ce44SJohn Forte if (*ppList == NULL) { 904fcf3ce44SJohn Forte free(stl_hdr); 905fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 906fcf3ce44SJohn Forte } 907fcf3ce44SJohn Forte 908fcf3ce44SJohn Forte (*ppList)->keyCount = stl_hdr->stl_out_cnt; 909fcf3ce44SJohn Forte 910fcf3ce44SJohn Forte for (ctr = 0; ctr < stl_hdr->stl_out_cnt; ctr++) { 911fcf3ce44SJohn Forte (void) mbstowcs((*ppList)->keys[ctr].name, 912fcf3ce44SJohn Forte (char *)stl_hdr->stl_list[ctr].ste_name, 913fcf3ce44SJohn Forte IMA_NODE_NAME_LEN); 914fcf3ce44SJohn Forte 915fcf3ce44SJohn Forte (*ppList)->keys[ctr].tpgt = stl_hdr->stl_list[ctr].ste_tpgt; 916fcf3ce44SJohn Forte 917fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.portNumber = 918fcf3ce44SJohn Forte stl_hdr->stl_list[ctr].ste_ipaddr.a_port; 919fcf3ce44SJohn Forte 920fcf3ce44SJohn Forte if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize == 921fcf3ce44SJohn Forte sizeof (struct in_addr)) { 922fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 923fcf3ce44SJohn Forte IMA_TRUE; 924fcf3ce44SJohn Forte } else if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize == 925fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 926fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 927fcf3ce44SJohn Forte IMA_FALSE; 928fcf3ce44SJohn Forte } else { 929fcf3ce44SJohn Forte free(stl_hdr); 930fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 931fcf3ce44SJohn Forte } 932fcf3ce44SJohn Forte 933fcf3ce44SJohn Forte (void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress, 934fcf3ce44SJohn Forte &(stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_addr), 935fcf3ce44SJohn Forte stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize); 936fcf3ce44SJohn Forte } 937fcf3ce44SJohn Forte free(stl_hdr); 938fcf3ce44SJohn Forte 939fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 940fcf3ce44SJohn Forte } 941fcf3ce44SJohn Forte 942fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetTargetBidirAuthFlag( 943fcf3ce44SJohn Forte IMA_OID targetOid, 944fcf3ce44SJohn Forte IMA_BOOL *bidirAuthFlag 945fcf3ce44SJohn Forte ) 946fcf3ce44SJohn Forte { 947fcf3ce44SJohn Forte int fd; 948fcf3ce44SJohn Forte int status; 949fcf3ce44SJohn Forte iscsi_auth_props_t auth; 950fcf3ce44SJohn Forte 951fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 952fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 953fcf3ce44SJohn Forte } 954fcf3ce44SJohn Forte 955fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 956fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 957fcf3ce44SJohn Forte auth.a_oid = (uint32_t)targetOid.objectSequenceNumber; 958fcf3ce44SJohn Forte /* Get first because other data fields may already exist */ 959fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 960fcf3ce44SJohn Forte /* EMPTY */ 961fcf3ce44SJohn Forte /* It is fine if there is no other data fields. */ 962fcf3ce44SJohn Forte } 963fcf3ce44SJohn Forte auth.a_bi_auth = (*bidirAuthFlag == IMA_TRUE) ? B_TRUE : B_FALSE; 964fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) { 965fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 966fcf3ce44SJohn Forte "ISCSI_AUTH_SET ioctl failed, errno: %d", errno); 967fcf3ce44SJohn Forte (void) close(fd); 968fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 969fcf3ce44SJohn Forte } 970fcf3ce44SJohn Forte 971fcf3ce44SJohn Forte (void) close(fd); 972fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 973fcf3ce44SJohn Forte } 974fcf3ce44SJohn Forte 975fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetTargetBidirAuthFlag( 976fcf3ce44SJohn Forte IMA_OID targetOid, 977fcf3ce44SJohn Forte IMA_BOOL *bidirAuthFlag 978fcf3ce44SJohn Forte ) 979fcf3ce44SJohn Forte { 980fcf3ce44SJohn Forte int fd; 981fcf3ce44SJohn Forte int status; 982fcf3ce44SJohn Forte iscsi_auth_props_t auth; 983fcf3ce44SJohn Forte 984fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 985fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 986fcf3ce44SJohn Forte } 987fcf3ce44SJohn Forte 988fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 989fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 990fcf3ce44SJohn Forte auth.a_oid = (uint32_t)targetOid.objectSequenceNumber; 991fcf3ce44SJohn Forte 992fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 993fcf3ce44SJohn Forte (void) close(fd); 994fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 995fcf3ce44SJohn Forte } 996fcf3ce44SJohn Forte 997fcf3ce44SJohn Forte *bidirAuthFlag = (auth.a_bi_auth == B_TRUE) ? 998fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 999fcf3ce44SJohn Forte 1000fcf3ce44SJohn Forte (void) close(fd); 1001fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1002fcf3ce44SJohn Forte } 1003fcf3ce44SJohn Forte 1004fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_CreateTargetOid( 1005fcf3ce44SJohn Forte IMA_NODE_NAME targetName, 1006fcf3ce44SJohn Forte IMA_OID *targetOid 1007fcf3ce44SJohn Forte ) 1008fcf3ce44SJohn Forte { 1009fcf3ce44SJohn Forte int fd; 1010fcf3ce44SJohn Forte int status; 1011fcf3ce44SJohn Forte iscsi_oid_t oid; 1012fcf3ce44SJohn Forte 1013fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1014fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1015fcf3ce44SJohn Forte } 1016fcf3ce44SJohn Forte 1017fcf3ce44SJohn Forte (void) memset(&oid, 0, sizeof (iscsi_oid_t)); 1018fcf3ce44SJohn Forte (void) wcstombs((char *)oid.o_name, targetName, ISCSI_MAX_NAME_LEN); 1019fcf3ce44SJohn Forte oid.o_tpgt = ISCSI_DEFAULT_TPGT; 1020fcf3ce44SJohn Forte oid.o_vers = ISCSI_INTERFACE_VERSION; 1021fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CREATE_OID, &oid) == -1) { 1022fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1023fcf3ce44SJohn Forte "ISCSI_CREATE_OID ioctl failed, errno: %d", errno); 1024fcf3ce44SJohn Forte (void) close(fd); 1025fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1026fcf3ce44SJohn Forte } 1027fcf3ce44SJohn Forte 1028fcf3ce44SJohn Forte targetOid->objectType = IMA_OBJECT_TYPE_TARGET; 1029fcf3ce44SJohn Forte targetOid->ownerId = 1; 1030fcf3ce44SJohn Forte targetOid->objectSequenceNumber = oid.o_oid; 1031fcf3ce44SJohn Forte 1032fcf3ce44SJohn Forte (void) close(fd); 1033fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1034fcf3ce44SJohn Forte } 1035fcf3ce44SJohn Forte 1036fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_RemoveTargetParam( 1037fcf3ce44SJohn Forte IMA_OID targetOid 1038fcf3ce44SJohn Forte ) 1039fcf3ce44SJohn Forte { 1040fcf3ce44SJohn Forte entry_t entry; 1041fcf3ce44SJohn Forte int fd; 1042fcf3ce44SJohn Forte int status; 1043fcf3ce44SJohn Forte iscsi_auth_props_t auth_p; 1044fcf3ce44SJohn Forte iscsi_chap_props_t chap_p; 1045fcf3ce44SJohn Forte 1046fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1047fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1048fcf3ce44SJohn Forte } 1049fcf3ce44SJohn Forte 1050fcf3ce44SJohn Forte (void) memset(&entry, 0, sizeof (entry_t)); 1051fcf3ce44SJohn Forte entry.e_vers = ISCSI_INTERFACE_VERSION; 1052fcf3ce44SJohn Forte entry.e_oid = (uint32_t)targetOid.objectSequenceNumber; 1053fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_PARAM_CLEAR, &entry)) { 1054fcf3ce44SJohn Forte /* 1055fcf3ce44SJohn Forte * It could be that the target exists but the associated 1056fcf3ce44SJohn Forte * target_param does not, and that is legitimate. 1057fcf3ce44SJohn Forte */ 1058fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1059fcf3ce44SJohn Forte "ISCSI_TARGET_PARAM_CLEAR ioctl failed, errno: %d", errno); 1060fcf3ce44SJohn Forte } 1061fcf3ce44SJohn Forte 1062fcf3ce44SJohn Forte /* Issue ISCSI_CHAP_CLEAR ioctl */ 1063fcf3ce44SJohn Forte (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 1064fcf3ce44SJohn Forte chap_p.c_vers = ISCSI_INTERFACE_VERSION; 1065fcf3ce44SJohn Forte chap_p.c_oid = (uint32_t)targetOid.objectSequenceNumber; 1066fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CHAP_CLEAR, &chap_p) != 0) { 1067fcf3ce44SJohn Forte /* 1068fcf3ce44SJohn Forte * It could be that the CHAP of this target has never 1069fcf3ce44SJohn Forte * been set. 1070fcf3ce44SJohn Forte */ 1071fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1072fcf3ce44SJohn Forte "ISCSI_CHAP_CLEAR ioctl failed, errno: %d", errno); 1073fcf3ce44SJohn Forte } 1074fcf3ce44SJohn Forte 1075fcf3ce44SJohn Forte /* Issue ISCSI_AUTH_CLEAR ioctl */ 1076fcf3ce44SJohn Forte (void) memset(&auth_p, 0, sizeof (iscsi_auth_props_t)); 1077fcf3ce44SJohn Forte auth_p.a_vers = ISCSI_INTERFACE_VERSION; 1078fcf3ce44SJohn Forte auth_p.a_oid = (uint32_t)targetOid.objectSequenceNumber; 1079fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_CLEAR, &auth_p) != 0) { 1080fcf3ce44SJohn Forte /* 1081fcf3ce44SJohn Forte * It could be that the auth data of this target has 1082fcf3ce44SJohn Forte * never been set. 1083fcf3ce44SJohn Forte */ 1084fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1085fcf3ce44SJohn Forte "ISCSI_AUTH_CLEAR ioctl failed, errno: %d", errno); 1086fcf3ce44SJohn Forte } 1087fcf3ce44SJohn Forte 1088fcf3ce44SJohn Forte (void) close(fd); 1089fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1090fcf3ce44SJohn Forte } 1091fcf3ce44SJohn Forte 1092fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetHeaderDigest( 1093fcf3ce44SJohn Forte IMA_OID oid, 1094fcf3ce44SJohn Forte IMA_UINT algorithmCount, 1095fcf3ce44SJohn Forte const SUN_IMA_DIGEST_ALGORITHM *algorithmList 1096fcf3ce44SJohn Forte ) 1097fcf3ce44SJohn Forte { 1098fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE mv; 1099fcf3ce44SJohn Forte uint32_t digest_algorithm; 1100fcf3ce44SJohn Forte 1101fcf3ce44SJohn Forte /* We only support one preference of digest algorithm. */ 1102fcf3ce44SJohn Forte if (algorithmCount > 1) { 1103fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1104fcf3ce44SJohn Forte "More than one digest algorithm specified."); 1105fcf3ce44SJohn Forte return (IMA_ERROR_NOT_SUPPORTED); 1106fcf3ce44SJohn Forte } 1107fcf3ce44SJohn Forte switch (algorithmList[0]) { 1108fcf3ce44SJohn Forte case SUN_IMA_DIGEST_NONE: 1109fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1110fcf3ce44SJohn Forte break; 1111fcf3ce44SJohn Forte case SUN_IMA_DIGEST_CRC32: 1112fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_CRC32C; 1113fcf3ce44SJohn Forte break; 1114fcf3ce44SJohn Forte default: 1115fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1116fcf3ce44SJohn Forte break; 1117fcf3ce44SJohn Forte } 1118fcf3ce44SJohn Forte mv.currentValue = digest_algorithm; 1119fcf3ce44SJohn Forte return (setISCSINodeParameter(MIN_MAX_PARAM, &oid, &mv, 1120fcf3ce44SJohn Forte ISCSI_LOGIN_PARAM_HEADER_DIGEST)); 1121fcf3ce44SJohn Forte } 1122fcf3ce44SJohn Forte 1123fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetDataDigest( 1124fcf3ce44SJohn Forte IMA_OID oid, 1125fcf3ce44SJohn Forte IMA_UINT algorithmCount, 1126fcf3ce44SJohn Forte const SUN_IMA_DIGEST_ALGORITHM *algorithmList 1127fcf3ce44SJohn Forte ) 1128fcf3ce44SJohn Forte { 1129fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE mv; 1130fcf3ce44SJohn Forte uint32_t digest_algorithm; 1131fcf3ce44SJohn Forte 1132fcf3ce44SJohn Forte /* We only support one preference of digest algorithm. */ 1133fcf3ce44SJohn Forte if (algorithmCount > 1) { 1134fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1135fcf3ce44SJohn Forte "More than one digest algorithm specified."); 1136fcf3ce44SJohn Forte return (IMA_ERROR_NOT_SUPPORTED); 1137fcf3ce44SJohn Forte } 1138fcf3ce44SJohn Forte switch (algorithmList[0]) { 1139fcf3ce44SJohn Forte case SUN_IMA_DIGEST_NONE: 1140fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1141fcf3ce44SJohn Forte break; 1142fcf3ce44SJohn Forte case SUN_IMA_DIGEST_CRC32: 1143fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_CRC32C; 1144fcf3ce44SJohn Forte break; 1145fcf3ce44SJohn Forte default: 1146fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1147fcf3ce44SJohn Forte break; 1148fcf3ce44SJohn Forte } 1149fcf3ce44SJohn Forte mv.currentValue = digest_algorithm; 1150fcf3ce44SJohn Forte return (setISCSINodeParameter(MIN_MAX_PARAM, &oid, &mv, 1151fcf3ce44SJohn Forte ISCSI_LOGIN_PARAM_DATA_DIGEST)); 1152fcf3ce44SJohn Forte } 1153fcf3ce44SJohn Forte 1154fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetHeaderDigest( 1155fcf3ce44SJohn Forte IMA_OID oid, 1156fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 1157fcf3ce44SJohn Forte ) 1158fcf3ce44SJohn Forte { 1159fcf3ce44SJohn Forte return (getDigest(oid, ISCSI_LOGIN_PARAM_HEADER_DIGEST, algorithm)); 1160fcf3ce44SJohn Forte } 1161fcf3ce44SJohn Forte 1162fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetDataDigest( 1163fcf3ce44SJohn Forte IMA_OID oid, 1164fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 1165fcf3ce44SJohn Forte ) 1166fcf3ce44SJohn Forte { 1167fcf3ce44SJohn Forte return (getDigest(oid, ISCSI_LOGIN_PARAM_DATA_DIGEST, algorithm)); 1168fcf3ce44SJohn Forte } 1169fcf3ce44SJohn Forte 1170fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetLuProperties( 1171fcf3ce44SJohn Forte IMA_OID luId, 1172fcf3ce44SJohn Forte SUN_IMA_LU_PROPERTIES *pProps 1173fcf3ce44SJohn Forte ) 1174fcf3ce44SJohn Forte { 1175fcf3ce44SJohn Forte IMA_STATUS status; 1176fcf3ce44SJohn Forte iscsi_lun_list_t *pLunList; 1177fcf3ce44SJohn Forte int j; 1178fcf3ce44SJohn Forte IMA_BOOL lunMatch = IMA_FALSE; 1179fcf3ce44SJohn Forte int fd; 1180fcf3ce44SJohn Forte int openStatus; 1181fcf3ce44SJohn Forte iscsi_lun_props_t lun; 1182fcf3ce44SJohn Forte di_devlink_handle_t hdl; 1183fcf3ce44SJohn Forte 1184fcf3ce44SJohn Forte if (luId.objectType != IMA_OBJECT_TYPE_LU) { 1185fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 1186fcf3ce44SJohn Forte } 1187fcf3ce44SJohn Forte 1188fcf3ce44SJohn Forte /* 1189fcf3ce44SJohn Forte * get list of lun oids for all targets 1190fcf3ce44SJohn Forte */ 1191fcf3ce44SJohn Forte status = get_target_lun_oid_list(NULL, &pLunList); 1192fcf3ce44SJohn Forte if (!IMA_SUCCESS(status)) { 1193fcf3ce44SJohn Forte return (status); 1194fcf3ce44SJohn Forte } 1195fcf3ce44SJohn Forte for (j = 0; j < pLunList->ll_out_cnt; j++) { 1196fcf3ce44SJohn Forte /* 1197fcf3ce44SJohn Forte * for each lun, check if match is found 1198fcf3ce44SJohn Forte */ 1199fcf3ce44SJohn Forte if (pLunList->ll_luns[j].l_oid == luId.objectSequenceNumber) { 1200fcf3ce44SJohn Forte /* 1201fcf3ce44SJohn Forte * match found, break out of lun loop 1202fcf3ce44SJohn Forte */ 1203fcf3ce44SJohn Forte lunMatch = IMA_TRUE; 1204fcf3ce44SJohn Forte break; 1205fcf3ce44SJohn Forte } 1206fcf3ce44SJohn Forte } 1207fcf3ce44SJohn Forte 1208fcf3ce44SJohn Forte if (lunMatch == IMA_TRUE) { 1209fcf3ce44SJohn Forte (void) memset(&lun, 0, sizeof (iscsi_lun_props_t)); 1210fcf3ce44SJohn Forte lun.lp_vers = ISCSI_INTERFACE_VERSION; 1211fcf3ce44SJohn Forte lun.lp_tgt_oid = pLunList->ll_luns[j].l_tgt_oid; 1212fcf3ce44SJohn Forte lun.lp_oid = pLunList->ll_luns[j].l_oid; 1213fcf3ce44SJohn Forte } 1214fcf3ce44SJohn Forte 1215fcf3ce44SJohn Forte free(pLunList); 1216fcf3ce44SJohn Forte 1217fcf3ce44SJohn Forte if (lunMatch == IMA_FALSE) { 1218fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 1219fcf3ce44SJohn Forte } 1220fcf3ce44SJohn Forte 1221fcf3ce44SJohn Forte /* 1222fcf3ce44SJohn Forte * get lun properties 1223fcf3ce44SJohn Forte */ 1224fcf3ce44SJohn Forte if ((openStatus = open_driver(&fd))) { 1225fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | openStatus); 1226fcf3ce44SJohn Forte } 1227fcf3ce44SJohn Forte 1228fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_PROPS_GET, &lun)) { 1229fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1230fcf3ce44SJohn Forte "ISCSI_LUN_PROPS_GET ioctl failed, errno: %d", errno); 1231fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1232fcf3ce44SJohn Forte } 1233fcf3ce44SJohn Forte 1234fcf3ce44SJohn Forte (void) close(fd); 1235fcf3ce44SJohn Forte 1236fcf3ce44SJohn Forte /* 1237fcf3ce44SJohn Forte * set property values 1238fcf3ce44SJohn Forte */ 1239fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.objectType = 1240fcf3ce44SJohn Forte IMA_OBJECT_TYPE_TARGET; 1241fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.ownerId = 1; 1242fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.objectSequenceNumber = lun.lp_oid; 1243fcf3ce44SJohn Forte pProps->imaProps.targetLun = (IMA_UINT64)lun.lp_num; 1244fcf3ce44SJohn Forte (void) strncpy(pProps->vendorId, lun.lp_vid, SUN_IMA_LU_VENDOR_ID_LEN); 1245fcf3ce44SJohn Forte (void) strncpy(pProps->productId, lun.lp_pid, 1246fcf3ce44SJohn Forte SUN_IMA_LU_PRODUCT_ID_LEN); 1247fcf3ce44SJohn Forte /* 1248fcf3ce44SJohn Forte * lun.lp_status is defined as 1249fcf3ce44SJohn Forte * LunValid = 0 1250fcf3ce44SJohn Forte * LunDoesNotExist = 1 1251fcf3ce44SJohn Forte * IMA_LU_PROPS.exposedtoOS is defined as an IMA_BOOL 1252fcf3ce44SJohn Forte * IMA_TRUE = 1 1253fcf3ce44SJohn Forte * IMA_FALSE = 0 1254fcf3ce44SJohn Forte */ 1255fcf3ce44SJohn Forte pProps->imaProps.exposedToOs = !lun.lp_status; 1256fcf3ce44SJohn Forte if (gmtime_r(&lun.lp_time_online, &pProps->imaProps.timeExposedToOs) 1257fcf3ce44SJohn Forte == NULL) { 1258fcf3ce44SJohn Forte (void) memset(&pProps->imaProps.timeExposedToOs, 0, 1259fcf3ce44SJohn Forte sizeof (pProps->imaProps.timeExposedToOs)); 1260fcf3ce44SJohn Forte } 1261fcf3ce44SJohn Forte 1262fcf3ce44SJohn Forte if (lun.lp_status == LunValid) { 1263fcf3ce44SJohn Forte 1264fcf3ce44SJohn Forte /* add minor device delimiter */ 1265fcf3ce44SJohn Forte (void) strcat(lun.lp_pathname, ":"); 1266fcf3ce44SJohn Forte 1267fcf3ce44SJohn Forte if ((strstr(lun.lp_pathname, "sd@") != NULL) || 1268fcf3ce44SJohn Forte (strstr(lun.lp_pathname, "ssd@") != NULL) || 1269fcf3ce44SJohn Forte (strstr(lun.lp_pathname, "disk@") != NULL)) { 1270fcf3ce44SJohn Forte /* 1271fcf3ce44SJohn Forte * modify returned pathname to obtain the 2nd slice 1272fcf3ce44SJohn Forte * of the raw disk 1273fcf3ce44SJohn Forte */ 1274fcf3ce44SJohn Forte (void) strcat(lun.lp_pathname, "c,raw"); 1275fcf3ce44SJohn Forte } 1276fcf3ce44SJohn Forte 1277fcf3ce44SJohn Forte /* 1278fcf3ce44SJohn Forte * Pathname returned by driver is the physical device path. 1279fcf3ce44SJohn Forte * This name needs to be converted to the OS device name. 1280fcf3ce44SJohn Forte */ 1281fcf3ce44SJohn Forte if (hdl = di_devlink_init(lun.lp_pathname, DI_MAKE_LINK)) { 1282fcf3ce44SJohn Forte pProps->imaProps.osDeviceName[0] = L'\0'; 1283fcf3ce44SJohn Forte (void) di_devlink_walk(hdl, NULL, lun.lp_pathname, 1284fcf3ce44SJohn Forte DI_PRIMARY_LINK, 1285fcf3ce44SJohn Forte (void *)pProps->imaProps.osDeviceName, 1286fcf3ce44SJohn Forte get_lun_devlink); 1287fcf3ce44SJohn Forte if (pProps->imaProps.osDeviceName[0] != L'\0') { 1288fcf3ce44SJohn Forte /* OS device name synchronously made */ 1289fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_TRUE; 1290fcf3ce44SJohn Forte } else { 1291fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1292fcf3ce44SJohn Forte } 1293fcf3ce44SJohn Forte 1294fcf3ce44SJohn Forte (void) di_devlink_fini(&hdl); 1295fcf3ce44SJohn Forte 1296fcf3ce44SJohn Forte } else { 1297fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1298fcf3ce44SJohn Forte } 1299fcf3ce44SJohn Forte 1300fcf3ce44SJohn Forte } else { 1301fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1302fcf3ce44SJohn Forte } 1303fcf3ce44SJohn Forte 1304fcf3ce44SJohn Forte pProps->imaProps.osParallelIdsValid = IMA_FALSE; 1305fcf3ce44SJohn Forte 1306fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1307fcf3ce44SJohn Forte } 1308fcf3ce44SJohn Forte 1309fcf3ce44SJohn Forte #define IMA_DISK_DEVICE_NAME_PREFIX "/dev/rdsk/" 1310fcf3ce44SJohn Forte #define IMA_TAPE_DEVICE_NAME_PREFIX "/dev/rmt/" 1311fcf3ce44SJohn Forte 1312fcf3ce44SJohn Forte static int 1313fcf3ce44SJohn Forte get_lun_devlink(di_devlink_t link, void *osDeviceName) 1314fcf3ce44SJohn Forte { 1315fcf3ce44SJohn Forte if ((strncmp(IMA_DISK_DEVICE_NAME_PREFIX, di_devlink_path(link), 1316fcf3ce44SJohn Forte strlen(IMA_DISK_DEVICE_NAME_PREFIX)) == 0) || 1317fcf3ce44SJohn Forte (strncmp(IMA_TAPE_DEVICE_NAME_PREFIX, di_devlink_path(link), 1318fcf3ce44SJohn Forte strlen(IMA_TAPE_DEVICE_NAME_PREFIX)) == 0)) { 1319fcf3ce44SJohn Forte (void) mbstowcs((wchar_t *)osDeviceName, di_devlink_path(link), 1320fcf3ce44SJohn Forte MAXPATHLEN); 1321fcf3ce44SJohn Forte return (DI_WALK_TERMINATE); 1322fcf3ce44SJohn Forte } 1323fcf3ce44SJohn Forte 1324fcf3ce44SJohn Forte return (DI_WALK_CONTINUE); 1325fcf3ce44SJohn Forte } 1326fcf3ce44SJohn Forte 1327fcf3ce44SJohn Forte /* 1328fcf3ce44SJohn Forte * SUN_IMA_GetConnectionOidList - 1329fcf3ce44SJohn Forte * 1330fcf3ce44SJohn Forte * Non-IMA defined function. 1331fcf3ce44SJohn Forte */ 1332fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConnOidList( 1333fcf3ce44SJohn Forte IMA_OID *oid, 1334fcf3ce44SJohn Forte IMA_OID_LIST **ppList 1335fcf3ce44SJohn Forte ) 1336fcf3ce44SJohn Forte { 1337fcf3ce44SJohn Forte IMA_STATUS imaStatus; 1338fcf3ce44SJohn Forte IMA_OID_LIST *imaOidList; 1339fcf3ce44SJohn Forte iscsi_conn_list_t *iscsiConnList = NULL; 1340fcf3ce44SJohn Forte int i; 1341fcf3ce44SJohn Forte size_t allocLen; 1342fcf3ce44SJohn Forte 1343fcf3ce44SJohn Forte if ((lhbaObjectId.objectType == oid->objectType) && 1344fcf3ce44SJohn Forte (lhbaObjectId.ownerId == oid->ownerId) && 1345fcf3ce44SJohn Forte (lhbaObjectId.objectSequenceNumber == oid->objectSequenceNumber)) { 1346fcf3ce44SJohn Forte imaStatus = getConnOidList(NULL, &iscsiConnList); 1347fcf3ce44SJohn Forte } else { 1348fcf3ce44SJohn Forte if (oid->objectType == IMA_OBJECT_TYPE_TARGET) { 1349fcf3ce44SJohn Forte imaStatus = getConnOidList(oid, &iscsiConnList); 1350fcf3ce44SJohn Forte } else { 1351fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 1352fcf3ce44SJohn Forte } 1353fcf3ce44SJohn Forte } 1354fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1355fcf3ce44SJohn Forte return (imaStatus); 1356fcf3ce44SJohn Forte } 1357fcf3ce44SJohn Forte 1358fcf3ce44SJohn Forte /* 1359fcf3ce44SJohn Forte * Based on the results a SUN_IMA_CONN_LIST structure is allocated. 1360fcf3ce44SJohn Forte */ 1361fcf3ce44SJohn Forte allocLen = iscsiConnList->cl_out_cnt * sizeof (IMA_OID); 1362fcf3ce44SJohn Forte allocLen += sizeof (IMA_OID_LIST) - sizeof (IMA_OID); 1363fcf3ce44SJohn Forte imaOidList = (IMA_OID_LIST *)calloc(1, allocLen); 1364fcf3ce44SJohn Forte 1365fcf3ce44SJohn Forte if (imaOidList == NULL) { 1366fcf3ce44SJohn Forte free(iscsiConnList); 1367fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1368fcf3ce44SJohn Forte } 1369fcf3ce44SJohn Forte 1370fcf3ce44SJohn Forte /* The data is transfered from iscsiConnList to imaConnList. */ 1371fcf3ce44SJohn Forte imaOidList->oidCount = iscsiConnList->cl_out_cnt; 1372fcf3ce44SJohn Forte for (i = 0; i < iscsiConnList->cl_out_cnt; i++) { 1373fcf3ce44SJohn Forte imaOidList->oids[i].objectType = SUN_IMA_OBJECT_TYPE_CONN; 1374fcf3ce44SJohn Forte imaOidList->oids[i].ownerId = 1; 1375fcf3ce44SJohn Forte imaOidList->oids[i].objectSequenceNumber = 1376fcf3ce44SJohn Forte iscsiConnList->cl_list[i].c_oid; 1377fcf3ce44SJohn Forte } 1378fcf3ce44SJohn Forte /* The pointer to the SUN_IMA_CONN_LIST structure is returned. */ 1379fcf3ce44SJohn Forte *ppList = imaOidList; 1380fcf3ce44SJohn Forte 1381fcf3ce44SJohn Forte free(iscsiConnList); 1382fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1383fcf3ce44SJohn Forte } 1384fcf3ce44SJohn Forte 1385fcf3ce44SJohn Forte /* 1386fcf3ce44SJohn Forte * SUN_IMA_GetConnProperties - 1387fcf3ce44SJohn Forte * 1388fcf3ce44SJohn Forte * Non-IMA defined function. 1389fcf3ce44SJohn Forte */ 1390fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConnProperties( 1391fcf3ce44SJohn Forte IMA_OID *connOid, 1392fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES **pProps 1393fcf3ce44SJohn Forte ) 1394fcf3ce44SJohn Forte { 1395fcf3ce44SJohn Forte iscsi_conn_list_t *pConnList; 1396fcf3ce44SJohn Forte iscsi_conn_props_t *pConnProps; 1397fcf3ce44SJohn Forte /* LINTED */ 1398fcf3ce44SJohn Forte struct sockaddr_in6 *addrIn6; 1399fcf3ce44SJohn Forte /* LINTED */ 1400fcf3ce44SJohn Forte struct sockaddr_in *addrIn; 1401fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES *pImaConnProps; 1402fcf3ce44SJohn Forte IMA_STATUS imaStatus; 1403fcf3ce44SJohn Forte int i; 1404fcf3ce44SJohn Forte 1405fcf3ce44SJohn Forte /* If there is any error *pProps should be set to NULL */ 1406fcf3ce44SJohn Forte *pProps = NULL; 1407fcf3ce44SJohn Forte 1408fcf3ce44SJohn Forte pImaConnProps = (SUN_IMA_CONN_PROPERTIES *)calloc(1, 1409fcf3ce44SJohn Forte sizeof (SUN_IMA_CONN_PROPERTIES)); 1410fcf3ce44SJohn Forte 1411fcf3ce44SJohn Forte if (pImaConnProps == NULL) { 1412fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1413fcf3ce44SJohn Forte } 1414fcf3ce44SJohn Forte 1415fcf3ce44SJohn Forte imaStatus = getConnOidList(NULL, &pConnList); 1416fcf3ce44SJohn Forte 1417fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1418fcf3ce44SJohn Forte free(pImaConnProps); 1419fcf3ce44SJohn Forte return (imaStatus); 1420fcf3ce44SJohn Forte } 1421fcf3ce44SJohn Forte 1422fcf3ce44SJohn Forte /* 1423fcf3ce44SJohn Forte * Walk the list returned to find our connection. 1424fcf3ce44SJohn Forte */ 1425fcf3ce44SJohn Forte for (i = 0; i < pConnList->cl_out_cnt; i++) { 1426fcf3ce44SJohn Forte 1427fcf3ce44SJohn Forte if (pConnList->cl_list[i].c_oid == 1428fcf3ce44SJohn Forte (uint32_t)connOid->objectSequenceNumber) { 1429fcf3ce44SJohn Forte 1430fcf3ce44SJohn Forte /* This is our connection. */ 1431fcf3ce44SJohn Forte imaStatus = getConnProps(&pConnList->cl_list[i], 1432fcf3ce44SJohn Forte &pConnProps); 1433fcf3ce44SJohn Forte 1434fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1435fcf3ce44SJohn Forte free(pConnList); 1436fcf3ce44SJohn Forte free(pImaConnProps); 1437fcf3ce44SJohn Forte return (imaStatus); 1438fcf3ce44SJohn Forte } 1439fcf3ce44SJohn Forte pImaConnProps->connectionID = pConnProps->cp_cid; 1440fcf3ce44SJohn Forte 1441fcf3ce44SJohn Forte /* 1442fcf3ce44SJohn Forte * Local Propeties 1443fcf3ce44SJohn Forte */ 1444fcf3ce44SJohn Forte if (pConnProps->cp_local.soa4.sin_family == AF_INET) { 1445fcf3ce44SJohn Forte 1446fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipv4Address = 1447fcf3ce44SJohn Forte IMA_TRUE; 1448fcf3ce44SJohn Forte pImaConnProps->local.portNumber = 1449fcf3ce44SJohn Forte pConnProps->cp_local.soa4.sin_port; 1450fcf3ce44SJohn Forte addrIn = &(pConnProps->cp_local.soa4); 1451fcf3ce44SJohn Forte bcopy(&pConnProps->cp_local.soa4.sin_addr, 1452fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipAddress, 1453fcf3ce44SJohn Forte sizeof (addrIn->sin_addr)); 1454fcf3ce44SJohn Forte 1455fcf3ce44SJohn Forte } else { 1456fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipv4Address = 1457fcf3ce44SJohn Forte IMA_FALSE; 1458fcf3ce44SJohn Forte pImaConnProps->local.portNumber = 1459fcf3ce44SJohn Forte pConnProps->cp_local.soa6.sin6_port; 1460fcf3ce44SJohn Forte addrIn6 = &(pConnProps->cp_local.soa6); 1461fcf3ce44SJohn Forte bcopy(&pConnProps->cp_local.soa6.sin6_addr, 1462fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipAddress, 1463fcf3ce44SJohn Forte sizeof (addrIn6->sin6_addr)); 1464fcf3ce44SJohn Forte 1465fcf3ce44SJohn Forte } 1466fcf3ce44SJohn Forte 1467fcf3ce44SJohn Forte /* 1468fcf3ce44SJohn Forte * Peer Propeties 1469fcf3ce44SJohn Forte */ 1470fcf3ce44SJohn Forte if (pConnProps->cp_peer.soa4.sin_family == AF_INET) { 1471fcf3ce44SJohn Forte 1472fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipv4Address = 1473fcf3ce44SJohn Forte IMA_TRUE; 1474fcf3ce44SJohn Forte pImaConnProps->peer.portNumber = 1475fcf3ce44SJohn Forte pConnProps->cp_peer.soa4.sin_port; 1476fcf3ce44SJohn Forte addrIn = &(pConnProps->cp_local.soa4); 1477fcf3ce44SJohn Forte bcopy(&pConnProps->cp_peer.soa4.sin_addr, 1478fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipAddress, 1479fcf3ce44SJohn Forte sizeof (addrIn->sin_addr)); 1480fcf3ce44SJohn Forte 1481fcf3ce44SJohn Forte } else { 1482fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipv4Address = 1483fcf3ce44SJohn Forte IMA_FALSE; 1484fcf3ce44SJohn Forte pImaConnProps->peer.portNumber = 1485fcf3ce44SJohn Forte pConnProps->cp_peer.soa6.sin6_port; 1486fcf3ce44SJohn Forte 1487fcf3ce44SJohn Forte addrIn6 = &pConnProps->cp_local.soa6; 1488fcf3ce44SJohn Forte bcopy(&pConnProps->cp_peer.soa6.sin6_addr, 1489fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipAddress, 1490fcf3ce44SJohn Forte sizeof (addrIn6->sin6_addr)); 1491fcf3ce44SJohn Forte } 1492fcf3ce44SJohn Forte 1493fcf3ce44SJohn Forte 1494fcf3ce44SJohn Forte pImaConnProps->valuesValid = 1495fcf3ce44SJohn Forte pConnProps->cp_params_valid; 1496fcf3ce44SJohn Forte pImaConnProps->defaultTime2Retain = 1497fcf3ce44SJohn Forte pConnProps->cp_params.default_time_to_retain; 1498fcf3ce44SJohn Forte pImaConnProps->defaultTime2Wait = 1499fcf3ce44SJohn Forte pConnProps->cp_params.default_time_to_wait; 1500fcf3ce44SJohn Forte pImaConnProps->errorRecoveryLevel = 1501fcf3ce44SJohn Forte pConnProps->cp_params.error_recovery_level; 1502fcf3ce44SJohn Forte pImaConnProps->firstBurstLength = 1503fcf3ce44SJohn Forte pConnProps->cp_params.first_burst_length; 1504fcf3ce44SJohn Forte pImaConnProps->maxBurstLength = 1505fcf3ce44SJohn Forte pConnProps->cp_params.max_burst_length; 1506fcf3ce44SJohn Forte pImaConnProps->maxConnections = 1507fcf3ce44SJohn Forte pConnProps->cp_params.max_connections; 1508fcf3ce44SJohn Forte pImaConnProps->maxOutstandingR2T = 1509fcf3ce44SJohn Forte pConnProps->cp_params.max_outstanding_r2t; 1510fcf3ce44SJohn Forte pImaConnProps->maxRecvDataSegmentLength = 1511fcf3ce44SJohn Forte pConnProps->cp_params.max_recv_data_seg_len; 1512fcf3ce44SJohn Forte 1513fcf3ce44SJohn Forte pImaConnProps->dataPduInOrder = 1514fcf3ce44SJohn Forte pConnProps->cp_params.data_pdu_in_order; 1515fcf3ce44SJohn Forte pImaConnProps->dataSequenceInOrder = 1516fcf3ce44SJohn Forte pConnProps->cp_params.data_sequence_in_order; 1517fcf3ce44SJohn Forte pImaConnProps->immediateData = 1518fcf3ce44SJohn Forte pConnProps->cp_params.immediate_data; 1519fcf3ce44SJohn Forte pImaConnProps->initialR2T = 1520fcf3ce44SJohn Forte pConnProps->cp_params.initial_r2t; 1521fcf3ce44SJohn Forte 1522fcf3ce44SJohn Forte pImaConnProps->headerDigest = 1523fcf3ce44SJohn Forte pConnProps->cp_params.header_digest; 1524fcf3ce44SJohn Forte pImaConnProps->dataDigest = 1525fcf3ce44SJohn Forte pConnProps->cp_params.data_digest; 1526fcf3ce44SJohn Forte 1527fcf3ce44SJohn Forte free(pConnProps); 1528fcf3ce44SJohn Forte break; 1529fcf3ce44SJohn Forte } 1530fcf3ce44SJohn Forte } 1531fcf3ce44SJohn Forte free(pConnList); 1532fcf3ce44SJohn Forte *pProps = pImaConnProps; 1533fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1534fcf3ce44SJohn Forte } 1535fcf3ce44SJohn Forte 1536fcf3ce44SJohn Forte 1537fcf3ce44SJohn Forte /* 1538fcf3ce44SJohn Forte * SUN_IMA_GetConfigSessions - 1539fcf3ce44SJohn Forte * 1540fcf3ce44SJohn Forte * Non-IMA defined function. 1541fcf3ce44SJohn Forte */ 1542fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConfigSessions( 1543fcf3ce44SJohn Forte IMA_OID targetOid, 1544fcf3ce44SJohn Forte SUN_IMA_CONFIG_SESSIONS **pConfigSessions 1545fcf3ce44SJohn Forte ) 1546fcf3ce44SJohn Forte { 1547fcf3ce44SJohn Forte int fd; 1548fcf3ce44SJohn Forte int status; 1549fcf3ce44SJohn Forte iscsi_config_sess_t *ics; 1550fcf3ce44SJohn Forte int size, idx; 1551fcf3ce44SJohn Forte 1552fcf3ce44SJohn Forte /* Allocate and setup initial buffer */ 1553fcf3ce44SJohn Forte size = sizeof (*ics); 1554fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)calloc(1, size); 1555fcf3ce44SJohn Forte if (ics == NULL) { 1556fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1557fcf3ce44SJohn Forte } 1558fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1559fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1560fcf3ce44SJohn Forte ics->ics_in = 1; 1561fcf3ce44SJohn Forte 1562fcf3ce44SJohn Forte /* Open driver devctl for ioctl */ 1563fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1564fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1565fcf3ce44SJohn Forte } 1566fcf3ce44SJohn Forte 1567fcf3ce44SJohn Forte /* Issue ioctl request */ 1568fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_GET_CONFIG_SESSIONS, ics) != 0) { 1569fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1570fcf3ce44SJohn Forte "ISCSI_GET_CONFIG_SESSIONS ioctl failed, errno: %d", 1571fcf3ce44SJohn Forte errno); 1572fcf3ce44SJohn Forte (void) close(fd); 1573fcf3ce44SJohn Forte free(ics); 1574fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1575fcf3ce44SJohn Forte } 1576fcf3ce44SJohn Forte 1577fcf3ce44SJohn Forte /* Check if we need to collect more information */ 1578fcf3ce44SJohn Forte idx = ics->ics_out; 1579fcf3ce44SJohn Forte if (idx > 1) { 1580fcf3ce44SJohn Forte 1581fcf3ce44SJohn Forte /* Free old buffer and reallocate re-sized buffer */ 1582fcf3ce44SJohn Forte free(ics); 1583fcf3ce44SJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(idx); 1584fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)calloc(1, size); 1585fcf3ce44SJohn Forte if (ics == NULL) { 1586fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1587fcf3ce44SJohn Forte } 1588fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1589fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1590fcf3ce44SJohn Forte ics->ics_in = idx; 1591fcf3ce44SJohn Forte 1592fcf3ce44SJohn Forte /* Issue ioctl request */ 1593fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_GET_CONFIG_SESSIONS, ics) != 0) { 1594fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1595fcf3ce44SJohn Forte "ISCSI_GET_CONFIG_SESSIONS ioctl failed, errno: %d", 1596fcf3ce44SJohn Forte errno); 1597fcf3ce44SJohn Forte (void) close(fd); 1598fcf3ce44SJohn Forte free(ics); 1599fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1600fcf3ce44SJohn Forte } 1601fcf3ce44SJohn Forte } 1602fcf3ce44SJohn Forte (void) close(fd); 1603fcf3ce44SJohn Forte 1604fcf3ce44SJohn Forte /* Allocate output buffer */ 1605fcf3ce44SJohn Forte size = sizeof (SUN_IMA_CONFIG_SESSIONS) + 1606fcf3ce44SJohn Forte ((ics->ics_out - 1) * sizeof (IMA_ADDRESS_KEY)); 1607fcf3ce44SJohn Forte *pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size); 1608fcf3ce44SJohn Forte if ((*pConfigSessions) == NULL) { 1609fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1610fcf3ce44SJohn Forte } 1611fcf3ce44SJohn Forte 1612fcf3ce44SJohn Forte /* Copy output information */ 1613fcf3ce44SJohn Forte (*pConfigSessions)->bound = 1614fcf3ce44SJohn Forte (ics->ics_bound == B_TRUE ? IMA_TRUE : IMA_FALSE); 1615fcf3ce44SJohn Forte (*pConfigSessions)->in = ics->ics_in; 1616fcf3ce44SJohn Forte (*pConfigSessions)->out = ics->ics_out; 1617fcf3ce44SJohn Forte for (idx = 0; idx < ics->ics_in; idx++) { 1618fcf3ce44SJohn Forte if (ics->ics_bindings[idx].i_insize == 1619fcf3ce44SJohn Forte sizeof (struct in_addr)) { 1620fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1621fcf3ce44SJohn Forte ipv4Address = IMA_TRUE; 1622fcf3ce44SJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in4, 1623fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1624fcf3ce44SJohn Forte ipAddress, sizeof (struct in_addr)); 1625fcf3ce44SJohn Forte } else { 1626fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1627fcf3ce44SJohn Forte ipv4Address = IMA_FALSE; 1628fcf3ce44SJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in6, 1629fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1630fcf3ce44SJohn Forte ipAddress, sizeof (struct in6_addr)); 1631fcf3ce44SJohn Forte } 1632fcf3ce44SJohn Forte } 1633fcf3ce44SJohn Forte 1634fcf3ce44SJohn Forte free(ics); 1635fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1636fcf3ce44SJohn Forte } 1637fcf3ce44SJohn Forte 1638fcf3ce44SJohn Forte /* 1639fcf3ce44SJohn Forte * SUN_IMA_SetConfigSessions - 1640fcf3ce44SJohn Forte * 1641fcf3ce44SJohn Forte * Non-IMA defined function. 1642fcf3ce44SJohn Forte */ 1643fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetConfigSessions( 1644fcf3ce44SJohn Forte IMA_OID targetOid, 1645fcf3ce44SJohn Forte SUN_IMA_CONFIG_SESSIONS *pConfigSessions 1646fcf3ce44SJohn Forte ) 1647fcf3ce44SJohn Forte { 1648fcf3ce44SJohn Forte int fd; 1649fcf3ce44SJohn Forte int status; 1650fcf3ce44SJohn Forte iscsi_config_sess_t *ics; 1651fcf3ce44SJohn Forte int idx, size; 1652fcf3ce44SJohn Forte 1653fcf3ce44SJohn Forte /* verify allowed range of sessions */ 1654fcf3ce44SJohn Forte if ((pConfigSessions->in < ISCSI_MIN_CONFIG_SESSIONS) || 1655fcf3ce44SJohn Forte (pConfigSessions->in > ISCSI_MAX_CONFIG_SESSIONS)) { 1656fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 1657fcf3ce44SJohn Forte } 1658fcf3ce44SJohn Forte 1659fcf3ce44SJohn Forte /* allocate record config_sess size */ 1660fcf3ce44SJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(pConfigSessions->in); 1661fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)malloc(size); 1662fcf3ce44SJohn Forte 1663fcf3ce44SJohn Forte /* setup config_sess information */ 1664fcf3ce44SJohn Forte (void) memset(ics, 0, sizeof (iscsi_config_sess_t)); 1665fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1666fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1667fcf3ce44SJohn Forte ics->ics_bound = 1668fcf3ce44SJohn Forte (pConfigSessions->bound == IMA_TRUE ? B_TRUE : B_FALSE); 1669fcf3ce44SJohn Forte ics->ics_in = pConfigSessions->in; 1670fcf3ce44SJohn Forte for (idx = 0; idx < ics->ics_in; idx++) { 1671fcf3ce44SJohn Forte if (pConfigSessions->bindings[idx].ipAddress. 1672fcf3ce44SJohn Forte ipv4Address == IMA_TRUE) { 1673fcf3ce44SJohn Forte ics->ics_bindings[idx].i_insize = 1674fcf3ce44SJohn Forte sizeof (struct in_addr); 1675fcf3ce44SJohn Forte bcopy(pConfigSessions->bindings[idx]. 1676fcf3ce44SJohn Forte ipAddress.ipAddress, 1677fcf3ce44SJohn Forte &ics->ics_bindings[idx].i_addr.in4, 1678fcf3ce44SJohn Forte sizeof (struct in_addr)); 1679fcf3ce44SJohn Forte } else { 1680fcf3ce44SJohn Forte ics->ics_bindings[idx].i_insize = 1681fcf3ce44SJohn Forte sizeof (struct in6_addr); 1682fcf3ce44SJohn Forte bcopy(pConfigSessions->bindings[idx]. 1683fcf3ce44SJohn Forte ipAddress.ipAddress, 1684fcf3ce44SJohn Forte &ics->ics_bindings[idx].i_addr.in6, 1685fcf3ce44SJohn Forte sizeof (struct in6_addr)); 1686fcf3ce44SJohn Forte } 1687fcf3ce44SJohn Forte } 1688fcf3ce44SJohn Forte 1689fcf3ce44SJohn Forte /* open driver */ 1690fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1691fcf3ce44SJohn Forte free(ics); 1692fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1693fcf3ce44SJohn Forte } 1694fcf3ce44SJohn Forte 1695fcf3ce44SJohn Forte /* issue ioctl request */ 1696fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_SET_CONFIG_SESSIONS, ics) != 0) { 1697fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1698fcf3ce44SJohn Forte "ISCSI_SET_CONFIG_SESSIONS ioctl failed, errno: %d", 1699fcf3ce44SJohn Forte errno); 1700fcf3ce44SJohn Forte (void) close(fd); 1701fcf3ce44SJohn Forte free(ics); 1702fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1703fcf3ce44SJohn Forte } 1704fcf3ce44SJohn Forte (void) close(fd); 1705fcf3ce44SJohn Forte free(ics); 1706fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1707fcf3ce44SJohn Forte } 1708fcf3ce44SJohn Forte 1709fcf3ce44SJohn Forte /* A helper function to obtain iSCSI node parameters. */ 1710fcf3ce44SJohn Forte static IMA_STATUS 1711fcf3ce44SJohn Forte getISCSINodeParameter( 1712fcf3ce44SJohn Forte int paramType, 1713fcf3ce44SJohn Forte IMA_OID *oid, 1714fcf3ce44SJohn Forte void *pProps, 1715fcf3ce44SJohn Forte uint32_t paramIndex 1716fcf3ce44SJohn Forte ) 1717fcf3ce44SJohn Forte { 1718fcf3ce44SJohn Forte int fd; 1719fcf3ce44SJohn Forte int status; 1720fcf3ce44SJohn Forte iscsi_param_get_t pg; 1721fcf3ce44SJohn Forte 1722fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1723fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1724fcf3ce44SJohn Forte } 1725fcf3ce44SJohn Forte 1726fcf3ce44SJohn Forte (void) memset(&pg, 0, sizeof (iscsi_param_get_t)); 1727fcf3ce44SJohn Forte pg.g_vers = ISCSI_INTERFACE_VERSION; 1728fcf3ce44SJohn Forte pg.g_oid = (uint32_t)oid->objectSequenceNumber; 1729fcf3ce44SJohn Forte pg.g_param = paramIndex; 1730fcf3ce44SJohn Forte pg.g_param_type = ISCSI_SESS_PARAM; 1731fcf3ce44SJohn Forte 1732fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) { 1733fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1734fcf3ce44SJohn Forte "ISCSI_PARAM_GET ioctl failed, errno: %d", errno); 1735fcf3ce44SJohn Forte (void) close(fd); 1736fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1737fcf3ce44SJohn Forte } 1738fcf3ce44SJohn Forte 1739fcf3ce44SJohn Forte switch (paramType) { 1740fcf3ce44SJohn Forte IMA_BOOL_VALUE *bp; 1741fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE *mp; 1742fcf3ce44SJohn Forte 1743fcf3ce44SJohn Forte case MIN_MAX_PARAM: 1744fcf3ce44SJohn Forte mp = (IMA_MIN_MAX_VALUE *)pProps; 1745fcf3ce44SJohn Forte 1746fcf3ce44SJohn Forte mp->currentValueValid = 1747fcf3ce44SJohn Forte (pg.g_value.v_valid == B_TRUE) ? 1748fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 1749fcf3ce44SJohn Forte mp->currentValue = pg.g_value.v_integer.i_current; 1750fcf3ce44SJohn Forte mp->defaultValue = pg.g_value.v_integer.i_default; 1751fcf3ce44SJohn Forte mp->minimumValue = pg.g_value.v_integer.i_min; 1752fcf3ce44SJohn Forte mp->maximumValue = pg.g_value.v_integer.i_max; 1753fcf3ce44SJohn Forte mp->incrementValue = pg.g_value.v_integer.i_incr; 1754fcf3ce44SJohn Forte break; 1755fcf3ce44SJohn Forte 1756fcf3ce44SJohn Forte case BOOL_PARAM: 1757fcf3ce44SJohn Forte bp = (IMA_BOOL_VALUE *)pProps; 1758fcf3ce44SJohn Forte bp->currentValueValid = 1759fcf3ce44SJohn Forte (pg.g_value.v_valid == B_TRUE) ? 1760fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 1761fcf3ce44SJohn Forte bp->currentValue = pg.g_value.v_bool.b_current; 1762fcf3ce44SJohn Forte bp->defaultValue = pg.g_value.v_bool.b_default; 1763fcf3ce44SJohn Forte break; 1764fcf3ce44SJohn Forte 1765fcf3ce44SJohn Forte default: 1766fcf3ce44SJohn Forte break; 1767fcf3ce44SJohn Forte } 1768fcf3ce44SJohn Forte 1769fcf3ce44SJohn Forte /* Issue ISCSI_PARAM_GET ioctl again to obtain connection parameters. */ 1770fcf3ce44SJohn Forte pg.g_param_type = ISCSI_CONN_PARAM; 1771fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) { 1772fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1773fcf3ce44SJohn Forte "ISCSI_PARAM_GET ioctl failed, errno: %d", errno); 1774fcf3ce44SJohn Forte (void) close(fd); 1775fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1776fcf3ce44SJohn Forte } 1777fcf3ce44SJohn Forte 1778fcf3ce44SJohn Forte (void) close(fd); 1779fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1780fcf3ce44SJohn Forte } 1781fcf3ce44SJohn Forte 1782fcf3ce44SJohn Forte /* A helper function to set iSCSI node parameters. */ 1783fcf3ce44SJohn Forte static IMA_STATUS 1784fcf3ce44SJohn Forte setISCSINodeParameter( 1785fcf3ce44SJohn Forte int paramType, 1786fcf3ce44SJohn Forte IMA_OID *oid, 1787fcf3ce44SJohn Forte void *pProp, 1788fcf3ce44SJohn Forte uint32_t paramIndex 1789fcf3ce44SJohn Forte ) 1790fcf3ce44SJohn Forte { 1791fcf3ce44SJohn Forte int fd; 1792fcf3ce44SJohn Forte int status; 1793fcf3ce44SJohn Forte iscsi_param_set_t ps; 1794fcf3ce44SJohn Forte 1795fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1796fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1797fcf3ce44SJohn Forte } 1798fcf3ce44SJohn Forte 1799fcf3ce44SJohn Forte (void) memset(&ps, 0, sizeof (iscsi_param_set_t)); 1800fcf3ce44SJohn Forte ps.s_vers = ISCSI_INTERFACE_VERSION; 1801fcf3ce44SJohn Forte ps.s_oid = (uint32_t)oid->objectSequenceNumber; 1802fcf3ce44SJohn Forte ps.s_param = paramIndex; 1803fcf3ce44SJohn Forte 1804fcf3ce44SJohn Forte switch (paramType) { 1805fcf3ce44SJohn Forte IMA_BOOL_VALUE *bp; 1806fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE *mp; 1807fcf3ce44SJohn Forte 1808fcf3ce44SJohn Forte case MIN_MAX_PARAM: 1809fcf3ce44SJohn Forte mp = (IMA_MIN_MAX_VALUE *)pProp; 1810fcf3ce44SJohn Forte ps.s_value.v_integer = mp->currentValue; 1811fcf3ce44SJohn Forte break; 1812fcf3ce44SJohn Forte case BOOL_PARAM: 1813fcf3ce44SJohn Forte bp = (IMA_BOOL_VALUE *)pProp; 1814fcf3ce44SJohn Forte ps.s_value.v_bool = 1815fcf3ce44SJohn Forte (bp->currentValue == IMA_TRUE) ? 1816fcf3ce44SJohn Forte B_TRUE : B_FALSE; 1817fcf3ce44SJohn Forte break; 1818fcf3ce44SJohn Forte 1819fcf3ce44SJohn Forte default: 1820fcf3ce44SJohn Forte break; 1821fcf3ce44SJohn Forte } 1822fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_SET, &ps)) { 1823fcf3ce44SJohn Forte (void) close(fd); 1824fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1825fcf3ce44SJohn Forte "ISCSI_PARAM_SET ioctl failed, errno: %d", errno); 1826fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1827fcf3ce44SJohn Forte } 1828fcf3ce44SJohn Forte 1829fcf3ce44SJohn Forte (void) close(fd); 1830fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1831fcf3ce44SJohn Forte } 1832fcf3ce44SJohn Forte 1833fcf3ce44SJohn Forte static int 1834fcf3ce44SJohn Forte prepare_discovery_entry( 1835fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS discoveryAddress, 1836fcf3ce44SJohn Forte entry_t *entry 1837fcf3ce44SJohn Forte ) 1838fcf3ce44SJohn Forte { 1839fcf3ce44SJohn Forte return (prepare_discovery_entry_IMA(discoveryAddress.imaStruct, entry)); 1840fcf3ce44SJohn Forte } 1841fcf3ce44SJohn Forte 1842fcf3ce44SJohn Forte static int 1843fcf3ce44SJohn Forte prepare_discovery_entry_IMA( 1844fcf3ce44SJohn Forte IMA_TARGET_ADDRESS discoveryAddress, 1845fcf3ce44SJohn Forte entry_t *entry 1846fcf3ce44SJohn Forte ) 1847fcf3ce44SJohn Forte { 1848fcf3ce44SJohn Forte (void) memset(entry, 0, sizeof (entry_t)); 1849fcf3ce44SJohn Forte entry->e_vers = ISCSI_INTERFACE_VERSION; 1850fcf3ce44SJohn Forte entry->e_oid = ISCSI_OID_NOTSET; 1851fcf3ce44SJohn Forte 1852fcf3ce44SJohn Forte if (discoveryAddress.hostnameIpAddress.id.ipAddress. 1853fcf3ce44SJohn Forte ipv4Address == IMA_FALSE) { 1854fcf3ce44SJohn Forte 1855fcf3ce44SJohn Forte bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress. 1856fcf3ce44SJohn Forte ipAddress, entry->e_u.u_in6.s6_addr, 1857fcf3ce44SJohn Forte sizeof (entry->e_u.u_in6.s6_addr)); 1858fcf3ce44SJohn Forte 1859fcf3ce44SJohn Forte entry->e_insize = sizeof (struct in6_addr); 1860fcf3ce44SJohn Forte } else { 1861fcf3ce44SJohn Forte 1862fcf3ce44SJohn Forte bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress. 1863fcf3ce44SJohn Forte ipAddress, &entry->e_u.u_in4.s_addr, 1864fcf3ce44SJohn Forte sizeof (entry->e_u.u_in4.s_addr)); 1865fcf3ce44SJohn Forte 1866fcf3ce44SJohn Forte entry->e_insize = sizeof (struct in_addr); 1867fcf3ce44SJohn Forte } 1868fcf3ce44SJohn Forte 1869fcf3ce44SJohn Forte entry->e_port = discoveryAddress.portNumber; 1870fcf3ce44SJohn Forte entry->e_tpgt = 0; 1871fcf3ce44SJohn Forte return (DISC_ADDR_OK); 1872fcf3ce44SJohn Forte } 1873fcf3ce44SJohn Forte 1874fcf3ce44SJohn Forte static IMA_STATUS configure_discovery_method( 1875fcf3ce44SJohn Forte IMA_BOOL enable, 1876fcf3ce44SJohn Forte iSCSIDiscoveryMethod_t method 1877fcf3ce44SJohn Forte ) 1878fcf3ce44SJohn Forte { 1879fcf3ce44SJohn Forte int fd, status; 1880fcf3ce44SJohn Forte 1881fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1882fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1883fcf3ce44SJohn Forte } 1884fcf3ce44SJohn Forte 1885fcf3ce44SJohn Forte if (enable == IMA_FALSE) { 1886fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_CLEAR, &method)) { 1887fcf3ce44SJohn Forte status = errno; 1888fcf3ce44SJohn Forte (void) close(fd); 1889fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1890fcf3ce44SJohn Forte "ISCSI_DISCOVERY_CLEAR ioctl failed, errno: %d", 1891fcf3ce44SJohn Forte status); 1892fcf3ce44SJohn Forte if (status == EBUSY) { 1893fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 1894fcf3ce44SJohn Forte } else { 1895fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1896fcf3ce44SJohn Forte } 1897fcf3ce44SJohn Forte } 1898fcf3ce44SJohn Forte 1899fcf3ce44SJohn Forte (void) close(fd); 1900fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1901fcf3ce44SJohn Forte } else { 1902fcf3ce44SJohn Forte /* Set the discovery method */ 1903fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_SET, &method)) { 1904fcf3ce44SJohn Forte status = errno; 1905fcf3ce44SJohn Forte (void) close(fd); 1906fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1907fcf3ce44SJohn Forte "ISCSI_DISCOVERY_SET ioctl failed, errno: %d", 1908fcf3ce44SJohn Forte status); 1909fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1910fcf3ce44SJohn Forte } 1911fcf3ce44SJohn Forte 1912fcf3ce44SJohn Forte (void) close(fd); 1913fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1914fcf3ce44SJohn Forte } 1915fcf3ce44SJohn Forte } 1916fcf3ce44SJohn Forte 1917fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 1918fcf3ce44SJohn Forte static IMA_BOOL authMethodMatch( 1919fcf3ce44SJohn Forte IMA_AUTHMETHOD matchingMethod, 1920fcf3ce44SJohn Forte IMA_AUTHMETHOD *methodList, 1921fcf3ce44SJohn Forte IMA_UINT maxEntries 1922fcf3ce44SJohn Forte ) 1923fcf3ce44SJohn Forte { 1924fcf3ce44SJohn Forte IMA_UINT i; 1925fcf3ce44SJohn Forte 1926fcf3ce44SJohn Forte for (i = 0; i < maxEntries; i++) { 1927fcf3ce44SJohn Forte if (methodList[i] == matchingMethod) { 1928fcf3ce44SJohn Forte return (IMA_TRUE); 1929fcf3ce44SJohn Forte } 1930fcf3ce44SJohn Forte } 1931fcf3ce44SJohn Forte 1932fcf3ce44SJohn Forte return (IMA_FALSE); 1933fcf3ce44SJohn Forte } 1934fcf3ce44SJohn Forte 1935fcf3ce44SJohn Forte static IMA_STATUS get_target_oid_list( 1936fcf3ce44SJohn Forte uint32_t targetListType, 1937fcf3ce44SJohn Forte IMA_OID_LIST **ppList) 1938fcf3ce44SJohn Forte { 1939fcf3ce44SJohn Forte int fd; 1940fcf3ce44SJohn Forte int i; 1941fcf3ce44SJohn Forte int target_list_size; 1942fcf3ce44SJohn Forte int status; 1943fcf3ce44SJohn Forte int out_cnt; 1944fcf3ce44SJohn Forte iscsi_target_list_t *idlp; 1945fcf3ce44SJohn Forte 1946fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1947fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1948fcf3ce44SJohn Forte } 1949fcf3ce44SJohn Forte 1950fcf3ce44SJohn Forte idlp = (iscsi_target_list_t *)calloc(1, sizeof (iscsi_target_list_t)); 1951fcf3ce44SJohn Forte if (idlp == NULL) { 1952fcf3ce44SJohn Forte (void) close(fd); 1953fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1954fcf3ce44SJohn Forte } 1955fcf3ce44SJohn Forte idlp->tl_vers = ISCSI_INTERFACE_VERSION; 1956fcf3ce44SJohn Forte idlp->tl_in_cnt = idlp->tl_out_cnt = 1; 1957fcf3ce44SJohn Forte idlp->tl_tgt_list_type = targetListType; 1958fcf3ce44SJohn Forte 1959fcf3ce44SJohn Forte /* 1960fcf3ce44SJohn Forte * Issue ioctl. Space has been allocted for one entry. 1961fcf3ce44SJohn Forte * If more than one entry should be returned, we will re-issue the 1962fcf3ce44SJohn Forte * entry with the right amount of space allocted 1963fcf3ce44SJohn Forte */ 1964fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) { 1965fcf3ce44SJohn Forte (void) close(fd); 1966fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1967fcf3ce44SJohn Forte "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 1968fcf3ce44SJohn Forte targetListType, errno); 1969fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1970fcf3ce44SJohn Forte } 1971fcf3ce44SJohn Forte if (idlp->tl_out_cnt > 1) { 1972fcf3ce44SJohn Forte out_cnt = idlp->tl_out_cnt; 1973fcf3ce44SJohn Forte free(idlp); 1974fcf3ce44SJohn Forte 1975fcf3ce44SJohn Forte target_list_size = sizeof (iscsi_target_list_t); 1976fcf3ce44SJohn Forte target_list_size += (sizeof (uint32_t) * out_cnt - 1); 1977fcf3ce44SJohn Forte idlp = (iscsi_target_list_t *)calloc(1, target_list_size); 1978fcf3ce44SJohn Forte if (idlp == NULL) { 1979fcf3ce44SJohn Forte (void) close(fd); 1980fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1981fcf3ce44SJohn Forte } 1982fcf3ce44SJohn Forte idlp->tl_vers = ISCSI_INTERFACE_VERSION; 1983fcf3ce44SJohn Forte idlp->tl_in_cnt = out_cnt; 1984fcf3ce44SJohn Forte idlp->tl_tgt_list_type = targetListType; 1985fcf3ce44SJohn Forte 1986fcf3ce44SJohn Forte /* Issue the same ioctl again to obtain all the OIDs. */ 1987fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) { 1988fcf3ce44SJohn Forte #define ERROR_STR "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno :%d" 1989fcf3ce44SJohn Forte free(idlp); 1990fcf3ce44SJohn Forte (void) close(fd); 1991fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1992fcf3ce44SJohn Forte ERROR_STR, targetListType, errno); 1993fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1994fcf3ce44SJohn Forte #undef ERROR_STR 1995fcf3ce44SJohn Forte 1996fcf3ce44SJohn Forte } 1997fcf3ce44SJohn Forte } 1998fcf3ce44SJohn Forte 1999fcf3ce44SJohn Forte *ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) + 2000fcf3ce44SJohn Forte idlp->tl_out_cnt * sizeof (IMA_OID)); 2001fcf3ce44SJohn Forte (*ppList)->oidCount = idlp->tl_out_cnt; 2002fcf3ce44SJohn Forte for (i = 0; i < idlp->tl_out_cnt; i++) { 2003fcf3ce44SJohn Forte (*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_TARGET; 2004fcf3ce44SJohn Forte (*ppList)->oids[i].ownerId = 1; 2005fcf3ce44SJohn Forte (*ppList)->oids[i].objectSequenceNumber = idlp->tl_oid_list[i]; 2006fcf3ce44SJohn Forte } 2007fcf3ce44SJohn Forte 2008fcf3ce44SJohn Forte free(idlp); 2009fcf3ce44SJohn Forte (void) close(fd); 2010fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2011fcf3ce44SJohn Forte } 2012fcf3ce44SJohn Forte 2013fcf3ce44SJohn Forte static IMA_STATUS get_target_lun_oid_list( 2014fcf3ce44SJohn Forte IMA_OID * targetOid, 2015fcf3ce44SJohn Forte iscsi_lun_list_t **ppLunList) 2016fcf3ce44SJohn Forte { 2017fcf3ce44SJohn Forte int fd; 2018fcf3ce44SJohn Forte iscsi_lun_list_t *illp, *illp_saved; 2019fcf3ce44SJohn Forte int lun_list_size; 2020fcf3ce44SJohn Forte int status; 2021fcf3ce44SJohn Forte 2022fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2023fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2024fcf3ce44SJohn Forte } 2025fcf3ce44SJohn Forte 2026fcf3ce44SJohn Forte illp = (iscsi_lun_list_t *)calloc(1, sizeof (iscsi_lun_list_t)); 2027fcf3ce44SJohn Forte if (illp == NULL) { 2028fcf3ce44SJohn Forte (void) close(fd); 2029fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2030fcf3ce44SJohn Forte } 2031fcf3ce44SJohn Forte illp->ll_vers = ISCSI_INTERFACE_VERSION; 2032fcf3ce44SJohn Forte if (targetOid == NULL) { 2033fcf3ce44SJohn Forte /* get lun oid list for all targets */ 2034fcf3ce44SJohn Forte illp->ll_all_tgts = B_TRUE; 2035fcf3ce44SJohn Forte } else { 2036fcf3ce44SJohn Forte /* get lun oid list for single target */ 2037fcf3ce44SJohn Forte illp->ll_all_tgts = B_FALSE; 2038fcf3ce44SJohn Forte illp->ll_tgt_oid = (uint32_t)targetOid->objectSequenceNumber; 2039fcf3ce44SJohn Forte } 2040fcf3ce44SJohn Forte illp->ll_in_cnt = illp->ll_out_cnt = 1; 2041fcf3ce44SJohn Forte 2042fcf3ce44SJohn Forte /* 2043fcf3ce44SJohn Forte * Issue ioctl to retrieve the target luns. Space has been allocted 2044fcf3ce44SJohn Forte * for one entry. If more than one entry should be returned, we 2045fcf3ce44SJohn Forte * will re-issue the entry with the right amount of space allocted 2046fcf3ce44SJohn Forte */ 2047fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) { 2048fcf3ce44SJohn Forte (void) close(fd); 2049fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2050fcf3ce44SJohn Forte "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno); 2051fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2052fcf3ce44SJohn Forte } 2053fcf3ce44SJohn Forte 2054fcf3ce44SJohn Forte if (illp->ll_out_cnt > 1) { 2055fcf3ce44SJohn Forte illp_saved = illp; 2056fcf3ce44SJohn Forte lun_list_size = sizeof (iscsi_lun_list_t); 2057fcf3ce44SJohn Forte lun_list_size += (sizeof (iscsi_if_lun_t) * 2058fcf3ce44SJohn Forte (illp->ll_out_cnt - 1)); 2059fcf3ce44SJohn Forte illp = (iscsi_lun_list_t *)calloc(1, lun_list_size); 2060fcf3ce44SJohn Forte if (illp == NULL) { 2061fcf3ce44SJohn Forte (void) close(fd); 2062fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2063fcf3ce44SJohn Forte } 2064fcf3ce44SJohn Forte illp->ll_vers = ISCSI_INTERFACE_VERSION; 2065fcf3ce44SJohn Forte illp->ll_all_tgts = illp_saved->ll_all_tgts; 2066fcf3ce44SJohn Forte illp->ll_tgt_oid = illp_saved->ll_tgt_oid; 2067fcf3ce44SJohn Forte illp->ll_in_cnt = illp_saved->ll_out_cnt; 2068fcf3ce44SJohn Forte 2069fcf3ce44SJohn Forte free(illp_saved); 2070fcf3ce44SJohn Forte 2071fcf3ce44SJohn Forte /* Issue the same ioctl again to get all the target LUN list */ 2072fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) { 2073fcf3ce44SJohn Forte free(illp); 2074fcf3ce44SJohn Forte (void) close(fd); 2075fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2076fcf3ce44SJohn Forte "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", 2077fcf3ce44SJohn Forte errno); 2078fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2079fcf3ce44SJohn Forte 2080fcf3ce44SJohn Forte } 2081fcf3ce44SJohn Forte } 2082fcf3ce44SJohn Forte *ppLunList = illp; 2083fcf3ce44SJohn Forte 2084fcf3ce44SJohn Forte 2085fcf3ce44SJohn Forte (void) close(fd); 2086fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2087fcf3ce44SJohn Forte } 2088fcf3ce44SJohn Forte 2089fcf3ce44SJohn Forte /* A helper function to obtain digest algorithms. */ 2090fcf3ce44SJohn Forte static IMA_STATUS 2091fcf3ce44SJohn Forte getDigest( 2092fcf3ce44SJohn Forte IMA_OID oid, 2093fcf3ce44SJohn Forte int ioctlCmd, 2094fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 2095fcf3ce44SJohn Forte ) 2096fcf3ce44SJohn Forte { 2097fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE pProps; 2098fcf3ce44SJohn Forte IMA_STATUS status; 2099fcf3ce44SJohn Forte 2100fcf3ce44SJohn Forte if ((status = getISCSINodeParameter(MIN_MAX_PARAM, &oid, &pProps, 2101fcf3ce44SJohn Forte ioctlCmd)) != IMA_STATUS_SUCCESS) { 2102fcf3ce44SJohn Forte return (status); 2103fcf3ce44SJohn Forte } 2104fcf3ce44SJohn Forte 2105fcf3ce44SJohn Forte switch (pProps.defaultValue) { 2106fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2107fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_NONE; 2108fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 1; 2109fcf3ce44SJohn Forte break; 2110fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2111fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_CRC32C; 2112fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 1; 2113fcf3ce44SJohn Forte break; 2114fcf3ce44SJohn Forte 2115fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2116fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_CRC32C; 2117fcf3ce44SJohn Forte algorithm->defaultAlgorithms[1] = ISCSI_DIGEST_NONE; 2118fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 2; 2119fcf3ce44SJohn Forte break; 2120fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2121fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_NONE; 2122fcf3ce44SJohn Forte algorithm->defaultAlgorithms[1] = ISCSI_DIGEST_CRC32C; 2123fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 2; 2124fcf3ce44SJohn Forte break; 2125fcf3ce44SJohn Forte default: 2126fcf3ce44SJohn Forte /* Error */ 2127fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2128fcf3ce44SJohn Forte "Invalid default digest: %d", pProps.defaultValue); 2129fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2130fcf3ce44SJohn Forte } 2131fcf3ce44SJohn Forte 2132fcf3ce44SJohn Forte /* The configured value */ 2133fcf3ce44SJohn Forte if (pProps.currentValueValid == IMA_TRUE) { 2134fcf3ce44SJohn Forte algorithm->currentValid = IMA_TRUE; 2135fcf3ce44SJohn Forte 2136fcf3ce44SJohn Forte switch (pProps.currentValue) { 2137fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2138fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2139fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2140fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 1; 2141fcf3ce44SJohn Forte break; 2142fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2143fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2144fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2145fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 1; 2146fcf3ce44SJohn Forte break; 2147fcf3ce44SJohn Forte 2148fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2149fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2150fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2151fcf3ce44SJohn Forte algorithm->currentAlgorithms[1] = 2152fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2153fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 2; 2154fcf3ce44SJohn Forte break; 2155fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2156fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2157fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2158fcf3ce44SJohn Forte algorithm->currentAlgorithms[1] = 2159fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2160fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 2; 2161fcf3ce44SJohn Forte break; 2162fcf3ce44SJohn Forte default: 2163fcf3ce44SJohn Forte /* Error */ 2164fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2165fcf3ce44SJohn Forte "Invalid configured digest: %d", 2166fcf3ce44SJohn Forte pProps.defaultValue); 2167fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2168fcf3ce44SJohn Forte } 2169fcf3ce44SJohn Forte 2170fcf3ce44SJohn Forte } else { 2171fcf3ce44SJohn Forte algorithm->currentValid = IMA_FALSE; 2172fcf3ce44SJohn Forte } 2173fcf3ce44SJohn Forte 2174fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2175fcf3ce44SJohn Forte } 2176fcf3ce44SJohn Forte 2177fcf3ce44SJohn Forte /* 2178fcf3ce44SJohn Forte * getConnOidList - 2179fcf3ce44SJohn Forte */ 2180fcf3ce44SJohn Forte static IMA_STATUS getConnOidList( 2181fcf3ce44SJohn Forte IMA_OID *sessOid, 2182fcf3ce44SJohn Forte iscsi_conn_list_t **ppConnList 2183fcf3ce44SJohn Forte ) 2184fcf3ce44SJohn Forte { 2185fcf3ce44SJohn Forte iscsi_conn_list_t *iscsiConnList = NULL; 2186fcf3ce44SJohn Forte size_t allocLen; 2187fcf3ce44SJohn Forte int fd; 2188fcf3ce44SJohn Forte int status; 2189fcf3ce44SJohn Forte int out_cnt; 2190fcf3ce44SJohn Forte 2191fcf3ce44SJohn Forte /* Preset it to NULL to prepare for the case of failure */ 2192fcf3ce44SJohn Forte *ppConnList = NULL; 2193fcf3ce44SJohn Forte 2194fcf3ce44SJohn Forte /* We try to open the driver now. */ 2195fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2196fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2197fcf3ce44SJohn Forte } 2198fcf3ce44SJohn Forte 2199fcf3ce44SJohn Forte iscsiConnList = (iscsi_conn_list_t *)calloc(1, 2200fcf3ce44SJohn Forte sizeof (iscsi_conn_list_t)); 2201fcf3ce44SJohn Forte if (iscsiConnList == NULL) { 2202fcf3ce44SJohn Forte (void) close(fd); 2203fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2204fcf3ce44SJohn Forte } 2205fcf3ce44SJohn Forte iscsiConnList->cl_vers = ISCSI_INTERFACE_VERSION; 2206fcf3ce44SJohn Forte iscsiConnList->cl_in_cnt = iscsiConnList->cl_out_cnt = 1; 2207fcf3ce44SJohn Forte if (sessOid == NULL) { 2208fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_TRUE; 2209fcf3ce44SJohn Forte } else { 2210fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_FALSE; 2211fcf3ce44SJohn Forte iscsiConnList->cl_sess_oid = 2212fcf3ce44SJohn Forte (uint32_t)sessOid->objectSequenceNumber; 2213fcf3ce44SJohn Forte } 2214fcf3ce44SJohn Forte /* 2215fcf3ce44SJohn Forte * Issue ioctl to retrieve the connection OIDs. Space has been 2216fcf3ce44SJohn Forte * allocated for one entry. If more than one entry should be 2217fcf3ce44SJohn Forte * returned, we will re-issue the entry with the right amount of 2218fcf3ce44SJohn Forte * space allocted 2219fcf3ce44SJohn Forte */ 2220fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_OID_LIST_GET, iscsiConnList) != 0) { 2221fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2222fcf3ce44SJohn Forte "ISCSI_CONN_OID_LIST_GET ioctl failed, errno: %d", errno); 2223fcf3ce44SJohn Forte *ppConnList = NULL; 2224fcf3ce44SJohn Forte (void) close(fd); 2225fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2226fcf3ce44SJohn Forte } 2227fcf3ce44SJohn Forte if (iscsiConnList->cl_out_cnt > 1) { 2228fcf3ce44SJohn Forte out_cnt = iscsiConnList->cl_out_cnt; 2229fcf3ce44SJohn Forte free(iscsiConnList); 2230fcf3ce44SJohn Forte 2231fcf3ce44SJohn Forte allocLen = sizeof (iscsi_conn_list_t); 2232fcf3ce44SJohn Forte allocLen += (sizeof (iscsi_if_conn_t) * out_cnt - 1); 2233fcf3ce44SJohn Forte iscsiConnList = (iscsi_conn_list_t *)calloc(1, allocLen); 2234fcf3ce44SJohn Forte if (iscsiConnList == NULL) { 2235fcf3ce44SJohn Forte *ppConnList = NULL; 2236fcf3ce44SJohn Forte (void) close(fd); 2237fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2238fcf3ce44SJohn Forte } 2239fcf3ce44SJohn Forte iscsiConnList->cl_vers = ISCSI_INTERFACE_VERSION; 2240fcf3ce44SJohn Forte iscsiConnList->cl_in_cnt = out_cnt; 2241fcf3ce44SJohn Forte if (sessOid == NULL) { 2242fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_TRUE; 2243fcf3ce44SJohn Forte } else { 2244fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_FALSE; 2245fcf3ce44SJohn Forte iscsiConnList->cl_sess_oid = 2246fcf3ce44SJohn Forte (uint32_t)sessOid->objectSequenceNumber; 2247fcf3ce44SJohn Forte } 2248fcf3ce44SJohn Forte /* Issue the same ioctl again to obtain all the OIDs */ 2249fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_OID_LIST_GET, iscsiConnList) != 0) { 2250fcf3ce44SJohn Forte 2251fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2252fcf3ce44SJohn Forte "ISCSI_CONN_OID_LIST_GET ioctl failed, errno: %d", 2253fcf3ce44SJohn Forte errno); 2254fcf3ce44SJohn Forte *ppConnList = NULL; 2255fcf3ce44SJohn Forte free(iscsiConnList); 2256fcf3ce44SJohn Forte (void) close(fd); 2257fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2258fcf3ce44SJohn Forte 2259fcf3ce44SJohn Forte } 2260fcf3ce44SJohn Forte 2261fcf3ce44SJohn Forte if (out_cnt < iscsiConnList->cl_out_cnt) { 2262fcf3ce44SJohn Forte /* 2263fcf3ce44SJohn Forte * The connection list grew between the first and second 2264fcf3ce44SJohn Forte * ioctls. 2265fcf3ce44SJohn Forte */ 2266fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2267fcf3ce44SJohn Forte "The connection list has grown. There could be " 2268fcf3ce44SJohn Forte "more connections than listed."); 2269fcf3ce44SJohn Forte } 2270fcf3ce44SJohn Forte } 2271fcf3ce44SJohn Forte 2272fcf3ce44SJohn Forte 2273fcf3ce44SJohn Forte (void) close(fd); 2274fcf3ce44SJohn Forte *ppConnList = iscsiConnList; 2275fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2276fcf3ce44SJohn Forte } 2277fcf3ce44SJohn Forte 2278fcf3ce44SJohn Forte /* 2279fcf3ce44SJohn Forte * getConnProps - 2280fcf3ce44SJohn Forte */ 2281fcf3ce44SJohn Forte static IMA_STATUS getConnProps( 2282fcf3ce44SJohn Forte iscsi_if_conn_t *pConn, 2283fcf3ce44SJohn Forte iscsi_conn_props_t **ppConnProps 2284fcf3ce44SJohn Forte ) 2285fcf3ce44SJohn Forte { 2286fcf3ce44SJohn Forte iscsi_conn_props_t *iscsiConnProps; 2287fcf3ce44SJohn Forte int fd; 2288fcf3ce44SJohn Forte int status; 2289fcf3ce44SJohn Forte 2290fcf3ce44SJohn Forte /* We try to open the driver. */ 2291fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2292fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2293fcf3ce44SJohn Forte } 2294fcf3ce44SJohn Forte 2295fcf3ce44SJohn Forte iscsiConnProps = (iscsi_conn_props_t *)calloc(1, 2296fcf3ce44SJohn Forte sizeof (*iscsiConnProps)); 2297fcf3ce44SJohn Forte 2298fcf3ce44SJohn Forte if (iscsiConnProps == NULL) { 2299fcf3ce44SJohn Forte (void) close(fd); 2300fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2301fcf3ce44SJohn Forte } 2302fcf3ce44SJohn Forte 2303fcf3ce44SJohn Forte iscsiConnProps->cp_vers = ISCSI_INTERFACE_VERSION; 2304fcf3ce44SJohn Forte iscsiConnProps->cp_oid = pConn->c_oid; 2305fcf3ce44SJohn Forte iscsiConnProps->cp_cid = pConn->c_cid; 2306fcf3ce44SJohn Forte iscsiConnProps->cp_sess_oid = pConn->c_sess_oid; 2307fcf3ce44SJohn Forte 2308fcf3ce44SJohn Forte /* The IOCTL is submitted. */ 2309fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_PROPS_GET, iscsiConnProps) != 0) { 2310fcf3ce44SJohn Forte /* IOCTL failed */ 2311fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2312fcf3ce44SJohn Forte "ISCSI_AUTH_CLEAR ioctl failed, errno: %d", errno); 2313fcf3ce44SJohn Forte free(iscsiConnProps); 2314fcf3ce44SJohn Forte (void) close(fd); 2315fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2316fcf3ce44SJohn Forte } 2317fcf3ce44SJohn Forte (void) close(fd); 2318fcf3ce44SJohn Forte *ppConnProps = iscsiConnProps; 2319fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2320fcf3ce44SJohn Forte } 2321fcf3ce44SJohn Forte 2322fcf3ce44SJohn Forte /* A helper function to set authentication method. */ 2323fcf3ce44SJohn Forte static IMA_STATUS 2324fcf3ce44SJohn Forte setAuthMethods( 2325fcf3ce44SJohn Forte IMA_OID oid, 2326fcf3ce44SJohn Forte IMA_UINT *pMethodCount, 2327fcf3ce44SJohn Forte const IMA_AUTHMETHOD *pMethodList 2328fcf3ce44SJohn Forte ) 2329fcf3ce44SJohn Forte { 2330fcf3ce44SJohn Forte int fd; 2331fcf3ce44SJohn Forte int i; 2332fcf3ce44SJohn Forte int status; 2333fcf3ce44SJohn Forte iscsi_auth_props_t auth; 2334fcf3ce44SJohn Forte 2335fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2336fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2337fcf3ce44SJohn Forte } 2338fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 2339fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 2340fcf3ce44SJohn Forte auth.a_oid = (uint32_t)oid.objectSequenceNumber; 2341fcf3ce44SJohn Forte 2342fcf3ce44SJohn Forte /* 2343fcf3ce44SJohn Forte * Get the current auth fields so they don't need to be reset 2344fcf3ce44SJohn Forte * here. 2345fcf3ce44SJohn Forte */ 2346fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 2347fcf3ce44SJohn Forte /* EMPTY */ 2348fcf3ce44SJohn Forte /* Initializing auth structure with current settings */ 2349fcf3ce44SJohn Forte } 2350fcf3ce44SJohn Forte auth.a_auth_method = authMethodNone; 2351fcf3ce44SJohn Forte 2352fcf3ce44SJohn Forte for (i = 0; i < *pMethodCount; i++) { 2353fcf3ce44SJohn Forte switch (pMethodList[i]) { 2354fcf3ce44SJohn Forte case IMA_AUTHMETHOD_CHAP: 2355fcf3ce44SJohn Forte auth.a_auth_method |= authMethodCHAP; 2356fcf3ce44SJohn Forte break; 2357fcf3ce44SJohn Forte default: 2358fcf3ce44SJohn Forte break; 2359fcf3ce44SJohn Forte } 2360fcf3ce44SJohn Forte } 2361fcf3ce44SJohn Forte 2362fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) { 2363fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2364fcf3ce44SJohn Forte "ISCSI_AUTH_SET failed, errno: %d", errno); 2365fcf3ce44SJohn Forte (void) close(fd); 2366fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2367fcf3ce44SJohn Forte } 2368fcf3ce44SJohn Forte 2369fcf3ce44SJohn Forte (void) close(fd); 2370fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2371fcf3ce44SJohn Forte } 2372fcf3ce44SJohn Forte 2373fcf3ce44SJohn Forte /* A helper function to set authentication method. */ 2374fcf3ce44SJohn Forte static IMA_STATUS getAuthMethods( 2375fcf3ce44SJohn Forte IMA_OID oid, 2376fcf3ce44SJohn Forte IMA_UINT *pMethodCount, 2377fcf3ce44SJohn Forte IMA_AUTHMETHOD *pMethodList 2378fcf3ce44SJohn Forte ) 2379fcf3ce44SJohn Forte { 2380fcf3ce44SJohn Forte int fd; 2381fcf3ce44SJohn Forte int status; 2382fcf3ce44SJohn Forte iscsi_auth_props_t auth; 2383fcf3ce44SJohn Forte 2384fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2385fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2386fcf3ce44SJohn Forte } 2387fcf3ce44SJohn Forte 2388fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 2389fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 2390fcf3ce44SJohn Forte auth.a_oid = (uint32_t)oid.objectSequenceNumber; 2391fcf3ce44SJohn Forte 2392fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 2393fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2394fcf3ce44SJohn Forte "ISCSI_AUTH_GET failed, errno: %d", errno); 2395fcf3ce44SJohn Forte (void) close(fd); 2396fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2397fcf3ce44SJohn Forte } 2398fcf3ce44SJohn Forte 2399fcf3ce44SJohn Forte if (auth.a_auth_method == authMethodNone) { 2400fcf3ce44SJohn Forte pMethodList[0] = IMA_AUTHMETHOD_NONE; 2401fcf3ce44SJohn Forte *pMethodCount = 1; 2402fcf3ce44SJohn Forte } else { 2403fcf3ce44SJohn Forte int i = 0; 2404fcf3ce44SJohn Forte if (!((auth.a_auth_method & authMethodCHAP)^authMethodCHAP)) { 2405fcf3ce44SJohn Forte pMethodList[i++] = IMA_AUTHMETHOD_CHAP; 2406fcf3ce44SJohn Forte } 2407fcf3ce44SJohn Forte *pMethodCount = i; 2408fcf3ce44SJohn Forte } 2409fcf3ce44SJohn Forte 2410fcf3ce44SJohn Forte (void) close(fd); 2411fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2412fcf3ce44SJohn Forte } 2413fcf3ce44SJohn Forte 2414fcf3ce44SJohn Forte /* Helper function to open driver */ 2415fcf3ce44SJohn Forte int open_driver( 2416fcf3ce44SJohn Forte int *fd 2417fcf3ce44SJohn Forte ) 2418fcf3ce44SJohn Forte { 2419fcf3ce44SJohn Forte int ret = 0; 2420fcf3ce44SJohn Forte if ((*fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 2421fcf3ce44SJohn Forte ret = errno; 2422fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 2423fcf3ce44SJohn Forte ISCSI_DRIVER_DEVCTL, ret); 2424fcf3ce44SJohn Forte } 2425fcf3ce44SJohn Forte return (ret); 2426fcf3ce44SJohn Forte } 2427fcf3ce44SJohn Forte 2428fcf3ce44SJohn Forte /* 2429fcf3ce44SJohn Forte * Iscsi driver does not support OID for discovery address. Create 2430fcf3ce44SJohn Forte * a modified version of IMA_RemoveDiscoveryAddress that takes 2431fcf3ce44SJohn Forte * discoveryAddress (instead of an OID) as input argument. 2432fcf3ce44SJohn Forte */ 2433fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_RemoveDiscoveryAddress( 2434fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS discoveryAddress 2435fcf3ce44SJohn Forte ) 2436fcf3ce44SJohn Forte { 2437fcf3ce44SJohn Forte entry_t entry; 2438fcf3ce44SJohn Forte int fd; 2439fcf3ce44SJohn Forte int status, i, addr_list_size, insize; 2440fcf3ce44SJohn Forte iscsi_addr_list_t *idlp, al_info; 2441fcf3ce44SJohn Forte iscsi_addr_t *matched_addr = NULL; 2442fcf3ce44SJohn Forte 2443fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2444fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2445fcf3ce44SJohn Forte } 2446fcf3ce44SJohn Forte 2447fcf3ce44SJohn Forte if (prepare_discovery_entry(discoveryAddress, &entry) != 2448fcf3ce44SJohn Forte DISC_ADDR_OK) { 2449fcf3ce44SJohn Forte (void) close(fd); 2450fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2451fcf3ce44SJohn Forte } 2452fcf3ce44SJohn Forte 2453fcf3ce44SJohn Forte (void) memset(&al_info, 0, sizeof (al_info)); 2454fcf3ce44SJohn Forte al_info.al_vers = ISCSI_INTERFACE_VERSION; 2455fcf3ce44SJohn Forte al_info.al_in_cnt = 0; 2456fcf3ce44SJohn Forte /* 2457fcf3ce44SJohn Forte * Issue ioctl to get the number of discovery address. 2458fcf3ce44SJohn Forte */ 2459fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 2460fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2461fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 2462fcf3ce44SJohn Forte ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 2463fcf3ce44SJohn Forte (void) close(fd); 2464fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2465fcf3ce44SJohn Forte } 2466fcf3ce44SJohn Forte 2467fcf3ce44SJohn Forte if (al_info.al_out_cnt == 0) { 2468fcf3ce44SJohn Forte (void) close(fd); 2469fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 2470fcf3ce44SJohn Forte } 2471fcf3ce44SJohn Forte 2472fcf3ce44SJohn Forte addr_list_size = sizeof (iscsi_addr_list_t); 2473fcf3ce44SJohn Forte if (al_info.al_out_cnt > 1) { 2474fcf3ce44SJohn Forte addr_list_size += (sizeof (iscsi_addr_t) * 2475fcf3ce44SJohn Forte (al_info.al_out_cnt - 1)); 2476fcf3ce44SJohn Forte } 2477fcf3ce44SJohn Forte 2478fcf3ce44SJohn Forte idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size); 2479fcf3ce44SJohn Forte if (idlp == NULL) { 2480fcf3ce44SJohn Forte (void) close(fd); 2481fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2482fcf3ce44SJohn Forte } 2483fcf3ce44SJohn Forte 2484fcf3ce44SJohn Forte idlp->al_vers = ISCSI_INTERFACE_VERSION; 2485fcf3ce44SJohn Forte idlp->al_in_cnt = al_info.al_out_cnt; 2486fcf3ce44SJohn Forte 2487fcf3ce44SJohn Forte /* issue the same ioctl to get all the discovery addresses */ 2488fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) { 2489fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2490fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 2491fcf3ce44SJohn Forte ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 2492fcf3ce44SJohn Forte free(idlp); 2493fcf3ce44SJohn Forte (void) close(fd); 2494fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2495fcf3ce44SJohn Forte } 2496fcf3ce44SJohn Forte 2497fcf3ce44SJohn Forte /* 2498fcf3ce44SJohn Forte * find the matched discovery address 2499fcf3ce44SJohn Forte */ 2500fcf3ce44SJohn Forte for (i = 0; i < idlp->al_out_cnt; i++) { 2501fcf3ce44SJohn Forte insize = idlp->al_addrs[i].a_addr.i_insize; 2502fcf3ce44SJohn Forte if (insize != entry.e_insize) { 2503fcf3ce44SJohn Forte continue; 2504fcf3ce44SJohn Forte } 2505fcf3ce44SJohn Forte if (insize == sizeof (struct in_addr)) { 2506fcf3ce44SJohn Forte if (idlp->al_addrs[i].a_addr.i_addr.in4.s_addr == 2507fcf3ce44SJohn Forte entry.e_u.u_in4.s_addr) { 2508fcf3ce44SJohn Forte matched_addr = &(idlp->al_addrs[i]); 2509fcf3ce44SJohn Forte break; 2510fcf3ce44SJohn Forte } 2511fcf3ce44SJohn Forte } 2512fcf3ce44SJohn Forte if (insize == sizeof (struct in6_addr)) { 2513fcf3ce44SJohn Forte if (bcmp(entry.e_u.u_in6.s6_addr, 2514fcf3ce44SJohn Forte idlp->al_addrs[i].a_addr.i_addr.in6.s6_addr, 2515fcf3ce44SJohn Forte insize) == 0) { 2516fcf3ce44SJohn Forte matched_addr = &(idlp->al_addrs[i]); 2517fcf3ce44SJohn Forte break; 2518fcf3ce44SJohn Forte } 2519fcf3ce44SJohn Forte } 2520fcf3ce44SJohn Forte } 2521fcf3ce44SJohn Forte 2522fcf3ce44SJohn Forte free(idlp); 2523fcf3ce44SJohn Forte 2524fcf3ce44SJohn Forte if (matched_addr == NULL) { 2525fcf3ce44SJohn Forte (void) close(fd); 2526fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 2527fcf3ce44SJohn Forte } 2528fcf3ce44SJohn Forte 2529fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_CLEAR, &entry)) { 2530fcf3ce44SJohn Forte status = errno; 2531fcf3ce44SJohn Forte (void) close(fd); 2532fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2533fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_CLEAR ioctl failed, errno: %d", 2534fcf3ce44SJohn Forte errno); 2535fcf3ce44SJohn Forte if (status == EBUSY) { 2536fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 2537fcf3ce44SJohn Forte } else { 2538fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2539fcf3ce44SJohn Forte } 2540fcf3ce44SJohn Forte } 2541fcf3ce44SJohn Forte 2542fcf3ce44SJohn Forte (void) close(fd); 2543fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2544fcf3ce44SJohn Forte } 2545fcf3ce44SJohn Forte 2546fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetTargetAuthMethods( 2547fcf3ce44SJohn Forte IMA_OID targetOid, 2548fcf3ce44SJohn Forte IMA_UINT *methodCount, 2549fcf3ce44SJohn Forte const IMA_AUTHMETHOD *pMethodList 2550fcf3ce44SJohn Forte ) 2551fcf3ce44SJohn Forte { 2552fcf3ce44SJohn Forte return (setAuthMethods(targetOid, methodCount, pMethodList)); 2553fcf3ce44SJohn Forte } 2554fcf3ce44SJohn Forte 2555fcf3ce44SJohn Forte IMA_STATUS getNegotiatedDigest( 2556fcf3ce44SJohn Forte int digestType, 2557fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm, 2558fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES *connProps) { 2559fcf3ce44SJohn Forte 2560fcf3ce44SJohn Forte IMA_UINT digest; 2561fcf3ce44SJohn Forte 2562fcf3ce44SJohn Forte if (connProps->valuesValid == IMA_TRUE) { 2563fcf3ce44SJohn Forte algorithm->negotiatedValid = IMA_TRUE; 2564fcf3ce44SJohn Forte 2565fcf3ce44SJohn Forte if (digestType == ISCSI_LOGIN_PARAM_HEADER_DIGEST) { 2566fcf3ce44SJohn Forte digest = connProps->headerDigest; 2567fcf3ce44SJohn Forte } else { 2568fcf3ce44SJohn Forte digest = connProps->dataDigest; 2569fcf3ce44SJohn Forte } 2570fcf3ce44SJohn Forte 2571fcf3ce44SJohn Forte switch (digest) { 2572fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2573fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2574fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2575fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 1; 2576fcf3ce44SJohn Forte break; 2577fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2578fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2579fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2580fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 1; 2581fcf3ce44SJohn Forte break; 2582fcf3ce44SJohn Forte 2583fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2584fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2585fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2586fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[1] = 2587fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2588fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 2; 2589fcf3ce44SJohn Forte break; 2590fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2591fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2592fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2593fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[1] = 2594fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2595fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 2; 2596fcf3ce44SJohn Forte break; 2597fcf3ce44SJohn Forte default: 2598fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2599fcf3ce44SJohn Forte "Invalid negotiated digest: %d", 2600fcf3ce44SJohn Forte digest); 2601fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2602fcf3ce44SJohn Forte } 2603fcf3ce44SJohn Forte } else { 2604fcf3ce44SJohn Forte algorithm->negotiatedValid = IMA_FALSE; 2605fcf3ce44SJohn Forte } 2606fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2607fcf3ce44SJohn Forte } 2608fcf3ce44SJohn Forte 2609fcf3ce44SJohn Forte /* 2610fcf3ce44SJohn Forte * Non-IMA defined function. 2611fcf3ce44SJohn Forte */ 2612fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetISNSServerAddressPropertiesList( 2613fcf3ce44SJohn Forte SUN_IMA_DISC_ADDR_PROP_LIST **ppList 2614fcf3ce44SJohn Forte ) 2615fcf3ce44SJohn Forte { 2616fcf3ce44SJohn Forte char isns_server_addr_str[256]; 2617fcf3ce44SJohn Forte int fd; 2618fcf3ce44SJohn Forte int i; 2619fcf3ce44SJohn Forte int isns_server_addr_list_size; 2620fcf3ce44SJohn Forte int status; 2621fcf3ce44SJohn Forte int out_cnt; 2622fcf3ce44SJohn Forte iscsi_addr_list_t *ialp; 2623fcf3ce44SJohn Forte /* LINTED */ 2624fcf3ce44SJohn Forte IMA_IP_ADDRESS *ipAddr; 2625fcf3ce44SJohn Forte 2626fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2627fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2628fcf3ce44SJohn Forte } 2629fcf3ce44SJohn Forte 2630fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, sizeof (iscsi_addr_list_t)); 2631fcf3ce44SJohn Forte if (ialp == NULL) { 2632fcf3ce44SJohn Forte (void) close(fd); 2633fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2634fcf3ce44SJohn Forte } 2635fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 2636fcf3ce44SJohn Forte ialp->al_in_cnt = ialp->al_out_cnt = 1; 2637fcf3ce44SJohn Forte 2638fcf3ce44SJohn Forte /* 2639fcf3ce44SJohn Forte * Issue ioctl to retrieve the isns server addresses. Space has been 2640fcf3ce44SJohn Forte * allocted for one entry. If more than one entry should be returned, 2641fcf3ce44SJohn Forte * we will re-issue the entry with the right amount of space allocted 2642fcf3ce44SJohn Forte */ 2643fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_LIST_GET, ialp) != 0) { 2644fcf3ce44SJohn Forte (void) close(fd); 2645fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2646fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl failed, errno: %d", 2647fcf3ce44SJohn Forte errno); 2648fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2649fcf3ce44SJohn Forte } 2650fcf3ce44SJohn Forte 2651fcf3ce44SJohn Forte isns_server_addr_list_size = sizeof (iscsi_addr_list_t); 2652fcf3ce44SJohn Forte if (ialp->al_out_cnt > 1) { 2653fcf3ce44SJohn Forte out_cnt = ialp->al_out_cnt; 2654fcf3ce44SJohn Forte free(ialp); 2655fcf3ce44SJohn Forte 2656fcf3ce44SJohn Forte isns_server_addr_list_size += (sizeof (iscsi_addr_t) * 2657fcf3ce44SJohn Forte out_cnt - 1); 2658fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, 2659fcf3ce44SJohn Forte isns_server_addr_list_size); 2660fcf3ce44SJohn Forte if (ialp == NULL) { 2661fcf3ce44SJohn Forte (void) close(fd); 2662fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2663fcf3ce44SJohn Forte } 2664fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 2665fcf3ce44SJohn Forte ialp->al_in_cnt = out_cnt; 2666fcf3ce44SJohn Forte 2667fcf3ce44SJohn Forte /* 2668fcf3ce44SJohn Forte * Issue ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl again to obtain 2669fcf3ce44SJohn Forte * the list of all the iSNS server addresses 2670fcf3ce44SJohn Forte */ 2671fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_LIST_GET, ialp) != 0) { 2672fcf3ce44SJohn Forte free(ialp); 2673fcf3ce44SJohn Forte (void) close(fd); 2674fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2675fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl failed, " 2676fcf3ce44SJohn Forte "errno: %d", errno); 2677fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2678fcf3ce44SJohn Forte 2679fcf3ce44SJohn Forte } 2680fcf3ce44SJohn Forte } 2681fcf3ce44SJohn Forte 2682fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *)calloc(1, 2683fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) + 2684fcf3ce44SJohn Forte ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES)); 2685fcf3ce44SJohn Forte if (*ppList == NULL) { 2686fcf3ce44SJohn Forte free(ialp); 2687fcf3ce44SJohn Forte (void) close(fd); 2688fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2689fcf3ce44SJohn Forte } 2690fcf3ce44SJohn Forte (*ppList)->discAddrCount = ialp->al_out_cnt; 2691fcf3ce44SJohn Forte 2692fcf3ce44SJohn Forte for (i = 0; i < ialp->al_out_cnt; i++) { 2693fcf3ce44SJohn Forte if (ialp->al_addrs[i].a_addr.i_insize == 2694fcf3ce44SJohn Forte sizeof (struct in_addr)) { 2695fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 2696fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_TRUE; 2697fcf3ce44SJohn Forte } else if (ialp->al_addrs[i].a_addr.i_insize == 2698fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 2699fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 2700fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_FALSE; 2701fcf3ce44SJohn Forte } else { 2702fcf3ce44SJohn Forte (void) strlcpy(isns_server_addr_str, "unknown", 2703fcf3ce44SJohn Forte sizeof (isns_server_addr_str)); 2704fcf3ce44SJohn Forte } 2705fcf3ce44SJohn Forte 2706fcf3ce44SJohn Forte ipAddr = &(*ppList)->props[i].discoveryAddress. 2707fcf3ce44SJohn Forte hostnameIpAddress.id.ipAddress; 2708fcf3ce44SJohn Forte bcopy(&ialp->al_addrs[i].a_addr.i_addr, 2709fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress.id. 2710fcf3ce44SJohn Forte ipAddress.ipAddress, 2711fcf3ce44SJohn Forte sizeof (ipAddr->ipAddress)); 2712fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.portNumber = 2713fcf3ce44SJohn Forte ialp->al_addrs[i].a_port; 2714fcf3ce44SJohn Forte } 2715fcf3ce44SJohn Forte 2716fcf3ce44SJohn Forte free(ialp); 2717fcf3ce44SJohn Forte (void) close(fd); 2718fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2719fcf3ce44SJohn Forte } 2720fcf3ce44SJohn Forte 2721fcf3ce44SJohn Forte /*ARGSUSED*/ 2722fcf3ce44SJohn Forte /* 2723fcf3ce44SJohn Forte * Remove iSNS Server Address 2724fcf3ce44SJohn Forte */ 2725fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_RemoveISNSServerAddress( 2726fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS isnsServerAddress 2727fcf3ce44SJohn Forte ) 2728fcf3ce44SJohn Forte { 2729fcf3ce44SJohn Forte entry_t entry; 2730fcf3ce44SJohn Forte int fd, status; 2731fcf3ce44SJohn Forte 2732fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2733fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2734fcf3ce44SJohn Forte } 2735fcf3ce44SJohn Forte 2736fcf3ce44SJohn Forte if (prepare_discovery_entry(isnsServerAddress, &entry) != 2737fcf3ce44SJohn Forte DISC_ADDR_OK) { 2738fcf3ce44SJohn Forte (void) close(fd); 2739fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2740fcf3ce44SJohn Forte } 2741fcf3ce44SJohn Forte 2742fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_CLEAR, &entry)) { 2743fcf3ce44SJohn Forte status = errno; 2744fcf3ce44SJohn Forte (void) close(fd); 2745fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2746fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_CLEAR ioctl failed, errno: %d", 2747fcf3ce44SJohn Forte status); 2748fcf3ce44SJohn Forte if (status == EBUSY) { 2749fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 2750fcf3ce44SJohn Forte } else { 2751fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2752fcf3ce44SJohn Forte } 2753fcf3ce44SJohn Forte } 2754fcf3ce44SJohn Forte 2755fcf3ce44SJohn Forte (void) close(fd); 2756fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2757fcf3ce44SJohn Forte } 2758fcf3ce44SJohn Forte 2759fcf3ce44SJohn Forte /*ARGSUSED*/ 2760fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_AddISNSServerAddress( 2761fcf3ce44SJohn Forte const SUN_IMA_TARGET_ADDRESS isnsServerAddress 2762fcf3ce44SJohn Forte ) 2763fcf3ce44SJohn Forte { 2764fcf3ce44SJohn Forte entry_t entry; 2765fcf3ce44SJohn Forte int fd; 2766fcf3ce44SJohn Forte int status; 2767fcf3ce44SJohn Forte 2768fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2769fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2770fcf3ce44SJohn Forte } 2771fcf3ce44SJohn Forte 2772fcf3ce44SJohn Forte if (prepare_discovery_entry(isnsServerAddress, &entry) != 2773fcf3ce44SJohn Forte DISC_ADDR_OK) { 2774fcf3ce44SJohn Forte (void) close(fd); 2775fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2776fcf3ce44SJohn Forte } 2777fcf3ce44SJohn Forte 2778fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_SET, &entry)) { 2779fcf3ce44SJohn Forte /* 2780fcf3ce44SJohn Forte * Encountered problem setting the discovery address. 2781fcf3ce44SJohn Forte */ 2782fcf3ce44SJohn Forte (void) close(fd); 2783fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2784fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_SET ioctl failed, errno: %d", 2785fcf3ce44SJohn Forte errno); 2786fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2787fcf3ce44SJohn Forte } 2788fcf3ce44SJohn Forte 2789fcf3ce44SJohn Forte (void) close(fd); 2790fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2791fcf3ce44SJohn Forte } 2792fcf3ce44SJohn Forte 2793fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_RetrieveISNSServerTargets( 2794fcf3ce44SJohn Forte IMA_TARGET_ADDRESS serverAddress, 2795fcf3ce44SJohn Forte SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList 2796fcf3ce44SJohn Forte ) 2797fcf3ce44SJohn Forte { 2798fcf3ce44SJohn Forte int fd; 2799fcf3ce44SJohn Forte int ctr; 2800fcf3ce44SJohn Forte int server_pg_list_sz; 2801fcf3ce44SJohn Forte int status; 2802fcf3ce44SJohn Forte isns_server_portal_group_list_t *server_pg_list = NULL; 2803fcf3ce44SJohn Forte isns_portal_group_list_t *pg_list = NULL; 2804fcf3ce44SJohn Forte IMA_BOOL retry = IMA_TRUE; 2805fcf3ce44SJohn Forte entry_t entry; 2806fcf3ce44SJohn Forte 2807fcf3ce44SJohn Forte #define ISNS_SERVER_DEFAULT_NUM_TARGETS 50 2808fcf3ce44SJohn Forte 2809fcf3ce44SJohn Forte server_pg_list_sz = sizeof (*server_pg_list) + 2810fcf3ce44SJohn Forte ((ISNS_SERVER_DEFAULT_NUM_TARGETS - 1) * 2811fcf3ce44SJohn Forte sizeof (isns_portal_group_t)); 2812fcf3ce44SJohn Forte 2813fcf3ce44SJohn Forte server_pg_list = (isns_server_portal_group_list_t *)calloc(1, 2814fcf3ce44SJohn Forte server_pg_list_sz); 2815fcf3ce44SJohn Forte if (server_pg_list == NULL) { 2816fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2817fcf3ce44SJohn Forte } 2818fcf3ce44SJohn Forte server_pg_list->addr_port_list.pg_in_cnt = 2819fcf3ce44SJohn Forte ISNS_SERVER_DEFAULT_NUM_TARGETS; 2820fcf3ce44SJohn Forte 2821fcf3ce44SJohn Forte if ((prepare_discovery_entry_IMA(serverAddress, &entry) 2822fcf3ce44SJohn Forte != DISC_ADDR_OK)) { 2823fcf3ce44SJohn Forte free(server_pg_list); 2824fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2825fcf3ce44SJohn Forte } 2826fcf3ce44SJohn Forte server_pg_list->addr.a_port = entry.e_port; 2827fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_insize = entry.e_insize; 2828fcf3ce44SJohn Forte if (entry.e_insize == sizeof (struct in_addr)) { 2829fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_addr.in4.s_addr = 2830fcf3ce44SJohn Forte (entry.e_u.u_in4.s_addr); 2831fcf3ce44SJohn Forte } else if (entry.e_insize == sizeof (struct in6_addr)) { 2832fcf3ce44SJohn Forte bcopy(&entry.e_u.u_in6.s6_addr, 2833fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_addr.in6.s6_addr, 16); 2834fcf3ce44SJohn Forte } 2835fcf3ce44SJohn Forte 2836fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2837fcf3ce44SJohn Forte free(server_pg_list); 2838fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2839fcf3ce44SJohn Forte } 2840fcf3ce44SJohn Forte 2841fcf3ce44SJohn Forte retry_isns: 2842fcf3ce44SJohn Forte /* 2843fcf3ce44SJohn Forte * Issue ioctl to obtain the ISNS Portal Group List list 2844fcf3ce44SJohn Forte */ 2845fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_GET, server_pg_list) != 0) { 2846fcf3ce44SJohn Forte int tmp_errno = errno; 2847fcf3ce44SJohn Forte IMA_STATUS return_status; 2848fcf3ce44SJohn Forte 2849fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2850fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_GET ioctl failed, errno: %d", tmp_errno); 2851fcf3ce44SJohn Forte if (tmp_errno == EACCES) { 2852fcf3ce44SJohn Forte return_status = IMA_ERROR_OBJECT_NOT_FOUND; 2853fcf3ce44SJohn Forte } else { 2854fcf3ce44SJohn Forte return_status = IMA_ERROR_UNEXPECTED_OS_ERROR; 2855fcf3ce44SJohn Forte } 2856fcf3ce44SJohn Forte (void) close(fd); 2857fcf3ce44SJohn Forte free(server_pg_list); 2858fcf3ce44SJohn Forte return (return_status); 2859fcf3ce44SJohn Forte } 2860fcf3ce44SJohn Forte pg_list = &server_pg_list->addr_port_list; 2861fcf3ce44SJohn Forte 2862fcf3ce44SJohn Forte /* check if all targets received */ 2863fcf3ce44SJohn Forte if (pg_list->pg_in_cnt < pg_list->pg_out_cnt) { 2864fcf3ce44SJohn Forte if (retry == IMA_TRUE) { 2865fcf3ce44SJohn Forte server_pg_list_sz = sizeof (*server_pg_list) + 2866fcf3ce44SJohn Forte ((pg_list->pg_out_cnt - 1) * 2867fcf3ce44SJohn Forte sizeof (isns_server_portal_group_list_t)); 2868fcf3ce44SJohn Forte server_pg_list = (isns_server_portal_group_list_t *) 2869fcf3ce44SJohn Forte realloc(server_pg_list, server_pg_list_sz); 2870fcf3ce44SJohn Forte if (server_pg_list == NULL) { 2871fcf3ce44SJohn Forte (void) close(fd); 2872fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2873fcf3ce44SJohn Forte } 2874fcf3ce44SJohn Forte pg_list = &server_pg_list->addr_port_list; 2875fcf3ce44SJohn Forte pg_list->pg_in_cnt = pg_list->pg_out_cnt; 2876fcf3ce44SJohn Forte retry = IMA_FALSE; 2877fcf3ce44SJohn Forte goto retry_isns; 2878fcf3ce44SJohn Forte } else { 2879fcf3ce44SJohn Forte /* 2880fcf3ce44SJohn Forte * don't retry after 2 attempts. The target list 2881fcf3ce44SJohn Forte * shouldn't continue growing. Just continue 2882fcf3ce44SJohn Forte * on and display what was found. 2883fcf3ce44SJohn Forte */ 2884fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2885fcf3ce44SJohn Forte "ISCSI_SENDTGTS_GET overflow: " 2886fcf3ce44SJohn Forte "failed to obtain all targets"); 2887fcf3ce44SJohn Forte pg_list->pg_out_cnt = pg_list->pg_in_cnt; 2888fcf3ce44SJohn Forte } 2889fcf3ce44SJohn Forte } 2890fcf3ce44SJohn Forte 2891fcf3ce44SJohn Forte (void) close(fd); 2892fcf3ce44SJohn Forte 2893fcf3ce44SJohn Forte /* allocate for caller return buffer */ 2894fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1, 2895fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) + 2896fcf3ce44SJohn Forte pg_list->pg_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY)); 2897fcf3ce44SJohn Forte if (*ppList == NULL) { 2898fcf3ce44SJohn Forte free(server_pg_list); 2899fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2900fcf3ce44SJohn Forte } 2901fcf3ce44SJohn Forte 2902fcf3ce44SJohn Forte (*ppList)->keyCount = pg_list->pg_out_cnt; 2903fcf3ce44SJohn Forte 2904fcf3ce44SJohn Forte for (ctr = 0; ctr < pg_list->pg_out_cnt; ctr++) { 2905fcf3ce44SJohn Forte (void) mbstowcs((*ppList)->keys[ctr].name, 2906fcf3ce44SJohn Forte (char *)pg_list->pg_list[ctr].pg_iscsi_name, 2907fcf3ce44SJohn Forte IMA_NODE_NAME_LEN); 2908fcf3ce44SJohn Forte 2909fcf3ce44SJohn Forte (*ppList)->keys[ctr].tpgt = pg_list->pg_list[ctr].pg_tag; 2910fcf3ce44SJohn Forte 2911fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.portNumber = 2912fcf3ce44SJohn Forte pg_list->pg_list[ctr].pg_port; 2913fcf3ce44SJohn Forte 2914fcf3ce44SJohn Forte if (pg_list->pg_list[ctr].insize == sizeof (struct in_addr)) { 2915fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 2916fcf3ce44SJohn Forte IMA_TRUE; 2917fcf3ce44SJohn Forte } else if (pg_list->pg_list[ctr].insize == 2918fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 2919fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 2920fcf3ce44SJohn Forte IMA_FALSE; 2921fcf3ce44SJohn Forte } else { 2922fcf3ce44SJohn Forte free(pg_list); 2923fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2924fcf3ce44SJohn Forte } 2925fcf3ce44SJohn Forte 2926fcf3ce44SJohn Forte (void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress, 2927fcf3ce44SJohn Forte &(pg_list->pg_list[ctr].pg_ip_addr), 2928fcf3ce44SJohn Forte pg_list->pg_list[ctr].insize); 2929fcf3ce44SJohn Forte } 2930fcf3ce44SJohn Forte free(server_pg_list); 2931fcf3ce44SJohn Forte 2932fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2933fcf3ce44SJohn Forte } 2934fcf3ce44SJohn Forte 2935fcf3ce44SJohn Forte /* ARGSUSED */ 2936fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetSessionOidList( 2937fcf3ce44SJohn Forte IMA_OID initiatorOid, 2938fcf3ce44SJohn Forte IMA_OID_LIST **ppList 2939fcf3ce44SJohn Forte ) 2940fcf3ce44SJohn Forte { 2941fcf3ce44SJohn Forte return (get_target_oid_list(ISCSI_TGT_OID_LIST, ppList)); 2942fcf3ce44SJohn Forte } 2943fcf3ce44SJohn Forte 2944fcf3ce44SJohn Forte /*ARGSUSED*/ 2945fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetTargetAuthParms( 2946fcf3ce44SJohn Forte IMA_OID oid, 2947fcf3ce44SJohn Forte IMA_AUTHMETHOD method, 2948fcf3ce44SJohn Forte IMA_INITIATOR_AUTHPARMS *pParms 2949fcf3ce44SJohn Forte ) 2950fcf3ce44SJohn Forte { 2951fcf3ce44SJohn Forte int fd; 2952fcf3ce44SJohn Forte iscsi_chap_props_t chap_p; 2953fcf3ce44SJohn Forte 2954fcf3ce44SJohn Forte if (pParms == NULL) { 2955fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2956fcf3ce44SJohn Forte } 2957fcf3ce44SJohn Forte 2958fcf3ce44SJohn Forte if (oid.objectType != IMA_OBJECT_TYPE_TARGET) { 2959fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 2960fcf3ce44SJohn Forte } 2961fcf3ce44SJohn Forte 2962fcf3ce44SJohn Forte if (method != IMA_AUTHMETHOD_CHAP) { 2963fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2964fcf3ce44SJohn Forte } 2965fcf3ce44SJohn Forte 2966fcf3ce44SJohn Forte if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 2967fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 2968fcf3ce44SJohn Forte ISCSI_DRIVER_DEVCTL, errno); 2969fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2970fcf3ce44SJohn Forte } 2971fcf3ce44SJohn Forte 2972fcf3ce44SJohn Forte (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 2973fcf3ce44SJohn Forte chap_p.c_vers = ISCSI_INTERFACE_VERSION; 2974fcf3ce44SJohn Forte chap_p.c_oid = (uint32_t)oid.objectSequenceNumber; 2975fcf3ce44SJohn Forte 2976fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CHAP_GET, &chap_p) != 0) { 2977fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2978fcf3ce44SJohn Forte 2979fcf3ce44SJohn Forte "ISCSI_CHAP_GET ioctl failed, errno: %d", 2980fcf3ce44SJohn Forte errno); 2981fcf3ce44SJohn Forte (void) close(fd); 2982fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2983fcf3ce44SJohn Forte } 2984fcf3ce44SJohn Forte 2985fcf3ce44SJohn Forte (void) memcpy(pParms->chapParms.name, chap_p.c_user, 2986fcf3ce44SJohn Forte chap_p.c_user_len); 2987fcf3ce44SJohn Forte 2988fcf3ce44SJohn Forte pParms->chapParms.nameLength = chap_p.c_user_len; 2989fcf3ce44SJohn Forte (void) memcpy(pParms->chapParms.challengeSecret, chap_p.c_secret, 2990fcf3ce44SJohn Forte chap_p.c_secret_len); 2991fcf3ce44SJohn Forte 2992fcf3ce44SJohn Forte pParms->chapParms.challengeSecretLength = chap_p.c_secret_len; 2993fcf3ce44SJohn Forte 2994fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2995fcf3ce44SJohn Forte } 2996*6cefaae1SJack Meng 2997*6cefaae1SJack Meng IMA_API IMA_STATUS SUN_IMA_GetBootTargetName( 2998*6cefaae1SJack Meng IMA_NODE_NAME tgtName 2999*6cefaae1SJack Meng ) 3000*6cefaae1SJack Meng { 3001*6cefaae1SJack Meng int fd; 3002*6cefaae1SJack Meng IMA_STATUS rtn; 3003*6cefaae1SJack Meng iscsi_boot_property_t bootProp; 3004*6cefaae1SJack Meng 3005*6cefaae1SJack Meng bootProp.tgt_name.n_name[0] = '\0'; 3006*6cefaae1SJack Meng bootProp.tgt_chap.c_user[0] = '\0'; 3007*6cefaae1SJack Meng tgtName[0] = L'\0'; 3008*6cefaae1SJack Meng rtn = IMA_ERROR_UNEXPECTED_OS_ERROR; 3009*6cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3010*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 3011*6cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 3012*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3013*6cefaae1SJack Meng } 3014*6cefaae1SJack Meng 3015*6cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 3016*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 3017*6cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 3018*6cefaae1SJack Meng errno); 3019*6cefaae1SJack Meng (void) close(fd); 3020*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3021*6cefaae1SJack Meng } 3022*6cefaae1SJack Meng 3023*6cefaae1SJack Meng if ((bootProp.tgt_name.n_name[0] != '\0') && (tgtName != NULL)) { 3024*6cefaae1SJack Meng if (mbstowcs(tgtName, (const char *)bootProp.tgt_name.n_name, 3025*6cefaae1SJack Meng IMA_NODE_NAME_LEN) == (size_t)-1) { 3026*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 3027*6cefaae1SJack Meng "ISCSI Target name covert to WCHAR fail"); 3028*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3029*6cefaae1SJack Meng } else { 3030*6cefaae1SJack Meng rtn = IMA_STATUS_SUCCESS; 3031*6cefaae1SJack Meng } 3032*6cefaae1SJack Meng } 3033*6cefaae1SJack Meng 3034*6cefaae1SJack Meng return (rtn); 3035*6cefaae1SJack Meng } 3036*6cefaae1SJack Meng 3037*6cefaae1SJack Meng IMA_API IMA_STATUS SUN_IMA_GetBootTargetAuthParams( 3038*6cefaae1SJack Meng IMA_INITIATOR_AUTHPARMS *pTgtCHAP 3039*6cefaae1SJack Meng ) 3040*6cefaae1SJack Meng { 3041*6cefaae1SJack Meng int fd; 3042*6cefaae1SJack Meng IMA_STATUS rtn; 3043*6cefaae1SJack Meng iscsi_boot_property_t bootProp; 3044*6cefaae1SJack Meng 3045*6cefaae1SJack Meng bootProp.tgt_name.n_name[0] = '\0'; 3046*6cefaae1SJack Meng bootProp.tgt_chap.c_user[0] = '\0'; 3047*6cefaae1SJack Meng bootProp.tgt_chap.c_secret[0] = '\0'; 3048*6cefaae1SJack Meng rtn = IMA_ERROR_UNEXPECTED_OS_ERROR; 3049*6cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3050*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 3051*6cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 3052*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3053*6cefaae1SJack Meng } 3054*6cefaae1SJack Meng 3055*6cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 3056*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 3057*6cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 3058*6cefaae1SJack Meng errno); 3059*6cefaae1SJack Meng (void) close(fd); 3060*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3061*6cefaae1SJack Meng } 3062*6cefaae1SJack Meng 3063*6cefaae1SJack Meng if (pTgtCHAP != NULL) { 3064*6cefaae1SJack Meng if (bootProp.tgt_chap.c_user[0] != '\0') { 3065*6cefaae1SJack Meng (void) memcpy(pTgtCHAP->chapParms.name, 3066*6cefaae1SJack Meng bootProp.tgt_chap.c_user, ISCSI_MAX_NAME_LEN); 3067*6cefaae1SJack Meng } else { 3068*6cefaae1SJack Meng pTgtCHAP->chapParms.name[0] = '\0'; 3069*6cefaae1SJack Meng } 3070*6cefaae1SJack Meng if (bootProp.tgt_chap.c_secret[0] != '\0') { 3071*6cefaae1SJack Meng (void) memcpy(pTgtCHAP->chapParms.challengeSecret, 3072*6cefaae1SJack Meng bootProp.tgt_chap.c_secret, MAX_CHAP_SECRET_LEN); 3073*6cefaae1SJack Meng } else { 3074*6cefaae1SJack Meng pTgtCHAP->chapParms.challengeSecret[0] = '\0'; 3075*6cefaae1SJack Meng } 3076*6cefaae1SJack Meng rtn = IMA_STATUS_SUCCESS; 3077*6cefaae1SJack Meng } 3078*6cefaae1SJack Meng return (rtn); 3079*6cefaae1SJack Meng } 3080*6cefaae1SJack Meng 3081*6cefaae1SJack Meng IMA_STATUS SUN_IMA_GetBootMpxio( 3082*6cefaae1SJack Meng IMA_BOOL *pMpxioEnabled 3083*6cefaae1SJack Meng ) 3084*6cefaae1SJack Meng { 3085*6cefaae1SJack Meng int fd; 3086*6cefaae1SJack Meng iscsi_boot_property_t bootProp; 3087*6cefaae1SJack Meng 3088*6cefaae1SJack Meng bootProp.hba_mpxio_enabled = B_FALSE; 3089*6cefaae1SJack Meng *pMpxioEnabled = IMA_UNKNOWN; 3090*6cefaae1SJack Meng 3091*6cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3092*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 3093*6cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 3094*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3095*6cefaae1SJack Meng } 3096*6cefaae1SJack Meng 3097*6cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 3098*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 3099*6cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 3100*6cefaae1SJack Meng errno); 3101*6cefaae1SJack Meng (void) close(fd); 3102*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3103*6cefaae1SJack Meng } 3104*6cefaae1SJack Meng 3105*6cefaae1SJack Meng if (bootProp.hba_mpxio_enabled) { 3106*6cefaae1SJack Meng *pMpxioEnabled = IMA_TRUE; 3107*6cefaae1SJack Meng } else { 3108*6cefaae1SJack Meng *pMpxioEnabled = IMA_FALSE; 3109*6cefaae1SJack Meng } 3110*6cefaae1SJack Meng 3111*6cefaae1SJack Meng (void) close(fd); 3112*6cefaae1SJack Meng return (IMA_STATUS_SUCCESS); 3113*6cefaae1SJack Meng } 3114*6cefaae1SJack Meng 3115*6cefaae1SJack Meng IMA_STATUS SUN_IMA_GetBootIscsi( 3116*6cefaae1SJack Meng IMA_BOOL *pIscsiBoot 3117*6cefaae1SJack Meng ) 3118*6cefaae1SJack Meng { 3119*6cefaae1SJack Meng int fd; 3120*6cefaae1SJack Meng iscsi_boot_property_t bootProp; 3121*6cefaae1SJack Meng 3122*6cefaae1SJack Meng bootProp.iscsiboot = 0; 3123*6cefaae1SJack Meng *pIscsiBoot = 0; 3124*6cefaae1SJack Meng 3125*6cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3126*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 3127*6cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 3128*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3129*6cefaae1SJack Meng } 3130*6cefaae1SJack Meng 3131*6cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 3132*6cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 3133*6cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 3134*6cefaae1SJack Meng errno); 3135*6cefaae1SJack Meng (void) close(fd); 3136*6cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3137*6cefaae1SJack Meng } 3138*6cefaae1SJack Meng 3139*6cefaae1SJack Meng *pIscsiBoot = bootProp.iscsiboot; 3140*6cefaae1SJack Meng 3141*6cefaae1SJack Meng (void) close(fd); 3142*6cefaae1SJack Meng return (IMA_STATUS_SUCCESS); 3143*6cefaae1SJack Meng } 3144