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