blob: b3ba44aab0ee6c9425fd278ebf8e2df1590a6d7a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* net/atm/raw.c - Raw AAL0 and AAL5 transports */
3
4/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5
Joe Perches99824462010-01-26 11:40:00 +00006#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/atmdev.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080010#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/kernel.h>
12#include <linux/skbuff.h>
13#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include "common.h"
17#include "protocols.h"
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20 * SKB == NULL indicates that the link is being closed
21 */
22
Joe Perchesfa61f0c2010-01-26 11:40:15 +000023static void atm_push_raw(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
25 if (skb) {
26 struct sock *sk = sk_atm(vcc);
27
28 skb_queue_tail(&sk->sk_receive_queue, skb);
David S. Miller676d2362014-04-11 16:15:36 -040029 sk->sk_data_ready(sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 }
31}
32
Joe Perchesfa61f0c2010-01-26 11:40:15 +000033static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 struct sock *sk = sk_atm(vcc);
36
Joe Perches99824462010-01-26 11:40:00 +000037 pr_debug("(%d) %d -= %d\n",
David Woodhouse9bbe60a2018-06-16 11:55:44 +010038 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 dev_kfree_skb_any(skb);
41 sk->sk_write_space(sk);
42}
43
Joe Perchesfa61f0c2010-01-26 11:40:15 +000044static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 /*
47 * Note that if vpi/vci are _ANY or _UNSPEC the below will
48 * still work
49 */
50 if (!capable(CAP_NET_ADMIN) &&
Joe Perchesfa61f0c2010-01-26 11:40:15 +000051 (((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))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 kfree_skb(skb);
55 return -EADDRNOTAVAIL;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +090056 }
Joe Perchesfa61f0c2010-01-26 11:40:15 +000057 return vcc->dev->ops->send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060int atm_init_aal0(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 = atm_send_aal0;
66 return 0;
67}
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069int atm_init_aal34(struct atm_vcc *vcc)
70{
71 vcc->push = atm_push_raw;
72 vcc->pop = atm_pop_raw;
73 vcc->push_oam = NULL;
74 vcc->send = vcc->dev->ops->send;
75 return 0;
76}
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078int atm_init_aal5(struct atm_vcc *vcc)
79{
80 vcc->push = atm_push_raw;
81 vcc->pop = atm_pop_raw;
82 vcc->push_oam = NULL;
83 vcc->send = vcc->dev->ops->send;
84 return 0;
85}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086EXPORT_SYMBOL(atm_init_aal5);