1 /* 2 * Copyright (c) 2012-2017 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef _NETINET_MPTCP_H_ 30 #define _NETINET_MPTCP_H_ 31 32 #ifdef BSD_KERNEL_PRIVATE 33 34 #include <machine/endian.h> 35 36 #include <libkern/crypto/sha1.h> 37 38 #if BYTE_ORDER == BIG_ENDIAN 39 #define mptcp_hton64(x) (x) 40 #define mptcp_ntoh64(x) (x) 41 #else /* LITTLE_ENDIAN */ 42 #define mptcp_hton64(x) __DARWIN_OSSwapInt64(x) 43 #define mptcp_ntoh64(x) __DARWIN_OSSwapInt64(x) 44 #endif 45 #include <netinet/mptcp_var.h> 46 47 /* Preferred MPTCP version to use when version discovery info is incomplete */ 48 extern int mptcp_preferred_version; 49 50 /* 51 * MPTCP Option Subtype Field values 52 */ 53 #define MPO_CAPABLE 0x0 54 #define MPO_JOIN 0x1 55 #define MPO_DSS 0x2 56 #define MPO_ADD_ADDR 0x3 57 #define MPO_REMOVE_ADDR 0x4 58 #define MPO_PRIO 0x5 59 #define MPO_FAIL 0x6 60 #define MPO_FASTCLOSE 0x7 61 62 /* MPTCP Protocol version */ 63 #define MPTCP_VERSION_0 0x0 64 #define MPTCP_VERSION_1 0x1 65 66 /* 67 * MPTCP MP_CAPABLE TCP Option definitions 68 * 69 * Used to establish an MPTCP connection and first subflow. 70 */ 71 struct mptcp_mpcapable_opt_common { 72 uint8_t mmco_kind; 73 uint8_t mmco_len; 74 #if BYTE_ORDER == LITTLE_ENDIAN 75 uint8_t mmco_version:4, 76 mmco_subtype:4; 77 #else /* BIG_ENDIAN */ 78 uint8_t mmco_subtype:4, 79 mmco_version:4; 80 #endif 81 #define MPCAP_PROPOSAL_SBIT 0x01 /* SHA1 (v0) or SHA256 (v1) Algorithm */ 82 #define MPCAP_HBIT 0x01 /* alias of MPCAP_PROPOSAL_SBIT */ 83 #define MPCAP_GBIT 0x02 /* must be 0 */ 84 #define MPCAP_FBIT 0x04 /* must be 0 */ 85 #define MPCAP_EBIT 0x08 /* must be 0 */ 86 #define MPCAP_DBIT 0x10 /* must be 0 */ 87 #define MPCAP_UNICAST_IPBIT 0x20 /* Should MPTCP only use ADD_ADDR IPs for new subflows */ 88 #define MPCAP_BBIT 0x40 /* Extensibility bit, must be 0 */ 89 #define MPCAP_CHECKSUM_CBIT 0x80 /* DSS Checksum bit */ 90 uint8_t mmco_flags; 91 } __attribute__((__packed__)); 92 93 struct mptcp_mpcapable_opt_rsp { 94 struct mptcp_mpcapable_opt_common mmc_common; 95 mptcp_key_t mmc_localkey; 96 } __attribute__((__packed__)); 97 98 struct mptcp_mpcapable_opt_rsp1 { 99 struct mptcp_mpcapable_opt_common mmc_common; 100 mptcp_key_t mmc_localkey; 101 mptcp_key_t mmc_remotekey; 102 } __attribute__((__packed__)); 103 104 struct mptcp_mpcapable_opt_rsp2 { 105 struct mptcp_mpcapable_opt_rsp1 mmc_rsp1; 106 uint16_t data_len; 107 uint16_t csum; 108 } __attribute__((__packed__)); 109 110 /* 111 * MPTCP MP_JOIN TCP Option definitions 112 * 113 * Used to add subflows to an existing MP_CAPABLE connection. 114 */ 115 116 /* MP_JOIN Option for SYN */ 117 struct mptcp_mpjoin_opt_req { 118 uint8_t mmjo_kind; 119 uint8_t mmjo_len; 120 #define MPTCP_BACKUP 0x1 121 uint8_t mmjo_subtype_bkp; 122 uint8_t mmjo_addr_id; 123 uint32_t mmjo_peer_token; 124 uint32_t mmjo_rand; 125 } __attribute__((__packed__)); 126 127 /* MP_JOIN Option for SYN/ACK */ 128 struct mptcp_mpjoin_opt_rsp { 129 uint8_t mmjo_kind; 130 uint8_t mmjo_len; 131 #define MPTCP_BACKUP 0x1 132 uint8_t mmjo_subtype_bkp; 133 uint8_t mmjo_addr_id; 134 uint64_t mmjo_mac; /* Truncated message auth code */ 135 uint32_t mmjo_rand; 136 } __attribute__((__packed__)); 137 138 /* MP_Join Option for ACK */ 139 struct mptcp_mpjoin_opt_rsp2 { 140 uint8_t mmjo_kind; 141 uint8_t mmjo_len; 142 #if BYTE_ORDER == LITTLE_ENDIAN 143 uint8_t mmjo_reserved1:4, 144 mmjo_subtype:4; 145 #else /* BIG_ENDIAN */ 146 uint8_t mmjo_subtype:4, 147 mmjo_reserved1:4; 148 #endif 149 uint8_t mmjo_reserved2; 150 uint8_t mmjo_mac[HMAC_TRUNCATED_ACK]; /* This is 160 bits HMAC per RFC */ 151 } __attribute__((__packed__)); 152 153 /* Remove Address Option */ 154 struct mptcp_remaddr_opt { 155 uint8_t mr_kind; 156 uint8_t mr_len; 157 #if BYTE_ORDER == LITTLE_ENDIAN 158 uint8_t mr_rest:4, 159 mr_subtype:4; 160 #else /* BIG_ENDIAN */ 161 uint8_t mr_subtype:4, 162 mr_rest:4; 163 #endif 164 uint8_t mr_addr_id; 165 } __attribute__((__packed__)); 166 167 /* 168 * MPTCP Data Sequence Signal (DSS) TCP Options 169 * 170 * Used to map subflow sequence space to MPTCP data sequence space. 171 * Used to send Data ACKs 172 */ 173 174 /* 175 * DSS Option variants coded as flags in the DSS option flags field 176 */ 177 #define MDSS_A 0x01 /* Data ACK present if set */ 178 #define MDSS_a 0x02 /* 64-bit Data ACK present if set */ 179 #define MDSS_M 0x04 /* Data Sequence Number present if set */ 180 #define MDSS_m 0x08 /* 64-bit Data Sequence Number present if set */ 181 #define MDSS_F 0x10 /* Data FIN present */ 182 183 /* DSS fields common to all DSS option variants */ 184 struct mptcp_dss_copt { 185 uint8_t mdss_kind; 186 uint8_t mdss_len; 187 #if BYTE_ORDER == LITTLE_ENDIAN 188 uint8_t mdss_reserved1:4, 189 mdss_subtype:4; 190 #else /* BIG_ENDIAN */ 191 uint8_t mdss_subtype:4, 192 mdss_reserved1:4; 193 #endif 194 uint8_t mdss_flags; 195 }__attribute__((__packed__)); 196 197 /* 32-bit DSS option */ 198 struct mptcp_dsn_opt { 199 struct mptcp_dss_copt mdss_copt; 200 uint32_t mdss_dsn; /* Data Sequence Number */ 201 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 202 uint16_t mdss_data_len; /* Data Length */ 203 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 204 }__attribute__((__packed__)); 205 206 /* 64-bit DSS option */ 207 struct mptcp_dsn64_opt { 208 struct mptcp_dss_copt mdss_copt; 209 uint64_t mdss_dsn; /* Data Sequence Number */ 210 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 211 uint16_t mdss_data_len; /* Data Length */ 212 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 213 }__attribute__((__packed__)); 214 215 /* 32-bit DSS Data ACK option */ 216 struct mptcp_data_ack_opt { 217 struct mptcp_dss_copt mdss_copt; 218 uint32_t mdss_ack; 219 }__attribute__((__packed__)); 220 221 /* 64-bit DSS Data ACK option */ 222 struct mptcp_data_ack64_opt { 223 struct mptcp_dss_copt mdss_copt; 224 uint64_t mdss_ack; 225 }__attribute__((__packed__)); 226 227 /* 32-bit DSS+Data ACK option */ 228 struct mptcp_dss_ack_opt { 229 struct mptcp_dss_copt mdss_copt; 230 uint32_t mdss_ack; /* Data ACK */ 231 uint32_t mdss_dsn; /* Data Sequence Number */ 232 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 233 uint16_t mdss_data_len; /* Data Length */ 234 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 235 }__attribute__((__packed__)); 236 237 /* 64-bit DSS+Data ACK option */ 238 struct mptcp_dss64_ack64_opt { 239 struct mptcp_dss_copt mdss_copt; 240 uint64_t mdss_ack; /* Data ACK */ 241 uint64_t mdss_dsn; /* Data Sequence Number */ 242 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 243 uint16_t mdss_data_len; /* Data Length */ 244 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 245 }__attribute__((__packed__)); 246 247 /* DSS+Data ACK mixed option variants */ 248 struct mptcp_dss32_ack64_opt { 249 struct mptcp_dss_copt mdss_copt; 250 uint64_t mdss_ack; /* Data ACK */ 251 uint32_t mdss_dsn; /* Data Sequence Number */ 252 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 253 uint16_t mdss_data_len; /* Data Length */ 254 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 255 }__attribute__((__packed__)); 256 257 struct mptcp_dss64_ack32_opt { 258 struct mptcp_dss_copt mdss_copt; 259 uint32_t mdss_ack; /* Data ACK */ 260 uint64_t mdss_dsn; /* Data Sequence Number */ 261 uint32_t mdss_subflow_seqn; /* Relative Subflow Seq Num */ 262 uint16_t mdss_data_len; /* Data Length */ 263 /* uint16_t mdss_xsum; */ /* Data checksum - optional */ 264 }__attribute__((__packed__)); 265 266 267 /* 268 * MPTCP Fast Close Option 269 * 270 * MPTCP connection is aborted if the FastClose option is received. 271 * In future, we may send this option if a MPTCP socket level abort 272 * API is supported. 273 */ 274 struct mptcp_fastclose_opt { 275 uint8_t mfast_kind; 276 uint8_t mfast_len; 277 #if BYTE_ORDER == LITTLE_ENDIAN 278 uint8_t mfast_reserved:4, 279 mfast_subtype:4; 280 #else /* BIG_ENDIAN */ 281 uint8_t mfast_subtype:4, 282 mfast_reserved:4; 283 #endif 284 uint8_t mfast_reserved1; 285 uint64_t mfast_key; /* Option receiver's key */ 286 }__attribute__((__packed__)); 287 288 /* 289 * MPTCP MP_FAIL Option 290 * 291 * When DSS checksum is ON, and checksum fails, remote peer may send 292 * this option to indicate the failure. Likewise, we may send this 293 * option. 294 */ 295 struct mptcp_mpfail_opt { 296 uint8_t mfail_kind; 297 uint8_t mfail_len; 298 #if BYTE_ORDER == LITTLE_ENDIAN 299 uint8_t mfail_reserved:4, 300 mfail_subtype:4; 301 #else /* BIG_ENDIAN */ 302 uint8_t mfail_subtype:4, 303 mfail_reserved:4; 304 #endif 305 uint8_t mfail_reserved1:8; 306 uint64_t mfail_dsn; 307 }__attribute__((__packed__)); 308 309 struct mptcp_add_addr_opt { 310 uint8_t maddr_kind; 311 uint8_t maddr_len; 312 #if BYTE_ORDER == LITTLE_ENDIAN 313 uint8_t maddr_flags:4, 314 maddr_subtype:4; 315 #else /* BIG_ENDIAN */ 316 uint8_t maddr_subtype:4, 317 maddr_flags:4; 318 #endif 319 uint8_t maddr_addrid; 320 union { 321 struct { 322 struct in_addr maddr_addrv4; 323 uint32_t maddr_pad[3]; 324 }; 325 326 struct { 327 struct in6_addr maddr_addrv6; 328 }; 329 } maddr_u; 330 }__attribute__((__packed__)); 331 332 struct mptcp_add_addr_hmac_msg_v4 { 333 uint8_t maddr_addrid; 334 struct in_addr maddr_addr; 335 uint16_t maddr_port; 336 }__attribute__((__packed__)); 337 338 struct mptcp_add_addr_hmac_msg_v6 { 339 uint8_t maddr_addrid; 340 struct in6_addr maddr_addr; 341 uint16_t maddr_port; 342 }__attribute__((__packed__)); 343 344 345 #define MPTCP_V0_ADD_ADDR_IPV4 4 346 #define MPTCP_V0_ADD_ADDR_IPV6 6 347 #define MPTCP_V1_ADD_ADDR_ECHO 0x1 348 349 #define MPTCP_V0_ADD_ADDR_OPT_LEN_V4 8 350 #define MPTCP_V0_ADD_ADDR_OPT_LEN_V6 20 351 #define MPTCP_V1_ADD_ADDR_OPT_LEN_V4 16 352 #define MPTCP_V1_ADD_ADDR_OPT_LEN_V6 28 353 #define MPTCP_V1_ADD_ADDR_ECHO_OPT_LEN_V4 8 354 #define MPTCP_V1_ADD_ADDR_ECHO_OPT_LEN_V6 20 355 /* 356 * MPTCP MP_PRIO Option 357 * 358 * When a subflow becomes unusable (due to bad radio coverage) or 359 * it is the costlier path or it is not the preferred path, the receiver may 360 * use this option to let the sender know of its path preference. 361 */ 362 363 /* Option to change priority of self */ 364 struct mptcp_mpprio_opt { 365 uint8_t mpprio_kind; 366 uint8_t mpprio_len; 367 #define MPTCP_MPPRIO_BKP 0x1 368 #if BYTE_ORDER == LITTLE_ENDIAN 369 uint8_t mpprio_flags:4, 370 mpprio_subtype:4; 371 #else /* BIG_ENDIAN */ 372 uint8_t mpprio_subtype:4, 373 mpprio_flags:4; 374 #endif 375 }__attribute__((__packed__)); 376 377 /* Option to change priority of some other subflow(s) using addr_id */ 378 struct mptcp_mpprio_addr_opt { 379 uint8_t mpprio_kind; 380 uint8_t mpprio_len; 381 #define MPTCP_MPPRIO_BKP 0x1 382 #if BYTE_ORDER == LITTLE_ENDIAN 383 uint8_t mpprio_flags:4, 384 mpprio_subtype:4; 385 #else /* BIG_ENDIAN */ 386 uint8_t mpprio_subtype:4, 387 mpprio_flags:4; 388 #endif 389 uint8_t mpprio_addrid; 390 }__attribute__((__packed__)); 391 392 /* 393 * MPTCP Checksum Psuedo Header 394 * 395 */ 396 struct mptcp_pseudohdr { 397 uint64_t mphdr_dsn; /* Data Sequence Number */ 398 uint32_t mphdr_ssn; /* Subflow Sequence Number */ 399 uint16_t mphdr_len; /* Data-Level Length */ 400 uint16_t mphdr_xsum; /* MPTCP Level Checksum */ 401 }__attribute__((__packed__)); 402 403 #endif /* BSD_KERNEL_PRIVATE */ 404 405 #endif /* _NETINET_MPTCP_H_ */ 406