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