]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/Ip6Dxe/Ip6Route.c
BaseTools/Capsule: Do not support -o with --dump-info
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / Ip6Route.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 The functions and routines to handle the route caches and route table.\r
3\r
c720da28 4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
a3bcde70
HT
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#include "Ip6Impl.h"\r
17\r
18/**\r
19 This is the worker function for IP6_ROUTE_CACHE_HASH(). It calculates the value\r
20 as the index of the route cache bucket according to the prefix of two IPv6 addresses.\r
21\r
22 @param[in] Ip1 The IPv6 address.\r
23 @param[in] Ip2 The IPv6 address.\r
24\r
25 @return The hash value of the prefix of two IPv6 addresses.\r
26\r
27**/\r
28UINT32\r
29Ip6RouteCacheHash (\r
30 IN EFI_IPv6_ADDRESS *Ip1,\r
31 IN EFI_IPv6_ADDRESS *Ip2\r
32 )\r
33{\r
34 UINT32 Prefix1;\r
35 UINT32 Prefix2;\r
36\r
37 Prefix1 = *((UINT32 *) ((UINTN *) (Ip1)));\r
38 Prefix2 = *((UINT32 *) ((UINTN *) (Ip2)));\r
39\r
40 return ((UINT32) (Prefix1 ^ Prefix2) % IP6_ROUTE_CACHE_HASH_SIZE);\r
41}\r
42\r
43/**\r
44 Allocate a route entry then initialize it with the Destination/PrefixLength\r
45 and Gateway.\r
46\r
47 @param[in] Destination The IPv6 destination address. This is an optional\r
48 parameter that may be NULL.\r
49 @param[in] PrefixLength The destination network's prefix length.\r
50 @param[in] GatewayAddress The next hop address. This is an optional parameter\r
51 that may be NULL.\r
52\r
53 @return NULL if failed to allocate memeory; otherwise, the newly created route entry.\r
54\r
55**/\r
56IP6_ROUTE_ENTRY *\r
57Ip6CreateRouteEntry (\r
58 IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r
59 IN UINT8 PrefixLength,\r
60 IN EFI_IPv6_ADDRESS *GatewayAddress OPTIONAL\r
61 )\r
62{\r
63 IP6_ROUTE_ENTRY *RtEntry;\r
64\r
65 RtEntry = AllocateZeroPool (sizeof (IP6_ROUTE_ENTRY));\r
66\r
67 if (RtEntry == NULL) {\r
68 return NULL;\r
69 }\r
70\r
71 RtEntry->RefCnt = 1;\r
72 RtEntry->Flag = 0;\r
73 RtEntry->PrefixLength = PrefixLength;\r
74\r
75 if (Destination != NULL) {\r
76 IP6_COPY_ADDRESS (&RtEntry->Destination, Destination);\r
77 }\r
78\r
79 if (GatewayAddress != NULL) {\r
80 IP6_COPY_ADDRESS (&RtEntry->NextHop, GatewayAddress);\r
81 }\r
82\r
83 return RtEntry;\r
84}\r
85\r
86/**\r
87 Free the route table entry. It is reference counted.\r
88\r
89 @param[in, out] RtEntry The route entry to free.\r
90\r
91**/\r
92VOID\r
93Ip6FreeRouteEntry (\r
94 IN OUT IP6_ROUTE_ENTRY *RtEntry\r
95 )\r
96{\r
97 ASSERT ((RtEntry != NULL) && (RtEntry->RefCnt > 0));\r
98\r
99 if (--RtEntry->RefCnt == 0) {\r
100 FreePool (RtEntry);\r
101 }\r
102}\r
103\r
104/**\r
105 Search the route table for a most specific match to the Dst. It searches\r
106 from the longest route area (prefix length == 128) to the shortest route area\r
107 (default routes). In each route area, it will first search the instance's\r
108 route table, then the default route table. This is required per the following\r
109 requirements:\r
110 1. IP search the route table for a most specific match.\r
111 2. The local route entries have precedence over the default route entry.\r
112\r
113 @param[in] RtTable The route table to search from.\r
114 @param[in] Destination The destionation address to search. If NULL, search\r
115 the route table by NextHop.\r
116 @param[in] NextHop The next hop address. If NULL, search the route table\r
117 by Destination.\r
118\r
119 @return NULL if no route matches the Dst. Otherwise, the point to the\r
120 @return most specific route to the Dst.\r
121\r
122**/\r
123IP6_ROUTE_ENTRY *\r
124Ip6FindRouteEntry (\r
125 IN IP6_ROUTE_TABLE *RtTable,\r
126 IN EFI_IPv6_ADDRESS *Destination OPTIONAL,\r
127 IN EFI_IPv6_ADDRESS *NextHop OPTIONAL\r
128 )\r
129{\r
130 LIST_ENTRY *Entry;\r
131 IP6_ROUTE_ENTRY *RtEntry;\r
132 INTN Index;\r
133\r
134 ASSERT (Destination != NULL || NextHop != NULL);\r
135\r
136 RtEntry = NULL;\r
137\r
c720da28 138 for (Index = IP6_PREFIX_MAX; Index >= 0; Index--) {\r
a3bcde70
HT
139 NET_LIST_FOR_EACH (Entry, &RtTable->RouteArea[Index]) {\r
140 RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
141\r
142 if (Destination != NULL) {\r
143 if (NetIp6IsNetEqual (Destination, &RtEntry->Destination, RtEntry->PrefixLength)) {\r
144 NET_GET_REF (RtEntry);\r
145 return RtEntry;\r
146 }\r
147 } else if (NextHop != NULL) {\r
148 if (NetIp6IsNetEqual (NextHop, &RtEntry->NextHop, RtEntry->PrefixLength)) {\r
149 NET_GET_REF (RtEntry);\r
150 return RtEntry;\r
151 }\r
152 }\r
153\r
154 }\r
155 }\r
156\r
157 return NULL;\r
158}\r
159\r
160/**\r
161 Allocate and initialize a IP6 route cache entry.\r
162\r
163 @param[in] Dst The destination address.\r
164 @param[in] Src The source address.\r
165 @param[in] GateWay The next hop address.\r
166 @param[in] Tag The tag from the caller. This marks all the cache entries\r
167 spawned from one route table entry.\r
168\r
169 @return NULL if failed to allocate memory for the cache. Otherwise, point\r
170 to the created route cache entry.\r
171\r
172**/\r
173IP6_ROUTE_CACHE_ENTRY *\r
174Ip6CreateRouteCacheEntry (\r
175 IN EFI_IPv6_ADDRESS *Dst,\r
176 IN EFI_IPv6_ADDRESS *Src,\r
177 IN EFI_IPv6_ADDRESS *GateWay,\r
178 IN UINTN Tag\r
179 )\r
180{\r
181 IP6_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
182\r
183 RtCacheEntry = AllocatePool (sizeof (IP6_ROUTE_CACHE_ENTRY));\r
184\r
185 if (RtCacheEntry == NULL) {\r
186 return NULL;\r
187 }\r
188\r
189 RtCacheEntry->RefCnt = 1;\r
190 RtCacheEntry->Tag = Tag;\r
191\r
192 IP6_COPY_ADDRESS (&RtCacheEntry->Destination, Dst);\r
193 IP6_COPY_ADDRESS (&RtCacheEntry->Source, Src);\r
194 IP6_COPY_ADDRESS (&RtCacheEntry->NextHop, GateWay);\r
195\r
196 return RtCacheEntry;\r
197}\r
198\r
199/**\r
200 Free the route cache entry. It is reference counted.\r
201\r
202 @param[in, out] RtCacheEntry The route cache entry to free.\r
203\r
204**/\r
205VOID\r
206Ip6FreeRouteCacheEntry (\r
207 IN OUT IP6_ROUTE_CACHE_ENTRY *RtCacheEntry\r
208 )\r
209{\r
210 ASSERT (RtCacheEntry->RefCnt > 0);\r
211\r
212 if (--RtCacheEntry->RefCnt == 0) {\r
213 FreePool (RtCacheEntry);\r
214 }\r
215}\r
216\r
217/**\r
218 Find a route cache with the destination and source address. This is\r
219 used by the ICMPv6 redirect messasge process.\r
220\r
221 @param[in] RtTable The route table to search the cache for.\r
222 @param[in] Dest The destination address.\r
223 @param[in] Src The source address.\r
224\r
225 @return NULL if no route entry to the (Dest, Src). Otherwise, the pointer\r
226 to the correct route cache entry.\r
227\r
228**/\r
229IP6_ROUTE_CACHE_ENTRY *\r
230Ip6FindRouteCache (\r
231 IN IP6_ROUTE_TABLE *RtTable,\r
232 IN EFI_IPv6_ADDRESS *Dest,\r
233 IN EFI_IPv6_ADDRESS *Src\r
234 )\r
235{\r
236 LIST_ENTRY *Entry;\r
237 IP6_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
238 UINT32 Index;\r
239\r
240 Index = IP6_ROUTE_CACHE_HASH (Dest, Src);\r
241\r
242 NET_LIST_FOR_EACH (Entry, &RtTable->Cache.CacheBucket[Index]) {\r
243 RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);\r
244\r
245 if (EFI_IP6_EQUAL (Dest, &RtCacheEntry->Destination)&& EFI_IP6_EQUAL (Src, &RtCacheEntry->Source)) {\r
246 NET_GET_REF (RtCacheEntry);\r
247 return RtCacheEntry;\r
248 }\r
249 }\r
250\r
251 return NULL;\r
252}\r
253\r
254/**\r
255 Build an array of EFI_IP6_ROUTE_TABLE to be returned to the caller. The number\r
256 of EFI_IP6_ROUTE_TABLE is also returned.\r
257\r
258 @param[in] RouteTable The pointer of IP6_ROUTE_TABLE internal used.\r
259 @param[out] EfiRouteCount The number of returned route entries.\r
260 @param[out] EfiRouteTable The pointer to the array of EFI_IP6_ROUTE_TABLE.\r
261 If NULL, only the route entry count is returned.\r
262\r
263 @retval EFI_SUCCESS The EFI_IP6_ROUTE_TABLE successfully built.\r
264 @retval EFI_OUT_OF_RESOURCES Failed to allocate the memory for the route table.\r
265\r
266**/\r
267EFI_STATUS\r
268Ip6BuildEfiRouteTable (\r
269 IN IP6_ROUTE_TABLE *RouteTable,\r
270 OUT UINT32 *EfiRouteCount,\r
271 OUT EFI_IP6_ROUTE_TABLE **EfiRouteTable OPTIONAL\r
272 )\r
273{\r
274 LIST_ENTRY *Entry;\r
275 IP6_ROUTE_ENTRY *RtEntry;\r
276 EFI_IP6_ROUTE_TABLE *EfiTable;\r
277 UINT32 Count;\r
278 INT32 Index;\r
279\r
280 ASSERT (EfiRouteCount != NULL);\r
281\r
282 Count = RouteTable->TotalNum;\r
283 *EfiRouteCount = Count;\r
284\r
285 if ((EfiRouteTable == NULL) || (Count == 0)) {\r
286 return EFI_SUCCESS;\r
287 }\r
288\r
289 if (*EfiRouteTable == NULL) {\r
290 *EfiRouteTable = AllocatePool (sizeof (EFI_IP6_ROUTE_TABLE) * Count);\r
291 if (*EfiRouteTable == NULL) {\r
292 return EFI_OUT_OF_RESOURCES;\r
293 }\r
294 }\r
295\r
296 EfiTable = *EfiRouteTable;\r
297\r
298 //\r
299 // Copy the route entry to EFI route table.\r
300 //\r
301 Count = 0;\r
302\r
c720da28 303 for (Index = IP6_PREFIX_MAX; Index >= 0; Index--) {\r
a3bcde70
HT
304\r
305 NET_LIST_FOR_EACH (Entry, &(RouteTable->RouteArea[Index])) {\r
306 RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
307\r
308 Ip6CopyAddressByPrefix (\r
309 &EfiTable[Count].Destination,\r
310 &RtEntry->Destination,\r
311 RtEntry->PrefixLength\r
312 );\r
313\r
314 IP6_COPY_ADDRESS (&EfiTable[Count].Gateway, &RtEntry->NextHop);\r
315 EfiTable[Count].PrefixLength = RtEntry->PrefixLength;\r
316\r
317 Count++;\r
318 }\r
319 }\r
320\r
321 ASSERT (Count == RouteTable->TotalNum);\r
322\r
323 return EFI_SUCCESS;\r
324}\r
325\r
326/**\r
327 Create an empty route table. This includes its internal route cache.\r
328\r
329 @return NULL if failed to allocate memory for the route table. Otherwise,\r
330 the point to newly created route table.\r
331\r
332**/\r
333IP6_ROUTE_TABLE *\r
334Ip6CreateRouteTable (\r
335 VOID\r
336 )\r
337{\r
338 IP6_ROUTE_TABLE *RtTable;\r
339 UINT32 Index;\r
340\r
341 RtTable = AllocatePool (sizeof (IP6_ROUTE_TABLE));\r
342 if (RtTable == NULL) {\r
343 return NULL;\r
344 }\r
345\r
346 RtTable->RefCnt = 1;\r
347 RtTable->TotalNum = 0;\r
348\r
c720da28 349 for (Index = 0; Index <= IP6_PREFIX_MAX; Index++) {\r
a3bcde70
HT
350 InitializeListHead (&RtTable->RouteArea[Index]);\r
351 }\r
352\r
353 for (Index = 0; Index < IP6_ROUTE_CACHE_HASH_SIZE; Index++) {\r
354 InitializeListHead (&RtTable->Cache.CacheBucket[Index]);\r
355 RtTable->Cache.CacheNum[Index] = 0;\r
356 }\r
357\r
358 return RtTable;\r
359}\r
360\r
361/**\r
362 Free the route table and its associated route cache. Route\r
363 table is reference counted.\r
364\r
365 @param[in, out] RtTable The route table to free.\r
366\r
367**/\r
368VOID\r
369Ip6CleanRouteTable (\r
370 IN OUT IP6_ROUTE_TABLE *RtTable\r
371 )\r
372{\r
373 LIST_ENTRY *Entry;\r
374 LIST_ENTRY *Next;\r
375 IP6_ROUTE_ENTRY *RtEntry;\r
376 IP6_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
377 UINT32 Index;\r
378\r
379 ASSERT (RtTable->RefCnt > 0);\r
380\r
381 if (--RtTable->RefCnt > 0) {\r
382 return ;\r
383 }\r
384\r
385 //\r
386 // Free all the route table entry and its route cache.\r
387 //\r
c720da28 388 for (Index = 0; Index <= IP6_PREFIX_MAX; Index++) {\r
a3bcde70
HT
389 NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtTable->RouteArea[Index]) {\r
390 RtEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
391 RemoveEntryList (Entry);\r
392 Ip6FreeRouteEntry (RtEntry);\r
393 }\r
394 }\r
395\r
396 for (Index = 0; Index < IP6_ROUTE_CACHE_HASH_SIZE; Index++) {\r
397 NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtTable->Cache.CacheBucket[Index]) {\r
398 RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);\r
399 RemoveEntryList (Entry);\r
400 Ip6FreeRouteCacheEntry (RtCacheEntry);\r
401 }\r
402 }\r
403\r
404 FreePool (RtTable);\r
405}\r
406\r
407/**\r
408 Remove all the cache entries bearing the Tag. When a route cache\r
409 entry is created, it is tagged with the address of route entry\r
410 from which it is spawned. When a route entry is deleted, the cache\r
411 entries spawned from it are also deleted.\r
412\r
413 @param[in] RtCache Route cache to remove the entries from.\r
414 @param[in] Tag The Tag of the entries to remove.\r
415\r
416**/\r
417VOID\r
418Ip6PurgeRouteCache (\r
419 IN IP6_ROUTE_CACHE *RtCache,\r
420 IN UINTN Tag\r
421 )\r
422{\r
423 LIST_ENTRY *Entry;\r
424 LIST_ENTRY *Next;\r
425 IP6_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
426 UINT32 Index;\r
427\r
428 for (Index = 0; Index < IP6_ROUTE_CACHE_HASH_SIZE; Index++) {\r
429 NET_LIST_FOR_EACH_SAFE (Entry, Next, &RtCache->CacheBucket[Index]) {\r
430\r
431 RtCacheEntry = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_CACHE_ENTRY, Link);\r
432\r
433 if (RtCacheEntry->Tag == Tag) {\r
434 RemoveEntryList (Entry);\r
435 Ip6FreeRouteCacheEntry (RtCacheEntry);\r
436 }\r
437 }\r
438 }\r
439}\r
440\r
441/**\r
442 Add a route entry to the route table. It is the help function for EfiIp6Routes.\r
443\r
444 @param[in, out] RtTable Route table to add route to.\r
445 @param[in] Destination The destination of the network.\r
446 @param[in] PrefixLength The PrefixLength of the destination.\r
447 @param[in] GatewayAddress The next hop address.\r
448\r
449 @retval EFI_ACCESS_DENIED The same route already exists.\r
450 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the entry.\r
451 @retval EFI_SUCCESS The route was added successfully.\r
452\r
453**/\r
454EFI_STATUS\r
455Ip6AddRoute (\r
456 IN OUT IP6_ROUTE_TABLE *RtTable,\r
457 IN EFI_IPv6_ADDRESS *Destination,\r
458 IN UINT8 PrefixLength,\r
459 IN EFI_IPv6_ADDRESS *GatewayAddress\r
460 )\r
461{\r
462 LIST_ENTRY *ListHead;\r
463 LIST_ENTRY *Entry;\r
464 IP6_ROUTE_ENTRY *Route;\r
465\r
466 ListHead = &RtTable->RouteArea[PrefixLength];\r
467\r
468 //\r
469 // First check whether the route exists\r
470 //\r
471 NET_LIST_FOR_EACH (Entry, ListHead) {\r
472 Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
473\r
474 if (NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength) &&\r
475 EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {\r
476 return EFI_ACCESS_DENIED;\r
477 }\r
478 }\r
479\r
480 //\r
481 // Create a route entry and insert it to the route area.\r
482 //\r
483 Route = Ip6CreateRouteEntry (Destination, PrefixLength, GatewayAddress);\r
484\r
485 if (Route == NULL) {\r
486 return EFI_OUT_OF_RESOURCES;\r
487 }\r
488\r
489 if (NetIp6IsUnspecifiedAddr (GatewayAddress)) {\r
490 Route->Flag = IP6_DIRECT_ROUTE;\r
491 }\r
492\r
493 InsertHeadList (ListHead, &Route->Link);\r
494 RtTable->TotalNum++;\r
495\r
496 return EFI_SUCCESS;\r
497}\r
498\r
499/**\r
500 Remove a route entry and all the route caches spawn from it.\r
501 It is the help function for EfiIp6Routes.\r
502\r
503 @param[in, out] RtTable The route table to remove the route from.\r
504 @param[in] Destination The destination network.\r
505 @param[in] PrefixLength The PrefixLength of the Destination.\r
506 @param[in] GatewayAddress The next hop address.\r
507\r
508 @retval EFI_SUCCESS The route entry was successfully removed.\r
509 @retval EFI_NOT_FOUND There is no route entry in the table with that\r
510 property.\r
511\r
512**/\r
513EFI_STATUS\r
514Ip6DelRoute (\r
515 IN OUT IP6_ROUTE_TABLE *RtTable,\r
516 IN EFI_IPv6_ADDRESS *Destination,\r
517 IN UINT8 PrefixLength,\r
518 IN EFI_IPv6_ADDRESS *GatewayAddress\r
519 )\r
520{\r
521 LIST_ENTRY *ListHead;\r
522 LIST_ENTRY *Entry;\r
523 LIST_ENTRY *Next;\r
524 IP6_ROUTE_ENTRY *Route;\r
525 UINT32 TotalNum;\r
526\r
527 ListHead = &RtTable->RouteArea[PrefixLength];\r
528 TotalNum = RtTable->TotalNum;\r
529\r
530 NET_LIST_FOR_EACH_SAFE (Entry, Next, ListHead) {\r
531 Route = NET_LIST_USER_STRUCT (Entry, IP6_ROUTE_ENTRY, Link);\r
532\r
533 if (Destination != NULL && !NetIp6IsNetEqual (Destination, &Route->Destination, PrefixLength)) {\r
534 continue;\r
535 }\r
536 if (GatewayAddress != NULL && !EFI_IP6_EQUAL (GatewayAddress, &Route->NextHop)) {\r
537 continue;\r
538 }\r
539\r
540 Ip6PurgeRouteCache (&RtTable->Cache, (UINTN) Route);\r
541 RemoveEntryList (Entry);\r
542 Ip6FreeRouteEntry (Route);\r
543\r
544 ASSERT (RtTable->TotalNum > 0);\r
545 RtTable->TotalNum--;\r
546 }\r
547\r
548 return TotalNum == RtTable->TotalNum ? EFI_NOT_FOUND : EFI_SUCCESS;\r
549}\r
550\r
551/**\r
552 Search the route table to route the packet. Return/create a route\r
553 cache if there is a route to the destination.\r
554\r
555 @param[in] IpSb The IP6 service data.\r
556 @param[in] Dest The destination address to search for.\r
557 @param[in] Src The source address to search for.\r
558\r
559 @return NULL if it failed to route the packet. Otherwise, a route cache\r
560 entry that can be used to route packets.\r
561\r
562**/\r
563IP6_ROUTE_CACHE_ENTRY *\r
564Ip6Route (\r
565 IN IP6_SERVICE *IpSb,\r
566 IN EFI_IPv6_ADDRESS *Dest,\r
567 IN EFI_IPv6_ADDRESS *Src\r
568 )\r
569{\r
570 IP6_ROUTE_TABLE *RtTable;\r
571 LIST_ENTRY *ListHead;\r
572 IP6_ROUTE_CACHE_ENTRY *RtCacheEntry;\r
573 IP6_ROUTE_ENTRY *RtEntry;\r
574 EFI_IPv6_ADDRESS NextHop;\r
575 UINT32 Index;\r
576\r
577 RtTable = IpSb->RouteTable;\r
578\r
579 ASSERT (RtTable != NULL);\r
580\r
581 //\r
582 // Search the destination cache in IP6_ROUTE_TABLE.\r
583 //\r
584 Index = IP6_ROUTE_CACHE_HASH (Dest, Src);\r
585 ListHead = &RtTable->Cache.CacheBucket[Index];\r
586\r
587 RtCacheEntry = Ip6FindRouteCache (RtTable, Dest, Src);\r
588\r
589 //\r
590 // If found, promote the cache entry to the head of the hash bucket.\r
591 //\r
592 if (RtCacheEntry != NULL) {\r
593 RemoveEntryList (&RtCacheEntry->Link);\r
594 InsertHeadList (ListHead, &RtCacheEntry->Link);\r
595 return RtCacheEntry;\r
596 }\r
597\r
598 //\r
599 // Search the route table for the most specific route\r
600 //\r
601 RtEntry = Ip6FindRouteEntry (RtTable, Dest, NULL);\r
602 if (RtEntry == NULL) {\r
603 return NULL;\r
604 }\r
605\r
606 //\r
607 // Found a route to the Dest, if it is a direct route, the packet\r
608 // will be send directly to the destination, such as for connected\r
609 // network. Otherwise, it is an indirect route, the packet will be\r
610 // send the next hop router.\r
611 //\r
612 if ((RtEntry->Flag & IP6_DIRECT_ROUTE) == IP6_DIRECT_ROUTE) {\r
613 IP6_COPY_ADDRESS (&NextHop, Dest);\r
614 } else {\r
615 IP6_COPY_ADDRESS (&NextHop, &RtEntry->NextHop);\r
616 }\r
617\r
618 Ip6FreeRouteEntry (RtEntry);\r
619\r
620 //\r
621 // Create a route cache entry, and tag it as spawned from this route entry\r
622 //\r
623 RtCacheEntry = Ip6CreateRouteCacheEntry (Dest, Src, &NextHop, (UINTN) RtEntry);\r
624\r
625 if (RtCacheEntry == NULL) {\r
626 return NULL;\r
627 }\r
628\r
629 InsertHeadList (ListHead, &RtCacheEntry->Link);\r
630 NET_GET_REF (RtCacheEntry);\r
631 RtTable->Cache.CacheNum[Index]++;\r
632\r
633 return RtCacheEntry;\r
634}\r
635\r