raw.c 1.9 KB

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