2 * SNAP data link layer. Derived from 802.2
4 * Alan Cox <alan@lxorguk.ukuu.org.uk>,
5 * from the 802.2 layer by Greg Page.
6 * Merged in additions from Greg Page's psnap.c.
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.
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/skbuff.h>
17 #include <linux/slab.h>
18 #include <net/datalink.h>
20 #include <net/psnap.h>
23 #include <linux/init.h>
24 #include <linux/rculist.h>
26 static LIST_HEAD(snap_list);
27 static DEFINE_SPINLOCK(snap_lock);
28 static struct llc_sap *snap_sap;
31 * Find a snap client by matching the 5 bytes.
33 static struct datalink_proto *find_snap_client(const unsigned char *desc)
35 struct datalink_proto *proto = NULL, *p;
37 list_for_each_entry_rcu(p, &snap_list, node) {
38 if (!memcmp(p->type, desc, 5)) {
47 * A SNAP packet has arrived
49 static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
50 struct packet_type *pt, struct net_device *orig_dev)
53 struct datalink_proto *proto;
54 static struct packet_type snap_packet_type = {
55 .type = cpu_to_be16(ETH_P_SNAP),
58 if (unlikely(!pskb_may_pull(skb, 5)))
62 proto = find_snap_client(skb_transport_header(skb));
64 /* Pass the frame on. */
65 skb->transport_header += 5;
66 skb_pull_rcsum(skb, 5);
67 rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev);
83 * Put a SNAP header on a frame and pass to 802.2
85 static int snap_request(struct datalink_proto *dl,
86 struct sk_buff *skb, u8 *dest)
88 memcpy(skb_push(skb, 5), dl->type, 5);
89 llc_build_and_send_ui_pkt(snap_sap, skb, dest, snap_sap->laddr.lsap);
94 * Set up the SNAP layer
96 EXPORT_SYMBOL(register_snap_client);
97 EXPORT_SYMBOL(unregister_snap_client);
99 static const char snap_err_msg[] __initconst =
100 KERN_CRIT "SNAP - unable to register with 802.2\n";
102 static int __init snap_init(void)
104 snap_sap = llc_sap_open(0xAA, snap_rcv);
106 printk(snap_err_msg);
113 module_init(snap_init);
115 static void __exit snap_exit(void)
117 llc_sap_put(snap_sap);
120 module_exit(snap_exit);
124 * Register SNAP clients. We don't yet use this for IP.
126 struct datalink_proto *register_snap_client(const unsigned char *desc,
127 int (*rcvfunc)(struct sk_buff *,
129 struct packet_type *,
130 struct net_device *))
132 struct datalink_proto *proto = NULL;
134 spin_lock_bh(&snap_lock);
136 if (find_snap_client(desc))
139 proto = kmalloc(sizeof(*proto), GFP_ATOMIC);
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);
148 spin_unlock_bh(&snap_lock);
155 * Unregister SNAP clients. Protocols no longer want to play with us ...
157 void unregister_snap_client(struct datalink_proto *proto)
159 spin_lock_bh(&snap_lock);
160 list_del_rcu(&proto->node);
161 spin_unlock_bh(&snap_lock);
168 MODULE_LICENSE("GPL");