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 static unsigned long silence
;
43 DECLARE_WAITQUEUE(wait
,current
);
45 add_wait_queue(&sigd_sleep
,&wait
);
47 set_current_state(TASK_UNINTERRUPTIBLE
);
48 if (time_after(jiffies
, silence
) || silence
== 0) {
49 printk(KERN_INFO
"atmsvc: waiting for signaling demon "
51 silence
= (jiffies
+30*HZ
)|1;
55 current
->state
= TASK_RUNNING
;
56 remove_wait_queue(&sigd_sleep
,&wait
);
59 printk(KERN_WARNING
"atmsvc: no signaling demon\n");
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
);
70 static void modify_qos(struct atm_vcc
*vcc
,struct atmsvc_msg
*msg
)
74 if (test_bit(ATM_VF_RELEASED
,&vcc
->flags
) ||
75 !test_bit(ATM_VF_READY
,&vcc
->flags
))
78 if (!vcc
->dev
->ops
->change_qos
) msg
->reply
= -EOPNOTSUPP
;
81 msg
->reply
= vcc
->dev
->ops
->change_qos(vcc
,&msg
->qos
,
83 if (!msg
->reply
) msg
->type
= as_okay
;
86 * Should probably just turn around the old skb. But the, the buffer
87 * space accounting needs to follow the change too. Maybe later.
89 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
91 *(struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
)) = *msg
;
96 static int sigd_send(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
98 struct atmsvc_msg
*msg
;
99 struct atm_vcc
*session_vcc
;
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
;
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);
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
;
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
);
136 vcc
= *(struct atm_vcc
**) &msg
->listen_vcc
;
138 DPRINTK("as_indicate!!!\n");
140 if (sk_acceptq_is_full(sk
)) {
141 sigd_enq(NULL
,as_reject
,vcc
,NULL
,NULL
);
143 goto as_indicate_complete
;
145 sk
->sk_ack_backlog
++;
146 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
147 DPRINTK("waking sk->sk_sleep 0x%p\n", sk
->sk_sleep
);
148 sk
->sk_state_change(sk
);
149 as_indicate_complete
:
153 set_bit(ATM_VF_RELEASED
,&vcc
->flags
);
154 vcc_release_async(vcc
, msg
->reply
);
161 sk
->sk_err_soft
= msg
->reply
; /* < 0 failure, otherwise ep_ref */
162 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
165 printk(KERN_ALERT
"sigd_send: bad message type %d\n",
169 sk
->sk_state_change(sk
);
176 void sigd_enq2(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
177 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
178 const struct sockaddr_atmsvc
*svc
,const struct atm_qos
*qos
,int reply
)
181 struct atmsvc_msg
*msg
;
182 static unsigned session
= 0;
184 DPRINTK("sigd_enq %d (0x%p)\n",(int) type
,vcc
);
185 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
187 msg
= (struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
));
188 memset(msg
,0,sizeof(*msg
));
190 *(struct atm_vcc
**) &msg
->vcc
= vcc
;
191 *(struct atm_vcc
**) &msg
->listen_vcc
= listen_vcc
;
193 if (qos
) msg
->qos
= *qos
;
194 if (vcc
) msg
->sap
= vcc
->sap
;
195 if (svc
) msg
->svc
= *svc
;
196 if (vcc
) msg
->local
= vcc
->local
;
197 if (pvc
) msg
->pvc
= *pvc
;
199 if (type
== as_connect
&& test_bit(ATM_VF_SESSION
, &vcc
->flags
))
200 msg
->session
= ++session
;
201 /* every new pmp connect gets the next session number */
204 if (vcc
) set_bit(ATM_VF_REGIS
,&vcc
->flags
);
208 void sigd_enq(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
209 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
210 const struct sockaddr_atmsvc
*svc
)
212 sigd_enq2(vcc
,type
,listen_vcc
,pvc
,svc
,vcc
? &vcc
->qos
: NULL
,0);
213 /* other ISP applications may use "reply" */
217 static void purge_vcc(struct atm_vcc
*vcc
)
219 if (sk_atm(vcc
)->sk_family
== PF_ATMSVC
&&
220 !test_bit(ATM_VF_META
, &vcc
->flags
)) {
221 set_bit(ATM_VF_RELEASED
, &vcc
->flags
);
222 clear_bit(ATM_VF_REGIS
, &vcc
->flags
);
223 vcc_release_async(vcc
, -EUNATCH
);
228 static void sigd_close(struct atm_vcc
*vcc
)
230 struct hlist_node
*node
;
234 DPRINTK("sigd_close\n");
236 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
237 printk(KERN_ERR
"sigd_close: closing with requests pending\n");
238 skb_queue_purge(&sk_atm(vcc
)->sk_receive_queue
);
240 read_lock(&vcc_sklist_lock
);
241 for(i
= 0; i
< VCC_HTABLE_SIZE
; ++i
) {
242 struct hlist_head
*head
= &vcc_hash
[i
];
244 sk_for_each(s
, node
, head
) {
245 struct atm_vcc
*vcc
= atm_sk(s
);
250 read_unlock(&vcc_sklist_lock
);
254 static struct atmdev_ops sigd_dev_ops
= {
260 static struct atm_dev sigd_dev
= {
261 .ops
= &sigd_dev_ops
,
264 .lock
= SPIN_LOCK_UNLOCKED
268 int sigd_attach(struct atm_vcc
*vcc
)
270 if (sigd
) return -EADDRINUSE
;
271 DPRINTK("sigd_attach\n");
273 vcc
->dev
= &sigd_dev
;
274 vcc_insert_socket(sk_atm(vcc
));
275 set_bit(ATM_VF_META
,&vcc
->flags
);
276 set_bit(ATM_VF_READY
,&vcc
->flags
);
277 #ifdef WAIT_FOR_DEMON
278 wake_up(&sigd_sleep
);