1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * INET An implementation of the TCP/I 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 4 * operating system. INET is imp 3 * operating system. INET is implemented using the BSD Socket 5 * interface as the means of comm 4 * interface as the means of communication with the user level. 6 * 5 * 7 * FDDI-type device handling. 6 * FDDI-type device handling. 8 * 7 * 9 * Version: @(#)fddi.c 1.0.0 08/12/ 8 * Version: @(#)fddi.c 1.0.0 08/12/96 10 * 9 * 11 * Authors: Lawrence V. Stefani, <stefani@ 10 * Authors: Lawrence V. Stefani, <stefani@lkg.dec.com> 12 * 11 * 13 * fddi.c is based on previous et 12 * fddi.c is based on previous eth.c and tr.c work by 14 * Ross Biro !! 13 * Ross Biro, <bir7@leland.Stanford.Edu> 15 * Fred N. van Kempen, <w 14 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 16 * Mark Evans, <evansmp@u 15 * Mark Evans, <evansmp@uhura.aston.ac.uk> 17 * Florian La Roche, <rzs 16 * Florian La Roche, <rzsfl@rz.uni-sb.de> 18 * Alan Cox, <gw4pts@gw4p 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. 19 * 23 * 20 * Changes 24 * Changes 21 * Alan Cox : 25 * Alan Cox : New arp/rebuild header 22 * Maciej W. Rozycki : 26 * Maciej W. Rozycki : IPv6 support 23 */ 27 */ 24 !! 28 >> 29 #include <linux/config.h> 25 #include <linux/module.h> 30 #include <linux/module.h> >> 31 #include <asm/system.h> 26 #include <linux/types.h> 32 #include <linux/types.h> 27 #include <linux/kernel.h> 33 #include <linux/kernel.h> >> 34 #include <linux/sched.h> 28 #include <linux/string.h> 35 #include <linux/string.h> 29 #include <linux/mm.h> 36 #include <linux/mm.h> 30 #include <linux/socket.h> 37 #include <linux/socket.h> 31 #include <linux/in.h> 38 #include <linux/in.h> 32 #include <linux/inet.h> 39 #include <linux/inet.h> 33 #include <linux/netdevice.h> 40 #include <linux/netdevice.h> 34 #include <linux/fddidevice.h> 41 #include <linux/fddidevice.h> 35 #include <linux/if_ether.h> 42 #include <linux/if_ether.h> 36 #include <linux/skbuff.h> 43 #include <linux/skbuff.h> 37 #include <linux/errno.h> 44 #include <linux/errno.h> 38 #include <net/arp.h> 45 #include <net/arp.h> 39 #include <net/sock.h> 46 #include <net/sock.h> 40 47 41 /* 48 /* 42 * Create the FDDI MAC header for an arbitrary 49 * Create the FDDI MAC header for an arbitrary protocol layer 43 * 50 * 44 * saddr=NULL means use device source addres 51 * saddr=NULL means use device source address 45 * daddr=NULL means leave destination addres 52 * daddr=NULL means leave destination address (eg unresolved arp) 46 */ 53 */ 47 54 48 static int fddi_header(struct sk_buff *skb, st !! 55 int fddi_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, 49 unsigned short type, !! 56 void *daddr, void *saddr, unsigned len) 50 const void *daddr, cons << 51 { 57 { 52 int hl = FDDI_K_SNAP_HLEN; 58 int hl = FDDI_K_SNAP_HLEN; 53 struct fddihdr *fddi; 59 struct fddihdr *fddi; 54 !! 60 55 if(type != ETH_P_IP && type != ETH_P_I 61 if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP) 56 hl=FDDI_K_8022_HLEN-3; 62 hl=FDDI_K_8022_HLEN-3; 57 fddi = skb_push(skb, hl); !! 63 fddi = (struct fddihdr *)skb_push(skb, hl); 58 fddi->fc = FDD 64 fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF; 59 if(type == ETH_P_IP || type == ETH_P_I 65 if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP) 60 { 66 { 61 fddi->hdr.llc_snap.dsap 67 fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP; 62 fddi->hdr.llc_snap.ssap 68 fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP; 63 fddi->hdr.llc_snap.ctrl 69 fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD; 64 fddi->hdr.llc_snap.oui[0] 70 fddi->hdr.llc_snap.oui[0] = 0x00; 65 fddi->hdr.llc_snap.oui[1] 71 fddi->hdr.llc_snap.oui[1] = 0x00; 66 fddi->hdr.llc_snap.oui[2] 72 fddi->hdr.llc_snap.oui[2] = 0x00; 67 fddi->hdr.llc_snap.ethertype 73 fddi->hdr.llc_snap.ethertype = htons(type); 68 } 74 } 69 75 70 /* Set the source and destination hard 76 /* Set the source and destination hardware addresses */ 71 !! 77 72 if (saddr != NULL) 78 if (saddr != NULL) 73 memcpy(fddi->saddr, saddr, dev 79 memcpy(fddi->saddr, saddr, dev->addr_len); 74 else 80 else 75 memcpy(fddi->saddr, dev->dev_a 81 memcpy(fddi->saddr, dev->dev_addr, dev->addr_len); 76 82 77 if (daddr != NULL) 83 if (daddr != NULL) 78 { 84 { 79 memcpy(fddi->daddr, daddr, dev 85 memcpy(fddi->daddr, daddr, dev->addr_len); 80 return hl; !! 86 return(hl); 81 } 87 } 82 88 83 return -hl; !! 89 return(-hl); >> 90 } >> 91 >> 92 >> 93 /* >> 94 * Rebuild the FDDI MAC header. This is called after an ARP >> 95 * (or in future other address resolution) has completed on >> 96 * this sk_buff. We now let ARP fill in the other fields. >> 97 */ >> 98 >> 99 int fddi_rebuild_header(struct sk_buff *skb) >> 100 { >> 101 struct fddihdr *fddi = (struct fddihdr *)skb->data; >> 102 >> 103 #ifdef CONFIG_INET >> 104 if (fddi->hdr.llc_snap.ethertype == __constant_htons(ETH_P_IP)) >> 105 /* Try to get ARP to resolve the header and fill destination address */ >> 106 return arp_find(fddi->daddr, skb); >> 107 else >> 108 #endif >> 109 { >> 110 printk("%s: Don't know how to resolve type %02X addresses.\n", >> 111 skb->dev->name, htons(fddi->hdr.llc_snap.ethertype)); >> 112 return(0); >> 113 } 84 } 114 } 85 115 >> 116 86 /* 117 /* 87 * Determine the packet's protocol ID and fill 118 * Determine the packet's protocol ID and fill in skb fields. 88 * This routine is called before an incoming p 119 * This routine is called before an incoming packet is passed 89 * up. It's used to fill in specific skb fiel 120 * up. It's used to fill in specific skb fields and to set 90 * the proper pointer to the start of packet d 121 * the proper pointer to the start of packet data (skb->data). 91 */ 122 */ 92 !! 123 93 __be16 fddi_type_trans(struct sk_buff *skb, st !! 124 unsigned short fddi_type_trans(struct sk_buff *skb, struct net_device *dev) 94 { 125 { 95 struct fddihdr *fddi = (struct fddihdr 126 struct fddihdr *fddi = (struct fddihdr *)skb->data; 96 __be16 type; !! 127 unsigned short type; 97 !! 128 98 /* 129 /* 99 * Set mac.raw field to point to FC by 130 * Set mac.raw field to point to FC byte, set data field to point 100 * to start of packet data. Assume 80 131 * to start of packet data. Assume 802.2 SNAP frames for now. 101 */ 132 */ 102 133 103 skb->dev = dev; !! 134 skb->mac.raw = skb->data; /* point to frame control (FC) */ 104 skb_reset_mac_header(skb); /* poi !! 135 105 << 106 if(fddi->hdr.llc_8022_1.dsap==0xe0) 136 if(fddi->hdr.llc_8022_1.dsap==0xe0) 107 { 137 { 108 skb_pull(skb, FDDI_K_8022_HLEN 138 skb_pull(skb, FDDI_K_8022_HLEN-3); 109 type = htons(ETH_P_802_2); !! 139 type = __constant_htons(ETH_P_802_2); 110 } 140 } 111 else 141 else 112 { 142 { 113 skb_pull(skb, FDDI_K_SNAP_HLEN 143 skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */ 114 type=fddi->hdr.llc_snap.ethert 144 type=fddi->hdr.llc_snap.ethertype; 115 } 145 } 116 !! 146 117 /* Set packet type based on destinatio 147 /* Set packet type based on destination address and flag settings */ 118 !! 148 119 if (*fddi->daddr & 0x01) 149 if (*fddi->daddr & 0x01) 120 { 150 { 121 if (memcmp(fddi->daddr, dev->b 151 if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0) 122 skb->pkt_type = PACKET 152 skb->pkt_type = PACKET_BROADCAST; 123 else 153 else 124 skb->pkt_type = PACKET 154 skb->pkt_type = PACKET_MULTICAST; 125 } 155 } 126 !! 156 127 else if (dev->flags & IFF_PROMISC) 157 else if (dev->flags & IFF_PROMISC) 128 { 158 { 129 if (memcmp(fddi->daddr, dev->d 159 if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN)) 130 skb->pkt_type = PACKET 160 skb->pkt_type = PACKET_OTHERHOST; 131 } 161 } 132 162 133 /* Assume 802.2 SNAP frames, for now * 163 /* Assume 802.2 SNAP frames, for now */ 134 164 135 return type; !! 165 return(type); 136 } 166 } 137 167 138 EXPORT_SYMBOL(fddi_type_trans); 168 EXPORT_SYMBOL(fddi_type_trans); 139 << 140 static const struct header_ops fddi_header_ops << 141 .create = fddi_header, << 142 }; << 143 << 144 << 145 static void fddi_setup(struct net_device *dev) << 146 { << 147 dev->header_ops = &fddi_header << 148 dev->type = ARPHRD_FDDI; << 149 dev->hard_header_len = FDDI_K_SNAP_ << 150 dev->mtu = FDDI_K_SNAP_ << 151 dev->min_mtu = FDDI_K_SNAP_ << 152 dev->max_mtu = FDDI_K_SNAP_ << 153 dev->addr_len = FDDI_K_ALEN; << 154 dev->tx_queue_len = 100; << 155 dev->flags = IFF_BROADCAS << 156 << 157 memset(dev->broadcast, 0xFF, FDDI_K_AL << 158 } << 159 << 160 /** << 161 * alloc_fddidev - Register FDDI device << 162 * @sizeof_priv: Size of additional driver-pri << 163 * for this FDDI device << 164 * << 165 * Fill in the fields of the device structure << 166 * << 167 * Constructs a new net device, complete with << 168 * size @sizeof_priv. A 32-byte (not bit) ali << 169 * this private data area. << 170 */ << 171 struct net_device *alloc_fddidev(int sizeof_pr << 172 { << 173 return alloc_netdev(sizeof_priv, "fddi << 174 fddi_setup); << 175 } << 176 EXPORT_SYMBOL(alloc_fddidev); << 177 << 178 MODULE_DESCRIPTION("Core routines for FDDI net << 179 MODULE_LICENSE("GPL"); << 180 169
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.