Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Multipath TCP |
| 3 | * |
| 4 | * Copyright (c) 2017 - 2019, Intel Corporation. |
| 5 | */ |
| 6 | |
Geliang Tang | c85adce | 2020-04-03 17:14:08 +0800 | [diff] [blame] | 7 | #define pr_fmt(fmt) "MPTCP: " fmt |
| 8 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Eric Biggers | a24d22b | 2020-11-12 21:20:21 -0800 | [diff] [blame] | 10 | #include <crypto/sha2.h> |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 11 | #include <net/tcp.h> |
| 12 | #include <net/mptcp.h> |
| 13 | #include "protocol.h" |
Geliang Tang | a877de06 | 2020-09-24 08:29:51 +0800 | [diff] [blame] | 14 | #include "mib.h" |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 15 | |
Paolo Abeni | 65492c5 | 2020-01-21 16:56:30 -0800 | [diff] [blame] | 16 | static bool mptcp_cap_flag_sha256(u8 flags) |
| 17 | { |
| 18 | return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256; |
| 19 | } |
| 20 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 21 | static void mptcp_parse_option(const struct sk_buff *skb, |
| 22 | const unsigned char *ptr, int opsize, |
| 23 | struct mptcp_options_received *mp_opt) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 24 | { |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 25 | u8 subtype = *ptr >> 4; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 26 | int expected_opsize; |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 27 | u8 version; |
| 28 | u8 flags; |
| 29 | |
| 30 | switch (subtype) { |
| 31 | case MPTCPOPT_MP_CAPABLE: |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 32 | /* strict size checking */ |
| 33 | if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { |
| 34 | if (skb->len > tcp_hdr(skb)->doff << 2) |
| 35 | expected_opsize = TCPOLEN_MPTCP_MPC_ACK_DATA; |
| 36 | else |
| 37 | expected_opsize = TCPOLEN_MPTCP_MPC_ACK; |
| 38 | } else { |
| 39 | if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK) |
| 40 | expected_opsize = TCPOLEN_MPTCP_MPC_SYNACK; |
| 41 | else |
| 42 | expected_opsize = TCPOLEN_MPTCP_MPC_SYN; |
| 43 | } |
| 44 | if (opsize != expected_opsize) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 45 | break; |
| 46 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 47 | /* try to be gentle vs future versions on the initial syn */ |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 48 | version = *ptr++ & MPTCP_VERSION_MASK; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 49 | if (opsize != TCPOLEN_MPTCP_MPC_SYN) { |
| 50 | if (version != MPTCP_SUPPORTED_VERSION) |
| 51 | break; |
| 52 | } else if (version < MPTCP_SUPPORTED_VERSION) { |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 53 | break; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 54 | } |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 55 | |
| 56 | flags = *ptr++; |
Paolo Abeni | 65492c5 | 2020-01-21 16:56:30 -0800 | [diff] [blame] | 57 | if (!mptcp_cap_flag_sha256(flags) || |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 58 | (flags & MPTCP_CAP_EXTENSIBILITY)) |
| 59 | break; |
| 60 | |
| 61 | /* RFC 6824, Section 3.1: |
| 62 | * "For the Checksum Required bit (labeled "A"), if either |
| 63 | * host requires the use of checksums, checksums MUST be used. |
| 64 | * In other words, the only way for checksums not to be used |
| 65 | * is if both hosts in their SYNs set A=0." |
| 66 | * |
| 67 | * Section 3.3.0: |
| 68 | * "If a checksum is not present when its use has been |
| 69 | * negotiated, the receiver MUST close the subflow with a RST as |
| 70 | * it is considered broken." |
| 71 | * |
| 72 | * We don't implement DSS checksum - fall back to TCP. |
| 73 | */ |
| 74 | if (flags & MPTCP_CAP_CHECKSUM_REQD) |
| 75 | break; |
| 76 | |
| 77 | mp_opt->mp_capable = 1; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 78 | if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) { |
| 79 | mp_opt->sndr_key = get_unaligned_be64(ptr); |
| 80 | ptr += 8; |
| 81 | } |
| 82 | if (opsize >= TCPOLEN_MPTCP_MPC_ACK) { |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 83 | mp_opt->rcvr_key = get_unaligned_be64(ptr); |
| 84 | ptr += 8; |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 85 | } |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 86 | if (opsize == TCPOLEN_MPTCP_MPC_ACK_DATA) { |
| 87 | /* Section 3.1.: |
| 88 | * "the data parameters in a MP_CAPABLE are semantically |
| 89 | * equivalent to those in a DSS option and can be used |
| 90 | * interchangeably." |
| 91 | */ |
| 92 | mp_opt->dss = 1; |
| 93 | mp_opt->use_map = 1; |
| 94 | mp_opt->mpc_map = 1; |
| 95 | mp_opt->data_len = get_unaligned_be16(ptr); |
| 96 | ptr += 2; |
| 97 | } |
| 98 | pr_debug("MP_CAPABLE version=%x, flags=%x, optlen=%d sndr=%llu, rcvr=%llu len=%d", |
| 99 | version, flags, opsize, mp_opt->sndr_key, |
| 100 | mp_opt->rcvr_key, mp_opt->data_len); |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 101 | break; |
| 102 | |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 103 | case MPTCPOPT_MP_JOIN: |
| 104 | mp_opt->mp_join = 1; |
| 105 | if (opsize == TCPOLEN_MPTCP_MPJ_SYN) { |
| 106 | mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP; |
| 107 | mp_opt->join_id = *ptr++; |
| 108 | mp_opt->token = get_unaligned_be32(ptr); |
| 109 | ptr += 4; |
| 110 | mp_opt->nonce = get_unaligned_be32(ptr); |
| 111 | ptr += 4; |
| 112 | pr_debug("MP_JOIN bkup=%u, id=%u, token=%u, nonce=%u", |
| 113 | mp_opt->backup, mp_opt->join_id, |
| 114 | mp_opt->token, mp_opt->nonce); |
| 115 | } else if (opsize == TCPOLEN_MPTCP_MPJ_SYNACK) { |
| 116 | mp_opt->backup = *ptr++ & MPTCPOPT_BACKUP; |
| 117 | mp_opt->join_id = *ptr++; |
| 118 | mp_opt->thmac = get_unaligned_be64(ptr); |
| 119 | ptr += 8; |
| 120 | mp_opt->nonce = get_unaligned_be32(ptr); |
| 121 | ptr += 4; |
| 122 | pr_debug("MP_JOIN bkup=%u, id=%u, thmac=%llu, nonce=%u", |
| 123 | mp_opt->backup, mp_opt->join_id, |
| 124 | mp_opt->thmac, mp_opt->nonce); |
| 125 | } else if (opsize == TCPOLEN_MPTCP_MPJ_ACK) { |
| 126 | ptr += 2; |
| 127 | memcpy(mp_opt->hmac, ptr, MPTCPOPT_HMAC_LEN); |
| 128 | pr_debug("MP_JOIN hmac"); |
| 129 | } else { |
| 130 | pr_warn("MP_JOIN bad option size"); |
| 131 | mp_opt->mp_join = 0; |
| 132 | } |
| 133 | break; |
| 134 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 135 | case MPTCPOPT_DSS: |
| 136 | pr_debug("DSS"); |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 137 | ptr++; |
| 138 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 139 | /* we must clear 'mpc_map' be able to detect MP_CAPABLE |
| 140 | * map vs DSS map in mptcp_incoming_options(), and reconstruct |
| 141 | * map info accordingly |
| 142 | */ |
| 143 | mp_opt->mpc_map = 0; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 144 | flags = (*ptr++) & MPTCP_DSS_FLAG_MASK; |
| 145 | mp_opt->data_fin = (flags & MPTCP_DSS_DATA_FIN) != 0; |
| 146 | mp_opt->dsn64 = (flags & MPTCP_DSS_DSN64) != 0; |
| 147 | mp_opt->use_map = (flags & MPTCP_DSS_HAS_MAP) != 0; |
| 148 | mp_opt->ack64 = (flags & MPTCP_DSS_ACK64) != 0; |
| 149 | mp_opt->use_ack = (flags & MPTCP_DSS_HAS_ACK); |
| 150 | |
| 151 | pr_debug("data_fin=%d dsn64=%d use_map=%d ack64=%d use_ack=%d", |
| 152 | mp_opt->data_fin, mp_opt->dsn64, |
| 153 | mp_opt->use_map, mp_opt->ack64, |
| 154 | mp_opt->use_ack); |
| 155 | |
| 156 | expected_opsize = TCPOLEN_MPTCP_DSS_BASE; |
| 157 | |
| 158 | if (mp_opt->use_ack) { |
| 159 | if (mp_opt->ack64) |
| 160 | expected_opsize += TCPOLEN_MPTCP_DSS_ACK64; |
| 161 | else |
| 162 | expected_opsize += TCPOLEN_MPTCP_DSS_ACK32; |
| 163 | } |
| 164 | |
| 165 | if (mp_opt->use_map) { |
| 166 | if (mp_opt->dsn64) |
| 167 | expected_opsize += TCPOLEN_MPTCP_DSS_MAP64; |
| 168 | else |
| 169 | expected_opsize += TCPOLEN_MPTCP_DSS_MAP32; |
| 170 | } |
| 171 | |
| 172 | /* RFC 6824, Section 3.3: |
| 173 | * If a checksum is present, but its use had |
| 174 | * not been negotiated in the MP_CAPABLE handshake, |
| 175 | * the checksum field MUST be ignored. |
| 176 | */ |
| 177 | if (opsize != expected_opsize && |
| 178 | opsize != expected_opsize + TCPOLEN_MPTCP_DSS_CHECKSUM) |
| 179 | break; |
| 180 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 181 | mp_opt->dss = 1; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 182 | |
| 183 | if (mp_opt->use_ack) { |
| 184 | if (mp_opt->ack64) { |
| 185 | mp_opt->data_ack = get_unaligned_be64(ptr); |
| 186 | ptr += 8; |
| 187 | } else { |
| 188 | mp_opt->data_ack = get_unaligned_be32(ptr); |
| 189 | ptr += 4; |
| 190 | } |
| 191 | |
| 192 | pr_debug("data_ack=%llu", mp_opt->data_ack); |
| 193 | } |
| 194 | |
| 195 | if (mp_opt->use_map) { |
| 196 | if (mp_opt->dsn64) { |
| 197 | mp_opt->data_seq = get_unaligned_be64(ptr); |
| 198 | ptr += 8; |
| 199 | } else { |
| 200 | mp_opt->data_seq = get_unaligned_be32(ptr); |
| 201 | ptr += 4; |
| 202 | } |
| 203 | |
| 204 | mp_opt->subflow_seq = get_unaligned_be32(ptr); |
| 205 | ptr += 4; |
| 206 | |
| 207 | mp_opt->data_len = get_unaligned_be16(ptr); |
| 208 | ptr += 2; |
| 209 | |
| 210 | pr_debug("data_seq=%llu subflow_seq=%u data_len=%u", |
| 211 | mp_opt->data_seq, mp_opt->subflow_seq, |
| 212 | mp_opt->data_len); |
| 213 | } |
| 214 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 215 | break; |
| 216 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 217 | case MPTCPOPT_ADD_ADDR: |
| 218 | mp_opt->echo = (*ptr++) & MPTCP_ADDR_ECHO; |
| 219 | if (!mp_opt->echo) { |
| 220 | if (opsize == TCPOLEN_MPTCP_ADD_ADDR || |
| 221 | opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT) |
| 222 | mp_opt->family = MPTCP_ADDR_IPVERSION_4; |
| 223 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 224 | else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6 || |
| 225 | opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT) |
| 226 | mp_opt->family = MPTCP_ADDR_IPVERSION_6; |
| 227 | #endif |
| 228 | else |
| 229 | break; |
| 230 | } else { |
| 231 | if (opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE || |
| 232 | opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) |
| 233 | mp_opt->family = MPTCP_ADDR_IPVERSION_4; |
| 234 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 235 | else if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE || |
| 236 | opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) |
| 237 | mp_opt->family = MPTCP_ADDR_IPVERSION_6; |
| 238 | #endif |
| 239 | else |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | mp_opt->add_addr = 1; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 244 | mp_opt->addr_id = *ptr++; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 245 | if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) { |
| 246 | memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4); |
| 247 | ptr += 4; |
| 248 | if (opsize == TCPOLEN_MPTCP_ADD_ADDR_PORT || |
| 249 | opsize == TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT) { |
| 250 | mp_opt->port = get_unaligned_be16(ptr); |
| 251 | ptr += 2; |
| 252 | } |
| 253 | } |
| 254 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 255 | else { |
| 256 | memcpy(mp_opt->addr6.s6_addr, (u8 *)ptr, 16); |
| 257 | ptr += 16; |
| 258 | if (opsize == TCPOLEN_MPTCP_ADD_ADDR6_PORT || |
| 259 | opsize == TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT) { |
| 260 | mp_opt->port = get_unaligned_be16(ptr); |
| 261 | ptr += 2; |
| 262 | } |
| 263 | } |
| 264 | #endif |
| 265 | if (!mp_opt->echo) { |
| 266 | mp_opt->ahmac = get_unaligned_be64(ptr); |
| 267 | ptr += 8; |
| 268 | } |
Geliang Tang | 90a4aea | 2020-12-09 15:51:25 -0800 | [diff] [blame] | 269 | pr_debug("ADD_ADDR%s: id=%d, ahmac=%llu, echo=%d, port=%d", |
| 270 | (mp_opt->family == MPTCP_ADDR_IPVERSION_6) ? "6" : "", |
| 271 | mp_opt->addr_id, mp_opt->ahmac, mp_opt->echo, mp_opt->port); |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 272 | break; |
| 273 | |
| 274 | case MPTCPOPT_RM_ADDR: |
| 275 | if (opsize != TCPOLEN_MPTCP_RM_ADDR_BASE) |
| 276 | break; |
| 277 | |
Geliang Tang | 8e60eed | 2020-06-08 18:47:54 +0800 | [diff] [blame] | 278 | ptr++; |
| 279 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 280 | mp_opt->rm_addr = 1; |
| 281 | mp_opt->rm_id = *ptr++; |
| 282 | pr_debug("RM_ADDR: id=%d", mp_opt->rm_id); |
| 283 | break; |
| 284 | |
Florian Westphal | 50c504a | 2020-12-10 14:25:04 -0800 | [diff] [blame] | 285 | case MPTCPOPT_MP_FASTCLOSE: |
| 286 | if (opsize != TCPOLEN_MPTCP_FASTCLOSE) |
| 287 | break; |
| 288 | |
| 289 | ptr += 2; |
| 290 | mp_opt->rcvr_key = get_unaligned_be64(ptr); |
| 291 | ptr += 8; |
| 292 | mp_opt->fastclose = 1; |
| 293 | break; |
| 294 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 295 | default: |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 300 | void mptcp_get_options(const struct sk_buff *skb, |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 301 | struct mptcp_options_received *mp_opt) |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 302 | { |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 303 | const struct tcphdr *th = tcp_hdr(skb); |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 304 | const unsigned char *ptr; |
| 305 | int length; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 306 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 307 | /* initialize option status */ |
| 308 | mp_opt->mp_capable = 0; |
| 309 | mp_opt->mp_join = 0; |
| 310 | mp_opt->add_addr = 0; |
Geliang Tang | fe2d9b1 | 2020-10-19 18:23:15 +0800 | [diff] [blame] | 311 | mp_opt->ahmac = 0; |
Florian Westphal | 50c504a | 2020-12-10 14:25:04 -0800 | [diff] [blame] | 312 | mp_opt->fastclose = 0; |
Geliang Tang | 65b8c8a | 2020-10-19 18:23:16 +0800 | [diff] [blame] | 313 | mp_opt->port = 0; |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 314 | mp_opt->rm_addr = 0; |
| 315 | mp_opt->dss = 0; |
| 316 | |
| 317 | length = (th->doff * 4) - sizeof(struct tcphdr); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 318 | ptr = (const unsigned char *)(th + 1); |
| 319 | |
| 320 | while (length > 0) { |
| 321 | int opcode = *ptr++; |
| 322 | int opsize; |
| 323 | |
| 324 | switch (opcode) { |
| 325 | case TCPOPT_EOL: |
| 326 | return; |
| 327 | case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */ |
| 328 | length--; |
| 329 | continue; |
| 330 | default: |
| 331 | opsize = *ptr++; |
| 332 | if (opsize < 2) /* "silly options" */ |
| 333 | return; |
| 334 | if (opsize > length) |
| 335 | return; /* don't parse partial options */ |
| 336 | if (opcode == TCPOPT_MPTCP) |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 337 | mptcp_parse_option(skb, ptr, opsize, mp_opt); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 338 | ptr += opsize - 2; |
| 339 | length -= opsize; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 344 | bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, |
| 345 | unsigned int *size, struct mptcp_out_options *opts) |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 346 | { |
| 347 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 348 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 349 | /* we will use snd_isn to detect first pkt [re]transmission |
| 350 | * in mptcp_established_options_mp() |
| 351 | */ |
| 352 | subflow->snd_isn = TCP_SKB_CB(skb)->end_seq; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 353 | if (subflow->request_mptcp) { |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 354 | opts->suboptions = OPTION_MPTCP_MPC_SYN; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 355 | *size = TCPOLEN_MPTCP_MPC_SYN; |
| 356 | return true; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 357 | } else if (subflow->request_join) { |
| 358 | pr_debug("remote_token=%u, nonce=%u", subflow->remote_token, |
| 359 | subflow->local_nonce); |
| 360 | opts->suboptions = OPTION_MPTCP_MPJ_SYN; |
| 361 | opts->join_id = subflow->local_id; |
| 362 | opts->token = subflow->remote_token; |
| 363 | opts->nonce = subflow->local_nonce; |
| 364 | opts->backup = subflow->request_bkup; |
| 365 | *size = TCPOLEN_MPTCP_MPJ_SYN; |
| 366 | return true; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 367 | } |
| 368 | return false; |
| 369 | } |
| 370 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 371 | /* MP_JOIN client subflow must wait for 4th ack before sending any data: |
| 372 | * TCP can't schedule delack timer before the subflow is fully established. |
| 373 | * MPTCP uses the delack timer to do 3rd ack retransmissions |
| 374 | */ |
| 375 | static void schedule_3rdack_retransmission(struct sock *sk) |
| 376 | { |
| 377 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 378 | struct tcp_sock *tp = tcp_sk(sk); |
| 379 | unsigned long timeout; |
| 380 | |
| 381 | /* reschedule with a timeout above RTT, as we must look only for drop */ |
| 382 | if (tp->srtt_us) |
| 383 | timeout = tp->srtt_us << 1; |
| 384 | else |
| 385 | timeout = TCP_TIMEOUT_INIT; |
| 386 | |
| 387 | WARN_ON_ONCE(icsk->icsk_ack.pending & ICSK_ACK_TIMER); |
| 388 | icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER; |
| 389 | icsk->icsk_ack.timeout = timeout; |
| 390 | sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout); |
| 391 | } |
| 392 | |
| 393 | static void clear_3rdack_retransmission(struct sock *sk) |
| 394 | { |
| 395 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 396 | |
| 397 | sk_stop_timer(sk, &icsk->icsk_delack_timer); |
| 398 | icsk->icsk_ack.timeout = 0; |
| 399 | icsk->icsk_ack.ato = 0; |
| 400 | icsk->icsk_ack.pending &= ~(ICSK_ACK_SCHED | ICSK_ACK_TIMER); |
| 401 | } |
| 402 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 403 | static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb, |
| 404 | unsigned int *size, |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 405 | unsigned int remaining, |
| 406 | struct mptcp_out_options *opts) |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 407 | { |
| 408 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 409 | struct mptcp_ext *mpext; |
| 410 | unsigned int data_len; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 411 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 412 | /* When skb is not available, we better over-estimate the emitted |
| 413 | * options len. A full DSS option (28 bytes) is longer than |
| 414 | * TCPOLEN_MPTCP_MPC_ACK_DATA(22) or TCPOLEN_MPTCP_MPJ_ACK(24), so |
| 415 | * tell the caller to defer the estimate to |
| 416 | * mptcp_established_options_dss(), which will reserve enough space. |
| 417 | */ |
| 418 | if (!skb) |
| 419 | return false; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 420 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 421 | /* MPC/MPJ needed only on 3rd ack packet */ |
| 422 | if (subflow->fully_established || |
| 423 | subflow->snd_isn != TCP_SKB_CB(skb)->seq) |
| 424 | return false; |
| 425 | |
| 426 | if (subflow->mp_capable) { |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 427 | mpext = mptcp_get_ext(skb); |
| 428 | data_len = mpext ? mpext->data_len : 0; |
| 429 | |
| 430 | /* we will check ext_copy.data_len in mptcp_write_options() to |
| 431 | * discriminate between TCPOLEN_MPTCP_MPC_ACK_DATA and |
| 432 | * TCPOLEN_MPTCP_MPC_ACK |
| 433 | */ |
| 434 | opts->ext_copy.data_len = data_len; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 435 | opts->suboptions = OPTION_MPTCP_MPC_ACK; |
| 436 | opts->sndr_key = subflow->local_key; |
| 437 | opts->rcvr_key = subflow->remote_key; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 438 | |
| 439 | /* Section 3.1. |
| 440 | * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK |
| 441 | * packets that start the first subflow of an MPTCP connection, |
| 442 | * as well as the first packet that carries data |
| 443 | */ |
| 444 | if (data_len > 0) |
| 445 | *size = ALIGN(TCPOLEN_MPTCP_MPC_ACK_DATA, 4); |
| 446 | else |
| 447 | *size = TCPOLEN_MPTCP_MPC_ACK; |
| 448 | |
| 449 | pr_debug("subflow=%p, local_key=%llu, remote_key=%llu map_len=%d", |
| 450 | subflow, subflow->local_key, subflow->remote_key, |
| 451 | data_len); |
| 452 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 453 | return true; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 454 | } else if (subflow->mp_join) { |
| 455 | opts->suboptions = OPTION_MPTCP_MPJ_ACK; |
| 456 | memcpy(opts->hmac, subflow->hmac, MPTCPOPT_HMAC_LEN); |
| 457 | *size = TCPOLEN_MPTCP_MPJ_ACK; |
| 458 | pr_debug("subflow=%p", subflow); |
| 459 | |
| 460 | schedule_3rdack_retransmission(sk); |
| 461 | return true; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 462 | } |
| 463 | return false; |
| 464 | } |
| 465 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 466 | static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow, |
Paolo Abeni | 9c29e36 | 2020-07-03 18:06:04 +0200 | [diff] [blame] | 467 | struct sk_buff *skb, struct mptcp_ext *ext) |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 468 | { |
Paolo Abeni | 017512a | 2020-10-05 12:01:06 +0200 | [diff] [blame] | 469 | /* The write_seq value has already been incremented, so the actual |
| 470 | * sequence number for the DATA_FIN is one less. |
| 471 | */ |
| 472 | u64 data_fin_tx_seq = READ_ONCE(mptcp_sk(subflow->conn)->write_seq) - 1; |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 473 | |
Paolo Abeni | 9c29e36 | 2020-07-03 18:06:04 +0200 | [diff] [blame] | 474 | if (!ext->use_map || !skb->len) { |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 475 | /* RFC6824 requires a DSS mapping with specific values |
| 476 | * if DATA_FIN is set but no data payload is mapped |
| 477 | */ |
Mat Martineau | 6d37a0b | 2020-02-28 15:47:41 -0800 | [diff] [blame] | 478 | ext->data_fin = 1; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 479 | ext->use_map = 1; |
| 480 | ext->dsn64 = 1; |
Paolo Abeni | 017512a | 2020-10-05 12:01:06 +0200 | [diff] [blame] | 481 | ext->data_seq = data_fin_tx_seq; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 482 | ext->subflow_seq = 0; |
| 483 | ext->data_len = 1; |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 484 | } else if (ext->data_seq + ext->data_len == data_fin_tx_seq) { |
Mat Martineau | 6d37a0b | 2020-02-28 15:47:41 -0800 | [diff] [blame] | 485 | /* If there's an existing DSS mapping and it is the |
| 486 | * final mapping, DATA_FIN consumes 1 additional byte of |
| 487 | * mapping space. |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 488 | */ |
Mat Martineau | 6d37a0b | 2020-02-28 15:47:41 -0800 | [diff] [blame] | 489 | ext->data_fin = 1; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 490 | ext->data_len++; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, |
| 495 | unsigned int *size, |
| 496 | unsigned int remaining, |
| 497 | struct mptcp_out_options *opts) |
| 498 | { |
| 499 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 500 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 501 | unsigned int dss_size = 0; |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 502 | u64 snd_data_fin_enable; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 503 | struct mptcp_ext *mpext; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 504 | unsigned int ack_size; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 505 | bool ret = false; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 506 | |
Mat Martineau | 0bac966 | 2020-07-28 15:11:59 -0700 | [diff] [blame] | 507 | mpext = skb ? mptcp_get_ext(skb) : NULL; |
Paolo Abeni | e16163b | 2020-11-16 10:48:09 +0100 | [diff] [blame] | 508 | snd_data_fin_enable = mptcp_data_fin_enabled(msk); |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 509 | |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 510 | if (!skb || (mpext && mpext->use_map) || snd_data_fin_enable) { |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 511 | unsigned int map_size; |
| 512 | |
| 513 | map_size = TCPOLEN_MPTCP_DSS_BASE + TCPOLEN_MPTCP_DSS_MAP64; |
| 514 | |
| 515 | remaining -= map_size; |
| 516 | dss_size = map_size; |
| 517 | if (mpext) |
| 518 | opts->ext_copy = *mpext; |
| 519 | |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 520 | if (skb && snd_data_fin_enable) |
Paolo Abeni | 9c29e36 | 2020-07-03 18:06:04 +0200 | [diff] [blame] | 521 | mptcp_write_data_fin(subflow, skb, &opts->ext_copy); |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 522 | ret = true; |
| 523 | } |
| 524 | |
Paolo Abeni | 2398e39 | 2020-03-04 16:51:07 +0100 | [diff] [blame] | 525 | /* passive sockets msk will set the 'can_ack' after accept(), even |
| 526 | * if the first subflow may have the already the remote key handy |
| 527 | */ |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 528 | opts->ext_copy.use_ack = 0; |
Paolo Abeni | dc093db | 2020-03-13 16:52:42 +0100 | [diff] [blame] | 529 | if (!READ_ONCE(msk->can_ack)) { |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 530 | *size = ALIGN(dss_size, 4); |
| 531 | return ret; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Davide Caratti | 37198e9 | 2020-10-06 18:26:17 +0200 | [diff] [blame] | 534 | if (READ_ONCE(msk->use_64bit_ack)) { |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 535 | ack_size = TCPOLEN_MPTCP_DSS_ACK64; |
Mat Martineau | 917944d | 2020-09-29 15:08:19 -0700 | [diff] [blame] | 536 | opts->ext_copy.data_ack = READ_ONCE(msk->ack_seq); |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 537 | opts->ext_copy.ack64 = 1; |
| 538 | } else { |
| 539 | ack_size = TCPOLEN_MPTCP_DSS_ACK32; |
Mat Martineau | 917944d | 2020-09-29 15:08:19 -0700 | [diff] [blame] | 540 | opts->ext_copy.data_ack32 = (uint32_t)READ_ONCE(msk->ack_seq); |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 541 | opts->ext_copy.ack64 = 0; |
| 542 | } |
| 543 | opts->ext_copy.use_ack = 1; |
Paolo Abeni | ea4ca58 | 2020-11-19 11:46:03 -0800 | [diff] [blame] | 544 | WRITE_ONCE(msk->old_wspace, __mptcp_space((struct sock *)msk)); |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 545 | |
| 546 | /* Add kind/length/subtype/flag overhead if mapping is not populated */ |
| 547 | if (dss_size == 0) |
| 548 | ack_size += TCPOLEN_MPTCP_DSS_BASE; |
| 549 | |
| 550 | dss_size += ack_size; |
| 551 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 552 | *size = ALIGN(dss_size, 4); |
| 553 | return true; |
| 554 | } |
| 555 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 556 | static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, |
| 557 | struct in_addr *addr) |
| 558 | { |
Todd Malsbary | bd69722 | 2020-05-21 19:10:49 -0700 | [diff] [blame] | 559 | u8 hmac[SHA256_DIGEST_SIZE]; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 560 | u8 msg[7]; |
| 561 | |
| 562 | msg[0] = addr_id; |
| 563 | memcpy(&msg[1], &addr->s_addr, 4); |
| 564 | msg[5] = 0; |
| 565 | msg[6] = 0; |
| 566 | |
| 567 | mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac); |
| 568 | |
Todd Malsbary | bd69722 | 2020-05-21 19:10:49 -0700 | [diff] [blame] | 569 | return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 573 | static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id, |
| 574 | struct in6_addr *addr) |
| 575 | { |
Todd Malsbary | bd69722 | 2020-05-21 19:10:49 -0700 | [diff] [blame] | 576 | u8 hmac[SHA256_DIGEST_SIZE]; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 577 | u8 msg[19]; |
| 578 | |
| 579 | msg[0] = addr_id; |
| 580 | memcpy(&msg[1], &addr->s6_addr, 16); |
| 581 | msg[17] = 0; |
| 582 | msg[18] = 0; |
| 583 | |
| 584 | mptcp_crypto_hmac_sha(key1, key2, msg, 19, hmac); |
| 585 | |
Todd Malsbary | bd69722 | 2020-05-21 19:10:49 -0700 | [diff] [blame] | 586 | return get_unaligned_be64(&hmac[SHA256_DIGEST_SIZE - sizeof(u64)]); |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 587 | } |
| 588 | #endif |
| 589 | |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 590 | static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *skb, |
Geliang Tang | f643b80 | 2020-09-24 08:29:47 +0800 | [diff] [blame] | 591 | unsigned int *size, |
| 592 | unsigned int remaining, |
| 593 | struct mptcp_out_options *opts) |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 594 | { |
| 595 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 596 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 597 | bool drop_other_suboptions = false; |
| 598 | unsigned int opt_size = *size; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 599 | struct mptcp_addr_info saddr; |
Geliang Tang | 6a6c05a | 2020-09-24 08:29:50 +0800 | [diff] [blame] | 600 | bool echo; |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 601 | bool port; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 602 | int len; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 603 | |
Geliang Tang | fbe0f87 | 2020-12-09 15:51:23 -0800 | [diff] [blame] | 604 | if ((mptcp_pm_should_add_signal_ipv6(msk) || |
| 605 | mptcp_pm_should_add_signal_port(msk)) && |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 606 | skb && skb_is_tcp_pure_ack(skb)) { |
| 607 | pr_debug("drop other suboptions"); |
| 608 | opts->suboptions = 0; |
Geliang Tang | 3ae32c0 | 2020-12-15 17:56:51 +0800 | [diff] [blame] | 609 | opts->ext_copy.use_ack = 0; |
| 610 | opts->ext_copy.use_map = 0; |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 611 | remaining += opt_size; |
| 612 | drop_other_suboptions = true; |
| 613 | } |
| 614 | |
Geliang Tang | f643b80 | 2020-09-24 08:29:47 +0800 | [diff] [blame] | 615 | if (!mptcp_pm_should_add_signal(msk) || |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 616 | !(mptcp_pm_add_addr_signal(msk, remaining, &saddr, &echo, &port))) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 617 | return false; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 618 | |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 619 | len = mptcp_add_addr_len(saddr.family, echo, port); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 620 | if (remaining < len) |
| 621 | return false; |
| 622 | |
| 623 | *size = len; |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 624 | if (drop_other_suboptions) |
| 625 | *size -= opt_size; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 626 | opts->addr_id = saddr.id; |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 627 | if (port) |
| 628 | opts->port = ntohs(saddr.port); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 629 | if (saddr.family == AF_INET) { |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 630 | opts->suboptions |= OPTION_MPTCP_ADD_ADDR; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 631 | opts->addr = saddr.addr; |
Geliang Tang | 6a6c05a | 2020-09-24 08:29:50 +0800 | [diff] [blame] | 632 | if (!echo) { |
| 633 | opts->ahmac = add_addr_generate_hmac(msk->local_key, |
| 634 | msk->remote_key, |
| 635 | opts->addr_id, |
| 636 | &opts->addr); |
| 637 | } |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 638 | } |
| 639 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 640 | else if (saddr.family == AF_INET6) { |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 641 | opts->suboptions |= OPTION_MPTCP_ADD_ADDR6; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 642 | opts->addr6 = saddr.addr6; |
Geliang Tang | 6a6c05a | 2020-09-24 08:29:50 +0800 | [diff] [blame] | 643 | if (!echo) { |
| 644 | opts->ahmac = add_addr6_generate_hmac(msk->local_key, |
| 645 | msk->remote_key, |
| 646 | opts->addr_id, |
| 647 | &opts->addr6); |
| 648 | } |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 649 | } |
| 650 | #endif |
Geliang Tang | 4a2777a8 | 2020-12-09 15:51:22 -0800 | [diff] [blame] | 651 | pr_debug("addr_id=%d, ahmac=%llu, echo=%d, port=%d", |
| 652 | opts->addr_id, opts->ahmac, echo, opts->port); |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 653 | |
| 654 | return true; |
| 655 | } |
| 656 | |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 657 | static bool mptcp_established_options_rm_addr(struct sock *sk, |
| 658 | unsigned int *size, |
| 659 | unsigned int remaining, |
| 660 | struct mptcp_out_options *opts) |
| 661 | { |
| 662 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 663 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
| 664 | u8 rm_id; |
| 665 | |
| 666 | if (!mptcp_pm_should_rm_signal(msk) || |
| 667 | !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_id))) |
| 668 | return false; |
| 669 | |
| 670 | if (remaining < TCPOLEN_MPTCP_RM_ADDR_BASE) |
| 671 | return false; |
| 672 | |
| 673 | *size = TCPOLEN_MPTCP_RM_ADDR_BASE; |
| 674 | opts->suboptions |= OPTION_MPTCP_RM_ADDR; |
| 675 | opts->rm_id = rm_id; |
| 676 | |
| 677 | pr_debug("rm_id=%d", opts->rm_id); |
| 678 | |
| 679 | return true; |
| 680 | } |
| 681 | |
Geliang Tang | 0670654 | 2021-01-08 16:47:57 -0800 | [diff] [blame^] | 682 | static bool mptcp_established_options_mp_prio(struct sock *sk, |
| 683 | unsigned int *size, |
| 684 | unsigned int remaining, |
| 685 | struct mptcp_out_options *opts) |
| 686 | { |
| 687 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 688 | |
| 689 | if (!subflow->send_mp_prio) |
| 690 | return false; |
| 691 | |
| 692 | if (remaining < TCPOLEN_MPTCP_PRIO) |
| 693 | return false; |
| 694 | |
| 695 | *size = TCPOLEN_MPTCP_PRIO; |
| 696 | opts->suboptions |= OPTION_MPTCP_PRIO; |
| 697 | opts->backup = subflow->request_bkup; |
| 698 | |
| 699 | pr_debug("prio=%d", opts->backup); |
| 700 | |
| 701 | return true; |
| 702 | } |
| 703 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 704 | bool mptcp_established_options(struct sock *sk, struct sk_buff *skb, |
| 705 | unsigned int *size, unsigned int remaining, |
| 706 | struct mptcp_out_options *opts) |
| 707 | { |
| 708 | unsigned int opt_size = 0; |
| 709 | bool ret = false; |
| 710 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 711 | opts->suboptions = 0; |
| 712 | |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 713 | if (unlikely(mptcp_check_fallback(sk))) |
| 714 | return false; |
| 715 | |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 716 | /* prevent adding of any MPTCP related options on reset packet |
| 717 | * until we support MP_TCPRST/MP_FASTCLOSE |
| 718 | */ |
| 719 | if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) |
| 720 | return false; |
| 721 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 722 | if (mptcp_established_options_mp(sk, skb, &opt_size, remaining, opts)) |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 723 | ret = true; |
| 724 | else if (mptcp_established_options_dss(sk, skb, &opt_size, remaining, |
| 725 | opts)) |
| 726 | ret = true; |
| 727 | |
| 728 | /* we reserved enough space for the above options, and exceeding the |
| 729 | * TCP option space would be fatal |
| 730 | */ |
| 731 | if (WARN_ON_ONCE(opt_size > remaining)) |
| 732 | return false; |
| 733 | |
| 734 | *size += opt_size; |
| 735 | remaining -= opt_size; |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 736 | if (mptcp_established_options_add_addr(sk, skb, &opt_size, remaining, opts)) { |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 737 | *size += opt_size; |
| 738 | remaining -= opt_size; |
| 739 | ret = true; |
Geliang Tang | 5cb104a | 2020-09-24 08:29:48 +0800 | [diff] [blame] | 740 | } else if (mptcp_established_options_rm_addr(sk, &opt_size, remaining, opts)) { |
| 741 | *size += opt_size; |
| 742 | remaining -= opt_size; |
| 743 | ret = true; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 744 | } |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 745 | |
Geliang Tang | 0670654 | 2021-01-08 16:47:57 -0800 | [diff] [blame^] | 746 | if (mptcp_established_options_mp_prio(sk, &opt_size, remaining, opts)) { |
| 747 | *size += opt_size; |
| 748 | remaining -= opt_size; |
| 749 | ret = true; |
| 750 | } |
| 751 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 752 | return ret; |
| 753 | } |
| 754 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 755 | bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, |
| 756 | struct mptcp_out_options *opts) |
| 757 | { |
| 758 | struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); |
| 759 | |
| 760 | if (subflow_req->mp_capable) { |
| 761 | opts->suboptions = OPTION_MPTCP_MPC_SYNACK; |
| 762 | opts->sndr_key = subflow_req->local_key; |
| 763 | *size = TCPOLEN_MPTCP_MPC_SYNACK; |
| 764 | pr_debug("subflow_req=%p, local_key=%llu", |
| 765 | subflow_req, subflow_req->local_key); |
| 766 | return true; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 767 | } else if (subflow_req->mp_join) { |
| 768 | opts->suboptions = OPTION_MPTCP_MPJ_SYNACK; |
| 769 | opts->backup = subflow_req->backup; |
| 770 | opts->join_id = subflow_req->local_id; |
| 771 | opts->thmac = subflow_req->thmac; |
| 772 | opts->nonce = subflow_req->local_nonce; |
| 773 | pr_debug("req=%p, bkup=%u, id=%u, thmac=%llu, nonce=%u", |
| 774 | subflow_req, opts->backup, opts->join_id, |
| 775 | opts->thmac, opts->nonce); |
| 776 | *size = TCPOLEN_MPTCP_MPJ_SYNACK; |
| 777 | return true; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 778 | } |
| 779 | return false; |
| 780 | } |
| 781 | |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 782 | static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 783 | struct mptcp_subflow_context *subflow, |
Paolo Abeni | 0be534f | 2020-03-19 11:06:30 +0100 | [diff] [blame] | 784 | struct sk_buff *skb, |
| 785 | struct mptcp_options_received *mp_opt) |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 786 | { |
| 787 | /* here we can process OoO, in-window pkts, only in-sequence 4th ack |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 788 | * will make the subflow fully established |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 789 | */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 790 | if (likely(subflow->fully_established)) { |
| 791 | /* on passive sockets, check for 3rd ack retransmission |
| 792 | * note that msk is always set by subflow_syn_recv_sock() |
| 793 | * for mp_join subflows |
| 794 | */ |
| 795 | if (TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 && |
| 796 | TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq && |
| 797 | subflow->mp_join && mp_opt->mp_join && |
| 798 | READ_ONCE(msk->pm.server_side)) |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 799 | tcp_send_ack(ssk); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 800 | goto fully_established; |
| 801 | } |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 802 | |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 803 | /* we must process OoO packets before the first subflow is fully |
| 804 | * established. OoO packets are instead a protocol violation |
| 805 | * for MP_JOIN subflows as the peer must not send any data |
| 806 | * before receiving the forth ack - cfr. RFC 8684 section 3.2. |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 807 | */ |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 808 | if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) { |
| 809 | if (subflow->mp_join) |
| 810 | goto reset; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 811 | return subflow->mp_capable; |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 812 | } |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 813 | |
Paolo Abeni | 5a91e32 | 2020-04-30 15:01:54 +0200 | [diff] [blame] | 814 | if (mp_opt->dss && mp_opt->use_ack) { |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 815 | /* subflows are fully established as soon as we get any |
| 816 | * additional ack. |
| 817 | */ |
Paolo Abeni | 0be534f | 2020-03-19 11:06:30 +0100 | [diff] [blame] | 818 | subflow->fully_established = 1; |
Paolo Abeni | b93df08 | 2020-07-23 13:02:32 +0200 | [diff] [blame] | 819 | WRITE_ONCE(msk->fully_established, true); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 820 | goto fully_established; |
| 821 | } |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 822 | |
Geliang Tang | 84dfe36 | 2020-11-19 11:46:00 -0800 | [diff] [blame] | 823 | if (mp_opt->add_addr) { |
| 824 | WRITE_ONCE(msk->fully_established, true); |
| 825 | return true; |
| 826 | } |
| 827 | |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 828 | /* If the first established packet does not contain MP_CAPABLE + data |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 829 | * then fallback to TCP. Fallback scenarios requires a reset for |
| 830 | * MP_JOIN subflows. |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 831 | */ |
| 832 | if (!mp_opt->mp_capable) { |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 833 | if (subflow->mp_join) |
| 834 | goto reset; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 835 | subflow->mp_capable = 0; |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 836 | pr_fallback(msk); |
| 837 | __mptcp_do_fallback(msk); |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 838 | return false; |
| 839 | } |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 840 | |
Paolo Abeni | d6085fe | 2020-04-30 15:01:53 +0200 | [diff] [blame] | 841 | if (unlikely(!READ_ONCE(msk->pm.server_side))) |
| 842 | pr_warn_once("bogus mpc option on established client sk"); |
Paolo Abeni | b93df08 | 2020-07-23 13:02:32 +0200 | [diff] [blame] | 843 | mptcp_subflow_fully_established(subflow, mp_opt); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 844 | |
| 845 | fully_established: |
Paolo Abeni | 5b950ff | 2020-12-09 12:03:29 +0100 | [diff] [blame] | 846 | /* if the subflow is not already linked into the conn_list, we can't |
| 847 | * notify the PM: this subflow is still on the listener queue |
| 848 | * and the PM possibly acquiring the subflow lock could race with |
| 849 | * the listener close |
| 850 | */ |
| 851 | if (likely(subflow->pm_notified) || list_empty(&subflow->node)) |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 852 | return true; |
| 853 | |
| 854 | subflow->pm_notified = 1; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 855 | if (subflow->mp_join) { |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 856 | clear_3rdack_retransmission(ssk); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 857 | mptcp_pm_subflow_established(msk, subflow); |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 858 | } else { |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 859 | mptcp_pm_fully_established(msk); |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 860 | } |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 861 | return true; |
Paolo Abeni | d582484 | 2020-10-09 19:00:00 +0200 | [diff] [blame] | 862 | |
| 863 | reset: |
| 864 | mptcp_subflow_reset(ssk); |
| 865 | return false; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 868 | static u64 expand_ack(u64 old_ack, u64 cur_ack, bool use_64bit) |
| 869 | { |
| 870 | u32 old_ack32, cur_ack32; |
| 871 | |
| 872 | if (use_64bit) |
| 873 | return cur_ack; |
| 874 | |
| 875 | old_ack32 = (u32)old_ack; |
| 876 | cur_ack32 = (u32)cur_ack; |
| 877 | cur_ack = (old_ack & GENMASK_ULL(63, 32)) + cur_ack32; |
| 878 | if (unlikely(before(cur_ack32, old_ack32))) |
| 879 | return cur_ack + (1LL << 32); |
| 880 | return cur_ack; |
| 881 | } |
| 882 | |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 883 | static void ack_update_msk(struct mptcp_sock *msk, |
Paolo Abeni | 6e628cd | 2020-11-27 11:10:27 +0100 | [diff] [blame] | 884 | struct sock *ssk, |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 885 | struct mptcp_options_received *mp_opt) |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 886 | { |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 887 | u64 new_wnd_end, new_snd_una, snd_nxt = READ_ONCE(msk->snd_nxt); |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 888 | struct sock *sk = (struct sock *)msk; |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 889 | u64 old_snd_una; |
| 890 | |
| 891 | mptcp_data_lock(sk); |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 892 | |
| 893 | /* avoid ack expansion on update conflict, to reduce the risk of |
| 894 | * wrongly expanding to a future ack sequence number, which is way |
| 895 | * more dangerous than missing an ack |
| 896 | */ |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 897 | old_snd_una = msk->snd_una; |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 898 | new_snd_una = expand_ack(old_snd_una, mp_opt->data_ack, mp_opt->ack64); |
| 899 | |
| 900 | /* ACK for data not even sent yet? Ignore. */ |
Paolo Abeni | eaa2ffa | 2020-11-16 10:48:08 +0100 | [diff] [blame] | 901 | if (after64(new_snd_una, snd_nxt)) |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 902 | new_snd_una = old_snd_una; |
| 903 | |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 904 | new_wnd_end = new_snd_una + tcp_sk(ssk)->snd_wnd; |
| 905 | |
Paolo Abeni | 219d049 | 2020-12-16 12:48:34 +0100 | [diff] [blame] | 906 | if (after64(new_wnd_end, msk->wnd_end)) |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 907 | msk->wnd_end = new_wnd_end; |
Paolo Abeni | 219d049 | 2020-12-16 12:48:34 +0100 | [diff] [blame] | 908 | |
| 909 | /* this assumes mptcp_incoming_options() is invoked after tcp_ack() */ |
| 910 | if (after64(msk->wnd_end, READ_ONCE(msk->snd_nxt)) && |
| 911 | sk_stream_memory_free(ssk)) |
| 912 | __mptcp_check_push(sk, ssk); |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 913 | |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 914 | if (after64(new_snd_una, old_snd_una)) { |
| 915 | msk->snd_una = new_snd_una; |
| 916 | __mptcp_data_acked(sk); |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 917 | } |
Paolo Abeni | 7439d68 | 2020-11-27 11:10:26 +0100 | [diff] [blame] | 918 | mptcp_data_unlock(sk); |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Mat Martineau | 1a49b2c | 2020-09-29 15:08:20 -0700 | [diff] [blame] | 921 | bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit) |
Mat Martineau | 3721b9b | 2020-07-28 15:12:03 -0700 | [diff] [blame] | 922 | { |
| 923 | /* Skip if DATA_FIN was already received. |
| 924 | * If updating simultaneously with the recvmsg loop, values |
| 925 | * should match. If they mismatch, the peer is misbehaving and |
| 926 | * we will prefer the most recent information. |
| 927 | */ |
| 928 | if (READ_ONCE(msk->rcv_data_fin) || !READ_ONCE(msk->first)) |
| 929 | return false; |
| 930 | |
Mat Martineau | 1a49b2c | 2020-09-29 15:08:20 -0700 | [diff] [blame] | 931 | WRITE_ONCE(msk->rcv_data_fin_seq, |
| 932 | expand_ack(READ_ONCE(msk->ack_seq), data_fin_seq, use_64bit)); |
Mat Martineau | 3721b9b | 2020-07-28 15:12:03 -0700 | [diff] [blame] | 933 | WRITE_ONCE(msk->rcv_data_fin, 1); |
| 934 | |
| 935 | return true; |
| 936 | } |
| 937 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 938 | static bool add_addr_hmac_valid(struct mptcp_sock *msk, |
| 939 | struct mptcp_options_received *mp_opt) |
| 940 | { |
| 941 | u64 hmac = 0; |
| 942 | |
| 943 | if (mp_opt->echo) |
| 944 | return true; |
| 945 | |
| 946 | if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) |
| 947 | hmac = add_addr_generate_hmac(msk->remote_key, |
| 948 | msk->local_key, |
| 949 | mp_opt->addr_id, &mp_opt->addr); |
| 950 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 951 | else |
| 952 | hmac = add_addr6_generate_hmac(msk->remote_key, |
| 953 | msk->local_key, |
| 954 | mp_opt->addr_id, &mp_opt->addr6); |
| 955 | #endif |
| 956 | |
| 957 | pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", |
| 958 | msk, (unsigned long long)hmac, |
| 959 | (unsigned long long)mp_opt->ahmac); |
| 960 | |
| 961 | return hmac == mp_opt->ahmac; |
| 962 | } |
| 963 | |
Florian Westphal | 77d0cab | 2020-09-25 01:23:02 +0200 | [diff] [blame] | 964 | void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 965 | { |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 966 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 967 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 968 | struct mptcp_options_received mp_opt; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 969 | struct mptcp_ext *mpext; |
| 970 | |
Paolo Abeni | 6e628cd | 2020-11-27 11:10:27 +0100 | [diff] [blame] | 971 | if (__mptcp_check_fallback(msk)) { |
| 972 | /* Keep it simple and unconditionally trigger send data cleanup and |
| 973 | * pending queue spooling. We will need to acquire the data lock |
| 974 | * for more accurate checks, and once the lock is acquired, such |
| 975 | * helpers are cheap. |
| 976 | */ |
| 977 | mptcp_data_lock(subflow->conn); |
Paolo Abeni | 219d049 | 2020-12-16 12:48:34 +0100 | [diff] [blame] | 978 | if (sk_stream_memory_free(sk)) |
| 979 | __mptcp_check_push(subflow->conn, sk); |
Paolo Abeni | 6e628cd | 2020-11-27 11:10:27 +0100 | [diff] [blame] | 980 | __mptcp_data_acked(subflow->conn); |
| 981 | mptcp_data_unlock(subflow->conn); |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 982 | return; |
Paolo Abeni | 6e628cd | 2020-11-27 11:10:27 +0100 | [diff] [blame] | 983 | } |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 984 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 985 | mptcp_get_options(skb, &mp_opt); |
| 986 | if (!check_fully_established(msk, sk, subflow, skb, &mp_opt)) |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 987 | return; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 988 | |
Florian Westphal | 50c504a | 2020-12-10 14:25:04 -0800 | [diff] [blame] | 989 | if (mp_opt.fastclose && |
| 990 | msk->local_key == mp_opt.rcvr_key) { |
| 991 | WRITE_ONCE(msk->rcv_fastclose, true); |
| 992 | mptcp_schedule_work((struct sock *)msk); |
| 993 | } |
| 994 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 995 | if (mp_opt.add_addr && add_addr_hmac_valid(msk, &mp_opt)) { |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 996 | struct mptcp_addr_info addr; |
| 997 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 998 | addr.port = htons(mp_opt.port); |
| 999 | addr.id = mp_opt.addr_id; |
| 1000 | if (mp_opt.family == MPTCP_ADDR_IPVERSION_4) { |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1001 | addr.family = AF_INET; |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1002 | addr.addr = mp_opt.addr; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1003 | } |
| 1004 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1005 | else if (mp_opt.family == MPTCP_ADDR_IPVERSION_6) { |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1006 | addr.family = AF_INET6; |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1007 | addr.addr6 = mp_opt.addr6; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1008 | } |
| 1009 | #endif |
Geliang Tang | a877de06 | 2020-09-24 08:29:51 +0800 | [diff] [blame] | 1010 | if (!mp_opt.echo) { |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1011 | mptcp_pm_add_addr_received(msk, &addr); |
Geliang Tang | a877de06 | 2020-09-24 08:29:51 +0800 | [diff] [blame] | 1012 | MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR); |
| 1013 | } else { |
Geliang Tang | 00cfd77 | 2020-09-24 08:30:02 +0800 | [diff] [blame] | 1014 | mptcp_pm_del_add_timer(msk, &addr); |
Geliang Tang | a877de06 | 2020-09-24 08:29:51 +0800 | [diff] [blame] | 1015 | MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD); |
| 1016 | } |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1017 | mp_opt.add_addr = 0; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Geliang Tang | d0876b2 | 2020-09-24 08:29:49 +0800 | [diff] [blame] | 1020 | if (mp_opt.rm_addr) { |
| 1021 | mptcp_pm_rm_addr_received(msk, mp_opt.rm_id); |
| 1022 | mp_opt.rm_addr = 0; |
| 1023 | } |
| 1024 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1025 | if (!mp_opt.dss) |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 1026 | return; |
| 1027 | |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 1028 | /* we can't wait for recvmsg() to update the ack_seq, otherwise |
| 1029 | * monodirectional flows will stuck |
| 1030 | */ |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1031 | if (mp_opt.use_ack) |
Florian Westphal | 6f8a612 | 2020-11-16 10:48:13 +0100 | [diff] [blame] | 1032 | ack_update_msk(msk, sk, &mp_opt); |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 1033 | |
Mat Martineau | 06827b3 | 2020-07-28 15:12:08 -0700 | [diff] [blame] | 1034 | /* Zero-data-length packets are dropped by the caller and not |
| 1035 | * propagated to the MPTCP layer, so the skb extension does not |
| 1036 | * need to be allocated or populated. DATA_FIN information, if |
| 1037 | * present, needs to be updated here before the skb is freed. |
Mat Martineau | 43b54c6 | 2020-07-28 15:12:06 -0700 | [diff] [blame] | 1038 | */ |
| 1039 | if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) { |
| 1040 | if (mp_opt.data_fin && mp_opt.data_len == 1 && |
Mat Martineau | 1a49b2c | 2020-09-29 15:08:20 -0700 | [diff] [blame] | 1041 | mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64) && |
Mat Martineau | 43b54c6 | 2020-07-28 15:12:06 -0700 | [diff] [blame] | 1042 | schedule_work(&msk->work)) |
| 1043 | sock_hold(subflow->conn); |
Mat Martineau | 06827b3 | 2020-07-28 15:12:08 -0700 | [diff] [blame] | 1044 | |
| 1045 | return; |
Mat Martineau | 43b54c6 | 2020-07-28 15:12:06 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 1048 | mpext = skb_ext_add(skb, SKB_EXT_MPTCP); |
| 1049 | if (!mpext) |
| 1050 | return; |
| 1051 | |
| 1052 | memset(mpext, 0, sizeof(*mpext)); |
| 1053 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1054 | if (mp_opt.use_map) { |
| 1055 | if (mp_opt.mpc_map) { |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1056 | /* this is an MP_CAPABLE carrying MPTCP data |
| 1057 | * we know this map the first chunk of data |
| 1058 | */ |
| 1059 | mptcp_crypto_key_sha(subflow->remote_key, NULL, |
| 1060 | &mpext->data_seq); |
| 1061 | mpext->data_seq++; |
| 1062 | mpext->subflow_seq = 1; |
| 1063 | mpext->dsn64 = 1; |
| 1064 | mpext->mpc_map = 1; |
Paolo Abeni | a77895d | 2020-04-30 15:01:55 +0200 | [diff] [blame] | 1065 | mpext->data_fin = 0; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1066 | } else { |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1067 | mpext->data_seq = mp_opt.data_seq; |
| 1068 | mpext->subflow_seq = mp_opt.subflow_seq; |
| 1069 | mpext->dsn64 = mp_opt.dsn64; |
| 1070 | mpext->data_fin = mp_opt.data_fin; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1071 | } |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 1072 | mpext->data_len = mp_opt.data_len; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 1073 | mpext->use_map = 1; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 1074 | } |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Florian Westphal | fa3fe2b | 2020-11-19 11:46:02 -0800 | [diff] [blame] | 1077 | static void mptcp_set_rwin(const struct tcp_sock *tp) |
| 1078 | { |
| 1079 | const struct sock *ssk = (const struct sock *)tp; |
| 1080 | const struct mptcp_subflow_context *subflow; |
| 1081 | struct mptcp_sock *msk; |
| 1082 | u64 ack_seq; |
| 1083 | |
| 1084 | subflow = mptcp_subflow_ctx(ssk); |
| 1085 | msk = mptcp_sk(subflow->conn); |
| 1086 | |
| 1087 | ack_seq = READ_ONCE(msk->ack_seq) + tp->rcv_wnd; |
| 1088 | |
| 1089 | if (after64(ack_seq, READ_ONCE(msk->rcv_wnd_sent))) |
| 1090 | WRITE_ONCE(msk->rcv_wnd_sent, ack_seq); |
| 1091 | } |
| 1092 | |
| 1093 | void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, |
| 1094 | struct mptcp_out_options *opts) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1095 | { |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1096 | if ((OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1097 | OPTION_MPTCP_MPC_ACK) & opts->suboptions) { |
| 1098 | u8 len; |
| 1099 | |
| 1100 | if (OPTION_MPTCP_MPC_SYN & opts->suboptions) |
| 1101 | len = TCPOLEN_MPTCP_MPC_SYN; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 1102 | else if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) |
| 1103 | len = TCPOLEN_MPTCP_MPC_SYNACK; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1104 | else if (opts->ext_copy.data_len) |
| 1105 | len = TCPOLEN_MPTCP_MPC_ACK_DATA; |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1106 | else |
| 1107 | len = TCPOLEN_MPTCP_MPC_ACK; |
| 1108 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1109 | *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len, |
| 1110 | MPTCP_SUPPORTED_VERSION, |
| 1111 | MPTCP_CAP_HMAC_SHA256); |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1112 | |
| 1113 | if (!((OPTION_MPTCP_MPC_SYNACK | OPTION_MPTCP_MPC_ACK) & |
| 1114 | opts->suboptions)) |
| 1115 | goto mp_capable_done; |
| 1116 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1117 | put_unaligned_be64(opts->sndr_key, ptr); |
| 1118 | ptr += 2; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1119 | if (!((OPTION_MPTCP_MPC_ACK) & opts->suboptions)) |
| 1120 | goto mp_capable_done; |
| 1121 | |
| 1122 | put_unaligned_be64(opts->rcvr_key, ptr); |
| 1123 | ptr += 2; |
| 1124 | if (!opts->ext_copy.data_len) |
| 1125 | goto mp_capable_done; |
| 1126 | |
| 1127 | put_unaligned_be32(opts->ext_copy.data_len << 16 | |
| 1128 | TCPOPT_NOP << 8 | TCPOPT_NOP, ptr); |
| 1129 | ptr += 1; |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1130 | } |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 1131 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 1132 | mp_capable_done: |
Geliang Tang | e1ef683 | 2020-12-09 15:51:19 -0800 | [diff] [blame] | 1133 | if ((OPTION_MPTCP_ADD_ADDR |
| 1134 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 1135 | | OPTION_MPTCP_ADD_ADDR6 |
| 1136 | #endif |
| 1137 | ) & opts->suboptions) { |
Geliang Tang | 6eb3d1e | 2020-12-09 15:51:18 -0800 | [diff] [blame] | 1138 | u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE; |
| 1139 | u8 echo = MPTCP_ADDR_ECHO; |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1140 | |
| 1141 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
Geliang Tang | e1ef683 | 2020-12-09 15:51:19 -0800 | [diff] [blame] | 1142 | if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) |
| 1143 | len = TCPOLEN_MPTCP_ADD_ADDR6_BASE; |
| 1144 | #endif |
Geliang Tang | 6eb3d1e | 2020-12-09 15:51:18 -0800 | [diff] [blame] | 1145 | |
Geliang Tang | 22fb85f | 2020-12-09 15:51:20 -0800 | [diff] [blame] | 1146 | if (opts->port) |
| 1147 | len += TCPOLEN_MPTCP_PORT_LEN; |
| 1148 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1149 | if (opts->ahmac) { |
Geliang Tang | 6eb3d1e | 2020-12-09 15:51:18 -0800 | [diff] [blame] | 1150 | len += sizeof(opts->ahmac); |
| 1151 | echo = 0; |
| 1152 | } |
Geliang Tang | e1ef683 | 2020-12-09 15:51:19 -0800 | [diff] [blame] | 1153 | |
Geliang Tang | 6eb3d1e | 2020-12-09 15:51:18 -0800 | [diff] [blame] | 1154 | *ptr++ = mptcp_option(MPTCPOPT_ADD_ADDR, |
| 1155 | len, echo, opts->addr_id); |
Geliang Tang | e1ef683 | 2020-12-09 15:51:19 -0800 | [diff] [blame] | 1156 | if (OPTION_MPTCP_ADD_ADDR & opts->suboptions) { |
| 1157 | memcpy((u8 *)ptr, (u8 *)&opts->addr.s_addr, 4); |
| 1158 | ptr += 1; |
| 1159 | } |
| 1160 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 1161 | else if (OPTION_MPTCP_ADD_ADDR6 & opts->suboptions) { |
| 1162 | memcpy((u8 *)ptr, opts->addr6.s6_addr, 16); |
| 1163 | ptr += 4; |
| 1164 | } |
| 1165 | #endif |
Geliang Tang | 22fb85f | 2020-12-09 15:51:20 -0800 | [diff] [blame] | 1166 | |
| 1167 | if (!opts->port) { |
| 1168 | if (opts->ahmac) { |
| 1169 | put_unaligned_be64(opts->ahmac, ptr); |
| 1170 | ptr += 2; |
| 1171 | } |
| 1172 | } else { |
| 1173 | if (opts->ahmac) { |
| 1174 | u8 *bptr = (u8 *)ptr; |
| 1175 | |
| 1176 | put_unaligned_be16(opts->port, bptr); |
| 1177 | bptr += 2; |
| 1178 | put_unaligned_be64(opts->ahmac, bptr); |
| 1179 | bptr += 8; |
| 1180 | put_unaligned_be16(TCPOPT_NOP << 8 | |
| 1181 | TCPOPT_NOP, bptr); |
| 1182 | |
| 1183 | ptr += 3; |
| 1184 | } else { |
| 1185 | put_unaligned_be32(opts->port << 16 | |
| 1186 | TCPOPT_NOP << 8 | |
| 1187 | TCPOPT_NOP, ptr); |
| 1188 | ptr += 1; |
| 1189 | } |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (OPTION_MPTCP_RM_ADDR & opts->suboptions) { |
| 1194 | *ptr++ = mptcp_option(MPTCPOPT_RM_ADDR, |
| 1195 | TCPOLEN_MPTCP_RM_ADDR_BASE, |
| 1196 | 0, opts->rm_id); |
| 1197 | } |
| 1198 | |
Geliang Tang | 0670654 | 2021-01-08 16:47:57 -0800 | [diff] [blame^] | 1199 | if (OPTION_MPTCP_PRIO & opts->suboptions) { |
| 1200 | const struct sock *ssk = (const struct sock *)tp; |
| 1201 | struct mptcp_subflow_context *subflow; |
| 1202 | |
| 1203 | subflow = mptcp_subflow_ctx(ssk); |
| 1204 | subflow->send_mp_prio = 0; |
| 1205 | |
| 1206 | *ptr++ = mptcp_option(MPTCPOPT_MP_PRIO, |
| 1207 | TCPOLEN_MPTCP_PRIO, |
| 1208 | opts->backup, TCPOPT_NOP); |
| 1209 | } |
| 1210 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 1211 | if (OPTION_MPTCP_MPJ_SYN & opts->suboptions) { |
| 1212 | *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN, |
| 1213 | TCPOLEN_MPTCP_MPJ_SYN, |
| 1214 | opts->backup, opts->join_id); |
| 1215 | put_unaligned_be32(opts->token, ptr); |
| 1216 | ptr += 1; |
| 1217 | put_unaligned_be32(opts->nonce, ptr); |
| 1218 | ptr += 1; |
| 1219 | } |
| 1220 | |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 1221 | if (OPTION_MPTCP_MPJ_SYNACK & opts->suboptions) { |
| 1222 | *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN, |
| 1223 | TCPOLEN_MPTCP_MPJ_SYNACK, |
| 1224 | opts->backup, opts->join_id); |
| 1225 | put_unaligned_be64(opts->thmac, ptr); |
| 1226 | ptr += 2; |
| 1227 | put_unaligned_be32(opts->nonce, ptr); |
| 1228 | ptr += 1; |
| 1229 | } |
| 1230 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 1231 | if (OPTION_MPTCP_MPJ_ACK & opts->suboptions) { |
| 1232 | *ptr++ = mptcp_option(MPTCPOPT_MP_JOIN, |
| 1233 | TCPOLEN_MPTCP_MPJ_ACK, 0, 0); |
| 1234 | memcpy(ptr, opts->hmac, MPTCPOPT_HMAC_LEN); |
| 1235 | ptr += 5; |
| 1236 | } |
| 1237 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 1238 | if (opts->ext_copy.use_ack || opts->ext_copy.use_map) { |
| 1239 | struct mptcp_ext *mpext = &opts->ext_copy; |
| 1240 | u8 len = TCPOLEN_MPTCP_DSS_BASE; |
| 1241 | u8 flags = 0; |
| 1242 | |
| 1243 | if (mpext->use_ack) { |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 1244 | flags = MPTCP_DSS_HAS_ACK; |
| 1245 | if (mpext->ack64) { |
| 1246 | len += TCPOLEN_MPTCP_DSS_ACK64; |
| 1247 | flags |= MPTCP_DSS_ACK64; |
| 1248 | } else { |
| 1249 | len += TCPOLEN_MPTCP_DSS_ACK32; |
| 1250 | } |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | if (mpext->use_map) { |
| 1254 | len += TCPOLEN_MPTCP_DSS_MAP64; |
| 1255 | |
| 1256 | /* Use only 64-bit mapping flags for now, add |
| 1257 | * support for optional 32-bit mappings later. |
| 1258 | */ |
| 1259 | flags |= MPTCP_DSS_HAS_MAP | MPTCP_DSS_DSN64; |
| 1260 | if (mpext->data_fin) |
| 1261 | flags |= MPTCP_DSS_DATA_FIN; |
| 1262 | } |
| 1263 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 1264 | *ptr++ = mptcp_option(MPTCPOPT_DSS, len, 0, flags); |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 1265 | |
| 1266 | if (mpext->use_ack) { |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 1267 | if (mpext->ack64) { |
| 1268 | put_unaligned_be64(mpext->data_ack, ptr); |
| 1269 | ptr += 2; |
| 1270 | } else { |
| 1271 | put_unaligned_be32(mpext->data_ack32, ptr); |
| 1272 | ptr += 1; |
| 1273 | } |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | if (mpext->use_map) { |
| 1277 | put_unaligned_be64(mpext->data_seq, ptr); |
| 1278 | ptr += 2; |
| 1279 | put_unaligned_be32(mpext->subflow_seq, ptr); |
| 1280 | ptr += 1; |
| 1281 | put_unaligned_be32(mpext->data_len << 16 | |
| 1282 | TCPOPT_NOP << 8 | TCPOPT_NOP, ptr); |
| 1283 | } |
| 1284 | } |
Florian Westphal | fa3fe2b | 2020-11-19 11:46:02 -0800 | [diff] [blame] | 1285 | |
| 1286 | if (tp) |
| 1287 | mptcp_set_rwin(tp); |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 1288 | } |