Import 2.3.10pre5
[davej-history.git] / net / 802 / p8022.c
blob70bc2162cd78148a3f48fd4134e2e08b1cdfd791
1 /*
2 * NET3: Support for 802.2 demultiplexing off Ethernet (Token ring
3 * is kept separate see p8022tr.c)
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Demultiplex 802.2 encoded protocols. We match the entry by the
10 * SSAP/DSAP pair and then deliver to the registered datalink that
11 * matches. The control byte is ignored and handling of such items
12 * is up to the routine passed the frame.
14 * Unlike the 802.3 datalink we have a list of 802.2 entries as there
15 * are multiple protocols to demux. The list is currently short (3 or
16 * 4 entries at most). The current demux assumes this.
19 #include <linux/module.h>
20 #include <linux/netdevice.h>
21 #include <linux/skbuff.h>
22 #include <net/datalink.h>
23 #include <linux/mm.h>
24 #include <linux/in.h>
25 #include <linux/init.h>
26 #include <net/p8022.h>
28 static struct datalink_proto *p8022_list = NULL;
31 * We don't handle the loopback SAP stuff, the extended
32 * 802.2 command set, multicast SAP identifiers and non UI
33 * frames. We have the absolute minimum needed for IPX,
34 * IP and Appletalk phase 2. See the llc_* routines for
35 * support libraries if your protocol needs these.
38 static struct datalink_proto *find_8022_client(unsigned char type)
40 struct datalink_proto *proto;
42 for (proto = p8022_list;
43 ((proto != NULL) && (*(proto->type) != type));
44 proto = proto->next)
47 return proto;
50 int p8022_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
52 struct datalink_proto *proto;
54 proto = find_8022_client(*(skb->h.raw));
55 if (proto != NULL)
57 skb->h.raw += 3;
58 skb->nh.raw += 3;
59 skb_pull(skb,3);
60 return proto->rcvfunc(skb, dev, pt);
63 skb->sk = NULL;
64 kfree_skb(skb);
65 return 0;
68 static void p8022_datalink_header(struct datalink_proto *dl,
69 struct sk_buff *skb, unsigned char *dest_node)
71 struct device *dev = skb->dev;
72 unsigned char *rawp;
74 rawp = skb_push(skb,3);
75 *rawp++ = dl->type[0];
76 *rawp++ = dl->type[0];
77 *rawp = 0x03; /* UI */
78 dev->hard_header(skb, dev, ETH_P_802_3, dest_node, NULL, skb->len);
81 static struct packet_type p8022_packet_type =
83 0, /* MUTTER ntohs(ETH_P_8022),*/
84 NULL, /* All devices */
85 p8022_rcv,
86 NULL,
87 NULL,
90 EXPORT_SYMBOL(register_8022_client);
91 EXPORT_SYMBOL(unregister_8022_client);
93 __initfunc(void p8022_proto_init(struct net_proto *pro))
95 p8022_packet_type.type=htons(ETH_P_802_2);
96 dev_add_pack(&p8022_packet_type);
99 struct datalink_proto *register_8022_client(unsigned char type, int (*rcvfunc)(struct sk_buff *, struct device *, struct packet_type *))
101 struct datalink_proto *proto;
103 if (find_8022_client(type) != NULL)
104 return NULL;
106 proto = (struct datalink_proto *) kmalloc(sizeof(*proto), GFP_ATOMIC);
107 if (proto != NULL) {
108 proto->type[0] = type;
109 proto->type_len = 1;
110 proto->rcvfunc = rcvfunc;
111 proto->header_length = 3;
112 proto->datalink_header = p8022_datalink_header;
113 proto->string_name = "802.2";
114 proto->next = p8022_list;
115 p8022_list = proto;
118 return proto;
121 void unregister_8022_client(unsigned char type)
123 struct datalink_proto *tmp, **clients = &p8022_list;
124 unsigned long flags;
126 save_flags(flags);
127 cli();
129 while ((tmp = *clients) != NULL)
131 if (tmp->type[0] == type) {
132 *clients = tmp->next;
133 kfree_s(tmp, sizeof(struct datalink_proto));
134 break;
135 } else {
136 clients = &tmp->next;
140 restore_flags(flags);