raw.c 1.9 KB

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