2 * X.25 Packet Layer release 002
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
6 * screw up. It might even work.
8 * This code REQUIRES 2.1.15 or higher
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 * X.25 001 Jonathan Naylor Started coding.
18 * X.25 002 Jonathan Naylor New timer architecture.
19 * Centralised disconnection processing.
22 #include <linux/errno.h>
23 #include <linux/jiffies.h>
24 #include <linux/timer.h>
26 #include <net/tcp_states.h>
29 static void x25_heartbeat_expiry(struct timer_list
*t
);
30 static void x25_timer_expiry(struct timer_list
*t
);
32 void x25_init_timers(struct sock
*sk
)
34 struct x25_sock
*x25
= x25_sk(sk
);
36 timer_setup(&x25
->timer
, x25_timer_expiry
, 0);
38 /* initialized by sock_init_data */
39 sk
->sk_timer
.function
= x25_heartbeat_expiry
;
42 void x25_start_heartbeat(struct sock
*sk
)
44 mod_timer(&sk
->sk_timer
, jiffies
+ 5 * HZ
);
47 void x25_stop_heartbeat(struct sock
*sk
)
49 del_timer(&sk
->sk_timer
);
52 void x25_start_t2timer(struct sock
*sk
)
54 struct x25_sock
*x25
= x25_sk(sk
);
56 mod_timer(&x25
->timer
, jiffies
+ x25
->t2
);
59 void x25_start_t21timer(struct sock
*sk
)
61 struct x25_sock
*x25
= x25_sk(sk
);
63 mod_timer(&x25
->timer
, jiffies
+ x25
->t21
);
66 void x25_start_t22timer(struct sock
*sk
)
68 struct x25_sock
*x25
= x25_sk(sk
);
70 mod_timer(&x25
->timer
, jiffies
+ x25
->t22
);
73 void x25_start_t23timer(struct sock
*sk
)
75 struct x25_sock
*x25
= x25_sk(sk
);
77 mod_timer(&x25
->timer
, jiffies
+ x25
->t23
);
80 void x25_stop_timer(struct sock
*sk
)
82 del_timer(&x25_sk(sk
)->timer
);
85 unsigned long x25_display_timer(struct sock
*sk
)
87 struct x25_sock
*x25
= x25_sk(sk
);
89 if (!timer_pending(&x25
->timer
))
92 return x25
->timer
.expires
- jiffies
;
95 static void x25_heartbeat_expiry(struct timer_list
*t
)
97 struct sock
*sk
= from_timer(sk
, t
, sk_timer
);
100 if (sock_owned_by_user(sk
)) /* can currently only occur in state 3 */
101 goto restart_heartbeat
;
103 switch (x25_sk(sk
)->state
) {
107 * Magic here: If we listen() and a new link dies
108 * before it is accepted() it isn't 'dead' so doesn't
111 if (sock_flag(sk
, SOCK_DESTROY
) ||
112 (sk
->sk_state
== TCP_LISTEN
&&
113 sock_flag(sk
, SOCK_DEAD
))) {
115 x25_destroy_socket_from_timer(sk
);
122 * Check for the state of the receive buffer.
128 x25_start_heartbeat(sk
);
133 * Timer has expired, it may have been T2, T21, T22, or T23. We can tell
134 * by the state machine state.
136 static inline void x25_do_timer_expiry(struct sock
* sk
)
138 struct x25_sock
*x25
= x25_sk(sk
);
140 switch (x25
->state
) {
142 case X25_STATE_3
: /* T2 */
143 if (x25
->condition
& X25_COND_ACK_PENDING
) {
144 x25
->condition
&= ~X25_COND_ACK_PENDING
;
145 x25_enquiry_response(sk
);
149 case X25_STATE_1
: /* T21 */
150 case X25_STATE_4
: /* T22 */
151 x25_write_internal(sk
, X25_CLEAR_REQUEST
);
152 x25
->state
= X25_STATE_2
;
153 x25_start_t23timer(sk
);
156 case X25_STATE_2
: /* T23 */
157 x25_disconnect(sk
, ETIMEDOUT
, 0, 0);
162 static void x25_timer_expiry(struct timer_list
*t
)
164 struct x25_sock
*x25
= from_timer(x25
, t
, timer
);
165 struct sock
*sk
= &x25
->sk
;
168 if (sock_owned_by_user(sk
)) { /* can currently only occur in state 3 */
169 if (x25_sk(sk
)->state
== X25_STATE_3
)
170 x25_start_t2timer(sk
);
172 x25_do_timer_expiry(sk
);