2007-07-24 10:06:37 +02:00
|
|
|
/** @file
|
2008-12-16 03:57:53 +01:00
|
|
|
TCP timer related functions.
|
|
|
|
|
|
|
|
Copyright (c) 2005 - 2007, Intel Corporation<BR>
|
2007-07-24 10:06:37 +02:00
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
2008-12-16 03:57:53 +01:00
|
|
|
http://opensource.org/licenses/bsd-license.php<BR>
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "Tcp4Main.h"
|
|
|
|
|
|
|
|
UINT32 mTcpTick = 1000;
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Connect timeout handler.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
TcpConnectTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Timeout handler for TCP retransmission timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
TcpRexmitTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
2008-12-06 00:47:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for window probe timer.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
TcpProbeTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Timeout handler for keepalive timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
TcpKeepaliveTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Timeout handler for FIN_WAIT_2 timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
TcpFinwait2Timeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
/**
|
|
|
|
Timeout handler for 2MSL timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
2007-07-24 10:06:37 +02:00
|
|
|
VOID
|
|
|
|
Tcp2MSLTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
TCP_TIMER_HANDLER mTcpTimerHandler[TCP_TIMER_NUMBER] = {
|
|
|
|
TcpConnectTimeout,
|
|
|
|
TcpRexmitTimeout,
|
|
|
|
TcpProbeTimeout,
|
|
|
|
TcpKeepaliveTimeout,
|
|
|
|
TcpFinwait2Timeout,
|
|
|
|
Tcp2MSLTimeout,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Close the TCP connection.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpClose (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
NetbufFreeList (&Tcb->SndQue);
|
|
|
|
NetbufFreeList (&Tcb->RcvQue);
|
|
|
|
|
|
|
|
TcpSetState (Tcb, TCP_CLOSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Connect timeout handler.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpConnectTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!TCP_CONNECTED (Tcb->State)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "TcpConnectTimeout: connection closed "
|
2008-10-27 11:13:00 +01:00
|
|
|
"because conenction timer timeout for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
if (EFI_ABORTED == Tcb->Sk->SockError) {
|
|
|
|
SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TCP_SYN_RCVD == Tcb->State) {
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "TcpConnectTimeout: send reset because "
|
2008-10-27 11:13:00 +01:00
|
|
|
"connection timer timeout for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
TcpResetConnection (Tcb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpClose (Tcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for TCP retransmission timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpRexmitTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 FlightSize;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "TcpRexmitTimeout: transmission "
|
2008-10-27 11:13:00 +01:00
|
|
|
"timeout for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set the congestion window. FlightSize is the
|
|
|
|
// amount of data that has been sent but not
|
|
|
|
// yet ACKed.
|
|
|
|
//
|
|
|
|
FlightSize = TCP_SUB_SEQ (Tcb->SndNxt, Tcb->SndUna);
|
2007-11-20 06:42:23 +01:00
|
|
|
Tcb->Ssthresh = MAX ((UINT32) (2 * Tcb->SndMss), FlightSize / 2);
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
Tcb->CWnd = Tcb->SndMss;
|
|
|
|
Tcb->LossRecover = Tcb->SndNxt;
|
|
|
|
|
|
|
|
Tcb->LossTimes++;
|
2008-12-06 00:47:55 +01:00
|
|
|
if ((Tcb->LossTimes > Tcb->MaxRexmit) &&
|
2007-07-24 10:06:37 +02:00
|
|
|
!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_CONNECT)) {
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "TcpRexmitTimeout: connection closed "
|
2008-10-27 11:13:00 +01:00
|
|
|
"because too many timeouts for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
if (EFI_ABORTED == Tcb->Sk->SockError) {
|
|
|
|
SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpClose (Tcb);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpBackoffRto (Tcb);
|
|
|
|
TcpRetransmit (Tcb, Tcb->SndUna);
|
|
|
|
TcpSetTimer (Tcb, TCP_TIMER_REXMIT, Tcb->Rto);
|
|
|
|
|
|
|
|
Tcb->CongestState = TCP_CONGEST_LOSS;
|
|
|
|
TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_RTT_ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for window probe timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpProbeTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// This is the timer for sender's SWSA. RFC1122 requires
|
|
|
|
// a timer set for sender's SWSA, and suggest combine it
|
|
|
|
// with window probe timer. If data is sent, don't set
|
|
|
|
// the probe timer, since retransmit timer is on.
|
|
|
|
//
|
|
|
|
if ((TcpDataToSend (Tcb, 1) != 0) && (TcpToSendData (Tcb, 1) > 0)) {
|
|
|
|
|
2008-12-24 09:14:19 +01:00
|
|
|
ASSERT (TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_REXMIT) != 0);
|
2007-07-24 10:06:37 +02:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpSendZeroProbe (Tcb);
|
|
|
|
TcpSetProbeTimer (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for keepalive timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpKeepaliveTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
Tcb->KeepAliveProbes++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Too many Keep-alive probes, drop the connection
|
|
|
|
//
|
|
|
|
if (Tcb->KeepAliveProbes > Tcb->MaxKeepAlive) {
|
|
|
|
|
|
|
|
if (EFI_ABORTED == Tcb->Sk->SockError) {
|
|
|
|
SOCK_ERROR (Tcb->Sk, EFI_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpClose (Tcb);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpSendZeroProbe (Tcb);
|
|
|
|
TcpSetKeepaliveTimer (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for FIN_WAIT_2 timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpFinwait2Timeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "TcpFinwait2Timeout: connection closed "
|
2008-10-27 11:13:00 +01:00
|
|
|
"because FIN_WAIT2 timer timeouts for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
TcpClose (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Timeout handler for 2MSL timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
Tcp2MSLTimeout (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
DEBUG ((EFI_D_WARN, "Tcp2MSLTimeout: connection closed "
|
2008-10-27 11:13:00 +01:00
|
|
|
"because TIME_WAIT timer timeouts for TCB %p\n", Tcb));
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
TcpClose (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-06 00:47:55 +01:00
|
|
|
Update the timer status and the next expire time according to the timers
|
|
|
|
to expire in a specific future time slot.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpUpdateTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Don't use a too large value to init NextExpire
|
|
|
|
// since mTcpTick wraps around as sequence no does.
|
|
|
|
//
|
|
|
|
Tcb->NextExpire = 65535;
|
|
|
|
TCP_CLEAR_FLG (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON);
|
|
|
|
|
|
|
|
for (Index = 0; Index < TCP_TIMER_NUMBER; Index++) {
|
|
|
|
|
|
|
|
if (TCP_TIMER_ON (Tcb->EnabledTimer, Index) &&
|
|
|
|
TCP_TIME_LT (Tcb->Timer[Index], mTcpTick + Tcb->NextExpire)) {
|
|
|
|
|
|
|
|
Tcb->NextExpire = TCP_SUB_TIME (Tcb->Timer[Index], mTcpTick);
|
|
|
|
TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enable a TCP timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
@param Timer The index of the timer to be enabled.
|
|
|
|
@param TimeOut The timeout value of this timer.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpSetTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb,
|
|
|
|
IN UINT16 Timer,
|
|
|
|
IN UINT32 TimeOut
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
TCP_SET_TIMER (Tcb->EnabledTimer, Timer);
|
|
|
|
Tcb->Timer[Timer] = mTcpTick + TimeOut;
|
|
|
|
|
|
|
|
TcpUpdateTimer (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear one TCP timer.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
@param Timer The index of the timer to be cleared.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpClearTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb,
|
|
|
|
IN UINT16 Timer
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
TCP_CLEAR_TIMER (Tcb->EnabledTimer, Timer);
|
|
|
|
TcpUpdateTimer (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear all TCP timers.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpClearAllTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
Tcb->EnabledTimer = 0;
|
|
|
|
TcpUpdateTimer (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enable the window prober timer and set the timeout value.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpSetProbeTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_PROBE)) {
|
|
|
|
Tcb->ProbeTime = Tcb->Rto;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Tcb->ProbeTime <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Tcb->ProbeTime < TCP_RTO_MIN) {
|
|
|
|
|
|
|
|
Tcb->ProbeTime = TCP_RTO_MIN;
|
|
|
|
} else if (Tcb->ProbeTime > TCP_RTO_MAX) {
|
|
|
|
|
|
|
|
Tcb->ProbeTime = TCP_RTO_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
TcpSetTimer (Tcb, TCP_TIMER_PROBE, Tcb->ProbeTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enable the keepalive timer and set the timeout value.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpSetKeepaliveTimer (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_NO_KEEPALIVE)) {
|
|
|
|
return ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set the timer to KeepAliveIdle if either
|
|
|
|
// 1. the keepalive timer is off
|
|
|
|
// 2. The keepalive timer is on, but the idle
|
|
|
|
// is less than KeepAliveIdle, that means the
|
|
|
|
// connection is alive since our last probe.
|
|
|
|
//
|
|
|
|
if (!TCP_TIMER_ON (Tcb->EnabledTimer, TCP_TIMER_KEEPALIVE) ||
|
|
|
|
(Tcb->Idle < Tcb->KeepAliveIdle)) {
|
|
|
|
|
|
|
|
TcpSetTimer (Tcb, TCP_TIMER_KEEPALIVE, Tcb->KeepAliveIdle);
|
|
|
|
Tcb->KeepAliveProbes = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TcpSetTimer (Tcb, TCP_TIMER_KEEPALIVE, Tcb->KeepAlivePeriod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Backoff the RTO.
|
|
|
|
|
|
|
|
@param Tcb Pointer to the TCP_CB of this TCP instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
TcpBackoffRto (
|
2008-12-29 13:58:38 +01:00
|
|
|
IN OUT TCP_CB *Tcb
|
2007-07-24 10:06:37 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Fold the RTT estimate if too many times, the estimate
|
|
|
|
// may be wrong, fold it. So the next time a valid
|
|
|
|
// measurement is sampled, we can start fresh.
|
|
|
|
//
|
2008-11-28 09:32:24 +01:00
|
|
|
if ((Tcb->LossTimes >= TCP_FOLD_RTT) && (Tcb->SRtt != 0)) {
|
2007-07-24 10:06:37 +02:00
|
|
|
Tcb->RttVar += Tcb->SRtt >> 2;
|
|
|
|
Tcb->SRtt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcb->Rto <<= 1;
|
|
|
|
|
|
|
|
if (Tcb->Rto < TCP_RTO_MIN) {
|
|
|
|
|
|
|
|
Tcb->Rto = TCP_RTO_MIN;
|
|
|
|
} else if (Tcb->Rto > TCP_RTO_MAX) {
|
|
|
|
|
|
|
|
Tcb->Rto = TCP_RTO_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Heart beat timer handler.
|
|
|
|
|
2008-12-06 00:47:55 +01:00
|
|
|
@param Context Context of the timer event, ignored.
|
2007-07-24 10:06:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2007-11-20 06:42:23 +01:00
|
|
|
TcpTickingDpc (
|
2007-07-24 10:06:37 +02:00
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
|
|
|
LIST_ENTRY *Next;
|
2007-07-24 10:06:37 +02:00
|
|
|
TCP_CB *Tcb;
|
|
|
|
INT16 Index;
|
|
|
|
|
|
|
|
mTcpTick++;
|
|
|
|
mTcpGlobalIss += 100;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Don't use LIST_FOR_EACH, which isn't delete safe.
|
|
|
|
//
|
|
|
|
for (Entry = mTcpRunQue.ForwardLink; Entry != &mTcpRunQue; Entry = Next) {
|
|
|
|
|
|
|
|
Next = Entry->ForwardLink;
|
|
|
|
|
|
|
|
Tcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List);
|
|
|
|
|
|
|
|
if (Tcb->State == TCP_CLOSED) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// The connection is doing RTT measurement.
|
|
|
|
//
|
|
|
|
if (TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_RTT_ON)) {
|
|
|
|
Tcb->RttMeasure++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcb->Idle++;
|
|
|
|
|
2008-11-28 09:32:24 +01:00
|
|
|
if (Tcb->DelayedAck != 0) {
|
2007-07-24 10:06:37 +02:00
|
|
|
TcpSendAck (Tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// No timer is active or no timer expired
|
|
|
|
//
|
|
|
|
if (!TCP_FLG_ON (Tcb->CtrlFlag, TCP_CTRL_TIMER_ON) ||
|
|
|
|
((--Tcb->NextExpire) > 0)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Call the timeout handler for each expired timer.
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < TCP_TIMER_NUMBER; Index++) {
|
|
|
|
|
|
|
|
if (TCP_TIMER_ON (Tcb->EnabledTimer, Index) &&
|
|
|
|
TCP_TIME_LEQ (Tcb->Timer[Index], mTcpTick)) {
|
|
|
|
//
|
|
|
|
// disable the timer before calling the handler
|
|
|
|
// in case the handler enables it again.
|
|
|
|
//
|
|
|
|
TCP_CLEAR_TIMER (Tcb->EnabledTimer, Index);
|
|
|
|
mTcpTimerHandler[Index](Tcb);
|
|
|
|
|
|
|
|
//
|
|
|
|
// The Tcb may have been deleted by the timer, or
|
|
|
|
// no other timer is set.
|
|
|
|
//
|
|
|
|
if ((Next->BackLink != Entry) ||
|
|
|
|
(Tcb->EnabledTimer == 0)) {
|
2008-12-26 04:40:27 +01:00
|
|
|
break;
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-29 13:58:38 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// If the Tcb still exist or some timer is set, update the timer
|
|
|
|
//
|
2008-12-26 04:40:27 +01:00
|
|
|
if (Index == TCP_TIMER_NUMBER) {
|
|
|
|
TcpUpdateTimer (Tcb);
|
|
|
|
}
|
2007-07-24 10:06:37 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-20 06:42:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Heart beat timer handler, queues the DPC at TPL_CALLBACK.
|
|
|
|
|
|
|
|
@param Event Timer event signaled, ignored.
|
|
|
|
@param Context Context of the timer event, ignored.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
TcpTicking (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
NetLibQueueDpc (TPL_CALLBACK, TcpTickingDpc, Context);
|
|
|
|
}
|
|
|
|
|