Commit | Line | Data |
---|---|---|
7380f986 | 1 | /* tcp_timer.c 4.20 82/04/04 */ |
f03530e6 BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/systm.h" | |
5 | #include "../h/mbuf.h" | |
6 | #include "../h/socket.h" | |
7 | #include "../h/socketvar.h" | |
8 | #include "../h/protosw.h" | |
0974b45c | 9 | #include "../net/in.h" |
c124e997 | 10 | #include "../net/route.h" |
0974b45c BJ |
11 | #include "../net/in_pcb.h" |
12 | #include "../net/in_systm.h" | |
f03530e6 | 13 | #include "../net/if.h" |
f03530e6 BJ |
14 | #include "../net/ip.h" |
15 | #include "../net/ip_var.h" | |
16 | #include "../net/tcp.h" | |
17 | #include "../net/tcp_fsm.h" | |
0974b45c BJ |
18 | #include "../net/tcp_seq.h" |
19 | #include "../net/tcp_timer.h" | |
f03530e6 | 20 | #include "../net/tcp_var.h" |
0974b45c | 21 | #include "../net/tcpip.h" |
f1b2fa5b | 22 | #include "../errno.h" |
f03530e6 | 23 | |
8b5a83bb | 24 | int tcpnodelack = 0; |
f03530e6 BJ |
25 | /* |
26 | * Fast timeout routine for processing delayed acks | |
27 | */ | |
28 | tcp_fasttimo() | |
29 | { | |
b8b9174f BJ |
30 | register struct inpcb *inp; |
31 | register struct tcpcb *tp; | |
32 | int s = splnet(); | |
0974b45c | 33 | COUNT(TCP_FASTTIMO); |
b8b9174f | 34 | |
fd5dc5f0 BJ |
35 | inp = tcb.inp_next; |
36 | if (inp) | |
37 | for (; inp != &tcb; inp = inp->inp_next) | |
b8b9174f BJ |
38 | if ((tp = (struct tcpcb *)inp->inp_ppcb) && |
39 | (tp->t_flags & TF_DELACK)) { | |
40 | tp->t_flags &= ~TF_DELACK; | |
41 | tp->t_flags |= TF_ACKNOW; | |
42 | (void) tcp_output(tp); | |
43 | } | |
44 | splx(s); | |
f03530e6 BJ |
45 | } |
46 | ||
47 | /* | |
48 | * Tcp protocol timeout routine called every 500 ms. | |
49 | * Updates the timers in all active tcb's and | |
50 | * causes finite state machine actions if timers expire. | |
51 | */ | |
52 | tcp_slowtimo() | |
53 | { | |
1e977657 | 54 | register struct inpcb *ip, *ipnxt; |
f03530e6 BJ |
55 | register struct tcpcb *tp; |
56 | int s = splnet(); | |
f03530e6 | 57 | register int i; |
0974b45c | 58 | COUNT(TCP_SLOWTIMO); |
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, | |
77 | (caddr_t)i); | |
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 |
85 | tpgone: |
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 | 95 | tcp_canceltimers(tp) |
f03530e6 BJ |
96 | struct tcpcb *tp; |
97 | { | |
f03530e6 BJ |
98 | register int i; |
99 | ||
0974b45c | 100 | COUNT(TCP_CANCELTIMERS); |
a6503abf BJ |
101 | for (i = 0; i < TCPT_NTIMERS; i++) |
102 | tp->t_timer[i] = 0; | |
f03530e6 BJ |
103 | } |
104 | ||
7380f986 BJ |
105 | float tcp_backoff[TCP_MAXRXTSHIFT] = |
106 | { 1.0, 1.2, 1.4, 1.7, 2.0, 3.0, 5.0, 8.0, 16.0, 32.0 }; | |
107 | int tcprexmtprint = 0; | |
108 | int tcpexprexmtbackoff = 0; | |
f03530e6 | 109 | /* |
405c9168 | 110 | * TCP timer processing. |
f03530e6 | 111 | */ |
a6503abf | 112 | tcp_timers(tp, timer) |
f03530e6 | 113 | register struct tcpcb *tp; |
a6503abf | 114 | int timer; |
f03530e6 BJ |
115 | { |
116 | ||
117 | COUNT(TCP_TIMERS); | |
0974b45c | 118 | switch (timer) { |
f03530e6 | 119 | |
405c9168 BJ |
120 | /* |
121 | * 2 MSL timeout in shutdown went off. Delete connection | |
122 | * control block. | |
123 | */ | |
a6503abf BJ |
124 | case TCPT_2MSL: |
125 | tcp_close(tp); | |
126 | return; | |
f03530e6 | 127 | |
405c9168 BJ |
128 | /* |
129 | * Retransmission timer went off. Message has not | |
130 | * been acked within retransmit interval. Back off | |
131 | * to a longer retransmit interval and retransmit all | |
132 | * unacknowledged messages in the window. | |
133 | */ | |
a6503abf | 134 | case TCPT_REXMT: |
405c9168 | 135 | tp->t_rxtshift++; |
fd5dc5f0 BJ |
136 | if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { |
137 | tcp_drop(tp, ETIMEDOUT); | |
138 | return; | |
139 | } | |
405c9168 | 140 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], |
d977a479 | 141 | (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); |
7380f986 BJ |
142 | if (tcpexprexmtbackoff) { |
143 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
144 | tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, | |
145 | TCPTV_MIN, TCPTV_MAX); | |
146 | } else { | |
147 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
148 | tp->t_timer[TCPT_REXMT] * | |
149 | tcp_backoff[tp->t_rxtshift - 1], | |
150 | TCPTV_MIN, TCPTV_MAX); | |
151 | } | |
d977a479 BJ |
152 | if (tcprexmtprint) |
153 | printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); | |
405c9168 BJ |
154 | tp->snd_nxt = tp->snd_una; |
155 | /* this only transmits one segment! */ | |
156 | (void) tcp_output(tp); | |
a6503abf | 157 | return; |
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: |
405c9168 BJ |
164 | tp->t_force = 1; |
165 | (void) tcp_output(tp); | |
166 | tp->t_force = 0; | |
167 | TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], | |
d977a479 | 168 | tcp_beta * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX); |
0974b45c | 169 | return; |
f03530e6 | 170 | |
405c9168 BJ |
171 | /* |
172 | * Keep-alive timer went off; send something | |
173 | * or drop connection if idle for too long. | |
174 | */ | |
a6503abf | 175 | case TCPT_KEEP: |
f3cdd721 BJ |
176 | if (tp->t_state < TCPS_ESTABLISHED) |
177 | goto dropit; | |
3bd14c98 | 178 | if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { |
f3cdd721 BJ |
179 | if (tp->t_idle >= TCPTV_MAXIDLE) |
180 | goto dropit; | |
3bd14c98 BJ |
181 | /* |
182 | * Saying tp->rcv_nxt-1 lies about what | |
183 | * we have received, and by the protocol spec | |
184 | * requires the correspondent TCP to respond. | |
185 | * Saying tp->snd_una-1 causes the transmitted | |
186 | * byte to lie outside the receive window; this | |
187 | * is important because we don't necessarily | |
188 | * have a byte in the window to send (consider | |
189 | * a one-way stream!) | |
190 | */ | |
8e65fd66 | 191 | tcp_respond(tp, |
3bd14c98 BJ |
192 | tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); |
193 | } else | |
1e977657 | 194 | tp->t_idle = 0; |
405c9168 | 195 | tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; |
a6503abf | 196 | return; |
f3cdd721 BJ |
197 | dropit: |
198 | tcp_drop(tp, ETIMEDOUT); | |
199 | return; | |
8b5a83bb BJ |
200 | |
201 | #ifdef TCPTRUEOOB | |
202 | /* | |
203 | * Out-of-band data retransmit timer. | |
204 | */ | |
205 | case TCPT_OOBREXMT: | |
206 | if (tp->t_flags & TF_NOOPT) | |
207 | return; | |
208 | (void) tcp_output(tp); | |
209 | TCPT_RANGESET(tp->t_timer[TCPT_OOBREXMT], | |
210 | 2 * tp->t_srtt, TCPTV_MIN, TCPTV_MAX); | |
211 | return; | |
212 | #endif | |
f03530e6 | 213 | } |
f03530e6 | 214 | } |