ioctl.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* ATM ioctl handling */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. /* 2003 John Levon <levon@movementarian.org> */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/kmod.h>
  7. #include <linux/net.h> /* struct socket, struct proto_ops */
  8. #include <linux/atm.h> /* ATM stuff */
  9. #include <linux/atmdev.h>
  10. #include <linux/atmclip.h> /* CLIP_*ENCAP */
  11. #include <linux/atmarp.h> /* manifest constants */
  12. #include <linux/sonet.h> /* for ioctls */
  13. #include <linux/atmsvc.h>
  14. #include <linux/atmmpc.h>
  15. #include <net/atmclip.h>
  16. #include <linux/atmlec.h>
  17. #include <asm/ioctls.h>
  18. #include "resources.h"
  19. #include "signaling.h" /* for WAITING and sigd_attach */
  20. #include "common.h"
  21. static DECLARE_MUTEX(ioctl_mutex);
  22. static LIST_HEAD(ioctl_list);
  23. void register_atm_ioctl(struct atm_ioctl *ioctl)
  24. {
  25. down(&ioctl_mutex);
  26. list_add_tail(&ioctl->list, &ioctl_list);
  27. up(&ioctl_mutex);
  28. }
  29. void deregister_atm_ioctl(struct atm_ioctl *ioctl)
  30. {
  31. down(&ioctl_mutex);
  32. list_del(&ioctl->list);
  33. up(&ioctl_mutex);
  34. }
  35. EXPORT_SYMBOL(register_atm_ioctl);
  36. EXPORT_SYMBOL(deregister_atm_ioctl);
  37. int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  38. {
  39. struct sock *sk = sock->sk;
  40. struct atm_vcc *vcc;
  41. int error;
  42. struct list_head * pos;
  43. void __user *argp = (void __user *)arg;
  44. vcc = ATM_SD(sock);
  45. switch (cmd) {
  46. case SIOCOUTQ:
  47. if (sock->state != SS_CONNECTED ||
  48. !test_bit(ATM_VF_READY, &vcc->flags)) {
  49. error = -EINVAL;
  50. goto done;
  51. }
  52. error = put_user(sk->sk_sndbuf -
  53. atomic_read(&sk->sk_wmem_alloc),
  54. (int __user *) argp) ? -EFAULT : 0;
  55. goto done;
  56. case SIOCINQ:
  57. {
  58. struct sk_buff *skb;
  59. if (sock->state != SS_CONNECTED) {
  60. error = -EINVAL;
  61. goto done;
  62. }
  63. skb = skb_peek(&sk->sk_receive_queue);
  64. error = put_user(skb ? skb->len : 0,
  65. (int __user *)argp) ? -EFAULT : 0;
  66. goto done;
  67. }
  68. case SIOCGSTAMP: /* borrowed from IP */
  69. error = sock_get_timestamp(sk, argp);
  70. goto done;
  71. case ATM_SETSC:
  72. printk(KERN_WARNING "ATM_SETSC is obsolete\n");
  73. error = 0;
  74. goto done;
  75. case ATMSIGD_CTRL:
  76. if (!capable(CAP_NET_ADMIN)) {
  77. error = -EPERM;
  78. goto done;
  79. }
  80. /*
  81. * The user/kernel protocol for exchanging signalling
  82. * info uses kernel pointers as opaque references,
  83. * so the holder of the file descriptor can scribble
  84. * on the kernel... so we should make sure that we
  85. * have the same privledges that /proc/kcore needs
  86. */
  87. if (!capable(CAP_SYS_RAWIO)) {
  88. error = -EPERM;
  89. goto done;
  90. }
  91. error = sigd_attach(vcc);
  92. if (!error)
  93. sock->state = SS_CONNECTED;
  94. goto done;
  95. default:
  96. break;
  97. }
  98. if (cmd == ATMMPC_CTRL || cmd == ATMMPC_DATA)
  99. request_module("mpoa");
  100. if (cmd == ATMARPD_CTRL)
  101. request_module("clip");
  102. if (cmd == ATMLEC_CTRL)
  103. request_module("lec");
  104. error = -ENOIOCTLCMD;
  105. down(&ioctl_mutex);
  106. list_for_each(pos, &ioctl_list) {
  107. struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list);
  108. if (try_module_get(ic->owner)) {
  109. error = ic->ioctl(sock, cmd, arg);
  110. module_put(ic->owner);
  111. if (error != -ENOIOCTLCMD)
  112. break;
  113. }
  114. }
  115. up(&ioctl_mutex);
  116. if (error != -ENOIOCTLCMD)
  117. goto done;
  118. error = atm_dev_ioctl(cmd, argp);
  119. done:
  120. return error;
  121. }