1e48354ceSNicholas Bellinger /******************************************************************************* 2e48354ceSNicholas Bellinger * This file contains main functions related to iSCSI Parameter negotiation. 3e48354ceSNicholas Bellinger * 4e48354ceSNicholas Bellinger * \u00a9 Copyright 2007-2011 RisingTide Systems LLC. 5e48354ceSNicholas Bellinger * 6e48354ceSNicholas Bellinger * Licensed to the Linux Foundation under the General Public License (GPL) version 2. 7e48354ceSNicholas Bellinger * 8e48354ceSNicholas Bellinger * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 9e48354ceSNicholas Bellinger * 10e48354ceSNicholas Bellinger * This program is free software; you can redistribute it and/or modify 11e48354ceSNicholas Bellinger * it under the terms of the GNU General Public License as published by 12e48354ceSNicholas Bellinger * the Free Software Foundation; either version 2 of the License, or 13e48354ceSNicholas Bellinger * (at your option) any later version. 14e48354ceSNicholas Bellinger * 15e48354ceSNicholas Bellinger * This program is distributed in the hope that it will be useful, 16e48354ceSNicholas Bellinger * but WITHOUT ANY WARRANTY; without even the implied warranty of 17e48354ceSNicholas Bellinger * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18e48354ceSNicholas Bellinger * GNU General Public License for more details. 19e48354ceSNicholas Bellinger ******************************************************************************/ 20e48354ceSNicholas Bellinger 21e48354ceSNicholas Bellinger #include <linux/ctype.h> 22e48354ceSNicholas Bellinger #include <scsi/iscsi_proto.h> 23e48354ceSNicholas Bellinger #include <target/target_core_base.h> 24c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h> 25e48354ceSNicholas Bellinger 26e48354ceSNicholas Bellinger #include "iscsi_target_core.h" 27e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h" 28e48354ceSNicholas Bellinger #include "iscsi_target_login.h" 29e48354ceSNicholas Bellinger #include "iscsi_target_nego.h" 30e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 31e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 32e48354ceSNicholas Bellinger #include "iscsi_target.h" 33e48354ceSNicholas Bellinger #include "iscsi_target_auth.h" 34e48354ceSNicholas Bellinger 35e48354ceSNicholas Bellinger #define MAX_LOGIN_PDUS 7 36e48354ceSNicholas Bellinger #define TEXT_LEN 4096 37e48354ceSNicholas Bellinger 38e48354ceSNicholas Bellinger void convert_null_to_semi(char *buf, int len) 39e48354ceSNicholas Bellinger { 40e48354ceSNicholas Bellinger int i; 41e48354ceSNicholas Bellinger 42e48354ceSNicholas Bellinger for (i = 0; i < len; i++) 43e48354ceSNicholas Bellinger if (buf[i] == '\0') 44e48354ceSNicholas Bellinger buf[i] = ';'; 45e48354ceSNicholas Bellinger } 46e48354ceSNicholas Bellinger 47fceb5bc7SChristoph Hellwig static int strlen_semi(char *buf) 48e48354ceSNicholas Bellinger { 49e48354ceSNicholas Bellinger int i = 0; 50e48354ceSNicholas Bellinger 51e48354ceSNicholas Bellinger while (buf[i] != '\0') { 52e48354ceSNicholas Bellinger if (buf[i] == ';') 53e48354ceSNicholas Bellinger return i; 54e48354ceSNicholas Bellinger i++; 55e48354ceSNicholas Bellinger } 56e48354ceSNicholas Bellinger 57e48354ceSNicholas Bellinger return -1; 58e48354ceSNicholas Bellinger } 59e48354ceSNicholas Bellinger 60e48354ceSNicholas Bellinger int extract_param( 61e48354ceSNicholas Bellinger const char *in_buf, 62e48354ceSNicholas Bellinger const char *pattern, 63e48354ceSNicholas Bellinger unsigned int max_length, 64e48354ceSNicholas Bellinger char *out_buf, 65e48354ceSNicholas Bellinger unsigned char *type) 66e48354ceSNicholas Bellinger { 67e48354ceSNicholas Bellinger char *ptr; 68e48354ceSNicholas Bellinger int len; 69e48354ceSNicholas Bellinger 70e48354ceSNicholas Bellinger if (!in_buf || !pattern || !out_buf || !type) 71e48354ceSNicholas Bellinger return -1; 72e48354ceSNicholas Bellinger 73e48354ceSNicholas Bellinger ptr = strstr(in_buf, pattern); 74e48354ceSNicholas Bellinger if (!ptr) 75e48354ceSNicholas Bellinger return -1; 76e48354ceSNicholas Bellinger 77e48354ceSNicholas Bellinger ptr = strstr(ptr, "="); 78e48354ceSNicholas Bellinger if (!ptr) 79e48354ceSNicholas Bellinger return -1; 80e48354ceSNicholas Bellinger 81e48354ceSNicholas Bellinger ptr += 1; 82e48354ceSNicholas Bellinger if (*ptr == '0' && (*(ptr+1) == 'x' || *(ptr+1) == 'X')) { 83e48354ceSNicholas Bellinger ptr += 2; /* skip 0x */ 84e48354ceSNicholas Bellinger *type = HEX; 85e48354ceSNicholas Bellinger } else 86e48354ceSNicholas Bellinger *type = DECIMAL; 87e48354ceSNicholas Bellinger 88e48354ceSNicholas Bellinger len = strlen_semi(ptr); 89e48354ceSNicholas Bellinger if (len < 0) 90e48354ceSNicholas Bellinger return -1; 91e48354ceSNicholas Bellinger 92e48354ceSNicholas Bellinger if (len > max_length) { 935e58b029SMasanari Iida pr_err("Length of input: %d exceeds max_length:" 94e48354ceSNicholas Bellinger " %d\n", len, max_length); 95e48354ceSNicholas Bellinger return -1; 96e48354ceSNicholas Bellinger } 97e48354ceSNicholas Bellinger memcpy(out_buf, ptr, len); 98e48354ceSNicholas Bellinger out_buf[len] = '\0'; 99e48354ceSNicholas Bellinger 100e48354ceSNicholas Bellinger return 0; 101e48354ceSNicholas Bellinger } 102e48354ceSNicholas Bellinger 103e48354ceSNicholas Bellinger static u32 iscsi_handle_authentication( 104e48354ceSNicholas Bellinger struct iscsi_conn *conn, 105e48354ceSNicholas Bellinger char *in_buf, 106e48354ceSNicholas Bellinger char *out_buf, 107e48354ceSNicholas Bellinger int in_length, 108e48354ceSNicholas Bellinger int *out_length, 109e48354ceSNicholas Bellinger unsigned char *authtype) 110e48354ceSNicholas Bellinger { 111e48354ceSNicholas Bellinger struct iscsi_session *sess = conn->sess; 112e48354ceSNicholas Bellinger struct iscsi_node_auth *auth; 113e48354ceSNicholas Bellinger struct iscsi_node_acl *iscsi_nacl; 114e48354ceSNicholas Bellinger struct se_node_acl *se_nacl; 115e48354ceSNicholas Bellinger 116e48354ceSNicholas Bellinger if (!sess->sess_ops->SessionType) { 117e48354ceSNicholas Bellinger /* 118e48354ceSNicholas Bellinger * For SessionType=Normal 119e48354ceSNicholas Bellinger */ 120e48354ceSNicholas Bellinger se_nacl = conn->sess->se_sess->se_node_acl; 121e48354ceSNicholas Bellinger if (!se_nacl) { 122e48354ceSNicholas Bellinger pr_err("Unable to locate struct se_node_acl for" 123e48354ceSNicholas Bellinger " CHAP auth\n"); 124e48354ceSNicholas Bellinger return -1; 125e48354ceSNicholas Bellinger } 126e48354ceSNicholas Bellinger iscsi_nacl = container_of(se_nacl, struct iscsi_node_acl, 127e48354ceSNicholas Bellinger se_node_acl); 128e48354ceSNicholas Bellinger if (!iscsi_nacl) { 129e48354ceSNicholas Bellinger pr_err("Unable to locate struct iscsi_node_acl for" 130e48354ceSNicholas Bellinger " CHAP auth\n"); 131e48354ceSNicholas Bellinger return -1; 132e48354ceSNicholas Bellinger } 133e48354ceSNicholas Bellinger 134e48354ceSNicholas Bellinger auth = ISCSI_NODE_AUTH(iscsi_nacl); 135e48354ceSNicholas Bellinger } else { 136e48354ceSNicholas Bellinger /* 137e48354ceSNicholas Bellinger * For SessionType=Discovery 138e48354ceSNicholas Bellinger */ 139e48354ceSNicholas Bellinger auth = &iscsit_global->discovery_acl.node_auth; 140e48354ceSNicholas Bellinger } 141e48354ceSNicholas Bellinger 142e48354ceSNicholas Bellinger if (strstr("CHAP", authtype)) 143e48354ceSNicholas Bellinger strcpy(conn->sess->auth_type, "CHAP"); 144e48354ceSNicholas Bellinger else 145e48354ceSNicholas Bellinger strcpy(conn->sess->auth_type, NONE); 146e48354ceSNicholas Bellinger 147e48354ceSNicholas Bellinger if (strstr("None", authtype)) 148e48354ceSNicholas Bellinger return 1; 149e48354ceSNicholas Bellinger #ifdef CANSRP 150e48354ceSNicholas Bellinger else if (strstr("SRP", authtype)) 151e48354ceSNicholas Bellinger return srp_main_loop(conn, auth, in_buf, out_buf, 152e48354ceSNicholas Bellinger &in_length, out_length); 153e48354ceSNicholas Bellinger #endif 154e48354ceSNicholas Bellinger else if (strstr("CHAP", authtype)) 155e48354ceSNicholas Bellinger return chap_main_loop(conn, auth, in_buf, out_buf, 156e48354ceSNicholas Bellinger &in_length, out_length); 157e48354ceSNicholas Bellinger else if (strstr("SPKM1", authtype)) 158e48354ceSNicholas Bellinger return 2; 159e48354ceSNicholas Bellinger else if (strstr("SPKM2", authtype)) 160e48354ceSNicholas Bellinger return 2; 161e48354ceSNicholas Bellinger else if (strstr("KRB5", authtype)) 162e48354ceSNicholas Bellinger return 2; 163e48354ceSNicholas Bellinger else 164e48354ceSNicholas Bellinger return 2; 165e48354ceSNicholas Bellinger } 166e48354ceSNicholas Bellinger 167e48354ceSNicholas Bellinger static void iscsi_remove_failed_auth_entry(struct iscsi_conn *conn) 168e48354ceSNicholas Bellinger { 169e48354ceSNicholas Bellinger kfree(conn->auth_protocol); 170e48354ceSNicholas Bellinger } 171e48354ceSNicholas Bellinger 172e48354ceSNicholas Bellinger static int iscsi_target_check_login_request( 173e48354ceSNicholas Bellinger struct iscsi_conn *conn, 174e48354ceSNicholas Bellinger struct iscsi_login *login) 175e48354ceSNicholas Bellinger { 17628168905SJörn Engel int req_csg, req_nsg; 177e48354ceSNicholas Bellinger u32 payload_length; 178e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 179e48354ceSNicholas Bellinger 180e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 181e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 182e48354ceSNicholas Bellinger 183e48354ceSNicholas Bellinger switch (login_req->opcode & ISCSI_OPCODE_MASK) { 184e48354ceSNicholas Bellinger case ISCSI_OP_LOGIN: 185e48354ceSNicholas Bellinger break; 186e48354ceSNicholas Bellinger default: 187e48354ceSNicholas Bellinger pr_err("Received unknown opcode 0x%02x.\n", 188e48354ceSNicholas Bellinger login_req->opcode & ISCSI_OPCODE_MASK); 189e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 190e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 191e48354ceSNicholas Bellinger return -1; 192e48354ceSNicholas Bellinger } 193e48354ceSNicholas Bellinger 194e48354ceSNicholas Bellinger if ((login_req->flags & ISCSI_FLAG_LOGIN_CONTINUE) && 195e48354ceSNicholas Bellinger (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) { 196e48354ceSNicholas Bellinger pr_err("Login request has both ISCSI_FLAG_LOGIN_CONTINUE" 197e48354ceSNicholas Bellinger " and ISCSI_FLAG_LOGIN_TRANSIT set, protocol error.\n"); 198e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 199e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 200e48354ceSNicholas Bellinger return -1; 201e48354ceSNicholas Bellinger } 202e48354ceSNicholas Bellinger 2035d358065SAndy Grover req_csg = ISCSI_LOGIN_CURRENT_STAGE(login_req->flags); 2045d358065SAndy Grover req_nsg = ISCSI_LOGIN_NEXT_STAGE(login_req->flags); 205e48354ceSNicholas Bellinger 206e48354ceSNicholas Bellinger if (req_csg != login->current_stage) { 207e48354ceSNicholas Bellinger pr_err("Initiator unexpectedly changed login stage" 208e48354ceSNicholas Bellinger " from %d to %d, login failed.\n", login->current_stage, 209e48354ceSNicholas Bellinger req_csg); 210e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 211e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 212e48354ceSNicholas Bellinger return -1; 213e48354ceSNicholas Bellinger } 214e48354ceSNicholas Bellinger 215e48354ceSNicholas Bellinger if ((req_nsg == 2) || (req_csg >= 2) || 216e48354ceSNicholas Bellinger ((login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT) && 217e48354ceSNicholas Bellinger (req_nsg <= req_csg))) { 218e48354ceSNicholas Bellinger pr_err("Illegal login_req->flags Combination, CSG: %d," 219e48354ceSNicholas Bellinger " NSG: %d, ISCSI_FLAG_LOGIN_TRANSIT: %d.\n", req_csg, 220e48354ceSNicholas Bellinger req_nsg, (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)); 221e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 222e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 223e48354ceSNicholas Bellinger return -1; 224e48354ceSNicholas Bellinger } 225e48354ceSNicholas Bellinger 226e48354ceSNicholas Bellinger if ((login_req->max_version != login->version_max) || 227e48354ceSNicholas Bellinger (login_req->min_version != login->version_min)) { 228e48354ceSNicholas Bellinger pr_err("Login request changed Version Max/Nin" 229e48354ceSNicholas Bellinger " unexpectedly to 0x%02x/0x%02x, protocol error\n", 230e48354ceSNicholas Bellinger login_req->max_version, login_req->min_version); 231e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 232e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 233e48354ceSNicholas Bellinger return -1; 234e48354ceSNicholas Bellinger } 235e48354ceSNicholas Bellinger 236e48354ceSNicholas Bellinger if (memcmp(login_req->isid, login->isid, 6) != 0) { 237e48354ceSNicholas Bellinger pr_err("Login request changed ISID unexpectedly," 238e48354ceSNicholas Bellinger " protocol error.\n"); 239e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 240e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 241e48354ceSNicholas Bellinger return -1; 242e48354ceSNicholas Bellinger } 243e48354ceSNicholas Bellinger 244e48354ceSNicholas Bellinger if (login_req->itt != login->init_task_tag) { 245e48354ceSNicholas Bellinger pr_err("Login request changed ITT unexpectedly to" 246e48354ceSNicholas Bellinger " 0x%08x, protocol error.\n", login_req->itt); 247e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 248e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 249e48354ceSNicholas Bellinger return -1; 250e48354ceSNicholas Bellinger } 251e48354ceSNicholas Bellinger 252e48354ceSNicholas Bellinger if (payload_length > MAX_KEY_VALUE_PAIRS) { 253e48354ceSNicholas Bellinger pr_err("Login request payload exceeds default" 254e48354ceSNicholas Bellinger " MaxRecvDataSegmentLength: %u, protocol error.\n", 255e48354ceSNicholas Bellinger MAX_KEY_VALUE_PAIRS); 256e48354ceSNicholas Bellinger return -1; 257e48354ceSNicholas Bellinger } 258e48354ceSNicholas Bellinger 259e48354ceSNicholas Bellinger return 0; 260e48354ceSNicholas Bellinger } 261e48354ceSNicholas Bellinger 262e48354ceSNicholas Bellinger static int iscsi_target_check_first_request( 263e48354ceSNicholas Bellinger struct iscsi_conn *conn, 264e48354ceSNicholas Bellinger struct iscsi_login *login) 265e48354ceSNicholas Bellinger { 266e48354ceSNicholas Bellinger struct iscsi_param *param = NULL; 267e48354ceSNicholas Bellinger struct se_node_acl *se_nacl; 268e48354ceSNicholas Bellinger 269e48354ceSNicholas Bellinger login->first_request = 0; 270e48354ceSNicholas Bellinger 271e48354ceSNicholas Bellinger list_for_each_entry(param, &conn->param_list->param_list, p_list) { 272e48354ceSNicholas Bellinger if (!strncmp(param->name, SESSIONTYPE, 11)) { 273e48354ceSNicholas Bellinger if (!IS_PSTATE_ACCEPTOR(param)) { 274e48354ceSNicholas Bellinger pr_err("SessionType key not received" 275e48354ceSNicholas Bellinger " in first login request.\n"); 276e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 277e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_MISSING_FIELDS); 278e48354ceSNicholas Bellinger return -1; 279e48354ceSNicholas Bellinger } 280e48354ceSNicholas Bellinger if (!strncmp(param->value, DISCOVERY, 9)) 281e48354ceSNicholas Bellinger return 0; 282e48354ceSNicholas Bellinger } 283e48354ceSNicholas Bellinger 284e48354ceSNicholas Bellinger if (!strncmp(param->name, INITIATORNAME, 13)) { 285e48354ceSNicholas Bellinger if (!IS_PSTATE_ACCEPTOR(param)) { 286e48354ceSNicholas Bellinger if (!login->leading_connection) 287e48354ceSNicholas Bellinger continue; 288e48354ceSNicholas Bellinger 289e48354ceSNicholas Bellinger pr_err("InitiatorName key not received" 290e48354ceSNicholas Bellinger " in first login request.\n"); 291e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 292e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_MISSING_FIELDS); 293e48354ceSNicholas Bellinger return -1; 294e48354ceSNicholas Bellinger } 295e48354ceSNicholas Bellinger 296e48354ceSNicholas Bellinger /* 297e48354ceSNicholas Bellinger * For non-leading connections, double check that the 298e48354ceSNicholas Bellinger * received InitiatorName matches the existing session's 299e48354ceSNicholas Bellinger * struct iscsi_node_acl. 300e48354ceSNicholas Bellinger */ 301e48354ceSNicholas Bellinger if (!login->leading_connection) { 302e48354ceSNicholas Bellinger se_nacl = conn->sess->se_sess->se_node_acl; 303e48354ceSNicholas Bellinger if (!se_nacl) { 304e48354ceSNicholas Bellinger pr_err("Unable to locate" 305e48354ceSNicholas Bellinger " struct se_node_acl\n"); 306e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, 307e48354ceSNicholas Bellinger ISCSI_STATUS_CLS_INITIATOR_ERR, 308e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_TGT_NOT_FOUND); 309e48354ceSNicholas Bellinger return -1; 310e48354ceSNicholas Bellinger } 311e48354ceSNicholas Bellinger 312e48354ceSNicholas Bellinger if (strcmp(param->value, 313e48354ceSNicholas Bellinger se_nacl->initiatorname)) { 314e48354ceSNicholas Bellinger pr_err("Incorrect" 315e48354ceSNicholas Bellinger " InitiatorName: %s for this" 316e48354ceSNicholas Bellinger " iSCSI Initiator Node.\n", 317e48354ceSNicholas Bellinger param->value); 318e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, 319e48354ceSNicholas Bellinger ISCSI_STATUS_CLS_INITIATOR_ERR, 320e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_TGT_NOT_FOUND); 321e48354ceSNicholas Bellinger return -1; 322e48354ceSNicholas Bellinger } 323e48354ceSNicholas Bellinger } 324e48354ceSNicholas Bellinger } 325e48354ceSNicholas Bellinger } 326e48354ceSNicholas Bellinger 327e48354ceSNicholas Bellinger return 0; 328e48354ceSNicholas Bellinger } 329e48354ceSNicholas Bellinger 330e48354ceSNicholas Bellinger static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_login *login) 331e48354ceSNicholas Bellinger { 332e48354ceSNicholas Bellinger u32 padding = 0; 333e48354ceSNicholas Bellinger struct iscsi_session *sess = conn->sess; 334e48354ceSNicholas Bellinger struct iscsi_login_rsp *login_rsp; 335e48354ceSNicholas Bellinger 336e48354ceSNicholas Bellinger login_rsp = (struct iscsi_login_rsp *) login->rsp; 337e48354ceSNicholas Bellinger 338e48354ceSNicholas Bellinger login_rsp->opcode = ISCSI_OP_LOGIN_RSP; 339e48354ceSNicholas Bellinger hton24(login_rsp->dlength, login->rsp_length); 340e48354ceSNicholas Bellinger memcpy(login_rsp->isid, login->isid, 6); 341e48354ceSNicholas Bellinger login_rsp->tsih = cpu_to_be16(login->tsih); 34266c7db68SChristoph Hellwig login_rsp->itt = login->init_task_tag; 343e48354ceSNicholas Bellinger login_rsp->statsn = cpu_to_be32(conn->stat_sn++); 344e48354ceSNicholas Bellinger login_rsp->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); 345e48354ceSNicholas Bellinger login_rsp->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); 346e48354ceSNicholas Bellinger 347e48354ceSNicholas Bellinger pr_debug("Sending Login Response, Flags: 0x%02x, ITT: 0x%08x," 348e48354ceSNicholas Bellinger " ExpCmdSN; 0x%08x, MaxCmdSN: 0x%08x, StatSN: 0x%08x, Length:" 34966c7db68SChristoph Hellwig " %u\n", login_rsp->flags, (__force u32)login_rsp->itt, 350e48354ceSNicholas Bellinger ntohl(login_rsp->exp_cmdsn), ntohl(login_rsp->max_cmdsn), 351e48354ceSNicholas Bellinger ntohl(login_rsp->statsn), login->rsp_length); 352e48354ceSNicholas Bellinger 353e48354ceSNicholas Bellinger padding = ((-login->rsp_length) & 3); 354e48354ceSNicholas Bellinger 355e48354ceSNicholas Bellinger if (iscsi_login_tx_data( 356e48354ceSNicholas Bellinger conn, 357e48354ceSNicholas Bellinger login->rsp, 358e48354ceSNicholas Bellinger login->rsp_buf, 359e48354ceSNicholas Bellinger login->rsp_length + padding) < 0) 360e48354ceSNicholas Bellinger return -1; 361e48354ceSNicholas Bellinger 362e48354ceSNicholas Bellinger login->rsp_length = 0; 363e48354ceSNicholas Bellinger mutex_lock(&sess->cmdsn_mutex); 36450e5c87dSChristoph Hellwig login_rsp->exp_cmdsn = cpu_to_be32(sess->exp_cmd_sn); 36550e5c87dSChristoph Hellwig login_rsp->max_cmdsn = cpu_to_be32(sess->max_cmd_sn); 366e48354ceSNicholas Bellinger mutex_unlock(&sess->cmdsn_mutex); 367e48354ceSNicholas Bellinger 368e48354ceSNicholas Bellinger return 0; 369e48354ceSNicholas Bellinger } 370e48354ceSNicholas Bellinger 371e48354ceSNicholas Bellinger static int iscsi_target_do_rx_login_io(struct iscsi_conn *conn, struct iscsi_login *login) 372e48354ceSNicholas Bellinger { 373e48354ceSNicholas Bellinger u32 padding = 0, payload_length; 374e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 375e48354ceSNicholas Bellinger 376e48354ceSNicholas Bellinger if (iscsi_login_rx_data(conn, login->req, ISCSI_HDR_LEN) < 0) 377e48354ceSNicholas Bellinger return -1; 378e48354ceSNicholas Bellinger 379e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 380e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 381e48354ceSNicholas Bellinger 382e48354ceSNicholas Bellinger pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x," 383e48354ceSNicholas Bellinger " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n", 384e48354ceSNicholas Bellinger login_req->flags, login_req->itt, login_req->cmdsn, 385e48354ceSNicholas Bellinger login_req->exp_statsn, login_req->cid, payload_length); 386e48354ceSNicholas Bellinger 387e48354ceSNicholas Bellinger if (iscsi_target_check_login_request(conn, login) < 0) 388e48354ceSNicholas Bellinger return -1; 389e48354ceSNicholas Bellinger 390e48354ceSNicholas Bellinger padding = ((-payload_length) & 3); 391e48354ceSNicholas Bellinger memset(login->req_buf, 0, MAX_KEY_VALUE_PAIRS); 392e48354ceSNicholas Bellinger 393e48354ceSNicholas Bellinger if (iscsi_login_rx_data( 394e48354ceSNicholas Bellinger conn, 395e48354ceSNicholas Bellinger login->req_buf, 396e48354ceSNicholas Bellinger payload_length + padding) < 0) 397e48354ceSNicholas Bellinger return -1; 398e48354ceSNicholas Bellinger 399e48354ceSNicholas Bellinger return 0; 400e48354ceSNicholas Bellinger } 401e48354ceSNicholas Bellinger 402e48354ceSNicholas Bellinger static int iscsi_target_do_login_io(struct iscsi_conn *conn, struct iscsi_login *login) 403e48354ceSNicholas Bellinger { 404e48354ceSNicholas Bellinger if (iscsi_target_do_tx_login_io(conn, login) < 0) 405e48354ceSNicholas Bellinger return -1; 406e48354ceSNicholas Bellinger 407e48354ceSNicholas Bellinger if (iscsi_target_do_rx_login_io(conn, login) < 0) 408e48354ceSNicholas Bellinger return -1; 409e48354ceSNicholas Bellinger 410e48354ceSNicholas Bellinger return 0; 411e48354ceSNicholas Bellinger } 412e48354ceSNicholas Bellinger 413e48354ceSNicholas Bellinger static int iscsi_target_get_initial_payload( 414e48354ceSNicholas Bellinger struct iscsi_conn *conn, 415e48354ceSNicholas Bellinger struct iscsi_login *login) 416e48354ceSNicholas Bellinger { 417e48354ceSNicholas Bellinger u32 padding = 0, payload_length; 418e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 419e48354ceSNicholas Bellinger 420e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 421e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 422e48354ceSNicholas Bellinger 423e48354ceSNicholas Bellinger pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x," 424e48354ceSNicholas Bellinger " CmdSN: 0x%08x, ExpStatSN: 0x%08x, Length: %u\n", 425e48354ceSNicholas Bellinger login_req->flags, login_req->itt, login_req->cmdsn, 426e48354ceSNicholas Bellinger login_req->exp_statsn, payload_length); 427e48354ceSNicholas Bellinger 428e48354ceSNicholas Bellinger if (iscsi_target_check_login_request(conn, login) < 0) 429e48354ceSNicholas Bellinger return -1; 430e48354ceSNicholas Bellinger 431e48354ceSNicholas Bellinger padding = ((-payload_length) & 3); 432e48354ceSNicholas Bellinger 433e48354ceSNicholas Bellinger if (iscsi_login_rx_data( 434e48354ceSNicholas Bellinger conn, 435e48354ceSNicholas Bellinger login->req_buf, 436e48354ceSNicholas Bellinger payload_length + padding) < 0) 437e48354ceSNicholas Bellinger return -1; 438e48354ceSNicholas Bellinger 439e48354ceSNicholas Bellinger return 0; 440e48354ceSNicholas Bellinger } 441e48354ceSNicholas Bellinger 442e48354ceSNicholas Bellinger /* 443e48354ceSNicholas Bellinger * NOTE: We check for existing sessions or connections AFTER the initiator 444e48354ceSNicholas Bellinger * has been successfully authenticated in order to protect against faked 445e48354ceSNicholas Bellinger * ISID/TSIH combinations. 446e48354ceSNicholas Bellinger */ 447e48354ceSNicholas Bellinger static int iscsi_target_check_for_existing_instances( 448e48354ceSNicholas Bellinger struct iscsi_conn *conn, 449e48354ceSNicholas Bellinger struct iscsi_login *login) 450e48354ceSNicholas Bellinger { 451e48354ceSNicholas Bellinger if (login->checked_for_existing) 452e48354ceSNicholas Bellinger return 0; 453e48354ceSNicholas Bellinger 454e48354ceSNicholas Bellinger login->checked_for_existing = 1; 455e48354ceSNicholas Bellinger 456e48354ceSNicholas Bellinger if (!login->tsih) 457e48354ceSNicholas Bellinger return iscsi_check_for_session_reinstatement(conn); 458e48354ceSNicholas Bellinger else 459e48354ceSNicholas Bellinger return iscsi_login_post_auth_non_zero_tsih(conn, login->cid, 460e48354ceSNicholas Bellinger login->initial_exp_statsn); 461e48354ceSNicholas Bellinger } 462e48354ceSNicholas Bellinger 463e48354ceSNicholas Bellinger static int iscsi_target_do_authentication( 464e48354ceSNicholas Bellinger struct iscsi_conn *conn, 465e48354ceSNicholas Bellinger struct iscsi_login *login) 466e48354ceSNicholas Bellinger { 467e48354ceSNicholas Bellinger int authret; 468e48354ceSNicholas Bellinger u32 payload_length; 469e48354ceSNicholas Bellinger struct iscsi_param *param; 470e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 471e48354ceSNicholas Bellinger struct iscsi_login_rsp *login_rsp; 472e48354ceSNicholas Bellinger 473e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 474e48354ceSNicholas Bellinger login_rsp = (struct iscsi_login_rsp *) login->rsp; 475e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 476e48354ceSNicholas Bellinger 477e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, conn->param_list); 478e48354ceSNicholas Bellinger if (!param) 479e48354ceSNicholas Bellinger return -1; 480e48354ceSNicholas Bellinger 481e48354ceSNicholas Bellinger authret = iscsi_handle_authentication( 482e48354ceSNicholas Bellinger conn, 483e48354ceSNicholas Bellinger login->req_buf, 484e48354ceSNicholas Bellinger login->rsp_buf, 485e48354ceSNicholas Bellinger payload_length, 486e48354ceSNicholas Bellinger &login->rsp_length, 487e48354ceSNicholas Bellinger param->value); 488e48354ceSNicholas Bellinger switch (authret) { 489e48354ceSNicholas Bellinger case 0: 490e48354ceSNicholas Bellinger pr_debug("Received OK response" 491e48354ceSNicholas Bellinger " from LIO Authentication, continuing.\n"); 492e48354ceSNicholas Bellinger break; 493e48354ceSNicholas Bellinger case 1: 494e48354ceSNicholas Bellinger pr_debug("iSCSI security negotiation" 495bfb9035cSJoe Perches " completed successfully.\n"); 496e48354ceSNicholas Bellinger login->auth_complete = 1; 497e48354ceSNicholas Bellinger if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE1) && 498e48354ceSNicholas Bellinger (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) { 499e48354ceSNicholas Bellinger login_rsp->flags |= (ISCSI_FLAG_LOGIN_NEXT_STAGE1 | 500e48354ceSNicholas Bellinger ISCSI_FLAG_LOGIN_TRANSIT); 501e48354ceSNicholas Bellinger login->current_stage = 1; 502e48354ceSNicholas Bellinger } 503e48354ceSNicholas Bellinger return iscsi_target_check_for_existing_instances( 504e48354ceSNicholas Bellinger conn, login); 505e48354ceSNicholas Bellinger case 2: 506e48354ceSNicholas Bellinger pr_err("Security negotiation" 507e48354ceSNicholas Bellinger " failed.\n"); 508e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 509e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_AUTH_FAILED); 510e48354ceSNicholas Bellinger return -1; 511e48354ceSNicholas Bellinger default: 512e48354ceSNicholas Bellinger pr_err("Received unknown error %d from LIO" 513e48354ceSNicholas Bellinger " Authentication\n", authret); 514e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 515e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_TARGET_ERROR); 516e48354ceSNicholas Bellinger return -1; 517e48354ceSNicholas Bellinger } 518e48354ceSNicholas Bellinger 519e48354ceSNicholas Bellinger return 0; 520e48354ceSNicholas Bellinger } 521e48354ceSNicholas Bellinger 522e48354ceSNicholas Bellinger static int iscsi_target_handle_csg_zero( 523e48354ceSNicholas Bellinger struct iscsi_conn *conn, 524e48354ceSNicholas Bellinger struct iscsi_login *login) 525e48354ceSNicholas Bellinger { 526e48354ceSNicholas Bellinger int ret; 527e48354ceSNicholas Bellinger u32 payload_length; 528e48354ceSNicholas Bellinger struct iscsi_param *param; 529e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 530e48354ceSNicholas Bellinger struct iscsi_login_rsp *login_rsp; 531e48354ceSNicholas Bellinger 532e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 533e48354ceSNicholas Bellinger login_rsp = (struct iscsi_login_rsp *) login->rsp; 534e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 535e48354ceSNicholas Bellinger 536e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, conn->param_list); 537e48354ceSNicholas Bellinger if (!param) 538e48354ceSNicholas Bellinger return -1; 539e48354ceSNicholas Bellinger 540e48354ceSNicholas Bellinger ret = iscsi_decode_text_input( 541e48354ceSNicholas Bellinger PHASE_SECURITY|PHASE_DECLARATIVE, 542e48354ceSNicholas Bellinger SENDER_INITIATOR|SENDER_RECEIVER, 543e48354ceSNicholas Bellinger login->req_buf, 544e48354ceSNicholas Bellinger payload_length, 5459977bb18SNicholas Bellinger conn); 546e48354ceSNicholas Bellinger if (ret < 0) 547e48354ceSNicholas Bellinger return -1; 548e48354ceSNicholas Bellinger 549e48354ceSNicholas Bellinger if (ret > 0) { 550e48354ceSNicholas Bellinger if (login->auth_complete) { 551e48354ceSNicholas Bellinger pr_err("Initiator has already been" 552e48354ceSNicholas Bellinger " successfully authenticated, but is still" 553e48354ceSNicholas Bellinger " sending %s keys.\n", param->value); 554e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 555e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_INIT_ERR); 556e48354ceSNicholas Bellinger return -1; 557e48354ceSNicholas Bellinger } 558e48354ceSNicholas Bellinger 559e48354ceSNicholas Bellinger goto do_auth; 560e48354ceSNicholas Bellinger } 561e48354ceSNicholas Bellinger 562e48354ceSNicholas Bellinger if (login->first_request) 563e48354ceSNicholas Bellinger if (iscsi_target_check_first_request(conn, login) < 0) 564e48354ceSNicholas Bellinger return -1; 565e48354ceSNicholas Bellinger 566e48354ceSNicholas Bellinger ret = iscsi_encode_text_output( 567e48354ceSNicholas Bellinger PHASE_SECURITY|PHASE_DECLARATIVE, 568e48354ceSNicholas Bellinger SENDER_TARGET, 569e48354ceSNicholas Bellinger login->rsp_buf, 570e48354ceSNicholas Bellinger &login->rsp_length, 571e48354ceSNicholas Bellinger conn->param_list); 572e48354ceSNicholas Bellinger if (ret < 0) 573e48354ceSNicholas Bellinger return -1; 574e48354ceSNicholas Bellinger 575e48354ceSNicholas Bellinger if (!iscsi_check_negotiated_keys(conn->param_list)) { 576e48354ceSNicholas Bellinger if (ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication && 577e48354ceSNicholas Bellinger !strncmp(param->value, NONE, 4)) { 578e48354ceSNicholas Bellinger pr_err("Initiator sent AuthMethod=None but" 579e48354ceSNicholas Bellinger " Target is enforcing iSCSI Authentication," 580e48354ceSNicholas Bellinger " login failed.\n"); 581e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 582e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_AUTH_FAILED); 583e48354ceSNicholas Bellinger return -1; 584e48354ceSNicholas Bellinger } 585e48354ceSNicholas Bellinger 586e48354ceSNicholas Bellinger if (ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication && 587e48354ceSNicholas Bellinger !login->auth_complete) 588e48354ceSNicholas Bellinger return 0; 589e48354ceSNicholas Bellinger 590e48354ceSNicholas Bellinger if (strncmp(param->value, NONE, 4) && !login->auth_complete) 591e48354ceSNicholas Bellinger return 0; 592e48354ceSNicholas Bellinger 593e48354ceSNicholas Bellinger if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE1) && 594e48354ceSNicholas Bellinger (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) { 595e48354ceSNicholas Bellinger login_rsp->flags |= ISCSI_FLAG_LOGIN_NEXT_STAGE1 | 596e48354ceSNicholas Bellinger ISCSI_FLAG_LOGIN_TRANSIT; 597e48354ceSNicholas Bellinger login->current_stage = 1; 598e48354ceSNicholas Bellinger } 599e48354ceSNicholas Bellinger } 600e48354ceSNicholas Bellinger 601e48354ceSNicholas Bellinger return 0; 602e48354ceSNicholas Bellinger do_auth: 603e48354ceSNicholas Bellinger return iscsi_target_do_authentication(conn, login); 604e48354ceSNicholas Bellinger } 605e48354ceSNicholas Bellinger 606e48354ceSNicholas Bellinger static int iscsi_target_handle_csg_one(struct iscsi_conn *conn, struct iscsi_login *login) 607e48354ceSNicholas Bellinger { 608e48354ceSNicholas Bellinger int ret; 609e48354ceSNicholas Bellinger u32 payload_length; 610e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 611e48354ceSNicholas Bellinger struct iscsi_login_rsp *login_rsp; 612e48354ceSNicholas Bellinger 613e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 614e48354ceSNicholas Bellinger login_rsp = (struct iscsi_login_rsp *) login->rsp; 615e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 616e48354ceSNicholas Bellinger 617e48354ceSNicholas Bellinger ret = iscsi_decode_text_input( 618e48354ceSNicholas Bellinger PHASE_OPERATIONAL|PHASE_DECLARATIVE, 619e48354ceSNicholas Bellinger SENDER_INITIATOR|SENDER_RECEIVER, 620e48354ceSNicholas Bellinger login->req_buf, 621e48354ceSNicholas Bellinger payload_length, 6229977bb18SNicholas Bellinger conn); 6231c5c12c6SRoland Dreier if (ret < 0) { 6241c5c12c6SRoland Dreier iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 6251c5c12c6SRoland Dreier ISCSI_LOGIN_STATUS_INIT_ERR); 626e48354ceSNicholas Bellinger return -1; 6271c5c12c6SRoland Dreier } 628e48354ceSNicholas Bellinger 629e48354ceSNicholas Bellinger if (login->first_request) 630e48354ceSNicholas Bellinger if (iscsi_target_check_first_request(conn, login) < 0) 631e48354ceSNicholas Bellinger return -1; 632e48354ceSNicholas Bellinger 633e48354ceSNicholas Bellinger if (iscsi_target_check_for_existing_instances(conn, login) < 0) 634e48354ceSNicholas Bellinger return -1; 635e48354ceSNicholas Bellinger 636e48354ceSNicholas Bellinger ret = iscsi_encode_text_output( 637e48354ceSNicholas Bellinger PHASE_OPERATIONAL|PHASE_DECLARATIVE, 638e48354ceSNicholas Bellinger SENDER_TARGET, 639e48354ceSNicholas Bellinger login->rsp_buf, 640e48354ceSNicholas Bellinger &login->rsp_length, 641e48354ceSNicholas Bellinger conn->param_list); 6421c5c12c6SRoland Dreier if (ret < 0) { 6431c5c12c6SRoland Dreier iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 6441c5c12c6SRoland Dreier ISCSI_LOGIN_STATUS_INIT_ERR); 645e48354ceSNicholas Bellinger return -1; 6461c5c12c6SRoland Dreier } 647e48354ceSNicholas Bellinger 648e48354ceSNicholas Bellinger if (!login->auth_complete && 649e48354ceSNicholas Bellinger ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication) { 650e48354ceSNicholas Bellinger pr_err("Initiator is requesting CSG: 1, has not been" 651e48354ceSNicholas Bellinger " successfully authenticated, and the Target is" 652e48354ceSNicholas Bellinger " enforcing iSCSI Authentication, login failed.\n"); 653e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 654e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_AUTH_FAILED); 655e48354ceSNicholas Bellinger return -1; 656e48354ceSNicholas Bellinger } 657e48354ceSNicholas Bellinger 658e48354ceSNicholas Bellinger if (!iscsi_check_negotiated_keys(conn->param_list)) 659e48354ceSNicholas Bellinger if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE3) && 660e48354ceSNicholas Bellinger (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) 661e48354ceSNicholas Bellinger login_rsp->flags |= ISCSI_FLAG_LOGIN_NEXT_STAGE3 | 662e48354ceSNicholas Bellinger ISCSI_FLAG_LOGIN_TRANSIT; 663e48354ceSNicholas Bellinger 664e48354ceSNicholas Bellinger return 0; 665e48354ceSNicholas Bellinger } 666e48354ceSNicholas Bellinger 667e48354ceSNicholas Bellinger static int iscsi_target_do_login(struct iscsi_conn *conn, struct iscsi_login *login) 668e48354ceSNicholas Bellinger { 669e48354ceSNicholas Bellinger int pdu_count = 0; 670e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 671e48354ceSNicholas Bellinger struct iscsi_login_rsp *login_rsp; 672e48354ceSNicholas Bellinger 673e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 674e48354ceSNicholas Bellinger login_rsp = (struct iscsi_login_rsp *) login->rsp; 675e48354ceSNicholas Bellinger 676e48354ceSNicholas Bellinger while (1) { 677e48354ceSNicholas Bellinger if (++pdu_count > MAX_LOGIN_PDUS) { 678e48354ceSNicholas Bellinger pr_err("MAX_LOGIN_PDUS count reached.\n"); 679e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 680e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_TARGET_ERROR); 681e48354ceSNicholas Bellinger return -1; 682e48354ceSNicholas Bellinger } 683e48354ceSNicholas Bellinger 6845d358065SAndy Grover switch (ISCSI_LOGIN_CURRENT_STAGE(login_req->flags)) { 685e48354ceSNicholas Bellinger case 0: 6865d358065SAndy Grover login_rsp->flags &= ~ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK; 687e48354ceSNicholas Bellinger if (iscsi_target_handle_csg_zero(conn, login) < 0) 688e48354ceSNicholas Bellinger return -1; 689e48354ceSNicholas Bellinger break; 690e48354ceSNicholas Bellinger case 1: 691e48354ceSNicholas Bellinger login_rsp->flags |= ISCSI_FLAG_LOGIN_CURRENT_STAGE1; 692e48354ceSNicholas Bellinger if (iscsi_target_handle_csg_one(conn, login) < 0) 693e48354ceSNicholas Bellinger return -1; 694e48354ceSNicholas Bellinger if (login_rsp->flags & ISCSI_FLAG_LOGIN_TRANSIT) { 695e48354ceSNicholas Bellinger login->tsih = conn->sess->tsih; 696e48354ceSNicholas Bellinger if (iscsi_target_do_tx_login_io(conn, 697e48354ceSNicholas Bellinger login) < 0) 698e48354ceSNicholas Bellinger return -1; 699e48354ceSNicholas Bellinger return 0; 700e48354ceSNicholas Bellinger } 701e48354ceSNicholas Bellinger break; 702e48354ceSNicholas Bellinger default: 703e48354ceSNicholas Bellinger pr_err("Illegal CSG: %d received from" 704e48354ceSNicholas Bellinger " Initiator, protocol error.\n", 7055d358065SAndy Grover ISCSI_LOGIN_CURRENT_STAGE(login_req->flags)); 706e48354ceSNicholas Bellinger break; 707e48354ceSNicholas Bellinger } 708e48354ceSNicholas Bellinger 709e48354ceSNicholas Bellinger if (iscsi_target_do_login_io(conn, login) < 0) 710e48354ceSNicholas Bellinger return -1; 711e48354ceSNicholas Bellinger 712e48354ceSNicholas Bellinger if (login_rsp->flags & ISCSI_FLAG_LOGIN_TRANSIT) { 713e48354ceSNicholas Bellinger login_rsp->flags &= ~ISCSI_FLAG_LOGIN_TRANSIT; 714e48354ceSNicholas Bellinger login_rsp->flags &= ~ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK; 715e48354ceSNicholas Bellinger } 716e48354ceSNicholas Bellinger } 717e48354ceSNicholas Bellinger 718e48354ceSNicholas Bellinger return 0; 719e48354ceSNicholas Bellinger } 720e48354ceSNicholas Bellinger 721e48354ceSNicholas Bellinger static void iscsi_initiatorname_tolower( 722e48354ceSNicholas Bellinger char *param_buf) 723e48354ceSNicholas Bellinger { 724e48354ceSNicholas Bellinger char *c; 725e48354ceSNicholas Bellinger u32 iqn_size = strlen(param_buf), i; 726e48354ceSNicholas Bellinger 727e48354ceSNicholas Bellinger for (i = 0; i < iqn_size; i++) { 7288359cf43SJörn Engel c = ¶m_buf[i]; 729e48354ceSNicholas Bellinger if (!isupper(*c)) 730e48354ceSNicholas Bellinger continue; 731e48354ceSNicholas Bellinger 732e48354ceSNicholas Bellinger *c = tolower(*c); 733e48354ceSNicholas Bellinger } 734e48354ceSNicholas Bellinger } 735e48354ceSNicholas Bellinger 736e48354ceSNicholas Bellinger /* 737e48354ceSNicholas Bellinger * Processes the first Login Request.. 738e48354ceSNicholas Bellinger */ 739e48354ceSNicholas Bellinger static int iscsi_target_locate_portal( 740e48354ceSNicholas Bellinger struct iscsi_np *np, 741e48354ceSNicholas Bellinger struct iscsi_conn *conn, 742e48354ceSNicholas Bellinger struct iscsi_login *login) 743e48354ceSNicholas Bellinger { 744e48354ceSNicholas Bellinger char *i_buf = NULL, *s_buf = NULL, *t_buf = NULL; 745e48354ceSNicholas Bellinger char *tmpbuf, *start = NULL, *end = NULL, *key, *value; 746e48354ceSNicholas Bellinger struct iscsi_session *sess = conn->sess; 747e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 748e48354ceSNicholas Bellinger struct iscsi_login_req *login_req; 749e48354ceSNicholas Bellinger u32 payload_length; 750e48354ceSNicholas Bellinger int sessiontype = 0, ret = 0; 751e48354ceSNicholas Bellinger 752e48354ceSNicholas Bellinger login_req = (struct iscsi_login_req *) login->req; 753e48354ceSNicholas Bellinger payload_length = ntoh24(login_req->dlength); 754e48354ceSNicholas Bellinger 755e48354ceSNicholas Bellinger login->first_request = 1; 756e48354ceSNicholas Bellinger login->leading_connection = (!login_req->tsih) ? 1 : 0; 7575d358065SAndy Grover login->current_stage = ISCSI_LOGIN_CURRENT_STAGE(login_req->flags); 758e48354ceSNicholas Bellinger login->version_min = login_req->min_version; 759e48354ceSNicholas Bellinger login->version_max = login_req->max_version; 760e48354ceSNicholas Bellinger memcpy(login->isid, login_req->isid, 6); 76150e5c87dSChristoph Hellwig login->cmd_sn = be32_to_cpu(login_req->cmdsn); 762e48354ceSNicholas Bellinger login->init_task_tag = login_req->itt; 76350e5c87dSChristoph Hellwig login->initial_exp_statsn = be32_to_cpu(login_req->exp_statsn); 76450e5c87dSChristoph Hellwig login->cid = be16_to_cpu(login_req->cid); 76550e5c87dSChristoph Hellwig login->tsih = be16_to_cpu(login_req->tsih); 766e48354ceSNicholas Bellinger 767e48354ceSNicholas Bellinger if (iscsi_target_get_initial_payload(conn, login) < 0) 768e48354ceSNicholas Bellinger return -1; 769e48354ceSNicholas Bellinger 770e48354ceSNicholas Bellinger tmpbuf = kzalloc(payload_length + 1, GFP_KERNEL); 771e48354ceSNicholas Bellinger if (!tmpbuf) { 772e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for tmpbuf.\n"); 773e48354ceSNicholas Bellinger return -1; 774e48354ceSNicholas Bellinger } 775e48354ceSNicholas Bellinger 776e48354ceSNicholas Bellinger memcpy(tmpbuf, login->req_buf, payload_length); 777e48354ceSNicholas Bellinger tmpbuf[payload_length] = '\0'; 778e48354ceSNicholas Bellinger start = tmpbuf; 779e48354ceSNicholas Bellinger end = (start + payload_length); 780e48354ceSNicholas Bellinger 781e48354ceSNicholas Bellinger /* 782e48354ceSNicholas Bellinger * Locate the initial keys expected from the Initiator node in 783e48354ceSNicholas Bellinger * the first login request in order to progress with the login phase. 784e48354ceSNicholas Bellinger */ 785e48354ceSNicholas Bellinger while (start < end) { 786e48354ceSNicholas Bellinger if (iscsi_extract_key_value(start, &key, &value) < 0) { 787e48354ceSNicholas Bellinger ret = -1; 788e48354ceSNicholas Bellinger goto out; 789e48354ceSNicholas Bellinger } 790e48354ceSNicholas Bellinger 791e48354ceSNicholas Bellinger if (!strncmp(key, "InitiatorName", 13)) 792e48354ceSNicholas Bellinger i_buf = value; 793e48354ceSNicholas Bellinger else if (!strncmp(key, "SessionType", 11)) 794e48354ceSNicholas Bellinger s_buf = value; 795e48354ceSNicholas Bellinger else if (!strncmp(key, "TargetName", 10)) 796e48354ceSNicholas Bellinger t_buf = value; 797e48354ceSNicholas Bellinger 798e48354ceSNicholas Bellinger start += strlen(key) + strlen(value) + 2; 799e48354ceSNicholas Bellinger } 800e48354ceSNicholas Bellinger 801e48354ceSNicholas Bellinger /* 802e48354ceSNicholas Bellinger * See 5.3. Login Phase. 803e48354ceSNicholas Bellinger */ 804e48354ceSNicholas Bellinger if (!i_buf) { 805e48354ceSNicholas Bellinger pr_err("InitiatorName key not received" 806e48354ceSNicholas Bellinger " in first login request.\n"); 807e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 808e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_MISSING_FIELDS); 809e48354ceSNicholas Bellinger ret = -1; 810e48354ceSNicholas Bellinger goto out; 811e48354ceSNicholas Bellinger } 812e48354ceSNicholas Bellinger /* 813e48354ceSNicholas Bellinger * Convert the incoming InitiatorName to lowercase following 814e48354ceSNicholas Bellinger * RFC-3720 3.2.6.1. section c) that says that iSCSI IQNs 815e48354ceSNicholas Bellinger * are NOT case sensitive. 816e48354ceSNicholas Bellinger */ 817e48354ceSNicholas Bellinger iscsi_initiatorname_tolower(i_buf); 818e48354ceSNicholas Bellinger 819e48354ceSNicholas Bellinger if (!s_buf) { 820e48354ceSNicholas Bellinger if (!login->leading_connection) 821e48354ceSNicholas Bellinger goto get_target; 822e48354ceSNicholas Bellinger 823e48354ceSNicholas Bellinger pr_err("SessionType key not received" 824e48354ceSNicholas Bellinger " in first login request.\n"); 825e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 826e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_MISSING_FIELDS); 827e48354ceSNicholas Bellinger ret = -1; 828e48354ceSNicholas Bellinger goto out; 829e48354ceSNicholas Bellinger } 830e48354ceSNicholas Bellinger 831e48354ceSNicholas Bellinger /* 832e48354ceSNicholas Bellinger * Use default portal group for discovery sessions. 833e48354ceSNicholas Bellinger */ 834e48354ceSNicholas Bellinger sessiontype = strncmp(s_buf, DISCOVERY, 9); 835e48354ceSNicholas Bellinger if (!sessiontype) { 836e48354ceSNicholas Bellinger conn->tpg = iscsit_global->discovery_tpg; 837e48354ceSNicholas Bellinger if (!login->leading_connection) 838e48354ceSNicholas Bellinger goto get_target; 839e48354ceSNicholas Bellinger 840e48354ceSNicholas Bellinger sess->sess_ops->SessionType = 1; 841e48354ceSNicholas Bellinger /* 842e48354ceSNicholas Bellinger * Setup crc32c modules from libcrypto 843e48354ceSNicholas Bellinger */ 844e48354ceSNicholas Bellinger if (iscsi_login_setup_crypto(conn) < 0) { 845e48354ceSNicholas Bellinger pr_err("iscsi_login_setup_crypto() failed\n"); 846e48354ceSNicholas Bellinger ret = -1; 847e48354ceSNicholas Bellinger goto out; 848e48354ceSNicholas Bellinger } 849e48354ceSNicholas Bellinger /* 850e48354ceSNicholas Bellinger * Serialize access across the discovery struct iscsi_portal_group to 851e48354ceSNicholas Bellinger * process login attempt. 852e48354ceSNicholas Bellinger */ 853e48354ceSNicholas Bellinger if (iscsit_access_np(np, conn->tpg) < 0) { 854e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 855e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); 856e48354ceSNicholas Bellinger ret = -1; 857e48354ceSNicholas Bellinger goto out; 858e48354ceSNicholas Bellinger } 859e48354ceSNicholas Bellinger ret = 0; 860e48354ceSNicholas Bellinger goto out; 861e48354ceSNicholas Bellinger } 862e48354ceSNicholas Bellinger 863e48354ceSNicholas Bellinger get_target: 864e48354ceSNicholas Bellinger if (!t_buf) { 865e48354ceSNicholas Bellinger pr_err("TargetName key not received" 866e48354ceSNicholas Bellinger " in first login request while" 867e48354ceSNicholas Bellinger " SessionType=Normal.\n"); 868e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 869e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_MISSING_FIELDS); 870e48354ceSNicholas Bellinger ret = -1; 871e48354ceSNicholas Bellinger goto out; 872e48354ceSNicholas Bellinger } 873e48354ceSNicholas Bellinger 874e48354ceSNicholas Bellinger /* 875e48354ceSNicholas Bellinger * Locate Target IQN from Storage Node. 876e48354ceSNicholas Bellinger */ 877e48354ceSNicholas Bellinger tiqn = iscsit_get_tiqn_for_login(t_buf); 878e48354ceSNicholas Bellinger if (!tiqn) { 879e48354ceSNicholas Bellinger pr_err("Unable to locate Target IQN: %s in" 880e48354ceSNicholas Bellinger " Storage Node\n", t_buf); 881e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 882e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); 883e48354ceSNicholas Bellinger ret = -1; 884e48354ceSNicholas Bellinger goto out; 885e48354ceSNicholas Bellinger } 886e48354ceSNicholas Bellinger pr_debug("Located Storage Object: %s\n", tiqn->tiqn); 887e48354ceSNicholas Bellinger 888e48354ceSNicholas Bellinger /* 889e48354ceSNicholas Bellinger * Locate Target Portal Group from Storage Node. 890e48354ceSNicholas Bellinger */ 891e48354ceSNicholas Bellinger conn->tpg = iscsit_get_tpg_from_np(tiqn, np); 892e48354ceSNicholas Bellinger if (!conn->tpg) { 893e48354ceSNicholas Bellinger pr_err("Unable to locate Target Portal Group" 894e48354ceSNicholas Bellinger " on %s\n", tiqn->tiqn); 895e48354ceSNicholas Bellinger iscsit_put_tiqn_for_login(tiqn); 896e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 897e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); 898e48354ceSNicholas Bellinger ret = -1; 899e48354ceSNicholas Bellinger goto out; 900e48354ceSNicholas Bellinger } 901e48354ceSNicholas Bellinger pr_debug("Located Portal Group Object: %hu\n", conn->tpg->tpgt); 902e48354ceSNicholas Bellinger /* 903e48354ceSNicholas Bellinger * Setup crc32c modules from libcrypto 904e48354ceSNicholas Bellinger */ 905e48354ceSNicholas Bellinger if (iscsi_login_setup_crypto(conn) < 0) { 906e48354ceSNicholas Bellinger pr_err("iscsi_login_setup_crypto() failed\n"); 907e48354ceSNicholas Bellinger ret = -1; 908e48354ceSNicholas Bellinger goto out; 909e48354ceSNicholas Bellinger } 910e48354ceSNicholas Bellinger /* 911e48354ceSNicholas Bellinger * Serialize access across the struct iscsi_portal_group to 912e48354ceSNicholas Bellinger * process login attempt. 913e48354ceSNicholas Bellinger */ 914e48354ceSNicholas Bellinger if (iscsit_access_np(np, conn->tpg) < 0) { 915e48354ceSNicholas Bellinger iscsit_put_tiqn_for_login(tiqn); 916e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 917e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); 918e48354ceSNicholas Bellinger ret = -1; 919e48354ceSNicholas Bellinger conn->tpg = NULL; 920e48354ceSNicholas Bellinger goto out; 921e48354ceSNicholas Bellinger } 922e48354ceSNicholas Bellinger 923e48354ceSNicholas Bellinger /* 924e48354ceSNicholas Bellinger * conn->sess->node_acl will be set when the referenced 925e48354ceSNicholas Bellinger * struct iscsi_session is located from received ISID+TSIH in 926e48354ceSNicholas Bellinger * iscsi_login_non_zero_tsih_s2(). 927e48354ceSNicholas Bellinger */ 928e48354ceSNicholas Bellinger if (!login->leading_connection) { 929e48354ceSNicholas Bellinger ret = 0; 930e48354ceSNicholas Bellinger goto out; 931e48354ceSNicholas Bellinger } 932e48354ceSNicholas Bellinger 933e48354ceSNicholas Bellinger /* 934e48354ceSNicholas Bellinger * This value is required in iscsi_login_zero_tsih_s2() 935e48354ceSNicholas Bellinger */ 936e48354ceSNicholas Bellinger sess->sess_ops->SessionType = 0; 937e48354ceSNicholas Bellinger 938e48354ceSNicholas Bellinger /* 939e48354ceSNicholas Bellinger * Locate incoming Initiator IQN reference from Storage Node. 940e48354ceSNicholas Bellinger */ 941e48354ceSNicholas Bellinger sess->se_sess->se_node_acl = core_tpg_check_initiator_node_acl( 942e48354ceSNicholas Bellinger &conn->tpg->tpg_se_tpg, i_buf); 943e48354ceSNicholas Bellinger if (!sess->se_sess->se_node_acl) { 944e48354ceSNicholas Bellinger pr_err("iSCSI Initiator Node: %s is not authorized to" 945e48354ceSNicholas Bellinger " access iSCSI target portal group: %hu.\n", 946e48354ceSNicholas Bellinger i_buf, conn->tpg->tpgt); 947e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, 948e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_TGT_FORBIDDEN); 949e48354ceSNicholas Bellinger ret = -1; 950e48354ceSNicholas Bellinger goto out; 951e48354ceSNicholas Bellinger } 952e48354ceSNicholas Bellinger 953e48354ceSNicholas Bellinger ret = 0; 954e48354ceSNicholas Bellinger out: 955e48354ceSNicholas Bellinger kfree(tmpbuf); 956e48354ceSNicholas Bellinger return ret; 957e48354ceSNicholas Bellinger } 958e48354ceSNicholas Bellinger 959e48354ceSNicholas Bellinger struct iscsi_login *iscsi_target_init_negotiation( 960e48354ceSNicholas Bellinger struct iscsi_np *np, 961e48354ceSNicholas Bellinger struct iscsi_conn *conn, 962e48354ceSNicholas Bellinger char *login_pdu) 963e48354ceSNicholas Bellinger { 964e48354ceSNicholas Bellinger struct iscsi_login *login; 965e48354ceSNicholas Bellinger 966e48354ceSNicholas Bellinger login = kzalloc(sizeof(struct iscsi_login), GFP_KERNEL); 967e48354ceSNicholas Bellinger if (!login) { 968e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for struct iscsi_login.\n"); 969e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 970e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_NO_RESOURCES); 9714a28a3faSDan Carpenter return NULL; 972e48354ceSNicholas Bellinger } 973e48354ceSNicholas Bellinger 9741c3d5794SThomas Meyer login->req = kmemdup(login_pdu, ISCSI_HDR_LEN, GFP_KERNEL); 975e48354ceSNicholas Bellinger if (!login->req) { 976e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for Login Request.\n"); 977e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 978e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_NO_RESOURCES); 979e48354ceSNicholas Bellinger goto out; 980e48354ceSNicholas Bellinger } 981e48354ceSNicholas Bellinger 982e48354ceSNicholas Bellinger login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL); 983e48354ceSNicholas Bellinger if (!login->req_buf) { 984e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for response buffer.\n"); 985e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 986e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_NO_RESOURCES); 987e48354ceSNicholas Bellinger goto out; 988e48354ceSNicholas Bellinger } 989e48354ceSNicholas Bellinger /* 990e48354ceSNicholas Bellinger * SessionType: Discovery 991e48354ceSNicholas Bellinger * 992e48354ceSNicholas Bellinger * Locates Default Portal 993e48354ceSNicholas Bellinger * 994e48354ceSNicholas Bellinger * SessionType: Normal 995e48354ceSNicholas Bellinger * 996e48354ceSNicholas Bellinger * Locates Target Portal from NP -> Target IQN 997e48354ceSNicholas Bellinger */ 998e48354ceSNicholas Bellinger if (iscsi_target_locate_portal(np, conn, login) < 0) { 999e48354ceSNicholas Bellinger goto out; 1000e48354ceSNicholas Bellinger } 1001e48354ceSNicholas Bellinger 1002e48354ceSNicholas Bellinger return login; 1003e48354ceSNicholas Bellinger out: 1004e48354ceSNicholas Bellinger kfree(login->req); 1005e48354ceSNicholas Bellinger kfree(login->req_buf); 1006e48354ceSNicholas Bellinger kfree(login); 1007e48354ceSNicholas Bellinger 1008e48354ceSNicholas Bellinger return NULL; 1009e48354ceSNicholas Bellinger } 1010e48354ceSNicholas Bellinger 1011e48354ceSNicholas Bellinger int iscsi_target_start_negotiation( 1012e48354ceSNicholas Bellinger struct iscsi_login *login, 1013e48354ceSNicholas Bellinger struct iscsi_conn *conn) 1014e48354ceSNicholas Bellinger { 1015e48354ceSNicholas Bellinger int ret = -1; 1016e48354ceSNicholas Bellinger 1017e48354ceSNicholas Bellinger login->rsp = kzalloc(ISCSI_HDR_LEN, GFP_KERNEL); 1018e48354ceSNicholas Bellinger if (!login->rsp) { 1019e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 1020e48354ceSNicholas Bellinger " Login Response.\n"); 1021e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 1022e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_NO_RESOURCES); 1023e48354ceSNicholas Bellinger ret = -1; 1024e48354ceSNicholas Bellinger goto out; 1025e48354ceSNicholas Bellinger } 1026e48354ceSNicholas Bellinger 1027e48354ceSNicholas Bellinger login->rsp_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL); 1028e48354ceSNicholas Bellinger if (!login->rsp_buf) { 1029e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 1030e48354ceSNicholas Bellinger " request buffer.\n"); 1031e48354ceSNicholas Bellinger iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 1032e48354ceSNicholas Bellinger ISCSI_LOGIN_STATUS_NO_RESOURCES); 1033e48354ceSNicholas Bellinger ret = -1; 1034e48354ceSNicholas Bellinger goto out; 1035e48354ceSNicholas Bellinger } 1036e48354ceSNicholas Bellinger 1037e48354ceSNicholas Bellinger ret = iscsi_target_do_login(conn, login); 1038e48354ceSNicholas Bellinger out: 1039e48354ceSNicholas Bellinger if (ret != 0) 1040e48354ceSNicholas Bellinger iscsi_remove_failed_auth_entry(conn); 1041e48354ceSNicholas Bellinger 1042e48354ceSNicholas Bellinger iscsi_target_nego_release(login, conn); 1043e48354ceSNicholas Bellinger return ret; 1044e48354ceSNicholas Bellinger } 1045e48354ceSNicholas Bellinger 1046e48354ceSNicholas Bellinger void iscsi_target_nego_release( 1047e48354ceSNicholas Bellinger struct iscsi_login *login, 1048e48354ceSNicholas Bellinger struct iscsi_conn *conn) 1049e48354ceSNicholas Bellinger { 1050e48354ceSNicholas Bellinger kfree(login->req); 1051e48354ceSNicholas Bellinger kfree(login->rsp); 1052e48354ceSNicholas Bellinger kfree(login->req_buf); 1053e48354ceSNicholas Bellinger kfree(login->rsp_buf); 1054e48354ceSNicholas Bellinger kfree(login); 1055e48354ceSNicholas Bellinger } 1056