Commit 535fb815 authored by Florian Westphal's avatar Florian Westphal Committed by David S. Miller

mptcp: token: move retry to caller

Once syncookie support is added, no state will be stored anymore when the
syn/ack is generated in syncookie mode.

When the ACK comes back, the generated key will be taken from the TCP ACK,
the token is re-generated and inserted into the token tree.

This means we can't retry with a new key when the token is already taken
in the syncookie case.

Therefore, move the retry logic to the caller to prepare for syncookie
support in mptcp.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Reviewed-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f8ace8d9
...@@ -126,11 +126,18 @@ static void subflow_init_req(struct request_sock *req, ...@@ -126,11 +126,18 @@ static void subflow_init_req(struct request_sock *req,
} }
if (mp_opt.mp_capable && listener->request_mptcp) { if (mp_opt.mp_capable && listener->request_mptcp) {
int err; int err, retries = 4;
again:
do {
get_random_bytes(&subflow_req->local_key, sizeof(subflow_req->local_key));
} while (subflow_req->local_key == 0);
err = mptcp_token_new_request(req); err = mptcp_token_new_request(req);
if (err == 0) if (err == 0)
subflow_req->mp_capable = 1; subflow_req->mp_capable = 1;
else if (retries-- > 0)
goto again;
subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq; subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
} else if (mp_opt.mp_join && listener->request_mptcp) { } else if (mp_opt.mp_join && listener->request_mptcp) {
......
...@@ -109,14 +109,12 @@ static void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn) ...@@ -109,14 +109,12 @@ static void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
int mptcp_token_new_request(struct request_sock *req) int mptcp_token_new_request(struct request_sock *req)
{ {
struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
int retries = TOKEN_MAX_RETRIES;
struct token_bucket *bucket; struct token_bucket *bucket;
u32 token; u32 token;
again: mptcp_crypto_key_sha(subflow_req->local_key,
mptcp_crypto_key_gen_sha(&subflow_req->local_key, &subflow_req->token,
&subflow_req->token, &subflow_req->idsn);
&subflow_req->idsn);
pr_debug("req=%p local_key=%llu, token=%u, idsn=%llu\n", pr_debug("req=%p local_key=%llu, token=%u, idsn=%llu\n",
req, subflow_req->local_key, subflow_req->token, req, subflow_req->local_key, subflow_req->token,
subflow_req->idsn); subflow_req->idsn);
...@@ -126,9 +124,7 @@ int mptcp_token_new_request(struct request_sock *req) ...@@ -126,9 +124,7 @@ int mptcp_token_new_request(struct request_sock *req)
spin_lock_bh(&bucket->lock); spin_lock_bh(&bucket->lock);
if (__token_bucket_busy(bucket, token)) { if (__token_bucket_busy(bucket, token)) {
spin_unlock_bh(&bucket->lock); spin_unlock_bh(&bucket->lock);
if (!--retries) return -EBUSY;
return -EBUSY;
goto again;
} }
hlist_nulls_add_head_rcu(&subflow_req->token_node, &bucket->req_chain); hlist_nulls_add_head_rcu(&subflow_req->token_node, &bucket->req_chain);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment