Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Jesper Juhl | 02c30a8 | 2005-05-05 16:16:16 -0700 | [diff] [blame] | 13 | * Ross Biro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
| 31 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * Create the FDDI MAC header for an arbitrary protocol layer |
| 47 | * |
| 48 | * saddr=NULL means use device source address |
| 49 | * daddr=NULL means leave destination address (eg unresolved arp) |
| 50 | */ |
| 51 | |
| 52 | static int fddi_header(struct sk_buff *skb, struct net_device *dev, |
| 53 | unsigned short type, |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 54 | const void *daddr, const void *saddr, unsigned len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
| 56 | int hl = FDDI_K_SNAP_HLEN; |
| 57 | struct fddihdr *fddi; |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* Set the source and destination hardware addresses */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 84 | return hl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 87 | return -hl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Rebuild the FDDI MAC header. This is called after an ARP |
| 93 | * (or in future other address resolution) has completed on |
| 94 | * this sk_buff. We now let ARP fill in the other fields. |
| 95 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static int fddi_rebuild_header(struct sk_buff *skb) |
| 98 | { |
| 99 | struct fddihdr *fddi = (struct fddihdr *)skb->data; |
| 100 | |
| 101 | #ifdef CONFIG_INET |
YOSHIFUJI Hideaki | 2953fd2 | 2007-03-25 20:11:55 -0700 | [diff] [blame] | 102 | if (fddi->hdr.llc_snap.ethertype == htons(ETH_P_IP)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* Try to get ARP to resolve the header and fill destination address */ |
| 104 | return arp_find(fddi->daddr, skb); |
| 105 | else |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 106 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Alexey Dobriyan | 57bf145 | 2005-08-25 16:06:19 -0700 | [diff] [blame] | 108 | printk("%s: Don't know how to resolve type %04X addresses.\n", |
| 109 | skb->dev->name, ntohs(fddi->hdr.llc_snap.ethertype)); |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 110 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /* |
| 116 | * Determine the packet's protocol ID and fill in skb fields. |
| 117 | * This routine is called before an incoming packet is passed |
| 118 | * up. It's used to fill in specific skb fields and to set |
| 119 | * the proper pointer to the start of packet data (skb->data). |
| 120 | */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 121 | |
Alexey Dobriyan | ab61148 | 2005-07-12 12:08:43 -0700 | [diff] [blame] | 122 | __be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | struct fddihdr *fddi = (struct fddihdr *)skb->data; |
Alexey Dobriyan | ab61148 | 2005-07-12 12:08:43 -0700 | [diff] [blame] | 125 | __be16 type; |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
| 128 | * Set mac.raw field to point to FC byte, set data field to point |
| 129 | * to start of packet data. Assume 802.2 SNAP frames for now. |
| 130 | */ |
| 131 | |
Arnaldo Carvalho de Melo | 0a4f23f | 2007-03-10 10:57:13 -0300 | [diff] [blame] | 132 | skb->dev = dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 133 | skb_reset_mac_header(skb); /* point to frame control (FC) */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | if(fddi->hdr.llc_8022_1.dsap==0xe0) |
| 136 | { |
| 137 | skb_pull(skb, FDDI_K_8022_HLEN-3); |
YOSHIFUJI Hideaki | 2953fd2 | 2007-03-25 20:11:55 -0700 | [diff] [blame] | 138 | type = htons(ETH_P_802_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | { |
| 142 | skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */ |
| 143 | type=fddi->hdr.llc_snap.ethertype; |
| 144 | } |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* Set packet type based on destination address and flag settings */ |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* Assume 802.2 SNAP frames, for now */ |
| 163 | |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 164 | return type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | EXPORT_SYMBOL(fddi_type_trans); |
| 168 | |
Stephen Hemminger | 145186a | 2008-11-20 20:29:48 -0800 | [diff] [blame] | 169 | int fddi_change_mtu(struct net_device *dev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN)) |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 172 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | dev->mtu = new_mtu; |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 174 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
Stephen Hemminger | 145186a | 2008-11-20 20:29:48 -0800 | [diff] [blame] | 176 | EXPORT_SYMBOL(fddi_change_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 178 | static const struct header_ops fddi_header_ops = { |
| 179 | .create = fddi_header, |
| 180 | .rebuild = fddi_rebuild_header, |
| 181 | }; |
| 182 | |
Stephen Hemminger | 145186a | 2008-11-20 20:29:48 -0800 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static void fddi_setup(struct net_device *dev) |
| 185 | { |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 186 | dev->header_ops = &fddi_header_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | dev->type = ARPHRD_FDDI; |
| 188 | dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */ |
| 189 | dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */ |
| 190 | dev->addr_len = FDDI_K_ALEN; |
| 191 | dev->tx_queue_len = 100; /* Long queues on FDDI */ |
| 192 | dev->flags = IFF_BROADCAST | IFF_MULTICAST; |
YOSHIFUJI Hideaki | 9afa094 | 2007-02-09 23:24:24 +0900 | [diff] [blame] | 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | memset(dev->broadcast, 0xFF, FDDI_K_ALEN); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * alloc_fddidev - Register FDDI device |
| 199 | * @sizeof_priv: Size of additional driver-private structure to be allocated |
| 200 | * for this FDDI device |
| 201 | * |
| 202 | * Fill in the fields of the device structure with FDDI-generic values. |
| 203 | * |
| 204 | * Constructs a new net device, complete with a private data area of |
| 205 | * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for |
| 206 | * this private data area. |
| 207 | */ |
| 208 | struct net_device *alloc_fddidev(int sizeof_priv) |
| 209 | { |
| 210 | return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup); |
| 211 | } |
| 212 | EXPORT_SYMBOL(alloc_fddidev); |
Adrian Bunk | d9677a4 | 2009-04-05 06:36:21 +0000 | [diff] [blame] | 213 | |
| 214 | MODULE_LICENSE("GPL"); |