1 // SPDX-License-Identifier: GPL-2.0 << 2 /* net/atm/raw.c - Raw AAL0 and AAL5 transport 1 /* net/atm/raw.c - Raw AAL0 and AAL5 transports */ 3 2 4 /* Written 1995-2000 by Werner Almesberger, EP 3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 5 4 6 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt 5 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ 7 6 8 #include <linux/module.h> 7 #include <linux/module.h> 9 #include <linux/atmdev.h> 8 #include <linux/atmdev.h> 10 #include <linux/capability.h> 9 #include <linux/capability.h> 11 #include <linux/kernel.h> 10 #include <linux/kernel.h> 12 #include <linux/skbuff.h> 11 #include <linux/skbuff.h> 13 #include <linux/mm.h> 12 #include <linux/mm.h> 14 #include <linux/slab.h> 13 #include <linux/slab.h> 15 14 16 #include "common.h" 15 #include "common.h" 17 #include "protocols.h" 16 #include "protocols.h" 18 17 19 /* 18 /* 20 * SKB == NULL indicates that the link is bein 19 * SKB == NULL indicates that the link is being closed 21 */ 20 */ 22 21 23 static void atm_push_raw(struct atm_vcc *vcc, 22 static void atm_push_raw(struct atm_vcc *vcc, struct sk_buff *skb) 24 { 23 { 25 if (skb) { 24 if (skb) { 26 struct sock *sk = sk_atm(vcc); 25 struct sock *sk = sk_atm(vcc); 27 26 28 skb_queue_tail(&sk->sk_receive 27 skb_queue_tail(&sk->sk_receive_queue, skb); 29 sk->sk_data_ready(sk); 28 sk->sk_data_ready(sk); 30 } 29 } 31 } 30 } 32 31 33 static void atm_pop_raw(struct atm_vcc *vcc, s 32 static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb) 34 { 33 { 35 struct sock *sk = sk_atm(vcc); 34 struct sock *sk = sk_atm(vcc); 36 35 37 pr_debug("(%d) %d -= %d\n", 36 pr_debug("(%d) %d -= %d\n", 38 vcc->vci, sk_wmem_alloc_get(s !! 37 vcc->vci, sk_wmem_alloc_get(sk), skb->truesize); 39 WARN_ON(refcount_sub_and_test(ATM_SKB( !! 38 atomic_sub(skb->truesize, &sk->sk_wmem_alloc); 40 dev_kfree_skb_any(skb); 39 dev_kfree_skb_any(skb); 41 sk->sk_write_space(sk); 40 sk->sk_write_space(sk); 42 } 41 } 43 42 44 static int atm_send_aal0(struct atm_vcc *vcc, 43 static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb) 45 { 44 { 46 /* 45 /* 47 * Note that if vpi/vci are _ANY or _U 46 * Note that if vpi/vci are _ANY or _UNSPEC the below will 48 * still work 47 * still work 49 */ 48 */ 50 if (!capable(CAP_NET_ADMIN) && 49 if (!capable(CAP_NET_ADMIN) && 51 (((u32 *)skb->data)[0] & (ATM_HDR_ 50 (((u32 *)skb->data)[0] & (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)) != 52 ((vcc->vpi << ATM_HDR_VPI_SHIFT) | 51 ((vcc->vpi << ATM_HDR_VPI_SHIFT) | 53 (vcc->vci << ATM_HDR_VCI_SHIFT))) 52 (vcc->vci << ATM_HDR_VCI_SHIFT))) { 54 kfree_skb(skb); 53 kfree_skb(skb); 55 return -EADDRNOTAVAIL; 54 return -EADDRNOTAVAIL; 56 } 55 } 57 if (vcc->dev->ops->send_bh) << 58 return vcc->dev->ops->send_bh( << 59 return vcc->dev->ops->send(vcc, skb); 56 return vcc->dev->ops->send(vcc, skb); 60 } 57 } 61 58 62 int atm_init_aal0(struct atm_vcc *vcc) 59 int atm_init_aal0(struct atm_vcc *vcc) 63 { 60 { 64 vcc->push = atm_push_raw; 61 vcc->push = atm_push_raw; 65 vcc->pop = atm_pop_raw; 62 vcc->pop = atm_pop_raw; 66 vcc->push_oam = NULL; 63 vcc->push_oam = NULL; 67 vcc->send = atm_send_aal0; 64 vcc->send = atm_send_aal0; 68 return 0; 65 return 0; 69 } 66 } 70 67 71 int atm_init_aal34(struct atm_vcc *vcc) 68 int atm_init_aal34(struct atm_vcc *vcc) 72 { 69 { 73 vcc->push = atm_push_raw; 70 vcc->push = atm_push_raw; 74 vcc->pop = atm_pop_raw; 71 vcc->pop = atm_pop_raw; 75 vcc->push_oam = NULL; 72 vcc->push_oam = NULL; 76 if (vcc->dev->ops->send_bh) !! 73 vcc->send = vcc->dev->ops->send; 77 vcc->send = vcc->dev->ops->sen << 78 else << 79 vcc->send = vcc->dev->ops->sen << 80 return 0; 74 return 0; 81 } 75 } 82 76 83 int atm_init_aal5(struct atm_vcc *vcc) 77 int atm_init_aal5(struct atm_vcc *vcc) 84 { 78 { 85 vcc->push = atm_push_raw; 79 vcc->push = atm_push_raw; 86 vcc->pop = atm_pop_raw; 80 vcc->pop = atm_pop_raw; 87 vcc->push_oam = NULL; 81 vcc->push_oam = NULL; 88 if (vcc->dev->ops->send_bh) !! 82 vcc->send = vcc->dev->ops->send; 89 vcc->send = vcc->dev->ops->sen << 90 else << 91 vcc->send = vcc->dev->ops->sen << 92 return 0; 83 return 0; 93 } 84 } 94 EXPORT_SYMBOL(atm_init_aal5); 85 EXPORT_SYMBOL(atm_init_aal5); 95 86
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.