fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSNS Client
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h" /* For ISCSI_MAX_IOVEC */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_protocol.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_client.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sunddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/tcp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* For local use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_MAX_IOVEC 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_XID (2^16)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_RCV_RSP_COUNT 10 /* Maximum number of unmatched xid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_RCV_TIMEOUT 5
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_RCV_RETRY_MAX 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IPV4_RSVD_BYTES 10
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct isns_reg_arg {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_alias_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} isns_reg_arg_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct isns_async_thread_arg {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *listening_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} isns_async_thread_arg_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* One global queue to serve all LHBA instances. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ddi_taskq_t *reg_query_taskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t reg_query_taskq_mutex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* One global queue to serve all LHBA instances. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ddi_taskq_t *scn_taskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t scn_taskq_mutex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* One globally maintained transaction ID. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint16_t xid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * One SCN callback registration per LHBA instance. For now, since we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * support only one instance, we create one place holder for the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid (*scn_callback_p)(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * One thread, port, local address, and listening socket per LHBA instance.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For now, since we support only one instance, we create one set of place
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * holder for these data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t esi_scn_thr_to_shutdown = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_thread_t *esi_scn_thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *instance_listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This mutex protects all the per LHBA instance variables, i.e.,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China * esi_scn_thr_to_shutdown, esi_scn_thr_id, and instance_listening_so.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t esi_scn_thr_mutex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* iSNS related helpers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Return status */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_OK 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_BAD_SVR_ADDR 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_INTERNAL_ERR 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISNS_CANNOT_FIND_LOCAL_ADDR 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int discover_isns_server(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_list_t **isns_server_addrs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int create_esi_scn_thr(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void esi_scn_thr_cleanup(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void register_isns_client(void *arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic isns_status_t do_isns_dev_attr_reg(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name, uint8_t *node_alias, uint32_t node_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic isns_status_t do_isns_dev_dereg(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make query to all iSNS servers visible to the specified LHBA.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The query could be made for all target nodes or for a specific target
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic isns_status_t do_isns_query(boolean_t is_query_all_nodes_b,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle, uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name, uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type, isns_portal_group_list_t **pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create DevAttrQuery message requesting portal group information for all
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * target nodes. Send it to the specified iSNS server. Parse the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * DevAttrQueryRsp PDU and translate the results into a portal group list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic isns_status_t do_isns_dev_attr_query_all_nodes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr, uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias, isns_portal_group_list_t **pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create DevAttrQuery message requesting portal group information for the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * specified target node. Send it to the specified iSNS server. Parse the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * DevAttrQueryRsp PDU and translate the results into a portal group list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic isns_status_t do_isns_dev_attr_query_one_node(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr, uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name, uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type, isns_portal_group_list_t **pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void isns_service_esi_scn(iscsi_thread_t *thread, void* arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void (*scn_callback_lookup(uint8_t *lhba_handle))(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Transport related helpers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *isns_open(iscsi_addr_t *isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ssize_t isns_send_pdu(void *socket, isns_pdu_t *pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_rcv_pdu(void *so, isns_pdu_t **pdu, size_t *pdu_size);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing Chinastatic boolean_t find_listening_addr(iscsi_addr_t *local_addr,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China void *listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t find_local_portal(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t **local_addr, void **listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* iSNS protocol related helpers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_pdu_header(uint16_t func_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags, isns_pdu_t **pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int isns_add_attr(isns_pdu_t *pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t max_pdu_size, uint32_t attr_id, uint32_t attr_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *attr_data, uint32_t attr_numeric_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint16_t create_xid(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_dev_attr_reg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name, uint8_t *node_alias, uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_dev_dereg_pdu(uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name, uint8_t *node_alias, uint16_t *xid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_dev_attr_qry_one_pg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *target_node_name, uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_esi_rsp_pdu(uint32_t rsp_status_code,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu, uint16_t *xid, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_scn_reg_pdu(uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias, uint16_t *xid, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_scn_dereg_pdu(uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t isns_create_scn_rsp_pdu(uint32_t rsp_status_code,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu, uint16_t *xid, isns_pdu_t **out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_dev_attr_reg_rsp(isns_pdu_t *resp_pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_dev_attr_dereg_rsp(isns_pdu_t *resp_pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Process and parse a DevAttrQryRsp message. The routine creates a list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of Portal Group objects if the message is parasable without any issue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the parsing is not successful, the pg_list will be set to NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr, uint16_t payload_funcId,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p, size_t resp_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_scn_reg_rsp(isns_pdu_t *resp_pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_scn_dereg_rsp(isns_pdu_t *resp_pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_esi(isns_pdu_t *esi_pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic uint32_t isns_process_scn(isns_pdu_t *scn_pdu_p, uint8_t *lhba_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_client_init()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&reg_query_taskq_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&reg_query_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_query_taskq = ddi_taskq_create(NULL, "isns_reg_query_taskq",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1, TASKQ_DEFAULTPRI, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&reg_query_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&scn_taskq_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_taskq = ddi_taskq_create(NULL, "isns_scn_taskq",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1, TASKQ_DEFAULTPRI, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&esi_scn_thr_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* MISC initializations. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_callback_p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte instance_listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_to_shutdown = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xid = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_client_cleanup()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_taskq_t *tmp_taskq_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_taskq_p = scn_taskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_taskq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_taskq_destroy(tmp_taskq_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&reg_query_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_taskq_p = reg_query_taskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_query_taskq = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&reg_query_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_taskq_destroy(tmp_taskq_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&reg_query_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_cleanup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_reg(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_name_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_alias_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*scn_callback)(void *))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int list_space;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_list_t *isns_server_addr_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_reg_arg_t *reg_args_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Look up the iSNS Server address(es) based on the specified ISID */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discover_isns_server(lhba_handle, &isns_server_addr_list) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No iSNS server discovered - no registration needed. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, list_space);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check and create ESI/SCN threads and populate local address */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < isns_server_addr_list->al_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (create_esi_scn_thr(lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(isns_server_addr_list->al_addrs[i])) == ISNS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i == isns_server_addr_list->al_out_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Problem creating ESI/SCN thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free the server list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space += (sizeof (iscsi_addr_t) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_server_addr_list->al_out_cnt - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, list_space);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_internal_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Register against all iSNS servers discovered. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < isns_server_addr_list->al_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p = kmem_zalloc(sizeof (isns_reg_arg_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->isns_server_addr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (iscsi_addr_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&isns_server_addr_list->al_addrs[i],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->isns_server_addr, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_name = kmem_zalloc(node_name_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(node_name, reg_args_p->node_name, node_name_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_name_len = node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_alias = kmem_zalloc(node_alias_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(node_alias, reg_args_p->node_alias, node_alias_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_alias_len = node_alias_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_type = node_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Dispatch the registration request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte register_isns_client(reg_args_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free the server list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space += (sizeof (iscsi_addr_t) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_server_addr_list->al_out_cnt - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, list_space);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Register the scn_callback. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_callback_p = scn_callback;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_ok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_reg_one_server(entry_t *isns_server,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_name_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t node_alias_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*scn_callback)(void *))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_reg_arg_t *reg_args_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap = (iscsi_addr_t *)kmem_zalloc(sizeof (iscsi_addr_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_port = isns_server->e_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_insize = isns_server->e_insize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server->e_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in4.s_addr = (isns_server->e_u.u_in4.s_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (isns_server->e_insize == sizeof (struct in6_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(isns_server->e_u.u_in6.s6_addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check and create ESI/SCN threads and populate local address */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((status = create_esi_scn_thr(lhba_handle, ap))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != ISNS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Problem creating ESI/SCN thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(isns_reg_one_server_create_esi_scn_thr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_internal_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p = kmem_zalloc(sizeof (isns_reg_arg_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->isns_server_addr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (iscsi_addr_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ap, reg_args_p->isns_server_addr, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_name = kmem_zalloc(node_name_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(node_name, reg_args_p->node_name, node_name_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_name_len = node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_alias = kmem_zalloc(node_alias_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(node_alias, reg_args_p->node_alias, node_alias_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_alias_len = node_alias_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args_p->node_type = node_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Dispatch the registration request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte register_isns_client(reg_args_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Register the scn_callback. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_callback_p = scn_callback;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_ok);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_dereg(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int isns_svr_lst_sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int list_space;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_list_t *isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t dereg_stat, combined_dereg_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Look up the iSNS Server address(es) based on the specified ISID */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discover_isns_server(lhba_handle, &isns_server_addr_list) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isns_server_addr_list != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_svr_lst_sz = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, isns_svr_lst_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_dereg_stat = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < isns_server_addr_list->al_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dereg_stat = do_isns_dev_dereg(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isns_server_addr_list->al_addrs[i],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dereg_stat == isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_dereg_stat != isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_dereg_stat = isns_op_partially_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_dereg_stat == isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_dereg_stat = isns_op_partially_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free the server list. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space += (sizeof (iscsi_addr_t) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_server_addr_list->al_out_cnt - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, list_space);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Cleanup ESI/SCN thread. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_cleanup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (combined_dereg_stat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_dereg_one_server(entry_t *isns_server,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t is_last_isns_server_b)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t dereg_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap = (iscsi_addr_t *)kmem_zalloc(sizeof (iscsi_addr_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_port = isns_server->e_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_insize = isns_server->e_insize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server->e_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in4.s_addr = (isns_server->e_u.u_in4.s_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (isns_server->e_insize == sizeof (struct in6_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(isns_server->e_u.u_in6.s6_addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dereg_stat = do_isns_dev_dereg(ap, node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ap, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_last_isns_server_b == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clean up ESI/SCN thread resource if it is the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * last known iSNS server.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_cleanup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dereg_stat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_query(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (do_isns_query(B_TRUE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint8_t *)"",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_query_one_server(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (do_isns_dev_attr_query_all_nodes(isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_query_one_node(uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (do_isns_query(B_FALSE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_query_one_server_one_node(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not supported yet. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortediscover_isns_server(uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_list_t **isns_server_addrs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte entry_t e;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int isns_server_count = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int list_space;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *void_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use supported iSNS server discovery method to find out all the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSNS servers. For now, only static configuration method is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * supported.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void_p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_isns_addr_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_isns_addr_next(&void_p, &e) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_isns_addr_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_count > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte list_space += (sizeof (iscsi_addr_t) * (isns_server_count - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *isns_server_addrs = (iscsi_addr_list_t *)kmem_zalloc(list_space,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*isns_server_addrs)->al_out_cnt = isns_server_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_isns_addr_lock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void_p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (persistent_isns_addr_next(&void_p, &e) == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *ap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap = &((*isns_server_addrs)->al_addrs[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_port = e.e_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_insize = e.e_insize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e.e_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in4.s_addr = (e.e_u.u_in4.s_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (e.e_insize == sizeof (struct in6_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&e.e_u.u_in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ap->a_addr.i_addr.in6.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(*isns_server_addrs, list_space);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *isns_server_addrs = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_BAD_SVR_ADDR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_isns_addr_unlock();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_esi_scn_thr(uint8_t *lhba_handle, iscsi_addr_t *isns_server_address)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China void *listening_so = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China boolean_t found = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(lhba_handle != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isns_server_address != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Bringing up of the thread should happen regardless of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * subsequent registration status. That means, do not destroy the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ESI/SCN thread already created.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check and create ESI/SCN thread. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China /* Determine local port and address. */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China found = find_local_portal(isns_server_address,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China NULL, &listening_so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (found == B_FALSE) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (listening_so != NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->close(listening_so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_exit(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (ISNS_CANNOT_FIND_LOCAL_ADDR);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (esi_scn_thr_id == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char thr_name[ISCSI_TH_MAX_NAME_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_async_thread_arg_t *larg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Assume the LHBA handle has a length of 4 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(thr_name, sizeof (thr_name) - 1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "isns_client_esi_%x%x%x%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle[0],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle[1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle[2],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle[3]) >=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (thr_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (listening_so != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_INTERNAL_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte larg = kmem_zalloc(sizeof (isns_async_thread_arg_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte larg->lhba_handle = lhba_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte larg->listening_so = listening_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte instance_listening_so = listening_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_to_shutdown = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_id = iscsi_thread_create(NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thr_name, isns_service_esi_scn, (void *)larg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (esi_scn_thr_id == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (listening_so != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte instance_listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_INTERNAL_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_thread_start(esi_scn_thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_thread_destroy(esi_scn_thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (listening_so != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte instance_listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_INTERNAL_ERR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
49311b3511690f5b23558b0fba067bc8067c7a87Jack Meng (void) iscsi_thread_send_wakeup(esi_scn_thr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_OK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteregister_isns_client(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_reg_arg_t *reg_args;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args = (isns_reg_arg_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Deregister stale registration (if any). */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = do_isns_dev_dereg(reg_args->isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == isns_open_conn_err) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Cannot open connection to the server. Stop proceeding. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->isns_server_addr, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->isns_server_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->node_name, reg_args->node_name_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_name = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->node_alias, reg_args->node_alias_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_alias = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args, sizeof (isns_reg_arg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(register_isns_client_dereg, isns_status_t, status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* New registration. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = do_isns_dev_attr_reg(reg_args->isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_name, reg_args->node_alias, reg_args->node_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(register_isns_client_reg, isns_status_t, status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->isns_server_addr, sizeof (iscsi_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->isns_server_addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->node_name, reg_args->node_name_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_name = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args->node_alias, reg_args->node_alias_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reg_args->node_alias = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(reg_args, sizeof (isns_reg_arg_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo_isns_dev_attr_reg(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name, uint8_t *node_alias, uint32_t node_type)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rsp_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *in_pdu, *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bytes_received, in_pdu_size = 0, out_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_dev_attr_reg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = isns_open(isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Log a message and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_open_conn_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= (size_t)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status = isns_process_dev_attr_reg_rsp(in_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status == ISNS_RSP_SRC_UNAUTHORIZED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_partially_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval != isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Always register SCN */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_scn_reg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name, node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= (size_t)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status = isns_process_scn_reg_rsp(in_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo_isns_dev_dereg(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rsp_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *in_pdu, *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bytes_received, in_pdu_size = 0, out_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_dev_dereg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = isns_open(isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Log a message and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_open_conn_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= (size_t)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status = isns_process_dev_attr_dereg_rsp(in_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval != isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Always deregister SCN */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_scn_dereg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= (size_t)0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status = isns_process_scn_dereg_rsp(in_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo_isns_query(boolean_t is_query_all_nodes_b,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j, k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int combined_num_of_pgs, combined_pg_lst_sz,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_svr_lst_sz,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_list_sz,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists_sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_list_t *isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_t *pg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t *combined_pg_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tmp_pg_list, **tmp_pg_lists;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t qry_stat, combined_qry_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Look up the iSNS Server address(es) based on the specified ISID */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (discover_isns_server(lhba_handle, &isns_server_addr_list) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_svr_lst_sz = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, isns_svr_lst_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_no_svr_found);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isns_server_addr_list->al_out_cnt should not be zero by the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * time it comes to this point.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists_sz = isns_server_addr_list->al_out_cnt *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_list_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists = (isns_portal_group_list_t **)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists_sz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_num_of_pgs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_qry_stat = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < isns_server_addr_list->al_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_query_all_nodes_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = do_isns_dev_attr_query_all_nodes(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isns_server_addr_list->al_addrs[i],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &tmp_pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = do_isns_dev_attr_query_one_node(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &isns_server_addr_list->al_addrs[i],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &tmp_pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Record the portal group list retrieved from this server. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists[i] = tmp_pg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp_pg_list != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_num_of_pgs += tmp_pg_list->pg_out_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qry_stat == isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_qry_stat != isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_qry_stat = isns_op_partially_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_qry_stat != isns_op_partially_failed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_qry_stat == isns_ok && i > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_qry_stat =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_op_partially_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_qry_stat = qry_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_query_all_nodes_b == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (qry_stat == isns_ok) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Break out of the loop if we already got
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the node information for one node.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Merge the retrieved portal lists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pg_lst_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_num_of_pgs > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pg_lst_sz += (combined_num_of_pgs - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pg_list = (isns_portal_group_list_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pg_lst_sz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pg_list->pg_out_cnt = combined_num_of_pgs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte k = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < isns_server_addr_list->al_out_cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp_pg_lists[i] == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < tmp_pg_lists[i]->pg_out_cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg = &(combined_pg_list->pg_list[k]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(tmp_pg_lists[i]->pg_list[j]),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg, sizeof (isns_portal_group_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte k++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_list_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp_pg_lists[i]->pg_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_list_sz += (tmp_pg_lists[i]->pg_out_cnt - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pg_lists[i], tmp_pg_list_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists[i] = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pg_lists, tmp_pg_lists_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pg_lists = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_svr_lst_sz = sizeof (iscsi_addr_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr_list->al_out_cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_svr_lst_sz += (sizeof (iscsi_addr_t) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_server_addr_list->al_out_cnt - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(isns_server_addr_list, isns_svr_lst_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(list, isns_portal_group_list_t *, combined_pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = combined_pg_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (combined_qry_stat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo_isns_dev_attr_query_all_nodes(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bytes_received;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rsp_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t xid, seq_id = 0, func_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *in_pdu, *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_mult_payload_t *combined_pdu = NULL, *old_combined_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t qry_stat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t out_pdu_size = 0, in_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t old_combined_pdu_size = 0, combined_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *payload_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = isns_open(isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Log a message and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_open_conn_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Then, ask for all PG attributes. Filter the non-target nodes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name, node_alias, &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * make sure we are processing the right transaction id
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check to see if FIRST and LAST PDU flag is set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if they are both set, then this response only has one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pdu and we can process the pdu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = in_pdu->flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((flags & ISNS_FLAG_FIRST_PDU) == ISNS_FLAG_FIRST_PDU) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((flags & ISNS_FLAG_LAST_PDU) == ISNS_FLAG_LAST_PDU)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_process_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu->func_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_resp_t *)in_pdu->payload,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (size_t)in_pdu->payload_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this pdu is part of a multi-pdu response. save off the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the payload of this pdu and continue processing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & ISNS_FLAG_FIRST_PDU) == ISNS_FLAG_FIRST_PDU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This is the first pdu, make sure sequence ID is 0 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in_pdu->seq != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "isns query response invalid: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "first pdu is not sequence ID 0");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seq_id = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create new pdu and copy in data from old pdu */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu_size = ISNSP_MULT_PAYLOAD_HEADER_SIZE +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu->payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu = (isns_pdu_mult_payload_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte func_id = in_pdu->func_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu->payload_len = in_pdu->payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(in_pdu->payload, combined_pdu->payload,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* done with in_pdu, free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte seq_id++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in_pdu->seq != seq_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "isns query response invalid: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Missing sequence ID %d from isns query "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "response.", seq_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_pdu != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(combined_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if conbined_pdu_size is still zero, then we never
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * processed the first pdu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (combined_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "isns query response invalid: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Did not receive first pdu.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_op_failed);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save off the old combined pdu */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_combined_pdu_size = combined_pdu_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_combined_pdu = combined_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * alloc a new pdu big enough to also hold the new
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pdu payload
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu_size += in_pdu->payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu = (isns_pdu_mult_payload_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy the old pdu into the new allocated pdu buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and append on the new pdu payload that we just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * received
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(old_combined_pdu, combined_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_combined_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = combined_pdu->payload +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu->payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu->payload_len += in_pdu->payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(in_pdu->payload, payload_ptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free in_pdu and old_combined_pdu */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(old_combined_pdu, old_combined_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_combined_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check to see if this is the LAST pdu.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it is, we can process it and move on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise continue to wait for the next pdu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & ISNS_FLAG_LAST_PDU) == ISNS_FLAG_LAST_PDU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_process_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte func_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_resp_t *)combined_pdu->payload,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu->payload_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(combined_pdu, combined_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte combined_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qry_stat = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (qry_stat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo_isns_dev_attr_query_one_node(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t source_node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bytes_received;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rcv_rsp_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rsp_status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *in_pdu, *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_status_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t out_pdu_size = 0, in_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Obtain the list of target type storage nodes first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_dev_attr_qry_one_pg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name, source_node_name, &xid, &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_create_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(out_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = isns_open(isns_server_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Log a message and return */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_open_conn_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(so, out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (isns_send_msg_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done with the out PDU - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_ok;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(so, &in_pdu, &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(bytes_received >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_rcv_msg_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(in_pdu_size > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohs(in_pdu->xid) != xid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcv_rsp_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rcv_rsp_cnt < MAX_RCV_RSP_COUNT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Exceed maximum receive count. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_no_rsp_rcvd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsp_status = isns_process_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr, in_pdu->func_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_resp_t *)in_pdu->payload, (size_t)in_pdu->payload_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_list);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsp_status != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_op_failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*isns_open(iscsi_addr_t *isns_server_addr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr sin;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in s_in4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 s_in6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } sa_rsvr = { 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockaddr_in6 t_addr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t t_addrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&t_addr, sizeof (struct sockaddr_in6));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning t_addrlen = sizeof (struct sockaddr_in6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_server_addr->a_addr.i_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv4 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in4.sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in4.sin_port = htons(isns_server_addr->a_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in4.sin_addr.s_addr =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_server_addr->a_addr.i_addr.in4.s_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create socket */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = iscsi_net->socket(AF_INET, SOCK_STREAM, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in6.sin6_family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(isns_server_addr->a_addr.i_addr.in6),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in6.sin6_addr.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sa_rsvr.s_in6.sin6_port = htons(isns_server_addr->a_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create socket */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = iscsi_net->socket(AF_INET6, SOCK_STREAM, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = iscsi_net->connect(so, &sa_rsvr.sin,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_server_addr->a_addr.i_insize == sizeof (struct in_addr)) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct sockaddr_in) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct sockaddr_in6), 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Flag value 2 indicates both cantsend and cantrecv */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->shutdown(so, 2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) iscsi_net->getsockname(so, (struct sockaddr *)&t_addr,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning &t_addrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic ssize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_send_pdu(void *socket, isns_pdu_t *pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int iovlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec_t iovec[ISNS_MAX_IOVEC];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct msghdr msg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t send_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t total_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(iovlen < ISNS_MAX_IOVEC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[iovlen].iov_base = (void *)pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[iovlen].iov_len = (ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_len += (ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovlen++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(iovlen < ISNS_MAX_IOVEC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[iovlen].iov_base = (void *)pdu->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[iovlen].iov_len = ntohs(pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_len += ntohs(pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovlen++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialization of the message header. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&msg, sizeof (msg));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iov = &iovec[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_flags = MSG_WAITALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iovlen = iovlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte send_len = iscsi_net->sendmsg(socket, &msg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (send_len == total_len ? 0 : -1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_rcv_pdu(void *socket, isns_pdu_t **pdu, size_t *pdu_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int poll_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec_t iovec[ISNS_MAX_IOVEC];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *tmp_pdu_hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bytes_received, total_bytes_received = 0, payload_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct msghdr msg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *tmp_pdu_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Receive the header first */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pdu_hdr = (isns_pdu_t *)kmem_zalloc(ISNSP_HEADER_SIZE, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&iovec[0], 0, sizeof (iovec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[0].iov_base = (void *)tmp_pdu_hdr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[0].iov_len = ISNSP_HEADER_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialization of the message header. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&msg, sizeof (msg));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iov = &iovec[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_flags = MSG_WAITALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iovlen = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Poll and receive the packets. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte poll_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = iscsi_net->recvmsg(socket, &msg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_RCV_TIMEOUT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not yet. Increase poll count and try again. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte poll_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* OK data received. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (poll_cnt < ISNS_RCV_RETRY_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(isns_rcv_pdu_hdr_summary,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, poll_cnt, int, bytes_received);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (poll_cnt >= ISNS_RCV_RETRY_MAX) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0 || bytes_received != ISNSP_HEADER_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_bytes_received += bytes_received;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len = ntohs(tmp_pdu_hdr->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(isns_rcv_pdu_probe1, int, payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Verify the received payload len is within limit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (payload_len > ISNSP_MAX_PAYLOAD_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Proceed to receive additional data. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pdu_data = kmem_zalloc(payload_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((char *)&iovec[0], 0, sizeof (iovec_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[0].iov_base = (void *)tmp_pdu_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovec[0].iov_len = payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Initialization of the message header. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&msg, sizeof (msg));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iov = &iovec[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_flags = MSG_WAITALL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte msg.msg_iovlen = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Poll and receive the rest of the PDU. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte poll_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = iscsi_net->recvmsg(socket, &msg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_RCV_TIMEOUT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Not yet. Increase poll count and try again. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte poll_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* OK data received. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (poll_cnt < ISNS_RCV_RETRY_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(isns_rcv_pdu_data_summary,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, poll_cnt, int, bytes_received);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (poll_cnt >= ISNS_RCV_RETRY_MAX) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_data, payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0 || bytes_received != payload_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_data, payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_bytes_received += bytes_received;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu_size = ISNSP_HEADER_SIZE + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu) = (isns_pdu_t *)kmem_zalloc((*pdu_size), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->version = ntohs(tmp_pdu_hdr->version);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->func_id = ntohs(tmp_pdu_hdr->func_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->payload_len = payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->flags = ntohs(tmp_pdu_hdr->flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->xid = ntohs(tmp_pdu_hdr->xid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->seq = ntohs(tmp_pdu_hdr->seq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(tmp_pdu_data, &((*pdu)->payload), payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_data, payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pdu_data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_pdu_hdr, ISNSP_HEADER_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_pdu_hdr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (total_bytes_received);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isns_create_dev_attr_reg_pdu - isns client registration pdu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_dev_attr_reg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t node_type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_port_t local_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, node_name_len, node_alias_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China boolean_t rval = B_FALSE;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_addr_t local_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_alias != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len = strlen((char *)node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_alias_len = strlen((char *)node_alias) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create DevAttrReg Message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Enable the replace bit so that we can update
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * existing registration
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_REPLACE_REG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_DEV_ATTR_REG, flags, &pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Message Key Attributes
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EID attribute - Section 6.2.1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is required for re-registrations or Replace
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Bit is ignored - Section 5.6.5.1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_EID_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* EID attribute - Section 6.2.1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_EID_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ENTITY Protocol - Section 6.2.2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ENTITY_PROTOCOL_ATTR_ID, 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, ISNS_ENTITY_PROTOCOL_ISCSI) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* iSCSI Name - Section 6.4.1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* iSCSI Alias - Section 6.4.3 Optional */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_alias_len > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_ALIAS_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_alias_len, node_alias, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* iSCSI Node Type - Section 6.4.2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NODE_TYPE_ATTR_ID, 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, node_type) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (instance_listening_so != NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China rval = find_listening_addr(&local_addr, instance_listening_so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (rval == B_FALSE) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China kmem_free(pdu, pdu_size);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *out_pdu = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_exit(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (0);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China kmem_free(pdu, pdu_size);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *out_pdu = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_exit(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (0);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_port = local_addr.a_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Portal IP Address - Section 6.5.2 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_PORTAL_IP_ADDR_ATTR_ID, 16,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China &(local_addr.a_addr.i_addr.in4),
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_addr.a_addr.i_insize) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Portal Port - Section 6.5.3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_PORTAL_PORT_ATTR_ID, 4, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_port) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* SCN Port - Section 6.3.7 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_SCN_PORT_ATTR_ID, 4, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_port) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ESI Port - Section 6.3.5 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ESI_PORT_ATTR_ID, 4, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_port) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isns_create_dev_dereg_pdu - Create an iSNS PDU for deregistration.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_dev_dereg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len = strlen((char *)node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create DevDeReg Message
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_DEV_DEREG, flags, &pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Entity Identifier */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_EID_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * isns_create_dev_attr_target_nodes_pdu - get all accessible targets
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Querys for a list of all accessible target nodes for this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiator. Requests all required login information (name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ip, port, tpgt).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic size_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p, isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_alias != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len = strlen((char *)node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create DevAttrQry Message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_DEV_ATTR_QRY, flags, &pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu_p->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Message Key Attribute
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI Node Type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Query target nodes only
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_ISCSI_NODE_TYPE_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 4, 0, ISNS_TARGET_NODE_TYPE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_DELIMITER_ATTR_ID, 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG iSCSI Name - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal IP Address - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_PORTAL_IP_ADDR_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal Port - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_PORTAL_PORT_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal Group Tag - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_PG_TAG_ATTR_ID, 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_dev_attr_qry_one_pg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *target_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *source_node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, source_node_name_len, target_node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(target_node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(source_node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_name_len = strlen((char *)source_node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name_len = strlen((char *)target_node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (source_node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create DevAttrQry message scoped to target_node_name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_DEV_ATTR_QRY, flags, &pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu_p->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte source_node_name_len, source_node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Message key attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* iSCSI Node Name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_DELIMITER_ATTR_ID, 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG iSCSI Name - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal IP Address - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_PORTAL_IP_ADDR_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal Port - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_PG_PORTAL_PORT_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* PG Portal Group Tag - Zero length TLV */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_PG_TAG_ATTR_ID, 0, 0, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_scn_reg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_alias != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len = strlen((char *)node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create SCNReg Message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_SCN_REG, flags, &pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Message attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Operating attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_SCN_BITMAP_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Microsoft seems to not differentiate between init and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * target. Hence, it makes no difference to turn on/off
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the initiator/target bit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TARGET_SELF_INFO_ONLY |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OBJ_REMOVED |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OBJ_ADDED |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_OBJ_UPDATED) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_scn_dereg_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *node_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, node_name_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(node_name != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* RFC 4171 section 6.1 - NULLs included in the length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len = strlen((char *)node_name) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (node_name_len == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create SCNReg Message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_SCN_DEREG, flags, &pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Source attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Message attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte node_name_len, node_name, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No operating attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_esi_rsp_pdu(uint32_t rsp_status_code,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *esi_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *payload_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t swapped_status_code = htonl(rsp_status_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, payload_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create ESIRsp Message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_ESI_RSP, flags, &pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu_p->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len = ntohs(pdu_p->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Status Code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = pdu_p->payload + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&swapped_status_code, payload_ptr, 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = pdu_p->payload + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((esi_pdu->payload_len) < ISNSP_MAX_PAYLOAD_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(esi_pdu->payload, payload_ptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (esi_pdu->payload_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += (esi_pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(esi_pdu->payload, payload_ptr, ISNSP_MAX_PAYLOAD_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += ISNSP_MAX_PAYLOAD_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_p->payload_len = htons(payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_scn_rsp_pdu(uint32_t rsp_status_code,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *scn_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t *xid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t **out_pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *payload_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t swapped_status_code = htonl(rsp_status_code);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size, payload_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create SCNRsp Message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags = ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_size = isns_create_pdu_header(ISNS_SCN_RSP, flags, &pdu_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xid_p = pdu_p->xid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len = ntohs(pdu_p->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Status Code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = pdu_p->payload + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&swapped_status_code, payload_ptr, 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = pdu_p->payload + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((scn_pdu->payload_len) < ISNSP_MAX_PAYLOAD_SIZE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(scn_pdu->payload, payload_ptr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (scn_pdu->payload_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += (scn_pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(scn_pdu->payload, payload_ptr, ISNSP_MAX_PAYLOAD_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += ISNSP_MAX_PAYLOAD_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu_p->payload_len = htons(payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Delimiter */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_add_attr(pdu_p, pdu_size, ISNS_DELIMITER_ATTR_ID, 0, 0, 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pdu_p, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *out_pdu = pdu_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_dev_attr_reg_rsp(isns_pdu_t *resp_pdu_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resp_pdu_p->func_id != ISNS_DEV_ATTR_REG_RSP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this happens the iSNS server may have a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check response's status code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp_p = (isns_resp_t *)resp_pdu_p->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(resp_p->status) != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohl(resp_p->status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_dev_attr_dereg_rsp(isns_pdu_t *resp_pdu_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resp_pdu_p->func_id != ISNS_DEV_DEREG_RSP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this happens the iSNS server may have a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check response's status code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp_p = (isns_resp_t *)resp_pdu_p->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(resp_p->status) != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohl(resp_p->status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_scn_reg_rsp(isns_pdu_t *resp_pdu_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(resp_pdu_p != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resp_pdu_p->func_id != ISNS_SCN_REG_RSP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this happens the iSNS server may have a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check response's status code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp_p = (isns_resp_t *)resp_pdu_p->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(resp_p->status) != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohl(resp_p->status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_scn_dereg_rsp(isns_pdu_t *resp_pdu_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(resp_pdu_p != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resp_pdu_p->func_id != ISNS_SCN_DEREG_RSP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this happens the iSNS server may have a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check response's status code */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte resp_p = (isns_resp_t *)resp_pdu_p->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(resp_p->status) != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohl(resp_p->status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_dev_attr_qry_target_nodes_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t *isns_server_addr, uint16_t payload_funcId,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_resp_t *resp_p, size_t resp_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_list_t **pg_list)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t done_b, found_delimiter_b, target_node_type_b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int num_of_pgs = 0, pg_sz, idx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_tlv_t *attr_tlv_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *data_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len, total_payload_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_portal_group_t *pg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t junk[IPV4_RSVD_BYTES];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(junk, IPV4_RSVD_BYTES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (payload_funcId != ISNS_DEV_ATTR_QRY_RSP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If this happens the iSNS server may have a problem. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(resp_p->status) != ISNS_RSP_SUCCESSFUL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ntohl(resp_p->status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If payload is smaller than the length of even 1 attribute
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is something wrong with the PDU.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (resp_len < (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Expected DevAttrQryRsp message format:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Status Code
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI Node Type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Delimiter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG iSCSI Name [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Portal IP Address [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Portal Port [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Tag [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG iSCSI Name [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Portal IP Address [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Portal Port [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * PG Tag [Optional]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * .
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * .
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * .
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p = resp_p->data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_delimiter_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte num_of_pgs = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len = sizeof (resp_p->status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Find out the number of entries retrieved */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!done_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv_p = (isns_tlv_t *)data_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(attr_tlv_p->attr_id) == ISNS_DELIMITER_ATTR_ID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found_delimiter_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_delimiter_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ntohl(attr_tlv_p->attr_id) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_PG_TAG_ATTR_ID) {
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China if (ntohl(attr_tlv_p->attr_len) > 0) {
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China /*
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * Count only those iSCSI node that have a
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * non-NULL PGT value as valid Entity.
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * Per rfc4171 section 3.4 - If the PGT value
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * registered for a specified Portal and iSCSI
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * Node is NULL, or if no PGT value is
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * registered, then the Portal does not provide
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * access to that iSCSI Node in the Entity.
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China */
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China num_of_pgs++;
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = ntohl(attr_tlv_p->attr_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len += (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (total_payload_len >= resp_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p += (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz = sizeof (isns_portal_group_list_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_of_pgs > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg_sz += (num_of_pgs - 1) * sizeof (isns_portal_group_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(isns_process_dev_attr_qry_target_nodes_pdu_pg_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int, pg_sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Once we passed this point, if for any reason we need to return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * because of a failure, we need to free the memory allocated for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the pg_list and nullify it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pg_list = (isns_portal_group_list_t *)kmem_zalloc(pg_sz, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pg_list)->pg_out_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Assign the isns_server information to all portal groups */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (idx = 0; idx < num_of_pgs; idx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg = &((*pg_list)->pg_list[idx]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&isns_server_addr->a_addr, &pg->isns_server_ip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_ipaddr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg->isns_server_port = isns_server_addr->a_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p = resp_p->data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_delimiter_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len = sizeof (resp_p->status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!done_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv_p = (isns_tlv_t *)data_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg = &((*pg_list)->pg_list[(*pg_list)->pg_out_cnt]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ntohl(attr_tlv_p->attr_id)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_DELIMITER_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found_delimiter_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found_delimiter_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_ISCSI_NAME_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_type_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_tlv_p->attr_value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)pg->pg_iscsi_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE1(isns_dev_attr_qry_process1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *, (char *)pg->pg_iscsi_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target_node_type_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Section 6.3.1 - The Portal IP Address
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is a 16-byte field that may contain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an IPv4 or IPv6 address. When this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * field contains an IPv4 address, it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is stored as an IPv4-mapped IPv6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * address
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ntohl(attr_tlv_p->attr_len) != 16) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STRING_AALR "address attribute length received "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STRING_FISE16 "from iSNS server, Expected = 16, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "Wrong IP "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRING_AALR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRING_FISE16
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Received = %d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv_p->attr_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#undef STRING_AALR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#undef STRING_FISE16
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Section 6.3.1 and RFC 2373 state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that an IPv4 address will be denoted
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by the 10 top bytes as all zero
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * followed by either 2 bytes of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0x0000 or 0xFFFF The 0x0000 states
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that the address is is IPv6 capable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and 0xFFFF states its not capable.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((bcmp(attr_tlv_p->attr_value, junk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IPV4_RSVD_BYTES) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((attr_tlv_p->attr_value[10] ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (attr_tlv_p->attr_value[11] ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0x00)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((attr_tlv_p->attr_value[10] ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xFF) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (attr_tlv_p->attr_value[11] ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0xFF)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv4 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_tlv_p->attr_value +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 12, &pg->pg_ip_addr.u_ip4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg->insize =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_tlv_p->attr_value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pg->pg_ip_addr.u_ip6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg->insize =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_PORTAL_PORT_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target_node_type_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg->pg_port =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(*(uint32_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*attr_tlv_p).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_TAG_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (target_node_type_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pg->pg_tag =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(*(uint32_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*attr_tlv_p).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_node_type_b = B_FALSE;
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China if (ntohl(attr_tlv_p->attr_len) > 0) {
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China /*
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * Only the iSCSI node that has a
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * non-NULL PGT value is an valid
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China * Entity.
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China */
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China (*pg_list)->pg_out_cnt++;
d3e3772eab14af9b62d61b6d55b6d20457c3075byi zhang - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = ntohl(attr_tlv_p->attr_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len += (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((total_payload_len >= resp_len) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((*pg_list)->pg_out_cnt == num_of_pgs)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p += (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_esi(isns_pdu_t *esi_pdu_p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* There's nothing particular to process for ESI. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_process_scn(isns_pdu_t *scn_pdu_p, uint8_t *lhba_handle)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t dest_attr_found_b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t done_b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t scn_type_found_b;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_scn_callback_arg_t *scn_args_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_tlv_t *attr_tlv_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *data_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *src_attr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t attr_eff_len, normalized_attr_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t scn_type;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t total_payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*scn_callback_to_use)(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the lhba_handle to use for the call back */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_callback_to_use = scn_callback_lookup(lhba_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scn_callback_to_use == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dest_attr_found_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_type = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_type_found_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p = scn_pdu_p->payload;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte src_attr = (uint8_t *)kmem_zalloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Section 5.6.5.8 states an SCN can have more than one
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * source attribute. Process all attributes until we
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * each process all the data or encounter the delimiter.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!done_b) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv_p = (isns_tlv_t *)data_p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ntohl(attr_tlv_p->attr_id)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ISNS_ISCSI_NAME_ATTR_ID - attribute name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_ISCSI_NAME_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_eff_len = strlen(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)attr_tlv_p->attr_value) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The attribute length must be 4-byte aligned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Section 5.1.3, RFC 4171.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte normalized_attr_len = (attr_eff_len % 4) == 0 ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (attr_eff_len) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (attr_eff_len + (4 - (attr_eff_len % 4)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (normalized_attr_len !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This SCN is bad. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(src_attr, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_MSG_FORMAT_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if this was the Destination Attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dest_attr_found_b == B_TRUE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (scn_type_found_b == B_TRUE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(src_attr, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_tlv_p->attr_value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)src_attr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len) <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate new callback structure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_args_p =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (isns_scn_callback_arg_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (isns_scn_callback_arg_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_args_p->scn_type = ntohl(scn_type);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(src_attr, scn_args_p->source_key_attr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (scn_args_p->source_key_attr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Dispatch the callback to process the SCN */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scn_taskq != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_taskq_dispatch(scn_taskq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_callback_to_use,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_args_p, DDI_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&scn_taskq_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip Destination Attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dest_attr_found_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ISNS_ISCSI_SCN_BITMAP_ATTR_ID - change type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_ISCSI_SCN_BITMAP_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine the type of action to take for this SCN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scn_type_found_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(attr_tlv_p->attr_value), &scn_type, 4);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ISNS_DELIMITER_ATTR_ID - end of the payload of a message */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_DELIMITER_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (done_b == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len += ntohl(attr_tlv_p->attr_len) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_ID_LEN + ISNS_TLV_ATTR_LEN_LEN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((total_payload_len >= scn_pdu_p->payload_len) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (total_payload_len > ISNSP_MAX_PAYLOAD_SIZE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No more Attributes to process */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scn_pdu_p->payload_len -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte total_payload_len <=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The rest of the data in the PDU
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is less than the size of a valid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSNS TLV. This next attribute
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * probably spans across the PDU
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * boundary. For now, do not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * process it further.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte done_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Advance to the next Attribute */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_p += (ISNS_TLV_ATTR_ID_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_TLV_ATTR_LEN_LEN +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ntohl(attr_tlv_p->attr_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(src_attr, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISNS_RSP_SUCCESSFUL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesize_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_create_pdu_header(uint16_t func_id, uint16_t flags, isns_pdu_t **pdu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It should be ok to assume ISNSP_MAX_PDU_SIZE is large enough
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * since we are creating our own PDU which is fully under our control.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t pdu_size = ISNSP_MAX_PDU_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pdu = (isns_pdu_t *)kmem_zalloc(pdu_size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memset((*pdu), 0, pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->version = htons((uint16_t)ISNSP_VERSION);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->func_id = htons((uint16_t)func_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->payload_len = htons(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->flags = htons((uint16_t)(flags | ISNS_FLAG_CLIENT));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->xid = htons(create_xid());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pdu)->seq = htons(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_add_attr(isns_pdu_t *pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t max_pdu_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t attr_id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t attr_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *attr_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t attr_numeric_data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_tlv_t *attr_tlv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *payload_ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint16_t payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t normalized_attr_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t attr_tlv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The attribute length must be 4-byte aligned. Section 5.1.3. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte normalized_attr_len = (attr_len % 4) == 0 ? (attr_len) :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (attr_len + (4 - (attr_len % 4)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv_len = ISNS_TLV_ATTR_ID_LEN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte + ISNS_TLV_ATTR_LEN_LEN
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte + normalized_attr_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if we are going to exceed the maximum PDU length. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len = ntohs(pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((payload_len + attr_tlv_len) > max_pdu_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv = (isns_tlv_t *)kmem_zalloc(attr_tlv_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv->attr_id = htonl(attr_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (attr_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_DELIMITER_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PORTAL_IP_ADDR_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (attr_numeric_data == sizeof (in_addr_t)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv4 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv->attr_value[10] = 0xFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv->attr_value[11] = 0xFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_data, ((attr_tlv->attr_value) + 12),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (in_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (attr_numeric_data == sizeof (in6_addr_t)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPv6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_data, attr_tlv->attr_value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (in6_addr_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (attr_numeric_data == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* EMPTY */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Do nothing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(attr_tlv, attr_tlv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_EID_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_ISCSI_NAME_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_ISCSI_ALIAS_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_PG_ISCSI_NAME_ATTR_ID:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((char *)attr_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv->attr_value,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (normalized_attr_len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 4:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(uint32_t *)attr_tlv->attr_value =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htonl(attr_numeric_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 8:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *(uint64_t *)attr_tlv->attr_value =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BE_64((uint64_t)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_numeric_data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv->attr_len = htonl(normalized_attr_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Convert the network byte ordered payload length to host byte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ordered for local address calculation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len = ntohs(pdu->payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_ptr = pdu->payload + payload_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(attr_tlv, payload_ptr, attr_tlv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte payload_len += attr_tlv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Convert the host byte ordered payload length back to network
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * byte ordered - it's now ready to be sent on the wire.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pdu->payload_len = htons(payload_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(attr_tlv, attr_tlv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte attr_tlv = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_service_esi_scn(iscsi_thread_t *thread, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int clnt_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_async_thread_arg_t *larg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *in_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bytes_received, in_pdu_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *lhba_handle;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockaddr_in6 t_addr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t t_addrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr sin;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in s_in4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 s_in6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } clnt_addr = { 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in soa4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 soa6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } local_conn_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *listening_so, *connecting_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte larg = (isns_async_thread_arg_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte listening_so = larg->listening_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle = larg->lhba_handle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Done using the argument - free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(larg, sizeof (*larg));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&t_addr, sizeof (struct sockaddr_in6));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning t_addrlen = sizeof (struct sockaddr_in6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) iscsi_net->getsockname(listening_so,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (struct sockaddr *)&t_addr, &t_addrlen);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (t_addrlen <= sizeof (local_conn_prop)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bcopy(&t_addr, &local_conn_prop, t_addrlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_net->listen(listening_so, 5) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (;;) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t out_pdu_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clnt_len = sizeof (clnt_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Blocking call */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte connecting_so = iscsi_net->accept(
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning listening_so, &clnt_addr.sin, &clnt_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (esi_scn_thr_to_shutdown == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Terminate the thread if instructed to do so. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (connecting_so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(listening_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bytes_received = isns_rcv_pdu(connecting_so, &in_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in_pdu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bytes_received == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (in_pdu->func_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_ESI:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISNS_SCN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in_pdu->func_id == ISNS_ESI) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_process_esi(in_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_esi_rsp_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (in_pdu->func_id == ISNS_SCN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = isns_process_scn(in_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lhba_handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_scn_rsp_pdu(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &xid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ignore all traffics other than
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ESI and SCN.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (out_pdu_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) isns_send_pdu(connecting_so, out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(connecting_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(in_pdu, in_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing Chinastatic
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing Chinaboolean_t
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing Chinafind_listening_addr(iscsi_addr_t *local_addr, void *listening_so)
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China{
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China union {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China struct sockaddr_in soa4;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China struct sockaddr_in6 soa6;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } local_conn_prop = { 0 };
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China struct sockaddr_in6 t_addr;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China socklen_t t_addrlen;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr == NULL || listening_so == NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China bzero(&t_addr, sizeof (struct sockaddr_in6));
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China t_addrlen = sizeof (struct sockaddr_in6);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (void) iscsi_net->getsockname(listening_so, (struct sockaddr *)&t_addr,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China &t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (t_addrlen > sizeof (local_conn_prop)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China bcopy(&t_addr, &local_conn_prop, t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_conn_prop.soa4.sin_family == AF_INET) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_addr->a_addr.i_addr.in4.s_addr =
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_conn_prop.soa4.sin_addr.s_addr;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_addr->a_addr.i_insize = sizeof (in_addr_t);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else if (local_conn_prop.soa4.sin_family == AF_INET6) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China /* Currently, IPv6 is not supported */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_addr->a_port = ntohs(local_conn_prop.soa4.sin_port);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_TRUE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China}
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefind_local_portal(iscsi_addr_t *isns_server_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_addr_t **local_addr, void **listening_so)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in soa4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 soa6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } local_conn_prop = { 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte union {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr sin;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in s_in4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 s_in6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } serv_addr = { 0 };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *so;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning struct sockaddr_in6 t_addr;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t t_addrlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (listening_so == NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr != NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *local_addr = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *listening_so = NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&t_addr, sizeof (struct sockaddr_in6));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning t_addrlen = sizeof (struct sockaddr_in6);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine the local IP address.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr != NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China so = isns_open(isns_server_addr);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (so == NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->getsockname(so,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (struct sockaddr *)&t_addr, &t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (t_addrlen > sizeof (local_conn_prop)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->close(so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China bcopy(&t_addr, &local_conn_prop, t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China t_addrlen = sizeof (struct sockaddr_in6);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_conn_prop.soa4.sin_family == AF_INET) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *local_addr =
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (iscsi_addr_t *)kmem_zalloc(sizeof (iscsi_addr_t),
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China KM_SLEEP);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (*local_addr)->a_addr.i_addr.in4.s_addr =
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China local_conn_prop.soa4.sin_addr.s_addr;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (*local_addr)->a_addr.i_insize = sizeof (in_addr_t);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else if (local_conn_prop.soa4.sin_family == AF_INET6) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China /* Currently, IPv6 is not supported */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->close(so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China return (B_FALSE);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine the local IP address. (End)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte serv_addr.s_in4.sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use INADDR_ANY to accept connections from any of the connected
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * networks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte serv_addr.s_in4.sin_addr.s_addr = htonl(INADDR_ANY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use port number 0 to allow the system to assign a unique unused
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte serv_addr.s_in4.sin_port = htons(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte so = iscsi_net->socket(AF_INET, SOCK_STREAM, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (so == NULL) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr != NULL && (*local_addr != NULL)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China kmem_free((*local_addr), sizeof (iscsi_addr_t));
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *local_addr = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_net->bind(so, &serv_addr.sin,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct sockaddr), 0, 0) < 0) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr != NULL && (*local_addr != NULL)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China kmem_free((*local_addr), sizeof (iscsi_addr_t));
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China *local_addr = NULL;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (local_addr != NULL && (*local_addr != NULL)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (void) iscsi_net->getsockname(so, (struct sockaddr *)&t_addr,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China &t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (t_addrlen <= sizeof (local_conn_prop)) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China bcopy(&t_addr, &local_conn_prop, t_addrlen);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (*local_addr)->a_port =
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China ntohs(local_conn_prop.soa4.sin_port);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China } else {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (*local_addr)->a_port = ISNS_DEFAULT_ESI_SCN_PORT;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *listening_so = so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte(*scn_callback_lookup(uint8_t *lhba_handle))(void *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When we support multiple HBA instance we will use lhba_handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to look up the associated SCN callback. For now, we only support
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one HBA instance therefore we always return the same SCN callback.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (scn_callback_p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint16_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecreate_xid()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (xid++ % MAX_XID);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteesi_scn_thr_cleanup()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China boolean_t unblock_esi_scn_thr_b = B_FALSE;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_addr_t local_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China if (esi_scn_thr_to_shutdown == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Instruct the ESI/SCN to shut itself down. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte esi_scn_thr_to_shutdown = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (instance_listening_so != NULL &&
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (find_listening_addr(&local_addr,
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China instance_listening_so) == B_TRUE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_pdu_t *out_pdu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t out_pdu_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *connecting_so;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open a connection to the local address and send
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a dummy header to unblock the accept call so that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the ESI/SCN thread has a chance to terminate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * itself.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China connecting_so = isns_open(&local_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (connecting_so == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unblock_esi_scn_thr_b = B_FALSE;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China esi_scn_thr_to_shutdown = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu_size = isns_create_pdu_header(0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_FIRST_PDU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISNS_FLAG_LAST_PDU,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &out_pdu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isns_send_pdu(connecting_so,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unblock_esi_scn_thr_b = B_FALSE;
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China esi_scn_thr_to_shutdown = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unblock_esi_scn_thr_b = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_net->close(connecting_so);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(out_pdu, out_pdu_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte out_pdu = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (unblock_esi_scn_thr_b == B_TRUE) {
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_exit(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China (void) iscsi_thread_stop(esi_scn_thr_id);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_thread_destroy(esi_scn_thr_id);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_enter(&esi_scn_thr_mutex);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China esi_scn_thr_id = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China /*
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China * Shutdown and close the listening socket.
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China */
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->shutdown(instance_listening_so, 2);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China iscsi_net->close(instance_listening_so);
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China instance_listening_so = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6362598e17a32c2de4dd1a508a5489f200a2397cbing zhao - Sun Microsystems - Beijing China mutex_exit(&esi_scn_thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}