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 u_int8_t mmco_version
:4,
72 #else /* BIG_ENDIAN */
73 u_int8_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_CBIT 0x20 /* must be 0 */
83 #define MPCAP_BBIT 0x40 /* Extensibility bit, must be 0 */
84 #define MPCAP_ABIT 0x80 /* alias of MPCAP_CHECKSUM_CBIT */
85 #define MPCAP_CHECKSUM_CBIT 0x80 /* DSS Checksum bit */
87 } __attribute__((__packed__
));
89 struct mptcp_mpcapable_opt_rsp
{
90 struct mptcp_mpcapable_opt_common mmc_common
;
91 mptcp_key_t mmc_localkey
;
92 } __attribute__((__packed__
));
94 struct mptcp_mpcapable_opt_rsp1
{
95 struct mptcp_mpcapable_opt_common mmc_common
;
96 mptcp_key_t mmc_localkey
;
97 mptcp_key_t mmc_remotekey
;
98 } __attribute__((__packed__
));
101 * MPTCP MP_JOIN TCP Option definitions
103 * Used to add subflows to an existing MP_CAPABLE connection.
106 /* MP_JOIN Option for SYN */
107 struct mptcp_mpjoin_opt_req
{
110 #define MPTCP_BACKUP 0x1
111 u_int8_t mmjo_subtype_bkp
;
112 u_int8_t mmjo_addr_id
;
113 u_int32_t mmjo_peer_token
;
115 } __attribute__((__packed__
));
117 /* MP_JOIN Option for SYN/ACK */
118 struct mptcp_mpjoin_opt_rsp
{
121 #define MPTCP_BACKUP 0x1
122 u_int8_t mmjo_subtype_bkp
;
123 u_int8_t mmjo_addr_id
;
124 u_int64_t mmjo_mac
; /* Truncated message auth code */
126 } __attribute__((__packed__
));
128 /* MP_Join Option for ACK */
129 struct mptcp_mpjoin_opt_rsp2
{
132 #if BYTE_ORDER == LITTLE_ENDIAN
133 u_int8_t mmjo_reserved1
:4,
135 #else /* BIG_ENDIAN */
136 u_int8_t mmjo_subtype
:4,
139 u_int8_t mmjo_reserved2
;
140 u_int8_t mmjo_mac
[SHA1_RESULTLEN
]; /* This is 160 bits HMAC SHA-1 per RFC */
141 } __attribute__((__packed__
));
145 * MPTCP ADD_ADDR and REMOVE_ADDR TCP Options
147 * ADD_ADDR option shall be ignored by this implementation
148 * REMOVE_ADDR option shall be sent to help flush dead subflows
151 /* Add Address Option */
152 struct mptcp_addaddr_opt
{
155 #if BYTE_ORDER == LITTLE_ENDIAN
158 #else /* BIG_ENDIAN */
159 u_int8_t ma_subtype
:4,
162 #define MA_IPVer_V4 4 /* IPv4 Address tagged to the option */
163 #define MA_IPVer_V6 6 /* IPv6 Address tagged to the option */
165 } __attribute__((__packed__
));
167 /* Address sent in the ADD_ADDR option */
168 struct mptcp_addr_family_val
{
170 struct in_addr ma_v4_addr
;
171 struct in6_addr ma_v6_addr
;
173 /* u_int16_t ma_ports; */ /* optional field */
174 } __attribute__((__packed__
));
176 /* Remove Address Option */
177 struct mptcp_remaddr_opt
{
180 #if BYTE_ORDER == LITTLE_ENDIAN
183 #else /* BIG_ENDIAN */
184 u_int8_t mr_subtype
:4,
188 } __attribute__((__packed__
));
191 * MPTCP Data Sequence Signal (DSS) TCP Options
193 * Used to map subflow sequence space to MPTCP data sequence space.
194 * Used to send Data ACKs
198 * DSS Option variants coded as flags in the DSS option flags field
200 #define MDSS_A 0x01 /* Data ACK present if set */
201 #define MDSS_a 0x02 /* 64-bit Data ACK present if set */
202 #define MDSS_M 0x04 /* Data Sequence Number present if set */
203 #define MDSS_m 0x08 /* 64-bit Data Sequence Number present if set */
204 #define MDSS_F 0x10 /* Data FIN present */
206 /* DSS fields common to all DSS option variants */
207 struct mptcp_dss_copt
{
210 #if BYTE_ORDER == LITTLE_ENDIAN
211 u_int8_t mdss_reserved1
:4,
213 #else /* BIG_ENDIAN */
214 u_int8_t mdss_subtype
:4,
218 }__attribute__((__packed__
));
220 /* 32-bit DSS option */
221 struct mptcp_dsn_opt
{
222 struct mptcp_dss_copt mdss_copt
;
223 u_int32_t mdss_dsn
; /* Data Sequence Number */
224 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
225 u_int16_t mdss_data_len
; /* Data Length */
226 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
228 }__attribute__((__packed__
));
230 /* 64-bit DSS option */
231 struct mptcp_dsn64_opt
{
232 struct mptcp_dss_copt mdss_copt
;
233 u_int64_t mdss_dsn
; /* Data Sequence Number */
234 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
235 u_int16_t mdss_data_len
; /* Data Length */
236 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
237 }__attribute__((__packed__
));
239 /* 32-bit DSS Data ACK option */
240 struct mptcp_data_ack_opt
{
241 struct mptcp_dss_copt mdss_copt
;
243 }__attribute__((__packed__
));
245 /* 64-bit DSS Data ACK option */
246 struct mptcp_data_ack64_opt
{
247 struct mptcp_dss_copt mdss_copt
;
249 }__attribute__((__packed__
));
251 /* 32-bit DSS+Data ACK option */
252 struct mptcp_dss_ack_opt
{
253 struct mptcp_dss_copt mdss_copt
;
254 u_int32_t mdss_ack
; /* Data ACK */
255 u_int32_t mdss_dsn
; /* Data Sequence Number */
256 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
257 u_int16_t mdss_data_len
; /* Data Length */
258 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
259 }__attribute__((__packed__
));
261 /* 64-bit DSS+Data ACK option */
262 struct mptcp_dss64_ack64_opt
{
263 struct mptcp_dss_copt mdss_copt
;
264 u_int64_t mdss_ack
; /* Data ACK */
265 u_int64_t mdss_dsn
; /* Data Sequence Number */
266 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
267 u_int16_t mdss_data_len
; /* Data Length */
268 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
269 }__attribute__((__packed__
));
271 /* DSS+Data ACK mixed option variants */
272 struct mptcp_dss32_ack64_opt
{
273 struct mptcp_dss_copt mdss_copt
;
274 u_int64_t mdss_ack
; /* Data ACK */
275 u_int32_t mdss_dsn
; /* Data Sequence Number */
276 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
277 u_int16_t mdss_data_len
; /* Data Length */
278 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
279 }__attribute__((__packed__
));
281 struct mptcp_dss64_ack32_opt
{
282 struct mptcp_dss_copt mdss_copt
;
283 u_int32_t mdss_ack
; /* Data ACK */
284 u_int64_t mdss_dsn
; /* Data Sequence Number */
285 u_int32_t mdss_subflow_seqn
; /* Relative Subflow Seq Num */
286 u_int16_t mdss_data_len
; /* Data Length */
287 /* u_int16_t mdss_xsum; */ /* Data checksum - optional */
288 }__attribute__((__packed__
));
292 * MPTCP Fast Close Option
294 * MPTCP connection is aborted if the FastClose option is received.
295 * In future, we may send this option if a MPTCP socket level abort
298 struct mptcp_fastclose_opt
{
301 #if BYTE_ORDER == LITTLE_ENDIAN
302 u_int8_t mfast_reserved
:4,
304 #else /* BIG_ENDIAN */
305 u_int8_t mfast_subtype
:4,
308 u_int8_t mfast_reserved1
;
309 u_int64_t mfast_key
; /* Option receiver's key */
310 }__attribute__((__packed__
));
313 * MPTCP MP_FAIL Option
315 * When DSS checksum is ON, and checksum fails, remote peer may send
316 * this option to indicate the failure. Likewise, we may send this
319 struct mptcp_mpfail_opt
{
322 #if BYTE_ORDER == LITTLE_ENDIAN
323 u_int8_t mfail_reserved
:4,
325 #else /* BIG_ENDIAN */
326 u_int8_t mfail_subtype
:4,
329 u_int8_t mfail_reserved1
:8;
331 }__attribute__((__packed__
));
335 * MPTCP MP_PRIO Option
337 * When a subflow becomes unusable (due to bad radio coverage) or
338 * it is the costlier path or it is not the preferred path, the receiver may
339 * use this option to let the sender know of its path preference.
342 /* Option to change priority of self */
343 struct mptcp_mpprio_opt
{
344 u_int8_t mpprio_kind
;
346 #define MPTCP_MPPRIO_BKP 0x1
347 #if BYTE_ORDER == LITTLE_ENDIAN
348 u_int8_t mpprio_flags
:4,
350 #else /* BIG_ENDIAN */
351 u_int8_t mpprio_subtype
:4,
354 }__attribute__((__packed__
));
356 /* Option to change priority of some other subflow(s) using addr_id */
357 struct mptcp_mpprio_addr_opt
{
358 u_int8_t mpprio_kind
;
360 #define MPTCP_MPPRIO_BKP 0x1
361 #if BYTE_ORDER == LITTLE_ENDIAN
362 u_int8_t mpprio_flags
:4,
364 #else /* BIG_ENDIAN */
365 u_int8_t mpprio_subtype
:4,
368 u_int8_t mpprio_addrid
;
369 }__attribute__((__packed__
));
372 * MPTCP Checksum Psuedo Header
375 struct mptcp_pseudohdr
{
376 u_int64_t mphdr_dsn
; /* Data Sequence Number */
377 u_int32_t mphdr_ssn
; /* Subflow Sequence Number */
378 u_int16_t mphdr_len
; /* Data-Level Length */
379 u_int16_t mphdr_xsum
; /* MPTCP Level Checksum */
380 }__attribute__((__packed__
));
382 #endif /* BSD_KERNEL_PRIVATE */
384 #endif /* _NETINET_MPTCP_H_ */