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
26 struct atm_vcc
*sigd
= NULL
;
28 static DECLARE_WAIT_QUEUE_HEAD(sigd_sleep
);
32 static void sigd_put_skb(struct sk_buff
*skb
)
35 DECLARE_WAITQUEUE(wait
,current
);
37 add_wait_queue(&sigd_sleep
,&wait
);
39 set_current_state(TASK_UNINTERRUPTIBLE
);
40 pr_debug("atmsvc: waiting for signaling demon...\n");
43 current
->state
= TASK_RUNNING
;
44 remove_wait_queue(&sigd_sleep
,&wait
);
47 pr_debug("atmsvc: no signaling demon\n");
52 atm_force_charge(sigd
,skb
->truesize
);
53 skb_queue_tail(&sk_atm(sigd
)->sk_receive_queue
,skb
);
54 sk_atm(sigd
)->sk_data_ready(sk_atm(sigd
), skb
->len
);
58 static void modify_qos(struct atm_vcc
*vcc
,struct atmsvc_msg
*msg
)
62 if (test_bit(ATM_VF_RELEASED
,&vcc
->flags
) ||
63 !test_bit(ATM_VF_READY
,&vcc
->flags
))
66 if (!vcc
->dev
->ops
->change_qos
) msg
->reply
= -EOPNOTSUPP
;
69 msg
->reply
= vcc
->dev
->ops
->change_qos(vcc
,&msg
->qos
,
71 if (!msg
->reply
) msg
->type
= as_okay
;
74 * Should probably just turn around the old skb. But the, the buffer
75 * space accounting needs to follow the change too. Maybe later.
77 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
79 *(struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
)) = *msg
;
84 static int sigd_send(struct atm_vcc
*vcc
,struct sk_buff
*skb
)
86 struct atmsvc_msg
*msg
;
87 struct atm_vcc
*session_vcc
;
90 msg
= (struct atmsvc_msg
*) skb
->data
;
91 atomic_sub(skb
->truesize
, &sk_atm(vcc
)->sk_wmem_alloc
);
92 vcc
= *(struct atm_vcc
**) &msg
->vcc
;
93 pr_debug("sigd_send %d (0x%lx)\n",(int) msg
->type
,
99 sk
->sk_err
= -msg
->reply
;
100 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
101 if (!*vcc
->local
.sas_addr
.prv
&&
102 !*vcc
->local
.sas_addr
.pub
) {
103 vcc
->local
.sas_family
= AF_ATMSVC
;
104 memcpy(vcc
->local
.sas_addr
.prv
,
105 msg
->local
.sas_addr
.prv
,ATM_ESA_LEN
);
106 memcpy(vcc
->local
.sas_addr
.pub
,
107 msg
->local
.sas_addr
.pub
,ATM_E164_LEN
+1);
109 session_vcc
= vcc
->session
? vcc
->session
: vcc
;
110 if (session_vcc
->vpi
|| session_vcc
->vci
) break;
111 session_vcc
->itf
= msg
->pvc
.sap_addr
.itf
;
112 session_vcc
->vpi
= msg
->pvc
.sap_addr
.vpi
;
113 session_vcc
->vci
= msg
->pvc
.sap_addr
.vci
;
114 if (session_vcc
->vpi
|| session_vcc
->vci
)
115 session_vcc
->qos
= msg
->qos
;
118 clear_bit(ATM_VF_REGIS
,&vcc
->flags
);
119 clear_bit(ATM_VF_READY
,&vcc
->flags
);
120 sk
->sk_err
= -msg
->reply
;
121 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
124 vcc
= *(struct atm_vcc
**) &msg
->listen_vcc
;
126 pr_debug("as_indicate!!!\n");
128 if (sk_acceptq_is_full(sk
)) {
129 sigd_enq(NULL
,as_reject
,vcc
,NULL
,NULL
);
131 goto as_indicate_complete
;
133 sk
->sk_ack_backlog
++;
134 skb_queue_tail(&sk
->sk_receive_queue
, skb
);
135 pr_debug("waking sk->sk_sleep 0x%p\n", sk
->sk_sleep
);
136 sk
->sk_state_change(sk
);
137 as_indicate_complete
:
141 set_bit(ATM_VF_RELEASED
,&vcc
->flags
);
142 vcc_release_async(vcc
, msg
->reply
);
149 sk
->sk_err_soft
= msg
->reply
; /* < 0 failure, otherwise ep_ref */
150 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
153 printk(KERN_ALERT
"sigd_send: bad message type %d\n",
157 sk
->sk_state_change(sk
);
164 void sigd_enq2(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
165 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
166 const struct sockaddr_atmsvc
*svc
,const struct atm_qos
*qos
,int reply
)
169 struct atmsvc_msg
*msg
;
170 static unsigned session
= 0;
172 pr_debug("sigd_enq %d (0x%p)\n",(int) type
,vcc
);
173 while (!(skb
= alloc_skb(sizeof(struct atmsvc_msg
),GFP_KERNEL
)))
175 msg
= (struct atmsvc_msg
*) skb_put(skb
,sizeof(struct atmsvc_msg
));
176 memset(msg
,0,sizeof(*msg
));
178 *(struct atm_vcc
**) &msg
->vcc
= vcc
;
179 *(struct atm_vcc
**) &msg
->listen_vcc
= listen_vcc
;
181 if (qos
) msg
->qos
= *qos
;
182 if (vcc
) msg
->sap
= vcc
->sap
;
183 if (svc
) msg
->svc
= *svc
;
184 if (vcc
) msg
->local
= vcc
->local
;
185 if (pvc
) msg
->pvc
= *pvc
;
187 if (type
== as_connect
&& test_bit(ATM_VF_SESSION
, &vcc
->flags
))
188 msg
->session
= ++session
;
189 /* every new pmp connect gets the next session number */
192 if (vcc
) set_bit(ATM_VF_REGIS
,&vcc
->flags
);
196 void sigd_enq(struct atm_vcc
*vcc
,enum atmsvc_msg_type type
,
197 struct atm_vcc
*listen_vcc
,const struct sockaddr_atmpvc
*pvc
,
198 const struct sockaddr_atmsvc
*svc
)
200 sigd_enq2(vcc
,type
,listen_vcc
,pvc
,svc
,vcc
? &vcc
->qos
: NULL
,0);
201 /* other ISP applications may use "reply" */
205 static void purge_vcc(struct atm_vcc
*vcc
)
207 if (sk_atm(vcc
)->sk_family
== PF_ATMSVC
&&
208 !test_bit(ATM_VF_META
, &vcc
->flags
)) {
209 set_bit(ATM_VF_RELEASED
, &vcc
->flags
);
210 clear_bit(ATM_VF_REGIS
, &vcc
->flags
);
211 vcc_release_async(vcc
, -EUNATCH
);
216 static void sigd_close(struct atm_vcc
*vcc
)
218 struct hlist_node
*node
;
222 pr_debug("sigd_close\n");
224 if (skb_peek(&sk_atm(vcc
)->sk_receive_queue
))
225 printk(KERN_ERR
"sigd_close: closing with requests pending\n");
226 skb_queue_purge(&sk_atm(vcc
)->sk_receive_queue
);
228 read_lock(&vcc_sklist_lock
);
229 for(i
= 0; i
< VCC_HTABLE_SIZE
; ++i
) {
230 struct hlist_head
*head
= &vcc_hash
[i
];
232 sk_for_each(s
, node
, head
) {
238 read_unlock(&vcc_sklist_lock
);
242 static struct atmdev_ops sigd_dev_ops
= {
248 static struct atm_dev sigd_dev
= {
249 .ops
= &sigd_dev_ops
,
252 .lock
= __SPIN_LOCK_UNLOCKED(sigd_dev
.lock
)
256 int sigd_attach(struct atm_vcc
*vcc
)
258 if (sigd
) return -EADDRINUSE
;
259 pr_debug("sigd_attach\n");
261 vcc
->dev
= &sigd_dev
;
262 vcc_insert_socket(sk_atm(vcc
));
263 set_bit(ATM_VF_META
,&vcc
->flags
);
264 set_bit(ATM_VF_READY
,&vcc
->flags
);
265 #ifdef WAIT_FOR_DEMON
266 wake_up(&sigd_sleep
);