2 EFI IP6 route table and route cache table definitions.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __EFI_IP6_ROUTE_H__
11 #define __EFI_IP6_ROUTE_H__
13 #define IP6_DIRECT_ROUTE 0x00000001
14 #define IP6_PACKET_TOO_BIG 0x00000010
16 #define IP6_ROUTE_CACHE_HASH_SIZE 31
18 /// Max NO. of cache entry per hash bucket
20 #define IP6_ROUTE_CACHE_MAX 32
22 #define IP6_ROUTE_CACHE_HASH(Ip1, Ip2) Ip6RouteCacheHash ((Ip1), (Ip2))
29 EFI_IPv6_ADDRESS Destination
;
30 EFI_IPv6_ADDRESS NextHop
;
37 EFI_IPv6_ADDRESS Destination
;
38 EFI_IPv6_ADDRESS Source
;
39 EFI_IPv6_ADDRESS NextHop
;
40 } IP6_ROUTE_CACHE_ENTRY
;
43 LIST_ENTRY CacheBucket
[IP6_ROUTE_CACHE_HASH_SIZE
];
44 UINT8 CacheNum
[IP6_ROUTE_CACHE_HASH_SIZE
];
48 // Each IP6 instance has its own route table. Each ServiceBinding
49 // instance has a default route table and default address.
51 // All the route table entries with the same prefix length are linked
52 // together in one route area. For example, RouteArea[0] contains
53 // the default routes. A route table also contains a route cache.
56 typedef struct _IP6_ROUTE_TABLE
{
59 LIST_ENTRY RouteArea
[IP6_PREFIX_NUM
];
60 IP6_ROUTE_CACHE Cache
;
64 This is the worker function for IP6_ROUTE_CACHE_HASH(). It calculates the value
65 as the index of the route cache bucket according to the prefix of two IPv6 addresses.
67 @param[in] Ip1 The IPv6 address.
68 @param[in] Ip2 The IPv6 address.
70 @return The hash value of the prefix of two IPv6 addresses.
75 IN EFI_IPv6_ADDRESS
*Ip1
,
76 IN EFI_IPv6_ADDRESS
*Ip2
80 Allocate and initialize an IP6 route cache entry.
82 @param[in] Dst The destination address.
83 @param[in] Src The source address.
84 @param[in] GateWay The next hop address.
85 @param[in] Tag The tag from the caller. This marks all the cache entries
86 spawned from one route table entry.
88 @return NULL if it failed to allocate memory for the cache. Otherwise, point
89 to the created route cache entry.
92 IP6_ROUTE_CACHE_ENTRY
*
93 Ip6CreateRouteCacheEntry (
94 IN EFI_IPv6_ADDRESS
*Dst
,
95 IN EFI_IPv6_ADDRESS
*Src
,
96 IN EFI_IPv6_ADDRESS
*GateWay
,
101 Free the route cache entry. It is reference counted.
103 @param[in, out] RtCacheEntry The route cache entry to free.
107 Ip6FreeRouteCacheEntry (
108 IN OUT IP6_ROUTE_CACHE_ENTRY
*RtCacheEntry
112 Find a route cache with the destination and source address. This is
113 used by the ICMPv6 redirect message process.
115 @param[in] RtTable The route table to search the cache for.
116 @param[in] Dest The destination address.
117 @param[in] Src The source address.
119 @return NULL if no route entry to the (Dest, Src). Otherwise, point
120 to the correct route cache entry.
123 IP6_ROUTE_CACHE_ENTRY
*
125 IN IP6_ROUTE_TABLE
*RtTable
,
126 IN EFI_IPv6_ADDRESS
*Dest
,
127 IN EFI_IPv6_ADDRESS
*Src
131 Build a array of EFI_IP6_ROUTE_TABLE to be returned to the caller. The number
132 of EFI_IP6_ROUTE_TABLE is also returned.
134 @param[in] RouteTable The pointer of IP6_ROUTE_TABLE internal used.
135 @param[out] EfiRouteCount The number of returned route entries.
136 @param[out] EfiRouteTable The pointer to the array of EFI_IP6_ROUTE_TABLE.
137 If NULL, only the route entry count is returned.
139 @retval EFI_SUCCESS The EFI_IP6_ROUTE_TABLE successfully built.
140 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the route table.
144 Ip6BuildEfiRouteTable (
145 IN IP6_ROUTE_TABLE
*RouteTable
,
146 OUT UINT32
*EfiRouteCount
,
147 OUT EFI_IP6_ROUTE_TABLE
**EfiRouteTable OPTIONAL
151 Create an empty route table, includes its internal route cache.
153 @return NULL if failed to allocate memory for the route table. Otherwise,
154 the point to newly created route table.
158 Ip6CreateRouteTable (
163 Free the route table and its associated route cache. Route
164 table is reference counted.
166 @param[in, out] RtTable The route table to free.
171 IN OUT IP6_ROUTE_TABLE
*RtTable
175 Allocate a route entry then initialize it with the Destination/PrefixLength
178 @param[in] Destination The IPv6 destination address. This is an optional
179 parameter that may be NULL.
180 @param[in] PrefixLength The destination network's prefix length.
181 @param[in] GatewayAddress The next hop address. This is optional parameter
184 @return NULL if it failed to allocate memory. Otherwise, the newly created route entry.
188 Ip6CreateRouteEntry (
189 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
190 IN UINT8 PrefixLength
,
191 IN EFI_IPv6_ADDRESS
*GatewayAddress OPTIONAL
195 Search the route table for a most specific match to the Dst. It searches
196 from the longest route area (prefix length == 128) to the shortest route area
197 (default routes). In each route area, it will first search the instance's
198 route table, then the default route table. This is required per the following
200 1. IP search the route table for a most specific match.
201 2. The local route entries have precedence over the default route entry.
203 @param[in] RtTable The route table to search from.
204 @param[in] Destination The destination address to search. If NULL, search
205 the route table by NextHop.
206 @param[in] NextHop The next hop address. If NULL, search the route table
209 @return NULL if no route matches the Dst. Otherwise the point to the
210 most specific route to the Dst.
215 IN IP6_ROUTE_TABLE
*RtTable
,
216 IN EFI_IPv6_ADDRESS
*Destination OPTIONAL
,
217 IN EFI_IPv6_ADDRESS
*NextHop OPTIONAL
221 Free the route table entry. It is reference counted.
223 @param[in, out] RtEntry The route entry to free.
228 IN OUT IP6_ROUTE_ENTRY
*RtEntry
232 Add a route entry to the route table. It is the help function for EfiIp6Routes.
234 @param[in, out] RtTable Route table to add route to.
235 @param[in] Destination The destination of the network.
236 @param[in] PrefixLength The PrefixLength of the destination.
237 @param[in] GatewayAddress The next hop address.
239 @retval EFI_ACCESS_DENIED The same route already exists.
240 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry.
241 @retval EFI_SUCCESS The route was added successfully.
246 IN OUT IP6_ROUTE_TABLE
*RtTable
,
247 IN EFI_IPv6_ADDRESS
*Destination
,
248 IN UINT8 PrefixLength
,
249 IN EFI_IPv6_ADDRESS
*GatewayAddress
253 Remove a route entry and all the route caches spawn from it.
254 It is the help function for EfiIp6Routes.
256 @param[in, out] RtTable The route table to remove the route from.
257 @param[in] Destination The destination network.
258 @param[in] PrefixLength The PrefixLength of the Destination.
259 @param[in] GatewayAddress The next hop address.
261 @retval EFI_SUCCESS Successfully removed the route entry.
262 @retval EFI_NOT_FOUND There is no route entry in the table with that
268 IN OUT IP6_ROUTE_TABLE
*RtTable
,
269 IN EFI_IPv6_ADDRESS
*Destination
,
270 IN UINT8 PrefixLength
,
271 IN EFI_IPv6_ADDRESS
*GatewayAddress
275 Search the route table to route the packet. Return/create a route
276 cache if there is a route to the destination.
278 @param[in] IpSb The IP6 service data.
279 @param[in] Dest The destination address to search for.
280 @param[in] Src The source address to search for.
282 @return NULL if failed to route packet. Otherwise, a route cache
283 entry that can be used to route packet.
286 IP6_ROUTE_CACHE_ENTRY
*
288 IN IP6_SERVICE
*IpSb
,
289 IN EFI_IPv6_ADDRESS
*Dest
,
290 IN EFI_IPv6_ADDRESS
*Src