X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=NetworkPkg%2FIp6Dxe%2FIp6Nd.c;h=c10c7017f88dcbb4d4e5027f0c3f2456d8c5fcaa;hp=0780a98cb3253897d2260714f8dc25ca37e8e474;hb=d1050b9dff1cace252aff86630bfdb59dff5f507;hpb=2f88bd3a1296c522317f1c21377876de63de5be7 diff --git a/NetworkPkg/Ip6Dxe/Ip6Nd.c b/NetworkPkg/Ip6Dxe/Ip6Nd.c index 0780a98cb3..c10c7017f8 100644 --- a/NetworkPkg/Ip6Dxe/Ip6Nd.c +++ b/NetworkPkg/Ip6Dxe/Ip6Nd.c @@ -9,7 +9,7 @@ #include "Ip6Impl.h" -EFI_MAC_ADDRESS mZeroMacAddress; +EFI_MAC_ADDRESS mZeroMacAddress; /** Update the ReachableTime in IP6 service binding instance data, in milliseconds. @@ -22,10 +22,10 @@ Ip6UpdateReachableTime ( IN OUT IP6_SERVICE *IpSb ) { - UINT32 Random; + UINT32 Random; - Random = (NetRandomInitSeed () / 4294967295UL) * IP6_RANDOM_FACTOR_SCALE; - Random = Random + IP6_MIN_RANDOM_FACTOR_SCALED; + Random = (NetRandomInitSeed () / 4294967295UL) * IP6_RANDOM_FACTOR_SCALE; + Random = Random + IP6_MIN_RANDOM_FACTOR_SCALED; IpSb->ReachableTime = (IpSb->BaseReachableTime * Random) / IP6_RANDOM_FACTOR_SCALE; } @@ -43,17 +43,17 @@ Ip6UpdateReachableTime ( **/ EFI_STATUS Ip6BuildEfiNeighborCache ( - IN IP6_PROTOCOL *IpInstance, - OUT UINT32 *NeighborCount, - OUT EFI_IP6_NEIGHBOR_CACHE **NeighborCache + IN IP6_PROTOCOL *IpInstance, + OUT UINT32 *NeighborCount, + OUT EFI_IP6_NEIGHBOR_CACHE **NeighborCache ) { - IP6_NEIGHBOR_ENTRY *Neighbor; - LIST_ENTRY *Entry; - IP6_SERVICE *IpSb; - UINT32 Count; - EFI_IP6_NEIGHBOR_CACHE *EfiNeighborCache; - EFI_IP6_NEIGHBOR_CACHE *NeighborCacheTmp; + IP6_NEIGHBOR_ENTRY *Neighbor; + LIST_ENTRY *Entry; + IP6_SERVICE *IpSb; + UINT32 Count; + EFI_IP6_NEIGHBOR_CACHE *EfiNeighborCache; + EFI_IP6_NEIGHBOR_CACHE *NeighborCacheTmp; NET_CHECK_SIGNATURE (IpInstance, IP6_PROTOCOL_SIGNATURE); ASSERT (NeighborCount != NULL && NeighborCache != NULL); @@ -82,7 +82,7 @@ Ip6BuildEfiNeighborCache ( EfiNeighborCache = NeighborCacheTmp + Count; - EfiNeighborCache->State = Neighbor->State; + EfiNeighborCache->State = Neighbor->State; IP6_COPY_ADDRESS (&EfiNeighborCache->Neighbor, &Neighbor->Neighbor); IP6_COPY_LINK_ADDRESS (&EfiNeighborCache->LinkAddress, &Neighbor->LinkAddress); @@ -114,12 +114,12 @@ Ip6BuildPrefixTable ( OUT EFI_IP6_ADDRESS_INFO **PrefixTable ) { - LIST_ENTRY *Entry; - IP6_SERVICE *IpSb; - UINT32 Count; - IP6_PREFIX_LIST_ENTRY *PrefixList; - EFI_IP6_ADDRESS_INFO *EfiPrefix; - EFI_IP6_ADDRESS_INFO *PrefixTableTmp; + LIST_ENTRY *Entry; + IP6_SERVICE *IpSb; + UINT32 Count; + IP6_PREFIX_LIST_ENTRY *PrefixList; + EFI_IP6_ADDRESS_INFO *EfiPrefix; + EFI_IP6_ADDRESS_INFO *PrefixTableTmp; NET_CHECK_SIGNATURE (IpInstance, IP6_PROTOCOL_SIGNATURE); ASSERT (PrefixCount != NULL && PrefixTable != NULL); @@ -178,21 +178,21 @@ Ip6BuildPrefixTable ( **/ IP6_PREFIX_LIST_ENTRY * Ip6CreatePrefixListEntry ( - IN IP6_SERVICE *IpSb, - IN BOOLEAN OnLinkOrAuto, - IN UINT32 ValidLifetime, - IN UINT32 PreferredLifetime, - IN UINT8 PrefixLength, - IN EFI_IPv6_ADDRESS *Prefix + IN IP6_SERVICE *IpSb, + IN BOOLEAN OnLinkOrAuto, + IN UINT32 ValidLifetime, + IN UINT32 PreferredLifetime, + IN UINT8 PrefixLength, + IN EFI_IPv6_ADDRESS *Prefix ) { - IP6_PREFIX_LIST_ENTRY *PrefixEntry; - IP6_ROUTE_ENTRY *RtEntry; - LIST_ENTRY *ListHead; - LIST_ENTRY *Entry; - IP6_PREFIX_LIST_ENTRY *TmpPrefixEntry; + IP6_PREFIX_LIST_ENTRY *PrefixEntry; + IP6_ROUTE_ENTRY *RtEntry; + LIST_ENTRY *ListHead; + LIST_ENTRY *Entry; + IP6_PREFIX_LIST_ENTRY *TmpPrefixEntry; - if (Prefix == NULL || PreferredLifetime > ValidLifetime || PrefixLength > IP6_PREFIX_MAX) { + if ((Prefix == NULL) || (PreferredLifetime > ValidLifetime) || (PrefixLength > IP6_PREFIX_MAX)) { return NULL; } @@ -205,7 +205,7 @@ Ip6CreatePrefixListEntry ( Prefix ); if (PrefixEntry != NULL) { - PrefixEntry->RefCnt ++; + PrefixEntry->RefCnt++; return PrefixEntry; } @@ -242,7 +242,7 @@ Ip6CreatePrefixListEntry ( // is put ahead in the list. // NET_LIST_FOR_EACH (Entry, ListHead) { - TmpPrefixEntry = NET_LIST_USER_STRUCT(Entry, IP6_PREFIX_LIST_ENTRY, Link); + TmpPrefixEntry = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link); if (TmpPrefixEntry->PrefixLength < PrefixEntry->PrefixLength) { break; @@ -274,26 +274,26 @@ Ip6DestroyPrefixListEntry ( IN BOOLEAN ImmediateDelete ) { - LIST_ENTRY *Entry; - IP6_INTERFACE *IpIf; - EFI_STATUS Status; + LIST_ENTRY *Entry; + IP6_INTERFACE *IpIf; + EFI_STATUS Status; if ((!ImmediateDelete) && (PrefixEntry->RefCnt > 0) && ((--PrefixEntry->RefCnt) > 0)) { - return ; + return; } if (OnLinkOrAuto) { - // - // Remove the direct route for onlink prefix from route table. - // - do { - Status = Ip6DelRoute ( - IpSb->RouteTable, - &PrefixEntry->Prefix, - PrefixEntry->PrefixLength, - NULL - ); - } while (Status != EFI_NOT_FOUND); + // + // Remove the direct route for onlink prefix from route table. + // + do { + Status = Ip6DelRoute ( + IpSb->RouteTable, + &PrefixEntry->Prefix, + PrefixEntry->PrefixLength, + NULL + ); + } while (Status != EFI_NOT_FOUND); } else { // // Remove the corresponding addresses generated from this autonomous prefix. @@ -324,15 +324,15 @@ Ip6DestroyPrefixListEntry ( **/ IP6_PREFIX_LIST_ENTRY * Ip6FindPrefixListEntry ( - IN IP6_SERVICE *IpSb, - IN BOOLEAN OnLinkOrAuto, - IN UINT8 PrefixLength, - IN EFI_IPv6_ADDRESS *Prefix + IN IP6_SERVICE *IpSb, + IN BOOLEAN OnLinkOrAuto, + IN UINT8 PrefixLength, + IN EFI_IPv6_ADDRESS *Prefix ) { - IP6_PREFIX_LIST_ENTRY *PrefixList; - LIST_ENTRY *Entry; - LIST_ENTRY *ListHead; + IP6_PREFIX_LIST_ENTRY *PrefixList; + LIST_ENTRY *Entry; + LIST_ENTRY *ListHead; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); ASSERT (Prefix != NULL); @@ -349,8 +349,9 @@ Ip6FindPrefixListEntry ( // // Perform exactly prefix match. // - if (PrefixList->PrefixLength == PrefixLength && - NetIp6IsNetEqual (&PrefixList->Prefix, Prefix, PrefixLength)) { + if ((PrefixList->PrefixLength == PrefixLength) && + NetIp6IsNetEqual (&PrefixList->Prefix, Prefix, PrefixLength)) + { return PrefixList; } } else { @@ -377,14 +378,14 @@ Ip6FindPrefixListEntry ( **/ VOID Ip6CleanPrefixListTable ( - IN IP6_SERVICE *IpSb, - IN LIST_ENTRY *ListHead + IN IP6_SERVICE *IpSb, + IN LIST_ENTRY *ListHead ) { - IP6_PREFIX_LIST_ENTRY *PrefixList; - BOOLEAN OnLink; + IP6_PREFIX_LIST_ENTRY *PrefixList; + BOOLEAN OnLink; - OnLink = (BOOLEAN) (ListHead == &IpSb->OnlinkPrefix); + OnLink = (BOOLEAN)(ListHead == &IpSb->OnlinkPrefix); while (!IsListEmpty (ListHead)) { PrefixList = NET_LIST_HEAD (ListHead, IP6_PREFIX_LIST_ENTRY, Link); @@ -402,25 +403,25 @@ Ip6CleanPrefixListTable ( **/ VOID Ip6OnArpResolved ( - IN VOID *Context + IN VOID *Context ) { - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - IP6_NEIGHBOR_ENTRY *ArpQue; - IP6_SERVICE *IpSb; - IP6_LINK_TX_TOKEN *Token; - EFI_STATUS Status; - BOOLEAN Sent; - - ArpQue = (IP6_NEIGHBOR_ENTRY *) Context; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + IP6_NEIGHBOR_ENTRY *ArpQue; + IP6_SERVICE *IpSb; + IP6_LINK_TX_TOKEN *Token; + EFI_STATUS Status; + BOOLEAN Sent; + + ArpQue = (IP6_NEIGHBOR_ENTRY *)Context; if ((ArpQue == NULL) || (ArpQue->Interface == NULL)) { - return ; + return; } - IpSb = ArpQue->Interface->Service; + IpSb = ArpQue->Interface->Service; if ((IpSb == NULL) || (IpSb->Signature != IP6_SERVICE_SIGNATURE)) { - return ; + return; } // @@ -430,7 +431,7 @@ Ip6OnArpResolved ( // if (NET_MAC_EQUAL (&ArpQue->LinkAddress, &mZeroMacAddress, IpSb->SnpMode.HwAddressSize)) { Ip6FreeNeighborEntry (IpSb, ArpQue, FALSE, TRUE, EFI_NO_MAPPING, NULL, NULL); - return ; + return; } // @@ -471,7 +472,7 @@ Ip6OnArpResolved ( if (Sent && (ArpQue->State == EfiNeighborStale)) { ArpQue->State = EfiNeighborDelay; - ArpQue->Ticks = (UINT32) IP6_GET_TICKS (IP6_DELAY_FIRST_PROBE_TIME); + ArpQue->Ticks = (UINT32)IP6_GET_TICKS (IP6_DELAY_FIRST_PROBE_TIME); } } @@ -491,17 +492,17 @@ Ip6OnArpResolved ( **/ IP6_NEIGHBOR_ENTRY * Ip6CreateNeighborEntry ( - IN IP6_SERVICE *IpSb, - IN IP6_ARP_CALLBACK CallBack, - IN EFI_IPv6_ADDRESS *Ip6Address, - IN EFI_MAC_ADDRESS *LinkAddress OPTIONAL + IN IP6_SERVICE *IpSb, + IN IP6_ARP_CALLBACK CallBack, + IN EFI_IPv6_ADDRESS *Ip6Address, + IN EFI_MAC_ADDRESS *LinkAddress OPTIONAL ) { - IP6_NEIGHBOR_ENTRY *Entry; - IP6_DEFAULT_ROUTER *DefaultRouter; + IP6_NEIGHBOR_ENTRY *Entry; + IP6_DEFAULT_ROUTER *DefaultRouter; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); - ASSERT (Ip6Address!= NULL); + ASSERT (Ip6Address != NULL); Entry = AllocateZeroPool (sizeof (IP6_NEIGHBOR_ENTRY)); if (Entry == NULL) { @@ -552,13 +553,13 @@ Ip6CreateNeighborEntry ( **/ IP6_NEIGHBOR_ENTRY * Ip6FindNeighborEntry ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *Ip6Address + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *Ip6Address ) { - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - IP6_NEIGHBOR_ENTRY *Neighbor; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + IP6_NEIGHBOR_ENTRY *Neighbor; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); ASSERT (Ip6Address != NULL); @@ -599,25 +600,25 @@ Ip6FindNeighborEntry ( **/ EFI_STATUS Ip6FreeNeighborEntry ( - IN IP6_SERVICE *IpSb, - IN IP6_NEIGHBOR_ENTRY *NeighborCache, - IN BOOLEAN SendIcmpError, - IN BOOLEAN FullFree, - IN EFI_STATUS IoStatus, - IN IP6_FRAME_TO_CANCEL FrameToCancel OPTIONAL, - IN VOID *Context OPTIONAL + IN IP6_SERVICE *IpSb, + IN IP6_NEIGHBOR_ENTRY *NeighborCache, + IN BOOLEAN SendIcmpError, + IN BOOLEAN FullFree, + IN EFI_STATUS IoStatus, + IN IP6_FRAME_TO_CANCEL FrameToCancel OPTIONAL, + IN VOID *Context OPTIONAL ) { - IP6_LINK_TX_TOKEN *TxToken; - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - IP6_DEFAULT_ROUTER *DefaultRouter; + IP6_LINK_TX_TOKEN *TxToken; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + IP6_DEFAULT_ROUTER *DefaultRouter; // // If FrameToCancel fails, the token will not be released. // To avoid the memory leak, stop this usage model. // - if (FullFree && FrameToCancel != NULL) { + if (FullFree && (FrameToCancel != NULL)) { return EFI_INVALID_PARAMETER; } @@ -677,13 +678,13 @@ Ip6FreeNeighborEntry ( **/ IP6_DEFAULT_ROUTER * Ip6CreateDefaultRouter ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *Ip6Address, - IN UINT16 RouterLifetime + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *Ip6Address, + IN UINT16 RouterLifetime ) { - IP6_DEFAULT_ROUTER *Entry; - IP6_ROUTE_ENTRY *RtEntry; + IP6_DEFAULT_ROUTER *Entry; + IP6_ROUTE_ENTRY *RtEntry; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); ASSERT (Ip6Address != NULL); @@ -724,11 +725,11 @@ Ip6CreateDefaultRouter ( **/ VOID Ip6DestroyDefaultRouter ( - IN IP6_SERVICE *IpSb, - IN IP6_DEFAULT_ROUTER *DefaultRouter + IN IP6_SERVICE *IpSb, + IN IP6_DEFAULT_ROUTER *DefaultRouter ) { - EFI_STATUS Status; + EFI_STATUS Status; RemoveEntryList (&DefaultRouter->Link); @@ -751,10 +752,10 @@ Ip6DestroyDefaultRouter ( **/ VOID Ip6CleanDefaultRouterList ( - IN IP6_SERVICE *IpSb + IN IP6_SERVICE *IpSb ) { - IP6_DEFAULT_ROUTER *DefaultRouter; + IP6_DEFAULT_ROUTER *DefaultRouter; while (!IsListEmpty (&IpSb->DefaultRouterList)) { DefaultRouter = NET_LIST_HEAD (&IpSb->DefaultRouterList, IP6_DEFAULT_ROUTER, Link); @@ -774,12 +775,12 @@ Ip6CleanDefaultRouterList ( **/ IP6_DEFAULT_ROUTER * Ip6FindDefaultRouter ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *Ip6Address + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *Ip6Address ) { - LIST_ENTRY *Entry; - IP6_DEFAULT_ROUTER *DefaultRouter; + LIST_ENTRY *Entry; + IP6_DEFAULT_ROUTER *DefaultRouter; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); ASSERT (Ip6Address != NULL); @@ -846,10 +847,10 @@ Ip6OnDADFinished ( // Set the exta options to send. Here we only want the option request option // with DNS SERVERS. // - Oro = (EFI_DHCP6_PACKET_OPTION *) OptBuf; - Oro->OpCode = HTONS (DHCP6_OPT_ORO); - Oro->OpLen = HTONS (2); - *((UINT16 *) &Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS); + Oro = (EFI_DHCP6_PACKET_OPTION *)OptBuf; + Oro->OpCode = HTONS (DHCP6_OPT_ORO); + Oro->OpLen = HTONS (2); + *((UINT16 *)&Oro->Data[0]) = HTONS (DHCP6_OPT_DNS_SERVERS); InfoReqReXmit.Irt = 4; InfoReqReXmit.Mrc = 64; @@ -875,12 +876,11 @@ Ip6OnDADFinished ( Ip6CreatePrefixListEntry ( IpSb, TRUE, - (UINT32) IP6_INFINIT_LIFETIME, - (UINT32) IP6_INFINIT_LIFETIME, + (UINT32)IP6_INFINIT_LIFETIME, + (UINT32)IP6_INFINIT_LIFETIME, IP6_LINK_LOCAL_PREFIX_LENGTH, &IpSb->LinkLocalAddr ); - } else { // // Global scope unicast address. @@ -928,7 +928,7 @@ Ip6OnDADFinished ( IpSb->Mnp->Configure (IpSb->Mnp, NULL); gBS->SetTimer (IpSb->Timer, TimerCancel, 0); gBS->SetTimer (IpSb->FasterTimer, TimerCancel, 0); - return ; + return; } if (!IsDadPassed || NetIp6IsLinkLocalAddr (&AddrInfo->Address)) { @@ -961,10 +961,10 @@ Ip6OnDADFinished ( **/ EFI_STATUS Ip6InitDADProcess ( - IN IP6_INTERFACE *IpIf, - IN IP6_ADDRESS_INFO *AddressInfo, - IN IP6_DAD_CALLBACK Callback OPTIONAL, - IN VOID *Context OPTIONAL + IN IP6_INTERFACE *IpIf, + IN IP6_ADDRESS_INFO *AddressInfo, + IN IP6_DAD_CALLBACK Callback OPTIONAL, + IN VOID *Context OPTIONAL ) { IP6_DAD_ENTRY *Entry; @@ -1009,15 +1009,15 @@ Ip6InitDADProcess ( return Status; } - Entry->Signature = IP6_DAD_ENTRY_SIGNATURE; - Entry->MaxTransmit = DadXmits->DupAddrDetectTransmits; - Entry->Transmit = 0; - Entry->Receive = 0; - MaxDelayTick = IP6_MAX_RTR_SOLICITATION_DELAY / IP6_TIMER_INTERVAL_IN_MS; - Entry->RetransTick = (MaxDelayTick * ((NET_RANDOM (NetRandomInitSeed ()) % 5) + 1)) / 5; - Entry->AddressInfo = AddressInfo; - Entry->Callback = Callback; - Entry->Context = Context; + Entry->Signature = IP6_DAD_ENTRY_SIGNATURE; + Entry->MaxTransmit = DadXmits->DupAddrDetectTransmits; + Entry->Transmit = 0; + Entry->Receive = 0; + MaxDelayTick = IP6_MAX_RTR_SOLICITATION_DELAY / IP6_TIMER_INTERVAL_IN_MS; + Entry->RetransTick = (MaxDelayTick * ((NET_RANDOM (NetRandomInitSeed ()) % 5) + 1)) / 5; + Entry->AddressInfo = AddressInfo; + Entry->Callback = Callback; + Entry->Context = Context; InsertTailList (&IpIf->DupAddrDetectList, &Entry->Link); if (Entry->MaxTransmit == 0) { @@ -1044,16 +1044,16 @@ Ip6InitDADProcess ( **/ IP6_DAD_ENTRY * Ip6FindDADEntry ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *Target, - OUT IP6_INTERFACE **Interface OPTIONAL + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *Target, + OUT IP6_INTERFACE **Interface OPTIONAL ) { - LIST_ENTRY *Entry; - LIST_ENTRY *Entry2; - IP6_INTERFACE *IpIf; - IP6_DAD_ENTRY *DupAddrDetect; - IP6_ADDRESS_INFO *AddrInfo; + LIST_ENTRY *Entry; + LIST_ENTRY *Entry2; + IP6_INTERFACE *IpIf; + IP6_DAD_ENTRY *DupAddrDetect; + IP6_ADDRESS_INFO *AddrInfo; NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) { IpIf = NET_LIST_USER_STRUCT (Entry, IP6_INTERFACE, Link); @@ -1065,6 +1065,7 @@ Ip6FindDADEntry ( if (Interface != NULL) { *Interface = IpIf; } + return DupAddrDetect; } } @@ -1093,24 +1094,24 @@ Ip6FindDADEntry ( **/ EFI_STATUS Ip6SendRouterSolicit ( - IN IP6_SERVICE *IpSb, - IN IP6_INTERFACE *Interface OPTIONAL, - IN EFI_IPv6_ADDRESS *SourceAddress OPTIONAL, - IN EFI_IPv6_ADDRESS *DestinationAddress OPTIONAL, - IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL + IN IP6_SERVICE *IpSb, + IN IP6_INTERFACE *Interface OPTIONAL, + IN EFI_IPv6_ADDRESS *SourceAddress OPTIONAL, + IN EFI_IPv6_ADDRESS *DestinationAddress OPTIONAL, + IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL ) { - NET_BUF *Packet; - EFI_IP6_HEADER Head; - IP6_ICMP_INFORMATION_HEAD *IcmpHead; - IP6_ETHER_ADDR_OPTION *LinkLayerOption; - UINT16 PayloadLen; - IP6_INTERFACE *IpIf; + NET_BUF *Packet; + EFI_IP6_HEADER Head; + IP6_ICMP_INFORMATION_HEAD *IcmpHead; + IP6_ETHER_ADDR_OPTION *LinkLayerOption; + UINT16 PayloadLen; + IP6_INTERFACE *IpIf; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); IpIf = Interface; - if (IpIf == NULL && IpSb->DefaultInterface != NULL) { + if ((IpIf == NULL) && (IpSb->DefaultInterface != NULL)) { IpIf = IpSb->DefaultInterface; } @@ -1118,12 +1119,12 @@ Ip6SendRouterSolicit ( // Generate the packet to be sent // - PayloadLen = (UINT16) sizeof (IP6_ICMP_INFORMATION_HEAD); + PayloadLen = (UINT16)sizeof (IP6_ICMP_INFORMATION_HEAD); if (SourceLinkAddress != NULL) { PayloadLen += sizeof (IP6_ETHER_ADDR_OPTION); } - Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen); + Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32)PayloadLen); if (Packet == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1131,11 +1132,11 @@ Ip6SendRouterSolicit ( // // Create the basic IPv6 header. // - Head.FlowLabelL = 0; - Head.FlowLabelH = 0; - Head.PayloadLength = HTONS (PayloadLen); - Head.NextHeader = IP6_ICMP; - Head.HopLimit = IP6_HOP_LIMIT; + Head.FlowLabelL = 0; + Head.FlowLabelH = 0; + Head.PayloadLength = HTONS (PayloadLen); + Head.NextHeader = IP6_ICMP; + Head.HopLimit = IP6_HOP_LIMIT; if (SourceAddress != NULL) { IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress); @@ -1143,7 +1144,6 @@ Ip6SendRouterSolicit ( ZeroMem (&Head.SourceAddress, sizeof (EFI_IPv6_ADDRESS)); } - if (DestinationAddress != NULL) { IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress); } else { @@ -1156,7 +1156,7 @@ Ip6SendRouterSolicit ( // Fill in the ICMP header, and Source link-layer address if contained. // - IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); + IcmpHead = (IP6_ICMP_INFORMATION_HEAD *)NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); ASSERT (IcmpHead != NULL); ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD)); IcmpHead->Head.Type = ICMP_V6_ROUTER_SOLICIT; @@ -1164,14 +1164,14 @@ Ip6SendRouterSolicit ( LinkLayerOption = NULL; if (SourceLinkAddress != NULL) { - LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace ( - Packet, - sizeof (IP6_ETHER_ADDR_OPTION), - FALSE - ); + LinkLayerOption = (IP6_ETHER_ADDR_OPTION *)NetbufAllocSpace ( + Packet, + sizeof (IP6_ETHER_ADDR_OPTION), + FALSE + ); ASSERT (LinkLayerOption != NULL); LinkLayerOption->Type = Ip6OptionEtherSource; - LinkLayerOption->Length = (UINT8) sizeof (IP6_ETHER_ADDR_OPTION); + LinkLayerOption->Length = (UINT8)sizeof (IP6_ETHER_ADDR_OPTION); CopyMem (LinkLayerOption->EtherAddr, SourceLinkAddress, 6); } @@ -1205,22 +1205,22 @@ Ip6SendRouterSolicit ( **/ EFI_STATUS Ip6SendNeighborAdvertise ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *SourceAddress, - IN EFI_IPv6_ADDRESS *DestinationAddress, - IN EFI_IPv6_ADDRESS *TargetIp6Address, - IN EFI_MAC_ADDRESS *TargetLinkAddress, - IN BOOLEAN IsRouter, - IN BOOLEAN Override, - IN BOOLEAN Solicited + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *SourceAddress, + IN EFI_IPv6_ADDRESS *DestinationAddress, + IN EFI_IPv6_ADDRESS *TargetIp6Address, + IN EFI_MAC_ADDRESS *TargetLinkAddress, + IN BOOLEAN IsRouter, + IN BOOLEAN Override, + IN BOOLEAN Solicited ) { - NET_BUF *Packet; - EFI_IP6_HEADER Head; - IP6_ICMP_INFORMATION_HEAD *IcmpHead; - IP6_ETHER_ADDR_OPTION *LinkLayerOption; - EFI_IPv6_ADDRESS *Target; - UINT16 PayloadLen; + NET_BUF *Packet; + EFI_IP6_HEADER Head; + IP6_ICMP_INFORMATION_HEAD *IcmpHead; + IP6_ETHER_ADDR_OPTION *LinkLayerOption; + EFI_IPv6_ADDRESS *Target; + UINT16 PayloadLen; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); @@ -1232,13 +1232,13 @@ Ip6SendNeighborAdvertise ( // ASSERT (DestinationAddress != NULL && TargetIp6Address != NULL && TargetLinkAddress != NULL); - PayloadLen = (UINT16) (sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS) + sizeof (IP6_ETHER_ADDR_OPTION)); + PayloadLen = (UINT16)(sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS) + sizeof (IP6_ETHER_ADDR_OPTION)); // // Generate the packet to be sent // - Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen); + Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32)PayloadLen); if (Packet == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1246,11 +1246,11 @@ Ip6SendNeighborAdvertise ( // // Create the basic IPv6 header. // - Head.FlowLabelL = 0; - Head.FlowLabelH = 0; - Head.PayloadLength = HTONS (PayloadLen); - Head.NextHeader = IP6_ICMP; - Head.HopLimit = IP6_HOP_LIMIT; + Head.FlowLabelL = 0; + Head.FlowLabelH = 0; + Head.PayloadLength = HTONS (PayloadLen); + Head.NextHeader = IP6_ICMP; + Head.HopLimit = IP6_HOP_LIMIT; IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress); IP6_COPY_ADDRESS (&Head.DestinationAddress, DestinationAddress); @@ -1262,7 +1262,7 @@ Ip6SendNeighborAdvertise ( // Set the Router flag, Solicited flag and Override flag. // - IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); + IcmpHead = (IP6_ICMP_INFORMATION_HEAD *)NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); ASSERT (IcmpHead != NULL); ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD)); IcmpHead->Head.Type = ICMP_V6_NEIGHBOR_ADVERTISE; @@ -1280,15 +1280,15 @@ Ip6SendNeighborAdvertise ( IcmpHead->Fourth |= IP6_OVERRIDE_FLAG; } - Target = (EFI_IPv6_ADDRESS *) NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE); + Target = (EFI_IPv6_ADDRESS *)NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE); ASSERT (Target != NULL); IP6_COPY_ADDRESS (Target, TargetIp6Address); - LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace ( - Packet, - sizeof (IP6_ETHER_ADDR_OPTION), - FALSE - ); + LinkLayerOption = (IP6_ETHER_ADDR_OPTION *)NetbufAllocSpace ( + Packet, + sizeof (IP6_ETHER_ADDR_OPTION), + FALSE + ); ASSERT (LinkLayerOption != NULL); LinkLayerOption->Type = Ip6OptionEtherTarget; LinkLayerOption->Length = 1; @@ -1320,33 +1320,33 @@ Ip6SendNeighborAdvertise ( **/ EFI_STATUS Ip6SendNeighborSolicit ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *SourceAddress, - IN EFI_IPv6_ADDRESS *DestinationAddress, - IN EFI_IPv6_ADDRESS *TargetIp6Address, - IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *SourceAddress, + IN EFI_IPv6_ADDRESS *DestinationAddress, + IN EFI_IPv6_ADDRESS *TargetIp6Address, + IN EFI_MAC_ADDRESS *SourceLinkAddress OPTIONAL ) { - NET_BUF *Packet; - EFI_IP6_HEADER Head; - IP6_ICMP_INFORMATION_HEAD *IcmpHead; - IP6_ETHER_ADDR_OPTION *LinkLayerOption; - EFI_IPv6_ADDRESS *Target; - BOOLEAN IsDAD; - UINT16 PayloadLen; - IP6_NEIGHBOR_ENTRY *Neighbor; + NET_BUF *Packet; + EFI_IP6_HEADER Head; + IP6_ICMP_INFORMATION_HEAD *IcmpHead; + IP6_ETHER_ADDR_OPTION *LinkLayerOption; + EFI_IPv6_ADDRESS *Target; + BOOLEAN IsDAD; + UINT16 PayloadLen; + IP6_NEIGHBOR_ENTRY *Neighbor; // // Check input parameters // NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); - if (DestinationAddress == NULL || TargetIp6Address == NULL) { + if ((DestinationAddress == NULL) || (TargetIp6Address == NULL)) { return EFI_INVALID_PARAMETER; } IsDAD = FALSE; - if (SourceAddress == NULL || (SourceAddress != NULL && NetIp6IsUnspecifiedAddr (SourceAddress))) { + if ((SourceAddress == NULL) || ((SourceAddress != NULL) && NetIp6IsUnspecifiedAddr (SourceAddress))) { IsDAD = TRUE; } @@ -1355,21 +1355,21 @@ Ip6SendNeighborSolicit ( // if the solicitation is not sent by performing DAD - Duplicate Address Detection. // Otherwise must not include it. // - PayloadLen = (UINT16) (sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS)); + PayloadLen = (UINT16)(sizeof (IP6_ICMP_INFORMATION_HEAD) + sizeof (EFI_IPv6_ADDRESS)); if (!IsDAD) { if (SourceLinkAddress == NULL) { return EFI_INVALID_PARAMETER; } - PayloadLen = (UINT16) (PayloadLen + sizeof (IP6_ETHER_ADDR_OPTION)); + PayloadLen = (UINT16)(PayloadLen + sizeof (IP6_ETHER_ADDR_OPTION)); } // // Generate the packet to be sent // - Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32) PayloadLen); + Packet = NetbufAlloc (sizeof (EFI_IP6_HEADER) + (UINT32)PayloadLen); if (Packet == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1377,11 +1377,11 @@ Ip6SendNeighborSolicit ( // // Create the basic IPv6 header // - Head.FlowLabelL = 0; - Head.FlowLabelH = 0; - Head.PayloadLength = HTONS (PayloadLen); - Head.NextHeader = IP6_ICMP; - Head.HopLimit = IP6_HOP_LIMIT; + Head.FlowLabelL = 0; + Head.FlowLabelH = 0; + Head.PayloadLength = HTONS (PayloadLen); + Head.NextHeader = IP6_ICMP; + Head.HopLimit = IP6_HOP_LIMIT; if (SourceAddress != NULL) { IP6_COPY_ADDRESS (&Head.SourceAddress, SourceAddress); @@ -1396,27 +1396,26 @@ Ip6SendNeighborSolicit ( // // Fill in the ICMP header, Target address, and Source link-layer address. // - IcmpHead = (IP6_ICMP_INFORMATION_HEAD *) NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); + IcmpHead = (IP6_ICMP_INFORMATION_HEAD *)NetbufAllocSpace (Packet, sizeof (IP6_ICMP_INFORMATION_HEAD), FALSE); ASSERT (IcmpHead != NULL); ZeroMem (IcmpHead, sizeof (IP6_ICMP_INFORMATION_HEAD)); IcmpHead->Head.Type = ICMP_V6_NEIGHBOR_SOLICIT; IcmpHead->Head.Code = 0; - Target = (EFI_IPv6_ADDRESS *) NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE); + Target = (EFI_IPv6_ADDRESS *)NetbufAllocSpace (Packet, sizeof (EFI_IPv6_ADDRESS), FALSE); ASSERT (Target != NULL); IP6_COPY_ADDRESS (Target, TargetIp6Address); LinkLayerOption = NULL; if (!IsDAD) { - // // Fill in the source link-layer address option // - LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) NetbufAllocSpace ( - Packet, - sizeof (IP6_ETHER_ADDR_OPTION), - FALSE - ); + LinkLayerOption = (IP6_ETHER_ADDR_OPTION *)NetbufAllocSpace ( + Packet, + sizeof (IP6_ETHER_ADDR_OPTION), + FALSE + ); ASSERT (LinkLayerOption != NULL); LinkLayerOption->Type = Ip6OptionEtherSource; LinkLayerOption->Length = 1; @@ -1457,30 +1456,30 @@ Ip6SendNeighborSolicit ( **/ EFI_STATUS Ip6ProcessNeighborSolicit ( - IN IP6_SERVICE *IpSb, - IN EFI_IP6_HEADER *Head, - IN NET_BUF *Packet + IN IP6_SERVICE *IpSb, + IN EFI_IP6_HEADER *Head, + IN NET_BUF *Packet ) { - IP6_ICMP_INFORMATION_HEAD Icmp; - EFI_IPv6_ADDRESS Target; - IP6_ETHER_ADDR_OPTION LinkLayerOption; - BOOLEAN IsDAD; - BOOLEAN IsUnicast; - BOOLEAN IsMaintained; - IP6_DAD_ENTRY *DupAddrDetect; - IP6_INTERFACE *IpIf; - IP6_NEIGHBOR_ENTRY *Neighbor; - BOOLEAN Solicited; - BOOLEAN UpdateCache; - EFI_IPv6_ADDRESS Dest; - UINT16 OptionLen; - UINT8 *Option; - BOOLEAN Provided; - EFI_STATUS Status; - VOID *MacAddress; - - NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp); + IP6_ICMP_INFORMATION_HEAD Icmp; + EFI_IPv6_ADDRESS Target; + IP6_ETHER_ADDR_OPTION LinkLayerOption; + BOOLEAN IsDAD; + BOOLEAN IsUnicast; + BOOLEAN IsMaintained; + IP6_DAD_ENTRY *DupAddrDetect; + IP6_INTERFACE *IpIf; + IP6_NEIGHBOR_ENTRY *Neighbor; + BOOLEAN Solicited; + BOOLEAN UpdateCache; + EFI_IPv6_ADDRESS Dest; + UINT16 OptionLen; + UINT8 *Option; + BOOLEAN Provided; + EFI_STATUS Status; + VOID *MacAddress; + + NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *)&Icmp); NetbufCopy (Packet, sizeof (Icmp), sizeof (Target), Target.Addr); // @@ -1492,7 +1491,7 @@ Ip6ProcessNeighborSolicit ( // Status = EFI_INVALID_PARAMETER; - if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 || !NetIp6IsValidUnicast (&Target)) { + if ((Head->HopLimit != IP6_HOP_LIMIT) || (Icmp.Head.Code != 0) || !NetIp6IsValidUnicast (&Target)) { goto Exit; } @@ -1503,9 +1502,9 @@ Ip6ProcessNeighborSolicit ( if (Head->PayloadLength < IP6_ND_LENGTH) { goto Exit; } else { - OptionLen = (UINT16) (Head->PayloadLength - IP6_ND_LENGTH); + OptionLen = (UINT16)(Head->PayloadLength - IP6_ND_LENGTH); if (OptionLen != 0) { - Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL); + Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL); ASSERT (Option != NULL); // @@ -1527,7 +1526,7 @@ Ip6ProcessNeighborSolicit ( Packet, IP6_ND_LENGTH, sizeof (IP6_ETHER_ADDR_OPTION), - (UINT8 *) &LinkLayerOption + (UINT8 *)&LinkLayerOption ); // // The solicitation for neighbor discovery should include a source link-layer @@ -1591,7 +1590,8 @@ Ip6ProcessNeighborSolicit ( MacAddress, &IpSb->SnpMode.CurrentAddress, IpSb->SnpMode.HwAddressSize - ) != 0) { + ) != 0) + { // // The NS is from another node to performing DAD on the same address. // Fail DAD for the tentative address. @@ -1607,6 +1607,7 @@ Ip6ProcessNeighborSolicit ( } } } + goto Exit; } @@ -1624,6 +1625,7 @@ Ip6ProcessNeighborSolicit ( Status = EFI_OUT_OF_RESOURCES; goto Exit; } + UpdateCache = TRUE; } else { if (CompareMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6) != 0) { @@ -1633,12 +1635,12 @@ Ip6ProcessNeighborSolicit ( if (UpdateCache) { Neighbor->State = EfiNeighborStale; - Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + Neighbor->Ticks = (UINT32)IP6_INFINIT_LIFETIME; CopyMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6); // // Send queued packets if exist. // - Neighbor->CallBack ((VOID *) Neighbor); + Neighbor->CallBack ((VOID *)Neighbor); } } @@ -1686,28 +1688,28 @@ Exit: **/ EFI_STATUS Ip6ProcessNeighborAdvertise ( - IN IP6_SERVICE *IpSb, - IN EFI_IP6_HEADER *Head, - IN NET_BUF *Packet + IN IP6_SERVICE *IpSb, + IN EFI_IP6_HEADER *Head, + IN NET_BUF *Packet ) { - IP6_ICMP_INFORMATION_HEAD Icmp; - EFI_IPv6_ADDRESS Target; - IP6_ETHER_ADDR_OPTION LinkLayerOption; - BOOLEAN Provided; - INTN Compare; - IP6_NEIGHBOR_ENTRY *Neighbor; - IP6_DEFAULT_ROUTER *DefaultRouter; - BOOLEAN Solicited; - BOOLEAN IsRouter; - BOOLEAN Override; - IP6_DAD_ENTRY *DupAddrDetect; - IP6_INTERFACE *IpIf; - UINT16 OptionLen; - UINT8 *Option; - EFI_STATUS Status; - - NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp); + IP6_ICMP_INFORMATION_HEAD Icmp; + EFI_IPv6_ADDRESS Target; + IP6_ETHER_ADDR_OPTION LinkLayerOption; + BOOLEAN Provided; + INTN Compare; + IP6_NEIGHBOR_ENTRY *Neighbor; + IP6_DEFAULT_ROUTER *DefaultRouter; + BOOLEAN Solicited; + BOOLEAN IsRouter; + BOOLEAN Override; + IP6_DAD_ENTRY *DupAddrDetect; + IP6_INTERFACE *IpIf; + UINT16 OptionLen; + UINT8 *Option; + EFI_STATUS Status; + + NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *)&Icmp); NetbufCopy (Packet, sizeof (Icmp), sizeof (Target), Target.Addr); // @@ -1720,7 +1722,7 @@ Ip6ProcessNeighborAdvertise ( // ICMP Code is 0. // Target Address is not a multicast address. // - if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 || !NetIp6IsValidUnicast (&Target)) { + if ((Head->HopLimit != IP6_HOP_LIMIT) || (Icmp.Head.Code != 0) || !NetIp6IsValidUnicast (&Target)) { goto Exit; } @@ -1732,9 +1734,9 @@ Ip6ProcessNeighborAdvertise ( if (Head->PayloadLength < IP6_ND_LENGTH) { goto Exit; } else { - OptionLen = (UINT16) (Head->PayloadLength - IP6_ND_LENGTH); + OptionLen = (UINT16)(Head->PayloadLength - IP6_ND_LENGTH); if (OptionLen != 0) { - Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL); + Option = NetbufGetByte (Packet, IP6_ND_LENGTH, NULL); ASSERT (Option != NULL); // @@ -1753,6 +1755,7 @@ Ip6ProcessNeighborAdvertise ( if ((Icmp.Fourth & IP6_SOLICITED_FLAG) == IP6_SOLICITED_FLAG) { Solicited = TRUE; } + if (IP6_IS_MULTICAST (&Head->DestinationAddress) && Solicited) { goto Exit; } @@ -1787,6 +1790,7 @@ Ip6ProcessNeighborAdvertise ( if ((Icmp.Fourth & IP6_IS_ROUTER_FLAG) == IP6_IS_ROUTER_FLAG) { IsRouter = TRUE; } + if ((Icmp.Fourth & IP6_OVERRIDE_FLAG) == IP6_OVERRIDE_FLAG) { Override = TRUE; } @@ -1799,7 +1803,7 @@ Ip6ProcessNeighborAdvertise ( Packet, IP6_ND_LENGTH, sizeof (IP6_ETHER_ADDR_OPTION), - (UINT8 *) &LinkLayerOption + (UINT8 *)&LinkLayerOption ); if (LinkLayerOption.Type == Ip6OptionEtherTarget) { @@ -1828,6 +1832,7 @@ Ip6ProcessNeighborAdvertise ( if (!Provided) { goto Exit; } + // // Update the Neighbor Cache // @@ -1837,17 +1842,16 @@ Ip6ProcessNeighborAdvertise ( Neighbor->Ticks = IP6_GET_TICKS (IpSb->ReachableTime); } else { Neighbor->State = EfiNeighborStale; - Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + Neighbor->Ticks = (UINT32)IP6_INFINIT_LIFETIME; // // Send any packets queued for the neighbor awaiting address resolution. // - Neighbor->CallBack ((VOID *) Neighbor); + Neighbor->CallBack ((VOID *)Neighbor); } Neighbor->IsRouter = IsRouter; - } else { - if (!Override && Compare != 0) { + if (!Override && (Compare != 0)) { // // When the Override Flag is clear and supplied link-layer address differs from // that in the cache, if the state of the entry is not REACHABLE, ignore the @@ -1856,12 +1860,13 @@ Ip6ProcessNeighborAdvertise ( // if (Neighbor->State == EfiNeighborReachable) { Neighbor->State = EfiNeighborStale; - Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + Neighbor->Ticks = (UINT32)IP6_INFINIT_LIFETIME; } } else { if (Compare != 0) { CopyMem (Neighbor->LinkAddress.Addr, LinkLayerOption.EtherAddr, 6); } + // // Update the entry's state // @@ -1871,7 +1876,7 @@ Ip6ProcessNeighborAdvertise ( } else { if (Compare != 0) { Neighbor->State = EfiNeighborStale; - Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + Neighbor->Ticks = (UINT32)IP6_INFINIT_LIFETIME; } } @@ -1892,7 +1897,7 @@ Ip6ProcessNeighborAdvertise ( } if (Neighbor->State == EfiNeighborReachable) { - Neighbor->CallBack ((VOID *) Neighbor); + Neighbor->CallBack ((VOID *)Neighbor); } Status = EFI_SUCCESS; @@ -1918,36 +1923,36 @@ Exit: **/ EFI_STATUS Ip6ProcessRouterAdvertise ( - IN IP6_SERVICE *IpSb, - IN EFI_IP6_HEADER *Head, - IN NET_BUF *Packet + IN IP6_SERVICE *IpSb, + IN EFI_IP6_HEADER *Head, + IN NET_BUF *Packet ) { - IP6_ICMP_INFORMATION_HEAD Icmp; - UINT32 ReachableTime; - UINT32 RetransTimer; - UINT16 RouterLifetime; - UINT32 Offset; - UINT8 Type; - UINT8 Length; - IP6_ETHER_ADDR_OPTION LinkLayerOption; - UINT32 Fourth; - UINT8 CurHopLimit; - BOOLEAN Mflag; - BOOLEAN Oflag; - IP6_DEFAULT_ROUTER *DefaultRouter; - IP6_NEIGHBOR_ENTRY *NeighborCache; - EFI_MAC_ADDRESS LinkLayerAddress; - IP6_MTU_OPTION MTUOption; - IP6_PREFIX_INFO_OPTION PrefixOption; - IP6_PREFIX_LIST_ENTRY *PrefixList; - BOOLEAN OnLink; - BOOLEAN Autonomous; - EFI_IPv6_ADDRESS StatelessAddress; - EFI_STATUS Status; - UINT16 OptionLen; - UINT8 *Option; - INTN Result; + IP6_ICMP_INFORMATION_HEAD Icmp; + UINT32 ReachableTime; + UINT32 RetransTimer; + UINT16 RouterLifetime; + UINT32 Offset; + UINT8 Type; + UINT8 Length; + IP6_ETHER_ADDR_OPTION LinkLayerOption; + UINT32 Fourth; + UINT8 CurHopLimit; + BOOLEAN Mflag; + BOOLEAN Oflag; + IP6_DEFAULT_ROUTER *DefaultRouter; + IP6_NEIGHBOR_ENTRY *NeighborCache; + EFI_MAC_ADDRESS LinkLayerAddress; + IP6_MTU_OPTION MTUOption; + IP6_PREFIX_INFO_OPTION PrefixOption; + IP6_PREFIX_LIST_ENTRY *PrefixList; + BOOLEAN OnLink; + BOOLEAN Autonomous; + EFI_IPv6_ADDRESS StatelessAddress; + EFI_STATUS Status; + UINT16 OptionLen; + UINT8 *Option; + INTN Result; Status = EFI_INVALID_PARAMETER; @@ -1958,7 +1963,7 @@ Ip6ProcessRouterAdvertise ( goto Exit; } - NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *) &Icmp); + NetbufCopy (Packet, 0, sizeof (Icmp), (UINT8 *)&Icmp); // // Validate the incoming Router Advertisement @@ -1970,23 +1975,25 @@ Ip6ProcessRouterAdvertise ( if (!NetIp6IsLinkLocalAddr (&Head->SourceAddress)) { goto Exit; } + // // The IP Hop Limit field has a value of 255, i.e. the packet // could not possibly have been forwarded by a router. // ICMP Code is 0. // ICMP length (derived from the IP length) is 16 or more octets. // - if (Head->HopLimit != IP6_HOP_LIMIT || Icmp.Head.Code != 0 || - Head->PayloadLength < IP6_RA_LENGTH) { + if ((Head->HopLimit != IP6_HOP_LIMIT) || (Icmp.Head.Code != 0) || + (Head->PayloadLength < IP6_RA_LENGTH)) + { goto Exit; } // // All included options have a length that is greater than zero. // - OptionLen = (UINT16) (Head->PayloadLength - IP6_RA_LENGTH); + OptionLen = (UINT16)(Head->PayloadLength - IP6_RA_LENGTH); if (OptionLen != 0) { - Option = NetbufGetByte (Packet, IP6_RA_LENGTH, NULL); + Option = NetbufGetByte (Packet, IP6_RA_LENGTH, NULL); ASSERT (Option != NULL); if (!Ip6IsNDOptionValid (Option, OptionLen)) { @@ -2035,17 +2042,17 @@ Ip6ProcessRouterAdvertise ( } } - CurHopLimit = *((UINT8 *) &Fourth + 3); + CurHopLimit = *((UINT8 *)&Fourth + 3); if (CurHopLimit != 0) { IpSb->CurHopLimit = CurHopLimit; } Mflag = FALSE; Oflag = FALSE; - if ((*((UINT8 *) &Fourth + 2) & IP6_M_ADDR_CONFIG_FLAG) == IP6_M_ADDR_CONFIG_FLAG) { + if ((*((UINT8 *)&Fourth + 2) & IP6_M_ADDR_CONFIG_FLAG) == IP6_M_ADDR_CONFIG_FLAG) { Mflag = TRUE; } else { - if ((*((UINT8 *) &Fourth + 2) & IP6_O_CONFIG_FLAG) == IP6_O_CONFIG_FLAG) { + if ((*((UINT8 *)&Fourth + 2) & IP6_O_CONFIG_FLAG) == IP6_O_CONFIG_FLAG) { Oflag = TRUE; } } @@ -2060,12 +2067,12 @@ Ip6ProcessRouterAdvertise ( // // Process Reachable Time and Retrans Timer fields. // - NetbufCopy (Packet, sizeof (Icmp), sizeof (UINT32), (UINT8 *) &ReachableTime); - NetbufCopy (Packet, sizeof (Icmp) + sizeof (UINT32), sizeof (UINT32), (UINT8 *) &RetransTimer); + NetbufCopy (Packet, sizeof (Icmp), sizeof (UINT32), (UINT8 *)&ReachableTime); + NetbufCopy (Packet, sizeof (Icmp) + sizeof (UINT32), sizeof (UINT32), (UINT8 *)&RetransTimer); ReachableTime = NTOHL (ReachableTime); RetransTimer = NTOHL (RetransTimer); - if (ReachableTime != 0 && ReachableTime != IpSb->BaseReachableTime) { + if ((ReachableTime != 0) && (ReachableTime != IpSb->BaseReachableTime)) { // // If new value is not unspecified and differs from the previous one, record it // in BaseReachableTime and recompute a ReachableTime. @@ -2098,262 +2105,266 @@ Ip6ProcessRouterAdvertise ( // fit within the input packet. // Offset = 16; - while (Offset < (UINT32) Head->PayloadLength) { + while (Offset < (UINT32)Head->PayloadLength) { NetbufCopy (Packet, Offset, sizeof (UINT8), &Type); switch (Type) { - case Ip6OptionEtherSource: - // - // Update the neighbor cache - // - NetbufCopy (Packet, Offset, sizeof (IP6_ETHER_ADDR_OPTION), (UINT8 *) &LinkLayerOption); + case Ip6OptionEtherSource: + // + // Update the neighbor cache + // + NetbufCopy (Packet, Offset, sizeof (IP6_ETHER_ADDR_OPTION), (UINT8 *)&LinkLayerOption); - // - // Option size validity ensured by Ip6IsNDOptionValid(). - // - ASSERT (LinkLayerOption.Length != 0); - ASSERT (Offset + (UINT32) LinkLayerOption.Length * 8 <= (UINT32) Head->PayloadLength); + // + // Option size validity ensured by Ip6IsNDOptionValid(). + // + ASSERT (LinkLayerOption.Length != 0); + ASSERT (Offset + (UINT32)LinkLayerOption.Length * 8 <= (UINT32)Head->PayloadLength); - ZeroMem (&LinkLayerAddress, sizeof (EFI_MAC_ADDRESS)); - CopyMem (&LinkLayerAddress, LinkLayerOption.EtherAddr, 6); + ZeroMem (&LinkLayerAddress, sizeof (EFI_MAC_ADDRESS)); + CopyMem (&LinkLayerAddress, LinkLayerOption.EtherAddr, 6); - if (NeighborCache == NULL) { - NeighborCache = Ip6CreateNeighborEntry ( - IpSb, - Ip6OnArpResolved, - &Head->SourceAddress, - &LinkLayerAddress - ); if (NeighborCache == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; + NeighborCache = Ip6CreateNeighborEntry ( + IpSb, + Ip6OnArpResolved, + &Head->SourceAddress, + &LinkLayerAddress + ); + if (NeighborCache == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + + NeighborCache->IsRouter = TRUE; + NeighborCache->State = EfiNeighborStale; + NeighborCache->Ticks = (UINT32)IP6_INFINIT_LIFETIME; + } else { + Result = CompareMem (&LinkLayerAddress, &NeighborCache->LinkAddress, 6); + + // + // If the link-local address is the same as that already in the cache, + // the cache entry's state remains unchanged. Otherwise update the + // reachability state to STALE. + // + if ((NeighborCache->State == EfiNeighborInComplete) || (Result != 0)) { + CopyMem (&NeighborCache->LinkAddress, &LinkLayerAddress, 6); + + NeighborCache->Ticks = (UINT32)IP6_INFINIT_LIFETIME; + + if (NeighborCache->State == EfiNeighborInComplete) { + // + // Send queued packets if exist. + // + NeighborCache->State = EfiNeighborStale; + NeighborCache->CallBack ((VOID *)NeighborCache); + } else { + NeighborCache->State = EfiNeighborStale; + } + } } - NeighborCache->IsRouter = TRUE; - NeighborCache->State = EfiNeighborStale; - NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME; - } else { - Result = CompareMem (&LinkLayerAddress, &NeighborCache->LinkAddress, 6); + + Offset += (UINT32)LinkLayerOption.Length * 8; + break; + case Ip6OptionPrefixInfo: + NetbufCopy (Packet, Offset, sizeof (IP6_PREFIX_INFO_OPTION), (UINT8 *)&PrefixOption); // - // If the link-local address is the same as that already in the cache, - // the cache entry's state remains unchanged. Otherwise update the - // reachability state to STALE. + // Option size validity ensured by Ip6IsNDOptionValid(). // - if ((NeighborCache->State == EfiNeighborInComplete) || (Result != 0)) { - CopyMem (&NeighborCache->LinkAddress, &LinkLayerAddress, 6); + ASSERT (PrefixOption.Length == 4); + ASSERT (Offset + (UINT32)PrefixOption.Length * 8 <= (UINT32)Head->PayloadLength); - NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + PrefixOption.ValidLifetime = NTOHL (PrefixOption.ValidLifetime); + PrefixOption.PreferredLifetime = NTOHL (PrefixOption.PreferredLifetime); - if (NeighborCache->State == EfiNeighborInComplete) { - // - // Send queued packets if exist. - // - NeighborCache->State = EfiNeighborStale; - NeighborCache->CallBack ((VOID *) NeighborCache); - } else { - NeighborCache->State = EfiNeighborStale; - } + // + // Get L and A flag, recorded in the lower 2 bits of Reserved1 + // + OnLink = FALSE; + if ((PrefixOption.Reserved1 & IP6_ON_LINK_FLAG) == IP6_ON_LINK_FLAG) { + OnLink = TRUE; } - } - - Offset += (UINT32) LinkLayerOption.Length * 8; - break; - case Ip6OptionPrefixInfo: - NetbufCopy (Packet, Offset, sizeof (IP6_PREFIX_INFO_OPTION), (UINT8 *) &PrefixOption); - // - // Option size validity ensured by Ip6IsNDOptionValid(). - // - ASSERT (PrefixOption.Length == 4); - ASSERT (Offset + (UINT32) PrefixOption.Length * 8 <= (UINT32) Head->PayloadLength); - - PrefixOption.ValidLifetime = NTOHL (PrefixOption.ValidLifetime); - PrefixOption.PreferredLifetime = NTOHL (PrefixOption.PreferredLifetime); + Autonomous = FALSE; + if ((PrefixOption.Reserved1 & IP6_AUTO_CONFIG_FLAG) == IP6_AUTO_CONFIG_FLAG) { + Autonomous = TRUE; + } - // - // Get L and A flag, recorded in the lower 2 bits of Reserved1 - // - OnLink = FALSE; - if ((PrefixOption.Reserved1 & IP6_ON_LINK_FLAG) == IP6_ON_LINK_FLAG) { - OnLink = TRUE; - } - Autonomous = FALSE; - if ((PrefixOption.Reserved1 & IP6_AUTO_CONFIG_FLAG) == IP6_AUTO_CONFIG_FLAG) { - Autonomous = TRUE; - } + // + // If the prefix is the link-local prefix, silently ignore the prefix option. + // + if ((PrefixOption.PrefixLength == IP6_LINK_LOCAL_PREFIX_LENGTH) && + NetIp6IsLinkLocalAddr (&PrefixOption.Prefix) + ) + { + Offset += sizeof (IP6_PREFIX_INFO_OPTION); + break; + } - // - // If the prefix is the link-local prefix, silently ignore the prefix option. - // - if (PrefixOption.PrefixLength == IP6_LINK_LOCAL_PREFIX_LENGTH && - NetIp6IsLinkLocalAddr (&PrefixOption.Prefix) - ) { - Offset += sizeof (IP6_PREFIX_INFO_OPTION); - break; - } - // - // Do following if on-link flag is set according to RFC4861. - // - if (OnLink) { - PrefixList = Ip6FindPrefixListEntry ( - IpSb, - TRUE, - PrefixOption.PrefixLength, - &PrefixOption.Prefix - ); // - // Create a new entry for the prefix, if the ValidLifetime is zero, - // silently ignore the prefix option. + // Do following if on-link flag is set according to RFC4861. // - if (PrefixList == NULL && PrefixOption.ValidLifetime != 0) { - PrefixList = Ip6CreatePrefixListEntry ( + if (OnLink) { + PrefixList = Ip6FindPrefixListEntry ( IpSb, TRUE, - PrefixOption.ValidLifetime, - PrefixOption.PreferredLifetime, PrefixOption.PrefixLength, &PrefixOption.Prefix ); - if (PrefixList == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } - } else if (PrefixList != NULL) { - if (PrefixOption.ValidLifetime != 0) { - PrefixList->ValidLifetime = PrefixOption.ValidLifetime; - } else { - // - // If the prefix exists and incoming ValidLifetime is zero, immediately - // remove the prefix. - Ip6DestroyPrefixListEntry (IpSb, PrefixList, OnLink, TRUE); - } - } - } - - // - // Do following if Autonomous flag is set according to RFC4862. - // - if (Autonomous && PrefixOption.PreferredLifetime <= PrefixOption.ValidLifetime) { - PrefixList = Ip6FindPrefixListEntry ( - IpSb, - FALSE, - PrefixOption.PrefixLength, - &PrefixOption.Prefix - ); - // - // Create a new entry for the prefix, and form an address by prefix + interface id - // If the sum of the prefix length and interface identifier length - // does not equal 128 bits, the Prefix Information option MUST be ignored. - // - if (PrefixList == NULL && - PrefixOption.ValidLifetime != 0 && - PrefixOption.PrefixLength + IpSb->InterfaceIdLen * 8 == 128 - ) { // - // Form the address in network order. + // Create a new entry for the prefix, if the ValidLifetime is zero, + // silently ignore the prefix option. // - CopyMem (&StatelessAddress, &PrefixOption.Prefix, sizeof (UINT64)); - CopyMem (&StatelessAddress.Addr[8], IpSb->InterfaceId, sizeof (UINT64)); - - // - // If the address is not yet in the assigned address list, adds it into. - // - if (!Ip6IsOneOfSetAddress (IpSb, &StatelessAddress, NULL, NULL)) { - // - // And also not in the DAD process, check its uniqueness firstly. - // - if (Ip6FindDADEntry (IpSb, &StatelessAddress, NULL) == NULL) { - Status = Ip6SetAddress ( - IpSb->DefaultInterface, - &StatelessAddress, - FALSE, - PrefixOption.PrefixLength, - PrefixOption.ValidLifetime, - PrefixOption.PreferredLifetime, - NULL, - NULL - ); - if (EFI_ERROR (Status)) { - goto Exit; - } + if ((PrefixList == NULL) && (PrefixOption.ValidLifetime != 0)) { + PrefixList = Ip6CreatePrefixListEntry ( + IpSb, + TRUE, + PrefixOption.ValidLifetime, + PrefixOption.PreferredLifetime, + PrefixOption.PrefixLength, + &PrefixOption.Prefix + ); + if (PrefixList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + } else if (PrefixList != NULL) { + if (PrefixOption.ValidLifetime != 0) { + PrefixList->ValidLifetime = PrefixOption.ValidLifetime; + } else { + // + // If the prefix exists and incoming ValidLifetime is zero, immediately + // remove the prefix. + Ip6DestroyPrefixListEntry (IpSb, PrefixList, OnLink, TRUE); } } + } - // - // Adds the prefix option to stateless prefix option list. - // - PrefixList = Ip6CreatePrefixListEntry ( + // + // Do following if Autonomous flag is set according to RFC4862. + // + if (Autonomous && (PrefixOption.PreferredLifetime <= PrefixOption.ValidLifetime)) { + PrefixList = Ip6FindPrefixListEntry ( IpSb, FALSE, - PrefixOption.ValidLifetime, - PrefixOption.PreferredLifetime, PrefixOption.PrefixLength, &PrefixOption.Prefix ); - if (PrefixList == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } - } else if (PrefixList != NULL) { - // - // Reset the preferred lifetime of the address if the advertised prefix exists. - // Perform specific action to valid lifetime together. + // Create a new entry for the prefix, and form an address by prefix + interface id + // If the sum of the prefix length and interface identifier length + // does not equal 128 bits, the Prefix Information option MUST be ignored. // - PrefixList->PreferredLifetime = PrefixOption.PreferredLifetime; - if ((PrefixOption.ValidLifetime > 7200) || - (PrefixOption.ValidLifetime > PrefixList->ValidLifetime)) { + if ((PrefixList == NULL) && + (PrefixOption.ValidLifetime != 0) && + (PrefixOption.PrefixLength + IpSb->InterfaceIdLen * 8 == 128) + ) + { // - // If the received Valid Lifetime is greater than 2 hours or - // greater than RemainingLifetime, set the valid lifetime of the - // corresponding address to the advertised Valid Lifetime. + // Form the address in network order. // - PrefixList->ValidLifetime = PrefixOption.ValidLifetime; + CopyMem (&StatelessAddress, &PrefixOption.Prefix, sizeof (UINT64)); + CopyMem (&StatelessAddress.Addr[8], IpSb->InterfaceId, sizeof (UINT64)); - } else if (PrefixList->ValidLifetime <= 7200) { // - // If RemainingLifetime is less than or equals to 2 hours, ignore the - // Prefix Information option with regards to the valid lifetime. - // TODO: If this option has been authenticated, set the valid lifetime. + // If the address is not yet in the assigned address list, adds it into. // - } else { + if (!Ip6IsOneOfSetAddress (IpSb, &StatelessAddress, NULL, NULL)) { + // + // And also not in the DAD process, check its uniqueness firstly. + // + if (Ip6FindDADEntry (IpSb, &StatelessAddress, NULL) == NULL) { + Status = Ip6SetAddress ( + IpSb->DefaultInterface, + &StatelessAddress, + FALSE, + PrefixOption.PrefixLength, + PrefixOption.ValidLifetime, + PrefixOption.PreferredLifetime, + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + } + } + // - // Otherwise, reset the valid lifetime of the corresponding - // address to 2 hours. + // Adds the prefix option to stateless prefix option list. + // + PrefixList = Ip6CreatePrefixListEntry ( + IpSb, + FALSE, + PrefixOption.ValidLifetime, + PrefixOption.PreferredLifetime, + PrefixOption.PrefixLength, + &PrefixOption.Prefix + ); + if (PrefixList == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + } else if (PrefixList != NULL) { // - PrefixList->ValidLifetime = 7200; + // Reset the preferred lifetime of the address if the advertised prefix exists. + // Perform specific action to valid lifetime together. + // + PrefixList->PreferredLifetime = PrefixOption.PreferredLifetime; + if ((PrefixOption.ValidLifetime > 7200) || + (PrefixOption.ValidLifetime > PrefixList->ValidLifetime)) + { + // + // If the received Valid Lifetime is greater than 2 hours or + // greater than RemainingLifetime, set the valid lifetime of the + // corresponding address to the advertised Valid Lifetime. + // + PrefixList->ValidLifetime = PrefixOption.ValidLifetime; + } else if (PrefixList->ValidLifetime <= 7200) { + // + // If RemainingLifetime is less than or equals to 2 hours, ignore the + // Prefix Information option with regards to the valid lifetime. + // TODO: If this option has been authenticated, set the valid lifetime. + // + } else { + // + // Otherwise, reset the valid lifetime of the corresponding + // address to 2 hours. + // + PrefixList->ValidLifetime = 7200; + } } } - } - Offset += sizeof (IP6_PREFIX_INFO_OPTION); - break; - case Ip6OptionMtu: - NetbufCopy (Packet, Offset, sizeof (IP6_MTU_OPTION), (UINT8 *) &MTUOption); + Offset += sizeof (IP6_PREFIX_INFO_OPTION); + break; + case Ip6OptionMtu: + NetbufCopy (Packet, Offset, sizeof (IP6_MTU_OPTION), (UINT8 *)&MTUOption); - // - // Option size validity ensured by Ip6IsNDOptionValid(). - // - ASSERT (MTUOption.Length == 1); - ASSERT (Offset + (UINT32) MTUOption.Length * 8 <= (UINT32) Head->PayloadLength); + // + // Option size validity ensured by Ip6IsNDOptionValid(). + // + ASSERT (MTUOption.Length == 1); + ASSERT (Offset + (UINT32)MTUOption.Length * 8 <= (UINT32)Head->PayloadLength); - // - // Use IPv6 minimum link MTU 1280 bytes as the maximum packet size in order - // to omit implementation of Path MTU Discovery. Thus ignore the MTU option - // in Router Advertisement. - // + // + // Use IPv6 minimum link MTU 1280 bytes as the maximum packet size in order + // to omit implementation of Path MTU Discovery. Thus ignore the MTU option + // in Router Advertisement. + // - Offset += sizeof (IP6_MTU_OPTION); - break; - default: - // - // Silently ignore unrecognized options - // - NetbufCopy (Packet, Offset + sizeof (UINT8), sizeof (UINT8), &Length); + Offset += sizeof (IP6_MTU_OPTION); + break; + default: + // + // Silently ignore unrecognized options + // + NetbufCopy (Packet, Offset + sizeof (UINT8), sizeof (UINT8), &Length); - ASSERT (Length != 0); + ASSERT (Length != 0); - Offset += (UINT32) Length * 8; - break; + Offset += (UINT32)Length * 8; + break; } } @@ -2382,31 +2393,31 @@ Exit: **/ EFI_STATUS Ip6ProcessRedirect ( - IN IP6_SERVICE *IpSb, - IN EFI_IP6_HEADER *Head, - IN NET_BUF *Packet + IN IP6_SERVICE *IpSb, + IN EFI_IP6_HEADER *Head, + IN NET_BUF *Packet ) { - IP6_ICMP_INFORMATION_HEAD *Icmp; - EFI_IPv6_ADDRESS *Target; - EFI_IPv6_ADDRESS *IcmpDest; - UINT8 *Option; - UINT16 OptionLen; - IP6_ROUTE_ENTRY *RouteEntry; - IP6_ROUTE_CACHE_ENTRY *RouteCache; - IP6_NEIGHBOR_ENTRY *NeighborCache; - INT32 Length; - UINT8 OptLen; - IP6_ETHER_ADDR_OPTION *LinkLayerOption; - EFI_MAC_ADDRESS Mac; - UINT32 Index; - BOOLEAN IsRouter; - EFI_STATUS Status; - INTN Result; + IP6_ICMP_INFORMATION_HEAD *Icmp; + EFI_IPv6_ADDRESS *Target; + EFI_IPv6_ADDRESS *IcmpDest; + UINT8 *Option; + UINT16 OptionLen; + IP6_ROUTE_ENTRY *RouteEntry; + IP6_ROUTE_CACHE_ENTRY *RouteCache; + IP6_NEIGHBOR_ENTRY *NeighborCache; + INT32 Length; + UINT8 OptLen; + IP6_ETHER_ADDR_OPTION *LinkLayerOption; + EFI_MAC_ADDRESS Mac; + UINT32 Index; + BOOLEAN IsRouter; + EFI_STATUS Status; + INTN Result; Status = EFI_INVALID_PARAMETER; - Icmp = (IP6_ICMP_INFORMATION_HEAD *) NetbufGetByte (Packet, 0, NULL); + Icmp = (IP6_ICMP_INFORMATION_HEAD *)NetbufGetByte (Packet, 0, NULL); if (Icmp == NULL) { goto Exit; } @@ -2421,8 +2432,9 @@ Ip6ProcessRedirect ( // ICMP Code is 0. // ICMP length (derived from the IP length) is 40 or more octets. // - if (Head->HopLimit != IP6_HOP_LIMIT || Icmp->Head.Code != 0 || - Head->PayloadLength < IP6_REDITECT_LENGTH) { + if ((Head->HopLimit != IP6_HOP_LIMIT) || (Icmp->Head.Code != 0) || + (Head->PayloadLength < IP6_REDITECT_LENGTH)) + { goto Exit; } @@ -2443,9 +2455,9 @@ Ip6ProcessRedirect ( // // All included options have a length that is greater than zero. // - OptionLen = (UINT16) (Head->PayloadLength - IP6_REDITECT_LENGTH); + OptionLen = (UINT16)(Head->PayloadLength - IP6_REDITECT_LENGTH); if (OptionLen != 0) { - Option = NetbufGetByte (Packet, IP6_REDITECT_LENGTH, NULL); + Option = NetbufGetByte (Packet, IP6_REDITECT_LENGTH, NULL); ASSERT (Option != NULL); if (!Ip6IsNDOptionValid (Option, OptionLen)) { @@ -2453,7 +2465,7 @@ Ip6ProcessRedirect ( } } - Target = (EFI_IPv6_ADDRESS *) (Icmp + 1); + Target = (EFI_IPv6_ADDRESS *)(Icmp + 1); IcmpDest = Target + 1; // @@ -2479,32 +2491,34 @@ Ip6ProcessRedirect ( // address option. // Length = Packet->TotalSize - 40; - Option = (UINT8 *) (IcmpDest + 1); + Option = (UINT8 *)(IcmpDest + 1); LinkLayerOption = NULL; while (Length > 0) { switch (*Option) { - case Ip6OptionEtherTarget: + case Ip6OptionEtherTarget: - LinkLayerOption = (IP6_ETHER_ADDR_OPTION *) Option; - OptLen = LinkLayerOption->Length; - if (OptLen != 1) { - // - // For ethernet, the length must be 1. - // - goto Exit; - } - break; + LinkLayerOption = (IP6_ETHER_ADDR_OPTION *)Option; + OptLen = LinkLayerOption->Length; + if (OptLen != 1) { + // + // For ethernet, the length must be 1. + // + goto Exit; + } - default: + break; - OptLen = *(Option + 1); - if (OptLen == 0) { - // - // A length of 0 is invalid. - // - goto Exit; - } - break; + default: + + OptLen = *(Option + 1); + if (OptLen == 0) { + // + // A length of 0 is invalid. + // + goto Exit; + } + + break; } Length -= 8 * OptLen; @@ -2535,10 +2549,9 @@ Ip6ProcessRedirect ( IP6_COPY_ADDRESS (&RouteCache->NextHop, Target); if (!IsRouter) { - RouteEntry = (IP6_ROUTE_ENTRY *) RouteCache->Tag; + RouteEntry = (IP6_ROUTE_ENTRY *)RouteCache->Tag; RouteEntry->Flag = RouteEntry->Flag | IP6_DIRECT_ROUTE; } - } else { // // Get the Route Entry. @@ -2563,7 +2576,7 @@ Ip6ProcessRedirect ( IcmpDest, &Head->DestinationAddress, Target, - (UINTN) RouteEntry + (UINTN)RouteEntry ); if (RouteCache == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -2600,7 +2613,7 @@ Ip6ProcessRedirect ( } NeighborCache->State = EfiNeighborStale; - NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + NeighborCache->Ticks = (UINT32)IP6_INFINIT_LIFETIME; } else { Result = CompareMem (LinkLayerOption->EtherAddr, &NeighborCache->LinkAddress, 6); @@ -2612,14 +2625,14 @@ Ip6ProcessRedirect ( if ((NeighborCache->State == EfiNeighborInComplete) || (Result != 0)) { CopyMem (&NeighborCache->LinkAddress, LinkLayerOption->EtherAddr, 6); - NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + NeighborCache->Ticks = (UINT32)IP6_INFINIT_LIFETIME; if (NeighborCache->State == EfiNeighborInComplete) { // // Send queued packets if exist. // NeighborCache->State = EfiNeighborStale; - NeighborCache->CallBack ((VOID *) NeighborCache); + NeighborCache->CallBack ((VOID *)NeighborCache); } else { NeighborCache->State = EfiNeighborStale; } @@ -2627,7 +2640,7 @@ Ip6ProcessRedirect ( } } - if (NeighborCache != NULL && IsRouter) { + if ((NeighborCache != NULL) && IsRouter) { // // The Target is a router, set IsRouter to TRUE. // @@ -2667,14 +2680,14 @@ Exit: **/ EFI_STATUS Ip6AddNeighbor ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *TargetIp6Address, - IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL, - IN UINT32 Timeout, - IN BOOLEAN Override + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *TargetIp6Address, + IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL, + IN UINT32 Timeout, + IN BOOLEAN Override ) { - IP6_NEIGHBOR_ENTRY *Neighbor; + IP6_NEIGHBOR_ENTRY *Neighbor; Neighbor = Ip6FindNeighborEntry (IpSb, TargetIp6Address); if (Neighbor != NULL) { @@ -2702,7 +2715,7 @@ Ip6AddNeighbor ( Neighbor->Ticks = IP6_GET_TICKS (Timeout / TICKS_PER_MS); Neighbor->Dynamic = TRUE; } else { - Neighbor->Ticks = (UINT32) IP6_INFINIT_LIFETIME; + Neighbor->Ticks = (UINT32)IP6_INFINIT_LIFETIME; } return EFI_SUCCESS; @@ -2729,14 +2742,14 @@ Ip6AddNeighbor ( **/ EFI_STATUS Ip6DelNeighbor ( - IN IP6_SERVICE *IpSb, - IN EFI_IPv6_ADDRESS *TargetIp6Address, - IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL, - IN UINT32 Timeout, - IN BOOLEAN Override + IN IP6_SERVICE *IpSb, + IN EFI_IPv6_ADDRESS *TargetIp6Address, + IN EFI_MAC_ADDRESS *TargetLinkAddress OPTIONAL, + IN UINT32 Timeout, + IN BOOLEAN Override ) { - IP6_NEIGHBOR_ENTRY *Neighbor; + IP6_NEIGHBOR_ENTRY *Neighbor; Neighbor = Ip6FindNeighborEntry (IpSb, TargetIp6Address); if (Neighbor == NULL) { @@ -2761,24 +2774,24 @@ Ip6DelNeighbor ( VOID EFIAPI Ip6NdFasterTimerTicking ( - IN EFI_EVENT Event, - IN VOID *Context + IN EFI_EVENT Event, + IN VOID *Context ) { - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - LIST_ENTRY *Entry2; - IP6_INTERFACE *IpIf; - IP6_DELAY_JOIN_LIST *DelayNode; - EFI_IPv6_ADDRESS Source; - IP6_DAD_ENTRY *DupAddrDetect; - EFI_STATUS Status; - IP6_NEIGHBOR_ENTRY *NeighborCache; - EFI_IPv6_ADDRESS Destination; - IP6_SERVICE *IpSb; - BOOLEAN Flag; - - IpSb = (IP6_SERVICE *) Context; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + LIST_ENTRY *Entry2; + IP6_INTERFACE *IpIf; + IP6_DELAY_JOIN_LIST *DelayNode; + EFI_IPv6_ADDRESS Source; + IP6_DAD_ENTRY *DupAddrDetect; + EFI_STATUS Status; + IP6_NEIGHBOR_ENTRY *NeighborCache; + EFI_IPv6_ADDRESS Destination; + IP6_SERVICE *IpSb; + BOOLEAN Flag; + + IpSb = (IP6_SERVICE *)Context; NET_CHECK_SIGNATURE (IpSb, IP6_SERVICE_SIGNATURE); ZeroMem (&Source, sizeof (EFI_IPv6_ADDRESS)); @@ -2790,13 +2803,14 @@ Ip6NdFasterTimerTicking ( // if ((IpSb->Ip6ConfigInstance.Policy == Ip6ConfigPolicyAutomatic) && !IpSb->RouterAdvertiseReceived && - IpSb->SolicitTimer > 0 - ) { + (IpSb->SolicitTimer > 0) + ) + { if ((IpSb->Ticks == 0) || (--IpSb->Ticks == 0)) { Status = Ip6SendRouterSolicit (IpSb, NULL, NULL, NULL, NULL); if (!EFI_ERROR (Status)) { IpSb->SolicitTimer--; - IpSb->Ticks = (UINT32) IP6_GET_TICKS (IP6_RTR_SOLICITATION_INTERVAL); + IpSb->Ticks = (UINT32)IP6_GET_TICKS (IP6_RTR_SOLICITATION_INTERVAL); } } } @@ -2864,7 +2878,8 @@ Ip6NdFasterTimerTicking ( // Flag = FALSE; if ((DupAddrDetect->Receive == 0) || - (DupAddrDetect->Transmit <= DupAddrDetect->Receive)) { + (DupAddrDetect->Transmit <= DupAddrDetect->Receive)) + { Flag = TRUE; } @@ -2881,149 +2896,111 @@ Ip6NdFasterTimerTicking ( NeighborCache = NET_LIST_USER_STRUCT (Entry, IP6_NEIGHBOR_ENTRY, Link); switch (NeighborCache->State) { - case EfiNeighborInComplete: - if (NeighborCache->Ticks > 0) { - --NeighborCache->Ticks; - } - - // - // Retransmit Neighbor Solicitation messages approximately every - // RetransTimer milliseconds while awaiting a response. - // - if (NeighborCache->Ticks == 0) { - if (NeighborCache->Transmit > 1) { - // - // Send out multicast neighbor solicitation for address resolution. - // After last neighbor solicitation message has been sent out, wait - // for RetransTimer and then remove entry if no response is received. - // - Ip6CreateSNMulticastAddr (&NeighborCache->Neighbor, &Destination); - Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source); - if (EFI_ERROR (Status)) { - return; - } - - Status = Ip6SendNeighborSolicit ( - IpSb, - &Source, - &Destination, - &NeighborCache->Neighbor, - &IpSb->SnpMode.CurrentAddress - ); - if (EFI_ERROR (Status)) { - return; - } + case EfiNeighborInComplete: + if (NeighborCache->Ticks > 0) { + --NeighborCache->Ticks; } // - // Update the retransmit times. + // Retransmit Neighbor Solicitation messages approximately every + // RetransTimer milliseconds while awaiting a response. // - if (NeighborCache->Transmit > 0) { - --NeighborCache->Transmit; - NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); - } - } - - if (NeighborCache->Transmit == 0) { - // - // Timeout, send ICMP destination unreachable packet and then remove entry - // - Status = Ip6FreeNeighborEntry ( - IpSb, - NeighborCache, - TRUE, - TRUE, - EFI_ICMP_ERROR, - NULL, - NULL - ); - if (EFI_ERROR (Status)) { - return; - } - } + if (NeighborCache->Ticks == 0) { + if (NeighborCache->Transmit > 1) { + // + // Send out multicast neighbor solicitation for address resolution. + // After last neighbor solicitation message has been sent out, wait + // for RetransTimer and then remove entry if no response is received. + // + Ip6CreateSNMulticastAddr (&NeighborCache->Neighbor, &Destination); + Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source); + if (EFI_ERROR (Status)) { + return; + } - break; + Status = Ip6SendNeighborSolicit ( + IpSb, + &Source, + &Destination, + &NeighborCache->Neighbor, + &IpSb->SnpMode.CurrentAddress + ); + if (EFI_ERROR (Status)) { + return; + } + } - case EfiNeighborReachable: - // - // This entry is inserted by EfiIp6Neighbors() as static entry - // and will not timeout. - // - if (!NeighborCache->Dynamic && (NeighborCache->Ticks == IP6_INFINIT_LIFETIME)) { - break; - } + // + // Update the retransmit times. + // + if (NeighborCache->Transmit > 0) { + --NeighborCache->Transmit; + NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); + } + } - if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) { - if (NeighborCache->Dynamic) { + if (NeighborCache->Transmit == 0) { // - // This entry is inserted by EfiIp6Neighbors() as dynamic entry - // and will be deleted after timeout. + // Timeout, send ICMP destination unreachable packet and then remove entry // Status = Ip6FreeNeighborEntry ( IpSb, NeighborCache, - FALSE, TRUE, - EFI_TIMEOUT, + TRUE, + EFI_ICMP_ERROR, NULL, NULL ); if (EFI_ERROR (Status)) { return; } - } else { - NeighborCache->State = EfiNeighborStale; - NeighborCache->Ticks = (UINT32) IP6_INFINIT_LIFETIME; } - } - break; - - case EfiNeighborDelay: - if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) { + break; - NeighborCache->State = EfiNeighborProbe; - NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); - NeighborCache->Transmit = IP6_MAX_UNICAST_SOLICIT + 1; + case EfiNeighborReachable: // - // Send out unicast neighbor solicitation for Neighbor Unreachability Detection + // This entry is inserted by EfiIp6Neighbors() as static entry + // and will not timeout. // - Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source); - if (EFI_ERROR (Status)) { - return; + if (!NeighborCache->Dynamic && (NeighborCache->Ticks == IP6_INFINIT_LIFETIME)) { + break; } - Status = Ip6SendNeighborSolicit ( - IpSb, - &Source, - &NeighborCache->Neighbor, - &NeighborCache->Neighbor, - &IpSb->SnpMode.CurrentAddress - ); - if (EFI_ERROR (Status)) { - return; + if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) { + if (NeighborCache->Dynamic) { + // + // This entry is inserted by EfiIp6Neighbors() as dynamic entry + // and will be deleted after timeout. + // + Status = Ip6FreeNeighborEntry ( + IpSb, + NeighborCache, + FALSE, + TRUE, + EFI_TIMEOUT, + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + return; + } + } else { + NeighborCache->State = EfiNeighborStale; + NeighborCache->Ticks = (UINT32)IP6_INFINIT_LIFETIME; + } } - NeighborCache->Transmit--; - } - - break; - - case EfiNeighborProbe: - if (NeighborCache->Ticks > 0) { - --NeighborCache->Ticks; - } + break; - // - // Retransmit Neighbor Solicitation messages approximately every - // RetransTimer milliseconds while awaiting a response. - // - if (NeighborCache->Ticks == 0) { - if (NeighborCache->Transmit > 1) { + case EfiNeighborDelay: + if ((NeighborCache->Ticks == 0) || (--NeighborCache->Ticks == 0)) { + NeighborCache->State = EfiNeighborProbe; + NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); + NeighborCache->Transmit = IP6_MAX_UNICAST_SOLICIT + 1; // - // Send out unicast neighbor solicitation for Neighbor Unreachability - // Detection. After last neighbor solicitation message has been sent out, - // wait for RetransTimer and then remove entry if no response is received. + // Send out unicast neighbor solicitation for Neighbor Unreachability Detection // Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source); if (EFI_ERROR (Status)) { @@ -3040,39 +3017,76 @@ Ip6NdFasterTimerTicking ( if (EFI_ERROR (Status)) { return; } + + NeighborCache->Transmit--; } - // - // Update the retransmit times. - // - if (NeighborCache->Transmit > 0) { - --NeighborCache->Transmit; - NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); + break; + + case EfiNeighborProbe: + if (NeighborCache->Ticks > 0) { + --NeighborCache->Ticks; } - } - if (NeighborCache->Transmit == 0) { // - // Delete the neighbor entry. + // Retransmit Neighbor Solicitation messages approximately every + // RetransTimer milliseconds while awaiting a response. // - Status = Ip6FreeNeighborEntry ( - IpSb, - NeighborCache, - FALSE, - TRUE, - EFI_TIMEOUT, - NULL, - NULL - ); - if (EFI_ERROR (Status)) { - return; + if (NeighborCache->Ticks == 0) { + if (NeighborCache->Transmit > 1) { + // + // Send out unicast neighbor solicitation for Neighbor Unreachability + // Detection. After last neighbor solicitation message has been sent out, + // wait for RetransTimer and then remove entry if no response is received. + // + Status = Ip6SelectSourceAddress (IpSb, &NeighborCache->Neighbor, &Source); + if (EFI_ERROR (Status)) { + return; + } + + Status = Ip6SendNeighborSolicit ( + IpSb, + &Source, + &NeighborCache->Neighbor, + &NeighborCache->Neighbor, + &IpSb->SnpMode.CurrentAddress + ); + if (EFI_ERROR (Status)) { + return; + } + } + + // + // Update the retransmit times. + // + if (NeighborCache->Transmit > 0) { + --NeighborCache->Transmit; + NeighborCache->Ticks = IP6_GET_TICKS (IpSb->RetransTimer); + } } - } - break; + if (NeighborCache->Transmit == 0) { + // + // Delete the neighbor entry. + // + Status = Ip6FreeNeighborEntry ( + IpSb, + NeighborCache, + FALSE, + TRUE, + EFI_TIMEOUT, + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + return; + } + } - default: - break; + break; + + default: + break; } } } @@ -3087,15 +3101,15 @@ Ip6NdFasterTimerTicking ( **/ VOID Ip6NdTimerTicking ( - IN IP6_SERVICE *IpSb + IN IP6_SERVICE *IpSb ) { - LIST_ENTRY *Entry; - LIST_ENTRY *Next; - IP6_DEFAULT_ROUTER *DefaultRouter; - IP6_PREFIX_LIST_ENTRY *PrefixOption; - UINT8 Index; - IP6_ROUTE_CACHE_ENTRY *RouteCache; + LIST_ENTRY *Entry; + LIST_ENTRY *Next; + IP6_DEFAULT_ROUTER *DefaultRouter; + IP6_PREFIX_LIST_ENTRY *PrefixOption; + UINT8 Index; + IP6_ROUTE_CACHE_ENTRY *RouteCache; // // Decrease the lifetime of default router, if expires remove it from default router list. @@ -3114,11 +3128,12 @@ Ip6NdTimerTicking ( // NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->AutonomousPrefix) { PrefixOption = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link); - if (PrefixOption->ValidLifetime != (UINT32) IP6_INFINIT_LIFETIME) { + if (PrefixOption->ValidLifetime != (UINT32)IP6_INFINIT_LIFETIME) { if ((PrefixOption->ValidLifetime > 0) && (--PrefixOption->ValidLifetime > 0)) { - if ((PrefixOption->PreferredLifetime != (UINT32) IP6_INFINIT_LIFETIME) && + if ((PrefixOption->PreferredLifetime != (UINT32)IP6_INFINIT_LIFETIME) && (PrefixOption->PreferredLifetime > 0) - ) { + ) + { --PrefixOption->PreferredLifetime; } } else { @@ -3129,7 +3144,7 @@ Ip6NdTimerTicking ( NET_LIST_FOR_EACH_SAFE (Entry, Next, &IpSb->OnlinkPrefix) { PrefixOption = NET_LIST_USER_STRUCT (Entry, IP6_PREFIX_LIST_ENTRY, Link); - if (PrefixOption->ValidLifetime != (UINT32) IP6_INFINIT_LIFETIME) { + if (PrefixOption->ValidLifetime != (UINT32)IP6_INFINIT_LIFETIME) { if ((PrefixOption->ValidLifetime == 0) || (--PrefixOption->ValidLifetime == 0)) { Ip6DestroyPrefixListEntry (IpSb, PrefixOption, TRUE, TRUE); } @@ -3156,4 +3171,3 @@ Ip6NdTimerTicking ( } } } -