1 | /** @file
|
---|
2 | Definition of IP6 option process routines.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #ifndef __EFI_IP6_OPTION_H__
|
---|
11 | #define __EFI_IP6_OPTION_H__
|
---|
12 |
|
---|
13 | #define IP6_FRAGMENT_OFFSET_MASK (~0x3)
|
---|
14 |
|
---|
15 | //
|
---|
16 | // For more information see RFC 8200, Section 4.3, 4.4, and 4.6
|
---|
17 | //
|
---|
18 | // This example format is from section 4.6
|
---|
19 | // This does not apply to fragment headers
|
---|
20 | //
|
---|
21 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
---|
22 | // | Next Header | Hdr Ext Len | |
|
---|
23 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
|
---|
24 | // | |
|
---|
25 | // . .
|
---|
26 | // . Header-Specific Data .
|
---|
27 | // . .
|
---|
28 | // | |
|
---|
29 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
---|
30 | //
|
---|
31 | // Next Header 8-bit selector. Identifies the type of
|
---|
32 | // header immediately following the extension
|
---|
33 | // header. Uses the same values as the IPv4
|
---|
34 | // Protocol field [IANA-PN].
|
---|
35 | //
|
---|
36 | // Hdr Ext Len 8-bit unsigned integer. Length of the
|
---|
37 | // Destination Options header in 8-octet units,
|
---|
38 | // not including the first 8 octets.
|
---|
39 |
|
---|
40 | //
|
---|
41 | // These defines apply to the following:
|
---|
42 | // 1. Hop by Hop
|
---|
43 | // 2. Routing
|
---|
44 | // 3. Destination
|
---|
45 | //
|
---|
46 | typedef struct _IP6_EXT_HDR {
|
---|
47 | ///
|
---|
48 | /// The Next Header field identifies the type of header immediately
|
---|
49 | ///
|
---|
50 | UINT8 NextHeader;
|
---|
51 | ///
|
---|
52 | /// The Hdr Ext Len field specifies the length of the Hop-by-Hop Options
|
---|
53 | ///
|
---|
54 | UINT8 HdrExtLen;
|
---|
55 | ///
|
---|
56 | /// Header-Specific Data
|
---|
57 | ///
|
---|
58 | } IP6_EXT_HDR;
|
---|
59 |
|
---|
60 | STATIC_ASSERT (
|
---|
61 | sizeof (IP6_EXT_HDR) == 2,
|
---|
62 | "The combined size of Next Header and Len is two 8 bit fields"
|
---|
63 | );
|
---|
64 |
|
---|
65 | //
|
---|
66 | // IPv6 extension headers contain an 8-bit length field which describes the size of
|
---|
67 | // the header. However, the length field only includes the size of the extension
|
---|
68 | // header options, not the size of the first 8 bytes of the header. Therefore, in
|
---|
69 | // order to calculate the full size of the extension header, we add 1 (to account
|
---|
70 | // for the first 8 bytes omitted by the length field reporting) and then multiply
|
---|
71 | // by 8 (since the size is represented in 8-byte units).
|
---|
72 | //
|
---|
73 | // a is the length field of the extension header (UINT8)
|
---|
74 | // The result may be up to 2046 octets (UINT16)
|
---|
75 | //
|
---|
76 | #define IP6_HDR_EXT_LEN(a) (((UINT16)((UINT8)(a)) + 1) * 8)
|
---|
77 |
|
---|
78 | // This is the maxmimum length permissible by a extension header
|
---|
79 | // Length is UINT8 of 8 octets not including the first 8 octets
|
---|
80 | #define IP6_MAX_EXT_DATA_LENGTH (IP6_HDR_EXT_LEN (MAX_UINT8) - sizeof(IP6_EXT_HDR))
|
---|
81 | STATIC_ASSERT (
|
---|
82 | IP6_MAX_EXT_DATA_LENGTH == 2046,
|
---|
83 | "Maximum data length is ((MAX_UINT8 + 1) * 8) - 2"
|
---|
84 | );
|
---|
85 |
|
---|
86 | typedef struct _IP6_FRAGMENT_HEADER {
|
---|
87 | UINT8 NextHeader;
|
---|
88 | UINT8 Reserved;
|
---|
89 | UINT16 FragmentOffset;
|
---|
90 | UINT32 Identification;
|
---|
91 | } IP6_FRAGMENT_HEADER;
|
---|
92 |
|
---|
93 | typedef struct _IP6_ROUTING_HEADER {
|
---|
94 | UINT8 NextHeader;
|
---|
95 | UINT8 HeaderLen;
|
---|
96 | UINT8 RoutingType;
|
---|
97 | UINT8 SegmentsLeft;
|
---|
98 | } IP6_ROUTING_HEADER;
|
---|
99 |
|
---|
100 | typedef enum {
|
---|
101 | Ip6OptionPad1 = 0,
|
---|
102 | Ip6OptionPadN = 1,
|
---|
103 | Ip6OptionRouterAlert = 5,
|
---|
104 | Ip6OptionSkip = 0,
|
---|
105 | Ip6OptionDiscard = 0x40,
|
---|
106 | Ip6OptionParameterProblem = 0x80,
|
---|
107 | Ip6OptionMask = 0xc0,
|
---|
108 |
|
---|
109 | Ip6OptionEtherSource = 1,
|
---|
110 | Ip6OptionEtherTarget = 2,
|
---|
111 | Ip6OptionPrefixInfo = 3,
|
---|
112 | Ip6OptionRedirected = 4,
|
---|
113 | Ip6OptionMtu = 5
|
---|
114 | } IP6_OPTION_TYPE;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | Validate the IP6 extension header format for both the packets we received
|
---|
118 | and that we will transmit. It will compute the ICMPv6 error message fields
|
---|
119 | if the option is mal-formatted.
|
---|
120 |
|
---|
121 | @param[in] IpSb The IP6 service instance. This is an optional parameter.
|
---|
122 | @param[in] Packet The data of the packet. Ignored if NULL.
|
---|
123 | @param[in] NextHeader The next header field in IPv6 basic header.
|
---|
124 | @param[in] ExtHdrs The first byte of the option.
|
---|
125 | @param[in] ExtHdrsLen The length of the whole option.
|
---|
126 | @param[in] Rcvd The option is from the packet we received if TRUE,
|
---|
127 | otherwise, the option we want to transmit.
|
---|
128 | @param[out] FormerHeader The offset of NextHeader which points to Fragment
|
---|
129 | Header when we received, of the ExtHdrs.
|
---|
130 | Ignored if we transmit.
|
---|
131 | @param[out] LastHeader The pointer of NextHeader of the last extension
|
---|
132 | header processed by IP6.
|
---|
133 | @param[out] RealExtsLen The length of extension headers processed by IP6 layer.
|
---|
134 | This is an optional parameter that may be NULL.
|
---|
135 | @param[out] UnFragmentLen The length of unfragmented length of extension headers.
|
---|
136 | This is an optional parameter that may be NULL.
|
---|
137 | @param[out] Fragmented Indicate whether the packet is fragmented.
|
---|
138 | This is an optional parameter that may be NULL.
|
---|
139 |
|
---|
140 | @retval TRUE The option is properly formatted.
|
---|
141 | @retval FALSE The option is malformatted.
|
---|
142 |
|
---|
143 | **/
|
---|
144 | BOOLEAN
|
---|
145 | Ip6IsExtsValid (
|
---|
146 | IN IP6_SERVICE *IpSb OPTIONAL,
|
---|
147 | IN NET_BUF *Packet OPTIONAL,
|
---|
148 | IN UINT8 *NextHeader,
|
---|
149 | IN UINT8 *ExtHdrs,
|
---|
150 | IN UINT32 ExtHdrsLen,
|
---|
151 | IN BOOLEAN Rcvd,
|
---|
152 | OUT UINT32 *FormerHeader OPTIONAL,
|
---|
153 | OUT UINT8 **LastHeader,
|
---|
154 | OUT UINT32 *RealExtsLen OPTIONAL,
|
---|
155 | OUT UINT32 *UnFragmentLen OPTIONAL,
|
---|
156 | OUT BOOLEAN *Fragmented OPTIONAL
|
---|
157 | );
|
---|
158 |
|
---|
159 | /**
|
---|
160 | Generate an IPv6 router alert option in network order and output it through Buffer.
|
---|
161 |
|
---|
162 | @param[out] Buffer Points to a buffer to record the generated option.
|
---|
163 | @param[in, out] BufferLen The length of Buffer, in bytes.
|
---|
164 | @param[in] NextHeader The 8-bit selector indicates the type of header
|
---|
165 | immediately following the Hop-by-Hop Options header.
|
---|
166 |
|
---|
167 | @retval EFI_BUFFER_TOO_SMALL The Buffer is too small to contain the generated
|
---|
168 | option. BufferLen is updated for the required size.
|
---|
169 |
|
---|
170 | @retval EFI_SUCCESS The option is generated and filled in to Buffer.
|
---|
171 |
|
---|
172 | **/
|
---|
173 | EFI_STATUS
|
---|
174 | Ip6FillHopByHop (
|
---|
175 | OUT UINT8 *Buffer,
|
---|
176 | IN OUT UINTN *BufferLen,
|
---|
177 | IN UINT8 NextHeader
|
---|
178 | );
|
---|
179 |
|
---|
180 | /**
|
---|
181 | Insert a Fragment Header to the Extension headers and output it in UpdatedExtHdrs.
|
---|
182 |
|
---|
183 | @param[in] IpSb The IP6 service instance to transmit the packet.
|
---|
184 | @param[in] NextHeader The extension header type of first extension header.
|
---|
185 | @param[in] LastHeader The extension header type of last extension header.
|
---|
186 | @param[in] ExtHdrs The length of the original extension header.
|
---|
187 | @param[in] ExtHdrsLen The length of the extension headers.
|
---|
188 | @param[in] FragmentOffset The fragment offset of the data following the header.
|
---|
189 | @param[out] UpdatedExtHdrs The updated ExtHdrs with Fragment header inserted.
|
---|
190 | It's caller's responsibility to free this buffer.
|
---|
191 |
|
---|
192 | @retval EFI_OUT_OF_RESOURCES Failed to finish the operation due to lake of
|
---|
193 | resource.
|
---|
194 | @retval EFI_UNSUPPORTED The extension header specified in ExtHdrs is not
|
---|
195 | supported currently.
|
---|
196 | @retval EFI_SUCCESS The operation performed successfully.
|
---|
197 |
|
---|
198 | **/
|
---|
199 | EFI_STATUS
|
---|
200 | Ip6FillFragmentHeader (
|
---|
201 | IN IP6_SERVICE *IpSb,
|
---|
202 | IN UINT8 NextHeader,
|
---|
203 | IN UINT8 LastHeader,
|
---|
204 | IN UINT8 *ExtHdrs,
|
---|
205 | IN UINT32 ExtHdrsLen,
|
---|
206 | IN UINT16 FragmentOffset,
|
---|
207 | OUT UINT8 **UpdatedExtHdrs
|
---|
208 | );
|
---|
209 |
|
---|
210 | /**
|
---|
211 | Copy the extension headers from the original to buffer. A Fragment header is
|
---|
212 | appended to the end.
|
---|
213 |
|
---|
214 | @param[in] NextHeader The 8-bit selector indicates the type of
|
---|
215 | the fragment header's next header.
|
---|
216 | @param[in] ExtHdrs The length of the original extension header.
|
---|
217 | @param[in] LastHeader The pointer of next header of last extension header.
|
---|
218 | @param[in] FragmentOffset The fragment offset of the data following the header.
|
---|
219 | @param[in] UnFragmentHdrLen The length of unfragmented length of extension headers.
|
---|
220 | @param[in, out] Buf The buffer to copy options to.
|
---|
221 | @param[in, out] BufLen The length of the buffer.
|
---|
222 |
|
---|
223 | @retval EFI_SUCCESS The options are copied over.
|
---|
224 | @retval EFI_BUFFER_TOO_SMALL The buffer caller provided is too small.
|
---|
225 |
|
---|
226 | **/
|
---|
227 | EFI_STATUS
|
---|
228 | Ip6CopyExts (
|
---|
229 | IN UINT8 NextHeader,
|
---|
230 | IN UINT8 *ExtHdrs,
|
---|
231 | IN UINT8 *LastHeader,
|
---|
232 | IN UINT16 FragmentOffset,
|
---|
233 | IN UINT32 UnFragmentHdrLen,
|
---|
234 | IN OUT UINT8 *Buf,
|
---|
235 | IN OUT UINT32 *BufLen
|
---|
236 | );
|
---|
237 |
|
---|
238 | /**
|
---|
239 | Validate the IP6 option format for both the packets we received
|
---|
240 | and that we will transmit. It supports the defined options in Neighbor
|
---|
241 | Discovery messages.
|
---|
242 |
|
---|
243 | @param[in] Option The first byte of the option.
|
---|
244 | @param[in] OptionLen The length of the whole option.
|
---|
245 |
|
---|
246 | @retval TRUE The option is properly formatted.
|
---|
247 | @retval FALSE The option is malformatted.
|
---|
248 |
|
---|
249 | **/
|
---|
250 | BOOLEAN
|
---|
251 | Ip6IsNDOptionValid (
|
---|
252 | IN UINT8 *Option,
|
---|
253 | IN UINT16 OptionLen
|
---|
254 | );
|
---|
255 |
|
---|
256 | #endif
|
---|