]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | |
02c30a84 | 13 | * Ross Biro |
1da177e4 LT |
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> | |
9afa0949 | 18 | * |
1da177e4 LT |
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 | */ | |
9afa0949 | 28 | |
1da177e4 LT |
29 | #include <linux/module.h> |
30 | #include <asm/system.h> | |
31 | #include <linux/types.h> | |
32 | #include <linux/kernel.h> | |
1da177e4 LT |
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 | * Create the FDDI MAC header for an arbitrary protocol layer | |
48 | * | |
49 | * saddr=NULL means use device source address | |
50 | * daddr=NULL means leave destination address (eg unresolved arp) | |
51 | */ | |
52 | ||
53 | static int fddi_header(struct sk_buff *skb, struct net_device *dev, | |
54 | unsigned short type, | |
55 | void *daddr, void *saddr, unsigned len) | |
56 | { | |
57 | int hl = FDDI_K_SNAP_HLEN; | |
58 | struct fddihdr *fddi; | |
9afa0949 | 59 | |
1da177e4 LT |
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 | /* Set the source and destination hardware addresses */ | |
9afa0949 | 76 | |
1da177e4 LT |
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 | * Rebuild the FDDI MAC header. This is called after an ARP | |
94 | * (or in future other address resolution) has completed on | |
95 | * this sk_buff. We now let ARP fill in the other fields. | |
96 | */ | |
9afa0949 | 97 | |
1da177e4 LT |
98 | static int fddi_rebuild_header(struct sk_buff *skb) |
99 | { | |
100 | struct fddihdr *fddi = (struct fddihdr *)skb->data; | |
101 | ||
102 | #ifdef CONFIG_INET | |
2953fd24 | 103 | if (fddi->hdr.llc_snap.ethertype == htons(ETH_P_IP)) |
1da177e4 LT |
104 | /* Try to get ARP to resolve the header and fill destination address */ |
105 | return arp_find(fddi->daddr, skb); | |
106 | else | |
9afa0949 | 107 | #endif |
1da177e4 | 108 | { |
57bf1451 AD |
109 | printk("%s: Don't know how to resolve type %04X addresses.\n", |
110 | skb->dev->name, ntohs(fddi->hdr.llc_snap.ethertype)); | |
1da177e4 LT |
111 | return(0); |
112 | } | |
113 | } | |
114 | ||
115 | ||
116 | /* | |
117 | * Determine the packet's protocol ID and fill in skb fields. | |
118 | * This routine is called before an incoming packet is passed | |
119 | * up. It's used to fill in specific skb fields and to set | |
120 | * the proper pointer to the start of packet data (skb->data). | |
121 | */ | |
9afa0949 | 122 | |
ab611487 | 123 | __be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev) |
1da177e4 LT |
124 | { |
125 | struct fddihdr *fddi = (struct fddihdr *)skb->data; | |
ab611487 | 126 | __be16 type; |
9afa0949 | 127 | |
1da177e4 LT |
128 | /* |
129 | * Set mac.raw field to point to FC byte, set data field to point | |
130 | * to start of packet data. Assume 802.2 SNAP frames for now. | |
131 | */ | |
132 | ||
0a4f23fb | 133 | skb->dev = dev; |
1da177e4 | 134 | skb->mac.raw = skb->data; /* point to frame control (FC) */ |
9afa0949 | 135 | |
1da177e4 LT |
136 | if(fddi->hdr.llc_8022_1.dsap==0xe0) |
137 | { | |
138 | skb_pull(skb, FDDI_K_8022_HLEN-3); | |
2953fd24 | 139 | type = htons(ETH_P_802_2); |
1da177e4 LT |
140 | } |
141 | else | |
142 | { | |
143 | skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */ | |
144 | type=fddi->hdr.llc_snap.ethertype; | |
145 | } | |
9afa0949 | 146 | |
1da177e4 | 147 | /* Set packet type based on destination address and flag settings */ |
9afa0949 | 148 | |
1da177e4 LT |
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 | } | |
9afa0949 | 156 | |
1da177e4 LT |
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 | /* Assume 802.2 SNAP frames, for now */ | |
164 | ||
165 | return(type); | |
166 | } | |
167 | ||
168 | EXPORT_SYMBOL(fddi_type_trans); | |
169 | ||
170 | static int 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 | } | |
177 | ||
178 | static void fddi_setup(struct net_device *dev) | |
179 | { | |
180 | dev->change_mtu = fddi_change_mtu; | |
181 | dev->hard_header = fddi_header; | |
182 | dev->rebuild_header = fddi_rebuild_header; | |
183 | ||
184 | dev->type = ARPHRD_FDDI; | |
185 | dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */ | |
186 | dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */ | |
187 | dev->addr_len = FDDI_K_ALEN; | |
188 | dev->tx_queue_len = 100; /* Long queues on FDDI */ | |
189 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; | |
9afa0949 | 190 | |
1da177e4 LT |
191 | memset(dev->broadcast, 0xFF, FDDI_K_ALEN); |
192 | } | |
193 | ||
194 | /** | |
195 | * alloc_fddidev - Register FDDI device | |
196 | * @sizeof_priv: Size of additional driver-private structure to be allocated | |
197 | * for this FDDI device | |
198 | * | |
199 | * Fill in the fields of the device structure with FDDI-generic values. | |
200 | * | |
201 | * Constructs a new net device, complete with a private data area of | |
202 | * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for | |
203 | * this private data area. | |
204 | */ | |
205 | struct net_device *alloc_fddidev(int sizeof_priv) | |
206 | { | |
207 | return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup); | |
208 | } | |
209 | EXPORT_SYMBOL(alloc_fddidev); |