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
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 t->timeout = timeout;
72
73 #if 1
74
75 if ((int) len < 0)
76 len = 3;
77 #endif
78 t->timer.expires = len;
79 add_timer (&t->timer);
80 }
81
82
83
84
85
86
87
88 void
89 net_timer (unsigned long data)
90 {
91 struct sock *sk = (struct sock*)data;
92 int why = sk->timeout;
93
94
95 cli();
96 if (sk->inuse || in_bh) {
97 sk->timer.expires = 10;
98 add_timer(&sk->timer);
99 sti();
100 return;
101 }
102 sk->inuse = 1;
103 sti();
104
105 DPRINTF ((DBG_TMR, "net_timer: found sk=%X why = %d\n", sk, why));
106 if (skb_peek(&sk->write_queue) &&
107 before(sk->window_seq, sk->write_queue.next->h.seq) &&
108 sk->send_head == NULL &&
109 sk->ack_backlog == 0 &&
110 sk->state != TCP_TIME_WAIT)
111 reset_timer(sk, TIME_PROBE0, sk->rto);
112 else if (sk->keepopen)
113 reset_timer (sk, TIME_KEEPOPEN, TCP_TIMEOUT_LEN);
114
115
116 if (sk->ack_backlog) {
117 sk->prot->read_wakeup (sk);
118 if (! sk->dead)
119 sk->data_ready(sk,0);
120 }
121
122
123 switch (why) {
124 case TIME_DONE:
125 if (! sk->dead || sk->state != TCP_CLOSE) {
126 printk ("non dead socket in time_done\n");
127 release_sock (sk);
128 break;
129 }
130 destroy_sock (sk);
131 break;
132 case TIME_DESTROY:
133
134
135
136 if(sk->wmem_alloc!=0 || sk->rmem_alloc!=0)
137 {
138 DPRINTF ((DBG_TMR, "possible memory leak. sk = %X\n", sk));
139 sk->wmem_alloc++;
140 destroy_sock (sk);
141 sk->wmem_alloc--;
142 sk->inuse = 0;
143 }
144 if(sk->wmem_alloc==0 && sk->rmem_alloc==0)
145 destroy_sock(sk);
146 break;
147 case TIME_CLOSE:
148
149 sk->state = TCP_CLOSE;
150 delete_timer (sk);
151
152 arp_destroy (sk->daddr, 0);
153 if (!sk->dead)
154 sk->state_change(sk);
155 sk->shutdown = SHUTDOWN_MASK;
156 reset_timer (sk, TIME_DESTROY, TCP_DONE_TIME);
157 release_sock (sk);
158 break;
159 case TIME_PROBE0:
160 tcp_send_probe0(sk);
161 release_sock (sk);
162 break;
163 case TIME_WRITE:
164
165
166
167 {
168 struct sk_buff *skb;
169 unsigned long flags;
170
171 save_flags(flags);
172 cli();
173 skb = sk->send_head;
174 if (!skb) {
175 restore_flags(flags);
176 } else {
177 if (jiffies < skb->when + sk->rto) {
178 reset_timer (sk, TIME_WRITE, skb->when + sk->rto - jiffies);
179 restore_flags(flags);
180 release_sock (sk);
181 break;
182 }
183 restore_flags(flags);
184
185
186 DPRINTF ((DBG_TMR, "retransmitting.\n"));
187 sk->prot->retransmit (sk, 0);
188 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
189 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1)) {
190 DPRINTF ((DBG_TMR, "timer.c TIME_WRITE time-out 1\n"));
191 arp_destroy (sk->daddr, 0);
192 ip_route_check (sk->daddr);
193 }
194 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2) {
195 DPRINTF ((DBG_TMR, "timer.c TIME_WRITE time-out 2\n"));
196 sk->err = ETIMEDOUT;
197 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2
198 || sk->state == TCP_LAST_ACK) {
199 sk->state = TCP_TIME_WAIT;
200 reset_timer (sk, TIME_CLOSE, TCP_TIMEWAIT_LEN);
201 } else {
202 sk->prot->close (sk, 1);
203 break;
204 }
205 }
206 }
207 release_sock (sk);
208 break;
209 }
210 case TIME_KEEPOPEN:
211
212 if (sk->prot->write_wakeup)
213 sk->prot->write_wakeup (sk);
214 sk->retransmits++;
215 if (sk->shutdown == SHUTDOWN_MASK) {
216 sk->prot->close (sk, 1);
217 sk->state = TCP_CLOSE;
218 }
219
220 if ((sk->state == TCP_ESTABLISHED && sk->retransmits && !(sk->retransmits & 7))
221 || (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR1)) {
222 DPRINTF ((DBG_TMR, "timer.c TIME_KEEPOPEN time-out 1\n"));
223 arp_destroy (sk->daddr, 0);
224 ip_route_check (sk->daddr);
225 release_sock (sk);
226 break;
227 }
228 if (sk->state != TCP_ESTABLISHED && sk->retransmits > TCP_RETR2) {
229 DPRINTF ((DBG_TMR, "timer.c TIME_KEEPOPEN time-out 2\n"));
230 arp_destroy (sk->daddr, 0);
231 sk->err = ETIMEDOUT;
232 if (sk->state == TCP_FIN_WAIT1 || sk->state == TCP_FIN_WAIT2) {
233 sk->state = TCP_TIME_WAIT;
234 if (!sk->dead)
235 sk->state_change(sk);
236 release_sock (sk);
237 } else {
238 sk->prot->close (sk, 1);
239 }
240 break;
241 }
242 release_sock (sk);
243 break;
244 default:
245 printk ("net_timer: timer expired - reason unknown\n");
246 release_sock (sk);
247 break;
248 }
249 }
250