dn_timer.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  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>
  25. #include <asm/atomic.h>
  26. #include <net/flow.h>
  27. #include <net/dn.h>
  28. /*
  29. * Slow timer is for everything else (n * 500mS)
  30. */
  31. #define SLOW_INTERVAL (HZ/2)
  32. static void dn_slow_timer(unsigned long arg);
  33. void dn_start_slow_timer(struct sock *sk)
  34. {
  35. sk->sk_timer.expires = jiffies + SLOW_INTERVAL;
  36. sk->sk_timer.function = dn_slow_timer;
  37. sk->sk_timer.data = (unsigned long)sk;
  38. add_timer(&sk->sk_timer);
  39. }
  40. void dn_stop_slow_timer(struct sock *sk)
  41. {
  42. del_timer(&sk->sk_timer);
  43. }
  44. static void dn_slow_timer(unsigned long arg)
  45. {
  46. struct sock *sk = (struct sock *)arg;
  47. struct dn_scp *scp = DN_SK(sk);
  48. sock_hold(sk);
  49. bh_lock_sock(sk);
  50. if (sock_owned_by_user(sk)) {
  51. sk->sk_timer.expires = jiffies + HZ / 10;
  52. add_timer(&sk->sk_timer);
  53. goto out;
  54. }
  55. /*
  56. * The persist timer is the standard slow timer used for retransmits
  57. * in both connection establishment and disconnection as well as
  58. * in the RUN state. The different states are catered for by changing
  59. * the function pointer in the socket. Setting the timer to a value
  60. * of zero turns it off. We allow the persist_fxn to turn the
  61. * timer off in a permant way by returning non-zero, so that
  62. * timer based routines may remove sockets. This is why we have a
  63. * sock_hold()/sock_put() around the timer to prevent the socket
  64. * going away in the middle.
  65. */
  66. if (scp->persist && scp->persist_fxn) {
  67. if (scp->persist <= SLOW_INTERVAL) {
  68. scp->persist = 0;
  69. if (scp->persist_fxn(sk))
  70. goto out;
  71. } else {
  72. scp->persist -= SLOW_INTERVAL;
  73. }
  74. }
  75. /*
  76. * Check for keepalive timeout. After the other timer 'cos if
  77. * the previous timer caused a retransmit, we don't need to
  78. * do this. scp->stamp is the last time that we sent a packet.
  79. * The keepalive function sends a link service packet to the
  80. * other end. If it remains unacknowledged, the standard
  81. * socket timers will eventually shut the socket down. Each
  82. * time we do this, scp->stamp will be updated, thus
  83. * we won't try and send another until scp->keepalive has passed
  84. * since the last successful transmission.
  85. */
  86. if (scp->keepalive && scp->keepalive_fxn && (scp->state == DN_RUN)) {
  87. if ((jiffies - scp->stamp) >= scp->keepalive)
  88. scp->keepalive_fxn(sk);
  89. }
  90. sk->sk_timer.expires = jiffies + SLOW_INTERVAL;
  91. add_timer(&sk->sk_timer);
  92. out:
  93. bh_unlock_sock(sk);
  94. sock_put(sk);
  95. }