/** @file\r
-\r
-Copyright (c) 2005 - 2006, Intel Corporation\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
-\r
-\r
-Module Name:\r
-\r
- Ip4Route.h\r
-\r
-Abstract:\r
-\r
EFI IP4 route table and route cache table defintions.\r
\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#ifndef __EFI_IP4_ROUTE_H__\r
#define __EFI_IP4_ROUTE_H__\r
\r
-#include "IP4Common.h"\r
+#include "Ip4Common.h"\r
\r
-enum {\r
- IP4_DIRECT_ROUTE = 0x00000001,\r
+#define IP4_DIRECT_ROUTE 0x00000001\r
\r
- IP4_ROUTE_CACHE_HASH = 31,\r
- IP4_ROUTE_CACHE_MAX = 64 // Max NO. of cache entry per hash bucket\r
-};\r
+#define IP4_ROUTE_CACHE_HASH_VALUE 31\r
+#define IP4_ROUTE_CACHE_MAX 64 // Max NO. of cache entry per hash bucket\r
\r
-#define IP4_ROUTE_CACHE_HASH(Dst, Src) (((Dst) ^ (Src)) % IP4_ROUTE_CACHE_HASH)\r
+#define IP4_ROUTE_CACHE_HASH(Dst, Src) (((Dst) ^ (Src)) % IP4_ROUTE_CACHE_HASH_VALUE)\r
\r
-//\r
-// The route entry in the route table. Dest/Netmask is the destion\r
-// network. The nexthop is the gateway to send the packet to in\r
-// order to reach the Dest/Netmask. If the Flag has IP4_DIRECT_ROUTE\r
-// on, the gateway is the destination of the IP packet itself. Route\r
-// enties of the connected network have the flag on.\r
-//\r
+///\r
+/// The route entry in the route table. Dest/Netmask is the destion\r
+/// network. The nexthop is the gateway to send the packet to in\r
+/// order to reach the Dest/Netmask. If the Flag has IP4_DIRECT_ROUTE\r
+/// on, the gateway is the destination of the IP packet itself. Route\r
+/// enties of the connected network have the flag on.\r
+///\r
typedef struct {\r
LIST_ENTRY Link;\r
INTN RefCnt;\r
UINT32 Flag;\r
} IP4_ROUTE_ENTRY;\r
\r
-//\r
-// The route cache entry. The route cache entry is optional.\r
-// But it is necessary to support the ICMP redirect message.\r
-// Check Ip4ProcessIcmpRedirect for information.\r
-//\r
-// The cache entry field Tag is used to tag all the route\r
-// cache entry spawned from a route table entry. This makes\r
-// it simple to delete all the route cache entries from a\r
-// to-be-deleted route entry.\r
-//\r
+///\r
+/// The route cache entry. The route cache entry is optional.\r
+/// But it is necessary to support the ICMP redirect message.\r
+/// Check Ip4ProcessIcmpRedirect for information.\r
+///\r
+/// The cache entry field Tag is used to tag all the route\r
+/// cache entry spawned from a route table entry. This makes\r
+/// it simple to delete all the route cache entries from a\r
+/// to-be-deleted route entry.\r
+///\r
typedef struct {\r
LIST_ENTRY Link;\r
INTN RefCnt;\r
UINTN Tag;\r
} IP4_ROUTE_CACHE_ENTRY;\r
\r
-//\r
-// The route cache table is organized as a hash table. Each\r
-// IP4 route table has a embedded route cache. For now the\r
-// route cache and route table are binded togehter. But keep\r
-// the route cache a seperated structure in case we want to\r
-// detach them later.\r
-//\r
+///\r
+/// The route cache table is organized as a hash table. Each\r
+/// IP4 route table has a embedded route cache. For now the\r
+/// route cache and route table are binded togehter. But keep\r
+/// the route cache a seperated structure in case we want to\r
+/// detach them later.\r
+///\r
typedef struct {\r
- LIST_ENTRY CacheBucket[IP4_ROUTE_CACHE_HASH];\r
+ LIST_ENTRY CacheBucket[IP4_ROUTE_CACHE_HASH_VALUE];\r
} IP4_ROUTE_CACHE;\r
\r
-//\r
-// Each IP4 instance has its own route table. Each ServiceBinding\r
-// instance has a default route table and default address.\r
-//\r
-// All the route table entries with the same mask are linked\r
-// together in one route area. For example, RouteArea[0] contains\r
-// the default routes. A route table also contains a route cache.\r
-//\r
+///\r
+/// Each IP4 instance has its own route table. Each ServiceBinding\r
+/// instance has a default route table and default address.\r
+///\r
+/// All the route table entries with the same mask are linked\r
+/// together in one route area. For example, RouteArea[0] contains\r
+/// the default routes. A route table also contains a route cache.\r
+///\r
typedef struct _IP4_ROUTE_TABLE IP4_ROUTE_TABLE;\r
\r
struct _IP4_ROUTE_TABLE {\r
IP4_ROUTE_CACHE Cache;\r
};\r
\r
-IP4_ROUTE_TABLE*\r
+/**\r
+ Create an empty route table, includes its internal route cache\r
+\r
+ @return NULL if failed to allocate memory for the route table, otherwise\r
+ the point to newly created route table.\r
+\r
+**/\r
+IP4_ROUTE_TABLE *\r
Ip4CreateRouteTable (\r
VOID\r
);\r
\r
+/**\r
+ Free the route table and its associated route cache. Route\r
+ table is reference counted.\r
+\r
+ @param[in] RtTable The route table to free.\r
+\r
+**/\r
VOID\r
Ip4FreeRouteTable (\r
- IN IP4_ROUTE_TABLE *RouteTable\r
+ IN IP4_ROUTE_TABLE *RtTable\r
);\r
\r
+/**\r
+ Add a route entry to the route table. All the IP4_ADDRs are in\r
+ host byte order.\r
+\r
+ @param[in, out] RtTable Route table to add route to\r
+ @param[in] Dest The destination of the network\r
+ @param[in] Netmask The netmask of the destination\r
+ @param[in] Gateway The next hop address\r
+\r
+ @retval EFI_ACCESS_DENIED The same route already exists\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry\r
+ @retval EFI_SUCCESS The route is added successfully.\r
+\r
+**/\r
EFI_STATUS\r
Ip4AddRoute (\r
- IN IP4_ROUTE_TABLE *RtTable,\r
- IN IP4_ADDR Dest,\r
- IN IP4_ADDR Netmask,\r
- IN IP4_ADDR Gateway\r
+ IN OUT IP4_ROUTE_TABLE *RtTable,\r
+ IN IP4_ADDR Dest,\r
+ IN IP4_ADDR Netmask,\r
+ IN IP4_ADDR Gateway\r
);\r
\r
+/**\r
+ Remove a route entry and all the route caches spawn from it.\r
+\r
+ @param RtTable The route table to remove the route from\r
+ @param Dest The destination network\r
+ @param Netmask The netmask of the Dest\r
+ @param Gateway The next hop address\r
+\r
+ @retval EFI_SUCCESS The route entry is successfully removed\r
+ @retval EFI_NOT_FOUND There is no route entry in the table with that\r
+ properity.\r
+\r
+**/\r
EFI_STATUS\r
Ip4DelRoute (\r
- IN IP4_ROUTE_TABLE *RtTable,\r
- IN IP4_ADDR Dest,\r
- IN IP4_ADDR Netmask,\r
- IN IP4_ADDR Gateway\r
+ IN OUT IP4_ROUTE_TABLE *RtTable,\r
+ IN IP4_ADDR Dest,\r
+ IN IP4_ADDR Netmask,\r
+ IN IP4_ADDR Gateway\r
);\r
\r
+/**\r
+ Find a route cache with the dst and src. This is used by ICMP\r
+ redirect messasge process. All kinds of redirect is treated as\r
+ host redirect according to RFC1122. So, only route cache entries\r
+ are modified according to the ICMP redirect message.\r
+\r
+ @param[in] RtTable The route table to search the cache for\r
+ @param[in] Dest The destination address\r
+ @param[in] Src The source address\r
+\r
+ @return NULL if no route entry to the (Dest, Src). Otherwise the point\r
+ to the correct route cache entry.\r
+\r
+**/\r
IP4_ROUTE_CACHE_ENTRY *\r
Ip4FindRouteCache (\r
IN IP4_ROUTE_TABLE *RtTable,\r
IN IP4_ADDR Src\r
);\r
\r
+/**\r
+ Free the route cache entry. It is reference counted.\r
+\r
+ @param RtCacheEntry The route cache entry to free.\r
+\r
+**/\r
VOID\r
Ip4FreeRouteCacheEntry (\r
IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry\r
);\r
\r
+/**\r
+ Search the route table to route the packet. Return/create a route\r
+ cache if there is a route to the destination.\r
+\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
+\r
+**/\r
IP4_ROUTE_CACHE_ENTRY *\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
+/**\r
+ Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of\r
+ GetModeData. The EFI_IP4_ROUTE_TABLE is clumsy to use in the\r
+ internal operation of the IP4 driver.\r
+\r
+ @param[in] IpInstance The IP4 child that requests the route table.\r
+\r
+ @retval EFI_SUCCESS The route table is successfully build\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the rotue table.\r
+\r
+**/\r
EFI_STATUS\r
Ip4BuildEfiRouteTable (\r
IN IP4_PROTOCOL *IpInstance\r