~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/rose/rose_timer.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.10 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.83 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.153 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.200 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.200 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.76 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * This program is free software; you can redistribute it and/or modify
  3  * it under the terms of the GNU General Public License as published by
  4  * the Free Software Foundation; either version 2 of the License, or
  5  * (at your option) any later version.
  6  *
  7  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  8  * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
  9  */
 10 #include <linux/errno.h>
 11 #include <linux/types.h>
 12 #include <linux/socket.h>
 13 #include <linux/in.h>
 14 #include <linux/kernel.h>
 15 #include <linux/jiffies.h>
 16 #include <linux/timer.h>
 17 #include <linux/string.h>
 18 #include <linux/sockios.h>
 19 #include <linux/net.h>
 20 #include <net/ax25.h>
 21 #include <linux/inet.h>
 22 #include <linux/netdevice.h>
 23 #include <linux/skbuff.h>
 24 #include <net/sock.h>
 25 #include <net/tcp_states.h>
 26 #include <linux/fcntl.h>
 27 #include <linux/mm.h>
 28 #include <linux/interrupt.h>
 29 #include <net/rose.h>
 30 
 31 static void rose_heartbeat_expiry(unsigned long);
 32 static void rose_timer_expiry(unsigned long);
 33 static void rose_idletimer_expiry(unsigned long);
 34 
 35 void rose_start_heartbeat(struct sock *sk)
 36 {
 37         del_timer(&sk->sk_timer);
 38 
 39         sk->sk_timer.data     = (unsigned long)sk;
 40         sk->sk_timer.function = &rose_heartbeat_expiry;
 41         sk->sk_timer.expires  = jiffies + 5 * HZ;
 42 
 43         add_timer(&sk->sk_timer);
 44 }
 45 
 46 void rose_start_t1timer(struct sock *sk)
 47 {
 48         struct rose_sock *rose = rose_sk(sk);
 49 
 50         del_timer(&rose->timer);
 51 
 52         rose->timer.data     = (unsigned long)sk;
 53         rose->timer.function = &rose_timer_expiry;
 54         rose->timer.expires  = jiffies + rose->t1;
 55 
 56         add_timer(&rose->timer);
 57 }
 58 
 59 void rose_start_t2timer(struct sock *sk)
 60 {
 61         struct rose_sock *rose = rose_sk(sk);
 62 
 63         del_timer(&rose->timer);
 64 
 65         rose->timer.data     = (unsigned long)sk;
 66         rose->timer.function = &rose_timer_expiry;
 67         rose->timer.expires  = jiffies + rose->t2;
 68 
 69         add_timer(&rose->timer);
 70 }
 71 
 72 void rose_start_t3timer(struct sock *sk)
 73 {
 74         struct rose_sock *rose = rose_sk(sk);
 75 
 76         del_timer(&rose->timer);
 77 
 78         rose->timer.data     = (unsigned long)sk;
 79         rose->timer.function = &rose_timer_expiry;
 80         rose->timer.expires  = jiffies + rose->t3;
 81 
 82         add_timer(&rose->timer);
 83 }
 84 
 85 void rose_start_hbtimer(struct sock *sk)
 86 {
 87         struct rose_sock *rose = rose_sk(sk);
 88 
 89         del_timer(&rose->timer);
 90 
 91         rose->timer.data     = (unsigned long)sk;
 92         rose->timer.function = &rose_timer_expiry;
 93         rose->timer.expires  = jiffies + rose->hb;
 94 
 95         add_timer(&rose->timer);
 96 }
 97 
 98 void rose_start_idletimer(struct sock *sk)
 99 {
100         struct rose_sock *rose = rose_sk(sk);
101 
102         del_timer(&rose->idletimer);
103 
104         if (rose->idle > 0) {
105                 rose->idletimer.data     = (unsigned long)sk;
106                 rose->idletimer.function = &rose_idletimer_expiry;
107                 rose->idletimer.expires  = jiffies + rose->idle;
108 
109                 add_timer(&rose->idletimer);
110         }
111 }
112 
113 void rose_stop_heartbeat(struct sock *sk)
114 {
115         del_timer(&sk->sk_timer);
116 }
117 
118 void rose_stop_timer(struct sock *sk)
119 {
120         del_timer(&rose_sk(sk)->timer);
121 }
122 
123 void rose_stop_idletimer(struct sock *sk)
124 {
125         del_timer(&rose_sk(sk)->idletimer);
126 }
127 
128 static void rose_heartbeat_expiry(unsigned long param)
129 {
130         struct sock *sk = (struct sock *)param;
131         struct rose_sock *rose = rose_sk(sk);
132 
133         bh_lock_sock(sk);
134         switch (rose->state) {
135         case ROSE_STATE_0:
136                 /* Magic here: If we listen() and a new link dies before it
137                    is accepted() it isn't 'dead' so doesn't get removed. */
138                 if (sock_flag(sk, SOCK_DESTROY) ||
139                     (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) {
140                         bh_unlock_sock(sk);
141                         rose_destroy_socket(sk);
142                         return;
143                 }
144                 break;
145 
146         case ROSE_STATE_3:
147                 /*
148                  * Check for the state of the receive buffer.
149                  */
150                 if (atomic_read(&sk->sk_rmem_alloc) < (sk->sk_rcvbuf / 2) &&
151                     (rose->condition & ROSE_COND_OWN_RX_BUSY)) {
152                         rose->condition &= ~ROSE_COND_OWN_RX_BUSY;
153                         rose->condition &= ~ROSE_COND_ACK_PENDING;
154                         rose->vl         = rose->vr;
155                         rose_write_internal(sk, ROSE_RR);
156                         rose_stop_timer(sk);    /* HB */
157                         break;
158                 }
159                 break;
160         }
161 
162         rose_start_heartbeat(sk);
163         bh_unlock_sock(sk);
164 }
165 
166 static void rose_timer_expiry(unsigned long param)
167 {
168         struct sock *sk = (struct sock *)param;
169         struct rose_sock *rose = rose_sk(sk);
170 
171         bh_lock_sock(sk);
172         switch (rose->state) {
173         case ROSE_STATE_1:      /* T1 */
174         case ROSE_STATE_4:      /* T2 */
175                 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
176                 rose->state = ROSE_STATE_2;
177                 rose_start_t3timer(sk);
178                 break;
179 
180         case ROSE_STATE_2:      /* T3 */
181                 rose->neighbour->use--;
182                 rose_disconnect(sk, ETIMEDOUT, -1, -1);
183                 break;
184 
185         case ROSE_STATE_3:      /* HB */
186                 if (rose->condition & ROSE_COND_ACK_PENDING) {
187                         rose->condition &= ~ROSE_COND_ACK_PENDING;
188                         rose_enquiry_response(sk);
189                 }
190                 break;
191         }
192         bh_unlock_sock(sk);
193 }
194 
195 static void rose_idletimer_expiry(unsigned long param)
196 {
197         struct sock *sk = (struct sock *)param;
198 
199         bh_lock_sock(sk);
200         rose_clear_queues(sk);
201 
202         rose_write_internal(sk, ROSE_CLEAR_REQUEST);
203         rose_sk(sk)->state = ROSE_STATE_2;
204 
205         rose_start_t3timer(sk);
206 
207         sk->sk_state     = TCP_CLOSE;
208         sk->sk_err       = 0;
209         sk->sk_shutdown |= SEND_SHUTDOWN;
210 
211         if (!sock_flag(sk, SOCK_DEAD)) {
212                 sk->sk_state_change(sk);
213                 sock_set_flag(sk, SOCK_DEAD);
214         }
215         bh_unlock_sock(sk);
216 }
217 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp