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 : 1886436 : 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 : 1886436 : u8 subtype = *ptr >> 4;
28 : 1886436 : int expected_opsize;
29 : 1886436 : u16 subopt;
30 : 1886436 : u8 version;
31 : 1886436 : u8 flags;
32 : 1886436 : u8 i;
33 : :
34 [ + + + + : 1886436 : switch (subtype) {
+ + + + +
- ][ + + +
+ + + + +
+ - ]
35 : 7684 : case MPTCPOPT_MP_CAPABLE:
36 : : /* strict size checking */
37 [ + ]: 7684 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
38 [ + ]: 4416 : if (skb->len > tcp_hdr(skb)->doff << 2)
39 : : expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
40 : : else
41 : 3311 : expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
42 : 4416 : 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 : 4416 : if (subopt == OPTION_MPTCP_MPC_ACK) {
55 [ + - ][ + - ]: 4416 : 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 [ + ]: 7684 : if (opsize != expected_opsize &&
72 : 120 : (expected_opsize != TCPOLEN_MPTCP_MPC_ACK_DATA ||
73 [ + ][ + ]: 120 : opsize != TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM))
74 : : break;
75 : :
76 : : /* try to be gentle vs future versions on the initial syn */
77 : 7672 : version = *ptr++ & MPTCP_VERSION_MASK;
78 [ + ]: 7672 : if (opsize != TCPOLEN_MPTCP_MPC_SYN) {
79 [ + + ][ + + ]: 5912 : if (version != MPTCP_SUPPORTED_VERSION)
80 : : break;
81 [ - ][ - ]: 1760 : } else if (version < MPTCP_SUPPORTED_VERSION) {
82 : : break;
83 : : }
84 : :
85 : 7666 : flags = *ptr++;
86 [ + + ][ + + ]: 7666 : 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 : 7630 : if ((flags & MPTCP_CAP_CHECKSUM_REQD) &&
97 [ + ]: 7630 : opsize < TCPOLEN_MPTCP_MPC_ACK_DATA)
98 : 476 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
99 : :
100 : 7630 : mp_opt->deny_join_id0 = !!(flags & MPTCP_CAP_DENY_JOIN_ID0);
101 : :
102 : 7630 : mp_opt->suboptions |= subopt;
103 [ + ]: 7630 : if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) {
104 [ + ]: 5882 : mp_opt->sndr_key = get_unaligned_be64(ptr);
105 : 5882 : ptr += 8;
106 : : }
107 [ + ]: 5882 : if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
108 [ + ]: 4398 : mp_opt->rcvr_key = get_unaligned_be64(ptr);
109 : 4398 : ptr += 8;
110 : : }
111 [ + ]: 4398 : 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 : 1105 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
118 : 1105 : mp_opt->use_map = 1;
119 : 1105 : mp_opt->mpc_map = 1;
120 [ + ]: 1105 : mp_opt->data_len = get_unaligned_be16(ptr);
121 : 1105 : ptr += 2;
122 : : }
123 [ + ]: 1105 : if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) {
124 : 108 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
125 : 108 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
126 : 108 : ptr += 2;
127 : : }
128 [ - - - - : 7630 : 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 : 2486 : case MPTCPOPT_MP_JOIN:
137 : : /* Can be used with a restricted number of other options */
138 [ - ][ - ]: 2486 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_RM_ADDR |
139 : : OPTION_MPTCP_PRIO)) != 0)
140 : : break;
141 : :
142 [ + ]: 2486 : 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 [ + ]: 1846 : } 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 [ - ][ - ]: 1252 : } else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) {
165 : 1252 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_ACK;
166 : 1252 : ptr += 2;
167 : 1252 : memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN);
168 [ - - ][ - - ]: 1252 : pr_debug("MP_JOIN hmac\n");
169 : : }
170 : : break;
171 : :
172 : 1874735 : case MPTCPOPT_DSS:
173 : : /* Can be used with a restricted number of other options */
174 [ - ][ - ]: 1874735 : 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 [ - - ]: 1874735 : pr_debug("DSS\n");
182 : 1874735 : ptr++;
183 : :
184 : 1874735 : flags = (*ptr++) & MPTCP_DSS_FLAG_MASK;
185 : 1874735 : mp_opt->dsn64 = (flags & MPTCP_DSS_DSN64) != 0;
186 : 1874735 : mp_opt->use_map = (flags & MPTCP_DSS_HAS_MAP) != 0;
187 : 1874735 : mp_opt->ack64 = (flags & MPTCP_DSS_ACK64) != 0;
188 : 1874735 : mp_opt->use_ack = (flags & MPTCP_DSS_HAS_ACK);
189 : :
190 : 1874735 : expected_opsize = TCPOLEN_MPTCP_DSS_BASE;
191 : :
192 [ - ]: 1874735 : if (mp_opt->use_ack) {
193 [ + ]: 1874735 : if (mp_opt->ack64)
194 : : expected_opsize += TCPOLEN_MPTCP_DSS_ACK64;
195 : : else
196 : 230471 : expected_opsize += TCPOLEN_MPTCP_DSS_ACK32;
197 : : }
198 : :
199 [ + ]: 1874735 : if (mp_opt->use_map) {
200 : 1200193 : mp_opt->data_fin = (flags & MPTCP_DSS_DATA_FIN) != 0;
201 [ + ]: 1200193 : if (mp_opt->dsn64)
202 : 1200151 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP64;
203 : : else
204 : 42 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP32;
205 : : }
206 : :
207 [ - - ]: 1874735 : 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 [ + ]: 1874735 : if (opsize != expected_opsize &&
216 [ + ]: 302270 : 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 : 1874735 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
226 [ - ]: 1874735 : if (mp_opt->use_ack) {
227 [ + ]: 1874735 : if (mp_opt->ack64) {
228 : 1644264 : mp_opt->data_ack = get_unaligned_be64(ptr);
229 : 1644264 : ptr += 8;
230 : : } else {
231 : 230471 : mp_opt->data_ack = get_unaligned_be32(ptr);
232 : 230471 : ptr += 4;
233 : : }
234 : :
235 [ - - ]: 1874735 : pr_debug("data_ack=%llu\n", mp_opt->data_ack);
236 : : }
237 : :
238 [ + ][ + ]: 1874735 : if (mp_opt->use_map) {
239 [ + ]: 1200193 : if (mp_opt->dsn64) {
240 : 1200151 : mp_opt->data_seq = get_unaligned_be64(ptr);
241 : 1200151 : ptr += 8;
242 : : } else {
243 : 42 : mp_opt->data_seq = get_unaligned_be32(ptr);
244 : 42 : ptr += 4;
245 : : }
246 : :
247 [ + ]: 1200193 : mp_opt->subflow_seq = get_unaligned_be32(ptr);
248 : 1200193 : ptr += 4;
249 : :
250 [ + ]: 1200193 : mp_opt->data_len = get_unaligned_be16(ptr);
251 : 1200193 : ptr += 2;
252 : :
253 [ + ]: 1200193 : if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
254 : 302270 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
255 : 302270 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
256 : 302270 : ptr += 2;
257 : : }
258 : :
259 [ - - - ]: 1200193 : 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 : 841 : case MPTCPOPT_ADD_ADDR:
268 : : /* Can be used with a restricted number of other options */
269 [ - ][ - ]: 841 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
270 : : OPTION_MPTCP_RM_ADDR |
271 : : OPTION_MPTCP_PRIO)) != 0)
272 : : break;
273 : :
274 : 841 : mp_opt->echo = (*ptr++) & MPTCP_ADDR_ECHO;
275 [ + ]: 841 : if (!mp_opt->echo) {
276 : 425 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR ||
277 [ + ]: 425 : opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT)
278 : 331 : mp_opt->addr.family = AF_INET;
279 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
280 : 94 : else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 ||
281 [ - ][ - ]: 94 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT)
282 : 94 : 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 : 841 : mp_opt->suboptions |= OPTION_MPTCP_ADD_ADDR;
300 : 841 : mp_opt->addr.id = *ptr++;
301 : 841 : mp_opt->addr.port = 0;
302 : 841 : mp_opt->ahmac = 0;
303 [ + ]: 841 : if (mp_opt->addr.family == AF_INET) {
304 : 649 : memcpy((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr, 4);
305 : 649 : ptr += 4;
306 : 649 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
307 [ + ]: 649 : 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 : 192 : memcpy(mp_opt->addr.addr6.s6_addr, (u8 *)ptr, 16);
315 : 192 : ptr += 16;
316 : 192 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
317 [ + ]: 192 : 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 [ + ]: 841 : if (!mp_opt->echo) {
324 : 425 : mp_opt->ahmac = get_unaligned_be64(ptr);
325 : 425 : ptr += 8;
326 : : }
327 [ - - - ]: 841 : 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 : 261 : case MPTCPOPT_MP_FASTCLOSE:
371 : : /* Can be used with a restricted number of other options */
372 [ - ][ - ]: 261 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
373 : : OPTION_MPTCP_RST)) != 0)
374 : : break;
375 : :
376 [ - ][ - ]: 261 : if (opsize != TCPOLEN_MPTCP_FASTCLOSE)
377 : : break;
378 : :
379 : 261 : ptr += 2;
380 [ - ][ - ]: 261 : mp_opt->fc_recv_key = get_unaligned_be64(ptr);
381 : 261 : ptr += 8;
382 : 261 : mp_opt->suboptions |= OPTION_MPTCP_FASTCLOSE;
383 [ - - ][ - - ]: 261 : pr_debug("MP_FASTCLOSE: recv_key=%llu\n", mp_opt->fc_recv_key);
384 : : break;
385 : :
386 : 269 : case MPTCPOPT_RST:
387 : : /* Can be used with a restricted number of other options */
388 [ - ][ - ]: 269 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_FAIL |
389 : : OPTION_MPTCP_FASTCLOSE)) != 0)
390 : : break;
391 : :
392 [ - ][ - ]: 269 : if (opsize != TCPOLEN_MPTCP_RST)
393 : : break;
394 : :
395 [ + ][ + ]: 269 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST))
396 : : break;
397 : :
398 : 257 : mp_opt->suboptions |= OPTION_MPTCP_RST;
399 : 257 : flags = *ptr++;
400 : 257 : mp_opt->reset_transient = flags & MPTCP_RST_TRANSIENT;
401 : 257 : mp_opt->reset_reason = *ptr;
402 [ - - ][ - - ]: 257 : 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 : 1886436 : }
425 : :
426 : 1886651 : void mptcp_get_options(const struct sk_buff *skb,
427 : : struct mptcp_options_received *mp_opt)
428 : : {
429 : 1886651 : const struct tcphdr *th = tcp_hdr(skb);
430 : 1886651 : const unsigned char *ptr;
431 : 1886651 : int length;
432 : :
433 : : /* Ensure that casting the whole status to u32 is efficient and safe */
434 : 1886651 : BUILD_BUG_ON(sizeof_field(struct mptcp_options_received, status) != sizeof(u32));
435 : 1886651 : BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct mptcp_options_received, status),
436 : : sizeof(u32)));
437 : 1886651 : *(u32 *)&mp_opt->status = 0;
438 : :
439 : 1886651 : length = (th->doff * 4) - sizeof(struct tcphdr);
440 : 1886651 : ptr = (const unsigned char *)(th + 1);
441 : :
442 [ + ]: 11278363 : while (length > 0) {
443 : 9391712 : int opcode = *ptr++;
444 : 9391712 : int opsize;
445 : :
446 [ + + - ]: 9391712 : switch (opcode) {
447 : : case TCPOPT_EOL:
448 : : return;
449 : 5592128 : case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
450 : 5592128 : length--;
451 : 5592128 : continue;
452 : 3799584 : default:
453 [ - ]: 3799584 : if (length < 2)
454 : : return;
455 : 3799584 : opsize = *ptr++;
456 [ - ]: 3799584 : if (opsize < 2) /* "silly options" */
457 : : return;
458 [ - ]: 3799584 : if (opsize > length)
459 : : return; /* don't parse partial options */
460 [ + ]: 3799584 : if (opcode == TCPOPT_MPTCP)
461 : 1886436 : mptcp_parse_option(skb, ptr, opsize, mp_opt);
462 : 3799584 : ptr += opsize - 2;
463 : 3799584 : length -= opsize;
464 : : }
465 : : }
466 : : }
467 : :
468 : 2509 : bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
469 : : unsigned int *size, struct mptcp_out_options *opts)
470 : : {
471 [ + ][ + ]: 2509 : 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 : 2509 : subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
477 [ + ][ + ]: 2509 : 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 [ + ][ + ]: 746 : } else if (subflow->request_join) {
494 [ - - ][ - - ]: 710 : pr_debug("remote_token=%u, nonce=%u\n", subflow->remote_token,
495 : : subflow->local_nonce);
496 : 710 : opts->suboptions = OPTION_MPTCP_MPJ_SYN;
497 : 710 : opts->join_id = subflow->local_id;
498 : 710 : opts->token = subflow->remote_token;
499 : 710 : opts->nonce = subflow->local_nonce;
500 : 710 : opts->backup = subflow->request_bkup;
501 : 710 : *size = TCPOLEN_MPTCP_MPJ_SYN;
502 : 710 : 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 : 3473841 : 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 [ + ]: 3473841 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
521 [ + ]: 3473841 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
522 : 3473841 : struct mptcp_ext *mpext;
523 : 3473841 : unsigned int data_len;
524 : 3473841 : 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 [ + ][ + ]: 3473841 : if (!skb)
533 : : return false;
534 : :
535 : : /* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
536 [ + ][ + + ]: 1560336 : if (subflow->fully_established || snd_data_fin_enable ||
537 [ + ][ + ]: 4235 : subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
538 [ - ][ - ]: 3018 : sk->sk_state != TCP_ESTABLISHED)
539 : : return false;
540 : :
541 [ + ][ + ]: 3018 : if (subflow->mp_capable) {
542 [ + ]: 2412 : mpext = mptcp_get_ext(skb);
543 [ - ][ + ]: 1669 : 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 : 2412 : opts->data_len = data_len;
550 : 2412 : opts->suboptions = OPTION_MPTCP_MPC_ACK;
551 : 2412 : opts->sndr_key = subflow->local_key;
552 : 2412 : opts->rcvr_key = subflow->remote_key;
553 [ + ]: 2412 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
554 : 2412 : 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 [ + ][ + ]: 2412 : if (data_len > 0) {
562 : 927 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
563 [ + ][ + ]: 927 : if (opts->csum_reqd) {
564 : : /* we need to propagate more info to csum the pseudo hdr */
565 : 84 : opts->data_seq = mpext->data_seq;
566 : 84 : opts->subflow_seq = mpext->subflow_seq;
567 : 84 : opts->csum = mpext->csum;
568 : 84 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
569 : : }
570 : 927 : *size = ALIGN(len, 4);
571 : : } else {
572 : 1485 : *size = TCPOLEN_MPTCP_MPC_ACK;
573 : : }
574 : :
575 [ - - ][ - - ]: 2412 : 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 : 2412 : return true;
580 [ - ][ - ]: 606 : } else if (subflow->mp_join) {
581 : 606 : opts->suboptions = OPTION_MPTCP_MPJ_ACK;
582 : 606 : memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
583 : 606 : *size = TCPOLEN_MPTCP_MPJ_ACK;
584 [ - - ][ - - ]: 606 : 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 [ + ][ + ]: 606 : if (sock_owned_by_user(sk))
592 : 516 : set_bit(MPTCP_DELEGATE_ACK, &subflow->delegated_status);
593 : : else
594 : 90 : mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_ACK);
595 : 606 : return true;
596 : : }
597 : : return false;
598 : : }
599 : :
600 : 39980 : 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 [ + ]: 39980 : u64 data_fin_tx_seq = READ_ONCE(mptcp_sk(subflow->conn)->write_seq) - 1;
607 : :
608 [ + + ]: 39980 : 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 : 19484 : ext->data_fin = 1;
613 : 19484 : ext->use_map = 1;
614 : 19484 : ext->dsn64 = 1;
615 : 19484 : ext->data_seq = data_fin_tx_seq;
616 : 19484 : ext->subflow_seq = 0;
617 : 19484 : ext->data_len = 1;
618 : 19484 : ext->csum = 0;
619 [ + ]: 20496 : } 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 : 2002 : ext->data_fin = 1;
625 : 2002 : ext->data_len++;
626 : : }
627 : 39980 : }
628 : :
629 : 3470823 : 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 [ + ]: 3470823 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
634 [ + ]: 3470823 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
635 [ + ]: 3470823 : struct tcp_sock *tp = tcp_sk(sk);
636 : 3470823 : unsigned int dss_size = 0;
637 : 3470823 : struct mptcp_ext *mpext;
638 : 3470823 : unsigned int ack_size;
639 : 3470823 : bool ret = false;
640 : :
641 : : /* Zero `use_ack` and `use_map` flags with one shot. */
642 : 3470823 : memset(&opts->ext_copy.flags, 0, sizeof(opts->ext_copy.flags));
643 [ + ]: 3470823 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
644 [ + ][ + ]: 3470823 : mpext = skb ? mptcp_get_ext(skb) : NULL;
645 : :
646 [ + + + ]: 1557318 : if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) {
[ + + + ]
647 : 2755322 : unsigned int map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64;
648 : :
649 [ + ][ + ]: 2755322 : if (mpext) {
650 [ + ][ + ]: 822333 : if (opts->csum_reqd)
651 : 201210 : map_size += TCPOLEN_MPTCP_DSS_CHECKSUM;
652 : :
653 : 822333 : opts->ext_copy = *mpext;
654 : : }
655 : :
656 : 2755322 : dss_size = map_size;
657 [ + ][ + ]: 2755322 : if (skb && snd_data_fin_enable)
658 : 39980 : mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
659 : 2755322 : opts->suboptions = OPTION_MPTCP_DSS;
660 : 2755322 : 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 [ + ][ + + ]: 3470823 : if (!READ_ONCE(msk->can_ack)) {
667 : 31 : *size = ALIGN(dss_size, 4);
668 : 31 : return ret;
669 : : }
670 : :
671 [ + ][ + + ]: 3470792 : if (READ_ONCE(msk->use_64bit_ack)) {
672 : 3088366 : ack_size = TCPOLEN_MPTCP_DSS_ACK64;
673 : 3088366 : opts->ext_copy.ack64 = 1;
674 : : } else {
675 : 382426 : ack_size = TCPOLEN_MPTCP_DSS_ACK32;
676 : 382426 : opts->ext_copy.ack64 = 0;
677 : : }
678 : 3470792 : opts->ext_copy.use_ack = 1;
679 : 3470792 : opts->suboptions = OPTION_MPTCP_DSS;
680 : :
681 : : /* Add kind/length/subtype/flag overhead if mapping is not populated */
682 [ + ][ + ]: 3470792 : if (dss_size == 0)
683 : 715501 : 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 [ + ][ + ]: 3470792 : if (skb)
689 : 1557318 : tp->rcv_wnd = tp->rcv_nxt - tp->rcv_wup;
690 : :
691 : 3470792 : dss_size += ack_size;
692 : :
693 : 3470792 : *size = ALIGN(dss_size, 4);
694 : 3470792 : return true;
695 : : }
696 : :
697 : 922 : static u64 add_addr_generate_hmac(u64 key1, u64 key2,
698 : : struct mptcp_addr_info *addr)
699 : : {
700 : 922 : u16 port = ntohs(addr->port);
701 : 922 : u8 hmac[SHA256_DIGEST_SIZE];
702 : 922 : u8 msg[19];
703 : 922 : int i = 0;
704 : :
705 : 922 : msg[i++] = addr->id;
706 [ + ]: 922 : if (addr->family == AF_INET) {
707 : 714 : memcpy(&msg[i], &addr->addr.s_addr, 4);
708 : 714 : i += 4;
709 : : }
710 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
711 [ - ]: 208 : else if (addr->family == AF_INET6) {
712 : 208 : memcpy(&msg[i], &addr->addr6.s6_addr, 16);
713 : 208 : i += 16;
714 : : }
715 : : #endif
716 : 922 : msg[i++] = port >> 8;
717 : 922 : msg[i++] = port & 0xFF;
718 : :
719 : 922 : mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac);
720 : :
721 : 922 : return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
722 : : }
723 : :
724 : 3473837 : 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 [ + ]: 3473837 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
731 [ + ]: 3473837 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
732 : 3473837 : struct mptcp_addr_info addr;
733 : 3473837 : bool drop_ts = has_ts;
734 : 3473837 : bool echo;
735 : :
736 : : /* add addr will strip the existing options, be sure to avoid breaking
737 : : * MPC/MPJ handshakes
738 : : */
739 [ + ]: 3473837 : if (!mptcp_pm_should_add_signal(msk) ||
740 [ - + ]: 921 : (opts->suboptions & (OPTION_MPTCP_MPJ_ACK | OPTION_MPTCP_MPC_ACK)) ||
741 [ + + ]: 1836 : !skb || !skb_is_tcp_pure_ack(skb) ||
742 : 917 : !mptcp_pm_add_addr_signal(msk, size, remaining, &addr, &echo,
743 : : &drop_ts))
744 : 3472928 : return false;
745 : :
746 [ - - ]: 909 : pr_debug("drop other suboptions\n");
747 : 909 : opts->suboptions = OPTION_MPTCP_ADD_ADDR;
748 [ + ]: 909 : opts->drop_ts = drop_ts;
749 : 909 : opts->addr = addr;
750 [ + ][ + + ]: 909 : if (!echo) {
751 [ - ][ - ]: 497 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX);
752 : 497 : opts->ahmac = add_addr_generate_hmac(READ_ONCE(msk->local_key),
753 : 497 : 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 [ - - ]: 909 : 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 : 3472928 : 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 [ + ]: 3472928 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
771 [ + ]: 3472928 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
772 : 3472928 : struct mptcp_rm_list rm_list;
773 : 3472928 : int i;
774 : :
775 [ + + ]: 3473042 : if (!mptcp_pm_should_rm_signal(msk) ||
776 : 114 : !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, size, !skb)))
777 : 3472814 : 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 : 3473837 : static bool mptcp_established_options_mp_prio(struct sock *sk, int *size,
793 : : unsigned int remaining,
794 : : struct mptcp_out_options *opts)
795 : : {
796 [ + ]: 3473837 : 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 [ + - ]: 3473837 : 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 : 525 : 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 [ - ][ - ]: 525 : const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
823 : :
824 [ - ][ - ]: 525 : if (remaining < TCPOLEN_MPTCP_RST)
825 : : return false;
826 : :
827 : 525 : *size = TCPOLEN_MPTCP_RST;
828 : 525 : opts->suboptions |= OPTION_MPTCP_RST;
829 : 525 : opts->reset_transient = subflow->reset_transient;
830 : 525 : opts->reset_reason = subflow->reset_reason;
831 [ - ][ - ]: 525 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTTX);
832 : :
833 : : return true;
834 : : }
835 : :
836 : 525 : static bool mptcp_established_options_fastclose(struct sock *sk, int *size,
837 : : unsigned int remaining,
838 : : struct mptcp_out_options *opts)
839 : : {
840 [ + ]: 525 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
841 [ + ]: 525 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
842 : :
843 [ + ][ + ]: 525 : if (likely(!subflow->send_fastclose))
844 : : return false;
845 : :
846 [ - ][ - ]: 467 : if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
847 : : return false;
848 : :
849 : 467 : *size = TCPOLEN_MPTCP_FASTCLOSE;
850 : 467 : opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
851 : 467 : opts->rcvr_key = READ_ONCE(msk->remote_key);
852 : :
853 [ - - ]: 467 : pr_debug("FASTCLOSE key=%llu\n", opts->rcvr_key);
854 [ - ][ - ]: 467 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX);
855 : : return true;
856 : : }
857 : :
858 : 3470881 : static bool mptcp_established_options_mp_fail(struct sock *sk, int *size,
859 : : unsigned int remaining,
860 : : struct mptcp_out_options *opts)
861 : : {
862 [ + ][ + ]: 3470881 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
863 : :
864 [ + ][ + ]: 3470881 : 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 : 3570176 : 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 [ + ]: 3570176 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
885 [ + ]: 3570176 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
886 : 3570176 : int total_size = 0;
887 : 3570176 : bool snd_data_fin;
888 : 3570176 : bool ret = false;
889 : 3570176 : int opt_size = 0;
890 : :
891 : 3570176 : opts->suboptions = 0;
892 : :
893 : : /* Force later mptcp_write_options(), but do not use any actual
894 : : * option space, except for an infinite mapping still to be sent.
895 : : */
896 [ + + + + ]: 3570176 : if (unlikely(__mptcp_check_fallback(msk) &&
[ + + + + ]
897 : : !mptcp_check_infinite_map(skb) &&
898 : : (skb || !subflow->send_infinite_map)))
899 : : return 0;
900 : :
901 [ + + ][ + + ]: 3474366 : if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
902 [ + + ][ + + ]: 583 : if (mptcp_established_options_fastclose(sk, &opt_size, remaining, opts) ||
903 : 58 : mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
904 : 469 : total_size += opt_size;
905 : 469 : remaining -= opt_size;
906 : : }
907 : : /* MP_RST can be used with MP_FASTCLOSE and MP_FAIL if there is room */
908 [ - ][ - ]: 525 : if (mptcp_established_options_rst(sk, &opt_size, remaining, opts)) {
909 : 525 : total_size += opt_size;
910 : 525 : remaining -= opt_size;
911 : : }
912 : 525 : return total_size;
913 : : }
914 : :
915 [ + ]: 3473841 : snd_data_fin = mptcp_data_fin_enabled(msk);
916 [ + ][ + ]: 3473841 : if (mptcp_established_options_mp(sk, skb, snd_data_fin, &opt_size, opts))
917 : : ret = true;
918 [ - ][ - ]: 3470823 : else if (mptcp_established_options_dss(sk, skb, snd_data_fin, &opt_size, opts)) {
919 : 3470823 : int mp_fail_size;
920 : :
921 : 3470823 : ret = true;
922 [ + ][ + ]: 3470823 : if (mptcp_established_options_mp_fail(sk, &mp_fail_size,
923 : : remaining - opt_size, opts)) {
924 : 4 : total_size += opt_size + mp_fail_size;
925 : 4 : remaining -= opt_size - mp_fail_size;
926 : 4 : return total_size;
927 : : }
928 : : }
929 : :
930 : : /* we reserved enough space for the above options, and exceeding the
931 : : * TCP option space would be fatal
932 : : */
933 [ + + ][ + + ]: 3473837 : if (WARN_ON_ONCE(opt_size > remaining))
934 : : return -1;
935 : :
936 : 3473837 : total_size += opt_size;
937 : 3473837 : remaining -= opt_size;
938 [ + ][ + ]: 3473837 : if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining,
939 : : has_ts, opts)) {
940 : 909 : total_size += opt_size;
941 : 909 : remaining -= opt_size;
942 : 909 : ret = true;
943 [ + ][ + ]: 3472928 : } else if (mptcp_established_options_rm_addr(sk, skb, &opt_size,
944 : : remaining, opts)) {
945 : 114 : total_size += opt_size;
946 : 114 : remaining -= opt_size;
947 : 114 : ret = true;
948 : : }
949 : :
950 [ + ][ + ]: 3473837 : if (mptcp_established_options_mp_prio(sk, &opt_size, remaining, opts)) {
951 : 28 : total_size += opt_size;
952 : 28 : remaining -= opt_size;
953 : 28 : ret = true;
954 : : }
955 : :
956 [ - ][ - ]: 3473837 : return ret ? total_size : -1;
957 : : }
958 : :
959 : 2484 : bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
960 : : struct mptcp_out_options *opts)
961 : : {
962 : 2484 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
963 : :
964 [ + ]: 2484 : if (subflow_req->mp_capable) {
965 : 1692 : opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
966 : 1692 : opts->sndr_key = subflow_req->local_key;
967 : 1692 : opts->csum_reqd = subflow_req->csum_reqd;
968 : 1692 : opts->allow_join_id0 = subflow_req->allow_join_id0;
969 : 1692 : *size = TCPOLEN_MPTCP_MPC_SYNACK;
970 [ - - ]: 1692 : pr_debug("subflow_req=%p, local_key=%llu\n",
971 : : subflow_req, subflow_req->local_key);
972 : 1692 : return true;
973 [ + ]: 792 : } else if (subflow_req->mp_join) {
974 : 632 : opts->suboptions = OPTION_MPTCP_MPJ_SYNACK;
975 : 632 : opts->backup = subflow_req->request_bkup;
976 : 632 : opts->join_id = subflow_req->local_id;
977 : 632 : opts->thmac = subflow_req->thmac;
978 : 632 : opts->nonce = subflow_req->local_nonce;
979 [ - - ]: 632 : pr_debug("req=%p, bkup=%u, id=%u, thmac=%llu, nonce=%u\n",
980 : : subflow_req, opts->backup, opts->join_id,
981 : : opts->thmac, opts->nonce);
982 : 632 : *size = TCPOLEN_MPTCP_MPJ_SYNACK;
983 : 632 : return true;
984 : : }
985 : : return false;
986 : : }
987 : :
988 : 1879529 : static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
989 : : struct mptcp_subflow_context *subflow,
990 : : struct sk_buff *skb,
991 : : struct mptcp_options_received *mp_opt)
992 : : {
993 : 1879529 : struct sock *sk = (struct sock *)msk;
994 : :
995 : : /* here we can process OoO, in-window pkts, only in-sequence 4th ack
996 : : * will make the subflow fully established
997 : : */
998 [ + ][ + + ]: 1879529 : if (likely(subflow->fully_established)) {
999 : : /* on passive sockets, check for 3rd ack retransmission
1000 : : * note that msk is always set by subflow_syn_recv_sock()
1001 : : * for mp_join subflows
1002 : : */
1003 [ + ][ + ]: 1877413 : if (TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 &&
1004 [ + + ][ + + ]: 189442 : TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq &&
1005 [ + ][ + ]: 31222 : subflow->mp_join && (mp_opt->suboptions & OPTIONS_MPTCP_MPJ) &&
1006 [ - ][ - ]: 612 : !subflow->request_join)
1007 : 612 : tcp_send_ack(ssk);
1008 : 1877413 : goto check_notify;
1009 : : }
1010 : :
1011 : : /* we must process OoO packets before the first subflow is fully
1012 : : * established. OoO packets are instead a protocol violation
1013 : : * for MP_JOIN subflows as the peer must not send any data
1014 : : * before receiving the forth ack - cfr. RFC 8684 section 3.2.
1015 : : */
1016 [ + ][ + ]: 2116 : if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
1017 [ + ][ + ]: 60 : if (subflow->mp_join)
1018 : 0 : goto reset;
1019 [ + - ][ + - ]: 60 : if (subflow->is_mptfo && mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
1020 : 0 : goto set_fully_established;
1021 : 60 : return subflow->mp_capable;
1022 : : }
1023 : :
1024 [ + ][ + ]: 2056 : if (subflow->remote_key_valid &&
1025 [ + + + ]: 2012 : (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
[ + + + ]
1026 : 129 : ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) &&
1027 [ + - ][ + - ]: 129 : (!mp_opt->echo || subflow->mp_join)))) {
1028 : : /* subflows are fully established as soon as we get any
1029 : : * additional ack, including ADD_ADDR.
1030 : : */
1031 : 1998 : goto set_fully_established;
1032 : : }
1033 : :
1034 : : /* If the first established packet does not contain MP_CAPABLE + data
1035 : : * then fallback to TCP. Fallback scenarios requires a reset for
1036 : : * MP_JOIN subflows.
1037 : : */
1038 [ + ][ + ]: 58 : if (!(mp_opt->suboptions & OPTIONS_MPTCP_MPC)) {
1039 [ + ][ + ]: 14 : if (subflow->mp_join)
1040 : 8 : goto reset;
1041 : 6 : subflow->mp_capable = 0;
1042 [ + ][ + ]: 6 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK)) {
1043 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
1044 : 0 : goto reset;
1045 : : }
1046 : : /* this ACK will not reach the fallback path: push from here */
1047 : 6 : mptcp_data_lock(sk);
1048 : 6 : __mptcp_check_push(sk, ssk);
1049 : 6 : mptcp_data_unlock(sk);
1050 : 6 : return false;
1051 : : }
1052 : :
1053 [ - ][ + - ]: 44 : if (unlikely(!READ_ONCE(msk->pm.server_side)))
1054 : : /* DO-NOT-MERGE: use WARN i/o pr_warn: only for MPTCP export */
1055 : 0 : WARN_ONCE(1, "bogus mpc option on established client sk");
1056 : :
1057 : 44 : set_fully_established:
1058 : : /* the peer can no longer fall back to TCP */
1059 [ + ][ + ]: 2042 : if (subflow->request_join)
1060 : 586 : set_bit(MPTCP_JOINED, &msk->flags);
1061 : :
1062 [ + ][ + ]: 2042 : if (mp_opt->deny_join_id0)
1063 : 0 : WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
1064 : :
1065 : 2042 : mptcp_data_lock(sk);
1066 : 2042 : __mptcp_subflow_fully_established(msk, subflow, mp_opt);
1067 [ + + ][ + + ]: 2042 : if (tcp_sk(ssk)->syn_fastopen_child)
1068 : 44 : __mptcp_check_push(sk, ssk);
1069 : 2042 : mptcp_data_unlock(sk);
1070 : :
1071 : 1879455 : check_notify:
1072 : : /* if the subflow is not already linked into the conn_list, we can't
1073 : : * notify the PM: this subflow is still on the listener queue
1074 : : * and the PM possibly acquiring the subflow lock could race with
1075 : : * the listener close
1076 : : */
1077 [ + - ][ + - ]: 1879455 : if (likely(subflow->pm_notified) || list_empty(&subflow->node))
1078 : : return true;
1079 : :
1080 : 2654 : subflow->pm_notified = 1;
1081 [ + ][ + ]: 2654 : if (subflow->mp_join) {
1082 : 1198 : clear_3rdack_retransmission(ssk);
1083 : 1198 : mptcp_pm_subflow_established(msk);
1084 : : } else {
1085 : 1456 : mptcp_pm_fully_established(msk, ssk);
1086 : : }
1087 : : return true;
1088 : :
1089 : 8 : reset:
1090 : 8 : mptcp_subflow_reset(ssk);
1091 : 8 : return false;
1092 : : }
1093 : :
1094 : 242104 : u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq)
1095 : : {
1096 : 242104 : u32 old_seq32, cur_seq32;
1097 : :
1098 : 242104 : old_seq32 = (u32)old_seq;
1099 : 242104 : cur_seq32 = (u32)cur_seq;
1100 : 242104 : cur_seq = (old_seq & GENMASK_ULL(63, 32)) + cur_seq32;
1101 [ + + ]: 242104 : if (unlikely(cur_seq32 < old_seq32 && before(old_seq32, cur_seq32)))
1102 : 0 : return cur_seq + (1LL << 32);
1103 : :
1104 : : /* reverse wrap could happen, too */
1105 [ + + ]: 242104 : if (unlikely(cur_seq32 > old_seq32 && after(old_seq32, cur_seq32)))
1106 : 0 : return cur_seq - (1LL << 32);
1107 : : return cur_seq;
1108 : : }
1109 : :
1110 : 0 : static void __mptcp_snd_una_update(struct mptcp_sock *msk, u64 new_snd_una)
1111 : : {
1112 : 508221 : msk->bytes_acked += new_snd_una - msk->snd_una;
1113 : 508221 : WRITE_ONCE(msk->snd_una, new_snd_una);
1114 : : }
1115 : :
1116 : 1875834 : static void rwin_update(struct mptcp_sock *msk, struct sock *ssk,
1117 : : struct sk_buff *skb)
1118 : : {
1119 [ + ]: 1875834 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1120 [ + ]: 1875834 : struct tcp_sock *tp = tcp_sk(ssk);
1121 : 1875834 : u64 mptcp_rcv_wnd;
1122 : :
1123 : : /* Avoid touching extra cachelines if TCP is going to accept this
1124 : : * skb without filling the TCP-level window even with a possibly
1125 : : * outdated mptcp-level rwin.
1126 : : */
1127 [ - + ][ - + ]: 1875834 : if (!skb->len || skb->len < tcp_receive_window(tp))
1128 : : return;
1129 : :
1130 [ + ]: 11555 : mptcp_rcv_wnd = atomic64_read(&msk->rcv_wnd_sent);
1131 [ + ][ + ]: 11555 : if (!after64(mptcp_rcv_wnd, subflow->rcv_wnd_sent))
1132 : : return;
1133 : :
1134 : : /* Some other subflow grew the mptcp-level rwin since rcv_wup,
1135 : : * resync.
1136 : : */
1137 : 0 : tp->rcv_wnd += mptcp_rcv_wnd - subflow->rcv_wnd_sent;
1138 [ # ][ # ]: 0 : tcp_update_max_rcv_wnd_seq(tp);
1139 : 0 : subflow->rcv_wnd_sent = mptcp_rcv_wnd;
1140 : : }
1141 : :
1142 : 1874735 : static void ack_update_msk(struct mptcp_sock *msk,
1143 : : struct sock *ssk,
1144 : : const struct sk_buff *skb,
1145 : : struct mptcp_options_received *mp_opt)
1146 : : {
1147 : 1874735 : u64 new_wnd_end, new_snd_una, old_snd_una;
1148 : 1874735 : u32 win = ntohs(tcp_hdr(skb)->window);
1149 : 1874735 : struct sock *sk = (struct sock *)msk;
1150 : 1874735 : u64 snd_nxt;
1151 : :
1152 : 1874735 : mptcp_data_lock(sk);
1153 : :
1154 : : /* avoid ack expansion on update conflict, to reduce the risk of
1155 : : * wrongly expanding to a future ack sequence number, which is way
1156 : : * more dangerous than missing an ack
1157 : : */
1158 : 1874735 : old_snd_una = msk->snd_una;
1159 : 1874735 : snd_nxt = READ_ONCE(msk->snd_nxt);
1160 [ + ]: 1874735 : new_snd_una = mptcp_expand_seq(old_snd_una, mp_opt->data_ack, mp_opt->ack64);
1161 : :
1162 : : /* The active-open state sync can defer the snd_nxt update. Do not
1163 : : * accept an ACK against a reversed interval, or beyond snd_nxt.
1164 : : */
1165 [ + + ]: 1874735 : if (unlikely(before64(snd_nxt, old_snd_una) ||
1166 : : after64(new_snd_una, snd_nxt)))
1167 : : new_snd_una = old_snd_una;
1168 : :
1169 : : /* What the peer announced: tcp_sk(ssk)->snd_wnd can be larger, see
1170 : : * mptcp_check_allowed_size(), and is not always updated.
1171 : : */
1172 [ - ]: 1874735 : if (likely(!tcp_hdr(skb)->syn))
1173 [ + ]: 1874735 : win <<= tcp_sk(ssk)->rx_opt.snd_wscale;
1174 : 1874735 : new_wnd_end = new_snd_una + win;
1175 : :
1176 [ + ]: 1874735 : if (after64(new_wnd_end, msk->wnd_end))
1177 : 494272 : WRITE_ONCE(msk->wnd_end, new_wnd_end);
1178 : :
1179 : : /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */
1180 [ + ]: 1874735 : if (after64(msk->wnd_end, snd_nxt))
1181 : 1725805 : __mptcp_check_push(sk, ssk);
1182 : :
1183 [ + ]: 1874735 : if (after64(new_snd_una, old_snd_una)) {
1184 : 487508 : __mptcp_snd_una_update(msk, new_snd_una);
1185 : 487508 : __mptcp_data_acked(sk);
1186 : : }
1187 : 1874735 : msk->last_ack_recv = tcp_jiffies32;
1188 : 1874735 : mptcp_data_unlock(sk);
1189 : :
1190 : 1874735 : trace_ack_update_msk(mp_opt->data_ack,
1191 : : old_snd_una, new_snd_una,
1192 : 1874735 : new_wnd_end, READ_ONCE(msk->wnd_end));
1193 : 1874735 : }
1194 : :
1195 : 18125 : bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit)
1196 : : {
1197 : : /* Skip if DATA_FIN was already received.
1198 : : * If updating simultaneously with the recvmsg loop, values
1199 : : * should match. If they mismatch, the peer is misbehaving and
1200 : : * we will prefer the most recent information.
1201 : : */
1202 [ + ][ + + ]: 18125 : if (READ_ONCE(msk->rcv_data_fin))
1203 : : return false;
1204 : :
1205 [ + ][ + ]: 3192 : WRITE_ONCE(msk->rcv_data_fin_seq,
1206 : : mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
1207 : 3192 : WRITE_ONCE(msk->rcv_data_fin, 1);
1208 : :
1209 : 3192 : return true;
1210 : : }
1211 : :
1212 : 841 : static bool add_addr_hmac_valid(struct mptcp_sock *msk,
1213 : : struct mptcp_options_received *mp_opt)
1214 : : {
1215 : 841 : u64 hmac = 0;
1216 : :
1217 [ + ]: 841 : if (mp_opt->echo)
1218 : : return true;
1219 : :
1220 : 425 : hmac = add_addr_generate_hmac(READ_ONCE(msk->remote_key),
1221 : 425 : READ_ONCE(msk->local_key),
1222 : : &mp_opt->addr);
1223 : :
1224 [ - - ]: 425 : pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
1225 : : msk, hmac, mp_opt->ahmac);
1226 : :
1227 : 425 : return hmac == mp_opt->ahmac;
1228 : : }
1229 : :
1230 : 20765 : static bool mptcp_over_limit(struct sock *sk, struct sock *ssk,
1231 : : const struct sk_buff *skb)
1232 : : {
1233 [ + ]: 20765 : struct mptcp_sock *msk = mptcp_sk(sk);
1234 : 20765 : u32 rcvbuf = READ_ONCE(sk->sk_rcvbuf);
1235 : :
1236 [ - + ][ - + ]: 20765 : if (likely((u32)sk_rmem_alloc_get(sk) <= rcvbuf &&
1237 : : READ_ONCE(msk->backlog_len) <= rcvbuf))
1238 : : return false;
1239 : :
1240 : : /* Avoid silently dropping pure acks, fin, rst or already-acked segm. */
1241 [ # ][ # ]: 0 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq ||
1242 [ # # ][ # # ]: 0 : TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_FIN | TCPHDR_RST) ||
1243 [ # # ][ # # ]: 0 : !after(TCP_SKB_CB(skb)->end_seq, tcp_sk(ssk)->rcv_nxt))
1244 : : return false;
1245 : :
1246 : : /* Dropped due to memory constraints, schedule an ack. */
1247 : 0 : inet_csk(ssk)->icsk_ack.pending |= ICSK_ACK_NOMEM | ICSK_ACK_NOW;
1248 : 0 : inet_csk_schedule_ack(ssk);
1249 : :
1250 : : /* Plain TCP (fallback) and skb is dropped before the TCP recv queue. */
1251 : 0 : NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP);
1252 : :
1253 : 0 : return true;
1254 : : }
1255 : :
1256 : : /* Return false when the caller must drop the packet, i.e. in case of error,
1257 : : * subflow has been reset, or over memory limits.
1258 : : */
1259 : 1900294 : bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
1260 : : {
1261 [ + ]: 1900294 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1262 [ + ]: 1900294 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
1263 : 1900294 : struct mptcp_options_received mp_opt;
1264 : 1900294 : struct mptcp_ext *mpext;
1265 : :
1266 [ + ]: 1900294 : if (__mptcp_check_fallback(msk)) {
1267 : : /* Keep it simple and unconditionally trigger send data cleanup and
1268 : : * pending queue spooling. We will need to acquire the data lock
1269 : : * for more accurate checks, and once the lock is acquired, such
1270 : : * helpers are cheap.
1271 : : */
1272 : 20765 : mptcp_data_lock(subflow->conn);
1273 [ + ]: 20765 : if (sk_stream_memory_free(sk))
1274 : 20759 : __mptcp_check_push(subflow->conn, sk);
1275 : :
1276 : : /* on fallback we just need to ignore the msk-level snd_una, as
1277 : : * this is really plain TCP
1278 : : */
1279 : 20765 : __mptcp_snd_una_update(msk, READ_ONCE(msk->snd_nxt));
1280 : :
1281 : 20765 : __mptcp_data_acked(subflow->conn);
1282 : 20765 : mptcp_data_unlock(subflow->conn);
1283 : 20765 : return !mptcp_over_limit(subflow->conn, sk, skb);
1284 : : }
1285 : :
1286 : 1879529 : mptcp_get_options(skb, &mp_opt);
1287 : :
1288 : : /* The subflow can be in close state only if check_fully_established()
1289 : : * just sent a reset. If so, tell the caller to ignore the current packet.
1290 : : */
1291 [ + ]: 1879529 : if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
1292 : 68 : return sk->sk_state != TCP_CLOSE;
1293 : :
1294 : : /* MPTCP opts, not an infinite map: the peer did not fall back */
1295 [ + + + ]: 1879461 : if (mp_opt.suboptions && !(mp_opt.use_map && !mp_opt.data_len)) {
1296 : 1879155 : u32 ack_seq = TCP_SKB_CB(skb)->ack_seq;
1297 : :
1298 [ + ]: 1879155 : if (after(ack_seq, subflow->opt_ack_seq))
1299 : 666834 : subflow->opt_ack_seq = ack_seq;
1300 [ + + ]: 1879155 : if (unlikely(subflow->old_data_pending) &&
1301 [ + ]: 19468 : !before(ack_seq, subflow->old_data_end))
1302 : 2862 : subflow->old_data_pending = 0;
1303 : : }
1304 : :
1305 [ + ][ + ]: 1879461 : if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
1306 [ + ][ + ]: 307170 : if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
1307 [ + ][ + ]: 261 : READ_ONCE(msk->local_key) == mp_opt.fc_recv_key) {
1308 : 251 : WRITE_ONCE(msk->rcv_fastclose, true);
1309 : 251 : mptcp_schedule_work((struct sock *)msk);
1310 [ - ][ - ]: 251 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX);
1311 : : }
1312 : :
1313 [ + - ][ + - ]: 308011 : if ((mp_opt.suboptions & OPTION_MPTCP_ADD_ADDR) &&
1314 : 841 : add_addr_hmac_valid(msk, &mp_opt)) {
1315 [ + ][ + ]: 841 : if (!mp_opt.echo) {
1316 : 425 : mptcp_pm_add_addr_received(sk, &mp_opt.addr);
1317 [ - ][ # ]: 425 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
1318 : : } else {
1319 : 416 : mptcp_pm_add_addr_echoed(msk, &mp_opt.addr);
1320 [ - ][ - ]: 416 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
1321 : : }
1322 : :
1323 [ + ][ + ]: 841 : if (mp_opt.addr.port)
1324 [ - ][ # ]: 96 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD);
1325 : : }
1326 : :
1327 [ + ][ + ]: 307170 : if (mp_opt.suboptions & OPTION_MPTCP_RM_ADDR)
1328 : 108 : mptcp_pm_rm_addr_received(msk, &mp_opt.rm_list);
1329 : :
1330 [ + ][ + ]: 307170 : if (mp_opt.suboptions & OPTION_MPTCP_PRIO) {
1331 : 40 : mptcp_pm_mp_prio_received(sk, mp_opt.backup);
1332 [ - ][ # ]: 40 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIORX);
1333 : : }
1334 : :
1335 [ + ][ + ]: 307170 : if (mp_opt.suboptions & OPTION_MPTCP_FAIL) {
1336 : 6 : mptcp_pm_mp_fail_received(sk, mp_opt.fail_seq);
1337 [ - ][ # ]: 6 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILRX);
1338 : : }
1339 : :
1340 [ + ][ + ]: 307170 : if (mp_opt.suboptions & OPTION_MPTCP_RST) {
1341 : 247 : subflow->reset_seen = 1;
1342 : 247 : subflow->reset_reason = mp_opt.reset_reason;
1343 : 247 : subflow->reset_transient = mp_opt.reset_transient;
1344 [ - ][ - ]: 247 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTRX);
1345 : : }
1346 : :
1347 [ + ][ + ]: 307170 : if (!(mp_opt.suboptions & OPTION_MPTCP_DSS))
1348 : : return true;
1349 : : }
1350 : :
1351 : : /* we can't wait for recvmsg() to update the ack_seq, otherwise
1352 : : * monodirectional flows will stuck
1353 : : */
1354 [ + ][ + ]: 1875834 : if (mp_opt.use_ack)
1355 : 1874735 : ack_update_msk(msk, sk, skb, &mp_opt);
1356 : 1875834 : rwin_update(msk, sk, skb);
1357 : :
1358 : : /* Zero-data-length packets are dropped by the caller and not
1359 : : * propagated to the MPTCP layer, so the skb extension does not
1360 : : * need to be allocated or populated. DATA_FIN information, if
1361 : : * present, needs to be updated here before the skb is freed.
1362 : : */
1363 [ + ][ + ]: 1875834 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
1364 [ + - + ]: 701933 : if (mp_opt.data_fin && mp_opt.data_len == 1 &&
[ + - + ]
1365 : 15198 : mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
1366 : 2973 : mptcp_schedule_work((struct sock *)msk);
1367 : :
1368 : 686735 : return true;
1369 : : }
1370 : :
1371 : : /* the push from ack_update_msk() can reset the subflow */
1372 [ + ][ + ]: 1189099 : if (unlikely(sk->sk_state == TCP_CLOSE))
1373 : : return false;
1374 : :
1375 : 1189099 : mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
1376 [ - ][ - ]: 1189099 : if (!mpext)
1377 : : return false;
1378 : :
1379 : 1189099 : memset(mpext, 0, sizeof(*mpext));
1380 : :
1381 [ + ][ + ]: 1189099 : if (likely(mp_opt.use_map)) {
1382 [ + ][ + ]: 1186058 : if (mp_opt.mpc_map) {
1383 : : /* this is an MP_CAPABLE carrying MPTCP data
1384 : : * we know this map the first chunk of data
1385 : : */
1386 : 1099 : mptcp_crypto_key_sha(subflow->remote_key, NULL,
1387 : : &mpext->data_seq);
1388 : 1099 : mpext->data_seq++;
1389 : 1099 : mpext->subflow_seq = 1;
1390 : 1099 : mpext->dsn64 = 1;
1391 : 1099 : mpext->mpc_map = 1;
1392 : 1099 : mpext->data_fin = 0;
1393 : : } else {
1394 : 1184959 : mpext->data_seq = mp_opt.data_seq;
1395 : 1184959 : mpext->subflow_seq = mp_opt.subflow_seq;
1396 : 1184959 : mpext->dsn64 = mp_opt.dsn64;
1397 : 1184959 : mpext->data_fin = mp_opt.data_fin;
1398 : : }
1399 : 1186058 : mpext->data_len = mp_opt.data_len;
1400 : 1186058 : mpext->use_map = 1;
1401 : 1186058 : mpext->csum_reqd = !!(mp_opt.suboptions & OPTION_MPTCP_CSUMREQD);
1402 : :
1403 [ + ][ + ]: 1186058 : if (mpext->csum_reqd)
1404 : 297655 : mpext->csum = mp_opt.csum;
1405 : : }
1406 : :
1407 : : return true;
1408 : : }
1409 : :
1410 : 1556409 : static u64 mptcp_set_rwin(struct mptcp_sock *msk, struct tcp_sock *tp,
1411 : : struct tcphdr *th, u64 ack_seq)
1412 : : {
1413 : 1556409 : const struct sock *ssk = (const struct sock *)tp;
1414 : 1556409 : u64 rcv_wnd_old, rcv_wnd_new;
1415 : 1556409 : u32 new_win;
1416 : 1556409 : u64 win;
1417 : :
1418 : 1556409 : rcv_wnd_new = ack_seq + tp->rcv_wnd;
1419 : :
1420 [ + + ]: 1556409 : rcv_wnd_old = atomic64_read(&msk->rcv_wnd_sent);
1421 [ + + ][ + + ]: 1556409 : if (after64(rcv_wnd_new, rcv_wnd_old)) {
1422 : 90 : u64 rcv_wnd;
1423 : :
1424 : 546001 : for (;;) {
1425 : 546091 : rcv_wnd = atomic64_cmpxchg(&msk->rcv_wnd_sent, rcv_wnd_old, rcv_wnd_new);
1426 : :
1427 [ + ][ + ]: 546001 : if (rcv_wnd == rcv_wnd_old)
1428 : : break;
1429 : :
1430 : 2 : rcv_wnd_old = rcv_wnd;
1431 [ + ][ + ]: 2 : if (before64(rcv_wnd_new, rcv_wnd_old)) {
1432 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICTUPDATE);
1433 : 0 : goto raise_win;
1434 : : }
1435 [ - ][ - ]: 92 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICT);
1436 : : }
1437 : 545999 : goto update_wspace;
1438 : : }
1439 : :
1440 [ + ][ + ]: 1010410 : if (rcv_wnd_new != rcv_wnd_old) {
1441 : 290794 : raise_win:
1442 : : /* The msk-level rcv wnd is after the tcp level one,
1443 : : * sync the latter.
1444 : : */
1445 : 290794 : rcv_wnd_new = rcv_wnd_old;
1446 : 290794 : win = rcv_wnd_old - ack_seq;
1447 : 290794 : new_win = min_t(u64, win, U32_MAX);
1448 : 290794 : tp->rcv_wnd = new_win;
1449 [ + ][ + ]: 290794 : tcp_update_max_rcv_wnd_seq(tp);
1450 : :
1451 : : /* Make sure we do not exceed the maximum possible
1452 : : * scaled window.
1453 : : */
1454 [ + ][ + ]: 290794 : if (unlikely(th->syn))
1455 : 0 : new_win = min(new_win, 65535U) << tp->rx_opt.rcv_wscale;
1456 [ + - ][ + ]: 290794 : if (!tp->rx_opt.rcv_wscale &&
1457 [ # ][ # ]: 0 : READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_workaround_signed_windows))
1458 : 0 : new_win = min(new_win, MAX_TCP_WINDOW);
1459 : : else
1460 : 290794 : new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale));
1461 : :
1462 : : /* RFC1323 scaling applied */
1463 : 290794 : new_win >>= tp->rx_opt.rcv_wscale;
1464 : 290794 : th->window = htons(new_win);
1465 [ - ][ # ]: 290794 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDSHARED);
1466 : : }
1467 : :
1468 : 719616 : update_wspace:
1469 : 1556409 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1470 : 1556409 : return rcv_wnd_new;
1471 : : }
1472 : :
1473 : 23704 : static void mptcp_track_rwin(struct tcp_sock *tp)
1474 : : {
1475 : 23704 : const struct sock *ssk = (const struct sock *)tp;
1476 : 23704 : struct mptcp_subflow_context *subflow;
1477 : 23704 : struct mptcp_sock *msk;
1478 : :
1479 [ - ]: 23704 : if (!ssk)
1480 : : return;
1481 : :
1482 [ + ]: 23704 : subflow = mptcp_subflow_ctx(ssk);
1483 [ + ]: 23704 : msk = mptcp_sk(subflow->conn);
1484 : 23704 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1485 : : }
1486 : :
1487 : 301892 : __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
1488 : : {
1489 : 301892 : struct csum_pseudo_header header;
1490 : 301892 : __wsum csum;
1491 : :
1492 : : /* cfr RFC 8684 3.3.1.:
1493 : : * the data sequence number used in the pseudo-header is
1494 : : * always the 64-bit value, irrespective of what length is used in the
1495 : : * DSS option itself.
1496 : : */
1497 : 301892 : header.data_seq = cpu_to_be64(data_seq);
1498 : 301892 : header.subflow_seq = htonl(subflow_seq);
1499 : 301892 : header.data_len = htons(data_len);
1500 : 301892 : header.csum = 0;
1501 : :
1502 : 301892 : csum = csum_partial(&header, sizeof(header), sum);
1503 : 301892 : return csum_fold(csum);
1504 : : }
1505 : :
1506 : 208137 : static __sum16 mptcp_make_csum(const struct mptcp_ext *mpext)
1507 : : {
1508 : 416274 : return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
1509 : 208137 : ~csum_unfold(mpext->csum));
1510 : : }
1511 : :
1512 : 0 : static void put_len_csum(u16 len, __sum16 csum, void *data)
1513 : : {
1514 : 208223 : __sum16 *sumptr = data + 2;
1515 : 208223 : __be16 *ptr = data;
1516 : :
1517 : 208223 : put_unaligned_be16(len, ptr);
1518 : :
1519 : 208223 : put_unaligned(csum, sumptr);
1520 : 208223 : }
1521 : :
1522 : 1589356 : void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp,
1523 : : struct mptcp_out_options *opts)
1524 : : {
1525 : 1589356 : const struct sock *ssk = (const struct sock *)tp;
1526 : 1589356 : struct mptcp_subflow_context *subflow;
1527 : :
1528 : : /* Which options can be used together?
1529 : : *
1530 : : * X: mutually exclusive
1531 : : * O: often used together
1532 : : * C: can be used together in some cases
1533 : : * P: could be used together but we prefer not to (optimisations)
1534 : : *
1535 : : * Opt: | MPC | MPJ | DSS | ADD | RM | PRIO | FAIL | FC |
1536 : : * ------|------|------|------|------|------|------|------|------|
1537 : : * MPC |------|------|------|------|------|------|------|------|
1538 : : * MPJ | X |------|------|------|------|------|------|------|
1539 : : * DSS | X | X |------|------|------|------|------|------|
1540 : : * ADD | X | X | P |------|------|------|------|------|
1541 : : * RM | C | C | C | P |------|------|------|------|
1542 : : * PRIO | X | C | C | C | C |------|------|------|
1543 : : * FAIL | X | X | C | X | X | X |------|------|
1544 : : * FC | X | X | P | X | X | X | X |------|
1545 : : * RST | X | X | X | X | X | X | O | O |
1546 : : * ------|------|------|------|------|------|------|------|------|
1547 : : *
1548 : : * The same applies in mptcp_established_options() function.
1549 : : */
1550 [ + ]: 1589356 : if (likely(OPTION_MPTCP_DSS & opts->suboptions)) {
1551 : 1556409 : struct mptcp_ext *mpext = &opts->ext_copy;
1552 : 1556409 : u8 len = TCPOLEN_MPTCP_DSS_BASE;
1553 : 1556409 : u8 flags = 0;
1554 : :
1555 [ - ]: 1556409 : if (mpext->use_ack) {
1556 : 1556409 : flags = MPTCP_DSS_HAS_ACK;
1557 [ + ]: 1556409 : if (mpext->ack64) {
1558 : : len += TCPOLEN_MPTCP_DSS_ACK64;
1559 : : flags |= MPTCP_DSS_ACK64;
1560 : : } else {
1561 : 97729 : len += TCPOLEN_MPTCP_DSS_ACK32;
1562 : : }
1563 : : }
1564 : :
1565 [ + ]: 1556409 : if (mpext->use_map) {
1566 : 841817 : len += TCPOLEN_MPTCP_DSS_MAP64;
1567 : :
1568 : : /* Use only 64-bit mapping flags for now, add
1569 : : * support for optional 32-bit mappings later.
1570 : : */
1571 : 841817 : flags |= MPTCP_DSS_HAS_MAP | MPTCP_DSS_DSN64;
1572 [ + ]: 841817 : if (mpext->data_fin)
1573 : 21486 : flags |= MPTCP_DSS_DATA_FIN;
1574 : :
1575 [ + ]: 841817 : if (opts->csum_reqd)
1576 : 208139 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1577 : : }
1578 : :
1579 [ - ]: 1556409 : *ptr++ = mptcp_option(MPTCPOPT_DSS, len, 0, flags);
1580 : :
1581 [ - ]: 1556409 : if (mpext->use_ack) {
1582 : 1556409 : struct mptcp_sock *msk;
1583 : 1556409 : u64 ack_seq;
1584 : :
1585 : : /* DSS option is set only by mptcp_established_options,
1586 : : * the caller is __tcp_transmit_skb() and ssk is always
1587 : : * not NULL.
1588 : : */
1589 [ + ]: 1556409 : subflow = mptcp_subflow_ctx(ssk);
1590 [ + ]: 1556409 : msk = mptcp_sk(subflow->conn);
1591 : 1556409 : ack_seq = READ_ONCE(msk->ack_seq);
1592 [ + ]: 1556409 : if (mpext->ack64) {
1593 : 1458680 : put_unaligned_be64(ack_seq, ptr);
1594 : 1458680 : ptr += 2;
1595 : : } else {
1596 : 97729 : put_unaligned_be32(ack_seq, ptr);
1597 : 97729 : ptr += 1;
1598 : : }
1599 : 1556409 : subflow->rcv_wnd_sent = mptcp_set_rwin(msk, tp, th,
1600 : : ack_seq);
1601 : : }
1602 : :
1603 [ + ]: 1556409 : if (mpext->use_map) {
1604 [ + ]: 841817 : put_unaligned_be64(mpext->data_seq, ptr);
1605 : 841817 : ptr += 2;
1606 [ + ]: 841817 : put_unaligned_be32(mpext->subflow_seq, ptr);
1607 : 841817 : ptr += 1;
1608 [ + ]: 841817 : if (opts->csum_reqd) {
1609 : : /* data_len == 0 is reserved for the infinite mapping,
1610 : : * the checksum will also be set to 0.
1611 : : */
1612 : 208139 : put_len_csum(mpext->data_len,
1613 [ + ]: 208139 : (mpext->data_len ? mptcp_make_csum(mpext) : 0),
1614 : : ptr);
1615 : : } else {
1616 : 633678 : put_unaligned_be32(mpext->data_len << 16 |
1617 : 633678 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1618 : : }
1619 : 841817 : ptr += 1;
1620 : : }
1621 : :
1622 : : /* We might need to add MP_FAIL options in rare cases */
1623 [ + ]: 1556409 : if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions))
1624 : 4 : goto mp_fail;
1625 [ + ]: 32947 : } else if (OPTIONS_MPTCP_MPC & opts->suboptions) {
1626 : 5861 : u8 len, flag = MPTCP_CAP_HMAC_SHA256;
1627 : :
1628 [ + ]: 5861 : if (OPTION_MPTCP_MPC_SYN & opts->suboptions) {
1629 : : len = TCPOLEN_MPTCP_MPC_SYN;
1630 [ + ]: 4104 : } else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) {
1631 : : len = TCPOLEN_MPTCP_MPC_SYNACK;
1632 [ + ]: 2412 : } else if (opts->data_len) {
1633 : 927 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
1634 [ + ]: 927 : if (opts->csum_reqd)
1635 : 84 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1636 : : } else {
1637 : : len = TCPOLEN_MPTCP_MPC_ACK;
1638 : : }
1639 : :
1640 [ + ]: 5861 : if (opts->csum_reqd)
1641 : 458 : flag |= MPTCP_CAP_CHECKSUM_REQD;
1642 : :
1643 [ + ]: 5861 : if (!opts->allow_join_id0)
1644 : 34 : flag |= MPTCP_CAP_DENY_JOIN_ID0;
1645 : :
1646 [ + ]: 5861 : *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len,
1647 : : MPTCP_SUPPORTED_VERSION,
1648 : : flag);
1649 : :
1650 : 5861 : if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
1651 [ + ]: 5861 : opts->suboptions))
1652 : 1757 : goto mp_capable_done;
1653 : :
1654 [ + ]: 4104 : put_unaligned_be64(opts->sndr_key, ptr);
1655 : 4104 : ptr += 2;
1656 [ + ]: 4104 : if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))
1657 : 1692 : goto mp_capable_done;
1658 : :
1659 [ + ]: 2412 : put_unaligned_be64(opts->rcvr_key, ptr);
1660 : 2412 : ptr += 2;
1661 [ + ]: 2412 : if (!opts->data_len)
1662 : 1485 : goto mp_capable_done;
1663 : :
1664 [ + ]: 927 : if (opts->csum_reqd) {
1665 : 84 : put_len_csum(opts->data_len,
1666 : 84 : __mptcp_make_csum(opts->data_seq,
1667 : : opts->subflow_seq,
1668 : : opts->data_len,
1669 : 84 : ~csum_unfold(opts->csum)),
1670 : : ptr);
1671 : : } else {
1672 : 843 : put_unaligned_be32(opts->data_len << 16 |
1673 : 843 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1674 : : }
1675 : 927 : ptr += 1;
1676 : :
1677 : : /* MPC is additionally mutually exclusive with MP_PRIO */
1678 : 927 : goto mp_capable_done;
1679 [ + ]: 27086 : } else if (OPTIONS_MPTCP_MPJ & opts->suboptions) {
1680 [ + ]: 1948 : if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
1681 : 710 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1682 : : TCPOLEN_MPTCP_MPJ_SYN,
1683 : 710 : opts->backup, opts->join_id);
1684 : 710 : put_unaligned_be32(opts->token, ptr);
1685 : 710 : ptr += 1;
1686 : 710 : put_unaligned_be32(opts->nonce, ptr);
1687 : 710 : ptr += 1;
1688 [ + ]: 1238 : } else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
1689 : 632 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1690 : : TCPOLEN_MPTCP_MPJ_SYNACK,
1691 : 632 : opts->backup, opts->join_id);
1692 : 632 : put_unaligned_be64(opts->thmac, ptr);
1693 : 632 : ptr += 2;
1694 : 632 : put_unaligned_be32(opts->nonce, ptr);
1695 : 632 : ptr += 1;
1696 : : } else {
1697 : 606 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1698 : : TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
1699 : 606 : memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
1700 : 606 : ptr += 5;
1701 : : }
1702 [ + ]: 25138 : } else if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
1703 : 909 : u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
1704 : 909 : u8 echo = MPTCP_ADDR_ECHO;
1705 : :
1706 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1707 [ + ]: 909 : if (opts->addr.family == AF_INET6)
1708 : 208 : len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
1709 : : #endif
1710 : :
1711 [ + ]: 909 : if (opts->addr.port)
1712 : 96 : len += TCPOLEN_MPTCP_PORT_LEN;
1713 : :
1714 [ + ]: 909 : if (opts->ahmac) {
1715 : 497 : len += sizeof(opts->ahmac);
1716 : 497 : echo = 0;
1717 : : }
1718 : :
1719 : 909 : *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
1720 [ + ]: 909 : len, echo, opts->addr.id);
1721 [ + ]: 909 : if (opts->addr.family == AF_INET) {
1722 : 701 : memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
1723 : 701 : ptr += 1;
1724 : : }
1725 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1726 [ - ]: 208 : else if (opts->addr.family == AF_INET6) {
1727 : 208 : memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
1728 : 208 : ptr += 4;
1729 : : }
1730 : : #endif
1731 : :
1732 [ + ]: 909 : if (!opts->addr.port) {
1733 [ + ]: 813 : if (opts->ahmac) {
1734 : 443 : put_unaligned_be64(opts->ahmac, ptr);
1735 : 443 : ptr += 2;
1736 : : }
1737 : : } else {
1738 : 96 : u16 port = ntohs(opts->addr.port);
1739 : :
1740 [ + ]: 96 : if (opts->ahmac) {
1741 : 54 : u8 *bptr = (u8 *)ptr;
1742 : :
1743 : 54 : put_unaligned_be16(port, bptr);
1744 : 54 : bptr += 2;
1745 : 54 : put_unaligned_be64(opts->ahmac, bptr);
1746 : 54 : bptr += 8;
1747 : 54 : put_unaligned_be16(TCPOPT_NOP << 8 |
1748 : : TCPOPT_NOP, bptr);
1749 : :
1750 : 54 : ptr += 3;
1751 : : } else {
1752 : 42 : put_unaligned_be32(port << 16 |
1753 : 42 : TCPOPT_NOP << 8 |
1754 : : TCPOPT_NOP, ptr);
1755 : 42 : ptr += 1;
1756 : : }
1757 : : }
1758 [ + ]: 24229 : } else if (unlikely(OPTION_MPTCP_FASTCLOSE & opts->suboptions)) {
1759 : : /* FASTCLOSE is mutually exclusive with others except RST */
1760 : 467 : *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
1761 : : TCPOLEN_MPTCP_FASTCLOSE,
1762 : : 0, 0);
1763 [ - ][ - ]: 467 : put_unaligned_be64(opts->rcvr_key, ptr);
1764 : 467 : ptr += 2;
1765 : :
1766 [ - ][ - ]: 467 : if (OPTION_MPTCP_RST & opts->suboptions)
1767 : 467 : goto mp_rst;
1768 : : return;
1769 [ + ]: 23762 : } else if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions)) {
1770 : 2 : mp_fail:
1771 : : /* MP_FAIL is mutually exclusive with others except RST */
1772 [ + ][ + ]: 6 : subflow = mptcp_subflow_ctx(ssk);
1773 : 6 : subflow->send_mp_fail = 0;
1774 : :
1775 : 6 : *ptr++ = mptcp_option(MPTCPOPT_MP_FAIL,
1776 : : TCPOLEN_MPTCP_FAIL,
1777 : : 0, 0);
1778 [ + ][ + ]: 6 : put_unaligned_be64(opts->fail_seq, ptr);
1779 : 6 : ptr += 2;
1780 : :
1781 [ + ][ + ]: 6 : if (OPTION_MPTCP_RST & opts->suboptions)
1782 : 2 : goto mp_rst;
1783 : : return;
1784 [ + ]: 23760 : } else if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
1785 : 56 : mp_rst:
1786 : 525 : *ptr++ = mptcp_option(MPTCPOPT_RST,
1787 : : TCPOLEN_MPTCP_RST,
1788 : 525 : opts->reset_transient,
1789 : 525 : opts->reset_reason);
1790 : 525 : return;
1791 [ - ]: 23704 : } else if (unlikely(!opts->suboptions)) {
1792 : : /* Fallback to TCP */
1793 : 23704 : mptcp_track_rwin(tp);
1794 : 23704 : return;
1795 : : }
1796 : :
1797 [ + ]: 1559262 : if (OPTION_MPTCP_PRIO & opts->suboptions) {
1798 [ - ]: 28 : subflow = mptcp_subflow_ctx(ssk);
1799 : 28 : subflow->send_mp_prio = 0;
1800 : :
1801 : 28 : *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO,
1802 : : TCPOLEN_MPTCP_PRIO,
1803 [ - ]: 28 : opts->backup, TCPOPT_NOP);
1804 : :
1805 [ - ][ # ]: 28 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPPRIOTX);
1806 : : }
1807 : :
1808 : 1559234 : mp_capable_done:
1809 [ + ][ + ]: 1565123 : if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
1810 : 114 : u8 i = 1;
1811 : :
1812 : 114 : *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
1813 : 114 : TCPOLEN_MPTCP_RM_ADDR_BASE + opts->rm_list.nr,
1814 : 114 : 0, opts->rm_list.ids[0]);
1815 : :
1816 [ + ][ + ]: 118 : while (i < opts->rm_list.nr) {
1817 : 4 : u8 id1, id2, id3, id4;
1818 : :
1819 : 4 : id1 = opts->rm_list.ids[i];
1820 [ - ][ - ]: 4 : id2 = i + 1 < opts->rm_list.nr ? opts->rm_list.ids[i + 1] : TCPOPT_NOP;
1821 [ + ][ + ]: 4 : id3 = i + 2 < opts->rm_list.nr ? opts->rm_list.ids[i + 2] : TCPOPT_NOP;
1822 [ + ][ + ]: 4 : id4 = i + 3 < opts->rm_list.nr ? opts->rm_list.ids[i + 3] : TCPOPT_NOP;
1823 : 4 : put_unaligned_be32(id1 << 24 | id2 << 16 | id3 << 8 | id4, ptr);
1824 : 4 : ptr += 1;
1825 : 4 : i += 4;
1826 : : }
1827 : : }
1828 : : }
1829 : :
1830 : 16 : __be32 mptcp_get_reset_option(const struct sk_buff *skb)
1831 : : {
1832 [ - ]: 16 : const struct mptcp_ext *ext = mptcp_get_ext(skb);
1833 : 16 : u8 flags, reason;
1834 : :
1835 [ - ]: 16 : if (ext) {
1836 : 16 : flags = ext->reset_transient;
1837 : 16 : reason = ext->reset_reason;
1838 : :
1839 : 16 : return mptcp_option(MPTCPOPT_RST, TCPOLEN_MPTCP_RST,
1840 : : flags, reason);
1841 : : }
1842 : :
1843 : : return htonl(0u);
1844 : : }
1845 : : EXPORT_SYMBOL_GPL(mptcp_get_reset_option);
|