aboutsummaryrefslogtreecommitdiffstats
path: root/net/802/fddi.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/802/fddi.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/802/fddi.c')
-rw-r--r--net/802/fddi.c210
1 files changed, 210 insertions, 0 deletions
diff --git a/net/802/fddi.c b/net/802/fddi.c
new file mode 100644
index 000000000000..f9a31a9f70f1
--- /dev/null
+++ b/net/802/fddi.c
@@ -0,0 +1,210 @@
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * FDDI-type device handling.
7 *
8 * Version: @(#)fddi.c 1.0.0 08/12/96
9 *
10 * Authors: Lawrence V. Stefani, <stefani@lkg.dec.com>
11 *
12 * fddi.c is based on previous eth.c and tr.c work by
13 * Ross Biro, <bir7@leland.Stanford.Edu>
14 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
15 * Mark Evans, <evansmp@uhura.aston.ac.uk>
16 * Florian La Roche, <rzsfl@rz.uni-sb.de>
17 * Alan Cox, <gw4pts@gw4pts.ampr.org>
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
23 *
24 * Changes
25 * Alan Cox : New arp/rebuild header
26 * Maciej W. Rozycki : IPv6 support
27 */
28
29#include <linux/config.h>
30#include <linux/module.h>
31#include <asm/system.h>
32#include <linux/types.h>
33#include <linux/kernel.h>
34#include <linux/sched.h>
35#include <linux/string.h>
36#include <linux/mm.h>
37#include <linux/socket.h>
38#include <linux/in.h>
39#include <linux/inet.h>
40#include <linux/netdevice.h>
41#include <linux/fddidevice.h>
42#include <linux/if_ether.h>
43#include <linux/skbuff.h>
44#include <linux/errno.h>
45#include <net/arp.h>
46#include <net/sock.h>
47
48/*
49 * Create the FDDI MAC header for an arbitrary protocol layer
50 *
51 * saddr=NULL means use device source address
52 * daddr=NULL means leave destination address (eg unresolved arp)
53 */
54
55static int fddi_header(struct sk_buff *skb, struct net_device *dev,
56 unsigned short type,
57 void *daddr, void *saddr, unsigned len)
58{
59 int hl = FDDI_K_SNAP_HLEN;
60 struct fddihdr *fddi;
61
62 if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
63 hl=FDDI_K_8022_HLEN-3;
64 fddi = (struct fddihdr *)skb_push(skb, hl);
65 fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF;
66 if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP)
67 {
68 fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP;
69 fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP;
70 fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD;
71 fddi->hdr.llc_snap.oui[0] = 0x00;
72 fddi->hdr.llc_snap.oui[1] = 0x00;
73 fddi->hdr.llc_snap.oui[2] = 0x00;
74 fddi->hdr.llc_snap.ethertype = htons(type);
75 }
76
77 /* Set the source and destination hardware addresses */
78
79 if (saddr != NULL)
80 memcpy(fddi->saddr, saddr, dev->addr_len);
81 else
82 memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
83
84 if (daddr != NULL)
85 {
86 memcpy(fddi->daddr, daddr, dev->addr_len);
87 return(hl);
88 }
89
90 return(-hl);
91}
92
93
94/*
95 * Rebuild the FDDI MAC header. This is called after an ARP
96 * (or in future other address resolution) has completed on
97 * this sk_buff. We now let ARP fill in the other fields.
98 */
99
100static int fddi_rebuild_header(struct sk_buff *skb)
101{
102 struct fddihdr *fddi = (struct fddihdr *)skb->data;
103
104#ifdef CONFIG_INET
105 if (fddi->hdr.llc_snap.ethertype == __constant_htons(ETH_P_IP))
106 /* Try to get ARP to resolve the header and fill destination address */
107 return arp_find(fddi->daddr, skb);
108 else
109#endif
110 {
111 printk("%s: Don't know how to resolve type %02X addresses.\n",
112 skb->dev->name, htons(fddi->hdr.llc_snap.ethertype));
113 return(0);
114 }
115}
116
117
118/*
119 * Determine the packet's protocol ID and fill in skb fields.
120 * This routine is called before an incoming packet is passed
121 * up. It's used to fill in specific skb fields and to set
122 * the proper pointer to the start of packet data (skb->data).
123 */
124
125unsigned short fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
126{
127 struct fddihdr *fddi = (struct fddihdr *)skb->data;
128 unsigned short type;
129
130 /*
131 * Set mac.raw field to point to FC byte, set data field to point
132 * to start of packet data. Assume 802.2 SNAP frames for now.
133 */
134
135 skb->mac.raw = skb->data; /* point to frame control (FC) */
136
137 if(fddi->hdr.llc_8022_1.dsap==0xe0)
138 {
139 skb_pull(skb, FDDI_K_8022_HLEN-3);
140 type = __constant_htons(ETH_P_802_2);
141 }
142 else
143 {
144 skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */
145 type=fddi->hdr.llc_snap.ethertype;
146 }
147
148 /* Set packet type based on destination address and flag settings */
149
150 if (*fddi->daddr & 0x01)
151 {
152 if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
153 skb->pkt_type = PACKET_BROADCAST;
154 else
155 skb->pkt_type = PACKET_MULTICAST;
156 }
157
158 else if (dev->flags & IFF_PROMISC)
159 {
160 if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
161 skb->pkt_type = PACKET_OTHERHOST;
162 }
163
164 /* Assume 802.2 SNAP frames, for now */
165
166 return(type);
167}
168
169EXPORT_SYMBOL(fddi_type_trans);
170
171static int fddi_change_mtu(struct net_device *dev, int new_mtu)
172{
173 if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
174 return(-EINVAL);
175 dev->mtu = new_mtu;
176 return(0);
177}
178
179static void fddi_setup(struct net_device *dev)
180{
181 dev->change_mtu = fddi_change_mtu;
182 dev->hard_header = fddi_header;
183 dev->rebuild_header = fddi_rebuild_header;
184
185 dev->type = ARPHRD_FDDI;
186 dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
187 dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */
188 dev->addr_len = FDDI_K_ALEN;
189 dev->tx_queue_len = 100; /* Long queues on FDDI */
190 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
191
192 memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
193}
194
195/**
196 * alloc_fddidev - Register FDDI device
197 * @sizeof_priv: Size of additional driver-private structure to be allocated
198 * for this FDDI device
199 *
200 * Fill in the fields of the device structure with FDDI-generic values.
201 *
202 * Constructs a new net device, complete with a private data area of
203 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
204 * this private data area.
205 */
206struct net_device *alloc_fddidev(int sizeof_priv)
207{
208 return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup);
209}
210EXPORT_SYMBOL(alloc_fddidev);