5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2000 by Cisco Systems, Inc. All rights reserved.
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * iSCSI Software Initiator
27 */
28
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <sys/conf.h>
32 #include <sys/cmn_err.h>
33 #include <sys/stat.h>
34 #include <sys/pathname.h>
35 #include <sys/door.h>
36 #include <sys/kmem.h>
37 #include <sys/socket.h>
38 #include <sys/fs/snode.h>
39 #include <netinet/in.h>
40
41 #include <sys/scsi/adapters/iscsi_door.h>
42 #include "iscsi.h"
43
44 #define ISCSI_DOOR_MAX_SEMA_VALUE 16
226 * There's some limitations to the information returned by this function.
227 * Only one address of the address list returned by getipnodebyname() is
228 * returned. The other parameters of the structure should be ignored.
229 */
230 struct hostent *
231 kgetipnodebyname(
232 const char *name,
233 int af,
234 int flags,
235 int *error_num
236 )
237 {
238 door_arg_t arg;
239 mybuffer_t *buffer;
240 size_t msg_size = ISCSI_DOOR_MAX_DATA_SIZE;
241 size_t hostent_size = ISCSI_DOOR_MAX_DATA_SIZE;
242 size_t buffer_size;
243 getipnodebyname_req_t *req;
244 getipnodebyname_cnf_t *cnf;
245 struct hostent *hptr;
246 int i;
247 uint16_t *swap;
248
249
250 buffer_size = msg_size + hostent_size + sizeof (mybuffer_t);
251 buffer = (mybuffer_t *)kmem_zalloc(buffer_size, KM_SLEEP);
252
253 if (buffer) {
254
255 /*
256 * The buffer was successfully allocated.
257 *
258 * Buffer
259 *
260 * +--------------------+ <--- buffer
261 * | mybuffer_t |
262 * +--------------------+ <--- hptr
263 * | |
264 * | |
265 * | hostent_size |
266 * | |
267 * | |
295 case AF_INET:
296 hptr->h_length = sizeof (struct in_addr);
297 break;
298 case AF_INET6:
299 hptr->h_length = sizeof (struct in6_addr);
300 break;
301 default:
302 kfreehostent(hptr);
303 *error_num = NO_RECOVERY;
304 return (NULL);
305 }
306 if ((msg_size < hptr->h_length) ||
307 (hostent_size < sizeof (char *))) {
308 kfreehostent(hptr);
309 *error_num = NO_RECOVERY;
310 return (NULL);
311 }
312 if (inet_pton(af, (char *)name, cnf) == 1) {
313 /*
314 * inet_pton converted the string successfully.
315 * reset to network order. swaps based on nfs code
316 */
317 if (af == AF_INET) {
318 *((uint32_t *)cnf) = htonl(*((uint32_t *)cnf));
319 } else {
320 for (swap = ((void *)cnf), i = 0;
321 i < hptr->h_length / sizeof (uint16_t);
322 i++) {
323 swap[i] = htons(swap[i]);
324 }
325 }
326 hptr->h_addrtype = af;
327 hptr->h_addr_list = (char **)((char *)hptr +
328 sizeof (struct hostent));
329 *hptr->h_addr_list = (char *)cnf;
330 return (hptr);
331 }
332
333 /*
334 * The name couldn't ne converted by inet_pton. The door is
335 * called.
336 */
337
338 /* Header initialization. */
339 req->hdr.signature = ISCSI_DOOR_REQ_SIGNATURE;
340 req->hdr.version = ISCSI_DOOR_REQ_VERSION_1;
341 req->hdr.opcode = ISCSI_DOOR_GETIPNODEBYNAME_REQ;
342
343 /* Body initialization. */
344 req->name_length = strlen(name);
345 if (req->name_length >
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2000 by Cisco Systems, Inc. All rights reserved.
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
26 *
27 * iSCSI Software Initiator
28 */
29
30 #include <sys/types.h>
31 #include <sys/errno.h>
32 #include <sys/conf.h>
33 #include <sys/cmn_err.h>
34 #include <sys/stat.h>
35 #include <sys/pathname.h>
36 #include <sys/door.h>
37 #include <sys/kmem.h>
38 #include <sys/socket.h>
39 #include <sys/fs/snode.h>
40 #include <netinet/in.h>
41
42 #include <sys/scsi/adapters/iscsi_door.h>
43 #include "iscsi.h"
44
45 #define ISCSI_DOOR_MAX_SEMA_VALUE 16
227 * There's some limitations to the information returned by this function.
228 * Only one address of the address list returned by getipnodebyname() is
229 * returned. The other parameters of the structure should be ignored.
230 */
231 struct hostent *
232 kgetipnodebyname(
233 const char *name,
234 int af,
235 int flags,
236 int *error_num
237 )
238 {
239 door_arg_t arg;
240 mybuffer_t *buffer;
241 size_t msg_size = ISCSI_DOOR_MAX_DATA_SIZE;
242 size_t hostent_size = ISCSI_DOOR_MAX_DATA_SIZE;
243 size_t buffer_size;
244 getipnodebyname_req_t *req;
245 getipnodebyname_cnf_t *cnf;
246 struct hostent *hptr;
247
248
249 buffer_size = msg_size + hostent_size + sizeof (mybuffer_t);
250 buffer = (mybuffer_t *)kmem_zalloc(buffer_size, KM_SLEEP);
251
252 if (buffer) {
253
254 /*
255 * The buffer was successfully allocated.
256 *
257 * Buffer
258 *
259 * +--------------------+ <--- buffer
260 * | mybuffer_t |
261 * +--------------------+ <--- hptr
262 * | |
263 * | |
264 * | hostent_size |
265 * | |
266 * | |
294 case AF_INET:
295 hptr->h_length = sizeof (struct in_addr);
296 break;
297 case AF_INET6:
298 hptr->h_length = sizeof (struct in6_addr);
299 break;
300 default:
301 kfreehostent(hptr);
302 *error_num = NO_RECOVERY;
303 return (NULL);
304 }
305 if ((msg_size < hptr->h_length) ||
306 (hostent_size < sizeof (char *))) {
307 kfreehostent(hptr);
308 *error_num = NO_RECOVERY;
309 return (NULL);
310 }
311 if (inet_pton(af, (char *)name, cnf) == 1) {
312 /*
313 * inet_pton converted the string successfully.
314 */
315 hptr->h_addrtype = af;
316 hptr->h_addr_list = (char **)((char *)hptr +
317 sizeof (struct hostent));
318 *hptr->h_addr_list = (char *)cnf;
319 return (hptr);
320 }
321
322 /*
323 * The name couldn't ne converted by inet_pton. The door is
324 * called.
325 */
326
327 /* Header initialization. */
328 req->hdr.signature = ISCSI_DOOR_REQ_SIGNATURE;
329 req->hdr.version = ISCSI_DOOR_REQ_VERSION_1;
330 req->hdr.opcode = ISCSI_DOOR_GETIPNODEBYNAME_REQ;
331
332 /* Body initialization. */
333 req->name_length = strlen(name);
334 if (req->name_length >
|