Blame view
net/802/psnap.c
3.27 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 |
/* * SNAP data link layer. Derived from 802.2 * |
113aa838e net: Rationalise ... |
5 |
* Alan Cox <alan@lxorguk.ukuu.org.uk>, |
1da177e4c Linux-2.6.12-rc2 |
6 7 |
* from the 802.2 layer by Greg Page. * Merged in additions from Greg Page's psnap.c. |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 11 12 |
*/ #include <linux/module.h> #include <linux/netdevice.h> #include <linux/skbuff.h> |
5a0e3ad6a include cleanup: ... |
13 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
14 15 16 17 18 19 |
#include <net/datalink.h> #include <net/llc.h> #include <net/psnap.h> #include <linux/mm.h> #include <linux/in.h> #include <linux/init.h> |
82524746c rcu: split list.h... |
20 |
#include <linux/rculist.h> |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 27 28 |
static LIST_HEAD(snap_list); static DEFINE_SPINLOCK(snap_lock); static struct llc_sap *snap_sap; /* * Find a snap client by matching the 5 bytes. */ |
7ca98fa23 snap: use const f... |
29 |
static struct datalink_proto *find_snap_client(const unsigned char *desc) |
1da177e4c Linux-2.6.12-rc2 |
30 |
{ |
1da177e4c Linux-2.6.12-rc2 |
31 |
struct datalink_proto *proto = NULL, *p; |
0a087bf23 net: 802: psnap.c... |
32 |
list_for_each_entry_rcu(p, &snap_list, node, lockdep_is_held(&snap_lock)) { |
1da177e4c Linux-2.6.12-rc2 |
33 34 35 36 37 38 39 40 41 42 43 44 |
if (!memcmp(p->type, desc, 5)) { proto = p; break; } } return proto; } /* * A SNAP packet has arrived */ static int snap_rcv(struct sk_buff *skb, struct net_device *dev, |
f2ccd8fa0 [NET]: Kill skb->... |
45 |
struct packet_type *pt, struct net_device *orig_dev) |
1da177e4c Linux-2.6.12-rc2 |
46 47 48 49 |
{ int rc = 1; struct datalink_proto *proto; static struct packet_type snap_packet_type = { |
09640e636 net: replace uses... |
50 |
.type = cpu_to_be16(ETH_P_SNAP), |
1da177e4c Linux-2.6.12-rc2 |
51 |
}; |
d92a7db71 [SNAP]: Check pac... |
52 53 |
if (unlikely(!pskb_may_pull(skb, 5))) goto drop; |
1da177e4c Linux-2.6.12-rc2 |
54 |
rcu_read_lock(); |
9c70220b7 [SK_BUFF]: Introd... |
55 |
proto = find_snap_client(skb_transport_header(skb)); |
1da177e4c Linux-2.6.12-rc2 |
56 57 |
if (proto) { /* Pass the frame on. */ |
b0e380b1d [SK_BUFF]: unions... |
58 |
skb->transport_header += 5; |
cbb042f9e [NET]: Replace sk... |
59 |
skb_pull_rcsum(skb, 5); |
f2ccd8fa0 [NET]: Kill skb->... |
60 |
rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev); |
1da177e4c Linux-2.6.12-rc2 |
61 |
} |
1da177e4c Linux-2.6.12-rc2 |
62 |
rcu_read_unlock(); |
d92a7db71 [SNAP]: Check pac... |
63 64 65 66 67 |
if (unlikely(!proto)) goto drop; out: |
1da177e4c Linux-2.6.12-rc2 |
68 |
return rc; |
d92a7db71 [SNAP]: Check pac... |
69 70 71 72 |
drop: kfree_skb(skb); goto out; |
1da177e4c Linux-2.6.12-rc2 |
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
} /* * Put a SNAP header on a frame and pass to 802.2 */ static int snap_request(struct datalink_proto *dl, struct sk_buff *skb, u8 *dest) { memcpy(skb_push(skb, 5), dl->type, 5); llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->laddr.lsap); return 0; } /* * Set up the SNAP layer */ EXPORT_SYMBOL(register_snap_client); EXPORT_SYMBOL(unregister_snap_client); |
0117cfabe snap: handle regi... |
91 |
static const char snap_err_msg[] __initconst = |
1da177e4c Linux-2.6.12-rc2 |
92 93 94 95 96 97 |
KERN_CRIT "SNAP - unable to register with 802.2 "; static int __init snap_init(void) { snap_sap = llc_sap_open(0xAA, snap_rcv); |
0117cfabe snap: handle regi... |
98 |
if (!snap_sap) { |
1da177e4c Linux-2.6.12-rc2 |
99 |
printk(snap_err_msg); |
0117cfabe snap: handle regi... |
100 101 |
return -EBUSY; } |
1da177e4c Linux-2.6.12-rc2 |
102 103 104 105 106 107 108 109 |
return 0; } module_init(snap_init); static void __exit snap_exit(void) { |
6e2144b76 [LLC]: Use refcou... |
110 |
llc_sap_put(snap_sap); |
1da177e4c Linux-2.6.12-rc2 |
111 112 113 114 115 116 117 118 |
} module_exit(snap_exit); /* * Register SNAP clients. We don't yet use this for IP. */ |
7ca98fa23 snap: use const f... |
119 |
struct datalink_proto *register_snap_client(const unsigned char *desc, |
1da177e4c Linux-2.6.12-rc2 |
120 |
int (*rcvfunc)(struct sk_buff *, |
9afa0949e [NET] 802: Fix wh... |
121 |
struct net_device *, |
f2ccd8fa0 [NET]: Kill skb->... |
122 123 |
struct packet_type *, struct net_device *)) |
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 128 129 130 131 132 133 |
{ struct datalink_proto *proto = NULL; spin_lock_bh(&snap_lock); if (find_snap_client(desc)) goto out; proto = kmalloc(sizeof(*proto), GFP_ATOMIC); if (proto) { |
7ca98fa23 snap: use const f... |
134 |
memcpy(proto->type, desc, 5); |
1da177e4c Linux-2.6.12-rc2 |
135 136 137 138 139 140 141 |
proto->rcvfunc = rcvfunc; proto->header_length = 5 + 3; /* snap + 802.2 */ proto->request = snap_request; list_add_rcu(&proto->node, &snap_list); } out: spin_unlock_bh(&snap_lock); |
1da177e4c Linux-2.6.12-rc2 |
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
return proto; } /* * Unregister SNAP clients. Protocols no longer want to play with us ... */ void unregister_snap_client(struct datalink_proto *proto) { spin_lock_bh(&snap_lock); list_del_rcu(&proto->node); spin_unlock_bh(&snap_lock); synchronize_net(); kfree(proto); } MODULE_LICENSE("GPL"); |