Blob Blame History Raw
From 7fa69ab8152392b11490950ff8aeeef7e0ad14de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Tue, 13 Mar 2018 23:13:35 +0100
Subject: [PATCH 10/15] KCM: Introduce kcm_input_get_payload_len()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As this piece of code will be useful for us in the future patches of
this series, let's move it to a new function.

Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
 src/responder/kcm/kcmsrv_cmd.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/responder/kcm/kcmsrv_cmd.c b/src/responder/kcm/kcmsrv_cmd.c
index d4ebb79bf..3ecba9df2 100644
--- a/src/responder/kcm/kcmsrv_cmd.c
+++ b/src/responder/kcm/kcmsrv_cmd.c
@@ -129,23 +129,27 @@ struct kcm_reqbuf {
     struct kcm_iovec v_msg;
 };
 
+static uint32_t kcm_input_get_payload_len(struct kcm_iovec *v)
+{
+    size_t lc = 0;
+    uint32_t len_be = 0;
+
+    /* The first 4 bytes before the payload is message length */
+    SAFEALIGN_COPY_UINT32_CHECK(&len_be, v->kiov_base, v->kiov_len, &lc);
+
+    return be32toh(len_be);
+}
+
 static errno_t kcm_input_parse(struct kcm_reqbuf *reqbuf,
                                struct kcm_op_io *op_io)
 {
-    size_t lc = 0;
     size_t mc = 0;
     uint16_t opcode_be = 0;
-    uint32_t len_be = 0;
     uint32_t msglen;
     uint8_t proto_maj = 0;
     uint8_t proto_min = 0;
 
-    /* The first 4 bytes before the payload is message length */
-    SAFEALIGN_COPY_UINT32_CHECK(&len_be,
-                                reqbuf->v_len.kiov_base,
-                                reqbuf->v_len.kiov_len,
-                                &lc);
-    msglen = be32toh(len_be);
+    msglen = kcm_input_get_payload_len(&reqbuf->v_len);
     DEBUG(SSSDBG_TRACE_LIBS,
           "Received message with length %"PRIu32"\n", msglen);
 
-- 
2.14.3