0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/errno.h>
0018 #include <linux/jiffies.h>
0019 #include <linux/timer.h>
0020 #include <net/sock.h>
0021 #include <net/tcp_states.h>
0022 #include <net/x25.h>
0023
0024 static void x25_heartbeat_expiry(struct timer_list *t);
0025 static void x25_timer_expiry(struct timer_list *t);
0026
0027 void x25_init_timers(struct sock *sk)
0028 {
0029 struct x25_sock *x25 = x25_sk(sk);
0030
0031 timer_setup(&x25->timer, x25_timer_expiry, 0);
0032
0033
0034 sk->sk_timer.function = x25_heartbeat_expiry;
0035 }
0036
0037 void x25_start_heartbeat(struct sock *sk)
0038 {
0039 mod_timer(&sk->sk_timer, jiffies + 5 * HZ);
0040 }
0041
0042 void x25_stop_heartbeat(struct sock *sk)
0043 {
0044 del_timer(&sk->sk_timer);
0045 }
0046
0047 void x25_start_t2timer(struct sock *sk)
0048 {
0049 struct x25_sock *x25 = x25_sk(sk);
0050
0051 mod_timer(&x25->timer, jiffies + x25->t2);
0052 }
0053
0054 void x25_start_t21timer(struct sock *sk)
0055 {
0056 struct x25_sock *x25 = x25_sk(sk);
0057
0058 mod_timer(&x25->timer, jiffies + x25->t21);
0059 }
0060
0061 void x25_start_t22timer(struct sock *sk)
0062 {
0063 struct x25_sock *x25 = x25_sk(sk);
0064
0065 mod_timer(&x25->timer, jiffies + x25->t22);
0066 }
0067
0068 void x25_start_t23timer(struct sock *sk)
0069 {
0070 struct x25_sock *x25 = x25_sk(sk);
0071
0072 mod_timer(&x25->timer, jiffies + x25->t23);
0073 }
0074
0075 void x25_stop_timer(struct sock *sk)
0076 {
0077 del_timer(&x25_sk(sk)->timer);
0078 }
0079
0080 unsigned long x25_display_timer(struct sock *sk)
0081 {
0082 struct x25_sock *x25 = x25_sk(sk);
0083
0084 if (!timer_pending(&x25->timer))
0085 return 0;
0086
0087 return x25->timer.expires - jiffies;
0088 }
0089
0090 static void x25_heartbeat_expiry(struct timer_list *t)
0091 {
0092 struct sock *sk = from_timer(sk, t, sk_timer);
0093
0094 bh_lock_sock(sk);
0095 if (sock_owned_by_user(sk))
0096 goto restart_heartbeat;
0097
0098 switch (x25_sk(sk)->state) {
0099
0100 case X25_STATE_0:
0101
0102
0103
0104
0105
0106 if (sock_flag(sk, SOCK_DESTROY) ||
0107 (sk->sk_state == TCP_LISTEN &&
0108 sock_flag(sk, SOCK_DEAD))) {
0109 bh_unlock_sock(sk);
0110 x25_destroy_socket_from_timer(sk);
0111 return;
0112 }
0113 break;
0114
0115 case X25_STATE_3:
0116
0117
0118
0119 x25_check_rbuf(sk);
0120 break;
0121 }
0122 restart_heartbeat:
0123 x25_start_heartbeat(sk);
0124 bh_unlock_sock(sk);
0125 }
0126
0127
0128
0129
0130
0131 static inline void x25_do_timer_expiry(struct sock * sk)
0132 {
0133 struct x25_sock *x25 = x25_sk(sk);
0134
0135 switch (x25->state) {
0136
0137 case X25_STATE_3:
0138 if (x25->condition & X25_COND_ACK_PENDING) {
0139 x25->condition &= ~X25_COND_ACK_PENDING;
0140 x25_enquiry_response(sk);
0141 }
0142 break;
0143
0144 case X25_STATE_1:
0145 case X25_STATE_4:
0146 x25_write_internal(sk, X25_CLEAR_REQUEST);
0147 x25->state = X25_STATE_2;
0148 x25_start_t23timer(sk);
0149 break;
0150
0151 case X25_STATE_2:
0152 x25_disconnect(sk, ETIMEDOUT, 0, 0);
0153 break;
0154 }
0155 }
0156
0157 static void x25_timer_expiry(struct timer_list *t)
0158 {
0159 struct x25_sock *x25 = from_timer(x25, t, timer);
0160 struct sock *sk = &x25->sk;
0161
0162 bh_lock_sock(sk);
0163 if (sock_owned_by_user(sk)) {
0164 if (x25_sk(sk)->state == X25_STATE_3)
0165 x25_start_t2timer(sk);
0166 } else
0167 x25_do_timer_expiry(sk);
0168 bh_unlock_sock(sk);
0169 }