fddi.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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
  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. #include <linux/module.h>
  29. #include <linux/types.h>
  30. #include <linux/kernel.h>
  31. #include <linux/string.h>
  32. #include <linux/mm.h>
  33. #include <linux/socket.h>
  34. #include <linux/in.h>
  35. #include <linux/inet.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/fddidevice.h>
  38. #include <linux/if_ether.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/errno.h>
  41. #include <net/arp.h>
  42. #include <net/sock.h>
  43. /*
  44. * Create the FDDI MAC header for an arbitrary protocol layer
  45. *
  46. * saddr=NULL means use device source address
  47. * daddr=NULL means leave destination address (eg unresolved arp)
  48. */
  49. static int fddi_header(struct sk_buff *skb, struct net_device *dev,
  50. unsigned short type,
  51. const void *daddr, const void *saddr, unsigned int len)
  52. {
  53. int hl = FDDI_K_SNAP_HLEN;
  54. struct fddihdr *fddi;
  55. if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
  56. hl=FDDI_K_8022_HLEN-3;
  57. fddi = (struct fddihdr *)skb_push(skb, hl);
  58. fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF;
  59. if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP)
  60. {
  61. fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP;
  62. fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP;
  63. fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD;
  64. fddi->hdr.llc_snap.oui[0] = 0x00;
  65. fddi->hdr.llc_snap.oui[1] = 0x00;
  66. fddi->hdr.llc_snap.oui[2] = 0x00;
  67. fddi->hdr.llc_snap.ethertype = htons(type);
  68. }
  69. /* Set the source and destination hardware addresses */
  70. if (saddr != NULL)
  71. memcpy(fddi->saddr, saddr, dev->addr_len);
  72. else
  73. memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
  74. if (daddr != NULL)
  75. {
  76. memcpy(fddi->daddr, daddr, dev->addr_len);
  77. return hl;
  78. }
  79. return -hl;
  80. }
  81. /*
  82. * Rebuild the FDDI MAC header. This is called after an ARP
  83. * (or in future other address resolution) has completed on
  84. * this sk_buff. We now let ARP fill in the other fields.
  85. */
  86. static int fddi_rebuild_header(struct sk_buff *skb)
  87. {
  88. struct fddihdr *fddi = (struct fddihdr *)skb->data;
  89. #ifdef CONFIG_INET
  90. if (fddi->hdr.llc_snap.ethertype == htons(ETH_P_IP))
  91. /* Try to get ARP to resolve the header and fill destination address */
  92. return arp_find(fddi->daddr, skb);
  93. else
  94. #endif
  95. {
  96. printk("%s: Don't know how to resolve type %04X addresses.\n",
  97. skb->dev->name, ntohs(fddi->hdr.llc_snap.ethertype));
  98. return 0;
  99. }
  100. }
  101. /*
  102. * Determine the packet's protocol ID and fill in skb fields.
  103. * This routine is called before an incoming packet is passed
  104. * up. It's used to fill in specific skb fields and to set
  105. * the proper pointer to the start of packet data (skb->data).
  106. */
  107. __be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
  108. {
  109. struct fddihdr *fddi = (struct fddihdr *)skb->data;
  110. __be16 type;
  111. /*
  112. * Set mac.raw field to point to FC byte, set data field to point
  113. * to start of packet data. Assume 802.2 SNAP frames for now.
  114. */
  115. skb->dev = dev;
  116. skb_reset_mac_header(skb); /* point to frame control (FC) */
  117. if(fddi->hdr.llc_8022_1.dsap==0xe0)
  118. {
  119. skb_pull(skb, FDDI_K_8022_HLEN-3);
  120. type = htons(ETH_P_802_2);
  121. }
  122. else
  123. {
  124. skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */
  125. type=fddi->hdr.llc_snap.ethertype;
  126. }
  127. /* Set packet type based on destination address and flag settings */
  128. if (*fddi->daddr & 0x01)
  129. {
  130. if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
  131. skb->pkt_type = PACKET_BROADCAST;
  132. else
  133. skb->pkt_type = PACKET_MULTICAST;
  134. }
  135. else if (dev->flags & IFF_PROMISC)
  136. {
  137. if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
  138. skb->pkt_type = PACKET_OTHERHOST;
  139. }
  140. /* Assume 802.2 SNAP frames, for now */
  141. return type;
  142. }
  143. EXPORT_SYMBOL(fddi_type_trans);
  144. int fddi_change_mtu(struct net_device *dev, int new_mtu)
  145. {
  146. if ((new_mtu < FDDI_K_SNAP_HLEN) || (new_mtu > FDDI_K_SNAP_DLEN))
  147. return -EINVAL;
  148. dev->mtu = new_mtu;
  149. return 0;
  150. }
  151. EXPORT_SYMBOL(fddi_change_mtu);
  152. static const struct header_ops fddi_header_ops = {
  153. .create = fddi_header,
  154. .rebuild = fddi_rebuild_header,
  155. };
  156. static void fddi_setup(struct net_device *dev)
  157. {
  158. dev->header_ops = &fddi_header_ops;
  159. dev->type = ARPHRD_FDDI;
  160. dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
  161. dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */
  162. dev->addr_len = FDDI_K_ALEN;
  163. dev->tx_queue_len = 100; /* Long queues on FDDI */
  164. dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  165. memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
  166. }
  167. /**
  168. * alloc_fddidev - Register FDDI device
  169. * @sizeof_priv: Size of additional driver-private structure to be allocated
  170. * for this FDDI device
  171. *
  172. * Fill in the fields of the device structure with FDDI-generic values.
  173. *
  174. * Constructs a new net device, complete with a private data area of
  175. * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
  176. * this private data area.
  177. */
  178. struct net_device *alloc_fddidev(int sizeof_priv)
  179. {
  180. return alloc_netdev(sizeof_priv, "fddi%d", fddi_setup);
  181. }
  182. EXPORT_SYMBOL(alloc_fddidev);
  183. MODULE_LICENSE("GPL");