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