2 * SNAP data link layer. Derived from 802.2
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.
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 <net/datalink.h>
19 #include <net/psnap.h>
22 #include <linux/init.h>
23 #include <linux/rculist.h>
25 static LIST_HEAD(snap_list
);
26 static DEFINE_SPINLOCK(snap_lock
);
27 static struct llc_sap
*snap_sap
;
30 * Find a snap client by matching the 5 bytes.
32 static struct datalink_proto
*find_snap_client(unsigned char *desc
)
34 struct datalink_proto
*proto
= NULL
, *p
;
36 list_for_each_entry_rcu(p
, &snap_list
, node
) {
37 if (!memcmp(p
->type
, desc
, 5)) {
46 * A SNAP packet has arrived
48 static int snap_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
49 struct packet_type
*pt
, struct net_device
*orig_dev
)
52 struct datalink_proto
*proto
;
53 static struct packet_type snap_packet_type
= {
54 .type
= __constant_htons(ETH_P_SNAP
),
57 if (unlikely(!pskb_may_pull(skb
, 5)))
61 proto
= find_snap_client(skb_transport_header(skb
));
63 /* Pass the frame on. */
64 skb
->transport_header
+= 5;
65 skb_pull_rcsum(skb
, 5);
66 rc
= proto
->rcvfunc(skb
, dev
, &snap_packet_type
, orig_dev
);
82 * Put a SNAP header on a frame and pass to 802.2
84 static int snap_request(struct datalink_proto
*dl
,
85 struct sk_buff
*skb
, u8
*dest
)
87 memcpy(skb_push(skb
, 5), dl
->type
, 5);
88 llc_build_and_send_ui_pkt(snap_sap
, skb
, dest
, snap_sap
->laddr
.lsap
);
93 * Set up the SNAP layer
95 EXPORT_SYMBOL(register_snap_client
);
96 EXPORT_SYMBOL(unregister_snap_client
);
98 static char snap_err_msg
[] __initdata
=
99 KERN_CRIT
"SNAP - unable to register with 802.2\n";
101 static int __init
snap_init(void)
103 snap_sap
= llc_sap_open(0xAA, snap_rcv
);
106 printk(snap_err_msg
);
111 module_init(snap_init
);
113 static void __exit
snap_exit(void)
115 llc_sap_put(snap_sap
);
118 module_exit(snap_exit
);
122 * Register SNAP clients. We don't yet use this for IP.
124 struct datalink_proto
*register_snap_client(unsigned char *desc
,
125 int (*rcvfunc
)(struct sk_buff
*,
127 struct packet_type
*,
128 struct net_device
*))
130 struct datalink_proto
*proto
= NULL
;
132 spin_lock_bh(&snap_lock
);
134 if (find_snap_client(desc
))
137 proto
= kmalloc(sizeof(*proto
), GFP_ATOMIC
);
139 memcpy(proto
->type
, desc
,5);
140 proto
->rcvfunc
= rcvfunc
;
141 proto
->header_length
= 5 + 3; /* snap + 802.2 */
142 proto
->request
= snap_request
;
143 list_add_rcu(&proto
->node
, &snap_list
);
146 spin_unlock_bh(&snap_lock
);
153 * Unregister SNAP clients. Protocols no longer want to play with us ...
155 void unregister_snap_client(struct datalink_proto
*proto
)
157 spin_lock_bh(&snap_lock
);
158 list_del_rcu(&proto
->node
);
159 spin_unlock_bh(&snap_lock
);
166 MODULE_LICENSE("GPL");