2007-06-20 19:29:17 +04:00
|
|
|
/* $NetBSD: tcp_timer.c,v 1.77 2007/06/20 15:29:18 christos Exp $ */
|
1999-07-01 12:12:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2002-06-09 20:33:36 +04:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2002-06-09 20:33:36 +04:00
|
|
|
*
|
1999-07-01 12:12:45 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1998-02-19 05:36:42 +03:00
|
|
|
|
|
|
|
/*-
|
2005-03-02 13:20:18 +03:00
|
|
|
* Copyright (c) 1997, 1998, 2001, 2005 The NetBSD Foundation, Inc.
|
1998-02-19 05:36:42 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
|
|
|
|
* Facility, NASA Ames Research Center.
|
2005-03-02 13:20:18 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
1998-02-19 05:36:42 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1998-01-05 13:31:44 +03:00
|
|
|
* Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
|
1994-05-13 10:02:48 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-01-05 13:31:44 +03:00
|
|
|
* @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:32:34 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-06-20 19:29:17 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.77 2007/06/20 15:29:18 christos Exp $");
|
2001-11-13 03:32:34 +03:00
|
|
|
|
1999-07-01 12:12:45 +04:00
|
|
|
#include "opt_inet.h"
|
2001-09-11 00:15:14 +04:00
|
|
|
#include "opt_tcp_debug.h"
|
1999-07-01 12:12:45 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
2001-09-10 08:24:24 +04:00
|
|
|
#include <sys/kernel.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/ip_var.h>
|
2005-07-19 21:00:02 +04:00
|
|
|
#include <netinet/ip_icmp.h>
|
1999-07-01 12:12:45 +04:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#ifndef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet6/in6_pcb.h>
|
|
|
|
#endif
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/tcp_fsm.h>
|
|
|
|
#include <netinet/tcp_seq.h>
|
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
2006-10-09 20:27:07 +04:00
|
|
|
#include <netinet/tcp_congctl.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netinet/tcpip.h>
|
2001-09-11 00:15:14 +04:00
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
#include <netinet/tcp_debug.h>
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-09-11 00:36:43 +04:00
|
|
|
/*
|
|
|
|
* Various tunable timer parameters. These are initialized in tcp_init(),
|
|
|
|
* unless they are patched.
|
|
|
|
*/
|
2007-06-20 19:29:17 +04:00
|
|
|
u_int tcp_keepinit = 0;
|
|
|
|
u_int tcp_keepidle = 0;
|
|
|
|
u_int tcp_keepintvl = 0;
|
|
|
|
u_int tcp_keepcnt = 0; /* max idle probes */
|
|
|
|
|
2001-09-11 00:36:43 +04:00
|
|
|
int tcp_maxpersistidle = 0; /* max idle time in persist */
|
1997-12-17 09:04:17 +03:00
|
|
|
|
2001-09-10 08:24:24 +04:00
|
|
|
/*
|
|
|
|
* Time to delay the ACK. This is initialized in tcp_init(), unless
|
|
|
|
* its patched.
|
|
|
|
*/
|
|
|
|
int tcp_delack_ticks = 0;
|
1997-12-31 06:31:23 +03:00
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
void tcp_timer_rexmt(void *);
|
|
|
|
void tcp_timer_persist(void *);
|
|
|
|
void tcp_timer_keep(void *);
|
|
|
|
void tcp_timer_2msl(void *);
|
|
|
|
|
2001-11-04 16:42:27 +03:00
|
|
|
const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS] = {
|
2001-09-11 00:15:14 +04:00
|
|
|
tcp_timer_rexmt,
|
|
|
|
tcp_timer_persist,
|
|
|
|
tcp_timer_keep,
|
|
|
|
tcp_timer_2msl,
|
|
|
|
};
|
|
|
|
|
2001-09-11 00:36:43 +04:00
|
|
|
/*
|
|
|
|
* Timer state initialization, called from tcp_init().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tcp_timer_init(void)
|
|
|
|
{
|
|
|
|
|
2007-06-20 19:29:17 +04:00
|
|
|
if (tcp_keepinit == 0)
|
|
|
|
tcp_keepinit = TCPTV_KEEP_INIT;
|
|
|
|
|
2001-09-11 00:36:43 +04:00
|
|
|
if (tcp_keepidle == 0)
|
|
|
|
tcp_keepidle = TCPTV_KEEP_IDLE;
|
|
|
|
|
|
|
|
if (tcp_keepintvl == 0)
|
|
|
|
tcp_keepintvl = TCPTV_KEEPINTVL;
|
|
|
|
|
|
|
|
if (tcp_keepcnt == 0)
|
|
|
|
tcp_keepcnt = TCPTV_KEEPCNT;
|
|
|
|
|
|
|
|
if (tcp_maxpersistidle == 0)
|
|
|
|
tcp_maxpersistidle = TCPTV_KEEP_IDLE;
|
|
|
|
|
|
|
|
if (tcp_delack_ticks == 0)
|
|
|
|
tcp_delack_ticks = TCP_DELACK_TICKS;
|
|
|
|
}
|
|
|
|
|
2003-07-20 20:35:07 +04:00
|
|
|
/*
|
|
|
|
* Return how many timers are currently being invoked.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
tcp_timers_invoking(struct tcpcb *tp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < TCPT_NTIMERS; i++)
|
|
|
|
if (callout_invoking(&tp->t_timer[i]))
|
|
|
|
count++;
|
|
|
|
if (callout_invoking(&tp->t_delack_ch))
|
|
|
|
count++;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2001-09-10 08:24:24 +04:00
|
|
|
* Callout to process delayed ACKs for a TCPCB.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-01-09 02:07:16 +03:00
|
|
|
void
|
2001-09-10 08:24:24 +04:00
|
|
|
tcp_delack(void *arg)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-09-10 08:24:24 +04:00
|
|
|
struct tcpcb *tp = arg;
|
1995-06-12 04:46:47 +04:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-09-10 08:24:24 +04:00
|
|
|
/*
|
|
|
|
* If tcp_output() wasn't able to transmit the ACK
|
|
|
|
* for whatever reason, it will restart the delayed
|
|
|
|
* ACK callout.
|
|
|
|
*/
|
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
2003-07-20 20:35:07 +04:00
|
|
|
callout_ack(&tp->t_delack_ch);
|
|
|
|
if (tcp_isdead(tp)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-10 08:24:24 +04:00
|
|
|
tp->t_flags |= TF_ACKNOW;
|
|
|
|
(void) tcp_output(tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tcp protocol timeout routine called every 500 ms.
|
|
|
|
* Updates the timers in all active tcb's and
|
|
|
|
* causes finite state machine actions if timers expire.
|
|
|
|
*/
|
1994-01-09 02:07:16 +03:00
|
|
|
void
|
2005-02-04 02:50:33 +03:00
|
|
|
tcp_slowtimo(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-09-11 02:14:26 +04:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-08-13 03:59:09 +04:00
|
|
|
s = splsoftnet();
|
1997-10-13 04:46:08 +04:00
|
|
|
tcp_iss_seq += TCP_ISSINCR; /* increment iss */
|
1994-05-13 10:02:48 +04:00
|
|
|
tcp_now++; /* for timestamps */
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel all timers for TCP tp.
|
|
|
|
*/
|
1994-01-09 02:07:16 +03:00
|
|
|
void
|
2005-02-04 02:50:33 +03:00
|
|
|
tcp_canceltimers(struct tcpcb *tp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (i = 0; i < TCPT_NTIMERS; i++)
|
1998-05-06 05:21:20 +04:00
|
|
|
TCP_TIMER_DISARM(tp, i);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2001-11-04 16:42:27 +03:00
|
|
|
const int tcp_backoff[TCP_MAXRXTSHIFT + 1] =
|
1993-03-21 12:45:37 +03:00
|
|
|
{ 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
|
|
|
|
|
2001-11-04 16:42:27 +03:00
|
|
|
const int tcp_totbackoff = 511; /* sum of tcp_backoff[] */
|
1997-12-17 09:04:17 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* TCP timer processing.
|
|
|
|
*/
|
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
void
|
|
|
|
tcp_timer_rexmt(void *arg)
|
|
|
|
{
|
|
|
|
struct tcpcb *tp = arg;
|
|
|
|
uint32_t rto;
|
|
|
|
int s;
|
|
|
|
#ifdef TCP_DEBUG
|
2003-10-27 10:43:01 +03:00
|
|
|
struct socket *so = NULL;
|
2001-09-11 00:15:14 +04:00
|
|
|
short ostate;
|
2000-10-17 07:06:42 +04:00
|
|
|
#endif
|
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
s = splsoftnet();
|
2004-01-02 18:51:04 +03:00
|
|
|
callout_ack(&tp->t_timer[TCPT_REXMT]);
|
2003-07-20 20:35:07 +04:00
|
|
|
if (tcp_isdead(tp)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-07-19 21:00:02 +04:00
|
|
|
if ((tp->t_flags & TF_PMTUD_PEND) && tp->t_inpcb &&
|
|
|
|
SEQ_GEQ(tp->t_pmtud_th_seq, tp->snd_una) &&
|
|
|
|
SEQ_LT(tp->t_pmtud_th_seq, (int)(tp->snd_una + tp->t_ourmss))) {
|
|
|
|
extern struct sockaddr_in icmpsrc;
|
|
|
|
struct icmp icmp;
|
|
|
|
|
|
|
|
tp->t_flags &= ~TF_PMTUD_PEND;
|
|
|
|
|
|
|
|
/* XXX create fake icmp message with relevant entries */
|
|
|
|
icmp.icmp_nextmtu = tp->t_pmtud_nextmtu;
|
|
|
|
icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len;
|
|
|
|
icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl;
|
|
|
|
icmpsrc.sin_addr = tp->t_inpcb->inp_faddr;
|
|
|
|
icmp_mtudisc(&icmp, icmpsrc.sin_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify all connections to the same peer about
|
|
|
|
* new mss and trigger retransmit.
|
|
|
|
*/
|
|
|
|
in_pcbnotifyall(&tcbtable, icmpsrc.sin_addr, EMSGSIZE,
|
|
|
|
tcp_mtudisc);
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-11 00:15:14 +04:00
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
#ifdef INET
|
|
|
|
if (tp->t_inpcb)
|
|
|
|
so = tp->t_inpcb->inp_socket;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (tp->t_in6pcb)
|
|
|
|
so = tp->t_in6pcb->in6p_socket;
|
|
|
|
#endif
|
|
|
|
ostate = tp->t_state;
|
|
|
|
#endif /* TCP_DEBUG */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Commit TCP SACK patches from Kentaro A. Karahone's patch at:
http://www.sigusr1.org/~kurahone/tcp-sack-netbsd-02152005.diff.gz
Fixes in that patch for pre-existing TCP pcb initializations were already
committed to NetBSD-current, so are not included in this commit.
The SACK patch has been observed to correctly negotiate and respond,
to SACKs in wide-area traffic.
There are two indepenently-observed, as-yet-unresolved anomalies:
First, seeing unexplained delays between in fast retransmission
(potentially explainable by an 0.2sec RTT between adjacent
ethernet/wifi NICs); and second, peculiar and unepxlained TCP
retransmits observed over an ath0 card.
After discussion with several interested developers, I'm committing
this now, as-is, for more eyes to use and look over. Current hypothesis
is that the anomalies above may in fact be due to link/level (hardware,
driver, HAL, firmware) abberations in the test setup, affecting both
Kentaro's wired-Ethernet NIC and in my two (different) WiFi NICs.
2005-02-28 19:20:59 +03:00
|
|
|
/*
|
|
|
|
* Clear the SACK scoreboard, reset FACK estimate.
|
|
|
|
*/
|
|
|
|
tcp_free_sackholes(tp);
|
|
|
|
tp->snd_fack = tp->snd_una;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Retransmission timer went off. Message has not
|
|
|
|
* been acked within retransmit interval. Back off
|
|
|
|
* to a longer retransmit interval and retransmit one segment.
|
|
|
|
*/
|
2001-09-11 00:15:14 +04:00
|
|
|
|
|
|
|
if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
|
|
|
|
tp->t_rxtshift = TCP_MAXRXTSHIFT;
|
|
|
|
tcpstat.tcps_timeoutdrop++;
|
|
|
|
tp = tcp_drop(tp, tp->t_softerror ?
|
|
|
|
tp->t_softerror : ETIMEDOUT);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
tcpstat.tcps_rexmttimeo++;
|
|
|
|
rto = TCP_REXMTVAL(tp);
|
|
|
|
if (rto < tp->t_rttmin)
|
|
|
|
rto = tp->t_rttmin;
|
|
|
|
TCPT_RANGESET(tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift],
|
|
|
|
tp->t_rttmin, TCPTV_REXMTMAX);
|
|
|
|
TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur);
|
2002-05-26 20:05:43 +04:00
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
/*
|
2001-09-11 00:15:14 +04:00
|
|
|
* If we are losing and we are trying path MTU discovery,
|
|
|
|
* try turning it off. This will avoid black holes in
|
|
|
|
* the network which suppress or fail to send "packet
|
|
|
|
* too big" ICMP messages. We should ideally do
|
|
|
|
* lots more sophisticated searching to find the right
|
|
|
|
* value here...
|
|
|
|
*/
|
2002-05-26 20:05:43 +04:00
|
|
|
if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) {
|
|
|
|
tcpstat.tcps_pmtublackhole++;
|
1999-07-01 12:12:45 +04:00
|
|
|
|
2000-10-17 07:06:42 +04:00
|
|
|
#ifdef INET
|
2002-05-26 20:05:43 +04:00
|
|
|
/* try turning PMTUD off */
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_inpcb)
|
2002-05-26 20:05:43 +04:00
|
|
|
tp->t_mtudisc = 0;
|
2000-10-17 07:06:42 +04:00
|
|
|
#endif
|
1999-07-01 12:12:45 +04:00
|
|
|
#ifdef INET6
|
2002-05-26 20:05:43 +04:00
|
|
|
/* try using IPv6 minimum MTU */
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_in6pcb)
|
2002-05-26 20:05:43 +04:00
|
|
|
tp->t_mtudisc = 0;
|
1999-07-01 12:12:45 +04:00
|
|
|
#endif
|
1998-04-29 07:44:11 +04:00
|
|
|
|
2002-05-26 20:05:43 +04:00
|
|
|
/* XXX: more sophisticated Black hole recovery code? */
|
2001-09-11 00:15:14 +04:00
|
|
|
}
|
2002-05-26 20:05:43 +04:00
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
/*
|
|
|
|
* If losing, let the lower level know and try for
|
|
|
|
* a better route. Also, if we backed off this far,
|
|
|
|
* our srtt estimate is probably bogus. Clobber it
|
|
|
|
* so we'll take the next rtt measurement as our srtt;
|
|
|
|
* move the current srtt into rttvar to keep the current
|
|
|
|
* retransmit times until then.
|
|
|
|
*/
|
|
|
|
if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
|
|
|
|
#ifdef INET
|
|
|
|
if (tp->t_inpcb)
|
|
|
|
in_losing(tp->t_inpcb);
|
1998-05-01 05:15:55 +04:00
|
|
|
#endif
|
2001-09-11 00:15:14 +04:00
|
|
|
#ifdef INET6
|
|
|
|
if (tp->t_in6pcb)
|
|
|
|
in6_losing(tp->t_in6pcb);
|
|
|
|
#endif
|
|
|
|
tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
|
|
|
|
tp->t_srtt = 0;
|
|
|
|
}
|
|
|
|
tp->snd_nxt = tp->snd_una;
|
2005-01-27 00:49:27 +03:00
|
|
|
tp->snd_high = tp->snd_max;
|
2001-09-11 00:15:14 +04:00
|
|
|
/*
|
|
|
|
* If timing a segment in this window, stop the timer.
|
|
|
|
*/
|
|
|
|
tp->t_rtttime = 0;
|
|
|
|
/*
|
|
|
|
* Remember if we are retransmitting a SYN, because if
|
|
|
|
* we do, set the initial congestion window must be set
|
|
|
|
* to 1 segment.
|
|
|
|
*/
|
|
|
|
if (tp->t_state == TCPS_SYN_SENT)
|
|
|
|
tp->t_flags |= TF_SYN_REXMT;
|
2006-10-09 20:27:07 +04:00
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
/*
|
2006-10-09 20:27:07 +04:00
|
|
|
* Adjust congestion control parameters.
|
2001-09-11 00:15:14 +04:00
|
|
|
*/
|
2006-10-09 20:27:07 +04:00
|
|
|
tp->t_congctl->slow_retransmit(tp);
|
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
(void) tcp_output(tp);
|
|
|
|
|
|
|
|
out:
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
if (tp && so->so_options & SO_DEBUG)
|
|
|
|
tcp_trace(TA_USER, ostate, tp, NULL,
|
|
|
|
PRU_SLOWTIMO | (TCPT_REXMT << 8));
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcp_timer_persist(void *arg)
|
|
|
|
{
|
|
|
|
struct tcpcb *tp = arg;
|
|
|
|
uint32_t rto;
|
|
|
|
int s;
|
|
|
|
#ifdef TCP_DEBUG
|
2003-10-27 10:43:01 +03:00
|
|
|
struct socket *so = NULL;
|
2001-09-11 00:15:14 +04:00
|
|
|
short ostate;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splsoftnet();
|
2003-07-20 20:35:07 +04:00
|
|
|
callout_ack(&tp->t_timer[TCPT_PERSIST]);
|
|
|
|
if (tcp_isdead(tp)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-11 00:15:14 +04:00
|
|
|
|
2002-10-22 07:11:03 +04:00
|
|
|
#ifdef TCP_DEBUG
|
2000-10-17 07:06:42 +04:00
|
|
|
#ifdef INET
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_inpcb)
|
|
|
|
so = tp->t_inpcb->inp_socket;
|
2000-10-17 07:06:42 +04:00
|
|
|
#endif
|
1999-07-01 12:12:45 +04:00
|
|
|
#ifdef INET6
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_in6pcb)
|
|
|
|
so = tp->t_in6pcb->in6p_socket;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ostate = tp->t_state;
|
2002-10-22 07:11:03 +04:00
|
|
|
#endif /* TCP_DEBUG */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Persistance timer into zero window.
|
|
|
|
* Force a byte to be output, if possible.
|
|
|
|
*/
|
2001-09-11 00:15:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hack: if the peer is dead/unreachable, we do not
|
|
|
|
* time out if the window is closed. After a full
|
|
|
|
* backoff, drop the connection if the idle time
|
|
|
|
* (no responses to probes) reaches the maximum
|
|
|
|
* backoff that we would use if retransmitting.
|
|
|
|
*/
|
|
|
|
rto = TCP_REXMTVAL(tp);
|
|
|
|
if (rto < tp->t_rttmin)
|
|
|
|
rto = tp->t_rttmin;
|
|
|
|
if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
|
|
|
|
((tcp_now - tp->t_rcvtime) >= tcp_maxpersistidle ||
|
|
|
|
(tcp_now - tp->t_rcvtime) >= rto * tcp_totbackoff)) {
|
|
|
|
tcpstat.tcps_persistdrops++;
|
|
|
|
tp = tcp_drop(tp, ETIMEDOUT);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
tcpstat.tcps_persisttimeo++;
|
|
|
|
tcp_setpersist(tp);
|
|
|
|
tp->t_force = 1;
|
|
|
|
(void) tcp_output(tp);
|
|
|
|
tp->t_force = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
if (tp && so->so_options & SO_DEBUG)
|
|
|
|
tcp_trace(TA_USER, ostate, tp, NULL,
|
|
|
|
PRU_SLOWTIMO | (TCPT_PERSIST << 8));
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcp_timer_keep(void *arg)
|
|
|
|
{
|
|
|
|
struct tcpcb *tp = arg;
|
2002-11-24 13:52:47 +03:00
|
|
|
struct socket *so = NULL; /* Quell compiler warning */
|
2001-09-11 00:15:14 +04:00
|
|
|
int s;
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
short ostate;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splsoftnet();
|
2003-07-20 20:35:07 +04:00
|
|
|
callout_ack(&tp->t_timer[TCPT_KEEP]);
|
|
|
|
if (tcp_isdead(tp)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-11 00:15:14 +04:00
|
|
|
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
ostate = tp->t_state;
|
|
|
|
#endif /* TCP_DEBUG */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Keep-alive timer went off; send something
|
|
|
|
* or drop connection if idle for too long.
|
|
|
|
*/
|
1999-07-01 12:12:45 +04:00
|
|
|
|
2001-09-11 00:15:14 +04:00
|
|
|
tcpstat.tcps_keeptimeo++;
|
|
|
|
if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
|
|
|
|
goto dropit;
|
2000-10-17 07:06:42 +04:00
|
|
|
#ifdef INET
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_inpcb)
|
|
|
|
so = tp->t_inpcb->inp_socket;
|
2000-10-17 07:06:42 +04:00
|
|
|
#endif
|
1999-07-01 12:12:45 +04:00
|
|
|
#ifdef INET6
|
2001-09-11 00:15:14 +04:00
|
|
|
if (tp->t_in6pcb)
|
|
|
|
so = tp->t_in6pcb->in6p_socket;
|
1999-07-01 12:12:45 +04:00
|
|
|
#endif
|
2006-04-15 06:33:41 +04:00
|
|
|
KASSERT(so != NULL);
|
2001-09-11 00:15:14 +04:00
|
|
|
if (so->so_options & SO_KEEPALIVE &&
|
|
|
|
tp->t_state <= TCPS_CLOSE_WAIT) {
|
2007-06-20 19:29:17 +04:00
|
|
|
if ((tp->t_maxidle > 0) &&
|
2001-09-11 00:15:14 +04:00
|
|
|
((tcp_now - tp->t_rcvtime) >=
|
2007-06-20 19:29:17 +04:00
|
|
|
tp->t_keepidle + tp->t_maxidle))
|
2001-09-11 00:15:14 +04:00
|
|
|
goto dropit;
|
|
|
|
/*
|
|
|
|
* Send a packet designed to force a response
|
|
|
|
* if the peer is up and reachable:
|
|
|
|
* either an ACK if the connection is still alive,
|
|
|
|
* or an RST if the peer has closed the connection
|
|
|
|
* due to timeout or reboot.
|
|
|
|
* Using sequence number tp->snd_una-1
|
|
|
|
* causes the transmitted zero-length segment
|
|
|
|
* to lie outside the receive window;
|
|
|
|
* by the protocol spec, this requires the
|
|
|
|
* correspondent TCP to respond.
|
|
|
|
*/
|
|
|
|
tcpstat.tcps_keepprobe++;
|
|
|
|
if (tcp_compat_42) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2001-09-11 00:15:14 +04:00
|
|
|
* The keepalive packet must have nonzero
|
|
|
|
* length to get a 4.2 host to respond.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2001-09-11 00:15:14 +04:00
|
|
|
(void)tcp_respond(tp, tp->t_template,
|
|
|
|
(struct mbuf *)NULL, NULL, tp->rcv_nxt - 1,
|
|
|
|
tp->snd_una - 1, 0);
|
|
|
|
} else {
|
|
|
|
(void)tcp_respond(tp, tp->t_template,
|
|
|
|
(struct mbuf *)NULL, NULL, tp->rcv_nxt,
|
|
|
|
tp->snd_una - 1, 0);
|
|
|
|
}
|
2007-06-20 19:29:17 +04:00
|
|
|
TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
|
2001-09-11 00:15:14 +04:00
|
|
|
} else
|
2007-06-20 19:29:17 +04:00
|
|
|
TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
|
2001-09-11 00:15:14 +04:00
|
|
|
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
if (tp && so->so_options & SO_DEBUG)
|
|
|
|
tcp_trace(TA_USER, ostate, tp, NULL,
|
|
|
|
PRU_SLOWTIMO | (TCPT_KEEP << 8));
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
dropit:
|
|
|
|
tcpstat.tcps_keepdrops++;
|
|
|
|
(void) tcp_drop(tp, ETIMEDOUT);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcp_timer_2msl(void *arg)
|
|
|
|
{
|
|
|
|
struct tcpcb *tp = arg;
|
|
|
|
int s;
|
|
|
|
#ifdef TCP_DEBUG
|
2003-10-27 10:43:01 +03:00
|
|
|
struct socket *so = NULL;
|
2001-09-11 00:15:14 +04:00
|
|
|
short ostate;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splsoftnet();
|
2003-07-20 20:35:07 +04:00
|
|
|
callout_ack(&tp->t_timer[TCPT_2MSL]);
|
|
|
|
if (tcp_isdead(tp)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-11 00:15:14 +04:00
|
|
|
|
Commit TCP SACK patches from Kentaro A. Karahone's patch at:
http://www.sigusr1.org/~kurahone/tcp-sack-netbsd-02152005.diff.gz
Fixes in that patch for pre-existing TCP pcb initializations were already
committed to NetBSD-current, so are not included in this commit.
The SACK patch has been observed to correctly negotiate and respond,
to SACKs in wide-area traffic.
There are two indepenently-observed, as-yet-unresolved anomalies:
First, seeing unexplained delays between in fast retransmission
(potentially explainable by an 0.2sec RTT between adjacent
ethernet/wifi NICs); and second, peculiar and unepxlained TCP
retransmits observed over an ath0 card.
After discussion with several interested developers, I'm committing
this now, as-is, for more eyes to use and look over. Current hypothesis
is that the anomalies above may in fact be due to link/level (hardware,
driver, HAL, firmware) abberations in the test setup, affecting both
Kentaro's wired-Ethernet NIC and in my two (different) WiFi NICs.
2005-02-28 19:20:59 +03:00
|
|
|
/*
|
|
|
|
* 2 MSL timeout went off, clear the SACK scoreboard, reset
|
|
|
|
* the FACK estimate.
|
|
|
|
*/
|
|
|
|
tcp_free_sackholes(tp);
|
|
|
|
tp->snd_fack = tp->snd_una;
|
|
|
|
|
2002-10-22 07:11:03 +04:00
|
|
|
#ifdef TCP_DEBUG
|
2001-09-11 00:15:14 +04:00
|
|
|
#ifdef INET
|
|
|
|
if (tp->t_inpcb)
|
|
|
|
so = tp->t_inpcb->inp_socket;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (tp->t_in6pcb)
|
|
|
|
so = tp->t_in6pcb->in6p_socket;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ostate = tp->t_state;
|
2002-10-22 07:11:03 +04:00
|
|
|
#endif /* TCP_DEBUG */
|
2001-09-11 00:15:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 2 MSL timeout in shutdown went off. If we're closed but
|
|
|
|
* still waiting for peer to close and connection has been idle
|
|
|
|
* too long, or if 2MSL time is up from TIME_WAIT, delete connection
|
|
|
|
* control block. Otherwise, check again in a bit.
|
|
|
|
*/
|
|
|
|
if (tp->t_state != TCPS_TIME_WAIT &&
|
2007-06-20 19:29:17 +04:00
|
|
|
((tp->t_maxidle == 0) ||
|
|
|
|
((tcp_now - tp->t_rcvtime) <= tp->t_maxidle)))
|
|
|
|
TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_keepintvl);
|
2001-09-11 00:15:14 +04:00
|
|
|
else
|
|
|
|
tp = tcp_close(tp);
|
|
|
|
|
|
|
|
#ifdef TCP_DEBUG
|
|
|
|
if (tp && so->so_options & SO_DEBUG)
|
|
|
|
tcp_trace(TA_USER, ostate, tp, NULL,
|
|
|
|
PRU_SLOWTIMO | (TCPT_2MSL << 8));
|
|
|
|
#endif
|
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|