This source file includes following definitions.
- delete_timer
- reset_timer
- net_timer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <linux/types.h>
35 #include <linux/errno.h>
36 #include <linux/socket.h>
37 #include <linux/in.h>
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/timer.h>
41 #include <asm/system.h>
42 #include <linux/interrupt.h>
43 #include "inet.h"
44 #include "dev.h"
45 #include "ip.h"
46 #include "protocol.h"
47 #include "tcp.h"
48 #include "skbuff.h"
49 #include "sock.h"
50 #include "arp.h"
51
52 void
53 delete_timer (struct sock *t)
54 {
55 unsigned long flags;
56
57 save_flags (flags);
58 cli();
59
60 t->timeout = 0;
61 del_timer (&t->timer);
62
63 restore_flags (flags);
64 }
65
66 void
67 reset_timer (struct sock *t, int timeout, unsigned long len)
68 {
69 delete_timer (t);
70
71 if (timeout != -1)
72 t->timeout = timeout;
73
74 #if 1
75
76 if ((int) len < 0)
77 len = 3;
78 #endif
79 t->timer.expires = len;
80 add_timer (&t->timer);
81 }
82
83
84
85
86
87
88
89 void
90 net_timer (unsigned long data)
91 {
92 struct sock *sk = (struct sock*)data;
93 int why = sk->timeout;
94
95
96 if (sk->inuse || in_inet_bh()) {
97 sk->timer.expires = 10;
98 add_timer(&sk->timer);
99 return;
100 }
101 sk->inuse = 1;
102
103 DPRINTF ((DBG_TMR, "net_timer: found sk=%X why = %d\n", sk, why));
104 if (sk->keepopen)
105 reset_timer (sk, TIME_KEEPOPEN, TCP_TIMEOUT_LEN);
106
107
108 if (sk->ack_backlog) {
109 sk->prot->read_wakeup (sk);
110 if (! sk->dead)
111 wake_up (sk->sleep);
112 }
113
114
115 switch (why) {
116 case TIME_DONE:
117 if (! sk->dead || sk->state != TCP_CLOSE) {
118 printk ("non dead socket in time_done\n");
119 release_sock (sk);
120 break;
121 }
122 destroy_sock (sk);
123 break;
124 case TIME_DESTROY:
125
126
127
128 if(sk->wmem_alloc!=0 || sk->rmem_alloc!=0)
129 {
130 DPRINTF ((DBG_TMR, "possible memory leak. sk = %X\n", sk));
131 sk->wmem_alloc++;
132 destroy_sock (sk);
133 sk->wmem_alloc--;
134 sk->inuse = 0;
135 }
136 if(sk->wmem_alloc==0 && sk->rmem_alloc==0)
137 destroy_sock(sk);
138 break;
139 case TIME_CLOSE:
140
141 sk->state = TCP_CLOSE;
142 delete_timer (sk);
143
144 arp_destroy (sk->daddr);
145 if (!sk->dead)
146 wake_up (sk->sleep);
147 sk->shutdown = SHUTDOWN_MASK;
148 reset_timer (sk, TIME_DESTROY, TCP_DONE_TIME);
149 release_sock (sk);
150 break;
151 case TIME_WRITE:
152
153
154
155 if (sk->send_head) {
156 if (jiffies < (sk->send_head->when + backoff (sk->backoff)
157 * (2 * sk->mdev + sk->rtt))) {
158 reset_timer (sk, TIME_WRITE, (sk->send_head->when
159 + backoff (sk->backoff) * (2 * sk->mdev + sk->rtt)) - jiffies);
160 release_sock (sk);
161 break;
162 }
163
164
165 DPRINTF ((DBG_TMR, "retransmitting.\n"));
166 sk->prot->retransmit (sk, 0);
167 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
168 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1)) {
169 DPRINTF ((DBG_TMR, "timer.c TIME_WRITE time-out 1\n"));
170 arp_destroy (sk->daddr);
171 ip_route_check (sk->daddr);
172 }
173 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2) {
174 DPRINTF ((DBG_TMR, "timer.c TIME_WRITE time-out 2\n"));
175 sk->err = ETIMEDOUT;
176 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2
177 || sk->state == TCP_LAST_ACK) {
178 sk->state = TCP_TIME_WAIT;
179 reset_timer (sk, TIME_CLOSE, TCP_TIMEWAIT_LEN);
180 } else {
181 sk->prot->close (sk, 1);
182 break;
183 }
184 }
185 }
186 release_sock (sk);
187 break;
188 case TIME_KEEPOPEN:
189
190 if (sk->prot->write_wakeup)
191 sk->prot->write_wakeup (sk);
192 sk->retransmits++;
193 if (sk->shutdown == SHUTDOWN_MASK) {
194 sk->prot->close (sk, 1);
195 sk->state = TCP_CLOSE;
196 }
197
198 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
199 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1)) {
200 DPRINTF ((DBG_TMR, "timer.c TIME_KEEPOPEN time-out 1\n"));
201 arp_destroy (sk->daddr);
202 ip_route_check (sk->daddr);
203 release_sock (sk);
204 break;
205 }
206 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2) {
207 DPRINTF ((DBG_TMR, "timer.c TIME_KEEPOPEN time-out 2\n"));
208 arp_destroy (sk->daddr);
209 sk->err = ETIMEDOUT;
210 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2) {
211 sk->state = TCP_TIME_WAIT;
212 if (!sk->dead)
213 wake_up (sk->sleep);
214 release_sock (sk);
215 } else {
216 sk->prot->close (sk, 1);
217 }
218 break;
219 }
220 release_sock (sk);
221 break;
222 default:
223 printk ("net timer expired - reason unknown, sk=%08X\n", (int)sk);
224 release_sock (sk);
225 break;
226 }
227 }
228