1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/module.h>
30#include <linux/types.h>
31#include <linux/kernel.h>
32#include <linux/string.h>
33#include <linux/mm.h>
34#include <linux/socket.h>
35#include <linux/in.h>
36#include <linux/inet.h>
37#include <linux/netdevice.h>
38#include <linux/fddidevice.h>
39#include <linux/if_ether.h>
40#include <linux/skbuff.h>
41#include <linux/errno.h>
42#include <net/arp.h>
43#include <net/sock.h>
44
45
46
47
48
49
50
51
52static int fddi_header(struct sk_buff *skb, struct net_device *dev,
53 unsigned short type,
54 const void *daddr, const void *saddr, unsigned int len)
55{
56 int hl = FDDI_K_SNAP_HLEN;
57 struct fddihdr *fddi;
58
59 if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
60 hl=FDDI_K_8022_HLEN-3;
61 fddi = (struct fddihdr *)skb_push(skb, hl);
62 fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF;
63 if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP)
64 {
65 fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP;
66 fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP;
67 fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD;
68 fddi->hdr.llc_snap.oui[0] = 0x00;
69 fddi->hdr.llc_snap.oui[1] = 0x00;
70 fddi->hdr.llc_snap.oui[2] = 0x00;
71 fddi->hdr.llc_snap.ethertype = htons(type);
72 }
73
74
75
76 if (saddr != NULL)
77 memcpy(fddi->saddr, saddr, dev->addr_len);
78 else
79 memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
80
81 if (daddr != NULL)
82 {
83 memcpy(fddi->daddr, daddr, dev->addr_len);
84 return hl;
85 }
86
87 return -hl;
88}
89
90
91
92
93
94
95
96
97static int fddi_rebuild_header(struct sk_buff *skb)
98{
99 struct fddihdr *fddi = (struct fddihdr *)skb->data;
100
101#ifdef CONFIG_INET
102 if (fddi->hdr.llc_snap.ethertype == htons(ETH_P_IP))
103
104 return arp_find(fddi->daddr, skb);
105 else
106#endif
107 {
108 printk("%s: Don't know how to resolve type %04X addresses.\n",
109 skb->dev->name, ntohs(fddi->hdr.llc_snap.ethertype));
110 return 0;
111 }
112}
113
114
115
116
117
118
119
120
121
122__be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
123{
124 struct fddihdr *fddi = (struct fddihdr *)skb->data;
125 __be16 type;
126
127
128
129
130
131
132 skb->dev = dev;
133 skb_reset_mac_header(skb);
134
135 if(fddi->hdr.llc_8022_1.dsap==0xe0)
136 {
137 skb_pull(skb, FDDI_K_8022_HLEN-3);
138 type = htons(ETH_P_802_2);
139 }
140 else
141 {
142 skb_pull(skb, FDDI_K_SNAP_HLEN);
143 type=fddi->hdr.llc_snap.ethertype;
144 }
145
146
147
148 if (*fddi->daddr & 0x01)
149 {
150 if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
151 skb->pkt_type = PACKET_BROADCAST;
152 else
153 skb->pkt_type = PACKET_MULTICAST;
154 }
155
156 else if (dev->flags & IFF_PROMISC)
157 {
158 if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
159 skb->pkt_type = PACKET_OTHERHOST;
160 }
161
162
163
164 return type;
165}
166
167EXPORT_SYMBOL(fddi_type_trans);
168
169int fddi_change_mtu(struct net_device *dev, int new_mtu)
170{
171 if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
172 return -EINVAL;
173 dev->mtu = new_mtu;
174 return 0;
175}
176EXPORT_SYMBOL(fddi_change_mtu);
177
178static const struct header_ops fddi_header_ops = {
179 .create = fddi_header,
180 .rebuild = fddi_rebuild_header,
181};
182
183
184static void fddi_setup(struct net_device *dev)
185{
186 dev->header_ops = &fddi_header_ops;
187 dev->type = ARPHRD_FDDI;
188 dev->hard_header_len = FDDI_K_SNAP_HLEN+3;
189 dev->mtu = FDDI_K_SNAP_DLEN;
190 dev->addr_len = FDDI_K_ALEN;
191 dev->tx_queue_len = 100;
192 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
193
194 memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
195}
196
197
198
199
200
201
202
203
204
205
206
207
208struct net_device *alloc_fddidev(int sizeof_priv)
209{
210 return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup);
211}
212EXPORT_SYMBOL(alloc_fddidev);
213
214MODULE_LICENSE("GPL");
215