2 To validate, parse and process the DHCP options.
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __EFI_DHCP4_OPTION_H__
16 #define __EFI_DHCP4_OPTION_H__
19 /// DHCP option tags (types)
22 #define DHCP_OPTION_MAGIC 0x63538263 // Network byte order
23 #define DHCP_MAX_OPTIONS 256
27 // DHCP option types, this is used to validate the DHCP options.
29 #define DHCP_OPTION_SWITCH 1
30 #define DHCP_OPTION_INT8 2
31 #define DHCP_OPTION_INT16 3
32 #define DHCP_OPTION_INT32 4
33 #define DHCP_OPTION_IP 5
34 #define DHCP_OPTION_IPPAIR 6
37 // Value of DHCP overload option
39 #define DHCP_OVERLOAD_FILENAME 1
40 #define DHCP_OVERLOAD_SVRNAME 2
41 #define DHCP_OVERLOAD_BOTH 3
44 /// The DHCP option structure. This structure extends the EFI_DHCP_OPTION
45 /// structure to support options longer than 255 bytes, such as classless route.
54 /// Structures used to parse the DHCP options with RFC3396 support.
62 DHCP_OPTION_COUNT
*OpCount
;
65 } DHCP_OPTION_CONTEXT
;
68 /// The options that matters to DHCP driver itself. The user of
69 /// DHCP clients may be interested in other options, such as
70 /// classless route, who can parse the DHCP offer to get them.
73 IP4_ADDR NetMask
; // DHCP4_TAG_NETMASK
74 IP4_ADDR Router
; // DHCP4_TAG_ROUTER, only the first router is used
77 // DHCP specific options
79 UINT8 DhcpType
; // DHCP4_TAG_MSG_TYPE
80 UINT8 Overload
; // DHCP4_TAG_OVERLOAD
81 IP4_ADDR ServerId
; // DHCP4_TAG_SERVER_ID
82 UINT32 Lease
; // DHCP4_TAG_LEASE
83 UINT32 T1
; // DHCP4_TAG_T1
84 UINT32 T2
; // DHCP4_TAG_T2
88 /// Structure used to describe and validate the format of DHCP options.
89 /// Type is the options' data type, such as DHCP_OPTION_INT8. MinOccur
90 /// is the minium occurance of this data type. MaxOccur is defined
91 /// similarly. If MaxOccur is -1, it means that there is no limit on the
92 /// maximum occurance. Alert tells whether DHCP client should further
93 /// inspect the option to parse DHCP_PARAMETER.
101 } DHCP_OPTION_FORMAT
;
105 (*DHCP_CHECK_OPTION
) (
113 Iterate through a DHCP message to visit each option. First inspect
114 all the options in the OPTION field. Then if overloaded, inspect
115 the options in FILENAME and SERVERNAME fields. One option may be
116 encoded in several places. See RFC 3396 Encoding Long Options in DHCP
118 @param[in] Packet The DHCP packet to check the options for
119 @param[in] Check The callback function to be called for each option
121 @param[in] Context The opaque parameter for Check
123 @retval EFI_SUCCESS The DHCP packet's options are well formated
124 @retval EFI_INVALID_PARAMETER The DHCP packet's options are not well formated
129 IN EFI_DHCP4_PACKET
*Packet
,
130 IN DHCP_CHECK_OPTION Check OPTIONAL
,
135 Validate the packet's options. If necessary, allocate
136 and fill in the interested parameters.
138 @param[in] Packet The packet to validate the options
139 @param[out] Para The variable to save the DHCP parameters.
141 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to validate the packet.
142 @retval EFI_INVALID_PARAMETER The options are mal-formated
143 @retval EFI_SUCCESS The options are parsed into OptionPoint
147 DhcpValidateOptions (
148 IN EFI_DHCP4_PACKET
*Packet
,
149 OUT DHCP_PARAMETER
**Para OPTIONAL
153 Parse the options of a DHCP packet. It supports RFC 3396: Encoding
154 Long Options in DHCP. That is, it will combine all the option value
155 of all the occurances of each option.
156 A little bit of implemenation:
157 It adopts the "Key indexed counting" algorithm. First, it allocates
158 an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded
159 as a UINT8. It then iterates the DHCP packet to get data length of
160 each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it
161 knows the number of present options and their length. It allocates a
162 array of DHCP_OPTION and a continuous buffer after the array to put
163 all the options' data. Each option's data is pointed to by the Data
164 field in DHCP_OPTION structure. At last, it call DhcpIterateOptions
165 with DhcpFillOption to fill each option's data to its position in the
168 @param[in] Packet The DHCP packet to parse the options
169 @param[out] Count The number of valid dhcp options present in the
171 @param[out] OptionPoint The array that contains the DHCP options. Caller
174 @retval EFI_NOT_FOUND Cannot find any option.
175 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to parse the packet.
176 @retval EFI_INVALID_PARAMETER The options are mal-formated
177 @retval EFI_SUCCESS The options are parsed into OptionPoint
182 IN EFI_DHCP4_PACKET
*Packet
,
184 OUT DHCP_OPTION
**OptionPoint
188 Append an option to the memory, if the option is longer than
189 255 bytes, splits it into several options.
191 @param[out] Buf The buffer to append the option to
192 @param[in] Tag The option's tag
193 @param[in] DataLen The length of the option's data
194 @param[in] Data The option's data
196 @return The position to append the next option
208 Build a new DHCP packet from a seed packet. Options may be deleted or
209 appended. The caller should free the NewPacket when finished using it.
211 @param[in] SeedPacket The seed packet to start with
212 @param[in] DeleteCount The number of options to delete
213 @param[in] DeleteList The options to delete from the packet
214 @param[in] AppendCount The number of options to append
215 @param[in] AppendList The options to append to the packet
216 @param[out] NewPacket The new packet, allocated and built by this
219 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory
220 @retval EFI_INVALID_PARAMETER The options in SeekPacket are mal-formated
221 @retval EFI_SUCCESS The packet is build.
226 IN EFI_DHCP4_PACKET
*SeedPacket
,
227 IN UINT32 DeleteCount
,
228 IN UINT8
*DeleteList OPTIONAL
,
229 IN UINT32 AppendCount
,
230 IN EFI_DHCP4_PACKET_OPTION
*AppendList
[] OPTIONAL
,
231 OUT EFI_DHCP4_PACKET
**NewPacket