This source file includes following definitions.
- find_snap_client
- snap_rcv
- snap_datalink_header
- snap_proto_init
- register_snap_client
- unregister_snap_client
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/skbuff.h>
16 #include <net/datalink.h>
17 #include <net/p8022.h>
18 #include <net/psnap.h>
19 #include <linux/mm.h>
20 #include <linux/in.h>
21
22 static struct datalink_proto *snap_list = NULL;
23 static struct datalink_proto *snap_dl = NULL;
24
25
26
27
28
29 static struct datalink_proto *find_snap_client(unsigned char *desc)
30 {
31 struct datalink_proto *proto;
32
33 for (proto = snap_list; proto != NULL && memcmp(proto->type, desc, 5) ; proto = proto->next);
34 return proto;
35 }
36
37
38
39
40
41 int snap_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
42 {
43 static struct packet_type psnap_packet_type =
44 {
45 0,
46 NULL,
47 snap_rcv,
48 NULL,
49 NULL,
50 };
51
52 struct datalink_proto *proto;
53
54 proto = find_snap_client(skb->h.raw);
55 if (proto != NULL)
56 {
57
58
59
60
61 skb->h.raw += 5;
62 skb_pull(skb,5);
63 if (psnap_packet_type.type == 0)
64 psnap_packet_type.type=htons(ETH_P_SNAP);
65 return proto->rcvfunc(skb, dev, &psnap_packet_type);
66 }
67 skb->sk = NULL;
68 kfree_skb(skb, FREE_READ);
69 return 0;
70 }
71
72
73
74
75
76 static void snap_datalink_header(struct datalink_proto *dl, struct sk_buff *skb, unsigned char *dest_node)
77 {
78 memcpy(skb_push(skb,5),dl->type,5);
79 snap_dl->datalink_header(snap_dl, skb, dest_node);
80 }
81
82
83
84
85
86 static struct symbol_table snap_proto_syms = {
87 #include <linux/symtab_begin.h>
88 X(register_snap_client),
89 X(unregister_snap_client),
90 #include <linux/symtab_end.h>
91 };
92
93 void snap_proto_init(struct net_proto *pro)
94 {
95 snap_dl=register_8022_client(0xAA, snap_rcv);
96 if(snap_dl==NULL)
97 printk("SNAP - unable to register with 802.2\n");
98 register_symtab(&snap_proto_syms);
99 }
100
101
102
103
104
105 struct datalink_proto *register_snap_client(unsigned char *desc, int (*rcvfunc)(struct sk_buff *, struct device *, struct packet_type *))
106 {
107 struct datalink_proto *proto;
108
109 if (find_snap_client(desc) != NULL)
110 return NULL;
111
112 proto = (struct datalink_proto *) kmalloc(sizeof(*proto), GFP_ATOMIC);
113 if (proto != NULL)
114 {
115 memcpy(proto->type, desc,5);
116 proto->type_len = 5;
117 proto->rcvfunc = rcvfunc;
118 proto->header_length = 5+snap_dl->header_length;
119 proto->datalink_header = snap_datalink_header;
120 proto->string_name = "SNAP";
121 proto->next = snap_list;
122 snap_list = proto;
123 }
124
125 return proto;
126 }
127
128
129
130
131
132 void unregister_snap_client(unsigned char *desc)
133 {
134 struct datalink_proto **clients = &snap_list;
135 struct datalink_proto *tmp;
136 unsigned long flags;
137
138 save_flags(flags);
139 cli();
140
141 while ((tmp = *clients) != NULL)
142 {
143 if (memcmp(tmp->type,desc,5) == 0)
144 {
145 *clients = tmp->next;
146 kfree_s(tmp, sizeof(struct datalink_proto));
147 break;
148 }
149 else
150 clients = &tmp->next;
151 }
152
153 restore_flags(flags);
154 }
155