xref: /titanic_41/usr/src/lib/libsun_ima/common/ima.c (revision 2c2d21e98a95cba5687ec6574c974a5c6c4a6adb)
1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte /*
221a1a84a3SPeter Dunlap  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce44SJohn Forte  * Use is subject to license terms.
24fcf3ce44SJohn Forte  */
25fcf3ce44SJohn Forte 
26fcf3ce44SJohn Forte #include <arpa/inet.h>
27fcf3ce44SJohn Forte #include <sys/socket.h>
28fcf3ce44SJohn Forte #include <sys/types.h>
29fcf3ce44SJohn Forte #include <stdarg.h>
30fcf3ce44SJohn Forte #include <stdlib.h>
31fcf3ce44SJohn Forte #include <string.h>
32fcf3ce44SJohn Forte #include <strings.h>
33fcf3ce44SJohn Forte #include <unistd.h>
34fcf3ce44SJohn Forte #include <syslog.h>
35fcf3ce44SJohn Forte #include <errno.h>
36fcf3ce44SJohn Forte #include <wchar.h>
37fcf3ce44SJohn Forte #include <widec.h>
38fcf3ce44SJohn Forte #include <libsysevent.h>
39fcf3ce44SJohn Forte #include <sys/nvpair.h>
40fcf3ce44SJohn Forte #include <fcntl.h>
41fcf3ce44SJohn Forte #include <stdio.h>
42fcf3ce44SJohn Forte #include <time.h>
43fcf3ce44SJohn Forte #include <libdevinfo.h>
44146832dbSMilos Muzik #include <sys/scsi/generic/commands.h>
45146832dbSMilos Muzik #include <sys/scsi/generic/status.h>
46fcf3ce44SJohn Forte #include <sys/scsi/adapters/iscsi_if.h>
471a1a84a3SPeter Dunlap #include <sys/iscsi_protocol.h>
48fcf3ce44SJohn Forte #include <ima.h>
49aff4bce5Syi zhang - Sun Microsystems - Beijing China #include <libsun_ima.h>
50fcf3ce44SJohn Forte 
51fcf3ce44SJohn Forte #define	LIBRARY_PROPERTY_IMPLEMENTATION_VERSION	L"1.0.0"
52fcf3ce44SJohn Forte #define	LIBRARY_PROPERTY_VENDOR			L"Sun Microsystems, Inc."
53fcf3ce44SJohn Forte #define	OS_DEVICE_NAME 				"/devices/iscsi"
54fcf3ce44SJohn Forte #define	LIBRARY_FILE_NAME			L"libsun_ima.so"
55fcf3ce44SJohn Forte 
56fcf3ce44SJohn Forte #define	OS_DEVICE_NAME_LEN		256
57fcf3ce44SJohn Forte #define	USCSI_TIMEOUT_IN_SEC		10
58fcf3ce44SJohn Forte #define	MAX_AUTHMETHODS			10
59fcf3ce44SJohn Forte #define	NUM_SUPPORTED_AUTH_METHODS	2
60fcf3ce44SJohn Forte #define	SUN_IMA_MAX_DIGEST_ALGORITHMS	2	/* NONE and CRC 32 */
61fcf3ce44SJohn Forte #define	SUN_IMA_IP_ADDRESS_LEN		256
62fcf3ce44SJohn Forte #define	SUN_IMA_IP_PORT_LEN		64
63fcf3ce44SJohn Forte #define	SUN_IMA_MAX_RADIUS_SECRET_LEN	128
64aff4bce5Syi zhang - Sun Microsystems - Beijing China #define	MAX_LONG_LONG_STRING_LEN	10
65146832dbSMilos Muzik #define	MAX_INQUIRY_BUFFER_LEN		0xffff
66146832dbSMilos Muzik #define	MAX_REPORT_LUNS_BUFFER_LEN	0xffffffff
67146832dbSMilos Muzik #define	MAX_READ_CAPACITY16_BUFFER_LEN	0xffffffff
68fcf3ce44SJohn Forte 
69fcf3ce44SJohn Forte /* Forward declaration */
70fcf3ce44SJohn Forte #define	BOOL_PARAM			1
71fcf3ce44SJohn Forte #define	MIN_MAX_PARAM			2
72fcf3ce44SJohn Forte 
73fcf3ce44SJohn Forte /* OK */
74fcf3ce44SJohn Forte #define	DISC_ADDR_OK			0
75fcf3ce44SJohn Forte /* Incorrect IP address */
76fcf3ce44SJohn Forte #define	DISC_ADDR_INTEGRITY_ERROR   	1
77fcf3ce44SJohn Forte /* Error converting text IP address to numeric binary form */
78fcf3ce44SJohn Forte #define	DISC_ADDR_IP_CONV_ERROR		2
79fcf3ce44SJohn Forte 
80fcf3ce44SJohn Forte /* Currently not defined in  IMA_TARGET_DISCOVERY_METHOD enum */
81fcf3ce44SJohn Forte #define	IMA_TARGET_DISCOVERY_METHOD_UNKNOWN  0
82fcf3ce44SJohn Forte 
83fcf3ce44SJohn Forte static IMA_OID		lhbaObjectId;
84fcf3ce44SJohn Forte static IMA_UINT32	pluginOwnerId;
85fcf3ce44SJohn Forte static sysevent_handle_t *shp;
86fcf3ce44SJohn Forte 
87fcf3ce44SJohn Forte 
88fcf3ce44SJohn Forte 
89fcf3ce44SJohn Forte /*
90fcf3ce44SJohn Forte  * Custom struct to allow tgpt to be specified.
91fcf3ce44SJohn Forte  */
92fcf3ce44SJohn Forte typedef struct _SUN_IMA_DISC_ADDRESS_KEY
93fcf3ce44SJohn Forte {
94fcf3ce44SJohn Forte 	IMA_NODE_NAME name;
95fcf3ce44SJohn Forte 	IMA_ADDRESS_KEY	address;
96fcf3ce44SJohn Forte 	IMA_UINT16 tpgt;
97fcf3ce44SJohn Forte } SUN_IMA_DISC_ADDRESS_KEY;
98fcf3ce44SJohn Forte 
99fcf3ce44SJohn Forte /*
100fcf3ce44SJohn Forte  * Custom struct to allow tgpt to be specified.
101fcf3ce44SJohn Forte  */
102fcf3ce44SJohn Forte typedef struct _SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES
103fcf3ce44SJohn Forte {
104fcf3ce44SJohn Forte 	IMA_UINT keyCount;
105fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDRESS_KEY keys[1];
106fcf3ce44SJohn Forte } SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES;
107fcf3ce44SJohn Forte 
108fcf3ce44SJohn Forte /*
109fcf3ce44SJohn Forte  * Custom struct to allow tgpt to be specified.
110fcf3ce44SJohn Forte  */
111fcf3ce44SJohn Forte typedef struct _SUN_IMA_DISC_ADDR_PROP_LIST
112fcf3ce44SJohn Forte {
113fcf3ce44SJohn Forte 	IMA_UINT discAddrCount;
114fcf3ce44SJohn Forte 	IMA_DISCOVERY_ADDRESS_PROPERTIES props[1];
115fcf3ce44SJohn Forte } SUN_IMA_DISC_ADDR_PROP_LIST;
116fcf3ce44SJohn Forte 
117fcf3ce44SJohn Forte 
118fcf3ce44SJohn Forte static IMA_OBJECT_VISIBILITY_FN pObjectVisibilityCallback = NULL;
119fcf3ce44SJohn Forte static IMA_OBJECT_PROPERTY_FN pObjectPropertyCallback = NULL;
120fcf3ce44SJohn Forte 
121fcf3ce44SJohn Forte static IMA_STATUS getISCSINodeParameter(int paramType, IMA_OID *oid,
122fcf3ce44SJohn Forte     void *pProps, uint32_t paramIndex);
123fcf3ce44SJohn Forte static IMA_STATUS setISCSINodeParameter(int paramType, IMA_OID *oid,
124fcf3ce44SJohn Forte     void *pProps, uint32_t paramIndex);
125fcf3ce44SJohn Forte static IMA_STATUS setAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount,
126fcf3ce44SJohn Forte     const IMA_AUTHMETHOD *pMethodList);
127fcf3ce44SJohn Forte static IMA_STATUS getAuthMethods(IMA_OID oid, IMA_UINT *pMethodCount,
128fcf3ce44SJohn Forte     IMA_AUTHMETHOD *pMethodList);
129fcf3ce44SJohn Forte 
130fcf3ce44SJohn Forte static int prepare_discovery_entry(IMA_TARGET_ADDRESS discoveryAddress,
131fcf3ce44SJohn Forte     entry_t *entry);
132fcf3ce44SJohn Forte static IMA_STATUS configure_discovery_method(IMA_BOOL enable,
133fcf3ce44SJohn Forte     iSCSIDiscoveryMethod_t method);
134fcf3ce44SJohn Forte static IMA_STATUS get_target_oid_list(uint32_t targetListType,
135fcf3ce44SJohn Forte     IMA_OID_LIST **ppList);
136fcf3ce44SJohn Forte static IMA_STATUS get_target_lun_oid_list(IMA_OID * targetOid,
137fcf3ce44SJohn Forte 		iscsi_lun_list_t  **ppLunList);
138fcf3ce44SJohn Forte static int get_lun_devlink(di_devlink_t link, void *osDeviceName);
139fcf3ce44SJohn Forte static IMA_STATUS getDiscoveryAddressPropertiesList(
140fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDR_PROP_LIST **ppList
141fcf3ce44SJohn Forte );
142fcf3ce44SJohn Forte static IMA_STATUS sendTargets(IMA_TARGET_ADDRESS address,
143fcf3ce44SJohn Forte     SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList
144fcf3ce44SJohn Forte );
145fcf3ce44SJohn Forte 
146fcf3ce44SJohn Forte static IMA_STATUS getSupportedAuthMethods(IMA_OID lhbaOid,
147fcf3ce44SJohn Forte     IMA_BOOL getSettableMethods, IMA_UINT *pMethodCount,
148fcf3ce44SJohn Forte     IMA_AUTHMETHOD *pMethodList);
149fcf3ce44SJohn Forte static IMA_STATUS getLuProperties(IMA_OID luId, IMA_LU_PROPERTIES *pProps);
150fcf3ce44SJohn Forte static IMA_STATUS getTargetProperties(IMA_OID targetId,
151fcf3ce44SJohn Forte     IMA_TARGET_PROPERTIES *pProps);
152fcf3ce44SJohn Forte 
153fcf3ce44SJohn Forte void InitLibrary();
154fcf3ce44SJohn Forte 
libSwprintf(wchar_t * wcs,const wchar_t * lpszFormat,...)155fcf3ce44SJohn Forte static void libSwprintf(wchar_t *wcs, const wchar_t *lpszFormat, ...)
156fcf3ce44SJohn Forte {
157fcf3ce44SJohn Forte 	va_list args;
158fcf3ce44SJohn Forte 	va_start(args, lpszFormat);
159fcf3ce44SJohn Forte 	(void) vswprintf(wcs, OS_DEVICE_NAME_LEN - 1, lpszFormat, args);
160fcf3ce44SJohn Forte 	va_end(args);
161fcf3ce44SJohn Forte }
162fcf3ce44SJohn Forte 
163fcf3ce44SJohn Forte static void
sysevent_handler(sysevent_t * ev)164fcf3ce44SJohn Forte sysevent_handler(sysevent_t *ev)
165fcf3ce44SJohn Forte {
166fcf3ce44SJohn Forte 	IMA_OID tmpOid;
167fcf3ce44SJohn Forte 	IMA_BOOL becomingVisible = IMA_FALSE;
168fcf3ce44SJohn Forte 	IMA_UINT i;
169fcf3ce44SJohn Forte 
170fcf3ce44SJohn Forte 	const char *visibility_subclasses[] = {
171fcf3ce44SJohn Forte 		ESC_ISCSI_STATIC_START,
172fcf3ce44SJohn Forte 		ESC_ISCSI_STATIC_END,
173fcf3ce44SJohn Forte 		ESC_ISCSI_SEND_TARGETS_START,
174fcf3ce44SJohn Forte 		ESC_ISCSI_SEND_TARGETS_END,
175fcf3ce44SJohn Forte 		ESC_ISCSI_SLP_START,
176fcf3ce44SJohn Forte 		ESC_ISCSI_SLP_END,
177fcf3ce44SJohn Forte 		ESC_ISCSI_ISNS_START,
178fcf3ce44SJohn Forte 		ESC_ISCSI_ISNS_END,
179fcf3ce44SJohn Forte 		NULL
180fcf3ce44SJohn Forte 	};
181fcf3ce44SJohn Forte 
182fcf3ce44SJohn Forte 	tmpOid.ownerId = pluginOwnerId;
183fcf3ce44SJohn Forte 	tmpOid.objectType = IMA_OBJECT_TYPE_TARGET;
184fcf3ce44SJohn Forte 	tmpOid.objectSequenceNumber = 0;
185fcf3ce44SJohn Forte 
186fcf3ce44SJohn Forte 	/* Make sure our event class matches what we are looking for */
187fcf3ce44SJohn Forte 	if (strncmp(EC_ISCSI, sysevent_get_class_name(ev),
188fcf3ce44SJohn Forte 	    strlen(EC_ISCSI)) != 0) {
189fcf3ce44SJohn Forte 		return;
190fcf3ce44SJohn Forte 	}
191fcf3ce44SJohn Forte 
192fcf3ce44SJohn Forte 
193fcf3ce44SJohn Forte 	/* Check for object property changes */
194fcf3ce44SJohn Forte 	if ((strncmp(ESC_ISCSI_PROP_CHANGE,
195fcf3ce44SJohn Forte 	    sysevent_get_subclass_name(ev),
196fcf3ce44SJohn Forte 	    strlen(ESC_ISCSI_PROP_CHANGE)) == 0)) {
197fcf3ce44SJohn Forte 		if (pObjectPropertyCallback != NULL)
198fcf3ce44SJohn Forte 			pObjectPropertyCallback(tmpOid);
199fcf3ce44SJohn Forte 	} else {
200fcf3ce44SJohn Forte 		i = 0;
201fcf3ce44SJohn Forte 		while (visibility_subclasses[i] != NULL) {
202fcf3ce44SJohn Forte 			if ((strncmp(visibility_subclasses[i],
203fcf3ce44SJohn Forte 			    sysevent_get_subclass_name(ev),
204fcf3ce44SJohn Forte 			    strlen(visibility_subclasses[i])) == 0) &&
205fcf3ce44SJohn Forte 			    pObjectVisibilityCallback != NULL) {
206fcf3ce44SJohn Forte 				becomingVisible = IMA_TRUE;
207fcf3ce44SJohn Forte 				pObjectVisibilityCallback(becomingVisible,
208fcf3ce44SJohn Forte 				    tmpOid);
209fcf3ce44SJohn Forte 			}
210fcf3ce44SJohn Forte 			i++;
211fcf3ce44SJohn Forte 		}
212fcf3ce44SJohn Forte 	}
213fcf3ce44SJohn Forte }
214fcf3ce44SJohn Forte 
init_sysevents()215fcf3ce44SJohn Forte IMA_STATUS init_sysevents() {
216fcf3ce44SJohn Forte 	const char *subclass_list[] = {
217fcf3ce44SJohn Forte 		ESC_ISCSI_STATIC_START,
218fcf3ce44SJohn Forte 		ESC_ISCSI_STATIC_END,
219fcf3ce44SJohn Forte 		ESC_ISCSI_SEND_TARGETS_START,
220fcf3ce44SJohn Forte 		ESC_ISCSI_SEND_TARGETS_END,
221fcf3ce44SJohn Forte 		ESC_ISCSI_SLP_START,
222fcf3ce44SJohn Forte 		ESC_ISCSI_SLP_END,
223fcf3ce44SJohn Forte 		ESC_ISCSI_ISNS_START,
224fcf3ce44SJohn Forte 		ESC_ISCSI_ISNS_END,
225fcf3ce44SJohn Forte 		ESC_ISCSI_PROP_CHANGE,
226fcf3ce44SJohn Forte 	};
227fcf3ce44SJohn Forte 
228fcf3ce44SJohn Forte 	/* Bind event handler and create subscriber handle */
229fcf3ce44SJohn Forte 	shp = sysevent_bind_handle(sysevent_handler);
230fcf3ce44SJohn Forte 	if (shp == NULL) {
231fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
232fcf3ce44SJohn Forte 	}
233fcf3ce44SJohn Forte 
234fcf3ce44SJohn Forte 	if (sysevent_subscribe_event(shp, EC_ISCSI, subclass_list, 9) != 0) {
235fcf3ce44SJohn Forte 		sysevent_unbind_handle(shp);
236fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
237fcf3ce44SJohn Forte 	}
238fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
239fcf3ce44SJohn Forte }
240fcf3ce44SJohn Forte 
Initialize(IMA_UINT32 pluginOid)241fcf3ce44SJohn Forte IMA_STATUS Initialize(IMA_UINT32 pluginOid) {
242fcf3ce44SJohn Forte 	pluginOwnerId = pluginOid;
243fcf3ce44SJohn Forte 	return (init_sysevents());
244fcf3ce44SJohn Forte }
245fcf3ce44SJohn Forte 
Terminate()246fcf3ce44SJohn Forte void Terminate() {
247fcf3ce44SJohn Forte 	if (shp != NULL) {
248fcf3ce44SJohn Forte 		sysevent_unsubscribe_event(shp, EC_ISCSI);
249fcf3ce44SJohn Forte 	}
250fcf3ce44SJohn Forte 
251fcf3ce44SJohn Forte }
252fcf3ce44SJohn Forte 
InitLibrary()253fcf3ce44SJohn Forte void InitLibrary() {
254fcf3ce44SJohn Forte }
255fcf3ce44SJohn Forte 
GetBuildTime(IMA_DATETIME * pdatetime)256fcf3ce44SJohn Forte static void GetBuildTime(IMA_DATETIME* pdatetime)
257fcf3ce44SJohn Forte {
258fcf3ce44SJohn Forte 	(void) memset(pdatetime, 0, sizeof (IMA_DATETIME));
259fcf3ce44SJohn Forte }
260fcf3ce44SJohn Forte 
261fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetNodeProperties(IMA_OID nodeOid,IMA_NODE_PROPERTIES * pProps)262fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetNodeProperties(
263fcf3ce44SJohn Forte 	IMA_OID nodeOid,
264fcf3ce44SJohn Forte 	IMA_NODE_PROPERTIES *pProps
265fcf3ce44SJohn Forte )
266fcf3ce44SJohn Forte {
267fcf3ce44SJohn Forte 	int fd;
268fcf3ce44SJohn Forte 	iscsi_param_get_t pg;
269fcf3ce44SJohn Forte 
270fcf3ce44SJohn Forte 	pProps->runningInInitiatorMode = IMA_TRUE;
271fcf3ce44SJohn Forte 	pProps->runningInTargetMode = IMA_FALSE;
272fcf3ce44SJohn Forte 	pProps->nameAndAliasSettable = IMA_FALSE;
273fcf3ce44SJohn Forte 
274fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
275fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
276fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
277fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
278fcf3ce44SJohn Forte 	}
279fcf3ce44SJohn Forte 
280fcf3ce44SJohn Forte 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
281fcf3ce44SJohn Forte 	pg.g_vers = ISCSI_INTERFACE_VERSION;
282fcf3ce44SJohn Forte 	pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME;
283fcf3ce44SJohn Forte 
284fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) {
285fcf3ce44SJohn Forte 		pProps->nameValid = IMA_FALSE;
286fcf3ce44SJohn Forte 	} else {
287fcf3ce44SJohn Forte 		if (strlen((char *)pg.g_value.v_name) > 0) {
288fcf3ce44SJohn Forte 			(void) mbstowcs(pProps->name,
289fcf3ce44SJohn Forte 			    (char *)pg.g_value.v_name,
290fcf3ce44SJohn Forte 			    IMA_NODE_NAME_LEN);
291fcf3ce44SJohn Forte 			pProps->nameValid = IMA_TRUE;
292fcf3ce44SJohn Forte 		} else {
293fcf3ce44SJohn Forte 			pProps->nameValid = IMA_FALSE;
294fcf3ce44SJohn Forte 		}
295fcf3ce44SJohn Forte 	}
296fcf3ce44SJohn Forte 
297fcf3ce44SJohn Forte 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
298fcf3ce44SJohn Forte 	pg.g_vers = ISCSI_INTERFACE_VERSION;
299fcf3ce44SJohn Forte 	pg.g_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS;
300fcf3ce44SJohn Forte 	(void) memset(pProps->alias, 0,
301fcf3ce44SJohn Forte 	    sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN);
302fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) == -1) {
303fcf3ce44SJohn Forte 		pProps->aliasValid = IMA_FALSE;
304fcf3ce44SJohn Forte 	} else {
305fcf3ce44SJohn Forte 		if (strlen((char *)pg.g_value.v_name) > 0) {
306fcf3ce44SJohn Forte 			(void) mbstowcs(pProps->alias,
307fcf3ce44SJohn Forte 			    (char *)pg.g_value.v_name,
308fcf3ce44SJohn Forte 			    IMA_NODE_ALIAS_LEN);
309fcf3ce44SJohn Forte 			pProps->aliasValid = IMA_TRUE;
310fcf3ce44SJohn Forte 		}
311fcf3ce44SJohn Forte 	}
312fcf3ce44SJohn Forte 
313fcf3ce44SJohn Forte 	(void) close(fd);
314fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
315fcf3ce44SJohn Forte }
316fcf3ce44SJohn Forte 
IMA_SetNodeName(IMA_OID nodeOid,const IMA_NODE_NAME newName)317fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetNodeName(
318fcf3ce44SJohn Forte 	IMA_OID nodeOid,
319fcf3ce44SJohn Forte 	const IMA_NODE_NAME newName
320fcf3ce44SJohn Forte )
321fcf3ce44SJohn Forte {
322fcf3ce44SJohn Forte 	int fd;
323fcf3ce44SJohn Forte 	iscsi_param_set_t ps;
324fcf3ce44SJohn Forte 
325fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
326fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
327fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
328fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
329fcf3ce44SJohn Forte 	}
330fcf3ce44SJohn Forte 
331fcf3ce44SJohn Forte 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
332fcf3ce44SJohn Forte 	ps.s_oid = nodeOid.objectSequenceNumber;
333fcf3ce44SJohn Forte 	ps.s_vers = ISCSI_INTERFACE_VERSION;
334fcf3ce44SJohn Forte 	ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_NAME;
335fcf3ce44SJohn Forte 	(void) wcstombs((char *)ps.s_value.v_name, newName, ISCSI_MAX_NAME_LEN);
336fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_INIT_NODE_NAME_SET, &ps)) {
337fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
338fcf3ce44SJohn Forte 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
339fcf3ce44SJohn Forte 		(void) close(fd);
340fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
341fcf3ce44SJohn Forte 	}
342fcf3ce44SJohn Forte 
343fcf3ce44SJohn Forte 	(void) close(fd);
344fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
345fcf3ce44SJohn Forte }
346fcf3ce44SJohn Forte 
IMA_SetNodeAlias(IMA_OID nodeOid,const IMA_NODE_ALIAS newAlias)347fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetNodeAlias(
348fcf3ce44SJohn Forte 	IMA_OID nodeOid,
349fcf3ce44SJohn Forte 	const IMA_NODE_ALIAS newAlias
350fcf3ce44SJohn Forte )
351fcf3ce44SJohn Forte {
352fcf3ce44SJohn Forte 	int fd;
353fcf3ce44SJohn Forte 	iscsi_param_set_t ps;
354fcf3ce44SJohn Forte 
355fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
356fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
357fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
358fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
359fcf3ce44SJohn Forte 	}
360fcf3ce44SJohn Forte 
361fcf3ce44SJohn Forte 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
362fcf3ce44SJohn Forte 	ps.s_oid = nodeOid.objectSequenceNumber;
363fcf3ce44SJohn Forte 	ps.s_vers = ISCSI_INTERFACE_VERSION;
364fcf3ce44SJohn Forte 	ps.s_param = ISCSI_LOGIN_PARAM_INITIATOR_ALIAS;
365fcf3ce44SJohn Forte 
366fcf3ce44SJohn Forte 	/* newAlias = NULL specifies that the alias should be deleted. */
367fcf3ce44SJohn Forte 	if (newAlias != NULL)
368fcf3ce44SJohn Forte 		(void) wcstombs((char *)ps.s_value.v_name, newAlias,
369fcf3ce44SJohn Forte 		    ISCSI_MAX_NAME_LEN);
370fcf3ce44SJohn Forte 	else
371fcf3ce44SJohn Forte 		(void) wcstombs((char *)ps.s_value.v_name,
372fcf3ce44SJohn Forte 		    L"", ISCSI_MAX_NAME_LEN);
373fcf3ce44SJohn Forte 
374fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_PARAM_SET, &ps)) {
375fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
376fcf3ce44SJohn Forte 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
377fcf3ce44SJohn Forte 		(void) close(fd);
378fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
379fcf3ce44SJohn Forte 	}
380fcf3ce44SJohn Forte 
381fcf3ce44SJohn Forte 	(void) close(fd);
382fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
383fcf3ce44SJohn Forte }
384fcf3ce44SJohn Forte 
385fcf3ce44SJohn Forte 
IMA_GetLhbaOidList(IMA_OID_LIST ** ppList)386fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetLhbaOidList(
387fcf3ce44SJohn Forte 	IMA_OID_LIST **ppList
388fcf3ce44SJohn Forte )
389fcf3ce44SJohn Forte {
390fcf3ce44SJohn Forte 	/* Always return the same object ID for the lhba */
391fcf3ce44SJohn Forte 	lhbaObjectId.objectType = IMA_OBJECT_TYPE_LHBA;
392fcf3ce44SJohn Forte 	lhbaObjectId.ownerId = pluginOwnerId;
393fcf3ce44SJohn Forte 	lhbaObjectId.objectSequenceNumber = ISCSI_INITIATOR_OID;
394fcf3ce44SJohn Forte 
395fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST));
396fcf3ce44SJohn Forte 	if (*ppList == NULL) {
397fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
398fcf3ce44SJohn Forte 	}
399fcf3ce44SJohn Forte 
400fcf3ce44SJohn Forte 	(*ppList)->oidCount = 1;
401fcf3ce44SJohn Forte 	(void) memcpy(&(*ppList)->oids[0],
402fcf3ce44SJohn Forte 	    &lhbaObjectId, sizeof (lhbaObjectId));
403fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
404fcf3ce44SJohn Forte }
405fcf3ce44SJohn Forte 
406fcf3ce44SJohn Forte 
407fcf3ce44SJohn Forte /*
408fcf3ce44SJohn Forte  * Get the discovery properties of the LHBA
409fcf3ce44SJohn Forte  */
410fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetDiscoveryProperties(IMA_OID oid,IMA_DISCOVERY_PROPERTIES * pProps)411fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetDiscoveryProperties(
412fcf3ce44SJohn Forte 	IMA_OID oid,
413fcf3ce44SJohn Forte 	IMA_DISCOVERY_PROPERTIES *pProps
414fcf3ce44SJohn Forte )
415fcf3ce44SJohn Forte {
416fcf3ce44SJohn Forte 	int fd;
417fcf3ce44SJohn Forte 	iSCSIDiscoveryProperties_t discoveryProps;
418fcf3ce44SJohn Forte 
419fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
420fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
421fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
422fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
423fcf3ce44SJohn Forte 	}
424fcf3ce44SJohn Forte 
425fcf3ce44SJohn Forte 	(void) memset(&discoveryProps, 0, sizeof (discoveryProps));
426fcf3ce44SJohn Forte 	discoveryProps.vers = ISCSI_INTERFACE_VERSION;
427fcf3ce44SJohn Forte 
428fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_PROPS, &discoveryProps) != 0) {
429fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
430fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_PROPS ioctl failed, errno: %d", errno);
431fcf3ce44SJohn Forte 		(void) close(fd);
432fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
433fcf3ce44SJohn Forte 	}
434fcf3ce44SJohn Forte 
435fcf3ce44SJohn Forte 	pProps->iSnsDiscoverySettable = discoveryProps.iSNSDiscoverySettable;
436fcf3ce44SJohn Forte 	pProps->iSnsDiscoveryEnabled = discoveryProps.iSNSDiscoveryEnabled;
437fcf3ce44SJohn Forte 	/*
438fcf3ce44SJohn Forte 	 * Set the iSNS discovery method - The IMA specification indicates
439fcf3ce44SJohn Forte 	 * this field is valid only if iSNS discovery is enabled.
440fcf3ce44SJohn Forte 	 */
441fcf3ce44SJohn Forte 	if (pProps->iSnsDiscoveryEnabled == IMA_TRUE) {
442fcf3ce44SJohn Forte 		switch (discoveryProps.iSNSDiscoveryMethod) {
443fcf3ce44SJohn Forte 			case iSNSDiscoveryMethodStatic:
444fcf3ce44SJohn Forte 				pProps->iSnsDiscoveryMethod =
445fcf3ce44SJohn Forte 				    IMA_ISNS_DISCOVERY_METHOD_STATIC;
446fcf3ce44SJohn Forte 				break;
447fcf3ce44SJohn Forte 			case iSNSDiscoveryMethodDHCP:
448fcf3ce44SJohn Forte 				pProps->iSnsDiscoveryMethod =
449fcf3ce44SJohn Forte 				    IMA_ISNS_DISCOVERY_METHOD_DHCP;
450fcf3ce44SJohn Forte 				break;
451fcf3ce44SJohn Forte 			case iSNSDiscoveryMethodSLP:
452fcf3ce44SJohn Forte 				pProps->iSnsDiscoveryMethod =
453fcf3ce44SJohn Forte 				    IMA_ISNS_DISCOVERY_METHOD_SLP;
454fcf3ce44SJohn Forte 				break;
455fcf3ce44SJohn Forte 			default:
456fcf3ce44SJohn Forte 				(void) close(fd);
457fcf3ce44SJohn Forte 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
458fcf3ce44SJohn Forte 		}
459fcf3ce44SJohn Forte 	}
460fcf3ce44SJohn Forte 	(void) memcpy(pProps->iSnsHost.id.hostname,
461fcf3ce44SJohn Forte 	    discoveryProps.iSNSDomainName,
462fcf3ce44SJohn Forte 	    sizeof (pProps->iSnsHost.id.hostname));
463fcf3ce44SJohn Forte 	pProps->slpDiscoverySettable = discoveryProps.SLPDiscoverySettable;
464fcf3ce44SJohn Forte 	pProps->slpDiscoveryEnabled = discoveryProps.SLPDiscoveryEnabled;
465fcf3ce44SJohn Forte 	pProps->staticDiscoverySettable =
466fcf3ce44SJohn Forte 	    discoveryProps.StaticDiscoverySettable;
467fcf3ce44SJohn Forte 	pProps->staticDiscoveryEnabled = discoveryProps.StaticDiscoveryEnabled;
468fcf3ce44SJohn Forte 	pProps->sendTargetsDiscoverySettable =
469fcf3ce44SJohn Forte 	    discoveryProps.SendTargetsDiscoverySettable;
470fcf3ce44SJohn Forte 	pProps->sendTargetsDiscoveryEnabled =
471fcf3ce44SJohn Forte 	    discoveryProps.SendTargetsDiscoveryEnabled;
472fcf3ce44SJohn Forte 
473fcf3ce44SJohn Forte 	(void) close(fd);
474fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
475fcf3ce44SJohn Forte }
476fcf3ce44SJohn Forte 
IMA_FreeMemory(void * pMemory)477fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_FreeMemory(
478fcf3ce44SJohn Forte 	void *pMemory
479fcf3ce44SJohn Forte )
480fcf3ce44SJohn Forte {
481fcf3ce44SJohn Forte 	if (pMemory != NULL)
482fcf3ce44SJohn Forte 		free(pMemory);
483fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
484fcf3ce44SJohn Forte }
485fcf3ce44SJohn Forte 
IMA_GetNonSharedNodeOidList(IMA_OID_LIST ** ppList)486fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetNonSharedNodeOidList(
487fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
488fcf3ce44SJohn Forte )
489fcf3ce44SJohn Forte {
490fcf3ce44SJohn Forte 	if (ppList == NULL)
491fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
492fcf3ce44SJohn Forte 
493fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST*) calloc(1, sizeof (IMA_OID_LIST));
494fcf3ce44SJohn Forte 	if (*ppList == NULL) {
495fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
496fcf3ce44SJohn Forte 	}
497fcf3ce44SJohn Forte 	(*ppList)->oidCount = 0;
498fcf3ce44SJohn Forte 
499fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
500fcf3ce44SJohn Forte }
501fcf3ce44SJohn Forte 
IMA_GetFirstBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)502fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetFirstBurstLengthProperties(
503fcf3ce44SJohn Forte 		IMA_OID Oid,
504fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
505fcf3ce44SJohn Forte )
506fcf3ce44SJohn Forte {
507fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
508fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH));
509fcf3ce44SJohn Forte }
510fcf3ce44SJohn Forte 
IMA_GetMaxBurstLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)511fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetMaxBurstLengthProperties(
512fcf3ce44SJohn Forte 		IMA_OID Oid,
513fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
514fcf3ce44SJohn Forte )
515fcf3ce44SJohn Forte {
516fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
517fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH));
518fcf3ce44SJohn Forte }
519fcf3ce44SJohn Forte 
IMA_GetMaxRecvDataSegmentLengthProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)520fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetMaxRecvDataSegmentLengthProperties(
521fcf3ce44SJohn Forte 		IMA_OID Oid,
522fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
523fcf3ce44SJohn Forte )
524fcf3ce44SJohn Forte {
525fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
526fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH));
527fcf3ce44SJohn Forte }
528fcf3ce44SJohn Forte 
529fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_PluginIOCtl(IMA_OID pluginOid,IMA_UINT command,const void * pInputBuffer,IMA_UINT inputBufferLength,void * pOutputBuffer,IMA_UINT * pOutputBufferLength)530fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_PluginIOCtl(
531fcf3ce44SJohn Forte 		IMA_OID pluginOid,
532fcf3ce44SJohn Forte 		IMA_UINT command,
533fcf3ce44SJohn Forte 		const void *pInputBuffer,
534fcf3ce44SJohn Forte 		IMA_UINT inputBufferLength,
535fcf3ce44SJohn Forte 		void *pOutputBuffer,
536fcf3ce44SJohn Forte 		IMA_UINT *pOutputBufferLength
537fcf3ce44SJohn Forte )
538fcf3ce44SJohn Forte {
539fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
540fcf3ce44SJohn Forte }
541fcf3ce44SJohn Forte 
IMA_SetFirstBurstLength(IMA_OID lhbaId,IMA_UINT firstBurstLength)542fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetFirstBurstLength(
543fcf3ce44SJohn Forte 		IMA_OID lhbaId,
544fcf3ce44SJohn Forte 		IMA_UINT firstBurstLength
545fcf3ce44SJohn Forte )
546fcf3ce44SJohn Forte {
547fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
548fcf3ce44SJohn Forte 
549fcf3ce44SJohn Forte 	mv.currentValue = firstBurstLength;
550fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
551fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH));
552fcf3ce44SJohn Forte }
553fcf3ce44SJohn Forte 
IMA_SetMaxBurstLength(IMA_OID lhbaId,IMA_UINT maxBurstLength)554fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetMaxBurstLength(
555fcf3ce44SJohn Forte 		IMA_OID lhbaId,
556fcf3ce44SJohn Forte 		IMA_UINT maxBurstLength
557fcf3ce44SJohn Forte )
558fcf3ce44SJohn Forte {
559fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
560fcf3ce44SJohn Forte 
561fcf3ce44SJohn Forte 	mv.currentValue = maxBurstLength;
562fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
563fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH));
564fcf3ce44SJohn Forte }
565fcf3ce44SJohn Forte 
IMA_SetMaxRecvDataSegmentLength(IMA_OID lhbaId,IMA_UINT maxRecvDataSegmentLength)566fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetMaxRecvDataSegmentLength(
567fcf3ce44SJohn Forte 		IMA_OID lhbaId,
568fcf3ce44SJohn Forte 		IMA_UINT maxRecvDataSegmentLength
569fcf3ce44SJohn Forte )
570fcf3ce44SJohn Forte {
571fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
572fcf3ce44SJohn Forte 
573fcf3ce44SJohn Forte 	mv.currentValue = maxRecvDataSegmentLength;
574fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
575fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH));
576fcf3ce44SJohn Forte }
577fcf3ce44SJohn Forte 
IMA_GetMaxConnectionsProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)578fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetMaxConnectionsProperties(
579fcf3ce44SJohn Forte 		IMA_OID Oid,
580fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
581fcf3ce44SJohn Forte )
582fcf3ce44SJohn Forte {
583fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
584fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_CONNECTIONS));
585fcf3ce44SJohn Forte }
586fcf3ce44SJohn Forte 
IMA_SetMaxConnections(IMA_OID lhbaId,IMA_UINT maxConnections)587fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetMaxConnections(
588fcf3ce44SJohn Forte 		IMA_OID lhbaId,
589fcf3ce44SJohn Forte 		IMA_UINT maxConnections
590fcf3ce44SJohn Forte )
591fcf3ce44SJohn Forte {
592fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
593fcf3ce44SJohn Forte 
594fcf3ce44SJohn Forte 	mv.currentValue = maxConnections;
595fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
596fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_MAX_CONNECTIONS));
597fcf3ce44SJohn Forte }
598fcf3ce44SJohn Forte 
IMA_GetDefaultTime2RetainProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)599fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDefaultTime2RetainProperties(
600fcf3ce44SJohn Forte 		IMA_OID lhbaId,
601fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
602fcf3ce44SJohn Forte )
603fcf3ce44SJohn Forte {
604fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps,
605fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN));
606fcf3ce44SJohn Forte }
607fcf3ce44SJohn Forte 
IMA_SetDefaultTime2Retain(IMA_OID lhbaId,IMA_UINT defaultTime2Retain)608fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetDefaultTime2Retain(
609fcf3ce44SJohn Forte 		IMA_OID lhbaId,
610fcf3ce44SJohn Forte 		IMA_UINT defaultTime2Retain
611fcf3ce44SJohn Forte )
612fcf3ce44SJohn Forte {
613fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
614fcf3ce44SJohn Forte 
615fcf3ce44SJohn Forte 	mv.currentValue = defaultTime2Retain;
616fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
617fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN));
618fcf3ce44SJohn Forte }
619fcf3ce44SJohn Forte 
IMA_GetDefaultTime2WaitProperties(IMA_OID lhbaId,IMA_MIN_MAX_VALUE * pProps)620fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDefaultTime2WaitProperties(
621fcf3ce44SJohn Forte 		IMA_OID lhbaId,
622fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
623fcf3ce44SJohn Forte )
624fcf3ce44SJohn Forte {
625fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, pProps,
626fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT));
627fcf3ce44SJohn Forte }
628fcf3ce44SJohn Forte 
IMA_SetDefaultTime2Wait(IMA_OID lhbaId,IMA_UINT defaultTime2Wait)629fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetDefaultTime2Wait(
630fcf3ce44SJohn Forte 		IMA_OID lhbaId,
631fcf3ce44SJohn Forte 		IMA_UINT defaultTime2Wait
632fcf3ce44SJohn Forte )
633fcf3ce44SJohn Forte {
634fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
635fcf3ce44SJohn Forte 
636fcf3ce44SJohn Forte 	mv.currentValue = defaultTime2Wait;
637fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
638fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT));
639fcf3ce44SJohn Forte }
640fcf3ce44SJohn Forte 
IMA_GetMaxOutstandingR2TProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)641fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetMaxOutstandingR2TProperties(
642fcf3ce44SJohn Forte 		IMA_OID Oid,
643fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
644fcf3ce44SJohn Forte )
645fcf3ce44SJohn Forte {
646fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
647fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_OUTSTANDING_R2T));
648fcf3ce44SJohn Forte }
649fcf3ce44SJohn Forte 
IMA_SetMaxOutstandingR2T(IMA_OID lhbaId,IMA_UINT maxOutstandingR2T)650fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetMaxOutstandingR2T(
651fcf3ce44SJohn Forte 		IMA_OID lhbaId,
652fcf3ce44SJohn Forte 		IMA_UINT maxOutstandingR2T
653fcf3ce44SJohn Forte )
654fcf3ce44SJohn Forte {
655fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
656fcf3ce44SJohn Forte 
657fcf3ce44SJohn Forte 	mv.currentValue = maxOutstandingR2T;
658fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &lhbaId, &mv,
659fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_OUTSTANDING_R2T));
660fcf3ce44SJohn Forte }
661fcf3ce44SJohn Forte 
662fcf3ce44SJohn Forte 
IMA_GetErrorRecoveryLevelProperties(IMA_OID Oid,IMA_MIN_MAX_VALUE * pProps)663fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetErrorRecoveryLevelProperties(
664fcf3ce44SJohn Forte 		IMA_OID Oid,
665fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *pProps
666fcf3ce44SJohn Forte )
667fcf3ce44SJohn Forte {
668fcf3ce44SJohn Forte 	return (getISCSINodeParameter(MIN_MAX_PARAM, &Oid, pProps,
669fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL));
670fcf3ce44SJohn Forte }
671fcf3ce44SJohn Forte 
IMA_SetErrorRecoveryLevel(IMA_OID Oid,IMA_UINT errorRecoveryLevel)672fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetErrorRecoveryLevel(
673fcf3ce44SJohn Forte 		IMA_OID Oid,
674fcf3ce44SJohn Forte 		IMA_UINT errorRecoveryLevel
675fcf3ce44SJohn Forte )
676fcf3ce44SJohn Forte {
677fcf3ce44SJohn Forte 	IMA_MIN_MAX_VALUE mv;
678fcf3ce44SJohn Forte 
679fcf3ce44SJohn Forte 	mv.currentValue = errorRecoveryLevel;
680fcf3ce44SJohn Forte 	return (setISCSINodeParameter(MIN_MAX_PARAM, &Oid, &mv,
681fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL));
682fcf3ce44SJohn Forte }
683fcf3ce44SJohn Forte 
IMA_GetInitialR2TProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)684fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetInitialR2TProperties(
685fcf3ce44SJohn Forte 		IMA_OID Oid,
686fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *pProps
687fcf3ce44SJohn Forte )
688fcf3ce44SJohn Forte {
689fcf3ce44SJohn Forte 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
690fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_INITIAL_R2T));
691fcf3ce44SJohn Forte }
692fcf3ce44SJohn Forte 
IMA_SetInitialR2T(IMA_OID Oid,IMA_BOOL initialR2T)693fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetInitialR2T(
694fcf3ce44SJohn Forte 		IMA_OID Oid,
695fcf3ce44SJohn Forte 		IMA_BOOL initialR2T
696fcf3ce44SJohn Forte )
697fcf3ce44SJohn Forte {
698fcf3ce44SJohn Forte 	IMA_BOOL_VALUE bv;
699fcf3ce44SJohn Forte 
700fcf3ce44SJohn Forte 	bv.currentValue = initialR2T;
701fcf3ce44SJohn Forte 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
702fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_INITIAL_R2T));
703fcf3ce44SJohn Forte }
704fcf3ce44SJohn Forte 
705fcf3ce44SJohn Forte 
IMA_GetImmediateDataProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)706fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetImmediateDataProperties(
707fcf3ce44SJohn Forte 		IMA_OID Oid,
708fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *pProps
709fcf3ce44SJohn Forte )
710fcf3ce44SJohn Forte {
711fcf3ce44SJohn Forte 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
712fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_IMMEDIATE_DATA));
713fcf3ce44SJohn Forte }
714fcf3ce44SJohn Forte 
IMA_SetImmediateData(IMA_OID Oid,IMA_BOOL immediateData)715fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetImmediateData(
716fcf3ce44SJohn Forte 		IMA_OID Oid,
717fcf3ce44SJohn Forte 		IMA_BOOL immediateData
718fcf3ce44SJohn Forte )
719fcf3ce44SJohn Forte {
720fcf3ce44SJohn Forte 	IMA_BOOL_VALUE bv;
721fcf3ce44SJohn Forte 
722fcf3ce44SJohn Forte 	bv.currentValue = immediateData;
723fcf3ce44SJohn Forte 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
724fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_IMMEDIATE_DATA));
725fcf3ce44SJohn Forte }
726fcf3ce44SJohn Forte 
IMA_GetDataPduInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)727fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDataPduInOrderProperties(
728fcf3ce44SJohn Forte 		IMA_OID Oid,
729fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *pProps
730fcf3ce44SJohn Forte )
731fcf3ce44SJohn Forte {
732fcf3ce44SJohn Forte 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
733fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER));
734fcf3ce44SJohn Forte }
735fcf3ce44SJohn Forte 
IMA_SetDataPduInOrder(IMA_OID Oid,IMA_BOOL dataPduInOrder)736fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetDataPduInOrder(
737fcf3ce44SJohn Forte 		IMA_OID Oid,
738fcf3ce44SJohn Forte 		IMA_BOOL dataPduInOrder
739fcf3ce44SJohn Forte )
740fcf3ce44SJohn Forte {
741fcf3ce44SJohn Forte 	IMA_BOOL_VALUE bv;
742fcf3ce44SJohn Forte 
743fcf3ce44SJohn Forte 	bv.currentValue = dataPduInOrder;
744fcf3ce44SJohn Forte 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
745fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER));
746fcf3ce44SJohn Forte }
747fcf3ce44SJohn Forte 
IMA_GetDataSequenceInOrderProperties(IMA_OID Oid,IMA_BOOL_VALUE * pProps)748fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDataSequenceInOrderProperties(
749fcf3ce44SJohn Forte 		IMA_OID Oid,
750fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *pProps
751fcf3ce44SJohn Forte )
752fcf3ce44SJohn Forte {
753fcf3ce44SJohn Forte 	return (getISCSINodeParameter(BOOL_PARAM, &Oid, pProps,
754fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER));
755fcf3ce44SJohn Forte }
756fcf3ce44SJohn Forte 
IMA_SetDataSequenceInOrder(IMA_OID Oid,IMA_BOOL dataSequenceInOrder)757fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetDataSequenceInOrder(
758fcf3ce44SJohn Forte 		IMA_OID Oid,
759fcf3ce44SJohn Forte 		IMA_BOOL dataSequenceInOrder
760fcf3ce44SJohn Forte )
761fcf3ce44SJohn Forte {
762fcf3ce44SJohn Forte 	IMA_BOOL_VALUE bv;
763fcf3ce44SJohn Forte 
764fcf3ce44SJohn Forte 	bv.currentValue = dataSequenceInOrder;
765fcf3ce44SJohn Forte 	return (setISCSINodeParameter(BOOL_PARAM, &Oid, &bv,
766fcf3ce44SJohn Forte 	    ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER));
767fcf3ce44SJohn Forte }
768fcf3ce44SJohn Forte 
769fcf3ce44SJohn Forte 
770fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_SetStatisticsCollection(IMA_OID Oid,IMA_BOOL enableStatisticsCollection)771fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetStatisticsCollection(
772fcf3ce44SJohn Forte 		IMA_OID Oid,
773fcf3ce44SJohn Forte 		IMA_BOOL enableStatisticsCollection
774fcf3ce44SJohn Forte )
775fcf3ce44SJohn Forte {
776fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
777fcf3ce44SJohn Forte }
778fcf3ce44SJohn Forte 
779fcf3ce44SJohn Forte 
780fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetDiscoveryAddressOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)781fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDiscoveryAddressOidList(
782fcf3ce44SJohn Forte 		IMA_OID Oid,
783fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
784fcf3ce44SJohn Forte )
785fcf3ce44SJohn Forte {
786fcf3ce44SJohn Forte 	int fd, i, addr_list_size;
787fcf3ce44SJohn Forte 	iscsi_addr_list_t *idlp, al_info;
788fcf3ce44SJohn Forte 
789fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
790fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
791fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
792fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
793fcf3ce44SJohn Forte 	}
794fcf3ce44SJohn Forte 
795fcf3ce44SJohn Forte 	(void) memset(&al_info, 0, sizeof (al_info));
796fcf3ce44SJohn Forte 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
797fcf3ce44SJohn Forte 	al_info.al_in_cnt = 0;
798fcf3ce44SJohn Forte 
799fcf3ce44SJohn Forte 	/*
800fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the number of targets.
801fcf3ce44SJohn Forte 	 */
802fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
803fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
804fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
805fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
806fcf3ce44SJohn Forte 		(void) close(fd);
807fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
808fcf3ce44SJohn Forte 	}
809fcf3ce44SJohn Forte 
810fcf3ce44SJohn Forte 	addr_list_size = sizeof (iscsi_addr_list_t);
811fcf3ce44SJohn Forte 	if (al_info.al_out_cnt > 1) {
812fcf3ce44SJohn Forte 		addr_list_size += (sizeof (iscsi_addr_list_t) *
813fcf3ce44SJohn Forte 		    al_info.al_out_cnt - 1);
814fcf3ce44SJohn Forte 	}
815fcf3ce44SJohn Forte 
816fcf3ce44SJohn Forte 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
817fcf3ce44SJohn Forte 	if (idlp == NULL) {
818fcf3ce44SJohn Forte 		(void) close(fd);
819fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
820fcf3ce44SJohn Forte 	}
821fcf3ce44SJohn Forte 
822fcf3ce44SJohn Forte 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
823fcf3ce44SJohn Forte 	idlp->al_in_cnt = al_info.al_out_cnt;
824fcf3ce44SJohn Forte 	/* Issue the same ioctl again to obtain the OIDs. */
825fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
826fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
827fcf3ce44SJohn Forte 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
828fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
829fcf3ce44SJohn Forte 		free(idlp);
830fcf3ce44SJohn Forte 		(void) close(fd);
831fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
832fcf3ce44SJohn Forte 	}
833fcf3ce44SJohn Forte 
834fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) +
835fcf3ce44SJohn Forte 	    idlp->al_out_cnt * sizeof (IMA_OID));
836fcf3ce44SJohn Forte 	if (*ppList == NULL) {
837fcf3ce44SJohn Forte 		free(idlp);
838fcf3ce44SJohn Forte 		(void) close(fd);
839fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
840fcf3ce44SJohn Forte 	}
841fcf3ce44SJohn Forte 	(*ppList)->oidCount = idlp->al_out_cnt;
842fcf3ce44SJohn Forte 
843fcf3ce44SJohn Forte 	for (i = 0; i < idlp->al_out_cnt; i++) {
844fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectType =
845fcf3ce44SJohn Forte 		    IMA_OBJECT_TYPE_DISCOVERY_ADDRESS;
846fcf3ce44SJohn Forte 		(*ppList)->oids[i].ownerId = pluginOwnerId;
847fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectSequenceNumber =
848fcf3ce44SJohn Forte 		    idlp->al_addrs[i].a_oid;
849fcf3ce44SJohn Forte 	}
850fcf3ce44SJohn Forte 
851fcf3ce44SJohn Forte 	free(idlp);
852fcf3ce44SJohn Forte 	(void) close(fd);
853fcf3ce44SJohn Forte 
854fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
855fcf3ce44SJohn Forte }
856fcf3ce44SJohn Forte 
857fcf3ce44SJohn Forte 
858fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetStaticDiscoveryTargetOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)859fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetStaticDiscoveryTargetOidList(
860fcf3ce44SJohn Forte 		IMA_OID Oid,
861fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
862fcf3ce44SJohn Forte )
863fcf3ce44SJohn Forte {
864fcf3ce44SJohn Forte 	if (Oid.objectType == IMA_OBJECT_TYPE_PNP) {
865fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
866fcf3ce44SJohn Forte 	}
867fcf3ce44SJohn Forte 
868fcf3ce44SJohn Forte 	return (get_target_oid_list(ISCSI_STATIC_TGT_OID_LIST, ppList));
869fcf3ce44SJohn Forte }
870fcf3ce44SJohn Forte 
871fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetTargetOidList(IMA_OID Oid,IMA_OID_LIST ** ppList)872fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetTargetOidList(
873fcf3ce44SJohn Forte 		IMA_OID Oid,
874fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
875fcf3ce44SJohn Forte )
876fcf3ce44SJohn Forte {
877fcf3ce44SJohn Forte 	return (get_target_oid_list(ISCSI_TGT_PARAM_OID_LIST, ppList));
878fcf3ce44SJohn Forte }
879fcf3ce44SJohn Forte 
880fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_SetIsnsDiscovery(IMA_OID phbaId,IMA_BOOL enableIsnsDiscovery,IMA_ISNS_DISCOVERY_METHOD discoveryMethod,const IMA_HOST_ID * iSnsHost)881fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetIsnsDiscovery(
882fcf3ce44SJohn Forte 		IMA_OID phbaId,
883fcf3ce44SJohn Forte 		IMA_BOOL enableIsnsDiscovery,
884fcf3ce44SJohn Forte 		IMA_ISNS_DISCOVERY_METHOD discoveryMethod,
885fcf3ce44SJohn Forte 		const IMA_HOST_ID *iSnsHost
886fcf3ce44SJohn Forte )
887fcf3ce44SJohn Forte {
888fcf3ce44SJohn Forte 	/* XXX need to set discovery Method and domaineName */
889fcf3ce44SJohn Forte 	return (configure_discovery_method(enableIsnsDiscovery,
890fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodISNS));
891fcf3ce44SJohn Forte }
892fcf3ce44SJohn Forte 
893fcf3ce44SJohn Forte 
894fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetSlpDiscovery(IMA_OID phbaId,IMA_BOOL enableSlpDiscovery)895fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetSlpDiscovery(
896fcf3ce44SJohn Forte 		IMA_OID phbaId,
897fcf3ce44SJohn Forte 		IMA_BOOL enableSlpDiscovery
898fcf3ce44SJohn Forte )
899fcf3ce44SJohn Forte {
900fcf3ce44SJohn Forte 	return (configure_discovery_method(enableSlpDiscovery,
901fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodSLP));
902fcf3ce44SJohn Forte }
903fcf3ce44SJohn Forte 
904fcf3ce44SJohn Forte 
905fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetStaticDiscovery(IMA_OID phbaId,IMA_BOOL enableStaticDiscovery)906fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetStaticDiscovery(
907fcf3ce44SJohn Forte 		IMA_OID phbaId,
908fcf3ce44SJohn Forte 		IMA_BOOL enableStaticDiscovery
909fcf3ce44SJohn Forte )
910fcf3ce44SJohn Forte {
911fcf3ce44SJohn Forte 	return (configure_discovery_method(enableStaticDiscovery,
912fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodStatic));
913fcf3ce44SJohn Forte }
914fcf3ce44SJohn Forte 
915fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetSendTargetsDiscovery(IMA_OID phbaId,IMA_BOOL enableSendTargetsDiscovery)916fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetSendTargetsDiscovery(
917fcf3ce44SJohn Forte 		IMA_OID phbaId,
918fcf3ce44SJohn Forte 		IMA_BOOL enableSendTargetsDiscovery
919fcf3ce44SJohn Forte )
920fcf3ce44SJohn Forte {
921fcf3ce44SJohn Forte 	return (configure_discovery_method(enableSendTargetsDiscovery,
922fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodSendTargets));
923fcf3ce44SJohn Forte }
924fcf3ce44SJohn Forte 
925fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_RemoveDiscoveryAddress(IMA_OID discoveryAddressOid)926fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_RemoveDiscoveryAddress(
927fcf3ce44SJohn Forte 		IMA_OID	discoveryAddressOid
928fcf3ce44SJohn Forte )
929fcf3ce44SJohn Forte {
930fcf3ce44SJohn Forte 	int status, fd, i, addr_list_size;
931fcf3ce44SJohn Forte 	iscsi_addr_list_t *idlp, al_info;
932fcf3ce44SJohn Forte 	iscsi_addr_t *matched_addr = NULL;
933fcf3ce44SJohn Forte 	entry_t	entry;
934fcf3ce44SJohn Forte 
935fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
936fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
937fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
938fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
939fcf3ce44SJohn Forte 	}
940fcf3ce44SJohn Forte 
941fcf3ce44SJohn Forte 	(void) memset(&al_info, 0, sizeof (al_info));
942fcf3ce44SJohn Forte 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
943fcf3ce44SJohn Forte 	al_info.al_in_cnt = 0;
944fcf3ce44SJohn Forte 
945fcf3ce44SJohn Forte 	/*
946fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the number of discovery address.
947fcf3ce44SJohn Forte 	 */
948fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
949fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
950fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
951fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
952fcf3ce44SJohn Forte 		(void) close(fd);
953fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
954fcf3ce44SJohn Forte 	}
955fcf3ce44SJohn Forte 
956fcf3ce44SJohn Forte 	if (al_info.al_out_cnt == 0) {
957fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
958fcf3ce44SJohn Forte 	}
959fcf3ce44SJohn Forte 
960fcf3ce44SJohn Forte 	addr_list_size = sizeof (iscsi_addr_list_t);
961fcf3ce44SJohn Forte 	if (al_info.al_out_cnt > 1) {
962fcf3ce44SJohn Forte 		addr_list_size += (sizeof (iscsi_addr_list_t) *
963fcf3ce44SJohn Forte 		    al_info.al_out_cnt - 1);
964fcf3ce44SJohn Forte 	}
965fcf3ce44SJohn Forte 
966fcf3ce44SJohn Forte 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
967fcf3ce44SJohn Forte 	if (idlp == NULL) {
968fcf3ce44SJohn Forte 		(void) close(fd);
969fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
970fcf3ce44SJohn Forte 	}
971fcf3ce44SJohn Forte 
972fcf3ce44SJohn Forte 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
973fcf3ce44SJohn Forte 	idlp->al_in_cnt = al_info.al_out_cnt;
974fcf3ce44SJohn Forte 
975fcf3ce44SJohn Forte 	/* Issue the same ioctl again to obtain the OIDs. */
976fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
977fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
978fcf3ce44SJohn Forte 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
979fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
980fcf3ce44SJohn Forte 		free(idlp);
981fcf3ce44SJohn Forte 		(void) close(fd);
982fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
983fcf3ce44SJohn Forte 	}
984fcf3ce44SJohn Forte 
985fcf3ce44SJohn Forte 	for (i = 0; i < idlp->al_out_cnt; i++) {
986fcf3ce44SJohn Forte 		if (discoveryAddressOid.objectSequenceNumber !=
987fcf3ce44SJohn Forte 		    idlp->al_addrs[i].a_oid)
988fcf3ce44SJohn Forte 			continue;
989fcf3ce44SJohn Forte 		matched_addr = &(idlp->al_addrs[i]);
990fcf3ce44SJohn Forte 	}
991fcf3ce44SJohn Forte 
992fcf3ce44SJohn Forte 	if (matched_addr == NULL) {
993fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
994fcf3ce44SJohn Forte 	}
995fcf3ce44SJohn Forte 
996fcf3ce44SJohn Forte 
997fcf3ce44SJohn Forte 	(void) memset(&entry, 0, sizeof (entry_t));
998fcf3ce44SJohn Forte 	entry.e_vers = ISCSI_INTERFACE_VERSION;
999fcf3ce44SJohn Forte 	entry.e_oid  = discoveryAddressOid.objectSequenceNumber;
1000fcf3ce44SJohn Forte 	if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) {
1001fcf3ce44SJohn Forte 		bcopy(&matched_addr->a_addr.i_addr.in4,
1002fcf3ce44SJohn Forte 		    &entry.e_u.u_in4, sizeof (entry.e_u.u_in4));
1003fcf3ce44SJohn Forte 		entry.e_insize = sizeof (struct in_addr);
1004fcf3ce44SJohn Forte 	} else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) {
1005fcf3ce44SJohn Forte 		bcopy(&matched_addr->a_addr.i_addr.in6,
1006fcf3ce44SJohn Forte 		    &entry.e_u.u_in6, sizeof (entry.e_u.u_in6));
1007fcf3ce44SJohn Forte 		entry.e_insize = sizeof (struct in6_addr);
1008fcf3ce44SJohn Forte 	} else {
1009fcf3ce44SJohn Forte 		/* Should not happen */
1010fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1011fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET returned bad address");
1012fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1013fcf3ce44SJohn Forte 	}
1014fcf3ce44SJohn Forte 
1015fcf3ce44SJohn Forte 	entry.e_port = matched_addr->a_port;
1016fcf3ce44SJohn Forte 	entry.e_tpgt = 0;
1017fcf3ce44SJohn Forte 	entry.e_oid = discoveryAddressOid.objectSequenceNumber;
1018fcf3ce44SJohn Forte 
1019fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_CLEAR, &entry)) {
1020fcf3ce44SJohn Forte 		status = errno;
1021fcf3ce44SJohn Forte 		(void) close(fd);
1022fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1023fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_CLEAR ioctl failed, errno: %d",
1024fcf3ce44SJohn Forte 		    errno);
1025fcf3ce44SJohn Forte 		if (status == EBUSY) {
1026fcf3ce44SJohn Forte 			return (IMA_ERROR_LU_IN_USE);
1027fcf3ce44SJohn Forte 		} else {
1028fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1029fcf3ce44SJohn Forte 		}
1030fcf3ce44SJohn Forte 	}
1031fcf3ce44SJohn Forte 
1032fcf3ce44SJohn Forte 	free(idlp);
1033fcf3ce44SJohn Forte 	(void) close(fd);
1034fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1035fcf3ce44SJohn Forte }
1036fcf3ce44SJohn Forte 
1037fcf3ce44SJohn Forte 
1038fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_AddDiscoveryAddress(IMA_OID oid,const IMA_TARGET_ADDRESS discoveryAddress,IMA_OID * pDiscoveryAddressOid)1039fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_AddDiscoveryAddress(
1040fcf3ce44SJohn Forte 		IMA_OID	oid,
1041fcf3ce44SJohn Forte 		const IMA_TARGET_ADDRESS discoveryAddress,
1042fcf3ce44SJohn Forte 		IMA_OID	*pDiscoveryAddressOid
1043fcf3ce44SJohn Forte )
1044fcf3ce44SJohn Forte {
1045fcf3ce44SJohn Forte 	entry_t	    entry;
1046fcf3ce44SJohn Forte 	int	    fd;
1047fcf3ce44SJohn Forte 
1048fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1049fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1050fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1051fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1052fcf3ce44SJohn Forte 	}
1053fcf3ce44SJohn Forte 
1054fcf3ce44SJohn Forte 	if (prepare_discovery_entry(discoveryAddress, &entry) !=
1055fcf3ce44SJohn Forte 	    DISC_ADDR_OK) {
1056fcf3ce44SJohn Forte 		(void) close(fd);
1057fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
1058fcf3ce44SJohn Forte 	}
1059fcf3ce44SJohn Forte 
1060fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_SET, &entry)) {
1061fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1062fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_SET ioctl failed, errno: %d",
1063fcf3ce44SJohn Forte 		    errno);
1064fcf3ce44SJohn Forte 		(void) close(fd);
1065fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1066fcf3ce44SJohn Forte 	}
1067fcf3ce44SJohn Forte 
1068fcf3ce44SJohn Forte 	pDiscoveryAddressOid->ownerId = pluginOwnerId;
1069fcf3ce44SJohn Forte 	pDiscoveryAddressOid->objectType = IMA_OBJECT_TYPE_DISCOVERY_ADDRESS;
1070fcf3ce44SJohn Forte 	pDiscoveryAddressOid->objectSequenceNumber = entry.e_oid;
1071fcf3ce44SJohn Forte 
1072fcf3ce44SJohn Forte 	(void) close(fd);
1073fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1074fcf3ce44SJohn Forte }
1075fcf3ce44SJohn Forte 
IMA_GetStaticDiscoveryTargetProperties(IMA_OID staticTargetOid,IMA_STATIC_DISCOVERY_TARGET_PROPERTIES * pProps)1076fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetStaticDiscoveryTargetProperties(
1077fcf3ce44SJohn Forte 		IMA_OID	staticTargetOid,
1078fcf3ce44SJohn Forte 		IMA_STATIC_DISCOVERY_TARGET_PROPERTIES *pProps
1079fcf3ce44SJohn Forte )
1080fcf3ce44SJohn Forte {
1081fcf3ce44SJohn Forte 	char static_target_addr_str[SUN_IMA_IP_ADDRESS_LEN];
1082fcf3ce44SJohn Forte 	char static_target_addr_port_str[SUN_IMA_IP_ADDRESS_LEN];
1083fcf3ce44SJohn Forte 	int af, fd, status;
1084fcf3ce44SJohn Forte 	iscsi_static_property_t prop;
1085fcf3ce44SJohn Forte 	/* LINTED */
1086fcf3ce44SJohn Forte 	IMA_HOST_ID *host;
1087fcf3ce44SJohn Forte 
1088fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1089fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1090fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1091fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1092fcf3ce44SJohn Forte 	}
1093fcf3ce44SJohn Forte 
1094fcf3ce44SJohn Forte 	(void) memset(&prop, 0, sizeof (iscsi_static_property_t));
1095fcf3ce44SJohn Forte 	prop.p_vers = ISCSI_INTERFACE_VERSION;
1096fcf3ce44SJohn Forte 	prop.p_oid = (uint32_t)staticTargetOid.objectSequenceNumber;
1097fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_STATIC_GET, &prop) != 0) {
1098fcf3ce44SJohn Forte 		status = errno;
1099fcf3ce44SJohn Forte 		(void) close(fd);
1100fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1101fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET ioctl failed, errno: %d", status);
1102fcf3ce44SJohn Forte 		if (status == ENOENT) {
1103fcf3ce44SJohn Forte 			return (IMA_ERROR_OBJECT_NOT_FOUND);
1104fcf3ce44SJohn Forte 
1105fcf3ce44SJohn Forte 		} else {
1106fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1107fcf3ce44SJohn Forte 		}
1108fcf3ce44SJohn Forte 	}
1109fcf3ce44SJohn Forte 	(void) close(fd);
1110fcf3ce44SJohn Forte 
1111fcf3ce44SJohn Forte 	(void) mbstowcs(pProps->staticTarget.targetName, (char *)prop.p_name,
1112fcf3ce44SJohn Forte 	    sizeof (pProps->staticTarget.targetName)/sizeof (IMA_WCHAR));
1113fcf3ce44SJohn Forte 
1114fcf3ce44SJohn Forte 	if (prop.p_addr_list.al_addrs[0].a_addr.i_insize ==
1115fcf3ce44SJohn Forte 	    sizeof (struct in_addr)) {
1116fcf3ce44SJohn Forte 		/* IPv4 */
1117fcf3ce44SJohn Forte 		af = AF_INET;
1118fcf3ce44SJohn Forte 	} else if (prop.p_addr_list.al_addrs[0].a_addr.i_insize ==
1119fcf3ce44SJohn Forte 	    sizeof (struct in6_addr)) {
1120fcf3ce44SJohn Forte 		/* IPv6 */
1121fcf3ce44SJohn Forte 		af = AF_INET6;
1122fcf3ce44SJohn Forte 	} else {
1123fcf3ce44SJohn Forte 		/* Should not happen */
1124fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1125fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET returned bad address");
1126fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1127fcf3ce44SJohn Forte 	}
1128fcf3ce44SJohn Forte 
1129fcf3ce44SJohn Forte 	if (inet_ntop(af, &prop.p_addr_list.al_addrs[0].a_addr.i_addr,
1130fcf3ce44SJohn Forte 	    static_target_addr_str, sizeof (static_target_addr_str)) == NULL) {
1131fcf3ce44SJohn Forte 		/* Should not happen */
1132fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1133fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET returned address that cannot "
1134fcf3ce44SJohn Forte 		    "be inet_ntop");
1135fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1136fcf3ce44SJohn Forte 	} else {
1137fcf3ce44SJohn Forte 		if (af == AF_INET) {
1138fcf3ce44SJohn Forte 			(void) snprintf(static_target_addr_port_str,
1139fcf3ce44SJohn Forte 			    SUN_IMA_IP_ADDRESS_LEN,
1140fcf3ce44SJohn Forte 			    "%s:%ld",
1141fcf3ce44SJohn Forte 			    static_target_addr_str,
1142fcf3ce44SJohn Forte 			    prop.p_addr_list.al_addrs[0].a_port);
1143fcf3ce44SJohn Forte 		} else {
1144fcf3ce44SJohn Forte 			(void) snprintf(static_target_addr_port_str,
1145fcf3ce44SJohn Forte 			    SUN_IMA_IP_ADDRESS_LEN,
1146fcf3ce44SJohn Forte 			    "[%s]:%ld",
1147fcf3ce44SJohn Forte 			    static_target_addr_str,
1148fcf3ce44SJohn Forte 			    prop.p_addr_list.al_addrs[0].a_port);
1149fcf3ce44SJohn Forte 		}
1150fcf3ce44SJohn Forte 		host = &pProps->staticTarget.targetAddress.hostnameIpAddress;
1151fcf3ce44SJohn Forte 		(void) mbstowcs(pProps->staticTarget.
1152fcf3ce44SJohn Forte 		    targetAddress.hostnameIpAddress.
1153fcf3ce44SJohn Forte 		    id.hostname, static_target_addr_port_str,
1154fcf3ce44SJohn Forte 		    sizeof (host->id.hostname) / sizeof (IMA_WCHAR));
1155fcf3ce44SJohn Forte 	}
1156fcf3ce44SJohn Forte 
1157fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1158fcf3ce44SJohn Forte }
1159fcf3ce44SJohn Forte 
1160fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetDiscoveryAddressProperties(IMA_OID discoveryAddressOid,IMA_DISCOVERY_ADDRESS_PROPERTIES * pProps)1161fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetDiscoveryAddressProperties(
1162fcf3ce44SJohn Forte 		IMA_OID	discoveryAddressOid,
1163fcf3ce44SJohn Forte 		IMA_DISCOVERY_ADDRESS_PROPERTIES *pProps
1164fcf3ce44SJohn Forte )
1165fcf3ce44SJohn Forte {
1166fcf3ce44SJohn Forte 	int fd;
1167fcf3ce44SJohn Forte 	int i;
1168fcf3ce44SJohn Forte 	int addr_list_size;
1169fcf3ce44SJohn Forte 	iscsi_addr_list_t *idlp, al_info;
1170fcf3ce44SJohn Forte 	iscsi_addr_t *matched_addr = NULL;
1171fcf3ce44SJohn Forte 	/* LINTED */
1172fcf3ce44SJohn Forte 	IMA_TARGET_ADDRESS *addr;
1173fcf3ce44SJohn Forte 
1174fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1175fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1176fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1177fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1178fcf3ce44SJohn Forte 	}
1179fcf3ce44SJohn Forte 
1180fcf3ce44SJohn Forte 	(void) memset(&al_info, 0, sizeof (al_info));
1181fcf3ce44SJohn Forte 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
1182fcf3ce44SJohn Forte 	al_info.al_in_cnt = 0;
1183fcf3ce44SJohn Forte 
1184fcf3ce44SJohn Forte 	/*
1185fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the number of discovery addresses.
1186fcf3ce44SJohn Forte 	 */
1187fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
1188fcf3ce44SJohn Forte 		(void) close(fd);
1189fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1190fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl %d failed, errno: %d",
1191fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
1192fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1193fcf3ce44SJohn Forte 	}
1194fcf3ce44SJohn Forte 
1195fcf3ce44SJohn Forte 	if (al_info.al_out_cnt == 0) {
1196fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
1197fcf3ce44SJohn Forte 	}
1198fcf3ce44SJohn Forte 
1199fcf3ce44SJohn Forte 	addr_list_size = sizeof (iscsi_addr_list_t);
1200fcf3ce44SJohn Forte 	if (al_info.al_out_cnt > 1) {
1201fcf3ce44SJohn Forte 		addr_list_size += (sizeof (iscsi_addr_list_t) *
1202fcf3ce44SJohn Forte 		    al_info.al_out_cnt - 1);
1203fcf3ce44SJohn Forte 	}
1204fcf3ce44SJohn Forte 
1205fcf3ce44SJohn Forte 	idlp = (iscsi_addr_list_t *)calloc(1, addr_list_size);
1206fcf3ce44SJohn Forte 	if (idlp == NULL) {
1207fcf3ce44SJohn Forte 		(void) close(fd);
1208fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
1209fcf3ce44SJohn Forte 	}
1210fcf3ce44SJohn Forte 
1211fcf3ce44SJohn Forte 	idlp->al_vers = ISCSI_INTERFACE_VERSION;
1212fcf3ce44SJohn Forte 	idlp->al_in_cnt = al_info.al_out_cnt;
1213fcf3ce44SJohn Forte 
1214fcf3ce44SJohn Forte 	/* Issue the same ioctl again to obtain the OIDs. */
1215fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, idlp) != 0) {
1216fcf3ce44SJohn Forte 		free(idlp);
1217fcf3ce44SJohn Forte 		(void) close(fd);
1218fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1219fcf3ce44SJohn Forte 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
1220fcf3ce44SJohn Forte 		    ISCSI_DISCOVERY_ADDR_LIST_GET, errno);
1221fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1222fcf3ce44SJohn Forte 	}
1223fcf3ce44SJohn Forte 
1224fcf3ce44SJohn Forte 	for (i = 0; i < idlp->al_out_cnt; i++) {
1225fcf3ce44SJohn Forte 		if (discoveryAddressOid.objectSequenceNumber !=
1226fcf3ce44SJohn Forte 		    idlp->al_addrs[i].a_oid)
1227fcf3ce44SJohn Forte 			continue;
1228fcf3ce44SJohn Forte 		matched_addr = &(idlp->al_addrs[i]);
1229fcf3ce44SJohn Forte 	}
1230fcf3ce44SJohn Forte 
1231fcf3ce44SJohn Forte 	if (matched_addr == NULL) {
1232fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
1233fcf3ce44SJohn Forte 	}
1234fcf3ce44SJohn Forte 
1235fcf3ce44SJohn Forte 	if (matched_addr->a_addr.i_insize == sizeof (struct in_addr)) {
1236fcf3ce44SJohn Forte 		pProps->discoveryAddress.hostnameIpAddress.id.
1237fcf3ce44SJohn Forte 		    ipAddress.ipv4Address = IMA_TRUE;
1238fcf3ce44SJohn Forte 	} else if (matched_addr->a_addr.i_insize == sizeof (struct in6_addr)) {
1239fcf3ce44SJohn Forte 		pProps->discoveryAddress.hostnameIpAddress.id.
1240fcf3ce44SJohn Forte 		    ipAddress.ipv4Address = IMA_FALSE;
1241fcf3ce44SJohn Forte 	} else {
1242fcf3ce44SJohn Forte 		/* Should not happen */
1243fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1244fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET returned bad address");
1245fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1246fcf3ce44SJohn Forte 	}
1247fcf3ce44SJohn Forte 
1248fcf3ce44SJohn Forte 	addr = &pProps->discoveryAddress;
1249fcf3ce44SJohn Forte 	bcopy(&(matched_addr->a_addr.i_addr), pProps->discoveryAddress.
1250fcf3ce44SJohn Forte 	    hostnameIpAddress.id.ipAddress.ipAddress,
1251fcf3ce44SJohn Forte 	    sizeof (addr->hostnameIpAddress.id.ipAddress.ipAddress));
1252fcf3ce44SJohn Forte 
1253fcf3ce44SJohn Forte 	pProps->discoveryAddress.portNumber = matched_addr->a_port;
1254fcf3ce44SJohn Forte 
1255fcf3ce44SJohn Forte 	pProps->associatedLhbaOid.objectType = IMA_OBJECT_TYPE_LHBA;
1256fcf3ce44SJohn Forte 	pProps->associatedLhbaOid.ownerId = pluginOwnerId;
1257fcf3ce44SJohn Forte 	pProps->associatedLhbaOid.objectSequenceNumber = ISCSI_INITIATOR_OID;
1258fcf3ce44SJohn Forte 
1259fcf3ce44SJohn Forte 	free(idlp);
1260fcf3ce44SJohn Forte 	(void) close(fd);
1261fcf3ce44SJohn Forte 
1262fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1263fcf3ce44SJohn Forte }
1264fcf3ce44SJohn Forte 
IMA_RemoveStaticDiscoveryTarget(IMA_OID staticTargetOid)1265fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_RemoveStaticDiscoveryTarget(
1266fcf3ce44SJohn Forte 		IMA_OID staticTargetOid
1267fcf3ce44SJohn Forte )
1268fcf3ce44SJohn Forte {
1269fcf3ce44SJohn Forte 	entry_t	entry;
1270fcf3ce44SJohn Forte 	int	status, fd;
1271fcf3ce44SJohn Forte 
1272fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1273fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1274fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1275fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1276fcf3ce44SJohn Forte 	}
1277fcf3ce44SJohn Forte 
1278fcf3ce44SJohn Forte 	(void) memset(&entry, 0, sizeof (entry_t));
1279fcf3ce44SJohn Forte 	entry.e_vers = ISCSI_INTERFACE_VERSION;
1280fcf3ce44SJohn Forte 	entry.e_oid = (uint32_t)staticTargetOid.objectSequenceNumber;
1281fcf3ce44SJohn Forte 
1282fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_STATIC_CLEAR, &entry)) {
1283fcf3ce44SJohn Forte 		status = errno;
1284fcf3ce44SJohn Forte 		(void) close(fd);
1285fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1286fcf3ce44SJohn Forte 		    "ISCSI_STATIC_CLEAR ioctl failed, errno: %d", errno);
1287fcf3ce44SJohn Forte 		if (status == EBUSY) {
1288fcf3ce44SJohn Forte 			return (IMA_ERROR_LU_IN_USE);
1289fcf3ce44SJohn Forte 		} else {
1290fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1291fcf3ce44SJohn Forte 		}
1292fcf3ce44SJohn Forte 	}
1293fcf3ce44SJohn Forte 
1294fcf3ce44SJohn Forte 	(void) close(fd);
1295fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1296fcf3ce44SJohn Forte }
1297fcf3ce44SJohn Forte 
1298fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_AddStaticDiscoveryTarget(IMA_OID lhbaOid,const IMA_STATIC_DISCOVERY_TARGET staticConfig,IMA_OID * pTargetOid)1299fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_AddStaticDiscoveryTarget(
1300fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
1301fcf3ce44SJohn Forte 		const IMA_STATIC_DISCOVERY_TARGET staticConfig,
1302fcf3ce44SJohn Forte 		IMA_OID *pTargetOid
1303fcf3ce44SJohn Forte )
1304fcf3ce44SJohn Forte {
1305fcf3ce44SJohn Forte 	char			tmp_target_str[SUN_IMA_IP_ADDRESS_LEN];
1306fcf3ce44SJohn Forte 	char			target_addr_str[SUN_IMA_IP_ADDRESS_LEN];
1307fcf3ce44SJohn Forte 	char			target_port_str[SUN_IMA_IP_PORT_LEN];
1308fcf3ce44SJohn Forte 	iscsi_target_entry_t	target;
1309fcf3ce44SJohn Forte 	int			fd;
1310fcf3ce44SJohn Forte 	int			target_in_addr_size;
1311fcf3ce44SJohn Forte 	int			target_port;
1312fcf3ce44SJohn Forte 	union {
1313fcf3ce44SJohn Forte 		struct in_addr	u_in4;
1314fcf3ce44SJohn Forte 		struct in6_addr	u_in6;
1315fcf3ce44SJohn Forte 	}			target_in;
1316fcf3ce44SJohn Forte 
1317fcf3ce44SJohn Forte 	/*
1318fcf3ce44SJohn Forte 	 * staticConfig.address may come in with port number at its trailer.
1319fcf3ce44SJohn Forte 	 * Parse it to separate the IP address and port number.
1320fcf3ce44SJohn Forte 	 * Also translate the hostname to IP address if needed.
1321fcf3ce44SJohn Forte 	 */
1322fcf3ce44SJohn Forte 	(void) wcstombs(tmp_target_str,
1323fcf3ce44SJohn Forte 	    staticConfig.targetAddress.hostnameIpAddress.
1324fcf3ce44SJohn Forte 	    id.hostname, sizeof (tmp_target_str));
1325fcf3ce44SJohn Forte 
1326fcf3ce44SJohn Forte 	if (tmp_target_str[0] == '[') {
1327fcf3ce44SJohn Forte 		/* IPv6 address */
1328fcf3ce44SJohn Forte 		char *closeBracketPos;
1329fcf3ce44SJohn Forte 		closeBracketPos = strchr(tmp_target_str, ']');
1330fcf3ce44SJohn Forte 		if (!closeBracketPos) {
1331fcf3ce44SJohn Forte 			return (IMA_ERROR_INVALID_PARAMETER);
1332fcf3ce44SJohn Forte 		}
1333fcf3ce44SJohn Forte 
1334fcf3ce44SJohn Forte 		*closeBracketPos = NULL;
1335fcf3ce44SJohn Forte 		(void) strlcpy(target_addr_str, &tmp_target_str[1],
1336fcf3ce44SJohn Forte 		    sizeof (target_addr_str));
1337fcf3ce44SJohn Forte 
1338fcf3ce44SJohn Forte 		if (inet_pton(AF_INET6, target_addr_str,
1339fcf3ce44SJohn Forte 		    &target_in.u_in6) != 1) {
1340fcf3ce44SJohn Forte 			return (IMA_ERROR_INVALID_PARAMETER);
1341fcf3ce44SJohn Forte 		}
1342fcf3ce44SJohn Forte 		target_in_addr_size = sizeof (struct in6_addr);
1343fcf3ce44SJohn Forte 
1344fcf3ce44SJohn Forte 		/* Extract the port number */
1345fcf3ce44SJohn Forte 		closeBracketPos++;
1346fcf3ce44SJohn Forte 		if (*closeBracketPos == ':') {
1347fcf3ce44SJohn Forte 			closeBracketPos++;
1348fcf3ce44SJohn Forte 
1349fcf3ce44SJohn Forte 			if (*closeBracketPos != NULL) {
1350fcf3ce44SJohn Forte 				(void) strlcpy(target_port_str, closeBracketPos,
1351fcf3ce44SJohn Forte 				    sizeof (target_port_str));
1352fcf3ce44SJohn Forte 				target_port = atoi(target_port_str);
1353fcf3ce44SJohn Forte 			} else {
1354fcf3ce44SJohn Forte 				target_port = ISCSI_LISTEN_PORT;
1355fcf3ce44SJohn Forte 			}
1356fcf3ce44SJohn Forte 		} else {
1357fcf3ce44SJohn Forte 			/* No port number specified; use default port */
1358fcf3ce44SJohn Forte 			target_port = ISCSI_LISTEN_PORT;
1359fcf3ce44SJohn Forte 		}
1360fcf3ce44SJohn Forte 	} else {
1361fcf3ce44SJohn Forte 		/* IPv4 address */
1362fcf3ce44SJohn Forte 		char *colonPos;
1363fcf3ce44SJohn Forte 		colonPos = strchr(tmp_target_str, ':');
1364fcf3ce44SJohn Forte 		if (!colonPos) {
1365fcf3ce44SJohn Forte 			/* No port number specified; use default port */
1366fcf3ce44SJohn Forte 			target_port = ISCSI_LISTEN_PORT;
1367fcf3ce44SJohn Forte 			(void) strlcpy(target_addr_str, tmp_target_str,
1368fcf3ce44SJohn Forte 			    sizeof (target_addr_str));
1369fcf3ce44SJohn Forte 		} else {
1370fcf3ce44SJohn Forte 			*colonPos = NULL;
1371fcf3ce44SJohn Forte 			(void) strlcpy(target_addr_str, tmp_target_str,
1372fcf3ce44SJohn Forte 			    sizeof (target_addr_str));
1373fcf3ce44SJohn Forte 			/* Extract the port number */
1374fcf3ce44SJohn Forte 			colonPos++;
1375fcf3ce44SJohn Forte 			if (*colonPos != NULL) {
1376fcf3ce44SJohn Forte 				(void) strlcpy(target_port_str, colonPos,
1377fcf3ce44SJohn Forte 				    sizeof (target_port_str));
1378fcf3ce44SJohn Forte 				target_port = atoi(target_port_str);
1379fcf3ce44SJohn Forte 			} else {
1380fcf3ce44SJohn Forte 				target_port = ISCSI_LISTEN_PORT;
1381fcf3ce44SJohn Forte 			}
1382fcf3ce44SJohn Forte 		}
1383fcf3ce44SJohn Forte 
1384fcf3ce44SJohn Forte 		if (inet_pton(AF_INET, target_addr_str,
1385fcf3ce44SJohn Forte 		    &target_in.u_in4) != 1) {
1386fcf3ce44SJohn Forte 			return (IMA_ERROR_INVALID_PARAMETER);
1387fcf3ce44SJohn Forte 		}
1388fcf3ce44SJohn Forte 
1389fcf3ce44SJohn Forte 		target_in_addr_size = sizeof (struct in_addr);
1390fcf3ce44SJohn Forte 	}
1391fcf3ce44SJohn Forte 
1392fcf3ce44SJohn Forte 
1393fcf3ce44SJohn Forte 	(void) memset(&target, 0, sizeof (iscsi_target_entry_t));
1394fcf3ce44SJohn Forte 	target.te_entry.e_vers = ISCSI_INTERFACE_VERSION;
1395fcf3ce44SJohn Forte 	target.te_entry.e_oid = ISCSI_OID_NOTSET;
1396fcf3ce44SJohn Forte 	target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT;
1397fcf3ce44SJohn Forte 
1398fcf3ce44SJohn Forte 	(void) wcstombs((char *)target.te_name, staticConfig.targetName,
1399fcf3ce44SJohn Forte 	    ISCSI_MAX_NAME_LEN);
1400fcf3ce44SJohn Forte 
1401fcf3ce44SJohn Forte 	target.te_entry.e_insize = target_in_addr_size;
1402fcf3ce44SJohn Forte 	if (target.te_entry.e_insize == sizeof (struct in_addr)) {
1403fcf3ce44SJohn Forte 		target.te_entry.e_u.u_in4.s_addr = target_in.u_in4.s_addr;
1404fcf3ce44SJohn Forte 	} else if (target.te_entry.e_insize == sizeof (struct in6_addr)) {
1405fcf3ce44SJohn Forte 		bcopy(target_in.u_in6.s6_addr,
1406fcf3ce44SJohn Forte 		    target.te_entry.e_u.u_in6.s6_addr,
1407fcf3ce44SJohn Forte 		    sizeof (struct in6_addr));
1408fcf3ce44SJohn Forte 	} else {
1409fcf3ce44SJohn Forte 		/* Should not happen */
1410fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1411fcf3ce44SJohn Forte 		    "ISCSI_STATIC_GET returned bad address");
1412fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1413fcf3ce44SJohn Forte 	}
1414fcf3ce44SJohn Forte 
1415fcf3ce44SJohn Forte 	target.te_entry.e_port = target_port;
1416fcf3ce44SJohn Forte 
1417fcf3ce44SJohn Forte 	/* No target portal group specified. Default to -1. */
1418fcf3ce44SJohn Forte 	target.te_entry.e_tpgt = ISCSI_DEFAULT_TPGT;
1419fcf3ce44SJohn Forte 
1420fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1421fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1422fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1423fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1424fcf3ce44SJohn Forte 	}
1425fcf3ce44SJohn Forte 
1426fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_STATIC_SET, &target)) {
1427fcf3ce44SJohn Forte 		/*
1428fcf3ce44SJohn Forte 		 * Encountered problem setting the IP address and port for
1429fcf3ce44SJohn Forte 		 * the target just added.
1430fcf3ce44SJohn Forte 		 */
1431fcf3ce44SJohn Forte 		(void) close(fd);
1432fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1433fcf3ce44SJohn Forte 		    "ISCSI_STATIC_SET ioctl failed, errno: %d", errno);
1434fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1435fcf3ce44SJohn Forte 	}
1436fcf3ce44SJohn Forte 
1437fcf3ce44SJohn Forte 	pTargetOid->objectType = IMA_OBJECT_TYPE_TARGET;
1438fcf3ce44SJohn Forte 	pTargetOid->ownerId = pluginOwnerId;
1439fcf3ce44SJohn Forte 	pTargetOid->objectSequenceNumber = target.te_entry.e_oid;
1440fcf3ce44SJohn Forte 
1441fcf3ce44SJohn Forte 	(void) close(fd);
1442fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1443fcf3ce44SJohn Forte }
1444fcf3ce44SJohn Forte 
IMA_GetTargetProperties(IMA_OID targetId,IMA_TARGET_PROPERTIES * pProps)1445fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetTargetProperties(
1446fcf3ce44SJohn Forte 		IMA_OID targetId,
1447fcf3ce44SJohn Forte 		IMA_TARGET_PROPERTIES *pProps
1448fcf3ce44SJohn Forte )
1449fcf3ce44SJohn Forte {
1450fcf3ce44SJohn Forte 	return (getTargetProperties(targetId, pProps));
1451fcf3ce44SJohn Forte }
1452fcf3ce44SJohn Forte 
getTargetProperties(IMA_OID targetId,IMA_TARGET_PROPERTIES * pProps)1453fcf3ce44SJohn Forte static IMA_STATUS getTargetProperties(
1454fcf3ce44SJohn Forte 		IMA_OID targetId,
1455fcf3ce44SJohn Forte 		IMA_TARGET_PROPERTIES *pProps
1456fcf3ce44SJohn Forte )
1457fcf3ce44SJohn Forte {
1458fcf3ce44SJohn Forte 	int		    fd;
1459fcf3ce44SJohn Forte 	iscsi_property_t    prop;
1460fcf3ce44SJohn Forte 
1461fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1462fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1463fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1464fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1465fcf3ce44SJohn Forte 	}
1466fcf3ce44SJohn Forte 
1467fcf3ce44SJohn Forte 	(void) memset(&prop, 0, sizeof (iscsi_property_t));
1468fcf3ce44SJohn Forte 	prop.p_vers = ISCSI_INTERFACE_VERSION;
1469fcf3ce44SJohn Forte 	prop.p_oid = (uint32_t)targetId.objectSequenceNumber;
1470fcf3ce44SJohn Forte 
1471fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_TARGET_PROPS_GET, &prop) != 0) {
1472fcf3ce44SJohn Forte 		(void) close(fd);
1473fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1474fcf3ce44SJohn Forte 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
1475fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1476fcf3ce44SJohn Forte 	}
1477fcf3ce44SJohn Forte 
1478fcf3ce44SJohn Forte 	(void) mbstowcs(pProps->name, (char *)prop.p_name, IMA_NODE_NAME_LEN);
1479fcf3ce44SJohn Forte 	(void) memset(pProps->alias, 0,
1480fcf3ce44SJohn Forte 	    sizeof (IMA_WCHAR) * IMA_NODE_ALIAS_LEN);
1481fcf3ce44SJohn Forte 	if (prop.p_alias_len > 0) {
1482fcf3ce44SJohn Forte 		(void) mbstowcs(pProps->alias, (char *)prop.p_alias,
1483fcf3ce44SJohn Forte 		    IMA_NODE_ALIAS_LEN);
1484fcf3ce44SJohn Forte 	}
1485fcf3ce44SJohn Forte 
1486fcf3ce44SJohn Forte 	/* Initialize the discovery method to unknown method. */
1487fcf3ce44SJohn Forte 	pProps->discoveryMethodFlags = IMA_TARGET_DISCOVERY_METHOD_UNKNOWN;
1488fcf3ce44SJohn Forte 	if (!((prop.p_discovery & iSCSIDiscoveryMethodStatic) ^
1489fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodStatic)) {
1490fcf3ce44SJohn Forte 		pProps->discoveryMethodFlags |=
1491fcf3ce44SJohn Forte 		    IMA_TARGET_DISCOVERY_METHOD_STATIC;
1492fcf3ce44SJohn Forte 	}
1493fcf3ce44SJohn Forte 
1494fcf3ce44SJohn Forte 	if (!((prop.p_discovery & iSCSIDiscoveryMethodSLP) ^
1495fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodSLP)) {
1496fcf3ce44SJohn Forte 		pProps->discoveryMethodFlags |=	IMA_TARGET_DISCOVERY_METHOD_SLP;
1497fcf3ce44SJohn Forte 	}
1498fcf3ce44SJohn Forte 
1499fcf3ce44SJohn Forte 	if (!((prop.p_discovery & iSCSIDiscoveryMethodISNS) ^
1500fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodISNS)) {
1501fcf3ce44SJohn Forte 		pProps->discoveryMethodFlags |=	iSCSIDiscoveryMethodISNS;
1502fcf3ce44SJohn Forte 	}
1503fcf3ce44SJohn Forte 
1504fcf3ce44SJohn Forte 	if (!((prop.p_discovery & iSCSIDiscoveryMethodSendTargets) ^
1505fcf3ce44SJohn Forte 	    iSCSIDiscoveryMethodSendTargets)) {
1506fcf3ce44SJohn Forte 		pProps->discoveryMethodFlags |= iSCSIDiscoveryMethodSendTargets;
1507fcf3ce44SJohn Forte 	}
1508fcf3ce44SJohn Forte 
1509fcf3ce44SJohn Forte 	(void) close(fd);
1510fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1511fcf3ce44SJohn Forte }
1512fcf3ce44SJohn Forte 
1513fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetTargetErrorStatistics(IMA_OID targetId,IMA_TARGET_ERROR_STATISTICS * pStats)1514fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetTargetErrorStatistics(
1515fcf3ce44SJohn Forte 		IMA_OID targetId,
1516fcf3ce44SJohn Forte 		IMA_TARGET_ERROR_STATISTICS *pStats
1517fcf3ce44SJohn Forte )
1518fcf3ce44SJohn Forte {
1519fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
1520fcf3ce44SJohn Forte }
1521fcf3ce44SJohn Forte 
IMA_GetLuOidList(IMA_OID oid,IMA_OID_LIST ** ppList)1522fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetLuOidList(
1523fcf3ce44SJohn Forte 		IMA_OID oid,
1524fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
1525fcf3ce44SJohn Forte )
1526fcf3ce44SJohn Forte {
1527fcf3ce44SJohn Forte 	IMA_STATUS		status;
1528fcf3ce44SJohn Forte 	int			i;
1529fcf3ce44SJohn Forte 	iscsi_lun_list_t	*pLunList;
1530fcf3ce44SJohn Forte 
1531fcf3ce44SJohn Forte 	if (oid.objectType == IMA_OBJECT_TYPE_LHBA) {
1532fcf3ce44SJohn Forte 		status = get_target_lun_oid_list(NULL, &pLunList);
1533fcf3ce44SJohn Forte 	} else {
1534fcf3ce44SJohn Forte 		status = get_target_lun_oid_list(&oid, &pLunList);
1535fcf3ce44SJohn Forte 	}
1536fcf3ce44SJohn Forte 
1537fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1538fcf3ce44SJohn Forte 		return (status);
1539fcf3ce44SJohn Forte 	}
1540fcf3ce44SJohn Forte 
1541fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST) +
1542fcf3ce44SJohn Forte 	    (pLunList->ll_out_cnt * sizeof (IMA_OID))));
1543fcf3ce44SJohn Forte 	if (*ppList == NULL) {
1544fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
1545fcf3ce44SJohn Forte 	}
1546fcf3ce44SJohn Forte 	(*ppList)->oidCount = pLunList->ll_out_cnt;
1547fcf3ce44SJohn Forte 	for (i = 0; i < pLunList->ll_out_cnt; i++) {
1548fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_LU;
1549fcf3ce44SJohn Forte 		(*ppList)->oids[i].ownerId = pluginOwnerId;
1550fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectSequenceNumber =
1551fcf3ce44SJohn Forte 		    pLunList->ll_luns[i].l_oid;
1552fcf3ce44SJohn Forte 	}
1553fcf3ce44SJohn Forte 
1554fcf3ce44SJohn Forte 	free(pLunList);
1555fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1556fcf3ce44SJohn Forte }
1557fcf3ce44SJohn Forte 
IMA_GetLuOid(IMA_OID targetId,IMA_UINT64 lun,IMA_OID * pluId)1558fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetLuOid(
1559fcf3ce44SJohn Forte 		IMA_OID targetId,
1560fcf3ce44SJohn Forte 		IMA_UINT64 lun,
1561fcf3ce44SJohn Forte 		IMA_OID *pluId
1562fcf3ce44SJohn Forte )
1563fcf3ce44SJohn Forte {
1564fcf3ce44SJohn Forte 	IMA_STATUS		status;
1565fcf3ce44SJohn Forte 	int			i;
1566fcf3ce44SJohn Forte 	iscsi_lun_list_t	*pLunList;
1567fcf3ce44SJohn Forte 
1568fcf3ce44SJohn Forte 	status = get_target_lun_oid_list(&targetId, &pLunList);
1569fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1570fcf3ce44SJohn Forte 		return (status);
1571fcf3ce44SJohn Forte 	}
1572fcf3ce44SJohn Forte 
1573fcf3ce44SJohn Forte 	for (i = 0; i < pLunList->ll_out_cnt; i++) {
1574fcf3ce44SJohn Forte 		if (pLunList->ll_luns[i].l_num == lun) {
1575fcf3ce44SJohn Forte 			pluId->objectType = IMA_OBJECT_TYPE_LU;
1576fcf3ce44SJohn Forte 			pluId->ownerId = pluginOwnerId;
1577fcf3ce44SJohn Forte 			pluId->objectSequenceNumber =
1578fcf3ce44SJohn Forte 			    pLunList->ll_luns[i].l_oid;
1579fcf3ce44SJohn Forte 			free(pLunList);
1580fcf3ce44SJohn Forte 			return (IMA_STATUS_SUCCESS);
1581fcf3ce44SJohn Forte 		}
1582fcf3ce44SJohn Forte 	}
1583fcf3ce44SJohn Forte 
1584fcf3ce44SJohn Forte 	free(pLunList);
1585fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
1586fcf3ce44SJohn Forte }
1587fcf3ce44SJohn Forte 
IMA_GetLuProperties(IMA_OID luId,IMA_LU_PROPERTIES * pProps)1588fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetLuProperties(
1589fcf3ce44SJohn Forte 		IMA_OID luId,
1590fcf3ce44SJohn Forte 		IMA_LU_PROPERTIES *pProps
1591fcf3ce44SJohn Forte )
1592fcf3ce44SJohn Forte {
1593fcf3ce44SJohn Forte 	return (getLuProperties(luId, pProps));
1594fcf3ce44SJohn Forte }
1595fcf3ce44SJohn Forte 
getLuProperties(IMA_OID luId,IMA_LU_PROPERTIES * pProps)1596fcf3ce44SJohn Forte static IMA_STATUS getLuProperties(
1597fcf3ce44SJohn Forte 		IMA_OID luId,
1598fcf3ce44SJohn Forte 		IMA_LU_PROPERTIES *pProps
1599fcf3ce44SJohn Forte )
1600fcf3ce44SJohn Forte {
1601fcf3ce44SJohn Forte 	IMA_STATUS		status;
1602fcf3ce44SJohn Forte 	iscsi_lun_list_t	*pLunList;
1603fcf3ce44SJohn Forte 	int			j;
1604fcf3ce44SJohn Forte 	IMA_BOOL		lunMatch = IMA_FALSE;
1605fcf3ce44SJohn Forte 	int			fd;
1606fcf3ce44SJohn Forte 	iscsi_lun_props_t	lun;
1607fcf3ce44SJohn Forte 	di_devlink_handle_t	hdl;
1608fcf3ce44SJohn Forte 
1609fcf3ce44SJohn Forte 	if (luId.objectType != IMA_OBJECT_TYPE_LU) {
1610fcf3ce44SJohn Forte 		return (IMA_ERROR_INCORRECT_OBJECT_TYPE);
1611fcf3ce44SJohn Forte 	}
1612fcf3ce44SJohn Forte 
1613fcf3ce44SJohn Forte 	/*
1614fcf3ce44SJohn Forte 	 * get list of lun oids for all targets
1615fcf3ce44SJohn Forte 	 */
1616fcf3ce44SJohn Forte 	status = get_target_lun_oid_list(NULL, &pLunList);
1617fcf3ce44SJohn Forte 	if (!IMA_SUCCESS(status)) {
1618fcf3ce44SJohn Forte 		return (status);
1619fcf3ce44SJohn Forte 	}
1620fcf3ce44SJohn Forte 	for (j = 0; j < pLunList->ll_out_cnt; j++) {
1621fcf3ce44SJohn Forte 		/*
1622fcf3ce44SJohn Forte 		 * for each lun, check if match is found
1623fcf3ce44SJohn Forte 		 */
1624fcf3ce44SJohn Forte 		if (pLunList->ll_luns[j].l_oid == luId.objectSequenceNumber) {
1625fcf3ce44SJohn Forte 			/*
1626fcf3ce44SJohn Forte 			 * match found, break out of lun loop
1627fcf3ce44SJohn Forte 			 */
1628fcf3ce44SJohn Forte 			lunMatch = IMA_TRUE;
1629fcf3ce44SJohn Forte 			break;
1630fcf3ce44SJohn Forte 		}
1631fcf3ce44SJohn Forte 	}
1632fcf3ce44SJohn Forte 
1633fcf3ce44SJohn Forte 	if (lunMatch == IMA_TRUE) {
1634fcf3ce44SJohn Forte 		(void) memset(&lun, 0, sizeof (iscsi_lun_props_t));
1635fcf3ce44SJohn Forte 		lun.lp_vers = ISCSI_INTERFACE_VERSION;
1636fcf3ce44SJohn Forte 		lun.lp_tgt_oid = pLunList->ll_luns[j].l_tgt_oid;
1637fcf3ce44SJohn Forte 		lun.lp_oid = pLunList->ll_luns[j].l_oid;
1638fcf3ce44SJohn Forte 	}
1639fcf3ce44SJohn Forte 
1640fcf3ce44SJohn Forte 	free(pLunList);
1641fcf3ce44SJohn Forte 
1642fcf3ce44SJohn Forte 	if (lunMatch == IMA_FALSE) {
1643fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
1644fcf3ce44SJohn Forte 	}
1645fcf3ce44SJohn Forte 
1646fcf3ce44SJohn Forte 	/*
1647fcf3ce44SJohn Forte 	 * get lun properties
1648fcf3ce44SJohn Forte 	 */
1649fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1650fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1651fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1652fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1653fcf3ce44SJohn Forte 	}
1654fcf3ce44SJohn Forte 
1655fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_LUN_PROPS_GET, &lun)) {
1656fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1657fcf3ce44SJohn Forte 		    "ISCSI_LUN_PROPS_GET ioctl failed, errno: %d", errno);
1658fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1659fcf3ce44SJohn Forte 	}
1660fcf3ce44SJohn Forte 	(void) close(fd);
1661fcf3ce44SJohn Forte 
1662fcf3ce44SJohn Forte 	/*
1663fcf3ce44SJohn Forte 	 * set property values
1664fcf3ce44SJohn Forte 	 */
1665fcf3ce44SJohn Forte 	pProps->associatedTargetOid.objectType = IMA_OBJECT_TYPE_TARGET;
1666fcf3ce44SJohn Forte 	pProps->associatedTargetOid.ownerId = pluginOwnerId;
1667fcf3ce44SJohn Forte 	pProps->associatedTargetOid.objectSequenceNumber = lun.lp_tgt_oid;
1668fcf3ce44SJohn Forte 	pProps->targetLun = (IMA_UINT64)lun.lp_num;
1669fcf3ce44SJohn Forte 	pProps->exposedToOs = IMA_TRUE;
1670fcf3ce44SJohn Forte 	(void) memset(&pProps->timeExposedToOs, 0,
1671fcf3ce44SJohn Forte 	    sizeof (pProps->timeExposedToOs));
1672fcf3ce44SJohn Forte 
1673fcf3ce44SJohn Forte 	if (lun.lp_status == LunValid) {
1674fcf3ce44SJohn Forte 
1675fcf3ce44SJohn Forte 		/* add minor device delimiter */
1676fcf3ce44SJohn Forte 		(void) strcat(lun.lp_pathname, ":");
1677fcf3ce44SJohn Forte 
1678fcf3ce44SJohn Forte 		if ((strstr(lun.lp_pathname, "sd@") != NULL) ||
1679fcf3ce44SJohn Forte 		    (strstr(lun.lp_pathname, "ssd@") != NULL) ||
1680fcf3ce44SJohn Forte 		    (strstr(lun.lp_pathname, "disk@") != NULL)) {
1681fcf3ce44SJohn Forte 			/*
1682fcf3ce44SJohn Forte 			 * modify returned pathname to obtain the 2nd slice
1683fcf3ce44SJohn Forte 			 * of the raw disk
1684fcf3ce44SJohn Forte 			 */
1685fcf3ce44SJohn Forte 			(void) strcat(lun.lp_pathname, "c,raw");
1686fcf3ce44SJohn Forte 		}
1687fcf3ce44SJohn Forte 
1688fcf3ce44SJohn Forte 		/*
1689fcf3ce44SJohn Forte 		 * Pathname returned by driver is the physical device path.
1690fcf3ce44SJohn Forte 		 * This name needs to be converted to the OS device name.
1691fcf3ce44SJohn Forte 		 */
1692fcf3ce44SJohn Forte 		if (hdl = di_devlink_init(lun.lp_pathname, DI_MAKE_LINK)) {
1693fcf3ce44SJohn Forte 			pProps->osDeviceName[0] = L'\0';
1694fcf3ce44SJohn Forte 			(void) di_devlink_walk(hdl, NULL, lun.lp_pathname,
1695fcf3ce44SJohn Forte 			    DI_PRIMARY_LINK, (void *)pProps->osDeviceName,
1696fcf3ce44SJohn Forte 			    get_lun_devlink);
1697fcf3ce44SJohn Forte 			if (pProps->osDeviceName[0] != L'\0') {
1698fcf3ce44SJohn Forte 				/* OS device name synchronously made */
1699fcf3ce44SJohn Forte 				pProps->osDeviceNameValid = IMA_TRUE;
1700fcf3ce44SJohn Forte 			} else {
1701fcf3ce44SJohn Forte 				pProps->osDeviceNameValid = IMA_FALSE;
1702fcf3ce44SJohn Forte 			}
1703fcf3ce44SJohn Forte 
1704fcf3ce44SJohn Forte 			(void) di_devlink_fini(&hdl);
1705fcf3ce44SJohn Forte 		} else {
1706fcf3ce44SJohn Forte 			pProps->osDeviceNameValid = IMA_FALSE;
1707fcf3ce44SJohn Forte 		}
1708fcf3ce44SJohn Forte 
1709fcf3ce44SJohn Forte 	} else {
1710fcf3ce44SJohn Forte 		pProps->osDeviceNameValid = IMA_FALSE;
1711fcf3ce44SJohn Forte 	}
1712fcf3ce44SJohn Forte 
1713fcf3ce44SJohn Forte 	pProps->osParallelIdsValid = IMA_FALSE;
1714fcf3ce44SJohn Forte 
1715fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1716fcf3ce44SJohn Forte }
1717fcf3ce44SJohn Forte 
1718fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetStatisticsProperties(IMA_OID oid,IMA_STATISTICS_PROPERTIES * pProps)1719fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetStatisticsProperties(
1720fcf3ce44SJohn Forte 		IMA_OID oid,
1721fcf3ce44SJohn Forte 		IMA_STATISTICS_PROPERTIES *pProps
1722fcf3ce44SJohn Forte )
1723fcf3ce44SJohn Forte {
1724fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
1725fcf3ce44SJohn Forte }
1726fcf3ce44SJohn Forte 
1727fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetDeviceStatistics(IMA_OID luId,IMA_DEVICE_STATISTICS * pStats)1728fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetDeviceStatistics(
1729fcf3ce44SJohn Forte 		IMA_OID luId,
1730fcf3ce44SJohn Forte 		IMA_DEVICE_STATISTICS *pStats
1731fcf3ce44SJohn Forte )
1732fcf3ce44SJohn Forte {
1733fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
1734fcf3ce44SJohn Forte }
1735fcf3ce44SJohn Forte 
IMA_LuInquiry(IMA_OID deviceId,IMA_BOOL evpd,IMA_BOOL cmddt,IMA_BYTE pageCode,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)1736fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_LuInquiry(
1737fcf3ce44SJohn Forte 	IMA_OID deviceId,
1738fcf3ce44SJohn Forte 	IMA_BOOL evpd,
1739fcf3ce44SJohn Forte 	IMA_BOOL cmddt,
1740fcf3ce44SJohn Forte 	IMA_BYTE pageCode,
1741fcf3ce44SJohn Forte 	IMA_BYTE *pOutputBuffer,
1742fcf3ce44SJohn Forte 	IMA_UINT *pOutputBufferLength,
1743fcf3ce44SJohn Forte 	IMA_BYTE *pSenseBuffer,
1744fcf3ce44SJohn Forte 	IMA_UINT *pSenseBufferLength
1745fcf3ce44SJohn Forte )
1746fcf3ce44SJohn Forte {
1747fcf3ce44SJohn Forte 	IMA_LU_PROPERTIES luProps;
1748fcf3ce44SJohn Forte 	IMA_STATUS status;
1749146832dbSMilos Muzik 	unsigned char cmdblk[CDB_GROUP0];
1750146832dbSMilos Muzik 	IMA_UINT buflen;
1751fcf3ce44SJohn Forte 	int fd;
1752fcf3ce44SJohn Forte 	iscsi_uscsi_t uscsi;
1753fcf3ce44SJohn Forte 
1754146832dbSMilos Muzik 	(void) memset(&cmdblk[0], 0, CDB_GROUP0);
1755146832dbSMilos Muzik 	cmdblk[0] = SCMD_INQUIRY;
1756146832dbSMilos Muzik 
1757146832dbSMilos Muzik 	if (evpd == IMA_TRUE)
1758146832dbSMilos Muzik 		cmdblk[1] |= 0x01;
1759146832dbSMilos Muzik 	if (cmddt == IMA_TRUE)
1760146832dbSMilos Muzik 		cmdblk[1] |= 0x02;
1761146832dbSMilos Muzik 
1762fcf3ce44SJohn Forte 	cmdblk[2] = pageCode;
1763fcf3ce44SJohn Forte 
1764146832dbSMilos Muzik 	if (*pOutputBufferLength > MAX_INQUIRY_BUFFER_LEN) {
1765146832dbSMilos Muzik 		buflen = MAX_INQUIRY_BUFFER_LEN;
1766146832dbSMilos Muzik 	} else {
1767146832dbSMilos Muzik 		buflen = *pOutputBufferLength;
1768146832dbSMilos Muzik 	}
1769146832dbSMilos Muzik 	cmdblk[3] = (buflen & 0xff00) >> 8;
1770146832dbSMilos Muzik 	cmdblk[4] = (buflen & 0x00ff);
1771146832dbSMilos Muzik 
1772fcf3ce44SJohn Forte 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
1773fcf3ce44SJohn Forte 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
1774fcf3ce44SJohn Forte 
1775fcf3ce44SJohn Forte 	/* iu_oid is a session oid in the driver */
1776fcf3ce44SJohn Forte 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
1777fcf3ce44SJohn Forte 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
1778fcf3ce44SJohn Forte 		uscsi.iu_lun	= 0;
1779fcf3ce44SJohn Forte 	} else {
1780fcf3ce44SJohn Forte 		/*
1781fcf3ce44SJohn Forte 		 * Get LU properties and associated session oid
1782fcf3ce44SJohn Forte 		 * for this lun(deviceId) and put in uscsi.iu_oid
1783fcf3ce44SJohn Forte 		 */
1784fcf3ce44SJohn Forte 		status = getLuProperties(deviceId, &luProps);
1785fcf3ce44SJohn Forte 		if (status != IMA_STATUS_SUCCESS) {
1786fcf3ce44SJohn Forte 			return (status);
1787fcf3ce44SJohn Forte 		}
1788fcf3ce44SJohn Forte 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
1789fcf3ce44SJohn Forte 		    objectSequenceNumber;
1790fcf3ce44SJohn Forte 		uscsi.iu_lun = luProps.targetLun;
1791fcf3ce44SJohn Forte 	}
1792fcf3ce44SJohn Forte 
1793fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
1794fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
1795fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
1796146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_buflen = buflen;
1797fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
1798146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
1799146832dbSMilos Muzik 	    *pSenseBufferLength : 0;
1800146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
1801146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdblen = CDB_GROUP0;
1802fcf3ce44SJohn Forte 
1803fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1804fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1805fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1806fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1807fcf3ce44SJohn Forte 	}
1808fcf3ce44SJohn Forte 
1809fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
1810fcf3ce44SJohn Forte 		(void) close(fd);
1811fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1812fcf3ce44SJohn Forte 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
1813fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1814fcf3ce44SJohn Forte 	}
1815fcf3ce44SJohn Forte 
1816146832dbSMilos Muzik 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
1817146832dbSMilos Muzik 		if (pSenseBufferLength != NULL) {
1818146832dbSMilos Muzik 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
1819146832dbSMilos Muzik 		}
1820146832dbSMilos Muzik 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
1821146832dbSMilos Muzik 	}
1822146832dbSMilos Muzik 
1823146832dbSMilos Muzik 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
1824fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1825fcf3ce44SJohn Forte }
1826fcf3ce44SJohn Forte 
IMA_LuReadCapacity(IMA_OID deviceId,IMA_UINT cdbLength,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)1827fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_LuReadCapacity(
1828fcf3ce44SJohn Forte 		IMA_OID deviceId,
1829fcf3ce44SJohn Forte 		IMA_UINT cdbLength,
1830fcf3ce44SJohn Forte 		IMA_BYTE *pOutputBuffer,
1831fcf3ce44SJohn Forte 		IMA_UINT *pOutputBufferLength,
1832fcf3ce44SJohn Forte 
1833fcf3ce44SJohn Forte 		IMA_BYTE *pSenseBuffer,
1834fcf3ce44SJohn Forte 		IMA_UINT *pSenseBufferLength
1835fcf3ce44SJohn Forte )
1836fcf3ce44SJohn Forte {
1837fcf3ce44SJohn Forte 	IMA_LU_PROPERTIES luProps;
1838fcf3ce44SJohn Forte 	IMA_STATUS status;
1839146832dbSMilos Muzik 	/* CDB_GROUP4 size is safe for both 10 and 16 byte CDBs */
1840146832dbSMilos Muzik 	unsigned char cmdblk[CDB_GROUP4];
1841146832dbSMilos Muzik 	IMA_UINT buflen;
1842fcf3ce44SJohn Forte 	int fd;
1843fcf3ce44SJohn Forte 	iscsi_uscsi_t uscsi;
1844fcf3ce44SJohn Forte 
1845146832dbSMilos Muzik 	(void) memset(&cmdblk[0], 0, CDB_GROUP4);
1846fcf3ce44SJohn Forte 
1847146832dbSMilos Muzik 	if (cdbLength == CDB_GROUP1) {
1848146832dbSMilos Muzik 		/* Read Capacity (10) command. */
1849146832dbSMilos Muzik 		cmdblk[0] = SCMD_READ_CAPACITY;
1850146832dbSMilos Muzik 		buflen = *pOutputBufferLength;
1851146832dbSMilos Muzik 	} else if (cdbLength == CDB_GROUP4) {
1852146832dbSMilos Muzik 		/*
1853146832dbSMilos Muzik 		 * Read Capacity (16) is a Service Action In command. One
1854146832dbSMilos Muzik 		 * command byte (0x9E) is overloaded for multiple operations,
1855146832dbSMilos Muzik 		 * with the second CDB byte specifying the desired operation.
1856146832dbSMilos Muzik 		 */
1857146832dbSMilos Muzik 		cmdblk[0] = SCMD_SVC_ACTION_IN_G4;
1858146832dbSMilos Muzik 		cmdblk[1] = SSVC_ACTION_READ_CAPACITY_G4;
1859fcf3ce44SJohn Forte 
1860146832dbSMilos Muzik 		if (*pOutputBufferLength > MAX_READ_CAPACITY16_BUFFER_LEN) {
1861146832dbSMilos Muzik 			buflen = MAX_READ_CAPACITY16_BUFFER_LEN;
1862146832dbSMilos Muzik 		} else {
1863146832dbSMilos Muzik 			buflen = *pOutputBufferLength;
1864146832dbSMilos Muzik 		}
1865146832dbSMilos Muzik 		cmdblk[10] = (buflen & 0xff000000) >> 24;
1866146832dbSMilos Muzik 		cmdblk[11] = (buflen & 0x00ff0000) >> 16;
1867146832dbSMilos Muzik 		cmdblk[12] = (buflen & 0x0000ff00) >> 8;
1868146832dbSMilos Muzik 		cmdblk[13] = (buflen & 0x000000ff);
1869146832dbSMilos Muzik 	} else {
1870146832dbSMilos Muzik 		/* only 10 and 16 byte CDB are supported */
1871146832dbSMilos Muzik 		return (IMA_ERROR_NOT_SUPPORTED);
1872146832dbSMilos Muzik 	}
1873fcf3ce44SJohn Forte 
1874fcf3ce44SJohn Forte 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
1875fcf3ce44SJohn Forte 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
1876fcf3ce44SJohn Forte 
1877fcf3ce44SJohn Forte 	/* iu_oid is a session oid in the driver */
1878fcf3ce44SJohn Forte 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
1879fcf3ce44SJohn Forte 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
1880fcf3ce44SJohn Forte 		uscsi.iu_lun	= 0;
1881fcf3ce44SJohn Forte 	} else {
1882fcf3ce44SJohn Forte 		/*
1883fcf3ce44SJohn Forte 		 * Get LU properties and associated session oid
1884fcf3ce44SJohn Forte 		 * for this lun(deviceId) and put in uscsi.iu_oid
1885fcf3ce44SJohn Forte 		 */
1886fcf3ce44SJohn Forte 		status = getLuProperties(deviceId, &luProps);
1887fcf3ce44SJohn Forte 		if (status != IMA_STATUS_SUCCESS) {
1888fcf3ce44SJohn Forte 			return (status);
1889fcf3ce44SJohn Forte 		}
1890fcf3ce44SJohn Forte 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
1891fcf3ce44SJohn Forte 		    objectSequenceNumber;
1892fcf3ce44SJohn Forte 		uscsi.iu_lun = luProps.targetLun;
1893fcf3ce44SJohn Forte 	}
1894fcf3ce44SJohn Forte 
1895fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
1896146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
1897fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
1898146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_buflen = buflen;
1899fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
1900146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
1901146832dbSMilos Muzik 	    *pSenseBufferLength : 0;
1902146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
1903146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdblen = cdbLength;
1904fcf3ce44SJohn Forte 
1905fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1906fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1907fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
1908fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1909fcf3ce44SJohn Forte 	}
1910fcf3ce44SJohn Forte 
1911fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
1912fcf3ce44SJohn Forte 		(void) close(fd);
1913fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
1914fcf3ce44SJohn Forte 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
1915fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
1916fcf3ce44SJohn Forte 	}
1917fcf3ce44SJohn Forte 
1918146832dbSMilos Muzik 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
1919146832dbSMilos Muzik 		if (pSenseBufferLength != NULL) {
1920146832dbSMilos Muzik 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
1921146832dbSMilos Muzik 		}
1922146832dbSMilos Muzik 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
1923146832dbSMilos Muzik 	}
1924146832dbSMilos Muzik 
1925146832dbSMilos Muzik 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
1926fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
1927fcf3ce44SJohn Forte }
1928fcf3ce44SJohn Forte 
IMA_LuReportLuns(IMA_OID deviceId,IMA_BOOL sendToWellKnownLun,IMA_BYTE selectReport,IMA_BYTE * pOutputBuffer,IMA_UINT * pOutputBufferLength,IMA_BYTE * pSenseBuffer,IMA_UINT * pSenseBufferLength)1929fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_LuReportLuns(
1930fcf3ce44SJohn Forte 		IMA_OID deviceId,
1931fcf3ce44SJohn Forte 		IMA_BOOL sendToWellKnownLun,
1932fcf3ce44SJohn Forte 		IMA_BYTE selectReport,
1933fcf3ce44SJohn Forte 
1934fcf3ce44SJohn Forte 		IMA_BYTE *pOutputBuffer,
1935fcf3ce44SJohn Forte 		IMA_UINT *pOutputBufferLength,
1936fcf3ce44SJohn Forte 
1937fcf3ce44SJohn Forte 		IMA_BYTE *pSenseBuffer,
1938fcf3ce44SJohn Forte 		IMA_UINT *pSenseBufferLength
1939fcf3ce44SJohn Forte )
1940fcf3ce44SJohn Forte {
1941fcf3ce44SJohn Forte 	IMA_LU_PROPERTIES luProps;
1942fcf3ce44SJohn Forte 	IMA_STATUS status;
1943146832dbSMilos Muzik 	unsigned char cmdblk[CDB_GROUP5];
1944146832dbSMilos Muzik 	IMA_UINT buflen;
1945fcf3ce44SJohn Forte 	int fd;
1946fcf3ce44SJohn Forte 	iscsi_uscsi_t uscsi;
1947fcf3ce44SJohn Forte 
1948146832dbSMilos Muzik 	(void) memset(&cmdblk[0], 0, CDB_GROUP5);
1949146832dbSMilos Muzik 	cmdblk[0] = SCMD_REPORT_LUNS;
1950146832dbSMilos Muzik 	cmdblk[2] = selectReport;
1951146832dbSMilos Muzik 
1952146832dbSMilos Muzik 	if (*pOutputBufferLength > MAX_REPORT_LUNS_BUFFER_LEN) {
1953146832dbSMilos Muzik 		buflen = MAX_REPORT_LUNS_BUFFER_LEN;
1954146832dbSMilos Muzik 	} else {
1955146832dbSMilos Muzik 		buflen = *pOutputBufferLength;
1956146832dbSMilos Muzik 	}
1957146832dbSMilos Muzik 	cmdblk[6] = (buflen & 0xff000000) >> 24;
1958146832dbSMilos Muzik 	cmdblk[7] = (buflen & 0x00ff0000) >> 16;
1959146832dbSMilos Muzik 	cmdblk[8] = (buflen & 0x0000ff00) >> 8;
1960146832dbSMilos Muzik 	cmdblk[9] = (buflen & 0x000000ff);
1961fcf3ce44SJohn Forte 
1962fcf3ce44SJohn Forte 	(void) memset(&uscsi, 0, sizeof (iscsi_uscsi_t));
1963fcf3ce44SJohn Forte 	uscsi.iu_vers 	= ISCSI_INTERFACE_VERSION;
1964fcf3ce44SJohn Forte 
1965fcf3ce44SJohn Forte 	/* iu_oid is a session oid in the driver */
1966fcf3ce44SJohn Forte 	if (deviceId.objectType == IMA_OBJECT_TYPE_TARGET) {
1967146832dbSMilos Muzik 		if (sendToWellKnownLun == IMA_TRUE) {
1968146832dbSMilos Muzik 			/* this optional feature is not supported now */
1969146832dbSMilos Muzik 			return (IMA_ERROR_NOT_SUPPORTED);
1970146832dbSMilos Muzik 		}
1971fcf3ce44SJohn Forte 		uscsi.iu_oid	= deviceId.objectSequenceNumber;
1972fcf3ce44SJohn Forte 		uscsi.iu_lun	= 0;
1973fcf3ce44SJohn Forte 	} else {
1974fcf3ce44SJohn Forte 		/*
1975fcf3ce44SJohn Forte 		 * Get LU properties and associated session oid
1976fcf3ce44SJohn Forte 		 * for this lun(deviceId) and put in uscsi.iu_oid
1977fcf3ce44SJohn Forte 		 */
1978fcf3ce44SJohn Forte 		status = getLuProperties(deviceId, &luProps);
1979fcf3ce44SJohn Forte 		if (status != IMA_STATUS_SUCCESS) {
1980fcf3ce44SJohn Forte 			return (status);
1981fcf3ce44SJohn Forte 		}
1982fcf3ce44SJohn Forte 		uscsi.iu_oid = (uint32_t)luProps.associatedTargetOid.
1983fcf3ce44SJohn Forte 		    objectSequenceNumber;
1984fcf3ce44SJohn Forte 		uscsi.iu_lun = luProps.targetLun;
1985fcf3ce44SJohn Forte 	}
1986fcf3ce44SJohn Forte 
1987fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_flags = USCSI_READ;
1988146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_timeout = USCSI_TIMEOUT_IN_SEC;
1989fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_bufaddr = (char *)pOutputBuffer;
1990146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_buflen = buflen;
1991fcf3ce44SJohn Forte 	uscsi.iu_ucmd.uscsi_rqbuf = (char *)pSenseBuffer;
1992146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_rqlen = (pSenseBufferLength != NULL) ?
1993146832dbSMilos Muzik 	    *pSenseBufferLength : 0;
1994146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdb = (char *)&cmdblk[0];
1995146832dbSMilos Muzik 	uscsi.iu_ucmd.uscsi_cdblen = CDB_GROUP5;
1996fcf3ce44SJohn Forte 
1997fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
1998fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
1999fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2000fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2001fcf3ce44SJohn Forte 	}
2002fcf3ce44SJohn Forte 
2003fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_USCSI, &uscsi) != 0) {
2004fcf3ce44SJohn Forte 		(void) close(fd);
2005fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2006fcf3ce44SJohn Forte 		    "ISCSI_TARGET_PROPS_GET ioctl failed, errno: %d", errno);
2007fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2008fcf3ce44SJohn Forte 	}
2009fcf3ce44SJohn Forte 
2010146832dbSMilos Muzik 	if (uscsi.iu_ucmd.uscsi_status == STATUS_CHECK) {
2011146832dbSMilos Muzik 		if (pSenseBufferLength != NULL) {
2012146832dbSMilos Muzik 			*pSenseBufferLength -= uscsi.iu_ucmd.uscsi_rqresid;
2013146832dbSMilos Muzik 		}
2014146832dbSMilos Muzik 		return (IMA_ERROR_SCSI_STATUS_CHECK_CONDITION);
2015146832dbSMilos Muzik 	}
2016146832dbSMilos Muzik 
2017146832dbSMilos Muzik 	*pOutputBufferLength = buflen - uscsi.iu_ucmd.uscsi_resid;
2018fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2019fcf3ce44SJohn Forte }
2020fcf3ce44SJohn Forte 
2021fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_ExposeLu(IMA_OID luId)2022fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_ExposeLu(
2023fcf3ce44SJohn Forte 		IMA_OID luId
2024fcf3ce44SJohn Forte )
2025fcf3ce44SJohn Forte {
2026fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
2027fcf3ce44SJohn Forte }
2028fcf3ce44SJohn Forte 
2029fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_UnexposeLu(IMA_OID luId)2030fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_UnexposeLu(
2031fcf3ce44SJohn Forte 		IMA_OID luId
2032fcf3ce44SJohn Forte )
2033fcf3ce44SJohn Forte {
2034fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
2035fcf3ce44SJohn Forte }
2036fcf3ce44SJohn Forte 
IMA_GetAddressKeys(IMA_OID targetOid,IMA_ADDRESS_KEYS ** ppKeys)2037fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetAddressKeys(
2038fcf3ce44SJohn Forte 		IMA_OID targetOid,
2039fcf3ce44SJohn Forte 		IMA_ADDRESS_KEYS **ppKeys
2040fcf3ce44SJohn Forte )
2041fcf3ce44SJohn Forte {
2042fcf3ce44SJohn Forte 	IMA_STATUS status;
2043fcf3ce44SJohn Forte 	IMA_TARGET_PROPERTIES targetProps;
2044fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDR_PROP_LIST *discAddressList;
2045fcf3ce44SJohn Forte 	SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *pList;
2046fcf3ce44SJohn Forte 	int i, j, addressKeyCount = 0;
2047fcf3ce44SJohn Forte 	int addressKeyIdx = 0;
2048fcf3ce44SJohn Forte 
2049fcf3ce44SJohn Forte 	status = getTargetProperties(targetOid, &targetProps);
2050fcf3ce44SJohn Forte 	if (status != IMA_STATUS_SUCCESS) {
2051fcf3ce44SJohn Forte 		return (status);
2052fcf3ce44SJohn Forte 	}
2053fcf3ce44SJohn Forte 
2054fcf3ce44SJohn Forte 	status = getDiscoveryAddressPropertiesList(&discAddressList);
2055fcf3ce44SJohn Forte 	if (status != IMA_STATUS_SUCCESS) {
2056fcf3ce44SJohn Forte 		return (status);
2057fcf3ce44SJohn Forte 	}
2058fcf3ce44SJohn Forte 
2059fcf3ce44SJohn Forte 	/* Get the number of addresses to allocate */
2060fcf3ce44SJohn Forte 	for (i = 0; i < discAddressList->discAddrCount; i++) {
2061fcf3ce44SJohn Forte 		(void) sendTargets(discAddressList->props[i].discoveryAddress,
2062fcf3ce44SJohn Forte 		    &pList);
2063fcf3ce44SJohn Forte 		for (j = 0; j < pList->keyCount; j++) {
2064fcf3ce44SJohn Forte 			if (wcsncmp(pList->keys[j].name, targetProps.name,
2065fcf3ce44SJohn Forte 			    wslen(pList->keys[j].name)) == 0) {
2066fcf3ce44SJohn Forte 				addressKeyCount++;
2067fcf3ce44SJohn Forte 			}
2068fcf3ce44SJohn Forte 		}
2069fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(pList);
2070fcf3ce44SJohn Forte 	}
2071fcf3ce44SJohn Forte 
2072fcf3ce44SJohn Forte 	*ppKeys = (IMA_ADDRESS_KEYS *)calloc(1, sizeof (IMA_ADDRESS_KEYS) +
2073fcf3ce44SJohn Forte 	    addressKeyCount * sizeof (IMA_ADDRESS_KEY));
2074fcf3ce44SJohn Forte 	if (*ppKeys == NULL) {
2075fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2076fcf3ce44SJohn Forte 	}
2077fcf3ce44SJohn Forte 	(*ppKeys)->addressKeyCount = addressKeyCount;
2078fcf3ce44SJohn Forte 	addressKeyIdx = 0;
2079fcf3ce44SJohn Forte 
2080fcf3ce44SJohn Forte 	for (i = 0; i < discAddressList->discAddrCount; i++) {
2081fcf3ce44SJohn Forte 		(void) sendTargets(discAddressList->props[i].discoveryAddress,
2082fcf3ce44SJohn Forte 		    &pList);
2083fcf3ce44SJohn Forte 		for (j = 0; j < pList->keyCount; j++) {
2084fcf3ce44SJohn Forte 			if (wcsncmp(pList->keys[j].name, targetProps.name,
2085fcf3ce44SJohn Forte 			    wslen(pList->keys[j].name)) != 0) {
2086fcf3ce44SJohn Forte 				continue;
2087fcf3ce44SJohn Forte 			}
2088fcf3ce44SJohn Forte 
2089fcf3ce44SJohn Forte 			bcopy(&(pList->keys[j].address.ipAddress),
2090fcf3ce44SJohn Forte 			    &((*ppKeys)->addressKeys[addressKeyIdx].
2091fcf3ce44SJohn Forte 			    ipAddress), sizeof (IMA_IP_ADDRESS));
2092fcf3ce44SJohn Forte 
2093fcf3ce44SJohn Forte 			(*ppKeys)->addressKeys[addressKeyIdx++].portNumber =
2094fcf3ce44SJohn Forte 			    pList->keys[j].address.portNumber;
2095fcf3ce44SJohn Forte 
2096fcf3ce44SJohn Forte 		}
2097fcf3ce44SJohn Forte 		(void) IMA_FreeMemory(pList);
2098fcf3ce44SJohn Forte 	}
2099fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2100fcf3ce44SJohn Forte }
2101fcf3ce44SJohn Forte 
isAuthMethodValid(IMA_OID oid,IMA_AUTHMETHOD method)2102fcf3ce44SJohn Forte IMA_BOOL isAuthMethodValid(IMA_OID oid, IMA_AUTHMETHOD method) {
2103fcf3ce44SJohn Forte 	IMA_STATUS status;
2104fcf3ce44SJohn Forte 	IMA_AUTHMETHOD supportedList[MAX_AUTHMETHODS];
2105fcf3ce44SJohn Forte 	IMA_UINT i, supportedCount;
2106fcf3ce44SJohn Forte 	IMA_BOOL supported;
2107fcf3ce44SJohn Forte 	status = getSupportedAuthMethods(oid, IMA_FALSE, &supportedCount,
2108fcf3ce44SJohn Forte 			supportedList);
2109fcf3ce44SJohn Forte 	if (status != IMA_STATUS_SUCCESS)
2110fcf3ce44SJohn Forte 		return (IMA_FALSE);
2111fcf3ce44SJohn Forte 
2112fcf3ce44SJohn Forte 	supported = IMA_FALSE;
2113fcf3ce44SJohn Forte 	for (i = 0; i < supportedCount; i++) {
2114fcf3ce44SJohn Forte 		if (method == supportedList[i]) {
2115fcf3ce44SJohn Forte 			supported = IMA_TRUE;
2116fcf3ce44SJohn Forte 		}
2117fcf3ce44SJohn Forte 	}
2118fcf3ce44SJohn Forte 
2119fcf3ce44SJohn Forte 	return (supported);
2120fcf3ce44SJohn Forte }
2121fcf3ce44SJohn Forte 
isAuthMethodListValid(IMA_OID oid,const IMA_AUTHMETHOD * pMethodList,IMA_UINT methodCount)2122fcf3ce44SJohn Forte IMA_BOOL isAuthMethodListValid(IMA_OID oid, const IMA_AUTHMETHOD *pMethodList,
2123fcf3ce44SJohn Forte 				IMA_UINT methodCount) {
2124fcf3ce44SJohn Forte 	IMA_UINT i, j;
2125fcf3ce44SJohn Forte 
2126fcf3ce44SJohn Forte 	if (pMethodList == NULL) {
2127fcf3ce44SJohn Forte 		return (IMA_FALSE);
2128fcf3ce44SJohn Forte 	}
2129fcf3ce44SJohn Forte 	/* Check list for duplicates */
2130fcf3ce44SJohn Forte 	for (i = 0; i < methodCount; i++) {
2131fcf3ce44SJohn Forte 		for (j = i + 1; j < methodCount; j++) {
2132fcf3ce44SJohn Forte 			if (pMethodList[i] == pMethodList[j]) {
2133fcf3ce44SJohn Forte 				return (IMA_FALSE);
2134fcf3ce44SJohn Forte 			}
2135fcf3ce44SJohn Forte 		}
2136fcf3ce44SJohn Forte 
2137fcf3ce44SJohn Forte 		if (isAuthMethodValid(oid, pMethodList[i]) == IMA_FALSE) {
2138fcf3ce44SJohn Forte 			return (IMA_FALSE);
2139fcf3ce44SJohn Forte 		}
2140fcf3ce44SJohn Forte 	}
2141fcf3ce44SJohn Forte 	return (IMA_TRUE);
2142fcf3ce44SJohn Forte }
2143fcf3ce44SJohn Forte 
IMA_GetSupportedAuthMethods(IMA_OID lhbaOid,IMA_BOOL getSettableMethods,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)2144fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetSupportedAuthMethods(
2145fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2146fcf3ce44SJohn Forte 		IMA_BOOL getSettableMethods,
2147fcf3ce44SJohn Forte 		IMA_UINT *pMethodCount,
2148fcf3ce44SJohn Forte 		IMA_AUTHMETHOD *pMethodList
2149fcf3ce44SJohn Forte )
2150fcf3ce44SJohn Forte {
2151fcf3ce44SJohn Forte 	return (getSupportedAuthMethods(lhbaOid, getSettableMethods,
2152fcf3ce44SJohn Forte 	    pMethodCount, pMethodList));
2153fcf3ce44SJohn Forte }
2154fcf3ce44SJohn Forte 
2155fcf3ce44SJohn Forte 
2156fcf3ce44SJohn Forte /*ARGSUSED*/
getSupportedAuthMethods(IMA_OID lhbaOid,IMA_BOOL getSettableMethods,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)2157fcf3ce44SJohn Forte static IMA_STATUS getSupportedAuthMethods(
2158fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2159fcf3ce44SJohn Forte 		IMA_BOOL getSettableMethods,
2160fcf3ce44SJohn Forte 		IMA_UINT *pMethodCount,
2161fcf3ce44SJohn Forte 		IMA_AUTHMETHOD *pMethodList
2162fcf3ce44SJohn Forte )
2163fcf3ce44SJohn Forte {
2164fcf3ce44SJohn Forte 	if (pMethodList == NULL) {
2165fcf3ce44SJohn Forte 		*pMethodCount = 0;
2166fcf3ce44SJohn Forte 		return (IMA_STATUS_SUCCESS);
2167fcf3ce44SJohn Forte 	}
2168fcf3ce44SJohn Forte 
2169fcf3ce44SJohn Forte 	*pMethodCount = NUM_SUPPORTED_AUTH_METHODS;
2170fcf3ce44SJohn Forte 	if (*pMethodCount > 1) {
2171fcf3ce44SJohn Forte 		pMethodList[0] = IMA_AUTHMETHOD_NONE;
2172fcf3ce44SJohn Forte 		pMethodList[1] = IMA_AUTHMETHOD_CHAP;
2173fcf3ce44SJohn Forte 	}
2174fcf3ce44SJohn Forte 
2175fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2176fcf3ce44SJohn Forte }
2177fcf3ce44SJohn Forte 
IMA_GetInUseInitiatorAuthMethods(IMA_OID lhbaOid,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)2178fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetInUseInitiatorAuthMethods(
2179fcf3ce44SJohn Forte 		IMA_OID		lhbaOid,
2180fcf3ce44SJohn Forte 		IMA_UINT	*pMethodCount,
2181fcf3ce44SJohn Forte 		IMA_AUTHMETHOD *pMethodList
2182fcf3ce44SJohn Forte )
2183fcf3ce44SJohn Forte {
2184fcf3ce44SJohn Forte 	return (getAuthMethods(lhbaOid, pMethodCount, pMethodList));
2185fcf3ce44SJohn Forte }
2186fcf3ce44SJohn Forte 
2187fcf3ce44SJohn Forte /*ARGSUSED*/
IMA_GetInitiatorAuthParms(IMA_OID lhbaOid,IMA_AUTHMETHOD method,IMA_INITIATOR_AUTHPARMS * pParms)2188fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_GetInitiatorAuthParms(
2189fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2190fcf3ce44SJohn Forte 		IMA_AUTHMETHOD method,
2191fcf3ce44SJohn Forte 		IMA_INITIATOR_AUTHPARMS *pParms
2192fcf3ce44SJohn Forte )
2193fcf3ce44SJohn Forte {
2194fcf3ce44SJohn Forte 	int fd;
2195fcf3ce44SJohn Forte 	iscsi_chap_props_t  chap_p;
2196fcf3ce44SJohn Forte 
2197fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2198fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2199fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2200fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2201fcf3ce44SJohn Forte 	}
2202fcf3ce44SJohn Forte 
2203fcf3ce44SJohn Forte 	(void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t));
2204fcf3ce44SJohn Forte 	chap_p.c_vers = ISCSI_INTERFACE_VERSION;
2205fcf3ce44SJohn Forte 	chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber;
2206fcf3ce44SJohn Forte 
2207fcf3ce44SJohn Forte 	if (method == IMA_AUTHMETHOD_CHAP) {
2208fcf3ce44SJohn Forte 		if (ioctl(fd, ISCSI_CHAP_GET, &chap_p) != 0) {
2209fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
2210fcf3ce44SJohn Forte 			"ISCSI_CHAP_GET ioctl failed, errno: %d", errno);
2211fcf3ce44SJohn Forte 			(void) close(fd);
2212fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2213fcf3ce44SJohn Forte 		}
2214fcf3ce44SJohn Forte 	} else {
2215fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
2216fcf3ce44SJohn Forte 	}
2217fcf3ce44SJohn Forte 
2218fcf3ce44SJohn Forte 	(void) memcpy(pParms->chapParms.name, chap_p.c_user,
2219fcf3ce44SJohn Forte 	    chap_p.c_user_len);
2220fcf3ce44SJohn Forte 	pParms->chapParms.nameLength = chap_p.c_user_len;
2221fcf3ce44SJohn Forte 	(void) memcpy(pParms->chapParms.challengeSecret, chap_p.c_secret,
2222fcf3ce44SJohn Forte 	    chap_p.c_secret_len);
2223fcf3ce44SJohn Forte 	pParms->chapParms.challengeSecretLength = chap_p.c_secret_len;
2224fcf3ce44SJohn Forte 
2225fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2226fcf3ce44SJohn Forte }
2227fcf3ce44SJohn Forte 
IMA_SetInitiatorAuthMethods(IMA_OID lhbaOid,IMA_UINT methodCount,const IMA_AUTHMETHOD * pMethodList)2228fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetInitiatorAuthMethods(
2229fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2230fcf3ce44SJohn Forte 		IMA_UINT methodCount,
2231fcf3ce44SJohn Forte 		const IMA_AUTHMETHOD *pMethodList
2232fcf3ce44SJohn Forte )
2233fcf3ce44SJohn Forte {
2234fcf3ce44SJohn Forte 	if (isAuthMethodListValid(lhbaOid, pMethodList,
2235fcf3ce44SJohn Forte 	    methodCount) == IMA_FALSE)
2236fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
2237fcf3ce44SJohn Forte 	return (setAuthMethods(lhbaOid, &methodCount, pMethodList));
2238fcf3ce44SJohn Forte }
2239fcf3ce44SJohn Forte 
2240fcf3ce44SJohn Forte /*
2241fcf3ce44SJohn Forte  * This function only sets CHAP params since we only support CHAP for now.
2242fcf3ce44SJohn Forte  */
IMA_SetInitiatorAuthParms(IMA_OID lhbaOid,IMA_AUTHMETHOD method,const IMA_INITIATOR_AUTHPARMS * pParms)2243fcf3ce44SJohn Forte IMA_API	IMA_STATUS IMA_SetInitiatorAuthParms(
2244fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2245fcf3ce44SJohn Forte 		IMA_AUTHMETHOD method,
2246fcf3ce44SJohn Forte 		const IMA_INITIATOR_AUTHPARMS *pParms
2247fcf3ce44SJohn Forte )
2248fcf3ce44SJohn Forte {
2249fcf3ce44SJohn Forte 	int fd;
2250fcf3ce44SJohn Forte 	iscsi_chap_props_t  chap_p;
2251fcf3ce44SJohn Forte 
2252fcf3ce44SJohn Forte 	if (method != IMA_AUTHMETHOD_CHAP)
2253fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
2254fcf3ce44SJohn Forte 
2255fcf3ce44SJohn Forte 	if (isAuthMethodValid(lhbaOid, method) == IMA_FALSE) {
2256fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
2257fcf3ce44SJohn Forte 	}
2258fcf3ce44SJohn Forte 
2259fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2260fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2261fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2262fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2263fcf3ce44SJohn Forte 	}
2264fcf3ce44SJohn Forte 
2265fcf3ce44SJohn Forte 	(void) memset(&chap_p, 0, sizeof (iscsi_chap_props_t));
2266fcf3ce44SJohn Forte 	chap_p.c_vers = ISCSI_INTERFACE_VERSION;
2267fcf3ce44SJohn Forte 	chap_p.c_oid = (uint32_t)lhbaOid.objectSequenceNumber;
2268fcf3ce44SJohn Forte 
2269fcf3ce44SJohn Forte 	chap_p.c_user_len = pParms->chapParms.nameLength;
2270fcf3ce44SJohn Forte 	(void) memcpy(chap_p.c_user, pParms->chapParms.name, chap_p.c_user_len);
2271fcf3ce44SJohn Forte 
2272fcf3ce44SJohn Forte 	chap_p.c_secret_len = pParms->chapParms.challengeSecretLength;
2273fcf3ce44SJohn Forte 	(void) memcpy(chap_p.c_secret, pParms->chapParms.challengeSecret,
2274fcf3ce44SJohn Forte 	    chap_p.c_secret_len);
2275fcf3ce44SJohn Forte 
2276fcf3ce44SJohn Forte 	if (method == IMA_AUTHMETHOD_CHAP) {
2277fcf3ce44SJohn Forte 		if (ioctl(fd, ISCSI_CHAP_SET, &chap_p) != 0) {
2278fcf3ce44SJohn Forte 			(void) close(fd);
2279fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
2280fcf3ce44SJohn Forte 			    "ISCSI_CHAP_SET ioctl failed, errno: %d", errno);
2281fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2282fcf3ce44SJohn Forte 		}
2283fcf3ce44SJohn Forte 	}
2284fcf3ce44SJohn Forte 
2285fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2286fcf3ce44SJohn Forte }
2287fcf3ce44SJohn Forte 
2288fcf3ce44SJohn Forte /* A helper function to obtain iSCSI node parameters. */
2289fcf3ce44SJohn Forte static IMA_STATUS
getISCSINodeParameter(int paramType,IMA_OID * oid,void * pProps,uint32_t paramIndex)2290fcf3ce44SJohn Forte getISCSINodeParameter(
2291fcf3ce44SJohn Forte     int paramType,
2292fcf3ce44SJohn Forte     IMA_OID *oid,
2293fcf3ce44SJohn Forte     void *pProps,
2294fcf3ce44SJohn Forte     uint32_t paramIndex
2295fcf3ce44SJohn Forte )
2296fcf3ce44SJohn Forte {
2297fcf3ce44SJohn Forte 	int		    fd;
2298fcf3ce44SJohn Forte 	iscsi_param_get_t   pg;
2299fcf3ce44SJohn Forte 
2300fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2301fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2302fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2303fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2304fcf3ce44SJohn Forte 	}
2305fcf3ce44SJohn Forte 
2306fcf3ce44SJohn Forte 	(void) memset(&pg, 0, sizeof (iscsi_param_get_t));
2307fcf3ce44SJohn Forte 	pg.g_vers = ISCSI_INTERFACE_VERSION;
2308fcf3ce44SJohn Forte 	pg.g_oid = (uint32_t)oid->objectSequenceNumber;
2309fcf3ce44SJohn Forte 	pg.g_param = paramIndex;
2310fcf3ce44SJohn Forte 	pg.g_param_type = ISCSI_SESS_PARAM;
2311fcf3ce44SJohn Forte 
2312fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_PARAM_GET, &pg) != 0) {
2313fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2314fcf3ce44SJohn Forte 		    "ISCSI_PARAM_GET ioctl failed, errno: %d", errno);
2315fcf3ce44SJohn Forte 		(void) close(fd);
2316fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2317fcf3ce44SJohn Forte 	}
2318fcf3ce44SJohn Forte 
2319fcf3ce44SJohn Forte 	switch (paramType) {
2320fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *bp;
2321fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *mp;
2322fcf3ce44SJohn Forte 
2323fcf3ce44SJohn Forte 		case MIN_MAX_PARAM:
2324fcf3ce44SJohn Forte 			mp = (IMA_MIN_MAX_VALUE *)pProps;
2325fcf3ce44SJohn Forte 
2326fcf3ce44SJohn Forte 			mp->currentValueValid =
2327fcf3ce44SJohn Forte 			    (pg.g_value.v_valid == B_TRUE) ?
2328fcf3ce44SJohn Forte 			    IMA_TRUE : IMA_FALSE;
2329fcf3ce44SJohn Forte 			mp->currentValue = pg.g_value.v_integer.i_current;
2330fcf3ce44SJohn Forte 			mp->defaultValue = pg.g_value.v_integer.i_default;
2331fcf3ce44SJohn Forte 			mp->minimumValue = pg.g_value.v_integer.i_min;
2332fcf3ce44SJohn Forte 			mp->maximumValue = pg.g_value.v_integer.i_max;
2333fcf3ce44SJohn Forte 			mp->incrementValue = pg.g_value.v_integer.i_incr;
2334fcf3ce44SJohn Forte 			break;
2335fcf3ce44SJohn Forte 
2336fcf3ce44SJohn Forte 		case BOOL_PARAM:
2337fcf3ce44SJohn Forte 			bp = (IMA_BOOL_VALUE *)pProps;
2338fcf3ce44SJohn Forte 			bp->currentValueValid =
2339fcf3ce44SJohn Forte 			    (pg.g_value.v_valid == B_TRUE) ?
2340fcf3ce44SJohn Forte 			    IMA_TRUE : IMA_FALSE;
2341fcf3ce44SJohn Forte 			bp->currentValue = pg.g_value.v_bool.b_current;
2342fcf3ce44SJohn Forte 			bp->defaultValue = pg.g_value.v_bool.b_default;
2343fcf3ce44SJohn Forte 			break;
2344fcf3ce44SJohn Forte 
2345fcf3ce44SJohn Forte 		default:
2346fcf3ce44SJohn Forte 			break;
2347fcf3ce44SJohn Forte 	}
2348fcf3ce44SJohn Forte 
2349fcf3ce44SJohn Forte 	(void) close(fd);
2350fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2351fcf3ce44SJohn Forte }
2352fcf3ce44SJohn Forte 
2353fcf3ce44SJohn Forte /* A helper function to set iSCSI node parameters. */
2354fcf3ce44SJohn Forte static IMA_STATUS
setISCSINodeParameter(int paramType,IMA_OID * oid,void * pProp,uint32_t paramIndex)2355fcf3ce44SJohn Forte setISCSINodeParameter(
2356fcf3ce44SJohn Forte     int paramType,
2357fcf3ce44SJohn Forte     IMA_OID *oid,
2358fcf3ce44SJohn Forte     void *pProp,
2359fcf3ce44SJohn Forte     uint32_t paramIndex
2360fcf3ce44SJohn Forte )
2361fcf3ce44SJohn Forte {
2362fcf3ce44SJohn Forte 	int		    fd;
2363fcf3ce44SJohn Forte 	iscsi_param_set_t   ps;
2364fcf3ce44SJohn Forte 
2365fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2366fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2367fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2368fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2369fcf3ce44SJohn Forte 	}
2370fcf3ce44SJohn Forte 
2371fcf3ce44SJohn Forte 	(void) memset(&ps, 0, sizeof (iscsi_param_set_t));
2372fcf3ce44SJohn Forte 	ps.s_vers = ISCSI_INTERFACE_VERSION;
2373fcf3ce44SJohn Forte 	ps.s_oid = (uint32_t)oid->objectSequenceNumber;
2374fcf3ce44SJohn Forte 	ps.s_param = paramIndex;
2375fcf3ce44SJohn Forte 
2376fcf3ce44SJohn Forte 	switch (paramType) {
2377fcf3ce44SJohn Forte 		IMA_BOOL_VALUE *bp;
2378fcf3ce44SJohn Forte 		IMA_MIN_MAX_VALUE *mp;
2379fcf3ce44SJohn Forte 
2380fcf3ce44SJohn Forte 		case MIN_MAX_PARAM:
2381fcf3ce44SJohn Forte 			mp = (IMA_MIN_MAX_VALUE *)pProp;
2382fcf3ce44SJohn Forte 			ps.s_value.v_integer = mp->currentValue;
2383fcf3ce44SJohn Forte 			break;
2384fcf3ce44SJohn Forte 		case BOOL_PARAM:
2385fcf3ce44SJohn Forte 			bp = (IMA_BOOL_VALUE *)pProp;
2386fcf3ce44SJohn Forte 			ps.s_value.v_bool =
2387fcf3ce44SJohn Forte 			    (bp->currentValue == IMA_TRUE) ?
2388fcf3ce44SJohn Forte 			    B_TRUE : B_FALSE;
2389fcf3ce44SJohn Forte 			break;
2390fcf3ce44SJohn Forte 
2391fcf3ce44SJohn Forte 		default:
2392fcf3ce44SJohn Forte 			break;
2393fcf3ce44SJohn Forte 	}
2394fcf3ce44SJohn Forte 
2395fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_PARAM_SET, &ps)) {
2396fcf3ce44SJohn Forte 		int tmpErrno = errno;
2397fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2398fcf3ce44SJohn Forte 		    "ISCSI_PARAM_SET ioctl failed, errno: %d", errno);
2399fcf3ce44SJohn Forte 		(void) close(fd);
2400fcf3ce44SJohn Forte 		switch (tmpErrno) {
2401fcf3ce44SJohn Forte 			case ENOTSUP :
2402fcf3ce44SJohn Forte 				return (IMA_ERROR_NOT_SUPPORTED);
2403fcf3ce44SJohn Forte 			default :
2404fcf3ce44SJohn Forte 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2405fcf3ce44SJohn Forte 		}
2406fcf3ce44SJohn Forte 	}
2407fcf3ce44SJohn Forte 
2408fcf3ce44SJohn Forte 	(void) close(fd);
2409fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2410fcf3ce44SJohn Forte }
2411fcf3ce44SJohn Forte 
2412fcf3ce44SJohn Forte static int
prepare_discovery_entry(IMA_TARGET_ADDRESS discoveryAddress,entry_t * entry)2413fcf3ce44SJohn Forte prepare_discovery_entry(
2414fcf3ce44SJohn Forte     IMA_TARGET_ADDRESS discoveryAddress,
2415fcf3ce44SJohn Forte     entry_t *entry
2416fcf3ce44SJohn Forte )
2417fcf3ce44SJohn Forte {
2418fcf3ce44SJohn Forte 	(void) memset(entry, 0, sizeof (entry_t));
2419fcf3ce44SJohn Forte 	entry->e_vers = ISCSI_INTERFACE_VERSION;
2420fcf3ce44SJohn Forte 	entry->e_oid = ISCSI_OID_NOTSET;
2421fcf3ce44SJohn Forte 
2422fcf3ce44SJohn Forte 	if (discoveryAddress.hostnameIpAddress.id.ipAddress.ipv4Address ==
2423fcf3ce44SJohn Forte 	    IMA_FALSE) {
2424fcf3ce44SJohn Forte 		bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
2425fcf3ce44SJohn Forte 		    entry->e_u.u_in6.s6_addr,
2426fcf3ce44SJohn Forte 		    sizeof (entry->e_u.u_in6.s6_addr));
2427fcf3ce44SJohn Forte 		entry->e_insize = sizeof (struct in6_addr);
2428fcf3ce44SJohn Forte 	} else {
2429fcf3ce44SJohn Forte 		bcopy(discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
2430fcf3ce44SJohn Forte 		    &entry->e_u.u_in4.s_addr,
2431fcf3ce44SJohn Forte 		    sizeof (entry->e_u.u_in4.s_addr));
2432fcf3ce44SJohn Forte 		entry->e_insize = sizeof (struct in_addr);
2433fcf3ce44SJohn Forte 	}
2434fcf3ce44SJohn Forte 
2435fcf3ce44SJohn Forte 	entry->e_port = discoveryAddress.portNumber;
2436fcf3ce44SJohn Forte 	entry->e_tpgt = 0;
2437fcf3ce44SJohn Forte 	return (DISC_ADDR_OK);
2438fcf3ce44SJohn Forte }
2439fcf3ce44SJohn Forte 
configure_discovery_method(IMA_BOOL enable,iSCSIDiscoveryMethod_t method)2440fcf3ce44SJohn Forte static IMA_STATUS configure_discovery_method(
2441fcf3ce44SJohn Forte     IMA_BOOL enable,
2442fcf3ce44SJohn Forte     iSCSIDiscoveryMethod_t method
2443fcf3ce44SJohn Forte )
2444fcf3ce44SJohn Forte {
2445fcf3ce44SJohn Forte 	int fd, status;
2446fcf3ce44SJohn Forte 
2447fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2448fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2449fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2450fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2451fcf3ce44SJohn Forte 	}
2452fcf3ce44SJohn Forte 
2453fcf3ce44SJohn Forte 	if (enable == IMA_FALSE) {
2454fcf3ce44SJohn Forte 		if (ioctl(fd, ISCSI_DISCOVERY_CLEAR, &method)) {
2455fcf3ce44SJohn Forte 			status = errno;
2456fcf3ce44SJohn Forte 			(void) close(fd);
2457fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
2458fcf3ce44SJohn Forte 			    "ISCSI_DISCOVERY_CLEAR ioctl failed, errno: %d",
2459fcf3ce44SJohn Forte 			    status);
2460fcf3ce44SJohn Forte 			if (status == EBUSY) {
2461fcf3ce44SJohn Forte 				return (IMA_ERROR_LU_IN_USE);
2462fcf3ce44SJohn Forte 			} else {
2463fcf3ce44SJohn Forte 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2464fcf3ce44SJohn Forte 			}
2465fcf3ce44SJohn Forte 		}
2466fcf3ce44SJohn Forte 
2467fcf3ce44SJohn Forte 		(void) close(fd);
2468fcf3ce44SJohn Forte 		return (IMA_STATUS_SUCCESS);
2469fcf3ce44SJohn Forte 	} else {
2470fcf3ce44SJohn Forte 		/* Set the discovery method */
2471fcf3ce44SJohn Forte 		if (ioctl(fd, ISCSI_DISCOVERY_SET, &method)) {
2472fcf3ce44SJohn Forte 			(void) close(fd);
2473fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
2474fcf3ce44SJohn Forte 			    "ISCSI_DISCOVERY_SET ioctl failed, errno: %d",
2475fcf3ce44SJohn Forte 			    errno);
2476fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2477fcf3ce44SJohn Forte 		}
2478fcf3ce44SJohn Forte 
2479fcf3ce44SJohn Forte 		(void) close(fd);
2480fcf3ce44SJohn Forte 		return (IMA_STATUS_SUCCESS);
2481fcf3ce44SJohn Forte 	}
2482fcf3ce44SJohn Forte }
2483fcf3ce44SJohn Forte 
get_target_oid_list(uint32_t targetListType,IMA_OID_LIST ** ppList)2484fcf3ce44SJohn Forte static IMA_STATUS get_target_oid_list(
2485fcf3ce44SJohn Forte     uint32_t targetListType,
2486fcf3ce44SJohn Forte     IMA_OID_LIST **ppList)
2487fcf3ce44SJohn Forte {
2488fcf3ce44SJohn Forte 	int		    fd;
2489fcf3ce44SJohn Forte 	int		    i;
2490fcf3ce44SJohn Forte 	int		    target_list_size;
2491fcf3ce44SJohn Forte 	iscsi_target_list_t *idlp, tl_info;
2492fcf3ce44SJohn Forte 
2493fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2494fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2495fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2496fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2497fcf3ce44SJohn Forte 	}
2498fcf3ce44SJohn Forte 
2499fcf3ce44SJohn Forte 	(void) memset(&tl_info, 0, sizeof (tl_info));
2500fcf3ce44SJohn Forte 	tl_info.tl_vers = ISCSI_INTERFACE_VERSION;
2501fcf3ce44SJohn Forte 	tl_info.tl_in_cnt = 0;
2502fcf3ce44SJohn Forte 	tl_info.tl_tgt_list_type = targetListType;
2503fcf3ce44SJohn Forte 
2504fcf3ce44SJohn Forte 	/*
2505fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the number of targets.
2506fcf3ce44SJohn Forte 	 */
2507fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, &tl_info) != 0) {
2508fcf3ce44SJohn Forte 		(void) close(fd);
2509fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2510fcf3ce44SJohn Forte 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
2511fcf3ce44SJohn Forte 		    targetListType, errno);
2512fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2513fcf3ce44SJohn Forte 	}
2514fcf3ce44SJohn Forte 
2515fcf3ce44SJohn Forte 	target_list_size = sizeof (iscsi_target_list_t);
2516fcf3ce44SJohn Forte 	if (tl_info.tl_out_cnt > 1) {
2517fcf3ce44SJohn Forte 		target_list_size += (sizeof (uint32_t) *
2518fcf3ce44SJohn Forte 		    tl_info.tl_out_cnt - 1);
2519fcf3ce44SJohn Forte 	}
2520fcf3ce44SJohn Forte 
2521fcf3ce44SJohn Forte 	idlp = (iscsi_target_list_t *)calloc(1, target_list_size);
2522fcf3ce44SJohn Forte 	if (idlp == NULL) {
2523fcf3ce44SJohn Forte 		(void) close(fd);
2524fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2525fcf3ce44SJohn Forte 	}
2526fcf3ce44SJohn Forte 
2527fcf3ce44SJohn Forte 	idlp->tl_vers = ISCSI_INTERFACE_VERSION;
2528fcf3ce44SJohn Forte 	idlp->tl_in_cnt = tl_info.tl_out_cnt;
2529fcf3ce44SJohn Forte 	idlp->tl_tgt_list_type = targetListType;
2530fcf3ce44SJohn Forte 
2531fcf3ce44SJohn Forte 	/* Issue the same ioctl again to obtain the OIDs. */
2532fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_TARGET_OID_LIST_GET, idlp) != 0) {
2533fcf3ce44SJohn Forte 		free(idlp);
2534fcf3ce44SJohn Forte 		(void) close(fd);
2535fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2536fcf3ce44SJohn Forte 		    "ISCSI_TARGET_OID_LIST_GET ioctl %d failed, errno: %d",
2537fcf3ce44SJohn Forte 		    targetListType, errno);
2538fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2539fcf3ce44SJohn Forte 	}
2540fcf3ce44SJohn Forte 
2541fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST *)calloc(1, sizeof (IMA_OID_LIST) +
2542fcf3ce44SJohn Forte 	    idlp->tl_out_cnt * sizeof (IMA_OID));
2543fcf3ce44SJohn Forte 	if (*ppList == NULL) {
2544fcf3ce44SJohn Forte 		free(idlp);
2545fcf3ce44SJohn Forte 		(void) close(fd);
2546fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2547fcf3ce44SJohn Forte 	}
2548fcf3ce44SJohn Forte 	(*ppList)->oidCount = idlp->tl_out_cnt;
2549fcf3ce44SJohn Forte 
2550fcf3ce44SJohn Forte 	for (i = 0; i < idlp->tl_out_cnt; i++) {
2551fcf3ce44SJohn Forte 
2552fcf3ce44SJohn Forte 		if (targetListType == ISCSI_STATIC_TGT_OID_LIST)
2553fcf3ce44SJohn Forte 			(*ppList)->oids[i].objectType =
2554fcf3ce44SJohn Forte 			    IMA_OBJECT_TYPE_STATIC_DISCOVERY_TARGET;
2555fcf3ce44SJohn Forte 		else
2556fcf3ce44SJohn Forte 			(*ppList)->oids[i].objectType = IMA_OBJECT_TYPE_TARGET;
2557fcf3ce44SJohn Forte 
2558fcf3ce44SJohn Forte 		(*ppList)->oids[i].ownerId = pluginOwnerId;
2559fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectSequenceNumber = idlp->tl_oid_list[i];
2560fcf3ce44SJohn Forte 	}
2561fcf3ce44SJohn Forte 
2562fcf3ce44SJohn Forte 	free(idlp);
2563fcf3ce44SJohn Forte 	(void) close(fd);
2564fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2565fcf3ce44SJohn Forte }
2566fcf3ce44SJohn Forte 
get_target_lun_oid_list(IMA_OID * targetOid,iscsi_lun_list_t ** ppLunList)2567fcf3ce44SJohn Forte static IMA_STATUS get_target_lun_oid_list(
2568fcf3ce44SJohn Forte     IMA_OID * targetOid,
2569fcf3ce44SJohn Forte     iscsi_lun_list_t  **ppLunList)
2570fcf3ce44SJohn Forte {
2571fcf3ce44SJohn Forte 	int			fd;
2572fcf3ce44SJohn Forte 	iscsi_lun_list_t	*illp, ll_info;
2573fcf3ce44SJohn Forte 	int			lun_list_size;
2574fcf3ce44SJohn Forte 
2575fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2576fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2577fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2578fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2579fcf3ce44SJohn Forte 	}
2580fcf3ce44SJohn Forte 
2581fcf3ce44SJohn Forte 	(void) memset(&ll_info, 0, sizeof (ll_info));
2582fcf3ce44SJohn Forte 	ll_info.ll_vers = ISCSI_INTERFACE_VERSION;
2583fcf3ce44SJohn Forte 	if (targetOid == NULL) {
2584fcf3ce44SJohn Forte 		/* get lun oid list for all targets */
2585fcf3ce44SJohn Forte 		ll_info.ll_all_tgts = B_TRUE;
2586fcf3ce44SJohn Forte 	} else {
2587fcf3ce44SJohn Forte 		/* get lun oid list for single target */
2588fcf3ce44SJohn Forte 		ll_info.ll_all_tgts = B_FALSE;
2589fcf3ce44SJohn Forte 		ll_info.ll_tgt_oid = (uint32_t)targetOid->objectSequenceNumber;
2590fcf3ce44SJohn Forte 	}
2591fcf3ce44SJohn Forte 	ll_info.ll_in_cnt = 0;
2592fcf3ce44SJohn Forte 
2593fcf3ce44SJohn Forte 	/*
2594fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the number of target LUNs.
2595fcf3ce44SJohn Forte 	 */
2596fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, &ll_info) != 0) {
2597fcf3ce44SJohn Forte 		(void) close(fd);
2598fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2599fcf3ce44SJohn Forte 		    "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno);
2600fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2601fcf3ce44SJohn Forte 	}
2602fcf3ce44SJohn Forte 
2603fcf3ce44SJohn Forte 	lun_list_size = sizeof (iscsi_lun_list_t);
2604fcf3ce44SJohn Forte 	if (ll_info.ll_out_cnt > 1) {
2605fcf3ce44SJohn Forte 		lun_list_size += (sizeof (iscsi_if_lun_t) *
2606fcf3ce44SJohn Forte 		    (ll_info.ll_out_cnt - 1));
2607fcf3ce44SJohn Forte 	}
2608fcf3ce44SJohn Forte 
2609fcf3ce44SJohn Forte 	illp = (iscsi_lun_list_t *)calloc(1, lun_list_size);
2610fcf3ce44SJohn Forte 	if (illp == NULL) {
2611fcf3ce44SJohn Forte 		(void) close(fd);
2612fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2613fcf3ce44SJohn Forte 	}
2614fcf3ce44SJohn Forte 	illp->ll_vers = ISCSI_INTERFACE_VERSION;
2615fcf3ce44SJohn Forte 	illp->ll_all_tgts = ll_info.ll_all_tgts;
2616fcf3ce44SJohn Forte 	illp->ll_tgt_oid = ll_info.ll_tgt_oid;
2617fcf3ce44SJohn Forte 	illp->ll_in_cnt = ll_info.ll_out_cnt;
2618fcf3ce44SJohn Forte 
2619fcf3ce44SJohn Forte 	/* Issue the same ioctl again to get the target LUN list */
2620fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_LUN_OID_LIST_GET, illp) != 0) {
2621fcf3ce44SJohn Forte 		free(illp);
2622fcf3ce44SJohn Forte 		(void) close(fd);
2623fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2624fcf3ce44SJohn Forte 		    "ISCSI_LUN_LIST_GET ioctl failed, errno: %d", errno);
2625fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2626fcf3ce44SJohn Forte 	}
2627fcf3ce44SJohn Forte 
2628fcf3ce44SJohn Forte 	*ppLunList = illp;
2629fcf3ce44SJohn Forte 
2630fcf3ce44SJohn Forte 	(void) close(fd);
2631fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2632fcf3ce44SJohn Forte }
2633fcf3ce44SJohn Forte 
2634fcf3ce44SJohn Forte 
2635fcf3ce44SJohn Forte /* A helper function to set authentication method. */
2636fcf3ce44SJohn Forte static IMA_STATUS
setAuthMethods(IMA_OID oid,IMA_UINT * pMethodCount,const IMA_AUTHMETHOD * pMethodList)2637fcf3ce44SJohn Forte setAuthMethods(
2638fcf3ce44SJohn Forte     IMA_OID oid,
2639fcf3ce44SJohn Forte     IMA_UINT *pMethodCount,
2640fcf3ce44SJohn Forte     const IMA_AUTHMETHOD *pMethodList
2641fcf3ce44SJohn Forte )
2642fcf3ce44SJohn Forte {
2643fcf3ce44SJohn Forte 	int fd;
2644fcf3ce44SJohn Forte 	int i;
2645fcf3ce44SJohn Forte 	iscsi_auth_props_t auth;
2646fcf3ce44SJohn Forte 
2647fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2648fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2649fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2650fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2651fcf3ce44SJohn Forte 	}
2652fcf3ce44SJohn Forte 	(void) memset(&auth, 0, sizeof (iscsi_auth_props_t));
2653fcf3ce44SJohn Forte 	auth.a_vers = ISCSI_INTERFACE_VERSION;
2654fcf3ce44SJohn Forte 	auth.a_oid = (uint32_t)oid.objectSequenceNumber;
2655fcf3ce44SJohn Forte 	/* First do a get because other data fields may exist */
2656fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) {
2657fcf3ce44SJohn Forte 		/* EMPTY */
2658fcf3ce44SJohn Forte 		/* It is fine if there is no other data fields. */
2659fcf3ce44SJohn Forte 	}
2660fcf3ce44SJohn Forte 	auth.a_auth_method = authMethodNone;
2661fcf3ce44SJohn Forte 
2662fcf3ce44SJohn Forte 	for (i = 0; i < *pMethodCount; i++) {
2663fcf3ce44SJohn Forte 		switch (pMethodList[i]) {
2664fcf3ce44SJohn Forte 			case IMA_AUTHMETHOD_CHAP:
2665fcf3ce44SJohn Forte 				auth.a_auth_method |= authMethodCHAP;
2666fcf3ce44SJohn Forte 				break;
2667fcf3ce44SJohn Forte 			default:
2668fcf3ce44SJohn Forte 				break;
2669fcf3ce44SJohn Forte 		}
2670fcf3ce44SJohn Forte 	}
2671fcf3ce44SJohn Forte 
2672fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_AUTH_SET, &auth) != 0) {
2673fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2674fcf3ce44SJohn Forte 		    "ISCSI_AUTH_SET failed, errno: %d", errno);
2675fcf3ce44SJohn Forte 		(void) close(fd);
2676fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2677fcf3ce44SJohn Forte 	}
2678fcf3ce44SJohn Forte 
2679fcf3ce44SJohn Forte 	(void) close(fd);
2680fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2681fcf3ce44SJohn Forte }
2682fcf3ce44SJohn Forte 
2683fcf3ce44SJohn Forte /* A helper function to get authentication method. */
2684fcf3ce44SJohn Forte static IMA_STATUS
getAuthMethods(IMA_OID oid,IMA_UINT * pMethodCount,IMA_AUTHMETHOD * pMethodList)2685fcf3ce44SJohn Forte getAuthMethods(
2686fcf3ce44SJohn Forte     IMA_OID oid,
2687fcf3ce44SJohn Forte     IMA_UINT	*pMethodCount,
2688fcf3ce44SJohn Forte     IMA_AUTHMETHOD *pMethodList
2689fcf3ce44SJohn Forte )
2690fcf3ce44SJohn Forte {
2691fcf3ce44SJohn Forte 	int fd, i;
2692fcf3ce44SJohn Forte 	iscsi_auth_props_t auth;
2693fcf3ce44SJohn Forte 
2694fcf3ce44SJohn Forte 	if (pMethodList == NULL) {
2695fcf3ce44SJohn Forte 		*pMethodCount = 0;
2696fcf3ce44SJohn Forte 		return (IMA_STATUS_SUCCESS);
2697fcf3ce44SJohn Forte 	}
2698fcf3ce44SJohn Forte 
2699fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
2700fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
2701fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
2702fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2703fcf3ce44SJohn Forte 	}
2704fcf3ce44SJohn Forte 
2705fcf3ce44SJohn Forte 	(void) memset(&auth, 0, sizeof (iscsi_auth_props_t));
2706fcf3ce44SJohn Forte 	auth.a_vers = ISCSI_INTERFACE_VERSION;
2707fcf3ce44SJohn Forte 	auth.a_oid = (uint32_t)oid.objectSequenceNumber;
2708fcf3ce44SJohn Forte 
2709fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_AUTH_GET, &auth) != 0) {
2710fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
2711fcf3ce44SJohn Forte 		    "ISCSI_AUTH_GET failed, errno: %d", errno);
2712fcf3ce44SJohn Forte 		(void) close(fd);
2713fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
2714fcf3ce44SJohn Forte 	}
2715fcf3ce44SJohn Forte 
2716fcf3ce44SJohn Forte 	i = 0;
2717*2c2d21e9SRichard Lowe 	if (auth.a_auth_method == authMethodNone) {
2718fcf3ce44SJohn Forte 		pMethodList[i++] = IMA_AUTHMETHOD_NONE;
2719fcf3ce44SJohn Forte 	} else if (auth.a_auth_method & authMethodCHAP) {
2720fcf3ce44SJohn Forte 		pMethodList[i++] = IMA_AUTHMETHOD_CHAP;
2721fcf3ce44SJohn Forte 	}
2722fcf3ce44SJohn Forte 	*pMethodCount = i;
2723fcf3ce44SJohn Forte 
2724fcf3ce44SJohn Forte 	(void) close(fd);
2725fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2726fcf3ce44SJohn Forte }
2727fcf3ce44SJohn Forte 
IMA_GetPhbaOidList(IMA_OID_LIST ** ppList)2728fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPhbaOidList(
2729fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
2730fcf3ce44SJohn Forte )
2731fcf3ce44SJohn Forte {
2732fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST));
2733fcf3ce44SJohn Forte 	if (*ppList == NULL) {
2734fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2735fcf3ce44SJohn Forte 	}
2736fcf3ce44SJohn Forte 	(*ppList)->oidCount = 0;
2737fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2738fcf3ce44SJohn Forte }
2739fcf3ce44SJohn Forte 
2740fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPhbaProperties(IMA_OID phbaOid,IMA_PHBA_PROPERTIES * pProps)2741fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPhbaProperties(
2742fcf3ce44SJohn Forte 		IMA_OID phbaOid,
2743fcf3ce44SJohn Forte 		IMA_PHBA_PROPERTIES *pProps
2744fcf3ce44SJohn Forte )
2745fcf3ce44SJohn Forte {
2746fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2747fcf3ce44SJohn Forte }
2748fcf3ce44SJohn Forte 
2749fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPhbaStatus(IMA_OID phbaOid,IMA_PHBA_STATUS * pStatus)2750fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPhbaStatus(
2751fcf3ce44SJohn Forte 		IMA_OID phbaOid,
2752fcf3ce44SJohn Forte 		IMA_PHBA_STATUS *pStatus
2753fcf3ce44SJohn Forte )
2754fcf3ce44SJohn Forte {
2755fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2756fcf3ce44SJohn Forte }
2757fcf3ce44SJohn Forte 
2758fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPhbaDownloadProperties(IMA_OID phbaOid,IMA_PHBA_DOWNLOAD_PROPERTIES * pProps)2759fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPhbaDownloadProperties(
2760fcf3ce44SJohn Forte 		IMA_OID phbaOid,
2761fcf3ce44SJohn Forte 		IMA_PHBA_DOWNLOAD_PROPERTIES *pProps
2762fcf3ce44SJohn Forte )
2763fcf3ce44SJohn Forte {
2764fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2765fcf3ce44SJohn Forte }
2766fcf3ce44SJohn Forte 
2767fcf3ce44SJohn Forte /* ARGSUSED */
IMA_IsPhbaDownloadFile(IMA_OID phbaOid,const IMA_WCHAR * pFileName,IMA_PHBA_DOWNLOAD_IMAGE_PROPERTIES * pProps)2768fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_IsPhbaDownloadFile(
2769fcf3ce44SJohn Forte 		IMA_OID phbaOid,
2770fcf3ce44SJohn Forte 		const IMA_WCHAR *pFileName,
2771fcf3ce44SJohn Forte 		IMA_PHBA_DOWNLOAD_IMAGE_PROPERTIES *pProps
2772fcf3ce44SJohn Forte )
2773fcf3ce44SJohn Forte {
2774fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2775fcf3ce44SJohn Forte }
2776fcf3ce44SJohn Forte 
2777fcf3ce44SJohn Forte /* ARGSUSED */
IMA_PhbaDownload(IMA_OID phbaOid,IMA_PHBA_DOWNLOAD_IMAGE_TYPE imageType,const IMA_WCHAR * pFileName)2778fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_PhbaDownload(
2779fcf3ce44SJohn Forte 		IMA_OID phbaOid,
2780fcf3ce44SJohn Forte 		IMA_PHBA_DOWNLOAD_IMAGE_TYPE imageType,
2781fcf3ce44SJohn Forte 		const IMA_WCHAR *pFileName
2782fcf3ce44SJohn Forte )
2783fcf3ce44SJohn Forte {
2784fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2785fcf3ce44SJohn Forte }
2786fcf3ce44SJohn Forte 
IMA_GetPnpOidList(IMA_OID pnpOid,IMA_OID_LIST ** ppList)2787fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPnpOidList(
2788fcf3ce44SJohn Forte 		IMA_OID pnpOid,
2789fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
2790fcf3ce44SJohn Forte )
2791fcf3ce44SJohn Forte {
2792fcf3ce44SJohn Forte 	/*
2793fcf3ce44SJohn Forte 	 * Always return the same object ID for the pnp as the spec
2794fcf3ce44SJohn Forte 	 * states that this function will always return a list of at least
2795fcf3ce44SJohn Forte 	 * one element
2796fcf3ce44SJohn Forte 	 */
2797fcf3ce44SJohn Forte 	pnpOid.objectType = IMA_OBJECT_TYPE_PNP;
2798fcf3ce44SJohn Forte 	pnpOid.ownerId = pluginOwnerId;
2799fcf3ce44SJohn Forte 	pnpOid.objectSequenceNumber = ISCSI_INITIATOR_OID;
2800fcf3ce44SJohn Forte 
2801fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST*)calloc(1, sizeof (IMA_OID_LIST) +
2802fcf3ce44SJohn Forte 	    (1* sizeof (IMA_OID)));
2803fcf3ce44SJohn Forte 
2804fcf3ce44SJohn Forte 	if (*ppList == NULL) {
2805fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
2806fcf3ce44SJohn Forte 	}
2807fcf3ce44SJohn Forte 
2808fcf3ce44SJohn Forte 	(*ppList)->oidCount = 1;
2809fcf3ce44SJohn Forte 	(void) memcpy(&(*ppList)->oids[0], &pnpOid, sizeof (pnpOid));
2810fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2811fcf3ce44SJohn Forte }
2812fcf3ce44SJohn Forte 
2813fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPnpProperties(IMA_OID pnpOid,IMA_PNP_PROPERTIES * pProps)2814fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPnpProperties(
2815fcf3ce44SJohn Forte 		IMA_OID pnpOid,
2816fcf3ce44SJohn Forte 		IMA_PNP_PROPERTIES *pProps
2817fcf3ce44SJohn Forte )
2818fcf3ce44SJohn Forte {
2819fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2820fcf3ce44SJohn Forte }
2821fcf3ce44SJohn Forte 
2822fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPnpStatistics(IMA_OID pnpOid,IMA_PNP_STATISTICS * pStats)2823fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPnpStatistics(
2824fcf3ce44SJohn Forte 		IMA_OID pnpOid,
2825fcf3ce44SJohn Forte 		IMA_PNP_STATISTICS *pStats
2826fcf3ce44SJohn Forte )
2827fcf3ce44SJohn Forte {
2828fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2829fcf3ce44SJohn Forte }
2830fcf3ce44SJohn Forte 
2831fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetIpProperties(IMA_OID oid,IMA_IP_PROPERTIES * pProps)2832fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetIpProperties(
2833fcf3ce44SJohn Forte 		IMA_OID oid,
2834fcf3ce44SJohn Forte 		IMA_IP_PROPERTIES *pProps
2835fcf3ce44SJohn Forte )
2836fcf3ce44SJohn Forte {
2837fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2838fcf3ce44SJohn Forte }
2839fcf3ce44SJohn Forte 
2840fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetDefaultGateway(IMA_OID oid,IMA_IP_ADDRESS defaultGateway)2841fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetDefaultGateway(
2842fcf3ce44SJohn Forte 		IMA_OID oid,
2843fcf3ce44SJohn Forte 		IMA_IP_ADDRESS defaultGateway
2844fcf3ce44SJohn Forte )
2845fcf3ce44SJohn Forte {
2846fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2847fcf3ce44SJohn Forte }
2848fcf3ce44SJohn Forte 
2849fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetDnsServerAddress(IMA_OID oid,const IMA_IP_ADDRESS * pPrimaryDnsServerAddress,const IMA_IP_ADDRESS * pAlternateDnsServerAddress)2850fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetDnsServerAddress(
2851fcf3ce44SJohn Forte 		IMA_OID oid,
2852fcf3ce44SJohn Forte 		const IMA_IP_ADDRESS *pPrimaryDnsServerAddress,
2853fcf3ce44SJohn Forte 		const IMA_IP_ADDRESS *pAlternateDnsServerAddress
2854fcf3ce44SJohn Forte )
2855fcf3ce44SJohn Forte {
2856fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2857fcf3ce44SJohn Forte }
2858fcf3ce44SJohn Forte 
2859fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetSubnetMask(IMA_OID oid,IMA_IP_ADDRESS subnetMask)2860fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetSubnetMask(
2861fcf3ce44SJohn Forte 		IMA_OID oid,
2862fcf3ce44SJohn Forte 		IMA_IP_ADDRESS subnetMask
2863fcf3ce44SJohn Forte )
2864fcf3ce44SJohn Forte {
2865fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2866fcf3ce44SJohn Forte }
2867fcf3ce44SJohn Forte 
2868fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetIpConfigMethod(IMA_OID oid,IMA_BOOL enableDhcpIpConfiguration)2869fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetIpConfigMethod(
2870fcf3ce44SJohn Forte 		IMA_OID oid,
2871fcf3ce44SJohn Forte 		IMA_BOOL enableDhcpIpConfiguration
2872fcf3ce44SJohn Forte )
2873fcf3ce44SJohn Forte {
2874fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2875fcf3ce44SJohn Forte }
2876fcf3ce44SJohn Forte 
IMA_RegisterForObjectPropertyChanges(IMA_OBJECT_PROPERTY_FN pClientFn)2877fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_RegisterForObjectPropertyChanges(
2878fcf3ce44SJohn Forte 		IMA_OBJECT_PROPERTY_FN pClientFn
2879fcf3ce44SJohn Forte )
2880fcf3ce44SJohn Forte {
2881fcf3ce44SJohn Forte 	pObjectPropertyCallback = pClientFn;
2882fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2883fcf3ce44SJohn Forte }
2884fcf3ce44SJohn Forte 
2885fcf3ce44SJohn Forte /* ARGSUSED */
IMA_DeregisterForObjectPropertyChanges(IMA_OBJECT_PROPERTY_FN pClientFn)2886fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_DeregisterForObjectPropertyChanges(
2887fcf3ce44SJohn Forte 		IMA_OBJECT_PROPERTY_FN pClientFn
2888fcf3ce44SJohn Forte )
2889fcf3ce44SJohn Forte {
2890fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2891fcf3ce44SJohn Forte }
2892fcf3ce44SJohn Forte 
IMA_RegisterForObjectVisibilityChanges(IMA_OBJECT_VISIBILITY_FN pClientFn)2893fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_RegisterForObjectVisibilityChanges(
2894fcf3ce44SJohn Forte 		IMA_OBJECT_VISIBILITY_FN pClientFn
2895fcf3ce44SJohn Forte )
2896fcf3ce44SJohn Forte {
2897fcf3ce44SJohn Forte 	pObjectVisibilityCallback = pClientFn;
2898fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2899fcf3ce44SJohn Forte }
2900fcf3ce44SJohn Forte 
2901fcf3ce44SJohn Forte /* ARGSUSED */
IMA_DeregisterForObjectVisibilityChanges(IMA_OBJECT_VISIBILITY_FN pClientFn)2902fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_DeregisterForObjectVisibilityChanges(
2903fcf3ce44SJohn Forte 		IMA_OBJECT_VISIBILITY_FN pClientFn
2904fcf3ce44SJohn Forte )
2905fcf3ce44SJohn Forte {
2906fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2907fcf3ce44SJohn Forte }
2908fcf3ce44SJohn Forte 
2909fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetNetworkPortStatus(IMA_OID portOid,IMA_NETWORK_PORT_STATUS * pStaus)2910fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetNetworkPortStatus(
2911fcf3ce44SJohn Forte 		IMA_OID portOid,
2912fcf3ce44SJohn Forte 		IMA_NETWORK_PORT_STATUS *pStaus
2913fcf3ce44SJohn Forte )
2914fcf3ce44SJohn Forte {
2915fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2916fcf3ce44SJohn Forte }
2917fcf3ce44SJohn Forte 
2918fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetNetworkPortalOidList(IMA_OID pnpOid,IMA_OID_LIST ** ppList)2919fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetNetworkPortalOidList(
2920fcf3ce44SJohn Forte 		IMA_OID pnpOid,
2921fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
2922fcf3ce44SJohn Forte )
2923fcf3ce44SJohn Forte {
2924fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2925fcf3ce44SJohn Forte }
2926fcf3ce44SJohn Forte 
2927fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetNetworkPortalProperties(IMA_OID networkPortalOid,IMA_NETWORK_PORTAL_PROPERTIES * pProps)2928fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetNetworkPortalProperties(
2929fcf3ce44SJohn Forte 		IMA_OID networkPortalOid,
2930fcf3ce44SJohn Forte 		IMA_NETWORK_PORTAL_PROPERTIES *pProps
2931fcf3ce44SJohn Forte )
2932fcf3ce44SJohn Forte {
2933fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2934fcf3ce44SJohn Forte }
2935fcf3ce44SJohn Forte 
2936fcf3ce44SJohn Forte /* ARGSUSED */
IMA_SetNetworkPortalIpAddress(IMA_OID networkPortalOid,const IMA_IP_ADDRESS NewIpAddress)2937fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_SetNetworkPortalIpAddress(
2938fcf3ce44SJohn Forte 		IMA_OID networkPortalOid,
2939fcf3ce44SJohn Forte 		const IMA_IP_ADDRESS NewIpAddress
2940fcf3ce44SJohn Forte )
2941fcf3ce44SJohn Forte {
2942fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
2943fcf3ce44SJohn Forte }
2944fcf3ce44SJohn Forte 
2945fcf3ce44SJohn Forte /* ARGSUSED */
IMA_RemoveStaleData(IMA_OID lhbaOid)2946fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_RemoveStaleData(
2947fcf3ce44SJohn Forte 		IMA_OID lhbaOid
2948fcf3ce44SJohn Forte )
2949fcf3ce44SJohn Forte {
2950fcf3ce44SJohn Forte 	return (IMA_ERROR_NOT_SUPPORTED);
2951fcf3ce44SJohn Forte }
2952fcf3ce44SJohn Forte 
2953fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetIpsecProperties(IMA_OID oid,IMA_IPSEC_PROPERTIES * pProps)2954fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetIpsecProperties(
2955fcf3ce44SJohn Forte 		IMA_OID oid,
2956fcf3ce44SJohn Forte 		IMA_IPSEC_PROPERTIES *pProps
2957fcf3ce44SJohn Forte )
2958fcf3ce44SJohn Forte {
2959fcf3ce44SJohn Forte 	pProps->ipsecSupported = IMA_TRUE;
2960fcf3ce44SJohn Forte 	pProps->implementedInHardware = IMA_FALSE;
2961fcf3ce44SJohn Forte 	pProps->implementedInSoftware = IMA_TRUE;
2962fcf3ce44SJohn Forte 
2963fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2964fcf3ce44SJohn Forte }
2965fcf3ce44SJohn Forte 
2966fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetLhbaProperties(IMA_OID lhbaOid,IMA_LHBA_PROPERTIES * pProps)2967fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetLhbaProperties(
2968fcf3ce44SJohn Forte 		IMA_OID lhbaOid,
2969fcf3ce44SJohn Forte 		IMA_LHBA_PROPERTIES *pProps
2970fcf3ce44SJohn Forte )
2971fcf3ce44SJohn Forte {
2972fcf3ce44SJohn Forte 
2973fcf3ce44SJohn Forte 	if (pProps == NULL) {
2974fcf3ce44SJohn Forte 		return (IMA_ERROR_INVALID_PARAMETER);
2975fcf3ce44SJohn Forte 	}
2976fcf3ce44SJohn Forte 
2977fcf3ce44SJohn Forte 	if (lhbaObjectId.objectSequenceNumber != ISCSI_INITIATOR_OID) {
2978fcf3ce44SJohn Forte 		return (IMA_ERROR_OBJECT_NOT_FOUND);
2979fcf3ce44SJohn Forte 	}
2980fcf3ce44SJohn Forte 
2981fcf3ce44SJohn Forte 	(void) memset(pProps, 0, sizeof (IMA_LHBA_PROPERTIES));
2982fcf3ce44SJohn Forte 	(void) mbstowcs(pProps->osDeviceName, OS_DEVICE_NAME,
2983fcf3ce44SJohn Forte 	    OS_DEVICE_NAME_LEN);
2984fcf3ce44SJohn Forte 	pProps->luExposingSupported = IMA_FALSE;
2985fcf3ce44SJohn Forte 	pProps->isDestroyable = IMA_FALSE;
2986fcf3ce44SJohn Forte 	pProps->staleDataRemovable = IMA_FALSE;
2987fcf3ce44SJohn Forte 	pProps->staleDataSize = 0;
2988fcf3ce44SJohn Forte 	pProps->initiatorAuthMethodsSettable = IMA_TRUE;
2989fcf3ce44SJohn Forte 	pProps->targetAuthMethodsSettable = IMA_FALSE;
2990fcf3ce44SJohn Forte 
2991fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
2992fcf3ce44SJohn Forte }
2993fcf3ce44SJohn Forte 
IMA_GetLnpOidList(IMA_OID_LIST ** ppList)2994fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetLnpOidList(
2995fcf3ce44SJohn Forte 		IMA_OID_LIST **ppList
2996fcf3ce44SJohn Forte )
2997fcf3ce44SJohn Forte {
2998fcf3ce44SJohn Forte 	*ppList = (IMA_OID_LIST *) calloc(1, (sizeof (IMA_OID_LIST)));
2999fcf3ce44SJohn Forte 	if (*ppList == NULL) {
3000fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3001fcf3ce44SJohn Forte 	}
3002fcf3ce44SJohn Forte 	(*ppList)->oidCount = 0;
3003fcf3ce44SJohn Forte 
3004fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
3005fcf3ce44SJohn Forte }
3006fcf3ce44SJohn Forte 
3007fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetLnpProperties(IMA_OID lnpOid,IMA_LNP_PROPERTIES * pProps)3008fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetLnpProperties(
3009fcf3ce44SJohn Forte 		IMA_OID lnpOid,
3010fcf3ce44SJohn Forte 		IMA_LNP_PROPERTIES *pProps
3011fcf3ce44SJohn Forte )
3012fcf3ce44SJohn Forte {
3013fcf3ce44SJohn Forte 	return (IMA_ERROR_OBJECT_NOT_FOUND);
3014fcf3ce44SJohn Forte }
3015fcf3ce44SJohn Forte 
3016fcf3ce44SJohn Forte #define	IMA_DISK_DEVICE_NAME_PREFIX	"/dev/rdsk/"
3017fcf3ce44SJohn Forte #define	IMA_TAPE_DEVICE_NAME_PREFIX	"/dev/rmt/"
3018fcf3ce44SJohn Forte static int
get_lun_devlink(di_devlink_t link,void * osDeviceName)3019fcf3ce44SJohn Forte get_lun_devlink(di_devlink_t link, void *osDeviceName)
3020fcf3ce44SJohn Forte {
3021fcf3ce44SJohn Forte 	if ((strncmp(IMA_DISK_DEVICE_NAME_PREFIX, di_devlink_path(link),
3022fcf3ce44SJohn Forte 	    strlen(IMA_DISK_DEVICE_NAME_PREFIX)) == 0) ||
3023fcf3ce44SJohn Forte 	    (strncmp(IMA_TAPE_DEVICE_NAME_PREFIX, di_devlink_path(link),
3024fcf3ce44SJohn Forte 	    strlen(IMA_TAPE_DEVICE_NAME_PREFIX)) == 0)) {
3025fcf3ce44SJohn Forte 		(void) mbstowcs((wchar_t *)osDeviceName, di_devlink_path(link),
3026fcf3ce44SJohn Forte 		    MAXPATHLEN);
3027fcf3ce44SJohn Forte 		return (DI_WALK_TERMINATE);
3028fcf3ce44SJohn Forte 	}
3029fcf3ce44SJohn Forte 
3030fcf3ce44SJohn Forte 	return (DI_WALK_CONTINUE);
3031fcf3ce44SJohn Forte }
3032fcf3ce44SJohn Forte 
3033fcf3ce44SJohn Forte /* ARGSUSED */
IMA_GetPluginProperties(IMA_OID pluginOid,IMA_PLUGIN_PROPERTIES * pProps)3034fcf3ce44SJohn Forte IMA_API IMA_STATUS IMA_GetPluginProperties(
3035fcf3ce44SJohn Forte 	IMA_OID pluginOid,
3036fcf3ce44SJohn Forte 	IMA_PLUGIN_PROPERTIES *pProps
3037fcf3ce44SJohn Forte )
3038fcf3ce44SJohn Forte {
3039fcf3ce44SJohn Forte 	pProps->supportedImaVersion = 1;
3040fcf3ce44SJohn Forte 	libSwprintf(pProps->vendor, L"%ls", LIBRARY_PROPERTY_VENDOR);
3041fcf3ce44SJohn Forte 	libSwprintf(pProps->implementationVersion, L"%ls",
3042fcf3ce44SJohn Forte 	    LIBRARY_PROPERTY_IMPLEMENTATION_VERSION);
3043fcf3ce44SJohn Forte 	libSwprintf(pProps->fileName, L"%ls", LIBRARY_FILE_NAME);
3044fcf3ce44SJohn Forte 	GetBuildTime(&(pProps->buildTime));
3045fcf3ce44SJohn Forte 	pProps->lhbasCanBeCreatedAndDestroyed = IMA_FALSE;
3046fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
3047fcf3ce44SJohn Forte }
3048fcf3ce44SJohn Forte 
getDiscoveryAddressPropertiesList(SUN_IMA_DISC_ADDR_PROP_LIST ** ppList)3049fcf3ce44SJohn Forte IMA_STATUS getDiscoveryAddressPropertiesList(
3050fcf3ce44SJohn Forte     SUN_IMA_DISC_ADDR_PROP_LIST **ppList
3051fcf3ce44SJohn Forte )
3052fcf3ce44SJohn Forte {
3053fcf3ce44SJohn Forte 	int		    fd;
3054fcf3ce44SJohn Forte 	int		    i;
3055fcf3ce44SJohn Forte 	int		    discovery_addr_list_size;
3056fcf3ce44SJohn Forte 	iscsi_addr_list_t   *ialp, al_info;
3057fcf3ce44SJohn Forte 
3058fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3059fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3060fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
3061fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3062fcf3ce44SJohn Forte 	}
3063fcf3ce44SJohn Forte 
3064fcf3ce44SJohn Forte 	(void) memset(&al_info, 0, sizeof (al_info));
3065fcf3ce44SJohn Forte 	al_info.al_vers = ISCSI_INTERFACE_VERSION;
3066fcf3ce44SJohn Forte 	al_info.al_in_cnt = 0;
3067fcf3ce44SJohn Forte 
3068fcf3ce44SJohn Forte 	/*
3069fcf3ce44SJohn Forte 	 * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl to obtain the number of
3070fcf3ce44SJohn Forte 	 * discovery addresses.
3071fcf3ce44SJohn Forte 	 */
3072fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, &al_info) != 0) {
3073fcf3ce44SJohn Forte 		(void) close(fd);
3074fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
3075fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d",
3076fcf3ce44SJohn Forte 		    errno);
3077fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3078fcf3ce44SJohn Forte 	}
3079fcf3ce44SJohn Forte 
3080fcf3ce44SJohn Forte 	discovery_addr_list_size = sizeof (iscsi_addr_list_t);
3081fcf3ce44SJohn Forte 	if (al_info.al_out_cnt > 1) {
3082fcf3ce44SJohn Forte 		discovery_addr_list_size += (sizeof (iscsi_addr_t) *
3083fcf3ce44SJohn Forte 		    al_info.al_out_cnt - 1);
3084fcf3ce44SJohn Forte 	}
3085fcf3ce44SJohn Forte 
3086fcf3ce44SJohn Forte 	ialp = (iscsi_addr_list_t *)calloc(1, discovery_addr_list_size);
3087fcf3ce44SJohn Forte 	if (ialp == NULL) {
3088fcf3ce44SJohn Forte 		(void) close(fd);
3089fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3090fcf3ce44SJohn Forte 	}
3091fcf3ce44SJohn Forte 	ialp->al_vers = ISCSI_INTERFACE_VERSION;
3092fcf3ce44SJohn Forte 	ialp->al_in_cnt = al_info.al_out_cnt;
3093fcf3ce44SJohn Forte 
3094fcf3ce44SJohn Forte 	/*
3095fcf3ce44SJohn Forte 	 * Issue ISCSI_DISCOVERY_ADDR_LIST_GET ioctl again to obtain the
3096fcf3ce44SJohn Forte 	 * discovery addresses.
3097fcf3ce44SJohn Forte 	 */
3098fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_DISCOVERY_ADDR_LIST_GET, ialp) != 0) {
3099fcf3ce44SJohn Forte 		free(ialp);
3100fcf3ce44SJohn Forte 		(void) close(fd);
3101fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
3102fcf3ce44SJohn Forte 		    "ISCSI_DISCOVERY_ADDR_LIST_GET ioctl failed, errno: %d",
3103fcf3ce44SJohn Forte 		    errno);
3104fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3105fcf3ce44SJohn Forte 	}
3106fcf3ce44SJohn Forte 
3107fcf3ce44SJohn Forte 	*ppList = (SUN_IMA_DISC_ADDR_PROP_LIST *)
3108fcf3ce44SJohn Forte 	    calloc(1, sizeof (SUN_IMA_DISC_ADDR_PROP_LIST) +
3109fcf3ce44SJohn Forte 	    ialp->al_out_cnt * sizeof (IMA_DISCOVERY_ADDRESS_PROPERTIES));
3110fcf3ce44SJohn Forte 
3111fcf3ce44SJohn Forte 	if (*ppList == NULL) {
3112fcf3ce44SJohn Forte 		free(ialp);
3113fcf3ce44SJohn Forte 		(void) close(fd);
3114fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3115fcf3ce44SJohn Forte 	}
3116fcf3ce44SJohn Forte 	(*ppList)->discAddrCount = ialp->al_out_cnt;
3117fcf3ce44SJohn Forte 
3118fcf3ce44SJohn Forte 	for (i = 0; i < ialp->al_out_cnt; i++) {
3119fcf3ce44SJohn Forte 		if (ialp->al_addrs[i].a_addr.i_insize ==
3120fcf3ce44SJohn Forte 		    sizeof (struct in_addr)) {
3121fcf3ce44SJohn Forte 			(*ppList)->props[i].discoveryAddress.hostnameIpAddress.
3122fcf3ce44SJohn Forte 			id.ipAddress.ipv4Address = IMA_TRUE;
3123fcf3ce44SJohn Forte 		} else if (ialp->al_addrs[i].a_addr.i_insize ==
3124fcf3ce44SJohn Forte 		    sizeof (struct in6_addr)) {
3125fcf3ce44SJohn Forte 			(*ppList)->props[i].discoveryAddress.
3126fcf3ce44SJohn Forte 			hostnameIpAddress.id.ipAddress.ipv4Address = IMA_FALSE;
3127fcf3ce44SJohn Forte 		} else {
3128fcf3ce44SJohn Forte 			/* Should not happen */
3129fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
3130fcf3ce44SJohn Forte 			"ISCSI_STATIC_GET returned bad address");
3131fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3132fcf3ce44SJohn Forte 		}
3133fcf3ce44SJohn Forte 
3134fcf3ce44SJohn Forte 		bcopy(&ialp->al_addrs[i].a_addr.i_addr,	(*ppList)->props[i].
3135fcf3ce44SJohn Forte 		    discoveryAddress.hostnameIpAddress.id.ipAddress.ipAddress,
3136fcf3ce44SJohn Forte 		    sizeof ((*ppList)->props[i].discoveryAddress.
3137fcf3ce44SJohn Forte 		    hostnameIpAddress.id.ipAddress.ipAddress));
3138fcf3ce44SJohn Forte 
3139fcf3ce44SJohn Forte 		(*ppList)->props[i].discoveryAddress.portNumber =
3140fcf3ce44SJohn Forte 		    ialp->al_addrs[i].a_port;
3141fcf3ce44SJohn Forte 	}
3142fcf3ce44SJohn Forte 
3143fcf3ce44SJohn Forte 	free(ialp);
3144fcf3ce44SJohn Forte 	(void) close(fd);
3145fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
3146fcf3ce44SJohn Forte }
3147fcf3ce44SJohn Forte 
3148fcf3ce44SJohn Forte 
3149fcf3ce44SJohn Forte /* ARGSUSED */
sendTargets(IMA_TARGET_ADDRESS address,SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES ** ppList)3150fcf3ce44SJohn Forte IMA_STATUS sendTargets(
3151fcf3ce44SJohn Forte     IMA_TARGET_ADDRESS address,
3152fcf3ce44SJohn Forte     SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES **ppList
3153fcf3ce44SJohn Forte )
3154fcf3ce44SJohn Forte {
3155fcf3ce44SJohn Forte 	char	*colonPos;
3156fcf3ce44SJohn Forte 	char	discAddrStr[SUN_IMA_IP_ADDRESS_LEN];
3157fcf3ce44SJohn Forte 	int	fd;
3158fcf3ce44SJohn Forte 	int	ctr;
3159fcf3ce44SJohn Forte 	int	stl_sz;
3160fcf3ce44SJohn Forte 	iscsi_sendtgts_list_t	*stl_hdr = NULL;
3161fcf3ce44SJohn Forte 	IMA_BOOL		retry = IMA_TRUE;
3162fcf3ce44SJohn Forte 
3163fcf3ce44SJohn Forte #define	SENDTGTS_DEFAULT_NUM_TARGETS	10
3164fcf3ce44SJohn Forte 
3165fcf3ce44SJohn Forte 	stl_sz = sizeof (*stl_hdr) + ((SENDTGTS_DEFAULT_NUM_TARGETS - 1) *
3166fcf3ce44SJohn Forte 	    sizeof (iscsi_sendtgts_entry_t));
3167fcf3ce44SJohn Forte 	stl_hdr = (iscsi_sendtgts_list_t *)calloc(1, stl_sz);
3168fcf3ce44SJohn Forte 	if (stl_hdr == NULL) {
3169fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3170fcf3ce44SJohn Forte 	}
3171fcf3ce44SJohn Forte 	stl_hdr->stl_entry.e_vers = ISCSI_INTERFACE_VERSION;
3172fcf3ce44SJohn Forte 	stl_hdr->stl_in_cnt = SENDTGTS_DEFAULT_NUM_TARGETS;
3173fcf3ce44SJohn Forte 
3174fcf3ce44SJohn Forte 	colonPos = strchr(discAddrStr, ':');
3175fcf3ce44SJohn Forte 	if (colonPos == NULL) {
3176fcf3ce44SJohn Forte 		/* IPv4 */
3177fcf3ce44SJohn Forte 		stl_hdr->stl_entry.e_insize = sizeof (struct in_addr);
3178fcf3ce44SJohn Forte 	} else {
3179fcf3ce44SJohn Forte 		/* IPv6 */
3180fcf3ce44SJohn Forte 		stl_hdr->stl_entry.e_insize = sizeof (struct in6_addr);
3181fcf3ce44SJohn Forte 	}
3182fcf3ce44SJohn Forte 
3183fcf3ce44SJohn Forte 
3184fcf3ce44SJohn Forte 	bcopy(address.hostnameIpAddress.id.ipAddress.ipAddress,
3185fcf3ce44SJohn Forte 	    &stl_hdr->stl_entry.e_u,
3186fcf3ce44SJohn Forte 	    sizeof (address.hostnameIpAddress.id.ipAddress.ipAddress));
3187fcf3ce44SJohn Forte 	stl_hdr->stl_entry.e_port = address.portNumber;
3188fcf3ce44SJohn Forte 
3189fcf3ce44SJohn Forte 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3190fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3191fcf3ce44SJohn Forte 		    ISCSI_DRIVER_DEVCTL, errno);
3192fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3193fcf3ce44SJohn Forte 	}
3194fcf3ce44SJohn Forte 
3195fcf3ce44SJohn Forte retry_sendtgts:
3196fcf3ce44SJohn Forte 	/*
3197fcf3ce44SJohn Forte 	 * Issue ioctl to obtain the SendTargets list
3198fcf3ce44SJohn Forte 	 */
3199fcf3ce44SJohn Forte 	if (ioctl(fd, ISCSI_SENDTGTS_GET, stl_hdr) != 0) {
3200fcf3ce44SJohn Forte 		syslog(LOG_USER|LOG_DEBUG,
3201fcf3ce44SJohn Forte 		    "ISCSI_SENDTGTS_GET ioctl failed, errno: %d", errno);
3202fcf3ce44SJohn Forte 		(void) close(fd);
3203fcf3ce44SJohn Forte 		free(stl_hdr);
3204fcf3ce44SJohn Forte 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3205fcf3ce44SJohn Forte 	}
3206fcf3ce44SJohn Forte 
3207fcf3ce44SJohn Forte 	/* check if all targets received */
3208fcf3ce44SJohn Forte 	if (stl_hdr->stl_in_cnt < stl_hdr->stl_out_cnt) {
3209fcf3ce44SJohn Forte 		if (retry == IMA_TRUE) {
3210fcf3ce44SJohn Forte 			stl_sz = sizeof (*stl_hdr) +
3211fcf3ce44SJohn Forte 			    ((stl_hdr->stl_out_cnt - 1) *
3212fcf3ce44SJohn Forte 			    sizeof (iscsi_sendtgts_entry_t));
3213fcf3ce44SJohn Forte 			stl_hdr = (iscsi_sendtgts_list_t *)
3214fcf3ce44SJohn Forte 			    realloc(stl_hdr, stl_sz);
3215fcf3ce44SJohn Forte 			if (stl_hdr == NULL) {
3216fcf3ce44SJohn Forte 				(void) close(fd);
3217fcf3ce44SJohn Forte 				return (IMA_ERROR_INSUFFICIENT_MEMORY);
3218fcf3ce44SJohn Forte 			}
3219fcf3ce44SJohn Forte 			stl_hdr->stl_in_cnt = stl_hdr->stl_out_cnt;
3220fcf3ce44SJohn Forte 			retry = IMA_FALSE;
3221fcf3ce44SJohn Forte 			goto retry_sendtgts;
3222fcf3ce44SJohn Forte 		} else {
3223fcf3ce44SJohn Forte 			/*
3224fcf3ce44SJohn Forte 			 * don't retry after 2 attempts.  The target list
3225fcf3ce44SJohn Forte 			 * shouldn't continue to growing. Justs continue
3226fcf3ce44SJohn Forte 			 * on and display what was found.
3227fcf3ce44SJohn Forte 			 */
3228fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
3229fcf3ce44SJohn Forte 			    "ISCSI_SENDTGTS_GET overflow: "
3230fcf3ce44SJohn Forte 			    "failed to obtain all targets");
3231fcf3ce44SJohn Forte 			stl_hdr->stl_out_cnt = stl_hdr->stl_in_cnt;
3232fcf3ce44SJohn Forte 		}
3233fcf3ce44SJohn Forte 	}
3234fcf3ce44SJohn Forte 
3235fcf3ce44SJohn Forte 	(void) close(fd);
3236fcf3ce44SJohn Forte 
3237fcf3ce44SJohn Forte 	/* allocate for caller return buffer */
3238fcf3ce44SJohn Forte 	*ppList = (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES *)calloc(1,
3239fcf3ce44SJohn Forte 	    sizeof (SUN_IMA_DISC_ADDRESS_KEY_PROPERTIES) +
3240fcf3ce44SJohn Forte 	    stl_hdr->stl_out_cnt * sizeof (SUN_IMA_DISC_ADDRESS_KEY));
3241fcf3ce44SJohn Forte 	if (*ppList == NULL) {
3242fcf3ce44SJohn Forte 		free(stl_hdr);
3243fcf3ce44SJohn Forte 		return (IMA_ERROR_INSUFFICIENT_MEMORY);
3244fcf3ce44SJohn Forte 	}
3245fcf3ce44SJohn Forte 
3246fcf3ce44SJohn Forte 	(*ppList)->keyCount = stl_hdr->stl_out_cnt;
3247fcf3ce44SJohn Forte 
3248fcf3ce44SJohn Forte 	for (ctr = 0; ctr < stl_hdr->stl_out_cnt; ctr++) {
3249fcf3ce44SJohn Forte 		(void) mbstowcs((*ppList)->keys[ctr].name,
3250fcf3ce44SJohn Forte 		    (char *)stl_hdr->stl_list[ctr].ste_name,
3251fcf3ce44SJohn Forte 		    IMA_NODE_NAME_LEN);
3252fcf3ce44SJohn Forte 
3253fcf3ce44SJohn Forte 		(*ppList)->keys[ctr].tpgt = stl_hdr->stl_list[ctr].ste_tpgt;
3254fcf3ce44SJohn Forte 
3255fcf3ce44SJohn Forte 		(*ppList)->keys[ctr].address.portNumber =
3256fcf3ce44SJohn Forte 		    stl_hdr->stl_list[ctr].ste_ipaddr.a_port;
3257fcf3ce44SJohn Forte 
3258fcf3ce44SJohn Forte 		if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize ==
3259fcf3ce44SJohn Forte 		    sizeof (struct in_addr)) {
3260fcf3ce44SJohn Forte 			(*ppList)->keys[ctr].address.ipAddress.ipv4Address =
3261fcf3ce44SJohn Forte 			    IMA_TRUE;
3262fcf3ce44SJohn Forte 		} else if (stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize ==
3263fcf3ce44SJohn Forte 		    sizeof (struct in6_addr)) {
3264fcf3ce44SJohn Forte 			(*ppList)->keys[ctr].address.ipAddress.ipv4Address =
3265fcf3ce44SJohn Forte 			    IMA_FALSE;
3266fcf3ce44SJohn Forte 		} else {
3267fcf3ce44SJohn Forte 			free(stl_hdr);
3268fcf3ce44SJohn Forte 			syslog(LOG_USER|LOG_DEBUG,
3269fcf3ce44SJohn Forte 			"ISCSI_STATIC_GET returned bad address");
3270fcf3ce44SJohn Forte 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3271fcf3ce44SJohn Forte 		}
3272fcf3ce44SJohn Forte 
3273fcf3ce44SJohn Forte 
3274fcf3ce44SJohn Forte 		(void) memcpy(&(*ppList)->keys[ctr].address.ipAddress.ipAddress,
3275fcf3ce44SJohn Forte 		    &(stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_addr),
3276fcf3ce44SJohn Forte 		    stl_hdr->stl_list[ctr].ste_ipaddr.a_addr.i_insize);
3277fcf3ce44SJohn Forte 	}
3278fcf3ce44SJohn Forte 	free(stl_hdr);
3279fcf3ce44SJohn Forte 
3280fcf3ce44SJohn Forte 	return (IMA_STATUS_SUCCESS);
3281fcf3ce44SJohn Forte }
3282aff4bce5Syi zhang - Sun Microsystems - Beijing China 
SUN_IMA_GetTunableProperties(IMA_OID oid,ISCSI_TUNABLE_PARAM * param)3283aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_API IMA_STATUS SUN_IMA_GetTunableProperties(
3284aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_OID oid,
3285aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ISCSI_TUNABLE_PARAM *param)
3286aff4bce5Syi zhang - Sun Microsystems - Beijing China {
3287aff4bce5Syi zhang - Sun Microsystems - Beijing China 	int fd;
3288aff4bce5Syi zhang - Sun Microsystems - Beijing China 	iscsi_tunable_object_t pg;
3289aff4bce5Syi zhang - Sun Microsystems - Beijing China 
3290aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3291aff4bce5Syi zhang - Sun Microsystems - Beijing China 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3292aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    ISCSI_DRIVER_DEVCTL, errno);
3293aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3294aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
3295aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) memset(&pg, 0, sizeof (iscsi_tunable_object_t));
3296aff4bce5Syi zhang - Sun Microsystems - Beijing China 	pg.t_param = param->tunable_objectType;
3297aff4bce5Syi zhang - Sun Microsystems - Beijing China 	pg.t_oid = (uint32_t)oid.objectSequenceNumber;
3298aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (ioctl(fd, ISCSI_TUNABLE_PARAM_GET, &pg) == -1) {
3299aff4bce5Syi zhang - Sun Microsystems - Beijing China 		syslog(LOG_USER|LOG_DEBUG,
3300aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    "ISCSI_TUNABLE_PARAM_GET ioctl failed, errno: %d", errno);
3301aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) close(fd);
3302aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3303aff4bce5Syi zhang - Sun Microsystems - Beijing China 	} else {
3304aff4bce5Syi zhang - Sun Microsystems - Beijing China 		long long value;
3305aff4bce5Syi zhang - Sun Microsystems - Beijing China 		char tmp[MAX_LONG_LONG_STRING_LEN], *ptr = NULL;
3306aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if (pg.t_set == B_FALSE) {
3307aff4bce5Syi zhang - Sun Microsystems - Beijing China 			/* default value */
3308aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) close(fd);
3309aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (IMA_STATUS_SUCCESS);
3310aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
3311aff4bce5Syi zhang - Sun Microsystems - Beijing China 		value = (long long)pg.t_value.v_integer;
33120f79c548Syi zhang - Sun Microsystems - Beijing China 		ptr = lltostr(value, &tmp[MAX_LONG_LONG_STRING_LEN -1]);
3313aff4bce5Syi zhang - Sun Microsystems - Beijing China 		if ((ptr != NULL) && (ptr != tmp)) {
33140f79c548Syi zhang - Sun Microsystems - Beijing China 			tmp[MAX_LONG_LONG_STRING_LEN - 1] = '\0';
3315aff4bce5Syi zhang - Sun Microsystems - Beijing China 		} else {
3316aff4bce5Syi zhang - Sun Microsystems - Beijing China 			(void) close(fd);
3317aff4bce5Syi zhang - Sun Microsystems - Beijing China 			return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3318aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
3319aff4bce5Syi zhang - Sun Microsystems - Beijing China 		switch (param->tunable_objectType) {
3320aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case ISCSI_RX_TIMEOUT_VALUE:
3321aff4bce5Syi zhang - Sun Microsystems - Beijing China 				(void) strlcpy(param->tunable_objectValue,
33220f79c548Syi zhang - Sun Microsystems - Beijing China 				    ptr, strlen(ptr) + 1);
3323aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
3324aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case ISCSI_CONN_DEFAULT_LOGIN_MAX:
3325aff4bce5Syi zhang - Sun Microsystems - Beijing China 				(void) strlcpy(param->tunable_objectValue,
33260f79c548Syi zhang - Sun Microsystems - Beijing China 				    ptr, strlen(ptr) + 1);
3327aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
3328aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case ISCSI_LOGIN_POLLING_DELAY:
3329aff4bce5Syi zhang - Sun Microsystems - Beijing China 				(void) strlcpy(param->tunable_objectValue,
33300f79c548Syi zhang - Sun Microsystems - Beijing China 				    ptr, strlen(ptr) + 1);
3331aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
3332aff4bce5Syi zhang - Sun Microsystems - Beijing China 			default:
3333aff4bce5Syi zhang - Sun Microsystems - Beijing China 				break;
3334aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
3335aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
3336aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) close(fd);
3337aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (IMA_STATUS_SUCCESS);
3338aff4bce5Syi zhang - Sun Microsystems - Beijing China }
3339aff4bce5Syi zhang - Sun Microsystems - Beijing China 
SUN_IMA_SetTunableProperties(IMA_OID oid,ISCSI_TUNABLE_PARAM * param)3340aff4bce5Syi zhang - Sun Microsystems - Beijing China IMA_API IMA_STATUS SUN_IMA_SetTunableProperties(
3341aff4bce5Syi zhang - Sun Microsystems - Beijing China 	IMA_OID oid,
3342aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ISCSI_TUNABLE_PARAM *param)
3343aff4bce5Syi zhang - Sun Microsystems - Beijing China {
3344aff4bce5Syi zhang - Sun Microsystems - Beijing China 	int fd;
3345aff4bce5Syi zhang - Sun Microsystems - Beijing China 	iscsi_tunable_object_t	ps;
3346aff4bce5Syi zhang - Sun Microsystems - Beijing China 
3347aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if ((fd = open(ISCSI_DRIVER_DEVCTL, O_RDONLY)) == -1) {
3348aff4bce5Syi zhang - Sun Microsystems - Beijing China 		syslog(LOG_USER|LOG_DEBUG, "Cannot open %s (%d)",
3349aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    ISCSI_DRIVER_DEVCTL, errno);
3350aff4bce5Syi zhang - Sun Microsystems - Beijing China 		return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3351aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
3352aff4bce5Syi zhang - Sun Microsystems - Beijing China 
3353aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) memset(&ps, 0, sizeof (iscsi_tunable_object_t));
3354aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ps.t_oid = oid.objectSequenceNumber;
3355aff4bce5Syi zhang - Sun Microsystems - Beijing China 	ps.t_param = param->tunable_objectType;
3356aff4bce5Syi zhang - Sun Microsystems - Beijing China 	switch (param->tunable_objectType) {
3357aff4bce5Syi zhang - Sun Microsystems - Beijing China 		long tmp;
3358aff4bce5Syi zhang - Sun Microsystems - Beijing China 		case ISCSI_RX_TIMEOUT_VALUE:
3359aff4bce5Syi zhang - Sun Microsystems - Beijing China 		case ISCSI_CONN_DEFAULT_LOGIN_MAX:
3360aff4bce5Syi zhang - Sun Microsystems - Beijing China 		case ISCSI_LOGIN_POLLING_DELAY:
3361aff4bce5Syi zhang - Sun Microsystems - Beijing China 			tmp = strtol(param->tunable_objectValue,
3362aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    NULL, 10);
3363aff4bce5Syi zhang - Sun Microsystems - Beijing China 			if (((tmp == 0) && (errno == EINVAL)) ||
3364aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ((tmp == LONG_MAX) && (errno == ERANGE)) ||
3365aff4bce5Syi zhang - Sun Microsystems - Beijing China 			    ((tmp == LONG_MIN) && (errno == ERANGE))) {
3366aff4bce5Syi zhang - Sun Microsystems - Beijing China 				(void) close(fd);
3367aff4bce5Syi zhang - Sun Microsystems - Beijing China 				return (IMA_ERROR_INVALID_PARAMETER);
3368aff4bce5Syi zhang - Sun Microsystems - Beijing China 			}
3369aff4bce5Syi zhang - Sun Microsystems - Beijing China 			ps.t_value.v_integer = (uint32_t)tmp;
3370aff4bce5Syi zhang - Sun Microsystems - Beijing China 			break;
3371aff4bce5Syi zhang - Sun Microsystems - Beijing China 		default:
3372aff4bce5Syi zhang - Sun Microsystems - Beijing China 			break;
3373aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
3374aff4bce5Syi zhang - Sun Microsystems - Beijing China 	if (ioctl(fd, ISCSI_TUNABLE_PARAM_SET, &ps)) {
3375aff4bce5Syi zhang - Sun Microsystems - Beijing China 		int tmpErrno = errno;
3376aff4bce5Syi zhang - Sun Microsystems - Beijing China 		syslog(LOG_USER|LOG_DEBUG,
3377aff4bce5Syi zhang - Sun Microsystems - Beijing China 		    "ISCSI_TUNABLE_PARAM_SET ioctl failed, errno: %d", errno);
3378aff4bce5Syi zhang - Sun Microsystems - Beijing China 		(void) close(fd);
3379aff4bce5Syi zhang - Sun Microsystems - Beijing China 		switch (tmpErrno) {
3380aff4bce5Syi zhang - Sun Microsystems - Beijing China 			case ENOTSUP :
3381aff4bce5Syi zhang - Sun Microsystems - Beijing China 				return (IMA_ERROR_NOT_SUPPORTED);
3382aff4bce5Syi zhang - Sun Microsystems - Beijing China 			default:
3383aff4bce5Syi zhang - Sun Microsystems - Beijing China 				return (IMA_ERROR_UNEXPECTED_OS_ERROR);
3384aff4bce5Syi zhang - Sun Microsystems - Beijing China 		}
3385aff4bce5Syi zhang - Sun Microsystems - Beijing China 	}
3386aff4bce5Syi zhang - Sun Microsystems - Beijing China 	(void) close(fd);
3387aff4bce5Syi zhang - Sun Microsystems - Beijing China 	return (IMA_STATUS_SUCCESS);
3388aff4bce5Syi zhang - Sun Microsystems - Beijing China }
3389