History

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.

Florian Westphal committed 6 years ago

Commit 6fc8c821 parent c83a47e4 files · +37 −11Browse files

Unified · Split

4 files
  1. include/net/tcp.h +2 −0
  2. net/ipv4/syncookies.c +34 −4
  3. net/ipv4/tcp_input.c +0 −3
  4. net/ipv6/syncookies.c +1 −4
include/net/tcp.h+2−0
@@ -469,6 +469,8 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, · 468 unmodified lines
469int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,469int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,
470 u32 cookie);470 u32 cookie);
471struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb);471struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb);
472struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,
473 struct sock *sk, struct sk_buff *skb);
472#ifdef CONFIG_SYN_COOKIES474#ifdef CONFIG_SYN_COOKIES
473 475
474/* Syncookies use a monotonic timer which increments every 60 seconds.476/* Syncookies use a monotonic timer which increments every 60 seconds.
net/ipv4/syncookies.c+34−4
@@ -276,6 +276,39 @@ bool cookie_ecn_ok(const struct tcp_options_received *tcp_opt, · 275 unmodified lines
276}276}
277EXPORT_SYMBOL(cookie_ecn_ok);277EXPORT_SYMBOL(cookie_ecn_ok);
278 278
279struct 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}
310EXPORT_SYMBOL_GPL(cookie_tcp_reqsk_alloc);
311
279/* On input, sk is a listener.312/* On input, sk is a listener.
280 * Output is listener if incoming packet would not create a child313 * Output is listener if incoming packet would not create a child
281 * NULL if memory could not be allocated.314 * NULL if memory could not be allocated.
@@ -326,7 +359,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) · 44 unmodified lines
326 goto out;359 goto out;
327 360
328 ret = NULL;361 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);
330 if (!req)363 if (!req)
331 goto out;364 goto out;
332 365
@@ -350,9 +383,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) · 17 unmodified lines
350 treq->snt_synack = 0;383 treq->snt_synack = 0;
351 treq->tfo_listener = false;384 treq->tfo_listener = false;
352 385
353 if (IS_ENABLED(CONFIG_MPTCP))
354 treq->is_mptcp = 0;
355
356 if (IS_ENABLED(CONFIG_SMC))386 if (IS_ENABLED(CONFIG_SMC))
357 ireq->smc_ok = 0;387 ireq->smc_ok = 0;
358 388
net/ipv4/tcp_input.c+0−3
@@ -6701,9 +6701,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, · 6700 unmodified lines
6701 6701
6702 af_ops->init_req(req, sk, skb);6702 af_ops->init_req(req, sk, skb);
6703 6703
6704 if (IS_ENABLED(CONFIG_MPTCP) && want_cookie)
6705 tcp_rsk(req)->is_mptcp = 0;
6706
6707 if (security_inet_conn_request(sk, skb, req))6704 if (security_inet_conn_request(sk, skb, req))
6708 goto drop_and_free;6705 goto drop_and_free;
6709 6706
net/ipv6/syncookies.c+1−4
@@ -170,7 +170,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · 169 unmodified lines
170 goto out;170 goto out;
171 171
172 ret = NULL;172 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);
174 if (!req)174 if (!req)
175 goto out;175 goto out;
176 176
@@ -178,9 +178,6 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · 1 unmodified line
178 treq = tcp_rsk(req);178 treq = tcp_rsk(req);
179 treq->tfo_listener = false;179 treq->tfo_listener = false;
180 180
181 if (IS_ENABLED(CONFIG_MPTCP))
182 treq->is_mptcp = 0;
183
184 if (security_inet_conn_request(sk, skb, req))181 if (security_inet_conn_request(sk, skb, req))
185 goto out_free;182 goto out_free;
186 183

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t