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