2 * SNAP data link layer. Derived from 802.2
4 * Alan Cox <Alan.Cox@linux.org>, from the 802.2 layer by Greg Page.
5 * Merged in additions from Greg Page's psnap.c.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
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>
21 #include <linux/init.h>
23 static struct datalink_proto
*snap_list
= NULL
;
24 static struct datalink_proto
*snap_dl
= NULL
; /* 802.2 DL for SNAP */
27 * Find a snap client by matching the 5 bytes.
30 static struct datalink_proto
*find_snap_client(unsigned char *desc
)
32 struct datalink_proto
*proto
;
34 for (proto
= snap_list
; proto
!= NULL
&& memcmp(proto
->type
, desc
, 5) ; proto
= proto
->next
);
39 * A SNAP packet has arrived
42 int snap_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
)
44 static struct packet_type psnap_packet_type
=
47 NULL
, /* All Devices */
53 struct datalink_proto
*proto
;
55 proto
= find_snap_client(skb
->h
.raw
);
65 if (psnap_packet_type
.type
== 0)
66 psnap_packet_type
.type
=htons(ETH_P_SNAP
);
68 return proto
->rcvfunc(skb
, dev
, &psnap_packet_type
);
76 * Put a SNAP header on a frame and pass to 802.2
79 static void snap_datalink_header(struct datalink_proto
*dl
, struct sk_buff
*skb
, unsigned char *dest_node
)
81 memcpy(skb_push(skb
,5),dl
->type
,5);
82 snap_dl
->datalink_header(snap_dl
, skb
, dest_node
);
86 * Set up the SNAP layer
89 EXPORT_SYMBOL(register_snap_client
);
90 EXPORT_SYMBOL(unregister_snap_client
);
92 void __init
snap_proto_init(struct net_proto
*pro
)
94 snap_dl
=register_8022_client(0xAA, snap_rcv
);
96 printk("SNAP - unable to register with 802.2\n");
100 * Register SNAP clients. We don't yet use this for IP.
103 struct datalink_proto
*register_snap_client(unsigned char *desc
, int (*rcvfunc
)(struct sk_buff
*, struct net_device
*, struct packet_type
*))
105 struct datalink_proto
*proto
;
107 if (find_snap_client(desc
) != NULL
)
110 proto
= (struct datalink_proto
*) kmalloc(sizeof(*proto
), GFP_ATOMIC
);
113 memcpy(proto
->type
, desc
,5);
115 proto
->rcvfunc
= rcvfunc
;
116 proto
->header_length
= 5+snap_dl
->header_length
;
117 proto
->datalink_header
= snap_datalink_header
;
118 proto
->string_name
= "SNAP";
119 proto
->next
= snap_list
;
127 * Unregister SNAP clients. Protocols no longer want to play with us ...
130 void unregister_snap_client(unsigned char *desc
)
132 struct datalink_proto
**clients
= &snap_list
;
133 struct datalink_proto
*tmp
;
139 while ((tmp
= *clients
) != NULL
)
141 if (memcmp(tmp
->type
,desc
,5) == 0)
143 *clients
= tmp
->next
;
144 kfree_s(tmp
, sizeof(struct datalink_proto
));
148 clients
= &tmp
->next
;
151 restore_flags(flags
);