blob: 1d330fd43dc7e177d162f77796d2142a4e563fdb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
5 *
6 * DECnet Socket Timer Functions
7 *
8 * Author: Steve Whitehouse <SteveW@ACM.org>
9 *
10 *
11 * Changes:
12 * Steve Whitehouse : Made keepalive timer part of the same
13 * timer idea.
14 * Steve Whitehouse : Added checks for sk->sock_readers
15 * David S. Miller : New socket locking
16 * Steve Whitehouse : Timer grabs socket ref.
17 */
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>
24#include <net/sock.h>
Arun Sharma600634972011-07-26 16:09:06 -070025#include <linux/atomic.h>
Himangi Saraogi8b1b1eb2014-08-20 23:20:09 +053026#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <net/flow.h>
28#include <net/dn.h>
29
30/*
31 * Slow timer is for everything else (n * 500mS)
32 */
33
34#define SLOW_INTERVAL (HZ/2)
35
36static void dn_slow_timer(unsigned long arg);
37
38void dn_start_slow_timer(struct sock *sk)
39{
Eric Dumazet8a6e77d2011-11-21 00:21:55 +000040 setup_timer(&sk->sk_timer, dn_slow_timer, (unsigned long)sk);
41 sk_reset_timer(sk, &sk->sk_timer, jiffies + SLOW_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
44void dn_stop_slow_timer(struct sock *sk)
45{
Eric Dumazet8a6e77d2011-11-21 00:21:55 +000046 sk_stop_timer(sk, &sk->sk_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49static void dn_slow_timer(unsigned long arg)
50{
51 struct sock *sk = (struct sock *)arg;
52 struct dn_scp *scp = DN_SK(sk);
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 bh_lock_sock(sk);
55
56 if (sock_owned_by_user(sk)) {
Eric Dumazet8a6e77d2011-11-21 00:21:55 +000057 sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ / 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 goto out;
59 }
60
61 /*
62 * The persist timer is the standard slow timer used for retransmits
63 * in both connection establishment and disconnection as well as
64 * in the RUN state. The different states are catered for by changing
65 * the function pointer in the socket. Setting the timer to a value
66 * of zero turns it off. We allow the persist_fxn to turn the
67 * timer off in a permant way by returning non-zero, so that
68 * timer based routines may remove sockets. This is why we have a
69 * sock_hold()/sock_put() around the timer to prevent the socket
70 * going away in the middle.
71 */
72 if (scp->persist && scp->persist_fxn) {
73 if (scp->persist <= SLOW_INTERVAL) {
74 scp->persist = 0;
75
76 if (scp->persist_fxn(sk))
77 goto out;
78 } else {
79 scp->persist -= SLOW_INTERVAL;
80 }
81 }
82
83 /*
84 * Check for keepalive timeout. After the other timer 'cos if
85 * the previous timer caused a retransmit, we don't need to
86 * do this. scp->stamp is the last time that we sent a packet.
87 * The keepalive function sends a link service packet to the
88 * other end. If it remains unacknowledged, the standard
89 * socket timers will eventually shut the socket down. Each
90 * time we do this, scp->stamp will be updated, thus
91 * we won't try and send another until scp->keepalive has passed
92 * since the last successful transmission.
93 */
94 if (scp->keepalive && scp->keepalive_fxn && (scp->state == DN_RUN)) {
Himangi Saraogi8b1b1eb2014-08-20 23:20:09 +053095 if (time_after_eq(jiffies, scp->stamp + scp->keepalive))
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 scp->keepalive_fxn(sk);
97 }
98
Eric Dumazet8a6e77d2011-11-21 00:21:55 +000099 sk_reset_timer(sk, &sk->sk_timer, jiffies + SLOW_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100out:
101 bh_unlock_sock(sk);
102 sock_put(sk);
103}