]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/mptcp_var.h
xnu-3247.1.106.tar.gz
[apple/xnu.git] / bsd / netinet / mptcp_var.h
CommitLineData
39236c6e 1/*
3e170ce0 2 * Copyright (c) 2012-2015 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
29#ifndef _NETINET_MPTCP_VAR_H_
30#define _NETINET_MPTCP_VAR_H_
31
32#ifdef PRIVATE
33#include <netinet/in.h>
34#include <netinet/tcp.h>
35#endif
36
37#ifdef BSD_KERNEL_PRIVATE
38#include <sys/queue.h>
39#include <sys/protosw.h>
40#include <kern/locks.h>
41#include <mach/boolean.h>
42#include <netinet/mp_pcb.h>
43
44/*
45 * MPTCP Session
46 *
47 * This is an extension to the multipath PCB specific for MPTCP, protected by
48 * the per-PCB mpp_lock (also the socket's lock); MPTCP thread signalling uses
49 * its own mpte_thread_lock due to lock ordering constraints.
50 */
51struct mptses {
52 struct mppcb *mpte_mppcb; /* back ptr to multipath PCB */
53 struct mptcb *mpte_mptcb; /* ptr to MPTCP PCB */
54 TAILQ_HEAD(, mptopt) mpte_sopts; /* list of socket options */
55 TAILQ_HEAD(, mptsub) mpte_subflows; /* list of subflows */
56 uint16_t mpte_numflows; /* # of subflows in list */
57 uint16_t mpte_nummpcapflows; /* # of MP_CAP subflows */
3e170ce0
A
58 sae_associd_t mpte_associd; /* MPTCP association ID */
59 sae_connid_t mpte_connid_last; /* last used connection ID */
39236c6e
A
60 /*
61 * Threading (protected by mpte_thread_lock)
62 */
63 decl_lck_mtx_data(, mpte_thread_lock); /* thread lock */
64 struct thread *mpte_thread; /* worker thread */
65 uint32_t mpte_thread_active; /* thread is running */
66 uint32_t mpte_thread_reqs; /* # of requests for thread */
67 struct mptsub *mpte_active_sub; /* ptr to last active subf */
a1c7dba1
A
68 uint8_t mpte_flags; /* per mptcp session flags */
69 uint8_t mpte_lost_aid; /* storing lost address id */
70 uint8_t mpte_addrid_last; /* storing address id parm */
39236c6e
A
71};
72
73/*
74 * Valid values for mpte_flags.
75 */
76#define MPTE_SND_REM_ADDR 0x01 /* Send Remove_addr option */
77
78#define mptompte(mp) ((struct mptses *)(mp)->mpp_pcbe)
79
80#define MPTE_LOCK_ASSERT_HELD(_mpte) \
81 lck_mtx_assert(&(_mpte)->mpte_mppcb->mpp_lock, LCK_MTX_ASSERT_OWNED)
82
83#define MPTE_LOCK_ASSERT_NOTHELD(_mpte) \
84 lck_mtx_assert(&(_mpte)->mpte_mppcb->mpp_lock, LCK_MTX_ASSERT_NOTOWNED)
85
86#define MPTE_LOCK(_mpte) \
87 lck_mtx_lock(&(_mpte)->mpte_mppcb->mpp_lock)
88
89#define MPTE_LOCK_SPIN(_mpte) \
90 lck_mtx_lock_spin(&(_mpte)->mpte_mppcb->mpp_lock)
91
92#define MPTE_CONVERT_LOCK(_mpte) do { \
93 MPTE_LOCK_ASSERT_HELD(_mpte); \
94 lck_mtx_convert_spin(&(_mpte)->mpte_mppcb->mpp_lock); \
95} while (0)
96
97#define MPTE_UNLOCK(_mpte) \
98 lck_mtx_unlock(&(_mpte)->mpte_mppcb->mpp_lock)
99
100/*
101 * MPTCP socket options
102 */
103struct mptopt {
104 TAILQ_ENTRY(mptopt) mpo_entry; /* glue to other options */
105 uint32_t mpo_flags; /* see flags below */
106 int mpo_level; /* sopt_level */
107 int mpo_name; /* sopt_name */
108 int mpo_intval; /* sopt_val */
109};
110
111#define MPOF_ATTACHED 0x1 /* attached to MP socket */
112#define MPOF_SUBFLOW_OK 0x2 /* can be issued on subflow socket */
113#define MPOF_INTERIM 0x4 /* has not been issued on any subflow */
114
115/*
116 * Structure passed down to TCP during subflow connection establishment
117 * containing information pertaining to the MPTCP.
118 */
119struct mptsub_connreq {
120 uint32_t mpcr_type; /* see MPTSUB_CONNREQ_* below */
121 uint32_t mpcr_ifscope; /* ifscope parameter to connectx(2) */
122 struct proc *mpcr_proc; /* process issuing connectx(2) */
123};
124
125/* valid values for mpcr_type */
126#define MPTSUB_CONNREQ_MP_ENABLE 1 /* enable MPTCP */
127#define MPTSUB_CONNREQ_MP_ADD 2 /* join an existing MPTCP */
128
129/*
130 * MPTCP subflow
131 *
132 * Protected by the the per-subflow mpts_lock. Note that mpts_flags
133 * and mpts_evctl are modified via atomic operations.
134 */
135struct mptsub {
136 decl_lck_mtx_data(, mpts_lock); /* per-subflow lock */
137 TAILQ_ENTRY(mptsub) mpts_entry; /* glue to peer subflows */
138 uint32_t mpts_refcnt; /* reference count */
139 uint32_t mpts_flags; /* see flags below */
140 uint32_t mpts_evctl; /* subflow control events */
141 uint32_t mpts_family; /* address family */
3e170ce0 142 sae_connid_t mpts_connid; /* subflow connection ID */
39236c6e
A
143 int mpts_oldintval; /* sopt_val before sosetopt */
144 uint32_t mpts_rank; /* subflow priority/rank */
145 int32_t mpts_soerror; /* most recent subflow error */
146 struct mptses *mpts_mpte; /* back ptr to MPTCP session */
147 struct socket *mpts_socket; /* subflow socket */
148 struct sockaddr_list *mpts_src_sl; /* source list */
149 struct sockaddr_list *mpts_dst_sl; /* destination list */
150 struct ifnet *mpts_outif; /* outbound interface */
151 u_int64_t mpts_sndnxt; /* next byte to send in mp so */
152 u_int32_t mpts_rel_seq; /* running count of subflow # */
39236c6e
A
153 struct protosw *mpts_oprotosw; /* original protosw */
154 struct mptsub_connreq mpts_mpcr; /* connection request */
3e170ce0
A
155 int32_t mpts_srtt; /* tcp's rtt estimate */
156 int32_t mpts_rxtcur; /* tcp's rto estimate */
157 uint32_t mpts_probesoon; /* send probe after probeto */
158 uint32_t mpts_probecnt; /* number of probes sent */
159 uint32_t mpts_maxseg; /* cached value of t_maxseg */
160 uint32_t mpts_peerswitch;/* no of uses of backup so */
161#define MPTSL_WIRED 0x01
162#define MPTSL_WIFI 0x02
163#define MPTSL_CELL 0x04
164 uint32_t mpts_linktype; /* wired, wifi, cell */
39236c6e
A
165};
166
167/*
168 * Valid values for mpts_flags. In particular:
169 *
170 * - MP_CAPABLE means that the connection is successfully established as
171 * MPTCP and data transfer may occur, but is not yet ready for multipath-
172 * related semantics until MP_READY. I.e. if this is on the first subflow,
173 * it causes the MPTCP socket to transition to a connected state, except
174 * that additional subflows will not be established; they will be marked
175 * with PENDING and will be processed when the first subflow is marked
176 * with MP_READY.
177 *
178 * - MP_READY implies that an MP_CAPABLE connection has been confirmed as
179 * an MPTCP connection. See notes above.
180 *
181 * - MP_DEGRADED implies that the connection has lost its MPTCP capabilities
182 * but data transfer on the MPTCP socket is unaffected. Any existing
183 * PENDING subflows will be disconnected, and further attempts to connect
184 * additional subflows will be rejected.
185 *
186 * Note that these are per-subflow flags. The setting and clearing of MP_READY
187 * reflects the state of the MPTCP connection with regards to its multipath
188 * semantics, via the MPTCPF_JOIN_READY flag. Until that flag is set (meaning
189 * until at least a subflow is marked with MP_READY), further connectx(2)
190 * attempts to join will be queued. When the flag is cleared (after it has
191 * been set), further connectx(2) will fail (and existing queued ones will be
192 * aborted) and the MPTCP connection loses all of its multipath semantics.
193 *
194 * Keep in sync with bsd/dev/dtrace/scripts/mptcp.d.
195 */
196#define MPTSF_ATTACHED 0x1 /* attached to MPTCP PCB */
197#define MPTSF_CONNECTING 0x2 /* connection was attempted */
198#define MPTSF_CONNECT_PENDING 0x4 /* will connect when MPTCP is ready */
199#define MPTSF_CONNECTED 0x8 /* connection is established */
200#define MPTSF_DISCONNECTING 0x10 /* disconnection was attempted */
201#define MPTSF_DISCONNECTED 0x20 /* has been disconnected */
202#define MPTSF_MP_CAPABLE 0x40 /* connected as a MPTCP subflow */
203#define MPTSF_MP_READY 0x80 /* MPTCP has been confirmed */
204#define MPTSF_MP_DEGRADED 0x100 /* has lost its MPTCP capabilities */
205#define MPTSF_SUSPENDED 0x200 /* write-side is flow controlled */
206#define MPTSF_BOUND_IF 0x400 /* subflow bound to an interface */
207#define MPTSF_BOUND_IP 0x800 /* subflow bound to a src address */
208#define MPTSF_BOUND_PORT 0x1000 /* subflow bound to a src port */
209#define MPTSF_PREFERRED 0x2000 /* primary/preferred subflow */
210#define MPTSF_SOPT_OLDVAL 0x4000 /* old option value is valid */
211#define MPTSF_SOPT_INPROG 0x8000 /* sosetopt in progress */
212#define MPTSF_DELETEOK 0x10000 /* subflow can be deleted */
213#define MPTSF_FAILINGOVER 0x20000 /* subflow not used for output */
214#define MPTSF_ACTIVE 0x40000 /* subflow currently in use */
215#define MPTSF_MPCAP_CTRSET 0x80000 /* mpcap counter */
fe8ab488
A
216#define MPTSF_FASTJ_SEND 0x100000 /* send data after SYN in MP_JOIN */
217#define MPTSF_FASTJ_REQD 0x200000 /* fastjoin required */
218#define MPTSF_USER_DISCONNECT 0x400000 /* User triggered disconnect */
39236c6e
A
219
220#define MPTSF_BITS \
221 "\020\1ATTACHED\2CONNECTING\3PENDING\4CONNECTED\5DISCONNECTING" \
222 "\6DISCONNECTED\7MP_CAPABLE\10MP_READY\11MP_DEGRADED\12SUSPENDED" \
223 "\13BOUND_IF\14BOUND_IP\15BOUND_PORT\16PREFERRED\17SOPT_OLDVAL" \
fe8ab488
A
224 "\20SOPT_INPROG\21NOLINGER\22FAILINGOVER\23ACTIVE\24MPCAP_CTRSET" \
225 "\25FASTJ_SEND\26FASTJ_REQD\27USER_DISCONNECT"
39236c6e
A
226
227#define MPTS_LOCK_ASSERT_HELD(_mpts) \
228 lck_mtx_assert(&(_mpts)->mpts_lock, LCK_MTX_ASSERT_OWNED)
229
230#define MPTS_LOCK_ASSERT_NOTHELD(_mpts) \
231 lck_mtx_assert(&(_mpts)->mpts_lock, LCK_MTX_ASSERT_NOTOWNED)
232
233#define MPTS_LOCK(_mpts) \
234 lck_mtx_lock(&(_mpts)->mpts_lock)
235
39236c6e
A
236#define MPTS_UNLOCK(_mpts) \
237 lck_mtx_unlock(&(_mpts)->mpts_lock)
238
239#define MPTS_ADDREF(_mpts) \
240 mptcp_subflow_addref(_mpts, 0)
241
242#define MPTS_ADDREF_LOCKED(_mpts) \
243 mptcp_subflow_addref(_mpts, 1)
244
245#define MPTS_REMREF(_mpts) \
246 mptcp_subflow_remref(_mpts)
247
248/*
249 * MPTCP states
250 * Keep in sync with bsd/dev/dtrace/mptcp.d
251 */
252typedef enum mptcp_state {
253 MPTCPS_CLOSED = 0, /* closed */
254 MPTCPS_LISTEN = 1, /* not yet implemented */
255 MPTCPS_ESTABLISHED = 2, /* MPTCP connection established */
256 MPTCPS_CLOSE_WAIT = 3, /* rcvd DFIN, waiting for close */
257 MPTCPS_FIN_WAIT_1 = 4, /* have closed, sent DFIN */
258 MPTCPS_CLOSING = 5, /* closed xchd DFIN, waiting DFIN ACK */
259 MPTCPS_LAST_ACK = 6, /* had DFIN and close; await DFIN ACK */
260 MPTCPS_FIN_WAIT_2 = 7, /* have closed, DFIN is acked */
261 MPTCPS_TIME_WAIT = 8, /* in 2*MSL quiet wait after close */
262 MPTCPS_FASTCLOSE_WAIT = 9, /* sent MP_FASTCLOSE */
fe8ab488 263 MPTCPS_TERMINATE = 10, /* terminal state */
39236c6e
A
264} mptcp_state_t;
265
266typedef u_int64_t mptcp_key_t;
267typedef u_int32_t mptcp_token_t;
268typedef u_int8_t mptcp_addr_id;
269
270
271/* Address ID list */
272struct mptcp_subf_auth_entry {
273 LIST_ENTRY(mptcp_subf_auth_entry) msae_next;
274 u_int32_t msae_laddr_rand; /* Local nonce */
275 u_int32_t msae_raddr_rand; /* Remote nonce */
276 mptcp_addr_id msae_laddr_id; /* Local addr ID */
277 mptcp_addr_id msae_raddr_id; /* Remote addr ID */
278};
279
280/*
281 * MPTCP Protocol Control Block
282 *
283 * Protected by per-MPTCP mpt_lock.
284 * Keep in sync with bsd/dev/dtrace/scripts/mptcp.d.
285 */
286struct mptcb {
287 decl_lck_mtx_data(, mpt_lock); /* per MPTCP PCB lock */
288 struct mptses *mpt_mpte; /* back ptr to MPTCP session */
289 mptcp_state_t mpt_state; /* MPTCP state */
290 u_int32_t mpt_flags; /* see flags below */
291 u_int32_t mpt_refcnt; /* references held on mptcb */
292 u_int32_t mpt_version; /* MPTCP proto version */
293 int mpt_softerror; /* error not yet reported */
294 /*
295 * Authentication and metadata invariants
296 */
297 mptcp_key_t *mpt_localkey; /* in network byte order */
298 mptcp_key_t mpt_remotekey; /* in network byte order */
299 mptcp_token_t mpt_localtoken; /* HMAC SHA1 of local key */
300 mptcp_token_t mpt_remotetoken; /* HMAC SHA1 of remote key */
301
302 /*
303 * Timer vars for scenarios where subflow level acks arrive, but
304 * Data ACKs do not.
305 */
306 int mpt_rxtshift; /* num of consecutive retrans */
307 u_int32_t mpt_rxtstart; /* time at which rxt started */
308 u_int64_t mpt_rtseq; /* seq # being tracked */
309 u_int32_t mpt_timer_vals; /* timer related values */
310 u_int32_t mpt_timewait; /* timewait */
311 /*
312 * Sending side
313 */
314 u_int64_t mpt_snduna; /* DSN of last unacked byte */
315 u_int64_t mpt_sndnxt; /* DSN of next byte to send */
316 u_int64_t mpt_sndmax; /* DSN of max byte sent */
317 u_int64_t mpt_local_idsn; /* First byte's DSN */
318 u_int32_t mpt_sndwnd;
319 /*
320 * Receiving side
321 */
322 u_int64_t mpt_rcvnxt; /* Next expected DSN */
323 u_int64_t mpt_rcvatmark; /* mpsocket marker of rcvnxt */
324 u_int64_t mpt_remote_idsn; /* Peer's IDSN */
325 u_int32_t mpt_rcvwnd;
326 LIST_HEAD(, mptcp_subf_auth_entry) mpt_subauth_list; /* address IDs */
327 /*
328 * Fastclose
329 */
330 u_int64_t mpt_dsn_at_csum_fail; /* MPFail Opt DSN */
fe8ab488 331 u_int32_t mpt_ssn_at_csum_fail; /* MPFail Subflow Seq */
39236c6e
A
332 /*
333 * Zombie handling
334 */
3e170ce0
A
335#define MPT_GC_TICKS (30)
336#define MPT_GC_TICKS_FAST (10)
39236c6e 337 int32_t mpt_gc_ticks; /* Used for zombie deletion */
fe8ab488
A
338
339 u_int32_t mpt_notsent_lowat; /* TCP_NOTSENT_LOWAT support */
3e170ce0 340 u_int32_t mpt_peer_version; /* Version from peer */
39236c6e
A
341};
342
343/* valid values for mpt_flags (see also notes on mpts_flags above) */
344#define MPTCPF_CHECKSUM 0x1 /* checksum DSS option */
345#define MPTCPF_FALLBACK_TO_TCP 0x2 /* Fallback to TCP */
346#define MPTCPF_JOIN_READY 0x4 /* Ready to start 2 or more subflows */
347#define MPTCPF_RECVD_MPFAIL 0x8 /* Received MP_FAIL option */
348#define MPTCPF_PEEL_OFF 0x10 /* Peel off this socket */
349#define MPTCPF_SND_64BITDSN 0x20 /* Send full 64-bit DSN */
350#define MPTCPF_SND_64BITACK 0x40 /* Send 64-bit ACK response */
351#define MPTCPF_RCVD_64BITACK 0x80 /* Received 64-bit Data ACK */
fe8ab488 352#define MPTCPF_POST_FALLBACK_SYNC 0x100 /* Post fallback resend data */
39236c6e
A
353
354#define MPTCPF_BITS \
355 "\020\1CHECKSUM\2FALLBACK_TO_TCP\3JOIN_READY\4RECVD_MPFAIL\5PEEL_OFF" \
fe8ab488 356 "\6SND_64BITDSN\7SND_64BITACK\10RCVD_64BITACK\11POST_FALLBACK_SYNC"
39236c6e
A
357
358/* valid values for mpt_timer_vals */
3e170ce0
A
359#define MPTT_REXMT 0x01 /* Starting Retransmit Timer */
360#define MPTT_TW 0x02 /* Starting Timewait Timer */
361#define MPTT_FASTCLOSE 0x04 /* Starting Fastclose wait timer */
362//#define MPTT_PROBE_TIMER 0x08 /* Timer for probing preferred path */
39236c6e
A
363
364#define MPT_LOCK_ASSERT_HELD(_mpt) \
365 lck_mtx_assert(&(_mpt)->mpt_lock, LCK_MTX_ASSERT_OWNED)
366
367#define MPT_LOCK_ASSERT_NOTHELD(_mpt) \
368 lck_mtx_assert(&(_mpt)->mpt_lock, LCK_MTX_ASSERT_NOTOWNED)
369
370#define MPT_LOCK(_mpt) \
371 lck_mtx_lock(&(_mpt)->mpt_lock)
372
373#define MPT_LOCK_SPIN(_mpt) \
374 lck_mtx_lock_spin(&(_mpt)->mpt_lock)
375
376#define MPT_CONVERT_LOCK(_mpt) do { \
377 MPT_LOCK_ASSERT_HELD(_mpt); \
378 lck_mtx_convert_spin(&(_mpt)->mpt_lock); \
379} while (0)
380
381#define MPT_UNLOCK(_mpt) \
382 lck_mtx_unlock(&(_mpt)->mpt_lock)
383
384/* events for close FSM */
385#define MPCE_CLOSE 0x1
386#define MPCE_RECV_DATA_ACK 0x2
387#define MPCE_RECV_DATA_FIN 0x4
388
389/* mptcb manipulation */
390#define tptomptp(tp) ((struct mptcb *)((tp)->t_mptcb))
391
392/*
393 * MPTCP control block and state structures are allocated along with
394 * the MP protocol control block; the folllowing represents the layout.
395 */
396struct mpp_mtp {
397 struct mppcb mpp; /* Multipath PCB */
398 struct mptses mpp_ses; /* MPTCP session */
399 struct mptcb mtcb; /* MPTCP PCB */
400};
401
402#ifdef SYSCTL_DECL
403SYSCTL_DECL(_net_inet_mptcp);
404#endif /* SYSCTL_DECL */
405
406extern struct mppcbinfo mtcbinfo;
407extern struct pr_usrreqs mptcp_usrreqs;
408
409/* Encryption algorithm related definitions */
410#define MPTCP_SHA1_RESULTLEN 20
411#define SHA1_TRUNCATED 8
412
413/* List of valid keys to use for MPTCP connections */
414#define MPTCP_KEY_DIGEST_LEN (MPTCP_SHA1_RESULTLEN)
415#define MPTCP_MX_KEY_ALLOCS (256)
416#define MPTCP_KEY_PREALLOCS_MX (16)
417#define MPTCP_MX_PREALLOC_ZONE_SZ (8192)
418
419struct mptcp_key_entry {
420 LIST_ENTRY(mptcp_key_entry) mkey_next;
421 mptcp_key_t mkey_value;
422#define MKEYF_FREE 0x0
423#define MKEYF_INUSE 0x1
424 u_int32_t mkey_flags;
425 char mkey_digest[MPTCP_KEY_DIGEST_LEN];
426};
427
428/* structure for managing unique key list */
429struct mptcp_keys_pool_head {
430 struct mptcp_key_entry *lh_first; /* list of keys */
431 u_int32_t mkph_count; /* total keys in pool */
432 vm_size_t mkph_key_elm_sz; /* size of key entry */
433 struct zone *mkph_key_entry_zone; /* zone for key entry */
434 decl_lck_mtx_data(, mkph_lock); /* lock for key list */
435};
436
437/* MPTCP Receive Window */
438#define MPTCP_RWIN_MAX (1<<16)
439
440/* MPTCP Debugging Levels */
3e170ce0
A
441#define MPTCP_LOGLVL_NONE 0x0 /* No debug logging */
442#define MPTCP_LOGLVL_ERR 0x1 /* Errors in execution are logged */
443#define MPTCP_LOGLVL_LOG 0x2 /* Important logs */
444#define MPTCP_LOGLVL_VERBOSE 0x3 /* Verbose logs */
445
446/* MPTCP sub-components for debug logging */
447#define MPTCP_NO_DBG 0x00 /* No areas are logged */
448#define MPTCP_STATE_DBG 0x01 /* State machine logging */
449#define MPTCP_SOCKET_DBG 0x02 /* Socket call logging */
450#define MPTCP_SENDER_DBG 0x04 /* Sender side logging */
451#define MPTCP_RECEIVER_DBG 0x08 /* Receiver logging */
452#define MPTCP_EVENTS_DBG 0x10 /* Subflow events logging */
453#define MPTCP_ALL_DBG (MPTCP_STATE_DBG | MPTCP_SOCKET_DBG | \
454 MPTCP_SENDER_DBG | MPTCP_RECEIVER_DBG | MPTCP_EVENTS_DBG)
39236c6e
A
455
456/* Mask to obtain 32-bit portion of data sequence number */
457#define MPTCP_DATASEQ_LOW32_MASK (0xffffffff)
458#define MPTCP_DATASEQ_LOW32(seq) (seq & MPTCP_DATASEQ_LOW32_MASK)
459
460/* Mask to obtain upper 32-bit portion of data sequence number */
461#define MPTCP_DATASEQ_HIGH32_MASK (0xffffffff00000000)
462#define MPTCP_DATASEQ_HIGH32(seq) (seq & MPTCP_DATASEQ_HIGH32_MASK)
463
464/* Mask to obtain 32-bit portion of data ack */
465#define MPTCP_DATAACK_LOW32_MASK (0xffffffff)
466#define MPTCP_DATAACK_LOW32(ack) (ack & MPTCP_DATAACK_LOW32_MASK)
467
468/* Mask to obtain upper 32-bit portion of data ack */
469#define MPTCP_DATAACK_HIGH32_MASK (0xffffffff00000000)
470#define MPTCP_DATAACK_HIGH32(ack) (ack & MPTCP_DATAACK_HIGH32_MASK)
471
472/*
473 * x is the 64-bit data sequence number, y the 32-bit data seq number to be
474 * extended. z is y extended to the appropriate 64-bit value.
475 * This algorithm is based on the fact that subflow level window sizes are
476 * at the maximum 2**30 (in reality, they are a lot lesser). A high throughput
477 * application sending on a large number of subflows can in theory have very
478 * large MPTCP level send and receive windows. In which case, 64 bit DSNs
479 * must be sent in place of 32 bit DSNs on wire. For us, with 2 subflows at
480 * 512K each, sequence wraparound detection can be done by checking whether
481 * the 32-bit value obtained on wire is 2**31 bytes apart from the stored
482 * lower 32-bits of the Data Sequence Number. Bogus DSNs are dropped by
483 * comparing against rwnd. Bogus DSNs within rwnd cannot be protected against
484 * and are as weak as bogus TCP sequence numbers.
485 */
486#define MPTCP_EXTEND_DSN(x, y, z) { \
487 if ((MPTCP_DATASEQ_LOW32(x) > y) && \
488 ((((u_int32_t)MPTCP_DATASEQ_LOW32(x)) - (u_int32_t)y) >= \
489 (u_int32_t)(1 << 31))) { \
490 /* \
491 * y wrapped around and x and y are 2**31 bytes apart \
492 */ \
493 z = MPTCP_DATASEQ_HIGH32(x) + 0x100000000; \
494 z |= y; \
495 } else if ((MPTCP_DATASEQ_LOW32(x) < y) && \
496 (((u_int32_t)y - \
497 ((u_int32_t)MPTCP_DATASEQ_LOW32(x))) >= \
498 (u_int32_t)(1 << 31))) { \
499 /* \
500 * x wrapped around and x and y are 2**31 apart \
501 */ \
502 z = MPTCP_DATASEQ_HIGH32(x) - 0x100000000; \
503 z |= y; \
504 } else { \
505 z = MPTCP_DATASEQ_HIGH32(x) | y; \
506 } \
507}
508
3e170ce0
A
509#define mptcplog(x, y, z) do { \
510 if ((mptcp_dbg_area & y) && \
511 (mptcp_dbg_level >= z)) \
512 log x; \
513} while (0)
39236c6e
A
514
515extern int mptcp_enable; /* Multipath TCP */
39236c6e
A
516extern int mptcp_mpcap_retries; /* Multipath TCP retries */
517extern int mptcp_join_retries; /* Multipath TCP Join retries */
518extern int mptcp_dss_csum; /* Multipath DSS Option checksum */
519extern int mptcp_fail_thresh; /* Multipath failover thresh of retransmits */
520extern int mptcp_subflow_keeptime; /* Multipath subflow TCP_KEEPALIVE opt */
521extern int mptcp_mpprio_enable; /* MP_PRIO option enable/disable */
522extern int mptcp_remaddr_enable;/* REMOVE_ADDR option enable/disable */
fe8ab488
A
523extern int mptcp_fastjoin; /* Enable FastJoin */
524extern int mptcp_zerortt_fastjoin; /* Enable Data after SYN Fast Join */
525extern int mptcp_rwnotify; /* Enable RW notification on resume */
3e170ce0
A
526extern uint32_t mptcp_dbg_level; /* Multipath TCP debugging level */
527extern uint32_t mptcp_dbg_area; /* Multipath TCP debugging area */
528
39236c6e
A
529#define MPPCB_LIMIT 16
530extern uint32_t mptcp_socket_limit; /* max number of mptcp sockets allowed */
fe8ab488 531extern uint32_t mptcp_delayed_subf_start; /* delayed cellular subflow start */
39236c6e
A
532extern int tcp_jack_rxmt; /* Join ACK retransmission value in msecs */
533
534__BEGIN_DECLS
535extern void mptcp_init(struct protosw *, struct domain *);
536extern int mptcp_ctloutput(struct socket *, struct sockopt *);
3e170ce0 537extern void *mptcp_sescreate(struct socket *, struct mppcb *);
39236c6e
A
538extern void mptcp_drain(void);
539extern struct mptses *mptcp_drop(struct mptses *, struct mptcb *, int);
540extern struct mptses *mptcp_close(struct mptses *, struct mptcb *);
541extern int mptcp_lock(struct socket *, int, void *);
542extern int mptcp_unlock(struct socket *, int, void *);
543extern lck_mtx_t *mptcp_getlock(struct socket *, int);
544extern void mptcp_thread_signal(struct mptses *);
545extern void mptcp_flush_sopts(struct mptses *);
3e170ce0
A
546extern int mptcp_setconnorder(struct mptses *, sae_connid_t, uint32_t);
547extern int mptcp_getconnorder(struct mptses *, sae_connid_t, uint32_t *);
39236c6e
A
548
549extern struct mptopt *mptcp_sopt_alloc(int);
550extern const char *mptcp_sopt2str(int, int, char *, int);
551extern void mptcp_sopt_free(struct mptopt *);
552extern void mptcp_sopt_insert(struct mptses *, struct mptopt *);
553extern void mptcp_sopt_remove(struct mptses *, struct mptopt *);
554extern struct mptopt *mptcp_sopt_find(struct mptses *, struct sockopt *);
555
556extern struct mptsub *mptcp_subflow_alloc(int);
557extern void mptcp_subflow_free(struct mptsub *);
558extern void mptcp_subflow_addref(struct mptsub *, int);
559extern int mptcp_subflow_add(struct mptses *, struct mptsub *,
560 struct proc *, uint32_t);
561extern void mptcp_subflow_del(struct mptses *, struct mptsub *, boolean_t);
562extern void mptcp_subflow_remref(struct mptsub *);
563extern int mptcp_subflow_output(struct mptses *, struct mptsub *);
564extern void mptcp_subflow_disconnect(struct mptses *, struct mptsub *,
565 boolean_t);
566extern void mptcp_subflow_sopeeloff(struct mptses *, struct mptsub *,
567 struct socket *);
568extern int mptcp_subflow_sosetopt(struct mptses *, struct socket *,
569 struct mptopt *);
570extern int mptcp_subflow_sogetopt(struct mptses *, struct socket *,
571 struct mptopt *);
572
573extern void mptcp_input(struct mptses *, struct mbuf *);
574extern int mptcp_output(struct mptses *);
575extern void mptcp_close_fsm(struct mptcb *, uint32_t);
576
577extern mptcp_token_t mptcp_get_localtoken(void *);
578extern mptcp_token_t mptcp_get_remotetoken(void *);
579
580extern u_int64_t mptcp_get_localkey(void *);
581extern u_int64_t mptcp_get_remotekey(void *);
582
583extern void mptcp_free_key(mptcp_key_t *key);
584extern void mptcp_hmac_sha1(mptcp_key_t, mptcp_key_t, u_int32_t, u_int32_t,
585 u_char*, int);
586extern void mptcp_get_hmac(mptcp_addr_id, struct mptcb *, u_char *, int);
587extern void mptcp_get_rands(mptcp_addr_id, struct mptcb *, u_int32_t *,
588 u_int32_t *);
589extern void mptcp_set_raddr_rand(mptcp_addr_id, struct mptcb *, mptcp_addr_id,
590 u_int32_t);
591extern u_int64_t mptcp_get_trunced_hmac(mptcp_addr_id, struct mptcb *mp_tp);
592extern int mptcp_generate_token(char *, int, caddr_t, int);
593extern int mptcp_generate_idsn(char *, int, caddr_t, int);
594extern boolean_t mptcp_ok_to_keepalive(struct mptcb *);
595extern void mptcp_insert_dsn(struct mppcb *, struct mbuf *);
596extern void mptcp_output_getm_dsnmap32(struct socket *, int, uint32_t,
597 u_int32_t *, u_int32_t *, u_int16_t *, u_int64_t *);
598extern void mptcp_output_getm_dsnmap64(struct socket *, int, uint32_t,
599 u_int64_t *, u_int32_t *, u_int16_t *);
600extern void mptcp_send_dfin(struct socket *);
601extern void mptcp_act_on_txfail(struct socket *);
3e170ce0
A
602extern struct mptsub *mptcp_get_subflow(struct mptses *, struct mptsub *,
603 struct mptsub **);
fe8ab488
A
604extern struct mptsub *mptcp_get_pending_subflow(struct mptses *,
605 struct mptsub *);
3e170ce0
A
606extern struct mptsub* mptcp_use_symptoms_hints(struct mptsub*,
607 struct mptsub *);
39236c6e
A
608extern int mptcp_get_map_for_dsn(struct socket *, u_int64_t, u_int32_t *);
609extern int32_t mptcp_adj_sendlen(struct socket *so, int32_t off, int32_t len);
610extern int32_t mptcp_sbspace(struct mptcb *);
611extern void mptcp_notify_mpready(struct socket *);
612extern void mptcp_notify_mpfail(struct socket *);
613extern void mptcp_notify_close(struct socket *);
fe8ab488
A
614extern boolean_t mptcp_no_rto_spike(struct socket*);
615extern int mptcp_set_notsent_lowat(struct mptses *mpte, int optval);
616extern u_int32_t mptcp_get_notsent_lowat(struct mptses *mpte);
617extern int mptcp_notsent_lowat_check(struct socket *so);
3e170ce0
A
618extern void mptcp_control_register(void);
619extern int mptcp_is_wifi_unusable(void);
620extern int mptcp_is_cell_unusable(void);
39236c6e
A
621__END_DECLS
622
623#endif /* BSD_KERNEL_PRIVATE */
624#ifdef PRIVATE
3e170ce0 625
39236c6e 626typedef struct mptcp_flow {
3e170ce0
A
627 size_t flow_len;
628 size_t flow_tcpci_offset;
39236c6e 629 uint32_t flow_flags;
3e170ce0 630 sae_connid_t flow_cid;
39236c6e
A
631 struct sockaddr_storage flow_src;
632 struct sockaddr_storage flow_dst;
3e170ce0
A
633 uint64_t flow_sndnxt; /* subflow's sndnxt snapshot */
634 uint32_t flow_relseq; /* last subflow rel seq# */
635 int32_t flow_soerror; /* subflow level error */
636 uint32_t flow_probecnt; /* number of probes sent */
637 uint32_t flow_peerswitch;/* did peer switch */
638 conninfo_tcp_t flow_ci; /* must be the last field */
39236c6e
A
639} mptcp_flow_t;
640
641typedef struct conninfo_mptcp {
642 size_t mptcpci_len;
3e170ce0
A
643 size_t mptcpci_flow_offset; /* offsetof first flow */
644 size_t mptcpci_nflows; /* number of subflows */
645 uint32_t mptcpci_state; /* MPTCP level state */
646 uint32_t mptcpci_mpte_flags; /* Session flags */
647 uint32_t mptcpci_flags; /* MPTCB flags */
648 uint32_t mptcpci_ltoken; /* local token */
649 uint32_t mptcpci_rtoken; /* remote token */
650 uint32_t mptcpci_notsent_lowat; /* NOTSENT_LOWAT */
651
652 /* Send side */
653 uint64_t mptcpci_snduna; /* DSN of last unacked byte */
654 uint64_t mptcpci_sndnxt; /* DSN of next byte to send */
655 uint64_t mptcpci_sndmax; /* DSN of max byte sent */
656 uint64_t mptcpci_lidsn; /* Local IDSN */
657 uint32_t mptcpci_sndwnd; /* Send window snapshot */
658
659 /* Receive side */
660 uint64_t mptcpci_rcvnxt; /* Next expected DSN */
661 uint64_t mptcpci_rcvatmark; /* Session level rcvnxt */
662 uint64_t mptcpci_ridsn; /* Peer's IDSN */
663 uint32_t mptcpci_rcvwnd; /* Receive window */
664
665 uint8_t mptcpci_mpte_addrid; /* last addr id */
666
39236c6e
A
667 mptcp_flow_t mptcpci_flows[1];
668} conninfo_mptcp_t;
669
3e170ce0
A
670/* Use SymptomsD notifications of wifi and cell status in subflow selection */
671#define MPTCP_KERN_CTL_NAME "com.apple.network.advisory"
672typedef struct symptoms_advisory {
673 union {
674 uint32_t sa_nwk_status_int;
675 struct {
676 union {
677#define SYMPTOMS_ADVISORY_NOCOMMENT 0x00
678 uint16_t sa_nwk_status;
679 struct {
680#define SYMPTOMS_ADVISORY_WIFI_BAD 0x01
681#define SYMPTOMS_ADVISORY_WIFI_OK 0x02
682 uint8_t sa_wifi_status;
683#define SYMPTOMS_ADVISORY_CELL_BAD 0x01
684#define SYMPTOMS_ADVISORY_CELL_OK 0x02
685 uint8_t sa_cell_status;
686 };
687 };
688 uint16_t sa_unused;
689 };
690 };
691} symptoms_advisory_t;
692
693
39236c6e
A
694#endif /* PRIVATE */
695#endif /* _NETINET_MPTCP_VAR_H_ */