1 /* net/atm/signaling.c - ATM signaling */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
7 #include <linux/errno.h> /* error codes */
8 #include <linux/kernel.h> /* printk */
9 #include <linux/skbuff.h>
10 #include <linux/wait.h>
11 #include <linux/sched.h> /* jiffies and HZ */
12 #include <linux/atm.h> /* ATM stuff */
13 #include <linux/atmsap.h>
14 #include <linux/atmsvc.h>
15 #include <linux/atmdev.h>
16 #include <linux/bitops.h>
17 #include <linux/slab.h>
19 #include "resources.h"
20 #include "signaling.h"
22 #undef WAIT_FOR_DEMON /* #define this if system calls on SVC sockets
23 should block until the demon runs.
24 Danger: may cause nasty hangs if the demon
27 struct atm_vcc *sigd = NULL;
29 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 daemon...\n");
43 current->state = TASK_RUNNING;
44 remove_wait_queue(&sigd_sleep, &wait);
47 pr_debug("atmsvc: no signaling daemon\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);
57 static void modify_qos(struct atm_vcc *vcc, struct atmsvc_msg *msg)
61 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
62 !test_bit(ATM_VF_READY, &vcc->flags))
65 if (!vcc->dev->ops->change_qos)
66 msg->reply = -EOPNOTSUPP;
69 msg->reply = vcc->dev->ops->change_qos(vcc, &msg->qos,
75 * Should probably just turn around the old skb. But the, the buffer
76 * space accounting needs to follow the change too. Maybe later.
78 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
80 *(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("%d (0x%lx)\n", (int)msg->type, (unsigned long)vcc);
98 sk->sk_err = -msg->reply;
99 clear_bit(ATM_VF_WAITING, &vcc->flags);
100 if (!*vcc->local.sas_addr.prv && !*vcc->local.sas_addr.pub) {
101 vcc->local.sas_family = AF_ATMSVC;
102 memcpy(vcc->local.sas_addr.prv,
103 msg->local.sas_addr.prv, ATM_ESA_LEN);
104 memcpy(vcc->local.sas_addr.pub,
105 msg->local.sas_addr.pub, ATM_E164_LEN + 1);
107 session_vcc = vcc->session ? vcc->session : vcc;
108 if (session_vcc->vpi || session_vcc->vci)
110 session_vcc->itf = msg->pvc.sap_addr.itf;
111 session_vcc->vpi = msg->pvc.sap_addr.vpi;
112 session_vcc->vci = msg->pvc.sap_addr.vci;
113 if (session_vcc->vpi || session_vcc->vci)
114 session_vcc->qos = msg->qos;
117 clear_bit(ATM_VF_REGIS, &vcc->flags);
118 clear_bit(ATM_VF_READY, &vcc->flags);
119 sk->sk_err = -msg->reply;
120 clear_bit(ATM_VF_WAITING, &vcc->flags);
123 vcc = *(struct atm_vcc **)&msg->listen_vcc;
125 pr_debug("as_indicate!!!\n");
127 if (sk_acceptq_is_full(sk)) {
128 sigd_enq(NULL, as_reject, vcc, NULL, NULL);
130 goto as_indicate_complete;
132 sk->sk_ack_backlog++;
133 skb_queue_tail(&sk->sk_receive_queue, skb);
134 pr_debug("waking sk_sleep(sk) 0x%p\n", sk_sleep(sk));
135 sk->sk_state_change(sk);
136 as_indicate_complete:
140 set_bit(ATM_VF_RELEASED, &vcc->flags);
141 vcc_release_async(vcc, msg->reply);
144 modify_qos(vcc, msg);
148 sk->sk_err_soft = msg->reply;
149 /* < 0 failure, otherwise ep_ref */
150 clear_bit(ATM_VF_WAITING, &vcc->flags);
153 pr_alert("bad message type %d\n", (int)msg->type);
156 sk->sk_state_change(sk);
162 void sigd_enq2(struct atm_vcc *vcc, enum atmsvc_msg_type type,
163 struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
164 const struct sockaddr_atmsvc *svc, const struct atm_qos *qos,
168 struct atmsvc_msg *msg;
169 static unsigned int session = 0;
171 pr_debug("%d (0x%p)\n", (int)type, vcc);
172 while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
174 msg = (struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg));
175 memset(msg, 0, sizeof(*msg));
177 *(struct atm_vcc **) &msg->vcc = vcc;
178 *(struct atm_vcc **) &msg->listen_vcc = listen_vcc;
187 msg->local = vcc->local;
191 if (type == as_connect && test_bit(ATM_VF_SESSION, &vcc->flags))
192 msg->session = ++session;
193 /* every new pmp connect gets the next session number */
197 set_bit(ATM_VF_REGIS, &vcc->flags);
200 void sigd_enq(struct atm_vcc *vcc, enum atmsvc_msg_type type,
201 struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
202 const struct sockaddr_atmsvc *svc)
204 sigd_enq2(vcc, type, listen_vcc, pvc, svc, vcc ? &vcc->qos : NULL, 0);
205 /* other ISP applications may use "reply" */
208 static void purge_vcc(struct atm_vcc *vcc)
210 if (sk_atm(vcc)->sk_family == PF_ATMSVC &&
211 !test_bit(ATM_VF_META, &vcc->flags)) {
212 set_bit(ATM_VF_RELEASED, &vcc->flags);
213 clear_bit(ATM_VF_REGIS, &vcc->flags);
214 vcc_release_async(vcc, -EUNATCH);
218 static void sigd_close(struct atm_vcc *vcc)
225 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
226 pr_err("closing with requests pending\n");
227 skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
229 read_lock(&vcc_sklist_lock);
230 for (i = 0; i < VCC_HTABLE_SIZE; ++i) {
231 struct hlist_head *head = &vcc_hash[i];
233 sk_for_each(s, head) {
239 read_unlock(&vcc_sklist_lock);
242 static struct atmdev_ops sigd_dev_ops = {
247 static struct atm_dev sigd_dev = {
248 .ops = &sigd_dev_ops,
251 .lock = __SPIN_LOCK_UNLOCKED(sigd_dev.lock)
254 int sigd_attach(struct atm_vcc *vcc)
260 vcc->dev = &sigd_dev;
261 vcc_insert_socket(sk_atm(vcc));
262 set_bit(ATM_VF_META, &vcc->flags);
263 set_bit(ATM_VF_READY, &vcc->flags);
264 #ifdef WAIT_FOR_DEMON
265 wake_up(&sigd_sleep);