Skip to content

Commit 535fb81

Browse files
Florian Westphaldavem330
authored andcommitted
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: Florian Westphal <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f8ace8d commit 535fb81

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

net/mptcp/subflow.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,18 @@ static void subflow_init_req(struct request_sock *req,
126126
}
127127

128128
if (mp_opt.mp_capable && listener->request_mptcp) {
129-
int err;
129+
int err, retries = 4;
130+
131+
again:
132+
do {
133+
get_random_bytes(&subflow_req->local_key, sizeof(subflow_req->local_key));
134+
} while (subflow_req->local_key == 0);
130135

131136
err = mptcp_token_new_request(req);
132137
if (err == 0)
133138
subflow_req->mp_capable = 1;
139+
else if (retries-- > 0)
140+
goto again;
134141

135142
subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
136143
} else if (mp_opt.mp_join && listener->request_mptcp) {

net/mptcp/token.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ static void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
109109
int mptcp_token_new_request(struct request_sock *req)
110110
{
111111
struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
112-
int retries = TOKEN_MAX_RETRIES;
113112
struct token_bucket *bucket;
114113
u32 token;
115114

116-
again:
117-
mptcp_crypto_key_gen_sha(&subflow_req->local_key,
118-
&subflow_req->token,
119-
&subflow_req->idsn);
115+
mptcp_crypto_key_sha(subflow_req->local_key,
116+
&subflow_req->token,
117+
&subflow_req->idsn);
120118
pr_debug("req=%p local_key=%llu, token=%u, idsn=%llu\n",
121119
req, subflow_req->local_key, subflow_req->token,
122120
subflow_req->idsn);
@@ -126,9 +124,7 @@ int mptcp_token_new_request(struct request_sock *req)
126124
spin_lock_bh(&bucket->lock);
127125
if (__token_bucket_busy(bucket, token)) {
128126
spin_unlock_bh(&bucket->lock);
129-
if (!--retries)
130-
return -EBUSY;
131-
goto again;
127+
return -EBUSY;
132128
}
133129

134130
hlist_nulls_add_head_rcu(&subflow_req->token_node, &bucket->req_chain);

0 commit comments

Comments
 (0)