VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c

Last change on this file was 105670, checked in by vboxsync, 5 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 77.4 KB
Line 
1/** @file
2 The implementation of EFI IPv6 Configuration Protocol.
3
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#include "Ip6Impl.h"
12
13LIST_ENTRY mIp6ConfigInstanceList = { &mIp6ConfigInstanceList, &mIp6ConfigInstanceList };
14
15/**
16 The event process routine when the DHCPv6 service binding protocol is installed
17 in the system.
18
19 @param[in] Event Not used.
20 @param[in] Context Pointer to the IP6 config instance data.
21
22**/
23VOID
24EFIAPI
25Ip6ConfigOnDhcp6SbInstalled (
26 IN EFI_EVENT Event,
27 IN VOID *Context
28 );
29
30/**
31 Update the current policy to NewPolicy. During the transition
32 period, the default router list, on-link prefix list, autonomous prefix list
33 and address list in all interfaces will be released.
34
35 @param[in] IpSb The IP6 service binding instance.
36 @param[in] NewPolicy The new policy to be updated to.
37
38**/
39VOID
40Ip6ConfigOnPolicyChanged (
41 IN IP6_SERVICE *IpSb,
42 IN EFI_IP6_CONFIG_POLICY NewPolicy
43 )
44{
45 LIST_ENTRY *Entry;
46 LIST_ENTRY *Entry2;
47 LIST_ENTRY *Next;
48 IP6_INTERFACE *IpIf;
49 IP6_DAD_ENTRY *DadEntry;
50 IP6_DELAY_JOIN_LIST *DelayNode;
51 IP6_ADDRESS_INFO *AddrInfo;
52 IP6_PROTOCOL *Instance;
53 BOOLEAN Recovery;
54
55 Recovery = FALSE;
56
57 //
58 // Currently there are only two policies: Manual and Automatic. Regardless of
59 // what transition is going on, i.e., Manual -> Automatic and Automatic ->
60 // Manual, we have to free default router list, on-link prefix list, autonomous
61 // prefix list, address list in all the interfaces and destroy any IPv6 child
62 // instance whose local IP is neither 0 nor the link-local address.
63 //
64 Ip6CleanDefaultRouterList (IpSb);
65 Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix);
66 Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix);
67
68 //
69 // It's tricky... If the LinkLocal address is O.K., add back the link-local
70 // prefix to the on-link prefix table.
71 //
72 if (IpSb->LinkLocalOk) {
73 Ip6CreatePrefixListEntry (
74 IpSb,
75 TRUE,
76 (UINT32)IP6_INFINIT_LIFETIME,
77 (UINT32)IP6_INFINIT_LIFETIME,
78 IP6_LINK_LOCAL_PREFIX_LENGTH,
79 &IpSb->LinkLocalAddr
80 );
81 }
82
83 if (!IsListEmpty (&IpSb->DefaultInterface->AddressList) && (IpSb->DefaultInterface->AddressCount > 0)) {
84 //
85 // If any IPv6 children (Instance) in configured state and use global unicast address, it will be
86 // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be
87 // called, which may break the upper layer network stacks. So, the driver should take the responsibility
88 // for the recovery by using ConnectController() after Ip6RemoveAddr().
89 // Here, just check whether need to recover the upper layer network stacks later.
90 //
91 NET_LIST_FOR_EACH (Entry, &IpSb->DefaultInterface->AddressList) {
92 AddrInfo = NET_LIST_USER_STRUCT_S (Entry, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);
93 if (!IsListEmpty (&IpSb->Children)) {
94 NET_LIST_FOR_EACH (Entry2, &IpSb->Children) {
95 Instance = NET_LIST_USER_STRUCT_S (Entry2, IP6_PROTOCOL, Link, IP6_PROTOCOL_SIGNATURE);
96 if ((Instance->State == IP6_STATE_CONFIGED) && EFI_IP6_EQUAL (&Instance->ConfigData.StationAddress, &AddrInfo->Address)) {
97 Recovery = TRUE;
98 break;
99 }
100 }
101 }
102 }
103
104 //
105 // All IPv6 children that use global unicast address as its source address
106 // should be destroyed now. The survivers are those use the link-local address
107 // or the unspecified address as the source address.
108 // TODO: Conduct a check here.
109 Ip6RemoveAddr (
110 IpSb,
111 &IpSb->DefaultInterface->AddressList,
112 &IpSb->DefaultInterface->AddressCount,
113 NULL,
114 0
115 );
116
117 if ((IpSb->Controller != NULL) && Recovery) {
118 //
119 // ConnectController() to recover the upper layer network stacks.
120 //
121 gBS->ConnectController (IpSb->Controller, NULL, NULL, TRUE);
122 }
123 }
124
125 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
126 //
127 // remove all pending delay node and DAD entries for the global addresses.
128 //
129 IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);
130
131 NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DelayJoinList) {
132 DelayNode = NET_LIST_USER_STRUCT (Entry2, IP6_DELAY_JOIN_LIST, Link);
133 if (!NetIp6IsLinkLocalAddr (&DelayNode->AddressInfo->Address)) {
134 RemoveEntryList (&DelayNode->Link);
135 FreePool (DelayNode);
136 }
137 }
138
139 NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {
140 DadEntry = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);
141
142 if (!NetIp6IsLinkLocalAddr (&DadEntry->AddressInfo->Address)) {
143 //
144 // Fail this DAD entry if the address is not link-local.
145 //
146 Ip6OnDADFinished (FALSE, IpIf, DadEntry);
147 }
148 }
149 }
150
151 if (NewPolicy == Ip6ConfigPolicyAutomatic) {
152 //
153 // Set parameters to trigger router solicitation sending in timer handler.
154 //
155 IpSb->RouterAdvertiseReceived = FALSE;
156 IpSb->SolicitTimer = IP6_MAX_RTR_SOLICITATIONS;
157 //
158 // delay 1 second
159 //
160 IpSb->Ticks = (UINT32)IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS);
161 }
162}
163
164/**
165 The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
166
167 @param[in] Instance Pointer to the IP6 config instance data.
168 @param[in] OtherInfoOnly If FALSE, get stateful address and other information
169 via DHCPv6. Otherwise, only get the other information.
170
171 @retval EFI_SUCCESS The operation finished successfully.
172 @retval EFI_UNSUPPORTED The DHCP6 driver is not available.
173
174**/
175EFI_STATUS
176Ip6ConfigStartStatefulAutoConfig (
177 IN IP6_CONFIG_INSTANCE *Instance,
178 IN BOOLEAN OtherInfoOnly
179 )
180{
181 EFI_STATUS Status;
182 IP6_SERVICE *IpSb;
183 EFI_DHCP6_CONFIG_DATA Dhcp6CfgData;
184 EFI_DHCP6_PROTOCOL *Dhcp6;
185 EFI_DHCP6_PACKET_OPTION *OptList[1];
186 UINT16 OptBuf[4];
187 EFI_DHCP6_PACKET_OPTION *Oro;
188 EFI_DHCP6_RETRANSMISSION InfoReqReXmit;
189
190 //
191 // A host must not invoke stateful address configuration if it is already
192 // participating in the statuful protocol as a result of an earlier advertisement.
193 //
194 if (Instance->Dhcp6Handle != NULL) {
195 return EFI_SUCCESS;
196 }
197
198 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
199
200 Instance->OtherInfoOnly = OtherInfoOnly;
201
202 Status = NetLibCreateServiceChild (
203 IpSb->Controller,
204 IpSb->Image,
205 &gEfiDhcp6ServiceBindingProtocolGuid,
206 &Instance->Dhcp6Handle
207 );
208
209 if (Status == EFI_UNSUPPORTED) {
210 //
211 // No DHCPv6 Service Binding protocol, register a notify.
212 //
213 if (Instance->Dhcp6SbNotifyEvent == NULL) {
214 Instance->Dhcp6SbNotifyEvent = EfiCreateProtocolNotifyEvent (
215 &gEfiDhcp6ServiceBindingProtocolGuid,
216 TPL_CALLBACK,
217 Ip6ConfigOnDhcp6SbInstalled,
218 (VOID *)Instance,
219 &Instance->Registration
220 );
221 }
222 }
223
224 if (EFI_ERROR (Status)) {
225 return Status;
226 }
227
228 if (Instance->Dhcp6SbNotifyEvent != NULL) {
229 gBS->CloseEvent (Instance->Dhcp6SbNotifyEvent);
230 }
231
232 Status = gBS->OpenProtocol (
233 Instance->Dhcp6Handle,
234 &gEfiDhcp6ProtocolGuid,
235 (VOID **)&Instance->Dhcp6,
236 IpSb->Image,
237 IpSb->Controller,
238 EFI_OPEN_PROTOCOL_BY_DRIVER
239 );
240 ASSERT_EFI_ERROR (Status);
241
242 Dhcp6 = Instance->Dhcp6;
243 Dhcp6->Configure (Dhcp6, NULL);
244
245 //
246 // Set the exta options to send. Here we only want the option request option
247 // with DNS SERVERS.
248 //
249 Oro = (EFI_DHCP6_PACKET_OPTION *)OptBuf;
250 Oro->OpCode = HTONS (DHCP6_OPT_ORO);
251 Oro->OpLen = HTONS (2);
252 *((UINT16 *)&Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS);
253 OptList[0] = Oro;
254
255 Status = EFI_SUCCESS;
256
257 if (!OtherInfoOnly) {
258 //
259 // Get stateful address and other information via DHCPv6.
260 //
261 Dhcp6CfgData.Dhcp6Callback = NULL;
262 Dhcp6CfgData.CallbackContext = NULL;
263 Dhcp6CfgData.OptionCount = 1;
264 Dhcp6CfgData.OptionList = &OptList[0];
265 Dhcp6CfgData.IaDescriptor.Type = EFI_DHCP6_IA_TYPE_NA;
266 Dhcp6CfgData.IaDescriptor.IaId = Instance->IaId;
267 Dhcp6CfgData.IaInfoEvent = Instance->Dhcp6Event;
268 Dhcp6CfgData.ReconfigureAccept = FALSE;
269 Dhcp6CfgData.RapidCommit = FALSE;
270 Dhcp6CfgData.SolicitRetransmission = NULL;
271
272 Status = Dhcp6->Configure (Dhcp6, &Dhcp6CfgData);
273
274 if (!EFI_ERROR (Status)) {
275 if (IpSb->LinkLocalOk) {
276 Status = Dhcp6->Start (Dhcp6);
277 } else {
278 IpSb->Dhcp6NeedStart = TRUE;
279 }
280 }
281 } else {
282 //
283 // Only get other information via DHCPv6, this doesn't require a config
284 // action.
285 //
286 InfoReqReXmit.Irt = 4;
287 InfoReqReXmit.Mrc = 64;
288 InfoReqReXmit.Mrt = 60;
289 InfoReqReXmit.Mrd = 0;
290
291 if (IpSb->LinkLocalOk) {
292 Status = Dhcp6->InfoRequest (
293 Dhcp6,
294 TRUE,
295 Oro,
296 0,
297 NULL,
298 &InfoReqReXmit,
299 Instance->Dhcp6Event,
300 Ip6ConfigOnDhcp6Reply,
301 Instance
302 );
303 } else {
304 IpSb->Dhcp6NeedInfoRequest = TRUE;
305 }
306 }
307
308 return Status;
309}
310
311/**
312 Signal the registered event. It is the callback routine for NetMapIterate.
313
314 @param[in] Map Points to the list of registered event.
315 @param[in] Item The registered event.
316 @param[in] Arg Not used.
317
318**/
319EFI_STATUS
320EFIAPI
321Ip6ConfigSignalEvent (
322 IN NET_MAP *Map,
323 IN NET_MAP_ITEM *Item,
324 IN VOID *Arg
325 )
326{
327 gBS->SignalEvent ((EFI_EVENT)Item->Key);
328
329 return EFI_SUCCESS;
330}
331
332/**
333 Read the configuration data from variable storage according to the VarName and
334 gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
335 data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the
336 configuration data to IP6_CONFIG_INSTANCE.
337
338 @param[in] VarName The pointer to the variable name
339 @param[in, out] Instance The pointer to the IP6 config instance data.
340
341 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
342 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
343 @retval EFI_SUCCESS The configuration data was retrieved successfully.
344
345**/
346EFI_STATUS
347Ip6ConfigReadConfigData (
348 IN CHAR16 *VarName,
349 IN OUT IP6_CONFIG_INSTANCE *Instance
350 )
351{
352 EFI_STATUS Status;
353 UINTN VarSize;
354 IP6_CONFIG_VARIABLE *Variable;
355 IP6_CONFIG_DATA_ITEM *DataItem;
356 UINTN Index;
357 IP6_CONFIG_DATA_RECORD DataRecord;
358 CHAR8 *Data;
359
360 //
361 // Try to read the configuration variable.
362 //
363 VarSize = 0;
364 Status = gRT->GetVariable (
365 VarName,
366 &gEfiIp6ConfigProtocolGuid,
367 NULL,
368 &VarSize,
369 NULL
370 );
371
372 if (Status == EFI_BUFFER_TOO_SMALL) {
373 //
374 // Allocate buffer and read the config variable.
375 //
376 Variable = AllocatePool (VarSize);
377 if (Variable == NULL) {
378 return EFI_OUT_OF_RESOURCES;
379 }
380
381 Status = gRT->GetVariable (
382 VarName,
383 &gEfiIp6ConfigProtocolGuid,
384 NULL,
385 &VarSize,
386 Variable
387 );
388 if (EFI_ERROR (Status) || ((UINT16)(~NetblockChecksum ((UINT8 *)Variable, (UINT32)VarSize)) != 0)) {
389 //
390 // GetVariable error or the variable is corrupted.
391 //
392 goto Error;
393 }
394
395 //
396 // Get the IAID we use.
397 //
398 Instance->IaId = Variable->IaId;
399
400 for (Index = 0; Index < Variable->DataRecordCount; Index++) {
401 CopyMem (&DataRecord, &Variable->DataRecord[Index], sizeof (DataRecord));
402
403 DataItem = &Instance->DataItem[DataRecord.DataType];
404 if (DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED) &&
405 (DataItem->DataSize != DataRecord.DataSize)
406 )
407 {
408 //
409 // Perhaps a corrupted data record...
410 //
411 continue;
412 }
413
414 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {
415 //
416 // This data item has variable length data.
417 // Check that the length is contained within the variable before allocating.
418 //
419 if (DataRecord.DataSize > VarSize - DataRecord.Offset) {
420 goto Error;
421 }
422
423 DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);
424 if (DataItem->Data.Ptr == NULL) {
425 //
426 // no memory resource
427 //
428 continue;
429 }
430 }
431
432 Data = (CHAR8 *)Variable + DataRecord.Offset;
433 CopyMem (DataItem->Data.Ptr, Data, DataRecord.DataSize);
434
435 DataItem->DataSize = DataRecord.DataSize;
436 DataItem->Status = EFI_SUCCESS;
437 }
438
439 FreePool (Variable);
440 return EFI_SUCCESS;
441 }
442
443 return Status;
444
445Error:
446 //
447 // Fall back to the default value.
448 //
449 if (Variable != NULL) {
450 FreePool (Variable);
451 }
452
453 //
454 // Remove the problematic variable and return EFI_NOT_FOUND, a new
455 // variable will be set again.
456 //
457 gRT->SetVariable (
458 VarName,
459 &gEfiIp6ConfigProtocolGuid,
460 IP6_CONFIG_VARIABLE_ATTRIBUTE,
461 0,
462 NULL
463 );
464
465 return EFI_NOT_FOUND;
466}
467
468/**
469 Write the configuration data from IP6_CONFIG_INSTANCE to variable storage.
470
471 @param[in] VarName The pointer to the variable name.
472 @param[in] Instance The pointer to the IP6 configuration instance data.
473
474 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
475 @retval EFI_SUCCESS The configuration data is written successfully.
476
477**/
478EFI_STATUS
479Ip6ConfigWriteConfigData (
480 IN CHAR16 *VarName,
481 IN IP6_CONFIG_INSTANCE *Instance
482 )
483{
484 UINTN Index;
485 UINTN VarSize;
486 IP6_CONFIG_DATA_ITEM *DataItem;
487 IP6_CONFIG_VARIABLE *Variable;
488 IP6_CONFIG_DATA_RECORD *DataRecord;
489 CHAR8 *Heap;
490 EFI_STATUS Status;
491
492 VarSize = sizeof (IP6_CONFIG_VARIABLE) - sizeof (IP6_CONFIG_DATA_RECORD);
493
494 for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {
495 DataItem = &Instance->DataItem[Index];
496 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {
497 VarSize += sizeof (IP6_CONFIG_DATA_RECORD) + DataItem->DataSize;
498 }
499 }
500
501 Variable = AllocatePool (VarSize);
502 if (Variable == NULL) {
503 return EFI_OUT_OF_RESOURCES;
504 }
505
506 Variable->IaId = Instance->IaId;
507 Heap = (CHAR8 *)Variable + VarSize;
508 Variable->DataRecordCount = 0;
509
510 for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {
511 DataItem = &Instance->DataItem[Index];
512 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {
513 Heap -= DataItem->DataSize;
514 CopyMem (Heap, DataItem->Data.Ptr, DataItem->DataSize);
515
516 DataRecord = &Variable->DataRecord[Variable->DataRecordCount];
517 DataRecord->DataType = (EFI_IP6_CONFIG_DATA_TYPE)Index;
518 DataRecord->DataSize = (UINT32)DataItem->DataSize;
519 DataRecord->Offset = (UINT16)(Heap - (CHAR8 *)Variable);
520
521 Variable->DataRecordCount++;
522 }
523 }
524
525 Variable->Checksum = 0;
526 Variable->Checksum = (UINT16) ~NetblockChecksum ((UINT8 *)Variable, (UINT32)VarSize);
527
528 Status = gRT->SetVariable (
529 VarName,
530 &gEfiIp6ConfigProtocolGuid,
531 IP6_CONFIG_VARIABLE_ATTRIBUTE,
532 VarSize,
533 Variable
534 );
535
536 FreePool (Variable);
537
538 return Status;
539}
540
541/**
542 The work function for EfiIp6ConfigGetData() to get the interface information
543 of the communication device this IP6Config instance manages.
544
545 @param[in] Instance Pointer to the IP6 config instance data.
546 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
547 bytes, the size of buffer required to store the specified
548 configuration data.
549 @param[in] Data The data buffer in which the configuration data is returned.
550 Ignored if DataSize is ZERO.
551
552 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
553 configuration data, and the required size is
554 returned in DataSize.
555 @retval EFI_SUCCESS The specified configuration data was obtained.
556
557**/
558EFI_STATUS
559Ip6ConfigGetIfInfo (
560 IN IP6_CONFIG_INSTANCE *Instance,
561 IN OUT UINTN *DataSize,
562 IN VOID *Data OPTIONAL
563 )
564{
565 IP6_SERVICE *IpSb;
566 UINTN Length;
567 IP6_CONFIG_DATA_ITEM *Item;
568 EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo;
569 UINT32 AddressCount;
570 UINT32 RouteCount;
571
572 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
573 Length = sizeof (EFI_IP6_CONFIG_INTERFACE_INFO);
574
575 //
576 // Calculate the required length, add the buffer size for AddressInfo and
577 // RouteTable
578 //
579 Ip6BuildEfiAddressList (IpSb, &AddressCount, NULL);
580 Ip6BuildEfiRouteTable (IpSb->RouteTable, &RouteCount, NULL);
581
582 Length += AddressCount * sizeof (EFI_IP6_ADDRESS_INFO) + RouteCount * sizeof (EFI_IP6_ROUTE_TABLE);
583
584 if (*DataSize < Length) {
585 *DataSize = Length;
586 return EFI_BUFFER_TOO_SMALL;
587 }
588
589 //
590 // Copy the fixed size part of the interface info.
591 //
592 Item = &Instance->DataItem[Ip6ConfigDataTypeInterfaceInfo];
593 IfInfo = (EFI_IP6_CONFIG_INTERFACE_INFO *)Data;
594 CopyMem (IfInfo, Item->Data.Ptr, sizeof (EFI_IP6_CONFIG_INTERFACE_INFO));
595
596 //
597 // AddressInfo
598 //
599 IfInfo->AddressInfo = (EFI_IP6_ADDRESS_INFO *)(IfInfo + 1);
600 Ip6BuildEfiAddressList (IpSb, &IfInfo->AddressInfoCount, &IfInfo->AddressInfo);
601
602 //
603 // RouteTable
604 //
605 IfInfo->RouteTable = (EFI_IP6_ROUTE_TABLE *)(IfInfo->AddressInfo + IfInfo->AddressInfoCount);
606 Ip6BuildEfiRouteTable (IpSb->RouteTable, &IfInfo->RouteCount, &IfInfo->RouteTable);
607
608 if (IfInfo->AddressInfoCount == 0) {
609 IfInfo->AddressInfo = NULL;
610 }
611
612 if (IfInfo->RouteCount == 0) {
613 IfInfo->RouteTable = NULL;
614 }
615
616 return EFI_SUCCESS;
617}
618
619/**
620 The work function for EfiIp6ConfigSetData() to set the alternative interface ID
621 for the communication device managed by this IP6Config instance, if the link local
622 IPv6 addresses generated from the interface ID based on the default source the
623 EFI IPv6 Protocol uses is a duplicate address.
624
625 @param[in] Instance Pointer to the IP6 configuration instance data.
626 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
627 @param[in] Data The data buffer to set.
628
629 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
630 8 bytes.
631 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
632 network stack was set.
633
634**/
635EFI_STATUS
636Ip6ConfigSetAltIfId (
637 IN IP6_CONFIG_INSTANCE *Instance,
638 IN UINTN DataSize,
639 IN VOID *Data
640 )
641{
642 EFI_IP6_CONFIG_INTERFACE_ID *OldIfId;
643 EFI_IP6_CONFIG_INTERFACE_ID *NewIfId;
644 IP6_CONFIG_DATA_ITEM *DataItem;
645
646 if (DataSize != sizeof (EFI_IP6_CONFIG_INTERFACE_ID)) {
647 return EFI_BAD_BUFFER_SIZE;
648 }
649
650 DataItem = &Instance->DataItem[Ip6ConfigDataTypeAltInterfaceId];
651 OldIfId = DataItem->Data.AltIfId;
652 NewIfId = (EFI_IP6_CONFIG_INTERFACE_ID *)Data;
653
654 CopyMem (OldIfId, NewIfId, DataSize);
655 DataItem->Status = EFI_SUCCESS;
656
657 return EFI_SUCCESS;
658}
659
660/**
661 The work function for EfiIp6ConfigSetData() to set the general configuration
662 policy for the EFI IPv6 network stack that is running on the communication device
663 managed by this IP6Config instance. The policy will affect other configuration settings.
664
665 @param[in] Instance Pointer to the IP6 config instance data.
666 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
667 @param[in] Data The data buffer to set.
668
669 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
670 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
671 @retval EFI_ABORTED The new policy equals the current policy.
672 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
673 network stack was set.
674
675**/
676EFI_STATUS
677Ip6ConfigSetPolicy (
678 IN IP6_CONFIG_INSTANCE *Instance,
679 IN UINTN DataSize,
680 IN VOID *Data
681 )
682{
683 EFI_IP6_CONFIG_POLICY NewPolicy;
684 IP6_CONFIG_DATA_ITEM *DataItem;
685 IP6_SERVICE *IpSb;
686
687 if (DataSize != sizeof (EFI_IP6_CONFIG_POLICY)) {
688 return EFI_BAD_BUFFER_SIZE;
689 }
690
691 NewPolicy = *((EFI_IP6_CONFIG_POLICY *)Data);
692
693 if (NewPolicy > Ip6ConfigPolicyAutomatic) {
694 return EFI_INVALID_PARAMETER;
695 }
696
697 if (NewPolicy == Instance->Policy) {
698 return EFI_ABORTED;
699 } else {
700 //
701 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
702 // data size, and fire up all the related events.
703 //
704 DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];
705 if (DataItem->Data.Ptr != NULL) {
706 FreePool (DataItem->Data.Ptr);
707 }
708
709 DataItem->Data.Ptr = NULL;
710 DataItem->DataSize = 0;
711 DataItem->Status = EFI_NOT_FOUND;
712 NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);
713
714 DataItem = &Instance->DataItem[Ip6ConfigDataTypeGateway];
715 if (DataItem->Data.Ptr != NULL) {
716 FreePool (DataItem->Data.Ptr);
717 }
718
719 DataItem->Data.Ptr = NULL;
720 DataItem->DataSize = 0;
721 DataItem->Status = EFI_NOT_FOUND;
722 NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);
723
724 DataItem = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];
725 DataItem->Data.Ptr = NULL;
726 DataItem->DataSize = 0;
727 DataItem->Status = EFI_NOT_FOUND;
728 NetMapIterate (&DataItem->EventMap, Ip6ConfigSignalEvent, NULL);
729
730 if (NewPolicy == Ip6ConfigPolicyManual) {
731 //
732 // The policy is changed from automatic to manual. Stop the DHCPv6 process
733 // and destroy the DHCPv6 child.
734 //
735 if (Instance->Dhcp6Handle != NULL) {
736 Ip6ConfigDestroyDhcp6 (Instance);
737 }
738 }
739
740 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
741 Ip6ConfigOnPolicyChanged (IpSb, NewPolicy);
742
743 Instance->Policy = NewPolicy;
744
745 return EFI_SUCCESS;
746 }
747}
748
749/**
750 The work function for EfiIp6ConfigSetData() to set the number of consecutive
751 Neighbor Solicitation messages sent while performing Duplicate Address Detection
752 on a tentative address. A value of ZERO indicates that Duplicate Address Detection
753 will not be performed on a tentative address.
754
755 @param[in] Instance The Instance Pointer to the IP6 config instance data.
756 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
757 @param[in] Data The data buffer to set.
758
759 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
760 @retval EFI_ABORTED The new transmit count equals the current configuration.
761 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
762 network stack was set.
763
764**/
765EFI_STATUS
766Ip6ConfigSetDadXmits (
767 IN IP6_CONFIG_INSTANCE *Instance,
768 IN UINTN DataSize,
769 IN VOID *Data
770 )
771{
772 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS *OldDadXmits;
773
774 if (DataSize != sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS)) {
775 return EFI_BAD_BUFFER_SIZE;
776 }
777
778 OldDadXmits = Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits].Data.DadXmits;
779
780 if ((*(UINT32 *)Data) == OldDadXmits->DupAddrDetectTransmits) {
781 return EFI_ABORTED;
782 } else {
783 OldDadXmits->DupAddrDetectTransmits = *((UINT32 *)Data);
784 return EFI_SUCCESS;
785 }
786}
787
788/**
789 The callback function for Ip6SetAddr. The prototype is defined
790 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
791 for the manual address set by Ip6ConfigSetManualAddress.
792
793 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passed.
794 @param[in] TargetAddress The tentative IPv6 address to be checked.
795 @param[in] Context Pointer to the IP6 configuration instance data.
796
797**/
798VOID
799Ip6ManualAddrDadCallback (
800 IN BOOLEAN IsDadPassed,
801 IN EFI_IPv6_ADDRESS *TargetAddress,
802 IN VOID *Context
803 )
804{
805 IP6_CONFIG_INSTANCE *Instance;
806 UINTN Index;
807 IP6_CONFIG_DATA_ITEM *Item;
808 EFI_IP6_CONFIG_MANUAL_ADDRESS *ManualAddr;
809 EFI_IP6_CONFIG_MANUAL_ADDRESS *PassedAddr;
810 UINTN DadPassCount;
811 UINTN DadFailCount;
812 IP6_SERVICE *IpSb;
813
814 Instance = (IP6_CONFIG_INSTANCE *)Context;
815 NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
816 Item = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];
817 ManualAddr = NULL;
818
819 if (Item->DataSize == 0) {
820 return;
821 }
822
823 for (Index = 0; Index < Item->DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS); Index++) {
824 //
825 // Find the original tag used to place into the NET_MAP.
826 //
827 ManualAddr = Item->Data.ManualAddress + Index;
828 if (EFI_IP6_EQUAL (TargetAddress, &ManualAddr->Address)) {
829 break;
830 }
831 }
832
833 ASSERT (Index != Item->DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
834
835 if (IsDadPassed) {
836 NetMapInsertTail (&Instance->DadPassedMap, ManualAddr, NULL);
837 } else {
838 NetMapInsertTail (&Instance->DadFailedMap, ManualAddr, NULL);
839 }
840
841 DadPassCount = NetMapGetCount (&Instance->DadPassedMap);
842 DadFailCount = NetMapGetCount (&Instance->DadFailedMap);
843
844 if ((DadPassCount + DadFailCount) == (Item->DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS))) {
845 //
846 // All addresses have finished the configuration process.
847 //
848 if (DadFailCount != 0) {
849 //
850 // There is at least one duplicate address.
851 //
852 FreePool (Item->Data.Ptr);
853
854 Item->DataSize = DadPassCount * sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);
855 if (Item->DataSize == 0) {
856 //
857 // All failed, bad luck.
858 //
859 Item->Data.Ptr = NULL;
860 Item->Status = EFI_NOT_FOUND;
861 } else {
862 //
863 // Part of addresses are detected to be duplicates, so update the
864 // data with those passed.
865 //
866 PassedAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)AllocatePool (Item->DataSize);
867 ASSERT (PassedAddr != NULL);
868
869 Item->Data.Ptr = PassedAddr;
870 Item->Status = EFI_SUCCESS;
871
872 while (!NetMapIsEmpty (&Instance->DadPassedMap)) {
873 ManualAddr = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)NetMapRemoveHead (&Instance->DadPassedMap, NULL);
874 CopyMem (PassedAddr, ManualAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));
875
876 PassedAddr++;
877 }
878
879 ASSERT ((UINTN)PassedAddr - (UINTN)Item->Data.Ptr == Item->DataSize);
880 }
881 } else {
882 //
883 // All addresses are valid.
884 //
885 Item->Status = EFI_SUCCESS;
886 }
887
888 //
889 // Remove the tags we put in the NET_MAPs.
890 //
891 while (!NetMapIsEmpty (&Instance->DadFailedMap)) {
892 NetMapRemoveHead (&Instance->DadFailedMap, NULL);
893 }
894
895 while (!NetMapIsEmpty (&Instance->DadPassedMap)) {
896 NetMapRemoveHead (&Instance->DadPassedMap, NULL);
897 }
898
899 //
900 // Signal the waiting events.
901 //
902 NetMapIterate (&Item->EventMap, Ip6ConfigSignalEvent, NULL);
903 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
904 Ip6ConfigWriteConfigData (IpSb->MacString, Instance);
905 }
906}
907
908/**
909 The work function for EfiIp6ConfigSetData() to set the station addresses manually
910 for the EFI IPv6 network stack. It is only configurable when the policy is
911 Ip6ConfigPolicyManual.
912
913 @param[in] Instance Pointer to the IP6 configuration instance data.
914 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
915 @param[in] Data The data buffer to set.
916
917 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
918 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
919 under the current policy.
920 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
921 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
922 @retval EFI_NOT_READY An asynchronous process is invoked to set the specified
923 configuration data, and the process is not finished.
924 @retval EFI_ABORTED The manual addresses to be set equal current
925 configuration.
926 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
927 network stack was set.
928
929**/
930EFI_STATUS
931Ip6ConfigSetManualAddress (
932 IN IP6_CONFIG_INSTANCE *Instance,
933 IN UINTN DataSize,
934 IN VOID *Data
935 )
936{
937 EFI_IP6_CONFIG_MANUAL_ADDRESS *NewAddress;
938 EFI_IP6_CONFIG_MANUAL_ADDRESS *TmpAddress;
939 IP6_CONFIG_DATA_ITEM *DataItem;
940 UINTN NewAddressCount;
941 UINTN Index1;
942 UINTN Index2;
943 IP6_SERVICE *IpSb;
944 IP6_ADDRESS_INFO *CurrentAddrInfo;
945 IP6_ADDRESS_INFO *Copy;
946 LIST_ENTRY CurrentSourceList;
947 UINT32 CurrentSourceCount;
948 LIST_ENTRY *Entry;
949 LIST_ENTRY *Entry2;
950 IP6_INTERFACE *IpIf;
951 IP6_PREFIX_LIST_ENTRY *PrefixEntry;
952 EFI_STATUS Status;
953 BOOLEAN IsUpdated;
954 LIST_ENTRY *Next;
955 IP6_DAD_ENTRY *DadEntry;
956 IP6_DELAY_JOIN_LIST *DelayNode;
957
958 NewAddress = NULL;
959 TmpAddress = NULL;
960 CurrentAddrInfo = NULL;
961 Copy = NULL;
962 Entry = NULL;
963 Entry2 = NULL;
964 IpIf = NULL;
965 PrefixEntry = NULL;
966 Next = NULL;
967 DadEntry = NULL;
968 DelayNode = NULL;
969 Status = EFI_SUCCESS;
970
971 ASSERT (Instance->DataItem[Ip6ConfigDataTypeManualAddress].Status != EFI_NOT_READY);
972
973 if ((DataSize != 0) && ((DataSize % sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS)) != 0)) {
974 return EFI_BAD_BUFFER_SIZE;
975 }
976
977 if (Instance->Policy != Ip6ConfigPolicyManual) {
978 return EFI_WRITE_PROTECTED;
979 }
980
981 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
982
983 DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];
984
985 if ((Data != NULL) && (DataSize != 0)) {
986 NewAddressCount = DataSize / sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);
987 NewAddress = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)Data;
988
989 for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {
990 if (NetIp6IsLinkLocalAddr (&NewAddress->Address) ||
991 !NetIp6IsValidUnicast (&NewAddress->Address) ||
992 (NewAddress->PrefixLength > 128)
993 )
994 {
995 //
996 // make sure the IPv6 address is unicast and not link-local address &&
997 // the prefix length is valid.
998 //
999 return EFI_INVALID_PARAMETER;
1000 }
1001
1002 TmpAddress = NewAddress + 1;
1003 for (Index2 = Index1 + 1; Index2 < NewAddressCount; Index2++, TmpAddress++) {
1004 //
1005 // Any two addresses in the array can't be equal.
1006 //
1007 if (EFI_IP6_EQUAL (&TmpAddress->Address, &NewAddress->Address)) {
1008 return EFI_INVALID_PARAMETER;
1009 }
1010 }
1011 }
1012
1013 //
1014 // Build the current source address list.
1015 //
1016 InitializeListHead (&CurrentSourceList);
1017 CurrentSourceCount = 0;
1018
1019 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
1020 IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);
1021
1022 NET_LIST_FOR_EACH (Entry2, &IpIf->AddressList) {
1023 CurrentAddrInfo = NET_LIST_USER_STRUCT_S (Entry2, IP6_ADDRESS_INFO, Link, IP6_ADDR_INFO_SIGNATURE);
1024
1025 Copy = AllocateCopyPool (sizeof (IP6_ADDRESS_INFO), CurrentAddrInfo);
1026 if (Copy == NULL) {
1027 break;
1028 }
1029
1030 InsertTailList (&CurrentSourceList, &Copy->Link);
1031 CurrentSourceCount++;
1032 }
1033 }
1034
1035 //
1036 // Update the value... a long journey starts
1037 //
1038 NewAddress = AllocateCopyPool (DataSize, Data);
1039 if (NewAddress == NULL) {
1040 Ip6RemoveAddr (NULL, &CurrentSourceList, &CurrentSourceCount, NULL, 0);
1041
1042 return EFI_OUT_OF_RESOURCES;
1043 }
1044
1045 //
1046 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1047 // we may have an asynchronous configuration process.
1048 //
1049 if (DataItem->Data.Ptr != NULL) {
1050 FreePool (DataItem->Data.Ptr);
1051 }
1052
1053 DataItem->Data.Ptr = NewAddress;
1054 DataItem->DataSize = DataSize;
1055 DataItem->Status = EFI_NOT_READY;
1056
1057 //
1058 // Trigger DAD, it's an asynchronous process.
1059 //
1060 IsUpdated = FALSE;
1061
1062 for (Index1 = 0; Index1 < NewAddressCount; Index1++, NewAddress++) {
1063 if (Ip6IsOneOfSetAddress (IpSb, &NewAddress->Address, NULL, &CurrentAddrInfo)) {
1064 ASSERT (CurrentAddrInfo != NULL);
1065 //
1066 // Remove this already existing source address from the CurrentSourceList
1067 // built before.
1068 //
1069 Ip6RemoveAddr (
1070 NULL,
1071 &CurrentSourceList,
1072 &CurrentSourceCount,
1073 &CurrentAddrInfo->Address,
1074 128
1075 );
1076
1077 //
1078 // If the new address's prefix length is not specified, just use the previous configured
1079 // prefix length for this address.
1080 //
1081 if (NewAddress->PrefixLength == 0) {
1082 NewAddress->PrefixLength = CurrentAddrInfo->PrefixLength;
1083 }
1084
1085 //
1086 // This manual address is already in use, see whether prefix length is changed.
1087 //
1088 if (NewAddress->PrefixLength != CurrentAddrInfo->PrefixLength) {
1089 //
1090 // Remove the on-link prefix table, the route entry will be removed
1091 // implicitly.
1092 //
1093 PrefixEntry = Ip6FindPrefixListEntry (
1094 IpSb,
1095 TRUE,
1096 CurrentAddrInfo->PrefixLength,
1097 &CurrentAddrInfo->Address
1098 );
1099 if (PrefixEntry != NULL) {
1100 Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);
1101 }
1102
1103 //
1104 // Save the prefix length.
1105 //
1106 CurrentAddrInfo->PrefixLength = NewAddress->PrefixLength;
1107 IsUpdated = TRUE;
1108 }
1109
1110 //
1111 // create a new on-link prefix entry.
1112 //
1113 PrefixEntry = Ip6FindPrefixListEntry (
1114 IpSb,
1115 TRUE,
1116 NewAddress->PrefixLength,
1117 &NewAddress->Address
1118 );
1119 if (PrefixEntry == NULL) {
1120 Ip6CreatePrefixListEntry (
1121 IpSb,
1122 TRUE,
1123 (UINT32)IP6_INFINIT_LIFETIME,
1124 (UINT32)IP6_INFINIT_LIFETIME,
1125 NewAddress->PrefixLength,
1126 &NewAddress->Address
1127 );
1128 }
1129
1130 CurrentAddrInfo->IsAnycast = NewAddress->IsAnycast;
1131 //
1132 // Artificially mark this address passed DAD be'coz it is already in use.
1133 //
1134 Ip6ManualAddrDadCallback (TRUE, &NewAddress->Address, Instance);
1135 } else {
1136 //
1137 // A new address.
1138 //
1139 IsUpdated = TRUE;
1140
1141 //
1142 // Set the new address, this will trigger DAD and activate the address if
1143 // DAD succeeds.
1144 //
1145 Ip6SetAddress (
1146 IpSb->DefaultInterface,
1147 &NewAddress->Address,
1148 NewAddress->IsAnycast,
1149 NewAddress->PrefixLength,
1150 (UINT32)IP6_INFINIT_LIFETIME,
1151 (UINT32)IP6_INFINIT_LIFETIME,
1152 Ip6ManualAddrDadCallback,
1153 Instance
1154 );
1155 }
1156 }
1157
1158 //
1159 // Check the CurrentSourceList, it now contains those addresses currently in
1160 // use and will be removed.
1161 //
1162 IpIf = IpSb->DefaultInterface;
1163
1164 while (!IsListEmpty (&CurrentSourceList)) {
1165 IsUpdated = TRUE;
1166
1167 CurrentAddrInfo = NET_LIST_HEAD (&CurrentSourceList, IP6_ADDRESS_INFO, Link);
1168
1169 //
1170 // This local address is going to be removed, the IP instances that are
1171 // currently using it will be destroyed.
1172 //
1173 Ip6RemoveAddr (
1174 IpSb,
1175 &IpIf->AddressList,
1176 &IpIf->AddressCount,
1177 &CurrentAddrInfo->Address,
1178 128
1179 );
1180
1181 //
1182 // Remove the on-link prefix table, the route entry will be removed
1183 // implicitly.
1184 //
1185 PrefixEntry = Ip6FindPrefixListEntry (
1186 IpSb,
1187 TRUE,
1188 CurrentAddrInfo->PrefixLength,
1189 &CurrentAddrInfo->Address
1190 );
1191 if (PrefixEntry != NULL) {
1192 Ip6DestroyPrefixListEntry (IpSb, PrefixEntry, TRUE, FALSE);
1193 }
1194
1195 RemoveEntryList (&CurrentAddrInfo->Link);
1196 FreePool (CurrentAddrInfo);
1197 }
1198
1199 if (IsUpdated) {
1200 if (DataItem->Status == EFI_NOT_READY) {
1201 //
1202 // If DAD is disabled on this interface, the configuration process is
1203 // actually synchronous, and the data item's status will be changed to
1204 // the final status before we reach here, just check it.
1205 //
1206 Status = EFI_NOT_READY;
1207 } else {
1208 Status = EFI_SUCCESS;
1209 }
1210 } else {
1211 //
1212 // No update is taken, reset the status to success and return EFI_ABORTED.
1213 //
1214 DataItem->Status = EFI_SUCCESS;
1215 Status = EFI_ABORTED;
1216 }
1217 } else {
1218 //
1219 // DataSize is 0 and Data is NULL, clean up the manual address.
1220 //
1221 if (DataItem->Data.Ptr != NULL) {
1222 FreePool (DataItem->Data.Ptr);
1223 }
1224
1225 DataItem->Data.Ptr = NULL;
1226 DataItem->DataSize = 0;
1227 DataItem->Status = EFI_NOT_FOUND;
1228
1229 Ip6CleanDefaultRouterList (IpSb);
1230 Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix);
1231 Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix);
1232 Ip6CleanAssembleTable (&IpSb->Assemble);
1233
1234 if (IpSb->LinkLocalOk) {
1235 Ip6CreatePrefixListEntry (
1236 IpSb,
1237 TRUE,
1238 (UINT32)IP6_INFINIT_LIFETIME,
1239 (UINT32)IP6_INFINIT_LIFETIME,
1240 IP6_LINK_LOCAL_PREFIX_LENGTH,
1241 &IpSb->LinkLocalAddr
1242 );
1243 }
1244
1245 Ip6RemoveAddr (
1246 IpSb,
1247 &IpSb->DefaultInterface->AddressList,
1248 &IpSb->DefaultInterface->AddressCount,
1249 NULL,
1250 0
1251 );
1252
1253 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
1254 //
1255 // Remove all pending delay node and DAD entries for the global addresses.
1256 //
1257 IpIf = NET_LIST_USER_STRUCT_S (Entry, IP6_INTERFACE, Link, IP6_INTERFACE_SIGNATURE);
1258
1259 NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DelayJoinList) {
1260 DelayNode = NET_LIST_USER_STRUCT (Entry2, IP6_DELAY_JOIN_LIST, Link);
1261 if (!NetIp6IsLinkLocalAddr (&DelayNode->AddressInfo->Address)) {
1262 RemoveEntryList (&DelayNode->Link);
1263 FreePool (DelayNode);
1264 }
1265 }
1266
1267 NET_LIST_FOR_EACH_SAFE (Entry2, Next, &IpIf->DupAddrDetectList) {
1268 DadEntry = NET_LIST_USER_STRUCT_S (Entry2, IP6_DAD_ENTRY, Link, IP6_DAD_ENTRY_SIGNATURE);
1269
1270 if (!NetIp6IsLinkLocalAddr (&DadEntry->AddressInfo->Address)) {
1271 //
1272 // Fail this DAD entry if the address is not link-local.
1273 //
1274 Ip6OnDADFinished (FALSE, IpIf, DadEntry);
1275 }
1276 }
1277 }
1278 }
1279
1280 return Status;
1281}
1282
1283/**
1284 The work function for EfiIp6ConfigSetData() to set the gateway addresses manually
1285 for the EFI IPv6 network stack that is running on the communication device that
1286 this EFI IPv6 Configuration Protocol manages. It is not configurable when the policy is
1287 Ip6ConfigPolicyAutomatic. The gateway addresses must be unicast IPv6 addresses.
1288
1289 @param[in] Instance The pointer to the IP6 config instance data.
1290 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1291 @param[in] Data The data buffer to set. This points to an array of
1292 EFI_IPv6_ADDRESS instances.
1293
1294 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1295 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1296 under the current policy.
1297 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1298 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1299 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1300 current configuration.
1301 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1302 network stack was set.
1303
1304**/
1305EFI_STATUS
1306Ip6ConfigSetGateway (
1307 IN IP6_CONFIG_INSTANCE *Instance,
1308 IN UINTN DataSize,
1309 IN VOID *Data
1310 )
1311{
1312 UINTN Index1;
1313 UINTN Index2;
1314 EFI_IPv6_ADDRESS *OldGateway;
1315 EFI_IPv6_ADDRESS *NewGateway;
1316 UINTN OldGatewayCount;
1317 UINTN NewGatewayCount;
1318 IP6_CONFIG_DATA_ITEM *Item;
1319 BOOLEAN OneRemoved;
1320 BOOLEAN OneAdded;
1321 IP6_SERVICE *IpSb;
1322 IP6_DEFAULT_ROUTER *DefaultRouter;
1323 VOID *Tmp;
1324
1325 OldGateway = NULL;
1326 NewGateway = NULL;
1327 Item = NULL;
1328 DefaultRouter = NULL;
1329 Tmp = NULL;
1330 OneRemoved = FALSE;
1331 OneAdded = FALSE;
1332
1333 if ((DataSize != 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {
1334 return EFI_BAD_BUFFER_SIZE;
1335 }
1336
1337 if (Instance->Policy != Ip6ConfigPolicyManual) {
1338 return EFI_WRITE_PROTECTED;
1339 }
1340
1341 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
1342 Item = &Instance->DataItem[Ip6ConfigDataTypeGateway];
1343 OldGateway = Item->Data.Gateway;
1344 OldGatewayCount = Item->DataSize / sizeof (EFI_IPv6_ADDRESS);
1345
1346 for (Index1 = 0; Index1 < OldGatewayCount; Index1++) {
1347 //
1348 // Remove this default router.
1349 //
1350 DefaultRouter = Ip6FindDefaultRouter (IpSb, OldGateway + Index1);
1351 if (DefaultRouter != NULL) {
1352 Ip6DestroyDefaultRouter (IpSb, DefaultRouter);
1353 OneRemoved = TRUE;
1354 }
1355 }
1356
1357 if ((Data != NULL) && (DataSize != 0)) {
1358 NewGateway = (EFI_IPv6_ADDRESS *)Data;
1359 NewGatewayCount = DataSize / sizeof (EFI_IPv6_ADDRESS);
1360 for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
1361 if (!NetIp6IsValidUnicast (NewGateway + Index1)) {
1362 return EFI_INVALID_PARAMETER;
1363 }
1364
1365 for (Index2 = Index1 + 1; Index2 < NewGatewayCount; Index2++) {
1366 if (EFI_IP6_EQUAL (NewGateway + Index1, NewGateway + Index2)) {
1367 return EFI_INVALID_PARAMETER;
1368 }
1369 }
1370 }
1371
1372 if (NewGatewayCount != OldGatewayCount) {
1373 Tmp = AllocatePool (DataSize);
1374 if (Tmp == NULL) {
1375 return EFI_OUT_OF_RESOURCES;
1376 }
1377 } else {
1378 Tmp = NULL;
1379 }
1380
1381 for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {
1382 DefaultRouter = Ip6FindDefaultRouter (IpSb, NewGateway + Index1);
1383 if (DefaultRouter == NULL) {
1384 Ip6CreateDefaultRouter (IpSb, NewGateway + Index1, IP6_INF_ROUTER_LIFETIME);
1385 OneAdded = TRUE;
1386 }
1387 }
1388
1389 if (!OneRemoved && !OneAdded) {
1390 Item->Status = EFI_SUCCESS;
1391 return EFI_ABORTED;
1392 } else {
1393 if (Tmp != NULL) {
1394 if (Item->Data.Ptr != NULL) {
1395 FreePool (Item->Data.Ptr);
1396 }
1397
1398 Item->Data.Ptr = Tmp;
1399 }
1400
1401 CopyMem (Item->Data.Ptr, Data, DataSize);
1402 Item->DataSize = DataSize;
1403 Item->Status = EFI_SUCCESS;
1404 return EFI_SUCCESS;
1405 }
1406 } else {
1407 //
1408 // DataSize is 0 and Data is NULL, clean up the Gateway address.
1409 //
1410 if (Item->Data.Ptr != NULL) {
1411 FreePool (Item->Data.Ptr);
1412 }
1413
1414 Item->Data.Ptr = NULL;
1415 Item->DataSize = 0;
1416 Item->Status = EFI_NOT_FOUND;
1417 }
1418
1419 return EFI_SUCCESS;
1420}
1421
1422/**
1423 The work function for EfiIp6ConfigSetData() to set the DNS server list for the
1424 EFI IPv6 network stack running on the communication device that this EFI IPv6
1425 Configuration Protocol manages. It is not configurable when the policy is
1426 Ip6ConfigPolicyAutomatic. The DNS server addresses must be unicast IPv6 addresses.
1427
1428 @param[in] Instance The pointer to the IP6 config instance data.
1429 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1430 @param[in] Data The data buffer to set, points to an array of
1431 EFI_IPv6_ADDRESS instances.
1432
1433 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1434 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1435 under the current policy.
1436 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1437 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1438 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1439 configuration.
1440 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1441 network stack was set.
1442
1443**/
1444EFI_STATUS
1445Ip6ConfigSetDnsServer (
1446 IN IP6_CONFIG_INSTANCE *Instance,
1447 IN UINTN DataSize,
1448 IN VOID *Data
1449 )
1450{
1451 UINTN OldIndex;
1452 UINTN NewIndex;
1453 EFI_IPv6_ADDRESS *OldDns;
1454 EFI_IPv6_ADDRESS *NewDns;
1455 UINTN OldDnsCount;
1456 UINTN NewDnsCount;
1457 IP6_CONFIG_DATA_ITEM *Item;
1458 BOOLEAN OneAdded;
1459 VOID *Tmp;
1460
1461 OldDns = NULL;
1462 NewDns = NULL;
1463 Item = NULL;
1464 Tmp = NULL;
1465
1466 if ((DataSize != 0) && (DataSize % sizeof (EFI_IPv6_ADDRESS) != 0)) {
1467 return EFI_BAD_BUFFER_SIZE;
1468 }
1469
1470 if (Instance->Policy != Ip6ConfigPolicyManual) {
1471 return EFI_WRITE_PROTECTED;
1472 }
1473
1474 Item = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];
1475
1476 if ((Data != NULL) && (DataSize != 0)) {
1477 NewDns = (EFI_IPv6_ADDRESS *)Data;
1478 OldDns = Item->Data.DnsServers;
1479 NewDnsCount = DataSize / sizeof (EFI_IPv6_ADDRESS);
1480 OldDnsCount = Item->DataSize / sizeof (EFI_IPv6_ADDRESS);
1481 OneAdded = FALSE;
1482
1483 if (NewDnsCount != OldDnsCount) {
1484 Tmp = AllocatePool (DataSize);
1485 if (Tmp == NULL) {
1486 return EFI_OUT_OF_RESOURCES;
1487 }
1488 } else {
1489 Tmp = NULL;
1490 }
1491
1492 for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {
1493 if (!NetIp6IsValidUnicast (NewDns + NewIndex)) {
1494 //
1495 // The dns server address must be unicast.
1496 //
1497 if (Tmp != NULL) {
1498 FreePool (Tmp);
1499 }
1500
1501 return EFI_INVALID_PARAMETER;
1502 }
1503
1504 if (OneAdded) {
1505 //
1506 // If any address in the new setting is not in the old settings, skip the
1507 // comparision below.
1508 //
1509 continue;
1510 }
1511
1512 for (OldIndex = 0; OldIndex < OldDnsCount; OldIndex++) {
1513 if (EFI_IP6_EQUAL (NewDns + NewIndex, OldDns + OldIndex)) {
1514 //
1515 // If found break out.
1516 //
1517 break;
1518 }
1519 }
1520
1521 if (OldIndex == OldDnsCount) {
1522 OneAdded = TRUE;
1523 }
1524 }
1525
1526 if (!OneAdded && (DataSize == Item->DataSize)) {
1527 //
1528 // No new item is added and the size is the same.
1529 //
1530 Item->Status = EFI_SUCCESS;
1531 return EFI_ABORTED;
1532 } else {
1533 if (Tmp != NULL) {
1534 if (Item->Data.Ptr != NULL) {
1535 FreePool (Item->Data.Ptr);
1536 }
1537
1538 Item->Data.Ptr = Tmp;
1539 }
1540
1541 CopyMem (Item->Data.Ptr, Data, DataSize);
1542 Item->DataSize = DataSize;
1543 Item->Status = EFI_SUCCESS;
1544 }
1545 } else {
1546 //
1547 // DataSize is 0 and Data is NULL, clean up the DnsServer address.
1548 //
1549 if (Item->Data.Ptr != NULL) {
1550 FreePool (Item->Data.Ptr);
1551 }
1552
1553 Item->Data.Ptr = NULL;
1554 Item->DataSize = 0;
1555 Item->Status = EFI_NOT_FOUND;
1556 }
1557
1558 return EFI_SUCCESS;
1559}
1560
1561/**
1562 Generate the operational state of the interface this IP6 config instance manages
1563 and output in EFI_IP6_CONFIG_INTERFACE_INFO.
1564
1565 @param[in] IpSb The pointer to the IP6 service binding instance.
1566 @param[out] IfInfo The pointer to the IP6 configuration interface information structure.
1567
1568**/
1569VOID
1570Ip6ConfigInitIfInfo (
1571 IN IP6_SERVICE *IpSb,
1572 OUT EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo
1573 )
1574{
1575 UnicodeSPrint (
1576 IfInfo->Name,
1577 sizeof (IfInfo->Name),
1578 L"eth%d",
1579 IpSb->Ip6ConfigInstance.IfIndex
1580 );
1581
1582 IfInfo->IfType = IpSb->SnpMode.IfType;
1583 IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;
1584 CopyMem (&IfInfo->HwAddress, &IpSb->SnpMode.CurrentAddress, IfInfo->HwAddressSize);
1585}
1586
1587/**
1588 Parse DHCPv6 reply packet to get the DNS server list.
1589 It is the work function for Ip6ConfigOnDhcp6Reply and Ip6ConfigOnDhcp6Event.
1590
1591 @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL instance.
1592 @param[in, out] Instance The pointer to the IP6 configuration instance data.
1593 @param[in] Reply The pointer to the DHCPv6 reply packet.
1594
1595 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1596 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1597 the DNS server address is not valid.
1598
1599**/
1600EFI_STATUS
1601Ip6ConfigParseDhcpReply (
1602 IN EFI_DHCP6_PROTOCOL *Dhcp6,
1603 IN OUT IP6_CONFIG_INSTANCE *Instance,
1604 IN EFI_DHCP6_PACKET *Reply
1605 )
1606{
1607 EFI_STATUS Status;
1608 UINT32 OptCount;
1609 EFI_DHCP6_PACKET_OPTION **OptList;
1610 UINT16 OpCode;
1611 UINT16 Length;
1612 UINTN Index;
1613 UINTN Index2;
1614 EFI_IPv6_ADDRESS *DnsServer;
1615 IP6_CONFIG_DATA_ITEM *Item;
1616
1617 //
1618 // A DHCPv6 reply packet is received as the response to our InfoRequest
1619 // packet.
1620 //
1621 OptCount = 0;
1622 Status = Dhcp6->Parse (Dhcp6, Reply, &OptCount, NULL);
1623 if (Status != EFI_BUFFER_TOO_SMALL) {
1624 return EFI_NOT_READY;
1625 }
1626
1627 OptList = AllocatePool (OptCount * sizeof (EFI_DHCP6_PACKET_OPTION *));
1628 if (OptList == NULL) {
1629 return EFI_NOT_READY;
1630 }
1631
1632 Status = Dhcp6->Parse (Dhcp6, Reply, &OptCount, OptList);
1633 if (EFI_ERROR (Status)) {
1634 Status = EFI_NOT_READY;
1635 goto ON_EXIT;
1636 }
1637
1638 Status = EFI_SUCCESS;
1639
1640 for (Index = 0; Index < OptCount; Index++) {
1641 //
1642 // Go through all the options to check the ones we are interested in.
1643 // The OpCode and Length are in network byte-order and may not be naturally
1644 // aligned.
1645 //
1646 CopyMem (&OpCode, &OptList[Index]->OpCode, sizeof (OpCode));
1647 OpCode = NTOHS (OpCode);
1648
1649 if (OpCode == DHCP6_OPT_DNS_SERVERS) {
1650 CopyMem (&Length, &OptList[Index]->OpLen, sizeof (Length));
1651 Length = NTOHS (Length);
1652
1653 if ((Length == 0) || ((Length % sizeof (EFI_IPv6_ADDRESS)) != 0)) {
1654 //
1655 // The length should be a multiple of 16 bytes.
1656 //
1657 Status = EFI_NOT_READY;
1658 break;
1659 }
1660
1661 //
1662 // Validate the DnsServers: whether they are unicast addresses.
1663 //
1664 DnsServer = (EFI_IPv6_ADDRESS *)OptList[Index]->Data;
1665 for (Index2 = 0; Index2 < Length / sizeof (EFI_IPv6_ADDRESS); Index2++) {
1666 if (!NetIp6IsValidUnicast (DnsServer)) {
1667 Status = EFI_NOT_READY;
1668 goto ON_EXIT;
1669 }
1670
1671 DnsServer++;
1672 }
1673
1674 Item = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];
1675
1676 if (Item->DataSize != Length) {
1677 if (Item->Data.Ptr != NULL) {
1678 FreePool (Item->Data.Ptr);
1679 }
1680
1681 Item->Data.Ptr = AllocatePool (Length);
1682 ASSERT (Item->Data.Ptr != NULL);
1683 }
1684
1685 CopyMem (Item->Data.Ptr, OptList[Index]->Data, Length);
1686 Item->DataSize = Length;
1687 Item->Status = EFI_SUCCESS;
1688
1689 //
1690 // Signal the waiting events.
1691 //
1692 NetMapIterate (&Item->EventMap, Ip6ConfigSignalEvent, NULL);
1693
1694 break;
1695 }
1696 }
1697
1698ON_EXIT:
1699
1700 FreePool (OptList);
1701 return Status;
1702}
1703
1704/**
1705 The callback function for Ip6SetAddr. The prototype is defined
1706 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
1707 on the tentative address by DHCPv6 in Ip6ConfigOnDhcp6Event().
1708
1709 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passes.
1710 @param[in] TargetAddress The tentative IPv6 address to be checked.
1711 @param[in] Context Pointer to the IP6 configuration instance data.
1712
1713**/
1714VOID
1715Ip6ConfigSetStatefulAddrCallback (
1716 IN BOOLEAN IsDadPassed,
1717 IN EFI_IPv6_ADDRESS *TargetAddress,
1718 IN VOID *Context
1719 )
1720{
1721 IP6_CONFIG_INSTANCE *Instance;
1722
1723 Instance = (IP6_CONFIG_INSTANCE *)Context;
1724 NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
1725
1726 //
1727 // We should record the addresses that fail the DAD, and DECLINE them.
1728 //
1729 if (IsDadPassed) {
1730 //
1731 // Decrease the count, no interests in those passed DAD.
1732 //
1733 if (Instance->FailedIaAddressCount > 0 ) {
1734 Instance->FailedIaAddressCount--;
1735 }
1736 } else {
1737 //
1738 // Record it.
1739 //
1740 IP6_COPY_ADDRESS (Instance->DeclineAddress + Instance->DeclineAddressCount, TargetAddress);
1741 Instance->DeclineAddressCount++;
1742 }
1743
1744 if (Instance->FailedIaAddressCount == Instance->DeclineAddressCount) {
1745 //
1746 // The checking on all addresses are finished.
1747 //
1748 if (Instance->DeclineAddressCount != 0) {
1749 //
1750 // Decline those duplicates.
1751 //
1752 if (Instance->Dhcp6 != NULL) {
1753 Instance->Dhcp6->Decline (
1754 Instance->Dhcp6,
1755 Instance->DeclineAddressCount,
1756 Instance->DeclineAddress
1757 );
1758 }
1759 }
1760
1761 if (Instance->DeclineAddress != NULL) {
1762 FreePool (Instance->DeclineAddress);
1763 }
1764
1765 Instance->DeclineAddress = NULL;
1766 Instance->DeclineAddressCount = 0;
1767 }
1768}
1769
1770/**
1771 The event handle routine when DHCPv6 process is finished or is updated.
1772
1773 @param[in] Event Not used.
1774 @param[in] Context The pointer to the IP6 configuration instance data.
1775
1776**/
1777VOID
1778EFIAPI
1779Ip6ConfigOnDhcp6Event (
1780 IN EFI_EVENT Event,
1781 IN VOID *Context
1782 )
1783{
1784 IP6_CONFIG_INSTANCE *Instance;
1785 EFI_DHCP6_PROTOCOL *Dhcp6;
1786 EFI_STATUS Status;
1787 EFI_DHCP6_MODE_DATA Dhcp6ModeData;
1788 EFI_DHCP6_IA *Ia;
1789 EFI_DHCP6_IA_ADDRESS *IaAddr;
1790 UINT32 Index;
1791 IP6_SERVICE *IpSb;
1792 IP6_ADDRESS_INFO *AddrInfo;
1793 IP6_INTERFACE *IpIf;
1794
1795 Instance = (IP6_CONFIG_INSTANCE *)Context;
1796
1797 if ((Instance->Policy != Ip6ConfigPolicyAutomatic) || Instance->OtherInfoOnly) {
1798 //
1799 // IPv6 is not operating in the automatic policy now or
1800 // the DHCPv6 information request message exchange is aborted.
1801 //
1802 return;
1803 }
1804
1805 //
1806 // The stateful address autoconfiguration is done or updated.
1807 //
1808 Dhcp6 = Instance->Dhcp6;
1809
1810 Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);
1811 if (EFI_ERROR (Status)) {
1812 return;
1813 }
1814
1815 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
1816 IpIf = IpSb->DefaultInterface;
1817 Ia = Dhcp6ModeData.Ia;
1818 IaAddr = Ia->IaAddress;
1819
1820 if (Instance->DeclineAddress != NULL) {
1821 FreePool (Instance->DeclineAddress);
1822 }
1823
1824 Instance->DeclineAddress = (EFI_IPv6_ADDRESS *)AllocatePool (Ia->IaAddressCount * sizeof (EFI_IPv6_ADDRESS));
1825 if (Instance->DeclineAddress == NULL) {
1826 goto ON_EXIT;
1827 }
1828
1829 Instance->FailedIaAddressCount = Ia->IaAddressCount;
1830 Instance->DeclineAddressCount = 0;
1831
1832 for (Index = 0; Index < Ia->IaAddressCount; Index++, IaAddr++) {
1833 if ((Ia->IaAddress[Index].ValidLifetime != 0) && (Ia->State == Dhcp6Bound)) {
1834 //
1835 // Set this address, either it's a new address or with updated lifetimes.
1836 // An appropriate prefix length will be set.
1837 //
1838 Ip6SetAddress (
1839 IpIf,
1840 &IaAddr->IpAddress,
1841 FALSE,
1842 0,
1843 IaAddr->ValidLifetime,
1844 IaAddr->PreferredLifetime,
1845 Ip6ConfigSetStatefulAddrCallback,
1846 Instance
1847 );
1848 } else {
1849 //
1850 // discard this address, artificially decrease the count as if this address
1851 // passed DAD.
1852 //
1853 if (Ip6IsOneOfSetAddress (IpSb, &IaAddr->IpAddress, NULL, &AddrInfo)) {
1854 ASSERT (AddrInfo != NULL);
1855 Ip6RemoveAddr (
1856 IpSb,
1857 &IpIf->AddressList,
1858 &IpIf->AddressCount,
1859 &AddrInfo->Address,
1860 AddrInfo->PrefixLength
1861 );
1862 }
1863
1864 if (Instance->FailedIaAddressCount > 0) {
1865 Instance->FailedIaAddressCount--;
1866 }
1867 }
1868 }
1869
1870 //
1871 // Parse the Reply packet to get the options we need.
1872 //
1873 if (Dhcp6ModeData.Ia->ReplyPacket != NULL) {
1874 Ip6ConfigParseDhcpReply (Dhcp6, Instance, Dhcp6ModeData.Ia->ReplyPacket);
1875 }
1876
1877ON_EXIT:
1878
1879 FreePool (Dhcp6ModeData.ClientId);
1880 FreePool (Dhcp6ModeData.Ia);
1881}
1882
1883/**
1884 The event process routine when the DHCPv6 server is answered with a reply packet
1885 for an information request.
1886
1887 @param[in] This Points to the EFI_DHCP6_PROTOCOL.
1888 @param[in] Context The pointer to the IP6 configuration instance data.
1889 @param[in] Packet The DHCPv6 reply packet.
1890
1891 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1892 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1893 the DNS server address is not valid.
1894
1895**/
1896EFI_STATUS
1897EFIAPI
1898Ip6ConfigOnDhcp6Reply (
1899 IN EFI_DHCP6_PROTOCOL *This,
1900 IN VOID *Context,
1901 IN EFI_DHCP6_PACKET *Packet
1902 )
1903{
1904 return Ip6ConfigParseDhcpReply (This, (IP6_CONFIG_INSTANCE *)Context, Packet);
1905}
1906
1907/**
1908 The event process routine when the DHCPv6 service binding protocol is installed
1909 in the system.
1910
1911 @param[in] Event Not used.
1912 @param[in] Context The pointer to the IP6 config instance data.
1913
1914**/
1915VOID
1916EFIAPI
1917Ip6ConfigOnDhcp6SbInstalled (
1918 IN EFI_EVENT Event,
1919 IN VOID *Context
1920 )
1921{
1922 IP6_CONFIG_INSTANCE *Instance;
1923
1924 Instance = (IP6_CONFIG_INSTANCE *)Context;
1925
1926 if ((Instance->Dhcp6Handle != NULL) || (Instance->Policy != Ip6ConfigPolicyAutomatic)) {
1927 //
1928 // The DHCP6 child is already created or the policy is no longer AUTOMATIC.
1929 //
1930 return;
1931 }
1932
1933 Ip6ConfigStartStatefulAutoConfig (Instance, Instance->OtherInfoOnly);
1934}
1935
1936/**
1937 Set the configuration for the EFI IPv6 network stack running on the communication
1938 device this EFI IPv6 Configuration Protocol instance manages.
1939
1940 This function is used to set the configuration data of type DataType for the EFI
1941 IPv6 network stack that is running on the communication device that this EFI IPv6
1942 Configuration Protocol instance manages.
1943
1944 DataSize is used to calculate the count of structure instances in the Data for
1945 a DataType in which multiple structure instances are allowed.
1946
1947 This function is always non-blocking. When setting some type of configuration data,
1948 an asynchronous process is invoked to check the correctness of the data, such as
1949 performing Duplicate Address Detection on the manually set local IPv6 addresses.
1950 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1951 is invoked, and the process is not finished yet. The caller wanting to get the result
1952 of the asynchronous process is required to call RegisterDataNotify() to register an
1953 event on the specified configuration data. Once the event is signaled, the caller
1954 can call GetData() to obtain the configuration data and know the result.
1955 For other types of configuration data that do not require an asynchronous configuration
1956 process, the result of the operation is immediately returned.
1957
1958 @param[in] This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1959 @param[in] DataType The type of data to set.
1960 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1961 @param[in] Data The data buffer to set. The type of the data buffer is
1962 associated with the DataType.
1963
1964 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1965 network stack was set successfully.
1966 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1967 - This is NULL.
1968 - One or more fields in Data and DataSizedo not match the
1969 requirement of the data type indicated by DataType.
1970 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1971 configuration data cannot be set under the current policy.
1972 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1973 data is already in process.
1974 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1975 configuration data, and the process is not finished yet.
1976 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1977 indicated by DataType.
1978 @retval EFI_UNSUPPORTED This DataType is not supported.
1979 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1980 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1981
1982**/
1983EFI_STATUS
1984EFIAPI
1985EfiIp6ConfigSetData (
1986 IN EFI_IP6_CONFIG_PROTOCOL *This,
1987 IN EFI_IP6_CONFIG_DATA_TYPE DataType,
1988 IN UINTN DataSize,
1989 IN VOID *Data
1990 )
1991{
1992 EFI_TPL OldTpl;
1993 EFI_STATUS Status;
1994 IP6_CONFIG_INSTANCE *Instance;
1995 IP6_SERVICE *IpSb;
1996
1997 if ((This == NULL) || ((Data == NULL) && (DataSize != 0)) || ((Data != NULL) && (DataSize == 0))) {
1998 return EFI_INVALID_PARAMETER;
1999 }
2000
2001 if (DataType >= Ip6ConfigDataTypeMaximum) {
2002 return EFI_UNSUPPORTED;
2003 }
2004
2005 Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);
2006 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
2007 NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE);
2008
2009 if (IpSb->LinkLocalDadFail) {
2010 return EFI_DEVICE_ERROR;
2011 }
2012
2013 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2014
2015 Status = Instance->DataItem[DataType].Status;
2016 if (Status != EFI_NOT_READY) {
2017 if (Instance->DataItem[DataType].SetData == NULL) {
2018 //
2019 // This type of data is readonly.
2020 //
2021 Status = EFI_WRITE_PROTECTED;
2022 } else {
2023 Status = Instance->DataItem[DataType].SetData (Instance, DataSize, Data);
2024 if (!EFI_ERROR (Status)) {
2025 //
2026 // Fire up the events registered with this type of data.
2027 //
2028 NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip6ConfigSignalEvent, NULL);
2029 Ip6ConfigWriteConfigData (IpSb->MacString, Instance);
2030 } else if (Status == EFI_ABORTED) {
2031 //
2032 // The SetData is aborted because the data to set is the same with
2033 // the one maintained.
2034 //
2035 Status = EFI_SUCCESS;
2036 NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip6ConfigSignalEvent, NULL);
2037 }
2038 }
2039 } else {
2040 //
2041 // Another asynchronous process is on the way.
2042 //
2043 Status = EFI_ACCESS_DENIED;
2044 }
2045
2046 gBS->RestoreTPL (OldTpl);
2047
2048 return Status;
2049}
2050
2051/**
2052 Get the configuration data for the EFI IPv6 network stack running on the communication
2053 device that this EFI IPv6 Configuration Protocol instance manages.
2054
2055 This function returns the configuration data of type DataType for the EFI IPv6 network
2056 stack running on the communication device that this EFI IPv6 Configuration Protocol instance
2057 manages.
2058
2059 The caller is responsible for allocating the buffer used to return the specified
2060 configuration data. The required size will be returned to the caller if the size of
2061 the buffer is too small.
2062
2063 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
2064 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
2065 to register an event on the specified configuration data. Once the asynchronous configuration
2066 process is finished, the event will be signaled, and a subsequent GetData() call will return
2067 the specified configuration data.
2068
2069 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2070 @param[in] DataType The type of data to get.
2071 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
2072 size of buffer required to store the specified configuration data.
2073 @param[in] Data The data buffer in which the configuration data is returned. The
2074 type of the data buffer is associated with the DataType.
2075 This is an optional parameter that may be NULL.
2076
2077 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
2078 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
2079 - This is NULL.
2080 - DataSize is NULL.
2081 - Data is NULL if *DataSize is not zero.
2082 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
2083 and the required size is returned in DataSize.
2084 @retval EFI_NOT_READY The specified configuration data is not ready due to an
2085 asynchronous configuration process already in progress.
2086 @retval EFI_NOT_FOUND The specified configuration data is not found.
2087
2088**/
2089EFI_STATUS
2090EFIAPI
2091EfiIp6ConfigGetData (
2092 IN EFI_IP6_CONFIG_PROTOCOL *This,
2093 IN EFI_IP6_CONFIG_DATA_TYPE DataType,
2094 IN OUT UINTN *DataSize,
2095 IN VOID *Data OPTIONAL
2096 )
2097{
2098 EFI_TPL OldTpl;
2099 EFI_STATUS Status;
2100 IP6_CONFIG_INSTANCE *Instance;
2101 IP6_CONFIG_DATA_ITEM *DataItem;
2102
2103 if ((This == NULL) || (DataSize == NULL) || ((*DataSize != 0) && (Data == NULL))) {
2104 return EFI_INVALID_PARAMETER;
2105 }
2106
2107 if (DataType >= Ip6ConfigDataTypeMaximum) {
2108 return EFI_NOT_FOUND;
2109 }
2110
2111 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2112
2113 Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);
2114 DataItem = &Instance->DataItem[DataType];
2115
2116 Status = Instance->DataItem[DataType].Status;
2117 if (!EFI_ERROR (Status)) {
2118 if (DataItem->GetData != NULL) {
2119 Status = DataItem->GetData (Instance, DataSize, Data);
2120 } else if (*DataSize < Instance->DataItem[DataType].DataSize) {
2121 //
2122 // Update the buffer length.
2123 //
2124 *DataSize = Instance->DataItem[DataType].DataSize;
2125 Status = EFI_BUFFER_TOO_SMALL;
2126 } else {
2127 *DataSize = Instance->DataItem[DataType].DataSize;
2128 CopyMem (Data, Instance->DataItem[DataType].Data.Ptr, *DataSize);
2129 }
2130 }
2131
2132 gBS->RestoreTPL (OldTpl);
2133
2134 return Status;
2135}
2136
2137/**
2138 Register an event that is signaled whenever a configuration process on the specified
2139 configuration data is done.
2140
2141 This function registers an event that is to be signaled whenever a configuration
2142 process on the specified configuration data is performed. An event can be registered
2143 for a different DataType simultaneously. The caller is responsible for determining
2144 which type of configuration data causes the signaling of the event in such an event.
2145
2146 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2147 @param[in] DataType The type of data to unregister the event for.
2148 @param[in] Event The event to register.
2149
2150 @retval EFI_SUCCESS The notification event for the specified configuration data is
2151 registered.
2152 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2153 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
2154 supported.
2155 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2156 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2157
2158**/
2159EFI_STATUS
2160EFIAPI
2161EfiIp6ConfigRegisterDataNotify (
2162 IN EFI_IP6_CONFIG_PROTOCOL *This,
2163 IN EFI_IP6_CONFIG_DATA_TYPE DataType,
2164 IN EFI_EVENT Event
2165 )
2166{
2167 EFI_TPL OldTpl;
2168 EFI_STATUS Status;
2169 IP6_CONFIG_INSTANCE *Instance;
2170 NET_MAP *EventMap;
2171 NET_MAP_ITEM *Item;
2172
2173 if ((This == NULL) || (Event == NULL)) {
2174 return EFI_INVALID_PARAMETER;
2175 }
2176
2177 if (DataType >= Ip6ConfigDataTypeMaximum) {
2178 return EFI_UNSUPPORTED;
2179 }
2180
2181 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2182
2183 Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);
2184 EventMap = &Instance->DataItem[DataType].EventMap;
2185
2186 //
2187 // Check whether this event is already registered for this DataType.
2188 //
2189 Item = NetMapFindKey (EventMap, Event);
2190 if (Item == NULL) {
2191 Status = NetMapInsertTail (EventMap, Event, NULL);
2192
2193 if (EFI_ERROR (Status)) {
2194 Status = EFI_OUT_OF_RESOURCES;
2195 }
2196 } else {
2197 Status = EFI_ACCESS_DENIED;
2198 }
2199
2200 gBS->RestoreTPL (OldTpl);
2201
2202 return Status;
2203}
2204
2205/**
2206 Remove a previously registered event for the specified configuration data.
2207
2208 @param This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2209 @param DataType The type of data to remove from the previously
2210 registered event.
2211 @param Event The event to be unregistered.
2212
2213 @retval EFI_SUCCESS The event registered for the specified
2214 configuration data was removed.
2215 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2216 @retval EFI_NOT_FOUND The Event has not been registered for the
2217 specified DataType.
2218
2219**/
2220EFI_STATUS
2221EFIAPI
2222EfiIp6ConfigUnregisterDataNotify (
2223 IN EFI_IP6_CONFIG_PROTOCOL *This,
2224 IN EFI_IP6_CONFIG_DATA_TYPE DataType,
2225 IN EFI_EVENT Event
2226 )
2227{
2228 EFI_TPL OldTpl;
2229 EFI_STATUS Status;
2230 IP6_CONFIG_INSTANCE *Instance;
2231 NET_MAP_ITEM *Item;
2232
2233 if ((This == NULL) || (Event == NULL)) {
2234 return EFI_INVALID_PARAMETER;
2235 }
2236
2237 if (DataType >= Ip6ConfigDataTypeMaximum) {
2238 return EFI_NOT_FOUND;
2239 }
2240
2241 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
2242
2243 Instance = IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This);
2244
2245 Item = NetMapFindKey (&Instance->DataItem[DataType].EventMap, Event);
2246 if (Item != NULL) {
2247 NetMapRemoveItem (&Instance->DataItem[DataType].EventMap, Item, NULL);
2248 Status = EFI_SUCCESS;
2249 } else {
2250 Status = EFI_NOT_FOUND;
2251 }
2252
2253 gBS->RestoreTPL (OldTpl);
2254
2255 return Status;
2256}
2257
2258/**
2259 Initialize an IP6_CONFIG_INSTANCE.
2260
2261 @param[out] Instance The buffer of IP6_CONFIG_INSTANCE to be initialized.
2262
2263 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
2264 @retval EFI_SUCCESS The IP6_CONFIG_INSTANCE initialized successfully.
2265
2266**/
2267EFI_STATUS
2268Ip6ConfigInitInstance (
2269 OUT IP6_CONFIG_INSTANCE *Instance
2270 )
2271{
2272 IP6_SERVICE *IpSb;
2273 IP6_CONFIG_INSTANCE *TmpInstance;
2274 LIST_ENTRY *Entry;
2275 EFI_STATUS Status;
2276 UINTN Index;
2277 UINT16 IfIndex;
2278 IP6_CONFIG_DATA_ITEM *DataItem;
2279 UINT32 Random;
2280
2281 Status = PseudoRandomU32 (&Random);
2282 if (EFI_ERROR (Status)) {
2283 DEBUG ((DEBUG_ERROR, "%a failed to generate random number: %r\n", __func__, Status));
2284 return Status;
2285 }
2286
2287 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
2288
2289 Instance->Signature = IP6_CONFIG_INSTANCE_SIGNATURE;
2290
2291 //
2292 // Determine the index of this interface.
2293 //
2294 IfIndex = 0;
2295 NET_LIST_FOR_EACH (Entry, &mIp6ConfigInstanceList) {
2296 TmpInstance = NET_LIST_USER_STRUCT_S (Entry, IP6_CONFIG_INSTANCE, Link, IP6_CONFIG_INSTANCE_SIGNATURE);
2297
2298 if (TmpInstance->IfIndex > IfIndex) {
2299 //
2300 // There is a sequence hole because some interface is down.
2301 //
2302 break;
2303 }
2304
2305 IfIndex++;
2306 }
2307
2308 Instance->IfIndex = IfIndex;
2309 NetListInsertBefore (Entry, &Instance->Link);
2310
2311 for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {
2312 //
2313 // Initialize the event map for each data item.
2314 //
2315 NetMapInit (&Instance->DataItem[Index].EventMap);
2316 }
2317
2318 //
2319 // Initialize the NET_MAPs used for DAD on manually configured source addresses.
2320 //
2321 NetMapInit (&Instance->DadFailedMap);
2322 NetMapInit (&Instance->DadPassedMap);
2323
2324 //
2325 // Initialize each data type: associate storage and set data size for the
2326 // fixed size data types, hook the SetData function, set the data attribute.
2327 //
2328 DataItem = &Instance->DataItem[Ip6ConfigDataTypeInterfaceInfo];
2329 DataItem->GetData = Ip6ConfigGetIfInfo;
2330 DataItem->Data.Ptr = &Instance->InterfaceInfo;
2331 DataItem->DataSize = sizeof (Instance->InterfaceInfo);
2332 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED | DATA_ATTRIB_VOLATILE);
2333 Ip6ConfigInitIfInfo (IpSb, &Instance->InterfaceInfo);
2334
2335 DataItem = &Instance->DataItem[Ip6ConfigDataTypeAltInterfaceId];
2336 DataItem->SetData = Ip6ConfigSetAltIfId;
2337 DataItem->Data.Ptr = &Instance->AltIfId;
2338 DataItem->DataSize = sizeof (Instance->AltIfId);
2339 DataItem->Status = EFI_NOT_FOUND;
2340 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);
2341
2342 DataItem = &Instance->DataItem[Ip6ConfigDataTypePolicy];
2343 DataItem->SetData = Ip6ConfigSetPolicy;
2344 DataItem->Data.Ptr = &Instance->Policy;
2345 DataItem->DataSize = sizeof (Instance->Policy);
2346 Instance->Policy = Ip6ConfigPolicyManual;
2347 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);
2348
2349 DataItem = &Instance->DataItem[Ip6ConfigDataTypeDupAddrDetectTransmits];
2350 DataItem->SetData = Ip6ConfigSetDadXmits;
2351 DataItem->Data.Ptr = &Instance->DadXmits;
2352 DataItem->DataSize = sizeof (Instance->DadXmits);
2353 Instance->DadXmits.DupAddrDetectTransmits = IP6_CONFIG_DEFAULT_DAD_XMITS;
2354 SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);
2355
2356 DataItem = &Instance->DataItem[Ip6ConfigDataTypeManualAddress];
2357 DataItem->SetData = Ip6ConfigSetManualAddress;
2358 DataItem->Status = EFI_NOT_FOUND;
2359
2360 DataItem = &Instance->DataItem[Ip6ConfigDataTypeGateway];
2361 DataItem->SetData = Ip6ConfigSetGateway;
2362 DataItem->Status = EFI_NOT_FOUND;
2363
2364 DataItem = &Instance->DataItem[Ip6ConfigDataTypeDnsServer];
2365 DataItem->SetData = Ip6ConfigSetDnsServer;
2366 DataItem->Status = EFI_NOT_FOUND;
2367
2368 //
2369 // Create the event used for DHCP.
2370 //
2371 Status = gBS->CreateEvent (
2372 EVT_NOTIFY_SIGNAL,
2373 TPL_CALLBACK,
2374 Ip6ConfigOnDhcp6Event,
2375 Instance,
2376 &Instance->Dhcp6Event
2377 );
2378 ASSERT_EFI_ERROR (Status);
2379
2380 Instance->Configured = TRUE;
2381
2382 //
2383 // Try to read the config data from NV variable.
2384 //
2385 Status = Ip6ConfigReadConfigData (IpSb->MacString, Instance);
2386 if (Status == EFI_NOT_FOUND) {
2387 //
2388 // The NV variable is not set, so generate a random IAID, and write down the
2389 // fresh new configuration as the NV variable now.
2390 //
2391 Instance->IaId = Random;
2392
2393 for (Index = 0; Index < IpSb->SnpMode.HwAddressSize; Index++) {
2394 Instance->IaId |= (IpSb->SnpMode.CurrentAddress.Addr[Index] << ((Index << 3) & 31));
2395 }
2396
2397 Ip6ConfigWriteConfigData (IpSb->MacString, Instance);
2398 } else if (EFI_ERROR (Status)) {
2399 return Status;
2400 }
2401
2402 Instance->Ip6Config.SetData = EfiIp6ConfigSetData;
2403 Instance->Ip6Config.GetData = EfiIp6ConfigGetData;
2404 Instance->Ip6Config.RegisterDataNotify = EfiIp6ConfigRegisterDataNotify;
2405 Instance->Ip6Config.UnregisterDataNotify = EfiIp6ConfigUnregisterDataNotify;
2406
2407 //
2408 // Publish the IP6 configuration form
2409 //
2410 return Ip6ConfigFormInit (Instance);
2411}
2412
2413/**
2414 Release an IP6_CONFIG_INSTANCE.
2415
2416 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2417
2418**/
2419VOID
2420Ip6ConfigCleanInstance (
2421 IN OUT IP6_CONFIG_INSTANCE *Instance
2422 )
2423{
2424 UINTN Index;
2425 IP6_CONFIG_DATA_ITEM *DataItem;
2426
2427 if (Instance->DeclineAddress != NULL) {
2428 FreePool (Instance->DeclineAddress);
2429 }
2430
2431 if (!Instance->Configured) {
2432 return;
2433 }
2434
2435 if (Instance->Dhcp6Handle != NULL) {
2436 Ip6ConfigDestroyDhcp6 (Instance);
2437 }
2438
2439 //
2440 // Close the event.
2441 //
2442 if (Instance->Dhcp6Event != NULL) {
2443 gBS->CloseEvent (Instance->Dhcp6Event);
2444 }
2445
2446 NetMapClean (&Instance->DadPassedMap);
2447 NetMapClean (&Instance->DadFailedMap);
2448
2449 for (Index = 0; Index < Ip6ConfigDataTypeMaximum; Index++) {
2450 DataItem = &Instance->DataItem[Index];
2451
2452 if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {
2453 if (DataItem->Data.Ptr != NULL) {
2454 FreePool (DataItem->Data.Ptr);
2455 }
2456
2457 DataItem->Data.Ptr = NULL;
2458 DataItem->DataSize = 0;
2459 }
2460
2461 NetMapClean (&Instance->DataItem[Index].EventMap);
2462 }
2463
2464 Ip6ConfigFormUnload (Instance);
2465
2466 RemoveEntryList (&Instance->Link);
2467}
2468
2469/**
2470 Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
2471
2472 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2473
2474 @retval EFI_SUCCESS The child was successfully destroyed.
2475 @retval Others Failed to destroy the child.
2476
2477**/
2478EFI_STATUS
2479Ip6ConfigDestroyDhcp6 (
2480 IN OUT IP6_CONFIG_INSTANCE *Instance
2481 )
2482{
2483 IP6_SERVICE *IpSb;
2484 EFI_STATUS Status;
2485 EFI_DHCP6_PROTOCOL *Dhcp6;
2486
2487 Dhcp6 = Instance->Dhcp6;
2488 ASSERT (Dhcp6 != NULL);
2489
2490 Dhcp6->Stop (Dhcp6);
2491 Dhcp6->Configure (Dhcp6, NULL);
2492 Instance->Dhcp6 = NULL;
2493
2494 IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
2495
2496 //
2497 // Close DHCPv6 protocol and destroy the child.
2498 //
2499 Status = gBS->CloseProtocol (
2500 Instance->Dhcp6Handle,
2501 &gEfiDhcp6ProtocolGuid,
2502 IpSb->Image,
2503 IpSb->Controller
2504 );
2505 if (EFI_ERROR (Status)) {
2506 return Status;
2507 }
2508
2509 Status = NetLibDestroyServiceChild (
2510 IpSb->Controller,
2511 IpSb->Image,
2512 &gEfiDhcp6ServiceBindingProtocolGuid,
2513 Instance->Dhcp6Handle
2514 );
2515
2516 Instance->Dhcp6Handle = NULL;
2517
2518 return Status;
2519}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette