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