]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg/Ip4Dxe: Ignore duplicated DNS address check
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.h
... / ...
CommitLineData
1/** @file\r
2 Ip4 internal functions and type defintions.\r
3 \r
4Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
5(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
6\r
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef __EFI_IP4_IMPL_H__\r
18#define __EFI_IP4_IMPL_H__\r
19\r
20#include <Uefi.h>\r
21\r
22#include <Protocol/IpSec.h>\r
23#include <Protocol/Ip4.h>\r
24#include <Protocol/Ip4Config2.h>\r
25#include <Protocol/Arp.h>\r
26#include <Protocol/ManagedNetwork.h>\r
27#include <Protocol/Dhcp4.h>\r
28#include <Protocol/HiiConfigRouting.h>\r
29#include <Protocol/HiiConfigAccess.h>\r
30\r
31#include <IndustryStandard/Dhcp.h>\r
32\r
33#include <Library/DebugLib.h>\r
34#include <Library/UefiRuntimeServicesTableLib.h>\r
35#include <Library/UefiDriverEntryPoint.h>\r
36#include <Library/UefiBootServicesTableLib.h>\r
37#include <Library/BaseLib.h>\r
38#include <Library/UefiLib.h>\r
39#include <Library/NetLib.h>\r
40#include <Library/BaseMemoryLib.h>\r
41#include <Library/MemoryAllocationLib.h>\r
42#include <Library/DpcLib.h>\r
43#include <Library/PrintLib.h>\r
44#include <Library/DevicePathLib.h>\r
45#include <Library/HiiLib.h>\r
46#include <Library/UefiHiiServicesLib.h>\r
47\r
48#include "Ip4Common.h"\r
49#include "Ip4Driver.h"\r
50#include "Ip4If.h"\r
51#include "Ip4Icmp.h"\r
52#include "Ip4Option.h"\r
53#include "Ip4Igmp.h"\r
54#include "Ip4Route.h"\r
55#include "Ip4Input.h"\r
56#include "Ip4Output.h"\r
57#include "Ip4Config2Impl.h"\r
58#include "Ip4Config2Nv.h"\r
59#include "Ip4NvData.h"\r
60\r
61#define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')\r
62#define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')\r
63\r
64//\r
65// The state of IP4 protocol. It starts from UNCONFIGED. if it is\r
66// successfully configured, it goes to CONFIGED. if configure NULL\r
67// is called, it becomes UNCONFIGED again. If (partly) destroyed, it\r
68// becomes DESTROY.\r
69//\r
70#define IP4_STATE_UNCONFIGED 0\r
71#define IP4_STATE_CONFIGED 1\r
72#define IP4_STATE_DESTROY 2\r
73\r
74//\r
75// The state of IP4 service. It starts from UNSTARTED. It transits\r
76// to STARTED if autoconfigure is started. If default address is\r
77// configured, it becomes CONFIGED. and if partly destroyed, it goes\r
78// to DESTROY.\r
79//\r
80#define IP4_SERVICE_UNSTARTED 0\r
81#define IP4_SERVICE_STARTED 1\r
82#define IP4_SERVICE_CONFIGED 2\r
83#define IP4_SERVICE_DESTROY 3\r
84\r
85\r
86///\r
87/// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.\r
88/// The user's data is kept in the Packet. When fragment is\r
89/// needed, each fragment of the Packet has a reference to the\r
90/// Packet, no data is actually copied. The Packet will be\r
91/// released when all the fragments of it have been recycled by\r
92/// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and\r
93/// user's event signalled.\r
94///\r
95typedef struct {\r
96 IP4_PROTOCOL *IpInstance;\r
97 EFI_IP4_COMPLETION_TOKEN *Token;\r
98 EFI_EVENT IpSecRecycleSignal;\r
99 NET_BUF *Packet;\r
100 BOOLEAN Sent;\r
101 INTN Life;\r
102} IP4_TXTOKEN_WRAP;\r
103\r
104///\r
105/// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r
106/// will be released after it has been processed by the receiver. Upon then,\r
107/// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r
108/// to notice IPsec to free the resources.\r
109///\r
110typedef struct {\r
111 EFI_EVENT IpSecRecycleSignal;\r
112 NET_BUF *Packet;\r
113} IP4_IPSEC_WRAP;\r
114\r
115///\r
116/// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r
117/// upper layers. The received packet is kept in the Packet.\r
118/// The Packet itself may be constructured from some fragments.\r
119/// All the fragments of the Packet is organized by a\r
120/// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by\r
121/// the upper layer, the assemble entry and its associated\r
122/// fragments will be freed at last.\r
123///\r
124typedef struct {\r
125 LIST_ENTRY Link;\r
126 IP4_PROTOCOL *IpInstance;\r
127 NET_BUF *Packet;\r
128 EFI_IP4_RECEIVE_DATA RxData;\r
129} IP4_RXDATA_WRAP;\r
130\r
131\r
132struct _IP4_PROTOCOL {\r
133 UINT32 Signature;\r
134\r
135 EFI_IP4_PROTOCOL Ip4Proto;\r
136 EFI_HANDLE Handle;\r
137 INTN State;\r
138\r
139 IP4_SERVICE *Service;\r
140 LIST_ENTRY Link; // Link to all the IP protocol from the service\r
141\r
142 //\r
143 // User's transmit/receive tokens, and received/deliverd packets\r
144 //\r
145 NET_MAP RxTokens;\r
146 NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)\r
147 LIST_ENTRY Received; // Received but not delivered packet\r
148 LIST_ENTRY Delivered; // Delivered and to be recycled packets\r
149 EFI_LOCK RecycleLock;\r
150\r
151 //\r
152 // Instance's address and route tables. There are two route tables.\r
153 // RouteTable is used by the IP4 driver to route packet. EfiRouteTable\r
154 // is used to communicate the current route info to the upper layer.\r
155 //\r
156 IP4_INTERFACE *Interface;\r
157 LIST_ENTRY AddrLink; // Ip instances with the same IP address.\r
158 IP4_ROUTE_TABLE *RouteTable;\r
159\r
160 EFI_IP4_ROUTE_TABLE *EfiRouteTable;\r
161 UINT32 EfiRouteCount;\r
162\r
163 //\r
164 // IGMP data for this instance\r
165 //\r
166 IP4_ADDR *Groups; // stored in network byte order\r
167 UINT32 GroupCount;\r
168\r
169 EFI_IP4_CONFIG_DATA ConfigData;\r
170\r
171};\r
172\r
173struct _IP4_SERVICE {\r
174 UINT32 Signature;\r
175 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r
176 INTN State;\r
177\r
178 //\r
179 // List of all the IP instances and interfaces, and default\r
180 // interface and route table and caches.\r
181 //\r
182 UINTN NumChildren;\r
183 LIST_ENTRY Children;\r
184\r
185 LIST_ENTRY Interfaces;\r
186\r
187 IP4_INTERFACE *DefaultInterface;\r
188 IP4_ROUTE_TABLE *DefaultRouteTable;\r
189\r
190 //\r
191 // Ip reassemble utilities, and IGMP data\r
192 //\r
193 IP4_ASSEMBLE_TABLE Assemble;\r
194 IGMP_SERVICE_DATA IgmpCtrl;\r
195\r
196 //\r
197 // Low level protocol used by this service instance\r
198 //\r
199 EFI_HANDLE Image;\r
200 EFI_HANDLE Controller;\r
201\r
202 EFI_HANDLE MnpChildHandle;\r
203 EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
204\r
205 EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;\r
206 EFI_SIMPLE_NETWORK_MODE SnpMode;\r
207\r
208 EFI_EVENT Timer;\r
209\r
210 EFI_EVENT ReconfigEvent;\r
211\r
212 BOOLEAN Reconfig;\r
213\r
214 //\r
215 // Underlying media present status. \r
216 //\r
217 BOOLEAN MediaPresent;\r
218\r
219 //\r
220 // IPv4 Configuration II Protocol instance\r
221 //\r
222 IP4_CONFIG2_INSTANCE Ip4Config2Instance;\r
223\r
224 CHAR16 *MacString;\r
225\r
226 UINT32 MaxPacketSize;\r
227 UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.\r
228};\r
229\r
230#define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r
231 CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)\r
232\r
233#define IP4_SERVICE_FROM_PROTOCOL(Sb) \\r
234 CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)\r
235\r
236#define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \\r
237 CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)\r
238\r
239\r
240#define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)\r
241\r
242extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;\r
243\r
244/**\r
245 Config the MNP parameter used by IP. The IP driver use one MNP\r
246 child to transmit/receive frames. By default, it configures MNP\r
247 to receive unicast/multicast/broadcast. And it will enable/disable\r
248 the promiscous receive according to whether there is IP child\r
249 enable that or not. If Force is FALSE, it will iterate through\r
250 all the IP children to check whether the promiscuous receive\r
251 setting has been changed. If it hasn't been changed, it won't\r
252 reconfigure the MNP. If Force is TRUE, the MNP is configured no\r
253 matter whether that is changed or not.\r
254\r
255 @param[in] IpSb The IP4 service instance that is to be changed.\r
256 @param[in] Force Force the configuration or not.\r
257\r
258 @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r
259 @retval Others Configuration failed.\r
260\r
261**/\r
262EFI_STATUS\r
263Ip4ServiceConfigMnp (\r
264 IN IP4_SERVICE *IpSb,\r
265 IN BOOLEAN Force\r
266 );\r
267\r
268/**\r
269 Intiialize the IP4_PROTOCOL structure to the unconfigured states.\r
270\r
271 @param IpSb The IP4 service instance.\r
272 @param IpInstance The IP4 child instance.\r
273\r
274**/\r
275VOID\r
276Ip4InitProtocol (\r
277 IN IP4_SERVICE *IpSb,\r
278 IN OUT IP4_PROTOCOL *IpInstance\r
279 );\r
280\r
281/**\r
282 Clean up the IP4 child, release all the resources used by it.\r
283\r
284 @param[in] IpInstance The IP4 child to clean up.\r
285\r
286 @retval EFI_SUCCESS The IP4 child is cleaned up.\r
287 @retval EFI_DEVICE_ERROR Some resources failed to be released.\r
288\r
289**/\r
290EFI_STATUS\r
291Ip4CleanProtocol (\r
292 IN IP4_PROTOCOL *IpInstance\r
293 );\r
294\r
295/**\r
296 Cancel the user's receive/transmit request.\r
297\r
298 @param[in] IpInstance The IP4 child.\r
299 @param[in] Token The token to cancel. If NULL, all token will be\r
300 cancelled.\r
301\r
302 @retval EFI_SUCCESS The token is cancelled.\r
303 @retval EFI_NOT_FOUND The token isn't found on either the\r
304 transmit/receive queue.\r
305 @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r
306\r
307**/\r
308EFI_STATUS\r
309Ip4Cancel (\r
310 IN IP4_PROTOCOL *IpInstance,\r
311 IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r
312 );\r
313\r
314/**\r
315 Change the IP4 child's multicast setting. The caller\r
316 should make sure that the parameters is valid.\r
317\r
318 @param[in] IpInstance The IP4 child to change the setting.\r
319 @param[in] JoinFlag TRUE to join the group, otherwise leave it\r
320 @param[in] GroupAddress The target group address\r
321\r
322 @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r
323 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r
324 @retval EFI_DEVICE_ERROR Failed to set the group configuraton\r
325 @retval EFI_SUCCESS Successfully updated the group setting.\r
326 @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r
327\r
328**/\r
329EFI_STATUS\r
330Ip4Groups (\r
331 IN IP4_PROTOCOL *IpInstance,\r
332 IN BOOLEAN JoinFlag,\r
333 IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r
334 );\r
335\r
336/**\r
337 The heart beat timer of IP4 service instance. It times out\r
338 all of its IP4 children's received-but-not-delivered and\r
339 transmitted-but-not-recycle packets, and provides time input\r
340 for its IGMP protocol.\r
341\r
342 @param[in] Event The IP4 service instance's heart beat timer.\r
343 @param[in] Context The IP4 service instance.\r
344\r
345**/\r
346VOID\r
347EFIAPI\r
348Ip4TimerTicking (\r
349 IN EFI_EVENT Event,\r
350 IN VOID *Context\r
351 );\r
352\r
353/**\r
354 Decrease the life of the transmitted packets. If it is\r
355 decreased to zero, cancel the packet. This function is\r
356 called by Ip4PacketTimerTicking which time out both the\r
357 received-but-not-delivered and transmitted-but-not-recycle\r
358 packets.\r
359\r
360 @param[in] Map The IP4 child's transmit map.\r
361 @param[in] Item Current transmitted packet.\r
362 @param[in] Context Not used.\r
363\r
364 @retval EFI_SUCCESS Always returns EFI_SUCCESS.\r
365\r
366**/\r
367EFI_STATUS\r
368EFIAPI\r
369Ip4SentPacketTicking (\r
370 IN NET_MAP *Map,\r
371 IN NET_MAP_ITEM *Item,\r
372 IN VOID *Context\r
373 );\r
374\r
375/**\r
376 The callback function for the net buffer which wraps the user's\r
377 transmit token. Although it seems this function is pretty simple,\r
378 there are some subtle things.\r
379 When user requests the IP to transmit a packet by passing it a\r
380 token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r
381 is wrapped in an net buffer. the net buffer's Free function is\r
382 set to Ip4FreeTxToken. The Token and token wrap are added to the\r
383 IP child's TxToken map. Then the buffer is passed to Ip4Output for\r
384 transmission. If something error happened before that, the buffer\r
385 is freed, which in turn will free the token wrap. The wrap may\r
386 have been added to the TxToken map or not, and the user's event\r
387 shouldn't be fired because we are still in the EfiIp4Transmit. If\r
388 the buffer has been sent by Ip4Output, it should be removed from\r
389 the TxToken map and user's event signaled. The token wrap and buffer\r
390 are bound together. Check the comments in Ip4Output for information\r
391 about IP fragmentation.\r
392\r
393 @param[in] Context The token's wrap.\r
394\r
395**/\r
396VOID\r
397EFIAPI\r
398Ip4FreeTxToken (\r
399 IN VOID *Context\r
400 );\r
401\r
402extern EFI_IPSEC2_PROTOCOL *mIpSec;\r
403extern BOOLEAN mIpSec2Installed;\r
404\r
405#endif\r