fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2000 by Cisco Systems, Inc. All rights reserved.
4246c8e92ef9ad6ada2b992b7af02832ff071bf7Jack Meng * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
59927d313a821b7f3822314ed16fc0a44c128431Yuri Pankov * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI Software Initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_door_ini
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function initializes the variables needed to handle the door upcall.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_door_term
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function releases the resources allocated to handle the door
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * upcall. It disconnects from the door if currently connected.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_door_bind
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function tries to connect the iscsi_door. If it succeeds
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it keeps the vnode.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The lookup failed. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The new handle is stored. If we had one, it is released. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_door_unbind
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function releases the current door handle.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_door_upcall
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function tries to call the iscsi_door.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This semaphore limits the number of simultaneous calls
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the door.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The mutex protecting the iscsi_door_handle is entered.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* There's no door handle. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kfreehostent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function frees the memory returned by kgetipnodebyname.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer = (mybuffer_t *)((char *)hptr - sizeof (mybuffer_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(buffer->signature == ISCSI_DOOR_REQ_SIGNATURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buffer->signature == ISCSI_DOOR_REQ_SIGNATURE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A message should be logged here. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kgetipnodebyname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function builds a request that will be sent to the iscsi_door.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The iSCSI door after receiving the request calls getipnodebyaddr().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for more information on the input, output parameter and return value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * consult the man page for getipnodebyname().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Before calling the iscsi door this function tries to do the conversion
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * locally. If a name resolution is needed the iscsi door is called.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There's some limitations to the information returned by this function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only one address of the address list returned by getipnodebyname() is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returned. The other parameters of the structure should be ignored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer_size = msg_size + hostent_size + sizeof (mybuffer_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buffer = (mybuffer_t *)kmem_zalloc(buffer_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The buffer was successfully allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------+ <--- buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | mybuffer_t |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------+ <--- hptr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | hostent_size |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------+ <--- req, cnf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | msg_size |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hptr = (struct hostent *)((char *)buffer + sizeof (mybuffer_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req = (getipnodebyname_req_t *)((char *)hptr + hostent_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnf = (getipnodebyname_cnf_t *)((char *)hptr + hostent_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We try first locally. If the conversion cannot be done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by inet_pton the door is called.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The cnf address is used as output buffer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inet_pton returns '1' if the conversion was successful.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (hostent_size < sizeof (char *))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inet_pton converted the string successfully.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct hostent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The name couldn't ne converted by inet_pton. The door is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Header initialization. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->hdr.opcode = ISCSI_DOOR_GETIPNODEBYNAME_REQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Body initialization. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (msg_size - sizeof (getipnodebyname_req_t) - 1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->name_offset = sizeof (getipnodebyname_req_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Door argument initialization. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The door call failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The door call itself was successful. The value returned
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in arg.rbuf should be cnf, but we never know.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cnf->hdr.signature != ISCSI_DOOR_REQ_SIGNATURE) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cnf->hdr.version != ISCSI_DOOR_REQ_VERSION_1) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (cnf->hdr.opcode != ISCSI_DOOR_GETIPNODEBYNAME_CNF) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((cnf->hdr.status != ISCSI_DOOR_STATUS_SUCCESS) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The door didn't like the request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct hostent));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *hptr->h_addr_list = ((char *)cnf + cnf->h_addr_list_offset);