Skip to content

Commit 6fc8c82

Browse files
Florian Westphaldavem330
authored andcommitted
tcp: syncookies: create mptcp request socket for ACK cookies with MPTCP option
If SYN packet contains MP_CAPABLE option, keep it enabled. Syncokie validation and cookie-based socket creation is changed to instantiate an mptcp request sockets if the ACK contains an MPTCP connection request. Rather than extend both cookie_v4/6_check, add a common helper to create the (mp)tcp request socket. Suggested-by: Paolo Abeni <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c83a47e commit 6fc8c82

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

include/net/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,
469469
int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,
470470
u32 cookie);
471471
struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb);
472+
struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,
473+
struct sock *sk, struct sk_buff *skb);
472474
#ifdef CONFIG_SYN_COOKIES
473475

474476
/* Syncookies use a monotonic timer which increments every 60 seconds.

net/ipv4/syncookies.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,39 @@ bool cookie_ecn_ok(const struct tcp_options_received *tcp_opt,
276276
}
277277
EXPORT_SYMBOL(cookie_ecn_ok);
278278

279+
struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,
280+
struct sock *sk,
281+
struct sk_buff *skb)
282+
{
283+
struct tcp_request_sock *treq;
284+
struct request_sock *req;
285+
286+
#ifdef CONFIG_MPTCP
287+
if (sk_is_mptcp(sk))
288+
ops = &mptcp_subflow_request_sock_ops;
289+
#endif
290+
291+
req = inet_reqsk_alloc(ops, sk, false);
292+
if (!req)
293+
return NULL;
294+
295+
#if IS_ENABLED(CONFIG_MPTCP)
296+
treq = tcp_rsk(req);
297+
treq->is_mptcp = sk_is_mptcp(sk);
298+
if (treq->is_mptcp) {
299+
int err = mptcp_subflow_init_cookie_req(req, sk, skb);
300+
301+
if (err) {
302+
reqsk_free(req);
303+
return NULL;
304+
}
305+
}
306+
#endif
307+
308+
return req;
309+
}
310+
EXPORT_SYMBOL_GPL(cookie_tcp_reqsk_alloc);
311+
279312
/* On input, sk is a listener.
280313
* Output is listener if incoming packet would not create a child
281314
* NULL if memory could not be allocated.
@@ -326,7 +359,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
326359
goto out;
327360

328361
ret = NULL;
329-
req = inet_reqsk_alloc(&tcp_request_sock_ops, sk, false); /* for safety */
362+
req = cookie_tcp_reqsk_alloc(&tcp_request_sock_ops, sk, skb);
330363
if (!req)
331364
goto out;
332365

@@ -350,9 +383,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
350383
treq->snt_synack = 0;
351384
treq->tfo_listener = false;
352385

353-
if (IS_ENABLED(CONFIG_MPTCP))
354-
treq->is_mptcp = 0;
355-
356386
if (IS_ENABLED(CONFIG_SMC))
357387
ireq->smc_ok = 0;
358388

net/ipv4/tcp_input.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6701,9 +6701,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
67016701

67026702
af_ops->init_req(req, sk, skb);
67036703

6704-
if (IS_ENABLED(CONFIG_MPTCP) && want_cookie)
6705-
tcp_rsk(req)->is_mptcp = 0;
6706-
67076704
if (security_inet_conn_request(sk, skb, req))
67086705
goto drop_and_free;
67096706

net/ipv6/syncookies.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,14 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
170170
goto out;
171171

172172
ret = NULL;
173-
req = inet_reqsk_alloc(&tcp6_request_sock_ops, sk, false);
173+
req = cookie_tcp_reqsk_alloc(&tcp6_request_sock_ops, sk, skb);
174174
if (!req)
175175
goto out;
176176

177177
ireq = inet_rsk(req);
178178
treq = tcp_rsk(req);
179179
treq->tfo_listener = false;
180180

181-
if (IS_ENABLED(CONFIG_MPTCP))
182-
treq->is_mptcp = 0;
183-
184181
if (security_inet_conn_request(sk, skb, req))
185182
goto out_free;
186183

0 commit comments

Comments
 (0)