]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/mptcp.h
xnu-7195.60.75.tar.gz
[apple/xnu.git] / bsd / netinet / mptcp.h
CommitLineData
39236c6e 1/*
5ba3f43e 2 * Copyright (c) 2012-2017 Apple Inc. All rights reserved.
39236c6e
A
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
0a7de745
A
29#ifndef _NETINET_MPTCP_H_
30#define _NETINET_MPTCP_H_
39236c6e
A
31
32#ifdef BSD_KERNEL_PRIVATE
33
34#include <machine/endian.h>
35
5ba3f43e
A
36#include <libkern/crypto/sha1.h>
37
39236c6e 38#if BYTE_ORDER == BIG_ENDIAN
0a7de745
A
39#define mptcp_hton64(x) (x)
40#define mptcp_ntoh64(x) (x)
39236c6e 41#else /* LITTLE_ENDIAN */
0a7de745
A
42#define mptcp_hton64(x) __DARWIN_OSSwapInt64(x)
43#define mptcp_ntoh64(x) __DARWIN_OSSwapInt64(x)
39236c6e
A
44#endif
45
46/*
47 * MPTCP Option Subtype Field values
48 */
0a7de745
A
49#define MPO_CAPABLE 0x0
50#define MPO_JOIN 0x1
51#define MPO_DSS 0x2
52#define MPO_ADD_ADDR 0x3
53#define MPO_REMOVE_ADDR 0x4
54#define MPO_PRIO 0x5
55#define MPO_FAIL 0x6
56#define MPO_FASTCLOSE 0x7
39236c6e
A
57
58/* MPTCP Protocol version */
0a7de745 59#define MPTCP_STD_VERSION_0 0x0
39236c6e
A
60
61/*
62 * MPTCP MP_CAPABLE TCP Option definitions
63 *
64 * Used to establish an MPTCP connection and first subflow.
65 */
66struct mptcp_mpcapable_opt_common {
cb323159
A
67 uint8_t mmco_kind;
68 uint8_t mmco_len;
39236c6e 69#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 70 uint8_t mmco_version:4,
0a7de745 71 mmco_subtype:4;
39236c6e 72#else /* BIG_ENDIAN */
cb323159 73 uint8_t mmco_subtype:4,
0a7de745 74 mmco_version:4;
39236c6e 75#endif
0a7de745
A
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 */
cb323159 82#define MPCAP_UNICAST_IPBIT 0x20 /* Should MPTCP only use ADD_ADDR IPs for new subflows */
0a7de745 83#define MPCAP_BBIT 0x40 /* Extensibility bit, must be 0 */
0a7de745 84#define MPCAP_CHECKSUM_CBIT 0x80 /* DSS Checksum bit */
cb323159 85 uint8_t mmco_flags;
39236c6e
A
86} __attribute__((__packed__));
87
88struct mptcp_mpcapable_opt_rsp {
89 struct mptcp_mpcapable_opt_common mmc_common;
90 mptcp_key_t mmc_localkey;
91} __attribute__((__packed__));
92
93struct 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__));
98
99/*
100 * MPTCP MP_JOIN TCP Option definitions
101 *
102 * Used to add subflows to an existing MP_CAPABLE connection.
103 */
104
105/* MP_JOIN Option for SYN */
106struct mptcp_mpjoin_opt_req {
cb323159
A
107 uint8_t mmjo_kind;
108 uint8_t mmjo_len;
0a7de745 109#define MPTCP_BACKUP 0x1
cb323159
A
110 uint8_t mmjo_subtype_bkp;
111 uint8_t mmjo_addr_id;
112 uint32_t mmjo_peer_token;
113 uint32_t mmjo_rand;
39236c6e
A
114} __attribute__((__packed__));
115
116/* MP_JOIN Option for SYN/ACK */
117struct mptcp_mpjoin_opt_rsp {
cb323159
A
118 uint8_t mmjo_kind;
119 uint8_t mmjo_len;
0a7de745 120#define MPTCP_BACKUP 0x1
cb323159
A
121 uint8_t mmjo_subtype_bkp;
122 uint8_t mmjo_addr_id;
123 uint64_t mmjo_mac; /* Truncated message auth code */
124 uint32_t mmjo_rand;
39236c6e
A
125} __attribute__((__packed__));
126
127/* MP_Join Option for ACK */
128struct mptcp_mpjoin_opt_rsp2 {
cb323159
A
129 uint8_t mmjo_kind;
130 uint8_t mmjo_len;
39236c6e 131#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 132 uint8_t mmjo_reserved1:4,
0a7de745 133 mmjo_subtype:4;
39236c6e 134#else /* BIG_ENDIAN */
cb323159 135 uint8_t mmjo_subtype:4,
0a7de745 136 mmjo_reserved1:4;
39236c6e 137#endif
cb323159
A
138 uint8_t mmjo_reserved2;
139 uint8_t mmjo_mac[SHA1_RESULTLEN]; /* This is 160 bits HMAC SHA-1 per RFC */
39236c6e
A
140} __attribute__((__packed__));
141
142/* Remove Address Option */
143struct mptcp_remaddr_opt {
cb323159
A
144 uint8_t mr_kind;
145 uint8_t mr_len;
39236c6e 146#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 147 uint8_t mr_rest:4,
0a7de745 148 mr_subtype:4;
39236c6e 149#else /* BIG_ENDIAN */
cb323159 150 uint8_t mr_subtype:4,
0a7de745 151 mr_rest:4;
39236c6e 152#endif
cb323159 153 uint8_t mr_addr_id;
39236c6e
A
154} __attribute__((__packed__));
155
156/*
157 * MPTCP Data Sequence Signal (DSS) TCP Options
158 *
159 * Used to map subflow sequence space to MPTCP data sequence space.
160 * Used to send Data ACKs
161 */
162
163/*
164 * DSS Option variants coded as flags in the DSS option flags field
165 */
0a7de745
A
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 */
39236c6e
A
171
172/* DSS fields common to all DSS option variants */
173struct mptcp_dss_copt {
cb323159
A
174 uint8_t mdss_kind;
175 uint8_t mdss_len;
39236c6e 176#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 177 uint8_t mdss_reserved1:4,
0a7de745 178 mdss_subtype:4;
39236c6e 179#else /* BIG_ENDIAN */
cb323159 180 uint8_t mdss_subtype:4,
0a7de745 181 mdss_reserved1:4;
39236c6e 182#endif
cb323159 183 uint8_t mdss_flags;
39236c6e
A
184}__attribute__((__packed__));
185
186/* 32-bit DSS option */
187struct mptcp_dsn_opt {
0a7de745 188 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
193}__attribute__((__packed__));
194
195/* 64-bit DSS option */
196struct mptcp_dsn64_opt {
197 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
202}__attribute__((__packed__));
203
204/* 32-bit DSS Data ACK option */
205struct mptcp_data_ack_opt {
206 struct mptcp_dss_copt mdss_copt;
cb323159 207 uint32_t mdss_ack;
39236c6e
A
208}__attribute__((__packed__));
209
210/* 64-bit DSS Data ACK option */
211struct mptcp_data_ack64_opt {
212 struct mptcp_dss_copt mdss_copt;
cb323159 213 uint64_t mdss_ack;
39236c6e
A
214}__attribute__((__packed__));
215
216/* 32-bit DSS+Data ACK option */
217struct mptcp_dss_ack_opt {
218 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
224}__attribute__((__packed__));
225
226/* 64-bit DSS+Data ACK option */
227struct mptcp_dss64_ack64_opt {
228 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
234}__attribute__((__packed__));
235
236/* DSS+Data ACK mixed option variants */
237struct mptcp_dss32_ack64_opt {
238 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
244}__attribute__((__packed__));
245
246struct mptcp_dss64_ack32_opt {
247 struct mptcp_dss_copt mdss_copt;
cb323159
A
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 */
39236c6e
A
253}__attribute__((__packed__));
254
255
256/*
257 * MPTCP Fast Close Option
258 *
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
261 * API is supported.
262 */
263struct mptcp_fastclose_opt {
cb323159
A
264 uint8_t mfast_kind;
265 uint8_t mfast_len;
39236c6e 266#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 267 uint8_t mfast_reserved:4,
0a7de745 268 mfast_subtype:4;
39236c6e 269#else /* BIG_ENDIAN */
cb323159 270 uint8_t mfast_subtype:4,
0a7de745 271 mfast_reserved:4;
39236c6e 272#endif
cb323159
A
273 uint8_t mfast_reserved1;
274 uint64_t mfast_key; /* Option receiver's key */
39236c6e
A
275}__attribute__((__packed__));
276
277/*
278 * MPTCP MP_FAIL Option
279 *
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
282 * option.
283 */
284struct mptcp_mpfail_opt {
cb323159
A
285 uint8_t mfail_kind;
286 uint8_t mfail_len;
39236c6e 287#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 288 uint8_t mfail_reserved:4,
0a7de745 289 mfail_subtype:4;
39236c6e 290#else /* BIG_ENDIAN */
cb323159 291 uint8_t mfail_subtype:4,
0a7de745 292 mfail_reserved:4;
39236c6e 293#endif
cb323159
A
294 uint8_t mfail_reserved1:8;
295 uint64_t mfail_dsn;
296}__attribute__((__packed__));
297
298struct mptcp_add_addr_opt {
299 uint8_t maddr_kind;
300 uint8_t maddr_len;
301#if BYTE_ORDER == LITTLE_ENDIAN
302 uint8_t maddr_ipversion:4,
303 maddr_subtype:4;
304#else /* BIG_ENDIAN */
305 uint8_t maddr_subtype:4,
306 maddr_ipversion:4;
307#endif
308 uint8_t maddr_addrid;
309 union {
310 struct {
311 struct in_addr maddr_addrv4;
312 uint32_t maddr_pad[3];
313 };
314
315 struct {
316 struct in6_addr maddr_addrv6;
317 };
318 } maddr_u;
39236c6e
A
319}__attribute__((__packed__));
320
cb323159
A
321#define MPTCP_ADD_ADDR_OPT_LEN_V4 8
322#define MPTCP_ADD_ADDR_OPT_LEN_V6 20
39236c6e
A
323
324/*
325 * MPTCP MP_PRIO Option
326 *
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.
330 */
331
332/* Option to change priority of self */
333struct mptcp_mpprio_opt {
cb323159
A
334 uint8_t mpprio_kind;
335 uint8_t mpprio_len;
0a7de745 336#define MPTCP_MPPRIO_BKP 0x1
39236c6e 337#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 338 uint8_t mpprio_flags:4,
0a7de745 339 mpprio_subtype:4;
39236c6e 340#else /* BIG_ENDIAN */
cb323159 341 uint8_t mpprio_subtype:4,
0a7de745 342 mpprio_flags:4;
39236c6e
A
343#endif
344}__attribute__((__packed__));
345
346/* Option to change priority of some other subflow(s) using addr_id */
347struct mptcp_mpprio_addr_opt {
cb323159
A
348 uint8_t mpprio_kind;
349 uint8_t mpprio_len;
0a7de745 350#define MPTCP_MPPRIO_BKP 0x1
39236c6e 351#if BYTE_ORDER == LITTLE_ENDIAN
cb323159 352 uint8_t mpprio_flags:4,
0a7de745 353 mpprio_subtype:4;
39236c6e 354#else /* BIG_ENDIAN */
cb323159 355 uint8_t mpprio_subtype:4,
0a7de745 356 mpprio_flags:4;
39236c6e 357#endif
cb323159 358 uint8_t mpprio_addrid;
39236c6e
A
359}__attribute__((__packed__));
360
361/*
362 * MPTCP Checksum Psuedo Header
363 *
364 */
365struct mptcp_pseudohdr {
cb323159
A
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 */
39236c6e
A
370}__attribute__((__packed__));
371
372#endif /* BSD_KERNEL_PRIVATE */
373
374#endif /* _NETINET_MPTCP_H_ */