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 <linux/inet.h>
44 #include <linux/netdevice.h>
45 #include "ip.h"
46 #include "protocol.h"
47 #include "tcp.h"
48 #include <linux/skbuff.h>
49 #include "sock.h"
50 #include "arp.h"
51
52 void delete_timer (struct sock *t)
53 {
54 unsigned long flags;
55
56 save_flags (flags);
57 cli();
58
59 t->timeout = 0;
60 del_timer (&t->timer);
61
62 restore_flags (flags);
63 }
64
65 void reset_timer (struct sock *t, int timeout, unsigned long len)
66 {
67 delete_timer (t);
68 t->timeout = timeout;
69 #if 1
70
71 if ((int) len < 0)
72 len = 3;
73 #endif
74 t->timer.expires = len;
75 add_timer (&t->timer);
76 }
77
78
79
80
81
82
83
84
85 void net_timer (unsigned long data)
86 {
87 struct sock *sk = (struct sock*)data;
88 int why = sk->timeout;
89
90
91
92
93
94 cli();
95 if (sk->inuse || in_bh)
96 {
97 sk->timer.expires = 10;
98 add_timer(&sk->timer);
99 sti();
100 return;
101 }
102
103 sk->inuse = 1;
104 sti();
105
106 #ifdef NOTDEF
107
108
109
110
111
112
113 if (skb_peek(&sk->write_queue) &&
114 before(sk->window_seq, sk->write_queue.next->h.seq) &&
115 sk->send_head == NULL &&
116 sk->ack_backlog == 0 &&
117 sk->state != TCP_TIME_WAIT)
118 reset_timer(sk, TIME_PROBE0, sk->rto);
119 else if (sk->keepopen)
120 reset_timer (sk, TIME_KEEPOPEN, TCP_TIMEOUT_LEN);
121 #endif
122
123
124
125 if (sk->ack_backlog)
126 {
127 sk->prot->read_wakeup (sk);
128 if (! sk->dead)
129 sk->data_ready(sk,0);
130 }
131
132
133
134 switch (why)
135 {
136 case TIME_DONE:
137 if (! sk->dead || sk->state != TCP_CLOSE)
138 {
139 printk ("non dead socket in time_done\n");
140 release_sock (sk);
141 break;
142 }
143 destroy_sock (sk);
144 break;
145
146 case TIME_DESTROY:
147
148
149
150
151 if(sk->wmem_alloc!=0 || sk->rmem_alloc!=0)
152 {
153 sk->wmem_alloc++;
154 destroy_sock (sk);
155 sk->wmem_alloc--;
156 sk->inuse = 0;
157 }
158 if(sk->wmem_alloc==0 && sk->rmem_alloc==0)
159 destroy_sock(sk);
160 break;
161 case TIME_CLOSE:
162
163 sk->state = TCP_CLOSE;
164 delete_timer (sk);
165
166 arp_destroy (sk->daddr, 0);
167 if (!sk->dead)
168 sk->state_change(sk);
169 sk->shutdown = SHUTDOWN_MASK;
170 reset_timer (sk, TIME_DESTROY, TCP_DONE_TIME);
171 release_sock (sk);
172 break;
173 case TIME_PROBE0:
174 tcp_send_probe0(sk);
175 release_sock (sk);
176 break;
177 case TIME_WRITE:
178
179
180
181 {
182 struct sk_buff *skb;
183 unsigned long flags;
184
185 save_flags(flags);
186 cli();
187 skb = sk->send_head;
188 if (!skb)
189 {
190 restore_flags(flags);
191 }
192 else
193 {
194 if (jiffies < skb->when + sk->rto)
195 {
196 reset_timer (sk, TIME_WRITE, skb->when + sk->rto - jiffies);
197 restore_flags(flags);
198 release_sock (sk);
199 break;
200 }
201 restore_flags(flags);
202
203
204 sk->prot->retransmit (sk, 0);
205 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
206 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1))
207 {
208 arp_destroy (sk->daddr, 0);
209 ip_route_check (sk->daddr);
210 }
211 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2)
212 {
213 sk->err = ETIMEDOUT;
214 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2 || sk->state == TCP_CLOSING)
215 {
216 sk->state = TCP_TIME_WAIT;
217 reset_timer (sk, TIME_CLOSE, TCP_TIMEWAIT_LEN);
218 }
219 else
220 {
221 sk->prot->close (sk, 1);
222 break;
223 }
224 }
225 }
226 release_sock (sk);
227 break;
228 }
229 case TIME_KEEPOPEN:
230
231
232
233
234 reset_timer (sk, TIME_KEEPOPEN, TCP_TIMEOUT_LEN);
235
236
237 if (sk->prot->write_wakeup)
238 sk->prot->write_wakeup (sk);
239 sk->retransmits++;
240 if (sk->shutdown == SHUTDOWN_MASK)
241 {
242 sk->prot->close (sk, 1);
243 sk->state = TCP_CLOSE;
244 }
245 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
246 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1))
247 {
248 arp_destroy (sk->daddr, 0);
249 ip_route_check (sk->daddr);
250 release_sock (sk);
251 break;
252 }
253 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2)
254 {
255 arp_destroy (sk->daddr, 0);
256 sk->err = ETIMEDOUT;
257 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2)
258 {
259 sk->state = TCP_TIME_WAIT;
260 if (!sk->dead)
261 sk->state_change(sk);
262 release_sock (sk);
263 }
264 else
265 {
266 sk->prot->close (sk, 1);
267 }
268 break;
269 }
270 release_sock (sk);
271 break;
272 default:
273 printk ("net_timer: timer expired - reason unknown\n");
274 release_sock (sk);
275 break;
276 }
277 }
278