2 Implementation of Neighbor Discovery support routines.
4 Copyright (c) 2009 - 2012, 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 EFI_MAC_ADDRESS mZeroMacAddress
;
21 Update the ReachableTime in IP6 service binding instance data, in milliseconds.
23 @param[in, out] IpSb Points to the IP6_SERVICE.
27 Ip6UpdateReachableTime (
28 IN OUT IP6_SERVICE
*IpSb
33 Random
= (NetRandomInitSeed () / 4294967295UL) * IP6_RANDOM_FACTOR_SCALE
;
34 Random
= Random
+ IP6_MIN_RANDOM_FACTOR_SCALED
;
35 IpSb
->ReachableTime
= (IpSb
->BaseReachableTime
* Random
) / IP6_RANDOM_FACTOR_SCALE
;
39 Build a array of EFI_IP6_NEIGHBOR_CACHE to be returned to the caller. The number
40 of EFI_IP6_NEIGHBOR_CACHE is also returned.
42 @param[in] IpInstance The pointer to IP6_PROTOCOL instance.
43 @param[out] NeighborCount The number of returned neighbor cache entries.
44 @param[out] NeighborCache The pointer to the array of EFI_IP6_NEIGHBOR_CACHE.
46 @retval EFI_SUCCESS The EFI_IP6_NEIGHBOR_CACHE successfully built.
47 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the route table.
51 Ip6BuildEfiNeighborCache (
52 IN IP6_PROTOCOL
*IpInstance
,
53 OUT UINT32
*NeighborCount
,
54 OUT EFI_IP6_NEIGHBOR_CACHE
**NeighborCache
57 IP6_NEIGHBOR_ENTRY
*Neighbor
;
61 EFI_IP6_NEIGHBOR_CACHE
*EfiNeighborCache
;
62 EFI_IP6_NEIGHBOR_CACHE
*NeighborCacheTmp
;
64 NET_CHECK_SIGNATURE (IpInstance
, IP6_PROTOCOL_SIGNATURE
);
65 ASSERT (NeighborCount
!= NULL
&& NeighborCache
!= NULL
);
67 IpSb
= IpInstance
->Service
;
70 NET_LIST_FOR_EACH (Entry
, &IpSb
->NeighborTable
) {
78 NeighborCacheTmp
= AllocatePool (Count
* sizeof (EFI_IP6_NEIGHBOR_CACHE
));
79 if (NeighborCacheTmp
== NULL
) {
80 return EFI_OUT_OF_RESOURCES
;
83 *NeighborCount
= Count
;
86 NET_LIST_FOR_EACH (Entry
, &IpSb
->NeighborTable
) {
87 Neighbor
= NET_LIST_USER_STRUCT (Entry
, IP6_NEIGHBOR_ENTRY
, Link
);
89 EfiNeighborCache
= NeighborCacheTmp
+ Count
;
91 EfiNeighborCache
->State
= Neighbor
->State
;
92 IP6_COPY_ADDRESS (&EfiNeighborCache
->Neighbor
, &Neighbor
->Neighbor
);
93 IP6_COPY_LINK_ADDRESS (&EfiNeighborCache
->LinkAddress
, &Neighbor
->LinkAddress
);
98 ASSERT (*NeighborCount
== Count
);
99 *NeighborCache
= NeighborCacheTmp
;
105 Build a array of EFI_IP6_ADDRESS_INFO to be returned to the caller. The number
106 of prefix entries is also returned.
108 @param[in] IpInstance The pointer to IP6_PROTOCOL instance.
109 @param[out] PrefixCount The number of returned prefix entries.
110 @param[out] PrefixTable The pointer to the array of PrefixTable.
112 @retval EFI_SUCCESS The prefix table successfully built.
113 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the prefix table.
117 Ip6BuildPrefixTable (
118 IN IP6_PROTOCOL
*IpInstance
,
119 OUT UINT32
*PrefixCount
,
120 OUT EFI_IP6_ADDRESS_INFO
**PrefixTable
126 IP6_PREFIX_LIST_ENTRY
*PrefixList
;
127 EFI_IP6_ADDRESS_INFO
*EfiPrefix
;
128 EFI_IP6_ADDRESS_INFO
*PrefixTableTmp
;
130 NET_CHECK_SIGNATURE (IpInstance
, IP6_PROTOCOL_SIGNATURE
);
131 ASSERT (PrefixCount
!= NULL
&& PrefixTable
!= NULL
);
133 IpSb
= IpInstance
->Service
;
136 NET_LIST_FOR_EACH (Entry
, &IpSb
->OnlinkPrefix
) {
144 PrefixTableTmp
= AllocatePool (Count
* sizeof (EFI_IP6_ADDRESS_INFO
));
145 if (PrefixTableTmp
== NULL
) {
146 return EFI_OUT_OF_RESOURCES
;
149 *PrefixCount
= Count
;
152 NET_LIST_FOR_EACH (Entry
, &IpSb
->OnlinkPrefix
) {
153 PrefixList
= NET_LIST_USER_STRUCT (Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
154 EfiPrefix
= PrefixTableTmp
+ Count
;
155 IP6_COPY_ADDRESS (&EfiPrefix
->Address
, &PrefixList
->Prefix
);
156 EfiPrefix
->PrefixLength
= PrefixList
->PrefixLength
;
161 ASSERT (*PrefixCount
== Count
);
162 *PrefixTable
= PrefixTableTmp
;
168 Allocate and initialize a IP6 prefix list entry.
170 @param[in] IpSb The pointer to IP6_SERVICE instance.
171 @param[in] OnLinkOrAuto If TRUE, the entry is created for the on link prefix list.
172 Otherwise, it is created for the autoconfiguration prefix list.
173 @param[in] ValidLifetime The length of time in seconds that the prefix
174 is valid for the purpose of on-link determination.
175 @param[in] PreferredLifetime The length of time in seconds that addresses
176 generated from the prefix via stateless address
177 autoconfiguration remain preferred.
178 @param[in] PrefixLength The prefix length of the Prefix.
179 @param[in] Prefix The prefix address.
181 @return NULL if it failed to allocate memory for the prefix node. Otherwise, point
182 to the created or existing prefix list entry.
185 IP6_PREFIX_LIST_ENTRY
*
186 Ip6CreatePrefixListEntry (
187 IN IP6_SERVICE
*IpSb
,
188 IN BOOLEAN OnLinkOrAuto
,
189 IN UINT32 ValidLifetime
,
190 IN UINT32 PreferredLifetime
,
191 IN UINT8 PrefixLength
,
192 IN EFI_IPv6_ADDRESS
*Prefix
195 IP6_PREFIX_LIST_ENTRY
*PrefixEntry
;
196 IP6_ROUTE_ENTRY
*RtEntry
;
197 LIST_ENTRY
*ListHead
;
199 IP6_PREFIX_LIST_ENTRY
*TmpPrefixEntry
;
201 if (Prefix
== NULL
|| PreferredLifetime
> ValidLifetime
|| PrefixLength
>= IP6_PREFIX_NUM
) {
205 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
207 PrefixEntry
= Ip6FindPrefixListEntry (
213 if (PrefixEntry
!= NULL
) {
214 PrefixEntry
->RefCnt
++;
218 PrefixEntry
= AllocatePool (sizeof (IP6_PREFIX_LIST_ENTRY
));
219 if (PrefixEntry
== NULL
) {
223 PrefixEntry
->RefCnt
= 1;
224 PrefixEntry
->ValidLifetime
= ValidLifetime
;
225 PrefixEntry
->PreferredLifetime
= PreferredLifetime
;
226 PrefixEntry
->PrefixLength
= PrefixLength
;
227 IP6_COPY_ADDRESS (&PrefixEntry
->Prefix
, Prefix
);
229 ListHead
= OnLinkOrAuto
? &IpSb
->OnlinkPrefix
: &IpSb
->AutonomousPrefix
;
232 // Create a direct route entry for on-link prefix and insert to route area.
235 RtEntry
= Ip6CreateRouteEntry (Prefix
, PrefixLength
, NULL
);
236 if (RtEntry
== NULL
) {
237 FreePool (PrefixEntry
);
241 RtEntry
->Flag
= IP6_DIRECT_ROUTE
;
242 InsertHeadList (&IpSb
->RouteTable
->RouteArea
[PrefixLength
], &RtEntry
->Link
);
243 IpSb
->RouteTable
->TotalNum
++;
247 // Insert the prefix entry in the order that a prefix with longer prefix length
248 // is put ahead in the list.
250 NET_LIST_FOR_EACH (Entry
, ListHead
) {
251 TmpPrefixEntry
= NET_LIST_USER_STRUCT(Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
253 if (TmpPrefixEntry
->PrefixLength
< PrefixEntry
->PrefixLength
) {
258 NetListInsertBefore (Entry
, &PrefixEntry
->Link
);
264 Destroy a IP6 prefix list entry.
266 @param[in] IpSb The pointer to IP6_SERVICE instance.
267 @param[in] PrefixEntry The to be destroyed prefix list entry.
268 @param[in] OnLinkOrAuto If TRUE, the entry is removed from on link prefix list.
269 Otherwise remove from autoconfiguration prefix list.
270 @param[in] ImmediateDelete If TRUE, remove the entry directly.
271 Otherwise, check the reference count to see whether
272 it should be removed.
276 Ip6DestroyPrefixListEntry (
277 IN IP6_SERVICE
*IpSb
,
278 IN IP6_PREFIX_LIST_ENTRY
*PrefixEntry
,
279 IN BOOLEAN OnLinkOrAuto
,
280 IN BOOLEAN ImmediateDelete
287 if ((!ImmediateDelete
) && (PrefixEntry
->RefCnt
> 0) && ((--PrefixEntry
->RefCnt
) > 0)) {
293 // Remove the direct route for onlink prefix from route table.
296 Status
= Ip6DelRoute (
298 &PrefixEntry
->Prefix
,
299 PrefixEntry
->PrefixLength
,
302 } while (Status
!= EFI_NOT_FOUND
);
305 // Remove the corresponding addresses generated from this autonomous prefix.
307 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
308 IpIf
= NET_LIST_USER_STRUCT_S (Entry
, IP6_INTERFACE
, Link
, IP6_INTERFACE_SIGNATURE
);
310 Ip6RemoveAddr (IpSb
, &IpIf
->AddressList
, &IpIf
->AddressCount
, &PrefixEntry
->Prefix
, PrefixEntry
->PrefixLength
);
314 RemoveEntryList (&PrefixEntry
->Link
);
315 FreePool (PrefixEntry
);
319 Search the list array to find an IP6 prefix list entry.
321 @param[in] IpSb The pointer to IP6_SERVICE instance.
322 @param[in] OnLinkOrAuto If TRUE, the search the link prefix list,
323 Otherwise search the autoconfiguration prefix list.
324 @param[in] PrefixLength The prefix length of the Prefix
325 @param[in] Prefix The prefix address.
327 @return NULL if cannot find the IP6 prefix list entry. Otherwise, return the
328 pointer to the IP6 prefix list entry.
331 IP6_PREFIX_LIST_ENTRY
*
332 Ip6FindPrefixListEntry (
333 IN IP6_SERVICE
*IpSb
,
334 IN BOOLEAN OnLinkOrAuto
,
335 IN UINT8 PrefixLength
,
336 IN EFI_IPv6_ADDRESS
*Prefix
339 IP6_PREFIX_LIST_ENTRY
*PrefixList
;
341 LIST_ENTRY
*ListHead
;
343 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
344 ASSERT (Prefix
!= NULL
);
347 ListHead
= &IpSb
->OnlinkPrefix
;
349 ListHead
= &IpSb
->AutonomousPrefix
;
352 NET_LIST_FOR_EACH (Entry
, ListHead
) {
353 PrefixList
= NET_LIST_USER_STRUCT (Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
354 if (PrefixLength
!= 255) {
356 // Perform exactly prefix match.
358 if (PrefixList
->PrefixLength
== PrefixLength
&&
359 NetIp6IsNetEqual (&PrefixList
->Prefix
, Prefix
, PrefixLength
)) {
364 // Perform the longest prefix match. The list is already sorted with
365 // the longest length prefix put at the head of the list.
367 if (NetIp6IsNetEqual (&PrefixList
->Prefix
, Prefix
, PrefixList
->PrefixLength
)) {
377 Release the resource in the prefix list table, and destroy the list entry and
378 corresponding addresses or route entries.
380 @param[in] IpSb The pointer to the IP6_SERVICE instance.
381 @param[in] ListHead The list entry head of the prefix list table.
385 Ip6CleanPrefixListTable (
386 IN IP6_SERVICE
*IpSb
,
387 IN LIST_ENTRY
*ListHead
390 IP6_PREFIX_LIST_ENTRY
*PrefixList
;
393 OnLink
= (BOOLEAN
) (ListHead
== &IpSb
->OnlinkPrefix
);
395 while (!IsListEmpty (ListHead
)) {
396 PrefixList
= NET_LIST_HEAD (ListHead
, IP6_PREFIX_LIST_ENTRY
, Link
);
397 Ip6DestroyPrefixListEntry (IpSb
, PrefixList
, OnLink
, TRUE
);
402 Callback function when address resolution is finished. It will cancel
403 all the queued frames if the address resolution failed, or transmit them
404 if the request succeeded.
406 @param[in] Context The context of the callback, a pointer to IP6_NEIGHBOR_ENTRY.
416 IP6_NEIGHBOR_ENTRY
*ArpQue
;
418 IP6_LINK_TX_TOKEN
*Token
;
422 ArpQue
= (IP6_NEIGHBOR_ENTRY
*) Context
;
423 if ((ArpQue
== NULL
) || (ArpQue
->Interface
== NULL
)) {
427 IpSb
= ArpQue
->Interface
->Service
;
428 if ((IpSb
== NULL
) || (IpSb
->Signature
!= IP6_SERVICE_SIGNATURE
)) {
433 // ARP resolve failed for some reason. Release all the frame
434 // and ARP queue itself. Ip6FreeArpQue will call the frame's
437 if (NET_MAC_EQUAL (&ArpQue
->LinkAddress
, &mZeroMacAddress
, IpSb
->SnpMode
.HwAddressSize
)) {
438 Ip6FreeNeighborEntry (IpSb
, ArpQue
, FALSE
, TRUE
, EFI_NO_MAPPING
, NULL
, NULL
);
443 // ARP resolve succeeded, Transmit all the frame.
446 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &ArpQue
->Frames
) {
447 RemoveEntryList (Entry
);
449 Token
= NET_LIST_USER_STRUCT (Entry
, IP6_LINK_TX_TOKEN
, Link
);
450 IP6_COPY_LINK_ADDRESS (&Token
->DstMac
, &ArpQue
->LinkAddress
);
453 // Insert the tx token before transmitting it via MNP as the FrameSentDpc
454 // may be called before Mnp->Transmit returns which will remove this tx
455 // token from the SentFrames list. Remove it from the list if the returned
456 // Status of Mnp->Transmit is not EFI_SUCCESS as in this case the
457 // FrameSentDpc won't be queued.
459 InsertTailList (&ArpQue
->Interface
->SentFrames
, &Token
->Link
);
461 Status
= IpSb
->Mnp
->Transmit (IpSb
->Mnp
, &Token
->MnpToken
);
462 if (EFI_ERROR (Status
)) {
463 RemoveEntryList (&Token
->Link
);
464 Token
->CallBack (Token
->Packet
, Status
, 0, Token
->Context
);
466 Ip6FreeLinkTxToken (Token
);
474 // Free the ArpQue only but not the whole neighbor entry.
476 Ip6FreeNeighborEntry (IpSb
, ArpQue
, FALSE
, FALSE
, EFI_SUCCESS
, NULL
, NULL
);
478 if (Sent
&& (ArpQue
->State
== EfiNeighborStale
)) {
479 ArpQue
->State
= EfiNeighborDelay
;
480 ArpQue
->Ticks
= (UINT32
) IP6_GET_TICKS (IP6_DELAY_FIRST_PROBE_TIME
);
485 Allocate and initialize an IP6 neighbor cache entry.
487 @param[in] IpSb The pointer to the IP6_SERVICE instance.
488 @param[in] CallBack The callback function to be called when
489 address resolution is finished.
490 @param[in] Ip6Address Points to the IPv6 address of the neighbor.
491 @param[in] LinkAddress Points to the MAC address of the neighbor.
494 @return NULL if failed to allocate memory for the neighbor cache entry.
495 Otherwise, point to the created neighbor cache entry.
499 Ip6CreateNeighborEntry (
500 IN IP6_SERVICE
*IpSb
,
501 IN IP6_ARP_CALLBACK CallBack
,
502 IN EFI_IPv6_ADDRESS
*Ip6Address
,
503 IN EFI_MAC_ADDRESS
*LinkAddress OPTIONAL
506 IP6_NEIGHBOR_ENTRY
*Entry
;
507 IP6_DEFAULT_ROUTER
*DefaultRouter
;
509 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
510 ASSERT (Ip6Address
!= NULL
);
512 Entry
= AllocateZeroPool (sizeof (IP6_NEIGHBOR_ENTRY
));
518 Entry
->IsRouter
= FALSE
;
519 Entry
->ArpFree
= FALSE
;
520 Entry
->Dynamic
= FALSE
;
521 Entry
->State
= EfiNeighborInComplete
;
522 Entry
->Transmit
= IP6_MAX_MULTICAST_SOLICIT
+ 1;
523 Entry
->CallBack
= CallBack
;
524 Entry
->Interface
= NULL
;
526 InitializeListHead (&Entry
->Frames
);
528 IP6_COPY_ADDRESS (&Entry
->Neighbor
, Ip6Address
);
530 if (LinkAddress
!= NULL
) {
531 IP6_COPY_LINK_ADDRESS (&Entry
->LinkAddress
, LinkAddress
);
533 IP6_COPY_LINK_ADDRESS (&Entry
->LinkAddress
, &mZeroMacAddress
);
536 InsertHeadList (&IpSb
->NeighborTable
, &Entry
->Link
);
539 // If corresponding default router entry exists, establish the relationship.
541 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, Ip6Address
);
542 if (DefaultRouter
!= NULL
) {
543 DefaultRouter
->NeighborCache
= Entry
;
550 Search a IP6 neighbor cache entry.
552 @param[in] IpSb The pointer to the IP6_SERVICE instance.
553 @param[in] Ip6Address Points to the IPv6 address of the neighbor.
555 @return NULL if it failed to find the matching neighbor cache entry.
556 Otherwise, point to the found neighbor cache entry.
560 Ip6FindNeighborEntry (
561 IN IP6_SERVICE
*IpSb
,
562 IN EFI_IPv6_ADDRESS
*Ip6Address
567 IP6_NEIGHBOR_ENTRY
*Neighbor
;
569 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
570 ASSERT (Ip6Address
!= NULL
);
572 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpSb
->NeighborTable
) {
573 Neighbor
= NET_LIST_USER_STRUCT (Entry
, IP6_NEIGHBOR_ENTRY
, Link
);
574 if (EFI_IP6_EQUAL (Ip6Address
, &Neighbor
->Neighbor
)) {
575 RemoveEntryList (Entry
);
576 InsertHeadList (&IpSb
->NeighborTable
, Entry
);
586 Free a IP6 neighbor cache entry and remove all the frames on the address
587 resolution queue that pass the FrameToCancel. That is, either FrameToCancel
588 is NULL, or it returns true for the frame.
590 @param[in] IpSb The pointer to the IP6_SERVICE instance.
591 @param[in] NeighborCache The to be free neighbor cache entry.
592 @param[in] SendIcmpError If TRUE, send out ICMP error.
593 @param[in] FullFree If TRUE, remove the neighbor cache entry.
594 Otherwise remove the pending frames.
595 @param[in] IoStatus The status returned to the cancelled frames'
597 @param[in] FrameToCancel Function to select which frame to cancel.
598 This is an optional parameter that may be NULL.
599 @param[in] Context Opaque parameter to the FrameToCancel.
600 Ignored if FrameToCancel is NULL.
602 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
603 @retval EFI_SUCCESS The operation finished successfully.
607 Ip6FreeNeighborEntry (
608 IN IP6_SERVICE
*IpSb
,
609 IN IP6_NEIGHBOR_ENTRY
*NeighborCache
,
610 IN BOOLEAN SendIcmpError
,
612 IN EFI_STATUS IoStatus
,
613 IN IP6_FRAME_TO_CANCEL FrameToCancel OPTIONAL
,
614 IN VOID
*Context OPTIONAL
617 IP6_LINK_TX_TOKEN
*TxToken
;
620 IP6_DEFAULT_ROUTER
*DefaultRouter
;
623 // If FrameToCancel fails, the token will not be released.
624 // To avoid the memory leak, stop this usage model.
626 if (FullFree
&& FrameToCancel
!= NULL
) {
627 return EFI_INVALID_PARAMETER
;
630 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &NeighborCache
->Frames
) {
631 TxToken
= NET_LIST_USER_STRUCT (Entry
, IP6_LINK_TX_TOKEN
, Link
);
633 if (SendIcmpError
&& !IP6_IS_MULTICAST (&TxToken
->Packet
->Ip
.Ip6
->DestinationAddress
)) {
638 &TxToken
->Packet
->Ip
.Ip6
->SourceAddress
,
639 ICMP_V6_DEST_UNREACHABLE
,
640 ICMP_V6_ADDR_UNREACHABLE
,
645 if ((FrameToCancel
== NULL
) || FrameToCancel (TxToken
, Context
)) {
646 RemoveEntryList (Entry
);
647 TxToken
->CallBack (TxToken
->Packet
, IoStatus
, 0, TxToken
->Context
);
648 Ip6FreeLinkTxToken (TxToken
);
652 if (NeighborCache
->ArpFree
&& IsListEmpty (&NeighborCache
->Frames
)) {
653 RemoveEntryList (&NeighborCache
->ArpList
);
654 NeighborCache
->ArpFree
= FALSE
;
658 if (NeighborCache
->IsRouter
) {
659 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, &NeighborCache
->Neighbor
);
660 if (DefaultRouter
!= NULL
) {
661 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
665 RemoveEntryList (&NeighborCache
->Link
);
666 FreePool (NeighborCache
);
673 Allocate and initialize an IP6 default router entry.
675 @param[in] IpSb The pointer to the IP6_SERVICE instance.
676 @param[in] Ip6Address The IPv6 address of the default router.
677 @param[in] RouterLifetime The lifetime associated with the default
678 router, in units of seconds.
680 @return NULL if it failed to allocate memory for the default router node.
681 Otherwise, point to the created default router node.
685 Ip6CreateDefaultRouter (
686 IN IP6_SERVICE
*IpSb
,
687 IN EFI_IPv6_ADDRESS
*Ip6Address
,
688 IN UINT16 RouterLifetime
691 IP6_DEFAULT_ROUTER
*Entry
;
692 IP6_ROUTE_ENTRY
*RtEntry
;
694 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
695 ASSERT (Ip6Address
!= NULL
);
697 Entry
= AllocatePool (sizeof (IP6_DEFAULT_ROUTER
));
703 Entry
->Lifetime
= RouterLifetime
;
704 Entry
->NeighborCache
= Ip6FindNeighborEntry (IpSb
, Ip6Address
);
705 IP6_COPY_ADDRESS (&Entry
->Router
, Ip6Address
);
708 // Add a default route into route table with both Destination and PrefixLength set to zero.
710 RtEntry
= Ip6CreateRouteEntry (NULL
, 0, Ip6Address
);
711 if (RtEntry
== NULL
) {
716 InsertHeadList (&IpSb
->RouteTable
->RouteArea
[0], &RtEntry
->Link
);
717 IpSb
->RouteTable
->TotalNum
++;
719 InsertTailList (&IpSb
->DefaultRouterList
, &Entry
->Link
);
725 Destroy an IP6 default router entry.
727 @param[in] IpSb The pointer to the IP6_SERVICE instance.
728 @param[in] DefaultRouter The to be destroyed IP6_DEFAULT_ROUTER.
732 Ip6DestroyDefaultRouter (
733 IN IP6_SERVICE
*IpSb
,
734 IN IP6_DEFAULT_ROUTER
*DefaultRouter
739 RemoveEntryList (&DefaultRouter
->Link
);
742 // Update the Destination Cache - all entries using the time-out router as next-hop
743 // should perform next-hop determination again.
746 Status
= Ip6DelRoute (IpSb
->RouteTable
, NULL
, 0, &DefaultRouter
->Router
);
747 } while (Status
!= EFI_NOT_FOUND
);
749 FreePool (DefaultRouter
);
753 Clean an IP6 default router list.
755 @param[in] IpSb The pointer to the IP6_SERVICE instance.
759 Ip6CleanDefaultRouterList (
763 IP6_DEFAULT_ROUTER
*DefaultRouter
;
765 while (!IsListEmpty (&IpSb
->DefaultRouterList
)) {
766 DefaultRouter
= NET_LIST_HEAD (&IpSb
->DefaultRouterList
, IP6_DEFAULT_ROUTER
, Link
);
767 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
772 Search a default router node from an IP6 default router list.
774 @param[in] IpSb The pointer to the IP6_SERVICE instance.
775 @param[in] Ip6Address The IPv6 address of the to be searched default router node.
777 @return NULL if it failed to find the matching default router node.
778 Otherwise, point to the found default router node.
782 Ip6FindDefaultRouter (
783 IN IP6_SERVICE
*IpSb
,
784 IN EFI_IPv6_ADDRESS
*Ip6Address
788 IP6_DEFAULT_ROUTER
*DefaultRouter
;
790 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
791 ASSERT (Ip6Address
!= NULL
);
793 NET_LIST_FOR_EACH (Entry
, &IpSb
->DefaultRouterList
) {
794 DefaultRouter
= NET_LIST_USER_STRUCT (Entry
, IP6_DEFAULT_ROUTER
, Link
);
795 if (EFI_IP6_EQUAL (Ip6Address
, &DefaultRouter
->Router
)) {
796 return DefaultRouter
;
804 The function to be called after DAD (Duplicate Address Detection) is performed.
806 @param[in] IsDadPassed If TRUE, the DAD operation succeed. Otherwise, the DAD operation failed.
807 @param[in] IpIf Points to the IP6_INTERFACE.
808 @param[in] DadEntry The DAD entry which already performed DAD.
813 IN BOOLEAN IsDadPassed
,
814 IN IP6_INTERFACE
*IpIf
,
815 IN IP6_DAD_ENTRY
*DadEntry
819 IP6_ADDRESS_INFO
*AddrInfo
;
820 EFI_DHCP6_PROTOCOL
*Dhcp6
;
822 EFI_DHCP6_PACKET_OPTION
*Oro
;
823 EFI_DHCP6_RETRANSMISSION InfoReqReXmit
;
824 EFI_IPv6_ADDRESS AllNodes
;
826 IpSb
= IpIf
->Service
;
827 AddrInfo
= DadEntry
->AddressInfo
;
833 if (NetIp6IsLinkLocalAddr (&AddrInfo
->Address
)) {
834 ASSERT (!IpSb
->LinkLocalOk
);
836 IP6_COPY_ADDRESS (&IpSb
->LinkLocalAddr
, &AddrInfo
->Address
);
837 IpSb
->LinkLocalOk
= TRUE
;
838 IpIf
->Configured
= TRUE
;
841 // Check whether DHCP6 need to be started.
843 Dhcp6
= IpSb
->Ip6ConfigInstance
.Dhcp6
;
845 if (IpSb
->Dhcp6NeedStart
) {
846 Dhcp6
->Start (Dhcp6
);
847 IpSb
->Dhcp6NeedStart
= FALSE
;
850 if (IpSb
->Dhcp6NeedInfoRequest
) {
852 // Set the exta options to send. Here we only want the option request option
855 Oro
= (EFI_DHCP6_PACKET_OPTION
*) OptBuf
;
856 Oro
->OpCode
= HTONS (IP6_CONFIG_DHCP6_OPTION_ORO
);
857 Oro
->OpLen
= HTONS (2);
858 *((UINT16
*) &Oro
->Data
[0]) = HTONS (IP6_CONFIG_DHCP6_OPTION_DNS_SERVERS
);
860 InfoReqReXmit
.Irt
= 4;
861 InfoReqReXmit
.Mrc
= 64;
862 InfoReqReXmit
.Mrt
= 60;
863 InfoReqReXmit
.Mrd
= 0;
872 IpSb
->Ip6ConfigInstance
.Dhcp6Event
,
873 Ip6ConfigOnDhcp6Reply
,
874 &IpSb
->Ip6ConfigInstance
879 // Add an on-link prefix for link-local address.
881 Ip6CreatePrefixListEntry (
884 (UINT32
) IP6_INFINIT_LIFETIME
,
885 (UINT32
) IP6_INFINIT_LIFETIME
,
886 IP6_LINK_LOCAL_PREFIX_LENGTH
,
892 // Global scope unicast address.
894 Ip6AddAddr (IpIf
, AddrInfo
);
897 // Add an on-link prefix for this address.
899 Ip6CreatePrefixListEntry (
902 AddrInfo
->ValidLifetime
,
903 AddrInfo
->PreferredLifetime
,
904 AddrInfo
->PrefixLength
,
908 IpIf
->Configured
= TRUE
;
912 // Leave the group we joined before.
914 Ip6LeaveGroup (IpSb
, &DadEntry
->Destination
);
917 if (DadEntry
->Callback
!= NULL
) {
918 DadEntry
->Callback (IsDadPassed
, &AddrInfo
->Address
, DadEntry
->Context
);
921 if (!IsDadPassed
&& NetIp6IsLinkLocalAddr (&AddrInfo
->Address
)) {
923 RemoveEntryList (&DadEntry
->Link
);
926 // Leave link-scope all-nodes multicast address (FF02::1)
928 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &AllNodes
);
929 Ip6LeaveGroup (IpSb
, &AllNodes
);
931 // Disable IP operation since link-local address is a duplicate address.
933 IpSb
->LinkLocalDadFail
= TRUE
;
934 IpSb
->Mnp
->Configure (IpSb
->Mnp
, NULL
);
935 gBS
->SetTimer (IpSb
->Timer
, TimerCancel
, 0);
936 gBS
->SetTimer (IpSb
->FasterTimer
, TimerCancel
, 0);
940 if (!IsDadPassed
|| NetIp6IsLinkLocalAddr (&AddrInfo
->Address
)) {
942 // Free the AddressInfo we hold if DAD fails or it is a link-local address.
947 RemoveEntryList (&DadEntry
->Link
);
952 Create a DAD (Duplicate Address Detection) entry and queue it to be performed.
954 @param[in] IpIf Points to the IP6_INTERFACE.
955 @param[in] AddressInfo The address information which needs DAD performed.
956 @param[in] Callback The callback routine that will be called after DAD
957 is performed. This is an optional parameter that
959 @param[in] Context The opaque parameter for a DAD callback routine.
960 This is an optional parameter that may be NULL.
962 @retval EFI_SUCCESS The DAD entry was created and queued.
963 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory to complete the
970 IN IP6_INTERFACE
*IpIf
,
971 IN IP6_ADDRESS_INFO
*AddressInfo
,
972 IN IP6_DAD_CALLBACK Callback OPTIONAL
,
973 IN VOID
*Context OPTIONAL
976 IP6_DAD_ENTRY
*Entry
;
977 EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS
*DadXmits
;
982 NET_CHECK_SIGNATURE (IpIf
, IP6_INTERFACE_SIGNATURE
);
983 ASSERT (AddressInfo
!= NULL
);
985 Status
= EFI_SUCCESS
;
986 IpSb
= IpIf
->Service
;
987 DadXmits
= &IpSb
->Ip6ConfigInstance
.DadXmits
;
990 // Allocate the resources and insert info
992 Entry
= AllocatePool (sizeof (IP6_DAD_ENTRY
));
994 return EFI_OUT_OF_RESOURCES
;
998 // Map the incoming unicast address to solicited-node multicast address
1000 Ip6CreateSNMulticastAddr (&AddressInfo
->Address
, &Entry
->Destination
);
1003 // Join in the solicited-node multicast address.
1005 Status
= Ip6JoinGroup (IpSb
, IpIf
, &Entry
->Destination
);
1006 if (EFI_ERROR (Status
)) {
1011 Entry
->Signature
= IP6_DAD_ENTRY_SIGNATURE
;
1012 Entry
->MaxTransmit
= DadXmits
->DupAddrDetectTransmits
;
1013 Entry
->Transmit
= 0;
1015 MaxDelayTick
= IP6_MAX_RTR_SOLICITATION_DELAY
/ IP6_TIMER_INTERVAL_IN_MS
;
1016 Entry
->RetransTick
= (MaxDelayTick
* ((NET_RANDOM (NetRandomInitSeed ()) % 5) + 1)) / 5;
1017 Entry
->AddressInfo
= AddressInfo
;
1018 Entry
->Callback
= Callback
;
1019 Entry
->Context
= Context
;
1020 InsertTailList (&IpIf
->DupAddrDetectList
, &Entry
->Link
);
1022 if (Entry
->MaxTransmit
== 0) {
1024 // DAD is disabled on this interface, immediately mark this DAD successful.
1026 Ip6OnDADFinished (TRUE
, IpIf
, Entry
);
1033 Search IP6_DAD_ENTRY from the Duplicate Address Detection List.
1035 @param[in] IpSb The pointer to the IP6_SERVICE instance.
1036 @param[in] Target The address information which needs DAD performed .
1037 @param[out] Interface If not NULL, output the IP6 interface that configures
1038 the tentative address.
1040 @return NULL if failed to find the matching DAD entry.
1041 Otherwise, point to the found DAD entry.
1046 IN IP6_SERVICE
*IpSb
,
1047 IN EFI_IPv6_ADDRESS
*Target
,
1048 OUT IP6_INTERFACE
**Interface OPTIONAL
1053 IP6_INTERFACE
*IpIf
;
1054 IP6_DAD_ENTRY
*DupAddrDetect
;
1055 IP6_ADDRESS_INFO
*AddrInfo
;
1057 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
1058 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
1060 NET_LIST_FOR_EACH (Entry2
, &IpIf
->DupAddrDetectList
) {
1061 DupAddrDetect
= NET_LIST_USER_STRUCT_S (Entry2
, IP6_DAD_ENTRY
, Link
, IP6_DAD_ENTRY_SIGNATURE
);
1062 AddrInfo
= DupAddrDetect
->AddressInfo
;
1063 if (EFI_IP6_EQUAL (&AddrInfo
->Address
, Target
)) {
1064 if (Interface
!= NULL
) {
1067 return DupAddrDetect
;
1076 Generate router solicit message and send it out to Destination Address or
1077 All Router Link Local scope multicast address.
1079 @param[in] IpSb The IP service to send the packet.
1080 @param[in] Interface If not NULL, points to the IP6 interface to send
1082 @param[in] SourceAddress If not NULL, the source address of the message.
1083 @param[in] DestinationAddress If not NULL, the destination address of the message.
1084 @param[in] SourceLinkAddress If not NULL, the MAC address of the source.
1085 A source link-layer address option will be appended
1088 @retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
1090 @retval EFI_SUCCESS The router solicit message was successfully sent.
1094 Ip6SendRouterSolicit (
1095 IN IP6_SERVICE
*IpSb
,
1096 IN IP6_INTERFACE
*Interface OPTIONAL
,
1097 IN EFI_IPv6_ADDRESS
*SourceAddress OPTIONAL
,
1098 IN EFI_IPv6_ADDRESS
*DestinationAddress OPTIONAL
,
1099 IN EFI_MAC_ADDRESS
*SourceLinkAddress OPTIONAL
1103 EFI_IP6_HEADER Head
;
1104 IP6_ICMP_INFORMATION_HEAD
*IcmpHead
;
1105 IP6_ETHER_ADDR_OPTION
*LinkLayerOption
;
1107 IP6_INTERFACE
*IpIf
;
1109 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1112 if (IpIf
== NULL
&& IpSb
->DefaultInterface
!= NULL
) {
1113 IpIf
= IpSb
->DefaultInterface
;
1117 // Generate the packet to be sent
1120 PayloadLen
= (UINT16
) sizeof (IP6_ICMP_INFORMATION_HEAD
);
1121 if (SourceLinkAddress
!= NULL
) {
1122 PayloadLen
+= sizeof (IP6_ETHER_ADDR_OPTION
);
1125 Packet
= NetbufAlloc (sizeof (EFI_IP6_HEADER
) + (UINT32
) PayloadLen
);
1126 if (Packet
== NULL
) {
1127 return EFI_OUT_OF_RESOURCES
;
1131 // Create the basic IPv6 header.
1133 Head
.FlowLabelL
= 0;
1134 Head
.FlowLabelH
= 0;
1135 Head
.PayloadLength
= HTONS (PayloadLen
);
1136 Head
.NextHeader
= IP6_ICMP
;
1137 Head
.HopLimit
= IP6_HOP_LIMIT
;
1139 if (SourceAddress
!= NULL
) {
1140 IP6_COPY_ADDRESS (&Head
.SourceAddress
, SourceAddress
);
1142 ZeroMem (&Head
.SourceAddress
, sizeof (EFI_IPv6_ADDRESS
));
1146 if (DestinationAddress
!= NULL
) {
1147 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, DestinationAddress
);
1149 Ip6SetToAllNodeMulticast (TRUE
, IP6_LINK_LOCAL_SCOPE
, &Head
.DestinationAddress
);
1152 NetbufReserve (Packet
, sizeof (EFI_IP6_HEADER
));
1155 // Fill in the ICMP header, and Source link-layer address if contained.
1158 IcmpHead
= (IP6_ICMP_INFORMATION_HEAD
*) NetbufAllocSpace (Packet
, sizeof (IP6_ICMP_INFORMATION_HEAD
), FALSE
);
1159 ASSERT (IcmpHead
!= NULL
);
1160 ZeroMem (IcmpHead
, sizeof (IP6_ICMP_INFORMATION_HEAD
));
1161 IcmpHead
->Head
.Type
= ICMP_V6_ROUTER_SOLICIT
;
1162 IcmpHead
->Head
.Code
= 0;
1164 LinkLayerOption
= NULL
;
1165 if (SourceLinkAddress
!= NULL
) {
1166 LinkLayerOption
= (IP6_ETHER_ADDR_OPTION
*) NetbufAllocSpace (
1168 sizeof (IP6_ETHER_ADDR_OPTION
),
1171 ASSERT (LinkLayerOption
!= NULL
);
1172 LinkLayerOption
->Type
= Ip6OptionEtherSource
;
1173 LinkLayerOption
->Length
= (UINT8
) sizeof (IP6_ETHER_ADDR_OPTION
);
1174 CopyMem (LinkLayerOption
->EtherAddr
, SourceLinkAddress
, 6);
1178 // Transmit the packet
1180 return Ip6Output (IpSb
, IpIf
, NULL
, Packet
, &Head
, NULL
, 0, Ip6SysPacketSent
, NULL
);
1184 Generate a Neighbor Advertisement message and send it out to Destination Address.
1186 @param[in] IpSb The IP service to send the packet.
1187 @param[in] SourceAddress The source address of the message.
1188 @param[in] DestinationAddress The destination address of the message.
1189 @param[in] TargetIp6Address The target address field in the Neighbor Solicitation
1190 message that prompted this advertisement.
1191 @param[in] TargetLinkAddress The MAC address for the target, i.e. the sender
1192 of the advertisement.
1193 @param[in] IsRouter If TRUE, indicates the sender is a router.
1194 @param[in] Override If TRUE, indicates the advertisement should override
1195 an existing cache entry and update the MAC address.
1196 @param[in] Solicited If TRUE, indicates the advertisement was sent
1197 in response to a Neighbor Solicitation from
1198 the Destination address.
1200 @retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
1202 @retval EFI_SUCCESS The Neighbor Advertise message was successfully sent.
1206 Ip6SendNeighborAdvertise (
1207 IN IP6_SERVICE
*IpSb
,
1208 IN EFI_IPv6_ADDRESS
*SourceAddress
,
1209 IN EFI_IPv6_ADDRESS
*DestinationAddress
,
1210 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
1211 IN EFI_MAC_ADDRESS
*TargetLinkAddress
,
1212 IN BOOLEAN IsRouter
,
1213 IN BOOLEAN Override
,
1214 IN BOOLEAN Solicited
1218 EFI_IP6_HEADER Head
;
1219 IP6_ICMP_INFORMATION_HEAD
*IcmpHead
;
1220 IP6_ETHER_ADDR_OPTION
*LinkLayerOption
;
1221 EFI_IPv6_ADDRESS
*Target
;
1224 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1227 // The Neighbor Advertisement message must include a Target link-layer address option
1228 // when responding to multicast solicitation and should include such option when
1229 // responding to unicast solicitation. It also must include such option as unsolicited
1232 ASSERT (DestinationAddress
!= NULL
&& TargetIp6Address
!= NULL
&& TargetLinkAddress
!= NULL
);
1234 PayloadLen
= (UINT16
) (sizeof (IP6_ICMP_INFORMATION_HEAD
) + sizeof (EFI_IPv6_ADDRESS
) + sizeof (IP6_ETHER_ADDR_OPTION
));
1237 // Generate the packet to be sent
1240 Packet
= NetbufAlloc (sizeof (EFI_IP6_HEADER
) + (UINT32
) PayloadLen
);
1241 if (Packet
== NULL
) {
1242 return EFI_OUT_OF_RESOURCES
;
1246 // Create the basic IPv6 header.
1248 Head
.FlowLabelL
= 0;
1249 Head
.FlowLabelH
= 0;
1250 Head
.PayloadLength
= HTONS (PayloadLen
);
1251 Head
.NextHeader
= IP6_ICMP
;
1252 Head
.HopLimit
= IP6_HOP_LIMIT
;
1254 IP6_COPY_ADDRESS (&Head
.SourceAddress
, SourceAddress
);
1255 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, DestinationAddress
);
1257 NetbufReserve (Packet
, sizeof (EFI_IP6_HEADER
));
1260 // Fill in the ICMP header, Target address, and Target link-layer address.
1261 // Set the Router flag, Solicited flag and Override flag.
1264 IcmpHead
= (IP6_ICMP_INFORMATION_HEAD
*) NetbufAllocSpace (Packet
, sizeof (IP6_ICMP_INFORMATION_HEAD
), FALSE
);
1265 ASSERT (IcmpHead
!= NULL
);
1266 ZeroMem (IcmpHead
, sizeof (IP6_ICMP_INFORMATION_HEAD
));
1267 IcmpHead
->Head
.Type
= ICMP_V6_NEIGHBOR_ADVERTISE
;
1268 IcmpHead
->Head
.Code
= 0;
1271 IcmpHead
->Fourth
|= IP6_IS_ROUTER_FLAG
;
1275 IcmpHead
->Fourth
|= IP6_SOLICITED_FLAG
;
1279 IcmpHead
->Fourth
|= IP6_OVERRIDE_FLAG
;
1282 Target
= (EFI_IPv6_ADDRESS
*) NetbufAllocSpace (Packet
, sizeof (EFI_IPv6_ADDRESS
), FALSE
);
1283 ASSERT (Target
!= NULL
);
1284 IP6_COPY_ADDRESS (Target
, TargetIp6Address
);
1286 LinkLayerOption
= (IP6_ETHER_ADDR_OPTION
*) NetbufAllocSpace (
1288 sizeof (IP6_ETHER_ADDR_OPTION
),
1291 ASSERT (LinkLayerOption
!= NULL
);
1292 LinkLayerOption
->Type
= Ip6OptionEtherTarget
;
1293 LinkLayerOption
->Length
= 1;
1294 CopyMem (LinkLayerOption
->EtherAddr
, TargetLinkAddress
, 6);
1297 // Transmit the packet
1299 return Ip6Output (IpSb
, NULL
, NULL
, Packet
, &Head
, NULL
, 0, Ip6SysPacketSent
, NULL
);
1303 Generate the Neighbor Solicitation message and send it to the Destination Address.
1305 @param[in] IpSb The IP service to send the packet
1306 @param[in] SourceAddress The source address of the message.
1307 @param[in] DestinationAddress The destination address of the message.
1308 @param[in] TargetIp6Address The IP address of the target of the solicitation.
1309 It must not be a multicast address.
1310 @param[in] SourceLinkAddress The MAC address for the sender. If not NULL,
1311 a source link-layer address option will be appended
1314 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1315 @retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
1317 @retval EFI_SUCCESS The Neighbor Advertise message was successfully sent.
1321 Ip6SendNeighborSolicit (
1322 IN IP6_SERVICE
*IpSb
,
1323 IN EFI_IPv6_ADDRESS
*SourceAddress
,
1324 IN EFI_IPv6_ADDRESS
*DestinationAddress
,
1325 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
1326 IN EFI_MAC_ADDRESS
*SourceLinkAddress OPTIONAL
1330 EFI_IP6_HEADER Head
;
1331 IP6_ICMP_INFORMATION_HEAD
*IcmpHead
;
1332 IP6_ETHER_ADDR_OPTION
*LinkLayerOption
;
1333 EFI_IPv6_ADDRESS
*Target
;
1336 IP6_NEIGHBOR_ENTRY
*Neighbor
;
1339 // Check input parameters
1341 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
1342 if (DestinationAddress
== NULL
|| TargetIp6Address
== NULL
) {
1343 return EFI_INVALID_PARAMETER
;
1348 if (SourceAddress
== NULL
|| (SourceAddress
!= NULL
&& NetIp6IsUnspecifiedAddr (SourceAddress
))) {
1353 // The Neighbor Solicitation message should include a source link-layer address option
1354 // if the solicitation is not sent by performing DAD - Duplicate Address Detection.
1355 // Otherwise must not include it.
1357 PayloadLen
= (UINT16
) (sizeof (IP6_ICMP_INFORMATION_HEAD
) + sizeof (EFI_IPv6_ADDRESS
));
1360 if (SourceLinkAddress
== NULL
) {
1361 return EFI_INVALID_PARAMETER
;
1364 PayloadLen
= (UINT16
) (PayloadLen
+ sizeof (IP6_ETHER_ADDR_OPTION
));
1368 // Generate the packet to be sent
1371 Packet
= NetbufAlloc (sizeof (EFI_IP6_HEADER
) + (UINT32
) PayloadLen
);
1372 if (Packet
== NULL
) {
1373 return EFI_OUT_OF_RESOURCES
;
1377 // Create the basic IPv6 header
1379 Head
.FlowLabelL
= 0;
1380 Head
.FlowLabelH
= 0;
1381 Head
.PayloadLength
= HTONS (PayloadLen
);
1382 Head
.NextHeader
= IP6_ICMP
;
1383 Head
.HopLimit
= IP6_HOP_LIMIT
;
1385 if (SourceAddress
!= NULL
) {
1386 IP6_COPY_ADDRESS (&Head
.SourceAddress
, SourceAddress
);
1388 ZeroMem (&Head
.SourceAddress
, sizeof (EFI_IPv6_ADDRESS
));
1391 IP6_COPY_ADDRESS (&Head
.DestinationAddress
, DestinationAddress
);
1393 NetbufReserve (Packet
, sizeof (EFI_IP6_HEADER
));
1396 // Fill in the ICMP header, Target address, and Source link-layer address.
1398 IcmpHead
= (IP6_ICMP_INFORMATION_HEAD
*) NetbufAllocSpace (Packet
, sizeof (IP6_ICMP_INFORMATION_HEAD
), FALSE
);
1399 ASSERT (IcmpHead
!= NULL
);
1400 ZeroMem (IcmpHead
, sizeof (IP6_ICMP_INFORMATION_HEAD
));
1401 IcmpHead
->Head
.Type
= ICMP_V6_NEIGHBOR_SOLICIT
;
1402 IcmpHead
->Head
.Code
= 0;
1404 Target
= (EFI_IPv6_ADDRESS
*) NetbufAllocSpace (Packet
, sizeof (EFI_IPv6_ADDRESS
), FALSE
);
1405 ASSERT (Target
!= NULL
);
1406 IP6_COPY_ADDRESS (Target
, TargetIp6Address
);
1408 LinkLayerOption
= NULL
;
1412 // Fill in the source link-layer address option
1414 LinkLayerOption
= (IP6_ETHER_ADDR_OPTION
*) NetbufAllocSpace (
1416 sizeof (IP6_ETHER_ADDR_OPTION
),
1419 ASSERT (LinkLayerOption
!= NULL
);
1420 LinkLayerOption
->Type
= Ip6OptionEtherSource
;
1421 LinkLayerOption
->Length
= 1;
1422 CopyMem (LinkLayerOption
->EtherAddr
, SourceLinkAddress
, 6);
1426 // Create a Neighbor Cache entry in the INCOMPLETE state when performing
1427 // address resolution.
1429 if (!IsDAD
&& Ip6IsSNMulticastAddr (DestinationAddress
)) {
1430 Neighbor
= Ip6FindNeighborEntry (IpSb
, TargetIp6Address
);
1431 if (Neighbor
== NULL
) {
1432 Neighbor
= Ip6CreateNeighborEntry (IpSb
, Ip6OnArpResolved
, TargetIp6Address
, NULL
);
1433 ASSERT (Neighbor
!= NULL
);
1438 // Transmit the packet
1440 return Ip6Output (IpSb
, IpSb
->DefaultInterface
, NULL
, Packet
, &Head
, NULL
, 0, Ip6SysPacketSent
, NULL
);
1444 Process the Neighbor Solicitation message. The message may be sent for Duplicate
1445 Address Detection or Address Resolution.
1447 @param[in] IpSb The IP service that received the packet.
1448 @param[in] Head The IP head of the message.
1449 @param[in] Packet The content of the message with IP head removed.
1451 @retval EFI_SUCCESS The packet processed successfully.
1452 @retval EFI_INVALID_PARAMETER The packet is invalid.
1453 @retval EFI_ICMP_ERROR The packet indicates that DAD is failed.
1454 @retval Others Failed to process the packet.
1458 Ip6ProcessNeighborSolicit (
1459 IN IP6_SERVICE
*IpSb
,
1460 IN EFI_IP6_HEADER
*Head
,
1464 IP6_ICMP_INFORMATION_HEAD Icmp
;
1465 EFI_IPv6_ADDRESS Target
;
1466 IP6_ETHER_ADDR_OPTION LinkLayerOption
;
1469 BOOLEAN IsMaintained
;
1470 IP6_DAD_ENTRY
*DupAddrDetect
;
1471 IP6_INTERFACE
*IpIf
;
1472 IP6_NEIGHBOR_ENTRY
*Neighbor
;
1474 BOOLEAN UpdateCache
;
1475 EFI_IPv6_ADDRESS Dest
;
1482 NetbufCopy (Packet
, 0, sizeof (Icmp
), (UINT8
*) &Icmp
);
1483 NetbufCopy (Packet
, sizeof (Icmp
), sizeof (Target
), Target
.Addr
);
1486 // Perform Message Validation:
1487 // The IP Hop Limit field has a value of 255, i.e., the packet
1488 // could not possibly have been forwarded by a router.
1490 // Target Address is not a multicast address.
1492 Status
= EFI_INVALID_PARAMETER
;
1494 if (Head
->HopLimit
!= IP6_HOP_LIMIT
|| Icmp
.Head
.Code
!= 0 || !NetIp6IsValidUnicast (&Target
)) {
1499 // ICMP length is 24 or more octets.
1502 if (Head
->PayloadLength
< IP6_ND_LENGTH
) {
1505 OptionLen
= (UINT16
) (Head
->PayloadLength
- IP6_ND_LENGTH
);
1506 if (OptionLen
!= 0) {
1507 Option
= NetbufGetByte (Packet
, IP6_ND_LENGTH
, NULL
);
1508 ASSERT (Option
!= NULL
);
1511 // All included options should have a length that is greater than zero.
1513 if (!Ip6IsNDOptionValid (Option
, OptionLen
)) {
1519 IsDAD
= NetIp6IsUnspecifiedAddr (&Head
->SourceAddress
);
1520 IsUnicast
= (BOOLEAN
) !Ip6IsSNMulticastAddr (&Head
->DestinationAddress
);
1521 IsMaintained
= Ip6IsOneOfSetAddress (IpSb
, &Target
, &IpIf
, NULL
);
1524 if (OptionLen
>= sizeof (IP6_ETHER_ADDR_OPTION
)) {
1528 sizeof (IP6_ETHER_ADDR_OPTION
),
1529 (UINT8
*) &LinkLayerOption
1532 // The solicitation for neighbor discovery should include a source link-layer
1533 // address option. If the option is not recognized, silently ignore it.
1535 if (LinkLayerOption
.Type
== Ip6OptionEtherSource
) {
1538 // If the IP source address is the unspecified address, the source
1539 // link-layer address option must not be included in the message.
1549 // If the IP source address is the unspecified address, the IP
1550 // destination address is a solicited-node multicast address.
1552 if (IsDAD
&& IsUnicast
) {
1557 // If the target address is tentative, and the source address is a unicast address,
1558 // the solicitation's sender is performing address resolution on the target;
1559 // the solicitation should be silently ignored.
1561 if (!IsDAD
&& !IsMaintained
) {
1566 // If received unicast neighbor solicitation but destination is not this node,
1569 if (IsUnicast
&& !IsMaintained
) {
1574 // In DAD, when target address is a tentative address,
1575 // process the received neighbor solicitation message but not send out response.
1577 if (IsDAD
&& !IsMaintained
) {
1578 DupAddrDetect
= Ip6FindDADEntry (IpSb
, &Target
, &IpIf
);
1579 if (DupAddrDetect
!= NULL
) {
1580 if (DupAddrDetect
->Transmit
== 0) {
1582 // The NS is from another node to performing DAD on the same address since
1583 // we haven't send out any NS yet. Fail DAD for the tentative address.
1585 Ip6OnDADFinished (FALSE
, IpIf
, DupAddrDetect
);
1586 Status
= EFI_ICMP_ERROR
;
1591 // Check the MAC address of the incoming packet.
1593 if (IpSb
->RecvRequest
.MnpToken
.Packet
.RxData
== NULL
) {
1597 MacAddress
= IpSb
->RecvRequest
.MnpToken
.Packet
.RxData
->SourceAddress
;
1598 if (MacAddress
!= NULL
) {
1601 &IpSb
->SnpMode
.CurrentAddress
,
1602 IpSb
->SnpMode
.HwAddressSize
1605 // The NS is from another node to performing DAD on the same address.
1606 // Fail DAD for the tentative address.
1608 Ip6OnDADFinished (FALSE
, IpIf
, DupAddrDetect
);
1609 Status
= EFI_ICMP_ERROR
;
1612 // The below layer loopback the NS we sent. Record it and wait for more.
1614 DupAddrDetect
->Receive
++;
1615 Status
= EFI_SUCCESS
;
1623 // If the solicitation does not contain a link-layer address, DO NOT create or
1624 // update the neighbor cache entries.
1627 Neighbor
= Ip6FindNeighborEntry (IpSb
, &Head
->SourceAddress
);
1628 UpdateCache
= FALSE
;
1630 if (Neighbor
== NULL
) {
1631 Neighbor
= Ip6CreateNeighborEntry (IpSb
, Ip6OnArpResolved
, &Head
->SourceAddress
, NULL
);
1632 if (Neighbor
== NULL
) {
1633 Status
= EFI_OUT_OF_RESOURCES
;
1638 if (CompareMem (Neighbor
->LinkAddress
.Addr
, LinkLayerOption
.EtherAddr
, 6) != 0) {
1644 Neighbor
->State
= EfiNeighborStale
;
1645 Neighbor
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
1646 CopyMem (Neighbor
->LinkAddress
.Addr
, LinkLayerOption
.EtherAddr
, 6);
1648 // Send queued packets if exist.
1650 Neighbor
->CallBack ((VOID
*) Neighbor
);
1655 // Sends a Neighbor Advertisement as response.
1656 // Set the Router flag to zero since the node is a host.
1657 // If the source address of the solicitation is unspeicifed, and target address
1658 // is one of the maintained address, reply a unsolicited multicast advertisement.
1660 if (IsDAD
&& IsMaintained
) {
1662 Ip6SetToAllNodeMulticast (FALSE
, IP6_LINK_LOCAL_SCOPE
, &Dest
);
1665 IP6_COPY_ADDRESS (&Dest
, &Head
->SourceAddress
);
1668 Status
= Ip6SendNeighborAdvertise (
1673 &IpSb
->SnpMode
.CurrentAddress
,
1679 NetbufFree (Packet
);
1684 Process the Neighbor Advertisement message.
1686 @param[in] IpSb The IP service that received the packet.
1687 @param[in] Head The IP head of the message.
1688 @param[in] Packet The content of the message with IP head removed.
1690 @retval EFI_SUCCESS The packet processed successfully.
1691 @retval EFI_INVALID_PARAMETER The packet is invalid.
1692 @retval EFI_ICMP_ERROR The packet indicates that DAD is failed.
1693 @retval Others Failed to process the packet.
1697 Ip6ProcessNeighborAdvertise (
1698 IN IP6_SERVICE
*IpSb
,
1699 IN EFI_IP6_HEADER
*Head
,
1703 IP6_ICMP_INFORMATION_HEAD Icmp
;
1704 EFI_IPv6_ADDRESS Target
;
1705 IP6_ETHER_ADDR_OPTION LinkLayerOption
;
1708 IP6_NEIGHBOR_ENTRY
*Neighbor
;
1709 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1713 IP6_DAD_ENTRY
*DupAddrDetect
;
1714 IP6_INTERFACE
*IpIf
;
1719 NetbufCopy (Packet
, 0, sizeof (Icmp
), (UINT8
*) &Icmp
);
1720 NetbufCopy (Packet
, sizeof (Icmp
), sizeof (Target
), Target
.Addr
);
1723 // Validate the incoming Neighbor Advertisement
1725 Status
= EFI_INVALID_PARAMETER
;
1727 // The IP Hop Limit field has a value of 255, i.e., the packet
1728 // could not possibly have been forwarded by a router.
1730 // Target Address is not a multicast address.
1732 if (Head
->HopLimit
!= IP6_HOP_LIMIT
|| Icmp
.Head
.Code
!= 0 || !NetIp6IsValidUnicast (&Target
)) {
1737 // ICMP length is 24 or more octets.
1741 if (Head
->PayloadLength
< IP6_ND_LENGTH
) {
1744 OptionLen
= (UINT16
) (Head
->PayloadLength
- IP6_ND_LENGTH
);
1745 if (OptionLen
!= 0) {
1746 Option
= NetbufGetByte (Packet
, IP6_ND_LENGTH
, NULL
);
1747 ASSERT (Option
!= NULL
);
1750 // All included options should have a length that is greater than zero.
1752 if (!Ip6IsNDOptionValid (Option
, OptionLen
)) {
1759 // If the IP destination address is a multicast address, Solicited Flag is ZERO.
1762 if ((Icmp
.Fourth
& IP6_SOLICITED_FLAG
) == IP6_SOLICITED_FLAG
) {
1765 if (IP6_IS_MULTICAST (&Head
->DestinationAddress
) && Solicited
) {
1770 // DAD - Check whether the Target is one of our tentative address.
1772 DupAddrDetect
= Ip6FindDADEntry (IpSb
, &Target
, &IpIf
);
1773 if (DupAddrDetect
!= NULL
) {
1775 // DAD fails, some other node is using this address.
1777 NetbufFree (Packet
);
1778 Ip6OnDADFinished (FALSE
, IpIf
, DupAddrDetect
);
1779 return EFI_ICMP_ERROR
;
1783 // Search the Neighbor Cache for the target's entry. If no entry exists,
1784 // the advertisement should be silently discarded.
1786 Neighbor
= Ip6FindNeighborEntry (IpSb
, &Target
);
1787 if (Neighbor
== NULL
) {
1792 // Get IsRouter Flag and Override Flag
1796 if ((Icmp
.Fourth
& IP6_IS_ROUTER_FLAG
) == IP6_IS_ROUTER_FLAG
) {
1799 if ((Icmp
.Fourth
& IP6_OVERRIDE_FLAG
) == IP6_OVERRIDE_FLAG
) {
1804 // Check whether link layer option is included.
1806 if (OptionLen
>= sizeof (IP6_ETHER_ADDR_OPTION
)) {
1810 sizeof (IP6_ETHER_ADDR_OPTION
),
1811 (UINT8
*) &LinkLayerOption
1814 if (LinkLayerOption
.Type
== Ip6OptionEtherTarget
) {
1821 Compare
= CompareMem (Neighbor
->LinkAddress
.Addr
, LinkLayerOption
.EtherAddr
, 6);
1824 if (!Neighbor
->IsRouter
&& IsRouter
) {
1825 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, &Target
);
1826 if (DefaultRouter
!= NULL
) {
1827 DefaultRouter
->NeighborCache
= Neighbor
;
1831 if (Neighbor
->State
== EfiNeighborInComplete
) {
1833 // If the target's Neighbor Cache entry is in INCOMPLETE state and no
1834 // Target Link-Layer address option is included while link layer has
1835 // address, the message should be silently discarded.
1841 // Update the Neighbor Cache
1843 CopyMem (Neighbor
->LinkAddress
.Addr
, LinkLayerOption
.EtherAddr
, 6);
1845 Neighbor
->State
= EfiNeighborReachable
;
1846 Neighbor
->Ticks
= IP6_GET_TICKS (IpSb
->ReachableTime
);
1848 Neighbor
->State
= EfiNeighborStale
;
1849 Neighbor
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
1851 // Send any packets queued for the neighbor awaiting address resolution.
1853 Neighbor
->CallBack ((VOID
*) Neighbor
);
1856 Neighbor
->IsRouter
= IsRouter
;
1859 if (!Override
&& Compare
!= 0) {
1861 // When the Override Flag is clear and supplied link-layer address differs from
1862 // that in the cache, if the state of the entry is not REACHABLE, ignore the
1863 // message. Otherwise set it to STALE but do not update the entry in any
1866 if (Neighbor
->State
== EfiNeighborReachable
) {
1867 Neighbor
->State
= EfiNeighborStale
;
1868 Neighbor
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
1872 CopyMem (Neighbor
->LinkAddress
.Addr
, LinkLayerOption
.EtherAddr
, 6);
1875 // Update the entry's state
1878 Neighbor
->State
= EfiNeighborReachable
;
1879 Neighbor
->Ticks
= IP6_GET_TICKS (IpSb
->ReachableTime
);
1882 Neighbor
->State
= EfiNeighborStale
;
1883 Neighbor
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
1888 // When IsRouter is changed from TRUE to FALSE, remove the router from the
1889 // Default Router List and remove the Destination Cache entries for all destinations
1890 // using the neighbor as a router.
1892 if (Neighbor
->IsRouter
&& !IsRouter
) {
1893 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, &Target
);
1894 if (DefaultRouter
!= NULL
) {
1895 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
1899 Neighbor
->IsRouter
= IsRouter
;
1903 if (Neighbor
->State
== EfiNeighborReachable
) {
1904 Neighbor
->CallBack ((VOID
*) Neighbor
);
1907 Status
= EFI_SUCCESS
;
1910 NetbufFree (Packet
);
1915 Process the Router Advertisement message according to RFC4861.
1917 @param[in] IpSb The IP service that received the packet.
1918 @param[in] Head The IP head of the message.
1919 @param[in] Packet The content of the message with the IP head removed.
1921 @retval EFI_SUCCESS The packet processed successfully.
1922 @retval EFI_INVALID_PARAMETER The packet is invalid.
1923 @retval EFI_OUT_OF_RESOURCES Insufficient resources to complete the
1925 @retval Others Failed to process the packet.
1929 Ip6ProcessRouterAdvertise (
1930 IN IP6_SERVICE
*IpSb
,
1931 IN EFI_IP6_HEADER
*Head
,
1935 IP6_ICMP_INFORMATION_HEAD Icmp
;
1936 UINT32 ReachableTime
;
1937 UINT32 RetransTimer
;
1938 UINT16 RouterLifetime
;
1942 IP6_ETHER_ADDR_OPTION LinkLayerOption
;
1947 IP6_DEFAULT_ROUTER
*DefaultRouter
;
1948 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
1949 EFI_MAC_ADDRESS LinkLayerAddress
;
1950 IP6_MTU_OPTION MTUOption
;
1951 IP6_PREFIX_INFO_OPTION PrefixOption
;
1952 IP6_PREFIX_LIST_ENTRY
*PrefixList
;
1955 EFI_IPv6_ADDRESS StatelessAddress
;
1961 Status
= EFI_INVALID_PARAMETER
;
1963 if (IpSb
->Ip6ConfigInstance
.Policy
!= Ip6ConfigPolicyAutomatic
) {
1965 // Skip the process below as it's not required under the current policy.
1970 NetbufCopy (Packet
, 0, sizeof (Icmp
), (UINT8
*) &Icmp
);
1973 // Validate the incoming Router Advertisement
1977 // The IP source address must be a link-local address
1979 if (!NetIp6IsLinkLocalAddr (&Head
->SourceAddress
)) {
1983 // The IP Hop Limit field has a value of 255, i.e. the packet
1984 // could not possibly have been forwarded by a router.
1986 // ICMP length (derived from the IP length) is 16 or more octets.
1988 if (Head
->HopLimit
!= IP6_HOP_LIMIT
|| Icmp
.Head
.Code
!= 0 ||
1989 Head
->PayloadLength
< IP6_RA_LENGTH
) {
1994 // All included options have a length that is greater than zero.
1996 OptionLen
= (UINT16
) (Head
->PayloadLength
- IP6_RA_LENGTH
);
1997 if (OptionLen
!= 0) {
1998 Option
= NetbufGetByte (Packet
, IP6_RA_LENGTH
, NULL
);
1999 ASSERT (Option
!= NULL
);
2001 if (!Ip6IsNDOptionValid (Option
, OptionLen
)) {
2007 // Process Fourth field.
2008 // In Router Advertisement, Fourth is composed of CurHopLimit (8bit), M flag, O flag,
2009 // and Router Lifetime (16 bit).
2012 Fourth
= NTOHL (Icmp
.Fourth
);
2013 CopyMem (&RouterLifetime
, &Fourth
, sizeof (UINT16
));
2016 // If the source address already in the default router list, update it.
2017 // Otherwise create a new entry.
2018 // A Lifetime of zero indicates that the router is not a default router.
2020 DefaultRouter
= Ip6FindDefaultRouter (IpSb
, &Head
->SourceAddress
);
2021 if (DefaultRouter
== NULL
) {
2022 if (RouterLifetime
!= 0) {
2023 DefaultRouter
= Ip6CreateDefaultRouter (IpSb
, &Head
->SourceAddress
, RouterLifetime
);
2024 if (DefaultRouter
== NULL
) {
2025 Status
= EFI_OUT_OF_RESOURCES
;
2030 if (RouterLifetime
!= 0) {
2031 DefaultRouter
->Lifetime
= RouterLifetime
;
2033 // Check the corresponding neighbor cache entry here.
2035 if (DefaultRouter
->NeighborCache
== NULL
) {
2036 DefaultRouter
->NeighborCache
= Ip6FindNeighborEntry (IpSb
, &Head
->SourceAddress
);
2040 // If the address is in the host's default router list and the router lifetime is zero,
2041 // immediately time-out the entry.
2043 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
2047 CurHopLimit
= *((UINT8
*) &Fourth
+ 3);
2048 if (CurHopLimit
!= 0) {
2049 IpSb
->CurHopLimit
= CurHopLimit
;
2054 if ((*((UINT8
*) &Fourth
+ 2) & IP6_M_ADDR_CONFIG_FLAG
) == IP6_M_ADDR_CONFIG_FLAG
) {
2057 if ((*((UINT8
*) &Fourth
+ 2) & IP6_O_CONFIG_FLAG
) == IP6_O_CONFIG_FLAG
) {
2062 if (Mflag
|| Oflag
) {
2064 // Use Ip6Config to get available addresses or other configuration from DHCP.
2066 Ip6ConfigStartStatefulAutoConfig (&IpSb
->Ip6ConfigInstance
, Oflag
);
2070 // Process Reachable Time and Retrans Timer fields.
2072 NetbufCopy (Packet
, sizeof (Icmp
), sizeof (UINT32
), (UINT8
*) &ReachableTime
);
2073 NetbufCopy (Packet
, sizeof (Icmp
) + sizeof (UINT32
), sizeof (UINT32
), (UINT8
*) &RetransTimer
);
2074 ReachableTime
= NTOHL (ReachableTime
);
2075 RetransTimer
= NTOHL (RetransTimer
);
2077 if (ReachableTime
!= 0 && ReachableTime
!= IpSb
->BaseReachableTime
) {
2079 // If new value is not unspecified and differs from the previous one, record it
2080 // in BaseReachableTime and recompute a ReachableTime.
2082 IpSb
->BaseReachableTime
= ReachableTime
;
2083 Ip6UpdateReachableTime (IpSb
);
2086 if (RetransTimer
!= 0) {
2087 IpSb
->RetransTimer
= RetransTimer
;
2091 // IsRouter flag must be set to TRUE if corresponding neighbor cache entry exists.
2093 NeighborCache
= Ip6FindNeighborEntry (IpSb
, &Head
->SourceAddress
);
2094 if (NeighborCache
!= NULL
) {
2095 NeighborCache
->IsRouter
= TRUE
;
2099 // If an valid router advertisment is received, stops router solicitation.
2101 IpSb
->RouterAdvertiseReceived
= TRUE
;
2104 // The only defined options that may appear are the Source
2105 // Link-Layer Address, Prefix information and MTU options.
2106 // All included options have a length that is greater than zero.
2109 while (Offset
< Head
->PayloadLength
) {
2110 NetbufCopy (Packet
, Offset
, sizeof (UINT8
), &Type
);
2112 case Ip6OptionEtherSource
:
2114 // Update the neighbor cache
2116 NetbufCopy (Packet
, Offset
, sizeof (IP6_ETHER_ADDR_OPTION
), (UINT8
*) &LinkLayerOption
);
2117 if (LinkLayerOption
.Length
<= 0) {
2121 ZeroMem (&LinkLayerAddress
, sizeof (EFI_MAC_ADDRESS
));
2122 CopyMem (&LinkLayerAddress
, LinkLayerOption
.EtherAddr
, 6);
2124 if (NeighborCache
== NULL
) {
2125 NeighborCache
= Ip6CreateNeighborEntry (
2128 &Head
->SourceAddress
,
2131 if (NeighborCache
== NULL
) {
2132 Status
= EFI_OUT_OF_RESOURCES
;
2135 NeighborCache
->IsRouter
= TRUE
;
2136 NeighborCache
->State
= EfiNeighborStale
;
2137 NeighborCache
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2139 Result
= CompareMem (&LinkLayerAddress
, &NeighborCache
->LinkAddress
, 6);
2142 // If the link-local address is the same as that already in the cache,
2143 // the cache entry's state remains unchanged. Otherwise update the
2144 // reachability state to STALE.
2146 if ((NeighborCache
->State
== EfiNeighborInComplete
) || (Result
!= 0)) {
2147 CopyMem (&NeighborCache
->LinkAddress
, &LinkLayerAddress
, 6);
2149 NeighborCache
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2151 if (NeighborCache
->State
== EfiNeighborInComplete
) {
2153 // Send queued packets if exist.
2155 NeighborCache
->State
= EfiNeighborStale
;
2156 NeighborCache
->CallBack ((VOID
*) NeighborCache
);
2158 NeighborCache
->State
= EfiNeighborStale
;
2163 Offset
= (UINT16
) (Offset
+ (UINT16
) LinkLayerOption
.Length
* 8);
2165 case Ip6OptionPrefixInfo
:
2166 NetbufCopy (Packet
, Offset
, sizeof (IP6_PREFIX_INFO_OPTION
), (UINT8
*) &PrefixOption
);
2167 if (PrefixOption
.Length
!= 4) {
2170 PrefixOption
.ValidLifetime
= NTOHL (PrefixOption
.ValidLifetime
);
2171 PrefixOption
.PreferredLifetime
= NTOHL (PrefixOption
.PreferredLifetime
);
2174 // Get L and A flag, recorded in the lower 2 bits of Reserved1
2177 if ((PrefixOption
.Reserved1
& IP6_ON_LINK_FLAG
) == IP6_ON_LINK_FLAG
) {
2181 if ((PrefixOption
.Reserved1
& IP6_AUTO_CONFIG_FLAG
) == IP6_AUTO_CONFIG_FLAG
) {
2186 // If the prefix is the link-local prefix, silently ignore the prefix option.
2188 if (PrefixOption
.PrefixLength
== IP6_LINK_LOCAL_PREFIX_LENGTH
&&
2189 NetIp6IsLinkLocalAddr (&PrefixOption
.Prefix
)
2191 Offset
+= sizeof (IP6_PREFIX_INFO_OPTION
);
2195 // Do following if on-link flag is set according to RFC4861.
2198 PrefixList
= Ip6FindPrefixListEntry (
2201 PrefixOption
.PrefixLength
,
2202 &PrefixOption
.Prefix
2205 // Create a new entry for the prefix, if the ValidLifetime is zero,
2206 // silently ignore the prefix option.
2208 if (PrefixList
== NULL
&& PrefixOption
.ValidLifetime
!= 0) {
2209 PrefixList
= Ip6CreatePrefixListEntry (
2212 PrefixOption
.ValidLifetime
,
2213 PrefixOption
.PreferredLifetime
,
2214 PrefixOption
.PrefixLength
,
2215 &PrefixOption
.Prefix
2217 if (PrefixList
== NULL
) {
2218 Status
= EFI_OUT_OF_RESOURCES
;
2221 } else if (PrefixList
!= NULL
) {
2222 if (PrefixOption
.ValidLifetime
!= 0) {
2223 PrefixList
->ValidLifetime
= PrefixOption
.ValidLifetime
;
2226 // If the prefix exists and incoming ValidLifetime is zero, immediately
2227 // remove the prefix.
2228 Ip6DestroyPrefixListEntry (IpSb
, PrefixList
, OnLink
, TRUE
);
2234 // Do following if Autonomous flag is set according to RFC4862.
2236 if (Autonomous
&& PrefixOption
.PreferredLifetime
<= PrefixOption
.ValidLifetime
) {
2237 PrefixList
= Ip6FindPrefixListEntry (
2240 PrefixOption
.PrefixLength
,
2241 &PrefixOption
.Prefix
2244 // Create a new entry for the prefix, and form an address by prefix + interface id
2245 // If the sum of the prefix length and interface identifier length
2246 // does not equal 128 bits, the Prefix Information option MUST be ignored.
2248 if (PrefixList
== NULL
&&
2249 PrefixOption
.ValidLifetime
!= 0 &&
2250 PrefixOption
.PrefixLength
+ IpSb
->InterfaceIdLen
* 8 == 128
2253 // Form the address in network order.
2255 CopyMem (&StatelessAddress
, &PrefixOption
.Prefix
, sizeof (UINT64
));
2256 CopyMem (&StatelessAddress
.Addr
[8], IpSb
->InterfaceId
, sizeof (UINT64
));
2259 // If the address is not yet in the assigned address list, adds it into.
2261 if (!Ip6IsOneOfSetAddress (IpSb
, &StatelessAddress
, NULL
, NULL
)) {
2263 // And also not in the DAD process, check its uniqeness firstly.
2265 if (Ip6FindDADEntry (IpSb
, &StatelessAddress
, NULL
) == NULL
) {
2266 Status
= Ip6SetAddress (
2267 IpSb
->DefaultInterface
,
2270 PrefixOption
.PrefixLength
,
2271 PrefixOption
.ValidLifetime
,
2272 PrefixOption
.PreferredLifetime
,
2276 if (EFI_ERROR (Status
)) {
2283 // Adds the prefix option to stateless prefix option list.
2285 PrefixList
= Ip6CreatePrefixListEntry (
2288 PrefixOption
.ValidLifetime
,
2289 PrefixOption
.PreferredLifetime
,
2290 PrefixOption
.PrefixLength
,
2291 &PrefixOption
.Prefix
2293 if (PrefixList
== NULL
) {
2294 Status
= EFI_OUT_OF_RESOURCES
;
2297 } else if (PrefixList
!= NULL
) {
2300 // Reset the preferred lifetime of the address if the advertised prefix exists.
2301 // Perform specific action to valid lifetime together.
2303 PrefixList
->PreferredLifetime
= PrefixOption
.PreferredLifetime
;
2304 if ((PrefixOption
.ValidLifetime
> 7200) ||
2305 (PrefixOption
.ValidLifetime
> PrefixList
->ValidLifetime
)) {
2307 // If the received Valid Lifetime is greater than 2 hours or
2308 // greater than RemainingLifetime, set the valid lifetime of the
2309 // corresponding address to the advertised Valid Lifetime.
2311 PrefixList
->ValidLifetime
= PrefixOption
.ValidLifetime
;
2313 } else if (PrefixList
->ValidLifetime
<= 7200) {
2315 // If RemainingLifetime is less than or equls to 2 hours, ignore the
2316 // Prefix Information option with regards to the valid lifetime.
2317 // TODO: If this option has been authenticated, set the valid lifetime.
2321 // Otherwise, reset the valid lifetime of the corresponding
2322 // address to 2 hours.
2324 PrefixList
->ValidLifetime
= 7200;
2329 Offset
+= sizeof (IP6_PREFIX_INFO_OPTION
);
2332 NetbufCopy (Packet
, Offset
, sizeof (IP6_MTU_OPTION
), (UINT8
*) &MTUOption
);
2333 if (MTUOption
.Length
!= 1) {
2338 // Use IPv6 minimum link MTU 1280 bytes as the maximum packet size in order
2339 // to omit implementation of Path MTU Discovery. Thus ignore the MTU option
2340 // in Router Advertisement.
2343 Offset
+= sizeof (IP6_MTU_OPTION
);
2347 // Silently ignore unrecognized options
2349 NetbufCopy (Packet
, Offset
+ sizeof (UINT8
), sizeof (UINT8
), &Length
);
2354 Offset
= (UINT16
) (Offset
+ (UINT16
) Length
* 8);
2359 Status
= EFI_SUCCESS
;
2362 NetbufFree (Packet
);
2367 Process the ICMPv6 redirect message. Find the instance, then update
2370 @param[in] IpSb The IP6 service binding instance that received
2372 @param[in] Head The IP head of the received ICMPv6 packet.
2373 @param[in] Packet The content of the ICMPv6 redirect packet with
2374 the IP head removed.
2376 @retval EFI_INVALID_PARAMETER The parameter is invalid.
2377 @retval EFI_OUT_OF_RESOURCES Insuffcient resources to complete the
2379 @retval EFI_SUCCESS Successfully updated the route caches.
2383 Ip6ProcessRedirect (
2384 IN IP6_SERVICE
*IpSb
,
2385 IN EFI_IP6_HEADER
*Head
,
2389 IP6_ICMP_INFORMATION_HEAD
*Icmp
;
2390 EFI_IPv6_ADDRESS
*Target
;
2391 EFI_IPv6_ADDRESS
*IcmpDest
;
2394 IP6_ROUTE_ENTRY
*RouteEntry
;
2395 IP6_ROUTE_CACHE_ENTRY
*RouteCache
;
2396 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
2399 IP6_ETHER_ADDR_OPTION
*LinkLayerOption
;
2400 EFI_MAC_ADDRESS Mac
;
2406 Status
= EFI_INVALID_PARAMETER
;
2408 Icmp
= (IP6_ICMP_INFORMATION_HEAD
*) NetbufGetByte (Packet
, 0, NULL
);
2414 // Validate the incoming Redirect message
2418 // The IP Hop Limit field has a value of 255, i.e. the packet
2419 // could not possibly have been forwarded by a router.
2421 // ICMP length (derived from the IP length) is 40 or more octets.
2423 if (Head
->HopLimit
!= IP6_HOP_LIMIT
|| Icmp
->Head
.Code
!= 0 ||
2424 Head
->PayloadLength
< IP6_REDITECT_LENGTH
) {
2429 // The IP source address must be a link-local address
2431 if (!NetIp6IsLinkLocalAddr (&Head
->SourceAddress
)) {
2436 // The dest of this ICMP redirect message is not us.
2438 if (!Ip6IsOneOfSetAddress (IpSb
, &Head
->DestinationAddress
, NULL
, NULL
)) {
2443 // All included options have a length that is greater than zero.
2445 OptionLen
= (UINT16
) (Head
->PayloadLength
- IP6_REDITECT_LENGTH
);
2446 if (OptionLen
!= 0) {
2447 Option
= NetbufGetByte (Packet
, IP6_REDITECT_LENGTH
, NULL
);
2448 ASSERT (Option
!= NULL
);
2450 if (!Ip6IsNDOptionValid (Option
, OptionLen
)) {
2455 Target
= (EFI_IPv6_ADDRESS
*) (Icmp
+ 1);
2456 IcmpDest
= Target
+ 1;
2459 // The ICMP Destination Address field in the redirect message does not contain
2460 // a multicast address.
2462 if (IP6_IS_MULTICAST (IcmpDest
)) {
2467 // The ICMP Target Address is either a link-local address (when redirected to
2468 // a router) or the same as the ICMP Destination Address (when redirected to
2469 // the on-link destination).
2471 IsRouter
= (BOOLEAN
) !EFI_IP6_EQUAL (Target
, IcmpDest
);
2472 if (!NetIp6IsLinkLocalAddr (Target
) && IsRouter
) {
2477 // Check the options. The only interested option here is the target-link layer
2480 Length
= Packet
->TotalSize
- 40;
2481 Option
= (UINT8
*) (IcmpDest
+ 1);
2482 LinkLayerOption
= NULL
;
2483 while (Length
> 0) {
2485 case Ip6OptionEtherTarget
:
2487 LinkLayerOption
= (IP6_ETHER_ADDR_OPTION
*) Option
;
2488 OptLen
= LinkLayerOption
->Length
;
2491 // For ethernet, the length must be 1.
2499 OptLen
= *(Option
+ 1);
2502 // A length of 0 is invalid.
2509 Length
-= 8 * OptLen
;
2510 Option
+= 8 * OptLen
;
2518 // The IP source address of the Redirect is the same as the current
2519 // first-hop router for the specified ICMP Destination Address.
2521 RouteCache
= Ip6FindRouteCache (IpSb
->RouteTable
, IcmpDest
, &Head
->DestinationAddress
);
2522 if (RouteCache
!= NULL
) {
2523 if (!EFI_IP6_EQUAL (&RouteCache
->NextHop
, &Head
->SourceAddress
)) {
2525 // The source of this Redirect message must match the NextHop of the
2526 // corresponding route cache entry.
2532 // Update the NextHop.
2534 IP6_COPY_ADDRESS (&RouteCache
->NextHop
, Target
);
2537 RouteEntry
= (IP6_ROUTE_ENTRY
*) RouteCache
->Tag
;
2538 RouteEntry
->Flag
= RouteEntry
->Flag
| IP6_DIRECT_ROUTE
;
2543 // Get the Route Entry.
2545 RouteEntry
= Ip6FindRouteEntry (IpSb
->RouteTable
, IcmpDest
, NULL
);
2546 if (RouteEntry
== NULL
) {
2547 RouteEntry
= Ip6CreateRouteEntry (IcmpDest
, 0, NULL
);
2548 if (RouteEntry
== NULL
) {
2549 Status
= EFI_OUT_OF_RESOURCES
;
2555 RouteEntry
->Flag
= IP6_DIRECT_ROUTE
;
2559 // Create a route cache for this.
2561 RouteCache
= Ip6CreateRouteCacheEntry (
2563 &Head
->DestinationAddress
,
2567 if (RouteCache
== NULL
) {
2568 Status
= EFI_OUT_OF_RESOURCES
;
2573 // Insert the newly created route cache entry.
2575 Index
= IP6_ROUTE_CACHE_HASH (IcmpDest
, &Head
->DestinationAddress
);
2576 InsertHeadList (&IpSb
->RouteTable
->Cache
.CacheBucket
[Index
], &RouteCache
->Link
);
2580 // Try to locate the neighbor cache for the Target.
2582 NeighborCache
= Ip6FindNeighborEntry (IpSb
, Target
);
2584 if (LinkLayerOption
!= NULL
) {
2585 if (NeighborCache
== NULL
) {
2587 // Create a neighbor cache for the Target.
2589 ZeroMem (&Mac
, sizeof (EFI_MAC_ADDRESS
));
2590 CopyMem (&Mac
, LinkLayerOption
->EtherAddr
, 6);
2591 NeighborCache
= Ip6CreateNeighborEntry (IpSb
, Ip6OnArpResolved
, Target
, &Mac
);
2592 if (NeighborCache
== NULL
) {
2594 // Just report a success here. The neighbor cache can be created in
2595 // some other place.
2597 Status
= EFI_SUCCESS
;
2601 NeighborCache
->State
= EfiNeighborStale
;
2602 NeighborCache
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2604 Result
= CompareMem (LinkLayerOption
->EtherAddr
, &NeighborCache
->LinkAddress
, 6);
2607 // If the link-local address is the same as that already in the cache,
2608 // the cache entry's state remains unchanged. Otherwise update the
2609 // reachability state to STALE.
2611 if ((NeighborCache
->State
== EfiNeighborInComplete
) || (Result
!= 0)) {
2612 CopyMem (&NeighborCache
->LinkAddress
, LinkLayerOption
->EtherAddr
, 6);
2614 NeighborCache
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2616 if (NeighborCache
->State
== EfiNeighborInComplete
) {
2618 // Send queued packets if exist.
2620 NeighborCache
->State
= EfiNeighborStale
;
2621 NeighborCache
->CallBack ((VOID
*) NeighborCache
);
2623 NeighborCache
->State
= EfiNeighborStale
;
2629 if (NeighborCache
!= NULL
&& IsRouter
) {
2631 // The Target is a router, set IsRouter to TRUE.
2633 NeighborCache
->IsRouter
= TRUE
;
2636 Status
= EFI_SUCCESS
;
2639 NetbufFree (Packet
);
2644 Add Neighbor cache entries. It is a work function for EfiIp6Neighbors().
2646 @param[in] IpSb The IP6 service binding instance.
2647 @param[in] TargetIp6Address Pointer to Target IPv6 address.
2648 @param[in] TargetLinkAddress Pointer to link-layer address of the target. Ignored if NULL.
2649 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
2650 cache. It will be deleted after Timeout. A value of zero means that
2651 the entry is permanent. A non-zero value means that the entry is
2653 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
2654 be overridden and updated; if FALSE, and if a
2655 corresponding cache entry already existed, EFI_ACCESS_DENIED
2658 @retval EFI_SUCCESS The neighbor cache entry has been added.
2659 @retval EFI_OUT_OF_RESOURCES Could not add the entry to the neighbor cache
2660 due to insufficient resources.
2661 @retval EFI_NOT_FOUND TargetLinkAddress is NULL.
2662 @retval EFI_ACCESS_DENIED The to-be-added entry is already defined in the neighbor cache,
2663 and that entry is tagged as un-overridden (when DeleteFlag
2669 IN IP6_SERVICE
*IpSb
,
2670 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
2671 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
2676 IP6_NEIGHBOR_ENTRY
*Neighbor
;
2678 Neighbor
= Ip6FindNeighborEntry (IpSb
, TargetIp6Address
);
2679 if (Neighbor
!= NULL
) {
2681 return EFI_ACCESS_DENIED
;
2683 if (TargetLinkAddress
!= NULL
) {
2684 IP6_COPY_LINK_ADDRESS (&Neighbor
->LinkAddress
, TargetLinkAddress
);
2688 if (TargetLinkAddress
== NULL
) {
2689 return EFI_NOT_FOUND
;
2692 Neighbor
= Ip6CreateNeighborEntry (IpSb
, Ip6OnArpResolved
, TargetIp6Address
, TargetLinkAddress
);
2693 if (Neighbor
== NULL
) {
2694 return EFI_OUT_OF_RESOURCES
;
2698 Neighbor
->State
= EfiNeighborReachable
;
2701 Neighbor
->Ticks
= IP6_GET_TICKS (Timeout
/ TICKS_PER_MS
);
2702 Neighbor
->Dynamic
= TRUE
;
2704 Neighbor
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2711 Delete or update Neighbor cache entries. It is a work function for EfiIp6Neighbors().
2713 @param[in] IpSb The IP6 service binding instance.
2714 @param[in] TargetIp6Address Pointer to Target IPv6 address.
2715 @param[in] TargetLinkAddress Pointer to link-layer address of the target. Ignored if NULL.
2716 @param[in] Timeout Time in 100-ns units that this entry will remain in the neighbor
2717 cache. It will be deleted after Timeout. A value of zero means that
2718 the entry is permanent. A non-zero value means that the entry is
2720 @param[in] Override If TRUE, the cached link-layer address of the matching entry will
2721 be overridden and updated; if FALSE, and if a
2722 corresponding cache entry already existed, EFI_ACCESS_DENIED
2725 @retval EFI_SUCCESS The neighbor cache entry has been updated or deleted.
2726 @retval EFI_NOT_FOUND This entry is not in the neighbor cache.
2731 IN IP6_SERVICE
*IpSb
,
2732 IN EFI_IPv6_ADDRESS
*TargetIp6Address
,
2733 IN EFI_MAC_ADDRESS
*TargetLinkAddress OPTIONAL
,
2738 IP6_NEIGHBOR_ENTRY
*Neighbor
;
2740 Neighbor
= Ip6FindNeighborEntry (IpSb
, TargetIp6Address
);
2741 if (Neighbor
== NULL
) {
2742 return EFI_NOT_FOUND
;
2745 RemoveEntryList (&Neighbor
->Link
);
2746 FreePool (Neighbor
);
2752 The heartbeat timer of ND module in IP6_TIMER_INTERVAL_IN_MS milliseconds.
2753 This time routine handles DAD module and neighbor state transition.
2754 It is also responsible for sending out router solicitations.
2756 @param[in] Event The IP6 service instance's heartbeat timer.
2757 @param[in] Context The IP6 service instance.
2762 Ip6NdFasterTimerTicking (
2770 IP6_INTERFACE
*IpIf
;
2771 IP6_DELAY_JOIN_LIST
*DelayNode
;
2772 EFI_IPv6_ADDRESS Source
;
2773 IP6_DAD_ENTRY
*DupAddrDetect
;
2775 IP6_NEIGHBOR_ENTRY
*NeighborCache
;
2776 EFI_IPv6_ADDRESS Destination
;
2780 IpSb
= (IP6_SERVICE
*) Context
;
2781 NET_CHECK_SIGNATURE (IpSb
, IP6_SERVICE_SIGNATURE
);
2783 ZeroMem (&Source
, sizeof (EFI_IPv6_ADDRESS
));
2786 // A host SHOULD transmit up to MAX_RTR_SOLICITATIONS (3) Router
2787 // Solicitation messages, each separated by at least
2788 // RTR_SOLICITATION_INTERVAL (4) seconds.
2790 if ((IpSb
->Ip6ConfigInstance
.Policy
== Ip6ConfigPolicyAutomatic
) &&
2791 !IpSb
->RouterAdvertiseReceived
&&
2792 IpSb
->SolicitTimer
> 0
2794 if ((IpSb
->Ticks
== 0) || (--IpSb
->Ticks
== 0)) {
2795 Status
= Ip6SendRouterSolicit (IpSb
, NULL
, NULL
, NULL
, NULL
);
2796 if (!EFI_ERROR (Status
)) {
2797 IpSb
->SolicitTimer
--;
2798 IpSb
->Ticks
= (UINT32
) IP6_GET_TICKS (IP6_RTR_SOLICITATION_INTERVAL
);
2803 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
2804 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP6_INTERFACE
, Link
);
2807 // Process the delay list to join the solicited-node multicast address.
2809 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DelayJoinList
) {
2810 DelayNode
= NET_LIST_USER_STRUCT (Entry2
, IP6_DELAY_JOIN_LIST
, Link
);
2811 if ((DelayNode
->DelayTime
== 0) || (--DelayNode
->DelayTime
== 0)) {
2813 // The timer expires, init the duplicate address detection.
2816 DelayNode
->Interface
,
2817 DelayNode
->AddressInfo
,
2818 DelayNode
->DadCallback
,
2823 // Remove the delay node
2825 RemoveEntryList (&DelayNode
->Link
);
2826 FreePool (DelayNode
);
2831 // Process the duplicate address detection list.
2833 NET_LIST_FOR_EACH_SAFE (Entry2
, Next
, &IpIf
->DupAddrDetectList
) {
2834 DupAddrDetect
= NET_LIST_USER_STRUCT (Entry2
, IP6_DAD_ENTRY
, Link
);
2836 if ((DupAddrDetect
->RetransTick
== 0) || (--DupAddrDetect
->RetransTick
== 0)) {
2838 // The timer expires, check the remaining transmit counts.
2840 if (DupAddrDetect
->Transmit
< DupAddrDetect
->MaxTransmit
) {
2842 // Send the Neighbor Solicitation message with
2843 // Source - unspecified address, destination - solicited-node multicast address
2844 // Target - the address to be validated
2846 Status
= Ip6SendNeighborSolicit (
2849 &DupAddrDetect
->Destination
,
2850 &DupAddrDetect
->AddressInfo
->Address
,
2853 if (EFI_ERROR (Status
)) {
2857 DupAddrDetect
->Transmit
++;
2858 DupAddrDetect
->RetransTick
= IP6_GET_TICKS (IpSb
->RetransTimer
);
2861 // All required solicitation has been sent out, and the RetransTime after the last
2862 // Neighbor Solicit is elapsed, finish the DAD process.
2865 if ((DupAddrDetect
->Receive
== 0) ||
2866 (DupAddrDetect
->Transmit
== DupAddrDetect
->Receive
)) {
2870 Ip6OnDADFinished (Flag
, IpIf
, DupAddrDetect
);
2877 // Polling the state of Neighbor cache
2879 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpSb
->NeighborTable
) {
2880 NeighborCache
= NET_LIST_USER_STRUCT (Entry
, IP6_NEIGHBOR_ENTRY
, Link
);
2882 switch (NeighborCache
->State
) {
2883 case EfiNeighborInComplete
:
2884 if (NeighborCache
->Ticks
> 0) {
2885 --NeighborCache
->Ticks
;
2889 // Retransmit Neighbor Solicitation messages approximately every
2890 // RetransTimer milliseconds while awaiting a response.
2892 if (NeighborCache
->Ticks
== 0) {
2893 if (NeighborCache
->Transmit
> 1) {
2895 // Send out multicast neighbor solicitation for address resolution.
2896 // After last neighbor solicitation message has been sent out, wait
2897 // for RetransTimer and then remove entry if no response is received.
2899 Ip6CreateSNMulticastAddr (&NeighborCache
->Neighbor
, &Destination
);
2900 Status
= Ip6SelectSourceAddress (IpSb
, &NeighborCache
->Neighbor
, &Source
);
2901 if (EFI_ERROR (Status
)) {
2905 Status
= Ip6SendNeighborSolicit (
2909 &NeighborCache
->Neighbor
,
2910 &IpSb
->SnpMode
.CurrentAddress
2912 if (EFI_ERROR (Status
)) {
2918 // Update the retransmit times.
2920 if (NeighborCache
->Transmit
> 0) {
2921 --NeighborCache
->Transmit
;
2922 NeighborCache
->Ticks
= IP6_GET_TICKS (IpSb
->RetransTimer
);
2926 if (NeighborCache
->Transmit
== 0) {
2928 // Timeout, send ICMP destination unreachable packet and then remove entry
2930 Status
= Ip6FreeNeighborEntry (
2939 if (EFI_ERROR (Status
)) {
2946 case EfiNeighborReachable
:
2948 // This entry is inserted by EfiIp6Neighbors() as static entry
2949 // and will not timeout.
2951 if (!NeighborCache
->Dynamic
&& (NeighborCache
->Ticks
== IP6_INFINIT_LIFETIME
)) {
2955 if ((NeighborCache
->Ticks
== 0) || (--NeighborCache
->Ticks
== 0)) {
2956 if (NeighborCache
->Dynamic
) {
2958 // This entry is inserted by EfiIp6Neighbors() as dynamic entry
2959 // and will be deleted after timeout.
2961 Status
= Ip6FreeNeighborEntry (
2970 if (EFI_ERROR (Status
)) {
2974 NeighborCache
->State
= EfiNeighborStale
;
2975 NeighborCache
->Ticks
= (UINT32
) IP6_INFINIT_LIFETIME
;
2981 case EfiNeighborDelay
:
2982 if ((NeighborCache
->Ticks
== 0) || (--NeighborCache
->Ticks
== 0)) {
2984 NeighborCache
->State
= EfiNeighborProbe
;
2985 NeighborCache
->Ticks
= IP6_GET_TICKS (IpSb
->RetransTimer
);
2986 NeighborCache
->Transmit
= IP6_MAX_UNICAST_SOLICIT
+ 1;
2988 // Send out unicast neighbor solicitation for Neighbor Unreachability Detection
2990 Status
= Ip6SelectSourceAddress (IpSb
, &NeighborCache
->Neighbor
, &Source
);
2991 if (EFI_ERROR (Status
)) {
2995 Status
= Ip6SendNeighborSolicit (
2998 &NeighborCache
->Neighbor
,
2999 &NeighborCache
->Neighbor
,
3000 &IpSb
->SnpMode
.CurrentAddress
3002 if (EFI_ERROR (Status
)) {
3006 NeighborCache
->Transmit
--;
3011 case EfiNeighborProbe
:
3012 if (NeighborCache
->Ticks
> 0) {
3013 --NeighborCache
->Ticks
;
3017 // Retransmit Neighbor Solicitation messages approximately every
3018 // RetransTimer milliseconds while awaiting a response.
3020 if (NeighborCache
->Ticks
== 0) {
3021 if (NeighborCache
->Transmit
> 1) {
3023 // Send out unicast neighbor solicitation for Neighbor Unreachability
3024 // Detection. After last neighbor solicitation message has been sent out,
3025 // wait for RetransTimer and then remove entry if no response is received.
3027 Status
= Ip6SelectSourceAddress (IpSb
, &NeighborCache
->Neighbor
, &Source
);
3028 if (EFI_ERROR (Status
)) {
3032 Status
= Ip6SendNeighborSolicit (
3035 &NeighborCache
->Neighbor
,
3036 &NeighborCache
->Neighbor
,
3037 &IpSb
->SnpMode
.CurrentAddress
3039 if (EFI_ERROR (Status
)) {
3045 // Update the retransmit times.
3047 if (NeighborCache
->Transmit
> 0) {
3048 --NeighborCache
->Transmit
;
3049 NeighborCache
->Ticks
= IP6_GET_TICKS (IpSb
->RetransTimer
);
3053 if (NeighborCache
->Transmit
== 0) {
3055 // Delete the neighbor entry.
3057 Status
= Ip6FreeNeighborEntry (
3066 if (EFI_ERROR (Status
)) {
3080 The heartbeat timer of ND module in 1 second. This time routine handles following
3081 things: 1) maitain default router list; 2) maintain prefix options;
3082 3) maintain route caches.
3084 @param[in] IpSb The IP6 service binding instance.
3089 IN IP6_SERVICE
*IpSb
3094 IP6_DEFAULT_ROUTER
*DefaultRouter
;
3095 IP6_PREFIX_LIST_ENTRY
*PrefixOption
;
3097 IP6_ROUTE_CACHE_ENTRY
*RouteCache
;
3100 // Decrease the lifetime of default router, if expires remove it from default router list.
3102 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpSb
->DefaultRouterList
) {
3103 DefaultRouter
= NET_LIST_USER_STRUCT (Entry
, IP6_DEFAULT_ROUTER
, Link
);
3104 if (DefaultRouter
->Lifetime
!= IP6_INF_ROUTER_LIFETIME
) {
3105 if ((DefaultRouter
->Lifetime
== 0) || (--DefaultRouter
->Lifetime
== 0)) {
3106 Ip6DestroyDefaultRouter (IpSb
, DefaultRouter
);
3112 // Decrease Valid lifetime and Preferred lifetime of Prefix options and corresponding addresses.
3114 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpSb
->AutonomousPrefix
) {
3115 PrefixOption
= NET_LIST_USER_STRUCT (Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
3116 if (PrefixOption
->ValidLifetime
!= (UINT32
) IP6_INFINIT_LIFETIME
) {
3117 if ((PrefixOption
->ValidLifetime
> 0) && (--PrefixOption
->ValidLifetime
> 0)) {
3118 if ((PrefixOption
->PreferredLifetime
!= (UINT32
) IP6_INFINIT_LIFETIME
) &&
3119 (PrefixOption
->PreferredLifetime
> 0)
3121 --PrefixOption
->PreferredLifetime
;
3124 Ip6DestroyPrefixListEntry (IpSb
, PrefixOption
, FALSE
, TRUE
);
3129 NET_LIST_FOR_EACH_SAFE (Entry
, Next
, &IpSb
->OnlinkPrefix
) {
3130 PrefixOption
= NET_LIST_USER_STRUCT (Entry
, IP6_PREFIX_LIST_ENTRY
, Link
);
3131 if (PrefixOption
->ValidLifetime
!= (UINT32
) IP6_INFINIT_LIFETIME
) {
3132 if ((PrefixOption
->ValidLifetime
== 0) || (--PrefixOption
->ValidLifetime
== 0)) {
3133 Ip6DestroyPrefixListEntry (IpSb
, PrefixOption
, TRUE
, TRUE
);
3139 // Each bucket of route cache can contain at most IP6_ROUTE_CACHE_MAX entries.
3140 // Remove the entries at the tail of the bucket. These entries
3141 // are likely to be used least.
3142 // Reclaim frequency is set to 1 second.
3144 for (Index
= 0; Index
< IP6_ROUTE_CACHE_HASH_SIZE
; Index
++) {
3145 while (IpSb
->RouteTable
->Cache
.CacheNum
[Index
] > IP6_ROUTE_CACHE_MAX
) {
3146 Entry
= NetListRemoveTail (&IpSb
->RouteTable
->Cache
.CacheBucket
[Index
]);
3147 if (Entry
== NULL
) {
3151 RouteCache
= NET_LIST_USER_STRUCT (Entry
, IP6_ROUTE_CACHE_ENTRY
, Link
);
3152 Ip6FreeRouteCacheEntry (RouteCache
);
3153 ASSERT (IpSb
->RouteTable
->Cache
.CacheNum
[Index
] > 0);
3154 IpSb
->RouteTable
->Cache
.CacheNum
[Index
]--;