]>
Commit | Line | Data |
---|---|---|
83cbd279 | 1 | /** @file\r |
3e8c18da | 2 | To validate, parse and process the DHCP options.\r |
3 | \r | |
e5eed7d3 HT |
4 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
83cbd279 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
83cbd279 | 13 | **/\r |
14 | \r | |
15 | #ifndef __EFI_DHCP4_OPTION_H__\r | |
16 | #define __EFI_DHCP4_OPTION_H__\r | |
17 | \r | |
f9204641 | 18 | ///\r |
19 | /// DHCP option tags (types)\r | |
20 | ///\r | |
f6b7393c | 21 | \r |
22 | //\r | |
23 | // RFC1497 vendor extensions\r | |
24 | //\r | |
25 | #define DHCP_TAG_PAD 0 // Pad Option\r | |
26 | #define DHCP_TAG_EOP 255 // End Option\r | |
27 | #define DHCP_TAG_NETMASK 1 // Subnet Mask\r | |
28 | #define DHCP_TAG_TIME_OFFSET 2 // Time Offset from UTC\r | |
29 | #define DHCP_TAG_ROUTER 3 // Router option,\r | |
30 | #define DHCP_TAG_TIME_SERVER 4 // Time Server\r | |
31 | #define DHCP_TAG_NAME_SERVER 5 // Name Server\r | |
32 | #define DHCP_TAG_DNS_SERVER 6 // Domain Name Server\r | |
33 | #define DHCP_TAG_LOG_SERVER 7 // Log Server\r | |
34 | #define DHCP_TAG_COOKIE_SERVER 8 // Cookie Server\r | |
35 | #define DHCP_TAG_LPR_SERVER 9 // LPR Print Server\r | |
36 | #define DHCP_TAG_IMPRESS_SERVER 10 // Impress Server\r | |
37 | #define DHCP_TAG_RL_SERVER 11 // Resource Location Server\r | |
38 | #define DHCP_TAG_HOSTNAME 12 // Host Name\r | |
39 | #define DHCP_TAG_BOOTFILE_LEN 13 // Boot File Size\r | |
40 | #define DHCP_TAG_DUMP 14 // Merit Dump File\r | |
41 | #define DHCP_TAG_DOMAINNAME 15 // Domain Name\r | |
42 | #define DHCP_TAG_SWAP_SERVER 16 // Swap Server\r | |
43 | #define DHCP_TAG_ROOTPATH 17 // Root path\r | |
44 | #define DHCP_TAG_EXTEND_PATH 18 // Extensions Path\r | |
45 | \r | |
46 | //\r | |
47 | // IP Layer Parameters per Host\r | |
48 | //\r | |
49 | #define DHCP_TAG_IPFORWARD 19 // IP Forwarding Enable/Disable\r | |
50 | #define DHCP_TAG_NONLOCAL_SRR 20 // on-Local Source Routing Enable/Disable\r | |
51 | #define DHCP_TAG_POLICY_SRR 21 // Policy Filter\r | |
52 | #define DHCP_TAG_EMTU 22 // Maximum Datagram Reassembly Size\r | |
53 | #define DHCP_TAG_TTL 23 // Default IP Time-to-live\r | |
54 | #define DHCP_TAG_PATHMTU_AGE 24 // Path MTU Aging Timeout\r | |
55 | #define DHCP_TAG_PATHMTU_PLATEAU 25 // Path MTU Plateau Table\r | |
56 | \r | |
57 | //\r | |
58 | // IP Layer Parameters per Interface\r | |
59 | //\r | |
60 | #define DHCP_TAG_IFMTU 26 // Interface MTU\r | |
61 | #define DHCP_TAG_SUBNET_LOCAL 27 // All Subnets are Local\r | |
62 | #define DHCP_TAG_BROADCAST 28 // Broadcast Address\r | |
63 | #define DHCP_TAG_DISCOVER_MASK 29 // Perform Mask Discovery\r | |
64 | #define DHCP_TAG_SUPPLY_MASK 30 // Mask Supplier\r | |
65 | #define DHCP_TAG_DISCOVER_ROUTE 31 // Perform Router Discovery\r | |
66 | #define DHCP_TAG_ROUTER_SOLICIT 32 // Router Solicitation Address\r | |
67 | #define DHCP_TAG_STATIC_ROUTE 33 // Static Route\r | |
68 | \r | |
69 | //\r | |
70 | // Link Layer Parameters per Interface\r | |
71 | //\r | |
72 | #define DHCP_TAG_TRAILER 34 // Trailer Encapsulation\r | |
73 | #define DHCP_TAG_ARPAGE 35 // ARP Cache Timeout\r | |
74 | #define DHCP_TAG_ETHER_ENCAP 36 // Ethernet Encapsulation\r | |
75 | \r | |
76 | //\r | |
77 | // TCP Parameters\r | |
78 | //\r | |
79 | #define DHCP_TAG_TCP_TTL 37 // TCP Default TTL\r | |
80 | #define DHCP_TAG_KEEP_INTERVAL 38 // TCP Keepalive Interval\r | |
81 | #define DHCP_TAG_KEEP_GARBAGE 39 // TCP Keepalive Garbage\r | |
82 | \r | |
83 | //\r | |
84 | // Application and Service Parameters\r | |
85 | //\r | |
86 | #define DHCP_TAG_NIS_DOMAIN 40 // Network Information Service Domain\r | |
87 | #define DHCP_TAG_NIS_SERVER 41 // Network Information Servers\r | |
88 | #define DHCP_TAG_NTP_SERVER 42 // Network Time Protocol Servers\r | |
89 | #define DHCP_TAG_VENDOR 43 // Vendor Specific Information\r | |
90 | #define DHCP_TAG_NBNS 44 // NetBIOS over TCP/IP Name Server\r | |
91 | #define DHCP_TAG_NBDD 45 // NetBIOS Datagram Distribution Server\r | |
92 | #define DHCP_TAG_NBTYPE 46 // NetBIOS over TCP/IP Node Type\r | |
93 | #define DHCP_TAG_NBSCOPE 47 // NetBIOS over TCP/IP Scope\r | |
94 | #define DHCP_TAG_XFONT 48 // X Window System Font Server\r | |
95 | #define DHCP_TAG_XDM 49 // X Window System Display Manager\r | |
96 | #define DHCP_TAG_NISPLUS 64 // Network Information Service+ Domain\r | |
97 | #define DHCP_TAG_NISPLUS_SERVER 65 // Network Information Service+ Servers\r | |
98 | #define DHCP_TAG_MOBILEIP 68 // Mobile IP Home Agent\r | |
99 | #define DHCP_TAG_SMTP 69 // Simple Mail Transport Protocol Server\r | |
100 | #define DHCP_TAG_POP3 70 // Post Office Protocol (POP3) Server\r | |
101 | #define DHCP_TAG_NNTP 71 // Network News Transport Protocol Server\r | |
102 | #define DHCP_TAG_WWW 72 // Default World Wide Web (WWW) Server\r | |
103 | #define DHCP_TAG_FINGER 73 // Default Finger Server\r | |
104 | #define DHCP_TAG_IRC 74 // Default Internet Relay Chat (IRC) Server\r | |
105 | #define DHCP_TAG_STTALK 75 // StreetTalk Server\r | |
106 | #define DHCP_TAG_STDA 76 // StreetTalk Directory Assistance Server\r | |
107 | #define DHCP_TAG_CLASSLESS_ROUTE 121 // Classless Route\r | |
108 | \r | |
109 | //\r | |
110 | // DHCP Extensions\r | |
111 | //\r | |
112 | #define DHCP_TAG_REQUEST_IP 50 // Requested IP Address\r | |
113 | #define DHCP_TAG_LEASE 51 // IP Address Lease Time\r | |
114 | #define DHCP_TAG_OVERLOAD 52 // Option Overload\r | |
115 | #define DHCP_TAG_TFTP 66 // TFTP server name\r | |
116 | #define DHCP_TAG_BOOTFILE 67 // Bootfile name\r | |
117 | #define DHCP_TAG_TYPE 53 // DHCP Message Type\r | |
118 | #define DHCP_TAG_SERVER_ID 54 // Server Identifier\r | |
119 | #define DHCP_TAG_PARA_LIST 55 // Parameter Request List\r | |
120 | #define DHCP_TAG_MESSAGE 56 // Message\r | |
121 | #define DHCP_TAG_MAXMSG 57 // Maximum DHCP Message Size\r | |
122 | #define DHCP_TAG_T1 58 // Renewal (T1) Time Value\r | |
123 | #define DHCP_TAG_T2 59 // Rebinding (T2) Time Value\r | |
124 | #define DHCP_TAG_VENDOR_CLASS 60 // Vendor class identifier\r | |
125 | #define DHCP_TAG_CLIENT_ID 61 // Client-identifier\r | |
126 | \r | |
127 | \r | |
128 | #define DHCP_OPTION_MAGIC 0x63538263 // Network byte order\r | |
129 | #define DHCP_MAX_OPTIONS 256\r | |
130 | \r | |
131 | \r | |
132 | //\r | |
133 | // DHCP option types, this is used to validate the DHCP options.\r | |
134 | //\r | |
135 | #define DHCP_OPTION_SWITCH 1\r | |
136 | #define DHCP_OPTION_INT8 2\r | |
137 | #define DHCP_OPTION_INT16 3\r | |
138 | #define DHCP_OPTION_INT32 4\r | |
139 | #define DHCP_OPTION_IP 5\r | |
140 | #define DHCP_OPTION_IPPAIR 6\r | |
141 | \r | |
142 | //\r | |
143 | // Value of DHCP overload option\r | |
144 | //\r | |
145 | #define DHCP_OVERLOAD_FILENAME 1\r | |
146 | #define DHCP_OVERLOAD_SVRNAME 2\r | |
147 | #define DHCP_OVERLOAD_BOTH 3\r | |
83cbd279 | 148 | \r |
f9204641 | 149 | ///\r |
150 | /// The DHCP option structure. This structure extends the EFI_DHCP_OPTION\r | |
151 | /// structure to support options longer than 255 bytes, such as classless route.\r | |
152 | ///\r | |
83cbd279 | 153 | typedef struct {\r |
154 | UINT8 Tag;\r | |
155 | UINT16 Len;\r | |
156 | UINT8 *Data;\r | |
157 | } DHCP_OPTION;\r | |
158 | \r | |
f9204641 | 159 | ///\r |
160 | /// Structures used to parse the DHCP options with RFC3396 support.\r | |
161 | ///\r | |
83cbd279 | 162 | typedef struct {\r |
163 | UINT8 Index;\r | |
164 | UINT16 Offset;\r | |
165 | } DHCP_OPTION_COUNT;\r | |
166 | \r | |
167 | typedef struct {\r | |
168 | DHCP_OPTION_COUNT *OpCount;\r | |
169 | DHCP_OPTION *Options;\r | |
170 | UINT8 *Buf;\r | |
171 | } DHCP_OPTION_CONTEXT;\r | |
172 | \r | |
f9204641 | 173 | ///\r |
174 | /// The options that matters to DHCP driver itself. The user of\r | |
175 | /// DHCP clients may be interested in other options, such as\r | |
176 | /// classless route, who can parse the DHCP offer to get them.\r | |
177 | ///\r | |
83cbd279 | 178 | typedef struct {\r |
179 | IP4_ADDR NetMask; // DHCP_TAG_NETMASK\r | |
180 | IP4_ADDR Router; // DHCP_TAG_ROUTER, only the first router is used\r | |
181 | \r | |
182 | //\r | |
183 | // DHCP specific options\r | |
184 | //\r | |
185 | UINT8 DhcpType; // DHCP_TAG_TYPE\r | |
186 | UINT8 Overload; // DHCP_TAG_OVERLOAD\r | |
187 | IP4_ADDR ServerId; // DHCP_TAG_SERVER_ID\r | |
188 | UINT32 Lease; // DHCP_TAG_LEASE\r | |
189 | UINT32 T1; // DHCP_TAG_T1\r | |
190 | UINT32 T2; // DHCP_TAG_T2\r | |
191 | } DHCP_PARAMETER;\r | |
192 | \r | |
f9204641 | 193 | ///\r |
194 | /// Structure used to describe and validate the format of DHCP options.\r | |
195 | /// Type is the options' data type, such as DHCP_OPTION_INT8. MinOccur\r | |
196 | /// is the minium occurance of this data type. MaxOccur is defined\r | |
197 | /// similarly. If MaxOccur is -1, it means that there is no limit on the\r | |
198 | /// maximum occurance. Alert tells whether DHCP client should further\r | |
199 | /// inspect the option to parse DHCP_PARAMETER.\r | |
200 | ///\r | |
83cbd279 | 201 | typedef struct {\r |
202 | UINT8 Tag;\r | |
203 | INTN Type;\r | |
204 | INTN MinOccur;\r | |
205 | INTN MaxOccur;\r | |
206 | BOOLEAN Alert;\r | |
207 | } DHCP_OPTION_FORMAT;\r | |
208 | \r | |
209 | typedef\r | |
210 | EFI_STATUS\r | |
211 | (*DHCP_CHECK_OPTION) (\r | |
212 | IN UINT8 Tag,\r | |
213 | IN UINT8 Len,\r | |
214 | IN UINT8 *Data,\r | |
215 | IN VOID *Context\r | |
216 | );\r | |
217 | \r | |
7bce0c5a | 218 | /**\r |
219 | Iterate through a DHCP message to visit each option. First inspect\r | |
220 | all the options in the OPTION field. Then if overloaded, inspect\r | |
221 | the options in FILENAME and SERVERNAME fields. One option may be\r | |
222 | encoded in several places. See RFC 3396 Encoding Long Options in DHCP\r | |
223 | \r | |
3e8c18da | 224 | @param[in] Packet The DHCP packet to check the options for\r |
225 | @param[in] Check The callback function to be called for each option\r | |
226 | found\r | |
227 | @param[in] Context The opaque parameter for Check\r | |
7bce0c5a | 228 | \r |
229 | @retval EFI_SUCCESS The DHCP packet's options are well formated\r | |
ed729a0c | 230 | @retval EFI_INVALID_PARAMETER The DHCP packet's options are not well formated\r |
7bce0c5a | 231 | \r |
232 | **/\r | |
83cbd279 | 233 | EFI_STATUS\r |
234 | DhcpIterateOptions (\r | |
235 | IN EFI_DHCP4_PACKET *Packet,\r | |
24af132f | 236 | IN DHCP_CHECK_OPTION Check OPTIONAL,\r |
83cbd279 | 237 | IN VOID *Context\r |
238 | );\r | |
239 | \r | |
7bce0c5a | 240 | /**\r |
241 | Validate the packet's options. If necessary, allocate\r | |
242 | and fill in the interested parameters.\r | |
243 | \r | |
3e8c18da | 244 | @param[in] Packet The packet to validate the options\r |
245 | @param[out] Para The variable to save the DHCP parameters.\r | |
7bce0c5a | 246 | \r |
247 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to validate the packet.\r | |
248 | @retval EFI_INVALID_PARAMETER The options are mal-formated\r | |
249 | @retval EFI_SUCCESS The options are parsed into OptionPoint\r | |
250 | \r | |
251 | **/\r | |
83cbd279 | 252 | EFI_STATUS\r |
253 | DhcpValidateOptions (\r | |
254 | IN EFI_DHCP4_PACKET *Packet,\r | |
ed729a0c | 255 | OUT DHCP_PARAMETER **Para OPTIONAL\r |
83cbd279 | 256 | );\r |
257 | \r | |
7bce0c5a | 258 | /**\r |
259 | Parse the options of a DHCP packet. It supports RFC 3396: Encoding\r | |
260 | Long Options in DHCP. That is, it will combine all the option value\r | |
261 | of all the occurances of each option.\r | |
262 | A little bit of implemenation:\r | |
263 | It adopts the "Key indexed counting" algorithm. First, it allocates\r | |
264 | an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded\r | |
265 | as a UINT8. It then iterates the DHCP packet to get data length of\r | |
266 | each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it\r | |
267 | knows the number of present options and their length. It allocates a\r | |
ed729a0c | 268 | array of DHCP_OPTION and a continuous buffer after the array to put\r |
7bce0c5a | 269 | all the options' data. Each option's data is pointed to by the Data\r |
270 | field in DHCP_OPTION structure. At last, it call DhcpIterateOptions\r | |
271 | with DhcpFillOption to fill each option's data to its position in the\r | |
272 | buffer.\r | |
273 | \r | |
3e8c18da | 274 | @param[in] Packet The DHCP packet to parse the options\r |
275 | @param[out] Count The number of valid dhcp options present in the\r | |
276 | packet\r | |
277 | @param[out] OptionPoint The array that contains the DHCP options. Caller\r | |
278 | should free it.\r | |
7bce0c5a | 279 | \r |
7b0ae7e8 | 280 | @retval EFI_NOT_FOUND Cannot find any option.\r |
7bce0c5a | 281 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory to parse the packet.\r |
282 | @retval EFI_INVALID_PARAMETER The options are mal-formated\r | |
283 | @retval EFI_SUCCESS The options are parsed into OptionPoint\r | |
284 | \r | |
285 | **/\r | |
83cbd279 | 286 | EFI_STATUS\r |
287 | DhcpParseOption (\r | |
288 | IN EFI_DHCP4_PACKET *Packet,\r | |
289 | OUT INTN *Count,\r | |
290 | OUT DHCP_OPTION **OptionPoint\r | |
291 | );\r | |
292 | \r | |
7bce0c5a | 293 | /**\r |
294 | Append an option to the memory, if the option is longer than\r | |
295 | 255 bytes, splits it into several options.\r | |
296 | \r | |
3e8c18da | 297 | @param[out] Buf The buffer to append the option to\r |
298 | @param[in] Tag The option's tag\r | |
299 | @param[in] DataLen The length of the option's data\r | |
300 | @param[in] Data The option's data\r | |
7bce0c5a | 301 | \r |
302 | @return The position to append the next option\r | |
303 | \r | |
304 | **/\r | |
83cbd279 | 305 | UINT8 *\r |
306 | DhcpAppendOption (\r | |
ed729a0c | 307 | OUT UINT8 *Buf,\r |
308 | IN UINT8 Tag,\r | |
309 | IN UINT16 DataLen,\r | |
310 | IN UINT8 *Data\r | |
83cbd279 | 311 | );\r |
312 | \r | |
7bce0c5a | 313 | /**\r |
314 | Build a new DHCP packet from a seed packet. Options may be deleted or\r | |
315 | appended. The caller should free the NewPacket when finished using it.\r | |
316 | \r | |
3e8c18da | 317 | @param[in] SeedPacket The seed packet to start with\r |
318 | @param[in] DeleteCount The number of options to delete\r | |
319 | @param[in] DeleteList The options to delete from the packet\r | |
320 | @param[in] AppendCount The number of options to append\r | |
321 | @param[in] AppendList The options to append to the packet\r | |
322 | @param[out] NewPacket The new packet, allocated and built by this\r | |
323 | function.\r | |
7bce0c5a | 324 | \r |
325 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory\r | |
ed729a0c | 326 | @retval EFI_INVALID_PARAMETER The options in SeekPacket are mal-formated\r |
7bce0c5a | 327 | @retval EFI_SUCCESS The packet is build.\r |
328 | \r | |
329 | **/\r | |
83cbd279 | 330 | EFI_STATUS\r |
331 | DhcpBuild (\r | |
ed729a0c | 332 | IN EFI_DHCP4_PACKET *SeedPacket,\r |
333 | IN UINT32 DeleteCount,\r | |
334 | IN UINT8 *DeleteList OPTIONAL,\r | |
335 | IN UINT32 AppendCount,\r | |
336 | IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL,\r | |
337 | OUT EFI_DHCP4_PACKET **NewPacket\r | |
83cbd279 | 338 | );\r |
339 | \r | |
340 | #endif\r |