1 // SPDX-License-Identifier: GPL-2.0
2 /* net/atm/raw.c - Raw AAL0 and AAL5 transports */
4 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
8 #include <linux/module.h>
9 #include <linux/atmdev.h>
10 #include <linux/capability.h>
11 #include <linux/kernel.h>
12 #include <linux/skbuff.h>
14 #include <linux/slab.h>
17 #include "protocols.h"
20 * SKB == NULL indicates that the link is being closed
23 static void atm_push_raw(struct atm_vcc *vcc, struct sk_buff *skb)
26 struct sock *sk = sk_atm(vcc);
28 skb_queue_tail(&sk->sk_receive_queue, skb);
29 sk->sk_data_ready(sk);
33 static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
35 struct sock *sk = sk_atm(vcc);
37 pr_debug("(%d) %d -= %d\n",
38 vcc->vci, sk_wmem_alloc_get(sk), ATM_SKB(skb)->acct_truesize);
39 WARN_ON(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize, &sk->sk_wmem_alloc));
40 dev_kfree_skb_any(skb);
41 sk->sk_write_space(sk);
44 static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb)
47 * Note that if vpi/vci are _ANY or _UNSPEC the below will
50 if (!capable(CAP_NET_ADMIN) &&
51 (((u32 *)skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) !=
52 ((vcc->vpi << ATM_HDR_VPI_SHIFT) |
53 (vcc->vci << ATM_HDR_VCI_SHIFT))) {
55 return -EADDRNOTAVAIL;
57 if (vcc->dev->ops->send_bh)
58 return vcc->dev->ops->send_bh(vcc, skb);
59 return vcc->dev->ops->send(vcc, skb);
62 int atm_init_aal0(struct atm_vcc *vcc)
64 vcc->push = atm_push_raw;
65 vcc->pop = atm_pop_raw;
67 vcc->send = atm_send_aal0;
71 int atm_init_aal34(struct atm_vcc *vcc)
73 vcc->push = atm_push_raw;
74 vcc->pop = atm_pop_raw;
76 if (vcc->dev->ops->send_bh)
77 vcc->send = vcc->dev->ops->send_bh;
79 vcc->send = vcc->dev->ops->send;
83 int atm_init_aal5(struct atm_vcc *vcc)
85 vcc->push = atm_push_raw;
86 vcc->pop = atm_pop_raw;
88 if (vcc->dev->ops->send_bh)
89 vcc->send = vcc->dev->ops->send_bh;
91 vcc->send = vcc->dev->ops->send;
94 EXPORT_SYMBOL(atm_init_aal5);