]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Ip6Dxe/Ip6Route.h
BaseTools: Library hashing fix and optimization for --hash feature
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Route.h
CommitLineData
a3bcde70
HT
1/** @file\r
2 EFI IP6 route table and route cache table defintions.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5\r
ecf98fbc 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
7\r
8**/\r
9\r
10#ifndef __EFI_IP6_ROUTE_H__\r
11#define __EFI_IP6_ROUTE_H__\r
12\r
13#define IP6_DIRECT_ROUTE 0x00000001\r
14#define IP6_PACKET_TOO_BIG 0x00000010\r
15\r
16#define IP6_ROUTE_CACHE_HASH_SIZE 31\r
17///\r
18/// Max NO. of cache entry per hash bucket\r
19///\r
20#define IP6_ROUTE_CACHE_MAX 32\r
21\r
22#define IP6_ROUTE_CACHE_HASH(Ip1, Ip2) Ip6RouteCacheHash ((Ip1), (Ip2))\r
23\r
24typedef struct {\r
25 LIST_ENTRY Link;\r
26 INTN RefCnt;\r
27 UINT32 Flag;\r
28 UINT8 PrefixLength;\r
29 EFI_IPv6_ADDRESS Destination;\r
30 EFI_IPv6_ADDRESS NextHop;\r
31} IP6_ROUTE_ENTRY;\r
32\r
33typedef struct {\r
34 LIST_ENTRY Link;\r
35 INTN RefCnt;\r
36 UINTN Tag;\r
37 EFI_IPv6_ADDRESS Destination;\r
38 EFI_IPv6_ADDRESS Source;\r
39 EFI_IPv6_ADDRESS NextHop;\r
40} IP6_ROUTE_CACHE_ENTRY;\r
41\r
42typedef struct {\r
43 LIST_ENTRY CacheBucket[IP6_ROUTE_CACHE_HASH_SIZE];\r
44 UINT8 CacheNum[IP6_ROUTE_CACHE_HASH_SIZE];\r
45} IP6_ROUTE_CACHE;\r
46\r
47//\r
48// Each IP6 instance has its own route table. Each ServiceBinding\r
49// instance has a default route table and default address.\r
50//\r
51// All the route table entries with the same prefix length are linked\r
52// together in one route area. For example, RouteArea[0] contains\r
53// the default routes. A route table also contains a route cache.\r
54//\r
55\r
56typedef struct _IP6_ROUTE_TABLE {\r
57 INTN RefCnt;\r
58 UINT32 TotalNum;\r
59 LIST_ENTRY RouteArea[IP6_PREFIX_NUM];\r
60 IP6_ROUTE_CACHE Cache;\r
61} IP6_ROUTE_TABLE;\r
62\r
63/**\r
64 This is the worker function for IP6_ROUTE_CACHE_HASH(). It calculates the value\r
65 as the index of the route cache bucket according to the prefix of two IPv6 addresses.\r
66\r
67 @param[in] Ip1 The IPv6 address.\r
68 @param[in] Ip2 The IPv6 address.\r
69\r
70 @return The hash value of the prefix of two IPv6 addresses.\r
71\r
72**/\r
73UINT32\r
74Ip6RouteCacheHash (\r
75 IN EFI_IPv6_ADDRESS *Ip1,\r
76 IN EFI_IPv6_ADDRESS *Ip2\r
77 );\r
78\r
79/**\r
80 Allocate and initialize an IP6 route cache entry.\r
81\r
82 @param[in] Dst The destination address.\r
83 @param[in] Src The source address.\r
84 @param[in] GateWay The next hop address.\r
85 @param[in] Tag The tag from the caller. This marks all the cache entries\r
86 spawned from one route table entry.\r
87\r
88 @return NULL if it failed to allocate memory for the cache. Otherwise, point\r
89 to the created route cache entry.\r
90\r
91**/\r
92IP6_ROUTE_CACHE_ENTRY *\r
93Ip6CreateRouteCacheEntry (\r
94 IN EFI_IPv6_ADDRESS *Dst,\r
95 IN EFI_IPv6_ADDRESS *Src,\r
96 IN EFI_IPv6_ADDRESS *GateWay,\r
97 IN UINTN Tag\r
98 );\r
99\r
100/**\r
101 Free the route cache entry. It is reference counted.\r
102\r
103 @param[in, out] RtCacheEntry The route cache entry to free.\r
104\r
105**/\r
106VOID\r
107Ip6FreeRouteCacheEntry (\r
108 IN OUT IP6_ROUTE_CACHE_ENTRY *RtCacheEntry\r
109 );\r
110\r
111/**\r
112 Find a route cache with the destination and source address. This is\r
113 used by the ICMPv6 redirect messasge process.\r
114\r
115 @param[in] RtTable The route table to search the cache for.\r
116 @param[in] Dest The destination address.\r
117 @param[in] Src The source address.\r
118\r
119 @return NULL if no route entry to the (Dest, Src). Otherwise, point\r
120 to the correct route cache entry.\r
121\r
122**/\r
123IP6_ROUTE_CACHE_ENTRY *\r
124Ip6FindRouteCache (\r
125 IN IP6_ROUTE_TABLE *RtTable,\r
126 IN EFI_IPv6_ADDRESS *Dest,\r
127 IN EFI_IPv6_ADDRESS *Src\r
128 );\r
129\r
130/**\r
131 Build a array of EFI_IP6_ROUTE_TABLE to be returned to the caller. The number\r
132 of EFI_IP6_ROUTE_TABLE is also returned.\r
133\r
134 @param[in] RouteTable The pointer of IP6_ROUTE_TABLE internal used.\r
135 @param[out] EfiRouteCount The number of returned route entries.\r
136 @param[out] EfiRouteTable The pointer to the array of EFI_IP6_ROUTE_TABLE.\r
137 If NULL, only the route entry count is returned.\r
138\r
139 @retval EFI_SUCCESS The EFI_IP6_ROUTE_TABLE successfully built.\r
140 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the route table.\r
141\r
142**/\r
143EFI_STATUS\r
144Ip6BuildEfiRouteTable (\r
145 IN IP6_ROUTE_TABLE *RouteTable,\r
146 OUT UINT32 *EfiRouteCount,\r
147 OUT EFI_IP6_ROUTE_TABLE **EfiRouteTable OPTIONAL\r
148 );\r
149\r
150/**\r
151 Create an empty route table, includes its internal route cache.\r
152\r
153 @return NULL if failed to allocate memory for the route table. Otherwise,\r
154 the point to newly created route table.\r
155\r
156**/\r
157IP6_ROUTE_TABLE *\r
158Ip6CreateRouteTable (\r
159 VOID\r
160 );\r
161\r
162/**\r
163 Free the route table and its associated route cache. Route\r
164 table is reference counted.\r
165\r
166 @param[in, out] RtTable The route table to free.\r
167\r
168**/\r
169VOID\r
170Ip6CleanRouteTable (\r
171 IN OUT IP6_ROUTE_TABLE *RtTable\r
172 );\r
173\r
174/**\r
175 Allocate a route entry then initialize it with the Destination/PrefixLength\r
176 and Gateway.\r
177\r
178 @param[in] Destination The IPv6 destination address. This is an optional\r
179 parameter that may be NULL.\r
180 @param[in] PrefixLength The destination network's prefix length.\r
181 @param[in] GatewayAddress The next hop address. This is optional parameter\r
182 that may be NULL.\r
183\r
184 @return NULL if it failed to allocate memeory. Otherwise, the newly created route entry.\r
185\r
186**/\r
187IP6_ROUTE_ENTRY *\r
188Ip6CreateRouteEntry (\r
189 IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r
190 IN UINT8 PrefixLength,\r
191 IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL\r
192 );\r
193\r
194/**\r
195 Search the route table for a most specific match to the Dst. It searches\r
196 from the longest route area (prefix length == 128) to the shortest route area\r
197 (default routes). In each route area, it will first search the instance's\r
198 route table, then the default route table. This is required per the following\r
199 requirements:\r
200 1. IP search the route table for a most specific match.\r
201 2. The local route entries have precedence over the default route entry.\r
202\r
203 @param[in] RtTable The route table to search from.\r
204 @param[in] Destination The destionation address to search. If NULL, search\r
205 the route table by NextHop.\r
206 @param[in] NextHop The next hop address. If NULL, search the route table\r
207 by Destination.\r
208\r
209 @return NULL if no route matches the Dst. Otherwise the point to the\r
210 most specific route to the Dst.\r
211\r
212**/\r
213IP6_ROUTE_ENTRY *\r
214Ip6FindRouteEntry (\r
215 IN IP6_ROUTE_TABLE *RtTable,\r
216 IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r
217 IN EFI_IPv6_ADDRESS *NextHop OPTIONAL\r
218 );\r
219\r
220/**\r
221 Free the route table entry. It is reference counted.\r
222\r
223 @param[in, out] RtEntry The route entry to free.\r
224\r
225**/\r
226VOID\r
227Ip6FreeRouteEntry (\r
228 IN OUT IP6_ROUTE_ENTRY *RtEntry\r
229 );\r
230\r
231/**\r
232 Add a route entry to the route table. It is the help function for EfiIp6Routes.\r
233\r
234 @param[in, out] RtTable Route table to add route to.\r
235 @param[in] Destination The destination of the network.\r
236 @param[in] PrefixLength The PrefixLength of the destination.\r
237 @param[in] GatewayAddress The next hop address.\r
238\r
239 @retval EFI_ACCESS_DENIED The same route already exists.\r
240 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry.\r
241 @retval EFI_SUCCESS The route was added successfully.\r
242\r
243**/\r
244EFI_STATUS\r
245Ip6AddRoute (\r
246 IN OUT IP6_ROUTE_TABLE *RtTable,\r
247 IN EFI_IPv6_ADDRESS *Destination,\r
248 IN UINT8 PrefixLength,\r
249 IN EFI_IPv6_ADDRESS *GatewayAddress\r
250 );\r
251\r
252/**\r
253 Remove a route entry and all the route caches spawn from it.\r
254 It is the help function for EfiIp6Routes.\r
255\r
256 @param[in, out] RtTable The route table to remove the route from.\r
257 @param[in] Destination The destination network.\r
258 @param[in] PrefixLength The PrefixLength of the Destination.\r
259 @param[in] GatewayAddress The next hop address.\r
260\r
261 @retval EFI_SUCCESS Successfully removed the route entry.\r
262 @retval EFI_NOT_FOUND There is no route entry in the table with that\r
263 properity.\r
264\r
265**/\r
266EFI_STATUS\r
267Ip6DelRoute (\r
268 IN OUT IP6_ROUTE_TABLE *RtTable,\r
269 IN EFI_IPv6_ADDRESS *Destination,\r
270 IN UINT8 PrefixLength,\r
271 IN EFI_IPv6_ADDRESS *GatewayAddress\r
272 );\r
273\r
274/**\r
275 Search the route table to route the packet. Return/create a route\r
276 cache if there is a route to the destination.\r
277\r
278 @param[in] IpSb The IP6 service data.\r
279 @param[in] Dest The destination address to search for.\r
280 @param[in] Src The source address to search for.\r
281\r
282 @return NULL if failed to route packet. Otherwise, a route cache\r
283 entry that can be used to route packet.\r
284\r
285**/\r
286IP6_ROUTE_CACHE_ENTRY *\r
287Ip6Route (\r
288 IN IP6_SERVICE *IpSb,\r
289 IN EFI_IPv6_ADDRESS *Dest,\r
290 IN EFI_IPv6_ADDRESS *Src\r
291 );\r
292\r
293#endif\r