ioctl.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/capability.h>
  13. #include <linux/sonet.h> /* for ioctls */
  14. #include <linux/atmsvc.h>
  15. #include <linux/atmmpc.h>
  16. #include <net/atmclip.h>
  17. #include <linux/atmlec.h>
  18. #include <linux/mutex.h>
  19. #include <asm/ioctls.h>
  20. #include "resources.h"
  21. #include "signaling.h" /* for WAITING and sigd_attach */
  22. #include "common.h"
  23. static DEFINE_MUTEX(ioctl_mutex);
  24. static LIST_HEAD(ioctl_list);
  25. void register_atm_ioctl(struct atm_ioctl *ioctl)
  26. {
  27. mutex_lock(&ioctl_mutex);
  28. list_add_tail(&ioctl->list, &ioctl_list);
  29. mutex_unlock(&ioctl_mutex);
  30. }
  31. void deregister_atm_ioctl(struct atm_ioctl *ioctl)
  32. {
  33. mutex_lock(&ioctl_mutex);
  34. list_del(&ioctl->list);
  35. mutex_unlock(&ioctl_mutex);
  36. }
  37. EXPORT_SYMBOL(register_atm_ioctl);
  38. EXPORT_SYMBOL(deregister_atm_ioctl);
  39. int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  40. {
  41. struct sock *sk = sock->sk;
  42. struct atm_vcc *vcc;
  43. int error;
  44. struct list_head * pos;
  45. void __user *argp = (void __user *)arg;
  46. vcc = ATM_SD(sock);
  47. switch (cmd) {
  48. case SIOCOUTQ:
  49. if (sock->state != SS_CONNECTED ||
  50. !test_bit(ATM_VF_READY, &vcc->flags)) {
  51. error = -EINVAL;
  52. goto done;
  53. }
  54. error = put_user(sk->sk_sndbuf -
  55. atomic_read(&sk->sk_wmem_alloc),
  56. (int __user *) argp) ? -EFAULT : 0;
  57. goto done;
  58. case SIOCINQ:
  59. {
  60. struct sk_buff *skb;
  61. if (sock->state != SS_CONNECTED) {
  62. error = -EINVAL;
  63. goto done;
  64. }
  65. skb = skb_peek(&sk->sk_receive_queue);
  66. error = put_user(skb ? skb->len : 0,
  67. (int __user *)argp) ? -EFAULT : 0;
  68. goto done;
  69. }
  70. case SIOCGSTAMP: /* borrowed from IP */
  71. error = sock_get_timestamp(sk, argp);
  72. goto done;
  73. case ATM_SETSC:
  74. printk(KERN_WARNING "ATM_SETSC is obsolete\n");
  75. error = 0;
  76. goto done;
  77. case ATMSIGD_CTRL:
  78. if (!capable(CAP_NET_ADMIN)) {
  79. error = -EPERM;
  80. goto done;
  81. }
  82. /*
  83. * The user/kernel protocol for exchanging signalling
  84. * info uses kernel pointers as opaque references,
  85. * so the holder of the file descriptor can scribble
  86. * on the kernel... so we should make sure that we
  87. * have the same privledges that /proc/kcore needs
  88. */
  89. if (!capable(CAP_SYS_RAWIO)) {
  90. error = -EPERM;
  91. goto done;
  92. }
  93. error = sigd_attach(vcc);
  94. if (!error)
  95. sock->state = SS_CONNECTED;
  96. goto done;
  97. case ATM_SETBACKEND:
  98. case ATM_NEWBACKENDIF:
  99. {
  100. atm_backend_t backend;
  101. error = get_user(backend, (atm_backend_t __user *) argp);
  102. if (error)
  103. goto done;
  104. switch (backend) {
  105. case ATM_BACKEND_PPP:
  106. request_module("pppoatm");
  107. break;
  108. case ATM_BACKEND_BR2684:
  109. request_module("br2684");
  110. break;
  111. }
  112. }
  113. break;
  114. case ATMMPC_CTRL:
  115. case ATMMPC_DATA:
  116. request_module("mpoa");
  117. break;
  118. case ATMARPD_CTRL:
  119. request_module("clip");
  120. break;
  121. case ATMLEC_CTRL:
  122. request_module("lec");
  123. break;
  124. }
  125. error = -ENOIOCTLCMD;
  126. mutex_lock(&ioctl_mutex);
  127. list_for_each(pos, &ioctl_list) {
  128. struct atm_ioctl * ic = list_entry(pos, struct atm_ioctl, list);
  129. if (try_module_get(ic->owner)) {
  130. error = ic->ioctl(sock, cmd, arg);
  131. module_put(ic->owner);
  132. if (error != -ENOIOCTLCMD)
  133. break;
  134. }
  135. }
  136. mutex_unlock(&ioctl_mutex);
  137. if (error != -ENOIOCTLCMD)
  138. goto done;
  139. error = atm_dev_ioctl(cmd, argp);
  140. done:
  141. return error;
  142. }