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
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+34−4
@@ -276,6 +276,39 @@ bool cookie_ecn_ok(const struct tcp_options_received *tcp_opt, · 275 unmodified lines
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) · 44 unmodified lines
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) · 17 unmodified lines
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+0−3
@@ -6701,9 +6701,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, · 6700 unmodified lines
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+1−4
@@ -170,7 +170,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · 169 unmodified lines
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
@@ -178,9 +178,6 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · 1 unmodified line
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

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