]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/Ip6Route.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Route.c
index 3e47fa4cc6154763b71f5e47b785f2eb1346de61..2f91ba9ef5334c3c5f3f25b0b44fbcbe077acb59 100644 (file)
@@ -3,13 +3,7 @@
 \r
   Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 **/\r
 UINT32\r
 Ip6RouteCacheHash (\r
-  IN EFI_IPv6_ADDRESS       *Ip1,\r
-  IN EFI_IPv6_ADDRESS       *Ip2\r
+  IN EFI_IPv6_ADDRESS  *Ip1,\r
+  IN EFI_IPv6_ADDRESS  *Ip2\r
   )\r
 {\r
-  UINT32 Prefix1;\r
-  UINT32 Prefix2;\r
+  UINT32  Prefix1;\r
+  UINT32  Prefix2;\r
 \r
-  Prefix1 = *((UINT32 *) ((UINTN *) (Ip1)));\r
-  Prefix2 = *((UINT32 *) ((UINTN *) (Ip2)));\r
+  Prefix1 = *((UINT32 *)((UINTN *)(Ip1)));\r
+  Prefix2 = *((UINT32 *)((UINTN *)(Ip2)));\r
 \r
-  return ((UINT32) (Prefix1 ^ Prefix2) % IP6_ROUTE_CACHE_HASH_SIZE);\r
+  return ((UINT32)(Prefix1 ^ Prefix2) % IP6_ROUTE_CACHE_HASH_SIZE);\r
 }\r
 \r
 /**\r
@@ -50,17 +44,17 @@ Ip6RouteCacheHash (
   @param[in]  GatewayAddress  The next hop address. This is an optional parameter\r
                               that may be NULL.\r
 \r
-  @return NULL if failed to allocate memeory; otherwise, the newly created route entry.\r
+  @return NULL if failed to allocate memory; otherwise, the newly created route entry.\r
 \r
 **/\r
 IP6_ROUTE_ENTRY *\r
 Ip6CreateRouteEntry (\r
-  IN EFI_IPv6_ADDRESS       *Destination    OPTIONAL,\r
-  IN UINT8                  PrefixLength,\r
-  IN EFI_IPv6_ADDRESS       *GatewayAddress OPTIONAL\r
+  IN EFI_IPv6_ADDRESS  *Destination    OPTIONAL,\r
+  IN UINT8             PrefixLength,\r
+  IN EFI_IPv6_ADDRESS  *GatewayAddress OPTIONAL\r
   )\r
 {\r
-  IP6_ROUTE_ENTRY           *RtEntry;\r
+  IP6_ROUTE_ENTRY  *RtEntry;\r
 \r
   RtEntry = AllocateZeroPool (sizeof (IP6_ROUTE_ENTRY));\r
 \r
@@ -91,7 +85,7 @@ Ip6CreateRouteEntry (
 **/\r
 VOID\r
 Ip6FreeRouteEntry (\r
-  IN OUT IP6_ROUTE_ENTRY    *RtEntry\r
+  IN OUT IP6_ROUTE_ENTRY  *RtEntry\r
   )\r
 {\r
   ASSERT ((RtEntry != NULL) && (RtEntry->RefCnt > 0));\r
@@ -111,7 +105,7 @@ Ip6FreeRouteEntry (
   2. The local route entries have precedence over the default route entry.\r
 \r
   @param[in]  RtTable       The route table to search from.\r
-  @param[in]  Destination   The destionation address to search. If NULL, search\r
+  @param[in]  Destination   The destination address to search. If NULL, search\r
                             the route table by NextHop.\r
   @param[in]  NextHop       The next hop address. If NULL, search the route table\r
                             by Destination.\r
@@ -122,14 +116,14 @@ Ip6FreeRouteEntry (
 **/\r
 IP6_ROUTE_ENTRY *\r
 Ip6FindRouteEntry (\r
-  IN IP6_ROUTE_TABLE        *RtTable,\r
-  IN EFI_IPv6_ADDRESS       *Destination OPTIONAL,\r
-  IN EFI_IPv6_ADDRESS       *NextHop     OPTIONAL\r
+  IN IP6_ROUTE_TABLE   *RtTable,\r
+  IN EFI_IPv6_ADDRESS  *Destination OPTIONAL,\r
+  IN EFI_IPv6_ADDRESS  *NextHop     OPTIONAL\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  IP6_ROUTE_ENTRY           *RtEntry;\r
-  INTN                      Index;\r
+  LIST_ENTRY       *Entry;\r
+  IP6_ROUTE_ENTRY  *RtEntry;\r
+  INTN             Index;\r
 \r
   ASSERT (Destination != NULL || NextHop != NULL);\r
 \r
@@ -150,7 +144,6 @@ Ip6FindRouteEntry (
           return RtEntry;\r
         }\r
       }\r
-\r
     }\r
   }\r
 \r
@@ -172,13 +165,13 @@ Ip6FindRouteEntry (
 **/\r
 IP6_ROUTE_CACHE_ENTRY *\r
 Ip6CreateRouteCacheEntry (\r
-  IN EFI_IPv6_ADDRESS       *Dst,\r
-  IN EFI_IPv6_ADDRESS       *Src,\r
-  IN EFI_IPv6_ADDRESS       *GateWay,\r
-  IN UINTN                  Tag\r
+  IN EFI_IPv6_ADDRESS  *Dst,\r
+  IN EFI_IPv6_ADDRESS  *Src,\r
+  IN EFI_IPv6_ADDRESS  *GateWay,\r
+  IN UINTN             Tag\r
   )\r
 {\r
-  IP6_ROUTE_CACHE_ENTRY     *RtCacheEntry;\r
+  IP6_ROUTE_CACHE_ENTRY  *RtCacheEntry;\r
 \r
   RtCacheEntry = AllocatePool (sizeof (IP6_ROUTE_CACHE_ENTRY));\r
 \r
@@ -216,7 +209,7 @@ Ip6FreeRouteCacheEntry (
 \r
 /**\r
   Find a route cache with the destination and source address. This is\r
-  used by the ICMPv6 redirect messasge process.\r
+  used by the ICMPv6 redirect message process.\r
 \r
   @param[in]  RtTable       The route table to search the cache for.\r
   @param[in]  Dest          The destination address.\r
@@ -228,21 +221,21 @@ Ip6FreeRouteCacheEntry (
 **/\r
 IP6_ROUTE_CACHE_ENTRY *\r
 Ip6FindRouteCache (\r
-  IN IP6_ROUTE_TABLE        *RtTable,\r
-  IN EFI_IPv6_ADDRESS       *Dest,\r
-  IN EFI_IPv6_ADDRESS       *Src\r
+  IN IP6_ROUTE_TABLE   *RtTable,\r
+  IN EFI_IPv6_ADDRESS  *Dest,\r
+  IN EFI_IPv6_ADDRESS  *Src\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  IP6_ROUTE_CACHE_ENTRY     *RtCacheEntry;\r
-  UINT32                    Index;\r
+  LIST_ENTRY             *Entry;\r
+  IP6_ROUTE_CACHE_ENTRY  *RtCacheEntry;\r
+  UINT32                 Index;\r
 \r
   Index = IP6_ROUTE_CACHE_HASH (Dest, Src);\r
 \r
   NET_LIST_FOR_EACH (Entry, &RtTable->Cache.CacheBucket[Index]) {\r
     RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);\r
 \r
-    if (EFI_IP6_EQUAL (Dest, &RtCacheEntry->Destination)&& EFI_IP6_EQUAL (Src, &RtCacheEntry->Source)) {\r
+    if (EFI_IP6_EQUAL (Dest, &RtCacheEntry->Destination) && EFI_IP6_EQUAL (Src, &RtCacheEntry->Source)) {\r
       NET_GET_REF (RtCacheEntry);\r
       return RtCacheEntry;\r
     }\r
@@ -266,16 +259,16 @@ Ip6FindRouteCache (
 **/\r
 EFI_STATUS\r
 Ip6BuildEfiRouteTable (\r
-  IN IP6_ROUTE_TABLE        *RouteTable,\r
-  OUT UINT32                *EfiRouteCount,\r
-  OUT EFI_IP6_ROUTE_TABLE   **EfiRouteTable OPTIONAL\r
+  IN IP6_ROUTE_TABLE       *RouteTable,\r
+  OUT UINT32               *EfiRouteCount,\r
+  OUT EFI_IP6_ROUTE_TABLE  **EfiRouteTable OPTIONAL\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  IP6_ROUTE_ENTRY           *RtEntry;\r
-  EFI_IP6_ROUTE_TABLE       *EfiTable;\r
-  UINT32                    Count;\r
-  INT32                     Index;\r
+  LIST_ENTRY           *Entry;\r
+  IP6_ROUTE_ENTRY      *RtEntry;\r
+  EFI_IP6_ROUTE_TABLE  *EfiTable;\r
+  UINT32               Count;\r
+  INT32                Index;\r
 \r
   ASSERT (EfiRouteCount != NULL);\r
 \r
@@ -301,7 +294,6 @@ Ip6BuildEfiRouteTable (
   Count = 0;\r
 \r
   for (Index = IP6_PREFIX_MAX; Index >= 0; Index--) {\r
-\r
     NET_LIST_FOR_EACH (Entry, &(RouteTable->RouteArea[Index])) {\r
       RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
 \r
@@ -335,8 +327,8 @@ Ip6CreateRouteTable (
   VOID\r
   )\r
 {\r
-  IP6_ROUTE_TABLE           *RtTable;\r
-  UINT32                    Index;\r
+  IP6_ROUTE_TABLE  *RtTable;\r
+  UINT32           Index;\r
 \r
   RtTable = AllocatePool (sizeof (IP6_ROUTE_TABLE));\r
   if (RtTable == NULL) {\r
@@ -367,19 +359,19 @@ Ip6CreateRouteTable (
 **/\r
 VOID\r
 Ip6CleanRouteTable (\r
-  IN OUT IP6_ROUTE_TABLE        *RtTable\r
+  IN OUT IP6_ROUTE_TABLE  *RtTable\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  LIST_ENTRY                *Next;\r
-  IP6_ROUTE_ENTRY           *RtEntry;\r
-  IP6_ROUTE_CACHE_ENTRY     *RtCacheEntry;\r
-  UINT32                    Index;\r
+  LIST_ENTRY             *Entry;\r
+  LIST_ENTRY             *Next;\r
+  IP6_ROUTE_ENTRY        *RtEntry;\r
+  IP6_ROUTE_CACHE_ENTRY  *RtCacheEntry;\r
+  UINT32                 Index;\r
 \r
   ASSERT (RtTable->RefCnt > 0);\r
 \r
   if (--RtTable->RefCnt > 0) {\r
-    return ;\r
+    return;\r
   }\r
 \r
   //\r
@@ -416,18 +408,17 @@ Ip6CleanRouteTable (
 **/\r
 VOID\r
 Ip6PurgeRouteCache (\r
-  IN IP6_ROUTE_CACHE        *RtCache,\r
-  IN UINTN                  Tag\r
+  IN IP6_ROUTE_CACHE  *RtCache,\r
+  IN UINTN            Tag\r
   )\r
 {\r
-  LIST_ENTRY                *Entry;\r
-  LIST_ENTRY                *Next;\r
-  IP6_ROUTE_CACHE_ENTRY     *RtCacheEntry;\r
-  UINT32                    Index;\r
+  LIST_ENTRY             *Entry;\r
+  LIST_ENTRY             *Next;\r
+  IP6_ROUTE_CACHE_ENTRY  *RtCacheEntry;\r
+  UINT32                 Index;\r
 \r
   for (Index = 0; Index < IP6_ROUTE_CACHE_HASH_SIZE; Index++) {\r
     NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtCache->CacheBucket[Index]) {\r
-\r
       RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);\r
 \r
       if (RtCacheEntry->Tag == Tag) {\r
@@ -453,15 +444,15 @@ Ip6PurgeRouteCache (
 **/\r
 EFI_STATUS\r
 Ip6AddRoute (\r
-  IN OUT IP6_ROUTE_TABLE    *RtTable,\r
-  IN EFI_IPv6_ADDRESS       *Destination,\r
-  IN UINT8                  PrefixLength,\r
-  IN EFI_IPv6_ADDRESS       *GatewayAddress\r
+  IN OUT IP6_ROUTE_TABLE  *RtTable,\r
+  IN EFI_IPv6_ADDRESS     *Destination,\r
+  IN UINT8                PrefixLength,\r
+  IN EFI_IPv6_ADDRESS     *GatewayAddress\r
   )\r
 {\r
-  LIST_ENTRY                *ListHead;\r
-  LIST_ENTRY                *Entry;\r
-  IP6_ROUTE_ENTRY           *Route;\r
+  LIST_ENTRY       *ListHead;\r
+  LIST_ENTRY       *Entry;\r
+  IP6_ROUTE_ENTRY  *Route;\r
 \r
   ListHead = &RtTable->RouteArea[PrefixLength];\r
 \r
@@ -472,7 +463,8 @@ Ip6AddRoute (
     Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
 \r
     if (NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength) &&\r
-        EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {\r
+        EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop))\r
+    {\r
       return EFI_ACCESS_DENIED;\r
     }\r
   }\r
@@ -512,17 +504,17 @@ Ip6AddRoute (
 **/\r
 EFI_STATUS\r
 Ip6DelRoute (\r
-  IN OUT IP6_ROUTE_TABLE    *RtTable,\r
-  IN EFI_IPv6_ADDRESS       *Destination,\r
-  IN UINT8                  PrefixLength,\r
-  IN EFI_IPv6_ADDRESS       *GatewayAddress\r
+  IN OUT IP6_ROUTE_TABLE  *RtTable,\r
+  IN EFI_IPv6_ADDRESS     *Destination,\r
+  IN UINT8                PrefixLength,\r
+  IN EFI_IPv6_ADDRESS     *GatewayAddress\r
   )\r
 {\r
-  LIST_ENTRY                *ListHead;\r
-  LIST_ENTRY                *Entry;\r
-  LIST_ENTRY                *Next;\r
-  IP6_ROUTE_ENTRY           *Route;\r
-  UINT32                    TotalNum;\r
+  LIST_ENTRY       *ListHead;\r
+  LIST_ENTRY       *Entry;\r
+  LIST_ENTRY       *Next;\r
+  IP6_ROUTE_ENTRY  *Route;\r
+  UINT32           TotalNum;\r
 \r
   ListHead = &RtTable->RouteArea[PrefixLength];\r
   TotalNum = RtTable->TotalNum;\r
@@ -530,14 +522,15 @@ Ip6DelRoute (
   NET_LIST_FOR_EACH_SAFE (Entry, Next, ListHead) {\r
     Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
 \r
-    if (Destination != NULL && !NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength)) {\r
+    if ((Destination != NULL) && !NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength)) {\r
       continue;\r
     }\r
-    if (GatewayAddress != NULL && !EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {\r
+\r
+    if ((GatewayAddress != NULL) && !EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {\r
       continue;\r
     }\r
 \r
-    Ip6PurgeRouteCache (&RtTable->Cache, (UINTN) Route);\r
+    Ip6PurgeRouteCache (&RtTable->Cache, (UINTN)Route);\r
     RemoveEntryList (Entry);\r
     Ip6FreeRouteEntry (Route);\r
 \r
@@ -562,17 +555,17 @@ Ip6DelRoute (
 **/\r
 IP6_ROUTE_CACHE_ENTRY *\r
 Ip6Route (\r
-  IN IP6_SERVICE            *IpSb,\r
-  IN EFI_IPv6_ADDRESS       *Dest,\r
-  IN EFI_IPv6_ADDRESS       *Src\r
+  IN IP6_SERVICE       *IpSb,\r
+  IN EFI_IPv6_ADDRESS  *Dest,\r
+  IN EFI_IPv6_ADDRESS  *Src\r
   )\r
 {\r
-  IP6_ROUTE_TABLE           *RtTable;\r
-  LIST_ENTRY                *ListHead;\r
-  IP6_ROUTE_CACHE_ENTRY     *RtCacheEntry;\r
-  IP6_ROUTE_ENTRY           *RtEntry;\r
-  EFI_IPv6_ADDRESS          NextHop;\r
-  UINT32                    Index;\r
+  IP6_ROUTE_TABLE        *RtTable;\r
+  LIST_ENTRY             *ListHead;\r
+  IP6_ROUTE_CACHE_ENTRY  *RtCacheEntry;\r
+  IP6_ROUTE_ENTRY        *RtEntry;\r
+  EFI_IPv6_ADDRESS       NextHop;\r
+  UINT32                 Index;\r
 \r
   RtTable = IpSb->RouteTable;\r
 \r
@@ -620,7 +613,7 @@ Ip6Route (
   //\r
   // Create a route cache entry, and tag it as spawned from this route entry\r
   //\r
-  RtCacheEntry = Ip6CreateRouteCacheEntry (Dest, Src, &NextHop, (UINTN) RtEntry);\r
+  RtCacheEntry = Ip6CreateRouteCacheEntry (Dest, Src, &NextHop, (UINTN)RtEntry);\r
 \r
   if (RtCacheEntry == NULL) {\r
     return NULL;\r
@@ -632,4 +625,3 @@ Ip6Route (
 \r
   return RtCacheEntry;\r
 }\r
-\r