2 * DECnet An implementation of the DECnet protocol suite for the LINUX
3 * operating system. DECnet is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * DECnet Socket Timer Functions
8 * Author: Steve Whitehouse <SteveW@ACM.org>
12 * Steve Whitehouse : Made keepalive timer part of the same
14 * Steve Whitehouse : Added checks for sk->sock_readers
15 * David S. Miller : New socket locking
16 * Steve Whitehouse : Timer grabs socket ref.
18 #include <linux/net.h>
19 #include <linux/socket.h>
20 #include <linux/skbuff.h>
21 #include <linux/netdevice.h>
22 #include <linux/timer.h>
23 #include <linux/spinlock.h>
25 #include <asm/atomic.h>
29 * Fast timer is for delayed acks (200mS max)
30 * Slow timer is for everything else (n * 500mS)
33 #define FAST_INTERVAL (HZ/5)
34 #define SLOW_INTERVAL (HZ/2)
36 static void dn_slow_timer(unsigned long arg
);
38 void dn_start_slow_timer(struct sock
*sk
)
40 sk
->timer
.expires
= jiffies
+ SLOW_INTERVAL
;
41 sk
->timer
.function
= dn_slow_timer
;
42 sk
->timer
.data
= (unsigned long)sk
;
44 add_timer(&sk
->timer
);
47 void dn_stop_slow_timer(struct sock
*sk
)
49 del_timer(&sk
->timer
);
52 static void dn_slow_timer(unsigned long arg
)
54 struct sock
*sk
= (struct sock
*)arg
;
55 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
60 if (sk
->lock
.users
!= 0) {
61 sk
->timer
.expires
= jiffies
+ HZ
/ 10;
62 add_timer(&sk
->timer
);
67 * The persist timer is the standard slow timer used for retransmits
68 * in both connection establishment and disconnection as well as
69 * in the RUN state. The different states are catered for by changing
70 * the function pointer in the socket. Setting the timer to a value
71 * of zero turns it off. We allow the persist_fxn to turn the
72 * timer off in a permant way by returning non-zero, so that
73 * timer based routines may remove sockets. This is why we have a
74 * sock_hold()/sock_put() around the timer to prevent the socket
75 * going away in the middle.
77 if (scp
->persist
&& scp
->persist_fxn
) {
78 if (scp
->persist
<= SLOW_INTERVAL
) {
81 if (scp
->persist_fxn(sk
))
84 scp
->persist
-= SLOW_INTERVAL
;
89 * Check for keepalive timeout. After the other timer 'cos if
90 * the previous timer caused a retransmit, we don't need to
91 * do this. scp->stamp is the last time that we sent a packet.
92 * The keepalive function sends a link service packet to the
93 * other end. If it remains unacknowledged, the standard
94 * socket timers will eventually shut the socket down. Each
95 * time we do this, scp->stamp will be updated, thus
96 * we won't try and send another until scp->keepalive has passed
97 * since the last successful transmission.
99 if (scp
->keepalive
&& scp
->keepalive_fxn
&& (scp
->state
== DN_RUN
)) {
100 if ((jiffies
- scp
->stamp
) >= scp
->keepalive
)
101 scp
->keepalive_fxn(sk
);
104 sk
->timer
.expires
= jiffies
+ SLOW_INTERVAL
;
106 add_timer(&sk
->timer
);
112 static void dn_fast_timer(unsigned long arg
)
114 struct sock
*sk
= (struct sock
*)arg
;
115 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
118 if (sk
->lock
.users
!= 0) {
119 scp
->delack_timer
.expires
= jiffies
+ HZ
/ 20;
120 add_timer(&scp
->delack_timer
);
124 scp
->delack_pending
= 0;
132 void dn_start_fast_timer(struct sock
*sk
)
134 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
136 if (!scp
->delack_pending
) {
137 scp
->delack_pending
= 1;
138 init_timer(&scp
->delack_timer
);
139 scp
->delack_timer
.expires
= jiffies
+ FAST_INTERVAL
;
140 scp
->delack_timer
.data
= (unsigned long)sk
;
141 scp
->delack_timer
.function
= dn_fast_timer
;
142 add_timer(&scp
->delack_timer
);
146 void dn_stop_fast_timer(struct sock
*sk
)
148 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
150 if (scp
->delack_pending
) {
151 scp
->delack_pending
= 0;
152 del_timer(&scp
->delack_timer
);