From 36325127b5fd6d2ddd17790621a36f5d15cb8e12 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 12 Dec 2018 09:27:06 +0900 Subject: [PATCH] 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: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/437055 Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ziye Yang Reviewed-by: Changpeng Liu --- lib/iscsi/iscsi.c | 85 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 34329c72b..0b1e6f4ce 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -1165,6 +1165,32 @@ spdk_iscsi_op_login_update_param(struct spdk_iscsi_conn *conn, return rc; } +static int +spdk_iscsi_negotiate_chap_param(struct spdk_iscsi_conn *conn, bool disable_chap, + bool require_chap, bool mutual_chap) +{ + int rc = 0; + + 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 (require_chap) { + conn->req_auth = 1; + rc = spdk_iscsi_op_login_update_param(conn, "AuthMethod", "CHAP", "CHAP"); + if (rc < 0) { + return rc; + } + } + if (mutual_chap) { + conn->req_mutual = 1; + } + + return rc; +} + /* * The function which is used to handle the part of session discovery * return: @@ -1174,26 +1200,9 @@ spdk_iscsi_op_login_update_param(struct spdk_iscsi_conn *conn, static int spdk_iscsi_op_login_session_discovery_chap(struct spdk_iscsi_conn *conn) { - int rc = 0; - - if (g_spdk_iscsi.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) { - 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) { - conn->req_mutual = 1; - } - - return rc; + return spdk_iscsi_negotiate_chap_param(conn, g_spdk_iscsi.disable_chap, + g_spdk_iscsi.require_chap, + g_spdk_iscsi.mutual_chap); } /* @@ -1204,29 +1213,19 @@ 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) +{ + return spdk_iscsi_negotiate_chap_param(conn, target->disable_chap, + target->require_chap, + target->mutual_chap); +} + +static int +spdk_iscsi_op_login_negotiate_digest_param(struct spdk_iscsi_conn *conn, 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; - } - } - - if (target->mutual_chap) { - conn->req_mutual = 1; - } - if (target->header_digest) { /* * User specified header digests, so update the list of @@ -1397,10 +1396,14 @@ 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)); - return rc; + if (rc != 0) { + return rc; + } + + return spdk_iscsi_op_login_negotiate_digest_param(conn, *target); } /*