blob: 90f1416567a144a63437595b124d46cf5d892d35 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Juhl02c30a82005-05-05 16:16:16 -070013 * Ross Biro
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 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 Hideaki9afa0942007-02-09 23:24:24 +090018 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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 Hideaki9afa0942007-02-09 23:24:24 +090028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/types.h>
31#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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
52static int fddi_header(struct sk_buff *skb, struct net_device *dev,
53 unsigned short type,
Eric Dumazet95c96172012-04-15 05:58:06 +000054 const void *daddr, const void *saddr, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 int hl = FDDI_K_SNAP_HLEN;
57 struct fddihdr *fddi;
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
60 hl=FDDI_K_8022_HLEN-3;
Johannes Bergd58ff352017-06-16 14:29:23 +020061 fddi = skb_push(skb, hl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 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 Hideaki9afa0942007-02-09 23:24:24 +090075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 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 Dumazeta02cec22010-09-22 20:43:57 +000084 return hl;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86
Eric Dumazeta02cec22010-09-22 20:43:57 +000087 return -hl;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/*
91 * Determine the packet's protocol ID and fill in skb fields.
92 * This routine is called before an incoming packet is passed
93 * up. It's used to fill in specific skb fields and to set
94 * the proper pointer to the start of packet data (skb->data).
95 */
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +090096
Alexey Dobriyanab611482005-07-12 12:08:43 -070097__be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 struct fddihdr *fddi = (struct fddihdr *)skb->data;
Alexey Dobriyanab611482005-07-12 12:08:43 -0700100 __be16 type;
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /*
103 * Set mac.raw field to point to FC byte, set data field to point
104 * to start of packet data. Assume 802.2 SNAP frames for now.
105 */
106
Arnaldo Carvalho de Melo0a4f23f2007-03-10 10:57:13 -0300107 skb->dev = dev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -0700108 skb_reset_mac_header(skb); /* point to frame control (FC) */
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 if(fddi->hdr.llc_8022_1.dsap==0xe0)
111 {
112 skb_pull(skb, FDDI_K_8022_HLEN-3);
YOSHIFUJI Hideaki2953fd22007-03-25 20:11:55 -0700113 type = htons(ETH_P_802_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115 else
116 {
117 skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */
118 type=fddi->hdr.llc_snap.ethertype;
119 }
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /* Set packet type based on destination address and flag settings */
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (*fddi->daddr & 0x01)
124 {
125 if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
126 skb->pkt_type = PACKET_BROADCAST;
127 else
128 skb->pkt_type = PACKET_MULTICAST;
129 }
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 else if (dev->flags & IFF_PROMISC)
132 {
133 if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
134 skb->pkt_type = PACKET_OTHERHOST;
135 }
136
137 /* Assume 802.2 SNAP frames, for now */
138
Eric Dumazeta02cec22010-09-22 20:43:57 +0000139 return type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
142EXPORT_SYMBOL(fddi_type_trans);
143
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700144static const struct header_ops fddi_header_ops = {
145 .create = fddi_header,
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700146};
147
Stephen Hemminger145186a2008-11-20 20:29:48 -0800148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static void fddi_setup(struct net_device *dev)
150{
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700151 dev->header_ops = &fddi_header_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 dev->type = ARPHRD_FDDI;
153 dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
154 dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */
Jarod Wilsonb3e38932016-10-20 13:55:22 -0400155 dev->min_mtu = FDDI_K_SNAP_HLEN;
156 dev->max_mtu = FDDI_K_SNAP_DLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 dev->addr_len = FDDI_K_ALEN;
158 dev->tx_queue_len = 100; /* Long queues on FDDI */
159 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
YOSHIFUJI Hideaki9afa0942007-02-09 23:24:24 +0900160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
162}
163
164/**
165 * alloc_fddidev - Register FDDI device
166 * @sizeof_priv: Size of additional driver-private structure to be allocated
167 * for this FDDI device
168 *
169 * Fill in the fields of the device structure with FDDI-generic values.
170 *
171 * Constructs a new net device, complete with a private data area of
172 * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
173 * this private data area.
174 */
175struct net_device *alloc_fddidev(int sizeof_priv)
176{
Tom Gundersenc835a672014-07-14 16:37:24 +0200177 return alloc_netdev(sizeof_priv, "fddi%d", NET_NAME_UNKNOWN,
178 fddi_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180EXPORT_SYMBOL(alloc_fddidev);
Adrian Bunkd9677a42009-04-05 06:36:21 +0000181
182MODULE_LICENSE("GPL");