Ip6Option.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /** @file
  2. Definition of IP6 option process routines.
  3. Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_IP6_OPTION_H__
  7. #define __EFI_IP6_OPTION_H__
  8. #define IP6_FRAGMENT_OFFSET_MASK (~0x3)
  9. typedef struct _IP6_FRAGMENT_HEADER {
  10. UINT8 NextHeader;
  11. UINT8 Reserved;
  12. UINT16 FragmentOffset;
  13. UINT32 Identification;
  14. } IP6_FRAGMENT_HEADER;
  15. typedef struct _IP6_ROUTING_HEADER {
  16. UINT8 NextHeader;
  17. UINT8 HeaderLen;
  18. UINT8 RoutingType;
  19. UINT8 SegmentsLeft;
  20. } IP6_ROUTING_HEADER;
  21. typedef enum {
  22. Ip6OptionPad1 = 0,
  23. Ip6OptionPadN = 1,
  24. Ip6OptionRouterAlert = 5,
  25. Ip6OptionSkip = 0,
  26. Ip6OptionDiscard = 0x40,
  27. Ip6OptionParameterProblem = 0x80,
  28. Ip6OptionMask = 0xc0,
  29. Ip6OptionEtherSource = 1,
  30. Ip6OptionEtherTarget = 2,
  31. Ip6OptionPrefixInfo = 3,
  32. Ip6OptionRedirected = 4,
  33. Ip6OptionMtu = 5
  34. } IP6_OPTION_TYPE;
  35. /**
  36. Validate the IP6 extension header format for both the packets we received
  37. and that we will transmit. It will compute the ICMPv6 error message fields
  38. if the option is mal-formatted.
  39. @param[in] IpSb The IP6 service instance. This is an optional parameter.
  40. @param[in] Packet The data of the packet. Ignored if NULL.
  41. @param[in] NextHeader The next header field in IPv6 basic header.
  42. @param[in] ExtHdrs The first byte of the option.
  43. @param[in] ExtHdrsLen The length of the whole option.
  44. @param[in] Rcvd The option is from the packet we received if TRUE,
  45. otherwise, the option we want to transmit.
  46. @param[out] FormerHeader The offset of NextHeader which points to Fragment
  47. Header when we received, of the ExtHdrs.
  48. Ignored if we transmit.
  49. @param[out] LastHeader The pointer of NextHeader of the last extension
  50. header processed by IP6.
  51. @param[out] RealExtsLen The length of extension headers processed by IP6 layer.
  52. This is an optional parameter that may be NULL.
  53. @param[out] UnFragmentLen The length of unfragmented length of extension headers.
  54. This is an optional parameter that may be NULL.
  55. @param[out] Fragmented Indicate whether the packet is fragmented.
  56. This is an optional parameter that may be NULL.
  57. @retval TRUE The option is properly formatted.
  58. @retval FALSE The option is malformatted.
  59. **/
  60. BOOLEAN
  61. Ip6IsExtsValid (
  62. IN IP6_SERVICE *IpSb OPTIONAL,
  63. IN NET_BUF *Packet OPTIONAL,
  64. IN UINT8 *NextHeader,
  65. IN UINT8 *ExtHdrs,
  66. IN UINT32 ExtHdrsLen,
  67. IN BOOLEAN Rcvd,
  68. OUT UINT32 *FormerHeader OPTIONAL,
  69. OUT UINT8 **LastHeader,
  70. OUT UINT32 *RealExtsLen OPTIONAL,
  71. OUT UINT32 *UnFragmentLen OPTIONAL,
  72. OUT BOOLEAN *Fragmented OPTIONAL
  73. );
  74. /**
  75. Generate an IPv6 router alert option in network order and output it through Buffer.
  76. @param[out] Buffer Points to a buffer to record the generated option.
  77. @param[in, out] BufferLen The length of Buffer, in bytes.
  78. @param[in] NextHeader The 8-bit selector indicates the type of header
  79. immediately following the Hop-by-Hop Options header.
  80. @retval EFI_BUFFER_TOO_SMALL The Buffer is too small to contain the generated
  81. option. BufferLen is updated for the required size.
  82. @retval EFI_SUCCESS The option is generated and filled in to Buffer.
  83. **/
  84. EFI_STATUS
  85. Ip6FillHopByHop (
  86. OUT UINT8 *Buffer,
  87. IN OUT UINTN *BufferLen,
  88. IN UINT8 NextHeader
  89. );
  90. /**
  91. Insert a Fragment Header to the Extension headers and output it in UpdatedExtHdrs.
  92. @param[in] IpSb The IP6 service instance to transmit the packet.
  93. @param[in] NextHeader The extension header type of first extension header.
  94. @param[in] LastHeader The extension header type of last extension header.
  95. @param[in] ExtHdrs The length of the original extension header.
  96. @param[in] ExtHdrsLen The length of the extension headers.
  97. @param[in] FragmentOffset The fragment offset of the data following the header.
  98. @param[out] UpdatedExtHdrs The updated ExtHdrs with Fragment header inserted.
  99. It's caller's responsibility to free this buffer.
  100. @retval EFI_OUT_OF_RESOURCES Failed to finish the operation due to lake of
  101. resource.
  102. @retval EFI_UNSUPPORTED The extension header specified in ExtHdrs is not
  103. supported currently.
  104. @retval EFI_SUCCESS The operation performed successfully.
  105. **/
  106. EFI_STATUS
  107. Ip6FillFragmentHeader (
  108. IN IP6_SERVICE *IpSb,
  109. IN UINT8 NextHeader,
  110. IN UINT8 LastHeader,
  111. IN UINT8 *ExtHdrs,
  112. IN UINT32 ExtHdrsLen,
  113. IN UINT16 FragmentOffset,
  114. OUT UINT8 **UpdatedExtHdrs
  115. );
  116. /**
  117. Copy the extension headers from the original to buffer. A Fragment header is
  118. appended to the end.
  119. @param[in] NextHeader The 8-bit selector indicates the type of
  120. the fragment header's next header.
  121. @param[in] ExtHdrs The length of the original extension header.
  122. @param[in] LastHeader The pointer of next header of last extension header.
  123. @param[in] FragmentOffset The fragment offset of the data following the header.
  124. @param[in] UnFragmentHdrLen The length of unfragmented length of extension headers.
  125. @param[in, out] Buf The buffer to copy options to.
  126. @param[in, out] BufLen The length of the buffer.
  127. @retval EFI_SUCCESS The options are copied over.
  128. @retval EFI_BUFFER_TOO_SMALL The buffer caller provided is too small.
  129. **/
  130. EFI_STATUS
  131. Ip6CopyExts (
  132. IN UINT8 NextHeader,
  133. IN UINT8 *ExtHdrs,
  134. IN UINT8 *LastHeader,
  135. IN UINT16 FragmentOffset,
  136. IN UINT32 UnFragmentHdrLen,
  137. IN OUT UINT8 *Buf,
  138. IN OUT UINT32 *BufLen
  139. );
  140. /**
  141. Validate the IP6 option format for both the packets we received
  142. and that we will transmit. It supports the defined options in Neighbor
  143. Discovery messages.
  144. @param[in] Option The first byte of the option.
  145. @param[in] OptionLen The length of the whole option.
  146. @retval TRUE The option is properly formatted.
  147. @retval FALSE The option is malformatted.
  148. **/
  149. BOOLEAN
  150. Ip6IsNDOptionValid (
  151. IN UINT8 *Option,
  152. IN UINT16 OptionLen
  153. );
  154. #endif