2 * Copyright (c) 2012-2017 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _NETINET_MPTCP_H_
30 #define _NETINET_MPTCP_H_
32 #ifdef BSD_KERNEL_PRIVATE
34 #include <machine/endian.h>
36 #include <libkern/crypto/sha1.h>
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)
47 * MPTCP Option Subtype Field values
49 #define MPO_CAPABLE 0x0
52 #define MPO_ADD_ADDR 0x3
53 #define MPO_REMOVE_ADDR 0x4
56 #define MPO_FASTCLOSE 0x7
58 /* MPTCP Protocol version */
59 #define MPTCP_STD_VERSION_0 0x0
62 * MPTCP MP_CAPABLE TCP Option definitions
64 * Used to establish an MPTCP connection and first subflow.
66 struct mptcp_mpcapable_opt_common
{
69 #if BYTE_ORDER == LITTLE_ENDIAN
70 uint8_t mmco_version
:4,
72 #else /* BIG_ENDIAN */
73 uint8_t mmco_subtype
:4,
76 #define MPCAP_PROPOSAL_SBIT 0x01 /* SHA1 Algorithm */
77 #define MPCAP_HBIT 0x01 /* alias of MPCAP_PROPOSAL_SBIT */
78 #define MPCAP_GBIT 0x02 /* must be 0 */
79 #define MPCAP_FBIT 0x04 /* must be 0 */
80 #define MPCAP_EBIT 0x08 /* must be 0 */
81 #define MPCAP_DBIT 0x10 /* must be 0 */
82 #define MPCAP_UNICAST_IPBIT 0x20 /* Should MPTCP only use ADD_ADDR IPs for new subflows */
83 #define MPCAP_BBIT 0x40 /* Extensibility bit, must be 0 */
84 #define MPCAP_CHECKSUM_CBIT 0x80 /* DSS Checksum bit */
86 } __attribute__((__packed__
));
88 struct mptcp_mpcapable_opt_rsp
{
89 struct mptcp_mpcapable_opt_common mmc_common
;
90 mptcp_key_t mmc_localkey
;
91 } __attribute__((__packed__
));
93 struct mptcp_mpcapable_opt_rsp1
{
94 struct mptcp_mpcapable_opt_common mmc_common
;
95 mptcp_key_t mmc_localkey
;
96 mptcp_key_t mmc_remotekey
;
97 } __attribute__((__packed__
));
100 * MPTCP MP_JOIN TCP Option definitions
102 * Used to add subflows to an existing MP_CAPABLE connection.
105 /* MP_JOIN Option for SYN */
106 struct mptcp_mpjoin_opt_req
{
109 #define MPTCP_BACKUP 0x1
110 uint8_t mmjo_subtype_bkp
;
111 uint8_t mmjo_addr_id
;
112 uint32_t mmjo_peer_token
;
114 } __attribute__((__packed__
));
116 /* MP_JOIN Option for SYN/ACK */
117 struct mptcp_mpjoin_opt_rsp
{
120 #define MPTCP_BACKUP 0x1
121 uint8_t mmjo_subtype_bkp
;
122 uint8_t mmjo_addr_id
;
123 uint64_t mmjo_mac
; /* Truncated message auth code */
125 } __attribute__((__packed__
));
127 /* MP_Join Option for ACK */
128 struct mptcp_mpjoin_opt_rsp2
{
131 #if BYTE_ORDER == LITTLE_ENDIAN
132 uint8_t mmjo_reserved1
:4,
134 #else /* BIG_ENDIAN */
135 uint8_t mmjo_subtype
:4,
138 uint8_t mmjo_reserved2
;
139 uint8_t mmjo_mac
[SHA1_RESULTLEN
]; /* This is 160 bits HMAC SHA-1 per RFC */
140 } __attribute__((__packed__
));
142 /* Remove Address Option */
143 struct mptcp_remaddr_opt
{
146 #if BYTE_ORDER == LITTLE_ENDIAN
149 #else /* BIG_ENDIAN */
150 uint8_t mr_subtype
:4,
154 } __attribute__((__packed__
));
157 * MPTCP Data Sequence Signal (DSS) TCP Options
159 * Used to map subflow sequence space to MPTCP data sequence space.
160 * Used to send Data ACKs
164 * DSS Option variants coded as flags in the DSS option flags field
166 #define MDSS_A 0x01 /* Data ACK present if set */
167 #define MDSS_a 0x02 /* 64-bit Data ACK present if set */
168 #define MDSS_M 0x04 /* Data Sequence Number present if set */
169 #define MDSS_m 0x08 /* 64-bit Data Sequence Number present if set */
170 #define MDSS_F 0x10 /* Data FIN present */
172 /* DSS fields common to all DSS option variants */
173 struct mptcp_dss_copt
{
176 #if BYTE_ORDER == LITTLE_ENDIAN
177 uint8_t mdss_reserved1
:4,
179 #else /* BIG_ENDIAN */
180 uint8_t mdss_subtype
:4,
184 }__attribute__((__packed__
));
186 /* 32-bit DSS option */
187 struct mptcp_dsn_opt
{
188 struct mptcp_dss_copt mdss_copt
;
189 uint32_t mdss_dsn
; /* Data Sequence Number */
190 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
191 uint16_t mdss_data_len
; /* Data Length */
192 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
193 }__attribute__((__packed__
));
195 /* 64-bit DSS option */
196 struct mptcp_dsn64_opt
{
197 struct mptcp_dss_copt mdss_copt
;
198 uint64_t mdss_dsn
; /* Data Sequence Number */
199 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
200 uint16_t mdss_data_len
; /* Data Length */
201 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
202 }__attribute__((__packed__
));
204 /* 32-bit DSS Data ACK option */
205 struct mptcp_data_ack_opt
{
206 struct mptcp_dss_copt mdss_copt
;
208 }__attribute__((__packed__
));
210 /* 64-bit DSS Data ACK option */
211 struct mptcp_data_ack64_opt
{
212 struct mptcp_dss_copt mdss_copt
;
214 }__attribute__((__packed__
));
216 /* 32-bit DSS+Data ACK option */
217 struct mptcp_dss_ack_opt
{
218 struct mptcp_dss_copt mdss_copt
;
219 uint32_t mdss_ack
; /* Data ACK */
220 uint32_t mdss_dsn
; /* Data Sequence Number */
221 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
222 uint16_t mdss_data_len
; /* Data Length */
223 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
224 }__attribute__((__packed__
));
226 /* 64-bit DSS+Data ACK option */
227 struct mptcp_dss64_ack64_opt
{
228 struct mptcp_dss_copt mdss_copt
;
229 uint64_t mdss_ack
; /* Data ACK */
230 uint64_t mdss_dsn
; /* Data Sequence Number */
231 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
232 uint16_t mdss_data_len
; /* Data Length */
233 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
234 }__attribute__((__packed__
));
236 /* DSS+Data ACK mixed option variants */
237 struct mptcp_dss32_ack64_opt
{
238 struct mptcp_dss_copt mdss_copt
;
239 uint64_t mdss_ack
; /* Data ACK */
240 uint32_t mdss_dsn
; /* Data Sequence Number */
241 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
242 uint16_t mdss_data_len
; /* Data Length */
243 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
244 }__attribute__((__packed__
));
246 struct mptcp_dss64_ack32_opt
{
247 struct mptcp_dss_copt mdss_copt
;
248 uint32_t mdss_ack
; /* Data ACK */
249 uint64_t mdss_dsn
; /* Data Sequence Number */
250 uint32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
251 uint16_t mdss_data_len
; /* Data Length */
252 /* uint16_t mdss_xsum; */ /* Data checksum - optional */
253 }__attribute__((__packed__
));
257 * MPTCP Fast Close Option
259 * MPTCP connection is aborted if the FastClose option is received.
260 * In future, we may send this option if a MPTCP socket level abort
263 struct mptcp_fastclose_opt
{
266 #if BYTE_ORDER == LITTLE_ENDIAN
267 uint8_t mfast_reserved
:4,
269 #else /* BIG_ENDIAN */
270 uint8_t mfast_subtype
:4,
273 uint8_t mfast_reserved1
;
274 uint64_t mfast_key
; /* Option receiver's key */
275 }__attribute__((__packed__
));
278 * MPTCP MP_FAIL Option
280 * When DSS checksum is ON, and checksum fails, remote peer may send
281 * this option to indicate the failure. Likewise, we may send this
284 struct mptcp_mpfail_opt
{
287 #if BYTE_ORDER == LITTLE_ENDIAN
288 uint8_t mfail_reserved
:4,
290 #else /* BIG_ENDIAN */
291 uint8_t mfail_subtype
:4,
294 uint8_t mfail_reserved1
:8;
296 }__attribute__((__packed__
));
298 struct mptcp_add_addr_opt
{
301 #if BYTE_ORDER == LITTLE_ENDIAN
302 uint8_t maddr_ipversion
:4,
304 #else /* BIG_ENDIAN */
305 uint8_t maddr_subtype
:4,
308 uint8_t maddr_addrid
;
311 struct in_addr maddr_addrv4
;
312 uint32_t maddr_pad
[3];
316 struct in6_addr maddr_addrv6
;
319 }__attribute__((__packed__
));
321 #define MPTCP_ADD_ADDR_OPT_LEN_V4 8
322 #define MPTCP_ADD_ADDR_OPT_LEN_V6 20
325 * MPTCP MP_PRIO Option
327 * When a subflow becomes unusable (due to bad radio coverage) or
328 * it is the costlier path or it is not the preferred path, the receiver may
329 * use this option to let the sender know of its path preference.
332 /* Option to change priority of self */
333 struct mptcp_mpprio_opt
{
336 #define MPTCP_MPPRIO_BKP 0x1
337 #if BYTE_ORDER == LITTLE_ENDIAN
338 uint8_t mpprio_flags
:4,
340 #else /* BIG_ENDIAN */
341 uint8_t mpprio_subtype
:4,
344 }__attribute__((__packed__
));
346 /* Option to change priority of some other subflow(s) using addr_id */
347 struct mptcp_mpprio_addr_opt
{
350 #define MPTCP_MPPRIO_BKP 0x1
351 #if BYTE_ORDER == LITTLE_ENDIAN
352 uint8_t mpprio_flags
:4,
354 #else /* BIG_ENDIAN */
355 uint8_t mpprio_subtype
:4,
358 uint8_t mpprio_addrid
;
359 }__attribute__((__packed__
));
362 * MPTCP Checksum Psuedo Header
365 struct mptcp_pseudohdr
{
366 uint64_t mphdr_dsn
; /* Data Sequence Number */
367 uint32_t mphdr_ssn
; /* Subflow Sequence Number */
368 uint16_t mphdr_len
; /* Data-Level Length */
369 uint16_t mphdr_xsum
; /* MPTCP Level Checksum */
370 }__attribute__((__packed__
));
372 #endif /* BSD_KERNEL_PRIVATE */
374 #endif /* _NETINET_MPTCP_H_ */