TianoCore EDK2 master
Loading...
Searching...
No Matches
Ip6ConfigImpl.c
Go to the documentation of this file.
1
11#include "Ip6Impl.h"
12
13LIST_ENTRY mIp6ConfigInstanceList = { &mIp6ConfigInstanceList, &mIp6ConfigInstanceList };
14
23VOID
24EFIAPI
26 IN EFI_EVENT Event,
27 IN VOID *Context
28 );
29
39VOID
41 IN IP6_SERVICE *IpSb,
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 //
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) {
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.
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
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];
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,
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];
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,
301 Instance
302 );
303 } else {
304 IpSb->Dhcp6NeedInfoRequest = TRUE;
305 }
306 }
307
308 return Status;
309}
310
320EFIAPI
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
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
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
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;
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
637 IN IP6_CONFIG_INSTANCE *Instance,
638 IN UINTN DataSize,
639 IN VOID *Data
640 )
641{
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
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
767 IN IP6_CONFIG_INSTANCE *Instance,
768 IN UINTN DataSize,
769 IN VOID *Data
770 )
771{
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
798VOID
800 IN BOOLEAN IsDadPassed,
801 IN EFI_IPv6_ADDRESS *TargetAddress,
802 IN VOID *Context
803 )
804{
805 IP6_CONFIG_INSTANCE *Instance;
806 UINTN Index;
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
932 IN IP6_CONFIG_INSTANCE *Instance,
933 IN UINTN DataSize,
934 IN VOID *Data
935 )
936{
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 //
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) {
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 //
1146 IpSb->DefaultInterface,
1147 &NewAddress->Address,
1148 NewAddress->IsAnycast,
1149 NewAddress->PrefixLength,
1150 (UINT32)IP6_INFINIT_LIFETIME,
1151 (UINT32)IP6_INFINIT_LIFETIME,
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 //
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
1230 Ip6CleanPrefixListTable (IpSb, &IpSb->OnlinkPrefix);
1231 Ip6CleanPrefixListTable (IpSb, &IpSb->AutonomousPrefix);
1232 Ip6CleanAssembleTable (&IpSb->Assemble);
1233
1234 if (IpSb->LinkLocalOk) {
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
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
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;
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
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;
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
1569VOID
1571 IN IP6_SERVICE *IpSb,
1573 )
1574{
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
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;
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
1714VOID
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
1777VOID
1778EFIAPI
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 //
1839 IpIf,
1840 &IaAddr->IpAddress,
1841 FALSE,
1842 0,
1843 IaAddr->ValidLifetime,
1844 IaAddr->PreferredLifetime,
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);
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
1897EFIAPI
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
1915VOID
1916EFIAPI
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
1984EFIAPI
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
2090EFIAPI
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
2160EFIAPI
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
2221EFIAPI
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
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,
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
2419VOID
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
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}
UINT64 UINTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define EFI_DHCP6_IA_TYPE_NA
Definition: Dhcp6.h:134
@ Dhcp6Bound
Definition: Dhcp6.h:63
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS Ip6RemoveAddr(IN IP6_SERVICE *IpSb OPTIONAL, IN OUT LIST_ENTRY *AddressList, IN OUT UINT32 *AddressCount, IN EFI_IPv6_ADDRESS *Prefix OPTIONAL, IN UINT8 PrefixLength)
Definition: Ip6Common.c:411
BOOLEAN Ip6IsOneOfSetAddress(IN IP6_SERVICE *IpSb, IN EFI_IPv6_ADDRESS *Address, OUT IP6_INTERFACE **Interface OPTIONAL, OUT IP6_ADDRESS_INFO **AddressInfo OPTIONAL)
Definition: Ip6Common.c:504
EFI_STATUS Ip6BuildEfiAddressList(IN IP6_SERVICE *IpSb, OUT UINT32 *AddressCount, OUT EFI_IP6_ADDRESS_INFO **AddressList OPTIONAL)
Definition: Ip6Common.c:29
EFI_IP6_CONFIG_DATA_TYPE
Definition: Ip6Config.h:25
@ Ip6ConfigDataTypeDupAddrDetectTransmits
Definition: Ip6Config.h:59
@ Ip6ConfigDataTypeMaximum
Definition: Ip6Config.h:94
@ Ip6ConfigDataTypeGateway
Definition: Ip6Config.h:79
@ Ip6ConfigDataTypeAltInterfaceId
Definition: Ip6Config.h:42
@ Ip6ConfigDataTypeManualAddress
Definition: Ip6Config.h:68
@ Ip6ConfigDataTypeInterfaceInfo
Definition: Ip6Config.h:32
@ Ip6ConfigDataTypePolicy
Definition: Ip6Config.h:50
@ Ip6ConfigDataTypeDnsServer
Definition: Ip6Config.h:90
EFI_IP6_CONFIG_POLICY
Definition: Ip6Config.h:154
@ Ip6ConfigPolicyManual
Definition: Ip6Config.h:163
@ Ip6ConfigPolicyAutomatic
Definition: Ip6Config.h:175
EFI_STATUS Ip6ConfigSetManualAddress(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS Ip6ConfigSetPolicy(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
VOID Ip6ConfigInitIfInfo(IN IP6_SERVICE *IpSb, OUT EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo)
EFI_STATUS Ip6ConfigGetIfInfo(IN IP6_CONFIG_INSTANCE *Instance, IN OUT UINTN *DataSize, IN VOID *Data OPTIONAL)
EFI_STATUS Ip6ConfigSetDadXmits(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS Ip6ConfigSetAltIfId(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS EFIAPI EfiIp6ConfigSetData(IN EFI_IP6_CONFIG_PROTOCOL *This, IN EFI_IP6_CONFIG_DATA_TYPE DataType, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS Ip6ConfigSetGateway(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS EFIAPI Ip6ConfigOnDhcp6Reply(IN EFI_DHCP6_PROTOCOL *This, IN VOID *Context, IN EFI_DHCP6_PACKET *Packet)
EFI_STATUS Ip6ConfigParseDhcpReply(IN EFI_DHCP6_PROTOCOL *Dhcp6, IN OUT IP6_CONFIG_INSTANCE *Instance, IN EFI_DHCP6_PACKET *Reply)
EFI_STATUS EFIAPI EfiIp6ConfigRegisterDataNotify(IN EFI_IP6_CONFIG_PROTOCOL *This, IN EFI_IP6_CONFIG_DATA_TYPE DataType, IN EFI_EVENT Event)
EFI_STATUS Ip6ConfigSetDnsServer(IN IP6_CONFIG_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data)
VOID EFIAPI Ip6ConfigOnDhcp6SbInstalled(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI EfiIp6ConfigUnregisterDataNotify(IN EFI_IP6_CONFIG_PROTOCOL *This, IN EFI_IP6_CONFIG_DATA_TYPE DataType, IN EFI_EVENT Event)
EFI_STATUS EFIAPI EfiIp6ConfigGetData(IN EFI_IP6_CONFIG_PROTOCOL *This, IN EFI_IP6_CONFIG_DATA_TYPE DataType, IN OUT UINTN *DataSize, IN VOID *Data OPTIONAL)
VOID Ip6ConfigCleanInstance(IN OUT IP6_CONFIG_INSTANCE *Instance)
EFI_STATUS Ip6ConfigStartStatefulAutoConfig(IN IP6_CONFIG_INSTANCE *Instance, IN BOOLEAN OtherInfoOnly)
EFI_STATUS EFIAPI Ip6ConfigSignalEvent(IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg)
EFI_STATUS Ip6ConfigInitInstance(OUT IP6_CONFIG_INSTANCE *Instance)
EFI_STATUS Ip6ConfigDestroyDhcp6(IN OUT IP6_CONFIG_INSTANCE *Instance)
VOID EFIAPI Ip6ConfigOnDhcp6Event(IN EFI_EVENT Event, IN VOID *Context)
VOID Ip6ConfigOnPolicyChanged(IN IP6_SERVICE *IpSb, IN EFI_IP6_CONFIG_POLICY NewPolicy)
Definition: Ip6ConfigImpl.c:40
VOID Ip6ManualAddrDadCallback(IN BOOLEAN IsDadPassed, IN EFI_IPv6_ADDRESS *TargetAddress, IN VOID *Context)
EFI_STATUS Ip6ConfigWriteConfigData(IN CHAR16 *VarName, IN IP6_CONFIG_INSTANCE *Instance)
EFI_STATUS Ip6ConfigReadConfigData(IN CHAR16 *VarName, IN OUT IP6_CONFIG_INSTANCE *Instance)
VOID Ip6ConfigSetStatefulAddrCallback(IN BOOLEAN IsDadPassed, IN EFI_IPv6_ADDRESS *TargetAddress, IN VOID *Context)
EFI_STATUS Ip6ConfigFormInit(IN OUT IP6_CONFIG_INSTANCE *Instance)
Definition: Ip6ConfigNv.c:1887
VOID Ip6ConfigFormUnload(IN OUT IP6_CONFIG_INSTANCE *Instance)
Definition: Ip6ConfigNv.c:2036
EFI_STATUS Ip6SetAddress(IN IP6_INTERFACE *Interface, IN EFI_IPv6_ADDRESS *Ip6Addr, IN BOOLEAN IsAnycast, IN UINT8 PrefixLength, IN UINT32 ValidLifetime, IN UINT32 PreferredLifetime, IN IP6_DAD_CALLBACK DadCallback OPTIONAL, IN VOID *Context OPTIONAL)
Definition: Ip6If.c:75
VOID Ip6CleanAssembleTable(IN OUT IP6_ASSEMBLE_TABLE *Table)
Definition: Ip6Input.c:1136
IP6_DEFAULT_ROUTER * Ip6CreateDefaultRouter(IN IP6_SERVICE *IpSb, IN EFI_IPv6_ADDRESS *Ip6Address, IN UINT16 RouterLifetime)
Definition: Ip6Nd.c:691
VOID Ip6DestroyDefaultRouter(IN IP6_SERVICE *IpSb, IN IP6_DEFAULT_ROUTER *DefaultRouter)
Definition: Ip6Nd.c:738
VOID Ip6OnDADFinished(IN BOOLEAN IsDadPassed, IN IP6_INTERFACE *IpIf, IN IP6_DAD_ENTRY *DadEntry)
Definition: Ip6Nd.c:818
IP6_PREFIX_LIST_ENTRY * Ip6FindPrefixListEntry(IN IP6_SERVICE *IpSb, IN BOOLEAN OnLinkOrAuto, IN UINT8 PrefixLength, IN EFI_IPv6_ADDRESS *Prefix)
Definition: Ip6Nd.c:337
VOID Ip6CleanDefaultRouterList(IN IP6_SERVICE *IpSb)
Definition: Ip6Nd.c:765
VOID Ip6CleanPrefixListTable(IN IP6_SERVICE *IpSb, IN LIST_ENTRY *ListHead)
Definition: Ip6Nd.c:391
VOID Ip6DestroyPrefixListEntry(IN IP6_SERVICE *IpSb, IN IP6_PREFIX_LIST_ENTRY *PrefixEntry, IN BOOLEAN OnLinkOrAuto, IN BOOLEAN ImmediateDelete)
Definition: Ip6Nd.c:281
IP6_DEFAULT_ROUTER * Ip6FindDefaultRouter(IN IP6_SERVICE *IpSb, IN EFI_IPv6_ADDRESS *Ip6Address)
Definition: Ip6Nd.c:788
IP6_PREFIX_LIST_ENTRY * Ip6CreatePrefixListEntry(IN IP6_SERVICE *IpSb, IN BOOLEAN OnLinkOrAuto, IN UINT32 ValidLifetime, IN UINT32 PreferredLifetime, IN UINT8 PrefixLength, IN EFI_IPv6_ADDRESS *Prefix)
Definition: Ip6Nd.c:191
EFI_STATUS Ip6BuildEfiRouteTable(IN IP6_ROUTE_TABLE *RouteTable, OUT UINT32 *EfiRouteCount, OUT EFI_IP6_ROUTE_TABLE **EfiRouteTable OPTIONAL)
Definition: Ip6Route.c:261
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT16 EFIAPI NetblockChecksum(IN UINT8 *Bulk, IN UINT32 Len)
Definition: NetBuffer.c:1615
BOOLEAN EFIAPI NetIp6IsValidUnicast(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:725
VOID EFIAPI NetMapClean(IN OUT NET_MAP *Map)
Definition: DxeNetLib.c:1368
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
Definition: DxeNetLib.c:1967
NET_MAP_ITEM *EFIAPI NetMapFindKey(IN NET_MAP *Map, IN VOID *Key)
Definition: DxeNetLib.c:1629
BOOLEAN EFIAPI NetIp6IsLinkLocalAddr(IN EFI_IPv6_ADDRESS *Ip6)
Definition: DxeNetLib.c:796
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
Definition: DxeNetLib.c:2020
VOID EFIAPI NetMapInit(IN OUT NET_MAP *Map)
Definition: DxeNetLib.c:1343
BOOLEAN EFIAPI NetMapIsEmpty(IN NET_MAP *Map)
Definition: DxeNetLib.c:1413
EFI_STATUS EFIAPI PseudoRandomU32(OUT UINT32 *Output)
Definition: DxeNetLib.c:1011
VOID *EFIAPI NetMapRemoveItem(IN OUT NET_MAP *Map, IN OUT NET_MAP_ITEM *Item, OUT VOID **Value OPTIONAL)
Definition: DxeNetLib.c:1671
VOID *EFIAPI NetMapRemoveHead(IN OUT NET_MAP *Map, OUT VOID **Value OPTIONAL)
Definition: DxeNetLib.c:1710
EFI_STATUS EFIAPI NetMapInsertTail(IN OUT NET_MAP *Map, IN VOID *Key, IN VOID *Value OPTIONAL)
Definition: DxeNetLib.c:1556
EFI_STATUS EFIAPI NetMapIterate(IN NET_MAP *Map, IN NET_MAP_CALLBACK CallBack, IN VOID *Arg OPTIONAL)
Definition: DxeNetLib.c:1800
VOID EFIAPI NetListInsertBefore(IN OUT LIST_ENTRY *PostEntry, IN OUT LIST_ENTRY *NewEntry)
Definition: DxeNetLib.c:1199
UINTN EFIAPI NetMapGetCount(IN NET_MAP *Map)
Definition: DxeNetLib.c:1433
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
IPv6_ADDRESS EFI_IPv6_ADDRESS
Definition: UefiBaseType.h:90
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
Definition: UefiLib.c:134
BOOLEAN ReconfigureAccept
Definition: Dhcp6.h:366
EFI_DHCP6_IA_DESCRIPTOR IaDescriptor
Definition: Dhcp6.h:352
BOOLEAN RapidCommit
Definition: Dhcp6.h:372
UINT32 OptionCount
Definition: Dhcp6.h:340
EFI_DHCP6_RETRANSMISSION * SolicitRetransmission
Definition: Dhcp6.h:377
VOID * CallbackContext
Definition: Dhcp6.h:336
EFI_EVENT IaInfoEvent
Definition: Dhcp6.h:360
EFI_DHCP6_CALLBACK Dhcp6Callback
Definition: Dhcp6.h:332
EFI_DHCP6_PACKET_OPTION ** OptionList
Definition: Dhcp6.h:348
EFI_IPv6_ADDRESS IpAddress
Definition: Dhcp6.h:244
UINT32 ValidLifetime
Definition: Dhcp6.h:252
UINT32 PreferredLifetime
Definition: Dhcp6.h:248
UINT16 Type
Type for an IA.
Definition: Dhcp6.h:256
UINT32 IaId
The identifier for an IA.
Definition: Dhcp6.h:257
EFI_DHCP6_PACKET * ReplyPacket
Definition: Dhcp6.h:272
EFI_DHCP6_IA_ADDRESS IaAddress[1]
Definition: Dhcp6.h:281
EFI_DHCP6_STATE State
Definition: Dhcp6.h:268
UINT32 IaAddressCount
Definition: Dhcp6.h:276
EFI_DHCP6_DUID * ClientId
Definition: Dhcp6.h:288
EFI_DHCP6_IA * Ia
Definition: Dhcp6.h:293
EFI_IPv6_ADDRESS StationAddress
Definition: Ip6.h:188
UINT32 DupAddrDetectTransmits
The number of consecutive Neighbor Solicitation messages sent.
Definition: Ip6Config.h:185
EFI_IP6_ROUTE_TABLE * RouteTable
Definition: Ip6Config.h:138
EFI_IP6_ADDRESS_INFO * AddressInfo
Definition: Ip6Config.h:129
UINT8 PrefixLength
The length, in bits, of the prefix associated with this Address.
Definition: Ip6Config.h:196
EFI_IPv6_ADDRESS Address
The IPv6 unicast address.
Definition: Ip6Config.h:194
BOOLEAN IsAnycast
Set to TRUE if Address is anycast.
Definition: Ip6Config.h:195
EFI_MAC_ADDRESS CurrentAddress