ioctl.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. static DECLARE_MUTEX(ioctl_mutex);
  21. static LIST_HEAD(ioctl_list);
  22. void register_atm_ioctl(struct atm_ioctl *ioctl)
  23. {
  24. down(&ioctl_mutex);
  25. list_add_tail(&ioctl->list, &ioctl_list);
  26. up(&ioctl_mutex);
  27. }
  28. void deregister_atm_ioctl(struct atm_ioctl *ioctl)
  29. {
  30. down(&ioctl_mutex);
  31. list_del(&ioctl->list);
  32. up(&ioctl_mutex);
  33. }
  34. EXPORT_SYMBOL(register_atm_ioctl);
  35. EXPORT_SYMBOL(deregister_atm_ioctl);
  36. int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  37. {
  38. struct sock *sk = sock->sk;
  39. struct atm_vcc *vcc;
  40. int error;
  41. struct list_head * pos;
  42. void __user *argp = (void __user *)arg;
  43. vcc = ATM_SD(sock);
  44. switch (cmd) {
  45. case SIOCOUTQ:
  46. if (sock->state != SS_CONNECTED ||
  47. !test_bit(ATM_VF_READY, &vcc->flags)) {
  48. error = -EINVAL;
  49. goto done;
  50. }
  51. error = put_user(sk->sk_sndbuf -
  52. atomic_read(&sk->sk_wmem_alloc),
  53. (int __user *) argp) ? -EFAULT : 0;
  54. goto done;
  55. case SIOCINQ:
  56. {
  57. struct sk_buff *skb;
  58. if (sock->state != SS_CONNECTED) {
  59. error = -EINVAL;
  60. goto done;
  61. }
  62. skb = skb_peek(&sk->sk_receive_queue);
  63. error = put_user(skb ? skb->len : 0,
  64. (int __user *)argp) ? -EFAULT : 0;
  65. goto done;
  66. }
  67. case SIOCGSTAMP: /* borrowed from IP */
  68. error = sock_get_timestamp(sk, argp);
  69. goto done;
  70. case ATM_SETSC:
  71. printk(KERN_WARNING "ATM_SETSC is obsolete\n");
  72. error = 0;
  73. goto done;
  74. case ATMSIGD_CTRL:
  75. if (!capable(CAP_NET_ADMIN)) {
  76. error = -EPERM;
  77. goto done;
  78. }
  79. /*
  80. * The user/kernel protocol for exchanging signalling
  81. * info uses kernel pointers as opaque references,
  82. * so the holder of the file descriptor can scribble
  83. * on the kernel... so we should make sure that we
  84. * have the same privledges that /proc/kcore needs
  85. */
  86. if (!capable(CAP_SYS_RAWIO)) {
  87. error = -EPERM;
  88. goto done;
  89. }
  90. error = sigd_attach(vcc);
  91. if (!error)
  92. sock->state = SS_CONNECTED;
  93. goto done;
  94. default:
  95. break;
  96. }
  97. if (cmd == ATMMPC_CTRL || cmd == ATMMPC_DATA)
  98. request_module("mpoa");
  99. if (cmd == ATMARPD_CTRL)
  100. request_module("clip");
  101. if (cmd == ATMLEC_CTRL)
  102. request_module("lec");
  103. error = -ENOIOCTLCMD;
  104. down(&ioctl_mutex);
  105. list_for_each(pos, &ioctl_list) {
  106. struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list);
  107. if (try_module_get(ic->owner)) {
  108. error = ic->ioctl(sock, cmd, arg);
  109. module_put(ic->owner);
  110. if (error != -ENOIOCTLCMD)
  111. break;
  112. }
  113. }
  114. up(&ioctl_mutex);
  115. if (error != -ENOIOCTLCMD)
  116. goto done;
  117. error = atm_dev_ioctl(cmd, argp);
  118. done:
  119. return error;
  120. }