This source file includes following definitions.
- find_8022_client
- p8022_rcv
- p8022_datalink_header
- p8022_proto_init
- register_8022_client
1 #include <linux/netdevice.h>
2 #include <linux/skbuff.h>
3 #include "datalink.h"
4 #include <linux/mm.h>
5 #include <linux/in.h>
6
7 static struct datalink_proto *p8022_list = NULL;
8
9 static struct datalink_proto *
10 find_8022_client(unsigned char type)
11 {
12 struct datalink_proto *proto;
13
14 for (proto = p8022_list;
15 ((proto != NULL) && (*(proto->type) != type));
16 proto = proto->next)
17 ;
18
19 return proto;
20 }
21
22 int
23 p8022_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
24 {
25 struct datalink_proto *proto;
26
27 proto = find_8022_client(*(skb->h.raw));
28 if (proto != NULL) {
29 skb->h.raw += 3;
30 return proto->rcvfunc(skb, dev, pt);
31 }
32
33 skb->sk = NULL;
34 kfree_skb(skb, FREE_READ);
35 return 0;
36 }
37
38 static void
39 p8022_datalink_header(struct datalink_proto *dl,
40 struct sk_buff *skb, unsigned char *dest_node)
41 {
42 struct device *dev = skb->dev;
43 unsigned long len = skb->len;
44 unsigned long hard_len = dev->hard_header_len;
45 unsigned char *rawp;
46
47 dev->hard_header(skb->data, dev, len - hard_len,
48 dest_node, NULL, len - hard_len, skb);
49 rawp = skb->data + hard_len;
50 *rawp = dl->type[0];
51 rawp++;
52 *rawp = dl->type[0];
53 rawp++;
54 *rawp = 0x03;
55 rawp++;
56 skb->h.raw = rawp;
57 }
58
59 static struct packet_type p8022_packet_type =
60 {
61 0,
62 0,
63 p8022_rcv,
64 NULL,
65 NULL,
66 };
67
68
69 void p8022_proto_init(struct net_proto *pro)
70 {
71 p8022_packet_type.type=htons(ETH_P_802_2);
72 dev_add_pack(&p8022_packet_type);
73 }
74
75 struct datalink_proto *
76 register_8022_client(unsigned char type, int (*rcvfunc)(struct sk_buff *, struct device *, struct packet_type *))
77 {
78 struct datalink_proto *proto;
79
80 if (find_8022_client(type) != NULL)
81 return NULL;
82
83 proto = (struct datalink_proto *) kmalloc(sizeof(*proto), GFP_ATOMIC);
84 if (proto != NULL) {
85 proto->type[0] = type;
86 proto->type_len = 1;
87 proto->rcvfunc = rcvfunc;
88 proto->header_length = 3;
89 proto->datalink_header = p8022_datalink_header;
90
91 proto->next = p8022_list;
92 p8022_list = proto;
93 }
94
95 return proto;
96 }
97