1 /* net/atm/signaling.c - ATM signaling */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
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>
17 #include "resources.h"
18 #include "signaling.h"
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
27 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
29 #define DPRINTK(format,args...)
33 struct atm_vcc
*sigd
= NULL
;
35 static DECLARE_WAIT_QUEUE_HEAD(sigd_sleep
);
39 static void sigd_put_skb(struct sk_buff
*skb
)
42 DECLARE_WAITQUEUE(wait
,current
);
44 add_wait_queue(&sigd_sleep
,&wait
);
46 set_current_state(TASK_UNINTERRUPTIBLE
);
47 DPRINTK("atmsvc: waiting for signaling demon...\n");
50 current
->state
= TASK_RUNNING
;
51 remove_wait_queue(&sigd_sleep
,&wait
);
54 DPRINTK("atmsvc: no signaling demon\n");
59 atm_force_charge(sigd
,skb
->truesize
);
60 skb_queue_tail(&sk_atm(sigd
)->sk_receive_queue
,skb
);
61 sk_atm(sigd
)->sk_data_ready(sk_atm(sigd
), skb
->len
);
65 static void modify_qos(struct atm_vcc
*vcc
,struct atmsvc_msg
*msg
)
69 if (test_bit(ATM_VF_RELEASED
,&vcc
->flags
) ||
70 !test_bit(ATM_VF_READY
,&vcc
->flags
))
73 if (!vcc
->dev
->ops
->change_qos
) msg
->reply
= -EOPNOTSUPP
;
76 msg
->reply
= vcc
->dev
->ops
->change_qos(vcc
,&msg
->qos
,
78 if (!msg
->reply
) msg
->type
= as_okay
;
81 * Should probably just turn around the old skb. But the, the buffer
82 * space accounting needs to follow the change too. Maybe later.
84 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
86 *(struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
)) = *msg
;
91 static int sigd_send(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
93 struct atmsvc_msg
*msg
;
94 struct atm_vcc
*session_vcc
;
97 msg
= (struct atmsvc_msg
*) skb
->data
;
98 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
99 DPRINTK("sigd_send %d (0x%lx)\n",(int) msg
->type
,
100 (unsigned long) msg
->vcc
);
101 vcc
= *(struct atm_vcc
**) &msg
->vcc
;
106 sk
->sk_err
= -msg
->reply
;
107 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
108 if (!*vcc
->local
.sas_addr
.prv
&&
109 !*vcc
->local
.sas_addr
.pub
) {
110 vcc
->local
.sas_family
= AF_ATMSVC
;
111 memcpy(vcc
->local
.sas_addr
.prv
,
112 msg
->local
.sas_addr
.prv
,ATM_ESA_LEN
);
113 memcpy(vcc
->local
.sas_addr
.pub
,
114 msg
->local
.sas_addr
.pub
,ATM_E164_LEN
+1);
116 session_vcc
= vcc
->session
? vcc
->session
: vcc
;
117 if (session_vcc
->vpi
|| session_vcc
->vci
) break;
118 session_vcc
->itf
= msg
->pvc
.sap_addr
.itf
;
119 session_vcc
->vpi
= msg
->pvc
.sap_addr
.vpi
;
120 session_vcc
->vci
= msg
->pvc
.sap_addr
.vci
;
121 if (session_vcc
->vpi
|| session_vcc
->vci
)
122 session_vcc
->qos
= msg
->qos
;
125 clear_bit(ATM_VF_REGIS
,&vcc
->flags
);
126 clear_bit(ATM_VF_READY
,&vcc
->flags
);
127 sk
->sk_err
= -msg
->reply
;
128 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
131 vcc
= *(struct atm_vcc
**) &msg
->listen_vcc
;
133 DPRINTK("as_indicate!!!\n");
135 if (sk_acceptq_is_full(sk
)) {
136 sigd_enq(NULL
,as_reject
,vcc
,NULL
,NULL
);
138 goto as_indicate_complete
;
140 sk
->sk_ack_backlog
++;
141 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
142 DPRINTK("waking sk->sk_sleep 0x%p\n", sk
->sk_sleep
);
143 sk
->sk_state_change(sk
);
144 as_indicate_complete
:
148 set_bit(ATM_VF_RELEASED
,&vcc
->flags
);
149 vcc_release_async(vcc
, msg
->reply
);
156 sk
->sk_err_soft
= msg
->reply
; /* < 0 failure, otherwise ep_ref */
157 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
160 printk(KERN_ALERT
"sigd_send: bad message type %d\n",
164 sk
->sk_state_change(sk
);
171 void sigd_enq2(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
172 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
173 const struct sockaddr_atmsvc
*svc
,const struct atm_qos
*qos
,int reply
)
176 struct atmsvc_msg
*msg
;
177 static unsigned session
= 0;
179 DPRINTK("sigd_enq %d (0x%p)\n",(int) type
,vcc
);
180 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
182 msg
= (struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
));
183 memset(msg
,0,sizeof(*msg
));
185 *(struct atm_vcc
**) &msg
->vcc
= vcc
;
186 *(struct atm_vcc
**) &msg
->listen_vcc
= listen_vcc
;
188 if (qos
) msg
->qos
= *qos
;
189 if (vcc
) msg
->sap
= vcc
->sap
;
190 if (svc
) msg
->svc
= *svc
;
191 if (vcc
) msg
->local
= vcc
->local
;
192 if (pvc
) msg
->pvc
= *pvc
;
194 if (type
== as_connect
&& test_bit(ATM_VF_SESSION
, &vcc
->flags
))
195 msg
->session
= ++session
;
196 /* every new pmp connect gets the next session number */
199 if (vcc
) set_bit(ATM_VF_REGIS
,&vcc
->flags
);
203 void sigd_enq(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
204 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
205 const struct sockaddr_atmsvc
*svc
)
207 sigd_enq2(vcc
,type
,listen_vcc
,pvc
,svc
,vcc
? &vcc
->qos
: NULL
,0);
208 /* other ISP applications may use "reply" */
212 static void purge_vcc(struct atm_vcc
*vcc
)
214 if (sk_atm(vcc
)->sk_family
== PF_ATMSVC
&&
215 !test_bit(ATM_VF_META
, &vcc
->flags
)) {
216 set_bit(ATM_VF_RELEASED
, &vcc
->flags
);
217 clear_bit(ATM_VF_REGIS
, &vcc
->flags
);
218 vcc_release_async(vcc
, -EUNATCH
);
223 static void sigd_close(struct atm_vcc
*vcc
)
225 struct hlist_node
*node
;
229 DPRINTK("sigd_close\n");
231 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
232 printk(KERN_ERR
"sigd_close: closing with requests pending\n");
233 skb_queue_purge(&sk_atm(vcc
)->sk_receive_queue
);
235 read_lock(&vcc_sklist_lock
);
236 for(i
= 0; i
< VCC_HTABLE_SIZE
; ++i
) {
237 struct hlist_head
*head
= &vcc_hash
[i
];
239 sk_for_each(s
, node
, head
) {
240 struct atm_vcc
*vcc
= atm_sk(s
);
245 read_unlock(&vcc_sklist_lock
);
249 static struct atmdev_ops sigd_dev_ops
= {
255 static struct atm_dev sigd_dev
= {
256 .ops
= &sigd_dev_ops
,
259 .lock
= SPIN_LOCK_UNLOCKED
263 int sigd_attach(struct atm_vcc
*vcc
)
265 if (sigd
) return -EADDRINUSE
;
266 DPRINTK("sigd_attach\n");
268 vcc
->dev
= &sigd_dev
;
269 vcc_insert_socket(sk_atm(vcc
));
270 set_bit(ATM_VF_META
,&vcc
->flags
);
271 set_bit(ATM_VF_READY
,&vcc
->flags
);
272 #ifdef WAIT_FOR_DEMON
273 wake_up(&sigd_sleep
);