/** @file\r
\r
-Copyright (c) 2005 - 2006, 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
ASSERT (RtEntry->RefCnt > 0);\r
\r
if (--RtEntry->RefCnt == 0) {\r
- gBS->FreePool (RtEntry);\r
+ FreePool (RtEntry);\r
}\r
}\r
\r
ASSERT (RtCacheEntry->RefCnt > 0);\r
\r
if (--RtCacheEntry->RefCnt == 0) {\r
- gBS->FreePool (RtCacheEntry);\r
+ FreePool (RtCacheEntry);\r
}\r
}\r
\r
{\r
UINT32 Index;\r
\r
- for (Index = 0; Index < IP4_ROUTE_CACHE_HASH; Index++) {\r
+ for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {\r
InitializeListHead (&(RtCache->CacheBucket[Index]));\r
}\r
}\r
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
UINT32 Index;\r
\r
- for (Index = 0; Index < IP4_ROUTE_CACHE_HASH; Index++) {\r
+ for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &(RtCache->CacheBucket[Index])) {\r
RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);\r
\r
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
//\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
\r
Ip4CleanRouteCache (&RtTable->Cache);\r
\r
- gBS->FreePool (RtTable);\r
+ FreePool (RtTable);\r
}\r
\r
\r
IP4_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
UINT32 Index;\r
\r
- for (Index = 0; Index < IP4_ROUTE_CACHE_HASH; Index++) {\r
+ for (Index = 0; Index < IP4_ROUTE_CACHE_HASH_VALUE; Index++) {\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtCache->CacheBucket[Index]) {\r
\r
RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_CACHE_ENTRY, Link);\r
\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
@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
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
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
// 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
RtTable = IpInstance->RouteTable;\r
\r
if (IpInstance->EfiRouteTable != NULL) {\r
- gBS->FreePool (IpInstance->EfiRouteTable);\r
+ FreePool (IpInstance->EfiRouteTable);\r
\r
IpInstance->EfiRouteTable = NULL;\r
IpInstance->EfiRouteCount = 0;\r
//\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