aboutsummaryrefslogtreecommitdiffstats
path: root/net/atm/signaling.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/atm/signaling.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/atm/signaling.c')
-rw-r--r--net/atm/signaling.c280
1 files changed, 280 insertions, 0 deletions
diff --git a/net/atm/signaling.c b/net/atm/signaling.c
new file mode 100644
index 000000000000..6ff803154c04
--- /dev/null
+++ b/net/atm/signaling.c
@@ -0,0 +1,280 @@
1/* net/atm/signaling.c - ATM signaling */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
5
6#include <linux/errno.h> /* error codes */
7#include <linux/kernel.h> /* printk */
8#include <linux/skbuff.h>
9#include <linux/wait.h>
10#include <linux/sched.h> /* jiffies and HZ */
11#include <linux/atm.h> /* ATM stuff */
12#include <linux/atmsap.h>
13#include <linux/atmsvc.h>
14#include <linux/atmdev.h>
15#include <linux/bitops.h>
16
17#include "resources.h"
18#include "signaling.h"
19
20
21#undef WAIT_FOR_DEMON /* #define this if system calls on SVC sockets
22 should block until the demon runs.
23 Danger: may cause nasty hangs if the demon
24 crashes. */
25
26#if 0
27#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
28#else
29#define DPRINTK(format,args...)
30#endif
31
32
33struct atm_vcc *sigd = NULL;
34#ifdef WAIT_FOR_DEMON
35static DECLARE_WAIT_QUEUE_HEAD(sigd_sleep);
36#endif
37
38
39static void sigd_put_skb(struct sk_buff *skb)
40{
41#ifdef WAIT_FOR_DEMON
42 static unsigned long silence;
43 DECLARE_WAITQUEUE(wait,current);
44
45 add_wait_queue(&sigd_sleep,&wait);
46 while (!sigd) {
47 set_current_state(TASK_UNINTERRUPTIBLE);
48 if (time_after(jiffies, silence) || silence == 0) {
49 printk(KERN_INFO "atmsvc: waiting for signaling demon "
50 "...\n");
51 silence = (jiffies+30*HZ)|1;
52 }
53 schedule();
54 }
55 current->state = TASK_RUNNING;
56 remove_wait_queue(&sigd_sleep,&wait);
57#else
58 if (!sigd) {
59 printk(KERN_WARNING "atmsvc: no signaling demon\n");
60 kfree_skb(skb);
61 return;
62 }
63#endif
64 atm_force_charge(sigd,skb->truesize);
65 skb_queue_tail(&sk_atm(sigd)->sk_receive_queue,skb);
66 sk_atm(sigd)->sk_data_ready(sk_atm(sigd), skb->len);
67}
68
69
70static void modify_qos(struct atm_vcc *vcc,struct atmsvc_msg *msg)
71{
72 struct sk_buff *skb;
73
74 if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
75 !test_bit(ATM_VF_READY,&vcc->flags))
76 return;
77 msg->type = as_error;
78 if (!vcc->dev->ops->change_qos) msg->reply = -EOPNOTSUPP;
79 else {
80 /* should lock VCC */
81 msg->reply = vcc->dev->ops->change_qos(vcc,&msg->qos,
82 msg->reply);
83 if (!msg->reply) msg->type = as_okay;
84 }
85 /*
86 * Should probably just turn around the old skb. But the, the buffer
87 * space accounting needs to follow the change too. Maybe later.
88 */
89 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL)))
90 schedule();
91 *(struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg)) = *msg;
92 sigd_put_skb(skb);
93}
94
95
96static int sigd_send(struct atm_vcc *vcc,struct sk_buff *skb)
97{
98 struct atmsvc_msg *msg;
99 struct atm_vcc *session_vcc;
100 struct sock *sk;
101
102 msg = (struct atmsvc_msg *) skb->data;
103 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
104 DPRINTK("sigd_send %d (0x%lx)\n",(int) msg->type,
105 (unsigned long) msg->vcc);
106 vcc = *(struct atm_vcc **) &msg->vcc;
107 sk = sk_atm(vcc);
108
109 switch (msg->type) {
110 case as_okay:
111 sk->sk_err = -msg->reply;
112 clear_bit(ATM_VF_WAITING, &vcc->flags);
113 if (!*vcc->local.sas_addr.prv &&
114 !*vcc->local.sas_addr.pub) {
115 vcc->local.sas_family = AF_ATMSVC;
116 memcpy(vcc->local.sas_addr.prv,
117 msg->local.sas_addr.prv,ATM_ESA_LEN);
118 memcpy(vcc->local.sas_addr.pub,
119 msg->local.sas_addr.pub,ATM_E164_LEN+1);
120 }
121 session_vcc = vcc->session ? vcc->session : vcc;
122 if (session_vcc->vpi || session_vcc->vci) break;
123 session_vcc->itf = msg->pvc.sap_addr.itf;
124 session_vcc->vpi = msg->pvc.sap_addr.vpi;
125 session_vcc->vci = msg->pvc.sap_addr.vci;
126 if (session_vcc->vpi || session_vcc->vci)
127 session_vcc->qos = msg->qos;
128 break;
129 case as_error:
130 clear_bit(ATM_VF_REGIS,&vcc->flags);
131 clear_bit(ATM_VF_READY,&vcc->flags);
132 sk->sk_err = -msg->reply;
133 clear_bit(ATM_VF_WAITING, &vcc->flags);
134 break;
135 case as_indicate:
136 vcc = *(struct atm_vcc **) &msg->listen_vcc;
137 DPRINTK("as_indicate!!!\n");
138 lock_sock(sk);
139 if (sk_acceptq_is_full(sk)) {
140 sigd_enq(NULL,as_reject,vcc,NULL,NULL);
141 dev_kfree_skb(skb);
142 goto as_indicate_complete;
143 }
144 sk->sk_ack_backlog++;
145 skb_queue_tail(&sk->sk_receive_queue, skb);
146 DPRINTK("waking sk->sk_sleep 0x%p\n", sk->sk_sleep);
147 sk->sk_state_change(sk);
148as_indicate_complete:
149 release_sock(sk);
150 return 0;
151 case as_close:
152 set_bit(ATM_VF_RELEASED,&vcc->flags);
153 vcc_release_async(vcc, msg->reply);
154 goto out;
155 case as_modify:
156 modify_qos(vcc,msg);
157 break;
158 case as_addparty:
159 case as_dropparty:
160 sk->sk_err_soft = msg->reply; /* < 0 failure, otherwise ep_ref */
161 clear_bit(ATM_VF_WAITING, &vcc->flags);
162 break;
163 default:
164 printk(KERN_ALERT "sigd_send: bad message type %d\n",
165 (int) msg->type);
166 return -EINVAL;
167 }
168 sk->sk_state_change(sk);
169out:
170 dev_kfree_skb(skb);
171 return 0;
172}
173
174
175void sigd_enq2(struct atm_vcc *vcc,enum atmsvc_msg_type type,
176 struct atm_vcc *listen_vcc,const struct sockaddr_atmpvc *pvc,
177 const struct sockaddr_atmsvc *svc,const struct atm_qos *qos,int reply)
178{
179 struct sk_buff *skb;
180 struct atmsvc_msg *msg;
181 static unsigned session = 0;
182
183 DPRINTK("sigd_enq %d (0x%p)\n",(int) type,vcc);
184 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg),GFP_KERNEL)))
185 schedule();
186 msg = (struct atmsvc_msg *) skb_put(skb,sizeof(struct atmsvc_msg));
187 memset(msg,0,sizeof(*msg));
188 msg->type = type;
189 *(struct atm_vcc **) &msg->vcc = vcc;
190 *(struct atm_vcc **) &msg->listen_vcc = listen_vcc;
191 msg->reply = reply;
192 if (qos) msg->qos = *qos;
193 if (vcc) msg->sap = vcc->sap;
194 if (svc) msg->svc = *svc;
195 if (vcc) msg->local = vcc->local;
196 if (pvc) msg->pvc = *pvc;
197 if (vcc) {
198 if (type == as_connect && test_bit(ATM_VF_SESSION, &vcc->flags))
199 msg->session = ++session;
200 /* every new pmp connect gets the next session number */
201 }
202 sigd_put_skb(skb);
203 if (vcc) set_bit(ATM_VF_REGIS,&vcc->flags);
204}
205
206
207void sigd_enq(struct atm_vcc *vcc,enum atmsvc_msg_type type,
208 struct atm_vcc *listen_vcc,const struct sockaddr_atmpvc *pvc,
209 const struct sockaddr_atmsvc *svc)
210{
211 sigd_enq2(vcc,type,listen_vcc,pvc,svc,vcc ? &vcc->qos : NULL,0);
212 /* other ISP applications may use "reply" */
213}
214
215
216static void purge_vcc(struct atm_vcc *vcc)
217{
218 if (sk_atm(vcc)->sk_family == PF_ATMSVC &&
219 !test_bit(ATM_VF_META,&vcc->flags)) {
220 set_bit(ATM_VF_RELEASED,&vcc->flags);
221 vcc_release_async(vcc, -EUNATCH);
222 }
223}
224
225
226static void sigd_close(struct atm_vcc *vcc)
227{
228 struct hlist_node *node;
229 struct sock *s;
230 int i;
231
232 DPRINTK("sigd_close\n");
233 sigd = NULL;
234 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
235 printk(KERN_ERR "sigd_close: closing with requests pending\n");
236 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
237
238 read_lock(&vcc_sklist_lock);
239 for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
240 struct hlist_head *head = &vcc_hash[i];
241
242 sk_for_each(s, node, head) {
243 struct atm_vcc *vcc = atm_sk(s);
244
245 if (vcc->dev)
246 purge_vcc(vcc);
247 }
248 }
249 read_unlock(&vcc_sklist_lock);
250}
251
252
253static struct atmdev_ops sigd_dev_ops = {
254 .close = sigd_close,
255 .send = sigd_send
256};
257
258
259static struct atm_dev sigd_dev = {
260 .ops = &sigd_dev_ops,
261 .type = "sig",
262 .number = 999,
263 .lock = SPIN_LOCK_UNLOCKED
264};
265
266
267int sigd_attach(struct atm_vcc *vcc)
268{
269 if (sigd) return -EADDRINUSE;
270 DPRINTK("sigd_attach\n");
271 sigd = vcc;
272 vcc->dev = &sigd_dev;
273 vcc_insert_socket(sk_atm(vcc));
274 set_bit(ATM_VF_META,&vcc->flags);
275 set_bit(ATM_VF_READY,&vcc->flags);
276#ifdef WAIT_FOR_DEMON
277 wake_up(&sigd_sleep);
278#endif
279 return 0;
280}