]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/mptcp.h
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / netinet / mptcp.h
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
46 /*
47 * MPTCP Option Subtype Field values
48 */
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
57
58 /* MPTCP Protocol version */
59 #define MPTCP_STD_VERSION_0 0x0
60
61 /*
62 * MPTCP MP_CAPABLE TCP Option definitions
63 *
64 * Used to establish an MPTCP connection and first subflow.
65 */
66 struct mptcp_mpcapable_opt_common {
67 uint8_t mmco_kind;
68 uint8_t mmco_len;
69 #if BYTE_ORDER == LITTLE_ENDIAN
70 uint8_t mmco_version:4,
71 mmco_subtype:4;
72 #else /* BIG_ENDIAN */
73 uint8_t mmco_subtype:4,
74 mmco_version:4;
75 #endif
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 */
85 uint8_t mmco_flags;
86 } __attribute__((__packed__));
87
88 struct mptcp_mpcapable_opt_rsp {
89 struct mptcp_mpcapable_opt_common mmc_common;
90 mptcp_key_t mmc_localkey;
91 } __attribute__((__packed__));
92
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__));
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 */
106 struct mptcp_mpjoin_opt_req {
107 uint8_t mmjo_kind;
108 uint8_t mmjo_len;
109 #define MPTCP_BACKUP 0x1
110 uint8_t mmjo_subtype_bkp;
111 uint8_t mmjo_addr_id;
112 uint32_t mmjo_peer_token;
113 uint32_t mmjo_rand;
114 } __attribute__((__packed__));
115
116 /* MP_JOIN Option for SYN/ACK */
117 struct mptcp_mpjoin_opt_rsp {
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 uint64_t mmjo_mac; /* Truncated message auth code */
124 uint32_t mmjo_rand;
125 } __attribute__((__packed__));
126
127 /* MP_Join Option for ACK */
128 struct mptcp_mpjoin_opt_rsp2 {
129 uint8_t mmjo_kind;
130 uint8_t mmjo_len;
131 #if BYTE_ORDER == LITTLE_ENDIAN
132 uint8_t mmjo_reserved1:4,
133 mmjo_subtype:4;
134 #else /* BIG_ENDIAN */
135 uint8_t mmjo_subtype:4,
136 mmjo_reserved1:4;
137 #endif
138 uint8_t mmjo_reserved2;
139 uint8_t mmjo_mac[SHA1_RESULTLEN]; /* This is 160 bits HMAC SHA-1 per RFC */
140 } __attribute__((__packed__));
141
142 /* Remove Address Option */
143 struct mptcp_remaddr_opt {
144 uint8_t mr_kind;
145 uint8_t mr_len;
146 #if BYTE_ORDER == LITTLE_ENDIAN
147 uint8_t mr_rest:4,
148 mr_subtype:4;
149 #else /* BIG_ENDIAN */
150 uint8_t mr_subtype:4,
151 mr_rest:4;
152 #endif
153 uint8_t mr_addr_id;
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 */
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 */
171
172 /* DSS fields common to all DSS option variants */
173 struct mptcp_dss_copt {
174 uint8_t mdss_kind;
175 uint8_t mdss_len;
176 #if BYTE_ORDER == LITTLE_ENDIAN
177 uint8_t mdss_reserved1:4,
178 mdss_subtype:4;
179 #else /* BIG_ENDIAN */
180 uint8_t mdss_subtype:4,
181 mdss_reserved1:4;
182 #endif
183 uint8_t mdss_flags;
184 }__attribute__((__packed__));
185
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__));
194
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__));
203
204 /* 32-bit DSS Data ACK option */
205 struct mptcp_data_ack_opt {
206 struct mptcp_dss_copt mdss_copt;
207 uint32_t mdss_ack;
208 }__attribute__((__packed__));
209
210 /* 64-bit DSS Data ACK option */
211 struct mptcp_data_ack64_opt {
212 struct mptcp_dss_copt mdss_copt;
213 uint64_t mdss_ack;
214 }__attribute__((__packed__));
215
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__));
225
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__));
235
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__));
245
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__));
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 */
263 struct mptcp_fastclose_opt {
264 uint8_t mfast_kind;
265 uint8_t mfast_len;
266 #if BYTE_ORDER == LITTLE_ENDIAN
267 uint8_t mfast_reserved:4,
268 mfast_subtype:4;
269 #else /* BIG_ENDIAN */
270 uint8_t mfast_subtype:4,
271 mfast_reserved:4;
272 #endif
273 uint8_t mfast_reserved1;
274 uint64_t mfast_key; /* Option receiver's key */
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 */
284 struct mptcp_mpfail_opt {
285 uint8_t mfail_kind;
286 uint8_t mfail_len;
287 #if BYTE_ORDER == LITTLE_ENDIAN
288 uint8_t mfail_reserved:4,
289 mfail_subtype:4;
290 #else /* BIG_ENDIAN */
291 uint8_t mfail_subtype:4,
292 mfail_reserved:4;
293 #endif
294 uint8_t mfail_reserved1:8;
295 uint64_t mfail_dsn;
296 }__attribute__((__packed__));
297
298 struct 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;
319 }__attribute__((__packed__));
320
321 #define MPTCP_ADD_ADDR_OPT_LEN_V4 8
322 #define MPTCP_ADD_ADDR_OPT_LEN_V6 20
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 */
333 struct mptcp_mpprio_opt {
334 uint8_t mpprio_kind;
335 uint8_t mpprio_len;
336 #define MPTCP_MPPRIO_BKP 0x1
337 #if BYTE_ORDER == LITTLE_ENDIAN
338 uint8_t mpprio_flags:4,
339 mpprio_subtype:4;
340 #else /* BIG_ENDIAN */
341 uint8_t mpprio_subtype:4,
342 mpprio_flags:4;
343 #endif
344 }__attribute__((__packed__));
345
346 /* Option to change priority of some other subflow(s) using addr_id */
347 struct mptcp_mpprio_addr_opt {
348 uint8_t mpprio_kind;
349 uint8_t mpprio_len;
350 #define MPTCP_MPPRIO_BKP 0x1
351 #if BYTE_ORDER == LITTLE_ENDIAN
352 uint8_t mpprio_flags:4,
353 mpprio_subtype:4;
354 #else /* BIG_ENDIAN */
355 uint8_t mpprio_subtype:4,
356 mpprio_flags:4;
357 #endif
358 uint8_t mpprio_addrid;
359 }__attribute__((__packed__));
360
361 /*
362 * MPTCP Checksum Psuedo Header
363 *
364 */
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__));
371
372 #endif /* BSD_KERNEL_PRIVATE */
373
374 #endif /* _NETINET_MPTCP_H_ */