Commit 36325127 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Changpeng Liu
Browse files

iscsi: Factor out negotiation of CHAP params from discovery and normal session



Factor out negotiation of CHAP params from discovery session and
normal session. Additionally separate negotiation of digest params
from CHAP params.

Change-Id: If3419262c88b95de5c7c1ec7057bcbaa67e9df62
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/437055


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent af017d1f
Loading
Loading
Loading
Loading
+34 −31
Original line number Diff line number Diff line
@@ -1165,37 +1165,46 @@ spdk_iscsi_op_login_update_param(struct spdk_iscsi_conn *conn,
	return rc;
}

/*
 * The function which is used to handle the part of session discovery
 * return:
 * 0, success;
 * otherwise: error;
 */
static int
spdk_iscsi_op_login_session_discovery_chap(struct spdk_iscsi_conn *conn)
spdk_iscsi_negotiate_chap_param(struct spdk_iscsi_conn *conn, bool disable_chap,
				bool require_chap, bool mutual_chap)
{
	int rc = 0;

	if (g_spdk_iscsi.disable_chap) {
	if (disable_chap) {
		conn->req_auth = 0;
		rc = spdk_iscsi_op_login_update_param(conn, "AuthMethod", "None", "None");
		if (rc < 0) {
			return rc;
		}
	} else if (g_spdk_iscsi.require_chap) {
	} else if (require_chap) {
		conn->req_auth = 1;
		rc = spdk_iscsi_op_login_update_param(conn, "AuthMethod", "CHAP", "CHAP");
		if (rc < 0) {
			return rc;
		}
	}
	if (g_spdk_iscsi.mutual_chap) {
	if (mutual_chap) {
		conn->req_mutual = 1;
	}

	return rc;
}

/*
 * The function which is used to handle the part of session discovery
 * return:
 * 0, success;
 * otherwise: error;
 */
static int
spdk_iscsi_op_login_session_discovery_chap(struct spdk_iscsi_conn *conn)
{
	return spdk_iscsi_negotiate_chap_param(conn, g_spdk_iscsi.disable_chap,
					       g_spdk_iscsi.require_chap,
					       g_spdk_iscsi.mutual_chap);
}

/*
 * This function is used to update the param related with chap
 * return:
@@ -1204,28 +1213,18 @@ spdk_iscsi_op_login_session_discovery_chap(struct spdk_iscsi_conn *conn)
 */
static int
spdk_iscsi_op_login_negotiate_chap_param(struct spdk_iscsi_conn *conn,
		struct spdk_iscsi_pdu *rsp_pdu,
		struct spdk_iscsi_tgt_node *target)
{
	int rc;

	if (target->disable_chap) {
		conn->req_auth = 0;
		rc = spdk_iscsi_op_login_update_param(conn, "AuthMethod", "None", "None");
		if (rc < 0) {
			return rc;
		}
	} else if (target->require_chap) {
		conn->req_auth = 1;
		rc = spdk_iscsi_op_login_update_param(conn, "AuthMethod", "CHAP", "CHAP");
		if (rc < 0) {
			return rc;
		}
	return spdk_iscsi_negotiate_chap_param(conn, target->disable_chap,
					       target->require_chap,
					       target->mutual_chap);
}

	if (target->mutual_chap) {
		conn->req_mutual = 1;
	}
static int
spdk_iscsi_op_login_negotiate_digest_param(struct spdk_iscsi_conn *conn,
		struct spdk_iscsi_tgt_node *target)
{
	int rc;

	if (target->header_digest) {
		/*
@@ -1397,12 +1396,16 @@ spdk_iscsi_op_login_session_normal(struct spdk_iscsi_conn *conn,

	/* force target flags */
	pthread_mutex_lock(&((*target)->mutex));
	rc = spdk_iscsi_op_login_negotiate_chap_param(conn, rsp_pdu, *target);
	rc = spdk_iscsi_op_login_negotiate_chap_param(conn, *target);
	pthread_mutex_unlock(&((*target)->mutex));

	if (rc != 0) {
		return rc;
	}

	return spdk_iscsi_op_login_negotiate_digest_param(conn, *target);
}

/*
 * This function is used to judge the session type
 * return