]>
Commit | Line | Data |
---|---|---|
a3bcde70 | 1 | /** @file\r |
7de8045a | 2 | EFI IP6 route table and route cache table definitions.\r |
a3bcde70 HT |
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 | |
d1050b9d MK |
13 | #define IP6_DIRECT_ROUTE 0x00000001\r |
14 | #define IP6_PACKET_TOO_BIG 0x00000010\r | |
a3bcde70 | 15 | \r |
d1050b9d | 16 | #define IP6_ROUTE_CACHE_HASH_SIZE 31\r |
a3bcde70 HT |
17 | ///\r |
18 | /// Max NO. of cache entry per hash bucket\r | |
19 | ///\r | |
d1050b9d | 20 | #define IP6_ROUTE_CACHE_MAX 32\r |
a3bcde70 | 21 | \r |
d1050b9d | 22 | #define IP6_ROUTE_CACHE_HASH(Ip1, Ip2) Ip6RouteCacheHash ((Ip1), (Ip2))\r |
a3bcde70 HT |
23 | \r |
24 | typedef struct {\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
31 | } IP6_ROUTE_ENTRY;\r |
32 | \r | |
33 | typedef struct {\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
40 | } IP6_ROUTE_CACHE_ENTRY;\r |
41 | \r | |
42 | typedef struct {\r | |
d1050b9d MK |
43 | LIST_ENTRY CacheBucket[IP6_ROUTE_CACHE_HASH_SIZE];\r |
44 | UINT8 CacheNum[IP6_ROUTE_CACHE_HASH_SIZE];\r | |
a3bcde70 HT |
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 | |
56 | typedef struct _IP6_ROUTE_TABLE {\r | |
d1050b9d MK |
57 | INTN RefCnt;\r |
58 | UINT32 TotalNum;\r | |
59 | LIST_ENTRY RouteArea[IP6_PREFIX_NUM];\r | |
60 | IP6_ROUTE_CACHE Cache;\r | |
a3bcde70 HT |
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 | |
73 | UINT32\r | |
74 | Ip6RouteCacheHash (\r | |
d1050b9d MK |
75 | IN EFI_IPv6_ADDRESS *Ip1,\r |
76 | IN EFI_IPv6_ADDRESS *Ip2\r | |
a3bcde70 HT |
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 | |
92 | IP6_ROUTE_CACHE_ENTRY *\r | |
93 | Ip6CreateRouteCacheEntry (\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
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 | |
106 | VOID\r | |
107 | Ip6FreeRouteCacheEntry (\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 | |
7de8045a | 113 | used by the ICMPv6 redirect message process.\r |
a3bcde70 HT |
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 | |
123 | IP6_ROUTE_CACHE_ENTRY *\r | |
124 | Ip6FindRouteCache (\r | |
d1050b9d MK |
125 | IN IP6_ROUTE_TABLE *RtTable,\r |
126 | IN EFI_IPv6_ADDRESS *Dest,\r | |
127 | IN EFI_IPv6_ADDRESS *Src\r | |
a3bcde70 HT |
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 | |
143 | EFI_STATUS\r | |
144 | Ip6BuildEfiRouteTable (\r | |
d1050b9d MK |
145 | IN IP6_ROUTE_TABLE *RouteTable,\r |
146 | OUT UINT32 *EfiRouteCount,\r | |
147 | OUT EFI_IP6_ROUTE_TABLE **EfiRouteTable OPTIONAL\r | |
a3bcde70 HT |
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 | |
157 | IP6_ROUTE_TABLE *\r | |
158 | Ip6CreateRouteTable (\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 | |
169 | VOID\r | |
170 | Ip6CleanRouteTable (\r | |
d1050b9d | 171 | IN OUT IP6_ROUTE_TABLE *RtTable\r |
a3bcde70 HT |
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 | |
7de8045a | 184 | @return NULL if it failed to allocate memory. Otherwise, the newly created route entry.\r |
a3bcde70 HT |
185 | \r |
186 | **/\r | |
187 | IP6_ROUTE_ENTRY *\r | |
188 | Ip6CreateRouteEntry (\r | |
d1050b9d MK |
189 | IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r |
190 | IN UINT8 PrefixLength,\r | |
191 | IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL\r | |
a3bcde70 HT |
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 | |
7de8045a | 204 | @param[in] Destination The destination address to search. If NULL, search\r |
a3bcde70 HT |
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 | |
213 | IP6_ROUTE_ENTRY *\r | |
214 | Ip6FindRouteEntry (\r | |
d1050b9d MK |
215 | IN IP6_ROUTE_TABLE *RtTable,\r |
216 | IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r | |
217 | IN EFI_IPv6_ADDRESS *NextHop OPTIONAL\r | |
a3bcde70 HT |
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 | |
226 | VOID\r | |
227 | Ip6FreeRouteEntry (\r | |
d1050b9d | 228 | IN OUT IP6_ROUTE_ENTRY *RtEntry\r |
a3bcde70 HT |
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 | |
244 | EFI_STATUS\r | |
245 | Ip6AddRoute (\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
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 | |
7de8045a | 263 | property.\r |
a3bcde70 HT |
264 | \r |
265 | **/\r | |
266 | EFI_STATUS\r | |
267 | Ip6DelRoute (\r | |
d1050b9d MK |
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 | |
a3bcde70 HT |
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 | |
286 | IP6_ROUTE_CACHE_ENTRY *\r | |
287 | Ip6Route (\r | |
d1050b9d MK |
288 | IN IP6_SERVICE *IpSb,\r |
289 | IN EFI_IPv6_ADDRESS *Dest,\r | |
290 | IN EFI_IPv6_ADDRESS *Src\r | |
a3bcde70 HT |
291 | );\r |
292 | \r | |
293 | #endif\r |