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