2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* SNAP data link layer. Derived from 802.2
|
|
|
|
*
|
2008-10-14 10:01:08 +08:00
|
|
|
* Alan Cox <alan@lxorguk.ukuu.org.uk>,
|
2005-04-17 06:20:36 +08:00
|
|
|
* from the 802.2 layer by Greg Page.
|
|
|
|
* Merged in additions from Greg Page's psnap.c.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/datalink.h>
|
|
|
|
#include <net/llc.h>
|
|
|
|
#include <net/psnap.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/init.h>
|
2008-05-13 03:21:05 +08:00
|
|
|
#include <linux/rculist.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2009-03-20 13:43:14 +08:00
|
|
|
static struct datalink_proto *find_snap_client(const unsigned char *desc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct datalink_proto *proto = NULL, *p;
|
|
|
|
|
2008-07-25 16:45:34 +08:00
|
|
|
list_for_each_entry_rcu(p, &snap_list, node) {
|
2005-04-17 06:20:36 +08:00
|
|
|
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,
|
2005-08-10 10:34:12 +08:00
|
|
|
struct packet_type *pt, struct net_device *orig_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc = 1;
|
|
|
|
struct datalink_proto *proto;
|
|
|
|
static struct packet_type snap_packet_type = {
|
2009-02-01 16:45:17 +08:00
|
|
|
.type = cpu_to_be16(ETH_P_SNAP),
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-08-21 15:06:37 +08:00
|
|
|
if (unlikely(!pskb_may_pull(skb, 5)))
|
|
|
|
goto drop;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rcu_read_lock();
|
2007-04-26 09:04:18 +08:00
|
|
|
proto = find_snap_client(skb_transport_header(skb));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (proto) {
|
|
|
|
/* Pass the frame on. */
|
2007-04-11 12:21:55 +08:00
|
|
|
skb->transport_header += 5;
|
2006-03-21 14:43:56 +08:00
|
|
|
skb_pull_rcsum(skb, 5);
|
2005-08-10 10:34:12 +08:00
|
|
|
rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2007-08-21 15:06:37 +08:00
|
|
|
|
|
|
|
if (unlikely(!proto))
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
2007-08-21 15:06:37 +08:00
|
|
|
|
|
|
|
drop:
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2009-02-22 16:03:19 +08:00
|
|
|
static const char snap_err_msg[] __initconst =
|
2005-04-17 06:20:36 +08:00
|
|
|
KERN_CRIT "SNAP - unable to register with 802.2\n";
|
|
|
|
|
|
|
|
static int __init snap_init(void)
|
|
|
|
{
|
|
|
|
snap_sap = llc_sap_open(0xAA, snap_rcv);
|
2009-02-22 16:03:19 +08:00
|
|
|
if (!snap_sap) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(snap_err_msg);
|
2009-02-22 16:03:19 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(snap_init);
|
|
|
|
|
|
|
|
static void __exit snap_exit(void)
|
|
|
|
{
|
2005-09-22 15:43:05 +08:00
|
|
|
llc_sap_put(snap_sap);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_exit(snap_exit);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register SNAP clients. We don't yet use this for IP.
|
|
|
|
*/
|
2009-03-20 13:43:14 +08:00
|
|
|
struct datalink_proto *register_snap_client(const unsigned char *desc,
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*rcvfunc)(struct sk_buff *,
|
2007-02-09 22:24:24 +08:00
|
|
|
struct net_device *,
|
2005-08-10 10:34:12 +08:00
|
|
|
struct packet_type *,
|
|
|
|
struct net_device *))
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
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) {
|
2009-03-20 13:43:14 +08:00
|
|
|
memcpy(proto->type, desc, 5);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
synchronize_net();
|
|
|
|
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");
|