Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / net / 802 / p8022.c
blob41a755e88842a67e648e4fab07dc699077b9ea16
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 net_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 net_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 static int __init p8022_init(void)
95 p8022_packet_type.type=htons(ETH_P_802_2);
96 dev_add_pack(&p8022_packet_type);
97 return 0;
100 module_init(p8022_init);
102 struct datalink_proto *register_8022_client(unsigned char type, int (*rcvfunc)(struct sk_buff *, struct net_device *, struct packet_type *))
104 struct datalink_proto *proto;
106 if (find_8022_client(type) != NULL)
107 return NULL;
109 proto = (struct datalink_proto *) kmalloc(sizeof(*proto), GFP_ATOMIC);
110 if (proto != NULL) {
111 proto->type[0] = type;
112 proto->type_len = 1;
113 proto->rcvfunc = rcvfunc;
114 proto->header_length = 3;
115 proto->datalink_header = p8022_datalink_header;
116 proto->string_name = "802.2";
117 proto->next = p8022_list;
118 p8022_list = proto;
121 return proto;
124 void unregister_8022_client(unsigned char type)
126 struct datalink_proto *tmp, **clients = &p8022_list;
127 unsigned long flags;
129 save_flags(flags);
130 cli();
132 while ((tmp = *clients) != NULL)
134 if (tmp->type[0] == type) {
135 *clients = tmp->next;
136 kfree(tmp);
137 break;
138 } else {
139 clients = &tmp->next;
143 restore_flags(flags);