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 : 1922755 : 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 : 1922755 : u8 subtype = *ptr >> 4;
28 : 1922755 : int expected_opsize;
29 : 1922755 : u16 subopt;
30 : 1922755 : u8 version;
31 : 1922755 : u8 flags;
32 : 1922755 : u8 i;
33 : :
34 [ + + + + : 1922755 : switch (subtype) {
+ + + + +
- ]
35 : 7763 : case MPTCPOPT_MP_CAPABLE:
36 : : /* strict size checking */
37 [ + + ]: 7763 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) {
38 [ + + ]: 4513 : if (skb->len > tcp_hdr(skb)->doff << 2)
39 : : expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA;
40 : : else
41 : 3274 : expected_opsize = TCPOLEN_MPTCP_MPC_ACK;
42 : 4513 : subopt = OPTION_MPTCP_MPC_ACK;
43 : : } else {
44 [ + + ]: 3250 : 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 : 4513 : if (subopt == OPTION_MPTCP_MPC_ACK) {
55 [ + - ]: 4513 : if ((mp_opt->suboptions & ~OPTION_MPTCP_RM_ADDR) != 0)
56 : : break;
57 [ + - ]: 3250 : } 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 [ + + ]: 7763 : if (opsize != expected_opsize &&
72 : 148 : (expected_opsize != TCPOLEN_MPTCP_MPC_ACK_DATA ||
73 [ + + ]: 148 : opsize != TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM))
74 : : break;
75 : :
76 : : /* try to be gentle vs future versions on the initial syn */
77 : 7751 : version = *ptr++ & MPTCP_VERSION_MASK;
78 [ + + ]: 7751 : if (opsize != TCPOLEN_MPTCP_MPC_SYN) {
79 [ + + ]: 6009 : if (version != MPTCP_SUPPORTED_VERSION)
80 : : break;
81 [ + - ]: 1742 : } else if (version < MPTCP_SUPPORTED_VERSION) {
82 : : break;
83 : : }
84 : :
85 : 7745 : flags = *ptr++;
86 [ + + + + ]: 7745 : 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 : 7709 : if ((flags & MPTCP_CAP_CHECKSUM_REQD) &&
97 [ + + ]: 7709 : opsize < TCPOLEN_MPTCP_MPC_ACK_DATA)
98 : 476 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
99 : :
100 : 7709 : mp_opt->deny_join_id0 = !!(flags & MPTCP_CAP_DENY_JOIN_ID0);
101 : :
102 : 7709 : mp_opt->suboptions |= subopt;
103 [ + + ]: 7709 : if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) {
104 [ + + ]: 5979 : mp_opt->sndr_key = get_unaligned_be64(ptr);
105 : 5979 : ptr += 8;
106 : : }
107 [ + + ]: 5979 : if (opsize >= TCPOLEN_MPTCP_MPC_ACK) {
108 [ + + ]: 4495 : mp_opt->rcvr_key = get_unaligned_be64(ptr);
109 : 4495 : ptr += 8;
110 : : }
111 [ + + ]: 4495 : 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 : 1239 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
118 : 1239 : mp_opt->use_map = 1;
119 : 1239 : mp_opt->mpc_map = 1;
120 [ + + ]: 1239 : mp_opt->data_len = get_unaligned_be16(ptr);
121 : 1239 : ptr += 2;
122 : : }
123 [ + + ]: 1239 : if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM) {
124 : 136 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
125 : 136 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
126 : 136 : ptr += 2;
127 : : }
128 [ - + - - : 7709 : 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 : 2481 : case MPTCPOPT_MP_JOIN:
137 : : /* Can be used with a restricted number of other options */
138 [ + - ]: 2481 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_RM_ADDR |
139 : : OPTION_MPTCP_PRIO)) != 0)
140 : : break;
141 : :
142 [ + + ]: 2481 : if (opsize == TCPOLEN_MPTCP_MPJ_SYN) {
143 : 634 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_SYN;
144 : 634 : mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP;
145 : 634 : mp_opt->join_id = *ptr++;
146 [ - + ]: 634 : mp_opt->token = get_unaligned_be32(ptr);
147 : 634 : ptr += 4;
148 : 634 : mp_opt->nonce = get_unaligned_be32(ptr);
149 : 634 : ptr += 4;
150 [ - + - - ]: 634 : 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 [ + + ]: 1847 : } 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 [ + - ]: 1253 : } else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) {
165 : 1253 : mp_opt->suboptions |= OPTION_MPTCP_MPJ_ACK;
166 : 1253 : ptr += 2;
167 : 1253 : memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN);
168 [ - + - - ]: 1253 : pr_debug("MP_JOIN hmac\n");
169 : : }
170 : : break;
171 : :
172 : 1910953 : case MPTCPOPT_DSS:
173 : : /* Can be used with a restricted number of other options */
174 [ + - ]: 1910953 : 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 [ - + - - ]: 1910953 : pr_debug("DSS\n");
182 : 1910953 : ptr++;
183 : :
184 : 1910953 : flags = (*ptr++) & MPTCP_DSS_FLAG_MASK;
185 : 1910953 : mp_opt->dsn64 = (flags & MPTCP_DSS_DSN64) != 0;
186 : 1910953 : mp_opt->use_map = (flags & MPTCP_DSS_HAS_MAP) != 0;
187 : 1910953 : mp_opt->ack64 = (flags & MPTCP_DSS_ACK64) != 0;
188 : 1910953 : mp_opt->use_ack = (flags & MPTCP_DSS_HAS_ACK);
189 : :
190 : 1910953 : expected_opsize = TCPOLEN_MPTCP_DSS_BASE;
191 : :
192 [ + - ]: 1910953 : if (mp_opt->use_ack) {
193 [ + + ]: 1910953 : if (mp_opt->ack64)
194 : : expected_opsize += TCPOLEN_MPTCP_DSS_ACK64;
195 : : else
196 : 309696 : expected_opsize += TCPOLEN_MPTCP_DSS_ACK32;
197 : : }
198 : :
199 [ + + ]: 1910953 : if (mp_opt->use_map) {
200 : 1203041 : mp_opt->data_fin = (flags & MPTCP_DSS_DATA_FIN) != 0;
201 [ + + ]: 1203041 : if (mp_opt->dsn64)
202 : 1202999 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP64;
203 : : else
204 : 42 : expected_opsize += TCPOLEN_MPTCP_DSS_MAP32;
205 : : }
206 : :
207 [ - + - - ]: 1910953 : 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 [ + + ]: 1910953 : if (opsize != expected_opsize &&
216 [ - + ]: 164073 : 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 : 1910953 : mp_opt->suboptions |= OPTION_MPTCP_DSS;
226 [ + - ]: 1910953 : if (mp_opt->use_ack) {
227 [ + + ]: 1910953 : if (mp_opt->ack64) {
228 : 1601257 : mp_opt->data_ack = get_unaligned_be64(ptr);
229 : 1601257 : ptr += 8;
230 : : } else {
231 : 309696 : mp_opt->data_ack = get_unaligned_be32(ptr);
232 : 309696 : ptr += 4;
233 : : }
234 : :
235 [ - + - - ]: 1910953 : pr_debug("data_ack=%llu\n", mp_opt->data_ack);
236 : : }
237 : :
238 [ + + ]: 1910953 : if (mp_opt->use_map) {
239 [ + + ]: 1203041 : if (mp_opt->dsn64) {
240 : 1202999 : mp_opt->data_seq = get_unaligned_be64(ptr);
241 : 1202999 : ptr += 8;
242 : : } else {
243 : 42 : mp_opt->data_seq = get_unaligned_be32(ptr);
244 : 42 : ptr += 4;
245 : : }
246 : :
247 [ + + ]: 1203041 : mp_opt->subflow_seq = get_unaligned_be32(ptr);
248 : 1203041 : ptr += 4;
249 : :
250 [ + + ]: 1203041 : mp_opt->data_len = get_unaligned_be16(ptr);
251 : 1203041 : ptr += 2;
252 : :
253 [ + + ]: 1203041 : if (opsize == expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) {
254 : 164073 : mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
255 : 164073 : mp_opt->csum = get_unaligned((__force __sum16 *)ptr);
256 : 164073 : ptr += 2;
257 : : }
258 : :
259 [ - + - - : 1203041 : pr_debug("data_seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n",
- - ]
260 : : mp_opt->data_seq, mp_opt->subflow_seq,
261 : : mp_opt->data_len, !!(mp_opt->suboptions & OPTION_MPTCP_CSUMREQD),
262 : : (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) ? mp_opt->csum : 0);
263 : : }
264 : :
265 : : break;
266 : :
267 : 841 : case MPTCPOPT_ADD_ADDR:
268 : : /* Can be used with a restricted number of other options */
269 [ + - ]: 841 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
270 : : OPTION_MPTCP_RM_ADDR |
271 : : OPTION_MPTCP_PRIO)) != 0)
272 : : break;
273 : :
274 : 841 : mp_opt->echo = (*ptr++) & MPTCP_ADDR_ECHO;
275 [ + + ]: 841 : if (!mp_opt->echo) {
276 : 425 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR ||
277 [ + + ]: 425 : opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT)
278 : 331 : mp_opt->addr.family = AF_INET;
279 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
280 : 94 : else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 ||
281 [ + - ]: 94 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT)
282 : 94 : mp_opt->addr.family = AF_INET6;
283 : : #endif
284 : : else
285 : : break;
286 : : } else {
287 : 416 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE ||
288 [ + + ]: 416 : opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT)
289 : 318 : mp_opt->addr.family = AF_INET;
290 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
291 : 98 : else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE ||
292 [ + - ]: 98 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT)
293 : 98 : mp_opt->addr.family = AF_INET6;
294 : : #endif
295 : : else
296 : : break;
297 : : }
298 : :
299 : 841 : mp_opt->suboptions |= OPTION_MPTCP_ADD_ADDR;
300 : 841 : mp_opt->addr.id = *ptr++;
301 : 841 : mp_opt->addr.port = 0;
302 : 841 : mp_opt->ahmac = 0;
303 [ + + ]: 841 : if (mp_opt->addr.family == AF_INET) {
304 : 649 : memcpy((u8 *)&mp_opt->addr.addr.s_addr, (u8 *)ptr, 4);
305 : 649 : ptr += 4;
306 : 649 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT ||
307 [ + + ]: 649 : opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) {
308 : 74 : mp_opt->addr.port = htons(get_unaligned_be16(ptr));
309 : 74 : ptr += 2;
310 : : }
311 : : }
312 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
313 : : else {
314 : 192 : memcpy(mp_opt->addr.addr6.s6_addr, (u8 *)ptr, 16);
315 : 192 : ptr += 16;
316 : 192 : if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT ||
317 [ + + ]: 192 : opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) {
318 : 22 : mp_opt->addr.port = htons(get_unaligned_be16(ptr));
319 : 22 : ptr += 2;
320 : : }
321 : : }
322 : : #endif
323 [ + + ]: 841 : if (!mp_opt->echo) {
324 : 425 : mp_opt->ahmac = get_unaligned_be64(ptr);
325 : 425 : ptr += 8;
326 : : }
327 [ - + - - : 841 : pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d\n",
- - ]
328 : : (mp_opt->addr.family == AF_INET6) ? "6" : "",
329 : : mp_opt->addr.id, mp_opt->ahmac, mp_opt->echo, ntohs(mp_opt->addr.port));
330 : : break;
331 : :
332 : 108 : case MPTCPOPT_RM_ADDR:
333 : : /* Can be used with a restricted number of other options */
334 [ + - ]: 108 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_MPC_ACK |
335 : : OPTIONS_MPTCP_MPJ |
336 : : OPTIONS_MPTCP_DSS |
337 : : OPTION_MPTCP_ADD_ADDR |
338 : : OPTION_MPTCP_PRIO)) != 0)
339 : : break;
340 : :
341 [ + - ]: 108 : if (opsize < TCPOLEN_MPTCP_RM_ADDR_BASE + 1 ||
342 : : opsize > TCPOLEN_MPTCP_RM_ADDR_BASE + MPTCP_RM_IDS_MAX)
343 : : break;
344 : :
345 : 108 : ptr++;
346 : :
347 : 108 : mp_opt->suboptions |= OPTION_MPTCP_RM_ADDR;
348 : 108 : mp_opt->rm_list.nr = opsize - TCPOLEN_MPTCP_RM_ADDR_BASE;
349 [ + + ]: 224 : for (i = 0; i < mp_opt->rm_list.nr; i++)
350 : 116 : mp_opt->rm_list.ids[i] = *ptr++;
351 [ - + - - ]: 108 : pr_debug("RM_ADDR: rm_list_nr=%d\n", mp_opt->rm_list.nr);
352 : : break;
353 : :
354 : 46 : case MPTCPOPT_MP_PRIO:
355 : : /* Can be used with a restricted number of other options */
356 [ + - ]: 46 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_MPJ |
357 : : OPTIONS_MPTCP_DSS |
358 : : OPTION_MPTCP_ADD_ADDR |
359 : : OPTION_MPTCP_RM_ADDR)) != 0)
360 : : break;
361 : :
362 [ + + ]: 46 : if (opsize != TCPOLEN_MPTCP_PRIO)
363 : : break;
364 : :
365 : 40 : mp_opt->suboptions |= OPTION_MPTCP_PRIO;
366 : 40 : mp_opt->backup = *ptr++ & MPTCP_PRIO_BKUP;
367 [ - + - - ]: 40 : pr_debug("MP_PRIO: prio=%d\n", mp_opt->backup);
368 : : break;
369 : :
370 : 276 : case MPTCPOPT_MP_FASTCLOSE:
371 : : /* Can be used with a restricted number of other options */
372 [ + - ]: 276 : if ((mp_opt->suboptions & ~(OPTIONS_MPTCP_DSS |
373 : : OPTION_MPTCP_RST)) != 0)
374 : : break;
375 : :
376 [ + - ]: 276 : if (opsize != TCPOLEN_MPTCP_FASTCLOSE)
377 : : break;
378 : :
379 : 276 : ptr += 2;
380 [ - + ]: 276 : mp_opt->rcvr_key = get_unaligned_be64(ptr);
381 : 276 : ptr += 8;
382 : 276 : mp_opt->suboptions |= OPTION_MPTCP_FASTCLOSE;
383 [ - + - - ]: 276 : pr_debug("MP_FASTCLOSE: recv_key=%llu\n", mp_opt->rcvr_key);
384 : : break;
385 : :
386 : 281 : case MPTCPOPT_RST:
387 : : /* Can be used with a restricted number of other options */
388 [ + - ]: 281 : if ((mp_opt->suboptions & ~(OPTION_MPTCP_FAIL |
389 : : OPTION_MPTCP_FASTCLOSE)) != 0)
390 : : break;
391 : :
392 [ + - ]: 281 : if (opsize != TCPOLEN_MPTCP_RST)
393 : : break;
394 : :
395 [ + + ]: 281 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST))
396 : : break;
397 : :
398 : 269 : mp_opt->suboptions |= OPTION_MPTCP_RST;
399 : 269 : flags = *ptr++;
400 : 269 : mp_opt->reset_transient = flags & MPTCP_RST_TRANSIENT;
401 : 269 : mp_opt->reset_reason = *ptr;
402 [ - + - - ]: 269 : 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 : 1922755 : }
425 : :
426 : 1922939 : void mptcp_get_options(const struct sk_buff *skb,
427 : : struct mptcp_options_received *mp_opt)
428 : : {
429 : 1922939 : const struct tcphdr *th = tcp_hdr(skb);
430 : 1922939 : const unsigned char *ptr;
431 : 1922939 : int length;
432 : :
433 : : /* Ensure that casting the whole status to u32 is efficient and safe */
434 : 1922939 : BUILD_BUG_ON(sizeof_field(struct mptcp_options_received, status) != sizeof(u32));
435 : 1922939 : BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct mptcp_options_received, status),
436 : : sizeof(u32)));
437 : 1922939 : *(u32 *)&mp_opt->status = 0;
438 : :
439 : 1922939 : length = (th->doff * 4) - sizeof(struct tcphdr);
440 : 1922939 : ptr = (const unsigned char *)(th + 1);
441 : :
442 [ + + ]: 11737105 : while (length > 0) {
443 : 9814166 : int opcode = *ptr++;
444 : 9814166 : int opsize;
445 : :
446 [ + + - ]: 9814166 : switch (opcode) {
447 : : case TCPOPT_EOL:
448 : : return;
449 : 5943692 : case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */
450 : 5943692 : length--;
451 : 5943692 : continue;
452 : 3870474 : default:
453 [ + - ]: 3870474 : if (length < 2)
454 : : return;
455 : 3870474 : opsize = *ptr++;
456 [ + - ]: 3870474 : if (opsize < 2) /* "silly options" */
457 : : return;
458 [ + - ]: 3870474 : if (opsize > length)
459 : : return; /* don't parse partial options */
460 [ + + ]: 3870474 : if (opcode == TCPOPT_MPTCP)
461 : 1922755 : mptcp_parse_option(skb, ptr, opsize, mp_opt);
462 : 3870474 : ptr += opsize - 2;
463 : 3870474 : length -= opsize;
464 : : }
465 : : }
466 : : }
467 : :
468 : 2504 : bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
469 : : unsigned int *size, struct mptcp_out_options *opts)
470 : : {
471 [ + + ]: 2504 : 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 : 2504 : subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
477 [ + + ]: 2504 : if (subflow->request_mptcp) {
478 [ + + ]: 1762 : 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 : 1756 : opts->suboptions = OPTION_MPTCP_MPC_SYN;
489 : 1756 : opts->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk));
490 : 1756 : opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk));
491 : 1756 : *size = TCPOLEN_MPTCP_MPC_SYN;
492 : 1756 : return true;
493 [ + + ]: 742 : } else if (subflow->request_join) {
494 [ - + - - ]: 706 : pr_debug("remote_token=%u, nonce=%u\n", subflow->remote_token,
495 : : subflow->local_nonce);
496 : 706 : opts->suboptions = OPTION_MPTCP_MPJ_SYN;
497 : 706 : opts->join_id = subflow->local_id;
498 : 706 : opts->token = subflow->remote_token;
499 : 706 : opts->nonce = subflow->local_nonce;
500 : 706 : opts->backup = subflow->request_bkup;
501 : 706 : *size = TCPOLEN_MPTCP_MPJ_SYN;
502 : 706 : 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 : 3301041 : 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 [ - + ]: 3301041 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
521 [ - + ]: 3301041 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
522 : 3301041 : struct mptcp_ext *mpext;
523 : 3301041 : unsigned int data_len;
524 : 3301041 : 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 [ + + ]: 3301041 : if (!skb)
533 : : return false;
534 : :
535 : : /* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
536 [ - + + + ]: 1513298 : if (subflow->fully_established || snd_data_fin_enable ||
[ + + ]
537 [ + + ]: 4248 : subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
538 [ + + ]: 3109 : sk->sk_state != TCP_ESTABLISHED)
539 : : return false;
540 : :
541 [ + + ]: 3109 : if (subflow->mp_capable) {
542 [ + + ]: 2502 : mpext = mptcp_get_ext(skb);
543 [ + + ]: 1760 : 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 : 2502 : opts->data_len = data_len;
550 : 2502 : opts->suboptions = OPTION_MPTCP_MPC_ACK;
551 : 2502 : opts->sndr_key = subflow->local_key;
552 : 2502 : opts->rcvr_key = subflow->remote_key;
553 [ - + ]: 2502 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
554 : 2502 : 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 [ + + ]: 2502 : if (data_len > 0) {
562 : 1018 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
563 [ + + ]: 1018 : if (opts->csum_reqd) {
564 : : /* we need to propagate more info to csum the pseudo hdr */
565 : 108 : opts->data_seq = mpext->data_seq;
566 : 108 : opts->subflow_seq = mpext->subflow_seq;
567 : 108 : opts->csum = mpext->csum;
568 : 108 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
569 : : }
570 : 1018 : *size = ALIGN(len, 4);
571 : : } else {
572 : 1484 : *size = TCPOLEN_MPTCP_MPC_ACK;
573 : : }
574 : :
575 [ - + - - ]: 2502 : 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 : 2502 : return true;
580 [ + + ]: 607 : } else if (subflow->mp_join) {
581 : 607 : opts->suboptions = OPTION_MPTCP_MPJ_ACK;
582 : 607 : memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN);
583 : 607 : *size = TCPOLEN_MPTCP_MPJ_ACK;
584 [ - + - - ]: 607 : 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 [ + + ]: 607 : if (sock_owned_by_user(sk))
592 : 516 : set_bit(MPTCP_DELEGATE_ACK, &subflow->delegated_status);
593 : : else
594 : 91 : mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_ACK);
595 : 607 : return true;
596 : : }
597 : : return false;
598 : : }
599 : :
600 : 35233 : 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 [ - + ]: 35233 : u64 data_fin_tx_seq = READ_ONCE(mptcp_sk(subflow->conn)->write_seq) - 1;
607 : :
608 [ + + - + ]: 35233 : 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 : 18607 : ext->data_fin = 1;
613 : 18607 : ext->use_map = 1;
614 : 18607 : ext->dsn64 = 1;
615 : 18607 : ext->data_seq = data_fin_tx_seq;
616 : 18607 : ext->subflow_seq = 0;
617 : 18607 : ext->data_len = 1;
618 : 18607 : ext->csum = 0;
619 [ + + ]: 16626 : } 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 : 1553 : ext->data_fin = 1;
625 : 1553 : ext->data_len++;
626 : : }
627 : 35233 : }
628 : :
629 : 3297932 : 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 [ - + ]: 3297932 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
634 [ - + ]: 3297932 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
635 [ - + ]: 3297932 : struct tcp_sock *tp = tcp_sk(sk);
636 : 3297932 : unsigned int dss_size = 0;
637 : 3297932 : struct mptcp_ext *mpext;
638 : 3297932 : unsigned int ack_size;
639 : 3297932 : bool ret = false;
640 : :
641 : : /* Zero `use_ack` and `use_map` flags with one shot. */
642 : 3297932 : memset(&opts->ext_copy.flags, 0, sizeof(opts->ext_copy.flags));
643 [ - + ]: 3297932 : opts->csum_reqd = READ_ONCE(msk->csum_enabled);
644 [ + + ]: 3297932 : mpext = skb ? mptcp_get_ext(skb) : NULL;
645 : :
646 [ + + - + : 1510189 : if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) {
+ + ]
647 : 2571363 : unsigned int map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64;
648 : :
649 [ + + ]: 2571363 : if (mpext) {
650 [ + + ]: 765013 : if (opts->csum_reqd)
651 : 89065 : map_size += TCPOLEN_MPTCP_DSS_CHECKSUM;
652 : :
653 : 765013 : opts->ext_copy = *mpext;
654 : : }
655 : :
656 : 2571363 : dss_size = map_size;
657 [ + + ]: 2571363 : if (skb && snd_data_fin_enable)
658 : 35233 : mptcp_write_data_fin(subflow, skb, &opts->ext_copy);
659 : 2571363 : opts->suboptions = OPTION_MPTCP_DSS;
660 : 2571363 : 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 [ - + + + ]: 3297932 : if (!READ_ONCE(msk->can_ack)) {
[ + + ]
667 : 30 : *size = ALIGN(dss_size, 4);
668 : 30 : return ret;
669 : : }
670 : :
671 [ - + + + ]: 3297902 : if (READ_ONCE(msk->use_64bit_ack)) {
[ + + ]
672 : 2892769 : ack_size = TCPOLEN_MPTCP_DSS_ACK64;
673 : 2892769 : opts->ext_copy.ack64 = 1;
674 : : } else {
675 : 405133 : ack_size = TCPOLEN_MPTCP_DSS_ACK32;
676 : 405133 : opts->ext_copy.ack64 = 0;
677 : : }
678 : 3297902 : opts->ext_copy.use_ack = 1;
679 : 3297902 : opts->suboptions = OPTION_MPTCP_DSS;
680 : :
681 : : /* Add kind/length/subtype/flag overhead if mapping is not populated */
682 [ + + ]: 3297902 : if (dss_size == 0)
683 : 726569 : 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 [ + + ]: 3297902 : if (skb)
689 : 1510189 : tp->rcv_wnd = tp->rcv_nxt - tp->rcv_wup;
690 : :
691 : 3297902 : dss_size += ack_size;
692 : :
693 : 3297902 : *size = ALIGN(dss_size, 4);
694 : 3297902 : return true;
695 : : }
696 : :
697 : 918 : static u64 add_addr_generate_hmac(u64 key1, u64 key2,
698 : : struct mptcp_addr_info *addr)
699 : : {
700 : 918 : u16 port = ntohs(addr->port);
701 : 918 : u8 hmac[SHA256_DIGEST_SIZE];
702 : 918 : u8 msg[19];
703 : 918 : int i = 0;
704 : :
705 : 918 : msg[i++] = addr->id;
706 [ + + ]: 918 : if (addr->family == AF_INET) {
707 : 710 : memcpy(&msg[i], &addr->addr.s_addr, 4);
708 : 710 : i += 4;
709 : : }
710 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
711 [ + - ]: 208 : else if (addr->family == AF_INET6) {
712 : 208 : memcpy(&msg[i], &addr->addr6.s6_addr, 16);
713 : 208 : i += 16;
714 : : }
715 : : #endif
716 : 918 : msg[i++] = port >> 8;
717 : 918 : msg[i++] = port & 0xFF;
718 : :
719 : 918 : mptcp_crypto_hmac_sha(key1, key2, msg, i, hmac);
720 : :
721 : 918 : return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]);
722 : : }
723 : :
724 : 3301037 : 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 [ - + ]: 3301037 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
731 [ - + ]: 3301037 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
732 : 3301037 : struct mptcp_addr_info addr;
733 : 3301037 : bool drop_ts = has_ts;
734 : 3301037 : bool echo;
735 : :
736 : : /* add addr will strip the existing options, be sure to avoid breaking
737 : : * MPC/MPJ handshakes
738 : : */
739 [ + + ]: 3301037 : if (!mptcp_pm_should_add_signal(msk) ||
740 [ + - + + ]: 919 : (opts->suboptions & (OPTION_MPTCP_MPJ_ACK | OPTION_MPTCP_MPC_ACK)) ||
741 [ + + + + ]: 1829 : !skb || !skb_is_tcp_pure_ack(skb) ||
742 : 913 : !mptcp_pm_add_addr_signal(msk, size, remaining, &addr, &echo,
743 : : &drop_ts))
744 : 3300132 : return false;
745 : :
746 [ - + - - ]: 905 : pr_debug("drop other suboptions\n");
747 : 905 : opts->suboptions = OPTION_MPTCP_ADD_ADDR;
748 [ - + ]: 905 : opts->drop_ts = drop_ts;
749 : 905 : opts->addr = addr;
750 [ - + + + ]: 905 : if (!echo) {
[ + + ]
751 [ + - ]: 493 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX);
752 : 493 : opts->ahmac = add_addr_generate_hmac(READ_ONCE(msk->local_key),
753 : 493 : 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 [ - + - - : 905 : 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 : 3300132 : static bool mptcp_established_options_rm_addr(struct sock *sk, int *size,
766 : : unsigned int remaining,
767 : : struct mptcp_out_options *opts)
768 : : {
769 [ - + ]: 3300132 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
770 [ - + ]: 3300132 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
771 : 3300132 : struct mptcp_rm_list rm_list;
772 : 3300132 : int i;
773 : :
774 [ + + - + ]: 3300246 : if (!mptcp_pm_should_rm_signal(msk) ||
775 : 114 : !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, size)))
776 : 3300018 : 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 : 3301037 : static bool mptcp_established_options_mp_prio(struct sock *sk, int *size,
788 : : unsigned int remaining,
789 : : struct mptcp_out_options *opts)
790 : : {
791 [ + + ]: 3301037 : 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 [ + + + - ]: 3301037 : 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 : 534 : 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 [ + - ]: 534 : const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
818 : :
819 [ + - ]: 534 : if (remaining < TCPOLEN_MPTCP_RST)
820 : : return false;
821 : :
822 : 534 : *size = TCPOLEN_MPTCP_RST;
823 : 534 : opts->suboptions |= OPTION_MPTCP_RST;
824 : 534 : opts->reset_transient = subflow->reset_transient;
825 : 534 : opts->reset_reason = subflow->reset_reason;
826 [ + - ]: 534 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTTX);
827 : :
828 : : return true;
829 : : }
830 : :
831 : 534 : static bool mptcp_established_options_fastclose(struct sock *sk, int *size,
832 : : unsigned int remaining,
833 : : struct mptcp_out_options *opts)
834 : : {
835 [ - + ]: 534 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
836 [ - + ]: 534 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
837 : :
838 [ + + ]: 534 : if (likely(!subflow->send_fastclose))
839 : : return false;
840 : :
841 [ + - ]: 479 : if (remaining < TCPOLEN_MPTCP_FASTCLOSE)
842 : : return false;
843 : :
844 : 479 : *size = TCPOLEN_MPTCP_FASTCLOSE;
845 : 479 : opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
846 : 479 : opts->rcvr_key = READ_ONCE(msk->remote_key);
847 : :
848 [ - + - - ]: 479 : pr_debug("FASTCLOSE key=%llu\n", opts->rcvr_key);
849 [ + - ]: 479 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX);
850 : : return true;
851 : : }
852 : :
853 : 3297987 : static bool mptcp_established_options_mp_fail(struct sock *sk, int *size,
854 : : unsigned int remaining,
855 : : struct mptcp_out_options *opts)
856 : : {
857 [ + + ]: 3297987 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
858 : :
859 [ + + ]: 3297987 : 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 : 3402990 : 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 [ - + ]: 3402990 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
880 [ - + ]: 3402990 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
881 : 3402990 : int total_size = 0;
882 : 3402990 : bool snd_data_fin;
883 : 3402990 : bool ret = false;
884 : 3402990 : int opt_size = 0;
885 : :
886 : 3402990 : opts->suboptions = 0;
887 : :
888 : : /* Force later mptcp_write_options(), but do not use any actual
889 : : * option space.
890 : : */
891 [ + + + + ]: 3402990 : if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb)))
892 : : return 0;
893 : :
894 [ + + + + ]: 3301575 : if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
895 [ + + + + ]: 589 : if (mptcp_established_options_fastclose(sk, &opt_size, remaining, opts) ||
896 : 55 : mptcp_established_options_mp_fail(sk, &opt_size, remaining, opts)) {
897 : 481 : total_size += opt_size;
898 : 481 : remaining -= opt_size;
899 : : }
900 : : /* MP_RST can be used with MP_FASTCLOSE and MP_FAIL if there is room */
901 [ + - ]: 534 : if (mptcp_established_options_rst(sk, &opt_size, remaining, opts)) {
902 : 534 : total_size += opt_size;
903 : 534 : remaining -= opt_size;
904 : : }
905 : 534 : return total_size;
906 : : }
907 : :
908 [ + + ]: 3301041 : snd_data_fin = mptcp_data_fin_enabled(msk);
909 [ + + ]: 3301041 : if (mptcp_established_options_mp(sk, skb, snd_data_fin, &opt_size, opts))
910 : : ret = true;
911 [ + - ]: 3297932 : else if (mptcp_established_options_dss(sk, skb, snd_data_fin, &opt_size, opts)) {
912 : 3297932 : int mp_fail_size;
913 : :
914 : 3297932 : ret = true;
915 [ + + ]: 3297932 : 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 [ - + - + ]: 3301037 : if (WARN_ON_ONCE(opt_size > remaining))
927 : : return -1;
928 : :
929 : 3301037 : total_size += opt_size;
930 : 3301037 : remaining -= opt_size;
931 [ + + ]: 3301037 : if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining,
932 : : has_ts, opts)) {
933 : 905 : total_size += opt_size;
934 : 905 : remaining -= opt_size;
935 : 905 : ret = true;
936 [ + + ]: 3300132 : } 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 [ + + ]: 3301037 : 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 [ - + ]: 3301037 : return ret ? total_size : -1;
949 : : }
950 : :
951 : 2460 : bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
952 : : struct mptcp_out_options *opts)
953 : : {
954 : 2460 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
955 : :
956 [ + + ]: 2460 : if (subflow_req->mp_capable) {
957 : 1672 : opts->suboptions = OPTION_MPTCP_MPC_SYNACK;
958 : 1672 : opts->sndr_key = subflow_req->local_key;
959 : 1672 : opts->csum_reqd = subflow_req->csum_reqd;
960 : 1672 : opts->allow_join_id0 = subflow_req->allow_join_id0;
961 : 1672 : *size = TCPOLEN_MPTCP_MPC_SYNACK;
962 [ - + - - ]: 1672 : pr_debug("subflow_req=%p, local_key=%llu\n",
963 : : subflow_req, subflow_req->local_key);
964 : 1672 : return true;
965 [ + + ]: 788 : } else if (subflow_req->mp_join) {
966 : 628 : opts->suboptions = OPTION_MPTCP_MPJ_SYNACK;
967 : 628 : opts->backup = subflow_req->request_bkup;
968 : 628 : opts->join_id = subflow_req->local_id;
969 : 628 : opts->thmac = subflow_req->thmac;
970 : 628 : opts->nonce = subflow_req->local_nonce;
971 [ - + - - ]: 628 : 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 : 628 : *size = TCPOLEN_MPTCP_MPJ_SYNACK;
975 : 628 : return true;
976 : : }
977 : : return false;
978 : : }
979 : :
980 : 1915859 : 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 [ - + + + ]: 1915859 : 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 [ + + ]: 1913748 : if (TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 &&
994 [ + + + + ]: 271438 : TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq &&
995 [ + + ]: 74082 : subflow->mp_join && (mp_opt->suboptions & OPTIONS_MPTCP_MPJ) &&
996 [ + - ]: 613 : !subflow->request_join)
997 : 613 : tcp_send_ack(ssk);
998 : 1913748 : 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 [ + + ]: 2111 : if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
1007 [ - + ]: 55 : if (subflow->mp_join)
1008 : 0 : goto reset;
1009 [ - + - - ]: 55 : if (subflow->is_mptfo && mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
1010 : 0 : goto set_fully_established;
1011 : 55 : 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 : 95 : ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) &&
1017 [ + + + - ]: 95 : (!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 : 1997 : 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 [ + + ]: 59 : if (!(mp_opt->suboptions & OPTIONS_MPTCP_MPC)) {
1029 [ + + ]: 15 : if (subflow->mp_join)
1030 : 8 : goto reset;
1031 : 7 : subflow->mp_capable = 0;
1032 [ - + ]: 7 : 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 [ - + ]: 2041 : if (mp_opt->deny_join_id0)
1045 : 0 : WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
1046 : :
1047 : 2041 : mptcp_data_lock((struct sock *)msk);
1048 : 2041 : __mptcp_subflow_fully_established(msk, subflow, mp_opt);
1049 : 2041 : mptcp_data_unlock((struct sock *)msk);
1050 : :
1051 : 1915789 : 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 [ + + + - ]: 1915789 : if (likely(subflow->pm_notified) || list_empty(&subflow->node))
1058 : : return true;
1059 : :
1060 : 2653 : subflow->pm_notified = 1;
1061 [ + + ]: 2653 : if (subflow->mp_join) {
1062 : 1198 : clear_3rdack_retransmission(ssk);
1063 : 1198 : mptcp_pm_subflow_established(msk);
1064 : : } else {
1065 : 1455 : 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 : 321323 : u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq)
1075 : : {
1076 : 321323 : u32 old_seq32, cur_seq32;
1077 : :
1078 : 321323 : old_seq32 = (u32)old_seq;
1079 : 321323 : cur_seq32 = (u32)cur_seq;
1080 : 321323 : cur_seq = (old_seq & GENMASK_ULL(63, 32)) + cur_seq32;
1081 [ + + - + ]: 321323 : 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 [ + + - + ]: 321323 : 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 : 544707 : msk->bytes_acked += new_snd_una - msk->snd_una;
1093 : 544707 : WRITE_ONCE(msk->snd_una, new_snd_una);
1094 : : }
1095 : :
1096 : 1912186 : static void rwin_update(struct mptcp_sock *msk, struct sock *ssk,
1097 : : struct sk_buff *skb)
1098 : : {
1099 [ - + ]: 1912186 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1100 [ - + ]: 1912186 : struct tcp_sock *tp = tcp_sk(ssk);
1101 : 1912186 : 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 [ + - + + ]: 1912186 : if (!skb->len || skb->len < tcp_receive_window(tp))
1108 : : return;
1109 : :
1110 [ - + ]: 7050 : mptcp_rcv_wnd = atomic64_read(&msk->rcv_wnd_sent);
1111 [ - + ]: 7050 : 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 : 1910953 : static void ack_update_msk(struct mptcp_sock *msk,
1123 : : struct sock *ssk,
1124 : : struct mptcp_options_received *mp_opt)
1125 : : {
1126 : 1910953 : u64 new_wnd_end, new_snd_una, snd_nxt = READ_ONCE(msk->snd_nxt);
1127 : 1910953 : struct sock *sk = (struct sock *)msk;
1128 : 1910953 : u64 old_snd_una;
1129 : :
1130 : 1910953 : 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 : 1910953 : old_snd_una = msk->snd_una;
1137 [ + + ]: 1910953 : new_snd_una = mptcp_expand_seq(old_snd_una, mp_opt->data_ack, mp_opt->ack64);
1138 : :
1139 : : /* ACK for data not even sent yet? Ignore.*/
1140 [ + + ]: 1910953 : if (unlikely(after64(new_snd_una, snd_nxt)))
1141 : 104 : new_snd_una = old_snd_una;
1142 : :
1143 [ - + ]: 1910953 : new_wnd_end = new_snd_una + tcp_sk(ssk)->snd_wnd;
1144 : :
1145 [ + + ]: 1910953 : if (after64(new_wnd_end, msk->wnd_end))
1146 : 524771 : WRITE_ONCE(msk->wnd_end, new_wnd_end);
1147 : :
1148 : : /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */
1149 [ + + ]: 1910953 : if (after64(msk->wnd_end, snd_nxt))
1150 : 1784142 : __mptcp_check_push(sk, ssk);
1151 : :
1152 [ + + ]: 1910953 : if (after64(new_snd_una, old_snd_una)) {
1153 : 522636 : __mptcp_snd_una_update(msk, new_snd_una);
1154 : 522636 : __mptcp_data_acked(sk);
1155 : : }
1156 : 1910953 : msk->last_ack_recv = tcp_jiffies32;
1157 : 1910953 : mptcp_data_unlock(sk);
1158 : :
1159 : 1910953 : trace_ack_update_msk(mp_opt->data_ack,
1160 : : old_snd_una, new_snd_una,
1161 : 1910953 : new_wnd_end, READ_ONCE(msk->wnd_end));
1162 : 1910953 : }
1163 : :
1164 : 17960 : bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit)
1165 : : {
1166 : : /* Skip if DATA_FIN was already received.
1167 : : * If updating simultaneously with the recvmsg loop, values
1168 : : * should match. If they mismatch, the peer is misbehaving and
1169 : : * we will prefer the most recent information.
1170 : : */
1171 [ - + + + ]: 17960 : if (READ_ONCE(msk->rcv_data_fin))
[ + + ]
1172 : : return false;
1173 : :
1174 [ + + ]: 3248 : WRITE_ONCE(msk->rcv_data_fin_seq,
1175 : : mptcp_expand_seq(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit));
1176 : 3248 : WRITE_ONCE(msk->rcv_data_fin, 1);
1177 : :
1178 : 3248 : return true;
1179 : : }
1180 : :
1181 : 841 : static bool add_addr_hmac_valid(struct mptcp_sock *msk,
1182 : : struct mptcp_options_received *mp_opt)
1183 : : {
1184 : 841 : u64 hmac = 0;
1185 : :
1186 [ + + ]: 841 : if (mp_opt->echo)
1187 : : return true;
1188 : :
1189 : 425 : hmac = add_addr_generate_hmac(READ_ONCE(msk->remote_key),
1190 : 425 : READ_ONCE(msk->local_key),
1191 : : &mp_opt->addr);
1192 : :
1193 [ - + - - ]: 425 : pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
1194 : : msk, hmac, mp_opt->ahmac);
1195 : :
1196 : 425 : return hmac == mp_opt->ahmac;
1197 : : }
1198 : :
1199 : 22118 : static bool mptcp_over_limit(struct sock *sk, struct sock *ssk,
1200 : : const struct sk_buff *skb)
1201 : : {
1202 [ - + ]: 22118 : struct mptcp_sock *msk = mptcp_sk(sk);
1203 : 22118 : u32 rcvbuf = READ_ONCE(sk->sk_rcvbuf);
1204 : :
1205 [ + - - + ]: 22118 : if (likely((u32)sk_rmem_alloc_get(sk) <= rcvbuf &&
1206 : : READ_ONCE(msk->backlog_len) <= rcvbuf))
1207 : : return false;
1208 : :
1209 : : /* Avoid silently dropping pure acks, fin, rst or already-acked segm. */
1210 [ # # ]: 0 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq ||
1211 [ # # # # ]: 0 : TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_FIN | TCPHDR_RST) ||
1212 [ # # # # ]: 0 : !after(TCP_SKB_CB(skb)->end_seq, tcp_sk(ssk)->rcv_nxt))
1213 : : return false;
1214 : :
1215 : : /* Dropped due to memory constraints, schedule an ack. */
1216 : 0 : inet_csk(ssk)->icsk_ack.pending |= ICSK_ACK_NOMEM | ICSK_ACK_NOW;
1217 : 0 : inet_csk_schedule_ack(ssk);
1218 : :
1219 : : /* Plain TCP (fallback) and skb is dropped before the TCP recv queue. */
1220 : 0 : NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP);
1221 : :
1222 : 0 : return true;
1223 : : }
1224 : :
1225 : : /* Return false when the caller must drop the packet, i.e. in case of error,
1226 : : * subflow has been reset, or over memory limits.
1227 : : */
1228 : 1937977 : bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
1229 : : {
1230 [ - + ]: 1937977 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1231 [ - + ]: 1937977 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
1232 : 1937977 : struct mptcp_options_received mp_opt;
1233 : 1937977 : struct mptcp_ext *mpext;
1234 : :
1235 [ + + ]: 1937977 : if (__mptcp_check_fallback(msk)) {
1236 : : /* Keep it simple and unconditionally trigger send data cleanup and
1237 : : * pending queue spooling. We will need to acquire the data lock
1238 : : * for more accurate checks, and once the lock is acquired, such
1239 : : * helpers are cheap.
1240 : : */
1241 : 22118 : mptcp_data_lock(subflow->conn);
1242 [ + + ]: 22118 : if (sk_stream_memory_free(sk))
1243 : 22108 : __mptcp_check_push(subflow->conn, sk);
1244 : :
1245 : : /* on fallback we just need to ignore the msk-level snd_una, as
1246 : : * this is really plain TCP
1247 : : */
1248 : 22118 : __mptcp_snd_una_update(msk, READ_ONCE(msk->snd_nxt));
1249 : :
1250 : 22118 : __mptcp_data_acked(subflow->conn);
1251 : 22118 : mptcp_data_unlock(subflow->conn);
1252 : 22118 : return !mptcp_over_limit(subflow->conn, sk, skb);
1253 : : }
1254 : :
1255 : 1915859 : mptcp_get_options(skb, &mp_opt);
1256 : :
1257 : : /* The subflow can be in close state only if check_fully_established()
1258 : : * just sent a reset. If so, tell the caller to ignore the current packet.
1259 : : */
1260 [ + + ]: 1915859 : if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
1261 : 64 : return sk->sk_state != TCP_CLOSE;
1262 : :
1263 [ + + ]: 1915795 : if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
1264 [ + + ]: 169089 : if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
1265 [ + + ]: 275 : READ_ONCE(msk->local_key) == mp_opt.rcvr_key) {
1266 : 265 : WRITE_ONCE(msk->rcv_fastclose, true);
1267 : 265 : mptcp_schedule_work((struct sock *)msk);
1268 [ + - ]: 265 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX);
1269 : : }
1270 : :
1271 [ + + + - ]: 169930 : if ((mp_opt.suboptions & OPTION_MPTCP_ADD_ADDR) &&
1272 : 841 : add_addr_hmac_valid(msk, &mp_opt)) {
1273 [ + + ]: 841 : if (!mp_opt.echo) {
1274 : 425 : mptcp_pm_add_addr_received(sk, &mp_opt.addr);
1275 [ + - ]: 425 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR);
1276 : : } else {
1277 : 416 : mptcp_pm_add_addr_echoed(msk, &mp_opt.addr);
1278 [ + - ]: 416 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD);
1279 : : }
1280 : :
1281 [ + + ]: 841 : if (mp_opt.addr.port)
1282 [ + - ]: 96 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_PORTADD);
1283 : : }
1284 : :
1285 [ + + ]: 169089 : if (mp_opt.suboptions & OPTION_MPTCP_RM_ADDR)
1286 : 108 : mptcp_pm_rm_addr_received(msk, &mp_opt.rm_list);
1287 : :
1288 [ + + ]: 169089 : if (mp_opt.suboptions & OPTION_MPTCP_PRIO) {
1289 : 40 : mptcp_pm_mp_prio_received(sk, mp_opt.backup);
1290 [ + - ]: 40 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIORX);
1291 : : }
1292 : :
1293 [ + + ]: 169089 : if (mp_opt.suboptions & OPTION_MPTCP_FAIL) {
1294 : 6 : mptcp_pm_mp_fail_received(sk, mp_opt.fail_seq);
1295 [ + - ]: 6 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFAILRX);
1296 : : }
1297 : :
1298 [ + + ]: 169089 : if (mp_opt.suboptions & OPTION_MPTCP_RST) {
1299 : 258 : subflow->reset_seen = 1;
1300 : 258 : subflow->reset_reason = mp_opt.reset_reason;
1301 : 258 : subflow->reset_transient = mp_opt.reset_transient;
1302 [ + - ]: 258 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPRSTRX);
1303 : : }
1304 : :
1305 [ + + ]: 169089 : if (!(mp_opt.suboptions & OPTION_MPTCP_DSS))
1306 : : return true;
1307 : : }
1308 : :
1309 : : /* we can't wait for recvmsg() to update the ack_seq, otherwise
1310 : : * monodirectional flows will stuck
1311 : : */
1312 [ + + ]: 1912186 : if (mp_opt.use_ack)
1313 : 1910953 : ack_update_msk(msk, sk, &mp_opt);
1314 : 1912186 : rwin_update(msk, sk, skb);
1315 : :
1316 : : /* Zero-data-length packets are dropped by the caller and not
1317 : : * propagated to the MPTCP layer, so the skb extension does not
1318 : : * need to be allocated or populated. DATA_FIN information, if
1319 : : * present, needs to be updated here before the skb is freed.
1320 : : */
1321 [ + + ]: 1912186 : if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
1322 [ + + + - : 735495 : if (mp_opt.data_fin && mp_opt.data_len == 1 &&
+ + ]
1323 : 15289 : mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
1324 : 3022 : mptcp_schedule_work((struct sock *)msk);
1325 : :
1326 : 720206 : return true;
1327 : : }
1328 : :
1329 : 1191980 : mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
1330 [ + - ]: 1191980 : if (!mpext)
1331 : : return false;
1332 : :
1333 : 1191980 : memset(mpext, 0, sizeof(*mpext));
1334 : :
1335 [ + + ]: 1191980 : if (likely(mp_opt.use_map)) {
1336 [ + + ]: 1188949 : if (mp_opt.mpc_map) {
1337 : : /* this is an MP_CAPABLE carrying MPTCP data
1338 : : * we know this map the first chunk of data
1339 : : */
1340 : 1233 : mptcp_crypto_key_sha(subflow->remote_key, NULL,
1341 : : &mpext->data_seq);
1342 : 1233 : mpext->data_seq++;
1343 : 1233 : mpext->subflow_seq = 1;
1344 : 1233 : mpext->dsn64 = 1;
1345 : 1233 : mpext->mpc_map = 1;
1346 : 1233 : mpext->data_fin = 0;
1347 : : } else {
1348 : 1187716 : mpext->data_seq = mp_opt.data_seq;
1349 : 1187716 : mpext->subflow_seq = mp_opt.subflow_seq;
1350 : 1187716 : mpext->dsn64 = mp_opt.dsn64;
1351 : 1187716 : mpext->data_fin = mp_opt.data_fin;
1352 : : }
1353 : 1188949 : mpext->data_len = mp_opt.data_len;
1354 : 1188949 : mpext->use_map = 1;
1355 : 1188949 : mpext->csum_reqd = !!(mp_opt.suboptions & OPTION_MPTCP_CSUMREQD);
1356 : :
1357 [ + + ]: 1188949 : if (mpext->csum_reqd)
1358 : 159147 : mpext->csum = mp_opt.csum;
1359 : : }
1360 : :
1361 : : return true;
1362 : : }
1363 : :
1364 : 1509284 : static u64 mptcp_set_rwin(struct mptcp_sock *msk, struct tcp_sock *tp,
1365 : : struct tcphdr *th, u64 ack_seq)
1366 : : {
1367 : 1509284 : const struct sock *ssk = (const struct sock *)tp;
1368 : 1509284 : u64 rcv_wnd_old, rcv_wnd_new;
1369 : 1509284 : u32 new_win;
1370 : 1509284 : u64 win;
1371 : :
1372 : 1509284 : rcv_wnd_new = ack_seq + tp->rcv_wnd;
1373 : :
1374 [ + + ]: 1509284 : rcv_wnd_old = atomic64_read(&msk->rcv_wnd_sent);
1375 [ + + ]: 1509284 : if (after64(rcv_wnd_new, rcv_wnd_old)) {
1376 : 83 : u64 rcv_wnd;
1377 : :
1378 : 562901 : for (;;) {
1379 : 562984 : rcv_wnd = atomic64_cmpxchg(&msk->rcv_wnd_sent, rcv_wnd_old, rcv_wnd_new);
1380 : :
1381 [ + + ]: 562901 : if (rcv_wnd == rcv_wnd_old)
1382 : : break;
1383 : :
1384 : 8 : rcv_wnd_old = rcv_wnd;
1385 [ + + ]: 8 : if (before64(rcv_wnd_new, rcv_wnd_old)) {
1386 [ # # ]: 1 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICTUPDATE);
1387 : 1 : goto raise_win;
1388 : : }
1389 [ - + ]: 90 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDCONFLICT);
1390 : : }
1391 : 562893 : goto update_wspace;
1392 : : }
1393 : :
1394 [ + + ]: 946390 : if (rcv_wnd_new != rcv_wnd_old) {
1395 : 338119 : raise_win:
1396 : : /* The msk-level rcv wnd is after the tcp level one,
1397 : : * sync the latter.
1398 : : */
1399 : 338120 : rcv_wnd_new = rcv_wnd_old;
1400 : 338120 : win = rcv_wnd_old - ack_seq;
1401 : 338120 : new_win = min_t(u64, win, U32_MAX);
1402 : 338120 : tp->rcv_wnd = new_win;
1403 [ + + ]: 338120 : tcp_update_max_rcv_wnd_seq(tp);
1404 : :
1405 : : /* Make sure we do not exceed the maximum possible
1406 : : * scaled window.
1407 : : */
1408 [ - + ]: 338120 : if (unlikely(th->syn))
1409 : 0 : new_win = min(new_win, 65535U) << tp->rx_opt.rcv_wscale;
1410 [ - + ]: 338120 : if (!tp->rx_opt.rcv_wscale &&
[ - + - - ]
1411 [ # # ]: 0 : READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_workaround_signed_windows))
1412 : 0 : new_win = min(new_win, MAX_TCP_WINDOW);
1413 : : else
1414 : 338120 : new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale));
1415 : :
1416 : : /* RFC1323 scaling applied */
1417 : 338120 : new_win >>= tp->rx_opt.rcv_wscale;
1418 : 338120 : th->window = htons(new_win);
1419 [ + - ]: 338120 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_RCVWNDSHARED);
1420 : : }
1421 : :
1422 : 608271 : update_wspace:
1423 : 1509284 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1424 : 1509284 : return rcv_wnd_new;
1425 : : }
1426 : :
1427 : 24835 : static void mptcp_track_rwin(struct tcp_sock *tp)
1428 : : {
1429 : 24835 : const struct sock *ssk = (const struct sock *)tp;
1430 : 24835 : struct mptcp_subflow_context *subflow;
1431 : 24835 : struct mptcp_sock *msk;
1432 : :
1433 [ + - ]: 24835 : if (!ssk)
1434 : : return;
1435 : :
1436 [ - + ]: 24835 : subflow = mptcp_subflow_ctx(ssk);
1437 [ - + ]: 24835 : msk = mptcp_sk(subflow->conn);
1438 : 24835 : WRITE_ONCE(msk->old_wspace, tp->rcv_wnd);
1439 : : }
1440 : :
1441 : 135221 : __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum)
1442 : : {
1443 : 135221 : struct csum_pseudo_header header;
1444 : 135221 : __wsum csum;
1445 : :
1446 : : /* cfr RFC 8684 3.3.1.:
1447 : : * the data sequence number used in the pseudo-header is
1448 : : * always the 64-bit value, irrespective of what length is used in the
1449 : : * DSS option itself.
1450 : : */
1451 : 135221 : header.data_seq = cpu_to_be64(data_seq);
1452 : 135221 : header.subflow_seq = htonl(subflow_seq);
1453 : 135221 : header.data_len = htons(data_len);
1454 : 135221 : header.csum = 0;
1455 : :
1456 : 135221 : csum = csum_partial(&header, sizeof(header), sum);
1457 : 135221 : return csum_fold(csum);
1458 : : }
1459 : :
1460 : 95510 : static __sum16 mptcp_make_csum(const struct mptcp_ext *mpext)
1461 : : {
1462 : 191020 : return __mptcp_make_csum(mpext->data_seq, mpext->subflow_seq, mpext->data_len,
1463 : 95510 : ~csum_unfold(mpext->csum));
1464 : : }
1465 : :
1466 : 0 : static void put_len_csum(u16 len, __sum16 csum, void *data)
1467 : : {
1468 : 95620 : __sum16 *sumptr = data + 2;
1469 : 95620 : __be16 *ptr = data;
1470 : :
1471 : 95620 : put_unaligned_be16(len, ptr);
1472 : :
1473 : 95620 : put_unaligned(csum, sumptr);
1474 : 95620 : }
1475 : :
1476 : 1543429 : void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp,
1477 : : struct mptcp_out_options *opts)
1478 : : {
1479 : 1543429 : const struct sock *ssk = (const struct sock *)tp;
1480 : 1543429 : struct mptcp_subflow_context *subflow;
1481 : :
1482 : : /* Which options can be used together?
1483 : : *
1484 : : * X: mutually exclusive
1485 : : * O: often used together
1486 : : * C: can be used together in some cases
1487 : : * P: could be used together but we prefer not to (optimisations)
1488 : : *
1489 : : * Opt: | MPC | MPJ | DSS | ADD | RM | PRIO | FAIL | FC |
1490 : : * ------|------|------|------|------|------|------|------|------|
1491 : : * MPC |------|------|------|------|------|------|------|------|
1492 : : * MPJ | X |------|------|------|------|------|------|------|
1493 : : * DSS | X | X |------|------|------|------|------|------|
1494 : : * ADD | X | X | P |------|------|------|------|------|
1495 : : * RM | C | C | C | P |------|------|------|------|
1496 : : * PRIO | X | C | C | C | C |------|------|------|
1497 : : * FAIL | X | X | C | X | X | X |------|------|
1498 : : * FC | X | X | P | X | X | X | X |------|
1499 : : * RST | X | X | X | X | X | X | O | O |
1500 : : * ------|------|------|------|------|------|------|------|------|
1501 : : *
1502 : : * The same applies in mptcp_established_options() function.
1503 : : */
1504 [ + + ]: 1543429 : if (likely(OPTION_MPTCP_DSS & opts->suboptions)) {
1505 : 1509284 : struct mptcp_ext *mpext = &opts->ext_copy;
1506 : 1509284 : u8 len = TCPOLEN_MPTCP_DSS_BASE;
1507 : 1509284 : u8 flags = 0;
1508 : :
1509 [ + - ]: 1509284 : if (mpext->use_ack) {
1510 : 1509284 : flags = MPTCP_DSS_HAS_ACK;
1511 [ + + ]: 1509284 : if (mpext->ack64) {
1512 : : len += TCPOLEN_MPTCP_DSS_ACK64;
1513 : : flags |= MPTCP_DSS_ACK64;
1514 : : } else {
1515 : 103539 : len += TCPOLEN_MPTCP_DSS_ACK32;
1516 : : }
1517 : : }
1518 : :
1519 [ + + ]: 1509284 : if (mpext->use_map) {
1520 : 783620 : len += TCPOLEN_MPTCP_DSS_MAP64;
1521 : :
1522 : : /* Use only 64-bit mapping flags for now, add
1523 : : * support for optional 32-bit mappings later.
1524 : : */
1525 : 783620 : flags |= MPTCP_DSS_HAS_MAP | MPTCP_DSS_DSN64;
1526 [ + + ]: 783620 : if (mpext->data_fin)
1527 : 20160 : flags |= MPTCP_DSS_DATA_FIN;
1528 : :
1529 [ + + ]: 783620 : if (opts->csum_reqd)
1530 : 95512 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1531 : : }
1532 : :
1533 [ + - ]: 1509284 : *ptr++ = mptcp_option(MPTCPOPT_DSS, len, 0, flags);
1534 : :
1535 [ + - ]: 1509284 : if (mpext->use_ack) {
1536 : 1509284 : struct mptcp_sock *msk;
1537 : 1509284 : u64 ack_seq;
1538 : :
1539 : : /* DSS option is set only by mptcp_established_options,
1540 : : * the caller is __tcp_transmit_skb() and ssk is always
1541 : : * not NULL.
1542 : : */
1543 [ - + ]: 1509284 : subflow = mptcp_subflow_ctx(ssk);
1544 [ - + ]: 1509284 : msk = mptcp_sk(subflow->conn);
1545 : 1509284 : ack_seq = READ_ONCE(msk->ack_seq);
1546 [ + + ]: 1509284 : if (mpext->ack64) {
1547 : 1405745 : put_unaligned_be64(ack_seq, ptr);
1548 : 1405745 : ptr += 2;
1549 : : } else {
1550 : 103539 : put_unaligned_be32(ack_seq, ptr);
1551 : 103539 : ptr += 1;
1552 : : }
1553 : 1509284 : subflow->rcv_wnd_sent = mptcp_set_rwin(msk, tp, th,
1554 : : ack_seq);
1555 : : }
1556 : :
1557 [ + + ]: 1509284 : if (mpext->use_map) {
1558 [ + + ]: 783620 : put_unaligned_be64(mpext->data_seq, ptr);
1559 : 783620 : ptr += 2;
1560 [ + + ]: 783620 : put_unaligned_be32(mpext->subflow_seq, ptr);
1561 : 783620 : ptr += 1;
1562 [ + + ]: 783620 : if (opts->csum_reqd) {
1563 : : /* data_len == 0 is reserved for the infinite mapping,
1564 : : * the checksum will also be set to 0.
1565 : : */
1566 : 95512 : put_len_csum(mpext->data_len,
1567 [ + + ]: 95512 : (mpext->data_len ? mptcp_make_csum(mpext) : 0),
1568 : : ptr);
1569 : : } else {
1570 : 688108 : put_unaligned_be32(mpext->data_len << 16 |
1571 : 688108 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1572 : : }
1573 : 783620 : ptr += 1;
1574 : : }
1575 : :
1576 : : /* We might need to add MP_FAIL options in rare cases */
1577 [ + + ]: 1509284 : if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions))
1578 : 4 : goto mp_fail;
1579 [ + + ]: 34145 : } else if (OPTIONS_MPTCP_MPC & opts->suboptions) {
1580 : 5930 : u8 len, flag = MPTCP_CAP_HMAC_SHA256;
1581 : :
1582 [ + + ]: 5930 : if (OPTION_MPTCP_MPC_SYN & opts->suboptions) {
1583 : : len = TCPOLEN_MPTCP_MPC_SYN;
1584 [ + + ]: 4174 : } else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) {
1585 : : len = TCPOLEN_MPTCP_MPC_SYNACK;
1586 [ + + ]: 2502 : } else if (opts->data_len) {
1587 : 1018 : len = TCPOLEN_MPTCP_MPC_ACK_DATA;
1588 [ + + ]: 1018 : if (opts->csum_reqd)
1589 : 108 : len += TCPOLEN_MPTCP_DSS_CHECKSUM;
1590 : : } else {
1591 : : len = TCPOLEN_MPTCP_MPC_ACK;
1592 : : }
1593 : :
1594 [ + + ]: 5930 : if (opts->csum_reqd)
1595 : 482 : flag |= MPTCP_CAP_CHECKSUM_REQD;
1596 : :
1597 [ + + ]: 5930 : if (!opts->allow_join_id0)
1598 : 37 : flag |= MPTCP_CAP_DENY_JOIN_ID0;
1599 : :
1600 [ + + ]: 5930 : *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len,
1601 : : MPTCP_SUPPORTED_VERSION,
1602 : : flag);
1603 : :
1604 : 5930 : if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) &
1605 [ + + ]: 5930 : opts->suboptions))
1606 : 1756 : goto mp_capable_done;
1607 : :
1608 [ + + ]: 4174 : put_unaligned_be64(opts->sndr_key, ptr);
1609 : 4174 : ptr += 2;
1610 [ + + ]: 4174 : if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions))
1611 : 1672 : goto mp_capable_done;
1612 : :
1613 [ + + ]: 2502 : put_unaligned_be64(opts->rcvr_key, ptr);
1614 : 2502 : ptr += 2;
1615 [ + + ]: 2502 : if (!opts->data_len)
1616 : 1484 : goto mp_capable_done;
1617 : :
1618 [ + + ]: 1018 : if (opts->csum_reqd) {
1619 : 108 : put_len_csum(opts->data_len,
1620 : 108 : __mptcp_make_csum(opts->data_seq,
1621 : : opts->subflow_seq,
1622 : : opts->data_len,
1623 : 108 : ~csum_unfold(opts->csum)),
1624 : : ptr);
1625 : : } else {
1626 : 910 : put_unaligned_be32(opts->data_len << 16 |
1627 : 910 : TCPOPT_NOP << 8 | TCPOPT_NOP, ptr);
1628 : : }
1629 : 1018 : ptr += 1;
1630 : :
1631 : : /* MPC is additionally mutually exclusive with MP_PRIO */
1632 : 1018 : goto mp_capable_done;
1633 [ + + ]: 28215 : } else if (OPTIONS_MPTCP_MPJ & opts->suboptions) {
1634 [ + + ]: 1941 : if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) {
1635 : 706 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1636 : : TCPOLEN_MPTCP_MPJ_SYN,
1637 : 706 : opts->backup, opts->join_id);
1638 : 706 : put_unaligned_be32(opts->token, ptr);
1639 : 706 : ptr += 1;
1640 : 706 : put_unaligned_be32(opts->nonce, ptr);
1641 : 706 : ptr += 1;
1642 [ + + ]: 1235 : } else if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) {
1643 : 628 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1644 : : TCPOLEN_MPTCP_MPJ_SYNACK,
1645 : 628 : opts->backup, opts->join_id);
1646 : 628 : put_unaligned_be64(opts->thmac, ptr);
1647 : 628 : ptr += 2;
1648 : 628 : put_unaligned_be32(opts->nonce, ptr);
1649 : 628 : ptr += 1;
1650 : : } else {
1651 : 607 : *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN,
1652 : : TCPOLEN_MPTCP_MPJ_ACK, 0, 0);
1653 : 607 : memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN);
1654 : 607 : ptr += 5;
1655 : : }
1656 [ + + ]: 26274 : } else if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) {
1657 : 905 : u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
1658 : 905 : u8 echo = MPTCP_ADDR_ECHO;
1659 : :
1660 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1661 [ + + ]: 905 : if (opts->addr.family == AF_INET6)
1662 : 208 : len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
1663 : : #endif
1664 : :
1665 [ + + ]: 905 : if (opts->addr.port)
1666 : 96 : len += TCPOLEN_MPTCP_PORT_LEN;
1667 : :
1668 [ + + ]: 905 : if (opts->ahmac) {
1669 : 493 : len += sizeof(opts->ahmac);
1670 : 493 : echo = 0;
1671 : : }
1672 : :
1673 : 905 : *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR,
1674 [ + + ]: 905 : len, echo, opts->addr.id);
1675 [ + + ]: 905 : if (opts->addr.family == AF_INET) {
1676 : 697 : memcpy((u8 *)ptr, (u8 *)&opts->addr.addr.s_addr, 4);
1677 : 697 : ptr += 1;
1678 : : }
1679 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1680 [ + - ]: 208 : else if (opts->addr.family == AF_INET6) {
1681 : 208 : memcpy((u8 *)ptr, opts->addr.addr6.s6_addr, 16);
1682 : 208 : ptr += 4;
1683 : : }
1684 : : #endif
1685 : :
1686 [ + + ]: 905 : if (!opts->addr.port) {
1687 [ + + ]: 809 : if (opts->ahmac) {
1688 : 439 : put_unaligned_be64(opts->ahmac, ptr);
1689 : 439 : ptr += 2;
1690 : : }
1691 : : } else {
1692 : 96 : u16 port = ntohs(opts->addr.port);
1693 : :
1694 [ + + ]: 96 : if (opts->ahmac) {
1695 : 54 : u8 *bptr = (u8 *)ptr;
1696 : :
1697 : 54 : put_unaligned_be16(port, bptr);
1698 : 54 : bptr += 2;
1699 : 54 : put_unaligned_be64(opts->ahmac, bptr);
1700 : 54 : bptr += 8;
1701 : 54 : put_unaligned_be16(TCPOPT_NOP << 8 |
1702 : : TCPOPT_NOP, bptr);
1703 : :
1704 : 54 : ptr += 3;
1705 : : } else {
1706 : 42 : put_unaligned_be32(port << 16 |
1707 : 42 : TCPOPT_NOP << 8 |
1708 : : TCPOPT_NOP, ptr);
1709 : 42 : ptr += 1;
1710 : : }
1711 : : }
1712 [ + + ]: 25369 : } else if (unlikely(OPTION_MPTCP_FASTCLOSE & opts->suboptions)) {
1713 : : /* FASTCLOSE is mutually exclusive with others except RST */
1714 : 479 : *ptr++ = mptcp_option(MPTCPOPT_MP_FASTCLOSE,
1715 : : TCPOLEN_MPTCP_FASTCLOSE,
1716 : : 0, 0);
1717 [ + - ]: 479 : put_unaligned_be64(opts->rcvr_key, ptr);
1718 : 479 : ptr += 2;
1719 : :
1720 [ + - ]: 479 : if (OPTION_MPTCP_RST & opts->suboptions)
1721 : 479 : goto mp_rst;
1722 : : return;
1723 [ + + ]: 24890 : } else if (unlikely(OPTION_MPTCP_FAIL & opts->suboptions)) {
1724 : 2 : mp_fail:
1725 : : /* MP_FAIL is mutually exclusive with others except RST */
1726 [ + + ]: 6 : subflow = mptcp_subflow_ctx(ssk);
1727 : 6 : subflow->send_mp_fail = 0;
1728 : :
1729 : 6 : *ptr++ = mptcp_option(MPTCPOPT_MP_FAIL,
1730 : : TCPOLEN_MPTCP_FAIL,
1731 : : 0, 0);
1732 [ + + ]: 6 : put_unaligned_be64(opts->fail_seq, ptr);
1733 : 6 : ptr += 2;
1734 : :
1735 [ + + ]: 6 : if (OPTION_MPTCP_RST & opts->suboptions)
1736 : 2 : goto mp_rst;
1737 : : return;
1738 [ + + ]: 24888 : } else if (unlikely(OPTION_MPTCP_RST & opts->suboptions)) {
1739 : 53 : mp_rst:
1740 : 534 : *ptr++ = mptcp_option(MPTCPOPT_RST,
1741 : : TCPOLEN_MPTCP_RST,
1742 : 534 : opts->reset_transient,
1743 : 534 : opts->reset_reason);
1744 : 534 : return;
1745 [ + - ]: 24835 : } else if (unlikely(!opts->suboptions)) {
1746 : : /* Fallback to TCP */
1747 : 24835 : mptcp_track_rwin(tp);
1748 : 24835 : return;
1749 : : }
1750 : :
1751 [ + + ]: 1512126 : if (OPTION_MPTCP_PRIO & opts->suboptions) {
1752 [ + - ]: 28 : subflow = mptcp_subflow_ctx(ssk);
1753 : 28 : subflow->send_mp_prio = 0;
1754 : :
1755 : 28 : *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO,
1756 : : TCPOLEN_MPTCP_PRIO,
1757 [ + - ]: 28 : opts->backup, TCPOPT_NOP);
1758 : :
1759 [ + - ]: 28 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPPRIOTX);
1760 : : }
1761 : :
1762 : 1512098 : mp_capable_done:
1763 [ + + ]: 1518056 : if (OPTION_MPTCP_RM_ADDR & opts->suboptions) {
1764 : 114 : u8 i = 1;
1765 : :
1766 : 114 : *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR,
1767 : 114 : TCPOLEN_MPTCP_RM_ADDR_BASE + opts->rm_list.nr,
1768 : 114 : 0, opts->rm_list.ids[0]);
1769 : :
1770 [ + + ]: 118 : while (i < opts->rm_list.nr) {
1771 : 4 : u8 id1, id2, id3, id4;
1772 : :
1773 : 4 : id1 = opts->rm_list.ids[i];
1774 [ + - ]: 4 : id2 = i + 1 < opts->rm_list.nr ? opts->rm_list.ids[i + 1] : TCPOPT_NOP;
1775 [ - + ]: 4 : id3 = i + 2 < opts->rm_list.nr ? opts->rm_list.ids[i + 2] : TCPOPT_NOP;
1776 [ - + ]: 4 : id4 = i + 3 < opts->rm_list.nr ? opts->rm_list.ids[i + 3] : TCPOPT_NOP;
1777 : 4 : put_unaligned_be32(id1 << 24 | id2 << 16 | id3 << 8 | id4, ptr);
1778 : 4 : ptr += 1;
1779 : 4 : i += 4;
1780 : : }
1781 : : }
1782 : : }
1783 : :
1784 : 16 : __be32 mptcp_get_reset_option(const struct sk_buff *skb)
1785 : : {
1786 [ + - ]: 16 : const struct mptcp_ext *ext = mptcp_get_ext(skb);
1787 : 16 : u8 flags, reason;
1788 : :
1789 [ + - ]: 16 : if (ext) {
1790 : 16 : flags = ext->reset_transient;
1791 : 16 : reason = ext->reset_reason;
1792 : :
1793 : 16 : return mptcp_option(MPTCPOPT_RST, TCPOLEN_MPTCP_RST,
1794 : : flags, reason);
1795 : : }
1796 : :
1797 : : return htonl(0u);
1798 : : }
1799 : : EXPORT_SYMBOL_GPL(mptcp_get_reset_option);
|