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 /* 22*904e51f6SJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23fcf3ce44SJohn Forte */ 24fcf3ce44SJohn Forte 25fcf3ce44SJohn Forte #include <arpa/inet.h> 26fcf3ce44SJohn Forte #include <sys/socket.h> 27fcf3ce44SJohn Forte #include <sys/types.h> 28fcf3ce44SJohn Forte #include <stdarg.h> 29fcf3ce44SJohn Forte #include <stdlib.h> 30fcf3ce44SJohn Forte #include <string.h> 31fcf3ce44SJohn Forte #include <strings.h> 32fcf3ce44SJohn Forte #include <unistd.h> 33fcf3ce44SJohn Forte #include <syslog.h> 34fcf3ce44SJohn Forte #include <errno.h> 35fcf3ce44SJohn Forte 36fcf3ce44SJohn Forte #include <fcntl.h> 37fcf3ce44SJohn Forte #include <stdio.h> 38fcf3ce44SJohn Forte #include <time.h> 39fcf3ce44SJohn Forte #include <libdevinfo.h> 40fcf3ce44SJohn Forte 41fcf3ce44SJohn Forte #include <sys/scsi/adapters/iscsi_if.h> 424246c8e9SJack Meng #include <sys/scsi/adapters/iscsi_door.h> 431a1a84a3SPeter Dunlap #include <sys/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 536cefaae1SJack 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 1161f6352c6Syi zhang - Sun Microsystems - Beijing China static int get_lun_devlink(di_devlink_t link, void *arg); 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 1075b4243054SSheng-Liang Eric Zhang /* 1076b4243054SSheng-Liang Eric Zhang * Issue ISCSI_AUTH_CLEAR ioctl, in which the authentication information 1077b4243054SSheng-Liang Eric Zhang * is removed and the target that is not discovered by initiator 1078b4243054SSheng-Liang Eric Zhang * is removed from the memory. So this ioctl should be called at last 1079b4243054SSheng-Liang Eric Zhang */ 1080fcf3ce44SJohn Forte (void) memset(&auth_p, 0, sizeof (iscsi_auth_props_t)); 1081fcf3ce44SJohn Forte auth_p.a_vers = ISCSI_INTERFACE_VERSION; 1082fcf3ce44SJohn Forte auth_p.a_oid = (uint32_t)targetOid.objectSequenceNumber; 1083fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_CLEAR, &auth_p) != 0) { 1084fcf3ce44SJohn Forte /* 1085fcf3ce44SJohn Forte * It could be that the auth data of this target has 1086fcf3ce44SJohn Forte * never been set. 1087fcf3ce44SJohn Forte */ 1088fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1089fcf3ce44SJohn Forte "ISCSI_AUTH_CLEAR ioctl failed, errno: %d", errno); 1090fcf3ce44SJohn Forte } 1091fcf3ce44SJohn Forte 1092fcf3ce44SJohn Forte (void) close(fd); 1093fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1094fcf3ce44SJohn Forte } 1095fcf3ce44SJohn Forte 1096fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetHeaderDigest( 1097fcf3ce44SJohn Forte IMA_OID oid, 1098fcf3ce44SJohn Forte IMA_UINT algorithmCount, 1099fcf3ce44SJohn Forte const SUN_IMA_DIGEST_ALGORITHM *algorithmList 1100fcf3ce44SJohn Forte ) 1101fcf3ce44SJohn Forte { 1102fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE mv; 1103fcf3ce44SJohn Forte uint32_t digest_algorithm; 1104fcf3ce44SJohn Forte 1105fcf3ce44SJohn Forte /* We only support one preference of digest algorithm. */ 1106fcf3ce44SJohn Forte if (algorithmCount > 1) { 1107fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1108fcf3ce44SJohn Forte "More than one digest algorithm specified."); 1109fcf3ce44SJohn Forte return (IMA_ERROR_NOT_SUPPORTED); 1110fcf3ce44SJohn Forte } 1111fcf3ce44SJohn Forte switch (algorithmList[0]) { 1112fcf3ce44SJohn Forte case SUN_IMA_DIGEST_NONE: 1113fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1114fcf3ce44SJohn Forte break; 1115fcf3ce44SJohn Forte case SUN_IMA_DIGEST_CRC32: 1116fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_CRC32C; 1117fcf3ce44SJohn Forte break; 1118fcf3ce44SJohn Forte default: 1119fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1120fcf3ce44SJohn Forte break; 1121fcf3ce44SJohn Forte } 1122fcf3ce44SJohn Forte mv.currentValue = digest_algorithm; 1123fcf3ce44SJohn Forte return (setISCSINodeParameter(MIN_MAX_PARAM, &oid, &mv, 1124fcf3ce44SJohn Forte ISCSI_LOGIN_PARAM_HEADER_DIGEST)); 1125fcf3ce44SJohn Forte } 1126fcf3ce44SJohn Forte 1127fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetDataDigest( 1128fcf3ce44SJohn Forte IMA_OID oid, 1129fcf3ce44SJohn Forte IMA_UINT algorithmCount, 1130fcf3ce44SJohn Forte const SUN_IMA_DIGEST_ALGORITHM *algorithmList 1131fcf3ce44SJohn Forte ) 1132fcf3ce44SJohn Forte { 1133fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE mv; 1134fcf3ce44SJohn Forte uint32_t digest_algorithm; 1135fcf3ce44SJohn Forte 1136fcf3ce44SJohn Forte /* We only support one preference of digest algorithm. */ 1137fcf3ce44SJohn Forte if (algorithmCount > 1) { 1138fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1139fcf3ce44SJohn Forte "More than one digest algorithm specified."); 1140fcf3ce44SJohn Forte return (IMA_ERROR_NOT_SUPPORTED); 1141fcf3ce44SJohn Forte } 1142fcf3ce44SJohn Forte switch (algorithmList[0]) { 1143fcf3ce44SJohn Forte case SUN_IMA_DIGEST_NONE: 1144fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1145fcf3ce44SJohn Forte break; 1146fcf3ce44SJohn Forte case SUN_IMA_DIGEST_CRC32: 1147fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_CRC32C; 1148fcf3ce44SJohn Forte break; 1149fcf3ce44SJohn Forte default: 1150fcf3ce44SJohn Forte digest_algorithm = ISCSI_DIGEST_NONE; 1151fcf3ce44SJohn Forte break; 1152fcf3ce44SJohn Forte } 1153fcf3ce44SJohn Forte mv.currentValue = digest_algorithm; 1154fcf3ce44SJohn Forte return (setISCSINodeParameter(MIN_MAX_PARAM, &oid, &mv, 1155fcf3ce44SJohn Forte ISCSI_LOGIN_PARAM_DATA_DIGEST)); 1156fcf3ce44SJohn Forte } 1157fcf3ce44SJohn Forte 1158fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetHeaderDigest( 1159fcf3ce44SJohn Forte IMA_OID oid, 1160fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 1161fcf3ce44SJohn Forte ) 1162fcf3ce44SJohn Forte { 1163fcf3ce44SJohn Forte return (getDigest(oid, ISCSI_LOGIN_PARAM_HEADER_DIGEST, algorithm)); 1164fcf3ce44SJohn Forte } 1165fcf3ce44SJohn Forte 1166fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetDataDigest( 1167fcf3ce44SJohn Forte IMA_OID oid, 1168fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 1169fcf3ce44SJohn Forte ) 1170fcf3ce44SJohn Forte { 1171fcf3ce44SJohn Forte return (getDigest(oid, ISCSI_LOGIN_PARAM_DATA_DIGEST, algorithm)); 1172fcf3ce44SJohn Forte } 1173fcf3ce44SJohn Forte 11741f6352c6Syi zhang - Sun Microsystems - Beijing China typedef struct walk_devlink { 11751f6352c6Syi zhang - Sun Microsystems - Beijing China char *path; 11761f6352c6Syi zhang - Sun Microsystems - Beijing China size_t len; 11771f6352c6Syi zhang - Sun Microsystems - Beijing China char **linkpp; 11781f6352c6Syi zhang - Sun Microsystems - Beijing China } walk_devlink_t; 11791f6352c6Syi zhang - Sun Microsystems - Beijing China 1180fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetLuProperties( 1181fcf3ce44SJohn Forte IMA_OID luId, 1182fcf3ce44SJohn Forte SUN_IMA_LU_PROPERTIES *pProps 1183fcf3ce44SJohn Forte ) 1184fcf3ce44SJohn Forte { 1185fcf3ce44SJohn Forte IMA_STATUS status; 1186fcf3ce44SJohn Forte iscsi_lun_list_t *pLunList; 1187fcf3ce44SJohn Forte int j; 1188fcf3ce44SJohn Forte IMA_BOOL lunMatch = IMA_FALSE; 1189fcf3ce44SJohn Forte int fd; 1190fcf3ce44SJohn Forte int openStatus; 1191fcf3ce44SJohn Forte iscsi_lun_props_t lun; 1192fcf3ce44SJohn Forte di_devlink_handle_t hdl; 11931f6352c6Syi zhang - Sun Microsystems - Beijing China walk_devlink_t warg; 11941f6352c6Syi zhang - Sun Microsystems - Beijing China char *minor_path, *devlinkp, lunpath[MAXPATHLEN]; 1195fcf3ce44SJohn Forte 1196fcf3ce44SJohn Forte if (luId.objectType != IMA_OBJECT_TYPE_LU) { 1197fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 1198fcf3ce44SJohn Forte } 1199fcf3ce44SJohn Forte 1200fcf3ce44SJohn Forte /* 1201fcf3ce44SJohn Forte * get list of lun oids for all targets 1202fcf3ce44SJohn Forte */ 1203fcf3ce44SJohn Forte status = get_target_lun_oid_list(NULL, &pLunList); 1204fcf3ce44SJohn Forte if (!IMA_SUCCESS(status)) { 1205fcf3ce44SJohn Forte return (status); 1206fcf3ce44SJohn Forte } 1207fcf3ce44SJohn Forte for (j = 0; j < pLunList->ll_out_cnt; j++) { 1208fcf3ce44SJohn Forte /* 1209fcf3ce44SJohn Forte * for each lun, check if match is found 1210fcf3ce44SJohn Forte */ 1211fcf3ce44SJohn Forte if (pLunList->ll_luns[j].l_oid == luId.objectSequenceNumber) { 1212fcf3ce44SJohn Forte /* 1213fcf3ce44SJohn Forte * match found, break out of lun loop 1214fcf3ce44SJohn Forte */ 1215fcf3ce44SJohn Forte lunMatch = IMA_TRUE; 1216fcf3ce44SJohn Forte break; 1217fcf3ce44SJohn Forte } 1218fcf3ce44SJohn Forte } 1219fcf3ce44SJohn Forte 1220fcf3ce44SJohn Forte if (lunMatch == IMA_TRUE) { 1221fcf3ce44SJohn Forte (void) memset(&lun, 0, sizeof (iscsi_lun_props_t)); 1222fcf3ce44SJohn Forte lun.lp_vers = ISCSI_INTERFACE_VERSION; 1223fcf3ce44SJohn Forte lun.lp_tgt_oid = pLunList->ll_luns[j].l_tgt_oid; 1224fcf3ce44SJohn Forte lun.lp_oid = pLunList->ll_luns[j].l_oid; 1225fcf3ce44SJohn Forte } 1226fcf3ce44SJohn Forte 1227fcf3ce44SJohn Forte free(pLunList); 1228fcf3ce44SJohn Forte 1229fcf3ce44SJohn Forte if (lunMatch == IMA_FALSE) { 1230fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 1231fcf3ce44SJohn Forte } 1232fcf3ce44SJohn Forte 1233fcf3ce44SJohn Forte /* 1234fcf3ce44SJohn Forte * get lun properties 1235fcf3ce44SJohn Forte */ 1236fcf3ce44SJohn Forte if ((openStatus = open_driver(&fd))) { 1237fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | openStatus); 1238fcf3ce44SJohn Forte } 1239fcf3ce44SJohn Forte 1240fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_PROPS_GET, &lun)) { 1241fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1242fcf3ce44SJohn Forte "ISCSI_LUN_PROPS_GET ioctl failed, errno: %d", errno); 1243fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1244fcf3ce44SJohn Forte } 1245fcf3ce44SJohn Forte 1246fcf3ce44SJohn Forte (void) close(fd); 1247fcf3ce44SJohn Forte 1248fcf3ce44SJohn Forte /* 1249fcf3ce44SJohn Forte * set property values 1250fcf3ce44SJohn Forte */ 1251fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.objectType = 1252fcf3ce44SJohn Forte IMA_OBJECT_TYPE_TARGET; 1253fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.ownerId = 1; 1254fcf3ce44SJohn Forte pProps->imaProps.associatedTargetOid.objectSequenceNumber = lun.lp_oid; 1255fcf3ce44SJohn Forte pProps->imaProps.targetLun = (IMA_UINT64)lun.lp_num; 1256fcf3ce44SJohn Forte (void) strncpy(pProps->vendorId, lun.lp_vid, SUN_IMA_LU_VENDOR_ID_LEN); 1257fcf3ce44SJohn Forte (void) strncpy(pProps->productId, lun.lp_pid, 1258fcf3ce44SJohn Forte SUN_IMA_LU_PRODUCT_ID_LEN); 1259fcf3ce44SJohn Forte /* 1260fcf3ce44SJohn Forte * lun.lp_status is defined as 1261fcf3ce44SJohn Forte * LunValid = 0 1262fcf3ce44SJohn Forte * LunDoesNotExist = 1 1263fcf3ce44SJohn Forte * IMA_LU_PROPS.exposedtoOS is defined as an IMA_BOOL 1264fcf3ce44SJohn Forte * IMA_TRUE = 1 1265fcf3ce44SJohn Forte * IMA_FALSE = 0 1266fcf3ce44SJohn Forte */ 1267fcf3ce44SJohn Forte pProps->imaProps.exposedToOs = !lun.lp_status; 1268fcf3ce44SJohn Forte if (gmtime_r(&lun.lp_time_online, &pProps->imaProps.timeExposedToOs) 1269fcf3ce44SJohn Forte == NULL) { 1270fcf3ce44SJohn Forte (void) memset(&pProps->imaProps.timeExposedToOs, 0, 1271fcf3ce44SJohn Forte sizeof (pProps->imaProps.timeExposedToOs)); 1272fcf3ce44SJohn Forte } 1273fcf3ce44SJohn Forte 1274fcf3ce44SJohn Forte if (lun.lp_status == LunValid) { 12751f6352c6Syi zhang - Sun Microsystems - Beijing China if ((strlen(lun.lp_pathname) + strlen("/devices")) > 12761f6352c6Syi zhang - Sun Microsystems - Beijing China (MAXPATHLEN -1)) { 12771f6352c6Syi zhang - Sun Microsystems - Beijing China /* 12781f6352c6Syi zhang - Sun Microsystems - Beijing China * lun.lp_pathname length too long 12791f6352c6Syi zhang - Sun Microsystems - Beijing China */ 12801f6352c6Syi zhang - Sun Microsystems - Beijing China pProps->imaProps.osDeviceNameValid = IMA_FALSE; 12811f6352c6Syi zhang - Sun Microsystems - Beijing China pProps->imaProps.osParallelIdsValid = IMA_FALSE; 12821f6352c6Syi zhang - Sun Microsystems - Beijing China return (IMA_STATUS_SUCCESS); 12831f6352c6Syi zhang - Sun Microsystems - Beijing China } 12841f6352c6Syi zhang - Sun Microsystems - Beijing China if ((strstr(lun.lp_pathname, "st@") != NULL) || 12851f6352c6Syi zhang - Sun Microsystems - Beijing China (strstr(lun.lp_pathname, "tape@") != NULL)) { 12861f6352c6Syi zhang - Sun Microsystems - Beijing China (void) strlcat(lun.lp_pathname, ":n", MAXPATHLEN); 12871f6352c6Syi zhang - Sun Microsystems - Beijing China } else if ((strstr(lun.lp_pathname, "sd@") != NULL) || 1288fcf3ce44SJohn Forte (strstr(lun.lp_pathname, "ssd@") != NULL) || 1289fcf3ce44SJohn Forte (strstr(lun.lp_pathname, "disk@") != NULL)) { 1290fcf3ce44SJohn Forte /* 1291fcf3ce44SJohn Forte * modify returned pathname to obtain the 2nd slice 1292fcf3ce44SJohn Forte * of the raw disk 1293fcf3ce44SJohn Forte */ 12941f6352c6Syi zhang - Sun Microsystems - Beijing China (void) strlcat(lun.lp_pathname, ":c,raw", MAXPATHLEN); 12951f6352c6Syi zhang - Sun Microsystems - Beijing China } else if ((strstr(lun.lp_pathname, "ses@") != NULL) || 12961f6352c6Syi zhang - Sun Microsystems - Beijing China (strstr(lun.lp_pathname, "enclosure@") != NULL)) { 12971f6352c6Syi zhang - Sun Microsystems - Beijing China (void) strlcat(lun.lp_pathname, ":0", MAXPATHLEN); 1298fcf3ce44SJohn Forte } 1299fcf3ce44SJohn Forte 13001f6352c6Syi zhang - Sun Microsystems - Beijing China (void) snprintf(lunpath, sizeof (lun.lp_pathname), 13011f6352c6Syi zhang - Sun Microsystems - Beijing China "/devices%s", lun.lp_pathname); 13021f6352c6Syi zhang - Sun Microsystems - Beijing China if (strchr(lunpath, ':')) { 13031f6352c6Syi zhang - Sun Microsystems - Beijing China minor_path = lunpath; 13041f6352c6Syi zhang - Sun Microsystems - Beijing China if (strstr(minor_path, "/devices") != NULL) { 13051f6352c6Syi zhang - Sun Microsystems - Beijing China minor_path = lunpath + 13061f6352c6Syi zhang - Sun Microsystems - Beijing China strlen("/devices"); 13071f6352c6Syi zhang - Sun Microsystems - Beijing China } else { 13081f6352c6Syi zhang - Sun Microsystems - Beijing China minor_path = lunpath; 13091f6352c6Syi zhang - Sun Microsystems - Beijing China } 13101f6352c6Syi zhang - Sun Microsystems - Beijing China warg.path = NULL; 13111f6352c6Syi zhang - Sun Microsystems - Beijing China } else { 13121f6352c6Syi zhang - Sun Microsystems - Beijing China minor_path = NULL; 13131f6352c6Syi zhang - Sun Microsystems - Beijing China warg.len = strlen(lunpath); 13141f6352c6Syi zhang - Sun Microsystems - Beijing China warg.path = lunpath; 13151f6352c6Syi zhang - Sun Microsystems - Beijing China } 13161f6352c6Syi zhang - Sun Microsystems - Beijing China devlinkp = NULL; 13171f6352c6Syi zhang - Sun Microsystems - Beijing China warg.linkpp = &devlinkp; 13181f6352c6Syi zhang - Sun Microsystems - Beijing China 1319fcf3ce44SJohn Forte /* 1320fcf3ce44SJohn Forte * Pathname returned by driver is the physical device path. 1321fcf3ce44SJohn Forte * This name needs to be converted to the OS device name. 1322fcf3ce44SJohn Forte */ 1323fcf3ce44SJohn Forte if (hdl = di_devlink_init(lun.lp_pathname, DI_MAKE_LINK)) { 1324fcf3ce44SJohn Forte pProps->imaProps.osDeviceName[0] = L'\0'; 13251f6352c6Syi zhang - Sun Microsystems - Beijing China (void) di_devlink_walk(hdl, NULL, minor_path, 13261f6352c6Syi zhang - Sun Microsystems - Beijing China DI_PRIMARY_LINK, (void *)&warg, get_lun_devlink); 13271f6352c6Syi zhang - Sun Microsystems - Beijing China if (devlinkp != NULL) { 13281f6352c6Syi zhang - Sun Microsystems - Beijing China (void) mbstowcs(pProps->imaProps.osDeviceName, 13291f6352c6Syi zhang - Sun Microsystems - Beijing China devlinkp, MAXPATHLEN); 13301f6352c6Syi zhang - Sun Microsystems - Beijing China free(devlinkp); 1331fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_TRUE; 1332fcf3ce44SJohn Forte } else { 1333*904e51f6SJack Meng /* OS device name is asynchronously made */ 1334fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1335fcf3ce44SJohn Forte } 1336fcf3ce44SJohn Forte 1337fcf3ce44SJohn Forte (void) di_devlink_fini(&hdl); 1338fcf3ce44SJohn Forte 1339fcf3ce44SJohn Forte } else { 1340fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1341fcf3ce44SJohn Forte } 1342fcf3ce44SJohn Forte 1343fcf3ce44SJohn Forte } else { 1344fcf3ce44SJohn Forte pProps->imaProps.osDeviceNameValid = IMA_FALSE; 1345fcf3ce44SJohn Forte } 1346fcf3ce44SJohn Forte 1347fcf3ce44SJohn Forte pProps->imaProps.osParallelIdsValid = IMA_FALSE; 1348fcf3ce44SJohn Forte 1349fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1350fcf3ce44SJohn Forte } 1351fcf3ce44SJohn Forte 1352fcf3ce44SJohn Forte static int 13531f6352c6Syi zhang - Sun Microsystems - Beijing China get_lun_devlink(di_devlink_t link, void *arg) 1354fcf3ce44SJohn Forte { 13551f6352c6Syi zhang - Sun Microsystems - Beijing China walk_devlink_t *warg = (walk_devlink_t *)arg; 13561f6352c6Syi zhang - Sun Microsystems - Beijing China if (warg->path) { 13571f6352c6Syi zhang - Sun Microsystems - Beijing China char *content = (char *)di_devlink_content(link); 13581f6352c6Syi zhang - Sun Microsystems - Beijing China char *start = strstr(content, "/devices"); 13591f6352c6Syi zhang - Sun Microsystems - Beijing China if (start == NULL || 13601f6352c6Syi zhang - Sun Microsystems - Beijing China strncmp(start, warg->path, warg->len) != 0 || 13611f6352c6Syi zhang - Sun Microsystems - Beijing China start[warg->len] != ':') 13621f6352c6Syi zhang - Sun Microsystems - Beijing China return (DI_WALK_CONTINUE); 1363fcf3ce44SJohn Forte } 1364fcf3ce44SJohn Forte 13651f6352c6Syi zhang - Sun Microsystems - Beijing China *(warg->linkpp) = strdup(di_devlink_path(link)); 13661f6352c6Syi zhang - Sun Microsystems - Beijing China return (DI_WALK_TERMINATE); 13671f6352c6Syi zhang - Sun Microsystems - Beijing China 1368fcf3ce44SJohn Forte } 1369fcf3ce44SJohn Forte 1370fcf3ce44SJohn Forte /* 1371fcf3ce44SJohn Forte * SUN_IMA_GetConnectionOidList - 1372fcf3ce44SJohn Forte * 1373fcf3ce44SJohn Forte * Non-IMA defined function. 1374fcf3ce44SJohn Forte */ 1375fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConnOidList( 1376fcf3ce44SJohn Forte IMA_OID *oid, 1377fcf3ce44SJohn Forte IMA_OID_LIST **ppList 1378fcf3ce44SJohn Forte ) 1379fcf3ce44SJohn Forte { 1380fcf3ce44SJohn Forte IMA_STATUS imaStatus; 1381fcf3ce44SJohn Forte IMA_OID_LIST *imaOidList; 1382fcf3ce44SJohn Forte iscsi_conn_list_t *iscsiConnList = NULL; 1383fcf3ce44SJohn Forte int i; 1384fcf3ce44SJohn Forte size_t allocLen; 1385fcf3ce44SJohn Forte 1386fcf3ce44SJohn Forte if ((lhbaObjectId.objectType == oid->objectType) && 1387fcf3ce44SJohn Forte (lhbaObjectId.ownerId == oid->ownerId) && 1388fcf3ce44SJohn Forte (lhbaObjectId.objectSequenceNumber == oid->objectSequenceNumber)) { 1389fcf3ce44SJohn Forte imaStatus = getConnOidList(NULL, &iscsiConnList); 1390fcf3ce44SJohn Forte } else { 1391fcf3ce44SJohn Forte if (oid->objectType == IMA_OBJECT_TYPE_TARGET) { 1392fcf3ce44SJohn Forte imaStatus = getConnOidList(oid, &iscsiConnList); 1393fcf3ce44SJohn Forte } else { 1394fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 1395fcf3ce44SJohn Forte } 1396fcf3ce44SJohn Forte } 1397fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1398fcf3ce44SJohn Forte return (imaStatus); 1399fcf3ce44SJohn Forte } 1400fcf3ce44SJohn Forte 1401fcf3ce44SJohn Forte /* 1402fcf3ce44SJohn Forte * Based on the results a SUN_IMA_CONN_LIST structure is allocated. 1403fcf3ce44SJohn Forte */ 1404fcf3ce44SJohn Forte allocLen = iscsiConnList->cl_out_cnt * sizeof (IMA_OID); 1405fcf3ce44SJohn Forte allocLen += sizeof (IMA_OID_LIST) - sizeof (IMA_OID); 1406fcf3ce44SJohn Forte imaOidList = (IMA_OID_LIST *)calloc(1, allocLen); 1407fcf3ce44SJohn Forte 1408fcf3ce44SJohn Forte if (imaOidList == NULL) { 1409fcf3ce44SJohn Forte free(iscsiConnList); 1410fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1411fcf3ce44SJohn Forte } 1412fcf3ce44SJohn Forte 1413fcf3ce44SJohn Forte /* The data is transfered from iscsiConnList to imaConnList. */ 1414fcf3ce44SJohn Forte imaOidList->oidCount = iscsiConnList->cl_out_cnt; 1415fcf3ce44SJohn Forte for (i = 0; i < iscsiConnList->cl_out_cnt; i++) { 1416fcf3ce44SJohn Forte imaOidList->oids[i].objectType = SUN_IMA_OBJECT_TYPE_CONN; 1417fcf3ce44SJohn Forte imaOidList->oids[i].ownerId = 1; 1418fcf3ce44SJohn Forte imaOidList->oids[i].objectSequenceNumber = 1419fcf3ce44SJohn Forte iscsiConnList->cl_list[i].c_oid; 1420fcf3ce44SJohn Forte } 1421fcf3ce44SJohn Forte /* The pointer to the SUN_IMA_CONN_LIST structure is returned. */ 1422fcf3ce44SJohn Forte *ppList = imaOidList; 1423fcf3ce44SJohn Forte 1424fcf3ce44SJohn Forte free(iscsiConnList); 1425fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1426fcf3ce44SJohn Forte } 1427fcf3ce44SJohn Forte 1428fcf3ce44SJohn Forte /* 1429fcf3ce44SJohn Forte * SUN_IMA_GetConnProperties - 1430fcf3ce44SJohn Forte * 1431fcf3ce44SJohn Forte * Non-IMA defined function. 1432fcf3ce44SJohn Forte */ 1433fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConnProperties( 1434fcf3ce44SJohn Forte IMA_OID *connOid, 1435fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES **pProps 1436fcf3ce44SJohn Forte ) 1437fcf3ce44SJohn Forte { 1438fcf3ce44SJohn Forte iscsi_conn_list_t *pConnList; 1439fcf3ce44SJohn Forte iscsi_conn_props_t *pConnProps; 1440fcf3ce44SJohn Forte /* LINTED */ 1441fcf3ce44SJohn Forte struct sockaddr_in6 *addrIn6; 1442fcf3ce44SJohn Forte /* LINTED */ 1443fcf3ce44SJohn Forte struct sockaddr_in *addrIn; 1444fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES *pImaConnProps; 1445fcf3ce44SJohn Forte IMA_STATUS imaStatus; 1446fcf3ce44SJohn Forte int i; 1447fcf3ce44SJohn Forte 1448fcf3ce44SJohn Forte /* If there is any error *pProps should be set to NULL */ 1449fcf3ce44SJohn Forte *pProps = NULL; 1450fcf3ce44SJohn Forte 1451fcf3ce44SJohn Forte pImaConnProps = (SUN_IMA_CONN_PROPERTIES *)calloc(1, 1452fcf3ce44SJohn Forte sizeof (SUN_IMA_CONN_PROPERTIES)); 1453fcf3ce44SJohn Forte 1454fcf3ce44SJohn Forte if (pImaConnProps == NULL) { 1455fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1456fcf3ce44SJohn Forte } 1457fcf3ce44SJohn Forte 1458fcf3ce44SJohn Forte imaStatus = getConnOidList(NULL, &pConnList); 1459fcf3ce44SJohn Forte 1460fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1461fcf3ce44SJohn Forte free(pImaConnProps); 1462fcf3ce44SJohn Forte return (imaStatus); 1463fcf3ce44SJohn Forte } 1464fcf3ce44SJohn Forte 1465fcf3ce44SJohn Forte /* 1466fcf3ce44SJohn Forte * Walk the list returned to find our connection. 1467fcf3ce44SJohn Forte */ 1468fcf3ce44SJohn Forte for (i = 0; i < pConnList->cl_out_cnt; i++) { 1469fcf3ce44SJohn Forte 1470fcf3ce44SJohn Forte if (pConnList->cl_list[i].c_oid == 1471fcf3ce44SJohn Forte (uint32_t)connOid->objectSequenceNumber) { 1472fcf3ce44SJohn Forte 1473fcf3ce44SJohn Forte /* This is our connection. */ 1474fcf3ce44SJohn Forte imaStatus = getConnProps(&pConnList->cl_list[i], 1475fcf3ce44SJohn Forte &pConnProps); 1476fcf3ce44SJohn Forte 1477fcf3ce44SJohn Forte if (imaStatus != IMA_STATUS_SUCCESS) { 1478fcf3ce44SJohn Forte free(pConnList); 1479fcf3ce44SJohn Forte free(pImaConnProps); 1480fcf3ce44SJohn Forte return (imaStatus); 1481fcf3ce44SJohn Forte } 1482fcf3ce44SJohn Forte pImaConnProps->connectionID = pConnProps->cp_cid; 1483fcf3ce44SJohn Forte 1484fcf3ce44SJohn Forte /* 1485fcf3ce44SJohn Forte * Local Propeties 1486fcf3ce44SJohn Forte */ 1487fcf3ce44SJohn Forte if (pConnProps->cp_local.soa4.sin_family == AF_INET) { 1488fcf3ce44SJohn Forte 1489fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipv4Address = 1490fcf3ce44SJohn Forte IMA_TRUE; 1491fcf3ce44SJohn Forte pImaConnProps->local.portNumber = 1492fcf3ce44SJohn Forte pConnProps->cp_local.soa4.sin_port; 1493fcf3ce44SJohn Forte addrIn = &(pConnProps->cp_local.soa4); 1494fcf3ce44SJohn Forte bcopy(&pConnProps->cp_local.soa4.sin_addr, 1495fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipAddress, 1496fcf3ce44SJohn Forte sizeof (addrIn->sin_addr)); 1497fcf3ce44SJohn Forte 1498fcf3ce44SJohn Forte } else { 1499fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipv4Address = 1500fcf3ce44SJohn Forte IMA_FALSE; 1501fcf3ce44SJohn Forte pImaConnProps->local.portNumber = 1502fcf3ce44SJohn Forte pConnProps->cp_local.soa6.sin6_port; 1503fcf3ce44SJohn Forte addrIn6 = &(pConnProps->cp_local.soa6); 1504fcf3ce44SJohn Forte bcopy(&pConnProps->cp_local.soa6.sin6_addr, 1505fcf3ce44SJohn Forte pImaConnProps->local.ipAddress.ipAddress, 1506fcf3ce44SJohn Forte sizeof (addrIn6->sin6_addr)); 1507fcf3ce44SJohn Forte 1508fcf3ce44SJohn Forte } 1509fcf3ce44SJohn Forte 1510fcf3ce44SJohn Forte /* 1511fcf3ce44SJohn Forte * Peer Propeties 1512fcf3ce44SJohn Forte */ 1513fcf3ce44SJohn Forte if (pConnProps->cp_peer.soa4.sin_family == AF_INET) { 1514fcf3ce44SJohn Forte 1515fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipv4Address = 1516fcf3ce44SJohn Forte IMA_TRUE; 1517fcf3ce44SJohn Forte pImaConnProps->peer.portNumber = 1518fcf3ce44SJohn Forte pConnProps->cp_peer.soa4.sin_port; 1519fcf3ce44SJohn Forte addrIn = &(pConnProps->cp_local.soa4); 1520fcf3ce44SJohn Forte bcopy(&pConnProps->cp_peer.soa4.sin_addr, 1521fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipAddress, 1522fcf3ce44SJohn Forte sizeof (addrIn->sin_addr)); 1523fcf3ce44SJohn Forte 1524fcf3ce44SJohn Forte } else { 1525fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipv4Address = 1526fcf3ce44SJohn Forte IMA_FALSE; 1527fcf3ce44SJohn Forte pImaConnProps->peer.portNumber = 1528fcf3ce44SJohn Forte pConnProps->cp_peer.soa6.sin6_port; 1529fcf3ce44SJohn Forte 1530fcf3ce44SJohn Forte addrIn6 = &pConnProps->cp_local.soa6; 1531fcf3ce44SJohn Forte bcopy(&pConnProps->cp_peer.soa6.sin6_addr, 1532fcf3ce44SJohn Forte pImaConnProps->peer.ipAddress.ipAddress, 1533fcf3ce44SJohn Forte sizeof (addrIn6->sin6_addr)); 1534fcf3ce44SJohn Forte } 1535fcf3ce44SJohn Forte 1536fcf3ce44SJohn Forte 1537fcf3ce44SJohn Forte pImaConnProps->valuesValid = 1538fcf3ce44SJohn Forte pConnProps->cp_params_valid; 1539fcf3ce44SJohn Forte pImaConnProps->defaultTime2Retain = 1540fcf3ce44SJohn Forte pConnProps->cp_params.default_time_to_retain; 1541fcf3ce44SJohn Forte pImaConnProps->defaultTime2Wait = 1542fcf3ce44SJohn Forte pConnProps->cp_params.default_time_to_wait; 1543fcf3ce44SJohn Forte pImaConnProps->errorRecoveryLevel = 1544fcf3ce44SJohn Forte pConnProps->cp_params.error_recovery_level; 1545fcf3ce44SJohn Forte pImaConnProps->firstBurstLength = 1546fcf3ce44SJohn Forte pConnProps->cp_params.first_burst_length; 1547fcf3ce44SJohn Forte pImaConnProps->maxBurstLength = 1548fcf3ce44SJohn Forte pConnProps->cp_params.max_burst_length; 1549fcf3ce44SJohn Forte pImaConnProps->maxConnections = 1550fcf3ce44SJohn Forte pConnProps->cp_params.max_connections; 1551fcf3ce44SJohn Forte pImaConnProps->maxOutstandingR2T = 1552fcf3ce44SJohn Forte pConnProps->cp_params.max_outstanding_r2t; 1553fcf3ce44SJohn Forte pImaConnProps->maxRecvDataSegmentLength = 1554fcf3ce44SJohn Forte pConnProps->cp_params.max_recv_data_seg_len; 1555fcf3ce44SJohn Forte 1556fcf3ce44SJohn Forte pImaConnProps->dataPduInOrder = 1557fcf3ce44SJohn Forte pConnProps->cp_params.data_pdu_in_order; 1558fcf3ce44SJohn Forte pImaConnProps->dataSequenceInOrder = 1559fcf3ce44SJohn Forte pConnProps->cp_params.data_sequence_in_order; 1560fcf3ce44SJohn Forte pImaConnProps->immediateData = 1561fcf3ce44SJohn Forte pConnProps->cp_params.immediate_data; 1562fcf3ce44SJohn Forte pImaConnProps->initialR2T = 1563fcf3ce44SJohn Forte pConnProps->cp_params.initial_r2t; 1564fcf3ce44SJohn Forte 1565fcf3ce44SJohn Forte pImaConnProps->headerDigest = 1566fcf3ce44SJohn Forte pConnProps->cp_params.header_digest; 1567fcf3ce44SJohn Forte pImaConnProps->dataDigest = 1568fcf3ce44SJohn Forte pConnProps->cp_params.data_digest; 1569fcf3ce44SJohn Forte 1570fcf3ce44SJohn Forte free(pConnProps); 1571fcf3ce44SJohn Forte break; 1572fcf3ce44SJohn Forte } 1573fcf3ce44SJohn Forte } 1574fcf3ce44SJohn Forte free(pConnList); 1575fcf3ce44SJohn Forte *pProps = pImaConnProps; 1576fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1577fcf3ce44SJohn Forte } 1578fcf3ce44SJohn Forte 1579fcf3ce44SJohn Forte 1580fcf3ce44SJohn Forte /* 1581fcf3ce44SJohn Forte * SUN_IMA_GetConfigSessions - 1582fcf3ce44SJohn Forte * 1583fcf3ce44SJohn Forte * Non-IMA defined function. 1584fcf3ce44SJohn Forte */ 1585fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetConfigSessions( 1586fcf3ce44SJohn Forte IMA_OID targetOid, 1587fcf3ce44SJohn Forte SUN_IMA_CONFIG_SESSIONS **pConfigSessions 1588fcf3ce44SJohn Forte ) 1589fcf3ce44SJohn Forte { 1590fcf3ce44SJohn Forte int fd; 1591fcf3ce44SJohn Forte int status; 1592fcf3ce44SJohn Forte iscsi_config_sess_t *ics; 1593fcf3ce44SJohn Forte int size, idx; 1594fcf3ce44SJohn Forte 1595fcf3ce44SJohn Forte /* Allocate and setup initial buffer */ 1596fcf3ce44SJohn Forte size = sizeof (*ics); 1597fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)calloc(1, size); 1598fcf3ce44SJohn Forte if (ics == NULL) { 1599fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1600fcf3ce44SJohn Forte } 1601fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1602fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1603fcf3ce44SJohn Forte ics->ics_in = 1; 1604fcf3ce44SJohn Forte 1605fcf3ce44SJohn Forte /* Open driver devctl for ioctl */ 1606fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1607fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1608fcf3ce44SJohn Forte } 1609fcf3ce44SJohn Forte 1610fcf3ce44SJohn Forte /* Issue ioctl request */ 1611fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_GET_CONFIG_SESSIONS, ics) != 0) { 1612fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1613fcf3ce44SJohn Forte "ISCSI_GET_CONFIG_SESSIONS ioctl failed, errno: %d", 1614fcf3ce44SJohn Forte errno); 1615fcf3ce44SJohn Forte (void) close(fd); 1616fcf3ce44SJohn Forte free(ics); 1617fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1618fcf3ce44SJohn Forte } 1619fcf3ce44SJohn Forte 1620fcf3ce44SJohn Forte /* Check if we need to collect more information */ 1621fcf3ce44SJohn Forte idx = ics->ics_out; 1622fcf3ce44SJohn Forte if (idx > 1) { 1623fcf3ce44SJohn Forte 1624fcf3ce44SJohn Forte /* Free old buffer and reallocate re-sized buffer */ 1625fcf3ce44SJohn Forte free(ics); 1626fcf3ce44SJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(idx); 1627fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)calloc(1, size); 1628fcf3ce44SJohn Forte if (ics == NULL) { 1629fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1630fcf3ce44SJohn Forte } 1631fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1632fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1633fcf3ce44SJohn Forte ics->ics_in = idx; 1634fcf3ce44SJohn Forte 1635fcf3ce44SJohn Forte /* Issue ioctl request */ 1636fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_GET_CONFIG_SESSIONS, ics) != 0) { 1637fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1638fcf3ce44SJohn Forte "ISCSI_GET_CONFIG_SESSIONS ioctl failed, errno: %d", 1639fcf3ce44SJohn Forte errno); 1640fcf3ce44SJohn Forte (void) close(fd); 1641fcf3ce44SJohn Forte free(ics); 1642fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1643fcf3ce44SJohn Forte } 1644fcf3ce44SJohn Forte } 1645fcf3ce44SJohn Forte (void) close(fd); 1646fcf3ce44SJohn Forte 1647fcf3ce44SJohn Forte /* Allocate output buffer */ 1648fcf3ce44SJohn Forte size = sizeof (SUN_IMA_CONFIG_SESSIONS) + 1649fcf3ce44SJohn Forte ((ics->ics_out - 1) * sizeof (IMA_ADDRESS_KEY)); 1650fcf3ce44SJohn Forte *pConfigSessions = (SUN_IMA_CONFIG_SESSIONS *)calloc(1, size); 1651fcf3ce44SJohn Forte if ((*pConfigSessions) == NULL) { 1652fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1653fcf3ce44SJohn Forte } 1654fcf3ce44SJohn Forte 1655fcf3ce44SJohn Forte /* Copy output information */ 1656fcf3ce44SJohn Forte (*pConfigSessions)->bound = 1657fcf3ce44SJohn Forte (ics->ics_bound == B_TRUE ? IMA_TRUE : IMA_FALSE); 1658fcf3ce44SJohn Forte (*pConfigSessions)->in = ics->ics_in; 1659fcf3ce44SJohn Forte (*pConfigSessions)->out = ics->ics_out; 1660fcf3ce44SJohn Forte for (idx = 0; idx < ics->ics_in; idx++) { 1661fcf3ce44SJohn Forte if (ics->ics_bindings[idx].i_insize == 1662fcf3ce44SJohn Forte sizeof (struct in_addr)) { 1663fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1664fcf3ce44SJohn Forte ipv4Address = IMA_TRUE; 1665fcf3ce44SJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in4, 1666fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1667fcf3ce44SJohn Forte ipAddress, sizeof (struct in_addr)); 1668fcf3ce44SJohn Forte } else { 1669fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1670fcf3ce44SJohn Forte ipv4Address = IMA_FALSE; 1671fcf3ce44SJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in6, 1672fcf3ce44SJohn Forte (*pConfigSessions)->bindings[idx].ipAddress. 1673fcf3ce44SJohn Forte ipAddress, sizeof (struct in6_addr)); 1674fcf3ce44SJohn Forte } 1675fcf3ce44SJohn Forte } 1676fcf3ce44SJohn Forte 1677fcf3ce44SJohn Forte free(ics); 1678fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1679fcf3ce44SJohn Forte } 1680fcf3ce44SJohn Forte 1681fcf3ce44SJohn Forte /* 1682fcf3ce44SJohn Forte * SUN_IMA_SetConfigSessions - 1683fcf3ce44SJohn Forte * 1684fcf3ce44SJohn Forte * Non-IMA defined function. 1685fcf3ce44SJohn Forte */ 1686fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_SetConfigSessions( 1687fcf3ce44SJohn Forte IMA_OID targetOid, 1688fcf3ce44SJohn Forte SUN_IMA_CONFIG_SESSIONS *pConfigSessions 1689fcf3ce44SJohn Forte ) 1690fcf3ce44SJohn Forte { 1691fcf3ce44SJohn Forte int fd; 1692fcf3ce44SJohn Forte int status; 1693fcf3ce44SJohn Forte iscsi_config_sess_t *ics; 1694fcf3ce44SJohn Forte int idx, size; 1695fcf3ce44SJohn Forte 1696fcf3ce44SJohn Forte /* verify allowed range of sessions */ 1697fcf3ce44SJohn Forte if ((pConfigSessions->in < ISCSI_MIN_CONFIG_SESSIONS) || 1698fcf3ce44SJohn Forte (pConfigSessions->in > ISCSI_MAX_CONFIG_SESSIONS)) { 1699fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 1700fcf3ce44SJohn Forte } 1701fcf3ce44SJohn Forte 1702fcf3ce44SJohn Forte /* allocate record config_sess size */ 1703fcf3ce44SJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(pConfigSessions->in); 1704fcf3ce44SJohn Forte ics = (iscsi_config_sess_t *)malloc(size); 1705fcf3ce44SJohn Forte 1706fcf3ce44SJohn Forte /* setup config_sess information */ 1707fcf3ce44SJohn Forte (void) memset(ics, 0, sizeof (iscsi_config_sess_t)); 1708fcf3ce44SJohn Forte ics->ics_ver = ISCSI_INTERFACE_VERSION; 1709fcf3ce44SJohn Forte ics->ics_oid = targetOid.objectSequenceNumber; 1710fcf3ce44SJohn Forte ics->ics_bound = 1711fcf3ce44SJohn Forte (pConfigSessions->bound == IMA_TRUE ? B_TRUE : B_FALSE); 1712fcf3ce44SJohn Forte ics->ics_in = pConfigSessions->in; 1713fcf3ce44SJohn Forte for (idx = 0; idx < ics->ics_in; idx++) { 1714fcf3ce44SJohn Forte if (pConfigSessions->bindings[idx].ipAddress. 1715fcf3ce44SJohn Forte ipv4Address == IMA_TRUE) { 1716fcf3ce44SJohn Forte ics->ics_bindings[idx].i_insize = 1717fcf3ce44SJohn Forte sizeof (struct in_addr); 1718fcf3ce44SJohn Forte bcopy(pConfigSessions->bindings[idx]. 1719fcf3ce44SJohn Forte ipAddress.ipAddress, 1720fcf3ce44SJohn Forte &ics->ics_bindings[idx].i_addr.in4, 1721fcf3ce44SJohn Forte sizeof (struct in_addr)); 1722fcf3ce44SJohn Forte } else { 1723fcf3ce44SJohn Forte ics->ics_bindings[idx].i_insize = 1724fcf3ce44SJohn Forte sizeof (struct in6_addr); 1725fcf3ce44SJohn Forte bcopy(pConfigSessions->bindings[idx]. 1726fcf3ce44SJohn Forte ipAddress.ipAddress, 1727fcf3ce44SJohn Forte &ics->ics_bindings[idx].i_addr.in6, 1728fcf3ce44SJohn Forte sizeof (struct in6_addr)); 1729fcf3ce44SJohn Forte } 1730fcf3ce44SJohn Forte } 1731fcf3ce44SJohn Forte 1732fcf3ce44SJohn Forte /* open driver */ 1733fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1734fcf3ce44SJohn Forte free(ics); 1735fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1736fcf3ce44SJohn Forte } 1737fcf3ce44SJohn Forte 1738fcf3ce44SJohn Forte /* issue ioctl request */ 1739fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_SET_CONFIG_SESSIONS, ics) != 0) { 1740fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1741fcf3ce44SJohn Forte "ISCSI_SET_CONFIG_SESSIONS ioctl failed, errno: %d", 1742fcf3ce44SJohn Forte errno); 1743fcf3ce44SJohn Forte (void) close(fd); 1744fcf3ce44SJohn Forte free(ics); 1745fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1746fcf3ce44SJohn Forte } 1747fcf3ce44SJohn Forte (void) close(fd); 1748fcf3ce44SJohn Forte free(ics); 1749fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1750fcf3ce44SJohn Forte } 1751fcf3ce44SJohn Forte 1752fcf3ce44SJohn Forte /* A helper function to obtain iSCSI node parameters. */ 1753fcf3ce44SJohn Forte static IMA_STATUS 1754fcf3ce44SJohn Forte getISCSINodeParameter( 1755fcf3ce44SJohn Forte int paramType, 1756fcf3ce44SJohn Forte IMA_OID *oid, 1757fcf3ce44SJohn Forte void *pProps, 1758fcf3ce44SJohn Forte uint32_t paramIndex 1759fcf3ce44SJohn Forte ) 1760fcf3ce44SJohn Forte { 1761fcf3ce44SJohn Forte int fd; 1762fcf3ce44SJohn Forte int status; 1763fcf3ce44SJohn Forte iscsi_param_get_t pg; 1764fcf3ce44SJohn Forte 1765fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1766fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1767fcf3ce44SJohn Forte } 1768fcf3ce44SJohn Forte 1769fcf3ce44SJohn Forte (void) memset(&pg, 0, sizeof (iscsi_param_get_t)); 1770fcf3ce44SJohn Forte pg.g_vers = ISCSI_INTERFACE_VERSION; 1771fcf3ce44SJohn Forte pg.g_oid = (uint32_t)oid->objectSequenceNumber; 1772fcf3ce44SJohn Forte pg.g_param = paramIndex; 1773fcf3ce44SJohn Forte pg.g_param_type = ISCSI_SESS_PARAM; 1774fcf3ce44SJohn Forte 1775fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) { 1776fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1777fcf3ce44SJohn Forte "ISCSI_PARAM_GET ioctl failed, errno: %d", errno); 1778fcf3ce44SJohn Forte (void) close(fd); 1779fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1780fcf3ce44SJohn Forte } 1781fcf3ce44SJohn Forte 1782fcf3ce44SJohn Forte switch (paramType) { 1783fcf3ce44SJohn Forte IMA_BOOL_VALUE *bp; 1784fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE *mp; 1785fcf3ce44SJohn Forte 1786fcf3ce44SJohn Forte case MIN_MAX_PARAM: 1787fcf3ce44SJohn Forte mp = (IMA_MIN_MAX_VALUE *)pProps; 1788fcf3ce44SJohn Forte 1789fcf3ce44SJohn Forte mp->currentValueValid = 1790fcf3ce44SJohn Forte (pg.g_value.v_valid == B_TRUE) ? 1791fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 1792fcf3ce44SJohn Forte mp->currentValue = pg.g_value.v_integer.i_current; 1793fcf3ce44SJohn Forte mp->defaultValue = pg.g_value.v_integer.i_default; 1794fcf3ce44SJohn Forte mp->minimumValue = pg.g_value.v_integer.i_min; 1795fcf3ce44SJohn Forte mp->maximumValue = pg.g_value.v_integer.i_max; 1796fcf3ce44SJohn Forte mp->incrementValue = pg.g_value.v_integer.i_incr; 1797fcf3ce44SJohn Forte break; 1798fcf3ce44SJohn Forte 1799fcf3ce44SJohn Forte case BOOL_PARAM: 1800fcf3ce44SJohn Forte bp = (IMA_BOOL_VALUE *)pProps; 1801fcf3ce44SJohn Forte bp->currentValueValid = 1802fcf3ce44SJohn Forte (pg.g_value.v_valid == B_TRUE) ? 1803fcf3ce44SJohn Forte IMA_TRUE : IMA_FALSE; 1804fcf3ce44SJohn Forte bp->currentValue = pg.g_value.v_bool.b_current; 1805fcf3ce44SJohn Forte bp->defaultValue = pg.g_value.v_bool.b_default; 1806fcf3ce44SJohn Forte break; 1807fcf3ce44SJohn Forte 1808fcf3ce44SJohn Forte default: 1809fcf3ce44SJohn Forte break; 1810fcf3ce44SJohn Forte } 1811fcf3ce44SJohn Forte 1812fcf3ce44SJohn Forte /* Issue ISCSI_PARAM_GET ioctl again to obtain connection parameters. */ 1813fcf3ce44SJohn Forte pg.g_param_type = ISCSI_CONN_PARAM; 1814fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) { 1815fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1816fcf3ce44SJohn Forte "ISCSI_PARAM_GET ioctl failed, errno: %d", errno); 1817fcf3ce44SJohn Forte (void) close(fd); 1818fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1819fcf3ce44SJohn Forte } 1820fcf3ce44SJohn Forte 1821fcf3ce44SJohn Forte (void) close(fd); 1822fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1823fcf3ce44SJohn Forte } 1824fcf3ce44SJohn Forte 1825fcf3ce44SJohn Forte /* A helper function to set iSCSI node parameters. */ 1826fcf3ce44SJohn Forte static IMA_STATUS 1827fcf3ce44SJohn Forte setISCSINodeParameter( 1828fcf3ce44SJohn Forte int paramType, 1829fcf3ce44SJohn Forte IMA_OID *oid, 1830fcf3ce44SJohn Forte void *pProp, 1831fcf3ce44SJohn Forte uint32_t paramIndex 1832fcf3ce44SJohn Forte ) 1833fcf3ce44SJohn Forte { 1834fcf3ce44SJohn Forte int fd; 1835fcf3ce44SJohn Forte int status; 1836fcf3ce44SJohn Forte iscsi_param_set_t ps; 1837fcf3ce44SJohn Forte 1838fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1839fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1840fcf3ce44SJohn Forte } 1841fcf3ce44SJohn Forte 1842fcf3ce44SJohn Forte (void) memset(&ps, 0, sizeof (iscsi_param_set_t)); 1843fcf3ce44SJohn Forte ps.s_vers = ISCSI_INTERFACE_VERSION; 1844fcf3ce44SJohn Forte ps.s_oid = (uint32_t)oid->objectSequenceNumber; 1845fcf3ce44SJohn Forte ps.s_param = paramIndex; 1846fcf3ce44SJohn Forte 1847fcf3ce44SJohn Forte switch (paramType) { 1848fcf3ce44SJohn Forte IMA_BOOL_VALUE *bp; 1849fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE *mp; 1850fcf3ce44SJohn Forte 1851fcf3ce44SJohn Forte case MIN_MAX_PARAM: 1852fcf3ce44SJohn Forte mp = (IMA_MIN_MAX_VALUE *)pProp; 1853fcf3ce44SJohn Forte ps.s_value.v_integer = mp->currentValue; 1854fcf3ce44SJohn Forte break; 1855fcf3ce44SJohn Forte case BOOL_PARAM: 1856fcf3ce44SJohn Forte bp = (IMA_BOOL_VALUE *)pProp; 1857fcf3ce44SJohn Forte ps.s_value.v_bool = 1858fcf3ce44SJohn Forte (bp->currentValue == IMA_TRUE) ? 1859fcf3ce44SJohn Forte B_TRUE : B_FALSE; 1860fcf3ce44SJohn Forte break; 1861fcf3ce44SJohn Forte 1862fcf3ce44SJohn Forte default: 1863fcf3ce44SJohn Forte break; 1864fcf3ce44SJohn Forte } 1865fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_PARAM_SET, &ps)) { 1866fcf3ce44SJohn Forte (void) close(fd); 1867fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1868fcf3ce44SJohn Forte "ISCSI_PARAM_SET ioctl failed, errno: %d", errno); 1869fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1870fcf3ce44SJohn Forte } 1871fcf3ce44SJohn Forte 1872fcf3ce44SJohn Forte (void) close(fd); 1873fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1874fcf3ce44SJohn Forte } 1875fcf3ce44SJohn Forte 1876fcf3ce44SJohn Forte static int 1877fcf3ce44SJohn Forte prepare_discovery_entry( 1878fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS discoveryAddress, 1879fcf3ce44SJohn Forte entry_t *entry 1880fcf3ce44SJohn Forte ) 1881fcf3ce44SJohn Forte { 1882fcf3ce44SJohn Forte return (prepare_discovery_entry_IMA(discoveryAddress.imaStruct, entry)); 1883fcf3ce44SJohn Forte } 1884fcf3ce44SJohn Forte 1885fcf3ce44SJohn Forte static int 1886fcf3ce44SJohn Forte prepare_discovery_entry_IMA( 1887fcf3ce44SJohn Forte IMA_TARGET_ADDRESS discoveryAddress, 1888fcf3ce44SJohn Forte entry_t *entry 1889fcf3ce44SJohn Forte ) 1890fcf3ce44SJohn Forte { 1891fcf3ce44SJohn Forte (void) memset(entry, 0, sizeof (entry_t)); 1892fcf3ce44SJohn Forte entry->e_vers = ISCSI_INTERFACE_VERSION; 1893fcf3ce44SJohn Forte entry->e_oid = ISCSI_OID_NOTSET; 1894fcf3ce44SJohn Forte 1895fcf3ce44SJohn Forte if (discoveryAddress.hostnameIpAddress.id.ipAddress. 1896fcf3ce44SJohn Forte ipv4Address == IMA_FALSE) { 1897fcf3ce44SJohn Forte 1898fcf3ce44SJohn Forte bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress. 1899fcf3ce44SJohn Forte ipAddress, entry->e_u.u_in6.s6_addr, 1900fcf3ce44SJohn Forte sizeof (entry->e_u.u_in6.s6_addr)); 1901fcf3ce44SJohn Forte 1902fcf3ce44SJohn Forte entry->e_insize = sizeof (struct in6_addr); 1903fcf3ce44SJohn Forte } else { 1904fcf3ce44SJohn Forte 1905fcf3ce44SJohn Forte bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress. 1906fcf3ce44SJohn Forte ipAddress, &entry->e_u.u_in4.s_addr, 1907fcf3ce44SJohn Forte sizeof (entry->e_u.u_in4.s_addr)); 1908fcf3ce44SJohn Forte 1909fcf3ce44SJohn Forte entry->e_insize = sizeof (struct in_addr); 1910fcf3ce44SJohn Forte } 1911fcf3ce44SJohn Forte 1912fcf3ce44SJohn Forte entry->e_port = discoveryAddress.portNumber; 1913fcf3ce44SJohn Forte entry->e_tpgt = 0; 1914fcf3ce44SJohn Forte return (DISC_ADDR_OK); 1915fcf3ce44SJohn Forte } 1916fcf3ce44SJohn Forte 1917fcf3ce44SJohn Forte static IMA_STATUS configure_discovery_method( 1918fcf3ce44SJohn Forte IMA_BOOL enable, 1919fcf3ce44SJohn Forte iSCSIDiscoveryMethod_t method 1920fcf3ce44SJohn Forte ) 1921fcf3ce44SJohn Forte { 1922fcf3ce44SJohn Forte int fd, status; 1923fcf3ce44SJohn Forte 1924fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1925fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1926fcf3ce44SJohn Forte } 1927fcf3ce44SJohn Forte 1928fcf3ce44SJohn Forte if (enable == IMA_FALSE) { 1929fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_CLEAR, &method)) { 1930fcf3ce44SJohn Forte status = errno; 1931fcf3ce44SJohn Forte (void) close(fd); 1932fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1933fcf3ce44SJohn Forte "ISCSI_DISCOVERY_CLEAR ioctl failed, errno: %d", 1934fcf3ce44SJohn Forte status); 1935fcf3ce44SJohn Forte if (status == EBUSY) { 1936fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 1937fcf3ce44SJohn Forte } else { 1938fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1939fcf3ce44SJohn Forte } 1940fcf3ce44SJohn Forte } 1941fcf3ce44SJohn Forte 1942fcf3ce44SJohn Forte (void) close(fd); 1943fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1944fcf3ce44SJohn Forte } else { 1945fcf3ce44SJohn Forte /* Set the discovery method */ 1946fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_SET, &method)) { 1947fcf3ce44SJohn Forte status = errno; 1948fcf3ce44SJohn Forte (void) close(fd); 1949fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 1950fcf3ce44SJohn Forte "ISCSI_DISCOVERY_SET ioctl failed, errno: %d", 1951fcf3ce44SJohn Forte status); 1952fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 1953fcf3ce44SJohn Forte } 1954fcf3ce44SJohn Forte 1955fcf3ce44SJohn Forte (void) close(fd); 1956fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 1957fcf3ce44SJohn Forte } 1958fcf3ce44SJohn Forte } 1959fcf3ce44SJohn Forte 1960fcf3ce44SJohn Forte /* LINTED E_STATIC_UNUSED */ 1961fcf3ce44SJohn Forte static IMA_BOOL authMethodMatch( 1962fcf3ce44SJohn Forte IMA_AUTHMETHOD matchingMethod, 1963fcf3ce44SJohn Forte IMA_AUTHMETHOD *methodList, 1964fcf3ce44SJohn Forte IMA_UINT maxEntries 1965fcf3ce44SJohn Forte ) 1966fcf3ce44SJohn Forte { 1967fcf3ce44SJohn Forte IMA_UINT i; 1968fcf3ce44SJohn Forte 1969fcf3ce44SJohn Forte for (i = 0; i < maxEntries; i++) { 1970fcf3ce44SJohn Forte if (methodList[i] == matchingMethod) { 1971fcf3ce44SJohn Forte return (IMA_TRUE); 1972fcf3ce44SJohn Forte } 1973fcf3ce44SJohn Forte } 1974fcf3ce44SJohn Forte 1975fcf3ce44SJohn Forte return (IMA_FALSE); 1976fcf3ce44SJohn Forte } 1977fcf3ce44SJohn Forte 1978fcf3ce44SJohn Forte static IMA_STATUS get_target_oid_list( 1979fcf3ce44SJohn Forte uint32_t targetListType, 1980fcf3ce44SJohn Forte IMA_OID_LIST **ppList) 1981fcf3ce44SJohn Forte { 1982fcf3ce44SJohn Forte int fd; 1983fcf3ce44SJohn Forte int i; 1984fcf3ce44SJohn Forte int target_list_size; 1985fcf3ce44SJohn Forte int status; 1986fcf3ce44SJohn Forte int out_cnt; 1987fcf3ce44SJohn Forte iscsi_target_list_t *idlp; 1988fcf3ce44SJohn Forte 1989fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 1990fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 1991fcf3ce44SJohn Forte } 1992fcf3ce44SJohn Forte 1993fcf3ce44SJohn Forte idlp = (iscsi_target_list_t *)calloc(1, sizeof (iscsi_target_list_t)); 1994fcf3ce44SJohn Forte if (idlp == NULL) { 1995fcf3ce44SJohn Forte (void) close(fd); 1996fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 1997fcf3ce44SJohn Forte } 1998fcf3ce44SJohn Forte idlp->tl_vers = ISCSI_INTERFACE_VERSION; 1999fcf3ce44SJohn Forte idlp->tl_in_cnt = idlp->tl_out_cnt = 1; 2000fcf3ce44SJohn Forte idlp->tl_tgt_list_type = targetListType; 2001fcf3ce44SJohn Forte 2002fcf3ce44SJohn Forte /* 2003fcf3ce44SJohn Forte * Issue ioctl. Space has been allocted for one entry. 2004fcf3ce44SJohn Forte * If more than one entry should be returned, we will re-issue the 2005fcf3ce44SJohn Forte * entry with the right amount of space allocted 2006fcf3ce44SJohn Forte */ 2007fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) { 2008fcf3ce44SJohn Forte (void) close(fd); 2009fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2010fcf3ce44SJohn Forte "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 2011fcf3ce44SJohn Forte targetListType, errno); 2012fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2013fcf3ce44SJohn Forte } 2014fcf3ce44SJohn Forte if (idlp->tl_out_cnt > 1) { 2015fcf3ce44SJohn Forte out_cnt = idlp->tl_out_cnt; 2016fcf3ce44SJohn Forte free(idlp); 2017fcf3ce44SJohn Forte 2018fcf3ce44SJohn Forte target_list_size = sizeof (iscsi_target_list_t); 2019fcf3ce44SJohn Forte target_list_size += (sizeof (uint32_t) * out_cnt - 1); 2020fcf3ce44SJohn Forte idlp = (iscsi_target_list_t *)calloc(1, target_list_size); 2021fcf3ce44SJohn Forte if (idlp == NULL) { 2022fcf3ce44SJohn Forte (void) close(fd); 2023fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2024fcf3ce44SJohn Forte } 2025fcf3ce44SJohn Forte idlp->tl_vers = ISCSI_INTERFACE_VERSION; 2026fcf3ce44SJohn Forte idlp->tl_in_cnt = out_cnt; 2027fcf3ce44SJohn Forte idlp->tl_tgt_list_type = targetListType; 2028fcf3ce44SJohn Forte 2029fcf3ce44SJohn Forte /* Issue the same ioctl again to obtain all the OIDs. */ 2030fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) { 2031fcf3ce44SJohn Forte #define ERROR_STR "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno :%d" 2032fcf3ce44SJohn Forte free(idlp); 2033fcf3ce44SJohn Forte (void) close(fd); 2034fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2035fcf3ce44SJohn Forte ERROR_STR, targetListType, errno); 2036fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2037fcf3ce44SJohn Forte #undef ERROR_STR 2038fcf3ce44SJohn Forte 2039fcf3ce44SJohn Forte } 2040fcf3ce44SJohn Forte } 2041fcf3ce44SJohn Forte 2042fcf3ce44SJohn Forte *ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) + 2043fcf3ce44SJohn Forte idlp->tl_out_cnt * sizeof (IMA_OID)); 2044fcf3ce44SJohn Forte (*ppList)->oidCount = idlp->tl_out_cnt; 2045fcf3ce44SJohn Forte for (i = 0; i < idlp->tl_out_cnt; i++) { 2046fcf3ce44SJohn Forte (*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_TARGET; 2047fcf3ce44SJohn Forte (*ppList)->oids[i].ownerId = 1; 2048fcf3ce44SJohn Forte (*ppList)->oids[i].objectSequenceNumber = idlp->tl_oid_list[i]; 2049fcf3ce44SJohn Forte } 2050fcf3ce44SJohn Forte 2051fcf3ce44SJohn Forte free(idlp); 2052fcf3ce44SJohn Forte (void) close(fd); 2053fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2054fcf3ce44SJohn Forte } 2055fcf3ce44SJohn Forte 2056fcf3ce44SJohn Forte static IMA_STATUS get_target_lun_oid_list( 2057fcf3ce44SJohn Forte IMA_OID * targetOid, 2058fcf3ce44SJohn Forte iscsi_lun_list_t **ppLunList) 2059fcf3ce44SJohn Forte { 2060fcf3ce44SJohn Forte int fd; 2061fcf3ce44SJohn Forte iscsi_lun_list_t *illp, *illp_saved; 2062fcf3ce44SJohn Forte int lun_list_size; 2063fcf3ce44SJohn Forte int status; 2064fcf3ce44SJohn Forte 2065fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2066fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2067fcf3ce44SJohn Forte } 2068fcf3ce44SJohn Forte 2069fcf3ce44SJohn Forte illp = (iscsi_lun_list_t *)calloc(1, sizeof (iscsi_lun_list_t)); 2070fcf3ce44SJohn Forte if (illp == NULL) { 2071fcf3ce44SJohn Forte (void) close(fd); 2072fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2073fcf3ce44SJohn Forte } 2074fcf3ce44SJohn Forte illp->ll_vers = ISCSI_INTERFACE_VERSION; 2075fcf3ce44SJohn Forte if (targetOid == NULL) { 2076fcf3ce44SJohn Forte /* get lun oid list for all targets */ 2077fcf3ce44SJohn Forte illp->ll_all_tgts = B_TRUE; 2078fcf3ce44SJohn Forte } else { 2079fcf3ce44SJohn Forte /* get lun oid list for single target */ 2080fcf3ce44SJohn Forte illp->ll_all_tgts = B_FALSE; 2081fcf3ce44SJohn Forte illp->ll_tgt_oid = (uint32_t)targetOid->objectSequenceNumber; 2082fcf3ce44SJohn Forte } 2083fcf3ce44SJohn Forte illp->ll_in_cnt = illp->ll_out_cnt = 1; 2084fcf3ce44SJohn Forte 2085fcf3ce44SJohn Forte /* 2086fcf3ce44SJohn Forte * Issue ioctl to retrieve the target luns. Space has been allocted 2087fcf3ce44SJohn Forte * for one entry. If more than one entry should be returned, we 2088fcf3ce44SJohn Forte * will re-issue the entry with the right amount of space allocted 2089fcf3ce44SJohn Forte */ 2090fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) { 2091fcf3ce44SJohn Forte (void) close(fd); 2092fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2093fcf3ce44SJohn Forte "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno); 2094fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2095fcf3ce44SJohn Forte } 2096fcf3ce44SJohn Forte 2097fcf3ce44SJohn Forte if (illp->ll_out_cnt > 1) { 2098fcf3ce44SJohn Forte illp_saved = illp; 2099fcf3ce44SJohn Forte lun_list_size = sizeof (iscsi_lun_list_t); 2100fcf3ce44SJohn Forte lun_list_size += (sizeof (iscsi_if_lun_t) * 2101fcf3ce44SJohn Forte (illp->ll_out_cnt - 1)); 2102fcf3ce44SJohn Forte illp = (iscsi_lun_list_t *)calloc(1, lun_list_size); 2103fcf3ce44SJohn Forte if (illp == NULL) { 2104fcf3ce44SJohn Forte (void) close(fd); 2105fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2106fcf3ce44SJohn Forte } 2107fcf3ce44SJohn Forte illp->ll_vers = ISCSI_INTERFACE_VERSION; 2108fcf3ce44SJohn Forte illp->ll_all_tgts = illp_saved->ll_all_tgts; 2109fcf3ce44SJohn Forte illp->ll_tgt_oid = illp_saved->ll_tgt_oid; 2110fcf3ce44SJohn Forte illp->ll_in_cnt = illp_saved->ll_out_cnt; 2111fcf3ce44SJohn Forte 2112fcf3ce44SJohn Forte free(illp_saved); 2113fcf3ce44SJohn Forte 2114fcf3ce44SJohn Forte /* Issue the same ioctl again to get all the target LUN list */ 2115fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) { 2116fcf3ce44SJohn Forte free(illp); 2117fcf3ce44SJohn Forte (void) close(fd); 2118fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2119fcf3ce44SJohn Forte "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", 2120fcf3ce44SJohn Forte errno); 2121fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2122fcf3ce44SJohn Forte 2123fcf3ce44SJohn Forte } 2124fcf3ce44SJohn Forte } 2125fcf3ce44SJohn Forte *ppLunList = illp; 2126fcf3ce44SJohn Forte 2127fcf3ce44SJohn Forte 2128fcf3ce44SJohn Forte (void) close(fd); 2129fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2130fcf3ce44SJohn Forte } 2131fcf3ce44SJohn Forte 2132fcf3ce44SJohn Forte /* A helper function to obtain digest algorithms. */ 2133fcf3ce44SJohn Forte static IMA_STATUS 2134fcf3ce44SJohn Forte getDigest( 2135fcf3ce44SJohn Forte IMA_OID oid, 2136fcf3ce44SJohn Forte int ioctlCmd, 2137fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm 2138fcf3ce44SJohn Forte ) 2139fcf3ce44SJohn Forte { 2140fcf3ce44SJohn Forte IMA_MIN_MAX_VALUE pProps; 2141fcf3ce44SJohn Forte IMA_STATUS status; 2142fcf3ce44SJohn Forte 2143fcf3ce44SJohn Forte if ((status = getISCSINodeParameter(MIN_MAX_PARAM, &oid, &pProps, 2144fcf3ce44SJohn Forte ioctlCmd)) != IMA_STATUS_SUCCESS) { 2145fcf3ce44SJohn Forte return (status); 2146fcf3ce44SJohn Forte } 2147fcf3ce44SJohn Forte 2148fcf3ce44SJohn Forte switch (pProps.defaultValue) { 2149fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2150fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_NONE; 2151fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 1; 2152fcf3ce44SJohn Forte break; 2153fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2154fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_CRC32C; 2155fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 1; 2156fcf3ce44SJohn Forte break; 2157fcf3ce44SJohn Forte 2158fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2159fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_CRC32C; 2160fcf3ce44SJohn Forte algorithm->defaultAlgorithms[1] = ISCSI_DIGEST_NONE; 2161fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 2; 2162fcf3ce44SJohn Forte break; 2163fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2164fcf3ce44SJohn Forte algorithm->defaultAlgorithms[0] = ISCSI_DIGEST_NONE; 2165fcf3ce44SJohn Forte algorithm->defaultAlgorithms[1] = ISCSI_DIGEST_CRC32C; 2166fcf3ce44SJohn Forte algorithm->defaultAlgorithmCount = 2; 2167fcf3ce44SJohn Forte break; 2168fcf3ce44SJohn Forte default: 2169fcf3ce44SJohn Forte /* Error */ 2170fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2171fcf3ce44SJohn Forte "Invalid default digest: %d", pProps.defaultValue); 2172fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2173fcf3ce44SJohn Forte } 2174fcf3ce44SJohn Forte 2175fcf3ce44SJohn Forte /* The configured value */ 2176fcf3ce44SJohn Forte if (pProps.currentValueValid == IMA_TRUE) { 2177fcf3ce44SJohn Forte algorithm->currentValid = IMA_TRUE; 2178fcf3ce44SJohn Forte 2179fcf3ce44SJohn Forte switch (pProps.currentValue) { 2180fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2181fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2182fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2183fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 1; 2184fcf3ce44SJohn Forte break; 2185fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2186fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2187fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2188fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 1; 2189fcf3ce44SJohn Forte break; 2190fcf3ce44SJohn Forte 2191fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2192fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2193fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2194fcf3ce44SJohn Forte algorithm->currentAlgorithms[1] = 2195fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2196fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 2; 2197fcf3ce44SJohn Forte break; 2198fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2199fcf3ce44SJohn Forte algorithm->currentAlgorithms[0] = 2200fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2201fcf3ce44SJohn Forte algorithm->currentAlgorithms[1] = 2202fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2203fcf3ce44SJohn Forte algorithm->currentAlgorithmCount = 2; 2204fcf3ce44SJohn Forte break; 2205fcf3ce44SJohn Forte default: 2206fcf3ce44SJohn Forte /* Error */ 2207fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2208fcf3ce44SJohn Forte "Invalid configured digest: %d", 2209fcf3ce44SJohn Forte pProps.defaultValue); 2210fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2211fcf3ce44SJohn Forte } 2212fcf3ce44SJohn Forte 2213fcf3ce44SJohn Forte } else { 2214fcf3ce44SJohn Forte algorithm->currentValid = IMA_FALSE; 2215fcf3ce44SJohn Forte } 2216fcf3ce44SJohn Forte 2217fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2218fcf3ce44SJohn Forte } 2219fcf3ce44SJohn Forte 2220fcf3ce44SJohn Forte /* 2221fcf3ce44SJohn Forte * getConnOidList - 2222fcf3ce44SJohn Forte */ 2223fcf3ce44SJohn Forte static IMA_STATUS getConnOidList( 2224fcf3ce44SJohn Forte IMA_OID *sessOid, 2225fcf3ce44SJohn Forte iscsi_conn_list_t **ppConnList 2226fcf3ce44SJohn Forte ) 2227fcf3ce44SJohn Forte { 2228fcf3ce44SJohn Forte iscsi_conn_list_t *iscsiConnList = NULL; 2229fcf3ce44SJohn Forte size_t allocLen; 2230fcf3ce44SJohn Forte int fd; 2231fcf3ce44SJohn Forte int status; 2232fcf3ce44SJohn Forte int out_cnt; 2233fcf3ce44SJohn Forte 2234fcf3ce44SJohn Forte /* Preset it to NULL to prepare for the case of failure */ 2235fcf3ce44SJohn Forte *ppConnList = NULL; 2236fcf3ce44SJohn Forte 2237fcf3ce44SJohn Forte /* We try to open the driver now. */ 2238fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2239fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2240fcf3ce44SJohn Forte } 2241fcf3ce44SJohn Forte 2242fcf3ce44SJohn Forte iscsiConnList = (iscsi_conn_list_t *)calloc(1, 2243fcf3ce44SJohn Forte sizeof (iscsi_conn_list_t)); 2244fcf3ce44SJohn Forte if (iscsiConnList == NULL) { 2245fcf3ce44SJohn Forte (void) close(fd); 2246fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2247fcf3ce44SJohn Forte } 2248fcf3ce44SJohn Forte iscsiConnList->cl_vers = ISCSI_INTERFACE_VERSION; 2249fcf3ce44SJohn Forte iscsiConnList->cl_in_cnt = iscsiConnList->cl_out_cnt = 1; 2250fcf3ce44SJohn Forte if (sessOid == NULL) { 2251fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_TRUE; 2252fcf3ce44SJohn Forte } else { 2253fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_FALSE; 2254fcf3ce44SJohn Forte iscsiConnList->cl_sess_oid = 2255fcf3ce44SJohn Forte (uint32_t)sessOid->objectSequenceNumber; 2256fcf3ce44SJohn Forte } 2257fcf3ce44SJohn Forte /* 2258fcf3ce44SJohn Forte * Issue ioctl to retrieve the connection OIDs. Space has been 2259fcf3ce44SJohn Forte * allocated for one entry. If more than one entry should be 2260fcf3ce44SJohn Forte * returned, we will re-issue the entry with the right amount of 2261fcf3ce44SJohn Forte * space allocted 2262fcf3ce44SJohn Forte */ 2263fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_OID_LIST_GET, iscsiConnList) != 0) { 2264fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2265fcf3ce44SJohn Forte "ISCSI_CONN_OID_LIST_GET ioctl failed, errno: %d", errno); 2266fcf3ce44SJohn Forte *ppConnList = NULL; 2267fcf3ce44SJohn Forte (void) close(fd); 2268fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2269fcf3ce44SJohn Forte } 2270fcf3ce44SJohn Forte if (iscsiConnList->cl_out_cnt > 1) { 2271fcf3ce44SJohn Forte out_cnt = iscsiConnList->cl_out_cnt; 2272fcf3ce44SJohn Forte free(iscsiConnList); 2273fcf3ce44SJohn Forte 2274fcf3ce44SJohn Forte allocLen = sizeof (iscsi_conn_list_t); 2275fcf3ce44SJohn Forte allocLen += (sizeof (iscsi_if_conn_t) * out_cnt - 1); 2276fcf3ce44SJohn Forte iscsiConnList = (iscsi_conn_list_t *)calloc(1, allocLen); 2277fcf3ce44SJohn Forte if (iscsiConnList == NULL) { 2278fcf3ce44SJohn Forte *ppConnList = NULL; 2279fcf3ce44SJohn Forte (void) close(fd); 2280fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2281fcf3ce44SJohn Forte } 2282fcf3ce44SJohn Forte iscsiConnList->cl_vers = ISCSI_INTERFACE_VERSION; 2283fcf3ce44SJohn Forte iscsiConnList->cl_in_cnt = out_cnt; 2284fcf3ce44SJohn Forte if (sessOid == NULL) { 2285fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_TRUE; 2286fcf3ce44SJohn Forte } else { 2287fcf3ce44SJohn Forte iscsiConnList->cl_all_sess = B_FALSE; 2288fcf3ce44SJohn Forte iscsiConnList->cl_sess_oid = 2289fcf3ce44SJohn Forte (uint32_t)sessOid->objectSequenceNumber; 2290fcf3ce44SJohn Forte } 2291fcf3ce44SJohn Forte /* Issue the same ioctl again to obtain all the OIDs */ 2292fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_OID_LIST_GET, iscsiConnList) != 0) { 2293fcf3ce44SJohn Forte 2294fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2295fcf3ce44SJohn Forte "ISCSI_CONN_OID_LIST_GET ioctl failed, errno: %d", 2296fcf3ce44SJohn Forte errno); 2297fcf3ce44SJohn Forte *ppConnList = NULL; 2298fcf3ce44SJohn Forte free(iscsiConnList); 2299fcf3ce44SJohn Forte (void) close(fd); 2300fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2301fcf3ce44SJohn Forte 2302fcf3ce44SJohn Forte } 2303fcf3ce44SJohn Forte 2304fcf3ce44SJohn Forte if (out_cnt < iscsiConnList->cl_out_cnt) { 2305fcf3ce44SJohn Forte /* 2306fcf3ce44SJohn Forte * The connection list grew between the first and second 2307fcf3ce44SJohn Forte * ioctls. 2308fcf3ce44SJohn Forte */ 2309fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2310fcf3ce44SJohn Forte "The connection list has grown. There could be " 2311fcf3ce44SJohn Forte "more connections than listed."); 2312fcf3ce44SJohn Forte } 2313fcf3ce44SJohn Forte } 2314fcf3ce44SJohn Forte 2315fcf3ce44SJohn Forte 2316fcf3ce44SJohn Forte (void) close(fd); 2317fcf3ce44SJohn Forte *ppConnList = iscsiConnList; 2318fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2319fcf3ce44SJohn Forte } 2320fcf3ce44SJohn Forte 2321fcf3ce44SJohn Forte /* 2322fcf3ce44SJohn Forte * getConnProps - 2323fcf3ce44SJohn Forte */ 2324fcf3ce44SJohn Forte static IMA_STATUS getConnProps( 2325fcf3ce44SJohn Forte iscsi_if_conn_t *pConn, 2326fcf3ce44SJohn Forte iscsi_conn_props_t **ppConnProps 2327fcf3ce44SJohn Forte ) 2328fcf3ce44SJohn Forte { 2329fcf3ce44SJohn Forte iscsi_conn_props_t *iscsiConnProps; 2330fcf3ce44SJohn Forte int fd; 2331fcf3ce44SJohn Forte int status; 2332fcf3ce44SJohn Forte 2333fcf3ce44SJohn Forte /* We try to open the driver. */ 2334fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2335fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2336fcf3ce44SJohn Forte } 2337fcf3ce44SJohn Forte 2338fcf3ce44SJohn Forte iscsiConnProps = (iscsi_conn_props_t *)calloc(1, 2339fcf3ce44SJohn Forte sizeof (*iscsiConnProps)); 2340fcf3ce44SJohn Forte 2341fcf3ce44SJohn Forte if (iscsiConnProps == NULL) { 2342fcf3ce44SJohn Forte (void) close(fd); 2343fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2344fcf3ce44SJohn Forte } 2345fcf3ce44SJohn Forte 2346fcf3ce44SJohn Forte iscsiConnProps->cp_vers = ISCSI_INTERFACE_VERSION; 2347fcf3ce44SJohn Forte iscsiConnProps->cp_oid = pConn->c_oid; 2348fcf3ce44SJohn Forte iscsiConnProps->cp_cid = pConn->c_cid; 2349fcf3ce44SJohn Forte iscsiConnProps->cp_sess_oid = pConn->c_sess_oid; 2350fcf3ce44SJohn Forte 2351fcf3ce44SJohn Forte /* The IOCTL is submitted. */ 2352fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CONN_PROPS_GET, iscsiConnProps) != 0) { 2353fcf3ce44SJohn Forte /* IOCTL failed */ 2354fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2355fcf3ce44SJohn Forte "ISCSI_AUTH_CLEAR ioctl failed, errno: %d", errno); 2356fcf3ce44SJohn Forte free(iscsiConnProps); 2357fcf3ce44SJohn Forte (void) close(fd); 2358fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2359fcf3ce44SJohn Forte } 2360fcf3ce44SJohn Forte (void) close(fd); 2361fcf3ce44SJohn Forte *ppConnProps = iscsiConnProps; 2362fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2363fcf3ce44SJohn Forte } 2364fcf3ce44SJohn Forte 2365fcf3ce44SJohn Forte /* A helper function to set authentication method. */ 2366fcf3ce44SJohn Forte static IMA_STATUS 2367fcf3ce44SJohn Forte setAuthMethods( 2368fcf3ce44SJohn Forte IMA_OID oid, 2369fcf3ce44SJohn Forte IMA_UINT *pMethodCount, 2370fcf3ce44SJohn Forte const IMA_AUTHMETHOD *pMethodList 2371fcf3ce44SJohn Forte ) 2372fcf3ce44SJohn Forte { 2373fcf3ce44SJohn Forte int fd; 2374fcf3ce44SJohn Forte int i; 2375fcf3ce44SJohn Forte int status; 2376fcf3ce44SJohn Forte iscsi_auth_props_t auth; 2377fcf3ce44SJohn Forte 2378fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2379fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2380fcf3ce44SJohn Forte } 2381fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 2382fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 2383fcf3ce44SJohn Forte auth.a_oid = (uint32_t)oid.objectSequenceNumber; 2384fcf3ce44SJohn Forte 2385fcf3ce44SJohn Forte /* 2386fcf3ce44SJohn Forte * Get the current auth fields so they don't need to be reset 2387fcf3ce44SJohn Forte * here. 2388fcf3ce44SJohn Forte */ 2389fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 2390fcf3ce44SJohn Forte /* EMPTY */ 2391fcf3ce44SJohn Forte /* Initializing auth structure with current settings */ 2392fcf3ce44SJohn Forte } 2393fcf3ce44SJohn Forte auth.a_auth_method = authMethodNone; 2394fcf3ce44SJohn Forte 2395fcf3ce44SJohn Forte for (i = 0; i < *pMethodCount; i++) { 2396fcf3ce44SJohn Forte switch (pMethodList[i]) { 2397fcf3ce44SJohn Forte case IMA_AUTHMETHOD_CHAP: 2398fcf3ce44SJohn Forte auth.a_auth_method |= authMethodCHAP; 2399fcf3ce44SJohn Forte break; 2400fcf3ce44SJohn Forte default: 2401fcf3ce44SJohn Forte break; 2402fcf3ce44SJohn Forte } 2403fcf3ce44SJohn Forte } 2404fcf3ce44SJohn Forte 2405fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) { 2406fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2407fcf3ce44SJohn Forte "ISCSI_AUTH_SET failed, errno: %d", errno); 2408fcf3ce44SJohn Forte (void) close(fd); 2409fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2410fcf3ce44SJohn Forte } 2411fcf3ce44SJohn Forte 2412fcf3ce44SJohn Forte (void) close(fd); 2413fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2414fcf3ce44SJohn Forte } 2415fcf3ce44SJohn Forte 2416fcf3ce44SJohn Forte /* A helper function to set authentication method. */ 2417fcf3ce44SJohn Forte static IMA_STATUS getAuthMethods( 2418fcf3ce44SJohn Forte IMA_OID oid, 2419fcf3ce44SJohn Forte IMA_UINT *pMethodCount, 2420fcf3ce44SJohn Forte IMA_AUTHMETHOD *pMethodList 2421fcf3ce44SJohn Forte ) 2422fcf3ce44SJohn Forte { 2423fcf3ce44SJohn Forte int fd; 2424fcf3ce44SJohn Forte int status; 2425fcf3ce44SJohn Forte iscsi_auth_props_t auth; 2426fcf3ce44SJohn Forte 2427fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2428fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2429fcf3ce44SJohn Forte } 2430fcf3ce44SJohn Forte 2431fcf3ce44SJohn Forte (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 2432fcf3ce44SJohn Forte auth.a_vers = ISCSI_INTERFACE_VERSION; 2433fcf3ce44SJohn Forte auth.a_oid = (uint32_t)oid.objectSequenceNumber; 2434fcf3ce44SJohn Forte 2435fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 2436fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2437fcf3ce44SJohn Forte "ISCSI_AUTH_GET failed, errno: %d", errno); 2438fcf3ce44SJohn Forte (void) close(fd); 2439fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2440fcf3ce44SJohn Forte } 2441fcf3ce44SJohn Forte 2442fcf3ce44SJohn Forte if (auth.a_auth_method == authMethodNone) { 2443fcf3ce44SJohn Forte pMethodList[0] = IMA_AUTHMETHOD_NONE; 2444fcf3ce44SJohn Forte *pMethodCount = 1; 2445fcf3ce44SJohn Forte } else { 2446fcf3ce44SJohn Forte int i = 0; 2447fcf3ce44SJohn Forte if (!((auth.a_auth_method & authMethodCHAP)^authMethodCHAP)) { 2448fcf3ce44SJohn Forte pMethodList[i++] = IMA_AUTHMETHOD_CHAP; 2449fcf3ce44SJohn Forte } 2450fcf3ce44SJohn Forte *pMethodCount = i; 2451fcf3ce44SJohn Forte } 2452fcf3ce44SJohn Forte 2453fcf3ce44SJohn Forte (void) close(fd); 2454fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2455fcf3ce44SJohn Forte } 2456fcf3ce44SJohn Forte 2457fcf3ce44SJohn Forte /* Helper function to open driver */ 2458fcf3ce44SJohn Forte int open_driver( 2459fcf3ce44SJohn Forte int *fd 2460fcf3ce44SJohn Forte ) 2461fcf3ce44SJohn Forte { 2462fcf3ce44SJohn Forte int ret = 0; 2463fcf3ce44SJohn Forte if ((*fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 2464fcf3ce44SJohn Forte ret = errno; 2465fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 2466fcf3ce44SJohn Forte ISCSI_DRIVER_DEVCTL, ret); 2467fcf3ce44SJohn Forte } 2468fcf3ce44SJohn Forte return (ret); 2469fcf3ce44SJohn Forte } 2470fcf3ce44SJohn Forte 2471fcf3ce44SJohn Forte /* 2472fcf3ce44SJohn Forte * Iscsi driver does not support OID for discovery address. Create 2473fcf3ce44SJohn Forte * a modified version of IMA_RemoveDiscoveryAddress that takes 2474fcf3ce44SJohn Forte * discoveryAddress (instead of an OID) as input argument. 2475fcf3ce44SJohn Forte */ 2476fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_RemoveDiscoveryAddress( 2477fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS discoveryAddress 2478fcf3ce44SJohn Forte ) 2479fcf3ce44SJohn Forte { 2480fcf3ce44SJohn Forte entry_t entry; 2481fcf3ce44SJohn Forte int fd; 2482fcf3ce44SJohn Forte int status, i, addr_list_size, insize; 2483fcf3ce44SJohn Forte iscsi_addr_list_t *idlp, al_info; 2484fcf3ce44SJohn Forte iscsi_addr_t *matched_addr = NULL; 2485fcf3ce44SJohn Forte 2486fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2487fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2488fcf3ce44SJohn Forte } 2489fcf3ce44SJohn Forte 2490fcf3ce44SJohn Forte if (prepare_discovery_entry(discoveryAddress, &entry) != 2491fcf3ce44SJohn Forte DISC_ADDR_OK) { 2492fcf3ce44SJohn Forte (void) close(fd); 2493fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2494fcf3ce44SJohn Forte } 2495fcf3ce44SJohn Forte 2496fcf3ce44SJohn Forte (void) memset(&al_info, 0, sizeof (al_info)); 2497fcf3ce44SJohn Forte al_info.al_vers = ISCSI_INTERFACE_VERSION; 2498fcf3ce44SJohn Forte al_info.al_in_cnt = 0; 2499fcf3ce44SJohn Forte /* 2500fcf3ce44SJohn Forte * Issue ioctl to get the number of discovery address. 2501fcf3ce44SJohn Forte */ 2502fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 2503fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2504fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 2505fcf3ce44SJohn Forte ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 2506fcf3ce44SJohn Forte (void) close(fd); 2507fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2508fcf3ce44SJohn Forte } 2509fcf3ce44SJohn Forte 2510fcf3ce44SJohn Forte if (al_info.al_out_cnt == 0) { 2511fcf3ce44SJohn Forte (void) close(fd); 2512fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 2513fcf3ce44SJohn Forte } 2514fcf3ce44SJohn Forte 2515fcf3ce44SJohn Forte addr_list_size = sizeof (iscsi_addr_list_t); 2516fcf3ce44SJohn Forte if (al_info.al_out_cnt > 1) { 2517fcf3ce44SJohn Forte addr_list_size += (sizeof (iscsi_addr_t) * 2518fcf3ce44SJohn Forte (al_info.al_out_cnt - 1)); 2519fcf3ce44SJohn Forte } 2520fcf3ce44SJohn Forte 2521fcf3ce44SJohn Forte idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size); 2522fcf3ce44SJohn Forte if (idlp == NULL) { 2523fcf3ce44SJohn Forte (void) close(fd); 2524fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2525fcf3ce44SJohn Forte } 2526fcf3ce44SJohn Forte 2527fcf3ce44SJohn Forte idlp->al_vers = ISCSI_INTERFACE_VERSION; 2528fcf3ce44SJohn Forte idlp->al_in_cnt = al_info.al_out_cnt; 2529fcf3ce44SJohn Forte 2530fcf3ce44SJohn Forte /* issue the same ioctl to get all the discovery addresses */ 2531fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) { 2532fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2533fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 2534fcf3ce44SJohn Forte ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 2535fcf3ce44SJohn Forte free(idlp); 2536fcf3ce44SJohn Forte (void) close(fd); 2537fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2538fcf3ce44SJohn Forte } 2539fcf3ce44SJohn Forte 2540fcf3ce44SJohn Forte /* 2541fcf3ce44SJohn Forte * find the matched discovery address 2542fcf3ce44SJohn Forte */ 2543fcf3ce44SJohn Forte for (i = 0; i < idlp->al_out_cnt; i++) { 2544fcf3ce44SJohn Forte insize = idlp->al_addrs[i].a_addr.i_insize; 2545fcf3ce44SJohn Forte if (insize != entry.e_insize) { 2546fcf3ce44SJohn Forte continue; 2547fcf3ce44SJohn Forte } 2548fcf3ce44SJohn Forte if (insize == sizeof (struct in_addr)) { 2549fcf3ce44SJohn Forte if (idlp->al_addrs[i].a_addr.i_addr.in4.s_addr == 2550fcf3ce44SJohn Forte entry.e_u.u_in4.s_addr) { 2551fcf3ce44SJohn Forte matched_addr = &(idlp->al_addrs[i]); 2552fcf3ce44SJohn Forte break; 2553fcf3ce44SJohn Forte } 2554fcf3ce44SJohn Forte } 2555fcf3ce44SJohn Forte if (insize == sizeof (struct in6_addr)) { 2556fcf3ce44SJohn Forte if (bcmp(entry.e_u.u_in6.s6_addr, 2557fcf3ce44SJohn Forte idlp->al_addrs[i].a_addr.i_addr.in6.s6_addr, 2558fcf3ce44SJohn Forte insize) == 0) { 2559fcf3ce44SJohn Forte matched_addr = &(idlp->al_addrs[i]); 2560fcf3ce44SJohn Forte break; 2561fcf3ce44SJohn Forte } 2562fcf3ce44SJohn Forte } 2563fcf3ce44SJohn Forte } 2564fcf3ce44SJohn Forte 2565fcf3ce44SJohn Forte free(idlp); 2566fcf3ce44SJohn Forte 2567fcf3ce44SJohn Forte if (matched_addr == NULL) { 2568fcf3ce44SJohn Forte (void) close(fd); 2569fcf3ce44SJohn Forte return (IMA_ERROR_OBJECT_NOT_FOUND); 2570fcf3ce44SJohn Forte } 2571fcf3ce44SJohn Forte 2572fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_DISCOVERY_ADDR_CLEAR, &entry)) { 2573fcf3ce44SJohn Forte status = errno; 2574fcf3ce44SJohn Forte (void) close(fd); 2575fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2576fcf3ce44SJohn Forte "ISCSI_DISCOVERY_ADDR_CLEAR ioctl failed, errno: %d", 2577fcf3ce44SJohn Forte errno); 2578fcf3ce44SJohn Forte if (status == EBUSY) { 2579fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 2580fcf3ce44SJohn Forte } else { 2581fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2582fcf3ce44SJohn Forte } 2583fcf3ce44SJohn Forte } 2584fcf3ce44SJohn Forte 2585fcf3ce44SJohn Forte (void) close(fd); 2586fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2587fcf3ce44SJohn Forte } 2588fcf3ce44SJohn Forte 2589fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_SetTargetAuthMethods( 2590fcf3ce44SJohn Forte IMA_OID targetOid, 2591fcf3ce44SJohn Forte IMA_UINT *methodCount, 2592fcf3ce44SJohn Forte const IMA_AUTHMETHOD *pMethodList 2593fcf3ce44SJohn Forte ) 2594fcf3ce44SJohn Forte { 2595fcf3ce44SJohn Forte return (setAuthMethods(targetOid, methodCount, pMethodList)); 2596fcf3ce44SJohn Forte } 2597fcf3ce44SJohn Forte 2598fcf3ce44SJohn Forte IMA_STATUS getNegotiatedDigest( 2599fcf3ce44SJohn Forte int digestType, 2600fcf3ce44SJohn Forte SUN_IMA_DIGEST_ALGORITHM_VALUE *algorithm, 2601fcf3ce44SJohn Forte SUN_IMA_CONN_PROPERTIES *connProps) { 2602fcf3ce44SJohn Forte 2603fcf3ce44SJohn Forte IMA_UINT digest; 2604fcf3ce44SJohn Forte 2605fcf3ce44SJohn Forte if (connProps->valuesValid == IMA_TRUE) { 2606fcf3ce44SJohn Forte algorithm->negotiatedValid = IMA_TRUE; 2607fcf3ce44SJohn Forte 2608fcf3ce44SJohn Forte if (digestType == ISCSI_LOGIN_PARAM_HEADER_DIGEST) { 2609fcf3ce44SJohn Forte digest = connProps->headerDigest; 2610fcf3ce44SJohn Forte } else { 2611fcf3ce44SJohn Forte digest = connProps->dataDigest; 2612fcf3ce44SJohn Forte } 2613fcf3ce44SJohn Forte 2614fcf3ce44SJohn Forte switch (digest) { 2615fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE: 2616fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2617fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2618fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 1; 2619fcf3ce44SJohn Forte break; 2620fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C: 2621fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2622fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2623fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 1; 2624fcf3ce44SJohn Forte break; 2625fcf3ce44SJohn Forte 2626fcf3ce44SJohn Forte case ISCSI_DIGEST_CRC32C_NONE: 2627fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2628fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2629fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[1] = 2630fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2631fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 2; 2632fcf3ce44SJohn Forte break; 2633fcf3ce44SJohn Forte case ISCSI_DIGEST_NONE_CRC32C: 2634fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[0] = 2635fcf3ce44SJohn Forte ISCSI_DIGEST_NONE; 2636fcf3ce44SJohn Forte algorithm->negotiatedAlgorithms[1] = 2637fcf3ce44SJohn Forte ISCSI_DIGEST_CRC32C; 2638fcf3ce44SJohn Forte algorithm->negotiatedAlgorithmCount = 2; 2639fcf3ce44SJohn Forte break; 2640fcf3ce44SJohn Forte default: 2641fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2642fcf3ce44SJohn Forte "Invalid negotiated digest: %d", 2643fcf3ce44SJohn Forte digest); 2644fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2645fcf3ce44SJohn Forte } 2646fcf3ce44SJohn Forte } else { 2647fcf3ce44SJohn Forte algorithm->negotiatedValid = IMA_FALSE; 2648fcf3ce44SJohn Forte } 2649fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2650fcf3ce44SJohn Forte } 2651fcf3ce44SJohn Forte 2652fcf3ce44SJohn Forte /* 2653fcf3ce44SJohn Forte * Non-IMA defined function. 2654fcf3ce44SJohn Forte */ 2655fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetISNSServerAddressPropertiesList( 2656fcf3ce44SJohn Forte SUN_IMA_DISC_ADDR_PROP_LIST **ppList 2657fcf3ce44SJohn Forte ) 2658fcf3ce44SJohn Forte { 2659fcf3ce44SJohn Forte char isns_server_addr_str[256]; 2660fcf3ce44SJohn Forte int fd; 2661fcf3ce44SJohn Forte int i; 2662fcf3ce44SJohn Forte int isns_server_addr_list_size; 2663fcf3ce44SJohn Forte int status; 2664fcf3ce44SJohn Forte int out_cnt; 2665fcf3ce44SJohn Forte iscsi_addr_list_t *ialp; 2666fcf3ce44SJohn Forte /* LINTED */ 2667fcf3ce44SJohn Forte IMA_IP_ADDRESS *ipAddr; 2668fcf3ce44SJohn Forte 2669fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2670fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2671fcf3ce44SJohn Forte } 2672fcf3ce44SJohn Forte 2673fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, sizeof (iscsi_addr_list_t)); 2674fcf3ce44SJohn Forte if (ialp == NULL) { 2675fcf3ce44SJohn Forte (void) close(fd); 2676fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2677fcf3ce44SJohn Forte } 2678fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 2679fcf3ce44SJohn Forte ialp->al_in_cnt = ialp->al_out_cnt = 1; 2680fcf3ce44SJohn Forte 2681fcf3ce44SJohn Forte /* 2682fcf3ce44SJohn Forte * Issue ioctl to retrieve the isns server addresses. Space has been 2683fcf3ce44SJohn Forte * allocted for one entry. If more than one entry should be returned, 2684fcf3ce44SJohn Forte * we will re-issue the entry with the right amount of space allocted 2685fcf3ce44SJohn Forte */ 2686fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_LIST_GET, ialp) != 0) { 2687fcf3ce44SJohn Forte (void) close(fd); 2688fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2689fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl failed, errno: %d", 2690fcf3ce44SJohn Forte errno); 2691fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2692fcf3ce44SJohn Forte } 2693fcf3ce44SJohn Forte 2694fcf3ce44SJohn Forte isns_server_addr_list_size = sizeof (iscsi_addr_list_t); 2695fcf3ce44SJohn Forte if (ialp->al_out_cnt > 1) { 2696fcf3ce44SJohn Forte out_cnt = ialp->al_out_cnt; 2697fcf3ce44SJohn Forte free(ialp); 2698fcf3ce44SJohn Forte 2699fcf3ce44SJohn Forte isns_server_addr_list_size += (sizeof (iscsi_addr_t) * 2700fcf3ce44SJohn Forte out_cnt - 1); 2701fcf3ce44SJohn Forte ialp = (iscsi_addr_list_t *)calloc(1, 2702fcf3ce44SJohn Forte isns_server_addr_list_size); 2703fcf3ce44SJohn Forte if (ialp == NULL) { 2704fcf3ce44SJohn Forte (void) close(fd); 2705fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2706fcf3ce44SJohn Forte } 2707fcf3ce44SJohn Forte ialp->al_vers = ISCSI_INTERFACE_VERSION; 2708fcf3ce44SJohn Forte ialp->al_in_cnt = out_cnt; 2709fcf3ce44SJohn Forte 2710fcf3ce44SJohn Forte /* 2711fcf3ce44SJohn Forte * Issue ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl again to obtain 2712fcf3ce44SJohn Forte * the list of all the iSNS server addresses 2713fcf3ce44SJohn Forte */ 2714fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_LIST_GET, ialp) != 0) { 2715fcf3ce44SJohn Forte free(ialp); 2716fcf3ce44SJohn Forte (void) close(fd); 2717fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2718fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_LIST_GET ioctl failed, " 2719fcf3ce44SJohn Forte "errno: %d", errno); 2720fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2721fcf3ce44SJohn Forte 2722fcf3ce44SJohn Forte } 2723fcf3ce44SJohn Forte } 2724fcf3ce44SJohn Forte 2725fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *)calloc(1, 2726fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) + 2727fcf3ce44SJohn Forte ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES)); 2728fcf3ce44SJohn Forte if (*ppList == NULL) { 2729fcf3ce44SJohn Forte free(ialp); 2730fcf3ce44SJohn Forte (void) close(fd); 2731fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2732fcf3ce44SJohn Forte } 2733fcf3ce44SJohn Forte (*ppList)->discAddrCount = ialp->al_out_cnt; 2734fcf3ce44SJohn Forte 2735fcf3ce44SJohn Forte for (i = 0; i < ialp->al_out_cnt; i++) { 2736fcf3ce44SJohn Forte if (ialp->al_addrs[i].a_addr.i_insize == 2737fcf3ce44SJohn Forte sizeof (struct in_addr)) { 2738fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 2739fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_TRUE; 2740fcf3ce44SJohn Forte } else if (ialp->al_addrs[i].a_addr.i_insize == 2741fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 2742fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 2743fcf3ce44SJohn Forte id.ipAddress.ipv4Address = IMA_FALSE; 2744fcf3ce44SJohn Forte } else { 2745fcf3ce44SJohn Forte (void) strlcpy(isns_server_addr_str, "unknown", 2746fcf3ce44SJohn Forte sizeof (isns_server_addr_str)); 2747fcf3ce44SJohn Forte } 2748fcf3ce44SJohn Forte 2749fcf3ce44SJohn Forte ipAddr = &(*ppList)->props[i].discoveryAddress. 2750fcf3ce44SJohn Forte hostnameIpAddress.id.ipAddress; 2751fcf3ce44SJohn Forte bcopy(&ialp->al_addrs[i].a_addr.i_addr, 2752fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.hostnameIpAddress.id. 2753fcf3ce44SJohn Forte ipAddress.ipAddress, 2754fcf3ce44SJohn Forte sizeof (ipAddr->ipAddress)); 2755fcf3ce44SJohn Forte (*ppList)->props[i].discoveryAddress.portNumber = 2756fcf3ce44SJohn Forte ialp->al_addrs[i].a_port; 2757fcf3ce44SJohn Forte } 2758fcf3ce44SJohn Forte 2759fcf3ce44SJohn Forte free(ialp); 2760fcf3ce44SJohn Forte (void) close(fd); 2761fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2762fcf3ce44SJohn Forte } 2763fcf3ce44SJohn Forte 2764fcf3ce44SJohn Forte /*ARGSUSED*/ 2765fcf3ce44SJohn Forte /* 2766fcf3ce44SJohn Forte * Remove iSNS Server Address 2767fcf3ce44SJohn Forte */ 2768fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_RemoveISNSServerAddress( 2769fcf3ce44SJohn Forte SUN_IMA_TARGET_ADDRESS isnsServerAddress 2770fcf3ce44SJohn Forte ) 2771fcf3ce44SJohn Forte { 2772fcf3ce44SJohn Forte entry_t entry; 2773fcf3ce44SJohn Forte int fd, status; 2774fcf3ce44SJohn Forte 2775fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2776fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2777fcf3ce44SJohn Forte } 2778fcf3ce44SJohn Forte 2779fcf3ce44SJohn Forte if (prepare_discovery_entry(isnsServerAddress, &entry) != 2780fcf3ce44SJohn Forte DISC_ADDR_OK) { 2781fcf3ce44SJohn Forte (void) close(fd); 2782fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2783fcf3ce44SJohn Forte } 2784fcf3ce44SJohn Forte 2785fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_CLEAR, &entry)) { 2786fcf3ce44SJohn Forte status = errno; 2787fcf3ce44SJohn Forte (void) close(fd); 2788fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2789fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_CLEAR ioctl failed, errno: %d", 2790fcf3ce44SJohn Forte status); 2791fcf3ce44SJohn Forte if (status == EBUSY) { 2792fcf3ce44SJohn Forte return (IMA_ERROR_LU_IN_USE); 2793fcf3ce44SJohn Forte } else { 2794fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2795fcf3ce44SJohn Forte } 2796fcf3ce44SJohn Forte } 2797fcf3ce44SJohn Forte 2798fcf3ce44SJohn Forte (void) close(fd); 2799fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2800fcf3ce44SJohn Forte } 2801fcf3ce44SJohn Forte 2802fcf3ce44SJohn Forte /*ARGSUSED*/ 2803fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_AddISNSServerAddress( 2804fcf3ce44SJohn Forte const SUN_IMA_TARGET_ADDRESS isnsServerAddress 2805fcf3ce44SJohn Forte ) 2806fcf3ce44SJohn Forte { 2807fcf3ce44SJohn Forte entry_t entry; 2808fcf3ce44SJohn Forte int fd; 2809fcf3ce44SJohn Forte int status; 2810fcf3ce44SJohn Forte 2811fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2812fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2813fcf3ce44SJohn Forte } 2814fcf3ce44SJohn Forte 2815fcf3ce44SJohn Forte if (prepare_discovery_entry(isnsServerAddress, &entry) != 2816fcf3ce44SJohn Forte DISC_ADDR_OK) { 2817fcf3ce44SJohn Forte (void) close(fd); 2818fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2819fcf3ce44SJohn Forte } 2820fcf3ce44SJohn Forte 2821fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_ADDR_SET, &entry)) { 2822fcf3ce44SJohn Forte /* 2823fcf3ce44SJohn Forte * Encountered problem setting the discovery address. 2824fcf3ce44SJohn Forte */ 2825fcf3ce44SJohn Forte (void) close(fd); 2826fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2827fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_ADDR_SET ioctl failed, errno: %d", 2828fcf3ce44SJohn Forte errno); 2829fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2830fcf3ce44SJohn Forte } 2831fcf3ce44SJohn Forte 2832fcf3ce44SJohn Forte (void) close(fd); 2833fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2834fcf3ce44SJohn Forte } 2835fcf3ce44SJohn Forte 2836fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_RetrieveISNSServerTargets( 2837fcf3ce44SJohn Forte IMA_TARGET_ADDRESS serverAddress, 2838fcf3ce44SJohn Forte SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList 2839fcf3ce44SJohn Forte ) 2840fcf3ce44SJohn Forte { 2841fcf3ce44SJohn Forte int fd; 2842fcf3ce44SJohn Forte int ctr; 2843fcf3ce44SJohn Forte int server_pg_list_sz; 2844fcf3ce44SJohn Forte int status; 2845fcf3ce44SJohn Forte isns_server_portal_group_list_t *server_pg_list = NULL; 2846fcf3ce44SJohn Forte isns_portal_group_list_t *pg_list = NULL; 2847fcf3ce44SJohn Forte IMA_BOOL retry = IMA_TRUE; 2848fcf3ce44SJohn Forte entry_t entry; 2849fcf3ce44SJohn Forte 2850fcf3ce44SJohn Forte #define ISNS_SERVER_DEFAULT_NUM_TARGETS 50 2851fcf3ce44SJohn Forte 2852fcf3ce44SJohn Forte server_pg_list_sz = sizeof (*server_pg_list) + 2853fcf3ce44SJohn Forte ((ISNS_SERVER_DEFAULT_NUM_TARGETS - 1) * 2854fcf3ce44SJohn Forte sizeof (isns_portal_group_t)); 2855fcf3ce44SJohn Forte 2856fcf3ce44SJohn Forte server_pg_list = (isns_server_portal_group_list_t *)calloc(1, 2857fcf3ce44SJohn Forte server_pg_list_sz); 2858fcf3ce44SJohn Forte if (server_pg_list == NULL) { 2859fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2860fcf3ce44SJohn Forte } 2861fcf3ce44SJohn Forte server_pg_list->addr_port_list.pg_in_cnt = 2862fcf3ce44SJohn Forte ISNS_SERVER_DEFAULT_NUM_TARGETS; 2863fcf3ce44SJohn Forte 2864fcf3ce44SJohn Forte if ((prepare_discovery_entry_IMA(serverAddress, &entry) 2865fcf3ce44SJohn Forte != DISC_ADDR_OK)) { 2866fcf3ce44SJohn Forte free(server_pg_list); 2867fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2868fcf3ce44SJohn Forte } 2869fcf3ce44SJohn Forte server_pg_list->addr.a_port = entry.e_port; 2870fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_insize = entry.e_insize; 2871fcf3ce44SJohn Forte if (entry.e_insize == sizeof (struct in_addr)) { 2872fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_addr.in4.s_addr = 2873fcf3ce44SJohn Forte (entry.e_u.u_in4.s_addr); 2874fcf3ce44SJohn Forte } else if (entry.e_insize == sizeof (struct in6_addr)) { 2875fcf3ce44SJohn Forte bcopy(&entry.e_u.u_in6.s6_addr, 2876fcf3ce44SJohn Forte server_pg_list->addr.a_addr.i_addr.in6.s6_addr, 16); 2877fcf3ce44SJohn Forte } 2878fcf3ce44SJohn Forte 2879fcf3ce44SJohn Forte if ((status = open_driver(&fd))) { 2880fcf3ce44SJohn Forte free(server_pg_list); 2881fcf3ce44SJohn Forte return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 2882fcf3ce44SJohn Forte } 2883fcf3ce44SJohn Forte 2884fcf3ce44SJohn Forte retry_isns: 2885fcf3ce44SJohn Forte /* 2886fcf3ce44SJohn Forte * Issue ioctl to obtain the ISNS Portal Group List list 2887fcf3ce44SJohn Forte */ 2888fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_ISNS_SERVER_GET, server_pg_list) != 0) { 2889fcf3ce44SJohn Forte int tmp_errno = errno; 2890fcf3ce44SJohn Forte IMA_STATUS return_status; 2891fcf3ce44SJohn Forte 2892fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2893fcf3ce44SJohn Forte "ISCSI_ISNS_SERVER_GET ioctl failed, errno: %d", tmp_errno); 2894fcf3ce44SJohn Forte if (tmp_errno == EACCES) { 2895fcf3ce44SJohn Forte return_status = IMA_ERROR_OBJECT_NOT_FOUND; 2896fcf3ce44SJohn Forte } else { 2897fcf3ce44SJohn Forte return_status = IMA_ERROR_UNEXPECTED_OS_ERROR; 2898fcf3ce44SJohn Forte } 2899fcf3ce44SJohn Forte (void) close(fd); 2900fcf3ce44SJohn Forte free(server_pg_list); 2901fcf3ce44SJohn Forte return (return_status); 2902fcf3ce44SJohn Forte } 2903fcf3ce44SJohn Forte pg_list = &server_pg_list->addr_port_list; 2904fcf3ce44SJohn Forte 2905fcf3ce44SJohn Forte /* check if all targets received */ 2906fcf3ce44SJohn Forte if (pg_list->pg_in_cnt < pg_list->pg_out_cnt) { 2907fcf3ce44SJohn Forte if (retry == IMA_TRUE) { 2908fcf3ce44SJohn Forte server_pg_list_sz = sizeof (*server_pg_list) + 2909fcf3ce44SJohn Forte ((pg_list->pg_out_cnt - 1) * 2910fcf3ce44SJohn Forte sizeof (isns_server_portal_group_list_t)); 2911fcf3ce44SJohn Forte server_pg_list = (isns_server_portal_group_list_t *) 2912fcf3ce44SJohn Forte realloc(server_pg_list, server_pg_list_sz); 2913fcf3ce44SJohn Forte if (server_pg_list == NULL) { 2914fcf3ce44SJohn Forte (void) close(fd); 2915fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2916fcf3ce44SJohn Forte } 2917fcf3ce44SJohn Forte pg_list = &server_pg_list->addr_port_list; 2918fcf3ce44SJohn Forte pg_list->pg_in_cnt = pg_list->pg_out_cnt; 2919fcf3ce44SJohn Forte retry = IMA_FALSE; 2920fcf3ce44SJohn Forte goto retry_isns; 2921fcf3ce44SJohn Forte } else { 2922fcf3ce44SJohn Forte /* 2923fcf3ce44SJohn Forte * don't retry after 2 attempts. The target list 2924fcf3ce44SJohn Forte * shouldn't continue growing. Just continue 2925fcf3ce44SJohn Forte * on and display what was found. 2926fcf3ce44SJohn Forte */ 2927fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 2928fcf3ce44SJohn Forte "ISCSI_SENDTGTS_GET overflow: " 2929fcf3ce44SJohn Forte "failed to obtain all targets"); 2930fcf3ce44SJohn Forte pg_list->pg_out_cnt = pg_list->pg_in_cnt; 2931fcf3ce44SJohn Forte } 2932fcf3ce44SJohn Forte } 2933fcf3ce44SJohn Forte 2934fcf3ce44SJohn Forte (void) close(fd); 2935fcf3ce44SJohn Forte 2936fcf3ce44SJohn Forte /* allocate for caller return buffer */ 2937fcf3ce44SJohn Forte *ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1, 2938fcf3ce44SJohn Forte sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) + 2939fcf3ce44SJohn Forte pg_list->pg_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY)); 2940fcf3ce44SJohn Forte if (*ppList == NULL) { 2941fcf3ce44SJohn Forte free(server_pg_list); 2942fcf3ce44SJohn Forte return (IMA_ERROR_INSUFFICIENT_MEMORY); 2943fcf3ce44SJohn Forte } 2944fcf3ce44SJohn Forte 2945fcf3ce44SJohn Forte (*ppList)->keyCount = pg_list->pg_out_cnt; 2946fcf3ce44SJohn Forte 2947fcf3ce44SJohn Forte for (ctr = 0; ctr < pg_list->pg_out_cnt; ctr++) { 2948fcf3ce44SJohn Forte (void) mbstowcs((*ppList)->keys[ctr].name, 2949fcf3ce44SJohn Forte (char *)pg_list->pg_list[ctr].pg_iscsi_name, 2950fcf3ce44SJohn Forte IMA_NODE_NAME_LEN); 2951fcf3ce44SJohn Forte 2952fcf3ce44SJohn Forte (*ppList)->keys[ctr].tpgt = pg_list->pg_list[ctr].pg_tag; 2953fcf3ce44SJohn Forte 2954fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.portNumber = 2955fcf3ce44SJohn Forte pg_list->pg_list[ctr].pg_port; 2956fcf3ce44SJohn Forte 2957fcf3ce44SJohn Forte if (pg_list->pg_list[ctr].insize == sizeof (struct in_addr)) { 2958fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 2959fcf3ce44SJohn Forte IMA_TRUE; 2960fcf3ce44SJohn Forte } else if (pg_list->pg_list[ctr].insize == 2961fcf3ce44SJohn Forte sizeof (struct in6_addr)) { 2962fcf3ce44SJohn Forte (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 2963fcf3ce44SJohn Forte IMA_FALSE; 2964fcf3ce44SJohn Forte } else { 2965fcf3ce44SJohn Forte free(pg_list); 2966fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2967fcf3ce44SJohn Forte } 2968fcf3ce44SJohn Forte 2969fcf3ce44SJohn Forte (void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress, 2970fcf3ce44SJohn Forte &(pg_list->pg_list[ctr].pg_ip_addr), 2971fcf3ce44SJohn Forte pg_list->pg_list[ctr].insize); 2972fcf3ce44SJohn Forte } 2973fcf3ce44SJohn Forte free(server_pg_list); 2974fcf3ce44SJohn Forte 2975fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 2976fcf3ce44SJohn Forte } 2977fcf3ce44SJohn Forte 2978fcf3ce44SJohn Forte /* ARGSUSED */ 2979fcf3ce44SJohn Forte IMA_STATUS SUN_IMA_GetSessionOidList( 2980fcf3ce44SJohn Forte IMA_OID initiatorOid, 2981fcf3ce44SJohn Forte IMA_OID_LIST **ppList 2982fcf3ce44SJohn Forte ) 2983fcf3ce44SJohn Forte { 2984fcf3ce44SJohn Forte return (get_target_oid_list(ISCSI_TGT_OID_LIST, ppList)); 2985fcf3ce44SJohn Forte } 2986fcf3ce44SJohn Forte 2987fcf3ce44SJohn Forte /*ARGSUSED*/ 2988fcf3ce44SJohn Forte IMA_API IMA_STATUS SUN_IMA_GetTargetAuthParms( 2989fcf3ce44SJohn Forte IMA_OID oid, 2990fcf3ce44SJohn Forte IMA_AUTHMETHOD method, 2991fcf3ce44SJohn Forte IMA_INITIATOR_AUTHPARMS *pParms 2992fcf3ce44SJohn Forte ) 2993fcf3ce44SJohn Forte { 2994fcf3ce44SJohn Forte int fd; 2995fcf3ce44SJohn Forte iscsi_chap_props_t chap_p; 2996fcf3ce44SJohn Forte 2997fcf3ce44SJohn Forte if (pParms == NULL) { 2998fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 2999fcf3ce44SJohn Forte } 3000fcf3ce44SJohn Forte 3001fcf3ce44SJohn Forte if (oid.objectType != IMA_OBJECT_TYPE_TARGET) { 3002fcf3ce44SJohn Forte return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 3003fcf3ce44SJohn Forte } 3004fcf3ce44SJohn Forte 3005fcf3ce44SJohn Forte if (method != IMA_AUTHMETHOD_CHAP) { 3006fcf3ce44SJohn Forte return (IMA_ERROR_INVALID_PARAMETER); 3007fcf3ce44SJohn Forte } 3008fcf3ce44SJohn Forte 3009fcf3ce44SJohn Forte if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3010fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 3011fcf3ce44SJohn Forte ISCSI_DRIVER_DEVCTL, errno); 3012fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3013fcf3ce44SJohn Forte } 3014fcf3ce44SJohn Forte 3015fcf3ce44SJohn Forte (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 3016fcf3ce44SJohn Forte chap_p.c_vers = ISCSI_INTERFACE_VERSION; 3017fcf3ce44SJohn Forte chap_p.c_oid = (uint32_t)oid.objectSequenceNumber; 3018fcf3ce44SJohn Forte 3019fcf3ce44SJohn Forte if (ioctl(fd, ISCSI_CHAP_GET, &chap_p) != 0) { 3020fcf3ce44SJohn Forte syslog(LOG_USER|LOG_DEBUG, 3021fcf3ce44SJohn Forte 3022fcf3ce44SJohn Forte "ISCSI_CHAP_GET ioctl failed, errno: %d", 3023fcf3ce44SJohn Forte errno); 3024fcf3ce44SJohn Forte (void) close(fd); 3025fcf3ce44SJohn Forte return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3026fcf3ce44SJohn Forte } 3027fcf3ce44SJohn Forte 3028fcf3ce44SJohn Forte (void) memcpy(pParms->chapParms.name, chap_p.c_user, 3029fcf3ce44SJohn Forte chap_p.c_user_len); 3030fcf3ce44SJohn Forte 3031fcf3ce44SJohn Forte pParms->chapParms.nameLength = chap_p.c_user_len; 3032fcf3ce44SJohn Forte (void) memcpy(pParms->chapParms.challengeSecret, chap_p.c_secret, 3033fcf3ce44SJohn Forte chap_p.c_secret_len); 3034fcf3ce44SJohn Forte 3035fcf3ce44SJohn Forte pParms->chapParms.challengeSecretLength = chap_p.c_secret_len; 3036fcf3ce44SJohn Forte 3037fcf3ce44SJohn Forte return (IMA_STATUS_SUCCESS); 3038fcf3ce44SJohn Forte } 30396cefaae1SJack Meng 30406cefaae1SJack Meng IMA_API IMA_STATUS SUN_IMA_GetBootTargetName( 30416cefaae1SJack Meng IMA_NODE_NAME tgtName 30426cefaae1SJack Meng ) 30436cefaae1SJack Meng { 30446cefaae1SJack Meng int fd; 30456cefaae1SJack Meng IMA_STATUS rtn; 30466cefaae1SJack Meng iscsi_boot_property_t bootProp; 30476cefaae1SJack Meng 30486cefaae1SJack Meng bootProp.tgt_name.n_name[0] = '\0'; 30496cefaae1SJack Meng bootProp.tgt_chap.c_user[0] = '\0'; 30506cefaae1SJack Meng tgtName[0] = L'\0'; 30516cefaae1SJack Meng rtn = IMA_ERROR_UNEXPECTED_OS_ERROR; 30526cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 30536cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 30546cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 30556cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30566cefaae1SJack Meng } 30576cefaae1SJack Meng 30586cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 30596cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 30606cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 30616cefaae1SJack Meng errno); 30626cefaae1SJack Meng (void) close(fd); 30636cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30646cefaae1SJack Meng } 30656cefaae1SJack Meng 30666cefaae1SJack Meng if ((bootProp.tgt_name.n_name[0] != '\0') && (tgtName != NULL)) { 30676cefaae1SJack Meng if (mbstowcs(tgtName, (const char *)bootProp.tgt_name.n_name, 30686cefaae1SJack Meng IMA_NODE_NAME_LEN) == (size_t)-1) { 30696cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 30706cefaae1SJack Meng "ISCSI Target name covert to WCHAR fail"); 30716cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30726cefaae1SJack Meng } else { 30736cefaae1SJack Meng rtn = IMA_STATUS_SUCCESS; 30746cefaae1SJack Meng } 30756cefaae1SJack Meng } 30766cefaae1SJack Meng 30776cefaae1SJack Meng return (rtn); 30786cefaae1SJack Meng } 30796cefaae1SJack Meng 30806cefaae1SJack Meng IMA_API IMA_STATUS SUN_IMA_GetBootTargetAuthParams( 30816cefaae1SJack Meng IMA_INITIATOR_AUTHPARMS *pTgtCHAP 30826cefaae1SJack Meng ) 30836cefaae1SJack Meng { 30846cefaae1SJack Meng int fd; 30856cefaae1SJack Meng IMA_STATUS rtn; 30866cefaae1SJack Meng iscsi_boot_property_t bootProp; 30876cefaae1SJack Meng 30886cefaae1SJack Meng bootProp.tgt_name.n_name[0] = '\0'; 30896cefaae1SJack Meng bootProp.tgt_chap.c_user[0] = '\0'; 30906cefaae1SJack Meng bootProp.tgt_chap.c_secret[0] = '\0'; 30916cefaae1SJack Meng rtn = IMA_ERROR_UNEXPECTED_OS_ERROR; 30926cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 30936cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 30946cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 30956cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30966cefaae1SJack Meng } 30976cefaae1SJack Meng 30986cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 30996cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 31006cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 31016cefaae1SJack Meng errno); 31026cefaae1SJack Meng (void) close(fd); 31036cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31046cefaae1SJack Meng } 31056cefaae1SJack Meng 31066cefaae1SJack Meng if (pTgtCHAP != NULL) { 31076cefaae1SJack Meng if (bootProp.tgt_chap.c_user[0] != '\0') { 31086cefaae1SJack Meng (void) memcpy(pTgtCHAP->chapParms.name, 31096cefaae1SJack Meng bootProp.tgt_chap.c_user, ISCSI_MAX_NAME_LEN); 31106cefaae1SJack Meng } else { 31116cefaae1SJack Meng pTgtCHAP->chapParms.name[0] = '\0'; 31126cefaae1SJack Meng } 31136cefaae1SJack Meng if (bootProp.tgt_chap.c_secret[0] != '\0') { 31146cefaae1SJack Meng (void) memcpy(pTgtCHAP->chapParms.challengeSecret, 31156cefaae1SJack Meng bootProp.tgt_chap.c_secret, MAX_CHAP_SECRET_LEN); 31166cefaae1SJack Meng } else { 31176cefaae1SJack Meng pTgtCHAP->chapParms.challengeSecret[0] = '\0'; 31186cefaae1SJack Meng } 31196cefaae1SJack Meng rtn = IMA_STATUS_SUCCESS; 31206cefaae1SJack Meng } 31216cefaae1SJack Meng return (rtn); 31226cefaae1SJack Meng } 31236cefaae1SJack Meng 31246cefaae1SJack Meng IMA_STATUS SUN_IMA_GetBootMpxio( 31256cefaae1SJack Meng IMA_BOOL *pMpxioEnabled 31266cefaae1SJack Meng ) 31276cefaae1SJack Meng { 31286cefaae1SJack Meng int fd; 31296cefaae1SJack Meng iscsi_boot_property_t bootProp; 31306cefaae1SJack Meng 31316cefaae1SJack Meng bootProp.hba_mpxio_enabled = B_FALSE; 31326cefaae1SJack Meng *pMpxioEnabled = IMA_UNKNOWN; 31336cefaae1SJack Meng 31346cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 31356cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 31366cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 31376cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31386cefaae1SJack Meng } 31396cefaae1SJack Meng 31406cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 31416cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 31426cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 31436cefaae1SJack Meng errno); 31446cefaae1SJack Meng (void) close(fd); 31456cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31466cefaae1SJack Meng } 31476cefaae1SJack Meng 31486cefaae1SJack Meng if (bootProp.hba_mpxio_enabled) { 31496cefaae1SJack Meng *pMpxioEnabled = IMA_TRUE; 31506cefaae1SJack Meng } else { 31516cefaae1SJack Meng *pMpxioEnabled = IMA_FALSE; 31526cefaae1SJack Meng } 31536cefaae1SJack Meng 31546cefaae1SJack Meng (void) close(fd); 31556cefaae1SJack Meng return (IMA_STATUS_SUCCESS); 31566cefaae1SJack Meng } 31576cefaae1SJack Meng 31586cefaae1SJack Meng IMA_STATUS SUN_IMA_GetBootIscsi( 31596cefaae1SJack Meng IMA_BOOL *pIscsiBoot 31606cefaae1SJack Meng ) 31616cefaae1SJack Meng { 31626cefaae1SJack Meng int fd; 31636cefaae1SJack Meng iscsi_boot_property_t bootProp; 31646cefaae1SJack Meng 31656cefaae1SJack Meng bootProp.iscsiboot = 0; 31666cefaae1SJack Meng *pIscsiBoot = 0; 31676cefaae1SJack Meng 31686cefaae1SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 31696cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 31706cefaae1SJack Meng ISCSI_DRIVER_DEVCTL, errno); 31716cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31726cefaae1SJack Meng } 31736cefaae1SJack Meng 31746cefaae1SJack Meng if (ioctl(fd, ISCSI_BOOTPROP_GET, &bootProp) != 0) { 31756cefaae1SJack Meng syslog(LOG_USER|LOG_DEBUG, 31766cefaae1SJack Meng "ISCSI_BOOTPROP_GET ioctl failed, errno: %d", 31776cefaae1SJack Meng errno); 31786cefaae1SJack Meng (void) close(fd); 31796cefaae1SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31806cefaae1SJack Meng } 31816cefaae1SJack Meng 31826cefaae1SJack Meng *pIscsiBoot = bootProp.iscsiboot; 31836cefaae1SJack Meng 31846cefaae1SJack Meng (void) close(fd); 31856cefaae1SJack Meng return (IMA_STATUS_SUCCESS); 31866cefaae1SJack Meng } 31874246c8e9SJack Meng 31884246c8e9SJack Meng IMA_STATUS SUN_IMA_GetSvcStatus( 31894246c8e9SJack Meng IMA_BOOL *pSvcEnabled) 31904246c8e9SJack Meng { 31914246c8e9SJack Meng int fd; 31924246c8e9SJack Meng uint32_t status = ISCSI_SERVICE_DISABLED; 31934246c8e9SJack Meng 31944246c8e9SJack Meng if (pSvcEnabled == NULL) 31954246c8e9SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31964246c8e9SJack Meng *pSvcEnabled = 0; 31974246c8e9SJack Meng 31984246c8e9SJack Meng if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 31994246c8e9SJack Meng syslog(LOG_USER|LOG_DEBUG, "Unable to open %s (%d)", 32004246c8e9SJack Meng ISCSI_DRIVER_DEVCTL, errno); 32014246c8e9SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 32024246c8e9SJack Meng } 32034246c8e9SJack Meng 32044246c8e9SJack Meng if (ioctl(fd, ISCSI_SMF_GET, &status) != 0) { 32054246c8e9SJack Meng syslog(LOG_USER|LOG_DEBUG, 32064246c8e9SJack Meng "ISCSI_SVC_GET ioctl failed, errno: %d", 32074246c8e9SJack Meng errno); 32084246c8e9SJack Meng (void) close(fd); 32094246c8e9SJack Meng return (IMA_ERROR_UNEXPECTED_OS_ERROR); 32104246c8e9SJack Meng } 32114246c8e9SJack Meng 32124246c8e9SJack Meng if (status == ISCSI_SERVICE_ENABLED) { 32134246c8e9SJack Meng *pSvcEnabled = 1; 32144246c8e9SJack Meng } 32154246c8e9SJack Meng 32164246c8e9SJack Meng (void) close(fd); 32174246c8e9SJack Meng return (IMA_STATUS_SUCCESS); 32184246c8e9SJack Meng } 3219*904e51f6SJack Meng 3220*904e51f6SJack Meng IMA_STATUS SUN_IMA_ReEnumeration( 3221*904e51f6SJack Meng IMA_OID targetId 3222*904e51f6SJack Meng ) 3223*904e51f6SJack Meng { 3224*904e51f6SJack Meng int fd; 3225*904e51f6SJack Meng int status; 3226*904e51f6SJack Meng iscsi_reen_t reet; 3227*904e51f6SJack Meng 3228*904e51f6SJack Meng reet.re_ver = ISCSI_INTERFACE_VERSION; 3229*904e51f6SJack Meng reet.re_oid = (uint32_t)targetId.objectSequenceNumber; 3230*904e51f6SJack Meng 3231*904e51f6SJack Meng if ((status = open_driver(&fd))) { 3232*904e51f6SJack Meng return (SUN_IMA_ERROR_SYSTEM_ERROR | status); 3233*904e51f6SJack Meng } 3234*904e51f6SJack Meng 3235*904e51f6SJack Meng (void) ioctl(fd, ISCSI_TARGET_REENUM, &reet); 3236*904e51f6SJack Meng 3237*904e51f6SJack Meng (void) close(fd); 3238*904e51f6SJack Meng 3239*904e51f6SJack Meng return (IMA_STATUS_SUCCESS); 3240*904e51f6SJack Meng } 3241