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