Commit | Line | Data |
---|---|---|
c47a5909 | 1 | /* tcp_timer.c 4.24 82/06/26 */ |
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" |
c47a5909 | 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(); | |
b8b9174f | 33 | |
fd5dc5f0 BJ |
34 | inp = tcb.inp_next; |
35 | if (inp) | |
36 | for (; inp != &tcb; inp = inp->inp_next) | |
b8b9174f BJ |
37 | if ((tp = (struct tcpcb *)inp->inp_ppcb) && |
38 | (tp->t_flags & TF_DELACK)) { | |
39 | tp->t_flags &= ~TF_DELACK; | |
40 | tp->t_flags |= TF_ACKNOW; | |
41 | (void) tcp_output(tp); | |
42 | } | |
43 | splx(s); | |
f03530e6 BJ |
44 | } |
45 | ||
46 | /* | |
47 | * Tcp protocol timeout routine called every 500 ms. | |
48 | * Updates the timers in all active tcb's and | |
49 | * causes finite state machine actions if timers expire. | |
50 | */ | |
51 | tcp_slowtimo() | |
52 | { | |
1e977657 | 53 | register struct inpcb *ip, *ipnxt; |
f03530e6 BJ |
54 | register struct tcpcb *tp; |
55 | int s = splnet(); | |
f03530e6 | 56 | register int i; |
f03530e6 BJ |
57 | |
58 | /* | |
59 | * Search through tcb's and update active timers. | |
60 | */ | |
4aed14e3 BJ |
61 | ip = tcb.inp_next; |
62 | if (ip == 0) { | |
63 | splx(s); | |
64 | return; | |
65 | } | |
1e977657 | 66 | while (ip != &tcb) { |
f03530e6 | 67 | tp = intotcpcb(ip); |
37de812c BJ |
68 | if (tp == 0) |
69 | continue; | |
1e977657 | 70 | ipnxt = ip->inp_next; |
a6503abf | 71 | for (i = 0; i < TCPT_NTIMERS; i++) { |
1e977657 | 72 | if (tp->t_timer[i] && --tp->t_timer[i] == 0) { |
f03530e6 BJ |
73 | (void) tcp_usrreq(tp->t_inpcb->inp_socket, |
74 | PRU_SLOWTIMO, (struct mbuf *)0, | |
75 | (caddr_t)i); | |
1e977657 BJ |
76 | if (ipnxt->inp_prev != ip) |
77 | goto tpgone; | |
78 | } | |
f03530e6 | 79 | } |
405c9168 BJ |
80 | tp->t_idle++; |
81 | if (tp->t_rtt) | |
82 | tp->t_rtt++; | |
1e977657 BJ |
83 | tpgone: |
84 | ip = ipnxt; | |
f03530e6 | 85 | } |
a6503abf | 86 | tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ |
f03530e6 BJ |
87 | splx(s); |
88 | } | |
89 | ||
90 | /* | |
a6503abf | 91 | * Cancel all timers for TCP tp. |
f03530e6 | 92 | */ |
0974b45c | 93 | tcp_canceltimers(tp) |
f03530e6 BJ |
94 | struct tcpcb *tp; |
95 | { | |
f03530e6 BJ |
96 | register int i; |
97 | ||
a6503abf BJ |
98 | for (i = 0; i < TCPT_NTIMERS; i++) |
99 | tp->t_timer[i] = 0; | |
f03530e6 BJ |
100 | } |
101 | ||
7380f986 BJ |
102 | float tcp_backoff[TCP_MAXRXTSHIFT] = |
103 | { 1.0, 1.2, 1.4, 1.7, 2.0, 3.0, 5.0, 8.0, 16.0, 32.0 }; | |
104 | int tcprexmtprint = 0; | |
105 | int tcpexprexmtbackoff = 0; | |
f03530e6 | 106 | /* |
405c9168 | 107 | * TCP timer processing. |
f03530e6 | 108 | */ |
a6503abf | 109 | tcp_timers(tp, timer) |
f03530e6 | 110 | register struct tcpcb *tp; |
a6503abf | 111 | int timer; |
f03530e6 BJ |
112 | { |
113 | ||
0974b45c | 114 | switch (timer) { |
f03530e6 | 115 | |
405c9168 BJ |
116 | /* |
117 | * 2 MSL timeout in shutdown went off. Delete connection | |
118 | * control block. | |
119 | */ | |
a6503abf BJ |
120 | case TCPT_2MSL: |
121 | tcp_close(tp); | |
122 | return; | |
f03530e6 | 123 | |
405c9168 BJ |
124 | /* |
125 | * Retransmission timer went off. Message has not | |
126 | * been acked within retransmit interval. Back off | |
127 | * to a longer retransmit interval and retransmit all | |
128 | * unacknowledged messages in the window. | |
129 | */ | |
a6503abf | 130 | case TCPT_REXMT: |
405c9168 | 131 | tp->t_rxtshift++; |
fd5dc5f0 BJ |
132 | if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { |
133 | tcp_drop(tp, ETIMEDOUT); | |
134 | return; | |
135 | } | |
405c9168 | 136 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], |
d977a479 | 137 | (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); |
7380f986 BJ |
138 | if (tcpexprexmtbackoff) { |
139 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
140 | tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, | |
141 | TCPTV_MIN, TCPTV_MAX); | |
142 | } else { | |
143 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
144 | tp->t_timer[TCPT_REXMT] * | |
145 | tcp_backoff[tp->t_rxtshift - 1], | |
146 | TCPTV_MIN, TCPTV_MAX); | |
147 | } | |
d977a479 BJ |
148 | if (tcprexmtprint) |
149 | printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); | |
405c9168 BJ |
150 | tp->snd_nxt = tp->snd_una; |
151 | /* this only transmits one segment! */ | |
152 | (void) tcp_output(tp); | |
a6503abf | 153 | return; |
f03530e6 | 154 | |
405c9168 BJ |
155 | /* |
156 | * Persistance timer into zero window. | |
157 | * Force a byte to be output, if possible. | |
158 | */ | |
a6503abf | 159 | case TCPT_PERSIST: |
a13c006d | 160 | tcp_setpersist(tp); |
405c9168 BJ |
161 | tp->t_force = 1; |
162 | (void) tcp_output(tp); | |
163 | tp->t_force = 0; | |
0974b45c | 164 | return; |
f03530e6 | 165 | |
405c9168 BJ |
166 | /* |
167 | * Keep-alive timer went off; send something | |
168 | * or drop connection if idle for too long. | |
169 | */ | |
a6503abf | 170 | case TCPT_KEEP: |
f3cdd721 BJ |
171 | if (tp->t_state < TCPS_ESTABLISHED) |
172 | goto dropit; | |
3bd14c98 | 173 | if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { |
f3cdd721 BJ |
174 | if (tp->t_idle >= TCPTV_MAXIDLE) |
175 | goto dropit; | |
3bd14c98 BJ |
176 | /* |
177 | * Saying tp->rcv_nxt-1 lies about what | |
178 | * we have received, and by the protocol spec | |
179 | * requires the correspondent TCP to respond. | |
180 | * Saying tp->snd_una-1 causes the transmitted | |
181 | * byte to lie outside the receive window; this | |
182 | * is important because we don't necessarily | |
183 | * have a byte in the window to send (consider | |
184 | * a one-way stream!) | |
185 | */ | |
8e65fd66 | 186 | tcp_respond(tp, |
3bd14c98 BJ |
187 | tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); |
188 | } else | |
1e977657 | 189 | tp->t_idle = 0; |
405c9168 | 190 | tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; |
a6503abf | 191 | return; |
f3cdd721 BJ |
192 | dropit: |
193 | tcp_drop(tp, ETIMEDOUT); | |
194 | return; | |
8b5a83bb BJ |
195 | |
196 | #ifdef TCPTRUEOOB | |
197 | /* | |
198 | * Out-of-band data retransmit timer. | |
199 | */ | |
200 | case TCPT_OOBREXMT: | |
201 | if (tp->t_flags & TF_NOOPT) | |
202 | return; | |
203 | (void) tcp_output(tp); | |
204 | TCPT_RANGESET(tp->t_timer[TCPT_OOBREXMT], | |
205 | 2 * tp->t_srtt, TCPTV_MIN, TCPTV_MAX); | |
206 | return; | |
207 | #endif | |
f03530e6 | 208 | } |
f03530e6 | 209 | } |