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