fix round-trip timing: rexmt timer shouldn't screw rtt up,
[unix-history] / usr / src / sys / netinet / tcp_timer.c
CommitLineData
7872cc0a 1/* tcp_timer.c 6.3 84/10/31 */
f03530e6 2
20666ad3
JB
3#include "param.h"
4#include "systm.h"
5#include "mbuf.h"
6#include "socket.h"
7#include "socketvar.h"
8#include "protosw.h"
9#include "errno.h"
6e7edb25
BJ
10
11#include "../net/if.h"
c124e997 12#include "../net/route.h"
f4d55810 13
20666ad3
JB
14#include "in.h"
15#include "in_pcb.h"
16#include "in_systm.h"
17#include "ip.h"
18#include "ip_var.h"
19#include "tcp.h"
20#include "tcp_fsm.h"
21#include "tcp_seq.h"
22#include "tcp_timer.h"
23#include "tcp_var.h"
24#include "tcpip.h"
f03530e6 25
8b5a83bb 26int tcpnodelack = 0;
f03530e6
BJ
27/*
28 * Fast timeout routine for processing delayed acks
29 */
30tcp_fasttimo()
31{
b8b9174f
BJ
32 register struct inpcb *inp;
33 register struct tcpcb *tp;
34 int s = splnet();
b8b9174f 35
fd5dc5f0
BJ
36 inp = tcb.inp_next;
37 if (inp)
38 for (; inp != &tcb; inp = inp->inp_next)
b8b9174f
BJ
39 if ((tp = (struct tcpcb *)inp->inp_ppcb) &&
40 (tp->t_flags & TF_DELACK)) {
41 tp->t_flags &= ~TF_DELACK;
42 tp->t_flags |= TF_ACKNOW;
43 (void) tcp_output(tp);
44 }
45 splx(s);
f03530e6
BJ
46}
47
48/*
49 * Tcp protocol timeout routine called every 500 ms.
50 * Updates the timers in all active tcb's and
51 * causes finite state machine actions if timers expire.
52 */
53tcp_slowtimo()
54{
1e977657 55 register struct inpcb *ip, *ipnxt;
f03530e6
BJ
56 register struct tcpcb *tp;
57 int s = splnet();
f03530e6 58 register int i;
f03530e6
BJ
59
60 /*
61 * Search through tcb's and update active timers.
62 */
4aed14e3
BJ
63 ip = tcb.inp_next;
64 if (ip == 0) {
65 splx(s);
66 return;
67 }
1e977657 68 while (ip != &tcb) {
f03530e6 69 tp = intotcpcb(ip);
37de812c
BJ
70 if (tp == 0)
71 continue;
1e977657 72 ipnxt = ip->inp_next;
a6503abf 73 for (i = 0; i < TCPT_NTIMERS; i++) {
1e977657 74 if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
f03530e6
BJ
75 (void) tcp_usrreq(tp->t_inpcb->inp_socket,
76 PRU_SLOWTIMO, (struct mbuf *)0,
755d8841 77 (struct mbuf *)i, (struct mbuf *)0);
1e977657
BJ
78 if (ipnxt->inp_prev != ip)
79 goto tpgone;
80 }
f03530e6 81 }
405c9168
BJ
82 tp->t_idle++;
83 if (tp->t_rtt)
84 tp->t_rtt++;
1e977657
BJ
85tpgone:
86 ip = ipnxt;
f03530e6 87 }
a6503abf 88 tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */
f03530e6
BJ
89 splx(s);
90}
91
92/*
a6503abf 93 * Cancel all timers for TCP tp.
f03530e6 94 */
0974b45c 95tcp_canceltimers(tp)
f03530e6
BJ
96 struct tcpcb *tp;
97{
f03530e6
BJ
98 register int i;
99
a6503abf
BJ
100 for (i = 0; i < TCPT_NTIMERS; i++)
101 tp->t_timer[i] = 0;
f03530e6
BJ
102}
103
7380f986
BJ
104float tcp_backoff[TCP_MAXRXTSHIFT] =
105 { 1.0, 1.2, 1.4, 1.7, 2.0, 3.0, 5.0, 8.0, 16.0, 32.0 };
7380f986 106int tcpexprexmtbackoff = 0;
f03530e6 107/*
405c9168 108 * TCP timer processing.
f03530e6 109 */
0e3936fa 110struct tcpcb *
a6503abf 111tcp_timers(tp, timer)
f03530e6 112 register struct tcpcb *tp;
a6503abf 113 int timer;
f03530e6
BJ
114{
115
0974b45c 116 switch (timer) {
f03530e6 117
405c9168
BJ
118 /*
119 * 2 MSL timeout in shutdown went off. Delete connection
120 * control block.
121 */
a6503abf 122 case TCPT_2MSL:
0e3936fa
SL
123 tp = tcp_close(tp);
124 break;
f03530e6 125
405c9168
BJ
126 /*
127 * Retransmission timer went off. Message has not
128 * been acked within retransmit interval. Back off
129 * to a longer retransmit interval and retransmit all
130 * unacknowledged messages in the window.
131 */
a6503abf 132 case TCPT_REXMT:
405c9168 133 tp->t_rxtshift++;
fd5dc5f0 134 if (tp->t_rxtshift > TCP_MAXRXTSHIFT) {
0e3936fa
SL
135 tp = tcp_drop(tp, ETIMEDOUT);
136 break;
fd5dc5f0 137 }
405c9168 138 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
d977a479 139 (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX);
7380f986
BJ
140 if (tcpexprexmtbackoff) {
141 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
142 tp->t_timer[TCPT_REXMT] << tp->t_rxtshift,
143 TCPTV_MIN, TCPTV_MAX);
144 } else {
145 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
146 tp->t_timer[TCPT_REXMT] *
147 tcp_backoff[tp->t_rxtshift - 1],
148 TCPTV_MIN, TCPTV_MAX);
149 }
405c9168 150 tp->snd_nxt = tp->snd_una;
7872cc0a
MK
151 /*
152 * If timing a segment in this window, stop the timer.
153 */
154 if (tp->t_rtt && SEQ_GT(tp->t_rtseq, tp->snd_una))
155 tp->t_rtt = 0;
405c9168 156 (void) tcp_output(tp);
0e3936fa 157 break;
f03530e6 158
405c9168
BJ
159 /*
160 * Persistance timer into zero window.
161 * Force a byte to be output, if possible.
162 */
a6503abf 163 case TCPT_PERSIST:
a13c006d 164 tcp_setpersist(tp);
405c9168
BJ
165 tp->t_force = 1;
166 (void) tcp_output(tp);
167 tp->t_force = 0;
0e3936fa 168 break;
f03530e6 169
405c9168
BJ
170 /*
171 * Keep-alive timer went off; send something
172 * or drop connection if idle for too long.
173 */
a6503abf 174 case TCPT_KEEP:
f3cdd721
BJ
175 if (tp->t_state < TCPS_ESTABLISHED)
176 goto dropit;
3bd14c98 177 if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) {
f3cdd721
BJ
178 if (tp->t_idle >= TCPTV_MAXIDLE)
179 goto dropit;
3bd14c98
BJ
180 /*
181 * Saying tp->rcv_nxt-1 lies about what
182 * we have received, and by the protocol spec
183 * requires the correspondent TCP to respond.
184 * Saying tp->snd_una-1 causes the transmitted
185 * byte to lie outside the receive window; this
186 * is important because we don't necessarily
187 * have a byte in the window to send (consider
188 * a one-way stream!)
189 */
8e65fd66 190 tcp_respond(tp,
3bd14c98
BJ
191 tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0);
192 } else
1e977657 193 tp->t_idle = 0;
405c9168 194 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
0e3936fa 195 break;
f3cdd721 196 dropit:
0e3936fa
SL
197 tp = tcp_drop(tp, ETIMEDOUT);
198 break;
f03530e6 199 }
0e3936fa 200 return (tp);
f03530e6 201}