From nobody Fri Apr 29 23:12:20 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 5ED4C1ABC264; Fri, 29 Apr 2022 23:12:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KqpD46NtZz3w7V; Fri, 29 Apr 2022 23:12:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651273941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YFRsZJK97a0aCsNa22Css6I3p9lttlNpFLJKqTijWfE=; b=vR4C4qmktB2yUzvWFu0PbS3YezzlJKs/KrDmEwAqg/Le6ixAQyJ3xMWv6IbjBUTHcjLVkO p7w7CBYNL65tcRsurA7B8QYqHpqWRqQZsbfKby8by8DnRIQB24hUHqA55V0xCc/N379C5L 3KfA0/PnzFQVWePedPvXH2Q6L3kSnQtHqAnNKrL81VQ2Wck62fvq7+PhDzKh0KNqtCvtl+ ubfhxztty1MEumPJ12FFAPGvCZyvLVBKcV9oCna2rNTkEFV/AtL7GckFXOnHWoeDuhPEIw dA0a0PH4U5oqQDlEJhv5OxjytHisAAYr25DExWrWrlyyxUJhsm3BmGxGPcWe3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8B13416119; Fri, 29 Apr 2022 23:12:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23TNCKKr044517; Fri, 29 Apr 2022 23:12:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23TNCKXD044516; Fri, 29 Apr 2022 23:12:20 GMT (envelope-from git) Date: Fri, 29 Apr 2022 23:12:20 GMT Message-Id: <202204292312.23TNCKXD044516@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 54262b09e5ba - stable/13 - libiscsiutil: Change keys_load/save to operate on data buffers. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 54262b09e5ba61f6370bf8977a694578b575c269 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651273941; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YFRsZJK97a0aCsNa22Css6I3p9lttlNpFLJKqTijWfE=; b=qHg5gDB4kBrIMUEoaXAazvlpw+5qJPiE0TprQg9HZQyR+HX13UWtmZcNB5HWRAXU8EVXLP hGrm/SPjgB07YdabzJSZRevwOvbGrjLC8O/aIm/u49AUQiehBypFeYlFJnkwYyohQdmJ2S PgDLBr5H16rxZIANDQFiGn5P1XUs8NdVd8aV+7ZEQms4U/dPVnqInvDw6JK2IQukKKQau8 7et9IYTZ6LifBPD4qWPcMoYofOqQoABvBbu2LrITUl9qMY+58TBKYny6xh+0qZ3mKFT4Rk sLEZ0SF/ndHO0b5UCJv75k/3/0ZUkKQg1BadQ/KX43H51PoqHxXqJfC1m53OTw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651273941; a=rsa-sha256; cv=none; b=dP6diXFgASgJfudOAqNAlzReg66oLnBgVMW4p2kfe7eGSc0n0s82qnks6UB3sDnrQ+ZRoE u2GPn2jfSYErh1Ym/5qDEIyUhC1wQt/bzi8Jk3dqx5wwA68ZH0r6QJjNUTuNF9hN50WoeB 6SDVAJhNwfvTWVGOSAf+5jVVZN8uh4lQu4dkBuURzMjcJ0v0nrHVvKKMx/62aj/mDk9MGd QxnQySKJquj0EvVx9mzySdy/K6V2hFfaqmLnhxy8u23B4+TGvXO68SiZibz9TN+FuAfbL5 pvQMDRtwC9qGdAt860QIHnklGcvtx1penEWogHXFpVPvisa1nlIm/PFT1atKaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=54262b09e5ba61f6370bf8977a694578b575c269 commit 54262b09e5ba61f6370bf8977a694578b575c269 Author: John Baldwin AuthorDate: 2021-12-22 18:42:29 +0000 Commit: John Baldwin CommitDate: 2022-04-29 21:15:45 +0000 libiscsiutil: Change keys_load/save to operate on data buffers. This will be used in future changes to support large text requests spanning multiple PDUs. Provide wrapper functions keys_load/save_pdu that operate use a PDU's data buffer. Reviewed by: mav Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D33547 (cherry picked from commit 25700db36640b1538ac91f893955a4f1a4167f63) --- lib/libiscsiutil/keys.c | 20 ++++++++++---------- lib/libiscsiutil/libiscsiutil.h | 18 ++++++++++++++++-- usr.sbin/ctld/discovery.c | 4 ++-- usr.sbin/ctld/login.c | 20 ++++++++++---------- usr.sbin/iscsid/discovery.c | 4 ++-- usr.sbin/iscsid/login.c | 18 +++++++++--------- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/lib/libiscsiutil/keys.c b/lib/libiscsiutil/keys.c index 9b165df87557..349be2a24f18 100644 --- a/lib/libiscsiutil/keys.c +++ b/lib/libiscsiutil/keys.c @@ -59,22 +59,22 @@ keys_delete(struct keys *keys) } void -keys_load(struct keys *keys, const struct pdu *pdu) +keys_load(struct keys *keys, const char *data, size_t len) { int i; char *keys_data, *name, *pair, *value; size_t pair_len; - if (pdu->pdu_data_len == 0) + if (len == 0) return; - if (pdu->pdu_data[pdu->pdu_data_len - 1] != '\0') + if (data[len - 1] != '\0') log_errx(1, "protocol error: key not NULL-terminated\n"); - keys_data = malloc(pdu->pdu_data_len); + keys_data = malloc(len); if (keys_data == NULL) log_err(1, "malloc"); - memcpy(keys_data, pdu->pdu_data, pdu->pdu_data_len); + memcpy(keys_data, data, len); /* * XXX: Review this carefully. @@ -96,15 +96,15 @@ keys_load(struct keys *keys, const struct pdu *pdu) keys->keys_names[i], keys->keys_values[i]); pair += pair_len + 1; /* +1 to skip the terminating '\0'. */ - if (pair == keys_data + pdu->pdu_data_len) + if (pair == keys_data + len) break; - assert(pair < keys_data + pdu->pdu_data_len); + assert(pair < keys_data + len); } free(keys_data); } void -keys_save(struct keys *keys, struct pdu *pdu) +keys_save(struct keys *keys, char **datap, size_t *lenp) { FILE *fp; char *data; @@ -131,8 +131,8 @@ keys_save(struct keys *keys, struct pdu *pdu) data = NULL; } - pdu->pdu_data = data; - pdu->pdu_data_len = len; + *datap = data; + *lenp = len; } const char * diff --git a/lib/libiscsiutil/libiscsiutil.h b/lib/libiscsiutil/libiscsiutil.h index 20979626aa3c..59682a7f6c74 100644 --- a/lib/libiscsiutil/libiscsiutil.h +++ b/lib/libiscsiutil/libiscsiutil.h @@ -109,14 +109,28 @@ void rchap_delete(struct rchap *rchap); struct keys *keys_new(void); void keys_delete(struct keys *key); -void keys_load(struct keys *keys, const struct pdu *pdu); -void keys_save(struct keys *keys, struct pdu *pdu); +void keys_load(struct keys *keys, const char *data, + size_t len); +void keys_save(struct keys *keys, char **datap, + size_t *lenp); const char *keys_find(struct keys *keys, const char *name); void keys_add(struct keys *keys, const char *name, const char *value); void keys_add_int(struct keys *keys, const char *name, int value); +static __inline void +keys_load_pdu(struct keys *keys, const struct pdu *pdu) +{ + keys_load(keys, pdu->pdu_data, pdu->pdu_data_len); +} + +static __inline void +keys_save_pdu(struct keys *keys, struct pdu *pdu) +{ + keys_save(keys, &pdu->pdu_data, &pdu->pdu_data_len); +} + struct pdu *pdu_new(struct connection *ic); struct pdu *pdu_new_response(struct pdu *request); int pdu_ahs_length(const struct pdu *pdu); diff --git a/usr.sbin/ctld/discovery.c b/usr.sbin/ctld/discovery.c index 242c5c7bca52..244b08a7f63c 100644 --- a/usr.sbin/ctld/discovery.c +++ b/usr.sbin/ctld/discovery.c @@ -287,7 +287,7 @@ discovery(struct ctld_connection *conn) log_debugx("beginning discovery session; waiting for Text PDU"); request = text_receive(&conn->conn); request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); send_targets = keys_find(request_keys, "SendTargets"); if (send_targets == NULL) @@ -317,7 +317,7 @@ discovery(struct ctld_connection *conn) } } } - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); pdu_send(response); pdu_delete(response); diff --git a/usr.sbin/ctld/login.c b/usr.sbin/ctld/login.c index da69961e40ae..19fab3bc494c 100644 --- a/usr.sbin/ctld/login.c +++ b/usr.sbin/ctld/login.c @@ -236,7 +236,7 @@ login_receive_chap_a(struct connection *conn) request = login_receive(conn, false); request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); chap_a = keys_find(request_keys, "CHAP_A"); if (chap_a == NULL) { @@ -270,7 +270,7 @@ login_send_chap_c(struct pdu *request, struct chap *chap) keys_add(response_keys, "CHAP_C", chap_c); free(chap_i); free(chap_c); - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); pdu_send(response); pdu_delete(response); keys_delete(response_keys); @@ -288,7 +288,7 @@ login_receive_chap_r(struct connection *conn, struct auth_group *ag, request = login_receive(conn, false); request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); chap_n = keys_find(request_keys, "CHAP_N"); if (chap_n == NULL) { @@ -352,7 +352,7 @@ login_send_chap_success(struct pdu *request, * Actually, one more thing: mutual authentication. */ request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); chap_i = keys_find(request_keys, "CHAP_I"); chap_c = keys_find(request_keys, "CHAP_C"); if (chap_i != NULL || chap_c != NULL) { @@ -389,7 +389,7 @@ login_send_chap_success(struct pdu *request, keys_add(response_keys, "CHAP_N", auth->a_mutual_user); keys_add(response_keys, "CHAP_R", chap_r); free(chap_r); - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); keys_delete(response_keys); } else { log_debugx("initiator did not request target authentication"); @@ -635,7 +635,7 @@ login_redirect(struct pdu *request, const char *target_address) response_keys = keys_new(); keys_add(response_keys, "TargetAddress", target_address); - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); pdu_send(response); pdu_delete(response); keys_delete(response_keys); @@ -753,7 +753,7 @@ login_negotiate(struct ctld_connection *conn, struct pdu *request) } request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); response = login_new_response(request); bhslr2 = (struct iscsi_bhs_login_response *)response->pdu_bhs; @@ -801,7 +801,7 @@ login_negotiate(struct ctld_connection *conn, struct pdu *request) log_debugx("operational parameter negotiation done; " "transitioning to Full Feature Phase"); - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); pdu_send(response); pdu_delete(response); keys_delete(response_keys); @@ -867,7 +867,7 @@ login(struct ctld_connection *conn) * XXX: Implement the C flag some day. */ request_keys = keys_new(); - keys_load(request_keys, request); + keys_load_pdu(request_keys, request); assert(conn->conn_initiator_name == NULL); initiator_name = keys_find(request_keys, "InitiatorName"); @@ -1036,7 +1036,7 @@ login(struct ctld_connection *conn) keys_add_int(response_keys, "TargetPortalGroupTag", pg->pg_tag); } - keys_save(response_keys, response); + keys_save_pdu(response_keys, response); pdu_send(response); pdu_delete(response); diff --git a/usr.sbin/iscsid/discovery.c b/usr.sbin/iscsid/discovery.c index c60c77307a55..60aff28c1b03 100644 --- a/usr.sbin/iscsid/discovery.c +++ b/usr.sbin/iscsid/discovery.c @@ -177,7 +177,7 @@ discovery(struct iscsid_connection *conn) request = text_new_request(&conn->conn); request_keys = keys_new(); keys_add(request_keys, "SendTargets", "All"); - keys_save(request_keys, request); + keys_save_pdu(request_keys, request); keys_delete(request_keys); request_keys = NULL; pdu_send(request); @@ -187,7 +187,7 @@ discovery(struct iscsid_connection *conn) log_debugx("waiting for Text Response"); response = text_receive(&conn->conn); response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); for (i = 0; i < KEYS_MAX; i++) { if (response_keys->keys_names[i] == NULL) break; diff --git a/usr.sbin/iscsid/login.c b/usr.sbin/iscsid/login.c index 11a22dfcfaf1..264bcb48104b 100644 --- a/usr.sbin/iscsid/login.c +++ b/usr.sbin/iscsid/login.c @@ -198,7 +198,7 @@ login_handle_redirection(struct iscsid_connection *conn, struct pdu *response) assert (bhslr->bhslr_status_class == 1); response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); target_address = keys_find(response_keys, "TargetAddress"); if (target_address == NULL) @@ -543,7 +543,7 @@ login_negotiate(struct iscsid_connection *conn) keys_add(request_keys, "DefaultTime2Wait", "0"); keys_add(request_keys, "DefaultTime2Retain", "0"); keys_add(request_keys, "ErrorRecoveryLevel", "0"); - keys_save(request_keys, request); + keys_save_pdu(request_keys, request); keys_delete(request_keys); request_keys = NULL; pdu_send(request); @@ -552,7 +552,7 @@ login_negotiate(struct iscsid_connection *conn) response = login_receive(&conn->conn); response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); for (i = 0; i < KEYS_MAX; i++) { if (response_keys->keys_names[i] == NULL) break; @@ -607,7 +607,7 @@ login_send_chap_a(struct connection *conn) request = login_new_request(conn, BHSLR_STAGE_SECURITY_NEGOTIATION); request_keys = keys_new(); keys_add(request_keys, "CHAP_A", "5"); - keys_save(request_keys, request); + keys_save_pdu(request_keys, request); keys_delete(request_keys); pdu_send(request); pdu_delete(request); @@ -636,7 +636,7 @@ login_send_chap_r(struct pdu *response) conn = (struct iscsid_connection *)response->pdu_connection; response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); /* * First, compute the response. @@ -693,7 +693,7 @@ login_send_chap_r(struct pdu *response) free(mutual_chap_c); } - keys_save(request_keys, request); + keys_save_pdu(request_keys, request); keys_delete(request_keys); pdu_send(request); pdu_delete(request); @@ -710,7 +710,7 @@ login_verify_mutual(const struct pdu *response) conn = (struct iscsid_connection *)response->pdu_connection; response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); chap_n = keys_find(response_keys, "CHAP_N"); if (chap_n == NULL) @@ -816,7 +816,7 @@ login(struct iscsid_connection *conn) } else { keys_add(request_keys, "SessionType", "Discovery"); } - keys_save(request_keys, request); + keys_save_pdu(request_keys, request); keys_delete(request_keys); pdu_send(request); pdu_delete(request); @@ -824,7 +824,7 @@ login(struct iscsid_connection *conn) response = login_receive(&conn->conn); response_keys = keys_new(); - keys_load(response_keys, response); + keys_load_pdu(response_keys, response); for (i = 0; i < KEYS_MAX; i++) { if (response_keys->keys_names[i] == NULL)