signaling.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* net/atm/signaling.c - ATM signaling */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  4. #include <linux/errno.h> /* error codes */
  5. #include <linux/kernel.h> /* printk */
  6. #include <linux/skbuff.h>
  7. #include <linux/wait.h>
  8. #include <linux/sched.h> /* jiffies and HZ */
  9. #include <linux/atm.h> /* ATM stuff */
  10. #include <linux/atmsap.h>
  11. #include <linux/atmsvc.h>
  12. #include <linux/atmdev.h>
  13. #include <linux/bitops.h>
  14. #include <linux/slab.h>
  15. #include "resources.h"
  16. #include "signaling.h"
  17. struct atm_vcc *sigd = NULL;
  18. static void sigd_put_skb(struct sk_buff *skb)
  19. {
  20. if (!sigd) {
  21. pr_debug("atmsvc: no signaling daemon\n");
  22. kfree_skb(skb);
  23. return;
  24. }
  25. atm_force_charge(sigd, skb->truesize);
  26. skb_queue_tail(&sk_atm(sigd)->sk_receive_queue, skb);
  27. sk_atm(sigd)->sk_data_ready(sk_atm(sigd));
  28. }
  29. static void modify_qos(struct atm_vcc *vcc, struct atmsvc_msg *msg)
  30. {
  31. struct sk_buff *skb;
  32. if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
  33. !test_bit(ATM_VF_READY, &vcc->flags))
  34. return;
  35. msg->type = as_error;
  36. if (!vcc->dev->ops->change_qos)
  37. msg->reply = -EOPNOTSUPP;
  38. else {
  39. /* should lock VCC */
  40. msg->reply = vcc->dev->ops->change_qos(vcc, &msg->qos,
  41. msg->reply);
  42. if (!msg->reply)
  43. msg->type = as_okay;
  44. }
  45. /*
  46. * Should probably just turn around the old skb. But the, the buffer
  47. * space accounting needs to follow the change too. Maybe later.
  48. */
  49. while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
  50. schedule();
  51. *(struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg)) = *msg;
  52. sigd_put_skb(skb);
  53. }
  54. static int sigd_send(struct atm_vcc *vcc, struct sk_buff *skb)
  55. {
  56. struct atmsvc_msg *msg;
  57. struct atm_vcc *session_vcc;
  58. struct sock *sk;
  59. msg = (struct atmsvc_msg *) skb->data;
  60. atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  61. vcc = *(struct atm_vcc **) &msg->vcc;
  62. pr_debug("%d (0x%lx)\n", (int)msg->type, (unsigned long)vcc);
  63. sk = sk_atm(vcc);
  64. switch (msg->type) {
  65. case as_okay:
  66. sk->sk_err = -msg->reply;
  67. clear_bit(ATM_VF_WAITING, &vcc->flags);
  68. if (!*vcc->local.sas_addr.prv && !*vcc->local.sas_addr.pub) {
  69. vcc->local.sas_family = AF_ATMSVC;
  70. memcpy(vcc->local.sas_addr.prv,
  71. msg->local.sas_addr.prv, ATM_ESA_LEN);
  72. memcpy(vcc->local.sas_addr.pub,
  73. msg->local.sas_addr.pub, ATM_E164_LEN + 1);
  74. }
  75. session_vcc = vcc->session ? vcc->session : vcc;
  76. if (session_vcc->vpi || session_vcc->vci)
  77. break;
  78. session_vcc->itf = msg->pvc.sap_addr.itf;
  79. session_vcc->vpi = msg->pvc.sap_addr.vpi;
  80. session_vcc->vci = msg->pvc.sap_addr.vci;
  81. if (session_vcc->vpi || session_vcc->vci)
  82. session_vcc->qos = msg->qos;
  83. break;
  84. case as_error:
  85. clear_bit(ATM_VF_REGIS, &vcc->flags);
  86. clear_bit(ATM_VF_READY, &vcc->flags);
  87. sk->sk_err = -msg->reply;
  88. clear_bit(ATM_VF_WAITING, &vcc->flags);
  89. break;
  90. case as_indicate:
  91. vcc = *(struct atm_vcc **)&msg->listen_vcc;
  92. sk = sk_atm(vcc);
  93. pr_debug("as_indicate!!!\n");
  94. lock_sock(sk);
  95. if (sk_acceptq_is_full(sk)) {
  96. sigd_enq(NULL, as_reject, vcc, NULL, NULL);
  97. dev_kfree_skb(skb);
  98. goto as_indicate_complete;
  99. }
  100. sk->sk_ack_backlog++;
  101. skb_queue_tail(&sk->sk_receive_queue, skb);
  102. pr_debug("waking sk_sleep(sk) 0x%p\n", sk_sleep(sk));
  103. sk->sk_state_change(sk);
  104. as_indicate_complete:
  105. release_sock(sk);
  106. return 0;
  107. case as_close:
  108. set_bit(ATM_VF_RELEASED, &vcc->flags);
  109. vcc_release_async(vcc, msg->reply);
  110. goto out;
  111. case as_modify:
  112. modify_qos(vcc, msg);
  113. break;
  114. case as_addparty:
  115. case as_dropparty:
  116. sk->sk_err_soft = -msg->reply;
  117. /* < 0 failure, otherwise ep_ref */
  118. clear_bit(ATM_VF_WAITING, &vcc->flags);
  119. break;
  120. default:
  121. pr_alert("bad message type %d\n", (int)msg->type);
  122. return -EINVAL;
  123. }
  124. sk->sk_state_change(sk);
  125. out:
  126. dev_kfree_skb(skb);
  127. return 0;
  128. }
  129. void sigd_enq2(struct atm_vcc *vcc, enum atmsvc_msg_type type,
  130. struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
  131. const struct sockaddr_atmsvc *svc, const struct atm_qos *qos,
  132. int reply)
  133. {
  134. struct sk_buff *skb;
  135. struct atmsvc_msg *msg;
  136. static unsigned int session = 0;
  137. pr_debug("%d (0x%p)\n", (int)type, vcc);
  138. while (!(skb = alloc_skb(sizeof(struct atmsvc_msg), GFP_KERNEL)))
  139. schedule();
  140. msg = (struct atmsvc_msg *)skb_put(skb, sizeof(struct atmsvc_msg));
  141. memset(msg, 0, sizeof(*msg));
  142. msg->type = type;
  143. *(struct atm_vcc **) &msg->vcc = vcc;
  144. *(struct atm_vcc **) &msg->listen_vcc = listen_vcc;
  145. msg->reply = reply;
  146. if (qos)
  147. msg->qos = *qos;
  148. if (vcc)
  149. msg->sap = vcc->sap;
  150. if (svc)
  151. msg->svc = *svc;
  152. if (vcc)
  153. msg->local = vcc->local;
  154. if (pvc)
  155. msg->pvc = *pvc;
  156. if (vcc) {
  157. if (type == as_connect && test_bit(ATM_VF_SESSION, &vcc->flags))
  158. msg->session = ++session;
  159. /* every new pmp connect gets the next session number */
  160. }
  161. sigd_put_skb(skb);
  162. if (vcc)
  163. set_bit(ATM_VF_REGIS, &vcc->flags);
  164. }
  165. void sigd_enq(struct atm_vcc *vcc, enum atmsvc_msg_type type,
  166. struct atm_vcc *listen_vcc, const struct sockaddr_atmpvc *pvc,
  167. const struct sockaddr_atmsvc *svc)
  168. {
  169. sigd_enq2(vcc, type, listen_vcc, pvc, svc, vcc ? &vcc->qos : NULL, 0);
  170. /* other ISP applications may use "reply" */
  171. }
  172. static void purge_vcc(struct atm_vcc *vcc)
  173. {
  174. if (sk_atm(vcc)->sk_family == PF_ATMSVC &&
  175. !test_bit(ATM_VF_META, &vcc->flags)) {
  176. set_bit(ATM_VF_RELEASED, &vcc->flags);
  177. clear_bit(ATM_VF_REGIS, &vcc->flags);
  178. vcc_release_async(vcc, -EUNATCH);
  179. }
  180. }
  181. static void sigd_close(struct atm_vcc *vcc)
  182. {
  183. struct sock *s;
  184. int i;
  185. pr_debug("\n");
  186. sigd = NULL;
  187. if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
  188. pr_err("closing with requests pending\n");
  189. skb_queue_purge(&sk_atm(vcc)->sk_receive_queue);
  190. read_lock(&vcc_sklist_lock);
  191. for (i = 0; i < VCC_HTABLE_SIZE; ++i) {
  192. struct hlist_head *head = &vcc_hash[i];
  193. sk_for_each(s, head) {
  194. vcc = atm_sk(s);
  195. purge_vcc(vcc);
  196. }
  197. }
  198. read_unlock(&vcc_sklist_lock);
  199. }
  200. static struct atmdev_ops sigd_dev_ops = {
  201. .close = sigd_close,
  202. .send = sigd_send
  203. };
  204. static struct atm_dev sigd_dev = {
  205. .ops = &sigd_dev_ops,
  206. .type = "sig",
  207. .number = 999,
  208. .lock = __SPIN_LOCK_UNLOCKED(sigd_dev.lock)
  209. };
  210. int sigd_attach(struct atm_vcc *vcc)
  211. {
  212. if (sigd)
  213. return -EADDRINUSE;
  214. pr_debug("\n");
  215. sigd = vcc;
  216. vcc->dev = &sigd_dev;
  217. vcc_insert_socket(sk_atm(vcc));
  218. set_bit(ATM_VF_META, &vcc->flags);
  219. set_bit(ATM_VF_READY, &vcc->flags);
  220. return 0;
  221. }