Ip6Input.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /** @file
  2. IP6 internal functions and definitions to process the incoming packets.
  3. Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_IP6_INPUT_H__
  7. #define __EFI_IP6_INPUT_H__
  8. #define IP6_MIN_HEADLEN 40
  9. #define IP6_MAX_HEADLEN 120
  10. ///
  11. /// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54
  12. ///
  13. #define IP6_MAX_IPSEC_HEADLEN 54
  14. #define IP6_ASSEMLE_HASH_SIZE 127
  15. ///
  16. /// Lift time in seconds.
  17. ///
  18. #define IP6_FRAGMENT_LIFE 60
  19. #define IP6_MAX_PACKET_SIZE 65535
  20. #define IP6_GET_CLIP_INFO(Packet) ((IP6_CLIP_INFO *) ((Packet)->ProtoData))
  21. #define IP6_ASSEMBLE_HASH(Dst, Src, Id) \
  22. ((*((UINT32 *) (Dst)) + *((UINT32 *) (Src)) + (Id)) % IP6_ASSEMLE_HASH_SIZE)
  23. #define IP6_RXDATA_WRAP_SIZE(NumFrag) \
  24. (sizeof (IP6_RXDATA_WRAP) + sizeof (EFI_IP6_FRAGMENT_DATA) * ((NumFrag) - 1))
  25. //
  26. // Per packet information for input process. LinkFlag specifies whether
  27. // the packet is received as Link layer unicast, multicast or broadcast.
  28. // The CastType is the IP layer cast type, such as IP multicast or unicast.
  29. // Start, End and Length are staffs used to assemble the packets. Start
  30. // is the sequence number of the first byte of data in the packet. Length
  31. // is the number of bytes of data. End = Start + Length, that is, the
  32. // sequence number of last byte + 1. Each assembled packet has a count down
  33. // life. If it isn't consumed before Life reaches zero, the packet is released.
  34. //
  35. typedef struct {
  36. UINT32 LinkFlag;
  37. INT32 CastType;
  38. INT32 Start;
  39. INT32 End;
  40. INT32 Length;
  41. UINT32 Life;
  42. EFI_STATUS Status;
  43. UINT32 Id;
  44. UINT16 HeadLen;
  45. UINT8 NextHeader;
  46. UINT8 LastFrag;
  47. UINT32 FormerNextHeader;
  48. } IP6_CLIP_INFO;
  49. //
  50. // Structure used to assemble IP packets.
  51. //
  52. typedef struct {
  53. LIST_ENTRY Link;
  54. LIST_ENTRY Fragments; // List of all the fragments of this packet
  55. //
  56. // Identity of one IP6 packet. Each fragment of a packet has
  57. // the same (Dst, Src, Id).
  58. //
  59. EFI_IPv6_ADDRESS Dst;
  60. EFI_IPv6_ADDRESS Src;
  61. UINT32 Id;
  62. UINT32 TotalLen;
  63. UINT32 CurLen;
  64. UINT32 Life; // Count down life for the packet.
  65. EFI_IP6_HEADER *Head; // IP head of the first fragment
  66. IP6_CLIP_INFO *Info; // Per packet information of the first fragment
  67. NET_BUF *Packet; // The first fragment of the packet
  68. } IP6_ASSEMBLE_ENTRY;
  69. //
  70. // Each Ip service instance has an assemble table to reassemble
  71. // the packets before delivery to its children. It is organized
  72. // as hash table.
  73. //
  74. typedef struct {
  75. LIST_ENTRY Bucket[IP6_ASSEMLE_HASH_SIZE];
  76. } IP6_ASSEMBLE_TABLE;
  77. /**
  78. The IP6 input routine. It is called by the IP6_INTERFACE when an
  79. IP6 fragment is received from MNP.
  80. @param[in] Packet The IP6 packet received.
  81. @param[in] IoStatus The return status of receive request.
  82. @param[in] Flag The link layer flag for the packet received, such
  83. as multicast.
  84. @param[in] Context The IP6 service instance that own the MNP.
  85. **/
  86. VOID
  87. Ip6AcceptFrame (
  88. IN NET_BUF *Packet,
  89. IN EFI_STATUS IoStatus,
  90. IN UINT32 Flag,
  91. IN VOID *Context
  92. );
  93. /**
  94. Deliver the received packets to upper layer if there are both received
  95. requests and enqueued packets. If the enqueued packet is shared, it will
  96. duplicate it to a non-shared packet, release the shared packet, then
  97. deliver the non-shared packet up.
  98. @param[in] IpInstance The IP child to deliver the packet up.
  99. @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
  100. packets.
  101. @retval EFI_SUCCESS All the enqueued packets that can be delivered
  102. are delivered up.
  103. **/
  104. EFI_STATUS
  105. Ip6InstanceDeliverPacket (
  106. IN IP6_PROTOCOL *IpInstance
  107. );
  108. /**
  109. The work function to locate the IPsec protocol to process the inbound or
  110. outbound IP packets. The process routine handles the packet with the following
  111. actions: bypass the packet, discard the packet, or protect the packet.
  112. @param[in] IpSb The IP6 service instance.
  113. @param[in, out] Head The caller-supplied IP6 header.
  114. @param[in, out] LastHead The next header field of last IP header.
  115. @param[in, out] Netbuf The IP6 packet to be processed by IPsec.
  116. @param[in, out] ExtHdrs The caller-supplied options.
  117. @param[in, out] ExtHdrsLen The length of the option.
  118. @param[in] Direction The directionality in an SPD entry,
  119. EfiIPsecInBound, or EfiIPsecOutBound.
  120. @param[in] Context The token's wrap.
  121. @retval EFI_SUCCESS The IPsec protocol is not available or disabled.
  122. @retval EFI_SUCCESS The packet was bypassed, and all buffers remain the same.
  123. @retval EFI_SUCCESS The packet was protected.
  124. @retval EFI_ACCESS_DENIED The packet was discarded.
  125. @retval EFI_OUT_OF_RESOURCES There are not sufficient resources to complete the operation.
  126. @retval EFI_BUFFER_TOO_SMALL The number of non-empty blocks is bigger than the
  127. number of input data blocks when building a fragment table.
  128. **/
  129. EFI_STATUS
  130. Ip6IpSecProcessPacket (
  131. IN IP6_SERVICE *IpSb,
  132. IN OUT EFI_IP6_HEADER **Head,
  133. IN OUT UINT8 *LastHead,
  134. IN OUT NET_BUF **Netbuf,
  135. IN OUT UINT8 **ExtHdrs,
  136. IN OUT UINT32 *ExtHdrsLen,
  137. IN EFI_IPSEC_TRAFFIC_DIR Direction,
  138. IN VOID *Context
  139. );
  140. /**
  141. Initialize an already allocated assemble table. This is generally
  142. the assemble table embedded in the IP6 service instance.
  143. @param[in, out] Table The assemble table to initialize.
  144. **/
  145. VOID
  146. Ip6CreateAssembleTable (
  147. IN OUT IP6_ASSEMBLE_TABLE *Table
  148. );
  149. /**
  150. Clean up the assemble table: remove all the fragments
  151. and assemble entries.
  152. @param[in, out] Table The assemble table to clean up.
  153. **/
  154. VOID
  155. Ip6CleanAssembleTable (
  156. IN OUT IP6_ASSEMBLE_TABLE *Table
  157. );
  158. /**
  159. Demultiple the packet. the packet delivery is processed in two
  160. passes. The first pass will enqueue a shared copy of the packet
  161. to each IP6 child that accepts the packet. The second pass will
  162. deliver a non-shared copy of the packet to each IP6 child that
  163. has pending receive requests. Data is copied if more than one
  164. child wants to consume the packet because each IP child need
  165. its own copy of the packet to make changes.
  166. @param[in] IpSb The IP6 service instance that received the packet.
  167. @param[in] Head The header of the received packet.
  168. @param[in] Packet The data of the received packet.
  169. @retval EFI_NOT_FOUND No IP child accepts the packet.
  170. @retval EFI_SUCCESS The packet is enqueued or delivered to some IP
  171. children.
  172. **/
  173. EFI_STATUS
  174. Ip6Demultiplex (
  175. IN IP6_SERVICE *IpSb,
  176. IN EFI_IP6_HEADER *Head,
  177. IN NET_BUF *Packet
  178. );
  179. /**
  180. Timeout the fragmented, enqueued, and transmitted packets.
  181. @param[in] IpSb The IP6 service instance to timeout.
  182. **/
  183. VOID
  184. Ip6PacketTimerTicking (
  185. IN IP6_SERVICE *IpSb
  186. );
  187. #endif