Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
8ae0e4b4 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
0880b18e | 6 | * @(#)tcp_timer.c 7.1 (Berkeley) %G% |
8ae0e4b4 | 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 | 32 | int tcpnodelack = 0; |
f03530e6 BJ |
33 | /* |
34 | * Fast timeout routine for processing delayed acks | |
35 | */ | |
36 | tcp_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 | */ | |
59 | tcp_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 | 91 | tpgone: |
039b88d5 | 92 | ; |
f03530e6 | 93 | } |
a6503abf | 94 | tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ |
367bed15 | 95 | #ifdef TCP_COMPAT_42 |
c50542f3 MK |
96 | if ((int)tcp_iss < 0) |
97 | tcp_iss = 0; /* XXX */ | |
98 | #endif | |
f03530e6 BJ |
99 | splx(s); |
100 | } | |
101 | ||
102 | /* | |
a6503abf | 103 | * Cancel all timers for TCP tp. |
f03530e6 | 104 | */ |
0974b45c | 105 | tcp_canceltimers(tp) |
f03530e6 BJ |
106 | struct tcpcb *tp; |
107 | { | |
f03530e6 BJ |
108 | register int i; |
109 | ||
a6503abf BJ |
110 | for (i = 0; i < TCPT_NTIMERS; i++) |
111 | tp->t_timer[i] = 0; | |
f03530e6 BJ |
112 | } |
113 | ||
2a89e5a6 MK |
114 | int tcp_backoff[TCP_MAXRXTSHIFT+1] = |
115 | { 1, 2, 4, 6, 8, 10, 15, 20, 30, 30, 30, 30, 30 }; | |
f03530e6 | 116 | /* |
405c9168 | 117 | * TCP timer processing. |
f03530e6 | 118 | */ |
0e3936fa | 119 | struct tcpcb * |
a6503abf | 120 | tcp_timers(tp, timer) |
f03530e6 | 121 | register struct tcpcb *tp; |
a6503abf | 122 | int timer; |
f03530e6 | 123 | { |
2a89e5a6 | 124 | register int rexmt; |
f03530e6 | 125 | |
0974b45c | 126 | switch (timer) { |
f03530e6 | 127 | |
405c9168 | 128 | /* |
6209c5c4 MK |
129 | * 2 MSL timeout in shutdown went off. If we're closed but |
130 | * still waiting for peer to close and connection has been idle | |
131 | * too long, or if 2MSL time is up from TIME_WAIT, delete connection | |
132 | * control block. Otherwise, check again in a bit. | |
405c9168 | 133 | */ |
a6503abf | 134 | case TCPT_2MSL: |
6209c5c4 MK |
135 | if (tp->t_state != TCPS_TIME_WAIT && |
136 | tp->t_idle <= TCPTV_MAXIDLE) | |
137 | tp->t_timer[TCPT_2MSL] = TCPTV_KEEP; | |
138 | else | |
139 | tp = tcp_close(tp); | |
0e3936fa | 140 | break; |
f03530e6 | 141 | |
405c9168 BJ |
142 | /* |
143 | * Retransmission timer went off. Message has not | |
144 | * been acked within retransmit interval. Back off | |
eeaf00e3 | 145 | * to a longer retransmit interval and retransmit one segment. |
405c9168 | 146 | */ |
a6503abf | 147 | case TCPT_REXMT: |
405c9168 | 148 | tp->t_rxtshift++; |
fd5dc5f0 | 149 | if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { |
0e3936fa SL |
150 | tp = tcp_drop(tp, ETIMEDOUT); |
151 | break; | |
fd5dc5f0 | 152 | } |
2a89e5a6 MK |
153 | if (tp->t_srtt == 0) |
154 | rexmt = tcp_beta * TCPTV_SRTTDFLT; | |
155 | else | |
156 | rexmt = (int)(tcp_beta * tp->t_srtt); | |
157 | rexmt *= tcp_backoff[tp->t_rxtshift - 1]; | |
158 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], rexmt, | |
7380f986 | 159 | TCPTV_MIN, TCPTV_MAX); |
6a4fd140 MK |
160 | /* |
161 | * If losing, let the lower level know | |
162 | * and try for a better route. | |
163 | */ | |
164 | if (tp->t_rxtshift >= TCP_MAXRXTSHIFT / 4 || | |
165 | rexmt >= 10 * PR_SLOWHZ) | |
166 | in_losing(tp->t_inpcb); | |
405c9168 | 167 | tp->snd_nxt = tp->snd_una; |
7872cc0a | 168 | /* |
f2da4d39 MK |
169 | * If timing a segment in this window, |
170 | * and we have already gotten some timing estimate, | |
171 | * stop the timer. | |
7872cc0a | 172 | */ |
f2da4d39 | 173 | if (tp->t_rtt && tp->t_srtt) |
7872cc0a | 174 | tp->t_rtt = 0; |
405c9168 | 175 | (void) tcp_output(tp); |
0e3936fa | 176 | break; |
f03530e6 | 177 | |
405c9168 BJ |
178 | /* |
179 | * Persistance timer into zero window. | |
180 | * Force a byte to be output, if possible. | |
181 | */ | |
a6503abf | 182 | case TCPT_PERSIST: |
a13c006d | 183 | tcp_setpersist(tp); |
405c9168 BJ |
184 | tp->t_force = 1; |
185 | (void) tcp_output(tp); | |
186 | tp->t_force = 0; | |
0e3936fa | 187 | break; |
f03530e6 | 188 | |
405c9168 BJ |
189 | /* |
190 | * Keep-alive timer went off; send something | |
191 | * or drop connection if idle for too long. | |
192 | */ | |
a6503abf | 193 | case TCPT_KEEP: |
f3cdd721 BJ |
194 | if (tp->t_state < TCPS_ESTABLISHED) |
195 | goto dropit; | |
c0200c65 MK |
196 | if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE && |
197 | tp->t_state <= TCPS_CLOSE_WAIT) { | |
f3cdd721 BJ |
198 | if (tp->t_idle >= TCPTV_MAXIDLE) |
199 | goto dropit; | |
3bd14c98 BJ |
200 | /* |
201 | * Saying tp->rcv_nxt-1 lies about what | |
202 | * we have received, and by the protocol spec | |
203 | * requires the correspondent TCP to respond. | |
204 | * Saying tp->snd_una-1 causes the transmitted | |
205 | * byte to lie outside the receive window; this | |
206 | * is important because we don't necessarily | |
207 | * have a byte in the window to send (consider | |
208 | * a one-way stream!) | |
209 | */ | |
8e65fd66 | 210 | tcp_respond(tp, |
3bd14c98 | 211 | tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); |
c0200c65 | 212 | } |
405c9168 | 213 | tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; |
0e3936fa | 214 | break; |
f3cdd721 | 215 | dropit: |
0e3936fa SL |
216 | tp = tcp_drop(tp, ETIMEDOUT); |
217 | break; | |
f03530e6 | 218 | } |
0e3936fa | 219 | return (tp); |
f03530e6 | 220 | } |