michael@0: /*- michael@0: * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * a) Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * michael@0: * b) Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the distribution. michael@0: * michael@0: * c) Neither the name of Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 257359 2013-10-29 20:04:50Z tuexen $"); michael@0: #endif michael@0: michael@0: #define _IP_VHL michael@0: #include michael@0: #include michael@0: #ifdef INET6 michael@0: #if defined(__Userspace_os_FreeBSD) michael@0: #include michael@0: #endif michael@0: #endif michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #if !defined(__Userspace_os_Windows) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined(__APPLE__) michael@0: #define APPLE_FILE_NO 6 michael@0: #endif michael@0: michael@0: void michael@0: sctp_audit_retranmission_queue(struct sctp_association *asoc) michael@0: { michael@0: struct sctp_tmit_chunk *chk; michael@0: michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, "Audit invoked on send queue cnt:%d onqueue:%d\n", michael@0: asoc->sent_queue_retran_cnt, michael@0: asoc->sent_queue_cnt); michael@0: asoc->sent_queue_retran_cnt = 0; michael@0: asoc->sent_queue_cnt = 0; michael@0: TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { michael@0: if (chk->sent == SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(asoc->sent_queue_retran_cnt); michael@0: } michael@0: asoc->sent_queue_cnt++; michael@0: } michael@0: TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { michael@0: if (chk->sent == SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(asoc->sent_queue_retran_cnt); michael@0: } michael@0: } michael@0: TAILQ_FOREACH(chk, &asoc->asconf_send_queue, sctp_next) { michael@0: if (chk->sent == SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(asoc->sent_queue_retran_cnt); michael@0: } michael@0: } michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, "Audit completes retran:%d onqueue:%d\n", michael@0: asoc->sent_queue_retran_cnt, michael@0: asoc->sent_queue_cnt); michael@0: } michael@0: michael@0: int michael@0: sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, uint16_t threshold) michael@0: { michael@0: if (net) { michael@0: net->error_count++; michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, "Error count for %p now %d thresh:%d\n", michael@0: (void *)net, net->error_count, michael@0: net->failure_threshold); michael@0: if (net->error_count > net->failure_threshold) { michael@0: /* We had a threshold failure */ michael@0: if (net->dest_state & SCTP_ADDR_REACHABLE) { michael@0: net->dest_state &= ~SCTP_ADDR_REACHABLE; michael@0: net->dest_state &= ~SCTP_ADDR_REQ_PRIMARY; michael@0: net->dest_state &= ~SCTP_ADDR_PF; michael@0: sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, michael@0: stcb, 0, michael@0: (void *)net, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } else if ((net->pf_threshold < net->failure_threshold) && michael@0: (net->error_count > net->pf_threshold)) { michael@0: if (!(net->dest_state & SCTP_ADDR_PF)) { michael@0: net->dest_state |= SCTP_ADDR_PF; michael@0: net->last_active = sctp_get_tick_count(); michael@0: sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); michael@0: } michael@0: } michael@0: } michael@0: if (stcb == NULL) michael@0: return (0); michael@0: michael@0: if (net) { michael@0: if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { michael@0: sctp_misc_ints(SCTP_THRESHOLD_INCR, michael@0: stcb->asoc.overall_error_count, michael@0: (stcb->asoc.overall_error_count+1), michael@0: SCTP_FROM_SCTP_TIMER, michael@0: __LINE__); michael@0: } michael@0: stcb->asoc.overall_error_count++; michael@0: } michael@0: } else { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { michael@0: sctp_misc_ints(SCTP_THRESHOLD_INCR, michael@0: stcb->asoc.overall_error_count, michael@0: (stcb->asoc.overall_error_count+1), michael@0: SCTP_FROM_SCTP_TIMER, michael@0: __LINE__); michael@0: } michael@0: stcb->asoc.overall_error_count++; michael@0: } michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, "Overall error count for %p now %d thresh:%u state:%x\n", michael@0: (void *)&stcb->asoc, stcb->asoc.overall_error_count, michael@0: (uint32_t)threshold, michael@0: ((net == NULL) ? (uint32_t) 0 : (uint32_t) net->dest_state)); michael@0: /* michael@0: * We specifically do not do >= to give the assoc one more change michael@0: * before we fail it. michael@0: */ michael@0: if (stcb->asoc.overall_error_count > threshold) { michael@0: /* Abort notification sends a ULP notify */ michael@0: struct mbuf *oper; michael@0: michael@0: oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (oper) { michael@0: struct sctp_paramhdr *ph; michael@0: uint32_t *ippp; michael@0: michael@0: SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + michael@0: sizeof(uint32_t); michael@0: ph = mtod(oper, struct sctp_paramhdr *); michael@0: ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); michael@0: ph->param_length = htons(SCTP_BUF_LEN(oper)); michael@0: ippp = (uint32_t *) (ph + 1); michael@0: *ippp = htonl(SCTP_FROM_SCTP_TIMER+SCTP_LOC_1); michael@0: } michael@0: inp->last_abort_code = SCTP_FROM_SCTP_TIMER+SCTP_LOC_1; michael@0: sctp_abort_an_association(inp, stcb, oper, SCTP_SO_NOT_LOCKED); michael@0: return (1); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * sctp_find_alternate_net() returns a non-NULL pointer as long michael@0: * the argument net is non-NULL. michael@0: */ michael@0: struct sctp_nets * michael@0: sctp_find_alternate_net(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, michael@0: int mode) michael@0: { michael@0: /* Find and return an alternate network if possible */ michael@0: struct sctp_nets *alt, *mnet, *min_errors_net = NULL , *max_cwnd_net = NULL; michael@0: int once; michael@0: /* JRS 5/14/07 - Initialize min_errors to an impossible value. */ michael@0: int min_errors = -1; michael@0: uint32_t max_cwnd = 0; michael@0: michael@0: if (stcb->asoc.numnets == 1) { michael@0: /* No others but net */ michael@0: return (TAILQ_FIRST(&stcb->asoc.nets)); michael@0: } michael@0: /* michael@0: * JRS 5/14/07 - If mode is set to 2, use the CMT PF find alternate net algorithm. michael@0: * This algorithm chooses the active destination (not in PF state) with the largest michael@0: * cwnd value. If all destinations are in PF state, unreachable, or unconfirmed, choose michael@0: * the desination that is in PF state with the lowest error count. In case of a tie, michael@0: * choose the destination that was most recently active. michael@0: */ michael@0: if (mode == 2) { michael@0: TAILQ_FOREACH(mnet, &stcb->asoc.nets, sctp_next) { michael@0: /* JRS 5/14/07 - If the destination is unreachable or unconfirmed, skip it. */ michael@0: if (((mnet->dest_state & SCTP_ADDR_REACHABLE) != SCTP_ADDR_REACHABLE) || michael@0: (mnet->dest_state & SCTP_ADDR_UNCONFIRMED)) { michael@0: continue; michael@0: } michael@0: /* michael@0: * JRS 5/14/07 - If the destination is reachable but in PF state, compare michael@0: * the error count of the destination to the minimum error count seen thus far. michael@0: * Store the destination with the lower error count. If the error counts are michael@0: * equal, store the destination that was most recently active. michael@0: */ michael@0: if (mnet->dest_state & SCTP_ADDR_PF) { michael@0: /* michael@0: * JRS 5/14/07 - If the destination under consideration is the current michael@0: * destination, work as if the error count is one higher. The michael@0: * actual error count will not be incremented until later in the michael@0: * t3 handler. michael@0: */ michael@0: if (mnet == net) { michael@0: if (min_errors == -1) { michael@0: min_errors = mnet->error_count + 1; michael@0: min_errors_net = mnet; michael@0: } else if (mnet->error_count + 1 < min_errors) { michael@0: min_errors = mnet->error_count + 1; michael@0: min_errors_net = mnet; michael@0: } else if (mnet->error_count + 1 == min_errors michael@0: && mnet->last_active > min_errors_net->last_active) { michael@0: min_errors_net = mnet; michael@0: min_errors = mnet->error_count + 1; michael@0: } michael@0: continue; michael@0: } else { michael@0: if (min_errors == -1) { michael@0: min_errors = mnet->error_count; michael@0: min_errors_net = mnet; michael@0: } else if (mnet->error_count < min_errors) { michael@0: min_errors = mnet->error_count; michael@0: min_errors_net = mnet; michael@0: } else if (mnet->error_count == min_errors michael@0: && mnet->last_active > min_errors_net->last_active) { michael@0: min_errors_net = mnet; michael@0: min_errors = mnet->error_count; michael@0: } michael@0: continue; michael@0: } michael@0: } michael@0: /* michael@0: * JRS 5/14/07 - If the destination is reachable and not in PF state, compare the michael@0: * cwnd of the destination to the highest cwnd seen thus far. Store the michael@0: * destination with the higher cwnd value. If the cwnd values are equal, michael@0: * randomly choose one of the two destinations. michael@0: */ michael@0: if (max_cwnd < mnet->cwnd) { michael@0: max_cwnd_net = mnet; michael@0: max_cwnd = mnet->cwnd; michael@0: } else if (max_cwnd == mnet->cwnd) { michael@0: uint32_t rndval; michael@0: uint8_t this_random; michael@0: michael@0: if (stcb->asoc.hb_random_idx > 3) { michael@0: rndval = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep); michael@0: memcpy(stcb->asoc.hb_random_values, &rndval, sizeof(stcb->asoc.hb_random_values)); michael@0: this_random = stcb->asoc.hb_random_values[0]; michael@0: stcb->asoc.hb_random_idx++; michael@0: stcb->asoc.hb_ect_randombit = 0; michael@0: } else { michael@0: this_random = stcb->asoc.hb_random_values[stcb->asoc.hb_random_idx]; michael@0: stcb->asoc.hb_random_idx++; michael@0: stcb->asoc.hb_ect_randombit = 0; michael@0: } michael@0: if (this_random % 2 == 1) { michael@0: max_cwnd_net = mnet; michael@0: max_cwnd = mnet->cwnd; /* Useless? */ michael@0: } michael@0: } michael@0: } michael@0: if (max_cwnd_net == NULL) { michael@0: if (min_errors_net == NULL) { michael@0: return (net); michael@0: } michael@0: return (min_errors_net); michael@0: } else { michael@0: return (max_cwnd_net); michael@0: } michael@0: } /* JRS 5/14/07 - If mode is set to 1, use the CMT policy for choosing an alternate net. */ michael@0: else if (mode == 1) { michael@0: TAILQ_FOREACH(mnet, &stcb->asoc.nets, sctp_next) { michael@0: if (((mnet->dest_state & SCTP_ADDR_REACHABLE) != SCTP_ADDR_REACHABLE) || michael@0: (mnet->dest_state & SCTP_ADDR_UNCONFIRMED)) { michael@0: /* michael@0: * will skip ones that are not-reachable or michael@0: * unconfirmed michael@0: */ michael@0: continue; michael@0: } michael@0: if (max_cwnd < mnet->cwnd) { michael@0: max_cwnd_net = mnet; michael@0: max_cwnd = mnet->cwnd; michael@0: } else if (max_cwnd == mnet->cwnd) { michael@0: uint32_t rndval; michael@0: uint8_t this_random; michael@0: michael@0: if (stcb->asoc.hb_random_idx > 3) { michael@0: rndval = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep); michael@0: memcpy(stcb->asoc.hb_random_values, &rndval, michael@0: sizeof(stcb->asoc.hb_random_values)); michael@0: this_random = stcb->asoc.hb_random_values[0]; michael@0: stcb->asoc.hb_random_idx = 0; michael@0: stcb->asoc.hb_ect_randombit = 0; michael@0: } else { michael@0: this_random = stcb->asoc.hb_random_values[stcb->asoc.hb_random_idx]; michael@0: stcb->asoc.hb_random_idx++; michael@0: stcb->asoc.hb_ect_randombit = 0; michael@0: } michael@0: if (this_random % 2) { michael@0: max_cwnd_net = mnet; michael@0: max_cwnd = mnet->cwnd; michael@0: } michael@0: } michael@0: } michael@0: if (max_cwnd_net) { michael@0: return (max_cwnd_net); michael@0: } michael@0: } michael@0: mnet = net; michael@0: once = 0; michael@0: michael@0: if (mnet == NULL) { michael@0: mnet = TAILQ_FIRST(&stcb->asoc.nets); michael@0: if (mnet == NULL) { michael@0: return (NULL); michael@0: } michael@0: } michael@0: do { michael@0: alt = TAILQ_NEXT(mnet, sctp_next); michael@0: if (alt == NULL) michael@0: { michael@0: once++; michael@0: if (once > 1) { michael@0: break; michael@0: } michael@0: alt = TAILQ_FIRST(&stcb->asoc.nets); michael@0: if (alt == NULL) { michael@0: return (NULL); michael@0: } michael@0: } michael@0: if (alt->ro.ro_rt == NULL) { michael@0: if (alt->ro._s_addr) { michael@0: sctp_free_ifa(alt->ro._s_addr); michael@0: alt->ro._s_addr = NULL; michael@0: } michael@0: alt->src_addr_selected = 0; michael@0: } michael@0: /*sa_ignore NO_NULL_CHK*/ michael@0: if (((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) && michael@0: (alt->ro.ro_rt != NULL) && michael@0: (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))) { michael@0: /* Found a reachable address */ michael@0: break; michael@0: } michael@0: mnet = alt; michael@0: } while (alt != NULL); michael@0: michael@0: if (alt == NULL) { michael@0: /* Case where NO insv network exists (dormant state) */ michael@0: /* we rotate destinations */ michael@0: once = 0; michael@0: mnet = net; michael@0: do { michael@0: if (mnet == NULL) { michael@0: return (TAILQ_FIRST(&stcb->asoc.nets)); michael@0: } michael@0: alt = TAILQ_NEXT(mnet, sctp_next); michael@0: if (alt == NULL) { michael@0: once++; michael@0: if (once > 1) { michael@0: break; michael@0: } michael@0: alt = TAILQ_FIRST(&stcb->asoc.nets); michael@0: } michael@0: /*sa_ignore NO_NULL_CHK*/ michael@0: if ((!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) && michael@0: (alt != net)) { michael@0: /* Found an alternate address */ michael@0: break; michael@0: } michael@0: mnet = alt; michael@0: } while (alt != NULL); michael@0: } michael@0: if (alt == NULL) { michael@0: return (net); michael@0: } michael@0: return (alt); michael@0: } michael@0: michael@0: static void michael@0: sctp_backoff_on_timeout(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, michael@0: int win_probe, michael@0: int num_marked, int num_abandoned) michael@0: { michael@0: if (net->RTO == 0) { michael@0: net->RTO = stcb->asoc.minrto; michael@0: } michael@0: net->RTO <<= 1; michael@0: if (net->RTO > stcb->asoc.maxrto) { michael@0: net->RTO = stcb->asoc.maxrto; michael@0: } michael@0: if ((win_probe == 0) && (num_marked || num_abandoned)) { michael@0: /* We don't apply penalty to window probe scenarios */ michael@0: /* JRS - Use the congestion control given in the CC module */ michael@0: stcb->asoc.cc_functions.sctp_cwnd_update_after_timeout(stcb, net); michael@0: } michael@0: } michael@0: michael@0: #ifndef INVARIANTS michael@0: static void michael@0: sctp_recover_sent_list(struct sctp_tcb *stcb) michael@0: { michael@0: struct sctp_tmit_chunk *chk, *nchk; michael@0: struct sctp_association *asoc; michael@0: michael@0: asoc = &stcb->asoc; michael@0: TAILQ_FOREACH_SAFE(chk, &asoc->sent_queue, sctp_next, nchk) { michael@0: if (SCTP_TSN_GE(asoc->last_acked_seq, chk->rec.data.TSN_seq)) { michael@0: SCTP_PRINTF("Found chk:%p tsn:%x <= last_acked_seq:%x\n", michael@0: (void *)chk, chk->rec.data.TSN_seq, asoc->last_acked_seq); michael@0: if (chk->sent != SCTP_DATAGRAM_NR_ACKED) { michael@0: if (asoc->strmout[chk->rec.data.stream_number].chunks_on_queues > 0) { michael@0: asoc->strmout[chk->rec.data.stream_number].chunks_on_queues--; michael@0: } michael@0: } michael@0: TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next); michael@0: if (PR_SCTP_ENABLED(chk->flags)) { michael@0: if (asoc->pr_sctp_cnt != 0) michael@0: asoc->pr_sctp_cnt--; michael@0: } michael@0: if (chk->data) { michael@0: /*sa_ignore NO_NULL_CHK*/ michael@0: sctp_free_bufspace(stcb, asoc, chk, 1); michael@0: sctp_m_freem(chk->data); michael@0: chk->data = NULL; michael@0: if (asoc->peer_supports_prsctp && PR_SCTP_BUF_ENABLED(chk->flags)) { michael@0: asoc->sent_queue_cnt_removeable--; michael@0: } michael@0: } michael@0: asoc->sent_queue_cnt--; michael@0: sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: SCTP_PRINTF("after recover order is as follows\n"); michael@0: TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { michael@0: SCTP_PRINTF("chk:%p TSN:%x\n", (void *)chk, chk->rec.data.TSN_seq); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: static int michael@0: sctp_mark_all_for_resend(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, michael@0: struct sctp_nets *alt, michael@0: int window_probe, michael@0: int *num_marked, michael@0: int *num_abandoned) michael@0: { michael@0: michael@0: /* michael@0: * Mark all chunks (well not all) that were sent to *net for michael@0: * retransmission. Move them to alt for there destination as well... michael@0: * We only mark chunks that have been outstanding long enough to michael@0: * have received feed-back. michael@0: */ michael@0: struct sctp_tmit_chunk *chk, *nchk; michael@0: struct sctp_nets *lnets; michael@0: struct timeval now, min_wait, tv; michael@0: int cur_rto; michael@0: int cnt_abandoned; michael@0: int audit_tf, num_mk, fir; michael@0: unsigned int cnt_mk; michael@0: uint32_t orig_flight, orig_tf; michael@0: uint32_t tsnlast, tsnfirst; michael@0: int recovery_cnt = 0; michael@0: michael@0: michael@0: /* none in flight now */ michael@0: audit_tf = 0; michael@0: fir = 0; michael@0: /* michael@0: * figure out how long a data chunk must be pending before we can michael@0: * mark it .. michael@0: */ michael@0: (void)SCTP_GETTIME_TIMEVAL(&now); michael@0: /* get cur rto in micro-seconds */ michael@0: cur_rto = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv; michael@0: cur_rto *= 1000; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(cur_rto, michael@0: stcb->asoc.peers_rwnd, michael@0: window_probe, michael@0: SCTP_FR_T3_MARK_TIME); michael@0: sctp_log_fr(net->flight_size, 0, 0, SCTP_FR_CWND_REPORT); michael@0: sctp_log_fr(net->flight_size, net->cwnd, stcb->asoc.total_flight, SCTP_FR_CWND_REPORT); michael@0: } michael@0: tv.tv_sec = cur_rto / 1000000; michael@0: tv.tv_usec = cur_rto % 1000000; michael@0: #ifndef __FreeBSD__ michael@0: timersub(&now, &tv, &min_wait); michael@0: #else michael@0: min_wait = now; michael@0: timevalsub(&min_wait, &tv); michael@0: #endif michael@0: if (min_wait.tv_sec < 0 || min_wait.tv_usec < 0) { michael@0: /* michael@0: * if we hit here, we don't have enough seconds on the clock michael@0: * to account for the RTO. We just let the lower seconds be michael@0: * the bounds and don't worry about it. This may mean we michael@0: * will mark a lot more than we should. michael@0: */ michael@0: min_wait.tv_sec = min_wait.tv_usec = 0; michael@0: } michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(cur_rto, now.tv_sec, now.tv_usec, SCTP_FR_T3_MARK_TIME); michael@0: sctp_log_fr(0, min_wait.tv_sec, min_wait.tv_usec, SCTP_FR_T3_MARK_TIME); michael@0: } michael@0: /* michael@0: * Our rwnd will be incorrect here since we are not adding back the michael@0: * cnt * mbuf but we will fix that down below. michael@0: */ michael@0: orig_flight = net->flight_size; michael@0: orig_tf = stcb->asoc.total_flight; michael@0: michael@0: net->fast_retran_ip = 0; michael@0: /* Now on to each chunk */ michael@0: cnt_abandoned = 0; michael@0: num_mk = cnt_mk = 0; michael@0: tsnfirst = tsnlast = 0; michael@0: #ifndef INVARIANTS michael@0: start_again: michael@0: #endif michael@0: TAILQ_FOREACH_SAFE(chk, &stcb->asoc.sent_queue, sctp_next, nchk) { michael@0: if (SCTP_TSN_GE(stcb->asoc.last_acked_seq, chk->rec.data.TSN_seq)) { michael@0: /* Strange case our list got out of order? */ michael@0: SCTP_PRINTF("Our list is out of order? last_acked:%x chk:%x\n", michael@0: (unsigned int)stcb->asoc.last_acked_seq, (unsigned int)chk->rec.data.TSN_seq); michael@0: recovery_cnt++; michael@0: #ifdef INVARIANTS michael@0: panic("last acked >= chk on sent-Q"); michael@0: #else michael@0: SCTP_PRINTF("Recover attempts a restart cnt:%d\n", recovery_cnt); michael@0: sctp_recover_sent_list(stcb); michael@0: if (recovery_cnt < 10) { michael@0: goto start_again; michael@0: } else { michael@0: SCTP_PRINTF("Recovery fails %d times??\n", recovery_cnt); michael@0: } michael@0: #endif michael@0: } michael@0: if ((chk->whoTo == net) && (chk->sent < SCTP_DATAGRAM_ACKED)) { michael@0: /* michael@0: * found one to mark: If it is less than michael@0: * DATAGRAM_ACKED it MUST not be a skipped or marked michael@0: * TSN but instead one that is either already set michael@0: * for retransmission OR one that needs michael@0: * retransmission. michael@0: */ michael@0: michael@0: /* validate its been outstanding long enough */ michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(chk->rec.data.TSN_seq, michael@0: chk->sent_rcv_time.tv_sec, michael@0: chk->sent_rcv_time.tv_usec, michael@0: SCTP_FR_T3_MARK_TIME); michael@0: } michael@0: if ((chk->sent_rcv_time.tv_sec > min_wait.tv_sec) && (window_probe == 0)) { michael@0: /* michael@0: * we have reached a chunk that was sent michael@0: * some seconds past our min.. forget it we michael@0: * will find no more to send. michael@0: */ michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(0, michael@0: chk->sent_rcv_time.tv_sec, michael@0: chk->sent_rcv_time.tv_usec, michael@0: SCTP_FR_T3_STOPPED); michael@0: } michael@0: continue; michael@0: } else if ((chk->sent_rcv_time.tv_sec == min_wait.tv_sec) && michael@0: (window_probe == 0)) { michael@0: /* michael@0: * we must look at the micro seconds to michael@0: * know. michael@0: */ michael@0: if (chk->sent_rcv_time.tv_usec >= min_wait.tv_usec) { michael@0: /* michael@0: * ok it was sent after our boundary michael@0: * time. michael@0: */ michael@0: continue; michael@0: } michael@0: } michael@0: if (stcb->asoc.peer_supports_prsctp && PR_SCTP_TTL_ENABLED(chk->flags)) { michael@0: /* Is it expired? */ michael@0: #ifndef __FreeBSD__ michael@0: if (timercmp(&now, &chk->rec.data.timetodrop, >)) { michael@0: #else michael@0: if (timevalcmp(&now, &chk->rec.data.timetodrop, >)) { michael@0: #endif michael@0: /* Yes so drop it */ michael@0: if (chk->data) { michael@0: (void)sctp_release_pr_sctp_chunk(stcb, michael@0: chk, michael@0: 1, michael@0: SCTP_SO_NOT_LOCKED); michael@0: cnt_abandoned++; michael@0: } michael@0: continue; michael@0: } michael@0: } michael@0: if (stcb->asoc.peer_supports_prsctp && PR_SCTP_RTX_ENABLED(chk->flags)) { michael@0: /* Has it been retransmitted tv_sec times? */ michael@0: if (chk->snd_count > chk->rec.data.timetodrop.tv_sec) { michael@0: if (chk->data) { michael@0: (void)sctp_release_pr_sctp_chunk(stcb, michael@0: chk, michael@0: 1, michael@0: SCTP_SO_NOT_LOCKED); michael@0: cnt_abandoned++; michael@0: } michael@0: continue; michael@0: } michael@0: } michael@0: if (chk->sent < SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: num_mk++; michael@0: if (fir == 0) { michael@0: fir = 1; michael@0: tsnfirst = chk->rec.data.TSN_seq; michael@0: } michael@0: tsnlast = chk->rec.data.TSN_seq; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(chk->rec.data.TSN_seq, chk->snd_count, michael@0: 0, SCTP_FR_T3_MARKED); michael@0: } michael@0: michael@0: if (chk->rec.data.chunk_was_revoked) { michael@0: /* deflate the cwnd */ michael@0: chk->whoTo->cwnd -= chk->book_size; michael@0: chk->rec.data.chunk_was_revoked = 0; michael@0: } michael@0: net->marked_retrans++; michael@0: stcb->asoc.marked_retrans++; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { michael@0: sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND_TO, michael@0: chk->whoTo->flight_size, michael@0: chk->book_size, michael@0: (uintptr_t)chk->whoTo, michael@0: chk->rec.data.TSN_seq); michael@0: } michael@0: sctp_flight_size_decrease(chk); michael@0: sctp_total_flight_decrease(stcb, chk); michael@0: stcb->asoc.peers_rwnd += chk->send_size; michael@0: stcb->asoc.peers_rwnd += SCTP_BASE_SYSCTL(sctp_peer_chunk_oh); michael@0: } michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: SCTP_STAT_INCR(sctps_markedretrans); michael@0: michael@0: /* reset the TSN for striking and other FR stuff */ michael@0: chk->rec.data.doing_fast_retransmit = 0; michael@0: /* Clear any time so NO RTT is being done */ michael@0: michael@0: if (chk->do_rtt) { michael@0: if (chk->whoTo->rto_needed == 0) { michael@0: chk->whoTo->rto_needed = 1; michael@0: } michael@0: } michael@0: chk->do_rtt = 0; michael@0: if (alt != net) { michael@0: sctp_free_remote_addr(chk->whoTo); michael@0: chk->no_fr_allowed = 1; michael@0: chk->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } else { michael@0: chk->no_fr_allowed = 0; michael@0: if (TAILQ_EMPTY(&stcb->asoc.send_queue)) { michael@0: chk->rec.data.fast_retran_tsn = stcb->asoc.sending_seq; michael@0: } else { michael@0: chk->rec.data.fast_retran_tsn = (TAILQ_FIRST(&stcb->asoc.send_queue))->rec.data.TSN_seq; michael@0: } michael@0: } michael@0: /* CMT: Do not allow FRs on retransmitted TSNs. michael@0: */ michael@0: if (stcb->asoc.sctp_cmt_on_off > 0) { michael@0: chk->no_fr_allowed = 1; michael@0: } michael@0: #ifdef THIS_SHOULD_NOT_BE_DONE michael@0: } else if (chk->sent == SCTP_DATAGRAM_ACKED) { michael@0: /* remember highest acked one */ michael@0: could_be_sent = chk; michael@0: #endif michael@0: } michael@0: if (chk->sent == SCTP_DATAGRAM_RESEND) { michael@0: cnt_mk++; michael@0: } michael@0: } michael@0: if ((orig_flight - net->flight_size) != (orig_tf - stcb->asoc.total_flight)) { michael@0: /* we did not subtract the same things? */ michael@0: audit_tf = 1; michael@0: } michael@0: michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(tsnfirst, tsnlast, num_mk, SCTP_FR_T3_TIMEOUT); michael@0: } michael@0: #ifdef SCTP_DEBUG michael@0: if (num_mk) { michael@0: SCTPDBG(SCTP_DEBUG_TIMER1, "LAST TSN marked was %x\n", michael@0: tsnlast); michael@0: SCTPDBG(SCTP_DEBUG_TIMER1, "Num marked for retransmission was %d peer-rwd:%ld\n", michael@0: num_mk, (u_long)stcb->asoc.peers_rwnd); michael@0: SCTPDBG(SCTP_DEBUG_TIMER1, "LAST TSN marked was %x\n", michael@0: tsnlast); michael@0: SCTPDBG(SCTP_DEBUG_TIMER1, "Num marked for retransmission was %d peer-rwd:%d\n", michael@0: num_mk, michael@0: (int)stcb->asoc.peers_rwnd); michael@0: } michael@0: #endif michael@0: *num_marked = num_mk; michael@0: *num_abandoned = cnt_abandoned; michael@0: /* Now check for a ECN Echo that may be stranded And michael@0: * include the cnt_mk'd to have all resends in the michael@0: * control queue. michael@0: */ michael@0: TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) { michael@0: if (chk->sent == SCTP_DATAGRAM_RESEND) { michael@0: cnt_mk++; michael@0: } michael@0: if ((chk->whoTo == net) && michael@0: (chk->rec.chunk_id.id == SCTP_ECN_ECHO)) { michael@0: sctp_free_remote_addr(chk->whoTo); michael@0: chk->whoTo = alt; michael@0: if (chk->sent != SCTP_DATAGRAM_RESEND) { michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: cnt_mk++; michael@0: } michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: } michael@0: #ifdef THIS_SHOULD_NOT_BE_DONE michael@0: if ((stcb->asoc.sent_queue_retran_cnt == 0) && (could_be_sent)) { michael@0: /* fix it so we retransmit the highest acked anyway */ michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: cnt_mk++; michael@0: could_be_sent->sent = SCTP_DATAGRAM_RESEND; michael@0: } michael@0: #endif michael@0: if (stcb->asoc.sent_queue_retran_cnt != cnt_mk) { michael@0: #ifdef INVARIANTS michael@0: SCTP_PRINTF("Local Audit says there are %d for retran asoc cnt:%d we marked:%d this time\n", michael@0: cnt_mk, stcb->asoc.sent_queue_retran_cnt, num_mk); michael@0: #endif michael@0: #ifndef SCTP_AUDITING_ENABLED michael@0: stcb->asoc.sent_queue_retran_cnt = cnt_mk; michael@0: #endif michael@0: } michael@0: if (audit_tf) { michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, michael@0: "Audit total flight due to negative value net:%p\n", michael@0: (void *)net); michael@0: stcb->asoc.total_flight = 0; michael@0: stcb->asoc.total_flight_count = 0; michael@0: /* Clear all networks flight size */ michael@0: TAILQ_FOREACH(lnets, &stcb->asoc.nets, sctp_next) { michael@0: lnets->flight_size = 0; michael@0: SCTPDBG(SCTP_DEBUG_TIMER4, michael@0: "Net:%p c-f cwnd:%d ssthresh:%d\n", michael@0: (void *)lnets, lnets->cwnd, lnets->ssthresh); michael@0: } michael@0: TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { michael@0: if (chk->sent < SCTP_DATAGRAM_RESEND) { michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { michael@0: sctp_misc_ints(SCTP_FLIGHT_LOG_UP, michael@0: chk->whoTo->flight_size, michael@0: chk->book_size, michael@0: (uintptr_t)chk->whoTo, michael@0: chk->rec.data.TSN_seq); michael@0: } michael@0: michael@0: sctp_flight_size_increase(chk); michael@0: sctp_total_flight_increase(stcb, chk); michael@0: } michael@0: } michael@0: } michael@0: /* We return 1 if we only have a window probe outstanding */ michael@0: return (0); michael@0: } michael@0: michael@0: michael@0: int michael@0: sctp_t3rxt_timer(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_nets *alt; michael@0: int win_probe, num_mk, num_abandoned; michael@0: michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { michael@0: sctp_log_fr(0, 0, 0, SCTP_FR_T3_TIMEOUT); michael@0: } michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) { michael@0: struct sctp_nets *lnet; michael@0: michael@0: TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) { michael@0: if (net == lnet) { michael@0: sctp_log_cwnd(stcb, lnet, 1, SCTP_CWND_LOG_FROM_T3); michael@0: } else { michael@0: sctp_log_cwnd(stcb, lnet, 0, SCTP_CWND_LOG_FROM_T3); michael@0: } michael@0: } michael@0: } michael@0: /* Find an alternate and mark those for retransmission */ michael@0: if ((stcb->asoc.peers_rwnd == 0) && michael@0: (stcb->asoc.total_flight < net->mtu)) { michael@0: SCTP_STAT_INCR(sctps_timowindowprobe); michael@0: win_probe = 1; michael@0: } else { michael@0: win_probe = 0; michael@0: } michael@0: michael@0: if (win_probe == 0) { michael@0: /* We don't do normal threshold management on window probes */ michael@0: if (sctp_threshold_management(inp, stcb, net, michael@0: stcb->asoc.max_send_times)) { michael@0: /* Association was destroyed */ michael@0: return (1); michael@0: } else { michael@0: if (net != stcb->asoc.primary_destination) { michael@0: /* send a immediate HB if our RTO is stale */ michael@0: struct timeval now; michael@0: unsigned int ms_goneby; michael@0: michael@0: (void)SCTP_GETTIME_TIMEVAL(&now); michael@0: if (net->last_sent_time.tv_sec) { michael@0: ms_goneby = (now.tv_sec - net->last_sent_time.tv_sec) * 1000; michael@0: } else { michael@0: ms_goneby = 0; michael@0: } michael@0: if ((net->dest_state & SCTP_ADDR_PF) == 0) { michael@0: if ((ms_goneby > net->RTO) || (net->RTO == 0)) { michael@0: /* michael@0: * no recent feed back in an RTO or michael@0: * more, request a RTT update michael@0: */ michael@0: sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: /* michael@0: * For a window probe we don't penalize the net's but only michael@0: * the association. This may fail it if SACKs are not coming michael@0: * back. If sack's are coming with rwnd locked at 0, we will michael@0: * continue to hold things waiting for rwnd to raise michael@0: */ michael@0: if (sctp_threshold_management(inp, stcb, NULL, michael@0: stcb->asoc.max_send_times)) { michael@0: /* Association was destroyed */ michael@0: return (1); michael@0: } michael@0: } michael@0: if (stcb->asoc.sctp_cmt_on_off > 0) { michael@0: if (net->pf_threshold < net->failure_threshold) { michael@0: alt = sctp_find_alternate_net(stcb, net, 2); michael@0: } else { michael@0: /* michael@0: * CMT: Using RTX_SSTHRESH policy for CMT. michael@0: * If CMT is being used, then pick dest with michael@0: * largest ssthresh for any retransmission. michael@0: */ michael@0: alt = sctp_find_alternate_net(stcb, net, 1); michael@0: /* michael@0: * CUCv2: If a different dest is picked for michael@0: * the retransmission, then new michael@0: * (rtx-)pseudo_cumack needs to be tracked michael@0: * for orig dest. Let CUCv2 track new (rtx-) michael@0: * pseudo-cumack always. michael@0: */ michael@0: net->find_pseudo_cumack = 1; michael@0: net->find_rtx_pseudo_cumack = 1; michael@0: } michael@0: } else { michael@0: alt = sctp_find_alternate_net(stcb, net, 0); michael@0: } michael@0: michael@0: num_mk = 0; michael@0: num_abandoned = 0; michael@0: (void)sctp_mark_all_for_resend(stcb, net, alt, win_probe, michael@0: &num_mk, &num_abandoned); michael@0: /* FR Loss recovery just ended with the T3. */ michael@0: stcb->asoc.fast_retran_loss_recovery = 0; michael@0: michael@0: /* CMT FR loss recovery ended with the T3 */ michael@0: net->fast_retran_loss_recovery = 0; michael@0: if ((stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) && michael@0: (net->flight_size == 0)) { michael@0: (*stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins)(stcb, net); michael@0: } michael@0: michael@0: /* michael@0: * setup the sat loss recovery that prevents satellite cwnd advance. michael@0: */ michael@0: stcb->asoc.sat_t3_loss_recovery = 1; michael@0: stcb->asoc.sat_t3_recovery_tsn = stcb->asoc.sending_seq; michael@0: michael@0: /* Backoff the timer and cwnd */ michael@0: sctp_backoff_on_timeout(stcb, net, win_probe, num_mk, num_abandoned); michael@0: if ((!(net->dest_state & SCTP_ADDR_REACHABLE)) || michael@0: (net->dest_state & SCTP_ADDR_PF)) { michael@0: /* Move all pending over too */ michael@0: sctp_move_chunks_from_net(stcb, net); michael@0: michael@0: /* Get the address that failed, to michael@0: * force a new src address selecton and michael@0: * a route allocation. michael@0: */ michael@0: if (net->ro._s_addr) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: } michael@0: net->src_addr_selected = 0; michael@0: michael@0: /* Force a route allocation too */ michael@0: if (net->ro.ro_rt) { michael@0: RTFREE(net->ro.ro_rt); michael@0: net->ro.ro_rt = NULL; michael@0: } michael@0: michael@0: /* Was it our primary? */ michael@0: if ((stcb->asoc.primary_destination == net) && (alt != net)) { michael@0: /* michael@0: * Yes, note it as such and find an alternate note: michael@0: * this means HB code must use this to resent the michael@0: * primary if it goes active AND if someone does a michael@0: * change-primary then this flag must be cleared michael@0: * from any net structures. michael@0: */ michael@0: if (stcb->asoc.alternate) { michael@0: sctp_free_remote_addr(stcb->asoc.alternate); michael@0: } michael@0: stcb->asoc.alternate = alt; michael@0: atomic_add_int(&stcb->asoc.alternate->ref_count, 1); michael@0: } michael@0: } michael@0: /* michael@0: * Special case for cookie-echo'ed case, we don't do output but must michael@0: * await the COOKIE-ACK before retransmission michael@0: */ michael@0: if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) { michael@0: /* michael@0: * Here we just reset the timer and start again since we michael@0: * have not established the asoc michael@0: */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net); michael@0: return (0); michael@0: } michael@0: if (stcb->asoc.peer_supports_prsctp) { michael@0: struct sctp_tmit_chunk *lchk; michael@0: michael@0: lchk = sctp_try_advance_peer_ack_point(stcb, &stcb->asoc); michael@0: /* C3. See if we need to send a Fwd-TSN */ michael@0: if (SCTP_TSN_GT(stcb->asoc.advanced_peer_ack_point, stcb->asoc.last_acked_seq)) { michael@0: send_forward_tsn(stcb, &stcb->asoc); michael@0: if (lchk) { michael@0: /* Assure a timer is up */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, lchk->whoTo); michael@0: } michael@0: } michael@0: } michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { michael@0: sctp_log_cwnd(stcb, net, net->cwnd, SCTP_CWND_LOG_FROM_RTX); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: sctp_t1init_timer(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: /* bump the thresholds */ michael@0: if (stcb->asoc.delayed_connection) { michael@0: /* michael@0: * special hook for delayed connection. The library did NOT michael@0: * complete the rest of its sends. michael@0: */ michael@0: stcb->asoc.delayed_connection = 0; michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_NOT_LOCKED); michael@0: return (0); michael@0: } michael@0: if (SCTP_GET_STATE((&stcb->asoc)) != SCTP_STATE_COOKIE_WAIT) { michael@0: return (0); michael@0: } michael@0: if (sctp_threshold_management(inp, stcb, net, michael@0: stcb->asoc.max_init_times)) { michael@0: /* Association was destroyed */ michael@0: return (1); michael@0: } michael@0: stcb->asoc.dropped_special_cnt = 0; michael@0: sctp_backoff_on_timeout(stcb, stcb->asoc.primary_destination, 1, 0, 0); michael@0: if (stcb->asoc.initial_init_rto_max < net->RTO) { michael@0: net->RTO = stcb->asoc.initial_init_rto_max; michael@0: } michael@0: if (stcb->asoc.numnets > 1) { michael@0: /* If we have more than one addr use it */ michael@0: struct sctp_nets *alt; michael@0: michael@0: alt = sctp_find_alternate_net(stcb, stcb->asoc.primary_destination, 0); michael@0: if (alt != stcb->asoc.primary_destination) { michael@0: sctp_move_chunks_from_net(stcb, stcb->asoc.primary_destination); michael@0: stcb->asoc.primary_destination = alt; michael@0: } michael@0: } michael@0: /* Send out a new init */ michael@0: sctp_send_initiate(inp, stcb, SCTP_SO_NOT_LOCKED); michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * For cookie and asconf we actually need to find and mark for resend, then michael@0: * increment the resend counter (after all the threshold management stuff of michael@0: * course). michael@0: */ michael@0: int michael@0: sctp_cookie_timer(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net SCTP_UNUSED) michael@0: { michael@0: struct sctp_nets *alt; michael@0: struct sctp_tmit_chunk *cookie; michael@0: michael@0: /* first before all else we must find the cookie */ michael@0: TAILQ_FOREACH(cookie, &stcb->asoc.control_send_queue, sctp_next) { michael@0: if (cookie->rec.chunk_id.id == SCTP_COOKIE_ECHO) { michael@0: break; michael@0: } michael@0: } michael@0: if (cookie == NULL) { michael@0: if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) { michael@0: /* FOOBAR! */ michael@0: struct mbuf *oper; michael@0: michael@0: oper = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (oper) { michael@0: struct sctp_paramhdr *ph; michael@0: uint32_t *ippp; michael@0: michael@0: SCTP_BUF_LEN(oper) = sizeof(struct sctp_paramhdr) + michael@0: sizeof(uint32_t); michael@0: ph = mtod(oper, struct sctp_paramhdr *); michael@0: ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); michael@0: ph->param_length = htons(SCTP_BUF_LEN(oper)); michael@0: ippp = (uint32_t *) (ph + 1); michael@0: *ippp = htonl(SCTP_FROM_SCTP_TIMER+SCTP_LOC_3); michael@0: } michael@0: inp->last_abort_code = SCTP_FROM_SCTP_TIMER+SCTP_LOC_4; michael@0: sctp_abort_an_association(inp, stcb, oper, SCTP_SO_NOT_LOCKED); michael@0: } else { michael@0: #ifdef INVARIANTS michael@0: panic("Cookie timer expires in wrong state?"); michael@0: #else michael@0: SCTP_PRINTF("Strange in state %d not cookie-echoed yet c-e timer expires?\n", SCTP_GET_STATE(&stcb->asoc)); michael@0: return (0); michael@0: #endif michael@0: } michael@0: return (0); michael@0: } michael@0: /* Ok we found the cookie, threshold management next */ michael@0: if (sctp_threshold_management(inp, stcb, cookie->whoTo, michael@0: stcb->asoc.max_init_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: /* michael@0: * cleared theshold management now lets backoff the address & select michael@0: * an alternate michael@0: */ michael@0: stcb->asoc.dropped_special_cnt = 0; michael@0: sctp_backoff_on_timeout(stcb, cookie->whoTo, 1, 0, 0); michael@0: alt = sctp_find_alternate_net(stcb, cookie->whoTo, 0); michael@0: if (alt != cookie->whoTo) { michael@0: sctp_free_remote_addr(cookie->whoTo); michael@0: cookie->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: /* Now mark the retran info */ michael@0: if (cookie->sent != SCTP_DATAGRAM_RESEND) { michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: } michael@0: cookie->sent = SCTP_DATAGRAM_RESEND; michael@0: /* michael@0: * Now call the output routine to kick out the cookie again, Note we michael@0: * don't mark any chunks for retran so that FR will need to kick in michael@0: * to move these (or a send timer). michael@0: */ michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_nets *alt; michael@0: struct sctp_tmit_chunk *strrst = NULL, *chk = NULL; michael@0: michael@0: if (stcb->asoc.stream_reset_outstanding == 0) { michael@0: return (0); michael@0: } michael@0: /* find the existing STRRESET, we use the seq number we sent out on */ michael@0: (void)sctp_find_stream_reset(stcb, stcb->asoc.str_reset_seq_out, &strrst); michael@0: if (strrst == NULL) { michael@0: return (0); michael@0: } michael@0: /* do threshold management */ michael@0: if (sctp_threshold_management(inp, stcb, strrst->whoTo, michael@0: stcb->asoc.max_send_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: /* michael@0: * cleared theshold management now lets backoff the address & select michael@0: * an alternate michael@0: */ michael@0: sctp_backoff_on_timeout(stcb, strrst->whoTo, 1, 0, 0); michael@0: alt = sctp_find_alternate_net(stcb, strrst->whoTo, 0); michael@0: sctp_free_remote_addr(strrst->whoTo); michael@0: strrst->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: michael@0: /* See if a ECN Echo is also stranded */ michael@0: TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) { michael@0: if ((chk->whoTo == net) && michael@0: (chk->rec.chunk_id.id == SCTP_ECN_ECHO)) { michael@0: sctp_free_remote_addr(chk->whoTo); michael@0: if (chk->sent != SCTP_DATAGRAM_RESEND) { michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: } michael@0: chk->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: } michael@0: if (!(net->dest_state & SCTP_ADDR_REACHABLE)) { michael@0: /* michael@0: * If the address went un-reachable, we need to move to michael@0: * alternates for ALL chk's in queue michael@0: */ michael@0: sctp_move_chunks_from_net(stcb, net); michael@0: } michael@0: /* mark the retran info */ michael@0: if (strrst->sent != SCTP_DATAGRAM_RESEND) michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: strrst->sent = SCTP_DATAGRAM_RESEND; michael@0: michael@0: /* restart the timer */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, strrst->whoTo); michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_nets *alt; michael@0: struct sctp_tmit_chunk *asconf, *chk; michael@0: michael@0: /* is this a first send, or a retransmission? */ michael@0: if (TAILQ_EMPTY(&stcb->asoc.asconf_send_queue)) { michael@0: /* compose a new ASCONF chunk and send it */ michael@0: sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); michael@0: } else { michael@0: /* michael@0: * Retransmission of the existing ASCONF is needed michael@0: */ michael@0: michael@0: /* find the existing ASCONF */ michael@0: asconf = TAILQ_FIRST(&stcb->asoc.asconf_send_queue); michael@0: if (asconf == NULL) { michael@0: return (0); michael@0: } michael@0: /* do threshold management */ michael@0: if (sctp_threshold_management(inp, stcb, asconf->whoTo, michael@0: stcb->asoc.max_send_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: if (asconf->snd_count > stcb->asoc.max_send_times) { michael@0: /* michael@0: * Something is rotten: our peer is not responding to michael@0: * ASCONFs but apparently is to other chunks. i.e. it michael@0: * is not properly handling the chunk type upper bits. michael@0: * Mark this peer as ASCONF incapable and cleanup. michael@0: */ michael@0: SCTPDBG(SCTP_DEBUG_TIMER1, "asconf_timer: Peer has not responded to our repeated ASCONFs\n"); michael@0: sctp_asconf_cleanup(stcb, net); michael@0: return (0); michael@0: } michael@0: /* michael@0: * cleared threshold management, so now backoff the net and michael@0: * select an alternate michael@0: */ michael@0: sctp_backoff_on_timeout(stcb, asconf->whoTo, 1, 0, 0); michael@0: alt = sctp_find_alternate_net(stcb, asconf->whoTo, 0); michael@0: if (asconf->whoTo != alt) { michael@0: sctp_free_remote_addr(asconf->whoTo); michael@0: asconf->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: michael@0: /* See if an ECN Echo is also stranded */ michael@0: TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) { michael@0: if ((chk->whoTo == net) && michael@0: (chk->rec.chunk_id.id == SCTP_ECN_ECHO)) { michael@0: sctp_free_remote_addr(chk->whoTo); michael@0: chk->whoTo = alt; michael@0: if (chk->sent != SCTP_DATAGRAM_RESEND) { michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: } michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: } michael@0: TAILQ_FOREACH(chk, &stcb->asoc.asconf_send_queue, sctp_next) { michael@0: if (chk->whoTo != alt) { michael@0: sctp_free_remote_addr(chk->whoTo); michael@0: chk->whoTo = alt; michael@0: atomic_add_int(&alt->ref_count, 1); michael@0: } michael@0: if (asconf->sent != SCTP_DATAGRAM_RESEND && chk->sent != SCTP_DATAGRAM_UNSENT) michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: } michael@0: if (!(net->dest_state & SCTP_ADDR_REACHABLE)) { michael@0: /* michael@0: * If the address went un-reachable, we need to move michael@0: * to the alternate for ALL chunks in queue michael@0: */ michael@0: sctp_move_chunks_from_net(stcb, net); michael@0: } michael@0: /* mark the retran info */ michael@0: if (asconf->sent != SCTP_DATAGRAM_RESEND) michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: asconf->sent = SCTP_DATAGRAM_RESEND; michael@0: michael@0: /* send another ASCONF if any and we can do */ michael@0: sctp_send_asconf(stcb, alt, SCTP_ADDR_NOT_LOCKED); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: /* Mobility adaptation */ michael@0: void michael@0: sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net SCTP_UNUSED) michael@0: { michael@0: if (stcb->asoc.deleted_primary == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "delete_prim_timer: deleted_primary is not stored...\n"); michael@0: sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED); michael@0: return; michael@0: } michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "delete_prim_timer: finished to keep deleted primary "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa); michael@0: sctp_free_remote_addr(stcb->asoc.deleted_primary); michael@0: stcb->asoc.deleted_primary = NULL; michael@0: sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED); michael@0: return; michael@0: } michael@0: michael@0: /* michael@0: * For the shutdown and shutdown-ack, we do not keep one around on the michael@0: * control queue. This means we must generate a new one and call the general michael@0: * chunk output routine, AFTER having done threshold management. michael@0: * It is assumed that net is non-NULL. michael@0: */ michael@0: int michael@0: sctp_shutdown_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_nets *alt; michael@0: michael@0: /* first threshold managment */ michael@0: if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: sctp_backoff_on_timeout(stcb, net, 1, 0, 0); michael@0: /* second select an alternative */ michael@0: alt = sctp_find_alternate_net(stcb, net, 0); michael@0: michael@0: /* third generate a shutdown into the queue for out net */ michael@0: sctp_send_shutdown(stcb, alt); michael@0: michael@0: /* fourth restart timer */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, inp, stcb, alt); michael@0: return (0); michael@0: } michael@0: michael@0: int michael@0: sctp_shutdownack_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_nets *alt; michael@0: michael@0: /* first threshold managment */ michael@0: if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: sctp_backoff_on_timeout(stcb, net, 1, 0, 0); michael@0: /* second select an alternative */ michael@0: alt = sctp_find_alternate_net(stcb, net, 0); michael@0: michael@0: /* third generate a shutdown into the queue for out net */ michael@0: sctp_send_shutdown_ack(stcb, alt); michael@0: michael@0: /* fourth restart timer */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, inp, stcb, alt); michael@0: return (0); michael@0: } michael@0: michael@0: static void michael@0: sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb) michael@0: { michael@0: struct sctp_stream_queue_pending *sp; michael@0: unsigned int i, chks_in_queue = 0; michael@0: int being_filled = 0; michael@0: /* michael@0: * This function is ONLY called when the send/sent queues are empty. michael@0: */ michael@0: if ((stcb == NULL) || (inp == NULL)) michael@0: return; michael@0: michael@0: if (stcb->asoc.sent_queue_retran_cnt) { michael@0: SCTP_PRINTF("Hmm, sent_queue_retran_cnt is non-zero %d\n", michael@0: stcb->asoc.sent_queue_retran_cnt); michael@0: stcb->asoc.sent_queue_retran_cnt = 0; michael@0: } michael@0: if (stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, &stcb->asoc)) { michael@0: /* No stream scheduler information, initialize scheduler */ michael@0: stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 0); michael@0: if (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, &stcb->asoc)) { michael@0: /* yep, we lost a stream or two */ michael@0: SCTP_PRINTF("Found additional streams NOT managed by scheduler, corrected\n"); michael@0: } else { michael@0: /* no streams lost */ michael@0: stcb->asoc.total_output_queue_size = 0; michael@0: } michael@0: } michael@0: /* Check to see if some data queued, if so report it */ michael@0: for (i = 0; i < stcb->asoc.streamoutcnt; i++) { michael@0: if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) { michael@0: TAILQ_FOREACH(sp, &stcb->asoc.strmout[i].outqueue, next) { michael@0: if (sp->msg_is_complete) michael@0: being_filled++; michael@0: chks_in_queue++; michael@0: } michael@0: } michael@0: } michael@0: if (chks_in_queue != stcb->asoc.stream_queue_cnt) { michael@0: SCTP_PRINTF("Hmm, stream queue cnt at %d I counted %d in stream out wheel\n", michael@0: stcb->asoc.stream_queue_cnt, chks_in_queue); michael@0: } michael@0: if (chks_in_queue) { michael@0: /* call the output queue function */ michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); michael@0: if ((TAILQ_EMPTY(&stcb->asoc.send_queue)) && michael@0: (TAILQ_EMPTY(&stcb->asoc.sent_queue))) { michael@0: /* michael@0: * Probably should go in and make it go back through michael@0: * and add fragments allowed michael@0: */ michael@0: if (being_filled == 0) { michael@0: SCTP_PRINTF("Still nothing moved %d chunks are stuck\n", michael@0: chks_in_queue); michael@0: } michael@0: } michael@0: } else { michael@0: SCTP_PRINTF("Found no chunks on any queue tot:%lu\n", michael@0: (u_long)stcb->asoc.total_output_queue_size); michael@0: stcb->asoc.total_output_queue_size = 0; michael@0: } michael@0: } michael@0: michael@0: int michael@0: sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: uint8_t net_was_pf; michael@0: michael@0: if (net->dest_state & SCTP_ADDR_PF) { michael@0: net_was_pf = 1; michael@0: } else { michael@0: net_was_pf = 0; michael@0: } michael@0: if (net->hb_responded == 0) { michael@0: if (net->ro._s_addr) { michael@0: /* Invalidate the src address if we did not get michael@0: * a response last time. michael@0: */ michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: } michael@0: sctp_backoff_on_timeout(stcb, net, 1, 0, 0); michael@0: if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) { michael@0: /* Assoc is over */ michael@0: return (1); michael@0: } michael@0: } michael@0: /* Zero PBA, if it needs it */ michael@0: if (net->partial_bytes_acked) { michael@0: net->partial_bytes_acked = 0; michael@0: } michael@0: if ((stcb->asoc.total_output_queue_size > 0) && michael@0: (TAILQ_EMPTY(&stcb->asoc.send_queue)) && michael@0: (TAILQ_EMPTY(&stcb->asoc.sent_queue))) { michael@0: sctp_audit_stream_queues_for_size(inp, stcb); michael@0: } michael@0: if (!(net->dest_state & SCTP_ADDR_NOHB) && michael@0: !((net_was_pf == 0) && (net->dest_state & SCTP_ADDR_PF))) { michael@0: /* when move to PF during threshold mangement, a HB has been michael@0: queued in that routine */ michael@0: uint32_t ms_gone_by; michael@0: michael@0: if ((net->last_sent_time.tv_sec > 0) || michael@0: (net->last_sent_time.tv_usec > 0)) { michael@0: #ifdef __FreeBSD__ michael@0: struct timeval diff; michael@0: michael@0: SCTP_GETTIME_TIMEVAL(&diff); michael@0: timevalsub(&diff, &net->last_sent_time); michael@0: #else michael@0: struct timeval diff, now; michael@0: michael@0: SCTP_GETTIME_TIMEVAL(&now); michael@0: timersub(&now, &net->last_sent_time, &diff); michael@0: #endif michael@0: ms_gone_by = (uint32_t)(diff.tv_sec * 1000) + michael@0: (uint32_t)(diff.tv_usec / 1000); michael@0: } else { michael@0: ms_gone_by = 0xffffffff; michael@0: } michael@0: if ((ms_gone_by >= net->heart_beat_delay) || michael@0: (net->dest_state & SCTP_ADDR_PF)) { michael@0: sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: void michael@0: sctp_pathmtu_timer(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: uint32_t next_mtu, mtu; michael@0: michael@0: next_mtu = sctp_get_next_mtu(net->mtu); michael@0: michael@0: if ((next_mtu > net->mtu) && (net->port == 0)) { michael@0: if ((net->src_addr_selected == 0) || michael@0: (net->ro._s_addr == NULL) || michael@0: (net->ro._s_addr->localifa_flags & SCTP_BEING_DELETED)) { michael@0: if ((net->ro._s_addr != NULL) && (net->ro._s_addr->localifa_flags & SCTP_BEING_DELETED)) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: } else if (net->ro._s_addr == NULL) { michael@0: #if defined(INET6) && defined(SCTP_EMBEDDED_V6_SCOPE) michael@0: if (net->ro._l_addr.sa.sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; michael@0: /* KAME hack: embed scopeid */ michael@0: #if defined(__APPLE__) michael@0: #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) michael@0: (void)in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL); michael@0: #else michael@0: (void)in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL, NULL); michael@0: #endif michael@0: #elif defined(SCTP_KAME) michael@0: (void)sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone)); michael@0: #else michael@0: (void)in6_embedscope(&sin6->sin6_addr, sin6); michael@0: #endif michael@0: } michael@0: #endif michael@0: michael@0: net->ro._s_addr = sctp_source_address_selection(inp, michael@0: stcb, michael@0: (sctp_route_t *)&net->ro, michael@0: net, 0, stcb->asoc.vrf_id); michael@0: #if defined(INET6) && defined(SCTP_EMBEDDED_V6_SCOPE) michael@0: if (net->ro._l_addr.sa.sa_family == AF_INET6) { michael@0: struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; michael@0: #ifdef SCTP_KAME michael@0: (void)sa6_recoverscope(sin6); michael@0: #else michael@0: (void)in6_recoverscope(sin6, &sin6->sin6_addr, NULL); michael@0: #endif /* SCTP_KAME */ michael@0: } michael@0: #endif /* INET6 */ michael@0: } michael@0: if (net->ro._s_addr) michael@0: net->src_addr_selected = 1; michael@0: } michael@0: if (net->ro._s_addr) { michael@0: mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._s_addr.sa, net->ro.ro_rt); michael@0: if (net->port) { michael@0: mtu -= sizeof(struct udphdr); michael@0: } michael@0: if (mtu > next_mtu) { michael@0: net->mtu = next_mtu; michael@0: } michael@0: } michael@0: } michael@0: /* restart the timer */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); michael@0: } michael@0: michael@0: void michael@0: sctp_autoclose_timer(struct sctp_inpcb *inp, michael@0: struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct timeval tn, *tim_touse; michael@0: struct sctp_association *asoc; michael@0: int ticks_gone_by; michael@0: michael@0: (void)SCTP_GETTIME_TIMEVAL(&tn); michael@0: if (stcb->asoc.sctp_autoclose_ticks && michael@0: sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) { michael@0: /* Auto close is on */ michael@0: asoc = &stcb->asoc; michael@0: /* pick the time to use */ michael@0: if (asoc->time_last_rcvd.tv_sec > michael@0: asoc->time_last_sent.tv_sec) { michael@0: tim_touse = &asoc->time_last_rcvd; michael@0: } else { michael@0: tim_touse = &asoc->time_last_sent; michael@0: } michael@0: /* Now has long enough transpired to autoclose? */ michael@0: ticks_gone_by = SEC_TO_TICKS(tn.tv_sec - tim_touse->tv_sec); michael@0: if ((ticks_gone_by > 0) && michael@0: (ticks_gone_by >= (int)asoc->sctp_autoclose_ticks)) { michael@0: /* michael@0: * autoclose time has hit, call the output routine, michael@0: * which should do nothing just to be SURE we don't michael@0: * have hanging data. We can then safely check the michael@0: * queues and know that we are clear to send michael@0: * shutdown michael@0: */ michael@0: sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_AUTOCLOSE_TMR, SCTP_SO_NOT_LOCKED); michael@0: /* Are we clean? */ michael@0: if (TAILQ_EMPTY(&asoc->send_queue) && michael@0: TAILQ_EMPTY(&asoc->sent_queue)) { michael@0: /* michael@0: * there is nothing queued to send, so I'm michael@0: * done... michael@0: */ michael@0: if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) { michael@0: /* only send SHUTDOWN 1st time thru */ michael@0: struct sctp_nets *netp; michael@0: michael@0: if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) || michael@0: (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { michael@0: SCTP_STAT_DECR_GAUGE32(sctps_currestab); michael@0: } michael@0: SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT); michael@0: SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); michael@0: sctp_stop_timers_for_shutdown(stcb); michael@0: if (stcb->asoc.alternate) { michael@0: netp = stcb->asoc.alternate; michael@0: } else { michael@0: netp = stcb->asoc.primary_destination; michael@0: } michael@0: sctp_send_shutdown(stcb, netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, michael@0: stcb->sctp_ep, stcb, michael@0: netp); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, michael@0: stcb->sctp_ep, stcb, michael@0: netp); michael@0: } michael@0: } michael@0: } else { michael@0: /* michael@0: * No auto close at this time, reset t-o to check michael@0: * later michael@0: */ michael@0: int tmp; michael@0: michael@0: /* fool the timer startup to use the time left */ michael@0: tmp = asoc->sctp_autoclose_ticks; michael@0: asoc->sctp_autoclose_ticks -= ticks_gone_by; michael@0: sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb, michael@0: net); michael@0: /* restore the real tick value */ michael@0: asoc->sctp_autoclose_ticks = tmp; michael@0: } michael@0: } michael@0: } michael@0: