17836SJohn.Forte@Sun.COM /* 27836SJohn.Forte@Sun.COM * CDDL HEADER START 37836SJohn.Forte@Sun.COM * 47836SJohn.Forte@Sun.COM * The contents of this file are subject to the terms of the 57836SJohn.Forte@Sun.COM * Common Development and Distribution License (the "License"). 67836SJohn.Forte@Sun.COM * You may not use this file except in compliance with the License. 77836SJohn.Forte@Sun.COM * 87836SJohn.Forte@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97836SJohn.Forte@Sun.COM * or http://www.opensolaris.org/os/licensing. 107836SJohn.Forte@Sun.COM * See the License for the specific language governing permissions 117836SJohn.Forte@Sun.COM * and limitations under the License. 127836SJohn.Forte@Sun.COM * 137836SJohn.Forte@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 147836SJohn.Forte@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157836SJohn.Forte@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 167836SJohn.Forte@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 177836SJohn.Forte@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 187836SJohn.Forte@Sun.COM * 197836SJohn.Forte@Sun.COM * CDDL HEADER END 207836SJohn.Forte@Sun.COM */ 217836SJohn.Forte@Sun.COM /* 228656SPeter.Dunlap@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237836SJohn.Forte@Sun.COM * Use is subject to license terms. 247836SJohn.Forte@Sun.COM */ 257836SJohn.Forte@Sun.COM 267836SJohn.Forte@Sun.COM #include <arpa/inet.h> 277836SJohn.Forte@Sun.COM #include <sys/socket.h> 287836SJohn.Forte@Sun.COM #include <sys/types.h> 297836SJohn.Forte@Sun.COM #include <stdarg.h> 307836SJohn.Forte@Sun.COM #include <stdlib.h> 317836SJohn.Forte@Sun.COM #include <string.h> 327836SJohn.Forte@Sun.COM #include <strings.h> 337836SJohn.Forte@Sun.COM #include <unistd.h> 347836SJohn.Forte@Sun.COM #include <syslog.h> 357836SJohn.Forte@Sun.COM #include <errno.h> 367836SJohn.Forte@Sun.COM #include <wchar.h> 377836SJohn.Forte@Sun.COM #include <widec.h> 387836SJohn.Forte@Sun.COM #include <libsysevent.h> 397836SJohn.Forte@Sun.COM #include <sys/nvpair.h> 407836SJohn.Forte@Sun.COM #include <fcntl.h> 417836SJohn.Forte@Sun.COM #include <stdio.h> 427836SJohn.Forte@Sun.COM #include <time.h> 437836SJohn.Forte@Sun.COM #include <libdevinfo.h> 447836SJohn.Forte@Sun.COM #include <sys/scsi/adapters/iscsi_if.h> 458656SPeter.Dunlap@Sun.COM #include <sys/iscsi_protocol.h> 467836SJohn.Forte@Sun.COM #include <ima.h> 47*10156SZhang.Yi@Sun.COM #include <libsun_ima.h> 487836SJohn.Forte@Sun.COM 497836SJohn.Forte@Sun.COM #define LIBRARY_PROPERTY_IMPLEMENTATION_VERSION L"1.0.0" 507836SJohn.Forte@Sun.COM #define LIBRARY_PROPERTY_VENDOR L"Sun Microsystems, Inc." 517836SJohn.Forte@Sun.COM #define OS_DEVICE_NAME "/devices/iscsi" 527836SJohn.Forte@Sun.COM #define LIBRARY_FILE_NAME L"libsun_ima.so" 537836SJohn.Forte@Sun.COM 547836SJohn.Forte@Sun.COM #define OS_DEVICE_NAME_LEN 256 557836SJohn.Forte@Sun.COM #define INQUIRY_CMD 0x12 567836SJohn.Forte@Sun.COM #define GETCAPACITY_CMD 0x25 577836SJohn.Forte@Sun.COM #define INQUIRY_CMDLEN 6 587836SJohn.Forte@Sun.COM #define INQUIRY_REPLY_LEN 96 597836SJohn.Forte@Sun.COM #define USCSI_TIMEOUT_IN_SEC 10 607836SJohn.Forte@Sun.COM #define MAX_AUTHMETHODS 10 617836SJohn.Forte@Sun.COM #define NUM_SUPPORTED_AUTH_METHODS 2 627836SJohn.Forte@Sun.COM #define SUN_IMA_MAX_DIGEST_ALGORITHMS 2 /* NONE and CRC 32 */ 637836SJohn.Forte@Sun.COM #define SUN_IMA_IP_ADDRESS_LEN 256 647836SJohn.Forte@Sun.COM #define SUN_IMA_IP_PORT_LEN 64 657836SJohn.Forte@Sun.COM #define SUN_IMA_MAX_RADIUS_SECRET_LEN 128 66*10156SZhang.Yi@Sun.COM #define MAX_LONG_LONG_STRING_LEN 10 677836SJohn.Forte@Sun.COM 687836SJohn.Forte@Sun.COM /* Forward declaration */ 697836SJohn.Forte@Sun.COM #define BOOL_PARAM 1 707836SJohn.Forte@Sun.COM #define MIN_MAX_PARAM 2 717836SJohn.Forte@Sun.COM 727836SJohn.Forte@Sun.COM /* OK */ 737836SJohn.Forte@Sun.COM #define DISC_ADDR_OK 0 747836SJohn.Forte@Sun.COM /* Incorrect IP address */ 757836SJohn.Forte@Sun.COM #define DISC_ADDR_INTEGRITY_ERROR 1 767836SJohn.Forte@Sun.COM /* Error converting text IP address to numeric binary form */ 777836SJohn.Forte@Sun.COM #define DISC_ADDR_IP_CONV_ERROR 2 787836SJohn.Forte@Sun.COM 797836SJohn.Forte@Sun.COM /* Currently not defined in IMA_TARGET_DISCOVERY_METHOD enum */ 807836SJohn.Forte@Sun.COM #define IMA_TARGET_DISCOVERY_METHOD_UNKNOWN 0 817836SJohn.Forte@Sun.COM 827836SJohn.Forte@Sun.COM static IMA_OID lhbaObjectId; 837836SJohn.Forte@Sun.COM static IMA_UINT32 pluginOwnerId; 847836SJohn.Forte@Sun.COM static sysevent_handle_t *shp; 857836SJohn.Forte@Sun.COM 867836SJohn.Forte@Sun.COM 877836SJohn.Forte@Sun.COM 887836SJohn.Forte@Sun.COM /* 897836SJohn.Forte@Sun.COM * Custom struct to allow tgpt to be specified. 907836SJohn.Forte@Sun.COM */ 917836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDRESS_KEY 927836SJohn.Forte@Sun.COM { 937836SJohn.Forte@Sun.COM IMA_NODE_NAME name; 947836SJohn.Forte@Sun.COM IMA_ADDRESS_KEY address; 957836SJohn.Forte@Sun.COM IMA_UINT16 tpgt; 967836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDRESS_KEY; 977836SJohn.Forte@Sun.COM 987836SJohn.Forte@Sun.COM /* 997836SJohn.Forte@Sun.COM * Custom struct to allow tgpt to be specified. 1007836SJohn.Forte@Sun.COM */ 1017836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES 1027836SJohn.Forte@Sun.COM { 1037836SJohn.Forte@Sun.COM IMA_UINT keyCount; 1047836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDRESS_KEY keys[1]; 1057836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES; 1067836SJohn.Forte@Sun.COM 1077836SJohn.Forte@Sun.COM /* 1087836SJohn.Forte@Sun.COM * Custom struct to allow tgpt to be specified. 1097836SJohn.Forte@Sun.COM */ 1107836SJohn.Forte@Sun.COM typedef struct _SUN_IMA_DISC_ADDR_PROP_LIST 1117836SJohn.Forte@Sun.COM { 1127836SJohn.Forte@Sun.COM IMA_UINT discAddrCount; 1137836SJohn.Forte@Sun.COM IMA_DISCOVERY_ADDRESS_PROPERTIES props[1]; 1147836SJohn.Forte@Sun.COM } SUN_IMA_DISC_ADDR_PROP_LIST; 1157836SJohn.Forte@Sun.COM 1167836SJohn.Forte@Sun.COM 1177836SJohn.Forte@Sun.COM static IMA_OBJECT_VISIBILITY_FN pObjectVisibilityCallback = NULL; 1187836SJohn.Forte@Sun.COM static IMA_OBJECT_PROPERTY_FN pObjectPropertyCallback = NULL; 1197836SJohn.Forte@Sun.COM 1207836SJohn.Forte@Sun.COM static IMA_STATUS getISCSINodeParameter(int paramType, IMA_OID *oid, 1217836SJohn.Forte@Sun.COM void *pProps, uint32_t paramIndex); 1227836SJohn.Forte@Sun.COM static IMA_STATUS setISCSINodeParameter(int paramType, IMA_OID *oid, 1237836SJohn.Forte@Sun.COM void *pProps, uint32_t paramIndex); 1247836SJohn.Forte@Sun.COM static IMA_STATUS setAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount, 1257836SJohn.Forte@Sun.COM const IMA_AUTHMETHOD *pMethodList); 1267836SJohn.Forte@Sun.COM static IMA_STATUS getAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount, 1277836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList); 1287836SJohn.Forte@Sun.COM 1297836SJohn.Forte@Sun.COM static int prepare_discovery_entry(IMA_TARGET_ADDRESS discoveryAddress, 1307836SJohn.Forte@Sun.COM entry_t *entry); 1317836SJohn.Forte@Sun.COM static IMA_STATUS configure_discovery_method(IMA_BOOL enable, 1327836SJohn.Forte@Sun.COM iSCSIDiscoveryMethod_t method); 1337836SJohn.Forte@Sun.COM static IMA_STATUS get_target_oid_list(uint32_t targetListType, 1347836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList); 1357836SJohn.Forte@Sun.COM static IMA_STATUS get_target_lun_oid_list(IMA_OID * targetOid, 1367836SJohn.Forte@Sun.COM iscsi_lun_list_t **ppLunList); 1377836SJohn.Forte@Sun.COM static int get_lun_devlink(di_devlink_t link, void *osDeviceName); 1387836SJohn.Forte@Sun.COM static IMA_STATUS getDiscoveryAddressPropertiesList( 1397836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDR_PROP_LIST **ppList 1407836SJohn.Forte@Sun.COM ); 1417836SJohn.Forte@Sun.COM static IMA_STATUS sendTargets(IMA_TARGET_ADDRESS address, 1427836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList 1437836SJohn.Forte@Sun.COM ); 1447836SJohn.Forte@Sun.COM 1457836SJohn.Forte@Sun.COM static IMA_STATUS getSupportedAuthMethods(IMA_OID lhbaOid, 1467836SJohn.Forte@Sun.COM IMA_BOOL getSettableMethods, IMA_UINT *pMethodCount, 1477836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList); 1487836SJohn.Forte@Sun.COM static IMA_STATUS getLuProperties(IMA_OID luId, IMA_LU_PROPERTIES *pProps); 1497836SJohn.Forte@Sun.COM static IMA_STATUS getTargetProperties(IMA_OID targetId, 1507836SJohn.Forte@Sun.COM IMA_TARGET_PROPERTIES *pProps); 1517836SJohn.Forte@Sun.COM 1527836SJohn.Forte@Sun.COM void InitLibrary(); 1537836SJohn.Forte@Sun.COM 1547836SJohn.Forte@Sun.COM static void libSwprintf(wchar_t *wcs, const wchar_t *lpszFormat, ...) 1557836SJohn.Forte@Sun.COM { 1567836SJohn.Forte@Sun.COM va_list args; 1577836SJohn.Forte@Sun.COM va_start(args, lpszFormat); 1587836SJohn.Forte@Sun.COM (void) vswprintf(wcs, OS_DEVICE_NAME_LEN - 1, lpszFormat, args); 1597836SJohn.Forte@Sun.COM va_end(args); 1607836SJohn.Forte@Sun.COM } 1617836SJohn.Forte@Sun.COM 1627836SJohn.Forte@Sun.COM static void 1637836SJohn.Forte@Sun.COM sysevent_handler(sysevent_t *ev) 1647836SJohn.Forte@Sun.COM { 1657836SJohn.Forte@Sun.COM IMA_OID tmpOid; 1667836SJohn.Forte@Sun.COM IMA_BOOL becomingVisible = IMA_FALSE; 1677836SJohn.Forte@Sun.COM IMA_UINT i; 1687836SJohn.Forte@Sun.COM 1697836SJohn.Forte@Sun.COM const char *visibility_subclasses[] = { 1707836SJohn.Forte@Sun.COM ESC_ISCSI_STATIC_START, 1717836SJohn.Forte@Sun.COM ESC_ISCSI_STATIC_END, 1727836SJohn.Forte@Sun.COM ESC_ISCSI_SEND_TARGETS_START, 1737836SJohn.Forte@Sun.COM ESC_ISCSI_SEND_TARGETS_END, 1747836SJohn.Forte@Sun.COM ESC_ISCSI_SLP_START, 1757836SJohn.Forte@Sun.COM ESC_ISCSI_SLP_END, 1767836SJohn.Forte@Sun.COM ESC_ISCSI_ISNS_START, 1777836SJohn.Forte@Sun.COM ESC_ISCSI_ISNS_END, 1787836SJohn.Forte@Sun.COM NULL 1797836SJohn.Forte@Sun.COM }; 1807836SJohn.Forte@Sun.COM 1817836SJohn.Forte@Sun.COM tmpOid.ownerId = pluginOwnerId; 1827836SJohn.Forte@Sun.COM tmpOid.objectType = IMA_OBJECT_TYPE_TARGET; 1837836SJohn.Forte@Sun.COM tmpOid.objectSequenceNumber = 0; 1847836SJohn.Forte@Sun.COM 1857836SJohn.Forte@Sun.COM /* Make sure our event class matches what we are looking for */ 1867836SJohn.Forte@Sun.COM if (strncmp(EC_ISCSI, sysevent_get_class_name(ev), 1877836SJohn.Forte@Sun.COM strlen(EC_ISCSI)) != 0) { 1887836SJohn.Forte@Sun.COM return; 1897836SJohn.Forte@Sun.COM } 1907836SJohn.Forte@Sun.COM 1917836SJohn.Forte@Sun.COM 1927836SJohn.Forte@Sun.COM /* Check for object property changes */ 1937836SJohn.Forte@Sun.COM if ((strncmp(ESC_ISCSI_PROP_CHANGE, 1947836SJohn.Forte@Sun.COM sysevent_get_subclass_name(ev), 1957836SJohn.Forte@Sun.COM strlen(ESC_ISCSI_PROP_CHANGE)) == 0)) { 1967836SJohn.Forte@Sun.COM if (pObjectPropertyCallback != NULL) 1977836SJohn.Forte@Sun.COM pObjectPropertyCallback(tmpOid); 1987836SJohn.Forte@Sun.COM } else { 1997836SJohn.Forte@Sun.COM i = 0; 2007836SJohn.Forte@Sun.COM while (visibility_subclasses[i] != NULL) { 2017836SJohn.Forte@Sun.COM if ((strncmp(visibility_subclasses[i], 2027836SJohn.Forte@Sun.COM sysevent_get_subclass_name(ev), 2037836SJohn.Forte@Sun.COM strlen(visibility_subclasses[i])) == 0) && 2047836SJohn.Forte@Sun.COM pObjectVisibilityCallback != NULL) { 2057836SJohn.Forte@Sun.COM becomingVisible = IMA_TRUE; 2067836SJohn.Forte@Sun.COM pObjectVisibilityCallback(becomingVisible, 2077836SJohn.Forte@Sun.COM tmpOid); 2087836SJohn.Forte@Sun.COM } 2097836SJohn.Forte@Sun.COM i++; 2107836SJohn.Forte@Sun.COM } 2117836SJohn.Forte@Sun.COM } 2127836SJohn.Forte@Sun.COM } 2137836SJohn.Forte@Sun.COM 2147836SJohn.Forte@Sun.COM IMA_STATUS init_sysevents() { 2157836SJohn.Forte@Sun.COM const char *subclass_list[] = { 2167836SJohn.Forte@Sun.COM ESC_ISCSI_STATIC_START, 2177836SJohn.Forte@Sun.COM ESC_ISCSI_STATIC_END, 2187836SJohn.Forte@Sun.COM ESC_ISCSI_SEND_TARGETS_START, 2197836SJohn.Forte@Sun.COM ESC_ISCSI_SEND_TARGETS_END, 2207836SJohn.Forte@Sun.COM ESC_ISCSI_SLP_START, 2217836SJohn.Forte@Sun.COM ESC_ISCSI_SLP_END, 2227836SJohn.Forte@Sun.COM ESC_ISCSI_ISNS_START, 2237836SJohn.Forte@Sun.COM ESC_ISCSI_ISNS_END, 2247836SJohn.Forte@Sun.COM ESC_ISCSI_PROP_CHANGE, 2257836SJohn.Forte@Sun.COM }; 2267836SJohn.Forte@Sun.COM 2277836SJohn.Forte@Sun.COM /* Bind event handler and create subscriber handle */ 2287836SJohn.Forte@Sun.COM shp = sysevent_bind_handle(sysevent_handler); 2297836SJohn.Forte@Sun.COM if (shp == NULL) { 2307836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2317836SJohn.Forte@Sun.COM } 2327836SJohn.Forte@Sun.COM 2337836SJohn.Forte@Sun.COM if (sysevent_subscribe_event(shp, EC_ISCSI, subclass_list, 9) != 0) { 2347836SJohn.Forte@Sun.COM sysevent_unbind_handle(shp); 2357836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2367836SJohn.Forte@Sun.COM } 2377836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 2387836SJohn.Forte@Sun.COM } 2397836SJohn.Forte@Sun.COM 2407836SJohn.Forte@Sun.COM IMA_STATUS Initialize(IMA_UINT32 pluginOid) { 2417836SJohn.Forte@Sun.COM pluginOwnerId = pluginOid; 2427836SJohn.Forte@Sun.COM return (init_sysevents()); 2437836SJohn.Forte@Sun.COM } 2447836SJohn.Forte@Sun.COM 2457836SJohn.Forte@Sun.COM void Terminate() { 2467836SJohn.Forte@Sun.COM if (shp != NULL) { 2477836SJohn.Forte@Sun.COM sysevent_unsubscribe_event(shp, EC_ISCSI); 2487836SJohn.Forte@Sun.COM } 2497836SJohn.Forte@Sun.COM 2507836SJohn.Forte@Sun.COM } 2517836SJohn.Forte@Sun.COM 2527836SJohn.Forte@Sun.COM void InitLibrary() { 2537836SJohn.Forte@Sun.COM } 2547836SJohn.Forte@Sun.COM 2557836SJohn.Forte@Sun.COM static void GetBuildTime(IMA_DATETIME* pdatetime) 2567836SJohn.Forte@Sun.COM { 2577836SJohn.Forte@Sun.COM (void) memset(pdatetime, 0, sizeof (IMA_DATETIME)); 2587836SJohn.Forte@Sun.COM } 2597836SJohn.Forte@Sun.COM 2607836SJohn.Forte@Sun.COM /*ARGSUSED*/ 2617836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNodeProperties( 2627836SJohn.Forte@Sun.COM IMA_OID nodeOid, 2637836SJohn.Forte@Sun.COM IMA_NODE_PROPERTIES *pProps 2647836SJohn.Forte@Sun.COM ) 2657836SJohn.Forte@Sun.COM { 2667836SJohn.Forte@Sun.COM int fd; 2677836SJohn.Forte@Sun.COM iscsi_param_get_t pg; 2687836SJohn.Forte@Sun.COM 2697836SJohn.Forte@Sun.COM pProps->runningInInitiatorMode = IMA_TRUE; 2707836SJohn.Forte@Sun.COM pProps->runningInTargetMode = IMA_FALSE; 2717836SJohn.Forte@Sun.COM pProps->nameAndAliasSettable = IMA_FALSE; 2727836SJohn.Forte@Sun.COM 2737836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 2747836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 2757836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 2767836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 2777836SJohn.Forte@Sun.COM } 2787836SJohn.Forte@Sun.COM 2797836SJohn.Forte@Sun.COM (void) memset(&pg, 0, sizeof (iscsi_param_get_t)); 2807836SJohn.Forte@Sun.COM pg.g_vers = ISCSI_INTERFACE_VERSION; 2817836SJohn.Forte@Sun.COM pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME; 2827836SJohn.Forte@Sun.COM 2837836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) { 2847836SJohn.Forte@Sun.COM pProps->nameValid = IMA_FALSE; 2857836SJohn.Forte@Sun.COM } else { 2867836SJohn.Forte@Sun.COM if (strlen((char *)pg.g_value.v_name) > 0) { 2877836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->name, 2887836SJohn.Forte@Sun.COM (char *)pg.g_value.v_name, 2897836SJohn.Forte@Sun.COM IMA_NODE_NAME_LEN); 2907836SJohn.Forte@Sun.COM pProps->nameValid = IMA_TRUE; 2917836SJohn.Forte@Sun.COM } else { 2927836SJohn.Forte@Sun.COM pProps->nameValid = IMA_FALSE; 2937836SJohn.Forte@Sun.COM } 2947836SJohn.Forte@Sun.COM } 2957836SJohn.Forte@Sun.COM 2967836SJohn.Forte@Sun.COM (void) memset(&pg, 0, sizeof (iscsi_param_get_t)); 2977836SJohn.Forte@Sun.COM pg.g_vers = ISCSI_INTERFACE_VERSION; 2987836SJohn.Forte@Sun.COM pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS; 2997836SJohn.Forte@Sun.COM (void) memset(pProps->alias, 0, 3007836SJohn.Forte@Sun.COM sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN); 3017836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) { 3027836SJohn.Forte@Sun.COM pProps->aliasValid = IMA_FALSE; 3037836SJohn.Forte@Sun.COM } else { 3047836SJohn.Forte@Sun.COM if (strlen((char *)pg.g_value.v_name) > 0) { 3057836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->alias, 3067836SJohn.Forte@Sun.COM (char *)pg.g_value.v_name, 3077836SJohn.Forte@Sun.COM IMA_NODE_ALIAS_LEN); 3087836SJohn.Forte@Sun.COM pProps->aliasValid = IMA_TRUE; 3097836SJohn.Forte@Sun.COM } 3107836SJohn.Forte@Sun.COM } 3117836SJohn.Forte@Sun.COM 3127836SJohn.Forte@Sun.COM (void) close(fd); 3137836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 3147836SJohn.Forte@Sun.COM } 3157836SJohn.Forte@Sun.COM 3167836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNodeName( 3177836SJohn.Forte@Sun.COM IMA_OID nodeOid, 3187836SJohn.Forte@Sun.COM const IMA_NODE_NAME newName 3197836SJohn.Forte@Sun.COM ) 3207836SJohn.Forte@Sun.COM { 3217836SJohn.Forte@Sun.COM int fd; 3227836SJohn.Forte@Sun.COM iscsi_param_set_t ps; 3237836SJohn.Forte@Sun.COM 3247836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3257836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 3267836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 3277836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3287836SJohn.Forte@Sun.COM } 3297836SJohn.Forte@Sun.COM 3307836SJohn.Forte@Sun.COM (void) memset(&ps, 0, sizeof (iscsi_param_set_t)); 3317836SJohn.Forte@Sun.COM ps.s_oid = nodeOid.objectSequenceNumber; 3327836SJohn.Forte@Sun.COM ps.s_vers = ISCSI_INTERFACE_VERSION; 3337836SJohn.Forte@Sun.COM ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME; 3347836SJohn.Forte@Sun.COM (void) wcstombs((char *)ps.s_value.v_name, newName, ISCSI_MAX_NAME_LEN); 3357836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_INIT_NODE_NAME_SET, &ps)) { 3367836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 3377836SJohn.Forte@Sun.COM "ISCSI_PARAM_SET ioctl failed, errno: %d", errno); 3387836SJohn.Forte@Sun.COM (void) close(fd); 3397836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3407836SJohn.Forte@Sun.COM } 3417836SJohn.Forte@Sun.COM 3427836SJohn.Forte@Sun.COM (void) close(fd); 3437836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 3447836SJohn.Forte@Sun.COM } 3457836SJohn.Forte@Sun.COM 3467836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNodeAlias( 3477836SJohn.Forte@Sun.COM IMA_OID nodeOid, 3487836SJohn.Forte@Sun.COM const IMA_NODE_ALIAS newAlias 3497836SJohn.Forte@Sun.COM ) 3507836SJohn.Forte@Sun.COM { 3517836SJohn.Forte@Sun.COM int fd; 3527836SJohn.Forte@Sun.COM iscsi_param_set_t ps; 3537836SJohn.Forte@Sun.COM 3547836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3557836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 3567836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 3577836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3587836SJohn.Forte@Sun.COM } 3597836SJohn.Forte@Sun.COM 3607836SJohn.Forte@Sun.COM (void) memset(&ps, 0, sizeof (iscsi_param_set_t)); 3617836SJohn.Forte@Sun.COM ps.s_oid = nodeOid.objectSequenceNumber; 3627836SJohn.Forte@Sun.COM ps.s_vers = ISCSI_INTERFACE_VERSION; 3637836SJohn.Forte@Sun.COM ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS; 3647836SJohn.Forte@Sun.COM 3657836SJohn.Forte@Sun.COM /* newAlias = NULL specifies that the alias should be deleted. */ 3667836SJohn.Forte@Sun.COM if (newAlias != NULL) 3677836SJohn.Forte@Sun.COM (void) wcstombs((char *)ps.s_value.v_name, newAlias, 3687836SJohn.Forte@Sun.COM ISCSI_MAX_NAME_LEN); 3697836SJohn.Forte@Sun.COM else 3707836SJohn.Forte@Sun.COM (void) wcstombs((char *)ps.s_value.v_name, 3717836SJohn.Forte@Sun.COM L"", ISCSI_MAX_NAME_LEN); 3727836SJohn.Forte@Sun.COM 3737836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_PARAM_SET, &ps)) { 3747836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 3757836SJohn.Forte@Sun.COM "ISCSI_PARAM_SET ioctl failed, errno: %d", errno); 3767836SJohn.Forte@Sun.COM (void) close(fd); 3777836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3787836SJohn.Forte@Sun.COM } 3797836SJohn.Forte@Sun.COM 3807836SJohn.Forte@Sun.COM (void) close(fd); 3817836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 3827836SJohn.Forte@Sun.COM } 3837836SJohn.Forte@Sun.COM 3847836SJohn.Forte@Sun.COM 3857836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLhbaOidList( 3867836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 3877836SJohn.Forte@Sun.COM ) 3887836SJohn.Forte@Sun.COM { 3897836SJohn.Forte@Sun.COM /* Always return the same object ID for the lhba */ 3907836SJohn.Forte@Sun.COM lhbaObjectId.objectType = IMA_OBJECT_TYPE_LHBA; 3917836SJohn.Forte@Sun.COM lhbaObjectId.ownerId = pluginOwnerId; 3927836SJohn.Forte@Sun.COM lhbaObjectId.objectSequenceNumber = ISCSI_INITIATOR_OID; 3937836SJohn.Forte@Sun.COM 3947836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST)); 3957836SJohn.Forte@Sun.COM if (*ppList == NULL) { 3967836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 3977836SJohn.Forte@Sun.COM } 3987836SJohn.Forte@Sun.COM 3997836SJohn.Forte@Sun.COM (*ppList)->oidCount = 1; 4007836SJohn.Forte@Sun.COM (void) memcpy(&(*ppList)->oids[0], 4017836SJohn.Forte@Sun.COM &lhbaObjectId, sizeof (lhbaObjectId)); 4027836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 4037836SJohn.Forte@Sun.COM } 4047836SJohn.Forte@Sun.COM 4057836SJohn.Forte@Sun.COM 4067836SJohn.Forte@Sun.COM /* 4077836SJohn.Forte@Sun.COM * Get the discovery properties of the LHBA 4087836SJohn.Forte@Sun.COM */ 4097836SJohn.Forte@Sun.COM /*ARGSUSED*/ 4107836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDiscoveryProperties( 4117836SJohn.Forte@Sun.COM IMA_OID oid, 4127836SJohn.Forte@Sun.COM IMA_DISCOVERY_PROPERTIES *pProps 4137836SJohn.Forte@Sun.COM ) 4147836SJohn.Forte@Sun.COM { 4157836SJohn.Forte@Sun.COM int fd; 4167836SJohn.Forte@Sun.COM iSCSIDiscoveryProperties_t discoveryProps; 4177836SJohn.Forte@Sun.COM 4187836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 4197836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 4207836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 4217836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 4227836SJohn.Forte@Sun.COM } 4237836SJohn.Forte@Sun.COM 4247836SJohn.Forte@Sun.COM (void) memset(&discoveryProps, 0, sizeof (discoveryProps)); 4257836SJohn.Forte@Sun.COM discoveryProps.vers = ISCSI_INTERFACE_VERSION; 4267836SJohn.Forte@Sun.COM 4277836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_PROPS, &discoveryProps) != 0) { 4287836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 4297836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_PROPS ioctl failed, errno: %d", errno); 4307836SJohn.Forte@Sun.COM (void) close(fd); 4317836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 4327836SJohn.Forte@Sun.COM } 4337836SJohn.Forte@Sun.COM 4347836SJohn.Forte@Sun.COM pProps->iSnsDiscoverySettable = discoveryProps.iSNSDiscoverySettable; 4357836SJohn.Forte@Sun.COM pProps->iSnsDiscoveryEnabled = discoveryProps.iSNSDiscoveryEnabled; 4367836SJohn.Forte@Sun.COM /* 4377836SJohn.Forte@Sun.COM * Set the iSNS discovery method - The IMA specification indicates 4387836SJohn.Forte@Sun.COM * this field is valid only if iSNS discovery is enabled. 4397836SJohn.Forte@Sun.COM */ 4407836SJohn.Forte@Sun.COM if (pProps->iSnsDiscoveryEnabled == IMA_TRUE) { 4417836SJohn.Forte@Sun.COM switch (discoveryProps.iSNSDiscoveryMethod) { 4427836SJohn.Forte@Sun.COM case iSNSDiscoveryMethodStatic: 4437836SJohn.Forte@Sun.COM pProps->iSnsDiscoveryMethod = 4447836SJohn.Forte@Sun.COM IMA_ISNS_DISCOVERY_METHOD_STATIC; 4457836SJohn.Forte@Sun.COM break; 4467836SJohn.Forte@Sun.COM case iSNSDiscoveryMethodDHCP: 4477836SJohn.Forte@Sun.COM pProps->iSnsDiscoveryMethod = 4487836SJohn.Forte@Sun.COM IMA_ISNS_DISCOVERY_METHOD_DHCP; 4497836SJohn.Forte@Sun.COM break; 4507836SJohn.Forte@Sun.COM case iSNSDiscoveryMethodSLP: 4517836SJohn.Forte@Sun.COM pProps->iSnsDiscoveryMethod = 4527836SJohn.Forte@Sun.COM IMA_ISNS_DISCOVERY_METHOD_SLP; 4537836SJohn.Forte@Sun.COM break; 4547836SJohn.Forte@Sun.COM default: 4557836SJohn.Forte@Sun.COM (void) close(fd); 4567836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 4577836SJohn.Forte@Sun.COM } 4587836SJohn.Forte@Sun.COM } 4597836SJohn.Forte@Sun.COM (void) memcpy(pProps->iSnsHost.id.hostname, 4607836SJohn.Forte@Sun.COM discoveryProps.iSNSDomainName, 4617836SJohn.Forte@Sun.COM sizeof (pProps->iSnsHost.id.hostname)); 4627836SJohn.Forte@Sun.COM pProps->slpDiscoverySettable = discoveryProps.SLPDiscoverySettable; 4637836SJohn.Forte@Sun.COM pProps->slpDiscoveryEnabled = discoveryProps.SLPDiscoveryEnabled; 4647836SJohn.Forte@Sun.COM pProps->staticDiscoverySettable = 4657836SJohn.Forte@Sun.COM discoveryProps.StaticDiscoverySettable; 4667836SJohn.Forte@Sun.COM pProps->staticDiscoveryEnabled = discoveryProps.StaticDiscoveryEnabled; 4677836SJohn.Forte@Sun.COM pProps->sendTargetsDiscoverySettable = 4687836SJohn.Forte@Sun.COM discoveryProps.SendTargetsDiscoverySettable; 4697836SJohn.Forte@Sun.COM pProps->sendTargetsDiscoveryEnabled = 4707836SJohn.Forte@Sun.COM discoveryProps.SendTargetsDiscoveryEnabled; 4717836SJohn.Forte@Sun.COM 4727836SJohn.Forte@Sun.COM (void) close(fd); 4737836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 4747836SJohn.Forte@Sun.COM } 4757836SJohn.Forte@Sun.COM 4767836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_FreeMemory( 4777836SJohn.Forte@Sun.COM void *pMemory 4787836SJohn.Forte@Sun.COM ) 4797836SJohn.Forte@Sun.COM { 4807836SJohn.Forte@Sun.COM if (pMemory != NULL) 4817836SJohn.Forte@Sun.COM free(pMemory); 4827836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 4837836SJohn.Forte@Sun.COM } 4847836SJohn.Forte@Sun.COM 4857836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNonSharedNodeOidList( 4867836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 4877836SJohn.Forte@Sun.COM ) 4887836SJohn.Forte@Sun.COM { 4897836SJohn.Forte@Sun.COM if (ppList == NULL) 4907836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 4917836SJohn.Forte@Sun.COM 4927836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST*) calloc(1, sizeof (IMA_OID_LIST)); 4937836SJohn.Forte@Sun.COM if (*ppList == NULL) { 4947836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 4957836SJohn.Forte@Sun.COM } 4967836SJohn.Forte@Sun.COM (*ppList)->oidCount = 0; 4977836SJohn.Forte@Sun.COM 4987836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 4997836SJohn.Forte@Sun.COM } 5007836SJohn.Forte@Sun.COM 5017836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetFirstBurstLengthProperties( 5027836SJohn.Forte@Sun.COM IMA_OID Oid, 5037836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 5047836SJohn.Forte@Sun.COM ) 5057836SJohn.Forte@Sun.COM { 5067836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 5077836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH)); 5087836SJohn.Forte@Sun.COM } 5097836SJohn.Forte@Sun.COM 5107836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxBurstLengthProperties( 5117836SJohn.Forte@Sun.COM IMA_OID Oid, 5127836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 5137836SJohn.Forte@Sun.COM ) 5147836SJohn.Forte@Sun.COM { 5157836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 5167836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH)); 5177836SJohn.Forte@Sun.COM } 5187836SJohn.Forte@Sun.COM 5197836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxRecvDataSegmentLengthProperties( 5207836SJohn.Forte@Sun.COM IMA_OID Oid, 5217836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 5227836SJohn.Forte@Sun.COM ) 5237836SJohn.Forte@Sun.COM { 5247836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 5257836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH)); 5267836SJohn.Forte@Sun.COM } 5277836SJohn.Forte@Sun.COM 5287836SJohn.Forte@Sun.COM /*ARGSUSED*/ 5297836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_PluginIOCtl( 5307836SJohn.Forte@Sun.COM IMA_OID pluginOid, 5317836SJohn.Forte@Sun.COM IMA_UINT command, 5327836SJohn.Forte@Sun.COM const void *pInputBuffer, 5337836SJohn.Forte@Sun.COM IMA_UINT inputBufferLength, 5347836SJohn.Forte@Sun.COM void *pOutputBuffer, 5357836SJohn.Forte@Sun.COM IMA_UINT *pOutputBufferLength 5367836SJohn.Forte@Sun.COM ) 5377836SJohn.Forte@Sun.COM { 5387836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 5397836SJohn.Forte@Sun.COM } 5407836SJohn.Forte@Sun.COM 5417836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetFirstBurstLength( 5427836SJohn.Forte@Sun.COM IMA_OID lhbaId, 5437836SJohn.Forte@Sun.COM IMA_UINT firstBurstLength 5447836SJohn.Forte@Sun.COM ) 5457836SJohn.Forte@Sun.COM { 5467836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 5477836SJohn.Forte@Sun.COM 5487836SJohn.Forte@Sun.COM mv.currentValue = firstBurstLength; 5497836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 5507836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH)); 5517836SJohn.Forte@Sun.COM } 5527836SJohn.Forte@Sun.COM 5537836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetMaxBurstLength( 5547836SJohn.Forte@Sun.COM IMA_OID lhbaId, 5557836SJohn.Forte@Sun.COM IMA_UINT maxBurstLength 5567836SJohn.Forte@Sun.COM ) 5577836SJohn.Forte@Sun.COM { 5587836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 5597836SJohn.Forte@Sun.COM 5607836SJohn.Forte@Sun.COM mv.currentValue = maxBurstLength; 5617836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 5627836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH)); 5637836SJohn.Forte@Sun.COM } 5647836SJohn.Forte@Sun.COM 5657836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetMaxRecvDataSegmentLength( 5667836SJohn.Forte@Sun.COM IMA_OID lhbaId, 5677836SJohn.Forte@Sun.COM IMA_UINT maxRecvDataSegmentLength 5687836SJohn.Forte@Sun.COM ) 5697836SJohn.Forte@Sun.COM { 5707836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 5717836SJohn.Forte@Sun.COM 5727836SJohn.Forte@Sun.COM mv.currentValue = maxRecvDataSegmentLength; 5737836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 5747836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH)); 5757836SJohn.Forte@Sun.COM } 5767836SJohn.Forte@Sun.COM 5777836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxConnectionsProperties( 5787836SJohn.Forte@Sun.COM IMA_OID Oid, 5797836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 5807836SJohn.Forte@Sun.COM ) 5817836SJohn.Forte@Sun.COM { 5827836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 5837836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_CONNECTIONS)); 5847836SJohn.Forte@Sun.COM } 5857836SJohn.Forte@Sun.COM 5867836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetMaxConnections( 5877836SJohn.Forte@Sun.COM IMA_OID lhbaId, 5887836SJohn.Forte@Sun.COM IMA_UINT maxConnections 5897836SJohn.Forte@Sun.COM ) 5907836SJohn.Forte@Sun.COM { 5917836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 5927836SJohn.Forte@Sun.COM 5937836SJohn.Forte@Sun.COM mv.currentValue = maxConnections; 5947836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 5957836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_MAX_CONNECTIONS)); 5967836SJohn.Forte@Sun.COM } 5977836SJohn.Forte@Sun.COM 5987836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDefaultTime2RetainProperties( 5997836SJohn.Forte@Sun.COM IMA_OID lhbaId, 6007836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 6017836SJohn.Forte@Sun.COM ) 6027836SJohn.Forte@Sun.COM { 6037836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps, 6047836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN)); 6057836SJohn.Forte@Sun.COM } 6067836SJohn.Forte@Sun.COM 6077836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDefaultTime2Retain( 6087836SJohn.Forte@Sun.COM IMA_OID lhbaId, 6097836SJohn.Forte@Sun.COM IMA_UINT defaultTime2Retain 6107836SJohn.Forte@Sun.COM ) 6117836SJohn.Forte@Sun.COM { 6127836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 6137836SJohn.Forte@Sun.COM 6147836SJohn.Forte@Sun.COM mv.currentValue = defaultTime2Retain; 6157836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 6167836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN)); 6177836SJohn.Forte@Sun.COM } 6187836SJohn.Forte@Sun.COM 6197836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDefaultTime2WaitProperties( 6207836SJohn.Forte@Sun.COM IMA_OID lhbaId, 6217836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 6227836SJohn.Forte@Sun.COM ) 6237836SJohn.Forte@Sun.COM { 6247836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps, 6257836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT)); 6267836SJohn.Forte@Sun.COM } 6277836SJohn.Forte@Sun.COM 6287836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDefaultTime2Wait( 6297836SJohn.Forte@Sun.COM IMA_OID lhbaId, 6307836SJohn.Forte@Sun.COM IMA_UINT defaultTime2Wait 6317836SJohn.Forte@Sun.COM ) 6327836SJohn.Forte@Sun.COM { 6337836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 6347836SJohn.Forte@Sun.COM 6357836SJohn.Forte@Sun.COM mv.currentValue = defaultTime2Wait; 6367836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 6377836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT)); 6387836SJohn.Forte@Sun.COM } 6397836SJohn.Forte@Sun.COM 6407836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetMaxOutstandingR2TProperties( 6417836SJohn.Forte@Sun.COM IMA_OID Oid, 6427836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 6437836SJohn.Forte@Sun.COM ) 6447836SJohn.Forte@Sun.COM { 6457836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 6467836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_OUTSTANDING_R2T)); 6477836SJohn.Forte@Sun.COM } 6487836SJohn.Forte@Sun.COM 6497836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetMaxOutstandingR2T( 6507836SJohn.Forte@Sun.COM IMA_OID lhbaId, 6517836SJohn.Forte@Sun.COM IMA_UINT maxOutstandingR2T 6527836SJohn.Forte@Sun.COM ) 6537836SJohn.Forte@Sun.COM { 6547836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 6557836SJohn.Forte@Sun.COM 6567836SJohn.Forte@Sun.COM mv.currentValue = maxOutstandingR2T; 6577836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv, 6587836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_OUTSTANDING_R2T)); 6597836SJohn.Forte@Sun.COM } 6607836SJohn.Forte@Sun.COM 6617836SJohn.Forte@Sun.COM 6627836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetErrorRecoveryLevelProperties( 6637836SJohn.Forte@Sun.COM IMA_OID Oid, 6647836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *pProps 6657836SJohn.Forte@Sun.COM ) 6667836SJohn.Forte@Sun.COM { 6677836SJohn.Forte@Sun.COM return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps, 6687836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL)); 6697836SJohn.Forte@Sun.COM } 6707836SJohn.Forte@Sun.COM 6717836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetErrorRecoveryLevel( 6727836SJohn.Forte@Sun.COM IMA_OID Oid, 6737836SJohn.Forte@Sun.COM IMA_UINT errorRecoveryLevel 6747836SJohn.Forte@Sun.COM ) 6757836SJohn.Forte@Sun.COM { 6767836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE mv; 6777836SJohn.Forte@Sun.COM 6787836SJohn.Forte@Sun.COM mv.currentValue = errorRecoveryLevel; 6797836SJohn.Forte@Sun.COM return (setISCSINodeParameter(MIN_MAX_PARAM, &Oid, &mv, 6807836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL)); 6817836SJohn.Forte@Sun.COM } 6827836SJohn.Forte@Sun.COM 6837836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetInitialR2TProperties( 6847836SJohn.Forte@Sun.COM IMA_OID Oid, 6857836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *pProps 6867836SJohn.Forte@Sun.COM ) 6877836SJohn.Forte@Sun.COM { 6887836SJohn.Forte@Sun.COM return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps, 6897836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_INITIAL_R2T)); 6907836SJohn.Forte@Sun.COM } 6917836SJohn.Forte@Sun.COM 6927836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetInitialR2T( 6937836SJohn.Forte@Sun.COM IMA_OID Oid, 6947836SJohn.Forte@Sun.COM IMA_BOOL initialR2T 6957836SJohn.Forte@Sun.COM ) 6967836SJohn.Forte@Sun.COM { 6977836SJohn.Forte@Sun.COM IMA_BOOL_VALUE bv; 6987836SJohn.Forte@Sun.COM 6997836SJohn.Forte@Sun.COM bv.currentValue = initialR2T; 7007836SJohn.Forte@Sun.COM return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv, 7017836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_INITIAL_R2T)); 7027836SJohn.Forte@Sun.COM } 7037836SJohn.Forte@Sun.COM 7047836SJohn.Forte@Sun.COM 7057836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetImmediateDataProperties( 7067836SJohn.Forte@Sun.COM IMA_OID Oid, 7077836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *pProps 7087836SJohn.Forte@Sun.COM ) 7097836SJohn.Forte@Sun.COM { 7107836SJohn.Forte@Sun.COM return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps, 7117836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_IMMEDIATE_DATA)); 7127836SJohn.Forte@Sun.COM } 7137836SJohn.Forte@Sun.COM 7147836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetImmediateData( 7157836SJohn.Forte@Sun.COM IMA_OID Oid, 7167836SJohn.Forte@Sun.COM IMA_BOOL immediateData 7177836SJohn.Forte@Sun.COM ) 7187836SJohn.Forte@Sun.COM { 7197836SJohn.Forte@Sun.COM IMA_BOOL_VALUE bv; 7207836SJohn.Forte@Sun.COM 7217836SJohn.Forte@Sun.COM bv.currentValue = immediateData; 7227836SJohn.Forte@Sun.COM return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv, 7237836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_IMMEDIATE_DATA)); 7247836SJohn.Forte@Sun.COM } 7257836SJohn.Forte@Sun.COM 7267836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDataPduInOrderProperties( 7277836SJohn.Forte@Sun.COM IMA_OID Oid, 7287836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *pProps 7297836SJohn.Forte@Sun.COM ) 7307836SJohn.Forte@Sun.COM { 7317836SJohn.Forte@Sun.COM return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps, 7327836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER)); 7337836SJohn.Forte@Sun.COM } 7347836SJohn.Forte@Sun.COM 7357836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDataPduInOrder( 7367836SJohn.Forte@Sun.COM IMA_OID Oid, 7377836SJohn.Forte@Sun.COM IMA_BOOL dataPduInOrder 7387836SJohn.Forte@Sun.COM ) 7397836SJohn.Forte@Sun.COM { 7407836SJohn.Forte@Sun.COM IMA_BOOL_VALUE bv; 7417836SJohn.Forte@Sun.COM 7427836SJohn.Forte@Sun.COM bv.currentValue = dataPduInOrder; 7437836SJohn.Forte@Sun.COM return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv, 7447836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER)); 7457836SJohn.Forte@Sun.COM } 7467836SJohn.Forte@Sun.COM 7477836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDataSequenceInOrderProperties( 7487836SJohn.Forte@Sun.COM IMA_OID Oid, 7497836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *pProps 7507836SJohn.Forte@Sun.COM ) 7517836SJohn.Forte@Sun.COM { 7527836SJohn.Forte@Sun.COM return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps, 7537836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER)); 7547836SJohn.Forte@Sun.COM } 7557836SJohn.Forte@Sun.COM 7567836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDataSequenceInOrder( 7577836SJohn.Forte@Sun.COM IMA_OID Oid, 7587836SJohn.Forte@Sun.COM IMA_BOOL dataSequenceInOrder 7597836SJohn.Forte@Sun.COM ) 7607836SJohn.Forte@Sun.COM { 7617836SJohn.Forte@Sun.COM IMA_BOOL_VALUE bv; 7627836SJohn.Forte@Sun.COM 7637836SJohn.Forte@Sun.COM bv.currentValue = dataSequenceInOrder; 7647836SJohn.Forte@Sun.COM return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv, 7657836SJohn.Forte@Sun.COM ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER)); 7667836SJohn.Forte@Sun.COM } 7677836SJohn.Forte@Sun.COM 7687836SJohn.Forte@Sun.COM 7697836SJohn.Forte@Sun.COM /*ARGSUSED*/ 7707836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetStatisticsCollection( 7717836SJohn.Forte@Sun.COM IMA_OID Oid, 7727836SJohn.Forte@Sun.COM IMA_BOOL enableStatisticsCollection 7737836SJohn.Forte@Sun.COM ) 7747836SJohn.Forte@Sun.COM { 7757836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 7767836SJohn.Forte@Sun.COM } 7777836SJohn.Forte@Sun.COM 7787836SJohn.Forte@Sun.COM 7797836SJohn.Forte@Sun.COM /*ARGSUSED*/ 7807836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDiscoveryAddressOidList( 7817836SJohn.Forte@Sun.COM IMA_OID Oid, 7827836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 7837836SJohn.Forte@Sun.COM ) 7847836SJohn.Forte@Sun.COM { 7857836SJohn.Forte@Sun.COM int fd, i, addr_list_size; 7867836SJohn.Forte@Sun.COM iscsi_addr_list_t *idlp, al_info; 7877836SJohn.Forte@Sun.COM 7887836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 7897836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 7907836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 7917836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 7927836SJohn.Forte@Sun.COM } 7937836SJohn.Forte@Sun.COM 7947836SJohn.Forte@Sun.COM (void) memset(&al_info, 0, sizeof (al_info)); 7957836SJohn.Forte@Sun.COM al_info.al_vers = ISCSI_INTERFACE_VERSION; 7967836SJohn.Forte@Sun.COM al_info.al_in_cnt = 0; 7977836SJohn.Forte@Sun.COM 7987836SJohn.Forte@Sun.COM /* 7997836SJohn.Forte@Sun.COM * Issue ioctl to obtain the number of targets. 8007836SJohn.Forte@Sun.COM */ 8017836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 8027836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 8037836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 8047836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 8057836SJohn.Forte@Sun.COM (void) close(fd); 8067836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 8077836SJohn.Forte@Sun.COM } 8087836SJohn.Forte@Sun.COM 8097836SJohn.Forte@Sun.COM addr_list_size = sizeof (iscsi_addr_list_t); 8107836SJohn.Forte@Sun.COM if (al_info.al_out_cnt > 1) { 8117836SJohn.Forte@Sun.COM addr_list_size += (sizeof (iscsi_addr_list_t) * 8127836SJohn.Forte@Sun.COM al_info.al_out_cnt - 1); 8137836SJohn.Forte@Sun.COM } 8147836SJohn.Forte@Sun.COM 8157836SJohn.Forte@Sun.COM idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size); 8167836SJohn.Forte@Sun.COM if (idlp == NULL) { 8177836SJohn.Forte@Sun.COM (void) close(fd); 8187836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 8197836SJohn.Forte@Sun.COM } 8207836SJohn.Forte@Sun.COM 8217836SJohn.Forte@Sun.COM idlp->al_vers = ISCSI_INTERFACE_VERSION; 8227836SJohn.Forte@Sun.COM idlp->al_in_cnt = al_info.al_out_cnt; 8237836SJohn.Forte@Sun.COM /* Issue the same ioctl again to obtain the OIDs. */ 8247836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) { 8257836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 8267836SJohn.Forte@Sun.COM "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 8277836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 8287836SJohn.Forte@Sun.COM free(idlp); 8297836SJohn.Forte@Sun.COM (void) close(fd); 8307836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 8317836SJohn.Forte@Sun.COM } 8327836SJohn.Forte@Sun.COM 8337836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) + 8347836SJohn.Forte@Sun.COM idlp->al_out_cnt * sizeof (IMA_OID)); 8357836SJohn.Forte@Sun.COM if (*ppList == NULL) { 8367836SJohn.Forte@Sun.COM free(idlp); 8377836SJohn.Forte@Sun.COM (void) close(fd); 8387836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 8397836SJohn.Forte@Sun.COM } 8407836SJohn.Forte@Sun.COM (*ppList)->oidCount = idlp->al_out_cnt; 8417836SJohn.Forte@Sun.COM 8427836SJohn.Forte@Sun.COM for (i = 0; i < idlp->al_out_cnt; i++) { 8437836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectType = 8447836SJohn.Forte@Sun.COM IMA_OBJECT_TYPE_DISCOVERY_ADDRESS; 8457836SJohn.Forte@Sun.COM (*ppList)->oids[i].ownerId = pluginOwnerId; 8467836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectSequenceNumber = 8477836SJohn.Forte@Sun.COM idlp->al_addrs[i].a_oid; 8487836SJohn.Forte@Sun.COM } 8497836SJohn.Forte@Sun.COM 8507836SJohn.Forte@Sun.COM free(idlp); 8517836SJohn.Forte@Sun.COM (void) close(fd); 8527836SJohn.Forte@Sun.COM 8537836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 8547836SJohn.Forte@Sun.COM } 8557836SJohn.Forte@Sun.COM 8567836SJohn.Forte@Sun.COM 8577836SJohn.Forte@Sun.COM /* ARGSUSED */ 8587836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetStaticDiscoveryTargetOidList( 8597836SJohn.Forte@Sun.COM IMA_OID Oid, 8607836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 8617836SJohn.Forte@Sun.COM ) 8627836SJohn.Forte@Sun.COM { 8637836SJohn.Forte@Sun.COM if (Oid.objectType == IMA_OBJECT_TYPE_PNP) { 8647836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 8657836SJohn.Forte@Sun.COM } 8667836SJohn.Forte@Sun.COM 8677836SJohn.Forte@Sun.COM return (get_target_oid_list(ISCSI_STATIC_TGT_OID_LIST, ppList)); 8687836SJohn.Forte@Sun.COM } 8697836SJohn.Forte@Sun.COM 8707836SJohn.Forte@Sun.COM /* ARGSUSED */ 8717836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetTargetOidList( 8727836SJohn.Forte@Sun.COM IMA_OID Oid, 8737836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 8747836SJohn.Forte@Sun.COM ) 8757836SJohn.Forte@Sun.COM { 8767836SJohn.Forte@Sun.COM return (get_target_oid_list(ISCSI_TGT_PARAM_OID_LIST, ppList)); 8777836SJohn.Forte@Sun.COM } 8787836SJohn.Forte@Sun.COM 8797836SJohn.Forte@Sun.COM /*ARGSUSED*/ 8807836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetIsnsDiscovery( 8817836SJohn.Forte@Sun.COM IMA_OID phbaId, 8827836SJohn.Forte@Sun.COM IMA_BOOL enableIsnsDiscovery, 8837836SJohn.Forte@Sun.COM IMA_ISNS_DISCOVERY_METHOD discoveryMethod, 8847836SJohn.Forte@Sun.COM const IMA_HOST_ID *iSnsHost 8857836SJohn.Forte@Sun.COM ) 8867836SJohn.Forte@Sun.COM { 8877836SJohn.Forte@Sun.COM /* XXX need to set discovery Method and domaineName */ 8887836SJohn.Forte@Sun.COM return (configure_discovery_method(enableIsnsDiscovery, 8897836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodISNS)); 8907836SJohn.Forte@Sun.COM } 8917836SJohn.Forte@Sun.COM 8927836SJohn.Forte@Sun.COM 8937836SJohn.Forte@Sun.COM /* ARGSUSED */ 8947836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetSlpDiscovery( 8957836SJohn.Forte@Sun.COM IMA_OID phbaId, 8967836SJohn.Forte@Sun.COM IMA_BOOL enableSlpDiscovery 8977836SJohn.Forte@Sun.COM ) 8987836SJohn.Forte@Sun.COM { 8997836SJohn.Forte@Sun.COM return (configure_discovery_method(enableSlpDiscovery, 9007836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodSLP)); 9017836SJohn.Forte@Sun.COM } 9027836SJohn.Forte@Sun.COM 9037836SJohn.Forte@Sun.COM 9047836SJohn.Forte@Sun.COM /* ARGSUSED */ 9057836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetStaticDiscovery( 9067836SJohn.Forte@Sun.COM IMA_OID phbaId, 9077836SJohn.Forte@Sun.COM IMA_BOOL enableStaticDiscovery 9087836SJohn.Forte@Sun.COM ) 9097836SJohn.Forte@Sun.COM { 9107836SJohn.Forte@Sun.COM return (configure_discovery_method(enableStaticDiscovery, 9117836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodStatic)); 9127836SJohn.Forte@Sun.COM } 9137836SJohn.Forte@Sun.COM 9147836SJohn.Forte@Sun.COM /* ARGSUSED */ 9157836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetSendTargetsDiscovery( 9167836SJohn.Forte@Sun.COM IMA_OID phbaId, 9177836SJohn.Forte@Sun.COM IMA_BOOL enableSendTargetsDiscovery 9187836SJohn.Forte@Sun.COM ) 9197836SJohn.Forte@Sun.COM { 9207836SJohn.Forte@Sun.COM return (configure_discovery_method(enableSendTargetsDiscovery, 9217836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodSendTargets)); 9227836SJohn.Forte@Sun.COM } 9237836SJohn.Forte@Sun.COM 9247836SJohn.Forte@Sun.COM /*ARGSUSED*/ 9257836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveDiscoveryAddress( 9267836SJohn.Forte@Sun.COM IMA_OID discoveryAddressOid 9277836SJohn.Forte@Sun.COM ) 9287836SJohn.Forte@Sun.COM { 9297836SJohn.Forte@Sun.COM int status, fd, i, addr_list_size; 9307836SJohn.Forte@Sun.COM iscsi_addr_list_t *idlp, al_info; 9317836SJohn.Forte@Sun.COM iscsi_addr_t *matched_addr = NULL; 9327836SJohn.Forte@Sun.COM entry_t entry; 9337836SJohn.Forte@Sun.COM 9347836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 9357836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 9367836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 9377836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 9387836SJohn.Forte@Sun.COM } 9397836SJohn.Forte@Sun.COM 9407836SJohn.Forte@Sun.COM (void) memset(&al_info, 0, sizeof (al_info)); 9417836SJohn.Forte@Sun.COM al_info.al_vers = ISCSI_INTERFACE_VERSION; 9427836SJohn.Forte@Sun.COM al_info.al_in_cnt = 0; 9437836SJohn.Forte@Sun.COM 9447836SJohn.Forte@Sun.COM /* 9457836SJohn.Forte@Sun.COM * Issue ioctl to obtain the number of discovery address. 9467836SJohn.Forte@Sun.COM */ 9477836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 9487836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 9497836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 9507836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 9517836SJohn.Forte@Sun.COM (void) close(fd); 9527836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 9537836SJohn.Forte@Sun.COM } 9547836SJohn.Forte@Sun.COM 9557836SJohn.Forte@Sun.COM if (al_info.al_out_cnt == 0) { 9567836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 9577836SJohn.Forte@Sun.COM } 9587836SJohn.Forte@Sun.COM 9597836SJohn.Forte@Sun.COM addr_list_size = sizeof (iscsi_addr_list_t); 9607836SJohn.Forte@Sun.COM if (al_info.al_out_cnt > 1) { 9617836SJohn.Forte@Sun.COM addr_list_size += (sizeof (iscsi_addr_list_t) * 9627836SJohn.Forte@Sun.COM al_info.al_out_cnt - 1); 9637836SJohn.Forte@Sun.COM } 9647836SJohn.Forte@Sun.COM 9657836SJohn.Forte@Sun.COM idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size); 9667836SJohn.Forte@Sun.COM if (idlp == NULL) { 9677836SJohn.Forte@Sun.COM (void) close(fd); 9687836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 9697836SJohn.Forte@Sun.COM } 9707836SJohn.Forte@Sun.COM 9717836SJohn.Forte@Sun.COM idlp->al_vers = ISCSI_INTERFACE_VERSION; 9727836SJohn.Forte@Sun.COM idlp->al_in_cnt = al_info.al_out_cnt; 9737836SJohn.Forte@Sun.COM 9747836SJohn.Forte@Sun.COM /* Issue the same ioctl again to obtain the OIDs. */ 9757836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) { 9767836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 9777836SJohn.Forte@Sun.COM "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 9787836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 9797836SJohn.Forte@Sun.COM free(idlp); 9807836SJohn.Forte@Sun.COM (void) close(fd); 9817836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 9827836SJohn.Forte@Sun.COM } 9837836SJohn.Forte@Sun.COM 9847836SJohn.Forte@Sun.COM for (i = 0; i < idlp->al_out_cnt; i++) { 9857836SJohn.Forte@Sun.COM if (discoveryAddressOid.objectSequenceNumber != 9867836SJohn.Forte@Sun.COM idlp->al_addrs[i].a_oid) 9877836SJohn.Forte@Sun.COM continue; 9887836SJohn.Forte@Sun.COM matched_addr = &(idlp->al_addrs[i]); 9897836SJohn.Forte@Sun.COM } 9907836SJohn.Forte@Sun.COM 9917836SJohn.Forte@Sun.COM if (matched_addr == NULL) { 9927836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 9937836SJohn.Forte@Sun.COM } 9947836SJohn.Forte@Sun.COM 9957836SJohn.Forte@Sun.COM 9967836SJohn.Forte@Sun.COM (void) memset(&entry, 0, sizeof (entry_t)); 9977836SJohn.Forte@Sun.COM entry.e_vers = ISCSI_INTERFACE_VERSION; 9987836SJohn.Forte@Sun.COM entry.e_oid = discoveryAddressOid.objectSequenceNumber; 9997836SJohn.Forte@Sun.COM if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) { 10007836SJohn.Forte@Sun.COM bcopy(&matched_addr->a_addr.i_addr.in4, 10017836SJohn.Forte@Sun.COM &entry.e_u.u_in4, sizeof (entry.e_u.u_in4)); 10027836SJohn.Forte@Sun.COM entry.e_insize = sizeof (struct in_addr); 10037836SJohn.Forte@Sun.COM } else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) { 10047836SJohn.Forte@Sun.COM bcopy(&matched_addr->a_addr.i_addr.in6, 10057836SJohn.Forte@Sun.COM &entry.e_u.u_in6, sizeof (entry.e_u.u_in6)); 10067836SJohn.Forte@Sun.COM entry.e_insize = sizeof (struct in6_addr); 10077836SJohn.Forte@Sun.COM } else { 10087836SJohn.Forte@Sun.COM /* Should not happen */ 10097836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 10107836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 10117836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 10127836SJohn.Forte@Sun.COM } 10137836SJohn.Forte@Sun.COM 10147836SJohn.Forte@Sun.COM entry.e_port = matched_addr->a_port; 10157836SJohn.Forte@Sun.COM entry.e_tpgt = 0; 10167836SJohn.Forte@Sun.COM entry.e_oid = discoveryAddressOid.objectSequenceNumber; 10177836SJohn.Forte@Sun.COM 10187836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_CLEAR, &entry)) { 10197836SJohn.Forte@Sun.COM status = errno; 10207836SJohn.Forte@Sun.COM (void) close(fd); 10217836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 10227836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_CLEAR ioctl failed, errno: %d", 10237836SJohn.Forte@Sun.COM errno); 10247836SJohn.Forte@Sun.COM if (status == EBUSY) { 10257836SJohn.Forte@Sun.COM return (IMA_ERROR_LU_IN_USE); 10267836SJohn.Forte@Sun.COM } else { 10277836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 10287836SJohn.Forte@Sun.COM } 10297836SJohn.Forte@Sun.COM } 10307836SJohn.Forte@Sun.COM 10317836SJohn.Forte@Sun.COM free(idlp); 10327836SJohn.Forte@Sun.COM (void) close(fd); 10337836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 10347836SJohn.Forte@Sun.COM } 10357836SJohn.Forte@Sun.COM 10367836SJohn.Forte@Sun.COM 10377836SJohn.Forte@Sun.COM /*ARGSUSED*/ 10387836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_AddDiscoveryAddress( 10397836SJohn.Forte@Sun.COM IMA_OID oid, 10407836SJohn.Forte@Sun.COM const IMA_TARGET_ADDRESS discoveryAddress, 10417836SJohn.Forte@Sun.COM IMA_OID *pDiscoveryAddressOid 10427836SJohn.Forte@Sun.COM ) 10437836SJohn.Forte@Sun.COM { 10447836SJohn.Forte@Sun.COM entry_t entry; 10457836SJohn.Forte@Sun.COM int fd; 10467836SJohn.Forte@Sun.COM 10477836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 10487836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 10497836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 10507836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 10517836SJohn.Forte@Sun.COM } 10527836SJohn.Forte@Sun.COM 10537836SJohn.Forte@Sun.COM if (prepare_discovery_entry(discoveryAddress, &entry) != 10547836SJohn.Forte@Sun.COM DISC_ADDR_OK) { 10557836SJohn.Forte@Sun.COM (void) close(fd); 10567836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 10577836SJohn.Forte@Sun.COM } 10587836SJohn.Forte@Sun.COM 10597836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_SET, &entry)) { 10607836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 10617836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_SET ioctl failed, errno: %d", 10627836SJohn.Forte@Sun.COM errno); 10637836SJohn.Forte@Sun.COM (void) close(fd); 10647836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 10657836SJohn.Forte@Sun.COM } 10667836SJohn.Forte@Sun.COM 10677836SJohn.Forte@Sun.COM pDiscoveryAddressOid->ownerId = pluginOwnerId; 10687836SJohn.Forte@Sun.COM pDiscoveryAddressOid->objectType = IMA_OBJECT_TYPE_DISCOVERY_ADDRESS; 10697836SJohn.Forte@Sun.COM pDiscoveryAddressOid->objectSequenceNumber = entry.e_oid; 10707836SJohn.Forte@Sun.COM 10717836SJohn.Forte@Sun.COM (void) close(fd); 10727836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 10737836SJohn.Forte@Sun.COM } 10747836SJohn.Forte@Sun.COM 10757836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetStaticDiscoveryTargetProperties( 10767836SJohn.Forte@Sun.COM IMA_OID staticTargetOid, 10777836SJohn.Forte@Sun.COM IMA_STATIC_DISCOVERY_TARGET_PROPERTIES *pProps 10787836SJohn.Forte@Sun.COM ) 10797836SJohn.Forte@Sun.COM { 10807836SJohn.Forte@Sun.COM char static_target_addr_str[SUN_IMA_IP_ADDRESS_LEN]; 10817836SJohn.Forte@Sun.COM char static_target_addr_port_str[SUN_IMA_IP_ADDRESS_LEN]; 10827836SJohn.Forte@Sun.COM int af, fd, status; 10837836SJohn.Forte@Sun.COM iscsi_static_property_t prop; 10847836SJohn.Forte@Sun.COM /* LINTED */ 10857836SJohn.Forte@Sun.COM IMA_HOST_ID *host; 10867836SJohn.Forte@Sun.COM 10877836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 10887836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 10897836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 10907836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 10917836SJohn.Forte@Sun.COM } 10927836SJohn.Forte@Sun.COM 10937836SJohn.Forte@Sun.COM (void) memset(&prop, 0, sizeof (iscsi_static_property_t)); 10947836SJohn.Forte@Sun.COM prop.p_vers = ISCSI_INTERFACE_VERSION; 10957836SJohn.Forte@Sun.COM prop.p_oid = (uint32_t)staticTargetOid.objectSequenceNumber; 10967836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_STATIC_GET, &prop) != 0) { 10977836SJohn.Forte@Sun.COM status = errno; 10987836SJohn.Forte@Sun.COM (void) close(fd); 10997836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 11007836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET ioctl failed, errno: %d", status); 11017836SJohn.Forte@Sun.COM if (status == ENOENT) { 11027836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 11037836SJohn.Forte@Sun.COM 11047836SJohn.Forte@Sun.COM } else { 11057836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 11067836SJohn.Forte@Sun.COM } 11077836SJohn.Forte@Sun.COM } 11087836SJohn.Forte@Sun.COM (void) close(fd); 11097836SJohn.Forte@Sun.COM 11107836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->staticTarget.targetName, (char *)prop.p_name, 11117836SJohn.Forte@Sun.COM sizeof (pProps->staticTarget.targetName)/sizeof (IMA_WCHAR)); 11127836SJohn.Forte@Sun.COM 11137836SJohn.Forte@Sun.COM if (prop.p_addr_list.al_addrs[0].a_addr.i_insize == 11147836SJohn.Forte@Sun.COM sizeof (struct in_addr)) { 11157836SJohn.Forte@Sun.COM /* IPv4 */ 11167836SJohn.Forte@Sun.COM af = AF_INET; 11177836SJohn.Forte@Sun.COM } else if (prop.p_addr_list.al_addrs[0].a_addr.i_insize == 11187836SJohn.Forte@Sun.COM sizeof (struct in6_addr)) { 11197836SJohn.Forte@Sun.COM /* IPv6 */ 11207836SJohn.Forte@Sun.COM af = AF_INET6; 11217836SJohn.Forte@Sun.COM } else { 11227836SJohn.Forte@Sun.COM /* Should not happen */ 11237836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 11247836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 11257836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 11267836SJohn.Forte@Sun.COM } 11277836SJohn.Forte@Sun.COM 11287836SJohn.Forte@Sun.COM if (inet_ntop(af, &prop.p_addr_list.al_addrs[0].a_addr.i_addr, 11297836SJohn.Forte@Sun.COM static_target_addr_str, sizeof (static_target_addr_str)) == NULL) { 11307836SJohn.Forte@Sun.COM /* Should not happen */ 11317836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 11327836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned address that cannot " 11337836SJohn.Forte@Sun.COM "be inet_ntop"); 11347836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 11357836SJohn.Forte@Sun.COM } else { 11367836SJohn.Forte@Sun.COM if (af == AF_INET) { 11377836SJohn.Forte@Sun.COM (void) snprintf(static_target_addr_port_str, 11387836SJohn.Forte@Sun.COM SUN_IMA_IP_ADDRESS_LEN, 11397836SJohn.Forte@Sun.COM "%s:%ld", 11407836SJohn.Forte@Sun.COM static_target_addr_str, 11417836SJohn.Forte@Sun.COM prop.p_addr_list.al_addrs[0].a_port); 11427836SJohn.Forte@Sun.COM } else { 11437836SJohn.Forte@Sun.COM (void) snprintf(static_target_addr_port_str, 11447836SJohn.Forte@Sun.COM SUN_IMA_IP_ADDRESS_LEN, 11457836SJohn.Forte@Sun.COM "[%s]:%ld", 11467836SJohn.Forte@Sun.COM static_target_addr_str, 11477836SJohn.Forte@Sun.COM prop.p_addr_list.al_addrs[0].a_port); 11487836SJohn.Forte@Sun.COM } 11497836SJohn.Forte@Sun.COM host = &pProps->staticTarget.targetAddress.hostnameIpAddress; 11507836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->staticTarget. 11517836SJohn.Forte@Sun.COM targetAddress.hostnameIpAddress. 11527836SJohn.Forte@Sun.COM id.hostname, static_target_addr_port_str, 11537836SJohn.Forte@Sun.COM sizeof (host->id.hostname) / sizeof (IMA_WCHAR)); 11547836SJohn.Forte@Sun.COM } 11557836SJohn.Forte@Sun.COM 11567836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 11577836SJohn.Forte@Sun.COM } 11587836SJohn.Forte@Sun.COM 11597836SJohn.Forte@Sun.COM /*ARGSUSED*/ 11607836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDiscoveryAddressProperties( 11617836SJohn.Forte@Sun.COM IMA_OID discoveryAddressOid, 11627836SJohn.Forte@Sun.COM IMA_DISCOVERY_ADDRESS_PROPERTIES *pProps 11637836SJohn.Forte@Sun.COM ) 11647836SJohn.Forte@Sun.COM { 11657836SJohn.Forte@Sun.COM int fd; 11667836SJohn.Forte@Sun.COM int i; 11677836SJohn.Forte@Sun.COM int addr_list_size; 11687836SJohn.Forte@Sun.COM iscsi_addr_list_t *idlp, al_info; 11697836SJohn.Forte@Sun.COM iscsi_addr_t *matched_addr = NULL; 11707836SJohn.Forte@Sun.COM /* LINTED */ 11717836SJohn.Forte@Sun.COM IMA_TARGET_ADDRESS *addr; 11727836SJohn.Forte@Sun.COM 11737836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 11747836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 11757836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 11767836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 11777836SJohn.Forte@Sun.COM } 11787836SJohn.Forte@Sun.COM 11797836SJohn.Forte@Sun.COM (void) memset(&al_info, 0, sizeof (al_info)); 11807836SJohn.Forte@Sun.COM al_info.al_vers = ISCSI_INTERFACE_VERSION; 11817836SJohn.Forte@Sun.COM al_info.al_in_cnt = 0; 11827836SJohn.Forte@Sun.COM 11837836SJohn.Forte@Sun.COM /* 11847836SJohn.Forte@Sun.COM * Issue ioctl to obtain the number of discovery addresses. 11857836SJohn.Forte@Sun.COM */ 11867836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 11877836SJohn.Forte@Sun.COM (void) close(fd); 11887836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 11897836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d", 11907836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 11917836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 11927836SJohn.Forte@Sun.COM } 11937836SJohn.Forte@Sun.COM 11947836SJohn.Forte@Sun.COM if (al_info.al_out_cnt == 0) { 11957836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 11967836SJohn.Forte@Sun.COM } 11977836SJohn.Forte@Sun.COM 11987836SJohn.Forte@Sun.COM addr_list_size = sizeof (iscsi_addr_list_t); 11997836SJohn.Forte@Sun.COM if (al_info.al_out_cnt > 1) { 12007836SJohn.Forte@Sun.COM addr_list_size += (sizeof (iscsi_addr_list_t) * 12017836SJohn.Forte@Sun.COM al_info.al_out_cnt - 1); 12027836SJohn.Forte@Sun.COM } 12037836SJohn.Forte@Sun.COM 12047836SJohn.Forte@Sun.COM idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size); 12057836SJohn.Forte@Sun.COM if (idlp == NULL) { 12067836SJohn.Forte@Sun.COM (void) close(fd); 12077836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 12087836SJohn.Forte@Sun.COM } 12097836SJohn.Forte@Sun.COM 12107836SJohn.Forte@Sun.COM idlp->al_vers = ISCSI_INTERFACE_VERSION; 12117836SJohn.Forte@Sun.COM idlp->al_in_cnt = al_info.al_out_cnt; 12127836SJohn.Forte@Sun.COM 12137836SJohn.Forte@Sun.COM /* Issue the same ioctl again to obtain the OIDs. */ 12147836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) { 12157836SJohn.Forte@Sun.COM free(idlp); 12167836SJohn.Forte@Sun.COM (void) close(fd); 12177836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 12187836SJohn.Forte@Sun.COM "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 12197836SJohn.Forte@Sun.COM ISCSI_DISCOVERY_ADDR_LIST_GET, errno); 12207836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 12217836SJohn.Forte@Sun.COM } 12227836SJohn.Forte@Sun.COM 12237836SJohn.Forte@Sun.COM for (i = 0; i < idlp->al_out_cnt; i++) { 12247836SJohn.Forte@Sun.COM if (discoveryAddressOid.objectSequenceNumber != 12257836SJohn.Forte@Sun.COM idlp->al_addrs[i].a_oid) 12267836SJohn.Forte@Sun.COM continue; 12277836SJohn.Forte@Sun.COM matched_addr = &(idlp->al_addrs[i]); 12287836SJohn.Forte@Sun.COM } 12297836SJohn.Forte@Sun.COM 12307836SJohn.Forte@Sun.COM if (matched_addr == NULL) { 12317836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 12327836SJohn.Forte@Sun.COM } 12337836SJohn.Forte@Sun.COM 12347836SJohn.Forte@Sun.COM if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) { 12357836SJohn.Forte@Sun.COM pProps->discoveryAddress.hostnameIpAddress.id. 12367836SJohn.Forte@Sun.COM ipAddress.ipv4Address = IMA_TRUE; 12377836SJohn.Forte@Sun.COM } else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) { 12387836SJohn.Forte@Sun.COM pProps->discoveryAddress.hostnameIpAddress.id. 12397836SJohn.Forte@Sun.COM ipAddress.ipv4Address = IMA_FALSE; 12407836SJohn.Forte@Sun.COM } else { 12417836SJohn.Forte@Sun.COM /* Should not happen */ 12427836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 12437836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 12447836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 12457836SJohn.Forte@Sun.COM } 12467836SJohn.Forte@Sun.COM 12477836SJohn.Forte@Sun.COM addr = &pProps->discoveryAddress; 12487836SJohn.Forte@Sun.COM bcopy(&(matched_addr->a_addr.i_addr), pProps->discoveryAddress. 12497836SJohn.Forte@Sun.COM hostnameIpAddress.id.ipAddress.ipAddress, 12507836SJohn.Forte@Sun.COM sizeof (addr->hostnameIpAddress.id.ipAddress.ipAddress)); 12517836SJohn.Forte@Sun.COM 12527836SJohn.Forte@Sun.COM pProps->discoveryAddress.portNumber = matched_addr->a_port; 12537836SJohn.Forte@Sun.COM 12547836SJohn.Forte@Sun.COM pProps->associatedLhbaOid.objectType = IMA_OBJECT_TYPE_LHBA; 12557836SJohn.Forte@Sun.COM pProps->associatedLhbaOid.ownerId = pluginOwnerId; 12567836SJohn.Forte@Sun.COM pProps->associatedLhbaOid.objectSequenceNumber = ISCSI_INITIATOR_OID; 12577836SJohn.Forte@Sun.COM 12587836SJohn.Forte@Sun.COM free(idlp); 12597836SJohn.Forte@Sun.COM (void) close(fd); 12607836SJohn.Forte@Sun.COM 12617836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 12627836SJohn.Forte@Sun.COM } 12637836SJohn.Forte@Sun.COM 12647836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveStaticDiscoveryTarget( 12657836SJohn.Forte@Sun.COM IMA_OID staticTargetOid 12667836SJohn.Forte@Sun.COM ) 12677836SJohn.Forte@Sun.COM { 12687836SJohn.Forte@Sun.COM entry_t entry; 12697836SJohn.Forte@Sun.COM int status, fd; 12707836SJohn.Forte@Sun.COM 12717836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 12727836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 12737836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 12747836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 12757836SJohn.Forte@Sun.COM } 12767836SJohn.Forte@Sun.COM 12777836SJohn.Forte@Sun.COM (void) memset(&entry, 0, sizeof (entry_t)); 12787836SJohn.Forte@Sun.COM entry.e_vers = ISCSI_INTERFACE_VERSION; 12797836SJohn.Forte@Sun.COM entry.e_oid = (uint32_t)staticTargetOid.objectSequenceNumber; 12807836SJohn.Forte@Sun.COM 12817836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_STATIC_CLEAR, &entry)) { 12827836SJohn.Forte@Sun.COM status = errno; 12837836SJohn.Forte@Sun.COM (void) close(fd); 12847836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 12857836SJohn.Forte@Sun.COM "ISCSI_STATIC_CLEAR ioctl failed, errno: %d", errno); 12867836SJohn.Forte@Sun.COM if (status == EBUSY) { 12877836SJohn.Forte@Sun.COM return (IMA_ERROR_LU_IN_USE); 12887836SJohn.Forte@Sun.COM } else { 12897836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 12907836SJohn.Forte@Sun.COM } 12917836SJohn.Forte@Sun.COM } 12927836SJohn.Forte@Sun.COM 12937836SJohn.Forte@Sun.COM (void) close(fd); 12947836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 12957836SJohn.Forte@Sun.COM } 12967836SJohn.Forte@Sun.COM 12977836SJohn.Forte@Sun.COM /*ARGSUSED*/ 12987836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_AddStaticDiscoveryTarget( 12997836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 13007836SJohn.Forte@Sun.COM const IMA_STATIC_DISCOVERY_TARGET staticConfig, 13017836SJohn.Forte@Sun.COM IMA_OID *pTargetOid 13027836SJohn.Forte@Sun.COM ) 13037836SJohn.Forte@Sun.COM { 13047836SJohn.Forte@Sun.COM char tmp_target_str[SUN_IMA_IP_ADDRESS_LEN]; 13057836SJohn.Forte@Sun.COM char target_addr_str[SUN_IMA_IP_ADDRESS_LEN]; 13067836SJohn.Forte@Sun.COM char target_port_str[SUN_IMA_IP_PORT_LEN]; 13077836SJohn.Forte@Sun.COM iscsi_target_entry_t target; 13087836SJohn.Forte@Sun.COM int fd; 13097836SJohn.Forte@Sun.COM int target_in_addr_size; 13107836SJohn.Forte@Sun.COM int target_port; 13117836SJohn.Forte@Sun.COM union { 13127836SJohn.Forte@Sun.COM struct in_addr u_in4; 13137836SJohn.Forte@Sun.COM struct in6_addr u_in6; 13147836SJohn.Forte@Sun.COM } target_in; 13157836SJohn.Forte@Sun.COM 13167836SJohn.Forte@Sun.COM /* 13177836SJohn.Forte@Sun.COM * staticConfig.address may come in with port number at its trailer. 13187836SJohn.Forte@Sun.COM * Parse it to separate the IP address and port number. 13197836SJohn.Forte@Sun.COM * Also translate the hostname to IP address if needed. 13207836SJohn.Forte@Sun.COM */ 13217836SJohn.Forte@Sun.COM (void) wcstombs(tmp_target_str, 13227836SJohn.Forte@Sun.COM staticConfig.targetAddress.hostnameIpAddress. 13237836SJohn.Forte@Sun.COM id.hostname, sizeof (tmp_target_str)); 13247836SJohn.Forte@Sun.COM 13257836SJohn.Forte@Sun.COM if (tmp_target_str[0] == '[') { 13267836SJohn.Forte@Sun.COM /* IPv6 address */ 13277836SJohn.Forte@Sun.COM char *closeBracketPos; 13287836SJohn.Forte@Sun.COM closeBracketPos = strchr(tmp_target_str, ']'); 13297836SJohn.Forte@Sun.COM if (!closeBracketPos) { 13307836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 13317836SJohn.Forte@Sun.COM } 13327836SJohn.Forte@Sun.COM 13337836SJohn.Forte@Sun.COM *closeBracketPos = NULL; 13347836SJohn.Forte@Sun.COM (void) strlcpy(target_addr_str, &tmp_target_str[1], 13357836SJohn.Forte@Sun.COM sizeof (target_addr_str)); 13367836SJohn.Forte@Sun.COM 13377836SJohn.Forte@Sun.COM if (inet_pton(AF_INET6, target_addr_str, 13387836SJohn.Forte@Sun.COM &target_in.u_in6) != 1) { 13397836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 13407836SJohn.Forte@Sun.COM } 13417836SJohn.Forte@Sun.COM target_in_addr_size = sizeof (struct in6_addr); 13427836SJohn.Forte@Sun.COM 13437836SJohn.Forte@Sun.COM /* Extract the port number */ 13447836SJohn.Forte@Sun.COM closeBracketPos++; 13457836SJohn.Forte@Sun.COM if (*closeBracketPos == ':') { 13467836SJohn.Forte@Sun.COM closeBracketPos++; 13477836SJohn.Forte@Sun.COM 13487836SJohn.Forte@Sun.COM if (*closeBracketPos != NULL) { 13497836SJohn.Forte@Sun.COM (void) strlcpy(target_port_str, closeBracketPos, 13507836SJohn.Forte@Sun.COM sizeof (target_port_str)); 13517836SJohn.Forte@Sun.COM target_port = atoi(target_port_str); 13527836SJohn.Forte@Sun.COM } else { 13537836SJohn.Forte@Sun.COM target_port = ISCSI_LISTEN_PORT; 13547836SJohn.Forte@Sun.COM } 13557836SJohn.Forte@Sun.COM } else { 13567836SJohn.Forte@Sun.COM /* No port number specified; use default port */ 13577836SJohn.Forte@Sun.COM target_port = ISCSI_LISTEN_PORT; 13587836SJohn.Forte@Sun.COM } 13597836SJohn.Forte@Sun.COM } else { 13607836SJohn.Forte@Sun.COM /* IPv4 address */ 13617836SJohn.Forte@Sun.COM char *colonPos; 13627836SJohn.Forte@Sun.COM colonPos = strchr(tmp_target_str, ':'); 13637836SJohn.Forte@Sun.COM if (!colonPos) { 13647836SJohn.Forte@Sun.COM /* No port number specified; use default port */ 13657836SJohn.Forte@Sun.COM target_port = ISCSI_LISTEN_PORT; 13667836SJohn.Forte@Sun.COM (void) strlcpy(target_addr_str, tmp_target_str, 13677836SJohn.Forte@Sun.COM sizeof (target_addr_str)); 13687836SJohn.Forte@Sun.COM } else { 13697836SJohn.Forte@Sun.COM *colonPos = NULL; 13707836SJohn.Forte@Sun.COM (void) strlcpy(target_addr_str, tmp_target_str, 13717836SJohn.Forte@Sun.COM sizeof (target_addr_str)); 13727836SJohn.Forte@Sun.COM /* Extract the port number */ 13737836SJohn.Forte@Sun.COM colonPos++; 13747836SJohn.Forte@Sun.COM if (*colonPos != NULL) { 13757836SJohn.Forte@Sun.COM (void) strlcpy(target_port_str, colonPos, 13767836SJohn.Forte@Sun.COM sizeof (target_port_str)); 13777836SJohn.Forte@Sun.COM target_port = atoi(target_port_str); 13787836SJohn.Forte@Sun.COM } else { 13797836SJohn.Forte@Sun.COM target_port = ISCSI_LISTEN_PORT; 13807836SJohn.Forte@Sun.COM } 13817836SJohn.Forte@Sun.COM } 13827836SJohn.Forte@Sun.COM 13837836SJohn.Forte@Sun.COM if (inet_pton(AF_INET, target_addr_str, 13847836SJohn.Forte@Sun.COM &target_in.u_in4) != 1) { 13857836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 13867836SJohn.Forte@Sun.COM } 13877836SJohn.Forte@Sun.COM 13887836SJohn.Forte@Sun.COM target_in_addr_size = sizeof (struct in_addr); 13897836SJohn.Forte@Sun.COM } 13907836SJohn.Forte@Sun.COM 13917836SJohn.Forte@Sun.COM 13927836SJohn.Forte@Sun.COM (void) memset(&target, 0, sizeof (iscsi_target_entry_t)); 13937836SJohn.Forte@Sun.COM target.te_entry.e_vers = ISCSI_INTERFACE_VERSION; 13947836SJohn.Forte@Sun.COM target.te_entry.e_oid = ISCSI_OID_NOTSET; 13957836SJohn.Forte@Sun.COM target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT; 13967836SJohn.Forte@Sun.COM 13977836SJohn.Forte@Sun.COM (void) wcstombs((char *)target.te_name, staticConfig.targetName, 13987836SJohn.Forte@Sun.COM ISCSI_MAX_NAME_LEN); 13997836SJohn.Forte@Sun.COM 14007836SJohn.Forte@Sun.COM target.te_entry.e_insize = target_in_addr_size; 14017836SJohn.Forte@Sun.COM if (target.te_entry.e_insize == sizeof (struct in_addr)) { 14027836SJohn.Forte@Sun.COM target.te_entry.e_u.u_in4.s_addr = target_in.u_in4.s_addr; 14037836SJohn.Forte@Sun.COM } else if (target.te_entry.e_insize == sizeof (struct in6_addr)) { 14047836SJohn.Forte@Sun.COM bcopy(target_in.u_in6.s6_addr, 14057836SJohn.Forte@Sun.COM target.te_entry.e_u.u_in6.s6_addr, 14067836SJohn.Forte@Sun.COM sizeof (struct in6_addr)); 14077836SJohn.Forte@Sun.COM } else { 14087836SJohn.Forte@Sun.COM /* Should not happen */ 14097836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 14107836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 14117836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 14127836SJohn.Forte@Sun.COM } 14137836SJohn.Forte@Sun.COM 14147836SJohn.Forte@Sun.COM target.te_entry.e_port = target_port; 14157836SJohn.Forte@Sun.COM 14167836SJohn.Forte@Sun.COM /* No target portal group specified. Default to -1. */ 14177836SJohn.Forte@Sun.COM target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT; 14187836SJohn.Forte@Sun.COM 14197836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 14207836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 14217836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 14227836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 14237836SJohn.Forte@Sun.COM } 14247836SJohn.Forte@Sun.COM 14257836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_STATIC_SET, &target)) { 14267836SJohn.Forte@Sun.COM /* 14277836SJohn.Forte@Sun.COM * Encountered problem setting the IP address and port for 14287836SJohn.Forte@Sun.COM * the target just added. 14297836SJohn.Forte@Sun.COM */ 14307836SJohn.Forte@Sun.COM (void) close(fd); 14317836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 14327836SJohn.Forte@Sun.COM "ISCSI_STATIC_SET ioctl failed, errno: %d", errno); 14337836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 14347836SJohn.Forte@Sun.COM } 14357836SJohn.Forte@Sun.COM 14367836SJohn.Forte@Sun.COM pTargetOid->objectType = IMA_OBJECT_TYPE_TARGET; 14377836SJohn.Forte@Sun.COM pTargetOid->ownerId = pluginOwnerId; 14387836SJohn.Forte@Sun.COM pTargetOid->objectSequenceNumber = target.te_entry.e_oid; 14397836SJohn.Forte@Sun.COM 14407836SJohn.Forte@Sun.COM (void) close(fd); 14417836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 14427836SJohn.Forte@Sun.COM } 14437836SJohn.Forte@Sun.COM 14447836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetTargetProperties( 14457836SJohn.Forte@Sun.COM IMA_OID targetId, 14467836SJohn.Forte@Sun.COM IMA_TARGET_PROPERTIES *pProps 14477836SJohn.Forte@Sun.COM ) 14487836SJohn.Forte@Sun.COM { 14497836SJohn.Forte@Sun.COM return (getTargetProperties(targetId, pProps)); 14507836SJohn.Forte@Sun.COM } 14517836SJohn.Forte@Sun.COM 14527836SJohn.Forte@Sun.COM static IMA_STATUS getTargetProperties( 14537836SJohn.Forte@Sun.COM IMA_OID targetId, 14547836SJohn.Forte@Sun.COM IMA_TARGET_PROPERTIES *pProps 14557836SJohn.Forte@Sun.COM ) 14567836SJohn.Forte@Sun.COM { 14577836SJohn.Forte@Sun.COM int fd; 14587836SJohn.Forte@Sun.COM iscsi_property_t prop; 14597836SJohn.Forte@Sun.COM 14607836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 14617836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 14627836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 14637836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 14647836SJohn.Forte@Sun.COM } 14657836SJohn.Forte@Sun.COM 14667836SJohn.Forte@Sun.COM (void) memset(&prop, 0, sizeof (iscsi_property_t)); 14677836SJohn.Forte@Sun.COM prop.p_vers = ISCSI_INTERFACE_VERSION; 14687836SJohn.Forte@Sun.COM prop.p_oid = (uint32_t)targetId.objectSequenceNumber; 14697836SJohn.Forte@Sun.COM 14707836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_TARGET_PROPS_GET, &prop) != 0) { 14717836SJohn.Forte@Sun.COM (void) close(fd); 14727836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 14737836SJohn.Forte@Sun.COM "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno); 14747836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 14757836SJohn.Forte@Sun.COM } 14767836SJohn.Forte@Sun.COM 14777836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->name, (char *)prop.p_name, IMA_NODE_NAME_LEN); 14787836SJohn.Forte@Sun.COM (void) memset(pProps->alias, 0, 14797836SJohn.Forte@Sun.COM sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN); 14807836SJohn.Forte@Sun.COM if (prop.p_alias_len > 0) { 14817836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->alias, (char *)prop.p_alias, 14827836SJohn.Forte@Sun.COM IMA_NODE_ALIAS_LEN); 14837836SJohn.Forte@Sun.COM } 14847836SJohn.Forte@Sun.COM 14857836SJohn.Forte@Sun.COM /* Initialize the discovery method to unknown method. */ 14867836SJohn.Forte@Sun.COM pProps->discoveryMethodFlags = IMA_TARGET_DISCOVERY_METHOD_UNKNOWN; 14877836SJohn.Forte@Sun.COM if (!((prop.p_discovery & iSCSIDiscoveryMethodStatic) ^ 14887836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodStatic)) { 14897836SJohn.Forte@Sun.COM pProps->discoveryMethodFlags |= 14907836SJohn.Forte@Sun.COM IMA_TARGET_DISCOVERY_METHOD_STATIC; 14917836SJohn.Forte@Sun.COM } 14927836SJohn.Forte@Sun.COM 14937836SJohn.Forte@Sun.COM if (!((prop.p_discovery & iSCSIDiscoveryMethodSLP) ^ 14947836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodSLP)) { 14957836SJohn.Forte@Sun.COM pProps->discoveryMethodFlags |= IMA_TARGET_DISCOVERY_METHOD_SLP; 14967836SJohn.Forte@Sun.COM } 14977836SJohn.Forte@Sun.COM 14987836SJohn.Forte@Sun.COM if (!((prop.p_discovery & iSCSIDiscoveryMethodISNS) ^ 14997836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodISNS)) { 15007836SJohn.Forte@Sun.COM pProps->discoveryMethodFlags |= iSCSIDiscoveryMethodISNS; 15017836SJohn.Forte@Sun.COM } 15027836SJohn.Forte@Sun.COM 15037836SJohn.Forte@Sun.COM if (!((prop.p_discovery & iSCSIDiscoveryMethodSendTargets) ^ 15047836SJohn.Forte@Sun.COM iSCSIDiscoveryMethodSendTargets)) { 15057836SJohn.Forte@Sun.COM pProps->discoveryMethodFlags |= iSCSIDiscoveryMethodSendTargets; 15067836SJohn.Forte@Sun.COM } 15077836SJohn.Forte@Sun.COM 15087836SJohn.Forte@Sun.COM (void) close(fd); 15097836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 15107836SJohn.Forte@Sun.COM } 15117836SJohn.Forte@Sun.COM 15127836SJohn.Forte@Sun.COM /*ARGSUSED*/ 15137836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetTargetErrorStatistics( 15147836SJohn.Forte@Sun.COM IMA_OID targetId, 15157836SJohn.Forte@Sun.COM IMA_TARGET_ERROR_STATISTICS *pStats 15167836SJohn.Forte@Sun.COM ) 15177836SJohn.Forte@Sun.COM { 15187836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 15197836SJohn.Forte@Sun.COM } 15207836SJohn.Forte@Sun.COM 15217836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLuOidList( 15227836SJohn.Forte@Sun.COM IMA_OID oid, 15237836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 15247836SJohn.Forte@Sun.COM ) 15257836SJohn.Forte@Sun.COM { 15267836SJohn.Forte@Sun.COM IMA_STATUS status; 15277836SJohn.Forte@Sun.COM int i; 15287836SJohn.Forte@Sun.COM iscsi_lun_list_t *pLunList; 15297836SJohn.Forte@Sun.COM 15307836SJohn.Forte@Sun.COM if (oid.objectType == IMA_OBJECT_TYPE_LHBA) { 15317836SJohn.Forte@Sun.COM status = get_target_lun_oid_list(NULL, &pLunList); 15327836SJohn.Forte@Sun.COM } else { 15337836SJohn.Forte@Sun.COM status = get_target_lun_oid_list(&oid, &pLunList); 15347836SJohn.Forte@Sun.COM } 15357836SJohn.Forte@Sun.COM 15367836SJohn.Forte@Sun.COM if (!IMA_SUCCESS(status)) { 15377836SJohn.Forte@Sun.COM return (status); 15387836SJohn.Forte@Sun.COM } 15397836SJohn.Forte@Sun.COM 15407836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST) + 15417836SJohn.Forte@Sun.COM (pLunList->ll_out_cnt * sizeof (IMA_OID)))); 15427836SJohn.Forte@Sun.COM if (*ppList == NULL) { 15437836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 15447836SJohn.Forte@Sun.COM } 15457836SJohn.Forte@Sun.COM (*ppList)->oidCount = pLunList->ll_out_cnt; 15467836SJohn.Forte@Sun.COM for (i = 0; i < pLunList->ll_out_cnt; i++) { 15477836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_LU; 15487836SJohn.Forte@Sun.COM (*ppList)->oids[i].ownerId = pluginOwnerId; 15497836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectSequenceNumber = 15507836SJohn.Forte@Sun.COM pLunList->ll_luns[i].l_oid; 15517836SJohn.Forte@Sun.COM } 15527836SJohn.Forte@Sun.COM 15537836SJohn.Forte@Sun.COM free(pLunList); 15547836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 15557836SJohn.Forte@Sun.COM } 15567836SJohn.Forte@Sun.COM 15577836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLuOid( 15587836SJohn.Forte@Sun.COM IMA_OID targetId, 15597836SJohn.Forte@Sun.COM IMA_UINT64 lun, 15607836SJohn.Forte@Sun.COM IMA_OID *pluId 15617836SJohn.Forte@Sun.COM ) 15627836SJohn.Forte@Sun.COM { 15637836SJohn.Forte@Sun.COM IMA_STATUS status; 15647836SJohn.Forte@Sun.COM int i; 15657836SJohn.Forte@Sun.COM iscsi_lun_list_t *pLunList; 15667836SJohn.Forte@Sun.COM 15677836SJohn.Forte@Sun.COM status = get_target_lun_oid_list(&targetId, &pLunList); 15687836SJohn.Forte@Sun.COM if (!IMA_SUCCESS(status)) { 15697836SJohn.Forte@Sun.COM return (status); 15707836SJohn.Forte@Sun.COM } 15717836SJohn.Forte@Sun.COM 15727836SJohn.Forte@Sun.COM for (i = 0; i < pLunList->ll_out_cnt; i++) { 15737836SJohn.Forte@Sun.COM if (pLunList->ll_luns[i].l_num == lun) { 15747836SJohn.Forte@Sun.COM pluId->objectType = IMA_OBJECT_TYPE_LU; 15757836SJohn.Forte@Sun.COM pluId->ownerId = pluginOwnerId; 15767836SJohn.Forte@Sun.COM pluId->objectSequenceNumber = 15777836SJohn.Forte@Sun.COM pLunList->ll_luns[i].l_oid; 15787836SJohn.Forte@Sun.COM free(pLunList); 15797836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 15807836SJohn.Forte@Sun.COM } 15817836SJohn.Forte@Sun.COM } 15827836SJohn.Forte@Sun.COM 15837836SJohn.Forte@Sun.COM free(pLunList); 15847836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 15857836SJohn.Forte@Sun.COM } 15867836SJohn.Forte@Sun.COM 15877836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLuProperties( 15887836SJohn.Forte@Sun.COM IMA_OID luId, 15897836SJohn.Forte@Sun.COM IMA_LU_PROPERTIES *pProps 15907836SJohn.Forte@Sun.COM ) 15917836SJohn.Forte@Sun.COM { 15927836SJohn.Forte@Sun.COM return (getLuProperties(luId, pProps)); 15937836SJohn.Forte@Sun.COM } 15947836SJohn.Forte@Sun.COM 15957836SJohn.Forte@Sun.COM static IMA_STATUS getLuProperties( 15967836SJohn.Forte@Sun.COM IMA_OID luId, 15977836SJohn.Forte@Sun.COM IMA_LU_PROPERTIES *pProps 15987836SJohn.Forte@Sun.COM ) 15997836SJohn.Forte@Sun.COM { 16007836SJohn.Forte@Sun.COM IMA_STATUS status; 16017836SJohn.Forte@Sun.COM iscsi_lun_list_t *pLunList; 16027836SJohn.Forte@Sun.COM int j; 16037836SJohn.Forte@Sun.COM IMA_BOOL lunMatch = IMA_FALSE; 16047836SJohn.Forte@Sun.COM int fd; 16057836SJohn.Forte@Sun.COM iscsi_lun_props_t lun; 16067836SJohn.Forte@Sun.COM di_devlink_handle_t hdl; 16077836SJohn.Forte@Sun.COM 16087836SJohn.Forte@Sun.COM if (luId.objectType != IMA_OBJECT_TYPE_LU) { 16097836SJohn.Forte@Sun.COM return (IMA_ERROR_INCORRECT_OBJECT_TYPE); 16107836SJohn.Forte@Sun.COM } 16117836SJohn.Forte@Sun.COM 16127836SJohn.Forte@Sun.COM /* 16137836SJohn.Forte@Sun.COM * get list of lun oids for all targets 16147836SJohn.Forte@Sun.COM */ 16157836SJohn.Forte@Sun.COM status = get_target_lun_oid_list(NULL, &pLunList); 16167836SJohn.Forte@Sun.COM if (!IMA_SUCCESS(status)) { 16177836SJohn.Forte@Sun.COM return (status); 16187836SJohn.Forte@Sun.COM } 16197836SJohn.Forte@Sun.COM for (j = 0; j < pLunList->ll_out_cnt; j++) { 16207836SJohn.Forte@Sun.COM /* 16217836SJohn.Forte@Sun.COM * for each lun, check if match is found 16227836SJohn.Forte@Sun.COM */ 16237836SJohn.Forte@Sun.COM if (pLunList->ll_luns[j].l_oid == luId.objectSequenceNumber) { 16247836SJohn.Forte@Sun.COM /* 16257836SJohn.Forte@Sun.COM * match found, break out of lun loop 16267836SJohn.Forte@Sun.COM */ 16277836SJohn.Forte@Sun.COM lunMatch = IMA_TRUE; 16287836SJohn.Forte@Sun.COM break; 16297836SJohn.Forte@Sun.COM } 16307836SJohn.Forte@Sun.COM } 16317836SJohn.Forte@Sun.COM 16327836SJohn.Forte@Sun.COM if (lunMatch == IMA_TRUE) { 16337836SJohn.Forte@Sun.COM (void) memset(&lun, 0, sizeof (iscsi_lun_props_t)); 16347836SJohn.Forte@Sun.COM lun.lp_vers = ISCSI_INTERFACE_VERSION; 16357836SJohn.Forte@Sun.COM lun.lp_tgt_oid = pLunList->ll_luns[j].l_tgt_oid; 16367836SJohn.Forte@Sun.COM lun.lp_oid = pLunList->ll_luns[j].l_oid; 16377836SJohn.Forte@Sun.COM } 16387836SJohn.Forte@Sun.COM 16397836SJohn.Forte@Sun.COM free(pLunList); 16407836SJohn.Forte@Sun.COM 16417836SJohn.Forte@Sun.COM if (lunMatch == IMA_FALSE) { 16427836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 16437836SJohn.Forte@Sun.COM } 16447836SJohn.Forte@Sun.COM 16457836SJohn.Forte@Sun.COM /* 16467836SJohn.Forte@Sun.COM * get lun properties 16477836SJohn.Forte@Sun.COM */ 16487836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 16497836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 16507836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 16517836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 16527836SJohn.Forte@Sun.COM } 16537836SJohn.Forte@Sun.COM 16547836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_LUN_PROPS_GET, &lun)) { 16557836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 16567836SJohn.Forte@Sun.COM "ISCSI_LUN_PROPS_GET ioctl failed, errno: %d", errno); 16577836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 16587836SJohn.Forte@Sun.COM } 16597836SJohn.Forte@Sun.COM (void) close(fd); 16607836SJohn.Forte@Sun.COM 16617836SJohn.Forte@Sun.COM /* 16627836SJohn.Forte@Sun.COM * set property values 16637836SJohn.Forte@Sun.COM */ 16647836SJohn.Forte@Sun.COM pProps->associatedTargetOid.objectType = IMA_OBJECT_TYPE_TARGET; 16657836SJohn.Forte@Sun.COM pProps->associatedTargetOid.ownerId = pluginOwnerId; 16667836SJohn.Forte@Sun.COM pProps->associatedTargetOid.objectSequenceNumber = lun.lp_tgt_oid; 16677836SJohn.Forte@Sun.COM pProps->targetLun = (IMA_UINT64)lun.lp_num; 16687836SJohn.Forte@Sun.COM pProps->exposedToOs = IMA_TRUE; 16697836SJohn.Forte@Sun.COM (void) memset(&pProps->timeExposedToOs, 0, 16707836SJohn.Forte@Sun.COM sizeof (pProps->timeExposedToOs)); 16717836SJohn.Forte@Sun.COM 16727836SJohn.Forte@Sun.COM if (lun.lp_status == LunValid) { 16737836SJohn.Forte@Sun.COM 16747836SJohn.Forte@Sun.COM /* add minor device delimiter */ 16757836SJohn.Forte@Sun.COM (void) strcat(lun.lp_pathname, ":"); 16767836SJohn.Forte@Sun.COM 16777836SJohn.Forte@Sun.COM if ((strstr(lun.lp_pathname, "sd@") != NULL) || 16787836SJohn.Forte@Sun.COM (strstr(lun.lp_pathname, "ssd@") != NULL) || 16797836SJohn.Forte@Sun.COM (strstr(lun.lp_pathname, "disk@") != NULL)) { 16807836SJohn.Forte@Sun.COM /* 16817836SJohn.Forte@Sun.COM * modify returned pathname to obtain the 2nd slice 16827836SJohn.Forte@Sun.COM * of the raw disk 16837836SJohn.Forte@Sun.COM */ 16847836SJohn.Forte@Sun.COM (void) strcat(lun.lp_pathname, "c,raw"); 16857836SJohn.Forte@Sun.COM } 16867836SJohn.Forte@Sun.COM 16877836SJohn.Forte@Sun.COM /* 16887836SJohn.Forte@Sun.COM * Pathname returned by driver is the physical device path. 16897836SJohn.Forte@Sun.COM * This name needs to be converted to the OS device name. 16907836SJohn.Forte@Sun.COM */ 16917836SJohn.Forte@Sun.COM if (hdl = di_devlink_init(lun.lp_pathname, DI_MAKE_LINK)) { 16927836SJohn.Forte@Sun.COM pProps->osDeviceName[0] = L'\0'; 16937836SJohn.Forte@Sun.COM (void) di_devlink_walk(hdl, NULL, lun.lp_pathname, 16947836SJohn.Forte@Sun.COM DI_PRIMARY_LINK, (void *)pProps->osDeviceName, 16957836SJohn.Forte@Sun.COM get_lun_devlink); 16967836SJohn.Forte@Sun.COM if (pProps->osDeviceName[0] != L'\0') { 16977836SJohn.Forte@Sun.COM /* OS device name synchronously made */ 16987836SJohn.Forte@Sun.COM pProps->osDeviceNameValid = IMA_TRUE; 16997836SJohn.Forte@Sun.COM } else { 17007836SJohn.Forte@Sun.COM pProps->osDeviceNameValid = IMA_FALSE; 17017836SJohn.Forte@Sun.COM } 17027836SJohn.Forte@Sun.COM 17037836SJohn.Forte@Sun.COM (void) di_devlink_fini(&hdl); 17047836SJohn.Forte@Sun.COM } else { 17057836SJohn.Forte@Sun.COM pProps->osDeviceNameValid = IMA_FALSE; 17067836SJohn.Forte@Sun.COM } 17077836SJohn.Forte@Sun.COM 17087836SJohn.Forte@Sun.COM } else { 17097836SJohn.Forte@Sun.COM pProps->osDeviceNameValid = IMA_FALSE; 17107836SJohn.Forte@Sun.COM } 17117836SJohn.Forte@Sun.COM 17127836SJohn.Forte@Sun.COM pProps->osParallelIdsValid = IMA_FALSE; 17137836SJohn.Forte@Sun.COM 17147836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 17157836SJohn.Forte@Sun.COM } 17167836SJohn.Forte@Sun.COM 17177836SJohn.Forte@Sun.COM /*ARGSUSED*/ 17187836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetStatisticsProperties( 17197836SJohn.Forte@Sun.COM IMA_OID oid, 17207836SJohn.Forte@Sun.COM IMA_STATISTICS_PROPERTIES *pProps 17217836SJohn.Forte@Sun.COM ) 17227836SJohn.Forte@Sun.COM { 17237836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 17247836SJohn.Forte@Sun.COM } 17257836SJohn.Forte@Sun.COM 17267836SJohn.Forte@Sun.COM /*ARGSUSED*/ 17277836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetDeviceStatistics( 17287836SJohn.Forte@Sun.COM IMA_OID luId, 17297836SJohn.Forte@Sun.COM IMA_DEVICE_STATISTICS *pStats 17307836SJohn.Forte@Sun.COM ) 17317836SJohn.Forte@Sun.COM { 17327836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 17337836SJohn.Forte@Sun.COM } 17347836SJohn.Forte@Sun.COM 17357836SJohn.Forte@Sun.COM /*ARGSUSED*/ 17367836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_LuInquiry( 17377836SJohn.Forte@Sun.COM IMA_OID deviceId, 17387836SJohn.Forte@Sun.COM IMA_BOOL evpd, 17397836SJohn.Forte@Sun.COM IMA_BOOL cmddt, 17407836SJohn.Forte@Sun.COM IMA_BYTE pageCode, 17417836SJohn.Forte@Sun.COM IMA_BYTE *pOutputBuffer, 17427836SJohn.Forte@Sun.COM IMA_UINT *pOutputBufferLength, 17437836SJohn.Forte@Sun.COM IMA_BYTE *pSenseBuffer, 17447836SJohn.Forte@Sun.COM IMA_UINT *pSenseBufferLength 17457836SJohn.Forte@Sun.COM ) 17467836SJohn.Forte@Sun.COM { 17477836SJohn.Forte@Sun.COM IMA_LU_PROPERTIES luProps; 17487836SJohn.Forte@Sun.COM IMA_STATUS status; 17497836SJohn.Forte@Sun.COM 17507836SJohn.Forte@Sun.COM char cmdblk [ INQUIRY_CMDLEN ] = 17517836SJohn.Forte@Sun.COM { INQUIRY_CMD, /* command */ 17527836SJohn.Forte@Sun.COM 0, /* lun/reserved */ 17537836SJohn.Forte@Sun.COM 0, /* page code */ 17547836SJohn.Forte@Sun.COM 0, /* reserved */ 17557836SJohn.Forte@Sun.COM INQUIRY_REPLY_LEN, /* allocation length */ 17567836SJohn.Forte@Sun.COM 0 }; /* reserved/flag/link */ 17577836SJohn.Forte@Sun.COM 17587836SJohn.Forte@Sun.COM 17597836SJohn.Forte@Sun.COM int fd; 17607836SJohn.Forte@Sun.COM iscsi_uscsi_t uscsi; 17617836SJohn.Forte@Sun.COM 17627836SJohn.Forte@Sun.COM cmdblk[2] = pageCode; 17637836SJohn.Forte@Sun.COM 17647836SJohn.Forte@Sun.COM (void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t)); 17657836SJohn.Forte@Sun.COM uscsi.iu_vers = ISCSI_INTERFACE_VERSION; 17667836SJohn.Forte@Sun.COM 17677836SJohn.Forte@Sun.COM /* iu_oid is a session oid in the driver */ 17687836SJohn.Forte@Sun.COM if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) { 17697836SJohn.Forte@Sun.COM uscsi.iu_oid = deviceId.objectSequenceNumber; 17707836SJohn.Forte@Sun.COM uscsi.iu_lun = 0; 17717836SJohn.Forte@Sun.COM } else { 17727836SJohn.Forte@Sun.COM /* 17737836SJohn.Forte@Sun.COM * Get LU properties and associated session oid 17747836SJohn.Forte@Sun.COM * for this lun(deviceId) and put in uscsi.iu_oid 17757836SJohn.Forte@Sun.COM */ 17767836SJohn.Forte@Sun.COM status = getLuProperties(deviceId, &luProps); 17777836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) { 17787836SJohn.Forte@Sun.COM return (status); 17797836SJohn.Forte@Sun.COM } 17807836SJohn.Forte@Sun.COM uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid. 17817836SJohn.Forte@Sun.COM objectSequenceNumber; 17827836SJohn.Forte@Sun.COM uscsi.iu_lun = luProps.targetLun; 17837836SJohn.Forte@Sun.COM } 17847836SJohn.Forte@Sun.COM 17857836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_flags = USCSI_READ; 17867836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC; 17877836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer; 17887836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_buflen = *pOutputBufferLength; 17897836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer; 17907836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqlen = *pSenseBufferLength; 17917836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdb = &cmdblk[0]; 17927836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdblen = INQUIRY_CMDLEN; 17937836SJohn.Forte@Sun.COM 17947836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 17957836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 17967836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 17977836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 17987836SJohn.Forte@Sun.COM } 17997836SJohn.Forte@Sun.COM 18007836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) { 18017836SJohn.Forte@Sun.COM (void) close(fd); 18027836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 18037836SJohn.Forte@Sun.COM "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno); 18047836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 18057836SJohn.Forte@Sun.COM } 18067836SJohn.Forte@Sun.COM 18077836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 18087836SJohn.Forte@Sun.COM } 18097836SJohn.Forte@Sun.COM 18107836SJohn.Forte@Sun.COM /*ARGSUSED*/ 18117836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_LuReadCapacity( 18127836SJohn.Forte@Sun.COM IMA_OID deviceId, 18137836SJohn.Forte@Sun.COM IMA_UINT cdbLength, 18147836SJohn.Forte@Sun.COM IMA_BYTE *pOutputBuffer, 18157836SJohn.Forte@Sun.COM IMA_UINT *pOutputBufferLength, 18167836SJohn.Forte@Sun.COM 18177836SJohn.Forte@Sun.COM IMA_BYTE *pSenseBuffer, 18187836SJohn.Forte@Sun.COM IMA_UINT *pSenseBufferLength 18197836SJohn.Forte@Sun.COM ) 18207836SJohn.Forte@Sun.COM { 18217836SJohn.Forte@Sun.COM IMA_LU_PROPERTIES luProps; 18227836SJohn.Forte@Sun.COM IMA_STATUS status; 18237836SJohn.Forte@Sun.COM int fd; 18247836SJohn.Forte@Sun.COM iscsi_uscsi_t uscsi; 18257836SJohn.Forte@Sun.COM 18267836SJohn.Forte@Sun.COM char cmdblk [ INQUIRY_CMDLEN ] = 18277836SJohn.Forte@Sun.COM { GETCAPACITY_CMD, /* command */ 18287836SJohn.Forte@Sun.COM 0, /* lun/reserved */ 18297836SJohn.Forte@Sun.COM 0, /* page code */ 18307836SJohn.Forte@Sun.COM 0, /* reserved */ 18317836SJohn.Forte@Sun.COM INQUIRY_REPLY_LEN, /* allocation length */ 18327836SJohn.Forte@Sun.COM 0 }; /* reserved/flag/link */ 18337836SJohn.Forte@Sun.COM 18347836SJohn.Forte@Sun.COM 18357836SJohn.Forte@Sun.COM 18367836SJohn.Forte@Sun.COM (void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t)); 18377836SJohn.Forte@Sun.COM uscsi.iu_vers = ISCSI_INTERFACE_VERSION; 18387836SJohn.Forte@Sun.COM 18397836SJohn.Forte@Sun.COM /* iu_oid is a session oid in the driver */ 18407836SJohn.Forte@Sun.COM if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) { 18417836SJohn.Forte@Sun.COM uscsi.iu_oid = deviceId.objectSequenceNumber; 18427836SJohn.Forte@Sun.COM uscsi.iu_lun = 0; 18437836SJohn.Forte@Sun.COM } else { 18447836SJohn.Forte@Sun.COM /* 18457836SJohn.Forte@Sun.COM * Get LU properties and associated session oid 18467836SJohn.Forte@Sun.COM * for this lun(deviceId) and put in uscsi.iu_oid 18477836SJohn.Forte@Sun.COM */ 18487836SJohn.Forte@Sun.COM status = getLuProperties(deviceId, &luProps); 18497836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) { 18507836SJohn.Forte@Sun.COM return (status); 18517836SJohn.Forte@Sun.COM } 18527836SJohn.Forte@Sun.COM uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid. 18537836SJohn.Forte@Sun.COM objectSequenceNumber; 18547836SJohn.Forte@Sun.COM uscsi.iu_lun = luProps.targetLun; 18557836SJohn.Forte@Sun.COM } 18567836SJohn.Forte@Sun.COM 18577836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_flags = USCSI_READ; 18587836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_timeout = 10; 18597836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer; 18607836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_buflen = *pOutputBufferLength; 18617836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer; 18627836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqlen = *pSenseBufferLength; 18637836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdb = &cmdblk[0]; 18647836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdblen = INQUIRY_CMDLEN; 18657836SJohn.Forte@Sun.COM 18667836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 18677836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 18687836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 18697836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 18707836SJohn.Forte@Sun.COM } 18717836SJohn.Forte@Sun.COM 18727836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) { 18737836SJohn.Forte@Sun.COM (void) close(fd); 18747836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 18757836SJohn.Forte@Sun.COM "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno); 18767836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 18777836SJohn.Forte@Sun.COM } 18787836SJohn.Forte@Sun.COM 18797836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 18807836SJohn.Forte@Sun.COM } 18817836SJohn.Forte@Sun.COM 18827836SJohn.Forte@Sun.COM /*ARGSUSED*/ 18837836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_LuReportLuns( 18847836SJohn.Forte@Sun.COM IMA_OID deviceId, 18857836SJohn.Forte@Sun.COM IMA_BOOL sendToWellKnownLun, 18867836SJohn.Forte@Sun.COM IMA_BYTE selectReport, 18877836SJohn.Forte@Sun.COM 18887836SJohn.Forte@Sun.COM IMA_BYTE *pOutputBuffer, 18897836SJohn.Forte@Sun.COM IMA_UINT *pOutputBufferLength, 18907836SJohn.Forte@Sun.COM 18917836SJohn.Forte@Sun.COM IMA_BYTE *pSenseBuffer, 18927836SJohn.Forte@Sun.COM IMA_UINT *pSenseBufferLength 18937836SJohn.Forte@Sun.COM ) 18947836SJohn.Forte@Sun.COM { 18957836SJohn.Forte@Sun.COM IMA_LU_PROPERTIES luProps; 18967836SJohn.Forte@Sun.COM IMA_STATUS status; 18977836SJohn.Forte@Sun.COM int fd; 18987836SJohn.Forte@Sun.COM iscsi_uscsi_t uscsi; 18997836SJohn.Forte@Sun.COM 19007836SJohn.Forte@Sun.COM char cmdblk [ INQUIRY_CMDLEN ] = 19017836SJohn.Forte@Sun.COM { INQUIRY_CMD, /* command */ 19027836SJohn.Forte@Sun.COM 0, /* lun/reserved */ 19037836SJohn.Forte@Sun.COM 0, /* page code */ 19047836SJohn.Forte@Sun.COM 0, /* reserved */ 19057836SJohn.Forte@Sun.COM INQUIRY_REPLY_LEN, /* allocation length */ 19067836SJohn.Forte@Sun.COM 0 }; /* reserved/flag/link */ 19077836SJohn.Forte@Sun.COM 19087836SJohn.Forte@Sun.COM (void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t)); 19097836SJohn.Forte@Sun.COM uscsi.iu_vers = ISCSI_INTERFACE_VERSION; 19107836SJohn.Forte@Sun.COM 19117836SJohn.Forte@Sun.COM /* iu_oid is a session oid in the driver */ 19127836SJohn.Forte@Sun.COM if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) { 19137836SJohn.Forte@Sun.COM uscsi.iu_oid = deviceId.objectSequenceNumber; 19147836SJohn.Forte@Sun.COM uscsi.iu_lun = 0; 19157836SJohn.Forte@Sun.COM } else { 19167836SJohn.Forte@Sun.COM /* 19177836SJohn.Forte@Sun.COM * Get LU properties and associated session oid 19187836SJohn.Forte@Sun.COM * for this lun(deviceId) and put in uscsi.iu_oid 19197836SJohn.Forte@Sun.COM */ 19207836SJohn.Forte@Sun.COM status = getLuProperties(deviceId, &luProps); 19217836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) { 19227836SJohn.Forte@Sun.COM return (status); 19237836SJohn.Forte@Sun.COM } 19247836SJohn.Forte@Sun.COM uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid. 19257836SJohn.Forte@Sun.COM objectSequenceNumber; 19267836SJohn.Forte@Sun.COM uscsi.iu_lun = luProps.targetLun; 19277836SJohn.Forte@Sun.COM } 19287836SJohn.Forte@Sun.COM 19297836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_flags = USCSI_READ; 19307836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_timeout = 10; 19317836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer; 19327836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_buflen = *pOutputBufferLength; 19337836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer; 19347836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_rqlen = *pSenseBufferLength; 19357836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdb = &cmdblk[0]; 19367836SJohn.Forte@Sun.COM uscsi.iu_ucmd.uscsi_cdblen = INQUIRY_CMDLEN; 19377836SJohn.Forte@Sun.COM 19387836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 19397836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 19407836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 19417836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 19427836SJohn.Forte@Sun.COM } 19437836SJohn.Forte@Sun.COM 19447836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) { 19457836SJohn.Forte@Sun.COM (void) close(fd); 19467836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 19477836SJohn.Forte@Sun.COM "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno); 19487836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 19497836SJohn.Forte@Sun.COM } 19507836SJohn.Forte@Sun.COM 19517836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 19527836SJohn.Forte@Sun.COM } 19537836SJohn.Forte@Sun.COM 19547836SJohn.Forte@Sun.COM /*ARGSUSED*/ 19557836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_ExposeLu( 19567836SJohn.Forte@Sun.COM IMA_OID luId 19577836SJohn.Forte@Sun.COM ) 19587836SJohn.Forte@Sun.COM { 19597836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 19607836SJohn.Forte@Sun.COM } 19617836SJohn.Forte@Sun.COM 19627836SJohn.Forte@Sun.COM /*ARGSUSED*/ 19637836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_UnexposeLu( 19647836SJohn.Forte@Sun.COM IMA_OID luId 19657836SJohn.Forte@Sun.COM ) 19667836SJohn.Forte@Sun.COM { 19677836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 19687836SJohn.Forte@Sun.COM } 19697836SJohn.Forte@Sun.COM 19707836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetAddressKeys( 19717836SJohn.Forte@Sun.COM IMA_OID targetOid, 19727836SJohn.Forte@Sun.COM IMA_ADDRESS_KEYS **ppKeys 19737836SJohn.Forte@Sun.COM ) 19747836SJohn.Forte@Sun.COM { 19757836SJohn.Forte@Sun.COM IMA_STATUS status; 19767836SJohn.Forte@Sun.COM IMA_TARGET_PROPERTIES targetProps; 19777836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDR_PROP_LIST *discAddressList; 19787836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList; 19797836SJohn.Forte@Sun.COM int i, j, addressKeyCount = 0; 19807836SJohn.Forte@Sun.COM int addressKeyIdx = 0; 19817836SJohn.Forte@Sun.COM 19827836SJohn.Forte@Sun.COM status = getTargetProperties(targetOid, &targetProps); 19837836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) { 19847836SJohn.Forte@Sun.COM return (status); 19857836SJohn.Forte@Sun.COM } 19867836SJohn.Forte@Sun.COM 19877836SJohn.Forte@Sun.COM status = getDiscoveryAddressPropertiesList(&discAddressList); 19887836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) { 19897836SJohn.Forte@Sun.COM return (status); 19907836SJohn.Forte@Sun.COM } 19917836SJohn.Forte@Sun.COM 19927836SJohn.Forte@Sun.COM /* Get the number of addresses to allocate */ 19937836SJohn.Forte@Sun.COM for (i = 0; i < discAddressList->discAddrCount; i++) { 19947836SJohn.Forte@Sun.COM (void) sendTargets(discAddressList->props[i].discoveryAddress, 19957836SJohn.Forte@Sun.COM &pList); 19967836SJohn.Forte@Sun.COM for (j = 0; j < pList->keyCount; j++) { 19977836SJohn.Forte@Sun.COM if (wcsncmp(pList->keys[j].name, targetProps.name, 19987836SJohn.Forte@Sun.COM wslen(pList->keys[j].name)) == 0) { 19997836SJohn.Forte@Sun.COM addressKeyCount++; 20007836SJohn.Forte@Sun.COM } 20017836SJohn.Forte@Sun.COM } 20027836SJohn.Forte@Sun.COM (void) IMA_FreeMemory(pList); 20037836SJohn.Forte@Sun.COM } 20047836SJohn.Forte@Sun.COM 20057836SJohn.Forte@Sun.COM *ppKeys = (IMA_ADDRESS_KEYS *)calloc(1, sizeof (IMA_ADDRESS_KEYS) + 20067836SJohn.Forte@Sun.COM addressKeyCount * sizeof (IMA_ADDRESS_KEY)); 20077836SJohn.Forte@Sun.COM if (*ppKeys == NULL) { 20087836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 20097836SJohn.Forte@Sun.COM } 20107836SJohn.Forte@Sun.COM (*ppKeys)->addressKeyCount = addressKeyCount; 20117836SJohn.Forte@Sun.COM addressKeyIdx = 0; 20127836SJohn.Forte@Sun.COM 20137836SJohn.Forte@Sun.COM for (i = 0; i < discAddressList->discAddrCount; i++) { 20147836SJohn.Forte@Sun.COM (void) sendTargets(discAddressList->props[i].discoveryAddress, 20157836SJohn.Forte@Sun.COM &pList); 20167836SJohn.Forte@Sun.COM for (j = 0; j < pList->keyCount; j++) { 20177836SJohn.Forte@Sun.COM if (wcsncmp(pList->keys[j].name, targetProps.name, 20187836SJohn.Forte@Sun.COM wslen(pList->keys[j].name)) != 0) { 20197836SJohn.Forte@Sun.COM continue; 20207836SJohn.Forte@Sun.COM } 20217836SJohn.Forte@Sun.COM 20227836SJohn.Forte@Sun.COM bcopy(&(pList->keys[j].address.ipAddress), 20237836SJohn.Forte@Sun.COM &((*ppKeys)->addressKeys[addressKeyIdx]. 20247836SJohn.Forte@Sun.COM ipAddress), sizeof (IMA_IP_ADDRESS)); 20257836SJohn.Forte@Sun.COM 20267836SJohn.Forte@Sun.COM (*ppKeys)->addressKeys[addressKeyIdx++].portNumber = 20277836SJohn.Forte@Sun.COM pList->keys[j].address.portNumber; 20287836SJohn.Forte@Sun.COM 20297836SJohn.Forte@Sun.COM } 20307836SJohn.Forte@Sun.COM (void) IMA_FreeMemory(pList); 20317836SJohn.Forte@Sun.COM } 20327836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 20337836SJohn.Forte@Sun.COM } 20347836SJohn.Forte@Sun.COM 20357836SJohn.Forte@Sun.COM IMA_BOOL isAuthMethodValid(IMA_OID oid, IMA_AUTHMETHOD method) { 20367836SJohn.Forte@Sun.COM IMA_STATUS status; 20377836SJohn.Forte@Sun.COM IMA_AUTHMETHOD supportedList[MAX_AUTHMETHODS]; 20387836SJohn.Forte@Sun.COM IMA_UINT i, supportedCount; 20397836SJohn.Forte@Sun.COM IMA_BOOL supported; 20407836SJohn.Forte@Sun.COM status = getSupportedAuthMethods(oid, IMA_FALSE, &supportedCount, 20417836SJohn.Forte@Sun.COM supportedList); 20427836SJohn.Forte@Sun.COM if (status != IMA_STATUS_SUCCESS) 20437836SJohn.Forte@Sun.COM return (IMA_FALSE); 20447836SJohn.Forte@Sun.COM 20457836SJohn.Forte@Sun.COM supported = IMA_FALSE; 20467836SJohn.Forte@Sun.COM for (i = 0; i < supportedCount; i++) { 20477836SJohn.Forte@Sun.COM if (method == supportedList[i]) { 20487836SJohn.Forte@Sun.COM supported = IMA_TRUE; 20497836SJohn.Forte@Sun.COM } 20507836SJohn.Forte@Sun.COM } 20517836SJohn.Forte@Sun.COM 20527836SJohn.Forte@Sun.COM return (supported); 20537836SJohn.Forte@Sun.COM } 20547836SJohn.Forte@Sun.COM 20557836SJohn.Forte@Sun.COM IMA_BOOL isAuthMethodListValid(IMA_OID oid, const IMA_AUTHMETHOD *pMethodList, 20567836SJohn.Forte@Sun.COM IMA_UINT methodCount) { 20577836SJohn.Forte@Sun.COM IMA_UINT i, j; 20587836SJohn.Forte@Sun.COM 20597836SJohn.Forte@Sun.COM if (pMethodList == NULL) { 20607836SJohn.Forte@Sun.COM return (IMA_FALSE); 20617836SJohn.Forte@Sun.COM } 20627836SJohn.Forte@Sun.COM /* Check list for duplicates */ 20637836SJohn.Forte@Sun.COM for (i = 0; i < methodCount; i++) { 20647836SJohn.Forte@Sun.COM for (j = i + 1; j < methodCount; j++) { 20657836SJohn.Forte@Sun.COM if (pMethodList[i] == pMethodList[j]) { 20667836SJohn.Forte@Sun.COM return (IMA_FALSE); 20677836SJohn.Forte@Sun.COM } 20687836SJohn.Forte@Sun.COM } 20697836SJohn.Forte@Sun.COM 20707836SJohn.Forte@Sun.COM if (isAuthMethodValid(oid, pMethodList[i]) == IMA_FALSE) { 20717836SJohn.Forte@Sun.COM return (IMA_FALSE); 20727836SJohn.Forte@Sun.COM } 20737836SJohn.Forte@Sun.COM } 20747836SJohn.Forte@Sun.COM return (IMA_TRUE); 20757836SJohn.Forte@Sun.COM } 20767836SJohn.Forte@Sun.COM 20777836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetSupportedAuthMethods( 20787836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 20797836SJohn.Forte@Sun.COM IMA_BOOL getSettableMethods, 20807836SJohn.Forte@Sun.COM IMA_UINT *pMethodCount, 20817836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList 20827836SJohn.Forte@Sun.COM ) 20837836SJohn.Forte@Sun.COM { 20847836SJohn.Forte@Sun.COM return (getSupportedAuthMethods(lhbaOid, getSettableMethods, 20857836SJohn.Forte@Sun.COM pMethodCount, pMethodList)); 20867836SJohn.Forte@Sun.COM } 20877836SJohn.Forte@Sun.COM 20887836SJohn.Forte@Sun.COM 20897836SJohn.Forte@Sun.COM /*ARGSUSED*/ 20907836SJohn.Forte@Sun.COM static IMA_STATUS getSupportedAuthMethods( 20917836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 20927836SJohn.Forte@Sun.COM IMA_BOOL getSettableMethods, 20937836SJohn.Forte@Sun.COM IMA_UINT *pMethodCount, 20947836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList 20957836SJohn.Forte@Sun.COM ) 20967836SJohn.Forte@Sun.COM { 20977836SJohn.Forte@Sun.COM if (pMethodList == NULL) { 20987836SJohn.Forte@Sun.COM *pMethodCount = 0; 20997836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 21007836SJohn.Forte@Sun.COM } 21017836SJohn.Forte@Sun.COM 21027836SJohn.Forte@Sun.COM *pMethodCount = NUM_SUPPORTED_AUTH_METHODS; 21037836SJohn.Forte@Sun.COM if (*pMethodCount > 1) { 21047836SJohn.Forte@Sun.COM pMethodList[0] = IMA_AUTHMETHOD_NONE; 21057836SJohn.Forte@Sun.COM pMethodList[1] = IMA_AUTHMETHOD_CHAP; 21067836SJohn.Forte@Sun.COM } 21077836SJohn.Forte@Sun.COM 21087836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 21097836SJohn.Forte@Sun.COM } 21107836SJohn.Forte@Sun.COM 21117836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetInUseInitiatorAuthMethods( 21127836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 21137836SJohn.Forte@Sun.COM IMA_UINT *pMethodCount, 21147836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList 21157836SJohn.Forte@Sun.COM ) 21167836SJohn.Forte@Sun.COM { 21177836SJohn.Forte@Sun.COM return (getAuthMethods(lhbaOid, pMethodCount, pMethodList)); 21187836SJohn.Forte@Sun.COM } 21197836SJohn.Forte@Sun.COM 21207836SJohn.Forte@Sun.COM /*ARGSUSED*/ 21217836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetInitiatorAuthParms( 21227836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 21237836SJohn.Forte@Sun.COM IMA_AUTHMETHOD method, 21247836SJohn.Forte@Sun.COM IMA_INITIATOR_AUTHPARMS *pParms 21257836SJohn.Forte@Sun.COM ) 21267836SJohn.Forte@Sun.COM { 21277836SJohn.Forte@Sun.COM int fd; 21287836SJohn.Forte@Sun.COM iscsi_chap_props_t chap_p; 21297836SJohn.Forte@Sun.COM 21307836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 21317836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 21327836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 21337836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 21347836SJohn.Forte@Sun.COM } 21357836SJohn.Forte@Sun.COM 21367836SJohn.Forte@Sun.COM (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 21377836SJohn.Forte@Sun.COM chap_p.c_vers = ISCSI_INTERFACE_VERSION; 21387836SJohn.Forte@Sun.COM chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber; 21397836SJohn.Forte@Sun.COM 21407836SJohn.Forte@Sun.COM if (method == IMA_AUTHMETHOD_CHAP) { 21417836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_CHAP_GET, &chap_p) != 0) { 21427836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 21437836SJohn.Forte@Sun.COM "ISCSI_CHAP_GET ioctl failed, errno: %d", errno); 21447836SJohn.Forte@Sun.COM (void) close(fd); 21457836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 21467836SJohn.Forte@Sun.COM } 21477836SJohn.Forte@Sun.COM } else { 21487836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 21497836SJohn.Forte@Sun.COM } 21507836SJohn.Forte@Sun.COM 21517836SJohn.Forte@Sun.COM (void) memcpy(pParms->chapParms.name, chap_p.c_user, 21527836SJohn.Forte@Sun.COM chap_p.c_user_len); 21537836SJohn.Forte@Sun.COM pParms->chapParms.nameLength = chap_p.c_user_len; 21547836SJohn.Forte@Sun.COM (void) memcpy(pParms->chapParms.challengeSecret, chap_p.c_secret, 21557836SJohn.Forte@Sun.COM chap_p.c_secret_len); 21567836SJohn.Forte@Sun.COM pParms->chapParms.challengeSecretLength = chap_p.c_secret_len; 21577836SJohn.Forte@Sun.COM 21587836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 21597836SJohn.Forte@Sun.COM } 21607836SJohn.Forte@Sun.COM 21617836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetInitiatorAuthMethods( 21627836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 21637836SJohn.Forte@Sun.COM IMA_UINT methodCount, 21647836SJohn.Forte@Sun.COM const IMA_AUTHMETHOD *pMethodList 21657836SJohn.Forte@Sun.COM ) 21667836SJohn.Forte@Sun.COM { 21677836SJohn.Forte@Sun.COM if (isAuthMethodListValid(lhbaOid, pMethodList, 21687836SJohn.Forte@Sun.COM methodCount) == IMA_FALSE) 21697836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 21707836SJohn.Forte@Sun.COM return (setAuthMethods(lhbaOid, &methodCount, pMethodList)); 21717836SJohn.Forte@Sun.COM } 21727836SJohn.Forte@Sun.COM 21737836SJohn.Forte@Sun.COM /* 21747836SJohn.Forte@Sun.COM * This function only sets CHAP params since we only support CHAP for now. 21757836SJohn.Forte@Sun.COM */ 21767836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetInitiatorAuthParms( 21777836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 21787836SJohn.Forte@Sun.COM IMA_AUTHMETHOD method, 21797836SJohn.Forte@Sun.COM const IMA_INITIATOR_AUTHPARMS *pParms 21807836SJohn.Forte@Sun.COM ) 21817836SJohn.Forte@Sun.COM { 21827836SJohn.Forte@Sun.COM int fd; 21837836SJohn.Forte@Sun.COM iscsi_chap_props_t chap_p; 21847836SJohn.Forte@Sun.COM 21857836SJohn.Forte@Sun.COM if (method != IMA_AUTHMETHOD_CHAP) 21867836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 21877836SJohn.Forte@Sun.COM 21887836SJohn.Forte@Sun.COM if (isAuthMethodValid(lhbaOid, method) == IMA_FALSE) { 21897836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 21907836SJohn.Forte@Sun.COM } 21917836SJohn.Forte@Sun.COM 21927836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 21937836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 21947836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 21957836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 21967836SJohn.Forte@Sun.COM } 21977836SJohn.Forte@Sun.COM 21987836SJohn.Forte@Sun.COM (void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t)); 21997836SJohn.Forte@Sun.COM chap_p.c_vers = ISCSI_INTERFACE_VERSION; 22007836SJohn.Forte@Sun.COM chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber; 22017836SJohn.Forte@Sun.COM 22027836SJohn.Forte@Sun.COM chap_p.c_user_len = pParms->chapParms.nameLength; 22037836SJohn.Forte@Sun.COM (void) memcpy(chap_p.c_user, pParms->chapParms.name, chap_p.c_user_len); 22047836SJohn.Forte@Sun.COM 22057836SJohn.Forte@Sun.COM chap_p.c_secret_len = pParms->chapParms.challengeSecretLength; 22067836SJohn.Forte@Sun.COM (void) memcpy(chap_p.c_secret, pParms->chapParms.challengeSecret, 22077836SJohn.Forte@Sun.COM chap_p.c_secret_len); 22087836SJohn.Forte@Sun.COM 22097836SJohn.Forte@Sun.COM if (method == IMA_AUTHMETHOD_CHAP) { 22107836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_CHAP_SET, &chap_p) != 0) { 22117836SJohn.Forte@Sun.COM (void) close(fd); 22127836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 22137836SJohn.Forte@Sun.COM "ISCSI_CHAP_SET ioctl failed, errno: %d", errno); 22147836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 22157836SJohn.Forte@Sun.COM } 22167836SJohn.Forte@Sun.COM } 22177836SJohn.Forte@Sun.COM 22187836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 22197836SJohn.Forte@Sun.COM } 22207836SJohn.Forte@Sun.COM 22217836SJohn.Forte@Sun.COM /* A helper function to obtain iSCSI node parameters. */ 22227836SJohn.Forte@Sun.COM static IMA_STATUS 22237836SJohn.Forte@Sun.COM getISCSINodeParameter( 22247836SJohn.Forte@Sun.COM int paramType, 22257836SJohn.Forte@Sun.COM IMA_OID *oid, 22267836SJohn.Forte@Sun.COM void *pProps, 22277836SJohn.Forte@Sun.COM uint32_t paramIndex 22287836SJohn.Forte@Sun.COM ) 22297836SJohn.Forte@Sun.COM { 22307836SJohn.Forte@Sun.COM int fd; 22317836SJohn.Forte@Sun.COM iscsi_param_get_t pg; 22327836SJohn.Forte@Sun.COM 22337836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 22347836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 22357836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 22367836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 22377836SJohn.Forte@Sun.COM } 22387836SJohn.Forte@Sun.COM 22397836SJohn.Forte@Sun.COM (void) memset(&pg, 0, sizeof (iscsi_param_get_t)); 22407836SJohn.Forte@Sun.COM pg.g_vers = ISCSI_INTERFACE_VERSION; 22417836SJohn.Forte@Sun.COM pg.g_oid = (uint32_t)oid->objectSequenceNumber; 22427836SJohn.Forte@Sun.COM pg.g_param = paramIndex; 22437836SJohn.Forte@Sun.COM pg.g_param_type = ISCSI_SESS_PARAM; 22447836SJohn.Forte@Sun.COM 22457836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) { 22467836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 22477836SJohn.Forte@Sun.COM "ISCSI_PARAM_GET ioctl failed, errno: %d", errno); 22487836SJohn.Forte@Sun.COM (void) close(fd); 22497836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 22507836SJohn.Forte@Sun.COM } 22517836SJohn.Forte@Sun.COM 22527836SJohn.Forte@Sun.COM switch (paramType) { 22537836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *bp; 22547836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *mp; 22557836SJohn.Forte@Sun.COM 22567836SJohn.Forte@Sun.COM case MIN_MAX_PARAM: 22577836SJohn.Forte@Sun.COM mp = (IMA_MIN_MAX_VALUE *)pProps; 22587836SJohn.Forte@Sun.COM 22597836SJohn.Forte@Sun.COM mp->currentValueValid = 22607836SJohn.Forte@Sun.COM (pg.g_value.v_valid == B_TRUE) ? 22617836SJohn.Forte@Sun.COM IMA_TRUE : IMA_FALSE; 22627836SJohn.Forte@Sun.COM mp->currentValue = pg.g_value.v_integer.i_current; 22637836SJohn.Forte@Sun.COM mp->defaultValue = pg.g_value.v_integer.i_default; 22647836SJohn.Forte@Sun.COM mp->minimumValue = pg.g_value.v_integer.i_min; 22657836SJohn.Forte@Sun.COM mp->maximumValue = pg.g_value.v_integer.i_max; 22667836SJohn.Forte@Sun.COM mp->incrementValue = pg.g_value.v_integer.i_incr; 22677836SJohn.Forte@Sun.COM break; 22687836SJohn.Forte@Sun.COM 22697836SJohn.Forte@Sun.COM case BOOL_PARAM: 22707836SJohn.Forte@Sun.COM bp = (IMA_BOOL_VALUE *)pProps; 22717836SJohn.Forte@Sun.COM bp->currentValueValid = 22727836SJohn.Forte@Sun.COM (pg.g_value.v_valid == B_TRUE) ? 22737836SJohn.Forte@Sun.COM IMA_TRUE : IMA_FALSE; 22747836SJohn.Forte@Sun.COM bp->currentValue = pg.g_value.v_bool.b_current; 22757836SJohn.Forte@Sun.COM bp->defaultValue = pg.g_value.v_bool.b_default; 22767836SJohn.Forte@Sun.COM break; 22777836SJohn.Forte@Sun.COM 22787836SJohn.Forte@Sun.COM default: 22797836SJohn.Forte@Sun.COM break; 22807836SJohn.Forte@Sun.COM } 22817836SJohn.Forte@Sun.COM 22827836SJohn.Forte@Sun.COM (void) close(fd); 22837836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 22847836SJohn.Forte@Sun.COM } 22857836SJohn.Forte@Sun.COM 22867836SJohn.Forte@Sun.COM /* A helper function to set iSCSI node parameters. */ 22877836SJohn.Forte@Sun.COM static IMA_STATUS 22887836SJohn.Forte@Sun.COM setISCSINodeParameter( 22897836SJohn.Forte@Sun.COM int paramType, 22907836SJohn.Forte@Sun.COM IMA_OID *oid, 22917836SJohn.Forte@Sun.COM void *pProp, 22927836SJohn.Forte@Sun.COM uint32_t paramIndex 22937836SJohn.Forte@Sun.COM ) 22947836SJohn.Forte@Sun.COM { 22957836SJohn.Forte@Sun.COM int fd; 22967836SJohn.Forte@Sun.COM iscsi_param_set_t ps; 22977836SJohn.Forte@Sun.COM 22987836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 22997836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 23007836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 23017836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 23027836SJohn.Forte@Sun.COM } 23037836SJohn.Forte@Sun.COM 23047836SJohn.Forte@Sun.COM (void) memset(&ps, 0, sizeof (iscsi_param_set_t)); 23057836SJohn.Forte@Sun.COM ps.s_vers = ISCSI_INTERFACE_VERSION; 23067836SJohn.Forte@Sun.COM ps.s_oid = (uint32_t)oid->objectSequenceNumber; 23077836SJohn.Forte@Sun.COM ps.s_param = paramIndex; 23087836SJohn.Forte@Sun.COM 23097836SJohn.Forte@Sun.COM switch (paramType) { 23107836SJohn.Forte@Sun.COM IMA_BOOL_VALUE *bp; 23117836SJohn.Forte@Sun.COM IMA_MIN_MAX_VALUE *mp; 23127836SJohn.Forte@Sun.COM 23137836SJohn.Forte@Sun.COM case MIN_MAX_PARAM: 23147836SJohn.Forte@Sun.COM mp = (IMA_MIN_MAX_VALUE *)pProp; 23157836SJohn.Forte@Sun.COM ps.s_value.v_integer = mp->currentValue; 23167836SJohn.Forte@Sun.COM break; 23177836SJohn.Forte@Sun.COM case BOOL_PARAM: 23187836SJohn.Forte@Sun.COM bp = (IMA_BOOL_VALUE *)pProp; 23197836SJohn.Forte@Sun.COM ps.s_value.v_bool = 23207836SJohn.Forte@Sun.COM (bp->currentValue == IMA_TRUE) ? 23217836SJohn.Forte@Sun.COM B_TRUE : B_FALSE; 23227836SJohn.Forte@Sun.COM break; 23237836SJohn.Forte@Sun.COM 23247836SJohn.Forte@Sun.COM default: 23257836SJohn.Forte@Sun.COM break; 23267836SJohn.Forte@Sun.COM } 23277836SJohn.Forte@Sun.COM 23287836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_PARAM_SET, &ps)) { 23297836SJohn.Forte@Sun.COM int tmpErrno = errno; 23307836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 23317836SJohn.Forte@Sun.COM "ISCSI_PARAM_SET ioctl failed, errno: %d", errno); 23327836SJohn.Forte@Sun.COM (void) close(fd); 23337836SJohn.Forte@Sun.COM switch (tmpErrno) { 23347836SJohn.Forte@Sun.COM case ENOTSUP : 23357836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 23367836SJohn.Forte@Sun.COM default : 23377836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 23387836SJohn.Forte@Sun.COM } 23397836SJohn.Forte@Sun.COM } 23407836SJohn.Forte@Sun.COM 23417836SJohn.Forte@Sun.COM (void) close(fd); 23427836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 23437836SJohn.Forte@Sun.COM } 23447836SJohn.Forte@Sun.COM 23457836SJohn.Forte@Sun.COM static int 23467836SJohn.Forte@Sun.COM prepare_discovery_entry( 23477836SJohn.Forte@Sun.COM IMA_TARGET_ADDRESS discoveryAddress, 23487836SJohn.Forte@Sun.COM entry_t *entry 23497836SJohn.Forte@Sun.COM ) 23507836SJohn.Forte@Sun.COM { 23517836SJohn.Forte@Sun.COM (void) memset(entry, 0, sizeof (entry_t)); 23527836SJohn.Forte@Sun.COM entry->e_vers = ISCSI_INTERFACE_VERSION; 23537836SJohn.Forte@Sun.COM entry->e_oid = ISCSI_OID_NOTSET; 23547836SJohn.Forte@Sun.COM 23557836SJohn.Forte@Sun.COM if (discoveryAddress.hostnameIpAddress.id.ipAddress.ipv4Address == 23567836SJohn.Forte@Sun.COM IMA_FALSE) { 23577836SJohn.Forte@Sun.COM bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress, 23587836SJohn.Forte@Sun.COM entry->e_u.u_in6.s6_addr, 23597836SJohn.Forte@Sun.COM sizeof (entry->e_u.u_in6.s6_addr)); 23607836SJohn.Forte@Sun.COM entry->e_insize = sizeof (struct in6_addr); 23617836SJohn.Forte@Sun.COM } else { 23627836SJohn.Forte@Sun.COM bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress, 23637836SJohn.Forte@Sun.COM &entry->e_u.u_in4.s_addr, 23647836SJohn.Forte@Sun.COM sizeof (entry->e_u.u_in4.s_addr)); 23657836SJohn.Forte@Sun.COM entry->e_insize = sizeof (struct in_addr); 23667836SJohn.Forte@Sun.COM } 23677836SJohn.Forte@Sun.COM 23687836SJohn.Forte@Sun.COM entry->e_port = discoveryAddress.portNumber; 23697836SJohn.Forte@Sun.COM entry->e_tpgt = 0; 23707836SJohn.Forte@Sun.COM return (DISC_ADDR_OK); 23717836SJohn.Forte@Sun.COM } 23727836SJohn.Forte@Sun.COM 23737836SJohn.Forte@Sun.COM static IMA_STATUS configure_discovery_method( 23747836SJohn.Forte@Sun.COM IMA_BOOL enable, 23757836SJohn.Forte@Sun.COM iSCSIDiscoveryMethod_t method 23767836SJohn.Forte@Sun.COM ) 23777836SJohn.Forte@Sun.COM { 23787836SJohn.Forte@Sun.COM int fd, status; 23797836SJohn.Forte@Sun.COM 23807836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 23817836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 23827836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 23837836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 23847836SJohn.Forte@Sun.COM } 23857836SJohn.Forte@Sun.COM 23867836SJohn.Forte@Sun.COM if (enable == IMA_FALSE) { 23877836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_CLEAR, &method)) { 23887836SJohn.Forte@Sun.COM status = errno; 23897836SJohn.Forte@Sun.COM (void) close(fd); 23907836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 23917836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_CLEAR ioctl failed, errno: %d", 23927836SJohn.Forte@Sun.COM status); 23937836SJohn.Forte@Sun.COM if (status == EBUSY) { 23947836SJohn.Forte@Sun.COM return (IMA_ERROR_LU_IN_USE); 23957836SJohn.Forte@Sun.COM } else { 23967836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 23977836SJohn.Forte@Sun.COM } 23987836SJohn.Forte@Sun.COM } 23997836SJohn.Forte@Sun.COM 24007836SJohn.Forte@Sun.COM (void) close(fd); 24017836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 24027836SJohn.Forte@Sun.COM } else { 24037836SJohn.Forte@Sun.COM /* Set the discovery method */ 24047836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_SET, &method)) { 24057836SJohn.Forte@Sun.COM (void) close(fd); 24067836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 24077836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_SET ioctl failed, errno: %d", 24087836SJohn.Forte@Sun.COM errno); 24097836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 24107836SJohn.Forte@Sun.COM } 24117836SJohn.Forte@Sun.COM 24127836SJohn.Forte@Sun.COM (void) close(fd); 24137836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 24147836SJohn.Forte@Sun.COM } 24157836SJohn.Forte@Sun.COM } 24167836SJohn.Forte@Sun.COM 24177836SJohn.Forte@Sun.COM static IMA_STATUS get_target_oid_list( 24187836SJohn.Forte@Sun.COM uint32_t targetListType, 24197836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList) 24207836SJohn.Forte@Sun.COM { 24217836SJohn.Forte@Sun.COM int fd; 24227836SJohn.Forte@Sun.COM int i; 24237836SJohn.Forte@Sun.COM int target_list_size; 24247836SJohn.Forte@Sun.COM iscsi_target_list_t *idlp, tl_info; 24257836SJohn.Forte@Sun.COM 24267836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 24277836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 24287836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 24297836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 24307836SJohn.Forte@Sun.COM } 24317836SJohn.Forte@Sun.COM 24327836SJohn.Forte@Sun.COM (void) memset(&tl_info, 0, sizeof (tl_info)); 24337836SJohn.Forte@Sun.COM tl_info.tl_vers = ISCSI_INTERFACE_VERSION; 24347836SJohn.Forte@Sun.COM tl_info.tl_in_cnt = 0; 24357836SJohn.Forte@Sun.COM tl_info.tl_tgt_list_type = targetListType; 24367836SJohn.Forte@Sun.COM 24377836SJohn.Forte@Sun.COM /* 24387836SJohn.Forte@Sun.COM * Issue ioctl to obtain the number of targets. 24397836SJohn.Forte@Sun.COM */ 24407836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, &tl_info) != 0) { 24417836SJohn.Forte@Sun.COM (void) close(fd); 24427836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 24437836SJohn.Forte@Sun.COM "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 24447836SJohn.Forte@Sun.COM targetListType, errno); 24457836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 24467836SJohn.Forte@Sun.COM } 24477836SJohn.Forte@Sun.COM 24487836SJohn.Forte@Sun.COM target_list_size = sizeof (iscsi_target_list_t); 24497836SJohn.Forte@Sun.COM if (tl_info.tl_out_cnt > 1) { 24507836SJohn.Forte@Sun.COM target_list_size += (sizeof (uint32_t) * 24517836SJohn.Forte@Sun.COM tl_info.tl_out_cnt - 1); 24527836SJohn.Forte@Sun.COM } 24537836SJohn.Forte@Sun.COM 24547836SJohn.Forte@Sun.COM idlp = (iscsi_target_list_t *)calloc(1, target_list_size); 24557836SJohn.Forte@Sun.COM if (idlp == NULL) { 24567836SJohn.Forte@Sun.COM (void) close(fd); 24577836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 24587836SJohn.Forte@Sun.COM } 24597836SJohn.Forte@Sun.COM 24607836SJohn.Forte@Sun.COM idlp->tl_vers = ISCSI_INTERFACE_VERSION; 24617836SJohn.Forte@Sun.COM idlp->tl_in_cnt = tl_info.tl_out_cnt; 24627836SJohn.Forte@Sun.COM idlp->tl_tgt_list_type = targetListType; 24637836SJohn.Forte@Sun.COM 24647836SJohn.Forte@Sun.COM /* Issue the same ioctl again to obtain the OIDs. */ 24657836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) { 24667836SJohn.Forte@Sun.COM free(idlp); 24677836SJohn.Forte@Sun.COM (void) close(fd); 24687836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 24697836SJohn.Forte@Sun.COM "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d", 24707836SJohn.Forte@Sun.COM targetListType, errno); 24717836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 24727836SJohn.Forte@Sun.COM } 24737836SJohn.Forte@Sun.COM 24747836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) + 24757836SJohn.Forte@Sun.COM idlp->tl_out_cnt * sizeof (IMA_OID)); 24767836SJohn.Forte@Sun.COM if (*ppList == NULL) { 24777836SJohn.Forte@Sun.COM free(idlp); 24787836SJohn.Forte@Sun.COM (void) close(fd); 24797836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 24807836SJohn.Forte@Sun.COM } 24817836SJohn.Forte@Sun.COM (*ppList)->oidCount = idlp->tl_out_cnt; 24827836SJohn.Forte@Sun.COM 24837836SJohn.Forte@Sun.COM for (i = 0; i < idlp->tl_out_cnt; i++) { 24847836SJohn.Forte@Sun.COM 24857836SJohn.Forte@Sun.COM if (targetListType == ISCSI_STATIC_TGT_OID_LIST) 24867836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectType = 24877836SJohn.Forte@Sun.COM IMA_OBJECT_TYPE_STATIC_DISCOVERY_TARGET; 24887836SJohn.Forte@Sun.COM else 24897836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_TARGET; 24907836SJohn.Forte@Sun.COM 24917836SJohn.Forte@Sun.COM (*ppList)->oids[i].ownerId = pluginOwnerId; 24927836SJohn.Forte@Sun.COM (*ppList)->oids[i].objectSequenceNumber = idlp->tl_oid_list[i]; 24937836SJohn.Forte@Sun.COM } 24947836SJohn.Forte@Sun.COM 24957836SJohn.Forte@Sun.COM free(idlp); 24967836SJohn.Forte@Sun.COM (void) close(fd); 24977836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 24987836SJohn.Forte@Sun.COM } 24997836SJohn.Forte@Sun.COM 25007836SJohn.Forte@Sun.COM static IMA_STATUS get_target_lun_oid_list( 25017836SJohn.Forte@Sun.COM IMA_OID * targetOid, 25027836SJohn.Forte@Sun.COM iscsi_lun_list_t **ppLunList) 25037836SJohn.Forte@Sun.COM { 25047836SJohn.Forte@Sun.COM int fd; 25057836SJohn.Forte@Sun.COM iscsi_lun_list_t *illp, ll_info; 25067836SJohn.Forte@Sun.COM int lun_list_size; 25077836SJohn.Forte@Sun.COM 25087836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 25097836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 25107836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 25117836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 25127836SJohn.Forte@Sun.COM } 25137836SJohn.Forte@Sun.COM 25147836SJohn.Forte@Sun.COM (void) memset(&ll_info, 0, sizeof (ll_info)); 25157836SJohn.Forte@Sun.COM ll_info.ll_vers = ISCSI_INTERFACE_VERSION; 25167836SJohn.Forte@Sun.COM if (targetOid == NULL) { 25177836SJohn.Forte@Sun.COM /* get lun oid list for all targets */ 25187836SJohn.Forte@Sun.COM ll_info.ll_all_tgts = B_TRUE; 25197836SJohn.Forte@Sun.COM } else { 25207836SJohn.Forte@Sun.COM /* get lun oid list for single target */ 25217836SJohn.Forte@Sun.COM ll_info.ll_all_tgts = B_FALSE; 25227836SJohn.Forte@Sun.COM ll_info.ll_tgt_oid = (uint32_t)targetOid->objectSequenceNumber; 25237836SJohn.Forte@Sun.COM } 25247836SJohn.Forte@Sun.COM ll_info.ll_in_cnt = 0; 25257836SJohn.Forte@Sun.COM 25267836SJohn.Forte@Sun.COM /* 25277836SJohn.Forte@Sun.COM * Issue ioctl to obtain the number of target LUNs. 25287836SJohn.Forte@Sun.COM */ 25297836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, &ll_info) != 0) { 25307836SJohn.Forte@Sun.COM (void) close(fd); 25317836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 25327836SJohn.Forte@Sun.COM "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno); 25337836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 25347836SJohn.Forte@Sun.COM } 25357836SJohn.Forte@Sun.COM 25367836SJohn.Forte@Sun.COM lun_list_size = sizeof (iscsi_lun_list_t); 25377836SJohn.Forte@Sun.COM if (ll_info.ll_out_cnt > 1) { 25387836SJohn.Forte@Sun.COM lun_list_size += (sizeof (iscsi_if_lun_t) * 25397836SJohn.Forte@Sun.COM (ll_info.ll_out_cnt - 1)); 25407836SJohn.Forte@Sun.COM } 25417836SJohn.Forte@Sun.COM 25427836SJohn.Forte@Sun.COM illp = (iscsi_lun_list_t *)calloc(1, lun_list_size); 25437836SJohn.Forte@Sun.COM if (illp == NULL) { 25447836SJohn.Forte@Sun.COM (void) close(fd); 25457836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 25467836SJohn.Forte@Sun.COM } 25477836SJohn.Forte@Sun.COM illp->ll_vers = ISCSI_INTERFACE_VERSION; 25487836SJohn.Forte@Sun.COM illp->ll_all_tgts = ll_info.ll_all_tgts; 25497836SJohn.Forte@Sun.COM illp->ll_tgt_oid = ll_info.ll_tgt_oid; 25507836SJohn.Forte@Sun.COM illp->ll_in_cnt = ll_info.ll_out_cnt; 25517836SJohn.Forte@Sun.COM 25527836SJohn.Forte@Sun.COM /* Issue the same ioctl again to get the target LUN list */ 25537836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) { 25547836SJohn.Forte@Sun.COM free(illp); 25557836SJohn.Forte@Sun.COM (void) close(fd); 25567836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 25577836SJohn.Forte@Sun.COM "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno); 25587836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 25597836SJohn.Forte@Sun.COM } 25607836SJohn.Forte@Sun.COM 25617836SJohn.Forte@Sun.COM *ppLunList = illp; 25627836SJohn.Forte@Sun.COM 25637836SJohn.Forte@Sun.COM (void) close(fd); 25647836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 25657836SJohn.Forte@Sun.COM } 25667836SJohn.Forte@Sun.COM 25677836SJohn.Forte@Sun.COM 25687836SJohn.Forte@Sun.COM /* A helper function to set authentication method. */ 25697836SJohn.Forte@Sun.COM static IMA_STATUS 25707836SJohn.Forte@Sun.COM setAuthMethods( 25717836SJohn.Forte@Sun.COM IMA_OID oid, 25727836SJohn.Forte@Sun.COM IMA_UINT *pMethodCount, 25737836SJohn.Forte@Sun.COM const IMA_AUTHMETHOD *pMethodList 25747836SJohn.Forte@Sun.COM ) 25757836SJohn.Forte@Sun.COM { 25767836SJohn.Forte@Sun.COM int fd; 25777836SJohn.Forte@Sun.COM int i; 25787836SJohn.Forte@Sun.COM iscsi_auth_props_t auth; 25797836SJohn.Forte@Sun.COM 25807836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 25817836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 25827836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 25837836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 25847836SJohn.Forte@Sun.COM } 25857836SJohn.Forte@Sun.COM (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 25867836SJohn.Forte@Sun.COM auth.a_vers = ISCSI_INTERFACE_VERSION; 25877836SJohn.Forte@Sun.COM auth.a_oid = (uint32_t)oid.objectSequenceNumber; 25887836SJohn.Forte@Sun.COM /* First do a get because other data fields may exist */ 25897836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 25907836SJohn.Forte@Sun.COM /* EMPTY */ 25917836SJohn.Forte@Sun.COM /* It is fine if there is no other data fields. */ 25927836SJohn.Forte@Sun.COM } 25937836SJohn.Forte@Sun.COM auth.a_auth_method = authMethodNone; 25947836SJohn.Forte@Sun.COM 25957836SJohn.Forte@Sun.COM for (i = 0; i < *pMethodCount; i++) { 25967836SJohn.Forte@Sun.COM switch (pMethodList[i]) { 25977836SJohn.Forte@Sun.COM case IMA_AUTHMETHOD_CHAP: 25987836SJohn.Forte@Sun.COM auth.a_auth_method |= authMethodCHAP; 25997836SJohn.Forte@Sun.COM break; 26007836SJohn.Forte@Sun.COM default: 26017836SJohn.Forte@Sun.COM break; 26027836SJohn.Forte@Sun.COM } 26037836SJohn.Forte@Sun.COM } 26047836SJohn.Forte@Sun.COM 26057836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) { 26067836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 26077836SJohn.Forte@Sun.COM "ISCSI_AUTH_SET failed, errno: %d", errno); 26087836SJohn.Forte@Sun.COM (void) close(fd); 26097836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 26107836SJohn.Forte@Sun.COM } 26117836SJohn.Forte@Sun.COM 26127836SJohn.Forte@Sun.COM (void) close(fd); 26137836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 26147836SJohn.Forte@Sun.COM } 26157836SJohn.Forte@Sun.COM 26167836SJohn.Forte@Sun.COM /* A helper function to get authentication method. */ 26177836SJohn.Forte@Sun.COM static IMA_STATUS 26187836SJohn.Forte@Sun.COM getAuthMethods( 26197836SJohn.Forte@Sun.COM IMA_OID oid, 26207836SJohn.Forte@Sun.COM IMA_UINT *pMethodCount, 26217836SJohn.Forte@Sun.COM IMA_AUTHMETHOD *pMethodList 26227836SJohn.Forte@Sun.COM ) 26237836SJohn.Forte@Sun.COM { 26247836SJohn.Forte@Sun.COM int fd, i; 26257836SJohn.Forte@Sun.COM iscsi_auth_props_t auth; 26267836SJohn.Forte@Sun.COM 26277836SJohn.Forte@Sun.COM if (pMethodList == NULL) { 26287836SJohn.Forte@Sun.COM *pMethodCount = 0; 26297836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 26307836SJohn.Forte@Sun.COM } 26317836SJohn.Forte@Sun.COM 26327836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 26337836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 26347836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 26357836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 26367836SJohn.Forte@Sun.COM } 26377836SJohn.Forte@Sun.COM 26387836SJohn.Forte@Sun.COM (void) memset(&auth, 0, sizeof (iscsi_auth_props_t)); 26397836SJohn.Forte@Sun.COM auth.a_vers = ISCSI_INTERFACE_VERSION; 26407836SJohn.Forte@Sun.COM auth.a_oid = (uint32_t)oid.objectSequenceNumber; 26417836SJohn.Forte@Sun.COM 26427836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) { 26437836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 26447836SJohn.Forte@Sun.COM "ISCSI_AUTH_GET failed, errno: %d", errno); 26457836SJohn.Forte@Sun.COM (void) close(fd); 26467836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 26477836SJohn.Forte@Sun.COM } 26487836SJohn.Forte@Sun.COM 26497836SJohn.Forte@Sun.COM i = 0; 26507836SJohn.Forte@Sun.COM if (auth.a_auth_method == IMA_AUTHMETHOD_NONE) { 26517836SJohn.Forte@Sun.COM pMethodList[i++] = IMA_AUTHMETHOD_NONE; 26527836SJohn.Forte@Sun.COM } else if (auth.a_auth_method & authMethodCHAP) { 26537836SJohn.Forte@Sun.COM pMethodList[i++] = IMA_AUTHMETHOD_CHAP; 26547836SJohn.Forte@Sun.COM } 26557836SJohn.Forte@Sun.COM *pMethodCount = i; 26567836SJohn.Forte@Sun.COM 26577836SJohn.Forte@Sun.COM (void) close(fd); 26587836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 26597836SJohn.Forte@Sun.COM } 26607836SJohn.Forte@Sun.COM 26617836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaOidList( 26627836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 26637836SJohn.Forte@Sun.COM ) 26647836SJohn.Forte@Sun.COM { 26657836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST)); 26667836SJohn.Forte@Sun.COM if (*ppList == NULL) { 26677836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 26687836SJohn.Forte@Sun.COM } 26697836SJohn.Forte@Sun.COM (*ppList)->oidCount = 0; 26707836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 26717836SJohn.Forte@Sun.COM } 26727836SJohn.Forte@Sun.COM 26737836SJohn.Forte@Sun.COM /* ARGSUSED */ 26747836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaProperties( 26757836SJohn.Forte@Sun.COM IMA_OID phbaOid, 26767836SJohn.Forte@Sun.COM IMA_PHBA_PROPERTIES *pProps 26777836SJohn.Forte@Sun.COM ) 26787836SJohn.Forte@Sun.COM { 26797836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 26807836SJohn.Forte@Sun.COM } 26817836SJohn.Forte@Sun.COM 26827836SJohn.Forte@Sun.COM /* ARGSUSED */ 26837836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaStatus( 26847836SJohn.Forte@Sun.COM IMA_OID phbaOid, 26857836SJohn.Forte@Sun.COM IMA_PHBA_STATUS *pStatus 26867836SJohn.Forte@Sun.COM ) 26877836SJohn.Forte@Sun.COM { 26887836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 26897836SJohn.Forte@Sun.COM } 26907836SJohn.Forte@Sun.COM 26917836SJohn.Forte@Sun.COM /* ARGSUSED */ 26927836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPhbaDownloadProperties( 26937836SJohn.Forte@Sun.COM IMA_OID phbaOid, 26947836SJohn.Forte@Sun.COM IMA_PHBA_DOWNLOAD_PROPERTIES *pProps 26957836SJohn.Forte@Sun.COM ) 26967836SJohn.Forte@Sun.COM { 26977836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 26987836SJohn.Forte@Sun.COM } 26997836SJohn.Forte@Sun.COM 27007836SJohn.Forte@Sun.COM /* ARGSUSED */ 27017836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_IsPhbaDownloadFile( 27027836SJohn.Forte@Sun.COM IMA_OID phbaOid, 27037836SJohn.Forte@Sun.COM const IMA_WCHAR *pFileName, 27047836SJohn.Forte@Sun.COM IMA_PHBA_DOWNLOAD_IMAGE_PROPERTIES *pProps 27057836SJohn.Forte@Sun.COM ) 27067836SJohn.Forte@Sun.COM { 27077836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27087836SJohn.Forte@Sun.COM } 27097836SJohn.Forte@Sun.COM 27107836SJohn.Forte@Sun.COM /* ARGSUSED */ 27117836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_PhbaDownload( 27127836SJohn.Forte@Sun.COM IMA_OID phbaOid, 27137836SJohn.Forte@Sun.COM IMA_PHBA_DOWNLOAD_IMAGE_TYPE imageType, 27147836SJohn.Forte@Sun.COM const IMA_WCHAR *pFileName 27157836SJohn.Forte@Sun.COM ) 27167836SJohn.Forte@Sun.COM { 27177836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27187836SJohn.Forte@Sun.COM } 27197836SJohn.Forte@Sun.COM 27207836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpOidList( 27217836SJohn.Forte@Sun.COM IMA_OID pnpOid, 27227836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 27237836SJohn.Forte@Sun.COM ) 27247836SJohn.Forte@Sun.COM { 27257836SJohn.Forte@Sun.COM /* 27267836SJohn.Forte@Sun.COM * Always return the same object ID for the pnp as the spec 27277836SJohn.Forte@Sun.COM * states that this function will always return a list of at least 27287836SJohn.Forte@Sun.COM * one element 27297836SJohn.Forte@Sun.COM */ 27307836SJohn.Forte@Sun.COM pnpOid.objectType = IMA_OBJECT_TYPE_PNP; 27317836SJohn.Forte@Sun.COM pnpOid.ownerId = pluginOwnerId; 27327836SJohn.Forte@Sun.COM pnpOid.objectSequenceNumber = ISCSI_INITIATOR_OID; 27337836SJohn.Forte@Sun.COM 27347836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) + 27357836SJohn.Forte@Sun.COM (1* sizeof (IMA_OID))); 27367836SJohn.Forte@Sun.COM 27377836SJohn.Forte@Sun.COM if (*ppList == NULL) { 27387836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 27397836SJohn.Forte@Sun.COM } 27407836SJohn.Forte@Sun.COM 27417836SJohn.Forte@Sun.COM (*ppList)->oidCount = 1; 27427836SJohn.Forte@Sun.COM (void) memcpy(&(*ppList)->oids[0], &pnpOid, sizeof (pnpOid)); 27437836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 27447836SJohn.Forte@Sun.COM } 27457836SJohn.Forte@Sun.COM 27467836SJohn.Forte@Sun.COM /* ARGSUSED */ 27477836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpProperties( 27487836SJohn.Forte@Sun.COM IMA_OID pnpOid, 27497836SJohn.Forte@Sun.COM IMA_PNP_PROPERTIES *pProps 27507836SJohn.Forte@Sun.COM ) 27517836SJohn.Forte@Sun.COM { 27527836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27537836SJohn.Forte@Sun.COM } 27547836SJohn.Forte@Sun.COM 27557836SJohn.Forte@Sun.COM /* ARGSUSED */ 27567836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPnpStatistics( 27577836SJohn.Forte@Sun.COM IMA_OID pnpOid, 27587836SJohn.Forte@Sun.COM IMA_PNP_STATISTICS *pStats 27597836SJohn.Forte@Sun.COM ) 27607836SJohn.Forte@Sun.COM { 27617836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27627836SJohn.Forte@Sun.COM } 27637836SJohn.Forte@Sun.COM 27647836SJohn.Forte@Sun.COM /* ARGSUSED */ 27657836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetIpProperties( 27667836SJohn.Forte@Sun.COM IMA_OID oid, 27677836SJohn.Forte@Sun.COM IMA_IP_PROPERTIES *pProps 27687836SJohn.Forte@Sun.COM ) 27697836SJohn.Forte@Sun.COM { 27707836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27717836SJohn.Forte@Sun.COM } 27727836SJohn.Forte@Sun.COM 27737836SJohn.Forte@Sun.COM /* ARGSUSED */ 27747836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDefaultGateway( 27757836SJohn.Forte@Sun.COM IMA_OID oid, 27767836SJohn.Forte@Sun.COM IMA_IP_ADDRESS defaultGateway 27777836SJohn.Forte@Sun.COM ) 27787836SJohn.Forte@Sun.COM { 27797836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27807836SJohn.Forte@Sun.COM } 27817836SJohn.Forte@Sun.COM 27827836SJohn.Forte@Sun.COM /* ARGSUSED */ 27837836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetDnsServerAddress( 27847836SJohn.Forte@Sun.COM IMA_OID oid, 27857836SJohn.Forte@Sun.COM const IMA_IP_ADDRESS *pPrimaryDnsServerAddress, 27867836SJohn.Forte@Sun.COM const IMA_IP_ADDRESS *pAlternateDnsServerAddress 27877836SJohn.Forte@Sun.COM ) 27887836SJohn.Forte@Sun.COM { 27897836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27907836SJohn.Forte@Sun.COM } 27917836SJohn.Forte@Sun.COM 27927836SJohn.Forte@Sun.COM /* ARGSUSED */ 27937836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetSubnetMask( 27947836SJohn.Forte@Sun.COM IMA_OID oid, 27957836SJohn.Forte@Sun.COM IMA_IP_ADDRESS subnetMask 27967836SJohn.Forte@Sun.COM ) 27977836SJohn.Forte@Sun.COM { 27987836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 27997836SJohn.Forte@Sun.COM } 28007836SJohn.Forte@Sun.COM 28017836SJohn.Forte@Sun.COM /* ARGSUSED */ 28027836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetIpConfigMethod( 28037836SJohn.Forte@Sun.COM IMA_OID oid, 28047836SJohn.Forte@Sun.COM IMA_BOOL enableDhcpIpConfiguration 28057836SJohn.Forte@Sun.COM ) 28067836SJohn.Forte@Sun.COM { 28077836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 28087836SJohn.Forte@Sun.COM } 28097836SJohn.Forte@Sun.COM 28107836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RegisterForObjectPropertyChanges( 28117836SJohn.Forte@Sun.COM IMA_OBJECT_PROPERTY_FN pClientFn 28127836SJohn.Forte@Sun.COM ) 28137836SJohn.Forte@Sun.COM { 28147836SJohn.Forte@Sun.COM pObjectPropertyCallback = pClientFn; 28157836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 28167836SJohn.Forte@Sun.COM } 28177836SJohn.Forte@Sun.COM 28187836SJohn.Forte@Sun.COM /* ARGSUSED */ 28197836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_DeregisterForObjectPropertyChanges( 28207836SJohn.Forte@Sun.COM IMA_OBJECT_PROPERTY_FN pClientFn 28217836SJohn.Forte@Sun.COM ) 28227836SJohn.Forte@Sun.COM { 28237836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 28247836SJohn.Forte@Sun.COM } 28257836SJohn.Forte@Sun.COM 28267836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RegisterForObjectVisibilityChanges( 28277836SJohn.Forte@Sun.COM IMA_OBJECT_VISIBILITY_FN pClientFn 28287836SJohn.Forte@Sun.COM ) 28297836SJohn.Forte@Sun.COM { 28307836SJohn.Forte@Sun.COM pObjectVisibilityCallback = pClientFn; 28317836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 28327836SJohn.Forte@Sun.COM } 28337836SJohn.Forte@Sun.COM 28347836SJohn.Forte@Sun.COM /* ARGSUSED */ 28357836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_DeregisterForObjectVisibilityChanges( 28367836SJohn.Forte@Sun.COM IMA_OBJECT_VISIBILITY_FN pClientFn 28377836SJohn.Forte@Sun.COM ) 28387836SJohn.Forte@Sun.COM { 28397836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 28407836SJohn.Forte@Sun.COM } 28417836SJohn.Forte@Sun.COM 28427836SJohn.Forte@Sun.COM /* ARGSUSED */ 28437836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortStatus( 28447836SJohn.Forte@Sun.COM IMA_OID portOid, 28457836SJohn.Forte@Sun.COM IMA_NETWORK_PORT_STATUS *pStaus 28467836SJohn.Forte@Sun.COM ) 28477836SJohn.Forte@Sun.COM { 28487836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 28497836SJohn.Forte@Sun.COM } 28507836SJohn.Forte@Sun.COM 28517836SJohn.Forte@Sun.COM /* ARGSUSED */ 28527836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortalOidList( 28537836SJohn.Forte@Sun.COM IMA_OID pnpOid, 28547836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 28557836SJohn.Forte@Sun.COM ) 28567836SJohn.Forte@Sun.COM { 28577836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 28587836SJohn.Forte@Sun.COM } 28597836SJohn.Forte@Sun.COM 28607836SJohn.Forte@Sun.COM /* ARGSUSED */ 28617836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetNetworkPortalProperties( 28627836SJohn.Forte@Sun.COM IMA_OID networkPortalOid, 28637836SJohn.Forte@Sun.COM IMA_NETWORK_PORTAL_PROPERTIES *pProps 28647836SJohn.Forte@Sun.COM ) 28657836SJohn.Forte@Sun.COM { 28667836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 28677836SJohn.Forte@Sun.COM } 28687836SJohn.Forte@Sun.COM 28697836SJohn.Forte@Sun.COM /* ARGSUSED */ 28707836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_SetNetworkPortalIpAddress( 28717836SJohn.Forte@Sun.COM IMA_OID networkPortalOid, 28727836SJohn.Forte@Sun.COM const IMA_IP_ADDRESS NewIpAddress 28737836SJohn.Forte@Sun.COM ) 28747836SJohn.Forte@Sun.COM { 28757836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 28767836SJohn.Forte@Sun.COM } 28777836SJohn.Forte@Sun.COM 28787836SJohn.Forte@Sun.COM /* ARGSUSED */ 28797836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_RemoveStaleData( 28807836SJohn.Forte@Sun.COM IMA_OID lhbaOid 28817836SJohn.Forte@Sun.COM ) 28827836SJohn.Forte@Sun.COM { 28837836SJohn.Forte@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 28847836SJohn.Forte@Sun.COM } 28857836SJohn.Forte@Sun.COM 28867836SJohn.Forte@Sun.COM /* ARGSUSED */ 28877836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetIpsecProperties( 28887836SJohn.Forte@Sun.COM IMA_OID oid, 28897836SJohn.Forte@Sun.COM IMA_IPSEC_PROPERTIES *pProps 28907836SJohn.Forte@Sun.COM ) 28917836SJohn.Forte@Sun.COM { 28927836SJohn.Forte@Sun.COM pProps->ipsecSupported = IMA_TRUE; 28937836SJohn.Forte@Sun.COM pProps->implementedInHardware = IMA_FALSE; 28947836SJohn.Forte@Sun.COM pProps->implementedInSoftware = IMA_TRUE; 28957836SJohn.Forte@Sun.COM 28967836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 28977836SJohn.Forte@Sun.COM } 28987836SJohn.Forte@Sun.COM 28997836SJohn.Forte@Sun.COM /* ARGSUSED */ 29007836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLhbaProperties( 29017836SJohn.Forte@Sun.COM IMA_OID lhbaOid, 29027836SJohn.Forte@Sun.COM IMA_LHBA_PROPERTIES *pProps 29037836SJohn.Forte@Sun.COM ) 29047836SJohn.Forte@Sun.COM { 29057836SJohn.Forte@Sun.COM 29067836SJohn.Forte@Sun.COM if (pProps == NULL) { 29077836SJohn.Forte@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 29087836SJohn.Forte@Sun.COM } 29097836SJohn.Forte@Sun.COM 29107836SJohn.Forte@Sun.COM if (lhbaObjectId.objectSequenceNumber != ISCSI_INITIATOR_OID) { 29117836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 29127836SJohn.Forte@Sun.COM } 29137836SJohn.Forte@Sun.COM 29147836SJohn.Forte@Sun.COM (void) memset(pProps, 0, sizeof (IMA_LHBA_PROPERTIES)); 29157836SJohn.Forte@Sun.COM (void) mbstowcs(pProps->osDeviceName, OS_DEVICE_NAME, 29167836SJohn.Forte@Sun.COM OS_DEVICE_NAME_LEN); 29177836SJohn.Forte@Sun.COM pProps->luExposingSupported = IMA_FALSE; 29187836SJohn.Forte@Sun.COM pProps->isDestroyable = IMA_FALSE; 29197836SJohn.Forte@Sun.COM pProps->staleDataRemovable = IMA_FALSE; 29207836SJohn.Forte@Sun.COM pProps->staleDataSize = 0; 29217836SJohn.Forte@Sun.COM pProps->initiatorAuthMethodsSettable = IMA_TRUE; 29227836SJohn.Forte@Sun.COM pProps->targetAuthMethodsSettable = IMA_FALSE; 29237836SJohn.Forte@Sun.COM 29247836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 29257836SJohn.Forte@Sun.COM } 29267836SJohn.Forte@Sun.COM 29277836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLnpOidList( 29287836SJohn.Forte@Sun.COM IMA_OID_LIST **ppList 29297836SJohn.Forte@Sun.COM ) 29307836SJohn.Forte@Sun.COM { 29317836SJohn.Forte@Sun.COM *ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST))); 29327836SJohn.Forte@Sun.COM if (*ppList == NULL) { 29337836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 29347836SJohn.Forte@Sun.COM } 29357836SJohn.Forte@Sun.COM (*ppList)->oidCount = 0; 29367836SJohn.Forte@Sun.COM 29377836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 29387836SJohn.Forte@Sun.COM } 29397836SJohn.Forte@Sun.COM 29407836SJohn.Forte@Sun.COM /* ARGSUSED */ 29417836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetLnpProperties( 29427836SJohn.Forte@Sun.COM IMA_OID lnpOid, 29437836SJohn.Forte@Sun.COM IMA_LNP_PROPERTIES *pProps 29447836SJohn.Forte@Sun.COM ) 29457836SJohn.Forte@Sun.COM { 29467836SJohn.Forte@Sun.COM return (IMA_ERROR_OBJECT_NOT_FOUND); 29477836SJohn.Forte@Sun.COM } 29487836SJohn.Forte@Sun.COM 29497836SJohn.Forte@Sun.COM #define IMA_DISK_DEVICE_NAME_PREFIX "/dev/rdsk/" 29507836SJohn.Forte@Sun.COM #define IMA_TAPE_DEVICE_NAME_PREFIX "/dev/rmt/" 29517836SJohn.Forte@Sun.COM static int 29527836SJohn.Forte@Sun.COM get_lun_devlink(di_devlink_t link, void *osDeviceName) 29537836SJohn.Forte@Sun.COM { 29547836SJohn.Forte@Sun.COM if ((strncmp(IMA_DISK_DEVICE_NAME_PREFIX, di_devlink_path(link), 29557836SJohn.Forte@Sun.COM strlen(IMA_DISK_DEVICE_NAME_PREFIX)) == 0) || 29567836SJohn.Forte@Sun.COM (strncmp(IMA_TAPE_DEVICE_NAME_PREFIX, di_devlink_path(link), 29577836SJohn.Forte@Sun.COM strlen(IMA_TAPE_DEVICE_NAME_PREFIX)) == 0)) { 29587836SJohn.Forte@Sun.COM (void) mbstowcs((wchar_t *)osDeviceName, di_devlink_path(link), 29597836SJohn.Forte@Sun.COM MAXPATHLEN); 29607836SJohn.Forte@Sun.COM return (DI_WALK_TERMINATE); 29617836SJohn.Forte@Sun.COM } 29627836SJohn.Forte@Sun.COM 29637836SJohn.Forte@Sun.COM return (DI_WALK_CONTINUE); 29647836SJohn.Forte@Sun.COM } 29657836SJohn.Forte@Sun.COM 29667836SJohn.Forte@Sun.COM /* ARGSUSED */ 29677836SJohn.Forte@Sun.COM IMA_API IMA_STATUS IMA_GetPluginProperties( 29687836SJohn.Forte@Sun.COM IMA_OID pluginOid, 29697836SJohn.Forte@Sun.COM IMA_PLUGIN_PROPERTIES *pProps 29707836SJohn.Forte@Sun.COM ) 29717836SJohn.Forte@Sun.COM { 29727836SJohn.Forte@Sun.COM pProps->supportedImaVersion = 1; 29737836SJohn.Forte@Sun.COM libSwprintf(pProps->vendor, L"%ls", LIBRARY_PROPERTY_VENDOR); 29747836SJohn.Forte@Sun.COM libSwprintf(pProps->implementationVersion, L"%ls", 29757836SJohn.Forte@Sun.COM LIBRARY_PROPERTY_IMPLEMENTATION_VERSION); 29767836SJohn.Forte@Sun.COM libSwprintf(pProps->fileName, L"%ls", LIBRARY_FILE_NAME); 29777836SJohn.Forte@Sun.COM GetBuildTime(&(pProps->buildTime)); 29787836SJohn.Forte@Sun.COM pProps->lhbasCanBeCreatedAndDestroyed = IMA_FALSE; 29797836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 29807836SJohn.Forte@Sun.COM } 29817836SJohn.Forte@Sun.COM 29827836SJohn.Forte@Sun.COM IMA_STATUS getDiscoveryAddressPropertiesList( 29837836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDR_PROP_LIST **ppList 29847836SJohn.Forte@Sun.COM ) 29857836SJohn.Forte@Sun.COM { 29867836SJohn.Forte@Sun.COM int fd; 29877836SJohn.Forte@Sun.COM int i; 29887836SJohn.Forte@Sun.COM int discovery_addr_list_size; 29897836SJohn.Forte@Sun.COM iscsi_addr_list_t *ialp, al_info; 29907836SJohn.Forte@Sun.COM 29917836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 29927836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 29937836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 29947836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 29957836SJohn.Forte@Sun.COM } 29967836SJohn.Forte@Sun.COM 29977836SJohn.Forte@Sun.COM (void) memset(&al_info, 0, sizeof (al_info)); 29987836SJohn.Forte@Sun.COM al_info.al_vers = ISCSI_INTERFACE_VERSION; 29997836SJohn.Forte@Sun.COM al_info.al_in_cnt = 0; 30007836SJohn.Forte@Sun.COM 30017836SJohn.Forte@Sun.COM /* 30027836SJohn.Forte@Sun.COM * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl to obtain the number of 30037836SJohn.Forte@Sun.COM * discovery addresses. 30047836SJohn.Forte@Sun.COM */ 30057836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) { 30067836SJohn.Forte@Sun.COM (void) close(fd); 30077836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 30087836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d", 30097836SJohn.Forte@Sun.COM errno); 30107836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30117836SJohn.Forte@Sun.COM } 30127836SJohn.Forte@Sun.COM 30137836SJohn.Forte@Sun.COM discovery_addr_list_size = sizeof (iscsi_addr_list_t); 30147836SJohn.Forte@Sun.COM if (al_info.al_out_cnt > 1) { 30157836SJohn.Forte@Sun.COM discovery_addr_list_size += (sizeof (iscsi_addr_t) * 30167836SJohn.Forte@Sun.COM al_info.al_out_cnt - 1); 30177836SJohn.Forte@Sun.COM } 30187836SJohn.Forte@Sun.COM 30197836SJohn.Forte@Sun.COM ialp = (iscsi_addr_list_t *)calloc(1, discovery_addr_list_size); 30207836SJohn.Forte@Sun.COM if (ialp == NULL) { 30217836SJohn.Forte@Sun.COM (void) close(fd); 30227836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 30237836SJohn.Forte@Sun.COM } 30247836SJohn.Forte@Sun.COM ialp->al_vers = ISCSI_INTERFACE_VERSION; 30257836SJohn.Forte@Sun.COM ialp->al_in_cnt = al_info.al_out_cnt; 30267836SJohn.Forte@Sun.COM 30277836SJohn.Forte@Sun.COM /* 30287836SJohn.Forte@Sun.COM * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl again to obtain the 30297836SJohn.Forte@Sun.COM * discovery addresses. 30307836SJohn.Forte@Sun.COM */ 30317836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, ialp) != 0) { 30327836SJohn.Forte@Sun.COM free(ialp); 30337836SJohn.Forte@Sun.COM (void) close(fd); 30347836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 30357836SJohn.Forte@Sun.COM "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d", 30367836SJohn.Forte@Sun.COM errno); 30377836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30387836SJohn.Forte@Sun.COM } 30397836SJohn.Forte@Sun.COM 30407836SJohn.Forte@Sun.COM *ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *) 30417836SJohn.Forte@Sun.COM calloc(1, sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) + 30427836SJohn.Forte@Sun.COM ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES)); 30437836SJohn.Forte@Sun.COM 30447836SJohn.Forte@Sun.COM if (*ppList == NULL) { 30457836SJohn.Forte@Sun.COM free(ialp); 30467836SJohn.Forte@Sun.COM (void) close(fd); 30477836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 30487836SJohn.Forte@Sun.COM } 30497836SJohn.Forte@Sun.COM (*ppList)->discAddrCount = ialp->al_out_cnt; 30507836SJohn.Forte@Sun.COM 30517836SJohn.Forte@Sun.COM for (i = 0; i < ialp->al_out_cnt; i++) { 30527836SJohn.Forte@Sun.COM if (ialp->al_addrs[i].a_addr.i_insize == 30537836SJohn.Forte@Sun.COM sizeof (struct in_addr)) { 30547836SJohn.Forte@Sun.COM (*ppList)->props[i].discoveryAddress.hostnameIpAddress. 30557836SJohn.Forte@Sun.COM id.ipAddress.ipv4Address = IMA_TRUE; 30567836SJohn.Forte@Sun.COM } else if (ialp->al_addrs[i].a_addr.i_insize == 30577836SJohn.Forte@Sun.COM sizeof (struct in6_addr)) { 30587836SJohn.Forte@Sun.COM (*ppList)->props[i].discoveryAddress. 30597836SJohn.Forte@Sun.COM hostnameIpAddress.id.ipAddress.ipv4Address = IMA_FALSE; 30607836SJohn.Forte@Sun.COM } else { 30617836SJohn.Forte@Sun.COM /* Should not happen */ 30627836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 30637836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 30647836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 30657836SJohn.Forte@Sun.COM } 30667836SJohn.Forte@Sun.COM 30677836SJohn.Forte@Sun.COM bcopy(&ialp->al_addrs[i].a_addr.i_addr, (*ppList)->props[i]. 30687836SJohn.Forte@Sun.COM discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress, 30697836SJohn.Forte@Sun.COM sizeof ((*ppList)->props[i].discoveryAddress. 30707836SJohn.Forte@Sun.COM hostnameIpAddress.id.ipAddress.ipAddress)); 30717836SJohn.Forte@Sun.COM 30727836SJohn.Forte@Sun.COM (*ppList)->props[i].discoveryAddress.portNumber = 30737836SJohn.Forte@Sun.COM ialp->al_addrs[i].a_port; 30747836SJohn.Forte@Sun.COM } 30757836SJohn.Forte@Sun.COM 30767836SJohn.Forte@Sun.COM free(ialp); 30777836SJohn.Forte@Sun.COM (void) close(fd); 30787836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 30797836SJohn.Forte@Sun.COM } 30807836SJohn.Forte@Sun.COM 30817836SJohn.Forte@Sun.COM 30827836SJohn.Forte@Sun.COM /* ARGSUSED */ 30837836SJohn.Forte@Sun.COM IMA_STATUS sendTargets( 30847836SJohn.Forte@Sun.COM IMA_TARGET_ADDRESS address, 30857836SJohn.Forte@Sun.COM SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList 30867836SJohn.Forte@Sun.COM ) 30877836SJohn.Forte@Sun.COM { 30887836SJohn.Forte@Sun.COM char *colonPos; 30897836SJohn.Forte@Sun.COM char discAddrStr[SUN_IMA_IP_ADDRESS_LEN]; 30907836SJohn.Forte@Sun.COM int fd; 30917836SJohn.Forte@Sun.COM int ctr; 30927836SJohn.Forte@Sun.COM int stl_sz; 30937836SJohn.Forte@Sun.COM iscsi_sendtgts_list_t *stl_hdr = NULL; 30947836SJohn.Forte@Sun.COM IMA_BOOL retry = IMA_TRUE; 30957836SJohn.Forte@Sun.COM 30967836SJohn.Forte@Sun.COM #define SENDTGTS_DEFAULT_NUM_TARGETS 10 30977836SJohn.Forte@Sun.COM 30987836SJohn.Forte@Sun.COM stl_sz = sizeof (*stl_hdr) + ((SENDTGTS_DEFAULT_NUM_TARGETS - 1) * 30997836SJohn.Forte@Sun.COM sizeof (iscsi_sendtgts_entry_t)); 31007836SJohn.Forte@Sun.COM stl_hdr = (iscsi_sendtgts_list_t *)calloc(1, stl_sz); 31017836SJohn.Forte@Sun.COM if (stl_hdr == NULL) { 31027836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 31037836SJohn.Forte@Sun.COM } 31047836SJohn.Forte@Sun.COM stl_hdr->stl_entry.e_vers = ISCSI_INTERFACE_VERSION; 31057836SJohn.Forte@Sun.COM stl_hdr->stl_in_cnt = SENDTGTS_DEFAULT_NUM_TARGETS; 31067836SJohn.Forte@Sun.COM 31077836SJohn.Forte@Sun.COM colonPos = strchr(discAddrStr, ':'); 31087836SJohn.Forte@Sun.COM if (colonPos == NULL) { 31097836SJohn.Forte@Sun.COM /* IPv4 */ 31107836SJohn.Forte@Sun.COM stl_hdr->stl_entry.e_insize = sizeof (struct in_addr); 31117836SJohn.Forte@Sun.COM } else { 31127836SJohn.Forte@Sun.COM /* IPv6 */ 31137836SJohn.Forte@Sun.COM stl_hdr->stl_entry.e_insize = sizeof (struct in6_addr); 31147836SJohn.Forte@Sun.COM } 31157836SJohn.Forte@Sun.COM 31167836SJohn.Forte@Sun.COM 31177836SJohn.Forte@Sun.COM bcopy(address.hostnameIpAddress.id.ipAddress.ipAddress, 31187836SJohn.Forte@Sun.COM &stl_hdr->stl_entry.e_u, 31197836SJohn.Forte@Sun.COM sizeof (address.hostnameIpAddress.id.ipAddress.ipAddress)); 31207836SJohn.Forte@Sun.COM stl_hdr->stl_entry.e_port = address.portNumber; 31217836SJohn.Forte@Sun.COM 31227836SJohn.Forte@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 31237836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 31247836SJohn.Forte@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 31257836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31267836SJohn.Forte@Sun.COM } 31277836SJohn.Forte@Sun.COM 31287836SJohn.Forte@Sun.COM retry_sendtgts: 31297836SJohn.Forte@Sun.COM /* 31307836SJohn.Forte@Sun.COM * Issue ioctl to obtain the SendTargets list 31317836SJohn.Forte@Sun.COM */ 31327836SJohn.Forte@Sun.COM if (ioctl(fd, ISCSI_SENDTGTS_GET, stl_hdr) != 0) { 31337836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 31347836SJohn.Forte@Sun.COM "ISCSI_SENDTGTS_GET ioctl failed, errno: %d", errno); 31357836SJohn.Forte@Sun.COM (void) close(fd); 31367836SJohn.Forte@Sun.COM free(stl_hdr); 31377836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 31387836SJohn.Forte@Sun.COM } 31397836SJohn.Forte@Sun.COM 31407836SJohn.Forte@Sun.COM /* check if all targets received */ 31417836SJohn.Forte@Sun.COM if (stl_hdr->stl_in_cnt < stl_hdr->stl_out_cnt) { 31427836SJohn.Forte@Sun.COM if (retry == IMA_TRUE) { 31437836SJohn.Forte@Sun.COM stl_sz = sizeof (*stl_hdr) + 31447836SJohn.Forte@Sun.COM ((stl_hdr->stl_out_cnt - 1) * 31457836SJohn.Forte@Sun.COM sizeof (iscsi_sendtgts_entry_t)); 31467836SJohn.Forte@Sun.COM stl_hdr = (iscsi_sendtgts_list_t *) 31477836SJohn.Forte@Sun.COM realloc(stl_hdr, stl_sz); 31487836SJohn.Forte@Sun.COM if (stl_hdr == NULL) { 31497836SJohn.Forte@Sun.COM (void) close(fd); 31507836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 31517836SJohn.Forte@Sun.COM } 31527836SJohn.Forte@Sun.COM stl_hdr->stl_in_cnt = stl_hdr->stl_out_cnt; 31537836SJohn.Forte@Sun.COM retry = IMA_FALSE; 31547836SJohn.Forte@Sun.COM goto retry_sendtgts; 31557836SJohn.Forte@Sun.COM } else { 31567836SJohn.Forte@Sun.COM /* 31577836SJohn.Forte@Sun.COM * don't retry after 2 attempts. The target list 31587836SJohn.Forte@Sun.COM * shouldn't continue to growing. Justs continue 31597836SJohn.Forte@Sun.COM * on and display what was found. 31607836SJohn.Forte@Sun.COM */ 31617836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 31627836SJohn.Forte@Sun.COM "ISCSI_SENDTGTS_GET overflow: " 31637836SJohn.Forte@Sun.COM "failed to obtain all targets"); 31647836SJohn.Forte@Sun.COM stl_hdr->stl_out_cnt = stl_hdr->stl_in_cnt; 31657836SJohn.Forte@Sun.COM } 31667836SJohn.Forte@Sun.COM } 31677836SJohn.Forte@Sun.COM 31687836SJohn.Forte@Sun.COM (void) close(fd); 31697836SJohn.Forte@Sun.COM 31707836SJohn.Forte@Sun.COM /* allocate for caller return buffer */ 31717836SJohn.Forte@Sun.COM *ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1, 31727836SJohn.Forte@Sun.COM sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) + 31737836SJohn.Forte@Sun.COM stl_hdr->stl_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY)); 31747836SJohn.Forte@Sun.COM if (*ppList == NULL) { 31757836SJohn.Forte@Sun.COM free(stl_hdr); 31767836SJohn.Forte@Sun.COM return (IMA_ERROR_INSUFFICIENT_MEMORY); 31777836SJohn.Forte@Sun.COM } 31787836SJohn.Forte@Sun.COM 31797836SJohn.Forte@Sun.COM (*ppList)->keyCount = stl_hdr->stl_out_cnt; 31807836SJohn.Forte@Sun.COM 31817836SJohn.Forte@Sun.COM for (ctr = 0; ctr < stl_hdr->stl_out_cnt; ctr++) { 31827836SJohn.Forte@Sun.COM (void) mbstowcs((*ppList)->keys[ctr].name, 31837836SJohn.Forte@Sun.COM (char *)stl_hdr->stl_list[ctr].ste_name, 31847836SJohn.Forte@Sun.COM IMA_NODE_NAME_LEN); 31857836SJohn.Forte@Sun.COM 31867836SJohn.Forte@Sun.COM (*ppList)->keys[ctr].tpgt = stl_hdr->stl_list[ctr].ste_tpgt; 31877836SJohn.Forte@Sun.COM 31887836SJohn.Forte@Sun.COM (*ppList)->keys[ctr].address.portNumber = 31897836SJohn.Forte@Sun.COM stl_hdr->stl_list[ctr].ste_ipaddr.a_port; 31907836SJohn.Forte@Sun.COM 31917836SJohn.Forte@Sun.COM if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize == 31927836SJohn.Forte@Sun.COM sizeof (struct in_addr)) { 31937836SJohn.Forte@Sun.COM (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 31947836SJohn.Forte@Sun.COM IMA_TRUE; 31957836SJohn.Forte@Sun.COM } else if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize == 31967836SJohn.Forte@Sun.COM sizeof (struct in6_addr)) { 31977836SJohn.Forte@Sun.COM (*ppList)->keys[ctr].address.ipAddress.ipv4Address = 31987836SJohn.Forte@Sun.COM IMA_FALSE; 31997836SJohn.Forte@Sun.COM } else { 32007836SJohn.Forte@Sun.COM free(stl_hdr); 32017836SJohn.Forte@Sun.COM syslog(LOG_USER|LOG_DEBUG, 32027836SJohn.Forte@Sun.COM "ISCSI_STATIC_GET returned bad address"); 32037836SJohn.Forte@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 32047836SJohn.Forte@Sun.COM } 32057836SJohn.Forte@Sun.COM 32067836SJohn.Forte@Sun.COM 32077836SJohn.Forte@Sun.COM (void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress, 32087836SJohn.Forte@Sun.COM &(stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_addr), 32097836SJohn.Forte@Sun.COM stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize); 32107836SJohn.Forte@Sun.COM } 32117836SJohn.Forte@Sun.COM free(stl_hdr); 32127836SJohn.Forte@Sun.COM 32137836SJohn.Forte@Sun.COM return (IMA_STATUS_SUCCESS); 32147836SJohn.Forte@Sun.COM } 3215*10156SZhang.Yi@Sun.COM 3216*10156SZhang.Yi@Sun.COM IMA_API IMA_STATUS SUN_IMA_GetTunableProperties( 3217*10156SZhang.Yi@Sun.COM IMA_OID oid, 3218*10156SZhang.Yi@Sun.COM ISCSI_TUNABLE_PARAM *param) 3219*10156SZhang.Yi@Sun.COM { 3220*10156SZhang.Yi@Sun.COM int fd; 3221*10156SZhang.Yi@Sun.COM iscsi_tunable_object_t pg; 3222*10156SZhang.Yi@Sun.COM 3223*10156SZhang.Yi@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3224*10156SZhang.Yi@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 3225*10156SZhang.Yi@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 3226*10156SZhang.Yi@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3227*10156SZhang.Yi@Sun.COM } 3228*10156SZhang.Yi@Sun.COM (void) memset(&pg, 0, sizeof (iscsi_tunable_object_t)); 3229*10156SZhang.Yi@Sun.COM pg.t_param = param->tunable_objectType; 3230*10156SZhang.Yi@Sun.COM pg.t_oid = (uint32_t)oid.objectSequenceNumber; 3231*10156SZhang.Yi@Sun.COM if (ioctl(fd, ISCSI_TUNABLE_PARAM_GET, &pg) == -1) { 3232*10156SZhang.Yi@Sun.COM syslog(LOG_USER|LOG_DEBUG, 3233*10156SZhang.Yi@Sun.COM "ISCSI_TUNABLE_PARAM_GET ioctl failed, errno: %d", errno); 3234*10156SZhang.Yi@Sun.COM (void) close(fd); 3235*10156SZhang.Yi@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3236*10156SZhang.Yi@Sun.COM } else { 3237*10156SZhang.Yi@Sun.COM long long value; 3238*10156SZhang.Yi@Sun.COM char tmp[MAX_LONG_LONG_STRING_LEN], *ptr = NULL; 3239*10156SZhang.Yi@Sun.COM if (pg.t_set == B_FALSE) { 3240*10156SZhang.Yi@Sun.COM /* default value */ 3241*10156SZhang.Yi@Sun.COM (void) close(fd); 3242*10156SZhang.Yi@Sun.COM return (IMA_STATUS_SUCCESS); 3243*10156SZhang.Yi@Sun.COM } 3244*10156SZhang.Yi@Sun.COM value = (long long)pg.t_value.v_integer; 3245*10156SZhang.Yi@Sun.COM ptr = lltostr(value, tmp); 3246*10156SZhang.Yi@Sun.COM if ((ptr != NULL) && (ptr != tmp)) { 3247*10156SZhang.Yi@Sun.COM *(tmp + 1) = '\0'; 3248*10156SZhang.Yi@Sun.COM } else { 3249*10156SZhang.Yi@Sun.COM (void) close(fd); 3250*10156SZhang.Yi@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3251*10156SZhang.Yi@Sun.COM } 3252*10156SZhang.Yi@Sun.COM switch (param->tunable_objectType) { 3253*10156SZhang.Yi@Sun.COM case ISCSI_RX_TIMEOUT_VALUE: 3254*10156SZhang.Yi@Sun.COM (void) strlcpy(param->tunable_objectValue, 3255*10156SZhang.Yi@Sun.COM ptr, strlen(ptr)); 3256*10156SZhang.Yi@Sun.COM break; 3257*10156SZhang.Yi@Sun.COM case ISCSI_CONN_DEFAULT_LOGIN_MAX: 3258*10156SZhang.Yi@Sun.COM (void) strlcpy(param->tunable_objectValue, 3259*10156SZhang.Yi@Sun.COM ptr, strlen(ptr)); 3260*10156SZhang.Yi@Sun.COM break; 3261*10156SZhang.Yi@Sun.COM case ISCSI_LOGIN_POLLING_DELAY: 3262*10156SZhang.Yi@Sun.COM (void) strlcpy(param->tunable_objectValue, 3263*10156SZhang.Yi@Sun.COM ptr, strlen(ptr)); 3264*10156SZhang.Yi@Sun.COM break; 3265*10156SZhang.Yi@Sun.COM default: 3266*10156SZhang.Yi@Sun.COM break; 3267*10156SZhang.Yi@Sun.COM } 3268*10156SZhang.Yi@Sun.COM } 3269*10156SZhang.Yi@Sun.COM (void) close(fd); 3270*10156SZhang.Yi@Sun.COM return (IMA_STATUS_SUCCESS); 3271*10156SZhang.Yi@Sun.COM } 3272*10156SZhang.Yi@Sun.COM 3273*10156SZhang.Yi@Sun.COM IMA_API IMA_STATUS SUN_IMA_SetTunableProperties( 3274*10156SZhang.Yi@Sun.COM IMA_OID oid, 3275*10156SZhang.Yi@Sun.COM ISCSI_TUNABLE_PARAM *param) 3276*10156SZhang.Yi@Sun.COM { 3277*10156SZhang.Yi@Sun.COM int fd; 3278*10156SZhang.Yi@Sun.COM iscsi_tunable_object_t ps; 3279*10156SZhang.Yi@Sun.COM 3280*10156SZhang.Yi@Sun.COM if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) { 3281*10156SZhang.Yi@Sun.COM syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)", 3282*10156SZhang.Yi@Sun.COM ISCSI_DRIVER_DEVCTL, errno); 3283*10156SZhang.Yi@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3284*10156SZhang.Yi@Sun.COM } 3285*10156SZhang.Yi@Sun.COM 3286*10156SZhang.Yi@Sun.COM (void) memset(&ps, 0, sizeof (iscsi_tunable_object_t)); 3287*10156SZhang.Yi@Sun.COM ps.t_oid = oid.objectSequenceNumber; 3288*10156SZhang.Yi@Sun.COM ps.t_param = param->tunable_objectType; 3289*10156SZhang.Yi@Sun.COM switch (param->tunable_objectType) { 3290*10156SZhang.Yi@Sun.COM long tmp; 3291*10156SZhang.Yi@Sun.COM case ISCSI_RX_TIMEOUT_VALUE: 3292*10156SZhang.Yi@Sun.COM case ISCSI_CONN_DEFAULT_LOGIN_MAX: 3293*10156SZhang.Yi@Sun.COM case ISCSI_LOGIN_POLLING_DELAY: 3294*10156SZhang.Yi@Sun.COM tmp = strtol(param->tunable_objectValue, 3295*10156SZhang.Yi@Sun.COM NULL, 10); 3296*10156SZhang.Yi@Sun.COM if (((tmp == 0) && (errno == EINVAL)) || 3297*10156SZhang.Yi@Sun.COM ((tmp == LONG_MAX) && (errno == ERANGE)) || 3298*10156SZhang.Yi@Sun.COM ((tmp == LONG_MIN) && (errno == ERANGE))) { 3299*10156SZhang.Yi@Sun.COM (void) close(fd); 3300*10156SZhang.Yi@Sun.COM return (IMA_ERROR_INVALID_PARAMETER); 3301*10156SZhang.Yi@Sun.COM } 3302*10156SZhang.Yi@Sun.COM ps.t_value.v_integer = (uint32_t)tmp; 3303*10156SZhang.Yi@Sun.COM break; 3304*10156SZhang.Yi@Sun.COM default: 3305*10156SZhang.Yi@Sun.COM break; 3306*10156SZhang.Yi@Sun.COM } 3307*10156SZhang.Yi@Sun.COM if (ioctl(fd, ISCSI_TUNABLE_PARAM_SET, &ps)) { 3308*10156SZhang.Yi@Sun.COM int tmpErrno = errno; 3309*10156SZhang.Yi@Sun.COM syslog(LOG_USER|LOG_DEBUG, 3310*10156SZhang.Yi@Sun.COM "ISCSI_TUNABLE_PARAM_SET ioctl failed, errno: %d", errno); 3311*10156SZhang.Yi@Sun.COM (void) close(fd); 3312*10156SZhang.Yi@Sun.COM switch (tmpErrno) { 3313*10156SZhang.Yi@Sun.COM case ENOTSUP : 3314*10156SZhang.Yi@Sun.COM return (IMA_ERROR_NOT_SUPPORTED); 3315*10156SZhang.Yi@Sun.COM default: 3316*10156SZhang.Yi@Sun.COM return (IMA_ERROR_UNEXPECTED_OS_ERROR); 3317*10156SZhang.Yi@Sun.COM } 3318*10156SZhang.Yi@Sun.COM } 3319*10156SZhang.Yi@Sun.COM (void) close(fd); 3320*10156SZhang.Yi@Sun.COM return (IMA_STATUS_SUCCESS); 3321*10156SZhang.Yi@Sun.COM } 3322