fddi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * FDDI-type device handling.
  8. *
  9. * Version: @(#)fddi.c 1.0.0 08/12/96
  10. *
  11. * Authors: Lawrence V. Stefani, <stefani@lkg.dec.com>
  12. *
  13. * fddi.c is based on previous eth.c and tr.c work by
  14. * Ross Biro
  15. * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  16. * Mark Evans, <evansmp@uhura.aston.ac.uk>
  17. * Florian La Roche, <rzsfl@rz.uni-sb.de>
  18. * Alan Cox, <gw4pts@gw4pts.ampr.org>
  19. *
  20. * Changes
  21. * Alan Cox : New arp/rebuild header
  22. * Maciej W. Rozycki : IPv6 support
  23. */
  24. #include <linux/module.h>
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/string.h>
  28. #include <linux/mm.h>
  29. #include <linux/socket.h>
  30. #include <linux/in.h>
  31. #include <linux/inet.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/fddidevice.h>
  34. #include <linux/if_ether.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/errno.h>
  37. #include <net/arp.h>
  38. #include <net/sock.h>
  39. /*
  40. * Create the FDDI MAC header for an arbitrary protocol layer
  41. *
  42. * saddr=NULL means use device source address
  43. * daddr=NULL means leave destination address (eg unresolved arp)
  44. */
  45. static int fddi_header(struct sk_buff *skb, struct net_device *dev,
  46. unsigned short type,
  47. const void *daddr, const void *saddr, unsigned int len)
  48. {
  49. int hl = FDDI_K_SNAP_HLEN;
  50. struct fddihdr *fddi;
  51. if(type != ETH_P_IP && type != ETH_P_IPV6 && type != ETH_P_ARP)
  52. hl=FDDI_K_8022_HLEN-3;
  53. fddi = skb_push(skb, hl);
  54. fddi->fc = FDDI_FC_K_ASYNC_LLC_DEF;
  55. if(type == ETH_P_IP || type == ETH_P_IPV6 || type == ETH_P_ARP)
  56. {
  57. fddi->hdr.llc_snap.dsap = FDDI_EXTENDED_SAP;
  58. fddi->hdr.llc_snap.ssap = FDDI_EXTENDED_SAP;
  59. fddi->hdr.llc_snap.ctrl = FDDI_UI_CMD;
  60. fddi->hdr.llc_snap.oui[0] = 0x00;
  61. fddi->hdr.llc_snap.oui[1] = 0x00;
  62. fddi->hdr.llc_snap.oui[2] = 0x00;
  63. fddi->hdr.llc_snap.ethertype = htons(type);
  64. }
  65. /* Set the source and destination hardware addresses */
  66. if (saddr != NULL)
  67. memcpy(fddi->saddr, saddr, dev->addr_len);
  68. else
  69. memcpy(fddi->saddr, dev->dev_addr, dev->addr_len);
  70. if (daddr != NULL)
  71. {
  72. memcpy(fddi->daddr, daddr, dev->addr_len);
  73. return hl;
  74. }
  75. return -hl;
  76. }
  77. /*
  78. * Determine the packet's protocol ID and fill in skb fields.
  79. * This routine is called before an incoming packet is passed
  80. * up. It's used to fill in specific skb fields and to set
  81. * the proper pointer to the start of packet data (skb->data).
  82. */
  83. __be16 fddi_type_trans(struct sk_buff *skb, struct net_device *dev)
  84. {
  85. struct fddihdr *fddi = (struct fddihdr *)skb->data;
  86. __be16 type;
  87. /*
  88. * Set mac.raw field to point to FC byte, set data field to point
  89. * to start of packet data. Assume 802.2 SNAP frames for now.
  90. */
  91. skb->dev = dev;
  92. skb_reset_mac_header(skb); /* point to frame control (FC) */
  93. if(fddi->hdr.llc_8022_1.dsap==0xe0)
  94. {
  95. skb_pull(skb, FDDI_K_8022_HLEN-3);
  96. type = htons(ETH_P_802_2);
  97. }
  98. else
  99. {
  100. skb_pull(skb, FDDI_K_SNAP_HLEN); /* adjust for 21 byte header */
  101. type=fddi->hdr.llc_snap.ethertype;
  102. }
  103. /* Set packet type based on destination address and flag settings */
  104. if (*fddi->daddr & 0x01)
  105. {
  106. if (memcmp(fddi->daddr, dev->broadcast, FDDI_K_ALEN) == 0)
  107. skb->pkt_type = PACKET_BROADCAST;
  108. else
  109. skb->pkt_type = PACKET_MULTICAST;
  110. }
  111. else if (dev->flags & IFF_PROMISC)
  112. {
  113. if (memcmp(fddi->daddr, dev->dev_addr, FDDI_K_ALEN))
  114. skb->pkt_type = PACKET_OTHERHOST;
  115. }
  116. /* Assume 802.2 SNAP frames, for now */
  117. return type;
  118. }
  119. EXPORT_SYMBOL(fddi_type_trans);
  120. static const struct header_ops fddi_header_ops = {
  121. .create = fddi_header,
  122. };
  123. static void fddi_setup(struct net_device *dev)
  124. {
  125. dev->header_ops = &fddi_header_ops;
  126. dev->type = ARPHRD_FDDI;
  127. dev->hard_header_len = FDDI_K_SNAP_HLEN+3; /* Assume 802.2 SNAP hdr len + 3 pad bytes */
  128. dev->mtu = FDDI_K_SNAP_DLEN; /* Assume max payload of 802.2 SNAP frame */
  129. dev->min_mtu = FDDI_K_SNAP_HLEN;
  130. dev->max_mtu = FDDI_K_SNAP_DLEN;
  131. dev->addr_len = FDDI_K_ALEN;
  132. dev->tx_queue_len = 100; /* Long queues on FDDI */
  133. dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  134. memset(dev->broadcast, 0xFF, FDDI_K_ALEN);
  135. }
  136. /**
  137. * alloc_fddidev - Register FDDI device
  138. * @sizeof_priv: Size of additional driver-private structure to be allocated
  139. * for this FDDI device
  140. *
  141. * Fill in the fields of the device structure with FDDI-generic values.
  142. *
  143. * Constructs a new net device, complete with a private data area of
  144. * size @sizeof_priv. A 32-byte (not bit) alignment is enforced for
  145. * this private data area.
  146. */
  147. struct net_device *alloc_fddidev(int sizeof_priv)
  148. {
  149. return alloc_netdev(sizeof_priv, "fddi%d", NET_NAME_UNKNOWN,
  150. fddi_setup);
  151. }
  152. EXPORT_SYMBOL(alloc_fddidev);
  153. MODULE_LICENSE("GPL");