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