rcu: split list.h and move rcu-protected lists into rculist.h
[deliverable/linux.git] / net / 802 / psnap.c
CommitLineData
1da177e4
LT
1/*
2 * SNAP data link layer. Derived from 802.2
3 *
4 * Alan Cox <Alan.Cox@linux.org>,
5 * from the 802.2 layer by Greg Page.
6 * Merged in additions from Greg Page's psnap.c.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/netdevice.h>
16#include <linux/skbuff.h>
17#include <net/datalink.h>
18#include <net/llc.h>
19#include <net/psnap.h>
20#include <linux/mm.h>
21#include <linux/in.h>
22#include <linux/init.h>
82524746 23#include <linux/rculist.h>
1da177e4
LT
24
25static LIST_HEAD(snap_list);
26static DEFINE_SPINLOCK(snap_lock);
27static struct llc_sap *snap_sap;
28
29/*
30 * Find a snap client by matching the 5 bytes.
31 */
32static struct datalink_proto *find_snap_client(unsigned char *desc)
33{
34 struct list_head *entry;
35 struct datalink_proto *proto = NULL, *p;
36
37 list_for_each_rcu(entry, &snap_list) {
38 p = list_entry(entry, struct datalink_proto, node);
39 if (!memcmp(p->type, desc, 5)) {
40 proto = p;
41 break;
42 }
43 }
44 return proto;
45}
46
47/*
48 * A SNAP packet has arrived
49 */
50static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
f2ccd8fa 51 struct packet_type *pt, struct net_device *orig_dev)
1da177e4
LT
52{
53 int rc = 1;
54 struct datalink_proto *proto;
55 static struct packet_type snap_packet_type = {
56 .type = __constant_htons(ETH_P_SNAP),
57 };
58
d92a7db7
HX
59 if (unlikely(!pskb_may_pull(skb, 5)))
60 goto drop;
61
1da177e4 62 rcu_read_lock();
9c70220b 63 proto = find_snap_client(skb_transport_header(skb));
1da177e4
LT
64 if (proto) {
65 /* Pass the frame on. */
b0e380b1 66 skb->transport_header += 5;
cbb042f9 67 skb_pull_rcsum(skb, 5);
f2ccd8fa 68 rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev);
1da177e4 69 }
1da177e4 70 rcu_read_unlock();
d92a7db7
HX
71
72 if (unlikely(!proto))
73 goto drop;
74
75out:
1da177e4 76 return rc;
d92a7db7
HX
77
78drop:
79 kfree_skb(skb);
80 goto out;
1da177e4
LT
81}
82
83/*
84 * Put a SNAP header on a frame and pass to 802.2
85 */
86static int snap_request(struct datalink_proto *dl,
87 struct sk_buff *skb, u8 *dest)
88{
89 memcpy(skb_push(skb, 5), dl->type, 5);
90 llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->laddr.lsap);
91 return 0;
92}
93
94/*
95 * Set up the SNAP layer
96 */
97EXPORT_SYMBOL(register_snap_client);
98EXPORT_SYMBOL(unregister_snap_client);
99
100static char snap_err_msg[] __initdata =
101 KERN_CRIT "SNAP - unable to register with 802.2\n";
102
103static int __init snap_init(void)
104{
105 snap_sap = llc_sap_open(0xAA, snap_rcv);
106
107 if (!snap_sap)
108 printk(snap_err_msg);
109
110 return 0;
111}
112
113module_init(snap_init);
114
115static void __exit snap_exit(void)
116{
6e2144b7 117 llc_sap_put(snap_sap);
1da177e4
LT
118}
119
120module_exit(snap_exit);
121
122
123/*
124 * Register SNAP clients. We don't yet use this for IP.
125 */
126struct datalink_proto *register_snap_client(unsigned char *desc,
127 int (*rcvfunc)(struct sk_buff *,
9afa0949 128 struct net_device *,
f2ccd8fa
DM
129 struct packet_type *,
130 struct net_device *))
1da177e4
LT
131{
132 struct datalink_proto *proto = NULL;
133
134 spin_lock_bh(&snap_lock);
135
136 if (find_snap_client(desc))
137 goto out;
138
139 proto = kmalloc(sizeof(*proto), GFP_ATOMIC);
140 if (proto) {
141 memcpy(proto->type, desc,5);
142 proto->rcvfunc = rcvfunc;
143 proto->header_length = 5 + 3; /* snap + 802.2 */
144 proto->request = snap_request;
145 list_add_rcu(&proto->node, &snap_list);
146 }
147out:
148 spin_unlock_bh(&snap_lock);
149
150 synchronize_net();
151 return proto;
152}
153
154/*
155 * Unregister SNAP clients. Protocols no longer want to play with us ...
156 */
157void unregister_snap_client(struct datalink_proto *proto)
158{
159 spin_lock_bh(&snap_lock);
160 list_del_rcu(&proto->node);
161 spin_unlock_bh(&snap_lock);
162
163 synchronize_net();
164
165 kfree(proto);
166}
167
168MODULE_LICENSE("GPL");
This page took 0.448133 seconds and 5 git commands to generate.