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 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Neighbor Discovery Cache                                            */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "nx_api.h"
29 #include "nx_nd_cache.h"
30 #ifdef FEATURE_NX_IPV6
31 #include "nx_ipv6.h"
32 #endif /* FEATURE_NX_IPV6 */
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nxd_nd_cache_entry_ip_address_find                 PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function finds an IPv6 address in the neighbor discovery       */
47 /*    cache table based on user-speicified MAC address.                   */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    ip_ptr                                Pointer to IP instance        */
52 /*    ip_address                            Pointer to the IP address     */
53 /*                                            to search for               */
54 /*    physical_msw                          Physical address, most        */
55 /*                                            significant word            */
56 /*    physical_lsw                          Physical address, least       */
57 /*                                            significant word            */
58 /*    interface_index                       Index to the network          */
59 /*                                            interface through which the */
60 /*                                            node is reachable.          */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    Status                                Completion status             */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    _nx_nd_cache_find_entry_by_mac_addr   Internal find IP address in   */
69 /*                                          ND cache table mapped to      */
70 /*                                            input by mac address.       */
71 /*                                                                        */
72 /*  CALLED BY                                                             */
73 /*                                                                        */
74 /*    Application Code                                                    */
75 /*                                                                        */
76 /*  RELEASE HISTORY                                                       */
77 /*                                                                        */
78 /*    DATE              NAME                      DESCRIPTION             */
79 /*                                                                        */
80 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
81 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
82 /*                                            resulting in version 6.1    */
83 /*                                                                        */
84 /**************************************************************************/
_nxd_nd_cache_ip_address_find(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,ULONG physical_msw,ULONG physical_lsw,UINT * interface_index)85 UINT  _nxd_nd_cache_ip_address_find(NX_IP *ip_ptr,
86                                     NXD_ADDRESS *ip_address,
87                                     ULONG physical_msw,
88                                     ULONG physical_lsw,
89                                     UINT *interface_index)
90 {
91 #ifdef FEATURE_NX_IPV6
92 
93 ND_CACHE_ENTRY *entry;
94 
95     /* Find ND entry according to the given MAC address. */
96     /* Obtain the protection. */
97     tx_mutex_get(&ip_ptr -> nx_ip_protection, TX_WAIT_FOREVER);
98 
99     if (_nx_nd_cache_find_entry_by_mac_addr(ip_ptr, physical_msw, physical_lsw, &entry) != NX_SUCCESS)
100     {
101 
102         /* Release the protection. */
103         tx_mutex_put(&ip_ptr -> nx_ip_protection);
104 
105         /* No such MAC address found in cache table. */
106         return(NX_ENTRY_NOT_FOUND);
107     }
108 
109     /* Copy the IP address and version from the cache entry into the address structure. */
110     ip_address -> nxd_ip_version = NX_IP_VERSION_V6;
111 
112     /*lint -e{644} suppress variable might not be initialized, since "entry" was initialized as long as previous call is NX_SUCCESS. */
113     COPY_IPV6_ADDRESS(entry -> nx_nd_cache_dest_ip, ip_address -> nxd_ip_address.v6);
114 
115     /* If trace is enabled, insert this event into the trace buffer. */
116     NX_TRACE_IN_LINE_INSERT(NX_TRACE_ND_CACHE_IP_ADDRESS_FIND, ip_ptr, ip_address -> nxd_ip_address.v6[3], physical_msw, physical_lsw, NX_TRACE_ARP_EVENTS, 0, 0);
117 
118     /* Get the interface_index.  */
119     *interface_index = entry -> nx_nd_cache_interface_ptr -> nx_interface_index;
120 
121     /* Release the protection. */
122     tx_mutex_put(&ip_ptr -> nx_ip_protection);
123 
124     /* Successful completion*/
125     return(NX_SUCCESS);
126 
127 #else /* !FEATURE_NX_IPV6 */
128     NX_PARAMETER_NOT_USED(ip_ptr);
129     NX_PARAMETER_NOT_USED(ip_address);
130     NX_PARAMETER_NOT_USED(physical_msw);
131     NX_PARAMETER_NOT_USED(physical_lsw);
132     NX_PARAMETER_NOT_USED(interface_index);
133 
134     return(NX_NOT_SUPPORTED);
135 
136 #endif /* FEATURE_NX_IPV6 */
137 }
138 
139