Skip to content

Commit 8fd4de1

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: cache msk on MP_JOIN init_req
The msk ownership is transferred to the child socket at 3rd ack time, so that we avoid more lookups later. If the request does not reach the 3rd ack, the MSK reference is dropped at request sock release time. As a side effect, fallback is now tracked by a NULL msk reference instead of zeroed 'mp_join' field. This will simplify the next patch. Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5eea3a6 commit 8fd4de1

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

net/mptcp/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct mptcp_subflow_request_sock {
249249
u64 thmac;
250250
u32 local_nonce;
251251
u32 remote_nonce;
252+
struct mptcp_sock *msk;
252253
};
253254

254255
static inline struct mptcp_subflow_request_sock *

net/mptcp/subflow.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ static void subflow_req_destructor(struct request_sock *req)
6969

7070
pr_debug("subflow_req=%p", subflow_req);
7171

72+
if (subflow_req->msk)
73+
sock_put((struct sock *)subflow_req->msk);
74+
7275
if (subflow_req->mp_capable)
7376
mptcp_token_destroy_request(subflow_req->token);
7477
tcp_request_sock_ops.destructor(req);
@@ -86,8 +89,8 @@ static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
8689
}
8790

8891
/* validate received token and create truncated hmac and nonce for SYN-ACK */
89-
static bool subflow_token_join_request(struct request_sock *req,
90-
const struct sk_buff *skb)
92+
static struct mptcp_sock *subflow_token_join_request(struct request_sock *req,
93+
const struct sk_buff *skb)
9194
{
9295
struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
9396
u8 hmac[SHA256_DIGEST_SIZE];
@@ -97,13 +100,13 @@ static bool subflow_token_join_request(struct request_sock *req,
97100
msk = mptcp_token_get_sock(subflow_req->token);
98101
if (!msk) {
99102
SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINNOTOKEN);
100-
return false;
103+
return NULL;
101104
}
102105

103106
local_id = mptcp_pm_get_local_id(msk, (struct sock_common *)req);
104107
if (local_id < 0) {
105108
sock_put((struct sock *)msk);
106-
return false;
109+
return NULL;
107110
}
108111
subflow_req->local_id = local_id;
109112

@@ -114,9 +117,7 @@ static bool subflow_token_join_request(struct request_sock *req,
114117
subflow_req->remote_nonce, hmac);
115118

116119
subflow_req->thmac = get_unaligned_be64(hmac);
117-
118-
sock_put((struct sock *)msk);
119-
return true;
120+
return msk;
120121
}
121122

122123
static void subflow_init_req(struct request_sock *req,
@@ -133,6 +134,7 @@ static void subflow_init_req(struct request_sock *req,
133134

134135
subflow_req->mp_capable = 0;
135136
subflow_req->mp_join = 0;
137+
subflow_req->msk = NULL;
136138

137139
#ifdef CONFIG_TCP_MD5SIG
138140
/* no MPTCP if MD5SIG is enabled on this socket or we may run out of
@@ -166,12 +168,9 @@ static void subflow_init_req(struct request_sock *req,
166168
subflow_req->remote_id = mp_opt.join_id;
167169
subflow_req->token = mp_opt.token;
168170
subflow_req->remote_nonce = mp_opt.nonce;
169-
pr_debug("token=%u, remote_nonce=%u", subflow_req->token,
170-
subflow_req->remote_nonce);
171-
if (!subflow_token_join_request(req, skb)) {
172-
subflow_req->mp_join = 0;
173-
// @@ need to trigger RST
174-
}
171+
subflow_req->msk = subflow_token_join_request(req, skb);
172+
pr_debug("token=%u, remote_nonce=%u msk=%p", subflow_req->token,
173+
subflow_req->remote_nonce, subflow_req->msk);
175174
}
176175
}
177176

@@ -354,23 +353,17 @@ static bool subflow_hmac_valid(const struct request_sock *req,
354353
const struct mptcp_subflow_request_sock *subflow_req;
355354
u8 hmac[SHA256_DIGEST_SIZE];
356355
struct mptcp_sock *msk;
357-
bool ret;
358356

359357
subflow_req = mptcp_subflow_rsk(req);
360-
msk = mptcp_token_get_sock(subflow_req->token);
358+
msk = subflow_req->msk;
361359
if (!msk)
362360
return false;
363361

364362
subflow_generate_hmac(msk->remote_key, msk->local_key,
365363
subflow_req->remote_nonce,
366364
subflow_req->local_nonce, hmac);
367365

368-
ret = true;
369-
if (crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN))
370-
ret = false;
371-
372-
sock_put((struct sock *)msk);
373-
return ret;
366+
return !crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN);
374367
}
375368

376369
static void mptcp_sock_destruct(struct sock *sk)
@@ -522,10 +515,12 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
522515
} else if (ctx->mp_join) {
523516
struct mptcp_sock *owner;
524517

525-
owner = mptcp_token_get_sock(ctx->token);
518+
owner = subflow_req->msk;
526519
if (!owner)
527520
goto dispose_child;
528521

522+
/* move the msk reference ownership to the subflow */
523+
subflow_req->msk = NULL;
529524
ctx->conn = (struct sock *)owner;
530525
if (!mptcp_finish_join(child))
531526
goto dispose_child;

0 commit comments

Comments
 (0)