raw.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* net/atm/raw.c - Raw AAL0 and AAL5 transports */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  4. #include <linux/module.h>
  5. #include <linux/atmdev.h>
  6. #include <linux/capability.h>
  7. #include <linux/kernel.h>
  8. #include <linux/skbuff.h>
  9. #include <linux/mm.h>
  10. #include <linux/slab.h>
  11. #include "common.h"
  12. #include "protocols.h"
  13. /*
  14. * SKB == NULL indicates that the link is being closed
  15. */
  16. static void atm_push_raw(struct atm_vcc *vcc, struct sk_buff *skb)
  17. {
  18. if (skb) {
  19. struct sock *sk = sk_atm(vcc);
  20. skb_queue_tail(&sk->sk_receive_queue, skb);
  21. sk->sk_data_ready(sk);
  22. }
  23. }
  24. static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
  25. {
  26. struct sock *sk = sk_atm(vcc);
  27. pr_debug("(%d) %d -= %d\n",
  28. vcc->vci, sk_wmem_alloc_get(sk), skb->truesize);
  29. atomic_sub(skb->truesize, &sk->sk_wmem_alloc);
  30. dev_kfree_skb_any(skb);
  31. sk->sk_write_space(sk);
  32. }
  33. static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb)
  34. {
  35. /*
  36. * Note that if vpi/vci are _ANY or _UNSPEC the below will
  37. * still work
  38. */
  39. if (!capable(CAP_NET_ADMIN) &&
  40. (((u32 *)skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) !=
  41. ((vcc->vpi << ATM_HDR_VPI_SHIFT) |
  42. (vcc->vci << ATM_HDR_VCI_SHIFT))) {
  43. kfree_skb(skb);
  44. return -EADDRNOTAVAIL;
  45. }
  46. return vcc->dev->ops->send(vcc, skb);
  47. }
  48. int atm_init_aal0(struct atm_vcc *vcc)
  49. {
  50. vcc->push = atm_push_raw;
  51. vcc->pop = atm_pop_raw;
  52. vcc->push_oam = NULL;
  53. vcc->send = atm_send_aal0;
  54. return 0;
  55. }
  56. int atm_init_aal34(struct atm_vcc *vcc)
  57. {
  58. vcc->push = atm_push_raw;
  59. vcc->pop = atm_pop_raw;
  60. vcc->push_oam = NULL;
  61. vcc->send = vcc->dev->ops->send;
  62. return 0;
  63. }
  64. int atm_init_aal5(struct atm_vcc *vcc)
  65. {
  66. vcc->push = atm_push_raw;
  67. vcc->pop = atm_pop_raw;
  68. vcc->push_oam = NULL;
  69. vcc->send = vcc->dev->ops->send;
  70. return 0;
  71. }
  72. EXPORT_SYMBOL(atm_init_aal5);