21 #include <linux/string.h>
42 static int iscsi_login_init_conn(
struct iscsi_conn *conn)
64 pr_err(
"Unable to allocate conn->conn_cpumask\n");
86 pr_err(
"crypto_alloc_hash() failed for conn_rx_tfm\n");
94 pr_err(
"crypto_alloc_hash() failed for conn_tx_tfm\n");
102 static int iscsi_login_check_initiator_version(
107 if ((version_max != 0x00) || (version_min != 0x00)) {
108 pr_err(
"Unsupported iSCSI IETF Pre-RFC Revision,"
109 " version Min/Max 0x%02x/0x%02x, rejecting login.\n",
110 version_min, version_max);
130 if (!initiatorname_param)
135 if (!sessiontype_param)
138 sessiontype = (
strncmp(sessiontype_param->value,
NORMAL, 6)) ? 1 : 0;
145 spin_lock(&sess_p->conn_lock);
146 if (
atomic_read(&sess_p->session_fall_back_to_erl0) ||
149 spin_unlock(&sess_p->conn_lock);
152 if (!
memcmp(sess_p->isid, conn->
sess->isid, 6) &&
153 (!
strcmp(sess_p->sess_ops->InitiatorName,
154 initiatorname_param->
value) &&
155 (sess_p->sess_ops->SessionType == sessiontype))) {
156 atomic_set(&sess_p->session_reinstatement, 1);
157 spin_unlock(&sess_p->conn_lock);
163 spin_unlock(&sess_p->conn_lock);
172 pr_debug(
"%s iSCSI Session SID %u is still active for %s,"
173 " preforming session reinstatement.\n", (sessiontype) ?
174 "Discovery" :
"Normal", sess->
sid,
193 static void iscsi_login_set_conn_values(
215 static int iscsi_login_zero_tsih_s1(
227 pr_err(
"Could not allocate memory for session\n");
231 iscsi_login_set_conn_values(sess, conn, pdu->
cid);
251 pr_err(
"idr_pre_get() for sess_idr failed\n");
262 pr_err(
"idr_get_new() for sess_idr failed\n");
281 pr_err(
"Unable to allocate memory for"
282 " struct iscsi_sess_ops.\n");
298 static int iscsi_login_zero_tsih_s2(
303 unsigned char buf[32];
379 pr_err(
"iscsi_find_param_from_key() for"
380 " OFMarker failed\n");
389 pr_err(
"iscsi_find_param_from_key() for"
390 " IFMarker failed\n");
399 pr_err(
"iscsi_find_param_from_key() for"
400 " IFMarker failed\n");
409 pr_err(
"iscsi_find_param_from_key() for"
410 " IFMarker failed\n");
420 static int iscsi_login_non_zero_tsih_s1(
426 iscsi_login_set_conn_values(
NULL, conn, pdu->
cid);
433 static int iscsi_login_non_zero_tsih_s2(
466 pr_err(
"Initiator attempting to add a connection to"
467 " a non-existent session, rejecting iSCSI Login.\n");
482 iscsi_login_set_conn_values(sess, conn, pdu->
cid);
528 pr_err(
"Connection exists with CID %hu for %s,"
529 " performing connection reinstatement.\n",
545 if (sess->
sess_ops->ErrorRecoveryLevel == 2) {
549 pr_debug(
"Performing implicit logout"
550 " for connection recovery on CID: %hu\n",
562 pr_debug(
"Adding CID %hu to existing session for %s.\n",
563 cid, sess->
sess_ops->InitiatorName);
566 pr_err(
"Adding additional connection to this session"
567 " would exceed MaxConnections %d, login failed.\n",
577 static void iscsi_post_login_start_timers(
struct iscsi_conn *conn)
585 static int iscsi_post_login_handler(
602 pr_debug(
"Moving to TARG_CONN_STATE_LOGGED_IN.\n");
621 " TARG_SESS_STATE_LOGGED_IN.\n");
626 pr_debug(
"iSCSI Login successful on CID: %hu from %s to"
632 pr_debug(
"Incremented iSCSI Connection count to %hu"
637 iscsi_post_login_start_timers(conn);
666 pr_debug(
"Moving to TARG_SESS_STATE_LOGGED_IN.\n");
669 pr_debug(
"iSCSI Login successful on CID: %hu from %s to %s:%hu,%hu\n",
676 pr_debug(
"Incremented iSCSI Connection count to %hu from node:"
684 pr_debug(
"Established iSCSI session from node: %s\n",
691 pr_debug(
"Incremented number of active iSCSI sessions to %u on"
692 " iSCSI Target Portal Group: %hu\n", tpg->
nsessions, tpg->
tpgt);
695 iscsi_post_login_start_timers(conn);
710 static void iscsi_handle_login_thread_timeout(
unsigned long data)
715 pr_err(
"iSCSI Login timeout on Network Portal %s:%hu\n",
730 static void iscsi_start_login_thread_timer(
struct iscsi_np *np)
745 pr_debug(
"Added timeout timer to iSCSI login request for"
750 static void iscsi_stop_login_thread_timer(
struct iscsi_np *np)
791 pr_err(
"Unsupported network_transport: %d\n",
799 pr_err(
"sock_create() failed.\n");
821 (
char *)&opt,
sizeof(opt));
823 pr_err(
"kernel_setsockopt() for TCP_NODELAY"
824 " failed: %d\n", ret);
831 (
char *)&opt,
sizeof(opt));
833 pr_err(
"kernel_setsockopt() for SO_REUSEADDR"
839 (
char *)&opt,
sizeof(opt));
841 pr_err(
"kernel_setsockopt() for IP_FREEBIND"
848 pr_err(
"kernel_bind() failed: %d\n", ret);
854 pr_err(
"kernel_listen() failed: %d\n", ret);
867 static int __iscsi_target_login_thread(
struct iscsi_np *np)
903 iscsi_start_login_thread_timer(np);
907 pr_err(
"Could not allocate memory for"
908 " new connection\n");
914 pr_debug(
"Moving to TARG_CONN_STATE_FREE.\n");
916 conn->
sock = new_sock;
918 pr_debug(
"Moving to TARG_CONN_STATE_XPT_UP.\n");
927 pr_err(
"Unable to allocate memory for"
928 " struct iscsi_conn_ops.\n");
934 if (iscsi_login_init_conn(conn) < 0)
943 pr_err(
"rx_data() returned an error.\n");
949 pr_err(
"First opcode is not login request,"
950 " failing login request.\n");
965 pr_err(
"iSCSI Network Portal on %s:%hu currently not"
976 if (conn->
sock->ops->getname(conn->
sock,
977 (
struct sockaddr *)&sock_in6, &err, 1) < 0) {
978 pr_err(
"sock_ops->getname() failed.\n");
984 &sock_in6.sin6_addr.in6_u);
987 if (conn->
sock->ops->getname(conn->
sock,
988 (
struct sockaddr *)&sock_in6, &err, 0) < 0) {
989 pr_err(
"sock_ops->getname() failed.\n");
995 &sock_in6.sin6_addr.in6_u);
1001 if (conn->
sock->ops->getname(conn->
sock,
1002 (
struct sockaddr *)&sock_in, &err, 1) < 0) {
1003 pr_err(
"sock_ops->getname() failed.\n");
1011 if (conn->
sock->ops->getname(conn->
sock,
1012 (
struct sockaddr *)&sock_in, &err, 0) < 0) {
1013 pr_err(
"sock_ops->getname() failed.\n");
1024 pr_debug(
"Received iSCSI login request from %s on %s Network"
1025 " Portal %s:%hu\n", conn->
login_ip,
1029 pr_debug(
"Moving to TARG_CONN_STATE_IN_LOGIN.\n");
1032 if (iscsi_login_check_initiator_version(conn, pdu->
max_version,
1036 zero_tsih = (pdu->
tsih == 0x0000);
1043 if (iscsi_login_zero_tsih_s1(conn, buffer) < 0)
1053 if (iscsi_login_non_zero_tsih_s1(conn, buffer) < 0)
1069 pr_err(
"Unable to locate struct iscsi_conn->tpg\n");
1074 if (iscsi_login_zero_tsih_s2(conn) < 0) {
1079 if (iscsi_login_non_zero_tsih_s2(conn, buffer) < 0) {
1089 pr_err(
"struct iscsi_conn session pointer is NULL!\n");
1093 iscsi_stop_login_thread_timer(np);
1098 ret = iscsi_post_login_handler(np, conn, zero_tsih);
1109 pr_err(
"iSCSI Login negotiation failed.\n");
1112 if (!zero_tsih || !conn->
sess)
1114 if (conn->
sess->se_sess)
1116 if (conn->
sess->session_index != 0) {
1121 if (conn->
sess->sess_ops)
1126 iscsi_stop_login_thread_timer(np);
1131 if (!zero_tsih && conn->
sess) {
1132 spin_lock_bh(&conn->
sess->conn_lock);
1138 spin_unlock_bh(&conn->
sess->conn_lock);
1143 spin_unlock_bh(&conn->
sess->conn_lock);
1181 iscsi_stop_login_thread_timer(np);
1196 ret = __iscsi_target_login_thread(np);