Commit | Line | Data |
---|---|---|
a1edc12b | 1 | /* tcp_timer.c 4.27 82/10/17 */ |
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" | |
fcfe450e | 9 | #include "../netinet/in.h" |
c124e997 | 10 | #include "../net/route.h" |
fcfe450e BJ |
11 | #include "../netinet/in_pcb.h" |
12 | #include "../netinet/in_systm.h" | |
f03530e6 | 13 | #include "../net/if.h" |
fcfe450e BJ |
14 | #include "../netinet/ip.h" |
15 | #include "../netinet/ip_var.h" | |
16 | #include "../netinet/tcp.h" | |
17 | #include "../netinet/tcp_fsm.h" | |
18 | #include "../netinet/tcp_seq.h" | |
19 | #include "../netinet/tcp_timer.h" | |
20 | #include "../netinet/tcp_var.h" | |
21 | #include "../netinet/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, | |
a1edc12b BJ |
75 | (struct mbuf *)i, |
76 | (struct sockopt *)0); | |
1e977657 BJ |
77 | if (ipnxt->inp_prev != ip) |
78 | goto tpgone; | |
79 | } | |
f03530e6 | 80 | } |
405c9168 BJ |
81 | tp->t_idle++; |
82 | if (tp->t_rtt) | |
83 | tp->t_rtt++; | |
1e977657 BJ |
84 | tpgone: |
85 | ip = ipnxt; | |
f03530e6 | 86 | } |
a6503abf | 87 | tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ |
f03530e6 BJ |
88 | splx(s); |
89 | } | |
90 | ||
91 | /* | |
a6503abf | 92 | * Cancel all timers for TCP tp. |
f03530e6 | 93 | */ |
0974b45c | 94 | tcp_canceltimers(tp) |
f03530e6 BJ |
95 | struct tcpcb *tp; |
96 | { | |
f03530e6 BJ |
97 | register int i; |
98 | ||
a6503abf BJ |
99 | for (i = 0; i < TCPT_NTIMERS; i++) |
100 | tp->t_timer[i] = 0; | |
f03530e6 BJ |
101 | } |
102 | ||
7380f986 BJ |
103 | float tcp_backoff[TCP_MAXRXTSHIFT] = |
104 | { 1.0, 1.2, 1.4, 1.7, 2.0, 3.0, 5.0, 8.0, 16.0, 32.0 }; | |
105 | int tcprexmtprint = 0; | |
106 | int tcpexprexmtbackoff = 0; | |
f03530e6 | 107 | /* |
405c9168 | 108 | * TCP timer processing. |
f03530e6 | 109 | */ |
a6503abf | 110 | tcp_timers(tp, timer) |
f03530e6 | 111 | register struct tcpcb *tp; |
a6503abf | 112 | int timer; |
f03530e6 BJ |
113 | { |
114 | ||
0974b45c | 115 | switch (timer) { |
f03530e6 | 116 | |
405c9168 BJ |
117 | /* |
118 | * 2 MSL timeout in shutdown went off. Delete connection | |
119 | * control block. | |
120 | */ | |
a6503abf BJ |
121 | case TCPT_2MSL: |
122 | tcp_close(tp); | |
123 | return; | |
f03530e6 | 124 | |
405c9168 BJ |
125 | /* |
126 | * Retransmission timer went off. Message has not | |
127 | * been acked within retransmit interval. Back off | |
128 | * to a longer retransmit interval and retransmit all | |
129 | * unacknowledged messages in the window. | |
130 | */ | |
a6503abf | 131 | case TCPT_REXMT: |
405c9168 | 132 | tp->t_rxtshift++; |
fd5dc5f0 BJ |
133 | if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { |
134 | tcp_drop(tp, ETIMEDOUT); | |
135 | return; | |
136 | } | |
405c9168 | 137 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], |
d977a479 | 138 | (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); |
7380f986 BJ |
139 | if (tcpexprexmtbackoff) { |
140 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
141 | tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, | |
142 | TCPTV_MIN, TCPTV_MAX); | |
143 | } else { | |
144 | TCPT_RANGESET(tp->t_timer[TCPT_REXMT], | |
145 | tp->t_timer[TCPT_REXMT] * | |
146 | tcp_backoff[tp->t_rxtshift - 1], | |
147 | TCPTV_MIN, TCPTV_MAX); | |
148 | } | |
d977a479 BJ |
149 | if (tcprexmtprint) |
150 | printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); | |
405c9168 BJ |
151 | tp->snd_nxt = tp->snd_una; |
152 | /* this only transmits one segment! */ | |
153 | (void) tcp_output(tp); | |
a6503abf | 154 | return; |
f03530e6 | 155 | |
405c9168 BJ |
156 | /* |
157 | * Persistance timer into zero window. | |
158 | * Force a byte to be output, if possible. | |
159 | */ | |
a6503abf | 160 | case TCPT_PERSIST: |
a13c006d | 161 | tcp_setpersist(tp); |
405c9168 BJ |
162 | tp->t_force = 1; |
163 | (void) tcp_output(tp); | |
164 | tp->t_force = 0; | |
0974b45c | 165 | return; |
f03530e6 | 166 | |
405c9168 BJ |
167 | /* |
168 | * Keep-alive timer went off; send something | |
169 | * or drop connection if idle for too long. | |
170 | */ | |
a6503abf | 171 | case TCPT_KEEP: |
f3cdd721 BJ |
172 | if (tp->t_state < TCPS_ESTABLISHED) |
173 | goto dropit; | |
3bd14c98 | 174 | if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { |
f3cdd721 BJ |
175 | if (tp->t_idle >= TCPTV_MAXIDLE) |
176 | goto dropit; | |
3bd14c98 BJ |
177 | /* |
178 | * Saying tp->rcv_nxt-1 lies about what | |
179 | * we have received, and by the protocol spec | |
180 | * requires the correspondent TCP to respond. | |
181 | * Saying tp->snd_una-1 causes the transmitted | |
182 | * byte to lie outside the receive window; this | |
183 | * is important because we don't necessarily | |
184 | * have a byte in the window to send (consider | |
185 | * a one-way stream!) | |
186 | */ | |
8e65fd66 | 187 | tcp_respond(tp, |
3bd14c98 BJ |
188 | tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); |
189 | } else | |
1e977657 | 190 | tp->t_idle = 0; |
405c9168 | 191 | tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; |
a6503abf | 192 | return; |
f3cdd721 BJ |
193 | dropit: |
194 | tcp_drop(tp, ETIMEDOUT); | |
195 | return; | |
f03530e6 | 196 | } |
f03530e6 | 197 | } |