2 The implementation of EFI IPv6 Configuration Protocol.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 LIST_ENTRY mIp6ConfigInstanceList
= { &mIp6ConfigInstanceList
, &mIp6ConfigInstanceList
};
16 The event process routine when the DHCPv6 service binding protocol is installed
19 @param[in] Event Not used.
20 @param[in] Context Pointer to the IP6 config instance data.
25 Ip6ConfigOnDhcp6SbInstalled (
31 Update the current policy to NewPolicy. During the transition
32 period, the default router list, on-link prefix list, autonomous prefix list
33 and address list in all interfaces will be released.
35 @param[in] IpSb The IP6 service binding instance.
36 @param[in] NewPolicy The new policy to be updated to.
40 Ip6ConfigOnPolicyChanged (
42 IN EFI_IP6_CONFIG_POLICY NewPolicy
49 IP6_DAD_ENTRY
*DadEntry
;
50 IP6_DELAY_JOIN_LIST
*DelayNode
;
51 IP6_ADDRESS_INFO
*AddrInfo
;
52 IP6_PROTOCOL
*Instance
;
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
,
83 if (!IsListEmpty (&IpSb
->DefaultInterface
->AddressList
) && (IpSb
->DefaultInterface
->AddressCount
> 0)) {
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.
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
)) {
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.
111 &IpSb
->DefaultInterface
->AddressList
,
112 &IpSb
->DefaultInterface
->AddressCount
,
117 if ((IpSb
->Controller
!= NULL
) && Recovery
) {
119 // ConnectController() to recover the upper layer network stacks.
121 gBS
->ConnectController (IpSb
->Controller
, NULL
, NULL
, TRUE
);
125 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
127 // remove all pending delay node and DAD entries for the global addresses.
129 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
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
);
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
);
142 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
144 // Fail this DAD entry if the address is not link-local.
146 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
151 if (NewPolicy
== Ip6ConfigPolicyAutomatic
) {
153 // Set parameters to trigger router solicitation sending in timer handler.
155 IpSb
->RouterAdvertiseReceived
= FALSE
;
156 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
160 IpSb
->Ticks
= (UINT32
)IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS
);
165 The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
167 @param[in] Instance Pointer to the IP6 config instance data.
168 @param[in] OtherInfoOnly If FALSE, get stateful address and other information
169 via DHCPv6. Otherwise, only get the other information.
171 @retval EFI_SUCCESS The operation finished successfully.
172 @retval EFI_UNSUPPORTED The DHCP6 driver is not available.
176 Ip6ConfigStartStatefulAutoConfig (
177 IN IP6_CONFIG_INSTANCE
*Instance
,
178 IN BOOLEAN OtherInfoOnly
183 EFI_DHCP6_CONFIG_DATA Dhcp6CfgData
;
184 EFI_DHCP6_PROTOCOL
*Dhcp6
;
185 EFI_DHCP6_PACKET_OPTION
*OptList
[1];
187 EFI_DHCP6_PACKET_OPTION
*Oro
;
188 EFI_DHCP6_RETRANSMISSION InfoReqReXmit
;
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.
194 if (Instance
->Dhcp6Handle
!= NULL
) {
198 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
200 Instance
->OtherInfoOnly
= OtherInfoOnly
;
202 Status
= NetLibCreateServiceChild (
205 &gEfiDhcp6ServiceBindingProtocolGuid
,
206 &Instance
->Dhcp6Handle
209 if (Status
== EFI_UNSUPPORTED
) {
211 // No DHCPv6 Service Binding protocol, register a notify.
213 if (Instance
->Dhcp6SbNotifyEvent
== NULL
) {
214 Instance
->Dhcp6SbNotifyEvent
= EfiCreateProtocolNotifyEvent (
215 &gEfiDhcp6ServiceBindingProtocolGuid
,
217 Ip6ConfigOnDhcp6SbInstalled
,
219 &Instance
->Registration
224 if (EFI_ERROR (Status
)) {
228 if (Instance
->Dhcp6SbNotifyEvent
!= NULL
) {
229 gBS
->CloseEvent (Instance
->Dhcp6SbNotifyEvent
);
232 Status
= gBS
->OpenProtocol (
233 Instance
->Dhcp6Handle
,
234 &gEfiDhcp6ProtocolGuid
,
235 (VOID
**)&Instance
->Dhcp6
,
238 EFI_OPEN_PROTOCOL_BY_DRIVER
240 ASSERT_EFI_ERROR (Status
);
242 Dhcp6
= Instance
->Dhcp6
;
243 Dhcp6
->Configure (Dhcp6
, NULL
);
246 // Set the exta options to send. Here we only want the option request option
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
);
255 Status
= EFI_SUCCESS
;
257 if (!OtherInfoOnly
) {
259 // Get stateful address and other information via DHCPv6.
261 Dhcp6CfgData
.Dhcp6Callback
= NULL
;
262 Dhcp6CfgData
.CallbackContext
= NULL
;
263 Dhcp6CfgData
.OptionCount
= 1;
264 Dhcp6CfgData
.OptionList
= &OptList
[0];
265 Dhcp6CfgData
.IaDescriptor
.Type
= EFI_DHCP6_IA_TYPE_NA
;
266 Dhcp6CfgData
.IaDescriptor
.IaId
= Instance
->IaId
;
267 Dhcp6CfgData
.IaInfoEvent
= Instance
->Dhcp6Event
;
268 Dhcp6CfgData
.ReconfigureAccept
= FALSE
;
269 Dhcp6CfgData
.RapidCommit
= FALSE
;
270 Dhcp6CfgData
.SolicitRetransmission
= NULL
;
272 Status
= Dhcp6
->Configure (Dhcp6
, &Dhcp6CfgData
);
274 if (!EFI_ERROR (Status
)) {
275 if (IpSb
->LinkLocalOk
) {
276 Status
= Dhcp6
->Start (Dhcp6
);
278 IpSb
->Dhcp6NeedStart
= TRUE
;
283 // Only get other information via DHCPv6, this doesn't require a config
286 InfoReqReXmit
.Irt
= 4;
287 InfoReqReXmit
.Mrc
= 64;
288 InfoReqReXmit
.Mrt
= 60;
289 InfoReqReXmit
.Mrd
= 0;
291 if (IpSb
->LinkLocalOk
) {
292 Status
= Dhcp6
->InfoRequest (
299 Instance
->Dhcp6Event
,
300 Ip6ConfigOnDhcp6Reply
,
304 IpSb
->Dhcp6NeedInfoRequest
= TRUE
;
312 Signal the registered event. It is the callback routine for NetMapIterate.
314 @param[in] Map Points to the list of registered event.
315 @param[in] Item The registered event.
316 @param[in] Arg Not used.
321 Ip6ConfigSignalEvent (
323 IN NET_MAP_ITEM
*Item
,
327 gBS
->SignalEvent ((EFI_EVENT
)Item
->Key
);
333 Read the configuration data from variable storage according to the VarName and
334 gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
335 data is corrupted, it clears the variable data to ZERO. Otherwise, it outputs the
336 configuration data to IP6_CONFIG_INSTANCE.
338 @param[in] VarName The pointer to the variable name
339 @param[in, out] Instance The pointer to the IP6 config instance data.
341 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
342 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
343 @retval EFI_SUCCESS The configuration data was retrieved successfully.
347 Ip6ConfigReadConfigData (
349 IN OUT IP6_CONFIG_INSTANCE
*Instance
354 IP6_CONFIG_VARIABLE
*Variable
;
355 IP6_CONFIG_DATA_ITEM
*DataItem
;
357 IP6_CONFIG_DATA_RECORD DataRecord
;
361 // Try to read the configuration variable.
364 Status
= gRT
->GetVariable (
366 &gEfiIp6ConfigProtocolGuid
,
372 if (Status
== EFI_BUFFER_TOO_SMALL
) {
374 // Allocate buffer and read the config variable.
376 Variable
= AllocatePool (VarSize
);
377 if (Variable
== NULL
) {
378 return EFI_OUT_OF_RESOURCES
;
381 Status
= gRT
->GetVariable (
383 &gEfiIp6ConfigProtocolGuid
,
388 if (EFI_ERROR (Status
) || ((UINT16
)(~NetblockChecksum ((UINT8
*)Variable
, (UINT32
)VarSize
)) != 0)) {
390 // GetVariable error or the variable is corrupted.
396 // Get the IAID we use.
398 Instance
->IaId
= Variable
->IaId
;
400 for (Index
= 0; Index
< Variable
->DataRecordCount
; Index
++) {
401 CopyMem (&DataRecord
, &Variable
->DataRecord
[Index
], sizeof (DataRecord
));
403 DataItem
= &Instance
->DataItem
[DataRecord
.DataType
];
404 if (DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
) &&
405 (DataItem
->DataSize
!= DataRecord
.DataSize
)
409 // Perhaps a corrupted data record...
414 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
416 // This data item has variable length data.
417 // Check that the length is contained within the variable before allocating.
419 if (DataRecord
.DataSize
> VarSize
- DataRecord
.Offset
) {
423 DataItem
->Data
.Ptr
= AllocatePool (DataRecord
.DataSize
);
424 if (DataItem
->Data
.Ptr
== NULL
) {
426 // no memory resource
432 Data
= (CHAR8
*)Variable
+ DataRecord
.Offset
;
433 CopyMem (DataItem
->Data
.Ptr
, Data
, DataRecord
.DataSize
);
435 DataItem
->DataSize
= DataRecord
.DataSize
;
436 DataItem
->Status
= EFI_SUCCESS
;
447 // Fall back to the default value.
449 if (Variable
!= NULL
) {
454 // Remove the problematic variable and return EFI_NOT_FOUND, a new
455 // variable will be set again.
459 &gEfiIp6ConfigProtocolGuid
,
460 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
465 return EFI_NOT_FOUND
;
469 Write the configuration data from IP6_CONFIG_INSTANCE to variable storage.
471 @param[in] VarName The pointer to the variable name.
472 @param[in] Instance The pointer to the IP6 configuration instance data.
474 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
475 @retval EFI_SUCCESS The configuration data is written successfully.
479 Ip6ConfigWriteConfigData (
481 IN IP6_CONFIG_INSTANCE
*Instance
486 IP6_CONFIG_DATA_ITEM
*DataItem
;
487 IP6_CONFIG_VARIABLE
*Variable
;
488 IP6_CONFIG_DATA_RECORD
*DataRecord
;
492 VarSize
= sizeof (IP6_CONFIG_VARIABLE
) - sizeof (IP6_CONFIG_DATA_RECORD
);
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
;
501 Variable
= AllocatePool (VarSize
);
502 if (Variable
== NULL
) {
503 return EFI_OUT_OF_RESOURCES
;
506 Variable
->IaId
= Instance
->IaId
;
507 Heap
= (CHAR8
*)Variable
+ VarSize
;
508 Variable
->DataRecordCount
= 0;
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
);
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
);
521 Variable
->DataRecordCount
++;
525 Variable
->Checksum
= 0;
526 Variable
->Checksum
= (UINT16
) ~NetblockChecksum ((UINT8
*)Variable
, (UINT32
)VarSize
);
528 Status
= gRT
->SetVariable (
530 &gEfiIp6ConfigProtocolGuid
,
531 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
542 The work function for EfiIp6ConfigGetData() to get the interface information
543 of the communication device this IP6Config instance manages.
545 @param[in] Instance Pointer to the IP6 config instance data.
546 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
547 bytes, the size of buffer required to store the specified
549 @param[in] Data The data buffer in which the configuration data is returned.
550 Ignored if DataSize is ZERO.
552 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
553 configuration data, and the required size is
554 returned in DataSize.
555 @retval EFI_SUCCESS The specified configuration data was obtained.
560 IN IP6_CONFIG_INSTANCE
*Instance
,
561 IN OUT UINTN
*DataSize
,
562 IN VOID
*Data OPTIONAL
567 IP6_CONFIG_DATA_ITEM
*Item
;
568 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
572 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
573 Length
= sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
);
576 // Calculate the required length, add the buffer size for AddressInfo and
579 Ip6BuildEfiAddressList (IpSb
, &AddressCount
, NULL
);
580 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &RouteCount
, NULL
);
582 Length
+= AddressCount
* sizeof (EFI_IP6_ADDRESS_INFO
) + RouteCount
* sizeof (EFI_IP6_ROUTE_TABLE
);
584 if (*DataSize
< Length
) {
586 return EFI_BUFFER_TOO_SMALL
;
590 // Copy the fixed size part of the interface info.
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
));
599 IfInfo
->AddressInfo
= (EFI_IP6_ADDRESS_INFO
*)(IfInfo
+ 1);
600 Ip6BuildEfiAddressList (IpSb
, &IfInfo
->AddressInfoCount
, &IfInfo
->AddressInfo
);
605 IfInfo
->RouteTable
= (EFI_IP6_ROUTE_TABLE
*)(IfInfo
->AddressInfo
+ IfInfo
->AddressInfoCount
);
606 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &IfInfo
->RouteCount
, &IfInfo
->RouteTable
);
608 if (IfInfo
->AddressInfoCount
== 0) {
609 IfInfo
->AddressInfo
= NULL
;
612 if (IfInfo
->RouteCount
== 0) {
613 IfInfo
->RouteTable
= NULL
;
620 The work function for EfiIp6ConfigSetData() to set the alternative interface ID
621 for the communication device managed by this IP6Config instance, if the link local
622 IPv6 addresses generated from the interface ID based on the default source the
623 EFI IPv6 Protocol uses is a duplicate address.
625 @param[in] Instance Pointer to the IP6 configuration instance data.
626 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
627 @param[in] Data The data buffer to set.
629 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
631 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
632 network stack was set.
636 Ip6ConfigSetAltIfId (
637 IN IP6_CONFIG_INSTANCE
*Instance
,
642 EFI_IP6_CONFIG_INTERFACE_ID
*OldIfId
;
643 EFI_IP6_CONFIG_INTERFACE_ID
*NewIfId
;
644 IP6_CONFIG_DATA_ITEM
*DataItem
;
646 if (DataSize
!= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
)) {
647 return EFI_BAD_BUFFER_SIZE
;
650 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
651 OldIfId
= DataItem
->Data
.AltIfId
;
652 NewIfId
= (EFI_IP6_CONFIG_INTERFACE_ID
*)Data
;
654 CopyMem (OldIfId
, NewIfId
, DataSize
);
655 DataItem
->Status
= EFI_SUCCESS
;
661 The work function for EfiIp6ConfigSetData() to set the general configuration
662 policy for the EFI IPv6 network stack that is running on the communication device
663 managed by this IP6Config instance. The policy will affect other configuration settings.
665 @param[in] Instance Pointer to the IP6 config instance data.
666 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
667 @param[in] Data The data buffer to set.
669 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
670 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
671 @retval EFI_ABORTED The new policy equals the current policy.
672 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
673 network stack was set.
678 IN IP6_CONFIG_INSTANCE
*Instance
,
683 EFI_IP6_CONFIG_POLICY NewPolicy
;
684 IP6_CONFIG_DATA_ITEM
*DataItem
;
687 if (DataSize
!= sizeof (EFI_IP6_CONFIG_POLICY
)) {
688 return EFI_BAD_BUFFER_SIZE
;
691 NewPolicy
= *((EFI_IP6_CONFIG_POLICY
*)Data
);
693 if (NewPolicy
> Ip6ConfigPolicyAutomatic
) {
694 return EFI_INVALID_PARAMETER
;
697 if (NewPolicy
== Instance
->Policy
) {
701 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
702 // data size, and fire up all the related events.
704 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
705 if (DataItem
->Data
.Ptr
!= NULL
) {
706 FreePool (DataItem
->Data
.Ptr
);
709 DataItem
->Data
.Ptr
= NULL
;
710 DataItem
->DataSize
= 0;
711 DataItem
->Status
= EFI_NOT_FOUND
;
712 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
714 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
715 if (DataItem
->Data
.Ptr
!= NULL
) {
716 FreePool (DataItem
->Data
.Ptr
);
719 DataItem
->Data
.Ptr
= NULL
;
720 DataItem
->DataSize
= 0;
721 DataItem
->Status
= EFI_NOT_FOUND
;
722 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
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
);
730 if (NewPolicy
== Ip6ConfigPolicyManual
) {
732 // The policy is changed from automatic to manual. Stop the DHCPv6 process
733 // and destroy the DHCPv6 child.
735 if (Instance
->Dhcp6Handle
!= NULL
) {
736 Ip6ConfigDestroyDhcp6 (Instance
);
740 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
741 Ip6ConfigOnPolicyChanged (IpSb
, NewPolicy
);
743 Instance
->Policy
= NewPolicy
;
750 The work function for EfiIp6ConfigSetData() to set the number of consecutive
751 Neighbor Solicitation messages sent while performing Duplicate Address Detection
752 on a tentative address. A value of ZERO indicates that Duplicate Address Detection
753 will not be performed on a tentative address.
755 @param[in] Instance The Instance Pointer to the IP6 config instance data.
756 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
757 @param[in] Data The data buffer to set.
759 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
760 @retval EFI_ABORTED The new transmit count equals the current configuration.
761 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
762 network stack was set.
766 Ip6ConfigSetDadXmits (
767 IN IP6_CONFIG_INSTANCE
*Instance
,
772 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
*OldDadXmits
;
774 if (DataSize
!= sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
)) {
775 return EFI_BAD_BUFFER_SIZE
;
778 OldDadXmits
= Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
].Data
.DadXmits
;
780 if ((*(UINT32
*)Data
) == OldDadXmits
->DupAddrDetectTransmits
) {
783 OldDadXmits
->DupAddrDetectTransmits
= *((UINT32
*)Data
);
789 The callback function for Ip6SetAddr. The prototype is defined
790 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
791 for the manual address set by Ip6ConfigSetManualAddress.
793 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passed.
794 @param[in] TargetAddress The tentative IPv6 address to be checked.
795 @param[in] Context Pointer to the IP6 configuration instance data.
799 Ip6ManualAddrDadCallback (
800 IN BOOLEAN IsDadPassed
,
801 IN EFI_IPv6_ADDRESS
*TargetAddress
,
805 IP6_CONFIG_INSTANCE
*Instance
;
807 IP6_CONFIG_DATA_ITEM
*Item
;
808 EFI_IP6_CONFIG_MANUAL_ADDRESS
*ManualAddr
;
809 EFI_IP6_CONFIG_MANUAL_ADDRESS
*PassedAddr
;
814 Instance
= (IP6_CONFIG_INSTANCE
*)Context
;
815 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
816 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
819 if (Item
->DataSize
== 0) {
823 for (Index
= 0; Index
< Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
); Index
++) {
825 // Find the original tag used to place into the NET_MAP.
827 ManualAddr
= Item
->Data
.ManualAddress
+ Index
;
828 if (EFI_IP6_EQUAL (TargetAddress
, &ManualAddr
->Address
)) {
833 ASSERT (Index
!= Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
836 NetMapInsertTail (&Instance
->DadPassedMap
, ManualAddr
, NULL
);
838 NetMapInsertTail (&Instance
->DadFailedMap
, ManualAddr
, NULL
);
841 DadPassCount
= NetMapGetCount (&Instance
->DadPassedMap
);
842 DadFailCount
= NetMapGetCount (&Instance
->DadFailedMap
);
844 if ((DadPassCount
+ DadFailCount
) == (Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
))) {
846 // All addresses have finished the configuration process.
848 if (DadFailCount
!= 0) {
850 // There is at least one duplicate address.
852 FreePool (Item
->Data
.Ptr
);
854 Item
->DataSize
= DadPassCount
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
855 if (Item
->DataSize
== 0) {
857 // All failed, bad luck.
859 Item
->Data
.Ptr
= NULL
;
860 Item
->Status
= EFI_NOT_FOUND
;
863 // Part of addresses are detected to be duplicates, so update the
864 // data with those passed.
866 PassedAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*)AllocatePool (Item
->DataSize
);
867 ASSERT (PassedAddr
!= NULL
);
869 Item
->Data
.Ptr
= PassedAddr
;
870 Item
->Status
= EFI_SUCCESS
;
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
));
879 ASSERT ((UINTN
)PassedAddr
- (UINTN
)Item
->Data
.Ptr
== Item
->DataSize
);
883 // All addresses are valid.
885 Item
->Status
= EFI_SUCCESS
;
889 // Remove the tags we put in the NET_MAPs.
891 while (!NetMapIsEmpty (&Instance
->DadFailedMap
)) {
892 NetMapRemoveHead (&Instance
->DadFailedMap
, NULL
);
895 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
896 NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
900 // Signal the waiting events.
902 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
903 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
904 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
909 The work function for EfiIp6ConfigSetData() to set the station addresses manually
910 for the EFI IPv6 network stack. It is only configurable when the policy is
911 Ip6ConfigPolicyManual.
913 @param[in] Instance Pointer to the IP6 configuration instance data.
914 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
915 @param[in] Data The data buffer to set.
917 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
918 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
919 under the current policy.
920 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
921 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
922 @retval EFI_NOT_READY An asynchronous process is invoked to set the specified
923 configuration data, and the process is not finished.
924 @retval EFI_ABORTED The manual addresses to be set equal current
926 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
927 network stack was set.
931 Ip6ConfigSetManualAddress (
932 IN IP6_CONFIG_INSTANCE
*Instance
,
937 EFI_IP6_CONFIG_MANUAL_ADDRESS
*NewAddress
;
938 EFI_IP6_CONFIG_MANUAL_ADDRESS
*TmpAddress
;
939 IP6_CONFIG_DATA_ITEM
*DataItem
;
940 UINTN NewAddressCount
;
944 IP6_ADDRESS_INFO
*CurrentAddrInfo
;
945 IP6_ADDRESS_INFO
*Copy
;
946 LIST_ENTRY CurrentSourceList
;
947 UINT32 CurrentSourceCount
;
951 IP6_PREFIX_LIST_ENTRY
*PrefixEntry
;
955 IP6_DAD_ENTRY
*DadEntry
;
956 IP6_DELAY_JOIN_LIST
*DelayNode
;
960 CurrentAddrInfo
= NULL
;
969 Status
= EFI_SUCCESS
;
971 ASSERT (Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
].Status
!= EFI_NOT_READY
);
973 if ((DataSize
!= 0) && ((DataSize
% sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
)) != 0)) {
974 return EFI_BAD_BUFFER_SIZE
;
977 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
978 return EFI_WRITE_PROTECTED
;
981 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
983 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
985 if ((Data
!= NULL
) && (DataSize
!= 0)) {
986 NewAddressCount
= DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
987 NewAddress
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*)Data
;
989 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
990 if (NetIp6IsLinkLocalAddr (&NewAddress
->Address
) ||
991 !NetIp6IsValidUnicast (&NewAddress
->Address
) ||
992 (NewAddress
->PrefixLength
> 128)
996 // make sure the IPv6 address is unicast and not link-local address &&
997 // the prefix length is valid.
999 return EFI_INVALID_PARAMETER
;
1002 TmpAddress
= NewAddress
+ 1;
1003 for (Index2
= Index1
+ 1; Index2
< NewAddressCount
; Index2
++, TmpAddress
++) {
1005 // Any two addresses in the array can't be equal.
1007 if (EFI_IP6_EQUAL (&TmpAddress
->Address
, &NewAddress
->Address
)) {
1008 return EFI_INVALID_PARAMETER
;
1014 // Build the current source address list.
1016 InitializeListHead (&CurrentSourceList
);
1017 CurrentSourceCount
= 0;
1019 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1020 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
1022 NET_LIST_FOR_EACH (Entry2
, &IpIf
->AddressList
) {
1023 CurrentAddrInfo
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
1025 Copy
= AllocateCopyPool (sizeof (IP6_ADDRESS_INFO
), CurrentAddrInfo
);
1030 InsertTailList (&CurrentSourceList
, &Copy
->Link
);
1031 CurrentSourceCount
++;
1036 // Update the value... a long journey starts
1038 NewAddress
= AllocateCopyPool (DataSize
, Data
);
1039 if (NewAddress
== NULL
) {
1040 Ip6RemoveAddr (NULL
, &CurrentSourceList
, &CurrentSourceCount
, NULL
, 0);
1042 return EFI_OUT_OF_RESOURCES
;
1046 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1047 // we may have an asynchronous configuration process.
1049 if (DataItem
->Data
.Ptr
!= NULL
) {
1050 FreePool (DataItem
->Data
.Ptr
);
1053 DataItem
->Data
.Ptr
= NewAddress
;
1054 DataItem
->DataSize
= DataSize
;
1055 DataItem
->Status
= EFI_NOT_READY
;
1058 // Trigger DAD, it's an asynchronous process.
1062 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
1063 if (Ip6IsOneOfSetAddress (IpSb
, &NewAddress
->Address
, NULL
, &CurrentAddrInfo
)) {
1064 ASSERT (CurrentAddrInfo
!= NULL
);
1066 // Remove this already existing source address from the CurrentSourceList
1072 &CurrentSourceCount
,
1073 &CurrentAddrInfo
->Address
,
1078 // If the new address's prefix length is not specified, just use the previous configured
1079 // prefix length for this address.
1081 if (NewAddress
->PrefixLength
== 0) {
1082 NewAddress
->PrefixLength
= CurrentAddrInfo
->PrefixLength
;
1086 // This manual address is already in use, see whether prefix length is changed.
1088 if (NewAddress
->PrefixLength
!= CurrentAddrInfo
->PrefixLength
) {
1090 // Remove the on-link prefix table, the route entry will be removed
1093 PrefixEntry
= Ip6FindPrefixListEntry (
1096 CurrentAddrInfo
->PrefixLength
,
1097 &CurrentAddrInfo
->Address
1099 if (PrefixEntry
!= NULL
) {
1100 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1104 // Save the prefix length.
1106 CurrentAddrInfo
->PrefixLength
= NewAddress
->PrefixLength
;
1111 // create a new on-link prefix entry.
1113 PrefixEntry
= Ip6FindPrefixListEntry (
1116 NewAddress
->PrefixLength
,
1117 &NewAddress
->Address
1119 if (PrefixEntry
== NULL
) {
1120 Ip6CreatePrefixListEntry (
1123 (UINT32
)IP6_INFINIT_LIFETIME
,
1124 (UINT32
)IP6_INFINIT_LIFETIME
,
1125 NewAddress
->PrefixLength
,
1126 &NewAddress
->Address
1130 CurrentAddrInfo
->IsAnycast
= NewAddress
->IsAnycast
;
1132 // Artificially mark this address passed DAD be'coz it is already in use.
1134 Ip6ManualAddrDadCallback (TRUE
, &NewAddress
->Address
, Instance
);
1142 // Set the new address, this will trigger DAD and activate the address if
1146 IpSb
->DefaultInterface
,
1147 &NewAddress
->Address
,
1148 NewAddress
->IsAnycast
,
1149 NewAddress
->PrefixLength
,
1150 (UINT32
)IP6_INFINIT_LIFETIME
,
1151 (UINT32
)IP6_INFINIT_LIFETIME
,
1152 Ip6ManualAddrDadCallback
,
1159 // Check the CurrentSourceList, it now contains those addresses currently in
1160 // use and will be removed.
1162 IpIf
= IpSb
->DefaultInterface
;
1164 while (!IsListEmpty (&CurrentSourceList
)) {
1167 CurrentAddrInfo
= NET_LIST_HEAD (&CurrentSourceList
, IP6_ADDRESS_INFO
, Link
);
1170 // This local address is going to be removed, the IP instances that are
1171 // currently using it will be destroyed.
1176 &IpIf
->AddressCount
,
1177 &CurrentAddrInfo
->Address
,
1182 // Remove the on-link prefix table, the route entry will be removed
1185 PrefixEntry
= Ip6FindPrefixListEntry (
1188 CurrentAddrInfo
->PrefixLength
,
1189 &CurrentAddrInfo
->Address
1191 if (PrefixEntry
!= NULL
) {
1192 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1195 RemoveEntryList (&CurrentAddrInfo
->Link
);
1196 FreePool (CurrentAddrInfo
);
1200 if (DataItem
->Status
== EFI_NOT_READY
) {
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.
1206 Status
= EFI_NOT_READY
;
1208 Status
= EFI_SUCCESS
;
1212 // No update is taken, reset the status to success and return EFI_ABORTED.
1214 DataItem
->Status
= EFI_SUCCESS
;
1215 Status
= EFI_ABORTED
;
1219 // DataSize is 0 and Data is NULL, clean up the manual address.
1221 if (DataItem
->Data
.Ptr
!= NULL
) {
1222 FreePool (DataItem
->Data
.Ptr
);
1225 DataItem
->Data
.Ptr
= NULL
;
1226 DataItem
->DataSize
= 0;
1227 DataItem
->Status
= EFI_NOT_FOUND
;
1229 Ip6CleanDefaultRouterList (IpSb
);
1230 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
1231 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
1232 Ip6CleanAssembleTable (&IpSb
->Assemble
);
1234 if (IpSb
->LinkLocalOk
) {
1235 Ip6CreatePrefixListEntry (
1238 (UINT32
)IP6_INFINIT_LIFETIME
,
1239 (UINT32
)IP6_INFINIT_LIFETIME
,
1240 IP6_LINK_LOCAL_PREFIX_LENGTH
,
1241 &IpSb
->LinkLocalAddr
1247 &IpSb
->DefaultInterface
->AddressList
,
1248 &IpSb
->DefaultInterface
->AddressCount
,
1253 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1255 // Remove all pending delay node and DAD entries for the global addresses.
1257 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
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
);
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
);
1270 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
1272 // Fail this DAD entry if the address is not link-local.
1274 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
1284 The work function for EfiIp6ConfigSetData() to set the gateway addresses manually
1285 for the EFI IPv6 network stack that is running on the communication device that
1286 this EFI IPv6 Configuration Protocol manages. It is not configurable when the policy is
1287 Ip6ConfigPolicyAutomatic. The gateway addresses must be unicast IPv6 addresses.
1289 @param[in] Instance The pointer to the IP6 config instance data.
1290 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1291 @param[in] Data The data buffer to set. This points to an array of
1292 EFI_IPv6_ADDRESS instances.
1294 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1295 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1296 under the current policy.
1297 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1298 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1299 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1300 current configuration.
1301 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1302 network stack was set.
1306 Ip6ConfigSetGateway (
1307 IN IP6_CONFIG_INSTANCE
*Instance
,
1314 EFI_IPv6_ADDRESS
*OldGateway
;
1315 EFI_IPv6_ADDRESS
*NewGateway
;
1316 UINTN OldGatewayCount
;
1317 UINTN NewGatewayCount
;
1318 IP6_CONFIG_DATA_ITEM
*Item
;
1322 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1328 DefaultRouter
= NULL
;
1333 if ((DataSize
!= 0) && (DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0)) {
1334 return EFI_BAD_BUFFER_SIZE
;
1337 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1338 return EFI_WRITE_PROTECTED
;
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
);
1346 for (Index1
= 0; Index1
< OldGatewayCount
; Index1
++) {
1348 // Remove this default router.
1350 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, OldGateway
+ Index1
);
1351 if (DefaultRouter
!= NULL
) {
1352 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
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
;
1365 for (Index2
= Index1
+ 1; Index2
< NewGatewayCount
; Index2
++) {
1366 if (EFI_IP6_EQUAL (NewGateway
+ Index1
, NewGateway
+ Index2
)) {
1367 return EFI_INVALID_PARAMETER
;
1372 if (NewGatewayCount
!= OldGatewayCount
) {
1373 Tmp
= AllocatePool (DataSize
);
1375 return EFI_OUT_OF_RESOURCES
;
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
);
1389 if (!OneRemoved
&& !OneAdded
) {
1390 Item
->Status
= EFI_SUCCESS
;
1394 if (Item
->Data
.Ptr
!= NULL
) {
1395 FreePool (Item
->Data
.Ptr
);
1398 Item
->Data
.Ptr
= Tmp
;
1401 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1402 Item
->DataSize
= DataSize
;
1403 Item
->Status
= EFI_SUCCESS
;
1408 // DataSize is 0 and Data is NULL, clean up the Gateway address.
1410 if (Item
->Data
.Ptr
!= NULL
) {
1411 FreePool (Item
->Data
.Ptr
);
1414 Item
->Data
.Ptr
= NULL
;
1416 Item
->Status
= EFI_NOT_FOUND
;
1423 The work function for EfiIp6ConfigSetData() to set the DNS server list for the
1424 EFI IPv6 network stack running on the communication device that this EFI IPv6
1425 Configuration Protocol manages. It is not configurable when the policy is
1426 Ip6ConfigPolicyAutomatic. The DNS server addresses must be unicast IPv6 addresses.
1428 @param[in] Instance The pointer to the IP6 config instance data.
1429 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1430 @param[in] Data The data buffer to set, points to an array of
1431 EFI_IPv6_ADDRESS instances.
1433 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1434 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1435 under the current policy.
1436 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1437 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1438 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1440 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1441 network stack was set.
1445 Ip6ConfigSetDnsServer (
1446 IN IP6_CONFIG_INSTANCE
*Instance
,
1453 EFI_IPv6_ADDRESS
*OldDns
;
1454 EFI_IPv6_ADDRESS
*NewDns
;
1457 IP6_CONFIG_DATA_ITEM
*Item
;
1466 if ((DataSize
!= 0) && (DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0)) {
1467 return EFI_BAD_BUFFER_SIZE
;
1470 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1471 return EFI_WRITE_PROTECTED
;
1474 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
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
);
1483 if (NewDnsCount
!= OldDnsCount
) {
1484 Tmp
= AllocatePool (DataSize
);
1486 return EFI_OUT_OF_RESOURCES
;
1492 for (NewIndex
= 0; NewIndex
< NewDnsCount
; NewIndex
++) {
1493 if (!NetIp6IsValidUnicast (NewDns
+ NewIndex
)) {
1495 // The dns server address must be unicast.
1501 return EFI_INVALID_PARAMETER
;
1506 // If any address in the new setting is not in the old settings, skip the
1507 // comparision below.
1512 for (OldIndex
= 0; OldIndex
< OldDnsCount
; OldIndex
++) {
1513 if (EFI_IP6_EQUAL (NewDns
+ NewIndex
, OldDns
+ OldIndex
)) {
1515 // If found break out.
1521 if (OldIndex
== OldDnsCount
) {
1526 if (!OneAdded
&& (DataSize
== Item
->DataSize
)) {
1528 // No new item is added and the size is the same.
1530 Item
->Status
= EFI_SUCCESS
;
1534 if (Item
->Data
.Ptr
!= NULL
) {
1535 FreePool (Item
->Data
.Ptr
);
1538 Item
->Data
.Ptr
= Tmp
;
1541 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1542 Item
->DataSize
= DataSize
;
1543 Item
->Status
= EFI_SUCCESS
;
1547 // DataSize is 0 and Data is NULL, clean up the DnsServer address.
1549 if (Item
->Data
.Ptr
!= NULL
) {
1550 FreePool (Item
->Data
.Ptr
);
1553 Item
->Data
.Ptr
= NULL
;
1555 Item
->Status
= EFI_NOT_FOUND
;
1562 Generate the operational state of the interface this IP6 config instance manages
1563 and output in EFI_IP6_CONFIG_INTERFACE_INFO.
1565 @param[in] IpSb The pointer to the IP6 service binding instance.
1566 @param[out] IfInfo The pointer to the IP6 configuration interface information structure.
1570 Ip6ConfigInitIfInfo (
1571 IN IP6_SERVICE
*IpSb
,
1572 OUT EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
1577 sizeof (IfInfo
->Name
),
1579 IpSb
->Ip6ConfigInstance
.IfIndex
1582 IfInfo
->IfType
= IpSb
->SnpMode
.IfType
;
1583 IfInfo
->HwAddressSize
= IpSb
->SnpMode
.HwAddressSize
;
1584 CopyMem (&IfInfo
->HwAddress
, &IpSb
->SnpMode
.CurrentAddress
, IfInfo
->HwAddressSize
);
1588 Parse DHCPv6 reply packet to get the DNS server list.
1589 It is the work function for Ip6ConfigOnDhcp6Reply and Ip6ConfigOnDhcp6Event.
1591 @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL instance.
1592 @param[in, out] Instance The pointer to the IP6 configuration instance data.
1593 @param[in] Reply The pointer to the DHCPv6 reply packet.
1595 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1596 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1597 the DNS server address is not valid.
1601 Ip6ConfigParseDhcpReply (
1602 IN EFI_DHCP6_PROTOCOL
*Dhcp6
,
1603 IN OUT IP6_CONFIG_INSTANCE
*Instance
,
1604 IN EFI_DHCP6_PACKET
*Reply
1609 EFI_DHCP6_PACKET_OPTION
**OptList
;
1614 EFI_IPv6_ADDRESS
*DnsServer
;
1615 IP6_CONFIG_DATA_ITEM
*Item
;
1618 // A DHCPv6 reply packet is received as the response to our InfoRequest
1622 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, NULL
);
1623 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1624 return EFI_NOT_READY
;
1627 OptList
= AllocatePool (OptCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*));
1628 if (OptList
== NULL
) {
1629 return EFI_NOT_READY
;
1632 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, OptList
);
1633 if (EFI_ERROR (Status
)) {
1634 Status
= EFI_NOT_READY
;
1638 Status
= EFI_SUCCESS
;
1640 for (Index
= 0; Index
< OptCount
; Index
++) {
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
1646 CopyMem (&OpCode
, &OptList
[Index
]->OpCode
, sizeof (OpCode
));
1647 OpCode
= NTOHS (OpCode
);
1649 if (OpCode
== DHCP6_OPT_DNS_SERVERS
) {
1650 CopyMem (&Length
, &OptList
[Index
]->OpLen
, sizeof (Length
));
1651 Length
= NTOHS (Length
);
1653 if ((Length
== 0) || ((Length
% sizeof (EFI_IPv6_ADDRESS
)) != 0)) {
1655 // The length should be a multiple of 16 bytes.
1657 Status
= EFI_NOT_READY
;
1662 // Validate the DnsServers: whether they are unicast addresses.
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
;
1674 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1676 if (Item
->DataSize
!= Length
) {
1677 if (Item
->Data
.Ptr
!= NULL
) {
1678 FreePool (Item
->Data
.Ptr
);
1681 Item
->Data
.Ptr
= AllocatePool (Length
);
1682 ASSERT (Item
->Data
.Ptr
!= NULL
);
1685 CopyMem (Item
->Data
.Ptr
, OptList
[Index
]->Data
, Length
);
1686 Item
->DataSize
= Length
;
1687 Item
->Status
= EFI_SUCCESS
;
1690 // Signal the waiting events.
1692 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
1705 The callback function for Ip6SetAddr. The prototype is defined
1706 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
1707 on the tentative address by DHCPv6 in Ip6ConfigOnDhcp6Event().
1709 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passes.
1710 @param[in] TargetAddress The tentative IPv6 address to be checked.
1711 @param[in] Context Pointer to the IP6 configuration instance data.
1715 Ip6ConfigSetStatefulAddrCallback (
1716 IN BOOLEAN IsDadPassed
,
1717 IN EFI_IPv6_ADDRESS
*TargetAddress
,
1721 IP6_CONFIG_INSTANCE
*Instance
;
1723 Instance
= (IP6_CONFIG_INSTANCE
*)Context
;
1724 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
1727 // We should record the addresses that fail the DAD, and DECLINE them.
1731 // Decrease the count, no interests in those passed DAD.
1733 if (Instance
->FailedIaAddressCount
> 0 ) {
1734 Instance
->FailedIaAddressCount
--;
1740 IP6_COPY_ADDRESS (Instance
->DeclineAddress
+ Instance
->DeclineAddressCount
, TargetAddress
);
1741 Instance
->DeclineAddressCount
++;
1744 if (Instance
->FailedIaAddressCount
== Instance
->DeclineAddressCount
) {
1746 // The checking on all addresses are finished.
1748 if (Instance
->DeclineAddressCount
!= 0) {
1750 // Decline those duplicates.
1752 if (Instance
->Dhcp6
!= NULL
) {
1753 Instance
->Dhcp6
->Decline (
1755 Instance
->DeclineAddressCount
,
1756 Instance
->DeclineAddress
1761 if (Instance
->DeclineAddress
!= NULL
) {
1762 FreePool (Instance
->DeclineAddress
);
1765 Instance
->DeclineAddress
= NULL
;
1766 Instance
->DeclineAddressCount
= 0;
1771 The event handle routine when DHCPv6 process is finished or is updated.
1773 @param[in] Event Not used.
1774 @param[in] Context The pointer to the IP6 configuration instance data.
1779 Ip6ConfigOnDhcp6Event (
1784 IP6_CONFIG_INSTANCE
*Instance
;
1785 EFI_DHCP6_PROTOCOL
*Dhcp6
;
1787 EFI_DHCP6_MODE_DATA Dhcp6ModeData
;
1789 EFI_DHCP6_IA_ADDRESS
*IaAddr
;
1792 IP6_ADDRESS_INFO
*AddrInfo
;
1793 IP6_INTERFACE
*IpIf
;
1795 Instance
= (IP6_CONFIG_INSTANCE
*)Context
;
1797 if ((Instance
->Policy
!= Ip6ConfigPolicyAutomatic
) || Instance
->OtherInfoOnly
) {
1799 // IPv6 is not operating in the automatic policy now or
1800 // the DHCPv6 information request message exchange is aborted.
1806 // The stateful address autoconfiguration is done or updated.
1808 Dhcp6
= Instance
->Dhcp6
;
1810 Status
= Dhcp6
->GetModeData (Dhcp6
, &Dhcp6ModeData
, NULL
);
1811 if (EFI_ERROR (Status
)) {
1815 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1816 IpIf
= IpSb
->DefaultInterface
;
1817 Ia
= Dhcp6ModeData
.Ia
;
1818 IaAddr
= Ia
->IaAddress
;
1820 if (Instance
->DeclineAddress
!= NULL
) {
1821 FreePool (Instance
->DeclineAddress
);
1824 Instance
->DeclineAddress
= (EFI_IPv6_ADDRESS
*)AllocatePool (Ia
->IaAddressCount
* sizeof (EFI_IPv6_ADDRESS
));
1825 if (Instance
->DeclineAddress
== NULL
) {
1829 Instance
->FailedIaAddressCount
= Ia
->IaAddressCount
;
1830 Instance
->DeclineAddressCount
= 0;
1832 for (Index
= 0; Index
< Ia
->IaAddressCount
; Index
++, IaAddr
++) {
1833 if ((Ia
->IaAddress
[Index
].ValidLifetime
!= 0) && (Ia
->State
== Dhcp6Bound
)) {
1835 // Set this address, either it's a new address or with updated lifetimes.
1836 // An appropriate prefix length will be set.
1843 IaAddr
->ValidLifetime
,
1844 IaAddr
->PreferredLifetime
,
1845 Ip6ConfigSetStatefulAddrCallback
,
1850 // discard this address, artificially decrease the count as if this address
1853 if (Ip6IsOneOfSetAddress (IpSb
, &IaAddr
->IpAddress
, NULL
, &AddrInfo
)) {
1854 ASSERT (AddrInfo
!= NULL
);
1858 &IpIf
->AddressCount
,
1860 AddrInfo
->PrefixLength
1864 if (Instance
->FailedIaAddressCount
> 0) {
1865 Instance
->FailedIaAddressCount
--;
1871 // Parse the Reply packet to get the options we need.
1873 if (Dhcp6ModeData
.Ia
->ReplyPacket
!= NULL
) {
1874 Ip6ConfigParseDhcpReply (Dhcp6
, Instance
, Dhcp6ModeData
.Ia
->ReplyPacket
);
1879 FreePool (Dhcp6ModeData
.ClientId
);
1880 FreePool (Dhcp6ModeData
.Ia
);
1884 The event process routine when the DHCPv6 server is answered with a reply packet
1885 for an information request.
1887 @param[in] This Points to the EFI_DHCP6_PROTOCOL.
1888 @param[in] Context The pointer to the IP6 configuration instance data.
1889 @param[in] Packet The DHCPv6 reply packet.
1891 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1892 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1893 the DNS server address is not valid.
1898 Ip6ConfigOnDhcp6Reply (
1899 IN EFI_DHCP6_PROTOCOL
*This
,
1901 IN EFI_DHCP6_PACKET
*Packet
1904 return Ip6ConfigParseDhcpReply (This
, (IP6_CONFIG_INSTANCE
*)Context
, Packet
);
1908 The event process routine when the DHCPv6 service binding protocol is installed
1911 @param[in] Event Not used.
1912 @param[in] Context The pointer to the IP6 config instance data.
1917 Ip6ConfigOnDhcp6SbInstalled (
1922 IP6_CONFIG_INSTANCE
*Instance
;
1924 Instance
= (IP6_CONFIG_INSTANCE
*)Context
;
1926 if ((Instance
->Dhcp6Handle
!= NULL
) || (Instance
->Policy
!= Ip6ConfigPolicyAutomatic
)) {
1928 // The DHCP6 child is already created or the policy is no longer AUTOMATIC.
1933 Ip6ConfigStartStatefulAutoConfig (Instance
, Instance
->OtherInfoOnly
);
1937 Set the configuration for the EFI IPv6 network stack running on the communication
1938 device this EFI IPv6 Configuration Protocol instance manages.
1940 This function is used to set the configuration data of type DataType for the EFI
1941 IPv6 network stack that is running on the communication device that this EFI IPv6
1942 Configuration Protocol instance manages.
1944 DataSize is used to calculate the count of structure instances in the Data for
1945 a DataType in which multiple structure instances are allowed.
1947 This function is always non-blocking. When setting some type of configuration data,
1948 an asynchronous process is invoked to check the correctness of the data, such as
1949 performing Duplicate Address Detection on the manually set local IPv6 addresses.
1950 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1951 is invoked, and the process is not finished yet. The caller wanting to get the result
1952 of the asynchronous process is required to call RegisterDataNotify() to register an
1953 event on the specified configuration data. Once the event is signaled, the caller
1954 can call GetData() to obtain the configuration data and know the result.
1955 For other types of configuration data that do not require an asynchronous configuration
1956 process, the result of the operation is immediately returned.
1958 @param[in] This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1959 @param[in] DataType The type of data to set.
1960 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1961 @param[in] Data The data buffer to set. The type of the data buffer is
1962 associated with the DataType.
1964 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1965 network stack was set successfully.
1966 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1968 - One or more fields in Data and DataSizedo not match the
1969 requirement of the data type indicated by DataType.
1970 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1971 configuration data cannot be set under the current policy.
1972 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1973 data is already in process.
1974 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1975 configuration data, and the process is not finished yet.
1976 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1977 indicated by DataType.
1978 @retval EFI_UNSUPPORTED This DataType is not supported.
1979 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1980 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1985 EfiIp6ConfigSetData (
1986 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1987 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1994 IP6_CONFIG_INSTANCE
*Instance
;
1997 if ((This
== NULL
) || ((Data
== NULL
) && (DataSize
!= 0)) || ((Data
!= NULL
) && (DataSize
== 0))) {
1998 return EFI_INVALID_PARAMETER
;
2001 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2002 return EFI_UNSUPPORTED
;
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
);
2009 if (IpSb
->LinkLocalDadFail
) {
2010 return EFI_DEVICE_ERROR
;
2013 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2015 Status
= Instance
->DataItem
[DataType
].Status
;
2016 if (Status
!= EFI_NOT_READY
) {
2017 if (Instance
->DataItem
[DataType
].SetData
== NULL
) {
2019 // This type of data is readonly.
2021 Status
= EFI_WRITE_PROTECTED
;
2023 Status
= Instance
->DataItem
[DataType
].SetData (Instance
, DataSize
, Data
);
2024 if (!EFI_ERROR (Status
)) {
2026 // Fire up the events registered with this type of data.
2028 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
2029 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2030 } else if (Status
== EFI_ABORTED
) {
2032 // The SetData is aborted because the data to set is the same with
2033 // the one maintained.
2035 Status
= EFI_SUCCESS
;
2036 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
2041 // Another asynchronous process is on the way.
2043 Status
= EFI_ACCESS_DENIED
;
2046 gBS
->RestoreTPL (OldTpl
);
2052 Get the configuration data for the EFI IPv6 network stack running on the communication
2053 device that this EFI IPv6 Configuration Protocol instance manages.
2055 This function returns the configuration data of type DataType for the EFI IPv6 network
2056 stack running on the communication device that this EFI IPv6 Configuration Protocol instance
2059 The caller is responsible for allocating the buffer used to return the specified
2060 configuration data. The required size will be returned to the caller if the size of
2061 the buffer is too small.
2063 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
2064 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
2065 to register an event on the specified configuration data. Once the asynchronous configuration
2066 process is finished, the event will be signaled, and a subsequent GetData() call will return
2067 the specified configuration data.
2069 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2070 @param[in] DataType The type of data to get.
2071 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
2072 size of buffer required to store the specified configuration data.
2073 @param[in] Data The data buffer in which the configuration data is returned. The
2074 type of the data buffer is associated with the DataType.
2075 This is an optional parameter that may be NULL.
2077 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
2078 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
2081 - Data is NULL if *DataSize is not zero.
2082 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
2083 and the required size is returned in DataSize.
2084 @retval EFI_NOT_READY The specified configuration data is not ready due to an
2085 asynchronous configuration process already in progress.
2086 @retval EFI_NOT_FOUND The specified configuration data is not found.
2091 EfiIp6ConfigGetData (
2092 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2093 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2094 IN OUT UINTN
*DataSize
,
2095 IN VOID
*Data OPTIONAL
2100 IP6_CONFIG_INSTANCE
*Instance
;
2101 IP6_CONFIG_DATA_ITEM
*DataItem
;
2103 if ((This
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
2104 return EFI_INVALID_PARAMETER
;
2107 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2108 return EFI_NOT_FOUND
;
2111 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2113 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2114 DataItem
= &Instance
->DataItem
[DataType
];
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
) {
2122 // Update the buffer length.
2124 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2125 Status
= EFI_BUFFER_TOO_SMALL
;
2127 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2128 CopyMem (Data
, Instance
->DataItem
[DataType
].Data
.Ptr
, *DataSize
);
2132 gBS
->RestoreTPL (OldTpl
);
2138 Register an event that is signaled whenever a configuration process on the specified
2139 configuration data is done.
2141 This function registers an event that is to be signaled whenever a configuration
2142 process on the specified configuration data is performed. An event can be registered
2143 for a different DataType simultaneously. The caller is responsible for determining
2144 which type of configuration data causes the signaling of the event in such an event.
2146 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2147 @param[in] DataType The type of data to unregister the event for.
2148 @param[in] Event The event to register.
2150 @retval EFI_SUCCESS The notification event for the specified configuration data is
2152 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2153 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
2155 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2156 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2161 EfiIp6ConfigRegisterDataNotify (
2162 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2163 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2169 IP6_CONFIG_INSTANCE
*Instance
;
2173 if ((This
== NULL
) || (Event
== NULL
)) {
2174 return EFI_INVALID_PARAMETER
;
2177 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2178 return EFI_UNSUPPORTED
;
2181 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2183 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2184 EventMap
= &Instance
->DataItem
[DataType
].EventMap
;
2187 // Check whether this event is already registered for this DataType.
2189 Item
= NetMapFindKey (EventMap
, Event
);
2191 Status
= NetMapInsertTail (EventMap
, Event
, NULL
);
2193 if (EFI_ERROR (Status
)) {
2194 Status
= EFI_OUT_OF_RESOURCES
;
2197 Status
= EFI_ACCESS_DENIED
;
2200 gBS
->RestoreTPL (OldTpl
);
2206 Remove a previously registered event for the specified configuration data.
2208 @param This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2209 @param DataType The type of data to remove from the previously
2211 @param Event The event to be unregistered.
2213 @retval EFI_SUCCESS The event registered for the specified
2214 configuration data was removed.
2215 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2216 @retval EFI_NOT_FOUND The Event has not been registered for the
2222 EfiIp6ConfigUnregisterDataNotify (
2223 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2224 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2230 IP6_CONFIG_INSTANCE
*Instance
;
2233 if ((This
== NULL
) || (Event
== NULL
)) {
2234 return EFI_INVALID_PARAMETER
;
2237 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2238 return EFI_NOT_FOUND
;
2241 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2243 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2245 Item
= NetMapFindKey (&Instance
->DataItem
[DataType
].EventMap
, Event
);
2247 NetMapRemoveItem (&Instance
->DataItem
[DataType
].EventMap
, Item
, NULL
);
2248 Status
= EFI_SUCCESS
;
2250 Status
= EFI_NOT_FOUND
;
2253 gBS
->RestoreTPL (OldTpl
);
2259 Initialize an IP6_CONFIG_INSTANCE.
2261 @param[out] Instance The buffer of IP6_CONFIG_INSTANCE to be initialized.
2263 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
2264 @retval EFI_SUCCESS The IP6_CONFIG_INSTANCE initialized successfully.
2268 Ip6ConfigInitInstance (
2269 OUT IP6_CONFIG_INSTANCE
*Instance
2273 IP6_CONFIG_INSTANCE
*TmpInstance
;
2278 IP6_CONFIG_DATA_ITEM
*DataItem
;
2280 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2282 Instance
->Signature
= IP6_CONFIG_INSTANCE_SIGNATURE
;
2285 // Determine the index of this interface.
2288 NET_LIST_FOR_EACH (Entry
, &mIp6ConfigInstanceList
) {
2289 TmpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_CONFIG_INSTANCE
, Link
, IP6_CONFIG_INSTANCE_SIGNATURE
);
2291 if (TmpInstance
->IfIndex
> IfIndex
) {
2293 // There is a sequence hole because some interface is down.
2301 Instance
->IfIndex
= IfIndex
;
2302 NetListInsertBefore (Entry
, &Instance
->Link
);
2304 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2306 // Initialize the event map for each data item.
2308 NetMapInit (&Instance
->DataItem
[Index
].EventMap
);
2312 // Initialize the NET_MAPs used for DAD on manually configured source addresses.
2314 NetMapInit (&Instance
->DadFailedMap
);
2315 NetMapInit (&Instance
->DadPassedMap
);
2318 // Initialize each data type: associate storage and set data size for the
2319 // fixed size data types, hook the SetData function, set the data attribute.
2321 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
2322 DataItem
->GetData
= Ip6ConfigGetIfInfo
;
2323 DataItem
->Data
.Ptr
= &Instance
->InterfaceInfo
;
2324 DataItem
->DataSize
= sizeof (Instance
->InterfaceInfo
);
2325 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
| DATA_ATTRIB_VOLATILE
);
2326 Ip6ConfigInitIfInfo (IpSb
, &Instance
->InterfaceInfo
);
2328 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
2329 DataItem
->SetData
= Ip6ConfigSetAltIfId
;
2330 DataItem
->Data
.Ptr
= &Instance
->AltIfId
;
2331 DataItem
->DataSize
= sizeof (Instance
->AltIfId
);
2332 DataItem
->Status
= EFI_NOT_FOUND
;
2333 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2335 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypePolicy
];
2336 DataItem
->SetData
= Ip6ConfigSetPolicy
;
2337 DataItem
->Data
.Ptr
= &Instance
->Policy
;
2338 DataItem
->DataSize
= sizeof (Instance
->Policy
);
2339 Instance
->Policy
= Ip6ConfigPolicyManual
;
2340 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2342 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
];
2343 DataItem
->SetData
= Ip6ConfigSetDadXmits
;
2344 DataItem
->Data
.Ptr
= &Instance
->DadXmits
;
2345 DataItem
->DataSize
= sizeof (Instance
->DadXmits
);
2346 Instance
->DadXmits
.DupAddrDetectTransmits
= IP6_CONFIG_DEFAULT_DAD_XMITS
;
2347 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2349 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
2350 DataItem
->SetData
= Ip6ConfigSetManualAddress
;
2351 DataItem
->Status
= EFI_NOT_FOUND
;
2353 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
2354 DataItem
->SetData
= Ip6ConfigSetGateway
;
2355 DataItem
->Status
= EFI_NOT_FOUND
;
2357 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
2358 DataItem
->SetData
= Ip6ConfigSetDnsServer
;
2359 DataItem
->Status
= EFI_NOT_FOUND
;
2362 // Create the event used for DHCP.
2364 Status
= gBS
->CreateEvent (
2367 Ip6ConfigOnDhcp6Event
,
2369 &Instance
->Dhcp6Event
2371 ASSERT_EFI_ERROR (Status
);
2373 Instance
->Configured
= TRUE
;
2376 // Try to read the config data from NV variable.
2378 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, Instance
);
2379 if (Status
== EFI_NOT_FOUND
) {
2381 // The NV variable is not set, so generate a random IAID, and write down the
2382 // fresh new configuration as the NV variable now.
2384 Instance
->IaId
= NET_RANDOM (NetRandomInitSeed ());
2386 for (Index
= 0; Index
< IpSb
->SnpMode
.HwAddressSize
; Index
++) {
2387 Instance
->IaId
|= (IpSb
->SnpMode
.CurrentAddress
.Addr
[Index
] << ((Index
<< 3) & 31));
2390 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2391 } else if (EFI_ERROR (Status
)) {
2395 Instance
->Ip6Config
.SetData
= EfiIp6ConfigSetData
;
2396 Instance
->Ip6Config
.GetData
= EfiIp6ConfigGetData
;
2397 Instance
->Ip6Config
.RegisterDataNotify
= EfiIp6ConfigRegisterDataNotify
;
2398 Instance
->Ip6Config
.UnregisterDataNotify
= EfiIp6ConfigUnregisterDataNotify
;
2401 // Publish the IP6 configuration form
2403 return Ip6ConfigFormInit (Instance
);
2407 Release an IP6_CONFIG_INSTANCE.
2409 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2413 Ip6ConfigCleanInstance (
2414 IN OUT IP6_CONFIG_INSTANCE
*Instance
2418 IP6_CONFIG_DATA_ITEM
*DataItem
;
2420 if (Instance
->DeclineAddress
!= NULL
) {
2421 FreePool (Instance
->DeclineAddress
);
2424 if (!Instance
->Configured
) {
2428 if (Instance
->Dhcp6Handle
!= NULL
) {
2429 Ip6ConfigDestroyDhcp6 (Instance
);
2435 if (Instance
->Dhcp6Event
!= NULL
) {
2436 gBS
->CloseEvent (Instance
->Dhcp6Event
);
2439 NetMapClean (&Instance
->DadPassedMap
);
2440 NetMapClean (&Instance
->DadFailedMap
);
2442 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2443 DataItem
= &Instance
->DataItem
[Index
];
2445 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
2446 if (DataItem
->Data
.Ptr
!= NULL
) {
2447 FreePool (DataItem
->Data
.Ptr
);
2450 DataItem
->Data
.Ptr
= NULL
;
2451 DataItem
->DataSize
= 0;
2454 NetMapClean (&Instance
->DataItem
[Index
].EventMap
);
2457 Ip6ConfigFormUnload (Instance
);
2459 RemoveEntryList (&Instance
->Link
);
2463 Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
2465 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2467 @retval EFI_SUCCESS The child was successfully destroyed.
2468 @retval Others Failed to destroy the child.
2472 Ip6ConfigDestroyDhcp6 (
2473 IN OUT IP6_CONFIG_INSTANCE
*Instance
2478 EFI_DHCP6_PROTOCOL
*Dhcp6
;
2480 Dhcp6
= Instance
->Dhcp6
;
2481 ASSERT (Dhcp6
!= NULL
);
2483 Dhcp6
->Stop (Dhcp6
);
2484 Dhcp6
->Configure (Dhcp6
, NULL
);
2485 Instance
->Dhcp6
= NULL
;
2487 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2490 // Close DHCPv6 protocol and destroy the child.
2492 Status
= gBS
->CloseProtocol (
2493 Instance
->Dhcp6Handle
,
2494 &gEfiDhcp6ProtocolGuid
,
2498 if (EFI_ERROR (Status
)) {
2502 Status
= NetLibDestroyServiceChild (
2505 &gEfiDhcp6ServiceBindingProtocolGuid
,
2506 Instance
->Dhcp6Handle
2509 Instance
->Dhcp6Handle
= NULL
;