* [MPTCP] [MPTCP][PATCH v10 mptcp-next 3/9] mptcp: add a new helper subflow_req_create_thmac
@ 2021-01-14 5:25 Geliang Tang
0 siblings, 0 replies; only message in thread
From: Geliang Tang @ 2021-01-14 5:25 UTC (permalink / raw)
To: mptcp
[-- Attachment #1: Type: text/plain, Size: 2143 bytes --]
This patch added a new helper named subflow_req_create_thmac, which split
from subflow_token_join_request. It initialized subflow_req's local_nonce
and thmac fields, those are the more expensive to populate.
Signed-off-by: Geliang Tang <geliangtang(a)gmail.com>
---
net/mptcp/subflow.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 700a87ee39f1..fee38bb9d80a 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -61,10 +61,23 @@ static bool mptcp_can_accept_new_subflow(const struct mptcp_sock *msk)
}
/* validate received token and create truncated hmac and nonce for SYN-ACK */
+static void subflow_req_create_thmac(struct mptcp_subflow_request_sock *subflow_req)
+{
+ struct mptcp_sock *msk = subflow_req->msk;
+ u8 hmac[SHA256_DIGEST_SIZE];
+
+ get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
+
+ subflow_generate_hmac(msk->local_key, msk->remote_key,
+ subflow_req->local_nonce,
+ subflow_req->remote_nonce, hmac);
+
+ subflow_req->thmac = get_unaligned_be64(hmac);
+}
+
static struct mptcp_sock *subflow_token_join_request(struct request_sock *req)
{
struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
- u8 hmac[SHA256_DIGEST_SIZE];
struct mptcp_sock *msk;
int local_id;
@@ -81,13 +94,6 @@ static struct mptcp_sock *subflow_token_join_request(struct request_sock *req)
}
subflow_req->local_id = local_id;
- get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
-
- subflow_generate_hmac(msk->local_key, msk->remote_key,
- subflow_req->local_nonce,
- subflow_req->remote_nonce, hmac);
-
- subflow_req->thmac = get_unaligned_be64(hmac);
return msk;
}
@@ -183,6 +189,8 @@ static int subflow_init_req(struct request_sock *req,
if (!subflow_req->msk)
return -EPERM;
+ subflow_req_create_thmac(subflow_req);
+
if (unlikely(req->syncookie)) {
if (mptcp_can_accept_new_subflow(subflow_req->msk))
subflow_init_req_cookie_join_save(subflow_req, skb);
--
2.29.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-14 5:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 5:25 [MPTCP] [MPTCP][PATCH v10 mptcp-next 3/9] mptcp: add a new helper subflow_req_create_thmac Geliang Tang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.