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
;
56 IP6_ADDRESS_INFO
*AddrInfo
;
57 IP6_PROTOCOL
*Instance
;
63 // Currently there are only two policies: Manual and Automatic. Regardless of
64 // what transition is going on, i.e., Manual -> Automatic and Automatic ->
65 // Manual, we have to free default router list, on-link prefix list, autonomous
66 // prefix list, address list in all the interfaces and destroy any IPv6 child
67 // instance whose local IP is neither 0 nor the link-local address.
69 Ip6CleanDefaultRouterList (IpSb
);
70 Ip6CleanPrefixListTable (IpSb
, &IpSb
->OnlinkPrefix
);
71 Ip6CleanPrefixListTable (IpSb
, &IpSb
->AutonomousPrefix
);
74 // It's tricky... If the LinkLocal address is O.K., add back the link-local
75 // prefix to the on-link prefix table.
77 if (IpSb
->LinkLocalOk
) {
78 Ip6CreatePrefixListEntry (
81 (UINT32
) IP6_INFINIT_LIFETIME
,
82 (UINT32
) IP6_INFINIT_LIFETIME
,
83 IP6_LINK_LOCAL_PREFIX_LENGTH
,
88 if (!IsListEmpty (&IpSb
->DefaultInterface
->AddressList
) && IpSb
->DefaultInterface
->AddressCount
> 0) {
90 // If any IPv6 children (Instance) in configured state and use global unicast address, it will be
91 // destroyed in Ip6RemoveAddr() function later. Then, the upper layer driver's Stop() function will be
92 // called, which may break the upper layer network stacks. So, the driver should take the responsibility
93 // for the recovery by using ConnectController() after Ip6RemoveAddr().
94 // Here, just check whether need to recover the upper layer network stacks later.
96 NET_LIST_FOR_EACH (Entry
, &IpSb
->DefaultInterface
->AddressList
) {
97 AddrInfo
= NET_LIST_USER_STRUCT_S (Entry
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
98 if (!IsListEmpty (&IpSb
->Children
)) {
99 NET_LIST_FOR_EACH (Entry2
, &IpSb
->Children
) {
100 Instance
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_PROTOCOL
, Link
, IP6_PROTOCOL_SIGNATURE
);
101 if ((Instance
->State
== IP6_STATE_CONFIGED
) && EFI_IP6_EQUAL (&Instance
->ConfigData
.StationAddress
, &AddrInfo
->Address
)) {
110 // All IPv6 children that use global unicast address as it's source address
111 // should be destroyed now. The survivers are those use the link-local address
112 // or the unspecified address as the source address.
113 // TODO: Conduct a check here.
116 &IpSb
->DefaultInterface
->AddressList
,
117 &IpSb
->DefaultInterface
->AddressCount
,
122 if (IpSb
->Controller
!= NULL
&& Recovery
) {
124 // ConnectController() to recover the upper layer network stacks.
126 gBS
->ConnectController (IpSb
->Controller
, NULL
, NULL
, TRUE
);
131 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
133 // remove all pending delay node and DAD entries for the global addresses.
135 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
137 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DelayJoinList
) {
138 DelayNode
= NET_LIST_USER_STRUCT (Entry2
, IP6_DELAY_JOIN_LIST
, Link
);
139 if (!NetIp6IsLinkLocalAddr (&DelayNode
->AddressInfo
->Address
)) {
140 RemoveEntryList (&DelayNode
->Link
);
141 FreePool (DelayNode
);
145 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DupAddrDetectList
) {
146 DadEntry
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_DAD_ENTRY
, Link
, IP6_DAD_ENTRY_SIGNATURE
);
148 if (!NetIp6IsLinkLocalAddr (&DadEntry
->AddressInfo
->Address
)) {
150 // Fail this DAD entry if the address is not link-local.
152 Ip6OnDADFinished (FALSE
, IpIf
, DadEntry
);
157 if (NewPolicy
== Ip6ConfigPolicyAutomatic
) {
159 // Set parameters to trigger router solicitation sending in timer handler.
161 IpSb
->RouterAdvertiseReceived
= FALSE
;
162 IpSb
->SolicitTimer
= IP6_MAX_RTR_SOLICITATIONS
;
166 IpSb
->Ticks
= (UINT32
) IP6_GET_TICKS (IP6_ONE_SECOND_IN_MS
);
171 The work function to trigger the DHCPv6 process to perform a stateful autoconfiguration.
173 @param[in] Instance Pointer to the IP6 config instance data.
174 @param[in] OtherInfoOnly If FALSE, get stateful address and other information
175 via DHCPv6. Otherwise, only get the other information.
177 @retval EFI_SUCCESS The operation finished successfully.
178 @retval EFI_UNSUPPORTED The DHCP6 driver is not available.
182 Ip6ConfigStartStatefulAutoConfig (
183 IN IP6_CONFIG_INSTANCE
*Instance
,
184 IN BOOLEAN OtherInfoOnly
189 EFI_DHCP6_CONFIG_DATA Dhcp6CfgData
;
190 EFI_DHCP6_PROTOCOL
*Dhcp6
;
191 EFI_DHCP6_PACKET_OPTION
*OptList
[1];
193 EFI_DHCP6_PACKET_OPTION
*Oro
;
194 EFI_DHCP6_RETRANSMISSION InfoReqReXmit
;
197 // A host must not invoke stateful address configuration if it is already
198 // participating in the statuful protocol as a result of an earlier advertisement.
200 if (Instance
->Dhcp6Handle
!= NULL
) {
204 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
206 Instance
->OtherInfoOnly
= OtherInfoOnly
;
208 Status
= NetLibCreateServiceChild (
211 &gEfiDhcp6ServiceBindingProtocolGuid
,
212 &Instance
->Dhcp6Handle
215 if (Status
== EFI_UNSUPPORTED
) {
217 // No DHCPv6 Service Binding protocol, register a notify.
219 if (Instance
->Dhcp6SbNotifyEvent
== NULL
) {
220 Instance
->Dhcp6SbNotifyEvent
= EfiCreateProtocolNotifyEvent (
221 &gEfiDhcp6ServiceBindingProtocolGuid
,
223 Ip6ConfigOnDhcp6SbInstalled
,
225 &Instance
->Registration
230 if (EFI_ERROR (Status
)) {
234 if (Instance
->Dhcp6SbNotifyEvent
!= NULL
) {
235 gBS
->CloseEvent (Instance
->Dhcp6SbNotifyEvent
);
238 Status
= gBS
->OpenProtocol (
239 Instance
->Dhcp6Handle
,
240 &gEfiDhcp6ProtocolGuid
,
241 (VOID
**) &Instance
->Dhcp6
,
244 EFI_OPEN_PROTOCOL_BY_DRIVER
246 ASSERT_EFI_ERROR (Status
);
248 Dhcp6
= Instance
->Dhcp6
;
249 Dhcp6
->Configure (Dhcp6
, NULL
);
252 // Set the exta options to send. Here we only want the option request option
255 Oro
= (EFI_DHCP6_PACKET_OPTION
*) OptBuf
;
256 Oro
->OpCode
= HTONS (DHCP6_OPT_ORO
);
257 Oro
->OpLen
= HTONS (2);
258 *((UINT16
*) &Oro
->Data
[0]) = HTONS (DHCP6_OPT_DNS_SERVERS
);
261 Status
= EFI_SUCCESS
;
263 if (!OtherInfoOnly
) {
265 // Get stateful address and other information via DHCPv6.
267 Dhcp6CfgData
.Dhcp6Callback
= NULL
;
268 Dhcp6CfgData
.CallbackContext
= NULL
;
269 Dhcp6CfgData
.OptionCount
= 1;
270 Dhcp6CfgData
.OptionList
= &OptList
[0];
271 Dhcp6CfgData
.IaDescriptor
.Type
= EFI_DHCP6_IA_TYPE_NA
;
272 Dhcp6CfgData
.IaDescriptor
.IaId
= Instance
->IaId
;
273 Dhcp6CfgData
.IaInfoEvent
= Instance
->Dhcp6Event
;
274 Dhcp6CfgData
.ReconfigureAccept
= FALSE
;
275 Dhcp6CfgData
.RapidCommit
= FALSE
;
276 Dhcp6CfgData
.SolicitRetransmission
= NULL
;
278 Status
= Dhcp6
->Configure (Dhcp6
, &Dhcp6CfgData
);
280 if (!EFI_ERROR (Status
)) {
282 if (IpSb
->LinkLocalOk
) {
283 Status
= Dhcp6
->Start (Dhcp6
);
285 IpSb
->Dhcp6NeedStart
= TRUE
;
291 // Only get other information via DHCPv6, this doesn't require a config
294 InfoReqReXmit
.Irt
= 4;
295 InfoReqReXmit
.Mrc
= 64;
296 InfoReqReXmit
.Mrt
= 60;
297 InfoReqReXmit
.Mrd
= 0;
299 if (IpSb
->LinkLocalOk
) {
300 Status
= Dhcp6
->InfoRequest (
307 Instance
->Dhcp6Event
,
308 Ip6ConfigOnDhcp6Reply
,
312 IpSb
->Dhcp6NeedInfoRequest
= TRUE
;
321 Signal the registered event. It is the callback routine for NetMapIterate.
323 @param[in] Map Points to the list of registered event.
324 @param[in] Item The registered event.
325 @param[in] Arg Not used.
330 Ip6ConfigSignalEvent (
332 IN NET_MAP_ITEM
*Item
,
336 gBS
->SignalEvent ((EFI_EVENT
) Item
->Key
);
342 Read the configuration data from variable storage according to the VarName and
343 gEfiIp6ConfigProtocolGuid. It checks the integrity of variable data. If the
344 data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the
345 configuration data to IP6_CONFIG_INSTANCE.
347 @param[in] VarName The pointer to the variable name
348 @param[in, out] Instance The pointer to the IP6 config instance data.
350 @retval EFI_NOT_FOUND The variable can not be found or already corrupted.
351 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
352 @retval EFI_SUCCESS The configuration data was retrieved successfully.
356 Ip6ConfigReadConfigData (
358 IN OUT IP6_CONFIG_INSTANCE
*Instance
363 IP6_CONFIG_VARIABLE
*Variable
;
364 IP6_CONFIG_DATA_ITEM
*DataItem
;
366 IP6_CONFIG_DATA_RECORD DataRecord
;
370 // Try to read the configuration variable.
373 Status
= gRT
->GetVariable (
375 &gEfiIp6ConfigProtocolGuid
,
381 if (Status
== EFI_BUFFER_TOO_SMALL
) {
383 // Allocate buffer and read the config variable.
385 Variable
= AllocatePool (VarSize
);
386 if (Variable
== NULL
) {
387 return EFI_OUT_OF_RESOURCES
;
390 Status
= gRT
->GetVariable (
392 &gEfiIp6ConfigProtocolGuid
,
397 if (EFI_ERROR (Status
) || (UINT16
) (~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
)) != 0) {
399 // GetVariable still error or the variable is corrupted.
400 // Fall back to the default value.
405 // Remove the problematic variable and return EFI_NOT_FOUND, a new
406 // variable will be set again.
410 &gEfiIp6ConfigProtocolGuid
,
411 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
416 return EFI_NOT_FOUND
;
420 // Get the IAID we use.
422 Instance
->IaId
= Variable
->IaId
;
424 for (Index
= 0; Index
< Variable
->DataRecordCount
; Index
++) {
426 CopyMem (&DataRecord
, &Variable
->DataRecord
[Index
], sizeof (DataRecord
));
428 DataItem
= &Instance
->DataItem
[DataRecord
.DataType
];
429 if (DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
) &&
430 (DataItem
->DataSize
!= DataRecord
.DataSize
)
433 // Perhaps a corrupted data record...
438 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
440 // This data item has variable length data.
442 DataItem
->Data
.Ptr
= AllocatePool (DataRecord
.DataSize
);
443 if (DataItem
->Data
.Ptr
== NULL
) {
445 // no memory resource
451 Data
= (CHAR8
*) Variable
+ DataRecord
.Offset
;
452 CopyMem (DataItem
->Data
.Ptr
, Data
, DataRecord
.DataSize
);
454 DataItem
->DataSize
= DataRecord
.DataSize
;
455 DataItem
->Status
= EFI_SUCCESS
;
466 Write the configuration data from IP6_CONFIG_INSTANCE to variable storage.
468 @param[in] VarName The pointer to the variable name.
469 @param[in] Instance The pointer to the IP6 configuration instance data.
471 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
472 @retval EFI_SUCCESS The configuration data is written successfully.
476 Ip6ConfigWriteConfigData (
478 IN IP6_CONFIG_INSTANCE
*Instance
483 IP6_CONFIG_DATA_ITEM
*DataItem
;
484 IP6_CONFIG_VARIABLE
*Variable
;
485 IP6_CONFIG_DATA_RECORD
*DataRecord
;
489 VarSize
= sizeof (IP6_CONFIG_VARIABLE
) - sizeof (IP6_CONFIG_DATA_RECORD
);
491 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
493 DataItem
= &Instance
->DataItem
[Index
];
494 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_VOLATILE
) && !EFI_ERROR (DataItem
->Status
)) {
496 VarSize
+= sizeof (IP6_CONFIG_DATA_RECORD
) + DataItem
->DataSize
;
500 Variable
= AllocatePool (VarSize
);
501 if (Variable
== NULL
) {
502 return EFI_OUT_OF_RESOURCES
;
505 Variable
->IaId
= Instance
->IaId
;
506 Heap
= (CHAR8
*) Variable
+ VarSize
;
507 Variable
->DataRecordCount
= 0;
509 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
)) {
514 Heap
-= DataItem
->DataSize
;
515 CopyMem (Heap
, DataItem
->Data
.Ptr
, DataItem
->DataSize
);
517 DataRecord
= &Variable
->DataRecord
[Variable
->DataRecordCount
];
518 DataRecord
->DataType
= (EFI_IP6_CONFIG_DATA_TYPE
) Index
;
519 DataRecord
->DataSize
= (UINT32
) DataItem
->DataSize
;
520 DataRecord
->Offset
= (UINT16
) (Heap
- (CHAR8
*) Variable
);
522 Variable
->DataRecordCount
++;
526 Variable
->Checksum
= 0;
527 Variable
->Checksum
= (UINT16
) ~NetblockChecksum ((UINT8
*) Variable
, (UINT32
) VarSize
);
529 Status
= gRT
->SetVariable (
531 &gEfiIp6ConfigProtocolGuid
,
532 IP6_CONFIG_VARIABLE_ATTRIBUTE
,
543 The work function for EfiIp6ConfigGetData() to get the interface information
544 of the communication device this IP6Config instance manages.
546 @param[in] Instance Pointer to the IP6 config instance data.
547 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in
548 bytes, the size of buffer required to store the specified
550 @param[in] Data The data buffer in which the configuration data is returned.
551 Ignored if DataSize is ZERO.
553 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified
554 configuration data, and the required size is
555 returned in DataSize.
556 @retval EFI_SUCCESS The specified configuration data was obtained.
561 IN IP6_CONFIG_INSTANCE
*Instance
,
562 IN OUT UINTN
*DataSize
,
563 IN VOID
*Data OPTIONAL
568 IP6_CONFIG_DATA_ITEM
*Item
;
569 EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
;
573 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
574 Length
= sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
);
577 // Calculate the required length, add the buffer size for AddressInfo and
580 Ip6BuildEfiAddressList (IpSb
, &AddressCount
, NULL
);
581 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &RouteCount
, NULL
);
583 Length
+= AddressCount
* sizeof (EFI_IP6_ADDRESS_INFO
) + RouteCount
* sizeof (EFI_IP6_ROUTE_TABLE
);
585 if (*DataSize
< Length
) {
587 return EFI_BUFFER_TOO_SMALL
;
591 // Copy the fixed size part of the interface info.
593 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
594 IfInfo
= (EFI_IP6_CONFIG_INTERFACE_INFO
*) Data
;
595 CopyMem (IfInfo
, Item
->Data
.Ptr
, sizeof (EFI_IP6_CONFIG_INTERFACE_INFO
));
600 IfInfo
->AddressInfo
= (EFI_IP6_ADDRESS_INFO
*) (IfInfo
+ 1);
601 Ip6BuildEfiAddressList (IpSb
, &IfInfo
->AddressInfoCount
, &IfInfo
->AddressInfo
);
606 IfInfo
->RouteTable
= (EFI_IP6_ROUTE_TABLE
*) (IfInfo
->AddressInfo
+ IfInfo
->AddressInfoCount
);
607 Ip6BuildEfiRouteTable (IpSb
->RouteTable
, &IfInfo
->RouteCount
, &IfInfo
->RouteTable
);
609 if (IfInfo
->AddressInfoCount
== 0) {
610 IfInfo
->AddressInfo
= NULL
;
613 if (IfInfo
->RouteCount
== 0) {
614 IfInfo
->RouteTable
= NULL
;
621 The work function for EfiIp6ConfigSetData() to set the alternative inteface ID
622 for the communication device managed by this IP6Config instance, if the link local
623 IPv6 addresses generated from the interface ID based on the default source the
624 EFI IPv6 Protocol uses is a duplicate address.
626 @param[in] Instance Pointer to the IP6 configuration instance data.
627 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
628 @param[in] Data The data buffer to set.
630 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type,
632 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
633 network stack was set.
637 Ip6ConfigSetAltIfId (
638 IN IP6_CONFIG_INSTANCE
*Instance
,
643 EFI_IP6_CONFIG_INTERFACE_ID
*OldIfId
;
644 EFI_IP6_CONFIG_INTERFACE_ID
*NewIfId
;
645 IP6_CONFIG_DATA_ITEM
*DataItem
;
647 if (DataSize
!= sizeof (EFI_IP6_CONFIG_INTERFACE_ID
)) {
648 return EFI_BAD_BUFFER_SIZE
;
651 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
652 OldIfId
= DataItem
->Data
.AltIfId
;
653 NewIfId
= (EFI_IP6_CONFIG_INTERFACE_ID
*) Data
;
655 CopyMem (OldIfId
, NewIfId
, DataSize
);
656 DataItem
->Status
= EFI_SUCCESS
;
662 The work function for EfiIp6ConfigSetData() to set the general configuration
663 policy for the EFI IPv6 network stack that is running on the communication device
664 managed by this IP6Config instance. The policy will affect other configuration settings.
666 @param[in] Instance Pointer to the IP6 config instance data.
667 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
668 @param[in] Data The data buffer to set.
670 @retval EFI_INVALID_PARAMETER The to be set policy is invalid.
671 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
672 @retval EFI_ABORTED The new policy equals the current policy.
673 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
674 network stack was set.
679 IN IP6_CONFIG_INSTANCE
*Instance
,
684 EFI_IP6_CONFIG_POLICY NewPolicy
;
685 IP6_CONFIG_DATA_ITEM
*DataItem
;
688 if (DataSize
!= sizeof (EFI_IP6_CONFIG_POLICY
)) {
689 return EFI_BAD_BUFFER_SIZE
;
692 NewPolicy
= *((EFI_IP6_CONFIG_POLICY
*) Data
);
694 if (NewPolicy
> Ip6ConfigPolicyAutomatic
) {
695 return EFI_INVALID_PARAMETER
;
698 if (NewPolicy
== Instance
->Policy
) {
703 // Clean the ManualAddress, Gateway and DnsServers, shrink the variable
704 // data size, and fire up all the related events.
706 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
707 if (DataItem
->Data
.Ptr
!= NULL
) {
708 FreePool (DataItem
->Data
.Ptr
);
710 DataItem
->Data
.Ptr
= NULL
;
711 DataItem
->DataSize
= 0;
712 DataItem
->Status
= EFI_NOT_FOUND
;
713 NetMapIterate (&DataItem
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
715 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
716 if (DataItem
->Data
.Ptr
!= NULL
) {
717 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
) {
785 OldDadXmits
->DupAddrDetectTransmits
= *((UINT32
*) Data
);
791 The callback function for Ip6SetAddr. The prototype is defined
792 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
793 for the manual address set by Ip6ConfigSetManualAddress.
795 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passed.
796 @param[in] TargetAddress The tentative IPv6 address to be checked.
797 @param[in] Context Pointer to the IP6 configuration instance data.
801 Ip6ManualAddrDadCallback (
802 IN BOOLEAN IsDadPassed
,
803 IN EFI_IPv6_ADDRESS
*TargetAddress
,
807 IP6_CONFIG_INSTANCE
*Instance
;
809 IP6_CONFIG_DATA_ITEM
*Item
;
810 EFI_IP6_CONFIG_MANUAL_ADDRESS
*ManualAddr
;
811 EFI_IP6_CONFIG_MANUAL_ADDRESS
*PassedAddr
;
816 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
817 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
818 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
821 if (Item
->DataSize
== 0) {
825 for (Index
= 0; Index
< Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
); Index
++) {
827 // Find the original tag used to place into the NET_MAP.
829 ManualAddr
= Item
->Data
.ManualAddress
+ Index
;
830 if (EFI_IP6_EQUAL (TargetAddress
, &ManualAddr
->Address
)) {
835 ASSERT (Index
!= Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
838 NetMapInsertTail (&Instance
->DadPassedMap
, ManualAddr
, NULL
);
840 NetMapInsertTail (&Instance
->DadFailedMap
, ManualAddr
, NULL
);
843 DadPassCount
= NetMapGetCount (&Instance
->DadPassedMap
);
844 DadFailCount
= NetMapGetCount (&Instance
->DadFailedMap
);
846 if ((DadPassCount
+ DadFailCount
) == (Item
->DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
))) {
848 // All addresses have finished the configuration process.
850 if (DadFailCount
!= 0) {
852 // There is at least one duplicate address.
854 FreePool (Item
->Data
.Ptr
);
856 Item
->DataSize
= DadPassCount
* sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
857 if (Item
->DataSize
== 0) {
859 // All failed, bad luck.
861 Item
->Data
.Ptr
= NULL
;
862 Item
->Status
= EFI_NOT_FOUND
;
865 // Part of addresses are detected to be duplicates, so update the
866 // data with those passed.
868 PassedAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) AllocatePool (Item
->DataSize
);
869 ASSERT (PassedAddr
!= NULL
);
871 Item
->Data
.Ptr
= PassedAddr
;
872 Item
->Status
= EFI_SUCCESS
;
874 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
875 ManualAddr
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
876 CopyMem (PassedAddr
, ManualAddr
, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
));
881 ASSERT ((UINTN
) PassedAddr
- (UINTN
) Item
->Data
.Ptr
== Item
->DataSize
);
885 // All addresses are valid.
887 Item
->Status
= EFI_SUCCESS
;
891 // Remove the tags we put in the NET_MAPs.
893 while (!NetMapIsEmpty (&Instance
->DadFailedMap
)) {
894 NetMapRemoveHead (&Instance
->DadFailedMap
, NULL
);
897 while (!NetMapIsEmpty (&Instance
->DadPassedMap
)) {
898 NetMapRemoveHead (&Instance
->DadPassedMap
, NULL
);
902 // Signal the waiting events.
904 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
905 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
906 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
911 The work function for EfiIp6ConfigSetData() to set the station addresses manually
912 for the EFI IPv6 network stack. It is only configurable when the policy is
913 Ip6ConfigPolicyManual.
915 @param[in] Instance Pointer to the IP6 configuration instance data.
916 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
917 @param[in] Data The data buffer to set.
919 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
920 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
921 under the current policy.
922 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
923 @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.
924 @retval EFI_NOT_READY An asynchrous process is invoked to set the specified
925 configuration data, and the process is not finished.
926 @retval EFI_ABORTED The manual addresses to be set equal current
928 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
929 network stack was set.
933 Ip6ConfigSetManualAddress (
934 IN IP6_CONFIG_INSTANCE
*Instance
,
939 EFI_IP6_CONFIG_MANUAL_ADDRESS
*NewAddress
;
940 EFI_IP6_CONFIG_MANUAL_ADDRESS
*TmpAddress
;
941 IP6_CONFIG_DATA_ITEM
*DataItem
;
942 UINTN NewAddressCount
;
946 IP6_ADDRESS_INFO
*CurrentAddrInfo
;
947 IP6_ADDRESS_INFO
*Copy
;
948 LIST_ENTRY CurrentSourceList
;
949 UINT32 CurrentSourceCount
;
953 IP6_PREFIX_LIST_ENTRY
*PrefixEntry
;
957 ASSERT (Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
].Status
!= EFI_NOT_READY
);
959 if (((DataSize
% sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
)) != 0) || (DataSize
== 0)) {
960 return EFI_BAD_BUFFER_SIZE
;
963 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
964 return EFI_WRITE_PROTECTED
;
967 NewAddressCount
= DataSize
/ sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS
);
968 NewAddress
= (EFI_IP6_CONFIG_MANUAL_ADDRESS
*) Data
;
970 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
972 if (NetIp6IsLinkLocalAddr (&NewAddress
->Address
) ||
973 !NetIp6IsValidUnicast (&NewAddress
->Address
) ||
974 (NewAddress
->PrefixLength
> 128)
977 // make sure the IPv6 address is unicast and not link-local address &&
978 // the prefix length is valid.
980 return EFI_INVALID_PARAMETER
;
983 TmpAddress
= NewAddress
+ 1;
984 for (Index2
= Index1
+ 1; Index2
< NewAddressCount
; Index2
++, TmpAddress
++) {
986 // Any two addresses in the array can't be equal.
988 if (EFI_IP6_EQUAL (&TmpAddress
->Address
, &NewAddress
->Address
)) {
990 return EFI_INVALID_PARAMETER
;
995 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
998 // Build the current source address list.
1000 InitializeListHead (&CurrentSourceList
);
1001 CurrentSourceCount
= 0;
1003 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1004 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
1006 NET_LIST_FOR_EACH (Entry2
, &IpIf
->AddressList
) {
1007 CurrentAddrInfo
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_ADDRESS_INFO
, Link
, IP6_ADDR_INFO_SIGNATURE
);
1009 Copy
= AllocateCopyPool (sizeof (IP6_ADDRESS_INFO
), CurrentAddrInfo
);
1014 InsertTailList (&CurrentSourceList
, &Copy
->Link
);
1015 CurrentSourceCount
++;
1020 // Update the value... a long journey starts
1022 NewAddress
= AllocateCopyPool (DataSize
, Data
);
1023 if (NewAddress
== NULL
) {
1024 Ip6RemoveAddr (NULL
, &CurrentSourceList
, &CurrentSourceCount
, NULL
, 0);
1026 return EFI_OUT_OF_RESOURCES
;
1030 // Store the new data, and init the DataItem status to EFI_NOT_READY because
1031 // we may have an asynchronous configuration process.
1033 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
1034 if (DataItem
->Data
.Ptr
!= NULL
) {
1035 FreePool (DataItem
->Data
.Ptr
);
1037 DataItem
->Data
.Ptr
= NewAddress
;
1038 DataItem
->DataSize
= DataSize
;
1039 DataItem
->Status
= EFI_NOT_READY
;
1042 // Trigger DAD, it's an asynchronous process.
1046 for (Index1
= 0; Index1
< NewAddressCount
; Index1
++, NewAddress
++) {
1047 if (Ip6IsOneOfSetAddress (IpSb
, &NewAddress
->Address
, NULL
, &CurrentAddrInfo
)) {
1048 ASSERT (CurrentAddrInfo
!= NULL
);
1050 // Remove this already existing source address from the CurrentSourceList
1056 &CurrentSourceCount
,
1057 &CurrentAddrInfo
->Address
,
1062 // If the new address's prefix length is not specified, just use the previous configured
1063 // prefix length for this address.
1065 if (NewAddress
->PrefixLength
== 0) {
1066 NewAddress
->PrefixLength
= CurrentAddrInfo
->PrefixLength
;
1070 // This manual address is already in use, see whether prefix length is changed.
1072 if (NewAddress
->PrefixLength
!= CurrentAddrInfo
->PrefixLength
) {
1074 // Remove the on-link prefix table, the route entry will be removed
1077 PrefixEntry
= Ip6FindPrefixListEntry (
1080 CurrentAddrInfo
->PrefixLength
,
1081 &CurrentAddrInfo
->Address
1083 if (PrefixEntry
!= NULL
) {
1084 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1088 // Save the prefix length.
1090 CurrentAddrInfo
->PrefixLength
= NewAddress
->PrefixLength
;
1095 // create a new on-link prefix entry.
1097 PrefixEntry
= Ip6FindPrefixListEntry (
1100 NewAddress
->PrefixLength
,
1101 &NewAddress
->Address
1103 if (PrefixEntry
== NULL
) {
1104 Ip6CreatePrefixListEntry (
1107 (UINT32
) IP6_INFINIT_LIFETIME
,
1108 (UINT32
) IP6_INFINIT_LIFETIME
,
1109 NewAddress
->PrefixLength
,
1110 &NewAddress
->Address
1114 CurrentAddrInfo
->IsAnycast
= NewAddress
->IsAnycast
;
1116 // Artificially mark this address passed DAD be'coz it is already in use.
1118 Ip6ManualAddrDadCallback (TRUE
, &NewAddress
->Address
, Instance
);
1126 // Set the new address, this will trigger DAD and activate the address if
1130 IpSb
->DefaultInterface
,
1131 &NewAddress
->Address
,
1132 NewAddress
->IsAnycast
,
1133 NewAddress
->PrefixLength
,
1134 (UINT32
) IP6_INFINIT_LIFETIME
,
1135 (UINT32
) IP6_INFINIT_LIFETIME
,
1136 Ip6ManualAddrDadCallback
,
1143 // Check the CurrentSourceList, it now contains those addresses currently in
1144 // use and will be removed.
1146 IpIf
= IpSb
->DefaultInterface
;
1148 while (!IsListEmpty (&CurrentSourceList
)) {
1151 CurrentAddrInfo
= NET_LIST_HEAD (&CurrentSourceList
, IP6_ADDRESS_INFO
, Link
);
1154 // This local address is going to be removed, the IP instances that are
1155 // currently using it will be destroyed.
1160 &IpIf
->AddressCount
,
1161 &CurrentAddrInfo
->Address
,
1166 // Remove the on-link prefix table, the route entry will be removed
1169 PrefixEntry
= Ip6FindPrefixListEntry (
1172 CurrentAddrInfo
->PrefixLength
,
1173 &CurrentAddrInfo
->Address
1175 if (PrefixEntry
!= NULL
) {
1176 Ip6DestroyPrefixListEntry (IpSb
, PrefixEntry
, TRUE
, FALSE
);
1179 RemoveEntryList (&CurrentAddrInfo
->Link
);
1180 FreePool (CurrentAddrInfo
);
1184 if (DataItem
->Status
== EFI_NOT_READY
) {
1186 // If DAD is disabled on this interface, the configuration process is
1187 // actually synchronous, and the data item's status will be changed to
1188 // the final status before we reach here, just check it.
1190 Status
= EFI_NOT_READY
;
1192 Status
= EFI_SUCCESS
;
1196 // No update is taken, reset the status to success and return EFI_ABORTED.
1198 DataItem
->Status
= EFI_SUCCESS
;
1199 Status
= EFI_ABORTED
;
1206 The work function for EfiIp6ConfigSetData() to set the gateway addresses manually
1207 for the EFI IPv6 network stack that is running on the communication device that
1208 this EFI IPv6 Configuration Protocol manages. It is not configurable when the policy is
1209 Ip6ConfigPolicyAutomatic. The gateway addresses must be unicast IPv6 addresses.
1211 @param[in] Instance The pointer to the IP6 config instance data.
1212 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1213 @param[in] Data The data buffer to set. This points to an array of
1214 EFI_IPv6_ADDRESS instances.
1216 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1217 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1218 under the current policy.
1219 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1220 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.
1221 @retval EFI_ABORTED The manual gateway addresses to be set equal the
1222 current configuration.
1223 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1224 network stack was set.
1228 Ip6ConfigSetGateway (
1229 IN IP6_CONFIG_INSTANCE
*Instance
,
1236 EFI_IPv6_ADDRESS
*OldGateway
;
1237 EFI_IPv6_ADDRESS
*NewGateway
;
1238 UINTN OldGatewayCount
;
1239 UINTN NewGatewayCount
;
1240 IP6_CONFIG_DATA_ITEM
*Item
;
1244 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1247 if ((DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0) || (DataSize
== 0)) {
1248 return EFI_BAD_BUFFER_SIZE
;
1251 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1252 return EFI_WRITE_PROTECTED
;
1255 NewGateway
= (EFI_IPv6_ADDRESS
*) Data
;
1256 NewGatewayCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1257 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1259 if (!NetIp6IsValidUnicast (NewGateway
+ Index1
)) {
1261 return EFI_INVALID_PARAMETER
;
1264 for (Index2
= Index1
+ 1; Index2
< NewGatewayCount
; Index2
++) {
1265 if (EFI_IP6_EQUAL (NewGateway
+ Index1
, NewGateway
+ Index2
)) {
1266 return EFI_INVALID_PARAMETER
;
1271 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1272 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
1273 OldGateway
= Item
->Data
.Gateway
;
1274 OldGatewayCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1278 if (NewGatewayCount
!= OldGatewayCount
) {
1279 Tmp
= AllocatePool (DataSize
);
1281 return EFI_OUT_OF_RESOURCES
;
1287 for (Index1
= 0; Index1
< OldGatewayCount
; Index1
++) {
1289 // Find the gateways that are no long in the new setting and remove them.
1291 for (Index2
= 0; Index2
< NewGatewayCount
; Index2
++) {
1292 if (EFI_IP6_EQUAL (OldGateway
+ Index1
, NewGateway
+ Index2
)) {
1298 if (Index2
== NewGatewayCount
) {
1300 // Remove this default router.
1302 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, OldGateway
+ Index1
);
1303 if (DefaultRouter
!= NULL
) {
1304 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
1309 for (Index1
= 0; Index1
< NewGatewayCount
; Index1
++) {
1311 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, NewGateway
+ Index1
);
1312 if (DefaultRouter
== NULL
) {
1313 Ip6CreateDefaultRouter (IpSb
, NewGateway
+ Index1
, IP6_INF_ROUTER_LIFETIME
);
1318 if (!OneRemoved
&& !OneAdded
) {
1319 Item
->Status
= EFI_SUCCESS
;
1324 if (Item
->Data
.Ptr
!= NULL
) {
1325 FreePool (Item
->Data
.Ptr
);
1327 Item
->Data
.Ptr
= Tmp
;
1330 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1331 Item
->DataSize
= DataSize
;
1332 Item
->Status
= EFI_SUCCESS
;
1338 The work function for EfiIp6ConfigSetData() to set the DNS server list for the
1339 EFI IPv6 network stack running on the communication device that this EFI IPv6
1340 Configuration Protocol manages. It is not configurable when the policy is
1341 Ip6ConfigPolicyAutomatic. The DNS server addresses must be unicast IPv6 addresses.
1343 @param[in] Instance The pointer to the IP6 config instance data.
1344 @param[in] DataSize The size of the buffer pointed to by Data in bytes.
1345 @param[in] Data The data buffer to set, points to an array of
1346 EFI_IPv6_ADDRESS instances.
1348 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.
1349 @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set
1350 under the current policy.
1351 @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.
1352 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
1353 @retval EFI_ABORTED The DNS server addresses to be set equal the current
1355 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1356 network stack was set.
1360 Ip6ConfigSetDnsServer (
1361 IN IP6_CONFIG_INSTANCE
*Instance
,
1368 EFI_IPv6_ADDRESS
*OldDns
;
1369 EFI_IPv6_ADDRESS
*NewDns
;
1372 IP6_CONFIG_DATA_ITEM
*Item
;
1376 if ((DataSize
% sizeof (EFI_IPv6_ADDRESS
) != 0) || (DataSize
== 0)) {
1377 return EFI_BAD_BUFFER_SIZE
;
1380 if (Instance
->Policy
!= Ip6ConfigPolicyManual
) {
1381 return EFI_WRITE_PROTECTED
;
1384 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1385 NewDns
= (EFI_IPv6_ADDRESS
*) Data
;
1386 OldDns
= Item
->Data
.DnsServers
;
1387 NewDnsCount
= DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1388 OldDnsCount
= Item
->DataSize
/ sizeof (EFI_IPv6_ADDRESS
);
1391 if (NewDnsCount
!= OldDnsCount
) {
1392 Tmp
= AllocatePool (DataSize
);
1394 return EFI_OUT_OF_RESOURCES
;
1400 for (NewIndex
= 0; NewIndex
< NewDnsCount
; NewIndex
++) {
1402 if (!NetIp6IsValidUnicast (NewDns
+ NewIndex
)) {
1404 // The dns server address must be unicast.
1409 return EFI_INVALID_PARAMETER
;
1414 // If any address in the new setting is not in the old settings, skip the
1415 // comparision below.
1420 for (OldIndex
= 0; OldIndex
< OldDnsCount
; OldIndex
++) {
1421 if (EFI_IP6_EQUAL (NewDns
+ NewIndex
, OldDns
+ OldIndex
)) {
1423 // If found break out.
1429 if (OldIndex
== OldDnsCount
) {
1434 if (!OneAdded
&& (DataSize
== Item
->DataSize
)) {
1436 // No new item is added and the size is the same.
1438 Item
->Status
= EFI_SUCCESS
;
1442 if (Item
->Data
.Ptr
!= NULL
) {
1443 FreePool (Item
->Data
.Ptr
);
1445 Item
->Data
.Ptr
= Tmp
;
1448 CopyMem (Item
->Data
.Ptr
, Data
, DataSize
);
1449 Item
->DataSize
= DataSize
;
1450 Item
->Status
= EFI_SUCCESS
;
1456 Generate the operational state of the interface this IP6 config instance manages
1457 and output in EFI_IP6_CONFIG_INTERFACE_INFO.
1459 @param[in] IpSb The pointer to the IP6 service binding instance.
1460 @param[out] IfInfo The pointer to the IP6 configuration interface information structure.
1464 Ip6ConfigInitIfInfo (
1465 IN IP6_SERVICE
*IpSb
,
1466 OUT EFI_IP6_CONFIG_INTERFACE_INFO
*IfInfo
1471 sizeof (IfInfo
->Name
),
1473 IpSb
->Ip6ConfigInstance
.IfIndex
1476 IfInfo
->IfType
= IpSb
->SnpMode
.IfType
;
1477 IfInfo
->HwAddressSize
= IpSb
->SnpMode
.HwAddressSize
;
1478 CopyMem (&IfInfo
->HwAddress
, &IpSb
->SnpMode
.CurrentAddress
, IfInfo
->HwAddressSize
);
1482 Parse DHCPv6 reply packet to get the DNS server list.
1483 It is the work function for Ip6ConfigOnDhcp6Reply and Ip6ConfigOnDhcp6Event.
1485 @param[in] Dhcp6 The pointer to the EFI_DHCP6_PROTOCOL instance.
1486 @param[in, out] Instance The pointer to the IP6 configuration instance data.
1487 @param[in] Reply The pointer to the DHCPv6 reply packet.
1489 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1490 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1491 the DNS server address is not valid.
1495 Ip6ConfigParseDhcpReply (
1496 IN EFI_DHCP6_PROTOCOL
*Dhcp6
,
1497 IN OUT IP6_CONFIG_INSTANCE
*Instance
,
1498 IN EFI_DHCP6_PACKET
*Reply
1503 EFI_DHCP6_PACKET_OPTION
**OptList
;
1508 EFI_IPv6_ADDRESS
*DnsServer
;
1509 IP6_CONFIG_DATA_ITEM
*Item
;
1512 // A DHCPv6 reply packet is received as the response to our InfoRequest
1516 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, NULL
);
1517 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1518 return EFI_NOT_READY
;
1521 OptList
= AllocatePool (OptCount
* sizeof (EFI_DHCP6_PACKET_OPTION
*));
1522 if (OptList
== NULL
) {
1523 return EFI_NOT_READY
;
1526 Status
= Dhcp6
->Parse (Dhcp6
, Reply
, &OptCount
, OptList
);
1527 if (EFI_ERROR (Status
)) {
1528 Status
= EFI_NOT_READY
;
1532 Status
= EFI_SUCCESS
;
1534 for (Index
= 0; Index
< OptCount
; Index
++) {
1536 // Go through all the options to check the ones we are interested in.
1537 // The OpCode and Length are in network byte-order and may not be naturally
1540 CopyMem (&OpCode
, &OptList
[Index
]->OpCode
, sizeof (OpCode
));
1541 OpCode
= NTOHS (OpCode
);
1543 if (OpCode
== DHCP6_OPT_DNS_SERVERS
) {
1544 CopyMem (&Length
, &OptList
[Index
]->OpLen
, sizeof (Length
));
1545 Length
= NTOHS (Length
);
1547 if ((Length
== 0) || ((Length
% sizeof (EFI_IPv6_ADDRESS
)) != 0)) {
1549 // The length should be a multiple of 16 bytes.
1551 Status
= EFI_NOT_READY
;
1556 // Validate the DnsServers: whether they are unicast addresses.
1558 DnsServer
= (EFI_IPv6_ADDRESS
*) OptList
[Index
]->Data
;
1559 for (Index2
= 0; Index2
< Length
/ sizeof (EFI_IPv6_ADDRESS
); Index2
++) {
1560 if (!NetIp6IsValidUnicast (DnsServer
)) {
1561 Status
= EFI_NOT_READY
;
1568 Item
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
1570 if (Item
->DataSize
!= Length
) {
1571 if (Item
->Data
.Ptr
!= NULL
) {
1572 FreePool (Item
->Data
.Ptr
);
1575 Item
->Data
.Ptr
= AllocatePool (Length
);
1576 ASSERT (Item
->Data
.Ptr
!= NULL
);
1579 CopyMem (Item
->Data
.Ptr
, OptList
[Index
]->Data
, Length
);
1580 Item
->DataSize
= Length
;
1581 Item
->Status
= EFI_SUCCESS
;
1584 // Signal the waiting events.
1586 NetMapIterate (&Item
->EventMap
, Ip6ConfigSignalEvent
, NULL
);
1599 The callback function for Ip6SetAddr. The prototype is defined
1600 as IP6_DAD_CALLBACK. It is called after Duplicate Address Detection is performed
1601 on the tentative address by DHCPv6 in Ip6ConfigOnDhcp6Event().
1603 @param[in] IsDadPassed If TRUE, Duplicate Address Detection passes.
1604 @param[in] TargetAddress The tentative IPv6 address to be checked.
1605 @param[in] Context Pointer to the IP6 configuration instance data.
1609 Ip6ConfigSetStatefulAddrCallback (
1610 IN BOOLEAN IsDadPassed
,
1611 IN EFI_IPv6_ADDRESS
*TargetAddress
,
1615 IP6_CONFIG_INSTANCE
*Instance
;
1617 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1618 NET_CHECK_SIGNATURE (Instance
, IP6_CONFIG_INSTANCE_SIGNATURE
);
1621 // We should record the addresses that fail the DAD, and DECLINE them.
1625 // Decrease the count, no interests in those passed DAD.
1627 if (Instance
->FailedIaAddressCount
> 0 ) {
1628 Instance
->FailedIaAddressCount
--;
1634 IP6_COPY_ADDRESS (Instance
->DeclineAddress
+ Instance
->DeclineAddressCount
, TargetAddress
);
1635 Instance
->DeclineAddressCount
++;
1638 if (Instance
->FailedIaAddressCount
== Instance
->DeclineAddressCount
) {
1640 // The checking on all addresses are finished.
1642 if (Instance
->DeclineAddressCount
!= 0) {
1644 // Decline those duplicates.
1646 if (Instance
->Dhcp6
!= NULL
) {
1647 Instance
->Dhcp6
->Decline (
1649 Instance
->DeclineAddressCount
,
1650 Instance
->DeclineAddress
1655 if (Instance
->DeclineAddress
!= NULL
) {
1656 FreePool (Instance
->DeclineAddress
);
1658 Instance
->DeclineAddress
= NULL
;
1659 Instance
->DeclineAddressCount
= 0;
1664 The event handle routine when DHCPv6 process is finished or is updated.
1666 @param[in] Event Not used.
1667 @param[in] Context The pointer to the IP6 configuration instance data.
1672 Ip6ConfigOnDhcp6Event (
1677 IP6_CONFIG_INSTANCE
*Instance
;
1678 EFI_DHCP6_PROTOCOL
*Dhcp6
;
1680 EFI_DHCP6_MODE_DATA Dhcp6ModeData
;
1682 EFI_DHCP6_IA_ADDRESS
*IaAddr
;
1685 IP6_ADDRESS_INFO
*AddrInfo
;
1686 IP6_INTERFACE
*IpIf
;
1688 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1690 if ((Instance
->Policy
!= Ip6ConfigPolicyAutomatic
) || Instance
->OtherInfoOnly
) {
1692 // IPv6 is not operating in the automatic policy now or
1693 // the DHCPv6 information request message exchange is aborted.
1699 // The stateful address autoconfiguration is done or updated.
1701 Dhcp6
= Instance
->Dhcp6
;
1703 Status
= Dhcp6
->GetModeData (Dhcp6
, &Dhcp6ModeData
, NULL
);
1704 if (EFI_ERROR (Status
)) {
1708 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1709 IpIf
= IpSb
->DefaultInterface
;
1710 Ia
= Dhcp6ModeData
.Ia
;
1711 IaAddr
= Ia
->IaAddress
;
1713 if (Instance
->DeclineAddress
!= NULL
) {
1714 FreePool (Instance
->DeclineAddress
);
1717 Instance
->DeclineAddress
= (EFI_IPv6_ADDRESS
*) AllocatePool (Ia
->IaAddressCount
* sizeof (EFI_IPv6_ADDRESS
));
1718 if (Instance
->DeclineAddress
== NULL
) {
1722 Instance
->FailedIaAddressCount
= Ia
->IaAddressCount
;
1723 Instance
->DeclineAddressCount
= 0;
1725 for (Index
= 0; Index
< Ia
->IaAddressCount
; Index
++, IaAddr
++) {
1726 if (Ia
->IaAddress
[Index
].ValidLifetime
!= 0 && Ia
->State
== Dhcp6Bound
) {
1728 // Set this address, either it's a new address or with updated lifetimes.
1729 // An appropriate prefix length will be set.
1736 IaAddr
->ValidLifetime
,
1737 IaAddr
->PreferredLifetime
,
1738 Ip6ConfigSetStatefulAddrCallback
,
1743 // discard this address, artificially decrease the count as if this address
1746 if (Ip6IsOneOfSetAddress (IpSb
, &IaAddr
->IpAddress
, NULL
, &AddrInfo
)) {
1747 ASSERT (AddrInfo
!= NULL
);
1751 &IpIf
->AddressCount
,
1753 AddrInfo
->PrefixLength
1757 if (Instance
->FailedIaAddressCount
> 0) {
1758 Instance
->FailedIaAddressCount
--;
1764 // Parse the Reply packet to get the options we need.
1766 if (Dhcp6ModeData
.Ia
->ReplyPacket
!= NULL
) {
1767 Ip6ConfigParseDhcpReply (Dhcp6
, Instance
, Dhcp6ModeData
.Ia
->ReplyPacket
);
1772 FreePool (Dhcp6ModeData
.ClientId
);
1773 FreePool (Dhcp6ModeData
.Ia
);
1777 The event process routine when the DHCPv6 server is answered with a reply packet
1778 for an information request.
1780 @param[in] This Points to the EFI_DHCP6_PROTOCOL.
1781 @param[in] Context The pointer to the IP6 configuration instance data.
1782 @param[in] Packet The DHCPv6 reply packet.
1784 @retval EFI_SUCCESS The DNS server address was retrieved from the reply packet.
1785 @retval EFI_NOT_READY The reply packet does not contain the DNS server option, or
1786 the DNS server address is not valid.
1791 Ip6ConfigOnDhcp6Reply (
1792 IN EFI_DHCP6_PROTOCOL
*This
,
1794 IN EFI_DHCP6_PACKET
*Packet
1797 return Ip6ConfigParseDhcpReply (This
, (IP6_CONFIG_INSTANCE
*) Context
, Packet
);
1801 The event process routine when the DHCPv6 service binding protocol is installed
1804 @param[in] Event Not used.
1805 @param[in] Context The pointer to the IP6 config instance data.
1810 Ip6ConfigOnDhcp6SbInstalled (
1815 IP6_CONFIG_INSTANCE
*Instance
;
1817 Instance
= (IP6_CONFIG_INSTANCE
*) Context
;
1819 if ((Instance
->Dhcp6Handle
!= NULL
) || (Instance
->Policy
!= Ip6ConfigPolicyAutomatic
)) {
1821 // The DHCP6 child is already created or the policy is no longer AUTOMATIC.
1826 Ip6ConfigStartStatefulAutoConfig (Instance
, Instance
->OtherInfoOnly
);
1830 Set the configuration for the EFI IPv6 network stack running on the communication
1831 device this EFI IPv6 Configuration Protocol instance manages.
1833 This function is used to set the configuration data of type DataType for the EFI
1834 IPv6 network stack that is running on the communication device that this EFI IPv6
1835 Configuration Protocol instance manages.
1837 DataSize is used to calculate the count of structure instances in the Data for
1838 a DataType in which multiple structure instances are allowed.
1840 This function is always non-blocking. When setting some type of configuration data,
1841 an asynchronous process is invoked to check the correctness of the data, such as
1842 performing Duplicate Address Detection on the manually set local IPv6 addresses.
1843 EFI_NOT_READY is returned immediately to indicate that such an asynchronous process
1844 is invoked, and the process is not finished yet. The caller wanting to get the result
1845 of the asynchronous process is required to call RegisterDataNotify() to register an
1846 event on the specified configuration data. Once the event is signaled, the caller
1847 can call GetData() to obtain the configuration data and know the result.
1848 For other types of configuration data that do not require an asynchronous configuration
1849 process, the result of the operation is immediately returned.
1851 @param[in] This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1852 @param[in] DataType The type of data to set.
1853 @param[in] DataSize Size of the buffer pointed to by Data in bytes.
1854 @param[in] Data The data buffer to set. The type of the data buffer is
1855 associated with the DataType.
1857 @retval EFI_SUCCESS The specified configuration data for the EFI IPv6
1858 network stack was set successfully.
1859 @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:
1862 - One or more fields in Data do not match the requirement of the
1863 data type indicated by DataType.
1864 @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified
1865 configuration data cannot be set under the current policy.
1866 @retval EFI_ACCESS_DENIED Another set operation on the specified configuration
1867 data is already in process.
1868 @retval EFI_NOT_READY An asynchronous process was invoked to set the specified
1869 configuration data, and the process is not finished yet.
1870 @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type
1871 indicated by DataType.
1872 @retval EFI_UNSUPPORTED This DataType is not supported.
1873 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
1874 @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.
1879 EfiIp6ConfigSetData (
1880 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1881 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1888 IP6_CONFIG_INSTANCE
*Instance
;
1891 if ((This
== NULL
) || (Data
== NULL
)) {
1892 return EFI_INVALID_PARAMETER
;
1895 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
1896 return EFI_UNSUPPORTED
;
1899 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
1900 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
1901 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1903 if (IpSb
->LinkLocalDadFail
) {
1904 return EFI_DEVICE_ERROR
;
1907 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
1909 Status
= Instance
->DataItem
[DataType
].Status
;
1910 if (Status
!= EFI_NOT_READY
) {
1912 if (Instance
->DataItem
[DataType
].SetData
== NULL
) {
1914 // This type of data is readonly.
1916 Status
= EFI_WRITE_PROTECTED
;
1919 Status
= Instance
->DataItem
[DataType
].SetData (Instance
, DataSize
, Data
);
1920 if (!EFI_ERROR (Status
)) {
1922 // Fire up the events registered with this type of data.
1924 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
1925 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
1926 } else if (Status
== EFI_ABORTED
) {
1928 // The SetData is aborted because the data to set is the same with
1929 // the one maintained.
1931 Status
= EFI_SUCCESS
;
1932 NetMapIterate (&Instance
->DataItem
[DataType
].EventMap
, Ip6ConfigSignalEvent
, NULL
);
1937 // Another asynchornous process is on the way.
1939 Status
= EFI_ACCESS_DENIED
;
1942 gBS
->RestoreTPL (OldTpl
);
1948 Get the configuration data for the EFI IPv6 network stack running on the communication
1949 device that this EFI IPv6 Configuration Protocol instance manages.
1951 This function returns the configuration data of type DataType for the EFI IPv6 network
1952 stack running on the communication device that this EFI IPv6 Configuration Protocol instance
1955 The caller is responsible for allocating the buffer used to return the specified
1956 configuration data. The required size will be returned to the caller if the size of
1957 the buffer is too small.
1959 EFI_NOT_READY is returned if the specified configuration data is not ready due to an
1960 asynchronous configuration process already in progress. The caller can call RegisterDataNotify()
1961 to register an event on the specified configuration data. Once the asynchronous configuration
1962 process is finished, the event will be signaled, and a subsequent GetData() call will return
1963 the specified configuration data.
1965 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
1966 @param[in] DataType The type of data to get.
1967 @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the
1968 size of buffer required to store the specified configuration data.
1969 @param[in] Data The data buffer in which the configuration data is returned. The
1970 type of the data buffer is associated with the DataType.
1971 This is an optional parameter that may be NULL.
1973 @retval EFI_SUCCESS The specified configuration data was obtained successfully.
1974 @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
1977 - Data is NULL if *DataSize is not zero.
1978 @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,
1979 and the required size is returned in DataSize.
1980 @retval EFI_NOT_READY The specified configuration data is not ready due to an
1981 asynchronous configuration process already in progress.
1982 @retval EFI_NOT_FOUND The specified configuration data is not found.
1987 EfiIp6ConfigGetData (
1988 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
1989 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
1990 IN OUT UINTN
*DataSize
,
1991 IN VOID
*Data OPTIONAL
1996 IP6_CONFIG_INSTANCE
*Instance
;
1997 IP6_CONFIG_DATA_ITEM
*DataItem
;
1999 if ((This
== NULL
) || (DataSize
== NULL
) || ((*DataSize
!= 0) && (Data
== NULL
))) {
2000 return EFI_INVALID_PARAMETER
;
2003 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2004 return EFI_NOT_FOUND
;
2007 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2009 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2010 DataItem
= &Instance
->DataItem
[DataType
];
2012 Status
= Instance
->DataItem
[DataType
].Status
;
2013 if (!EFI_ERROR (Status
)) {
2015 if (DataItem
->GetData
!= NULL
) {
2017 Status
= DataItem
->GetData (Instance
, DataSize
, Data
);
2018 } else if (*DataSize
< Instance
->DataItem
[DataType
].DataSize
) {
2020 // Update the buffer length.
2022 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2023 Status
= EFI_BUFFER_TOO_SMALL
;
2026 *DataSize
= Instance
->DataItem
[DataType
].DataSize
;
2027 CopyMem (Data
, Instance
->DataItem
[DataType
].Data
.Ptr
, *DataSize
);
2031 gBS
->RestoreTPL (OldTpl
);
2037 Register an event that is signaled whenever a configuration process on the specified
2038 configuration data is done.
2040 This function registers an event that is to be signaled whenever a configuration
2041 process on the specified configuration data is performed. An event can be registered
2042 for a different DataType simultaneously. The caller is responsible for determining
2043 which type of configuration data causes the signaling of the event in such an event.
2045 @param[in] This Pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2046 @param[in] DataType The type of data to unregister the event for.
2047 @param[in] Event The event to register.
2049 @retval EFI_SUCCESS The notification event for the specified configuration data is
2051 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2052 @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not
2054 @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
2055 @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.
2060 EfiIp6ConfigRegisterDataNotify (
2061 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2062 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2068 IP6_CONFIG_INSTANCE
*Instance
;
2072 if ((This
== NULL
) || (Event
== NULL
)) {
2073 return EFI_INVALID_PARAMETER
;
2076 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2077 return EFI_UNSUPPORTED
;
2080 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2082 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2083 EventMap
= &Instance
->DataItem
[DataType
].EventMap
;
2086 // Check whether this event is already registered for this DataType.
2088 Item
= NetMapFindKey (EventMap
, Event
);
2091 Status
= NetMapInsertTail (EventMap
, Event
, NULL
);
2093 if (EFI_ERROR (Status
)) {
2095 Status
= EFI_OUT_OF_RESOURCES
;
2100 Status
= EFI_ACCESS_DENIED
;
2103 gBS
->RestoreTPL (OldTpl
);
2109 Remove a previously registered event for the specified configuration data.
2111 @param This The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
2112 @param DataType The type of data to remove from the previously
2114 @param Event The event to be unregistered.
2116 @retval EFI_SUCCESS The event registered for the specified
2117 configuration data was removed.
2118 @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.
2119 @retval EFI_NOT_FOUND The Event has not been registered for the
2125 EfiIp6ConfigUnregisterDataNotify (
2126 IN EFI_IP6_CONFIG_PROTOCOL
*This
,
2127 IN EFI_IP6_CONFIG_DATA_TYPE DataType
,
2133 IP6_CONFIG_INSTANCE
*Instance
;
2136 if ((This
== NULL
) || (Event
== NULL
)) {
2137 return EFI_INVALID_PARAMETER
;
2140 if (DataType
>= Ip6ConfigDataTypeMaximum
) {
2141 return EFI_NOT_FOUND
;
2144 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
2146 Instance
= IP6_CONFIG_INSTANCE_FROM_PROTOCOL (This
);
2148 Item
= NetMapFindKey (&Instance
->DataItem
[DataType
].EventMap
, Event
);
2151 NetMapRemoveItem (&Instance
->DataItem
[DataType
].EventMap
, Item
, NULL
);
2152 Status
= EFI_SUCCESS
;
2155 Status
= EFI_NOT_FOUND
;
2158 gBS
->RestoreTPL (OldTpl
);
2164 Initialize an IP6_CONFIG_INSTANCE.
2166 @param[out] Instance The buffer of IP6_CONFIG_INSTANCE to be initialized.
2168 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.
2169 @retval EFI_SUCCESS The IP6_CONFIG_INSTANCE initialized successfully.
2173 Ip6ConfigInitInstance (
2174 OUT IP6_CONFIG_INSTANCE
*Instance
2178 IP6_CONFIG_INSTANCE
*TmpInstance
;
2183 IP6_CONFIG_DATA_ITEM
*DataItem
;
2185 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2187 Instance
->Signature
= IP6_CONFIG_INSTANCE_SIGNATURE
;
2190 // Determine the index of this interface.
2193 NET_LIST_FOR_EACH (Entry
, &mIp6ConfigInstanceList
) {
2194 TmpInstance
= NET_LIST_USER_STRUCT_S (Entry
, IP6_CONFIG_INSTANCE
, Link
, IP6_CONFIG_INSTANCE_SIGNATURE
);
2196 if (TmpInstance
->IfIndex
> IfIndex
) {
2198 // There is a sequence hole because some interface is down.
2206 Instance
->IfIndex
= IfIndex
;
2207 NetListInsertBefore (Entry
, &Instance
->Link
);
2209 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2211 // Initialize the event map for each data item.
2213 NetMapInit (&Instance
->DataItem
[Index
].EventMap
);
2217 // Initialize the NET_MAPs used for DAD on manually configured source addresses.
2219 NetMapInit (&Instance
->DadFailedMap
);
2220 NetMapInit (&Instance
->DadPassedMap
);
2223 // Initialize each data type: associate storage and set data size for the
2224 // fixed size data types, hook the SetData function, set the data attribute.
2226 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeInterfaceInfo
];
2227 DataItem
->GetData
= Ip6ConfigGetIfInfo
;
2228 DataItem
->Data
.Ptr
= &Instance
->InterfaceInfo
;
2229 DataItem
->DataSize
= sizeof (Instance
->InterfaceInfo
);
2230 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
| DATA_ATTRIB_VOLATILE
);
2231 Ip6ConfigInitIfInfo (IpSb
, &Instance
->InterfaceInfo
);
2233 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeAltInterfaceId
];
2234 DataItem
->SetData
= Ip6ConfigSetAltIfId
;
2235 DataItem
->Data
.Ptr
= &Instance
->AltIfId
;
2236 DataItem
->DataSize
= sizeof (Instance
->AltIfId
);
2237 DataItem
->Status
= EFI_NOT_FOUND
;
2238 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2240 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypePolicy
];
2241 DataItem
->SetData
= Ip6ConfigSetPolicy
;
2242 DataItem
->Data
.Ptr
= &Instance
->Policy
;
2243 DataItem
->DataSize
= sizeof (Instance
->Policy
);
2244 Instance
->Policy
= Ip6ConfigPolicyManual
;
2245 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2247 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDupAddrDetectTransmits
];
2248 DataItem
->SetData
= Ip6ConfigSetDadXmits
;
2249 DataItem
->Data
.Ptr
= &Instance
->DadXmits
;
2250 DataItem
->DataSize
= sizeof (Instance
->DadXmits
);
2251 Instance
->DadXmits
.DupAddrDetectTransmits
= IP6_CONFIG_DEFAULT_DAD_XMITS
;
2252 SET_DATA_ATTRIB (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
);
2254 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeManualAddress
];
2255 DataItem
->SetData
= Ip6ConfigSetManualAddress
;
2256 DataItem
->Status
= EFI_NOT_FOUND
;
2258 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeGateway
];
2259 DataItem
->SetData
= Ip6ConfigSetGateway
;
2260 DataItem
->Status
= EFI_NOT_FOUND
;
2262 DataItem
= &Instance
->DataItem
[Ip6ConfigDataTypeDnsServer
];
2263 DataItem
->SetData
= Ip6ConfigSetDnsServer
;
2264 DataItem
->Status
= EFI_NOT_FOUND
;
2267 // Create the event used for DHCP.
2269 Status
= gBS
->CreateEvent (
2272 Ip6ConfigOnDhcp6Event
,
2274 &Instance
->Dhcp6Event
2276 ASSERT_EFI_ERROR (Status
);
2278 Instance
->Configured
= TRUE
;
2281 // Try to read the config data from NV variable.
2283 Status
= Ip6ConfigReadConfigData (IpSb
->MacString
, Instance
);
2284 if (Status
== EFI_NOT_FOUND
) {
2286 // The NV variable is not set, so generate a random IAID, and write down the
2287 // fresh new configuration as the NV variable now.
2289 Instance
->IaId
= NET_RANDOM (NetRandomInitSeed ());
2291 for (Index
= 0; Index
< IpSb
->SnpMode
.HwAddressSize
; Index
++) {
2292 Instance
->IaId
|= (IpSb
->SnpMode
.CurrentAddress
.Addr
[Index
] << ((Index
<< 3) & 31));
2295 Ip6ConfigWriteConfigData (IpSb
->MacString
, Instance
);
2296 } else if (EFI_ERROR (Status
)) {
2300 Instance
->Ip6Config
.SetData
= EfiIp6ConfigSetData
;
2301 Instance
->Ip6Config
.GetData
= EfiIp6ConfigGetData
;
2302 Instance
->Ip6Config
.RegisterDataNotify
= EfiIp6ConfigRegisterDataNotify
;
2303 Instance
->Ip6Config
.UnregisterDataNotify
= EfiIp6ConfigUnregisterDataNotify
;
2307 // Publish the IP6 configuration form
2309 return Ip6ConfigFormInit (Instance
);
2313 Release an IP6_CONFIG_INSTANCE.
2315 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2319 Ip6ConfigCleanInstance (
2320 IN OUT IP6_CONFIG_INSTANCE
*Instance
2324 IP6_CONFIG_DATA_ITEM
*DataItem
;
2326 if (Instance
->DeclineAddress
!= NULL
) {
2327 FreePool (Instance
->DeclineAddress
);
2330 if (!Instance
->Configured
) {
2334 if (Instance
->Dhcp6Handle
!= NULL
) {
2336 Ip6ConfigDestroyDhcp6 (Instance
);
2342 if (Instance
->Dhcp6Event
!= NULL
) {
2343 gBS
->CloseEvent (Instance
->Dhcp6Event
);
2346 NetMapClean (&Instance
->DadPassedMap
);
2347 NetMapClean (&Instance
->DadFailedMap
);
2349 for (Index
= 0; Index
< Ip6ConfigDataTypeMaximum
; Index
++) {
2351 DataItem
= &Instance
->DataItem
[Index
];
2353 if (!DATA_ATTRIB_SET (DataItem
->Attribute
, DATA_ATTRIB_SIZE_FIXED
)) {
2354 if (DataItem
->Data
.Ptr
!= NULL
) {
2355 FreePool (DataItem
->Data
.Ptr
);
2357 DataItem
->Data
.Ptr
= NULL
;
2358 DataItem
->DataSize
= 0;
2361 NetMapClean (&Instance
->DataItem
[Index
].EventMap
);
2364 Ip6ConfigFormUnload (Instance
);
2366 RemoveEntryList (&Instance
->Link
);
2370 Destroy the Dhcp6 child in IP6_CONFIG_INSTANCE and release the resources.
2372 @param[in, out] Instance The buffer of IP6_CONFIG_INSTANCE to be freed.
2374 @retval EFI_SUCCESS The child was successfully destroyed.
2375 @retval Others Failed to destroy the child.
2379 Ip6ConfigDestroyDhcp6 (
2380 IN OUT IP6_CONFIG_INSTANCE
*Instance
2385 EFI_DHCP6_PROTOCOL
*Dhcp6
;
2387 Dhcp6
= Instance
->Dhcp6
;
2388 ASSERT (Dhcp6
!= NULL
);
2390 Dhcp6
->Stop (Dhcp6
);
2391 Dhcp6
->Configure (Dhcp6
, NULL
);
2392 Instance
->Dhcp6
= NULL
;
2394 IpSb
= IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance
);
2397 // Close DHCPv6 protocol and destroy the child.
2399 Status
= gBS
->CloseProtocol (
2400 Instance
->Dhcp6Handle
,
2401 &gEfiDhcp6ProtocolGuid
,
2405 if (EFI_ERROR (Status
)) {
2409 Status
= NetLibDestroyServiceChild (
2412 &gEfiDhcp6ServiceBindingProtocolGuid
,
2413 Instance
->Dhcp6Handle
2416 Instance
->Dhcp6Handle
= NULL
;