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