raw.c 1.9 KB

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