]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Route.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Route.c
index cdf8538dcd691c68f616bb890237407feaa588f1..124c0730ad8740cfce5fc92f405412f0f441823f 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
-All rights reserved. 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
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -204,7 +198,7 @@ Ip4CreateRouteTable (
   RtTable->RefCnt   = 1;\r
   RtTable->TotalNum = 0;\r
 \r
-  for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
+  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {\r
     InitializeListHead (&(RtTable->RouteArea[Index]));\r
   }\r
 \r
@@ -241,7 +235,7 @@ Ip4FreeRouteTable (
   //\r
   // Free all the route table entry and its route cache.\r
   //\r
-  for (Index = 0; Index < IP4_MASK_NUM; Index++) {\r
+  for (Index = 0; Index <= IP4_MASK_MAX; Index++) {\r
     NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtTable->RouteArea[Index])) {\r
       RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r
 \r
@@ -469,7 +463,7 @@ Ip4FindRouteEntry (
 \r
   RtEntry = NULL;\r
 \r
-  for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r
+  for (Index = IP4_MASK_MAX; Index >= 0; Index--) {\r
     for (Table = RtTable; Table != NULL; Table = Table->Next) {\r
       NET_LIST_FOR_EACH (Entry, &Table->RouteArea[Index]) {\r
         RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r
@@ -494,6 +488,11 @@ Ip4FindRouteEntry (
   @param[in]  RtTable               The route table to search from\r
   @param[in]  Dest                  The destination address to search for\r
   @param[in]  Src                   The source address to search for\r
+  @param[in]  SubnetMask            The subnet mask of the Src address, this field is\r
+                                    used to check if the station is using /32 subnet.\r
+  @param[in]  AlwaysTryDestAddr     Always try to use the dest address as next hop even\r
+                                    though we can't find a matching route entry. This\r
+                                    field is only valid when using /32 subnet.\r
 \r
   @return NULL if failed to route packet, otherwise a route cache\r
           entry that can be used to route packet.\r
@@ -503,7 +502,9 @@ IP4_ROUTE_CACHE_ENTRY *
 Ip4Route (\r
   IN IP4_ROUTE_TABLE        *RtTable,\r
   IN IP4_ADDR               Dest,\r
-  IN IP4_ADDR               Src\r
+  IN IP4_ADDR               Src,\r
+  IN IP4_ADDR               SubnetMask,\r
+  IN BOOLEAN                AlwaysTryDestAddr\r
   )\r
 {\r
   LIST_ENTRY                *Head;\r
@@ -535,7 +536,11 @@ Ip4Route (
   RtEntry = Ip4FindRouteEntry (RtTable, Dest);\r
 \r
   if (RtEntry == NULL) {\r
-    return NULL;\r
+    if (SubnetMask != IP4_ALLONE_ADDRESS) {\r
+      return NULL;\r
+    } else if (!AlwaysTryDestAddr) {\r
+      return NULL;\r
+    }\r
   }\r
 \r
   //\r
@@ -544,16 +549,23 @@ Ip4Route (
   // network. Otherwise, it is an indirect route, the packet will be\r
   // sent to the next hop router.\r
   //\r
-  if ((RtEntry->Flag & IP4_DIRECT_ROUTE) != 0) {\r
+  // When using /32 subnet mask, the packet will always be sent to the direct\r
+  // destination first, if we can't find a matching route cache.\r
+  //\r
+  if (SubnetMask == IP4_ALLONE_ADDRESS || ((RtEntry->Flag & IP4_DIRECT_ROUTE) != 0)) {\r
     NextHop = Dest;\r
   } else {\r
     NextHop = RtEntry->NextHop;\r
   }\r
 \r
-  Ip4FreeRouteEntry (RtEntry);\r
+  if (RtEntry != NULL) {\r
+    Ip4FreeRouteEntry (RtEntry);\r
+  }\r
 \r
   //\r
   // Create a route cache entry, and tag it as spawned from this route entry\r
+  // For /32 subnet mask, the default route in RtEntry will be used if failed\r
+  // to send the packet to driect destination address.\r
   //\r
   RtCacheEntry = Ip4CreateRouteCacheEntry (Dest, Src, NextHop, (UINTN) RtEntry);\r
 \r
@@ -641,7 +653,7 @@ Ip4BuildEfiRouteTable (
   //\r
   Count = 0;\r
 \r
-  for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r
+  for (Index = IP4_MASK_MAX; Index >= 0; Index--) {\r
     for (RtTable = IpInstance->RouteTable; RtTable != NULL; RtTable = RtTable->Next) {\r
       NET_LIST_FOR_EACH (Entry, &(RtTable->RouteArea[Index])) {\r
         RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r