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