xref: /xnu-8796.121.2/bsd/netinet/mptcp_timer.c (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions /*
2*c54f35caSApple OSS Distributions  * Copyright (c) 2012-2017 Apple Inc. All rights reserved.
3*c54f35caSApple OSS Distributions  *
4*c54f35caSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions  *
6*c54f35caSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions  *
15*c54f35caSApple OSS Distributions  * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions  *
18*c54f35caSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions  * limitations under the License.
25*c54f35caSApple OSS Distributions  *
26*c54f35caSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions  */
28*c54f35caSApple OSS Distributions 
29*c54f35caSApple OSS Distributions #include <sys/param.h>
30*c54f35caSApple OSS Distributions #include <sys/systm.h>
31*c54f35caSApple OSS Distributions #include <sys/kernel.h>
32*c54f35caSApple OSS Distributions #include <sys/mcache.h>
33*c54f35caSApple OSS Distributions #include <sys/socket.h>
34*c54f35caSApple OSS Distributions #include <sys/socketvar.h>
35*c54f35caSApple OSS Distributions #include <sys/syslog.h>
36*c54f35caSApple OSS Distributions #include <sys/protosw.h>
37*c54f35caSApple OSS Distributions #include <sys/sysctl.h>
38*c54f35caSApple OSS Distributions 
39*c54f35caSApple OSS Distributions #include <mach/sdt.h>
40*c54f35caSApple OSS Distributions 
41*c54f35caSApple OSS Distributions #include <netinet/mp_pcb.h>
42*c54f35caSApple OSS Distributions #include <netinet/mptcp_var.h>
43*c54f35caSApple OSS Distributions #include <netinet/mptcp_timer.h>
44*c54f35caSApple OSS Distributions #include <netinet/mptcp_seq.h>
45*c54f35caSApple OSS Distributions 
46*c54f35caSApple OSS Distributions #include <kern/locks.h>
47*c54f35caSApple OSS Distributions 
48*c54f35caSApple OSS Distributions /*
49*c54f35caSApple OSS Distributions  * MPTCP Retransmission Timer comes into play only when subflow level
50*c54f35caSApple OSS Distributions  * data is acked, but Data ACK is not received. Time is in seconds.
51*c54f35caSApple OSS Distributions  */
52*c54f35caSApple OSS Distributions static u_int32_t mptcp_rto = 3;
53*c54f35caSApple OSS Distributions SYSCTL_INT(_net_inet_mptcp, OID_AUTO, rto, CTLFLAG_RW | CTLFLAG_LOCKED,
54*c54f35caSApple OSS Distributions     &mptcp_rto, 0, "MPTCP Retransmission Timeout");
55*c54f35caSApple OSS Distributions 
56*c54f35caSApple OSS Distributions static int mptcp_nrtos = 3;
57*c54f35caSApple OSS Distributions SYSCTL_INT(_net_inet_mptcp, OID_AUTO, nrto, CTLFLAG_RW | CTLFLAG_LOCKED,
58*c54f35caSApple OSS Distributions     &mptcp_rto, 0, "MPTCP Retransmissions");
59*c54f35caSApple OSS Distributions 
60*c54f35caSApple OSS Distributions /*
61*c54f35caSApple OSS Distributions  * MPTCP connections timewait interval in seconds.
62*c54f35caSApple OSS Distributions  */
63*c54f35caSApple OSS Distributions static u_int32_t mptcp_tw = 60;
64*c54f35caSApple OSS Distributions SYSCTL_INT(_net_inet_mptcp, OID_AUTO, tw, CTLFLAG_RW | CTLFLAG_LOCKED,
65*c54f35caSApple OSS Distributions     &mptcp_tw, 0, "MPTCP Timewait Period");
66*c54f35caSApple OSS Distributions 
67*c54f35caSApple OSS Distributions #define TIMEVAL_TO_HZ(_tv_)     ((_tv_).tv_sec * hz + (_tv_).tv_usec / hz)
68*c54f35caSApple OSS Distributions 
69*c54f35caSApple OSS Distributions static int mptcp_cancel_urgency_timer(struct mptses *mpte);
70*c54f35caSApple OSS Distributions 
71*c54f35caSApple OSS Distributions static int
mptcp_timer_demux(struct mptses * mpte,uint64_t now_msecs)72*c54f35caSApple OSS Distributions mptcp_timer_demux(struct mptses *mpte, uint64_t now_msecs)
73*c54f35caSApple OSS Distributions {
74*c54f35caSApple OSS Distributions 	struct mptcb *mp_tp = NULL;
75*c54f35caSApple OSS Distributions 	mp_tp = mpte->mpte_mptcb;
76*c54f35caSApple OSS Distributions 	int resched_timer = 0;
77*c54f35caSApple OSS Distributions 
78*c54f35caSApple OSS Distributions 	DTRACE_MPTCP2(timer, struct mptses *, mpte, struct mptcb *, mp_tp);
79*c54f35caSApple OSS Distributions 
80*c54f35caSApple OSS Distributions 	switch (mp_tp->mpt_timer_vals) {
81*c54f35caSApple OSS Distributions 	case MPTT_REXMT:
82*c54f35caSApple OSS Distributions 		if (mp_tp->mpt_rxtstart == 0) {
83*c54f35caSApple OSS Distributions 			break;
84*c54f35caSApple OSS Distributions 		}
85*c54f35caSApple OSS Distributions 		if ((now_msecs - mp_tp->mpt_rxtstart) > (mptcp_rto * hz)) {
86*c54f35caSApple OSS Distributions 			if (MPTCP_SEQ_GT(mp_tp->mpt_snduna, mp_tp->mpt_rtseq)) {
87*c54f35caSApple OSS Distributions 				mp_tp->mpt_timer_vals = 0;
88*c54f35caSApple OSS Distributions 				mp_tp->mpt_rtseq = 0;
89*c54f35caSApple OSS Distributions 				break;
90*c54f35caSApple OSS Distributions 			}
91*c54f35caSApple OSS Distributions 			mp_tp->mpt_rxtshift++;
92*c54f35caSApple OSS Distributions 			if (mp_tp->mpt_rxtshift > mptcp_nrtos) {
93*c54f35caSApple OSS Distributions 				mp_tp->mpt_softerror = ETIMEDOUT;
94*c54f35caSApple OSS Distributions 				DTRACE_MPTCP1(error, struct mptcb *, mp_tp);
95*c54f35caSApple OSS Distributions 			} else {
96*c54f35caSApple OSS Distributions 				mp_tp->mpt_sndnxt = mp_tp->mpt_rtseq;
97*c54f35caSApple OSS Distributions 				os_log_info(mptcp_log_handle,
98*c54f35caSApple OSS Distributions 				    "%s: REXMT %d sndnxt %u\n",
99*c54f35caSApple OSS Distributions 				    __func__, mp_tp->mpt_rxtshift,
100*c54f35caSApple OSS Distributions 				    (uint32_t)mp_tp->mpt_sndnxt);
101*c54f35caSApple OSS Distributions 				mptcp_output(mpte);
102*c54f35caSApple OSS Distributions 			}
103*c54f35caSApple OSS Distributions 		} else {
104*c54f35caSApple OSS Distributions 			resched_timer = 1;
105*c54f35caSApple OSS Distributions 		}
106*c54f35caSApple OSS Distributions 		break;
107*c54f35caSApple OSS Distributions 	case MPTT_TW:
108*c54f35caSApple OSS Distributions 		/* Allows for break before make XXX */
109*c54f35caSApple OSS Distributions 		if (mp_tp->mpt_timewait == 0) {
110*c54f35caSApple OSS Distributions 			VERIFY(0);
111*c54f35caSApple OSS Distributions 		}
112*c54f35caSApple OSS Distributions 		if ((now_msecs - mp_tp->mpt_timewait) >
113*c54f35caSApple OSS Distributions 		    (mptcp_tw * hz)) {
114*c54f35caSApple OSS Distributions 			mp_tp->mpt_softerror = ETIMEDOUT;
115*c54f35caSApple OSS Distributions 			DTRACE_MPTCP1(error, struct mptcb *, mp_tp);
116*c54f35caSApple OSS Distributions 		} else {
117*c54f35caSApple OSS Distributions 			resched_timer = 1;
118*c54f35caSApple OSS Distributions 		}
119*c54f35caSApple OSS Distributions 		break;
120*c54f35caSApple OSS Distributions 	case MPTT_FASTCLOSE:
121*c54f35caSApple OSS Distributions 		/* TODO XXX */
122*c54f35caSApple OSS Distributions 		break;
123*c54f35caSApple OSS Distributions 	default:
124*c54f35caSApple OSS Distributions 		break;
125*c54f35caSApple OSS Distributions 	}
126*c54f35caSApple OSS Distributions 
127*c54f35caSApple OSS Distributions 	return resched_timer;
128*c54f35caSApple OSS Distributions }
129*c54f35caSApple OSS Distributions 
130*c54f35caSApple OSS Distributions uint32_t
mptcp_timer(struct mppcbinfo * mppi)131*c54f35caSApple OSS Distributions mptcp_timer(struct mppcbinfo *mppi)
132*c54f35caSApple OSS Distributions {
133*c54f35caSApple OSS Distributions 	struct mppcb *mpp, *tmpp;
134*c54f35caSApple OSS Distributions 	struct timeval now;
135*c54f35caSApple OSS Distributions 	uint32_t resched_timer = 0;
136*c54f35caSApple OSS Distributions 	uint64_t now_msecs;
137*c54f35caSApple OSS Distributions 
138*c54f35caSApple OSS Distributions 	LCK_MTX_ASSERT(&mppi->mppi_lock, LCK_MTX_ASSERT_OWNED);
139*c54f35caSApple OSS Distributions 
140*c54f35caSApple OSS Distributions 	microuptime(&now);
141*c54f35caSApple OSS Distributions 	now_msecs = TIMEVAL_TO_HZ(now);
142*c54f35caSApple OSS Distributions 	TAILQ_FOREACH_SAFE(mpp, &mppi->mppi_pcbs, mpp_entry, tmpp) {
143*c54f35caSApple OSS Distributions 		struct socket *mp_so;
144*c54f35caSApple OSS Distributions 		struct mptses *mpte;
145*c54f35caSApple OSS Distributions 
146*c54f35caSApple OSS Distributions 		mp_so = mpp->mpp_socket;
147*c54f35caSApple OSS Distributions 		mpte = mptompte(mpp);
148*c54f35caSApple OSS Distributions 		socket_lock(mp_so, 1);
149*c54f35caSApple OSS Distributions 
150*c54f35caSApple OSS Distributions 		VERIFY(mpp->mpp_flags & MPP_ATTACHED);
151*c54f35caSApple OSS Distributions 
152*c54f35caSApple OSS Distributions 		if (mptcp_timer_demux(mpte, now_msecs)) {
153*c54f35caSApple OSS Distributions 			resched_timer = 1;
154*c54f35caSApple OSS Distributions 		}
155*c54f35caSApple OSS Distributions 		socket_unlock(mp_so, 1);
156*c54f35caSApple OSS Distributions 	}
157*c54f35caSApple OSS Distributions 
158*c54f35caSApple OSS Distributions 	return resched_timer;
159*c54f35caSApple OSS Distributions }
160*c54f35caSApple OSS Distributions 
161*c54f35caSApple OSS Distributions void
mptcp_start_timer(struct mptses * mpte,int timer_type)162*c54f35caSApple OSS Distributions mptcp_start_timer(struct mptses *mpte, int timer_type)
163*c54f35caSApple OSS Distributions {
164*c54f35caSApple OSS Distributions 	struct timeval now;
165*c54f35caSApple OSS Distributions 	struct mptcb *mp_tp = mpte->mpte_mptcb;
166*c54f35caSApple OSS Distributions 
167*c54f35caSApple OSS Distributions 	microuptime(&now);
168*c54f35caSApple OSS Distributions 
169*c54f35caSApple OSS Distributions 	DTRACE_MPTCP2(start__timer, struct mptcb *, mp_tp, int, timer_type);
170*c54f35caSApple OSS Distributions 
171*c54f35caSApple OSS Distributions 	socket_lock_assert_owned(mptetoso(mpte));
172*c54f35caSApple OSS Distributions 
173*c54f35caSApple OSS Distributions 	switch (timer_type) {
174*c54f35caSApple OSS Distributions 	case MPTT_REXMT:
175*c54f35caSApple OSS Distributions 		mp_tp->mpt_timer_vals |= MPTT_REXMT;
176*c54f35caSApple OSS Distributions 		mp_tp->mpt_rxtstart = TIMEVAL_TO_HZ(now);
177*c54f35caSApple OSS Distributions 		mp_tp->mpt_rxtshift = 0;
178*c54f35caSApple OSS Distributions 		mp_tp->mpt_rtseq = mp_tp->mpt_sndnxt;
179*c54f35caSApple OSS Distributions 		break;
180*c54f35caSApple OSS Distributions 	case MPTT_TW:
181*c54f35caSApple OSS Distributions 		/* XXX: Not implemented yet */
182*c54f35caSApple OSS Distributions 		mp_tp->mpt_timer_vals |= MPTT_TW;
183*c54f35caSApple OSS Distributions 		mp_tp->mpt_timewait = TIMEVAL_TO_HZ(now);
184*c54f35caSApple OSS Distributions 		break;
185*c54f35caSApple OSS Distributions 	case MPTT_FASTCLOSE:
186*c54f35caSApple OSS Distributions 		/* NO-OP */
187*c54f35caSApple OSS Distributions 		break;
188*c54f35caSApple OSS Distributions 	default:
189*c54f35caSApple OSS Distributions 		VERIFY(0);
190*c54f35caSApple OSS Distributions 		/* NOTREACHED */
191*c54f35caSApple OSS Distributions 	}
192*c54f35caSApple OSS Distributions 	mptcp_timer_sched();
193*c54f35caSApple OSS Distributions }
194*c54f35caSApple OSS Distributions 
195*c54f35caSApple OSS Distributions void
mptcp_cancel_timer(struct mptcb * mp_tp,int timer_type)196*c54f35caSApple OSS Distributions mptcp_cancel_timer(struct mptcb *mp_tp, int timer_type)
197*c54f35caSApple OSS Distributions {
198*c54f35caSApple OSS Distributions 	socket_lock_assert_owned(mptetoso(mp_tp->mpt_mpte));
199*c54f35caSApple OSS Distributions 
200*c54f35caSApple OSS Distributions 	switch (timer_type) {
201*c54f35caSApple OSS Distributions 	case MPTT_REXMT:
202*c54f35caSApple OSS Distributions 		mp_tp->mpt_rxtstart = 0;
203*c54f35caSApple OSS Distributions 		mp_tp->mpt_rxtshift = 0;
204*c54f35caSApple OSS Distributions 		mp_tp->mpt_timer_vals = 0;
205*c54f35caSApple OSS Distributions 		break;
206*c54f35caSApple OSS Distributions 	case MPTT_TW:
207*c54f35caSApple OSS Distributions 		/* NO-OP */
208*c54f35caSApple OSS Distributions 		break;
209*c54f35caSApple OSS Distributions 	case MPTT_FASTCLOSE:
210*c54f35caSApple OSS Distributions 		/* NO-OP */
211*c54f35caSApple OSS Distributions 		break;
212*c54f35caSApple OSS Distributions 	default:
213*c54f35caSApple OSS Distributions 		break;
214*c54f35caSApple OSS Distributions 	}
215*c54f35caSApple OSS Distributions }
216*c54f35caSApple OSS Distributions 
217*c54f35caSApple OSS Distributions void
mptcp_cancel_all_timers(struct mptcb * mp_tp)218*c54f35caSApple OSS Distributions mptcp_cancel_all_timers(struct mptcb *mp_tp)
219*c54f35caSApple OSS Distributions {
220*c54f35caSApple OSS Distributions 	struct mptses *mpte = mp_tp->mpt_mpte;
221*c54f35caSApple OSS Distributions 
222*c54f35caSApple OSS Distributions 	mptcp_cancel_urgency_timer(mpte);
223*c54f35caSApple OSS Distributions 
224*c54f35caSApple OSS Distributions 	mptcp_cancel_timer(mp_tp, MPTT_REXMT);
225*c54f35caSApple OSS Distributions 	mptcp_cancel_timer(mp_tp, MPTT_TW);
226*c54f35caSApple OSS Distributions 	mptcp_cancel_timer(mp_tp, MPTT_FASTCLOSE);
227*c54f35caSApple OSS Distributions }
228*c54f35caSApple OSS Distributions 
229*c54f35caSApple OSS Distributions static void
mptcp_urgency_timer(void * param0,__unused void * param1)230*c54f35caSApple OSS Distributions mptcp_urgency_timer(void *param0, __unused void *param1)
231*c54f35caSApple OSS Distributions {
232*c54f35caSApple OSS Distributions 	struct mptses *mpte = (struct mptses *)param0;
233*c54f35caSApple OSS Distributions 	struct socket *mp_so = mptetoso(mpte);
234*c54f35caSApple OSS Distributions 	uint64_t time_now;
235*c54f35caSApple OSS Distributions 
236*c54f35caSApple OSS Distributions 	socket_lock(mp_so, 1);
237*c54f35caSApple OSS Distributions 
238*c54f35caSApple OSS Distributions 	time_now = mach_continuous_time();
239*c54f35caSApple OSS Distributions 	VERIFY(mp_so->so_usecount >= 0);
240*c54f35caSApple OSS Distributions 
241*c54f35caSApple OSS Distributions 	os_log(mptcp_log_handle, "%s - %lx: timer at %llu now %llu usecount %u\n",
242*c54f35caSApple OSS Distributions 	    __func__, (unsigned long)VM_KERNEL_ADDRPERM(mpte), mpte->mpte_time_target, time_now, mp_so->so_usecount);
243*c54f35caSApple OSS Distributions 
244*c54f35caSApple OSS Distributions 	mptcp_check_subflows_and_add(mpte);
245*c54f35caSApple OSS Distributions 
246*c54f35caSApple OSS Distributions 	mp_so->so_usecount--;
247*c54f35caSApple OSS Distributions 
248*c54f35caSApple OSS Distributions 	socket_unlock(mp_so, 1);
249*c54f35caSApple OSS Distributions }
250*c54f35caSApple OSS Distributions 
251*c54f35caSApple OSS Distributions static void
mptcp_urgency_stop(void * param0,__unused void * param1)252*c54f35caSApple OSS Distributions mptcp_urgency_stop(void *param0, __unused void *param1)
253*c54f35caSApple OSS Distributions {
254*c54f35caSApple OSS Distributions 	struct mptses *mpte = (struct mptses *)param0;
255*c54f35caSApple OSS Distributions 	struct socket *mp_so = mptetoso(mpte);
256*c54f35caSApple OSS Distributions 
257*c54f35caSApple OSS Distributions 	socket_lock(mp_so, 1);
258*c54f35caSApple OSS Distributions 
259*c54f35caSApple OSS Distributions 	VERIFY(mp_so->so_usecount >= 0);
260*c54f35caSApple OSS Distributions 
261*c54f35caSApple OSS Distributions 	os_log(mptcp_log_handle, "%s - %lx: usecount %u\n",
262*c54f35caSApple OSS Distributions 	    __func__, (unsigned long)VM_KERNEL_ADDRPERM(mpte), mp_so->so_usecount);
263*c54f35caSApple OSS Distributions 
264*c54f35caSApple OSS Distributions 	mptcp_check_subflows_and_remove(mpte);
265*c54f35caSApple OSS Distributions 
266*c54f35caSApple OSS Distributions 	mp_so->so_usecount--;
267*c54f35caSApple OSS Distributions 
268*c54f35caSApple OSS Distributions 	socket_unlock(mp_so, 1);
269*c54f35caSApple OSS Distributions }
270*c54f35caSApple OSS Distributions 
271*c54f35caSApple OSS Distributions void
mptcp_init_urgency_timer(struct mptses * mpte)272*c54f35caSApple OSS Distributions mptcp_init_urgency_timer(struct mptses *mpte)
273*c54f35caSApple OSS Distributions {
274*c54f35caSApple OSS Distributions 	/* thread_call_allocate never fails */
275*c54f35caSApple OSS Distributions 	mpte->mpte_time_thread = thread_call_allocate(mptcp_urgency_timer, mpte);
276*c54f35caSApple OSS Distributions 	mpte->mpte_stop_urgency = thread_call_allocate(mptcp_urgency_stop, mpte);
277*c54f35caSApple OSS Distributions }
278*c54f35caSApple OSS Distributions 
279*c54f35caSApple OSS Distributions void
mptcp_set_urgency_timer(struct mptses * mpte)280*c54f35caSApple OSS Distributions mptcp_set_urgency_timer(struct mptses *mpte)
281*c54f35caSApple OSS Distributions {
282*c54f35caSApple OSS Distributions 	struct socket *mp_so = mptetoso(mpte);
283*c54f35caSApple OSS Distributions 	uint64_t time_now = 0;
284*c54f35caSApple OSS Distributions 	boolean_t ret = FALSE;
285*c54f35caSApple OSS Distributions 
286*c54f35caSApple OSS Distributions 	socket_lock_assert_owned(mp_so);
287*c54f35caSApple OSS Distributions 
288*c54f35caSApple OSS Distributions 	VERIFY(mp_so->so_usecount >= 0);
289*c54f35caSApple OSS Distributions 	if (mp_so->so_usecount == 0) {
290*c54f35caSApple OSS Distributions 		goto exit_log;
291*c54f35caSApple OSS Distributions 	}
292*c54f35caSApple OSS Distributions 
293*c54f35caSApple OSS Distributions 	if (mpte->mpte_time_target == 0) {
294*c54f35caSApple OSS Distributions 		/* Close subflows right now */
295*c54f35caSApple OSS Distributions 
296*c54f35caSApple OSS Distributions 		ret = thread_call_enter(mpte->mpte_stop_urgency);
297*c54f35caSApple OSS Distributions 
298*c54f35caSApple OSS Distributions 		if (!ret) {
299*c54f35caSApple OSS Distributions 			mp_so->so_usecount++;
300*c54f35caSApple OSS Distributions 		}
301*c54f35caSApple OSS Distributions 
302*c54f35caSApple OSS Distributions 		goto exit_log;
303*c54f35caSApple OSS Distributions 	}
304*c54f35caSApple OSS Distributions 
305*c54f35caSApple OSS Distributions 	time_now = mach_continuous_time();
306*c54f35caSApple OSS Distributions 
307*c54f35caSApple OSS Distributions 	if ((int64_t)(mpte->mpte_time_target - time_now) > 0) {
308*c54f35caSApple OSS Distributions 		ret = thread_call_enter(mpte->mpte_stop_urgency);
309*c54f35caSApple OSS Distributions 
310*c54f35caSApple OSS Distributions 		if (!ret) {
311*c54f35caSApple OSS Distributions 			mp_so->so_usecount++;
312*c54f35caSApple OSS Distributions 		}
313*c54f35caSApple OSS Distributions 
314*c54f35caSApple OSS Distributions 		ret = thread_call_enter_delayed_with_leeway(mpte->mpte_time_thread, NULL,
315*c54f35caSApple OSS Distributions 		    mpte->mpte_time_target, 0, THREAD_CALL_CONTINUOUS);
316*c54f35caSApple OSS Distributions 
317*c54f35caSApple OSS Distributions 		if (!ret) {
318*c54f35caSApple OSS Distributions 			mp_so->so_usecount++;
319*c54f35caSApple OSS Distributions 		}
320*c54f35caSApple OSS Distributions 	} else if ((int64_t)(mpte->mpte_time_target - time_now) <= 0) {
321*c54f35caSApple OSS Distributions 		/* Already passed the deadline, trigger subflows now */
322*c54f35caSApple OSS Distributions 		ret = thread_call_enter(mpte->mpte_time_thread);
323*c54f35caSApple OSS Distributions 
324*c54f35caSApple OSS Distributions 		if (!ret) {
325*c54f35caSApple OSS Distributions 			mp_so->so_usecount++;
326*c54f35caSApple OSS Distributions 		}
327*c54f35caSApple OSS Distributions 	}
328*c54f35caSApple OSS Distributions 
329*c54f35caSApple OSS Distributions exit_log:
330*c54f35caSApple OSS Distributions 	os_log(mptcp_log_handle, "%s - %lx: timer at %llu now %llu usecount %u ret %u\n",
331*c54f35caSApple OSS Distributions 	    __func__, (unsigned long)VM_KERNEL_ADDRPERM(mpte), mpte->mpte_time_target, time_now,
332*c54f35caSApple OSS Distributions 	    mp_so->so_usecount, ret);
333*c54f35caSApple OSS Distributions }
334*c54f35caSApple OSS Distributions 
335*c54f35caSApple OSS Distributions static int
mptcp_cancel_urgency_timer(struct mptses * mpte)336*c54f35caSApple OSS Distributions mptcp_cancel_urgency_timer(struct mptses *mpte)
337*c54f35caSApple OSS Distributions {
338*c54f35caSApple OSS Distributions 	struct socket *mp_so = mptetoso(mpte);
339*c54f35caSApple OSS Distributions 	boolean_t ret;
340*c54f35caSApple OSS Distributions 
341*c54f35caSApple OSS Distributions 	ret = thread_call_cancel(mpte->mpte_time_thread);
342*c54f35caSApple OSS Distributions 
343*c54f35caSApple OSS Distributions 	os_log(mptcp_log_handle, "%s - %lx: Canceled timer thread usecount %u ret %u\n",
344*c54f35caSApple OSS Distributions 	    __func__, (unsigned long)VM_KERNEL_ADDRPERM(mpte), mp_so->so_usecount, ret);
345*c54f35caSApple OSS Distributions 
346*c54f35caSApple OSS Distributions 	mptcp_check_subflows_and_remove(mpte);
347*c54f35caSApple OSS Distributions 
348*c54f35caSApple OSS Distributions 	if (ret) {
349*c54f35caSApple OSS Distributions 		mp_so->so_usecount--;
350*c54f35caSApple OSS Distributions 	}
351*c54f35caSApple OSS Distributions 
352*c54f35caSApple OSS Distributions 	ret = thread_call_cancel(mpte->mpte_stop_urgency);
353*c54f35caSApple OSS Distributions 	if (ret) {
354*c54f35caSApple OSS Distributions 		mp_so->so_usecount--;
355*c54f35caSApple OSS Distributions 	}
356*c54f35caSApple OSS Distributions 
357*c54f35caSApple OSS Distributions 	return 0;
358*c54f35caSApple OSS Distributions }
359