Branch data Line data Source code
1 : : // SPDX-License-Identifier: GPL-2.0
2 : : /* Multipath TCP
3 : : *
4 : : * Copyright (c) 2017 - 2019, Intel Corporation.
5 : : */
6 : :
7 : : #define pr_fmt(fmt) "MPTCP: " fmt
8 : :
9 : : #include <linux/kernel.h>
10 : : #include <crypto/sha2.h>
11 : : #include <net/tcp.h>
12 : : #include <net/mptcp.h>
13 : : #include "protocol.h"
14 : : #include "mib.h"
15 : :
16 : : #include <trace/events/mptcp.h>
17 : :
18 : : static bool mptcp_cap_flag_sha256(u8 flags)
19 : : {
20 : : return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
21 : : }
22 : :
23 : 1936329 : static void mptcp_parse_option(const struct sk_buff *skb,
24 : : const unsigned char *ptr, int opsize,
25 : : struct mptcp_options_received *mp_opt)
26 : : {
27 : 1936329 : u8 subtype = *ptr >> 4;
28 : 1936329 : int expected_opsize;
29 : 1936329 : u16 subopt;
30 : 1936329 : u8 version;
31 : 1936329 : u8 flags;
32 : 1936329 : u8 i;
33 : :
34 [ + + + + : 1936329 : switch (subtype) {
+ + + + +
- ][ + + +
+ + + + +
+ - ]
35 : 7754 : case MPTCPOPT_MP_CAPABLE:
36 : : /* strict size checking */
37 [ + ]: 7754 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
38 [ + ]: 4486 : if (skb->len > tcp_hdr(skb)->doff << 2)
39 : : expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
40 : : else
41 : 3307 : expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
42 : 4486 : subopt = OPTION_MPTCP_MPC_ACK;
43 : : } else {
44 [ + ]: 3268 : if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK) {
45 : : expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK;
46 : : subopt = OPTION_MPTCP_MPC_SYNACK;
47 : : } else {
48 : : expected_opsize = TCPOLEN_MPTCP_MPC_SYN;
49 : : subopt = OPTION_MPTCP_MPC_SYN;
50 : : }
51 : : }
52 : :
53 : : /* Only the MPC + ACK can be used with a RM_ADDR */
54 : 4486 : if (subopt == OPTION_MPTCP_MPC_ACK) {
55 [ + - ][ + - ]: 4486 : if ((mp_opt->suboptions & ~OPTION_MPTCP_RM_ADDR) != 0)
56 : : break;
57 [ - ][ - ]: 3268 : } else if (mp_opt->suboptions != 0) {
58 : : break;
59 : : }
60 : :
61 : : /* Cfr RFC 8684 Section 3.3.0:
62 : : * If a checksum is present but its use had
63 : : * not been negotiated in the MP_CAPABLE handshake, the receiver MUST
64 : : * close the subflow with a RST, as it is not behaving as negotiated.
65 : : * If a checksum is not present when its use has been negotiated, the
66 : : * receiver MUST close the subflow with a RST, as it is considered
67 : : * broken
68 : : * We parse even option with mismatching csum presence, so that
69 : : * later in subflow_data_ready we can trigger the reset.
70 : : */
71 [ + ]: 7754 : if (opsize != expected_opsize &&
72 : 94 : (expected_opsize != TCPOLEN_MPTCP_MPC_ACK_DATA ||
73 [ + ][ + ]: 94 : opsize != TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM))
74 : : break;
75 : :
76 : : /* try to be gentle vs future versions on the initial syn */
77 : 7742 : version = *ptr++ & MPTCP_VERSION_MASK;
78 [ + ]: 7742 : if (opsize != TCPOLEN_MPTCP_MPC_SYN) {
79 [ + + ][ + + ]: 5982 : if (version != MPTCP_SUPPORTED_VERSION)
80 : : break;
81 [ - ][ - ]: 1760 : } else if (version < MPTCP_SUPPORTED_VERSION) {
82 : : break;
83 : : }
84 : :
85 : 7736 : flags = *ptr++;
86 [ + + ][ + + ]: 7736 : if (!mptcp_cap_flag_sha256(flags) ||
87 : : (flags & MPTCP_CAP_EXTENSIBILITY))
88 : : break;
89 : :
90 : : /* RFC 6824, Section 3.1:
91 : : * "For the Checksum Required bit (labeled "A"), if either
92 : : * host requires the use of checksums, checksums MUST be used.
93 : : * In other words, the only way for checksums not to be used
94 : : * is if both hosts in their SYNs set A=0."
95 : : */
96 : 7700 : if ((flags & MPTCP_CAP_CHECKSUM_REQD) &&
97 [ + ]: 7700 : opsize < TCPOLEN_MPTCP_MPC_ACK_DATA)
98 : 476 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
99 : :
100 : 7700 : mp_opt->deny_join_id0 = !!(flags & MPTCP_CAP_DENY_JOIN_ID0);
101 : :
102 : 7700 : mp_opt->suboptions |= subopt;
103 [ + ]: 7700 : if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) {
104 [ + ]: 5952 : mp_opt->sndr_key = get_unaligned_be64(ptr);
105 : 5952 : ptr += 8;
106 : : }
107 [ + ]: 5952 : if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
108 [ + ]: 4468 : mp_opt->rcvr_key = get_unaligned_be64(ptr);
109 : 4468 : ptr += 8;
110 : : }
111 [ + ]: 4468 : if (opsize >= TCPOLEN_MPTCP_MPC_ACK_DATA) {
112 : : /* Section 3.1.:
113 : : * "the data parameters in a MP_CAPABLE are semantically
114 : : * equivalent to those in a DSS option and can be used
115 : : * interchangeably."
116 : : */
117 : 1179 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
118 : 1179 : mp_opt->use_map = 1;
119 : 1179 : mp_opt->mpc_map = 1;
120 [ + ]: 1179 : mp_opt->data_len = get_unaligned_be16(ptr);
121 : 1179 : ptr += 2;
122 : : }
123 [ + ]: 1179 : if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) {
124 : 82 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
125 : 82 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
126 : 82 : ptr += 2;
127 : : }
128 [ - - - - : 7700 : pr_debug("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d csum=%u\n",
- - ][ - -
- - - - ]
129 : : version, flags, opsize,
130 : : opsize >= TCPOLEN_MPTCP_MPC_SYNACK ? mp_opt->sndr_key : 0,
131 : : opsize >= TCPOLEN_MPTCP_MPC_ACK ? mp_opt->rcvr_key : 0,
132 : : opsize >= TCPOLEN_MPTCP_MPC_ACK_DATA ? mp_opt->data_len : 0,
133 : : opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM ? mp_opt->csum : 0);
134 : : break;
135 : :
136 : 2489 : case MPTCPOPT_MP_JOIN:
137 : : /* Can be used with a restricted number of other options */
138 [ - ][ - ]: 2489 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_RM_ADDR |
139 : : OPTION_MPTCP_PRIO)) != 0)
140 : : break;
141 : :
142 [ + ]: 2489 : if (opsize == TCPOLEN_MPTCP_MPJ_SYN) {
143 : 640 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_SYN;
144 : 640 : mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP;
145 : 640 : mp_opt->join_id = *ptr++;
146 [ - ]: 640 : mp_opt->token = get_unaligned_be32(ptr);
147 : 640 : ptr += 4;
148 : 640 : mp_opt->nonce = get_unaligned_be32(ptr);
149 : 640 : ptr += 4;
150 [ - - ][ - - ]: 640 : pr_debug("MP_JOIN bkup=%u, id=%u, token=%u, nonce=%u\n",
151 : : mp_opt->backup, mp_opt->join_id,
152 : : mp_opt->token, mp_opt->nonce);
153 [ + ]: 1849 : } else if (opsize == TCPOLEN_MPTCP_MPJ_SYNACK) {
154 : 594 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_SYNACK;
155 : 594 : mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP;
156 : 594 : mp_opt->join_id = *ptr++;
157 [ - ]: 594 : mp_opt->thmac = get_unaligned_be64(ptr);
158 : 594 : ptr += 8;
159 [ - ]: 594 : mp_opt->nonce = get_unaligned_be32(ptr);
160 : 594 : ptr += 4;
161 [ - - ][ - - ]: 594 : pr_debug("MP_JOIN bkup=%u, id=%u, thmac=%llu, nonce=%u\n",
162 : : mp_opt->backup, mp_opt->join_id,
163 : : mp_opt->thmac, mp_opt->nonce);
164 [ - ][ - ]: 1255 : } else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) {
165 : 1255 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_ACK;
166 : 1255 : ptr += 2;
167 : 1255 : memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN);
168 [ - - ][ - - ]: 1255 : pr_debug("MP_JOIN hmac\n");
169 : : }
170 : : break;
171 : :
172 : 1924553 : case MPTCPOPT_DSS:
173 : : /* Can be used with a restricted number of other options */
174 [ - ][ - ]: 1924553 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_ADD_ADDR |
175 : : OPTION_MPTCP_RM_ADDR |
176 : : OPTION_MPTCP_PRIO |
177 : : OPTION_MPTCP_FASTCLOSE |
178 : : OPTION_MPTCP_FAIL)) != 0)
179 : : break;
180 : :
181 [ - - ]: 1924553 : pr_debug("DSS\n");
182 : 1924553 : ptr++;
183 : :
184 : 1924553 : flags = (*ptr++) & MPTCP_DSS_FLAG_MASK;
185 : 1924553 : mp_opt->dsn64 = (flags & MPTCP_DSS_DSN64) != 0;
186 : 1924553 : mp_opt->use_map = (flags & MPTCP_DSS_HAS_MAP) != 0;
187 : 1924553 : mp_opt->ack64 = (flags & MPTCP_DSS_ACK64) != 0;
188 : 1924553 : mp_opt->use_ack = (flags & MPTCP_DSS_HAS_ACK);
189 : :
190 : 1924553 : expected_opsize = TCPOLEN_MPTCP_DSS_BASE;
191 : :
192 [ - ]: 1924553 : if (mp_opt->use_ack) {
193 [ + ]: 1924553 : if (mp_opt->ack64)
194 : : expected_opsize += TCPOLEN_MPTCP_DSS_ACK64;
195 : : else
196 : 207177 : expected_opsize += TCPOLEN_MPTCP_DSS_ACK32;
197 : : }
198 : :
199 [ + ]: 1924553 : if (mp_opt->use_map) {
200 : 1202105 : mp_opt->data_fin = (flags & MPTCP_DSS_DATA_FIN) != 0;
201 [ + ]: 1202105 : if (mp_opt->dsn64)
202 : 1202063 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP64;
203 : : else
204 : 42 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP32;
205 : : }
206 : :
207 [ - - ]: 1924553 : pr_debug("data_fin=%d dsn64=%d use_map=%d ack64=%d use_ack=%d\n",
208 : : mp_opt->data_fin, mp_opt->dsn64,
209 : : mp_opt->use_map, mp_opt->ack64,
210 : : mp_opt->use_ack);
211 : :
212 : : /* Always parse any csum presence combination, we will enforce
213 : : * RFC 8684 Section 3.3.0 checks later in subflow_data_ready
214 : : */
215 [ + ]: 1924553 : if (opsize != expected_opsize &&
216 [ + ]: 111916 : opsize != expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
217 : 0 : mp_opt->dsn64 = 0;
218 : 0 : mp_opt->use_map = 0;
219 : 0 : mp_opt->ack64 = 0;
220 : 0 : mp_opt->use_ack = 0;
221 : 0 : mp_opt->data_fin = 0;
222 : 0 : break;
223 : : }
224 : :
225 : 1924553 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
226 [ - ]: 1924553 : if (mp_opt->use_ack) {
227 [ + ]: 1924553 : if (mp_opt->ack64) {
228 : 1717376 : mp_opt->data_ack = get_unaligned_be64(ptr);
229 : 1717376 : ptr += 8;
230 : : } else {
231 : 207177 : mp_opt->data_ack = get_unaligned_be32(ptr);
232 : 207177 : ptr += 4;
233 : : }
234 : :
235 [ - - ]: 1924553 : pr_debug("data_ack=%llu\n", mp_opt->data_ack);
236 : : }
237 : :
238 [ + ][ + ]: 1924553 : if (mp_opt->use_map) {
239 [ + ]: 1202105 : if (mp_opt->dsn64) {
240 : 1202063 : mp_opt->data_seq = get_unaligned_be64(ptr);
241 : 1202063 : ptr += 8;
242 : : } else {
243 : 42 : mp_opt->data_seq = get_unaligned_be32(ptr);
244 : 42 : ptr += 4;
245 : : }
246 : :
247 [ + ]: 1202105 : mp_opt->subflow_seq = get_unaligned_be32(ptr);
248 : 1202105 : ptr += 4;
249 : :
250 [ + ]: 1202105 : mp_opt->data_len = get_unaligned_be16(ptr);
251 : 1202105 : ptr += 2;
252 : :
253 [ + ]: 1202105 : if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
254 : 111916 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
255 : 111916 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
256 : 111916 : ptr += 2;
257 : : }
258 : :
259 [ - - - ]: 1202105 : pr_debug("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n",
[ - - - ]
260 : : mp_opt->data_seq, mp_opt->subflow_seq,
261 : : mp_opt->data_len, !!(mp_opt->suboptions & OPTION_MPTCP_CSUMREQD),
262 : : (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) ? mp_opt->csum : 0);
263 : : }
264 : :
265 : : break;
266 : :
267 : 838 : case MPTCPOPT_ADD_ADDR:
268 : : /* Can be used with a restricted number of other options */
269 [ - ][ - ]: 838 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
270 : : OPTION_MPTCP_RM_ADDR |
271 : : OPTION_MPTCP_PRIO)) != 0)
272 : : break;
273 : :
274 : 838 : mp_opt->echo = (*ptr++) & MPTCP_ADDR_ECHO;
275 [ + ]: 838 : if (!mp_opt->echo) {
276 : 422 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR ||
277 [ + ]: 422 : opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT)
278 : 326 : mp_opt->addr.family = AF_INET;
279 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
280 : 96 : else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 ||
281 [ - ][ - ]: 96 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT)
282 : 96 : mp_opt->addr.family = AF_INET6;
283 : : #endif
284 : : else
285 : : break;
286 : : } else {
287 : 416 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE ||
288 [ + ]: 416 : opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT)
289 : 318 : mp_opt->addr.family = AF_INET;
290 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
291 : 98 : else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE ||
292 [ - ][ - ]: 98 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT)
293 : 98 : mp_opt->addr.family = AF_INET6;
294 : : #endif
295 : : else
296 : : break;
297 : : }
298 : :
299 : 838 : mp_opt->suboptions |= OPTION_MPTCP_ADD_ADDR;
300 : 838 : mp_opt->addr.id = *ptr++;
301 : 838 : mp_opt->addr.port = 0;
302 : 838 : mp_opt->ahmac = 0;
303 [ + ]: 838 : if (mp_opt->addr.family == AF_INET) {
304 : 644 : memcpy((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr, 4);
305 : 644 : ptr += 4;
306 : 644 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
307 [ + ]: 644 : opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
308 : 74 : mp_opt->addr.port = htons(get_unaligned_be16(ptr));
309 : 74 : ptr += 2;
310 : : }
311 : : }
312 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
313 : : else {
314 : 194 : memcpy(mp_opt->addr.addr6.s6_addr, (u8 *)ptr, 16);
315 : 194 : ptr += 16;
316 : 194 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
317 [ + ]: 194 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
318 : 22 : mp_opt->addr.port = htons(get_unaligned_be16(ptr));
319 : 22 : ptr += 2;
320 : : }
321 : : }
322 : : #endif
323 [ + ]: 838 : if (!mp_opt->echo) {
324 : 422 : mp_opt->ahmac = get_unaligned_be64(ptr);
325 : 422 : ptr += 8;
326 : : }
327 [ - - - ]: 838 : pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d\n",
[ - - - ]
328 : : (mp_opt->addr.family == AF_INET6) ? "6" : "",
329 : : mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo, ntohs(mp_opt->addr.port));
330 : : break;
331 : :
332 : 108 : case MPTCPOPT_RM_ADDR:
333 : : /* Can be used with a restricted number of other options */
334 [ - ][ - ]: 108 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_MPC_ACK |
335 : : OPTIONS_MPTCP_MPJ |
336 : : OPTIONS_MPTCP_DSS |
337 : : OPTION_MPTCP_ADD_ADDR |
338 : : OPTION_MPTCP_PRIO)) != 0)
339 : : break;
340 : :
341 [ - ][ - ]: 108 : if (opsize < TCPOLEN_MPTCP_RM_ADDR_BASE + 1 ||
342 : : opsize > TCPOLEN_MPTCP_RM_ADDR_BASE + MPTCP_RM_IDS_MAX)
343 : : break;
344 : :
345 : 108 : ptr++;
346 : :
347 : 108 : mp_opt->suboptions |= OPTION_MPTCP_RM_ADDR;
348 : 108 : mp_opt->rm_list.nr = opsize - TCPOLEN_MPTCP_RM_ADDR_BASE;
349 [ + ][ + ]: 224 : for (i = 0; i < mp_opt->rm_list.nr; i++)
350 : 116 : mp_opt->rm_list.ids[i] = *ptr++;
351 [ - - ][ - - ]: 108 : pr_debug("RM_ADDR: rm_list_nr=%d\n", mp_opt->rm_list.nr);
352 : : break;
353 : :
354 : 46 : case MPTCPOPT_MP_PRIO:
355 : : /* Can be used with a restricted number of other options */
356 [ - ][ - ]: 46 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_MPJ |
357 : : OPTIONS_MPTCP_DSS |
358 : : OPTION_MPTCP_ADD_ADDR |
359 : : OPTION_MPTCP_RM_ADDR)) != 0)
360 : : break;
361 : :
362 [ + ][ + ]: 46 : if (opsize != TCPOLEN_MPTCP_PRIO)
363 : : break;
364 : :
365 : 40 : mp_opt->suboptions |= OPTION_MPTCP_PRIO;
366 : 40 : mp_opt->backup = *ptr++ & MPTCP_PRIO_BKUP;
367 [ - - ][ - - ]: 40 : pr_debug("MP_PRIO: prio=%d\n", mp_opt->backup);
368 : : break;
369 : :
370 : 265 : case MPTCPOPT_MP_FASTCLOSE:
371 : : /* Can be used with a restricted number of other options */
372 [ - ][ - ]: 265 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
373 : : OPTION_MPTCP_RST)) != 0)
374 : : break;
375 : :
376 [ - ][ - ]: 265 : if (opsize != TCPOLEN_MPTCP_FASTCLOSE)
377 : : break;
378 : :
379 : 265 : ptr += 2;
380 [ - ][ - ]: 265 : mp_opt->fc_recv_key = get_unaligned_be64(ptr);
381 : 265 : ptr += 8;
382 : 265 : mp_opt->suboptions |= OPTION_MPTCP_FASTCLOSE;
383 [ - - ][ - - ]: 265 : pr_debug("MP_FASTCLOSE: recv_key=%llu\n", mp_opt->fc_recv_key);
384 : : break;
385 : :
386 : 270 : case MPTCPOPT_RST:
387 : : /* Can be used with a restricted number of other options */
388 [ - ][ - ]: 270 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_FAIL |
389 : : OPTION_MPTCP_FASTCLOSE)) != 0)
390 : : break;
391 : :
392 [ - ][ - ]: 270 : if (opsize != TCPOLEN_MPTCP_RST)
393 : : break;
394 : :
395 [ + ][ + ]: 270 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST))
396 : : break;
397 : :
398 : 258 : mp_opt->suboptions |= OPTION_MPTCP_RST;
399 : 258 : flags = *ptr++;
400 : 258 : mp_opt->reset_transient = flags & MPTCP_RST_TRANSIENT;
401 : 258 : mp_opt->reset_reason = *ptr;
402 [ - - ][ - - ]: 258 : pr_debug("MP_RST: transient=%u reason=%u\n",
403 : : mp_opt->reset_transient, mp_opt->reset_reason);
404 : : break;
405 : :
406 : 6 : case MPTCPOPT_MP_FAIL:
407 : : /* Can be used with a restricted number of other options */
408 [ - ][ - ]: 6 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
409 : : OPTION_MPTCP_RST)) != 0)
410 : : break;
411 : :
412 [ - ][ - ]: 6 : if (opsize != TCPOLEN_MPTCP_FAIL)
413 : : break;
414 : :
415 : 6 : ptr += 2;
416 : 6 : mp_opt->suboptions |= OPTION_MPTCP_FAIL;
417 [ - ][ - ]: 6 : mp_opt->fail_seq = get_unaligned_be64(ptr);
418 [ - - ][ - - ]: 6 : pr_debug("MP_FAIL: data_seq=%llu\n", mp_opt->fail_seq);
419 : : break;
420 : :
421 : : default:
422 : : break;
423 : : }
424 : 1936329 : }
425 : :
426 : 1936538 : void mptcp_get_options(const struct sk_buff *skb,
427 : : struct mptcp_options_received *mp_opt)
428 : : {
429 : 1936538 : const struct tcphdr *th = tcp_hdr(skb);
430 : 1936538 : const unsigned char *ptr;
431 : 1936538 : int length;
432 : :
433 : : /* Ensure that casting the whole status to u32 is efficient and safe */
434 : 1936538 : BUILD_BUG_ON(sizeof_field(struct mptcp_options_received, status) != sizeof(u32));
435 : 1936538 : BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct mptcp_options_received, status),
436 : : sizeof(u32)));
437 : 1936538 : *(u32 *)&mp_opt->status = 0;
438 : :
439 : 1936538 : length = (th->doff * 4) - sizeof(struct tcphdr);
440 : 1936538 : ptr = (const unsigned char *)(th + 1);
441 : :
442 [ + ]: 11863903 : while (length > 0) {
443 : 9927365 : int opcode = *ptr++;
444 : 9927365 : int opsize;
445 : :
446 [ + + - ]: 9927365 : switch (opcode) {
447 : : case TCPOPT_EOL:
448 : : return;
449 : 6044212 : case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
450 : 6044212 : length--;
451 : 6044212 : continue;
452 : 3883153 : default:
453 [ - ]: 3883153 : if (length < 2)
454 : : return;
455 : 3883153 : opsize = *ptr++;
456 [ - ]: 3883153 : if (opsize < 2) /* "silly options" */
457 : : return;
458 [ - ]: 3883153 : if (opsize > length)
459 : : return; /* don't parse partial options */
460 [ + ]: 3883153 : if (opcode == TCPOPT_MPTCP)
461 : 1936329 : mptcp_parse_option(skb, ptr, opsize, mp_opt);
462 : 3883153 : ptr += opsize - 2;
463 : 3883153 : length -= opsize;
464 : : }
465 : : }
466 : : }
467 : :
468 : 2508 : bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
469 : : unsigned int *size, struct mptcp_out_options *opts)
470 : : {
471 [ + ][ + ]: 2508 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
472 : :
473 : : /* we will use snd_isn to detect first pkt [re]transmission
474 : : * in mptcp_established_options_mp()
475 : : */
476 : 2508 : subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
477 [ + ][ + ]: 2508 : if (subflow->request_mptcp) {
478 [ + ]: 1763 : if (unlikely(subflow_simultaneous_connect(sk))) {
479 [ + ]: 6 : WARN_ON_ONCE(!mptcp_try_fallback(sk, MPTCP_MIB_SIMULTCONNFALLBACK));
480 : :
481 : : /* Ensure mptcp_finish_connect() will not process the
482 : : * MPC handshake.
483 : : */
484 : 6 : subflow->request_mptcp = 0;
485 : 6 : return false;
486 : : }
487 : :
488 : 1757 : opts->suboptions = OPTION_MPTCP_MPC_SYN;
489 : 1757 : opts->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk));
490 : 1757 : opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk));
491 : 1757 : *size = TCPOLEN_MPTCP_MPC_SYN;
492 : 1757 : return true;
493 [ + ][ + ]: 745 : } else if (subflow->request_join) {
494 [ - - ][ - - ]: 709 : pr_debug("remote_token=%u, nonce=%u\n", subflow->remote_token,
495 : : subflow->local_nonce);
496 : 709 : opts->suboptions = OPTION_MPTCP_MPJ_SYN;
497 : 709 : opts->join_id = subflow->local_id;
498 : 709 : opts->token = subflow->remote_token;
499 : 709 : opts->nonce = subflow->local_nonce;
500 : 709 : opts->backup = subflow->request_bkup;
501 : 709 : *size = TCPOLEN_MPTCP_MPJ_SYN;
502 : 709 : return true;
503 : : }
504 : : return false;
505 : : }
506 : :
507 : 1198 : static void clear_3rdack_retransmission(struct sock *sk)
508 : : {
509 : 1198 : struct inet_connection_sock *icsk = inet_csk(sk);
510 : :
511 : 1198 : sk_stop_timer(sk, &icsk->icsk_delack_timer);
512 : 1198 : icsk->icsk_ack.ato = 0;
513 : 1198 : icsk->icsk_ack.pending &= ~(ICSK_ACK_SCHED | ICSK_ACK_TIMER);
514 : 1198 : }
515 : :
516 : 3396925 : static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
517 : : bool snd_data_fin_enable, int *size,
518 : : struct mptcp_out_options *opts)
519 : : {
520 [ + ]: 3396925 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
521 [ + ]: 3396925 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
522 : 3396925 : struct mptcp_ext *mpext;
523 : 3396925 : unsigned int data_len;
524 : 3396925 : u8 len;
525 : :
526 : : /* When skb is not available, we better over-estimate the emitted
527 : : * options len. A full DSS option (28 bytes) is longer than
528 : : * TCPOLEN_MPTCP_MPC_ACK_DATA(22) or TCPOLEN_MPTCP_MPJ_ACK(24), so
529 : : * tell the caller to defer the estimate to
530 : : * mptcp_established_options_dss(), which will reserve enough space.
531 : : */
532 [ + ][ + ]: 3396925 : if (!skb)
533 : : return false;
534 : :
535 : : /* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
536 [ + + ][ + ]: 1561437 : if (subflow->fully_established || snd_data_fin_enable ||
537 [ + ][ + ]: 4179 : subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
538 [ - ][ - ]: 3030 : sk->sk_state != TCP_ESTABLISHED)
539 : : return false;
540 : :
541 [ + ][ + ]: 3030 : if (subflow->mp_capable) {
542 [ + ]: 2421 : mpext = mptcp_get_ext(skb);
543 [ + ][ - ]: 1679 : data_len = mpext ? mpext->data_len : 0;
544 : :
545 : : /* we will check ops->data_len in mptcp_write_options() to
546 : : * discriminate between TCPOLEN_MPTCP_MPC_ACK_DATA and
547 : : * TCPOLEN_MPTCP_MPC_ACK
548 : : */
549 : 2421 : opts->data_len = data_len;
550 : 2421 : opts->suboptions = OPTION_MPTCP_MPC_ACK;
551 : 2421 : opts->sndr_key = subflow->local_key;
552 : 2421 : opts->rcvr_key = subflow->remote_key;
553 [ + ]: 2421 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
554 : 2421 : opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk));
555 : :
556 : : /* Section 3.1.
557 : : * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK
558 : : * packets that start the first subflow of an MPTCP connection,
559 : : * as well as the first packet that carries data
560 : : */
561 [ + ][ + ]: 2421 : if (data_len > 0) {
562 : 936 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
563 [ + ][ + ]: 936 : if (opts->csum_reqd) {
564 : : /* we need to propagate more info to csum the pseudo hdr */
565 : 82 : opts->data_seq = mpext->data_seq;
566 : 82 : opts->subflow_seq = mpext->subflow_seq;
567 : 82 : opts->csum = mpext->csum;
568 : 82 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
569 : : }
570 : 936 : *size = ALIGN(len, 4);
571 : : } else {
572 : 1485 : *size = TCPOLEN_MPTCP_MPC_ACK;
573 : : }
574 : :
575 [ - - ][ - - ]: 2421 : pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d\n",
576 : : subflow, subflow->local_key, subflow->remote_key,
577 : : data_len);
578 : :
579 : 2421 : return true;
580 [ - ][ - ]: 609 : } else if (subflow->mp_join) {
581 : 609 : opts->suboptions = OPTION_MPTCP_MPJ_ACK;
582 : 609 : memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
583 : 609 : *size = TCPOLEN_MPTCP_MPJ_ACK;
584 [ - - ][ - - ]: 609 : pr_debug("subflow=%p\n", subflow);
585 : :
586 : : /* we can use the full delegate action helper only from BH context
587 : : * If we are in process context - sk is flushing the backlog at
588 : : * socket lock release time - just set the appropriate flag, will
589 : : * be handled by the release callback
590 : : */
591 [ + ][ + ]: 609 : if (sock_owned_by_user(sk))
592 : 517 : set_bit(MPTCP_DELEGATE_ACK, &subflow->delegated_status);
593 : : else
594 : 92 : mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_ACK);
595 : 609 : return true;
596 : : }
597 : : return false;
598 : : }
599 : :
600 : 32265 : static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
601 : : struct sk_buff *skb, struct mptcp_ext *ext)
602 : : {
603 : : /* The write_seq value has already been incremented, so the actual
604 : : * sequence number for the DATA_FIN is one less.
605 : : */
606 [ + ]: 32265 : u64 data_fin_tx_seq = READ_ONCE(mptcp_sk(subflow->conn)->write_seq) - 1;
607 : :
608 [ + + ]: 32265 : if (!ext->use_map || !skb->len) {
609 : : /* RFC6824 requires a DSS mapping with specific values
610 : : * if DATA_FIN is set but no data payload is mapped
611 : : */
612 : 17934 : ext->data_fin = 1;
613 : 17934 : ext->use_map = 1;
614 : 17934 : ext->dsn64 = 1;
615 : 17934 : ext->data_seq = data_fin_tx_seq;
616 : 17934 : ext->subflow_seq = 0;
617 : 17934 : ext->data_len = 1;
618 : 17934 : ext->csum = 0;
619 [ + ]: 14331 : } else if (ext->data_seq + ext->data_len == data_fin_tx_seq) {
620 : : /* If there's an existing DSS mapping and it is the
621 : : * final mapping, DATA_FIN consumes 1 additional byte of
622 : : * mapping space.
623 : : */
624 : 1449 : ext->data_fin = 1;
625 : 1449 : ext->data_len++;
626 : : }
627 : 32265 : }
628 : :
629 : 3393895 : static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
630 : : bool snd_data_fin_enable, int *size,
631 : : struct mptcp_out_options *opts)
632 : : {
633 [ + ]: 3393895 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
634 [ + ]: 3393895 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
635 [ + ]: 3393895 : struct tcp_sock *tp = tcp_sk(sk);
636 : 3393895 : unsigned int dss_size = 0;
637 : 3393895 : struct mptcp_ext *mpext;
638 : 3393895 : unsigned int ack_size;
639 : 3393895 : bool ret = false;
640 : :
641 : : /* Zero `use_ack` and `use_map` flags with one shot. */
642 : 3393895 : memset(&opts->ext_copy.flags, 0, sizeof(opts->ext_copy.flags));
643 [ + ]: 3393895 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
644 [ + ][ + ]: 3393895 : mpext = skb ? mptcp_get_ext(skb) : NULL;
645 : :
646 [ + + + ]: 1558407 : if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) {
[ + + + ]
647 : 2634841 : unsigned int map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64;
648 : :
649 [ + ][ + ]: 2634841 : if (mpext) {
650 [ + ][ + ]: 781419 : if (opts->csum_reqd)
651 : 110304 : map_size += TCPOLEN_MPTCP_DSS_CHECKSUM;
652 : :
653 : 781419 : opts->ext_copy = *mpext;
654 : : }
655 : :
656 : 2634841 : dss_size = map_size;
657 [ + ][ + ]: 2634841 : if (skb && snd_data_fin_enable)
658 : 32265 : mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
659 : 2634841 : opts->suboptions = OPTION_MPTCP_DSS;
660 : 2634841 : ret = true;
661 : : }
662 : :
663 : : /* passive sockets msk will set the 'can_ack' after accept(), even
664 : : * if the first subflow may have the already the remote key handy
665 : : */
666 [ + + ][ + ]: 3393895 : if (!READ_ONCE(msk->can_ack)) {
667 : 31 : *size = ALIGN(dss_size, 4);
668 : 31 : return ret;
669 : : }
670 : :
671 [ + + ][ + ]: 3393864 : if (READ_ONCE(msk->use_64bit_ack)) {
672 : 3086507 : ack_size = TCPOLEN_MPTCP_DSS_ACK64;
673 : 3086507 : opts->ext_copy.ack64 = 1;
674 : : } else {
675 : 307357 : ack_size = TCPOLEN_MPTCP_DSS_ACK32;
676 : 307357 : opts->ext_copy.ack64 = 0;
677 : : }
678 : 3393864 : opts->ext_copy.use_ack = 1;
679 : 3393864 : opts->suboptions = OPTION_MPTCP_DSS;
680 : :
681 : : /* Add kind/length/subtype/flag overhead if mapping is not populated */
682 [ + ][ + ]: 3393864 : if (dss_size == 0)
683 : 759054 : ack_size += TCPOLEN_MPTCP_DSS_BASE;
684 : :
685 : : /* The caller is __tcp_transmit_skb(), and will compute the new rcv
686 : : * wnd soon: ensure that the window can shrink.
687 : : */
688 [ + ][ + ]: 3393864 : if (skb)
689 : 1558407 : tp->rcv_wnd = tp->rcv_nxt - tp->rcv_wup;
690 : :
691 : 3393864 : dss_size += ack_size;
692 : :
693 : 3393864 : *size = ALIGN(dss_size, 4);
694 : 3393864 : return true;
695 : : }
696 : :
697 : 912 : static u64 add_addr_generate_hmac(u64 key1, u64 key2,
698 : : struct mptcp_addr_info *addr)
699 : : {
700 : 912 : u16 port = ntohs(addr->port);
701 : 912 : u8 hmac[SHA256_DIGEST_SIZE];
702 : 912 : u8 msg[19];
703 : 912 : int i = 0;
704 : :
705 : 912 : msg[i++] = addr->id;
706 [ + ]: 912 : if (addr->family == AF_INET) {
707 : 700 : memcpy(&msg[i], &addr->addr.s_addr, 4);
708 : 700 : i += 4;
709 : : }
710 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
711 [ - ]: 212 : else if (addr->family == AF_INET6) {
712 : 212 : memcpy(&msg[i], &addr->addr6.s6_addr, 16);
713 : 212 : i += 16;
714 : : }
715 : : #endif
716 : 912 : msg[i++] = port >> 8;
717 : 912 : msg[i++] = port & 0xFF;
718 : :
719 : 912 : mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac);
720 : :
721 : 912 : return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
722 : : }
723 : :
724 : 3396921 : static bool mptcp_established_options_add_addr(struct sock *sk,
725 : : struct sk_buff *skb, int *size,
726 : : unsigned int remaining,
727 : : bool has_ts,
728 : : struct mptcp_out_options *opts)
729 : : {
730 [ + ]: 3396921 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
731 [ + ]: 3396921 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
732 : 3396921 : struct mptcp_addr_info addr;
733 : 3396921 : bool drop_ts = has_ts;
734 : 3396921 : bool echo;
735 : :
736 : : /* add addr will strip the existing options, be sure to avoid breaking
737 : : * MPC/MPJ handshakes
738 : : */
739 [ + ]: 3396921 : if (!mptcp_pm_should_add_signal(msk) ||
740 [ - - ]: 910 : (opts->suboptions & (OPTION_MPTCP_MPJ_ACK | OPTION_MPTCP_MPC_ACK)) ||
741 [ - + ]: 1820 : !skb || !skb_is_tcp_pure_ack(skb) ||
742 : 910 : !mptcp_pm_add_addr_signal(msk, size, remaining, &addr, &echo,
743 : : &drop_ts))
744 : 3396019 : return false;
745 : :
746 [ - - ]: 902 : pr_debug("drop other suboptions\n");
747 : 902 : opts->suboptions = OPTION_MPTCP_ADD_ADDR;
748 [ + ]: 902 : opts->drop_ts = drop_ts;
749 : 902 : opts->addr = addr;
750 [ + + ][ + ]: 902 : if (!echo) {
751 [ - ][ - ]: 490 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX);
752 : 490 : opts->ahmac = add_addr_generate_hmac(READ_ONCE(msk->local_key),
753 : 490 : READ_ONCE(msk->remote_key),
754 : : &opts->addr);
755 : : } else {
756 [ - ][ # ]: 412 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADDTX);
757 : 412 : opts->ahmac = 0;
758 : : }
759 [ - - - ]: 902 : pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d\n",
[ - - ]
760 : : opts->addr.id, opts->ahmac, echo, ntohs(opts->addr.port));
761 : :
762 : : return true;
763 : : }
764 : :
765 : 3396019 : static bool mptcp_established_options_rm_addr(struct sock *sk,
766 : : struct sk_buff *skb, int *size,
767 : : unsigned int remaining,
768 : : struct mptcp_out_options *opts)
769 : : {
770 [ + ]: 3396019 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
771 [ + ]: 3396019 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
772 : 3396019 : struct mptcp_rm_list rm_list;
773 : 3396019 : int i;
774 : :
775 [ + + ]: 3396133 : if (!mptcp_pm_should_rm_signal(msk) ||
776 : 114 : !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, size, !skb)))
777 : 3395905 : return false;
778 : :
779 : : /* without skb, only the size is needed: keep it for the next packet */
780 [ + ]: 114 : if (!skb)
781 : : return true;
782 : :
783 : 114 : opts->suboptions |= OPTION_MPTCP_RM_ADDR;
784 : 114 : opts->rm_list = rm_list;
785 : :
786 [ + ][ + ]: 236 : for (i = 0; i < opts->rm_list.nr; i++)
787 [ - - ][ - - ]: 122 : pr_debug("rm_list_ids[%d]=%d\n", i, opts->rm_list.ids[i]);
788 : 114 : MPTCP_ADD_STATS(sock_net(sk), MPTCP_MIB_RMADDRTX, opts->rm_list.nr);
789 : 114 : return true;
790 : : }
791 : :
792 : 3396921 : static bool mptcp_established_options_mp_prio(struct sock *sk, int *size,
793 : : unsigned int remaining,
794 : : struct mptcp_out_options *opts)
795 : : {
796 [ + ]: 3396921 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
797 : :
798 : : /* can't send MP_PRIO with MPC, as they share the same option space:
799 : : * 'backup'. Also it makes no sense at all
800 : : */
801 [ + - ]: 3396921 : if (!subflow->send_mp_prio || (opts->suboptions & OPTIONS_MPTCP_MPC))
802 : : return false;
803 : :
804 : : /* account for the trailing 'nop' option */
805 [ - ]: 28 : if (remaining < TCPOLEN_MPTCP_PRIO_ALIGN)
806 : : return false;
807 : :
808 : 28 : *size = TCPOLEN_MPTCP_PRIO_ALIGN;
809 : 28 : opts->suboptions |= OPTION_MPTCP_PRIO;
810 : 28 : opts->backup = subflow->request_bkup;
811 : :
812 [ - - ]: 28 : pr_debug("prio=%d\n", opts->backup);
813 : :
814 : : return true;
815 : : }
816 : :
817 : 539 : static noinline bool mptcp_established_options_rst(struct sock *sk,
818 : : int *size,
819 : : unsigned int remaining,
820 : : struct mptcp_out_options *opts)
821 : : {
822 [ - ][ - ]: 539 : const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
823 : :
824 [ - ][ - ]: 539 : if (remaining < TCPOLEN_MPTCP_RST)
825 : : return false;
826 : :
827 : 539 : *size = TCPOLEN_MPTCP_RST;
828 : 539 : opts->suboptions |= OPTION_MPTCP_RST;
829 : 539 : opts->reset_transient = subflow->reset_transient;
830 : 539 : opts->reset_reason = subflow->reset_reason;
831 [ - ][ - ]: 539 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTTX);
832 : :
833 : : return true;
834 : : }
835 : :
836 : 539 : static bool mptcp_established_options_fastclose(struct sock *sk, int *size,
837 : : unsigned int remaining,
838 : : struct mptcp_out_options *opts)
839 : : {
840 [ + ]: 539 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
841 [ + ]: 539 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
842 : :
843 [ + ][ + ]: 539 : if (likely(!subflow->send_fastclose))
844 : : return false;
845 : :
846 [ - ][ - ]: 484 : if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
847 : : return false;
848 : :
849 : 484 : *size = TCPOLEN_MPTCP_FASTCLOSE;
850 : 484 : opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
851 : 484 : opts->rcvr_key = READ_ONCE(msk->remote_key);
852 : :
853 [ - - ]: 484 : pr_debug("FASTCLOSE key=%llu\n", opts->rcvr_key);
854 [ - ][ - ]: 484 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX);
855 : : return true;
856 : : }
857 : :
858 : 3393950 : static bool mptcp_established_options_mp_fail(struct sock *sk, int *size,
859 : : unsigned int remaining,
860 : : struct mptcp_out_options *opts)
861 : : {
862 [ + ][ + ]: 3393950 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
863 : :
864 [ + ][ + ]: 3393950 : if (likely(!subflow->send_mp_fail))
865 : : return false;
866 : :
867 [ - ][ - ]: 6 : if (remaining < TCPOLEN_MPTCP_FAIL)
868 : : return false;
869 : :
870 : 6 : *size = TCPOLEN_MPTCP_FAIL;
871 : 6 : opts->suboptions |= OPTION_MPTCP_FAIL;
872 : 6 : opts->fail_seq = subflow->map_seq;
873 : :
874 [ - - ]: 6 : pr_debug("MP_FAIL fail_seq=%llu\n", opts->fail_seq);
875 [ - ][ # ]: 6 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILTX);
876 : :
877 : : return true;
878 : : }
879 : :
880 : 3483777 : int mptcp_established_options(struct sock *sk, struct sk_buff *skb,
881 : : unsigned int remaining, bool has_ts,
882 : : struct mptcp_out_options *opts)
883 : : {
884 [ + ]: 3483777 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
885 [ + ]: 3483777 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
886 : 3483777 : int total_size = 0;
887 : 3483777 : bool snd_data_fin;
888 : 3483777 : bool ret = false;
889 : 3483777 : int opt_size = 0;
890 : :
891 : 3483777 : opts->suboptions = 0;
892 : :
893 : : /* Force later mptcp_write_options(), but do not use any actual
894 : : * option space.
895 : : */
896 [ + + ][ + + ]: 3483777 : if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb)))
897 : : return 0;
898 : :
899 [ + + ][ + + ]: 3397464 : if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
900 [ + + ][ + + ]: 594 : if (mptcp_established_options_fastclose(sk, &opt_size, remaining, opts) ||
901 : 55 : mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
902 : 486 : total_size += opt_size;
903 : 486 : remaining -= opt_size;
904 : : }
905 : : /* MP_RST can be used with MP_FASTCLOSE and MP_FAIL if there is room */
906 [ - ][ - ]: 539 : if (mptcp_established_options_rst(sk, &opt_size, remaining, opts)) {
907 : 539 : total_size += opt_size;
908 : 539 : remaining -= opt_size;
909 : : }
910 : 539 : return total_size;
911 : : }
912 : :
913 [ + ]: 3396925 : snd_data_fin = mptcp_data_fin_enabled(msk);
914 [ + ][ + ]: 3396925 : if (mptcp_established_options_mp(sk, skb, snd_data_fin, &opt_size, opts))
915 : : ret = true;
916 [ - ][ - ]: 3393895 : else if (mptcp_established_options_dss(sk, skb, snd_data_fin, &opt_size, opts)) {
917 : 3393895 : int mp_fail_size;
918 : :
919 : 3393895 : ret = true;
920 [ + ][ + ]: 3393895 : if (mptcp_established_options_mp_fail(sk, &mp_fail_size,
921 : : remaining - opt_size, opts)) {
922 : 4 : total_size += opt_size + mp_fail_size;
923 : 4 : remaining -= opt_size - mp_fail_size;
924 : 4 : return total_size;
925 : : }
926 : : }
927 : :
928 : : /* we reserved enough space for the above options, and exceeding the
929 : : * TCP option space would be fatal
930 : : */
931 [ + + ][ + + ]: 3396921 : if (WARN_ON_ONCE(opt_size > remaining))
932 : : return -1;
933 : :
934 : 3396921 : total_size += opt_size;
935 : 3396921 : remaining -= opt_size;
936 [ + ][ + ]: 3396921 : if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining,
937 : : has_ts, opts)) {
938 : 902 : total_size += opt_size;
939 : 902 : remaining -= opt_size;
940 : 902 : ret = true;
941 [ + ][ + ]: 3396019 : } else if (mptcp_established_options_rm_addr(sk, skb, &opt_size,
942 : : remaining, opts)) {
943 : 114 : total_size += opt_size;
944 : 114 : remaining -= opt_size;
945 : 114 : ret = true;
946 : : }
947 : :
948 [ + ][ + ]: 3396921 : if (mptcp_established_options_mp_prio(sk, &opt_size, remaining, opts)) {
949 : 28 : total_size += opt_size;
950 : 28 : remaining -= opt_size;
951 : 28 : ret = true;
952 : : }
953 : :
954 [ - ][ - ]: 3396921 : return ret ? total_size : -1;
955 : : }
956 : :
957 : 2488 : bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
958 : : struct mptcp_out_options *opts)
959 : : {
960 : 2488 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
961 : :
962 [ + ]: 2488 : if (subflow_req->mp_capable) {
963 : 1692 : opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
964 : 1692 : opts->sndr_key = subflow_req->local_key;
965 : 1692 : opts->csum_reqd = subflow_req->csum_reqd;
966 : 1692 : opts->allow_join_id0 = subflow_req->allow_join_id0;
967 : 1692 : *size = TCPOLEN_MPTCP_MPC_SYNACK;
968 [ - - ]: 1692 : pr_debug("subflow_req=%p, local_key=%llu\n",
969 : : subflow_req, subflow_req->local_key);
970 : 1692 : return true;
971 [ + ]: 796 : } else if (subflow_req->mp_join) {
972 : 636 : opts->suboptions = OPTION_MPTCP_MPJ_SYNACK;
973 : 636 : opts->backup = subflow_req->request_bkup;
974 : 636 : opts->join_id = subflow_req->local_id;
975 : 636 : opts->thmac = subflow_req->thmac;
976 : 636 : opts->nonce = subflow_req->local_nonce;
977 [ - - ]: 636 : pr_debug("req=%p, bkup=%u, id=%u, thmac=%llu, nonce=%u\n",
978 : : subflow_req, opts->backup, opts->join_id,
979 : : opts->thmac, opts->nonce);
980 : 636 : *size = TCPOLEN_MPTCP_MPJ_SYNACK;
981 : 636 : return true;
982 : : }
983 : : return false;
984 : : }
985 : :
986 : 1929416 : static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
987 : : struct mptcp_subflow_context *subflow,
988 : : struct sk_buff *skb,
989 : : struct mptcp_options_received *mp_opt)
990 : : {
991 : 1929416 : struct sock *sk = (struct sock *)msk;
992 : :
993 : : /* here we can process OoO, in-window pkts, only in-sequence 4th ack
994 : : * will make the subflow fully established
995 : : */
996 [ + + ][ + ]: 1929416 : if (likely(subflow->fully_established)) {
997 : : /* on passive sockets, check for 3rd ack retransmission
998 : : * note that msk is always set by subflow_syn_recv_sock()
999 : : * for mp_join subflows
1000 : : */
1001 [ + ][ + ]: 1927290 : if (TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 &&
1002 [ + + ][ + + ]: 204490 : TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq &&
1003 [ + ][ + ]: 53169 : subflow->mp_join && (mp_opt->suboptions & OPTIONS_MPTCP_MPJ) &&
1004 [ - ][ - ]: 615 : !subflow->request_join)
1005 : 615 : tcp_send_ack(ssk);
1006 : 1927290 : goto check_notify;
1007 : : }
1008 : :
1009 : : /* we must process OoO packets before the first subflow is fully
1010 : : * established. OoO packets are instead a protocol violation
1011 : : * for MP_JOIN subflows as the peer must not send any data
1012 : : * before receiving the forth ack - cfr. RFC 8684 section 3.2.
1013 : : */
1014 [ + ][ + ]: 2126 : if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
1015 [ + ][ + ]: 70 : if (subflow->mp_join)
1016 : 0 : goto reset;
1017 [ + - ][ + - ]: 70 : if (subflow->is_mptfo && mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
1018 : 0 : goto set_fully_established;
1019 : 70 : return subflow->mp_capable;
1020 : : }
1021 : :
1022 [ + ][ + ]: 2056 : if (subflow->remote_key_valid &&
1023 [ + + + ]: 2012 : (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
[ + + + ]
1024 : 96 : ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) &&
1025 [ + - ][ + - ]: 96 : (!mp_opt->echo || subflow->mp_join)))) {
1026 : : /* subflows are fully established as soon as we get any
1027 : : * additional ack, including ADD_ADDR.
1028 : : */
1029 : 1998 : goto set_fully_established;
1030 : : }
1031 : :
1032 : : /* If the first established packet does not contain MP_CAPABLE + data
1033 : : * then fallback to TCP. Fallback scenarios requires a reset for
1034 : : * MP_JOIN subflows.
1035 : : */
1036 [ + ][ + ]: 58 : if (!(mp_opt->suboptions & OPTIONS_MPTCP_MPC)) {
1037 [ + ][ + ]: 14 : if (subflow->mp_join)
1038 : 8 : goto reset;
1039 : 6 : subflow->mp_capable = 0;
1040 [ + ][ + ]: 6 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK)) {
1041 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
1042 : 0 : goto reset;
1043 : : }
1044 : : /* this ACK will not reach the fallback path: push from here */
1045 : 6 : mptcp_data_lock(sk);
1046 : 6 : __mptcp_check_push(sk, ssk);
1047 : 6 : mptcp_data_unlock(sk);
1048 : 6 : return false;
1049 : : }
1050 : :
1051 [ + - ][ - ]: 44 : if (unlikely(!READ_ONCE(msk->pm.server_side)))
1052 : : /* DO-NOT-MERGE: use WARN i/o pr_warn: only for MPTCP export */
1053 : 0 : WARN_ONCE(1, "bogus mpc option on established client sk");
1054 : :
1055 : 44 : set_fully_established:
1056 [ + ][ + ]: 2042 : if (mp_opt->deny_join_id0)
1057 : 0 : WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
1058 : :
1059 : 2042 : mptcp_data_lock(sk);
1060 : 2042 : __mptcp_subflow_fully_established(msk, subflow, mp_opt);
1061 [ + + ][ + + ]: 2042 : if (tcp_sk(ssk)->syn_fastopen_child)
1062 : 44 : __mptcp_check_push(sk, ssk);
1063 : 2042 : mptcp_data_unlock(sk);
1064 : :
1065 : 1929332 : check_notify:
1066 : : /* if the subflow is not already linked into the conn_list, we can't
1067 : : * notify the PM: this subflow is still on the listener queue
1068 : : * and the PM possibly acquiring the subflow lock could race with
1069 : : * the listener close
1070 : : */
1071 [ + - ][ + - ]: 1929332 : if (likely(subflow->pm_notified) || list_empty(&subflow->node))
1072 : : return true;
1073 : :
1074 : 2654 : subflow->pm_notified = 1;
1075 [ + ][ + ]: 2654 : if (subflow->mp_join) {
1076 : 1198 : clear_3rdack_retransmission(ssk);
1077 : 1198 : mptcp_pm_subflow_established(msk);
1078 : : } else {
1079 : 1456 : mptcp_pm_fully_established(msk, ssk);
1080 : : }
1081 : : return true;
1082 : :
1083 : 8 : reset:
1084 : 8 : mptcp_subflow_reset(ssk);
1085 : 8 : return false;
1086 : : }
1087 : :
1088 : 218896 : u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq)
1089 : : {
1090 : 218896 : u32 old_seq32, cur_seq32;
1091 : :
1092 : 218896 : old_seq32 = (u32)old_seq;
1093 : 218896 : cur_seq32 = (u32)cur_seq;
1094 : 218896 : cur_seq = (old_seq & GENMASK_ULL(63, 32)) + cur_seq32;
1095 [ + + ]: 218896 : if (unlikely(cur_seq32 < old_seq32 && before(old_seq32, cur_seq32)))
1096 : 0 : return cur_seq + (1LL << 32);
1097 : :
1098 : : /* reverse wrap could happen, too */
1099 [ + + ]: 218896 : if (unlikely(cur_seq32 > old_seq32 && after(old_seq32, cur_seq32)))
1100 : 0 : return cur_seq - (1LL << 32);
1101 : : return cur_seq;
1102 : : }
1103 : :
1104 : 0 : static void __mptcp_snd_una_update(struct mptcp_sock *msk, u64 new_snd_una)
1105 : : {
1106 : 583903 : msk->bytes_acked += new_snd_una - msk->snd_una;
1107 : 583903 : WRITE_ONCE(msk->snd_una, new_snd_una);
1108 : : }
1109 : :
1110 : 1925724 : static void rwin_update(struct mptcp_sock *msk, struct sock *ssk,
1111 : : struct sk_buff *skb)
1112 : : {
1113 [ + ]: 1925724 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1114 [ + ]: 1925724 : struct tcp_sock *tp = tcp_sk(ssk);
1115 : 1925724 : u64 mptcp_rcv_wnd;
1116 : :
1117 : : /* Avoid touching extra cachelines if TCP is going to accept this
1118 : : * skb without filling the TCP-level window even with a possibly
1119 : : * outdated mptcp-level rwin.
1120 : : */
1121 [ - + ][ - + ]: 1925724 : if (!skb->len || skb->len < tcp_receive_window(tp))
1122 : : return;
1123 : :
1124 [ + ]: 13936 : mptcp_rcv_wnd = atomic64_read(&msk->rcv_wnd_sent);
1125 [ + ][ + ]: 13936 : if (!after64(mptcp_rcv_wnd, subflow->rcv_wnd_sent))
1126 : : return;
1127 : :
1128 : : /* Some other subflow grew the mptcp-level rwin since rcv_wup,
1129 : : * resync.
1130 : : */
1131 : 0 : tp->rcv_wnd += mptcp_rcv_wnd - subflow->rcv_wnd_sent;
1132 [ # ][ # ]: 0 : tcp_update_max_rcv_wnd_seq(tp);
1133 : 0 : subflow->rcv_wnd_sent = mptcp_rcv_wnd;
1134 : : }
1135 : :
1136 : 1924553 : static void ack_update_msk(struct mptcp_sock *msk,
1137 : : struct sock *ssk,
1138 : : const struct sk_buff *skb,
1139 : : struct mptcp_options_received *mp_opt)
1140 : : {
1141 : 1924553 : u64 new_wnd_end, new_snd_una, old_snd_una;
1142 : 1924553 : u32 win = ntohs(tcp_hdr(skb)->window);
1143 : 1924553 : struct sock *sk = (struct sock *)msk;
1144 : 1924553 : u64 snd_nxt;
1145 : :
1146 : 1924553 : mptcp_data_lock(sk);
1147 : :
1148 : : /* avoid ack expansion on update conflict, to reduce the risk of
1149 : : * wrongly expanding to a future ack sequence number, which is way
1150 : : * more dangerous than missing an ack
1151 : : */
1152 : 1924553 : old_snd_una = msk->snd_una;
1153 : 1924553 : snd_nxt = READ_ONCE(msk->snd_nxt);
1154 [ + ]: 1924553 : new_snd_una = mptcp_expand_seq(old_snd_una, mp_opt->data_ack, mp_opt->ack64);
1155 : :
1156 : : /* The active-open state sync can defer the snd_nxt update. Do not
1157 : : * accept an ACK against a reversed interval, or beyond snd_nxt.
1158 : : */
1159 [ + + ]: 1924553 : if (unlikely(before64(snd_nxt, old_snd_una) ||
1160 : : after64(new_snd_una, snd_nxt)))
1161 : : new_snd_una = old_snd_una;
1162 : :
1163 : : /* What the peer announced: tcp_sk(ssk)->snd_wnd can be larger, see
1164 : : * mptcp_check_allowed_size(), and is not always updated.
1165 : : */
1166 [ - ]: 1924553 : if (likely(!tcp_hdr(skb)->syn))
1167 [ + ]: 1924553 : win <<= tcp_sk(ssk)->rx_opt.snd_wscale;
1168 : 1924553 : new_wnd_end = new_snd_una + win;
1169 : :
1170 [ + ]: 1924553 : if (after64(new_wnd_end, msk->wnd_end))
1171 : 562383 : WRITE_ONCE(msk->wnd_end, new_wnd_end);
1172 : :
1173 : : /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */
1174 [ + ]: 1924553 : if (after64(msk->wnd_end, snd_nxt))
1175 : 1800482 : __mptcp_check_push(sk, ssk);
1176 : :
1177 [ + ]: 1924553 : if (after64(new_snd_una, old_snd_una)) {
1178 : 564643 : __mptcp_snd_una_update(msk, new_snd_una);
1179 : 564643 : __mptcp_data_acked(sk);
1180 : : }
1181 : 1924553 : msk->last_ack_recv = tcp_jiffies32;
1182 : 1924553 : mptcp_data_unlock(sk);
1183 : :
1184 : 1924553 : trace_ack_update_msk(mp_opt->data_ack,
1185 : : old_snd_una, new_snd_una,
1186 : 1924553 : new_wnd_end, READ_ONCE(msk->wnd_end));
1187 : 1924553 : }
1188 : :
1189 : 18931 : bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit)
1190 : : {
1191 : : /* Skip if DATA_FIN was already received.
1192 : : * If updating simultaneously with the recvmsg loop, values
1193 : : * should match. If they mismatch, the peer is misbehaving and
1194 : : * we will prefer the most recent information.
1195 : : */
1196 [ + + ][ + ]: 18931 : if (READ_ONCE(msk->rcv_data_fin))
1197 : : return false;
1198 : :
1199 [ + ][ + ]: 3229 : WRITE_ONCE(msk->rcv_data_fin_seq,
1200 : : mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
1201 : 3229 : WRITE_ONCE(msk->rcv_data_fin, 1);
1202 : :
1203 : 3229 : return true;
1204 : : }
1205 : :
1206 : 838 : static bool add_addr_hmac_valid(struct mptcp_sock *msk,
1207 : : struct mptcp_options_received *mp_opt)
1208 : : {
1209 : 838 : u64 hmac = 0;
1210 : :
1211 [ + ]: 838 : if (mp_opt->echo)
1212 : : return true;
1213 : :
1214 : 422 : hmac = add_addr_generate_hmac(READ_ONCE(msk->remote_key),
1215 : 422 : READ_ONCE(msk->local_key),
1216 : : &mp_opt->addr);
1217 : :
1218 [ - - ]: 422 : pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
1219 : : msk, hmac, mp_opt->ahmac);
1220 : :
1221 : 422 : return hmac == mp_opt->ahmac;
1222 : : }
1223 : :
1224 : 19308 : static bool mptcp_over_limit(struct sock *sk, struct sock *ssk,
1225 : : const struct sk_buff *skb)
1226 : : {
1227 [ + ]: 19308 : struct mptcp_sock *msk = mptcp_sk(sk);
1228 : 19308 : u32 rcvbuf = READ_ONCE(sk->sk_rcvbuf);
1229 : :
1230 [ - + ][ - + ]: 19308 : if (likely((u32)sk_rmem_alloc_get(sk) <= rcvbuf &&
1231 : : READ_ONCE(msk->backlog_len) <= rcvbuf))
1232 : : return false;
1233 : :
1234 : : /* Avoid silently dropping pure acks, fin, rst or already-acked segm. */
1235 [ # ][ # ]: 0 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq ||
1236 [ # # ][ # # ]: 0 : TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_FIN | TCPHDR_RST) ||
1237 [ # # ][ # # ]: 0 : !after(TCP_SKB_CB(skb)->end_seq, tcp_sk(ssk)->rcv_nxt))
1238 : : return false;
1239 : :
1240 : : /* Dropped due to memory constraints, schedule an ack. */
1241 : 0 : inet_csk(ssk)->icsk_ack.pending |= ICSK_ACK_NOMEM | ICSK_ACK_NOW;
1242 : 0 : inet_csk_schedule_ack(ssk);
1243 : :
1244 : : /* Plain TCP (fallback) and skb is dropped before the TCP recv queue. */
1245 : 0 : NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP);
1246 : :
1247 : 0 : return true;
1248 : : }
1249 : :
1250 : : /* Return false when the caller must drop the packet, i.e. in case of error,
1251 : : * subflow has been reset, or over memory limits.
1252 : : */
1253 : 1948724 : bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
1254 : : {
1255 [ + ]: 1948724 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1256 [ + ]: 1948724 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
1257 : 1948724 : struct mptcp_options_received mp_opt;
1258 : 1948724 : struct mptcp_ext *mpext;
1259 : :
1260 [ + ]: 1948724 : if (__mptcp_check_fallback(msk)) {
1261 : : /* Keep it simple and unconditionally trigger send data cleanup and
1262 : : * pending queue spooling. We will need to acquire the data lock
1263 : : * for more accurate checks, and once the lock is acquired, such
1264 : : * helpers are cheap.
1265 : : */
1266 : 19308 : mptcp_data_lock(subflow->conn);
1267 [ + ]: 19308 : if (sk_stream_memory_free(sk))
1268 : 19298 : __mptcp_check_push(subflow->conn, sk);
1269 : :
1270 : : /* on fallback we just need to ignore the msk-level snd_una, as
1271 : : * this is really plain TCP
1272 : : */
1273 : 19308 : __mptcp_snd_una_update(msk, READ_ONCE(msk->snd_nxt));
1274 : :
1275 : 19308 : __mptcp_data_acked(subflow->conn);
1276 : 19308 : mptcp_data_unlock(subflow->conn);
1277 : 19308 : return !mptcp_over_limit(subflow->conn, sk, skb);
1278 : : }
1279 : :
1280 : 1929416 : mptcp_get_options(skb, &mp_opt);
1281 : :
1282 : : /* The subflow can be in close state only if check_fully_established()
1283 : : * just sent a reset. If so, tell the caller to ignore the current packet.
1284 : : */
1285 [ + ]: 1929416 : if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
1286 : 65 : return sk->sk_state != TCP_CLOSE;
1287 : :
1288 [ + ][ + ]: 1929351 : if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
1289 [ + ][ + ]: 116888 : if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
1290 [ + ][ + ]: 265 : READ_ONCE(msk->local_key) == mp_opt.fc_recv_key) {
1291 : 255 : WRITE_ONCE(msk->rcv_fastclose, true);
1292 : 255 : mptcp_schedule_work((struct sock *)msk);
1293 [ - ][ - ]: 255 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX);
1294 : : }
1295 : :
1296 [ + - ][ + - ]: 117726 : if ((mp_opt.suboptions & OPTION_MPTCP_ADD_ADDR) &&
1297 : 838 : add_addr_hmac_valid(msk, &mp_opt)) {
1298 [ + ][ + ]: 838 : if (!mp_opt.echo) {
1299 : 422 : mptcp_pm_add_addr_received(sk, &mp_opt.addr);
1300 [ - ][ # ]: 422 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
1301 : : } else {
1302 : 416 : mptcp_pm_add_addr_echoed(msk, &mp_opt.addr);
1303 [ - ][ - ]: 416 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
1304 : : }
1305 : :
1306 [ + ][ + ]: 838 : if (mp_opt.addr.port)
1307 [ - ][ # ]: 96 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD);
1308 : : }
1309 : :
1310 [ + ][ + ]: 116888 : if (mp_opt.suboptions & OPTION_MPTCP_RM_ADDR)
1311 : 108 : mptcp_pm_rm_addr_received(msk, &mp_opt.rm_list);
1312 : :
1313 [ + ][ + ]: 116888 : if (mp_opt.suboptions & OPTION_MPTCP_PRIO) {
1314 : 40 : mptcp_pm_mp_prio_received(sk, mp_opt.backup);
1315 [ - ][ # ]: 40 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIORX);
1316 : : }
1317 : :
1318 [ + ][ + ]: 116888 : if (mp_opt.suboptions & OPTION_MPTCP_FAIL) {
1319 : 6 : mptcp_pm_mp_fail_received(sk, mp_opt.fail_seq);
1320 [ - ][ # ]: 6 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILRX);
1321 : : }
1322 : :
1323 [ + ][ + ]: 116888 : if (mp_opt.suboptions & OPTION_MPTCP_RST) {
1324 : 248 : subflow->reset_seen = 1;
1325 : 248 : subflow->reset_reason = mp_opt.reset_reason;
1326 : 248 : subflow->reset_transient = mp_opt.reset_transient;
1327 [ - ][ - ]: 248 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTRX);
1328 : : }
1329 : :
1330 [ + ][ + ]: 116888 : if (!(mp_opt.suboptions & OPTION_MPTCP_DSS))
1331 : : return true;
1332 : : }
1333 : :
1334 : : /* we can't wait for recvmsg() to update the ack_seq, otherwise
1335 : : * monodirectional flows will stuck
1336 : : */
1337 [ + ][ + ]: 1925724 : if (mp_opt.use_ack)
1338 : 1924553 : ack_update_msk(msk, sk, skb, &mp_opt);
1339 : 1925724 : rwin_update(msk, sk, skb);
1340 : :
1341 : : /* Zero-data-length packets are dropped by the caller and not
1342 : : * propagated to the MPTCP layer, so the skb extension does not
1343 : : * need to be allocated or populated. DATA_FIN information, if
1344 : : * present, needs to be updated here before the skb is freed.
1345 : : */
1346 [ + ][ + ]: 1925724 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
1347 [ + - + ]: 751084 : if (mp_opt.data_fin && mp_opt.data_len == 1 &&
[ + - + ]
1348 : 15824 : mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
1349 : 3004 : mptcp_schedule_work((struct sock *)msk);
1350 : :
1351 : 735260 : return true;
1352 : : }
1353 : :
1354 : 1190464 : mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
1355 [ - ][ - ]: 1190464 : if (!mpext)
1356 : : return false;
1357 : :
1358 : 1190464 : memset(mpext, 0, sizeof(*mpext));
1359 : :
1360 [ + ][ + ]: 1190464 : if (likely(mp_opt.use_map)) {
1361 [ + ][ + ]: 1187416 : if (mp_opt.mpc_map) {
1362 : : /* this is an MP_CAPABLE carrying MPTCP data
1363 : : * we know this map the first chunk of data
1364 : : */
1365 : 1171 : mptcp_crypto_key_sha(subflow->remote_key, NULL,
1366 : : &mpext->data_seq);
1367 : 1171 : mpext->data_seq++;
1368 : 1171 : mpext->subflow_seq = 1;
1369 : 1171 : mpext->dsn64 = 1;
1370 : 1171 : mpext->mpc_map = 1;
1371 : 1171 : mpext->data_fin = 0;
1372 : : } else {
1373 : 1186245 : mpext->data_seq = mp_opt.data_seq;
1374 : 1186245 : mpext->subflow_seq = mp_opt.subflow_seq;
1375 : 1186245 : mpext->dsn64 = mp_opt.dsn64;
1376 : 1186245 : mpext->data_fin = mp_opt.data_fin;
1377 : : }
1378 : 1187416 : mpext->data_len = mp_opt.data_len;
1379 : 1187416 : mpext->use_map = 1;
1380 : 1187416 : mpext->csum_reqd = !!(mp_opt.suboptions & OPTION_MPTCP_CSUMREQD);
1381 : :
1382 [ + ][ + ]: 1187416 : if (mpext->csum_reqd)
1383 : 108908 : mpext->csum = mp_opt.csum;
1384 : : }
1385 : :
1386 : : return true;
1387 : : }
1388 : :
1389 : 1557505 : static u64 mptcp_set_rwin(struct mptcp_sock *msk, struct tcp_sock *tp,
1390 : : struct tcphdr *th, u64 ack_seq)
1391 : : {
1392 : 1557505 : const struct sock *ssk = (const struct sock *)tp;
1393 : 1557505 : u64 rcv_wnd_old, rcv_wnd_new;
1394 : 1557505 : u32 new_win;
1395 : 1557505 : u64 win;
1396 : :
1397 : 1557505 : rcv_wnd_new = ack_seq + tp->rcv_wnd;
1398 : :
1399 [ + + ]: 1557505 : rcv_wnd_old = atomic64_read(&msk->rcv_wnd_sent);
1400 [ + + ][ + + ]: 1557505 : if (after64(rcv_wnd_new, rcv_wnd_old)) {
1401 : 86 : u64 rcv_wnd;
1402 : :
1403 : 623046 : for (;;) {
1404 : 623132 : rcv_wnd = atomic64_cmpxchg(&msk->rcv_wnd_sent, rcv_wnd_old, rcv_wnd_new);
1405 : :
1406 [ + ][ + ]: 623046 : if (rcv_wnd == rcv_wnd_old)
1407 : : break;
1408 : :
1409 : 2 : rcv_wnd_old = rcv_wnd;
1410 [ + ][ # ]: 2 : if (before64(rcv_wnd_new, rcv_wnd_old)) {
1411 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICTUPDATE);
1412 : 0 : goto raise_win;
1413 : : }
1414 [ - ][ - ]: 88 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICT);
1415 : : }
1416 : 623044 : goto update_wspace;
1417 : : }
1418 : :
1419 [ + ][ + ]: 934461 : if (rcv_wnd_new != rcv_wnd_old) {
1420 : 325441 : raise_win:
1421 : : /* The msk-level rcv wnd is after the tcp level one,
1422 : : * sync the latter.
1423 : : */
1424 : 325441 : rcv_wnd_new = rcv_wnd_old;
1425 : 325441 : win = rcv_wnd_old - ack_seq;
1426 : 325441 : new_win = min_t(u64, win, U32_MAX);
1427 : 325441 : tp->rcv_wnd = new_win;
1428 [ + ][ + ]: 325441 : tcp_update_max_rcv_wnd_seq(tp);
1429 : :
1430 : : /* Make sure we do not exceed the maximum possible
1431 : : * scaled window.
1432 : : */
1433 [ + ][ + ]: 325441 : if (unlikely(th->syn))
1434 : 0 : new_win = min(new_win, 65535U) << tp->rx_opt.rcv_wscale;
1435 [ + ][ + - ]: 325441 : if (!tp->rx_opt.rcv_wscale &&
1436 [ # ][ # ]: 0 : READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_workaround_signed_windows))
1437 : 0 : new_win = min(new_win, MAX_TCP_WINDOW);
1438 : : else
1439 : 325441 : new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale));
1440 : :
1441 : : /* RFC1323 scaling applied */
1442 : 325441 : new_win >>= tp->rx_opt.rcv_wscale;
1443 : 325441 : th->window = htons(new_win);
1444 [ - ][ # ]: 325441 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDSHARED);
1445 : : }
1446 : :
1447 : 609020 : update_wspace:
1448 : 1557505 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1449 : 1557505 : return rcv_wnd_new;
1450 : : }
1451 : :
1452 : 21741 : static void mptcp_track_rwin(struct tcp_sock *tp)
1453 : : {
1454 : 21741 : const struct sock *ssk = (const struct sock *)tp;
1455 : 21741 : struct mptcp_subflow_context *subflow;
1456 : 21741 : struct mptcp_sock *msk;
1457 : :
1458 [ - ]: 21741 : if (!ssk)
1459 : : return;
1460 : :
1461 [ + ]: 21741 : subflow = mptcp_subflow_ctx(ssk);
1462 [ + ]: 21741 : msk = mptcp_sk(subflow->conn);
1463 : 21741 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1464 : : }
1465 : :
1466 : 174397 : __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
1467 : : {
1468 : 174397 : struct csum_pseudo_header header;
1469 : 174397 : __wsum csum;
1470 : :
1471 : : /* cfr RFC 8684 3.3.1.:
1472 : : * the data sequence number used in the pseudo-header is
1473 : : * always the 64-bit value, irrespective of what length is used in the
1474 : : * DSS option itself.
1475 : : */
1476 : 174397 : header.data_seq = cpu_to_be64(data_seq);
1477 : 174397 : header.subflow_seq = htonl(subflow_seq);
1478 : 174397 : header.data_len = htons(data_len);
1479 : 174397 : header.csum = 0;
1480 : :
1481 : 174397 : csum = csum_partial(&header, sizeof(header), sum);
1482 : 174397 : return csum_fold(csum);
1483 : : }
1484 : :
1485 : 113519 : static __sum16 mptcp_make_csum(const struct mptcp_ext *mpext)
1486 : : {
1487 : 227038 : return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
1488 : 113519 : ~csum_unfold(mpext->csum));
1489 : : }
1490 : :
1491 : 0 : static void put_len_csum(u16 len, __sum16 csum, void *data)
1492 : : {
1493 : 113603 : __sum16 *sumptr = data + 2;
1494 : 113603 : __be16 *ptr = data;
1495 : :
1496 : 113603 : put_unaligned_be16(len, ptr);
1497 : :
1498 : 113603 : put_unaligned(csum, sumptr);
1499 : 113603 : }
1500 : :
1501 : 1588511 : void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp,
1502 : : struct mptcp_out_options *opts)
1503 : : {
1504 : 1588511 : const struct sock *ssk = (const struct sock *)tp;
1505 : 1588511 : struct mptcp_subflow_context *subflow;
1506 : :
1507 : : /* Which options can be used together?
1508 : : *
1509 : : * X: mutually exclusive
1510 : : * O: often used together
1511 : : * C: can be used together in some cases
1512 : : * P: could be used together but we prefer not to (optimisations)
1513 : : *
1514 : : * Opt: | MPC | MPJ | DSS | ADD | RM | PRIO | FAIL | FC |
1515 : : * ------|------|------|------|------|------|------|------|------|
1516 : : * MPC |------|------|------|------|------|------|------|------|
1517 : : * MPJ | X |------|------|------|------|------|------|------|
1518 : : * DSS | X | X |------|------|------|------|------|------|
1519 : : * ADD | X | X | P |------|------|------|------|------|
1520 : : * RM | C | C | C | P |------|------|------|------|
1521 : : * PRIO | X | C | C | C | C |------|------|------|
1522 : : * FAIL | X | X | C | X | X | X |------|------|
1523 : : * FC | X | X | P | X | X | X | X |------|
1524 : : * RST | X | X | X | X | X | X | O | O |
1525 : : * ------|------|------|------|------|------|------|------|------|
1526 : : *
1527 : : * The same applies in mptcp_established_options() function.
1528 : : */
1529 [ + ]: 1588511 : if (likely(OPTION_MPTCP_DSS & opts->suboptions)) {
1530 : 1557505 : struct mptcp_ext *mpext = &opts->ext_copy;
1531 : 1557505 : u8 len = TCPOLEN_MPTCP_DSS_BASE;
1532 : 1557505 : u8 flags = 0;
1533 : :
1534 [ - ]: 1557505 : if (mpext->use_ack) {
1535 : 1557505 : flags = MPTCP_DSS_HAS_ACK;
1536 [ + ]: 1557505 : if (mpext->ack64) {
1537 : : len += TCPOLEN_MPTCP_DSS_ACK64;
1538 : : flags |= MPTCP_DSS_ACK64;
1539 : : } else {
1540 : 65918 : len += TCPOLEN_MPTCP_DSS_ACK32;
1541 : : }
1542 : : }
1543 : :
1544 [ + ]: 1557505 : if (mpext->use_map) {
1545 : 799353 : len += TCPOLEN_MPTCP_DSS_MAP64;
1546 : :
1547 : : /* Use only 64-bit mapping flags for now, add
1548 : : * support for optional 32-bit mappings later.
1549 : : */
1550 : 799353 : flags |= MPTCP_DSS_HAS_MAP | MPTCP_DSS_DSN64;
1551 [ + ]: 799353 : if (mpext->data_fin)
1552 : 19383 : flags |= MPTCP_DSS_DATA_FIN;
1553 : :
1554 [ + ]: 799353 : if (opts->csum_reqd)
1555 : 113521 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1556 : : }
1557 : :
1558 [ - ]: 1557505 : *ptr++ = mptcp_option(MPTCPOPT_DSS, len, 0, flags);
1559 : :
1560 [ - ]: 1557505 : if (mpext->use_ack) {
1561 : 1557505 : struct mptcp_sock *msk;
1562 : 1557505 : u64 ack_seq;
1563 : :
1564 : : /* DSS option is set only by mptcp_established_options,
1565 : : * the caller is __tcp_transmit_skb() and ssk is always
1566 : : * not NULL.
1567 : : */
1568 [ + ]: 1557505 : subflow = mptcp_subflow_ctx(ssk);
1569 [ + ]: 1557505 : msk = mptcp_sk(subflow->conn);
1570 : 1557505 : ack_seq = READ_ONCE(msk->ack_seq);
1571 [ + ]: 1557505 : if (mpext->ack64) {
1572 : 1491587 : put_unaligned_be64(ack_seq, ptr);
1573 : 1491587 : ptr += 2;
1574 : : } else {
1575 : 65918 : put_unaligned_be32(ack_seq, ptr);
1576 : 65918 : ptr += 1;
1577 : : }
1578 : 1557505 : subflow->rcv_wnd_sent = mptcp_set_rwin(msk, tp, th,
1579 : : ack_seq);
1580 : : }
1581 : :
1582 [ + ]: 1557505 : if (mpext->use_map) {
1583 [ + ]: 799353 : put_unaligned_be64(mpext->data_seq, ptr);
1584 : 799353 : ptr += 2;
1585 [ + ]: 799353 : put_unaligned_be32(mpext->subflow_seq, ptr);
1586 : 799353 : ptr += 1;
1587 [ + ]: 799353 : if (opts->csum_reqd) {
1588 : : /* data_len == 0 is reserved for the infinite mapping,
1589 : : * the checksum will also be set to 0.
1590 : : */
1591 : 113521 : put_len_csum(mpext->data_len,
1592 [ + ]: 113521 : (mpext->data_len ? mptcp_make_csum(mpext) : 0),
1593 : : ptr);
1594 : : } else {
1595 : 685832 : put_unaligned_be32(mpext->data_len << 16 |
1596 : 685832 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1597 : : }
1598 : 799353 : ptr += 1;
1599 : : }
1600 : :
1601 : : /* We might need to add MP_FAIL options in rare cases */
1602 [ + ]: 1557505 : if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions))
1603 : 4 : goto mp_fail;
1604 [ + ]: 31006 : } else if (OPTIONS_MPTCP_MPC & opts->suboptions) {
1605 : 5870 : u8 len, flag = MPTCP_CAP_HMAC_SHA256;
1606 : :
1607 [ + ]: 5870 : if (OPTION_MPTCP_MPC_SYN & opts->suboptions) {
1608 : : len = TCPOLEN_MPTCP_MPC_SYN;
1609 [ + ]: 4113 : } else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) {
1610 : : len = TCPOLEN_MPTCP_MPC_SYNACK;
1611 [ + ]: 2421 : } else if (opts->data_len) {
1612 : 936 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
1613 [ + ]: 936 : if (opts->csum_reqd)
1614 : 82 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1615 : : } else {
1616 : : len = TCPOLEN_MPTCP_MPC_ACK;
1617 : : }
1618 : :
1619 [ + ]: 5870 : if (opts->csum_reqd)
1620 : 456 : flag |= MPTCP_CAP_CHECKSUM_REQD;
1621 : :
1622 [ + ]: 5870 : if (!opts->allow_join_id0)
1623 : 34 : flag |= MPTCP_CAP_DENY_JOIN_ID0;
1624 : :
1625 [ + ]: 5870 : *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len,
1626 : : MPTCP_SUPPORTED_VERSION,
1627 : : flag);
1628 : :
1629 : 5870 : if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
1630 [ + ]: 5870 : opts->suboptions))
1631 : 1757 : goto mp_capable_done;
1632 : :
1633 [ + ]: 4113 : put_unaligned_be64(opts->sndr_key, ptr);
1634 : 4113 : ptr += 2;
1635 [ + ]: 4113 : if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))
1636 : 1692 : goto mp_capable_done;
1637 : :
1638 [ + ]: 2421 : put_unaligned_be64(opts->rcvr_key, ptr);
1639 : 2421 : ptr += 2;
1640 [ + ]: 2421 : if (!opts->data_len)
1641 : 1485 : goto mp_capable_done;
1642 : :
1643 [ + ]: 936 : if (opts->csum_reqd) {
1644 : 82 : put_len_csum(opts->data_len,
1645 : 82 : __mptcp_make_csum(opts->data_seq,
1646 : : opts->subflow_seq,
1647 : : opts->data_len,
1648 : 82 : ~csum_unfold(opts->csum)),
1649 : : ptr);
1650 : : } else {
1651 : 854 : put_unaligned_be32(opts->data_len << 16 |
1652 : 854 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1653 : : }
1654 : 936 : ptr += 1;
1655 : :
1656 : : /* MPC is additionally mutually exclusive with MP_PRIO */
1657 : 936 : goto mp_capable_done;
1658 [ + ]: 25136 : } else if (OPTIONS_MPTCP_MPJ & opts->suboptions) {
1659 [ + ]: 1954 : if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
1660 : 709 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1661 : : TCPOLEN_MPTCP_MPJ_SYN,
1662 : 709 : opts->backup, opts->join_id);
1663 : 709 : put_unaligned_be32(opts->token, ptr);
1664 : 709 : ptr += 1;
1665 : 709 : put_unaligned_be32(opts->nonce, ptr);
1666 : 709 : ptr += 1;
1667 [ + ]: 1245 : } else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
1668 : 636 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1669 : : TCPOLEN_MPTCP_MPJ_SYNACK,
1670 : 636 : opts->backup, opts->join_id);
1671 : 636 : put_unaligned_be64(opts->thmac, ptr);
1672 : 636 : ptr += 2;
1673 : 636 : put_unaligned_be32(opts->nonce, ptr);
1674 : 636 : ptr += 1;
1675 : : } else {
1676 : 609 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1677 : : TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
1678 : 609 : memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
1679 : 609 : ptr += 5;
1680 : : }
1681 [ + ]: 23182 : } else if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
1682 : 902 : u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
1683 : 902 : u8 echo = MPTCP_ADDR_ECHO;
1684 : :
1685 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1686 [ + ]: 902 : if (opts->addr.family == AF_INET6)
1687 : 210 : len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
1688 : : #endif
1689 : :
1690 [ + ]: 902 : if (opts->addr.port)
1691 : 96 : len += TCPOLEN_MPTCP_PORT_LEN;
1692 : :
1693 [ + ]: 902 : if (opts->ahmac) {
1694 : 490 : len += sizeof(opts->ahmac);
1695 : 490 : echo = 0;
1696 : : }
1697 : :
1698 : 902 : *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
1699 [ + ]: 902 : len, echo, opts->addr.id);
1700 [ + ]: 902 : if (opts->addr.family == AF_INET) {
1701 : 692 : memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
1702 : 692 : ptr += 1;
1703 : : }
1704 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1705 [ - ]: 210 : else if (opts->addr.family == AF_INET6) {
1706 : 210 : memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
1707 : 210 : ptr += 4;
1708 : : }
1709 : : #endif
1710 : :
1711 [ + ]: 902 : if (!opts->addr.port) {
1712 [ + ]: 806 : if (opts->ahmac) {
1713 : 436 : put_unaligned_be64(opts->ahmac, ptr);
1714 : 436 : ptr += 2;
1715 : : }
1716 : : } else {
1717 : 96 : u16 port = ntohs(opts->addr.port);
1718 : :
1719 [ + ]: 96 : if (opts->ahmac) {
1720 : 54 : u8 *bptr = (u8 *)ptr;
1721 : :
1722 : 54 : put_unaligned_be16(port, bptr);
1723 : 54 : bptr += 2;
1724 : 54 : put_unaligned_be64(opts->ahmac, bptr);
1725 : 54 : bptr += 8;
1726 : 54 : put_unaligned_be16(TCPOPT_NOP << 8 |
1727 : : TCPOPT_NOP, bptr);
1728 : :
1729 : 54 : ptr += 3;
1730 : : } else {
1731 : 42 : put_unaligned_be32(port << 16 |
1732 : 42 : TCPOPT_NOP << 8 |
1733 : : TCPOPT_NOP, ptr);
1734 : 42 : ptr += 1;
1735 : : }
1736 : : }
1737 [ + ]: 22280 : } else if (unlikely(OPTION_MPTCP_FASTCLOSE & opts->suboptions)) {
1738 : : /* FASTCLOSE is mutually exclusive with others except RST */
1739 : 484 : *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
1740 : : TCPOLEN_MPTCP_FASTCLOSE,
1741 : : 0, 0);
1742 [ - ][ - ]: 484 : put_unaligned_be64(opts->rcvr_key, ptr);
1743 : 484 : ptr += 2;
1744 : :
1745 [ - ][ - ]: 484 : if (OPTION_MPTCP_RST & opts->suboptions)
1746 : 484 : goto mp_rst;
1747 : : return;
1748 [ + ]: 21796 : } else if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions)) {
1749 : 2 : mp_fail:
1750 : : /* MP_FAIL is mutually exclusive with others except RST */
1751 [ + ][ + ]: 6 : subflow = mptcp_subflow_ctx(ssk);
1752 : 6 : subflow->send_mp_fail = 0;
1753 : :
1754 : 6 : *ptr++ = mptcp_option(MPTCPOPT_MP_FAIL,
1755 : : TCPOLEN_MPTCP_FAIL,
1756 : : 0, 0);
1757 [ + ][ + ]: 6 : put_unaligned_be64(opts->fail_seq, ptr);
1758 : 6 : ptr += 2;
1759 : :
1760 [ + ][ + ]: 6 : if (OPTION_MPTCP_RST & opts->suboptions)
1761 : 2 : goto mp_rst;
1762 : : return;
1763 [ + ]: 21794 : } else if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
1764 : 53 : mp_rst:
1765 : 539 : *ptr++ = mptcp_option(MPTCPOPT_RST,
1766 : : TCPOLEN_MPTCP_RST,
1767 : 539 : opts->reset_transient,
1768 : 539 : opts->reset_reason);
1769 : 539 : return;
1770 [ - ]: 21741 : } else if (unlikely(!opts->suboptions)) {
1771 : : /* Fallback to TCP */
1772 : 21741 : mptcp_track_rwin(tp);
1773 : 21741 : return;
1774 : : }
1775 : :
1776 [ + ]: 1560357 : if (OPTION_MPTCP_PRIO & opts->suboptions) {
1777 [ - ]: 28 : subflow = mptcp_subflow_ctx(ssk);
1778 : 28 : subflow->send_mp_prio = 0;
1779 : :
1780 : 28 : *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO,
1781 : : TCPOLEN_MPTCP_PRIO,
1782 [ - ]: 28 : opts->backup, TCPOPT_NOP);
1783 : :
1784 [ - ][ # ]: 28 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPPRIOTX);
1785 : : }
1786 : :
1787 : 1560329 : mp_capable_done:
1788 [ + ][ + ]: 1566227 : if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
1789 : 114 : u8 i = 1;
1790 : :
1791 : 114 : *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
1792 : 114 : TCPOLEN_MPTCP_RM_ADDR_BASE + opts->rm_list.nr,
1793 : 114 : 0, opts->rm_list.ids[0]);
1794 : :
1795 [ + ][ + ]: 118 : while (i < opts->rm_list.nr) {
1796 : 4 : u8 id1, id2, id3, id4;
1797 : :
1798 : 4 : id1 = opts->rm_list.ids[i];
1799 [ - ][ - ]: 4 : id2 = i + 1 < opts->rm_list.nr ? opts->rm_list.ids[i + 1] : TCPOPT_NOP;
1800 [ + ][ + ]: 4 : id3 = i + 2 < opts->rm_list.nr ? opts->rm_list.ids[i + 2] : TCPOPT_NOP;
1801 [ + ][ + ]: 4 : id4 = i + 3 < opts->rm_list.nr ? opts->rm_list.ids[i + 3] : TCPOPT_NOP;
1802 : 4 : put_unaligned_be32(id1 << 24 | id2 << 16 | id3 << 8 | id4, ptr);
1803 : 4 : ptr += 1;
1804 : 4 : i += 4;
1805 : : }
1806 : : }
1807 : : }
1808 : :
1809 : 16 : __be32 mptcp_get_reset_option(const struct sk_buff *skb)
1810 : : {
1811 [ - ]: 16 : const struct mptcp_ext *ext = mptcp_get_ext(skb);
1812 : 16 : u8 flags, reason;
1813 : :
1814 [ - ]: 16 : if (ext) {
1815 : 16 : flags = ext->reset_transient;
1816 : 16 : reason = ext->reset_reason;
1817 : :
1818 : 16 : return mptcp_option(MPTCPOPT_RST, TCPOLEN_MPTCP_RST,
1819 : : flags, reason);
1820 : : }
1821 : :
1822 : : return htonl(0u);
1823 : : }
1824 : : EXPORT_SYMBOL_GPL(mptcp_get_reset_option);
|