2 The implementation of EFI IPv6 Configuration Protocol.
4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 LIST_ENTRY mIp6ConfigInstanceList
= {&mIp6ConfigInstanceList
, &mIp6ConfigInstanceList
};
21 The event process routine when the DHCPv6 service binding protocol is installed
24 @param[in] Event Not used.
25 @param[in] Context Pointer to the IP6 config instance data.
30 Ip6ConfigOnDhcp6SbInstalled (
36 Update the current policy to NewPolicy. During the transition
37 period, the default router list, on-link prefix list, autonomous prefix list
38 and address list in all interfaces will be released.
40 @param[in] IpSb The IP6 service binding instance.
41 @param[in] NewPolicy The new policy to be updated to.
45 Ip6ConfigOnPolicyChanged (
47 IN EFI_IP6_CONFIG_POLICY NewPolicy
54 IP6_DAD_ENTRY
*DadEntry
;
55 IP6_DELAY_JOIN_LIST
*DelayNode
;
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.
64 Ip6CleanDefaultRouterList (IpSb
);
65 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
66 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
69 // It's tricky... If the LinkLocal address is O.K., add back the link-local
70 // prefix to the on-link prefix table.
72 if (IpSb
->LinkLocalOk
) {
73 Ip6CreatePrefixListEntry (
76 (UINT32
) IP6_INFINIT_LIFETIME
,
77 (UINT32
) IP6_INFINIT_LIFETIME
,
78 IP6_LINK_LOCAL_PREFIX_LENGTH
,
84 // All IPv6 children that use global unicast address as it's source address
85 // should be destryoed now. The survivers are those use the link-local address
86 // or the unspecified address as the source address.
87 // TODO: Conduct a check here.
90 &IpSb
->DefaultInterface
->AddressList
,
91 &IpSb
->DefaultInterface
->AddressCount
,
96 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
98 // remove all pending delay node and DAD entries for the global addresses.
100 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
102 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DelayJoinList
) {
103 DelayNode
= NET_LIST_USER_STRUCT (Entry2
, IP6_DELAY_JOIN_LIST
, Link
);
104 if (!NetIp6IsLinkLocalAddr (&DelayNode
->AddressInfo
->Address
)) {
105 RemoveEntryList (&DelayNode
->Link
);
106 FreePool (DelayNode
);
110 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DupAddrDetectList
) {
111 DadEntry
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_DAD_ENTRY
, Link
, IP6_DAD_ENTRY_SIGNATURE
);
113 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
115 // Fail this DAD entry if the address is not link-local.
117 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
122 if (NewPolicy
== Ip6ConfigPolicyAutomatic
) {
124 // Set parameters to trigger router solicitation sending in timer handler.
126 IpSb
->RouterAdvertiseReceived
= FALSE
;
127 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
131 IpSb
->Ticks
= (UINT32
) IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS
);
137 The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
139 @param[in] Instance Pointer to the IP6 config instance data.
140 @param[in] OtherInfoOnly If FALSE, get stateful address and other information
141 via DHCPv6. Otherwise, only get the other information.
143 @retval EFI_SUCCESS The operation finished successfully.
144 @retval EFI_UNSUPPORTED The DHCP6 driver is not available.
148 Ip6ConfigStartStatefulAutoConfig (
149 IN IP6_CONFIG_INSTANCE
*Instance
,
150 IN BOOLEAN OtherInfoOnly
155 EFI_DHCP6_CONFIG_DATA Dhcp6CfgData
;
156 EFI_DHCP6_PROTOCOL
*Dhcp6
;
157 EFI_DHCP6_PACKET_OPTION
*OptList
[1];
159 EFI_DHCP6_PACKET_OPTION
*Oro
;
160 EFI_DHCP6_RETRANSMISSION InfoReqReXmit
;
163 // A host must not invoke stateful address configuration if it is already
164 // participating in the statuful protocol as a result of an earlier advertisement.
166 if (Instance
->Dhcp6Handle
!= NULL
) {
170 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
172 Instance
->OtherInfoOnly
= OtherInfoOnly
;
174 Status
= NetLibCreateServiceChild (
177 &gEfiDhcp6ServiceBindingProtocolGuid
,
178 &Instance
->Dhcp6Handle
181 if (Status
== EFI_UNSUPPORTED
) {
183 // No DHCPv6 Service Binding protocol, register a notify.
185 if (Instance
->Dhcp6SbNotifyEvent
== NULL
) {
186 Instance
->Dhcp6SbNotifyEvent
= EfiCreateProtocolNotifyEvent (
187 &gEfiDhcp6ServiceBindingProtocolGuid
,
189 Ip6ConfigOnDhcp6SbInstalled
,
191 &Instance
->Registration
196 if (EFI_ERROR (Status
)) {
200 if (Instance
->Dhcp6SbNotifyEvent
!= NULL
) {
201 gBS
->CloseEvent (Instance
->Dhcp6SbNotifyEvent
);
204 Status
= gBS
->OpenProtocol (
205 Instance
->Dhcp6Handle
,
206 &gEfiDhcp6ProtocolGuid
,
207 (VOID
**) &Instance
->Dhcp6
,
210 EFI_OPEN_PROTOCOL_BY_DRIVER
212 ASSERT_EFI_ERROR (Status
);
214 Dhcp6
= Instance
->Dhcp6
;
215 Dhcp6
->Configure (Dhcp6
, NULL
);
218 // Set the exta options to send. Here we only want the option request option
221 Oro
= (EFI_DHCP6_PACKET_OPTION
*) OptBuf
;
222 Oro
->OpCode
= HTONS (DHCP6_OPT_ORO
);
223 Oro
->OpLen
= HTONS (2);
224 *((UINT16
*) &Oro
->Data
[0]) = HTONS (DHCP6_OPT_DNS_SERVERS
);
227 Status
= EFI_SUCCESS
;
229 if (!OtherInfoOnly
) {
231 // Get stateful address and other information via DHCPv6.
233 Dhcp6CfgData
.Dhcp6Callback
= NULL
;
234 Dhcp6CfgData
.CallbackContext
= NULL
;
235 Dhcp6CfgData
.OptionCount
= 1;
236 Dhcp6CfgData
.OptionList
= &OptList
[0];
237 Dhcp6CfgData
.IaDescriptor
.Type
= EFI_DHCP6_IA_TYPE_NA
;
238 Dhcp6CfgData
.IaDescriptor
.IaId
= Instance
->IaId
;
239 Dhcp6CfgData
.IaInfoEvent
= Instance
->Dhcp6Event
;
240 Dhcp6CfgData
.ReconfigureAccept
= FALSE
;
241 Dhcp6CfgData
.RapidCommit
= FALSE
;
242 Dhcp6CfgData
.SolicitRetransmission
= NULL
;
244 Status
= Dhcp6
->Configure (Dhcp6
, &Dhcp6CfgData
);
246 if (!EFI_ERROR (Status
)) {
248 if (IpSb
->LinkLocalOk
) {
249 Status
= Dhcp6
->Start (Dhcp6
);
251 IpSb
->Dhcp6NeedStart
= TRUE
;
257 // Only get other information via DHCPv6, this doesn't require a config
260 InfoReqReXmit
.Irt
= 4;
261 InfoReqReXmit
.Mrc
= 64;
262 InfoReqReXmit
.Mrt
= 60;
263 InfoReqReXmit
.Mrd
= 0;
265 if (IpSb
->LinkLocalOk
) {
266 Status
= Dhcp6
->InfoRequest (
273 Instance
->Dhcp6Event
,
274 Ip6ConfigOnDhcp6Reply
,
278 IpSb
->Dhcp6NeedInfoRequest
= TRUE
;
287 Signal the registered event. It is the callback routine for NetMapIterate.
289 @param[in] Map Points to the list of registered event.
290 @param[in] Item The registered event.
291 @param[in] Arg Not used.
296 Ip6ConfigSignalEvent (
298 IN NET_MAP_ITEM
*Item
,
302 gBS
->SignalEvent ((EFI_EVENT
) Item
->Key
);
308 Read the configuration data from variable storage according to the VarName and
309 gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
310 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
311 configuration data to IP6_CONFIG_INSTANCE.
313 @param[in] VarName The pointer to the variable name
314 @param[in, out] Instance The pointer to the IP6 config instance data.
316 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
317 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
318 @retval EFI_SUCCESS The configuration data was retrieved successfully.
322 Ip6ConfigReadConfigData (
324 IN OUT IP6_CONFIG_INSTANCE
*Instance
329 IP6_CONFIG_VARIABLE
*Variable
;
330 IP6_CONFIG_DATA_ITEM
*DataItem
;
332 IP6_CONFIG_DATA_RECORD DataRecord
;
336 // Try to read the configuration variable.
339 Status
= gRT
->GetVariable (
341 &gEfiIp6ConfigProtocolGuid
,
347 if (Status
== EFI_BUFFER_TOO_SMALL
) {
349 // Allocate buffer and read the config variable.
351 Variable
= AllocatePool (VarSize
);
352 if (Variable
== NULL
) {
353 return EFI_OUT_OF_RESOURCES
;
356 Status
= gRT
->GetVariable (
358 &gEfiIp6ConfigProtocolGuid
,
363 if (EFI_ERROR (Status
) || (UINT16
) (~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
)) != 0) {
365 // GetVariable still error or the variable is corrupted.
366 // Fall back to the default value.
371 // Remove the problematic variable and return EFI_NOT_FOUND, a new
372 // variable will be set again.
376 &gEfiIp6ConfigProtocolGuid
,
377 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
382 return EFI_NOT_FOUND
;
386 // Get the IAID we use.
388 Instance
->IaId
= Variable
->IaId
;
390 for (Index
= 0; Index
< Variable
->DataRecordCount
; Index
++) {
392 CopyMem (&DataRecord
, &Variable
->DataRecord
[Index
], sizeof (DataRecord
));
394 DataItem
= &Instance
->DataItem
[DataRecord
.DataType
];
395 if (DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
) &&
396 (DataItem
->DataSize
!= DataRecord
.DataSize
)
399 // Perhaps a corrupted data record...
404 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
406 // This data item has variable length data.
408 DataItem
->Data
.Ptr
= AllocatePool (DataRecord
.DataSize
);
409 if (DataItem
->Data
.Ptr
== NULL
) {
411 // no memory resource
417 Data
= (CHAR8
*) Variable
+ DataRecord
.Offset
;
418 CopyMem (DataItem
->Data
.Ptr
, Data
, DataRecord
.DataSize
);
420 DataItem
->DataSize
= DataRecord
.DataSize
;
421 DataItem
->Status
= EFI_SUCCESS
;
432 Write the configuration data from IP6_CONFIG_INSTANCE to variable storage.
434 @param[in] VarName The pointer to the variable name.
435 @param[in] Instance The pointer to the IP6 configuration instance data.
437 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
438 @retval EFI_SUCCESS The configuration data is written successfully.
442 Ip6ConfigWriteConfigData (
444 IN IP6_CONFIG_INSTANCE
*Instance
449 IP6_CONFIG_DATA_ITEM
*DataItem
;
450 IP6_CONFIG_VARIABLE
*Variable
;
451 IP6_CONFIG_DATA_RECORD
*DataRecord
;
455 VarSize
= sizeof (IP6_CONFIG_VARIABLE
) - sizeof (IP6_CONFIG_DATA_RECORD
);
457 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
459 DataItem
= &Instance
->DataItem
[Index
];
460 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
462 VarSize
+= sizeof (IP6_CONFIG_DATA_RECORD
) + DataItem
->DataSize
;
466 Variable
= AllocatePool (VarSize
);
467 if (Variable
== NULL
) {
468 return EFI_OUT_OF_RESOURCES
;
471 Variable
->IaId
= Instance
->IaId
;
472 Heap
= (CHAR8
*) Variable
+ VarSize
;
473 Variable
->DataRecordCount
= 0;
475 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
477 DataItem
= &Instance
->DataItem
[Index
];
478 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
480 Heap
-= DataItem
->DataSize
;
481 CopyMem (Heap
, DataItem
->Data
.Ptr
, DataItem
->DataSize
);
483 DataRecord
= &Variable
->DataRecord
[Variable
->DataRecordCount
];
484 DataRecord
->DataType
= (EFI_IP6_CONFIG_DATA_TYPE
) Index
;
485 DataRecord
->DataSize
= (UINT32
) DataItem
->DataSize
;
486 DataRecord
->Offset
= (UINT16
) (Heap
- (CHAR8
*) Variable
);
488 Variable
->DataRecordCount
++;
492 Variable
->Checksum
= 0;
493 Variable
->Checksum
= (UINT16
) ~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
);
495 Status
= gRT
->SetVariable (
497 &gEfiIp6ConfigProtocolGuid
,
498 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
509 The work function for EfiIp6ConfigGetData() to get the interface information
510 of the communication device this IP6Config instance manages.
512 @param[in] Instance Pointer to the IP6 config instance data.
513 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
514 bytes, the size of buffer required to store the specified
516 @param[in] Data The data buffer in which the configuration data is returned.
517 Ignored if DataSize is ZERO.
519 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
520 configuration data, and the required size is
521 returned in DataSize.
522 @retval EFI_SUCCESS The specified configuration data was obtained.
527 IN IP6_CONFIG_INSTANCE
*Instance
,
528 IN OUT UINTN
*DataSize
,
529 IN VOID
*Data OPTIONAL
534 IP6_CONFIG_DATA_ITEM
*Item
;
535 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
539 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
540 Length
= sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
);
543 // Calculate the required length, add the buffer size for AddressInfo and
546 Ip6BuildEfiAddressList (IpSb
, &AddressCount
, NULL
);
547 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &RouteCount
, NULL
);
549 Length
+= AddressCount
* sizeof (EFI_IP6_ADDRESS_INFO
) + RouteCount
* sizeof (EFI_IP6_ROUTE_TABLE
);
551 if (*DataSize
< Length
) {
553 return EFI_BUFFER_TOO_SMALL
;
557 // Copy the fixed size part of the interface info.
559 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
560 IfInfo
= (EFI_IP6_CONFIG_INTERFACE_INFO
*) Data
;
561 CopyMem (IfInfo
, Item
->Data
.Ptr
, sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
));
566 IfInfo
->AddressInfo
= (EFI_IP6_ADDRESS_INFO
*) (IfInfo
+ 1);
567 Ip6BuildEfiAddressList (IpSb
, &IfInfo
->AddressInfoCount
, &IfInfo
->AddressInfo
);
572 IfInfo
->RouteTable
= (EFI_IP6_ROUTE_TABLE
*) (IfInfo
->AddressInfo
+ IfInfo
->AddressInfoCount
);
573 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &IfInfo
->RouteCount
, &IfInfo
->RouteTable
);
575 if (IfInfo
->AddressInfoCount
== 0) {
576 IfInfo
->AddressInfo
= NULL
;
579 if (IfInfo
->RouteCount
== 0) {
580 IfInfo
->RouteTable
= NULL
;
587 The work function for EfiIp6ConfigSetData() to set the alternative inteface ID
588 for the communication device managed by this IP6Config instance, if the link local
589 IPv6 addresses generated from the interface ID based on the default source the
590 EFI IPv6 Protocol uses is a duplicate address.
592 @param[in] Instance Pointer to the IP6 configuration instance data.
593 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
594 @param[in] Data The data buffer to set.
596 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
598 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
599 network stack was set.
603 Ip6ConfigSetAltIfId (
604 IN IP6_CONFIG_INSTANCE
*Instance
,
609 EFI_IP6_CONFIG_INTERFACE_ID
*OldIfId
;
610 EFI_IP6_CONFIG_INTERFACE_ID
*NewIfId
;
611 IP6_CONFIG_DATA_ITEM
*DataItem
;
613 if (DataSize
!= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
)) {
614 return EFI_BAD_BUFFER_SIZE
;
617 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
618 OldIfId
= DataItem
->Data
.AltIfId
;
619 NewIfId
= (EFI_IP6_CONFIG_INTERFACE_ID
*) Data
;
621 CopyMem (OldIfId
, NewIfId
, DataSize
);
622 DataItem
->Status
= EFI_SUCCESS
;
628 The work function for EfiIp6ConfigSetData() to set the general configuration
629 policy for the EFI IPv6 network stack that is running on the communication device
630 managed by this IP6Config instance. The policy will affect other configuration settings.
632 @param[in] Instance Pointer to the IP6 config instance data.
633 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
634 @param[in] Data The data buffer to set.
636 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
637 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
638 @retval EFI_ABORTED The new policy equals the current policy.
639 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
640 network stack was set.
645 IN IP6_CONFIG_INSTANCE
*Instance
,
650 EFI_IP6_CONFIG_POLICY NewPolicy
;
651 IP6_CONFIG_DATA_ITEM
*DataItem
;
654 if (DataSize
!= sizeof (EFI_IP6_CONFIG_POLICY
)) {
655 return EFI_BAD_BUFFER_SIZE
;
658 NewPolicy
= *((EFI_IP6_CONFIG_POLICY
*) Data
);
660 if (NewPolicy
> Ip6ConfigPolicyAutomatic
) {
661 return EFI_INVALID_PARAMETER
;
664 if (NewPolicy
== Instance
->Policy
) {
669 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
670 // data size, and fire up all the related events.
672 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
673 if (DataItem
->Data
.Ptr
!= NULL
) {
674 FreePool (DataItem
->Data
.Ptr
);
676 DataItem
->Data
.Ptr
= NULL
;
677 DataItem
->DataSize
= 0;
678 DataItem
->Status
= EFI_NOT_FOUND
;
679 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
681 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
682 if (DataItem
->Data
.Ptr
!= NULL
) {
683 FreePool (DataItem
->Data
.Ptr
);
685 DataItem
->Data
.Ptr
= NULL
;
686 DataItem
->DataSize
= 0;
687 DataItem
->Status
= EFI_NOT_FOUND
;
688 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
690 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
691 DataItem
->Data
.Ptr
= NULL
;
692 DataItem
->DataSize
= 0;
693 DataItem
->Status
= EFI_NOT_FOUND
;
694 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
696 if (NewPolicy
== Ip6ConfigPolicyManual
) {
698 // The policy is changed from automatic to manual. Stop the DHCPv6 process
699 // and destroy the DHCPv6 child.
701 if (Instance
->Dhcp6Handle
!= NULL
) {
702 Ip6ConfigDestroyDhcp6 (Instance
);
706 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
707 Ip6ConfigOnPolicyChanged (IpSb
, NewPolicy
);
709 Instance
->Policy
= NewPolicy
;
716 The work function for EfiIp6ConfigSetData() to set the number of consecutive
717 Neighbor Solicitation messages sent while performing Duplicate Address Detection
718 on a tentative address. A value of ZERO indicates that Duplicate Address Detection
719 will not be performed on a tentative address.
721 @param[in] Instance The Instance Pointer to the IP6 config instance data.
722 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
723 @param[in] Data The data buffer to set.
725 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
726 @retval EFI_ABORTED The new transmit count equals the current configuration.
727 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
728 network stack was set.
732 Ip6ConfigSetDadXmits (
733 IN IP6_CONFIG_INSTANCE
*Instance
,
738 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
*OldDadXmits
;
740 if (DataSize
!= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
)) {
741 return EFI_BAD_BUFFER_SIZE
;
744 OldDadXmits
= Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
].Data
.DadXmits
;
746 if ((*(UINT32
*) Data
) == OldDadXmits
->DupAddrDetectTransmits
) {
751 OldDadXmits
->DupAddrDetectTransmits
= *((UINT32
*) Data
);
757 The callback function for Ip6SetAddr. The prototype is defined
758 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
759 for the manual address set by Ip6ConfigSetMaunualAddress.
761 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passed.
762 @param[in] TargetAddress The tentative IPv6 address to be checked.
763 @param[in] Context Pointer to the IP6 configuration instance data.
767 Ip6ManualAddrDadCallback (
768 IN BOOLEAN IsDadPassed
,
769 IN EFI_IPv6_ADDRESS
*TargetAddress
,
773 IP6_CONFIG_INSTANCE
*Instance
;
775 IP6_CONFIG_DATA_ITEM
*Item
;
776 EFI_IP6_CONFIG_MANUAL_ADDRESS
*ManualAddr
;
777 EFI_IP6_CONFIG_MANUAL_ADDRESS
*PassedAddr
;
782 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
783 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
784 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
787 if (Item
->DataSize
== 0) {
791 for (Index
= 0; Index
< Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
); Index
++) {
793 // Find the original tag used to place into the NET_MAP.
795 ManualAddr
= Item
->Data
.ManualAddress
+ Index
;
796 if (EFI_IP6_EQUAL (TargetAddress
, &ManualAddr
->Address
)) {
801 ASSERT (Index
!= Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
804 NetMapInsertTail (&Instance
->DadPassedMap
, ManualAddr
, NULL
);
806 NetMapInsertTail (&Instance
->DadFailedMap
, ManualAddr
, NULL
);
809 DadPassCount
= NetMapGetCount (&Instance
->DadPassedMap
);
810 DadFailCount
= NetMapGetCount (&Instance
->DadFailedMap
);
812 if ((DadPassCount
+ DadFailCount
) == (Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
))) {
814 // All addresses have finished the configuration process.
816 if (DadFailCount
!= 0) {
818 // There is at least one duplicate address.
820 FreePool (Item
->Data
.Ptr
);
822 Item
->DataSize
= DadPassCount
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
823 if (Item
->DataSize
== 0) {
825 // All failed, bad luck.
827 Item
->Data
.Ptr
= NULL
;
828 Item
->Status
= EFI_NOT_FOUND
;
831 // Part of addresses are detected to be duplicates, so update the
832 // data with those passed.
834 PassedAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) AllocatePool (Item
->DataSize
);
835 ASSERT (PassedAddr
!= NULL
);
837 Item
->Data
.Ptr
= PassedAddr
;
838 Item
->Status
= EFI_SUCCESS
;
840 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
841 ManualAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
842 CopyMem (PassedAddr
, ManualAddr
, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
847 ASSERT ((UINTN
) PassedAddr
- (UINTN
) Item
->Data
.Ptr
== Item
->DataSize
);
851 // All addresses are valid.
853 Item
->Status
= EFI_SUCCESS
;
857 // Remove the tags we put in the NET_MAPs.
859 while (!NetMapIsEmpty (&Instance
->DadFailedMap
)) {
860 NetMapRemoveHead (&Instance
->DadFailedMap
, NULL
);
863 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
864 NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
868 // Signal the waiting events.
870 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
871 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
872 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
877 The work function for EfiIp6ConfigSetData() to set the station addresses manually
878 for the EFI IPv6 network stack. It is only configurable when the policy is
879 Ip6ConfigPolicyManual.
881 @param[in] Instance Pointer to the IP6 configuration instance data.
882 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
883 @param[in] Data The data buffer to set.
885 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
886 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
887 under the current policy.
888 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
889 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
890 @retval EFI_NOT_READY An asynchrous process is invoked to set the specified
891 configuration data, and the process is not finished.
892 @retval EFI_ABORTED The manual addresses to be set equal current
894 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
895 network stack was set.
899 Ip6ConfigSetMaunualAddress (
900 IN IP6_CONFIG_INSTANCE
*Instance
,
905 EFI_IP6_CONFIG_MANUAL_ADDRESS
*NewAddress
;
906 EFI_IP6_CONFIG_MANUAL_ADDRESS
*TmpAddress
;
907 IP6_CONFIG_DATA_ITEM
*DataItem
;
908 UINTN NewAddressCount
;
912 IP6_ADDRESS_INFO
*CurrentAddrInfo
;
913 IP6_ADDRESS_INFO
*Copy
;
914 LIST_ENTRY CurrentSourceList
;
915 UINT32 CurrentSourceCount
;
919 IP6_PREFIX_LIST_ENTRY
*PrefixEntry
;
923 ASSERT (Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
].Status
!= EFI_NOT_READY
);
925 if (((DataSize
% sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
)) != 0) || (DataSize
== 0)) {
926 return EFI_BAD_BUFFER_SIZE
;
929 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
930 return EFI_WRITE_PROTECTED
;
933 NewAddressCount
= DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
934 NewAddress
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) Data
;
936 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
938 if (NetIp6IsLinkLocalAddr (&NewAddress
->Address
) ||
939 !NetIp6IsValidUnicast (&NewAddress
->Address
) ||
940 (NewAddress
->PrefixLength
> 128)
943 // make sure the IPv6 address is unicast and not link-local address &&
944 // the prefix length is valid.
946 return EFI_INVALID_PARAMETER
;
949 TmpAddress
= NewAddress
+ 1;
950 for (Index2
= Index1
+ 1; Index2
< NewAddressCount
; Index2
++, TmpAddress
++) {
952 // Any two addresses in the array can't be equal.
954 if (EFI_IP6_EQUAL (&TmpAddress
->Address
, &NewAddress
->Address
)) {
956 return EFI_INVALID_PARAMETER
;
961 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
964 // Build the current source address list.
966 InitializeListHead (&CurrentSourceList
);
967 CurrentSourceCount
= 0;
969 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
970 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
972 NET_LIST_FOR_EACH (Entry2
, &IpIf
->AddressList
) {
973 CurrentAddrInfo
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
975 Copy
= AllocateCopyPool (sizeof (IP6_ADDRESS_INFO
), CurrentAddrInfo
);
980 InsertTailList (&CurrentSourceList
, &Copy
->Link
);
981 CurrentSourceCount
++;
986 // Update the value... a long journey starts
988 NewAddress
= AllocateCopyPool (DataSize
, Data
);
989 if (NewAddress
== NULL
) {
990 Ip6RemoveAddr (NULL
, &CurrentSourceList
, &CurrentSourceCount
, NULL
, 0);
992 return EFI_OUT_OF_RESOURCES
;
996 // Store the new data, and init the DataItem status to EFI_NOT_READY because
997 // we may have an asynchronous configuration process.
999 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
1000 if (DataItem
->Data
.Ptr
!= NULL
) {
1001 FreePool (DataItem
->Data
.Ptr
);
1003 DataItem
->Data
.Ptr
= NewAddress
;
1004 DataItem
->DataSize
= DataSize
;
1005 DataItem
->Status
= EFI_NOT_READY
;
1008 // Trigger DAD, it's an asynchronous process.
1012 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
1013 if (Ip6IsOneOfSetAddress (IpSb
, &NewAddress
->Address
, NULL
, &CurrentAddrInfo
)) {
1014 ASSERT (CurrentAddrInfo
!= NULL
);
1016 // Remove this already existing source address from the CurrentSourceList
1022 &CurrentSourceCount
,
1023 &CurrentAddrInfo
->Address
,
1028 // If the new address's prefix length is not specified, just use the previous configured
1029 // prefix length for this address.
1031 if (NewAddress
->PrefixLength
== 0) {
1032 NewAddress
->PrefixLength
= CurrentAddrInfo
->PrefixLength
;
1036 // This manual address is already in use, see whether prefix length is changed.
1038 if (NewAddress
->PrefixLength
!= CurrentAddrInfo
->PrefixLength
) {
1040 // Remove the on-link prefix table, the route entry will be removed
1043 PrefixEntry
= Ip6FindPrefixListEntry (
1046 CurrentAddrInfo
->PrefixLength
,
1047 &CurrentAddrInfo
->Address
1049 if (PrefixEntry
!= NULL
) {
1050 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1054 // Save the prefix length.
1056 CurrentAddrInfo
->PrefixLength
= NewAddress
->PrefixLength
;
1061 // create a new on-link prefix entry.
1063 PrefixEntry
= Ip6FindPrefixListEntry (
1066 NewAddress
->PrefixLength
,
1067 &NewAddress
->Address
1069 if (PrefixEntry
== NULL
) {
1070 Ip6CreatePrefixListEntry (
1073 (UINT32
) IP6_INFINIT_LIFETIME
,
1074 (UINT32
) IP6_INFINIT_LIFETIME
,
1075 NewAddress
->PrefixLength
,
1076 &NewAddress
->Address
1080 CurrentAddrInfo
->IsAnycast
= NewAddress
->IsAnycast
;
1082 // Artificially mark this address passed DAD be'coz it is already in use.
1084 Ip6ManualAddrDadCallback (TRUE
, &NewAddress
->Address
, Instance
);
1092 // Set the new address, this will trigger DAD and activate the address if
1096 IpSb
->DefaultInterface
,
1097 &NewAddress
->Address
,
1098 NewAddress
->IsAnycast
,
1099 NewAddress
->PrefixLength
,
1100 (UINT32
) IP6_INFINIT_LIFETIME
,
1101 (UINT32
) IP6_INFINIT_LIFETIME
,
1102 Ip6ManualAddrDadCallback
,
1109 // Check the CurrentSourceList, it now contains those addresses currently in
1110 // use and will be removed.
1112 IpIf
= IpSb
->DefaultInterface
;
1114 while (!IsListEmpty (&CurrentSourceList
)) {
1117 CurrentAddrInfo
= NET_LIST_HEAD (&CurrentSourceList
, IP6_ADDRESS_INFO
, Link
);
1120 // This local address is going to be removed, the IP instances that are
1121 // currently using it will be destroyed.
1126 &IpIf
->AddressCount
,
1127 &CurrentAddrInfo
->Address
,
1132 // Remove the on-link prefix table, the route entry will be removed
1135 PrefixEntry
= Ip6FindPrefixListEntry (
1138 CurrentAddrInfo
->PrefixLength
,
1139 &CurrentAddrInfo
->Address
1141 if (PrefixEntry
!= NULL
) {
1142 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1145 RemoveEntryList (&CurrentAddrInfo
->Link
);
1146 FreePool (CurrentAddrInfo
);
1150 if (DataItem
->Status
== EFI_NOT_READY
) {
1152 // If DAD is disabled on this interface, the configuration process is
1153 // actually synchronous, and the data item's status will be changed to
1154 // the final status before we reach here, just check it.
1156 Status
= EFI_NOT_READY
;
1158 Status
= EFI_SUCCESS
;
1162 // No update is taken, reset the status to success and return EFI_ABORTED.
1164 DataItem
->Status
= EFI_SUCCESS
;
1165 Status
= EFI_ABORTED
;
1172 The work function for EfiIp6ConfigSetData() to set the gateway addresses manually
1173 for the EFI IPv6 network stack that is running on the communication device that
1174 this EFI IPv6 Configuration Protocol manages. It is not configurable when the policy is
1175 Ip6ConfigPolicyAutomatic. The gateway addresses must be unicast IPv6 addresses.
1177 @param[in] Instance The pointer to the IP6 config instance data.
1178 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1179 @param[in] Data The data buffer to set. This points to an array of
1180 EFI_IPv6_ADDRESS instances.
1182 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1183 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1184 under the current policy.
1185 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1186 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1187 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1188 current configuration.
1189 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1190 network stack was set.
1194 Ip6ConfigSetGateway (
1195 IN IP6_CONFIG_INSTANCE
*Instance
,
1202 EFI_IPv6_ADDRESS
*OldGateway
;
1203 EFI_IPv6_ADDRESS
*NewGateway
;
1204 UINTN OldGatewayCount
;
1205 UINTN NewGatewayCount
;
1206 IP6_CONFIG_DATA_ITEM
*Item
;
1210 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1213 if ((DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0) || (DataSize
== 0)) {
1214 return EFI_BAD_BUFFER_SIZE
;
1217 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1218 return EFI_WRITE_PROTECTED
;
1221 NewGateway
= (EFI_IPv6_ADDRESS
*) Data
;
1222 NewGatewayCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1223 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1225 if (!NetIp6IsValidUnicast (NewGateway
+ Index1
)) {
1227 return EFI_INVALID_PARAMETER
;
1230 for (Index2
= Index1
+ 1; Index2
< NewGatewayCount
; Index2
++) {
1231 if (EFI_IP6_EQUAL (NewGateway
+ Index1
, NewGateway
+ Index2
)) {
1232 return EFI_INVALID_PARAMETER
;
1237 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1238 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
1239 OldGateway
= Item
->Data
.Gateway
;
1240 OldGatewayCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1244 if (NewGatewayCount
!= OldGatewayCount
) {
1245 Tmp
= AllocatePool (DataSize
);
1247 return EFI_OUT_OF_RESOURCES
;
1253 for (Index1
= 0; Index1
< OldGatewayCount
; Index1
++) {
1255 // Find the gateways that are no long in the new setting and remove them.
1257 for (Index2
= 0; Index2
< NewGatewayCount
; Index2
++) {
1258 if (EFI_IP6_EQUAL (OldGateway
+ Index1
, NewGateway
+ Index2
)) {
1264 if (Index2
== NewGatewayCount
) {
1266 // Remove this default router.
1268 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, OldGateway
+ Index1
);
1269 if (DefaultRouter
!= NULL
) {
1270 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
1275 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1277 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, NewGateway
+ Index1
);
1278 if (DefaultRouter
== NULL
) {
1279 Ip6CreateDefaultRouter (IpSb
, NewGateway
+ Index1
, IP6_INF_ROUTER_LIFETIME
);
1284 if (!OneRemoved
&& !OneAdded
) {
1285 Item
->Status
= EFI_SUCCESS
;
1290 if (Item
->Data
.Ptr
!= NULL
) {
1291 FreePool (Item
->Data
.Ptr
);
1293 Item
->Data
.Ptr
= Tmp
;
1296 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1297 Item
->DataSize
= DataSize
;
1298 Item
->Status
= EFI_SUCCESS
;
1304 The work function for EfiIp6ConfigSetData() to set the DNS server list for the
1305 EFI IPv6 network stack running on the communication device that this EFI IPv6
1306 Configuration Protocol manages. It is not configurable when the policy is
1307 Ip6ConfigPolicyAutomatic. The DNS server addresses must be unicast IPv6 addresses.
1309 @param[in] Instance The pointer to the IP6 config instance data.
1310 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1311 @param[in] Data The data buffer to set, points to an array of
1312 EFI_IPv6_ADDRESS instances.
1314 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1315 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1316 under the current policy.
1317 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1318 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1319 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1321 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1322 network stack was set.
1326 Ip6ConfigSetDnsServer (
1327 IN IP6_CONFIG_INSTANCE
*Instance
,
1334 EFI_IPv6_ADDRESS
*OldDns
;
1335 EFI_IPv6_ADDRESS
*NewDns
;
1338 IP6_CONFIG_DATA_ITEM
*Item
;
1342 if ((DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0) || (DataSize
== 0)) {
1343 return EFI_BAD_BUFFER_SIZE
;
1346 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1347 return EFI_WRITE_PROTECTED
;
1350 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1351 NewDns
= (EFI_IPv6_ADDRESS
*) Data
;
1352 OldDns
= Item
->Data
.DnsServers
;
1353 NewDnsCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1354 OldDnsCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1357 if (NewDnsCount
!= OldDnsCount
) {
1358 Tmp
= AllocatePool (DataSize
);
1360 return EFI_OUT_OF_RESOURCES
;
1366 for (NewIndex
= 0; NewIndex
< NewDnsCount
; NewIndex
++) {
1368 if (!NetIp6IsValidUnicast (NewDns
+ NewIndex
)) {
1370 // The dns server address must be unicast.
1375 return EFI_INVALID_PARAMETER
;
1380 // If any address in the new setting is not in the old settings, skip the
1381 // comparision below.
1386 for (OldIndex
= 0; OldIndex
< OldDnsCount
; OldIndex
++) {
1387 if (EFI_IP6_EQUAL (NewDns
+ NewIndex
, OldDns
+ OldIndex
)) {
1389 // If found break out.
1395 if (OldIndex
== OldDnsCount
) {
1400 if (!OneAdded
&& (DataSize
== Item
->DataSize
)) {
1402 // No new item is added and the size is the same.
1404 Item
->Status
= EFI_SUCCESS
;
1408 if (Item
->Data
.Ptr
!= NULL
) {
1409 FreePool (Item
->Data
.Ptr
);
1411 Item
->Data
.Ptr
= Tmp
;
1414 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1415 Item
->DataSize
= DataSize
;
1416 Item
->Status
= EFI_SUCCESS
;
1422 Generate the operational state of the interface this IP6 config instance manages
1423 and output in EFI_IP6_CONFIG_INTERFACE_INFO.
1425 @param[in] IpSb The pointer to the IP6 service binding instance.
1426 @param[out] IfInfo The pointer to the IP6 configuration interface information structure.
1430 Ip6ConfigInitIfInfo (
1431 IN IP6_SERVICE
*IpSb
,
1432 OUT EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
1437 sizeof (IfInfo
->Name
),
1439 IpSb
->Ip6ConfigInstance
.IfIndex
1442 IfInfo
->IfType
= IpSb
->SnpMode
.IfType
;
1443 IfInfo
->HwAddressSize
= IpSb
->SnpMode
.HwAddressSize
;
1444 CopyMem (&IfInfo
->HwAddress
, &IpSb
->SnpMode
.CurrentAddress
, IfInfo
->HwAddressSize
);
1448 Parse DHCPv6 reply packet to get the DNS server list.
1449 It is the work function for Ip6ConfigOnDhcp6Reply and Ip6ConfigOnDhcp6Event.
1451 @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL instance.
1452 @param[in, out] Instance The pointer to the IP6 configuration instance data.
1453 @param[in] Reply The pointer to the DHCPv6 reply packet.
1455 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1456 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1457 the DNS server address is not valid.
1461 Ip6ConfigParseDhcpReply (
1462 IN EFI_DHCP6_PROTOCOL
*Dhcp6
,
1463 IN OUT IP6_CONFIG_INSTANCE
*Instance
,
1464 IN EFI_DHCP6_PACKET
*Reply
1469 EFI_DHCP6_PACKET_OPTION
**OptList
;
1474 EFI_IPv6_ADDRESS
*DnsServer
;
1475 IP6_CONFIG_DATA_ITEM
*Item
;
1478 // A DHCPv6 reply packet is received as the response to our InfoRequest
1482 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, NULL
);
1483 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1484 return EFI_NOT_READY
;
1487 OptList
= AllocatePool (OptCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*));
1488 if (OptList
== NULL
) {
1489 return EFI_NOT_READY
;
1492 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, OptList
);
1493 if (EFI_ERROR (Status
)) {
1494 Status
= EFI_NOT_READY
;
1498 Status
= EFI_SUCCESS
;
1500 for (Index
= 0; Index
< OptCount
; Index
++) {
1502 // Go through all the options to check the ones we are interested in.
1503 // The OpCode and Length are in network byte-order and may not be naturally
1506 CopyMem (&OpCode
, &OptList
[Index
]->OpCode
, sizeof (OpCode
));
1507 OpCode
= NTOHS (OpCode
);
1509 if (OpCode
== DHCP6_OPT_DNS_SERVERS
) {
1510 CopyMem (&Length
, &OptList
[Index
]->OpLen
, sizeof (Length
));
1511 Length
= NTOHS (Length
);
1513 if ((Length
== 0) || ((Length
% sizeof (EFI_IPv6_ADDRESS
)) != 0)) {
1515 // The length should be a multiple of 16 bytes.
1517 Status
= EFI_NOT_READY
;
1522 // Validate the DnsServers: whether they are unicast addresses.
1524 DnsServer
= (EFI_IPv6_ADDRESS
*) OptList
[Index
]->Data
;
1525 for (Index2
= 0; Index2
< Length
/ sizeof (EFI_IPv6_ADDRESS
); Index2
++) {
1526 if (!NetIp6IsValidUnicast (DnsServer
)) {
1527 Status
= EFI_NOT_READY
;
1534 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1536 if (Item
->DataSize
!= Length
) {
1537 if (Item
->Data
.Ptr
!= NULL
) {
1538 FreePool (Item
->Data
.Ptr
);
1541 Item
->Data
.Ptr
= AllocatePool (Length
);
1542 ASSERT (Item
->Data
.Ptr
!= NULL
);
1545 CopyMem (Item
->Data
.Ptr
, OptList
[Index
]->Data
, Length
);
1546 Item
->DataSize
= Length
;
1547 Item
->Status
= EFI_SUCCESS
;
1550 // Signal the waiting events.
1552 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
1565 The callback function for Ip6SetAddr. The prototype is defined
1566 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
1567 on the tentative address by DHCPv6 in Ip6ConfigOnDhcp6Event().
1569 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passes.
1570 @param[in] TargetAddress The tentative IPv6 address to be checked.
1571 @param[in] Context Pointer to the IP6 configuration instance data.
1575 Ip6ConfigSetStatefulAddrCallback (
1576 IN BOOLEAN IsDadPassed
,
1577 IN EFI_IPv6_ADDRESS
*TargetAddress
,
1581 IP6_CONFIG_INSTANCE
*Instance
;
1583 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1584 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
1587 // We should record the addresses that fail the DAD, and DECLINE them.
1591 // Decrease the count, no interests in those passed DAD.
1593 if (Instance
->FailedIaAddressCount
> 0 ) {
1594 Instance
->FailedIaAddressCount
--;
1600 IP6_COPY_ADDRESS (Instance
->DeclineAddress
+ Instance
->DeclineAddressCount
, TargetAddress
);
1601 Instance
->DeclineAddressCount
++;
1604 if (Instance
->FailedIaAddressCount
== Instance
->DeclineAddressCount
) {
1606 // The checking on all addresses are finished.
1608 if (Instance
->DeclineAddressCount
!= 0) {
1610 // Decline those duplicates.
1612 if (Instance
->Dhcp6
!= NULL
) {
1613 Instance
->Dhcp6
->Decline (
1615 Instance
->DeclineAddressCount
,
1616 Instance
->DeclineAddress
1621 if (Instance
->DeclineAddress
!= NULL
) {
1622 FreePool (Instance
->DeclineAddress
);
1624 Instance
->DeclineAddress
= NULL
;
1625 Instance
->DeclineAddressCount
= 0;
1630 The event handle routine when DHCPv6 process is finished or is updated.
1632 @param[in] Event Not used.
1633 @param[in] Context The pointer to the IP6 configuration instance data.
1638 Ip6ConfigOnDhcp6Event (
1643 IP6_CONFIG_INSTANCE
*Instance
;
1644 EFI_DHCP6_PROTOCOL
*Dhcp6
;
1646 EFI_DHCP6_MODE_DATA Dhcp6ModeData
;
1648 EFI_DHCP6_IA_ADDRESS
*IaAddr
;
1651 IP6_ADDRESS_INFO
*AddrInfo
;
1652 IP6_INTERFACE
*IpIf
;
1654 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1656 if ((Instance
->Policy
!= Ip6ConfigPolicyAutomatic
) || Instance
->OtherInfoOnly
) {
1658 // IPv6 is not operating in the automatic policy now or
1659 // the DHCPv6 information request message exchange is aborted.
1665 // The stateful address autoconfiguration is done or updated.
1667 Dhcp6
= Instance
->Dhcp6
;
1669 Status
= Dhcp6
->GetModeData (Dhcp6
, &Dhcp6ModeData
, NULL
);
1670 if (EFI_ERROR (Status
)) {
1674 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1675 IpIf
= IpSb
->DefaultInterface
;
1676 Ia
= Dhcp6ModeData
.Ia
;
1677 IaAddr
= Ia
->IaAddress
;
1679 if (Instance
->DeclineAddress
!= NULL
) {
1680 FreePool (Instance
->DeclineAddress
);
1683 Instance
->DeclineAddress
= (EFI_IPv6_ADDRESS
*) AllocatePool (Ia
->IaAddressCount
* sizeof (EFI_IPv6_ADDRESS
));
1684 if (Instance
->DeclineAddress
== NULL
) {
1688 Instance
->FailedIaAddressCount
= Ia
->IaAddressCount
;
1689 Instance
->DeclineAddressCount
= 0;
1691 for (Index
= 0; Index
< Ia
->IaAddressCount
; Index
++, IaAddr
++) {
1692 if (Ia
->IaAddress
[Index
].ValidLifetime
!= 0 && Ia
->State
== Dhcp6Bound
) {
1694 // Set this address, either it's a new address or with updated lifetimes.
1695 // An appropriate prefix length will be set.
1702 IaAddr
->ValidLifetime
,
1703 IaAddr
->PreferredLifetime
,
1704 Ip6ConfigSetStatefulAddrCallback
,
1709 // discard this address, artificially decrease the count as if this address
1712 if (Ip6IsOneOfSetAddress (IpSb
, &IaAddr
->IpAddress
, NULL
, &AddrInfo
)) {
1713 ASSERT (AddrInfo
!= NULL
);
1717 &IpIf
->AddressCount
,
1719 AddrInfo
->PrefixLength
1723 if (Instance
->FailedIaAddressCount
> 0) {
1724 Instance
->FailedIaAddressCount
--;
1730 // Parse the Reply packet to get the options we need.
1732 if (Dhcp6ModeData
.Ia
->ReplyPacket
!= NULL
) {
1733 Ip6ConfigParseDhcpReply (Dhcp6
, Instance
, Dhcp6ModeData
.Ia
->ReplyPacket
);
1738 FreePool (Dhcp6ModeData
.ClientId
);
1739 FreePool (Dhcp6ModeData
.Ia
);
1743 The event process routine when the DHCPv6 server is answered with a reply packet
1744 for an information request.
1746 @param[in] This Points to the EFI_DHCP6_PROTOCOL.
1747 @param[in] Context The pointer to the IP6 configuration instance data.
1748 @param[in] Packet The DHCPv6 reply packet.
1750 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1751 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1752 the DNS server address is not valid.
1757 Ip6ConfigOnDhcp6Reply (
1758 IN EFI_DHCP6_PROTOCOL
*This
,
1760 IN EFI_DHCP6_PACKET
*Packet
1763 return Ip6ConfigParseDhcpReply (This
, (IP6_CONFIG_INSTANCE
*) Context
, Packet
);
1767 The event process routine when the DHCPv6 service binding protocol is installed
1770 @param[in] Event Not used.
1771 @param[in] Context The pointer to the IP6 config instance data.
1776 Ip6ConfigOnDhcp6SbInstalled (
1781 IP6_CONFIG_INSTANCE
*Instance
;
1783 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1785 if ((Instance
->Dhcp6Handle
!= NULL
) || (Instance
->Policy
!= Ip6ConfigPolicyAutomatic
)) {
1787 // The DHCP6 child is already created or the policy is no longer AUTOMATIC.
1792 Ip6ConfigStartStatefulAutoConfig (Instance
, Instance
->OtherInfoOnly
);
1796 Set the configuration for the EFI IPv6 network stack running on the communication
1797 device this EFI IPv6 Configuration Protocol instance manages.
1799 This function is used to set the configuration data of type DataType for the EFI
1800 IPv6 network stack that is running on the communication device that this EFI IPv6
1801 Configuration Protocol instance manages.
1803 DataSize is used to calculate the count of structure instances in the Data for
1804 a DataType in which multiple structure instances are allowed.
1806 This function is always non-blocking. When setting some type of configuration data,
1807 an asynchronous process is invoked to check the correctness of the data, such as
1808 performing Duplicate Address Detection on the manually set local IPv6 addresses.
1809 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1810 is invoked, and the process is not finished yet. The caller wanting to get the result
1811 of the asynchronous process is required to call RegisterDataNotify() to register an
1812 event on the specified configuration data. Once the event is signaled, the caller
1813 can call GetData() to obtain the configuration data and know the result.
1814 For other types of configuration data that do not require an asynchronous configuration
1815 process, the result of the operation is immediately returned.
1817 @param[in] This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1818 @param[in] DataType The type of data to set.
1819 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1820 @param[in] Data The data buffer to set. The type of the data buffer is
1821 associated with the DataType.
1823 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1824 network stack was set successfully.
1825 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1828 - One or more fields in Data do not match the requirement of the
1829 data type indicated by DataType.
1830 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1831 configuration data cannot be set under the current policy.
1832 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1833 data is already in process.
1834 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1835 configuration data, and the process is not finished yet.
1836 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1837 indicated by DataType.
1838 @retval EFI_UNSUPPORTED This DataType is not supported.
1839 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1840 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1845 EfiIp6ConfigSetData (
1846 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1847 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1854 IP6_CONFIG_INSTANCE
*Instance
;
1857 if ((This
== NULL
) || (Data
== NULL
)) {
1858 return EFI_INVALID_PARAMETER
;
1861 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
1862 return EFI_UNSUPPORTED
;
1865 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
1866 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1867 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1869 if (IpSb
->LinkLocalDadFail
) {
1870 return EFI_DEVICE_ERROR
;
1873 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1875 Status
= Instance
->DataItem
[DataType
].Status
;
1876 if (Status
!= EFI_NOT_READY
) {
1878 if (Instance
->DataItem
[DataType
].SetData
== NULL
) {
1880 // This type of data is readonly.
1882 Status
= EFI_WRITE_PROTECTED
;
1885 Status
= Instance
->DataItem
[DataType
].SetData (Instance
, DataSize
, Data
);
1886 if (!EFI_ERROR (Status
)) {
1888 // Fire up the events registered with this type of data.
1890 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
1891 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
1892 } else if (Status
== EFI_ABORTED
) {
1894 // The SetData is aborted because the data to set is the same with
1895 // the one maintained.
1897 Status
= EFI_SUCCESS
;
1898 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
1903 // Another asynchornous process is on the way.
1905 Status
= EFI_ACCESS_DENIED
;
1908 gBS
->RestoreTPL (OldTpl
);
1914 Get the configuration data for the EFI IPv6 network stack running on the communication
1915 device that this EFI IPv6 Configuration Protocol instance manages.
1917 This function returns the configuration data of type DataType for the EFI IPv6 network
1918 stack running on the communication device that this EFI IPv6 Configuration Protocol instance
1921 The caller is responsible for allocating the buffer used to return the specified
1922 configuration data. The required size will be returned to the caller if the size of
1923 the buffer is too small.
1925 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
1926 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
1927 to register an event on the specified configuration data. Once the asynchronous configuration
1928 process is finished, the event will be signaled, and a subsequent GetData() call will return
1929 the specified configuration data.
1931 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1932 @param[in] DataType The type of data to get.
1933 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
1934 size of buffer required to store the specified configuration data.
1935 @param[in] Data The data buffer in which the configuration data is returned. The
1936 type of the data buffer is associated with the DataType.
1937 This is an optional parameter that may be NULL.
1939 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1940 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
1943 - Data is NULL if *DataSize is not zero.
1944 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
1945 and the required size is returned in DataSize.
1946 @retval EFI_NOT_READY The specified configuration data is not ready due to an
1947 asynchronous configuration process already in progress.
1948 @retval EFI_NOT_FOUND The specified configuration data is not found.
1953 EfiIp6ConfigGetData (
1954 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1955 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1956 IN OUT UINTN
*DataSize
,
1957 IN VOID
*Data OPTIONAL
1962 IP6_CONFIG_INSTANCE
*Instance
;
1963 IP6_CONFIG_DATA_ITEM
*DataItem
;
1965 if ((This
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
1966 return EFI_INVALID_PARAMETER
;
1969 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
1970 return EFI_NOT_FOUND
;
1973 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1975 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
1976 DataItem
= &Instance
->DataItem
[DataType
];
1978 Status
= Instance
->DataItem
[DataType
].Status
;
1979 if (!EFI_ERROR (Status
)) {
1981 if (DataItem
->GetData
!= NULL
) {
1983 Status
= DataItem
->GetData (Instance
, DataSize
, Data
);
1984 } else if (*DataSize
< Instance
->DataItem
[DataType
].DataSize
) {
1986 // Update the buffer length.
1988 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
1989 Status
= EFI_BUFFER_TOO_SMALL
;
1992 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
1993 CopyMem (Data
, Instance
->DataItem
[DataType
].Data
.Ptr
, *DataSize
);
1997 gBS
->RestoreTPL (OldTpl
);
2003 Register an event that is signaled whenever a configuration process on the specified
2004 configuration data is done.
2006 This function registers an event that is to be signaled whenever a configuration
2007 process on the specified configuration data is performed. An event can be registered
2008 for a different DataType simultaneously. The caller is responsible for determining
2009 which type of configuration data causes the signaling of the event in such an event.
2011 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2012 @param[in] DataType The type of data to unregister the event for.
2013 @param[in] Event The event to register.
2015 @retval EFI_SUCCESS The notification event for the specified configuration data is
2017 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2018 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
2020 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2021 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2026 EfiIp6ConfigRegisterDataNotify (
2027 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2028 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2034 IP6_CONFIG_INSTANCE
*Instance
;
2038 if ((This
== NULL
) || (Event
== NULL
)) {
2039 return EFI_INVALID_PARAMETER
;
2042 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2043 return EFI_UNSUPPORTED
;
2046 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2048 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2049 EventMap
= &Instance
->DataItem
[DataType
].EventMap
;
2052 // Check whether this event is already registered for this DataType.
2054 Item
= NetMapFindKey (EventMap
, Event
);
2057 Status
= NetMapInsertTail (EventMap
, Event
, NULL
);
2059 if (EFI_ERROR (Status
)) {
2061 Status
= EFI_OUT_OF_RESOURCES
;
2066 Status
= EFI_ACCESS_DENIED
;
2069 gBS
->RestoreTPL (OldTpl
);
2075 Remove a previously registered event for the specified configuration data.
2077 @param This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2078 @param DataType The type of data to remove from the previously
2080 @param Event The event to be unregistered.
2082 @retval EFI_SUCCESS The event registered for the specified
2083 configuration data was removed.
2084 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2085 @retval EFI_NOT_FOUND The Event has not been registered for the
2091 EfiIp6ConfigUnregisterDataNotify (
2092 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2093 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2099 IP6_CONFIG_INSTANCE
*Instance
;
2102 if ((This
== NULL
) || (Event
== NULL
)) {
2103 return EFI_INVALID_PARAMETER
;
2106 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2107 return EFI_NOT_FOUND
;
2110 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2112 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2114 Item
= NetMapFindKey (&Instance
->DataItem
[DataType
].EventMap
, Event
);
2117 NetMapRemoveItem (&Instance
->DataItem
[DataType
].EventMap
, Item
, NULL
);
2118 Status
= EFI_SUCCESS
;
2121 Status
= EFI_NOT_FOUND
;
2124 gBS
->RestoreTPL (OldTpl
);
2130 Initialize an IP6_CONFIG_INSTANCE.
2132 @param[out] Instance The buffer of IP6_CONFIG_INSTANCE to be initialized.
2134 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
2135 @retval EFI_SUCCESS The IP6_CONFIG_INSTANCE initialized successfully.
2139 Ip6ConfigInitInstance (
2140 OUT IP6_CONFIG_INSTANCE
*Instance
2144 IP6_CONFIG_INSTANCE
*TmpInstance
;
2149 IP6_CONFIG_DATA_ITEM
*DataItem
;
2151 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2153 Instance
->Signature
= IP6_CONFIG_INSTANCE_SIGNATURE
;
2156 // Determine the index of this interface.
2159 NET_LIST_FOR_EACH (Entry
, &mIp6ConfigInstanceList
) {
2160 TmpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_CONFIG_INSTANCE
, Link
, IP6_CONFIG_INSTANCE_SIGNATURE
);
2162 if (TmpInstance
->IfIndex
> IfIndex
) {
2164 // There is a sequence hole because some interface is down.
2172 Instance
->IfIndex
= IfIndex
;
2173 NetListInsertBefore (Entry
, &Instance
->Link
);
2175 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2177 // Initialize the event map for each data item.
2179 NetMapInit (&Instance
->DataItem
[Index
].EventMap
);
2183 // Initialize the NET_MAPs used for DAD on manually configured source addresses.
2185 NetMapInit (&Instance
->DadFailedMap
);
2186 NetMapInit (&Instance
->DadPassedMap
);
2189 // Initialize each data type: associate storage and set data size for the
2190 // fixed size data types, hook the SetData function, set the data attribute.
2192 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
2193 DataItem
->GetData
= Ip6ConfigGetIfInfo
;
2194 DataItem
->Data
.Ptr
= &Instance
->InterfaceInfo
;
2195 DataItem
->DataSize
= sizeof (Instance
->InterfaceInfo
);
2196 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
| DATA_ATTRIB_VOLATILE
);
2197 Ip6ConfigInitIfInfo (IpSb
, &Instance
->InterfaceInfo
);
2199 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
2200 DataItem
->SetData
= Ip6ConfigSetAltIfId
;
2201 DataItem
->Data
.Ptr
= &Instance
->AltIfId
;
2202 DataItem
->DataSize
= sizeof (Instance
->AltIfId
);
2203 DataItem
->Status
= EFI_NOT_FOUND
;
2204 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2206 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypePolicy
];
2207 DataItem
->SetData
= Ip6ConfigSetPolicy
;
2208 DataItem
->Data
.Ptr
= &Instance
->Policy
;
2209 DataItem
->DataSize
= sizeof (Instance
->Policy
);
2210 Instance
->Policy
= Ip6ConfigPolicyManual
;
2211 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2213 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
];
2214 DataItem
->SetData
= Ip6ConfigSetDadXmits
;
2215 DataItem
->Data
.Ptr
= &Instance
->DadXmits
;
2216 DataItem
->DataSize
= sizeof (Instance
->DadXmits
);
2217 Instance
->DadXmits
.DupAddrDetectTransmits
= IP6_CONFIG_DEFAULT_DAD_XMITS
;
2218 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2220 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
2221 DataItem
->SetData
= Ip6ConfigSetMaunualAddress
;
2222 DataItem
->Status
= EFI_NOT_FOUND
;
2224 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
2225 DataItem
->SetData
= Ip6ConfigSetGateway
;
2226 DataItem
->Status
= EFI_NOT_FOUND
;
2228 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
2229 DataItem
->SetData
= Ip6ConfigSetDnsServer
;
2230 DataItem
->Status
= EFI_NOT_FOUND
;
2233 // Create the event used for DHCP.
2235 Status
= gBS
->CreateEvent (
2238 Ip6ConfigOnDhcp6Event
,
2240 &Instance
->Dhcp6Event
2242 ASSERT_EFI_ERROR (Status
);
2244 Instance
->Configured
= TRUE
;
2247 // Try to read the config data from NV variable.
2249 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, Instance
);
2250 if (Status
== EFI_NOT_FOUND
) {
2252 // The NV variable is not set, so generate a random IAID, and write down the
2253 // fresh new configuration as the NV variable now.
2255 Instance
->IaId
= NET_RANDOM (NetRandomInitSeed ());
2257 for (Index
= 0; Index
< IpSb
->SnpMode
.HwAddressSize
; Index
++) {
2258 Instance
->IaId
|= (IpSb
->SnpMode
.CurrentAddress
.Addr
[Index
] << ((Index
<< 3) & 31));
2261 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2262 } else if (EFI_ERROR (Status
)) {
2266 Instance
->Ip6Config
.SetData
= EfiIp6ConfigSetData
;
2267 Instance
->Ip6Config
.GetData
= EfiIp6ConfigGetData
;
2268 Instance
->Ip6Config
.RegisterDataNotify
= EfiIp6ConfigRegisterDataNotify
;
2269 Instance
->Ip6Config
.UnregisterDataNotify
= EfiIp6ConfigUnregisterDataNotify
;
2273 // Publish the IP6 configuration form
2275 return Ip6ConfigFormInit (Instance
);
2279 Release an IP6_CONFIG_INSTANCE.
2281 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2285 Ip6ConfigCleanInstance (
2286 IN OUT IP6_CONFIG_INSTANCE
*Instance
2290 IP6_CONFIG_DATA_ITEM
*DataItem
;
2292 if (Instance
->DeclineAddress
!= NULL
) {
2293 FreePool (Instance
->DeclineAddress
);
2296 if (!Instance
->Configured
) {
2300 if (Instance
->Dhcp6Handle
!= NULL
) {
2302 Ip6ConfigDestroyDhcp6 (Instance
);
2308 if (Instance
->Dhcp6Event
!= NULL
) {
2309 gBS
->CloseEvent (Instance
->Dhcp6Event
);
2312 NetMapClean (&Instance
->DadPassedMap
);
2313 NetMapClean (&Instance
->DadFailedMap
);
2315 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2317 DataItem
= &Instance
->DataItem
[Index
];
2319 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
2320 if (DataItem
->Data
.Ptr
!= NULL
) {
2321 FreePool (DataItem
->Data
.Ptr
);
2323 DataItem
->Data
.Ptr
= NULL
;
2324 DataItem
->DataSize
= 0;
2327 NetMapClean (&Instance
->DataItem
[Index
].EventMap
);
2330 Ip6ConfigFormUnload (Instance
);
2332 RemoveEntryList (&Instance
->Link
);
2336 Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
2338 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2340 @retval EFI_SUCCESS The child was successfully destroyed.
2341 @retval Others Failed to destroy the child.
2345 Ip6ConfigDestroyDhcp6 (
2346 IN OUT IP6_CONFIG_INSTANCE
*Instance
2351 EFI_DHCP6_PROTOCOL
*Dhcp6
;
2353 Dhcp6
= Instance
->Dhcp6
;
2354 ASSERT (Dhcp6
!= NULL
);
2356 Dhcp6
->Stop (Dhcp6
);
2357 Dhcp6
->Configure (Dhcp6
, NULL
);
2358 Instance
->Dhcp6
= NULL
;
2360 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2363 // Close DHCPv6 protocol and destroy the child.
2365 Status
= gBS
->CloseProtocol (
2366 Instance
->Dhcp6Handle
,
2367 &gEfiDhcp6ProtocolGuid
,
2371 if (EFI_ERROR (Status
)) {
2375 Status
= NetLibDestroyServiceChild (
2378 &gEfiDhcp6ServiceBindingProtocolGuid
,
2379 Instance
->Dhcp6Handle
2382 Instance
->Dhcp6Handle
= NULL
;