pvc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* net/atm/pvc.c - ATM PVC sockets */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #include <linux/net.h> /* struct socket, struct proto_ops */
  4. #include <linux/atm.h> /* ATM stuff */
  5. #include <linux/atmdev.h> /* ATM devices */
  6. #include <linux/errno.h> /* error codes */
  7. #include <linux/kernel.h> /* printk */
  8. #include <linux/init.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/bitops.h>
  11. #include <linux/export.h>
  12. #include <net/sock.h> /* for sock_no_* */
  13. #include "resources.h" /* devs and vccs */
  14. #include "common.h" /* common for PVCs and SVCs */
  15. static int pvc_shutdown(struct socket *sock, int how)
  16. {
  17. return 0;
  18. }
  19. static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
  20. int sockaddr_len)
  21. {
  22. struct sock *sk = sock->sk;
  23. struct sockaddr_atmpvc *addr;
  24. struct atm_vcc *vcc;
  25. int error;
  26. if (sockaddr_len != sizeof(struct sockaddr_atmpvc))
  27. return -EINVAL;
  28. addr = (struct sockaddr_atmpvc *)sockaddr;
  29. if (addr->sap_family != AF_ATMPVC)
  30. return -EAFNOSUPPORT;
  31. lock_sock(sk);
  32. vcc = ATM_SD(sock);
  33. if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
  34. error = -EBADFD;
  35. goto out;
  36. }
  37. if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
  38. if (vcc->vpi != ATM_VPI_UNSPEC)
  39. addr->sap_addr.vpi = vcc->vpi;
  40. if (vcc->vci != ATM_VCI_UNSPEC)
  41. addr->sap_addr.vci = vcc->vci;
  42. }
  43. error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
  44. addr->sap_addr.vci);
  45. out:
  46. release_sock(sk);
  47. return error;
  48. }
  49. static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
  50. int sockaddr_len, int flags)
  51. {
  52. return pvc_bind(sock, sockaddr, sockaddr_len);
  53. }
  54. static int pvc_setsockopt(struct socket *sock, int level, int optname,
  55. char __user *optval, unsigned int optlen)
  56. {
  57. struct sock *sk = sock->sk;
  58. int error;
  59. lock_sock(sk);
  60. error = vcc_setsockopt(sock, level, optname, optval, optlen);
  61. release_sock(sk);
  62. return error;
  63. }
  64. static int pvc_getsockopt(struct socket *sock, int level, int optname,
  65. char __user *optval, int __user *optlen)
  66. {
  67. struct sock *sk = sock->sk;
  68. int error;
  69. lock_sock(sk);
  70. error = vcc_getsockopt(sock, level, optname, optval, optlen);
  71. release_sock(sk);
  72. return error;
  73. }
  74. static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
  75. int *sockaddr_len, int peer)
  76. {
  77. struct sockaddr_atmpvc *addr;
  78. struct atm_vcc *vcc = ATM_SD(sock);
  79. if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
  80. return -ENOTCONN;
  81. *sockaddr_len = sizeof(struct sockaddr_atmpvc);
  82. addr = (struct sockaddr_atmpvc *)sockaddr;
  83. memset(addr, 0, sizeof(*addr));
  84. addr->sap_family = AF_ATMPVC;
  85. addr->sap_addr.itf = vcc->dev->number;
  86. addr->sap_addr.vpi = vcc->vpi;
  87. addr->sap_addr.vci = vcc->vci;
  88. return 0;
  89. }
  90. static const struct proto_ops pvc_proto_ops = {
  91. .family = PF_ATMPVC,
  92. .owner = THIS_MODULE,
  93. .release = vcc_release,
  94. .bind = pvc_bind,
  95. .connect = pvc_connect,
  96. .socketpair = sock_no_socketpair,
  97. .accept = sock_no_accept,
  98. .getname = pvc_getname,
  99. .poll = vcc_poll,
  100. .ioctl = vcc_ioctl,
  101. #ifdef CONFIG_COMPAT
  102. .compat_ioctl = vcc_compat_ioctl,
  103. #endif
  104. .listen = sock_no_listen,
  105. .shutdown = pvc_shutdown,
  106. .setsockopt = pvc_setsockopt,
  107. .getsockopt = pvc_getsockopt,
  108. .sendmsg = vcc_sendmsg,
  109. .recvmsg = vcc_recvmsg,
  110. .mmap = sock_no_mmap,
  111. .sendpage = sock_no_sendpage,
  112. };
  113. static int pvc_create(struct net *net, struct socket *sock, int protocol,
  114. int kern)
  115. {
  116. if (net != &init_net)
  117. return -EAFNOSUPPORT;
  118. sock->ops = &pvc_proto_ops;
  119. return vcc_create(net, sock, protocol, PF_ATMPVC, kern);
  120. }
  121. static const struct net_proto_family pvc_family_ops = {
  122. .family = PF_ATMPVC,
  123. .create = pvc_create,
  124. .owner = THIS_MODULE,
  125. };
  126. /*
  127. * Initialize the ATM PVC protocol family
  128. */
  129. int __init atmpvc_init(void)
  130. {
  131. return sock_register(&pvc_family_ops);
  132. }
  133. void atmpvc_exit(void)
  134. {
  135. sock_unregister(PF_ATMPVC);
  136. }