1 /*******************************************************************************
2 * This file contains main functions related to iSCSI Parameter negotiation.
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
21 #include <linux/ctype.h>
22 #include <scsi/iscsi_proto.h>
23 #include <target/target_core_base.h>
24 #include <target/target_core_fabric.h>
25 #include <target/iscsi/iscsi_transport.h>
27 #include "iscsi_target_core.h"
28 #include "iscsi_target_parameters.h"
29 #include "iscsi_target_login.h"
30 #include "iscsi_target_nego.h"
31 #include "iscsi_target_tpg.h"
32 #include "iscsi_target_util.h"
33 #include "iscsi_target.h"
34 #include "iscsi_target_auth.h"
36 #define MAX_LOGIN_PDUS 7
39 void convert_null_to_semi(char *buf, int len)
43 for (i = 0; i < len; i++)
48 static int strlen_semi(char *buf)
52 while (buf[i] != '\0') {
64 unsigned int max_length,
71 if (!in_buf || !pattern || !out_buf || !type)
74 ptr = strstr(in_buf, pattern);
78 ptr = strstr(ptr, "=");
83 if (*ptr == '0' && (*(ptr+1) == 'x' || *(ptr+1) == 'X')) {
84 ptr += 2; /* skip 0x */
89 len = strlen_semi(ptr);
93 if (len > max_length) {
94 pr_err("Length of input: %d exceeds max_length:"
95 " %d\n", len, max_length);
98 memcpy(out_buf, ptr, len);
104 static u32 iscsi_handle_authentication(
105 struct iscsi_conn *conn,
110 unsigned char *authtype)
112 struct iscsi_session *sess = conn->sess;
113 struct iscsi_node_auth *auth;
114 struct iscsi_node_acl *iscsi_nacl;
115 struct se_node_acl *se_nacl;
117 if (!sess->sess_ops->SessionType) {
119 * For SessionType=Normal
121 se_nacl = conn->sess->se_sess->se_node_acl;
123 pr_err("Unable to locate struct se_node_acl for"
127 iscsi_nacl = container_of(se_nacl, struct iscsi_node_acl,
130 pr_err("Unable to locate struct iscsi_node_acl for"
135 auth = ISCSI_NODE_AUTH(iscsi_nacl);
138 * For SessionType=Discovery
140 auth = &iscsit_global->discovery_acl.node_auth;
143 if (strstr("CHAP", authtype))
144 strcpy(conn->sess->auth_type, "CHAP");
146 strcpy(conn->sess->auth_type, NONE);
148 if (strstr("None", authtype))
151 else if (strstr("SRP", authtype))
152 return srp_main_loop(conn, auth, in_buf, out_buf,
153 &in_length, out_length);
155 else if (strstr("CHAP", authtype))
156 return chap_main_loop(conn, auth, in_buf, out_buf,
157 &in_length, out_length);
158 else if (strstr("SPKM1", authtype))
160 else if (strstr("SPKM2", authtype))
162 else if (strstr("KRB5", authtype))
168 static void iscsi_remove_failed_auth_entry(struct iscsi_conn *conn)
170 kfree(conn->auth_protocol);
173 int iscsi_target_check_login_request(
174 struct iscsi_conn *conn,
175 struct iscsi_login *login)
177 int req_csg, req_nsg;
179 struct iscsi_login_req *login_req;
181 login_req = (struct iscsi_login_req *) login->req;
182 payload_length = ntoh24(login_req->dlength);
184 switch (login_req->opcode & ISCSI_OPCODE_MASK) {
188 pr_err("Received unknown opcode 0x%02x.\n",
189 login_req->opcode & ISCSI_OPCODE_MASK);
190 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
191 ISCSI_LOGIN_STATUS_INIT_ERR);
195 if ((login_req->flags & ISCSI_FLAG_LOGIN_CONTINUE) &&
196 (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) {
197 pr_err("Login request has both ISCSI_FLAG_LOGIN_CONTINUE"
198 " and ISCSI_FLAG_LOGIN_TRANSIT set, protocol error.\n");
199 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
200 ISCSI_LOGIN_STATUS_INIT_ERR);
204 req_csg = ISCSI_LOGIN_CURRENT_STAGE(login_req->flags);
205 req_nsg = ISCSI_LOGIN_NEXT_STAGE(login_req->flags);
207 if (req_csg != login->current_stage) {
208 pr_err("Initiator unexpectedly changed login stage"
209 " from %d to %d, login failed.\n", login->current_stage,
211 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
212 ISCSI_LOGIN_STATUS_INIT_ERR);
216 if ((req_nsg == 2) || (req_csg >= 2) ||
217 ((login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT) &&
218 (req_nsg <= req_csg))) {
219 pr_err("Illegal login_req->flags Combination, CSG: %d,"
220 " NSG: %d, ISCSI_FLAG_LOGIN_TRANSIT: %d.\n", req_csg,
221 req_nsg, (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT));
222 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
223 ISCSI_LOGIN_STATUS_INIT_ERR);
227 if ((login_req->max_version != login->version_max) ||
228 (login_req->min_version != login->version_min)) {
229 pr_err("Login request changed Version Max/Nin"
230 " unexpectedly to 0x%02x/0x%02x, protocol error\n",
231 login_req->max_version, login_req->min_version);
232 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
233 ISCSI_LOGIN_STATUS_INIT_ERR);
237 if (memcmp(login_req->isid, login->isid, 6) != 0) {
238 pr_err("Login request changed ISID unexpectedly,"
239 " protocol error.\n");
240 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
241 ISCSI_LOGIN_STATUS_INIT_ERR);
245 if (login_req->itt != login->init_task_tag) {
246 pr_err("Login request changed ITT unexpectedly to"
247 " 0x%08x, protocol error.\n", login_req->itt);
248 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
249 ISCSI_LOGIN_STATUS_INIT_ERR);
253 if (payload_length > MAX_KEY_VALUE_PAIRS) {
254 pr_err("Login request payload exceeds default"
255 " MaxRecvDataSegmentLength: %u, protocol error.\n",
256 MAX_KEY_VALUE_PAIRS);
263 static int iscsi_target_check_first_request(
264 struct iscsi_conn *conn,
265 struct iscsi_login *login)
267 struct iscsi_param *param = NULL;
268 struct se_node_acl *se_nacl;
270 login->first_request = 0;
272 list_for_each_entry(param, &conn->param_list->param_list, p_list) {
273 if (!strncmp(param->name, SESSIONTYPE, 11)) {
274 if (!IS_PSTATE_ACCEPTOR(param)) {
275 pr_err("SessionType key not received"
276 " in first login request.\n");
277 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
278 ISCSI_LOGIN_STATUS_MISSING_FIELDS);
281 if (!strncmp(param->value, DISCOVERY, 9))
285 if (!strncmp(param->name, INITIATORNAME, 13)) {
286 if (!IS_PSTATE_ACCEPTOR(param)) {
287 if (!login->leading_connection)
290 pr_err("InitiatorName key not received"
291 " in first login request.\n");
292 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
293 ISCSI_LOGIN_STATUS_MISSING_FIELDS);
298 * For non-leading connections, double check that the
299 * received InitiatorName matches the existing session's
300 * struct iscsi_node_acl.
302 if (!login->leading_connection) {
303 se_nacl = conn->sess->se_sess->se_node_acl;
305 pr_err("Unable to locate"
306 " struct se_node_acl\n");
307 iscsit_tx_login_rsp(conn,
308 ISCSI_STATUS_CLS_INITIATOR_ERR,
309 ISCSI_LOGIN_STATUS_TGT_NOT_FOUND);
313 if (strcmp(param->value,
314 se_nacl->initiatorname)) {
316 " InitiatorName: %s for this"
317 " iSCSI Initiator Node.\n",
319 iscsit_tx_login_rsp(conn,
320 ISCSI_STATUS_CLS_INITIATOR_ERR,
321 ISCSI_LOGIN_STATUS_TGT_NOT_FOUND);
331 static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_login *login)
334 struct iscsi_session *sess = conn->sess;
335 struct iscsi_login_rsp *login_rsp;
337 login_rsp = (struct iscsi_login_rsp *) login->rsp;
339 login_rsp->opcode = ISCSI_OP_LOGIN_RSP;
340 hton24(login_rsp->dlength, login->rsp_length);
341 memcpy(login_rsp->isid, login->isid, 6);
342 login_rsp->tsih = cpu_to_be16(login->tsih);
343 login_rsp->itt = login->init_task_tag;
344 login_rsp->statsn = cpu_to_be32(conn->stat_sn++);
345 login_rsp->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn);
346 login_rsp->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn);
348 pr_debug("Sending Login Response, Flags: 0x%02x, ITT: 0x%08x,"
349 " ExpCmdSN; 0x%08x, MaxCmdSN: 0x%08x, StatSN: 0x%08x, Length:"
350 " %u\n", login_rsp->flags, (__force u32)login_rsp->itt,
351 ntohl(login_rsp->exp_cmdsn), ntohl(login_rsp->max_cmdsn),
352 ntohl(login_rsp->statsn), login->rsp_length);
354 padding = ((-login->rsp_length) & 3);
356 if (conn->conn_transport->iscsit_put_login_tx(conn, login,
357 login->rsp_length + padding) < 0)
360 login->rsp_length = 0;
361 mutex_lock(&sess->cmdsn_mutex);
362 login_rsp->exp_cmdsn = cpu_to_be32(sess->exp_cmd_sn);
363 login_rsp->max_cmdsn = cpu_to_be32(sess->max_cmd_sn);
364 mutex_unlock(&sess->cmdsn_mutex);
369 static int iscsi_target_do_login_io(struct iscsi_conn *conn, struct iscsi_login *login)
371 if (iscsi_target_do_tx_login_io(conn, login) < 0)
374 if (conn->conn_transport->iscsit_get_login_rx(conn, login) < 0)
381 * NOTE: We check for existing sessions or connections AFTER the initiator
382 * has been successfully authenticated in order to protect against faked
383 * ISID/TSIH combinations.
385 static int iscsi_target_check_for_existing_instances(
386 struct iscsi_conn *conn,
387 struct iscsi_login *login)
389 if (login->checked_for_existing)
392 login->checked_for_existing = 1;
395 return iscsi_check_for_session_reinstatement(conn);
397 return iscsi_login_post_auth_non_zero_tsih(conn, login->cid,
398 login->initial_exp_statsn);
401 static int iscsi_target_do_authentication(
402 struct iscsi_conn *conn,
403 struct iscsi_login *login)
407 struct iscsi_param *param;
408 struct iscsi_login_req *login_req;
409 struct iscsi_login_rsp *login_rsp;
411 login_req = (struct iscsi_login_req *) login->req;
412 login_rsp = (struct iscsi_login_rsp *) login->rsp;
413 payload_length = ntoh24(login_req->dlength);
415 param = iscsi_find_param_from_key(AUTHMETHOD, conn->param_list);
419 authret = iscsi_handle_authentication(
428 pr_debug("Received OK response"
429 " from LIO Authentication, continuing.\n");
432 pr_debug("iSCSI security negotiation"
433 " completed successfully.\n");
434 login->auth_complete = 1;
435 if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE1) &&
436 (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) {
437 login_rsp->flags |= (ISCSI_FLAG_LOGIN_NEXT_STAGE1 |
438 ISCSI_FLAG_LOGIN_TRANSIT);
439 login->current_stage = 1;
441 return iscsi_target_check_for_existing_instances(
444 pr_err("Security negotiation"
446 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
447 ISCSI_LOGIN_STATUS_AUTH_FAILED);
450 pr_err("Received unknown error %d from LIO"
451 " Authentication\n", authret);
452 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
453 ISCSI_LOGIN_STATUS_TARGET_ERROR);
460 static int iscsi_target_handle_csg_zero(
461 struct iscsi_conn *conn,
462 struct iscsi_login *login)
466 struct iscsi_param *param;
467 struct iscsi_login_req *login_req;
468 struct iscsi_login_rsp *login_rsp;
470 login_req = (struct iscsi_login_req *) login->req;
471 login_rsp = (struct iscsi_login_rsp *) login->rsp;
472 payload_length = ntoh24(login_req->dlength);
474 param = iscsi_find_param_from_key(AUTHMETHOD, conn->param_list);
478 ret = iscsi_decode_text_input(
479 PHASE_SECURITY|PHASE_DECLARATIVE,
480 SENDER_INITIATOR|SENDER_RECEIVER,
488 if (login->auth_complete) {
489 pr_err("Initiator has already been"
490 " successfully authenticated, but is still"
491 " sending %s keys.\n", param->value);
492 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
493 ISCSI_LOGIN_STATUS_INIT_ERR);
500 if (login->first_request)
501 if (iscsi_target_check_first_request(conn, login) < 0)
504 ret = iscsi_encode_text_output(
505 PHASE_SECURITY|PHASE_DECLARATIVE,
513 if (!iscsi_check_negotiated_keys(conn->param_list)) {
514 if (ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication &&
515 !strncmp(param->value, NONE, 4)) {
516 pr_err("Initiator sent AuthMethod=None but"
517 " Target is enforcing iSCSI Authentication,"
519 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
520 ISCSI_LOGIN_STATUS_AUTH_FAILED);
524 if (ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication &&
525 !login->auth_complete)
528 if (strncmp(param->value, NONE, 4) && !login->auth_complete)
531 if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE1) &&
532 (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT)) {
533 login_rsp->flags |= ISCSI_FLAG_LOGIN_NEXT_STAGE1 |
534 ISCSI_FLAG_LOGIN_TRANSIT;
535 login->current_stage = 1;
541 return iscsi_target_do_authentication(conn, login);
544 static int iscsi_target_handle_csg_one(struct iscsi_conn *conn, struct iscsi_login *login)
548 struct iscsi_login_req *login_req;
549 struct iscsi_login_rsp *login_rsp;
551 login_req = (struct iscsi_login_req *) login->req;
552 login_rsp = (struct iscsi_login_rsp *) login->rsp;
553 payload_length = ntoh24(login_req->dlength);
555 ret = iscsi_decode_text_input(
556 PHASE_OPERATIONAL|PHASE_DECLARATIVE,
557 SENDER_INITIATOR|SENDER_RECEIVER,
562 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
563 ISCSI_LOGIN_STATUS_INIT_ERR);
567 if (login->first_request)
568 if (iscsi_target_check_first_request(conn, login) < 0)
571 if (iscsi_target_check_for_existing_instances(conn, login) < 0)
574 ret = iscsi_encode_text_output(
575 PHASE_OPERATIONAL|PHASE_DECLARATIVE,
581 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
582 ISCSI_LOGIN_STATUS_INIT_ERR);
586 if (!login->auth_complete &&
587 ISCSI_TPG_ATTRIB(ISCSI_TPG_C(conn))->authentication) {
588 pr_err("Initiator is requesting CSG: 1, has not been"
589 " successfully authenticated, and the Target is"
590 " enforcing iSCSI Authentication, login failed.\n");
591 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
592 ISCSI_LOGIN_STATUS_AUTH_FAILED);
596 if (!iscsi_check_negotiated_keys(conn->param_list))
597 if ((login_req->flags & ISCSI_FLAG_LOGIN_NEXT_STAGE3) &&
598 (login_req->flags & ISCSI_FLAG_LOGIN_TRANSIT))
599 login_rsp->flags |= ISCSI_FLAG_LOGIN_NEXT_STAGE3 |
600 ISCSI_FLAG_LOGIN_TRANSIT;
605 static int iscsi_target_do_login(struct iscsi_conn *conn, struct iscsi_login *login)
608 struct iscsi_login_req *login_req;
609 struct iscsi_login_rsp *login_rsp;
611 login_req = (struct iscsi_login_req *) login->req;
612 login_rsp = (struct iscsi_login_rsp *) login->rsp;
615 if (++pdu_count > MAX_LOGIN_PDUS) {
616 pr_err("MAX_LOGIN_PDUS count reached.\n");
617 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
618 ISCSI_LOGIN_STATUS_TARGET_ERROR);
622 switch (ISCSI_LOGIN_CURRENT_STAGE(login_req->flags)) {
624 login_rsp->flags &= ~ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK;
625 if (iscsi_target_handle_csg_zero(conn, login) < 0)
629 login_rsp->flags |= ISCSI_FLAG_LOGIN_CURRENT_STAGE1;
630 if (iscsi_target_handle_csg_one(conn, login) < 0)
632 if (login_rsp->flags & ISCSI_FLAG_LOGIN_TRANSIT) {
633 login->tsih = conn->sess->tsih;
634 login->login_complete = 1;
635 if (iscsi_target_do_tx_login_io(conn,
642 pr_err("Illegal CSG: %d received from"
643 " Initiator, protocol error.\n",
644 ISCSI_LOGIN_CURRENT_STAGE(login_req->flags));
648 if (iscsi_target_do_login_io(conn, login) < 0)
651 if (login_rsp->flags & ISCSI_FLAG_LOGIN_TRANSIT) {
652 login_rsp->flags &= ~ISCSI_FLAG_LOGIN_TRANSIT;
653 login_rsp->flags &= ~ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK;
660 static void iscsi_initiatorname_tolower(
664 u32 iqn_size = strlen(param_buf), i;
666 for (i = 0; i < iqn_size; i++) {
676 * Processes the first Login Request..
678 int iscsi_target_locate_portal(
680 struct iscsi_conn *conn,
681 struct iscsi_login *login)
683 char *i_buf = NULL, *s_buf = NULL, *t_buf = NULL;
684 char *tmpbuf, *start = NULL, *end = NULL, *key, *value;
685 struct iscsi_session *sess = conn->sess;
686 struct iscsi_tiqn *tiqn;
687 struct iscsi_login_req *login_req;
689 int sessiontype = 0, ret = 0;
691 login_req = (struct iscsi_login_req *) login->req;
692 payload_length = ntoh24(login_req->dlength);
694 tmpbuf = kzalloc(payload_length + 1, GFP_KERNEL);
696 pr_err("Unable to allocate memory for tmpbuf.\n");
700 memcpy(tmpbuf, login->req_buf, payload_length);
701 tmpbuf[payload_length] = '\0';
703 end = (start + payload_length);
706 * Locate the initial keys expected from the Initiator node in
707 * the first login request in order to progress with the login phase.
709 while (start < end) {
710 if (iscsi_extract_key_value(start, &key, &value) < 0) {
715 if (!strncmp(key, "InitiatorName", 13))
717 else if (!strncmp(key, "SessionType", 11))
719 else if (!strncmp(key, "TargetName", 10))
722 start += strlen(key) + strlen(value) + 2;
725 * See 5.3. Login Phase.
728 pr_err("InitiatorName key not received"
729 " in first login request.\n");
730 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
731 ISCSI_LOGIN_STATUS_MISSING_FIELDS);
736 * Convert the incoming InitiatorName to lowercase following
737 * RFC-3720 3.2.6.1. section c) that says that iSCSI IQNs
738 * are NOT case sensitive.
740 iscsi_initiatorname_tolower(i_buf);
743 if (!login->leading_connection)
746 pr_err("SessionType key not received"
747 " in first login request.\n");
748 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
749 ISCSI_LOGIN_STATUS_MISSING_FIELDS);
755 * Use default portal group for discovery sessions.
757 sessiontype = strncmp(s_buf, DISCOVERY, 9);
759 conn->tpg = iscsit_global->discovery_tpg;
760 if (!login->leading_connection)
763 sess->sess_ops->SessionType = 1;
765 * Setup crc32c modules from libcrypto
767 if (iscsi_login_setup_crypto(conn) < 0) {
768 pr_err("iscsi_login_setup_crypto() failed\n");
773 * Serialize access across the discovery struct iscsi_portal_group to
774 * process login attempt.
776 if (iscsit_access_np(np, conn->tpg) < 0) {
777 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
778 ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE);
788 pr_err("TargetName key not received"
789 " in first login request while"
790 " SessionType=Normal.\n");
791 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
792 ISCSI_LOGIN_STATUS_MISSING_FIELDS);
798 * Locate Target IQN from Storage Node.
800 tiqn = iscsit_get_tiqn_for_login(t_buf);
802 pr_err("Unable to locate Target IQN: %s in"
803 " Storage Node\n", t_buf);
804 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
805 ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE);
809 pr_debug("Located Storage Object: %s\n", tiqn->tiqn);
812 * Locate Target Portal Group from Storage Node.
814 conn->tpg = iscsit_get_tpg_from_np(tiqn, np);
816 pr_err("Unable to locate Target Portal Group"
817 " on %s\n", tiqn->tiqn);
818 iscsit_put_tiqn_for_login(tiqn);
819 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
820 ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE);
824 pr_debug("Located Portal Group Object: %hu\n", conn->tpg->tpgt);
826 * Setup crc32c modules from libcrypto
828 if (iscsi_login_setup_crypto(conn) < 0) {
829 pr_err("iscsi_login_setup_crypto() failed\n");
834 * Serialize access across the struct iscsi_portal_group to
835 * process login attempt.
837 if (iscsit_access_np(np, conn->tpg) < 0) {
838 iscsit_put_tiqn_for_login(tiqn);
839 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
840 ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE);
847 * conn->sess->node_acl will be set when the referenced
848 * struct iscsi_session is located from received ISID+TSIH in
849 * iscsi_login_non_zero_tsih_s2().
851 if (!login->leading_connection) {
857 * This value is required in iscsi_login_zero_tsih_s2()
859 sess->sess_ops->SessionType = 0;
862 * Locate incoming Initiator IQN reference from Storage Node.
864 sess->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
865 &conn->tpg->tpg_se_tpg, i_buf);
866 if (!sess->se_sess->se_node_acl) {
867 pr_err("iSCSI Initiator Node: %s is not authorized to"
868 " access iSCSI target portal group: %hu.\n",
869 i_buf, conn->tpg->tpgt);
870 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR,
871 ISCSI_LOGIN_STATUS_TGT_FORBIDDEN);
882 int iscsi_target_start_negotiation(
883 struct iscsi_login *login,
884 struct iscsi_conn *conn)
888 ret = iscsi_target_do_login(conn, login);
890 iscsi_remove_failed_auth_entry(conn);
892 iscsi_target_nego_release(conn);
896 void iscsi_target_nego_release(struct iscsi_conn *conn)
898 struct iscsi_login *login = conn->conn_login;
903 kfree(login->req_buf);
904 kfree(login->rsp_buf);
907 conn->conn_login = NULL;