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