1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Internet Control Message Protocol (ICMP)                            */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 #include "nx_api.h"
27 #include "nx_ipv6.h"
28 #include "nx_icmpv6.h"
29 
30 #ifdef FEATURE_NX_IPV6
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nxd_ipv6_destination_table_find_next_hop           PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This is an internal function.  It searches the destination table    */
45 /*    (equivalent to IPv4 static routing table) for a possible match.     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP.                */
50 /*    destination_ip                        IP address to search for.     */
51 /*    next_hop                              Storage space for next hop    */
52 /*                                             address.                   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    NX_SUCCESS                            Valid next hop returned       */
57 /*    NX_NOT_SUCCESSFUL                     Invalid pointer input or no   */
58 /*                                            match found; next hop not   */
59 /*                                            returned                    */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    _nx_icmpv6_process_redirect           Process incoming redirect     */
66 /*                                             message.                   */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nxd_ipv6_destination_table_find_next_hop(NX_IP * ip_ptr,ULONG * destination_ip,ULONG * next_hop)77 UINT _nxd_ipv6_destination_table_find_next_hop(NX_IP *ip_ptr, ULONG *destination_ip, ULONG *next_hop)
78 {
79 
80 UINT i, table_size;
81 UINT status;
82 
83 
84     status = NX_NOT_SUCCESSFUL;
85 
86     /* Next hop storage must not be valid. */
87     NX_ASSERT(next_hop != NX_NULL);
88 
89     /* Set a local variable for convenience. */
90     table_size = ip_ptr -> nx_ipv6_destination_table_size;
91 
92     /* Check the num of destination. */
93     if (table_size == 0)
94     {
95         return(NX_NOT_SUCCESSFUL);
96     }
97 
98     /* Loop through all entries. */
99     for (i = 0; table_size && (i < NX_IPV6_DESTINATION_TABLE_SIZE); i++)
100     {
101 
102         /* Skip invalid entries. */
103         if (!ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_valid)
104         {
105             continue;
106         }
107 
108         /* Keep track of valid entries we have checked. */
109         table_size--;
110 
111         /* Check whether or not the address is the same. */
112         if (CHECK_IPV6_ADDRESSES_SAME(ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_destination_address, destination_ip))
113         {
114 
115             /* Copy next hop address to user-supplied storage. */
116             COPY_IPV6_ADDRESS(ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_next_hop, next_hop);
117 
118             status = NX_SUCCESS;
119 
120             /* break out of the for loop */
121             break;
122         }
123     }
124 
125 
126     return(status);
127 }
128 
129 
130 #endif  /* FEATURE_NX_IPV6 */
131 
132